Skip to content

Commit bd36751

Browse files
tylerlinpprsunny
authored andcommitted
Change nexthop key to ip & ifname (#977)
* Change nexthop key to ip & ifname
1 parent fee1aaa commit bd36751

15 files changed

+468
-209
lines changed

debian/changelog

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
sonic (1.0.0) stable; urgency=medium
22

3+
* next-hop key add ifname
4+
5+
-- Tyler Li <[email protected]> Thu, 19 Sep 2019 04:00:00 -0700
6+
37
* Initial release.
48

59
-- Shuotian Cheng <[email protected]> Wed, 09 Mar 2016 12:00:00 -0800

doc/swss-schema.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,10 @@ Stores rules associated with a specific ACL table on the switch.
456456
; it could be:
457457
: name of physical port. Example: "Ethernet10"
458458
: name of LAG port Example: "PortChannel5"
459-
: next-hop ip address Example: "10.0.0.1"
460-
: next-hop group set of addresses Example: "10.0.0.1,10.0.0.3"
459+
: next-hop ip address (in global) Example: "10.0.0.1"
460+
: next-hop ip address and vrf Example: "10.0.0.2@Vrf2"
461+
: next-hop ip address and ifname Example: "10.0.0.3@Ethernet1"
462+
: next-hop group set of next-hop Example: "10.0.0.1,10.0.0.3@Ethernet1"
461463

462464
redirect_action = 1*255CHAR ; redirect parameter
463465
; This parameter defines a destination for redirected packets

fpmsyncd/routesync.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ string RouteSync::getNextHopGw(struct rtnl_route *route_obj)
334334
nl_addr2str(addr, gw_ip, MAX_ADDR_SIZE);
335335
result += gw_ip;
336336
}
337+
else
338+
{
339+
if (rtnl_route_get_family(route_obj) == AF_INET)
340+
{
341+
result += "0.0.0.0";
342+
}
343+
else
344+
{
345+
result += "::";
346+
}
347+
}
337348

338349
if (i + 1 < rtnl_route_get_nnexthops(route_obj))
339350
{

orchagent/aclorch.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,12 @@ void AclRule::decreaseNextHopRefCount()
546546
{
547547
if (!m_redirect_target_next_hop.empty())
548548
{
549-
m_pAclOrch->m_neighOrch->decreaseNextHopRefCount(IpAddress(m_redirect_target_next_hop));
549+
m_pAclOrch->m_neighOrch->decreaseNextHopRefCount(NextHopKey(m_redirect_target_next_hop));
550550
m_redirect_target_next_hop.clear();
551551
}
552552
if (!m_redirect_target_next_hop_group.empty())
553553
{
554-
IpAddresses target = IpAddresses(m_redirect_target_next_hop_group);
554+
NextHopGroupKey target = NextHopGroupKey(m_redirect_target_next_hop_group);
555555
m_pAclOrch->m_routeOrch->decreaseNextHopRefCount(target);
556556
// remove next hop group in case it's not used by anything else
557557
if (m_pAclOrch->m_routeOrch->isRefCounterZero(target))
@@ -880,44 +880,44 @@ sai_object_id_t AclRuleL3::getRedirectObjectId(const string& redirect_value)
880880
}
881881
}
882882

883-
// Try to parse nexthop ip address
883+
// Try to parse nexthop ip address and interface name
884884
try
885885
{
886-
IpAddress ip(target);
887-
if (!m_pAclOrch->m_neighOrch->hasNextHop(ip))
886+
NextHopKey nh(target);
887+
if (!m_pAclOrch->m_neighOrch->hasNextHop(nh))
888888
{
889-
SWSS_LOG_ERROR("ACL Redirect action target next hop ip: '%s' doesn't exist on the switch", ip.to_string().c_str());
889+
SWSS_LOG_ERROR("ACL Redirect action target next hop ip: '%s' doesn't exist on the switch", nh.to_string().c_str());
890890
return SAI_NULL_OBJECT_ID;
891891
}
892892

893893
m_redirect_target_next_hop = target;
894-
m_pAclOrch->m_neighOrch->increaseNextHopRefCount(ip);
895-
return m_pAclOrch->m_neighOrch->getNextHopId(ip);
894+
m_pAclOrch->m_neighOrch->increaseNextHopRefCount(nh);
895+
return m_pAclOrch->m_neighOrch->getNextHopId(nh);
896896
}
897897
catch (...)
898898
{
899899
// no error, just try next variant
900900
}
901901

902-
// try to parse nh group ip addresses
902+
// try to parse nh group the set of <ip address, interface name>
903903
try
904904
{
905-
IpAddresses ips(target);
906-
if (!m_pAclOrch->m_routeOrch->hasNextHopGroup(ips))
905+
NextHopGroupKey nhg(target);
906+
if (!m_pAclOrch->m_routeOrch->hasNextHopGroup(nhg))
907907
{
908-
SWSS_LOG_INFO("ACL Redirect action target next hop group: '%s' doesn't exist on the switch. Creating it.", ips.to_string().c_str());
908+
SWSS_LOG_INFO("ACL Redirect action target next hop group: '%s' doesn't exist on the switch. Creating it.", nhg.to_string().c_str());
909909

910-
if (!m_pAclOrch->m_routeOrch->addNextHopGroup(ips))
910+
if (!m_pAclOrch->m_routeOrch->addNextHopGroup(nhg))
911911
{
912-
SWSS_LOG_ERROR("Can't create required target next hop group '%s'", ips.to_string().c_str());
912+
SWSS_LOG_ERROR("Can't create required target next hop group '%s'", nhg.to_string().c_str());
913913
return SAI_NULL_OBJECT_ID;
914914
}
915-
SWSS_LOG_DEBUG("Created acl redirect target next hop group '%s'", ips.to_string().c_str());
915+
SWSS_LOG_DEBUG("Created acl redirect target next hop group '%s'", nhg.to_string().c_str());
916916
}
917917

918918
m_redirect_target_next_hop_group = target;
919-
m_pAclOrch->m_routeOrch->increaseNextHopRefCount(ips);
920-
return m_pAclOrch->m_routeOrch->getNextHopGroupId(ips);
919+
m_pAclOrch->m_routeOrch->increaseNextHopRefCount(nhg);
920+
return m_pAclOrch->m_routeOrch->getNextHopGroupId(nhg);
921921
}
922922
catch (...)
923923
{

orchagent/intfsorch.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,35 @@ sai_object_id_t IntfsOrch::getRouterIntfsId(const string &alias)
7979
{
8080
Port port;
8181
gPortsOrch->getPort(alias, port);
82-
assert(port.m_rif_id);
8382
return port.m_rif_id;
8483
}
8584

85+
string IntfsOrch::getRouterIntfsAlias(const IpAddress &ip, const string &vrf_name)
86+
{
87+
sai_object_id_t vrf_id = gVirtualRouterId;
88+
89+
if (!vrf_name.empty())
90+
{
91+
vrf_id = m_vrfOrch->getVRFid(vrf_name);
92+
}
93+
94+
for (const auto &it_intfs: m_syncdIntfses)
95+
{
96+
if (it_intfs.second.vrf_id != vrf_id)
97+
{
98+
continue;
99+
}
100+
for (const auto &prefixIt: it_intfs.second.ip_addresses)
101+
{
102+
if (prefixIt.isAddressInSubnet(ip))
103+
{
104+
return it_intfs.first;
105+
}
106+
}
107+
}
108+
return string();
109+
}
110+
86111
void IntfsOrch::increaseRouterIntfsRefCount(const string &alias)
87112
{
88113
SWSS_LOG_ENTER();
@@ -154,6 +179,7 @@ bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPre
154179
gPortsOrch->increasePortRefCount(alias);
155180
IntfsEntry intfs_entry;
156181
intfs_entry.ref_count = 0;
182+
intfs_entry.vrf_id = vrf_id;
157183
m_syncdIntfses[alias] = intfs_entry;
158184
}
159185
else
@@ -328,6 +354,7 @@ void IntfsOrch::doTask(Consumer &consumer)
328354
IntfsEntry intfs_entry;
329355

330356
intfs_entry.ref_count = 0;
357+
intfs_entry.vrf_id = vrf_id;
331358
intfs_entry.ip_addresses.insert(ip_prefix);
332359
m_syncdIntfses[alias] = intfs_entry;
333360
addIp2Me = true;
@@ -629,7 +656,7 @@ void IntfsOrch::addSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
629656
gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
630657
}
631658

632-
gRouteOrch->notifyNextHopChangeObservers(ip_prefix, IpAddresses(), true);
659+
gRouteOrch->notifyNextHopChangeObservers(ip_prefix, NextHopGroupKey(), true);
633660
}
634661

635662
void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
@@ -661,7 +688,7 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
661688
gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
662689
}
663690

664-
gRouteOrch->notifyNextHopChangeObservers(ip_prefix, IpAddresses(), false);
691+
gRouteOrch->notifyNextHopChangeObservers(ip_prefix, NextHopGroupKey(), false);
665692
}
666693

667694
void IntfsOrch::addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)

orchagent/intfsorch.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct IntfsEntry
2222
{
2323
std::set<IpPrefix> ip_addresses;
2424
int ref_count;
25+
sai_object_id_t vrf_id;
2526
};
2627

2728
typedef map<string, IntfsEntry> IntfsTable;
@@ -32,6 +33,7 @@ class IntfsOrch : public Orch
3233
IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch);
3334

3435
sai_object_id_t getRouterIntfsId(const string&);
36+
string getRouterIntfsAlias(const IpAddress &ip, const string &vrf_name = "");
3537

3638
void increaseRouterIntfsRefCount(const string&);
3739
void decreaseRouterIntfsRefCount(const string&);

orchagent/mirrororch.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ MirrorEntry::MirrorEntry(const string& platform) :
6060
}
6161

6262
nexthopInfo.prefix = IpPrefix("0.0.0.0/0");
63-
nexthopInfo.nexthop = IpAddress("0.0.0.0");
63+
nexthopInfo.nexthop = NextHopKey("0.0.0.0", "");
6464
}
6565

6666
MirrorOrch::MirrorOrch(TableConnector stateDbConnector, TableConnector confDbConnector,
@@ -456,7 +456,7 @@ bool MirrorOrch::getNeighborInfo(const string& name, MirrorEntry& session)
456456
// 3) Otherwise, return false.
457457
if (!m_neighOrch->getNeighborEntry(session.dstIp,
458458
session.neighborInfo.neighbor, session.neighborInfo.mac) &&
459-
(session.nexthopInfo.nexthop.isZero() ||
459+
(session.nexthopInfo.nexthop.ip_address.isZero() ||
460460
!m_neighOrch->getNeighborEntry(session.nexthopInfo.nexthop,
461461
session.neighborInfo.neighbor, session.neighborInfo.mac)))
462462
{
@@ -894,8 +894,8 @@ void MirrorOrch::updateNextHop(const NextHopUpdate& update)
894894

895895
// This is the ECMP scenario that the new next hop group contains the previous
896896
// next hop. There is no need to update this session's monitor port.
897-
if (update.nexthopGroup != IpAddresses() &&
898-
update.nexthopGroup.getIpAddresses().count(session.nexthopInfo.nexthop))
897+
if (update.nexthopGroup != NextHopGroupKey() &&
898+
update.nexthopGroup.getNextHops().count(session.nexthopInfo.nexthop))
899899

900900
{
901901
continue;
@@ -904,18 +904,18 @@ void MirrorOrch::updateNextHop(const NextHopUpdate& update)
904904
SWSS_LOG_NOTICE("Updating mirror session %s with route %s",
905905
name.c_str(), update.prefix.to_string().c_str());
906906

907-
if (update.nexthopGroup != IpAddresses())
907+
if (update.nexthopGroup != NextHopGroupKey())
908908
{
909909
SWSS_LOG_NOTICE(" next hop IPs: %s", update.nexthopGroup.to_string().c_str());
910910

911911
// Recover the session based on the state database information
912912
if (m_recoverySessionMap.find(name) != m_recoverySessionMap.end())
913913
{
914-
IpAddress nexthop = IpAddress(tokenize(m_recoverySessionMap[name],
914+
NextHopKey nexthop = NextHopKey(tokenize(m_recoverySessionMap[name],
915915
state_db_key_delimiter, 1)[1]);
916916

917917
// Check if recovered next hop IP is within the update's next hop IPs
918-
if (update.nexthopGroup.getIpAddresses().count(nexthop))
918+
if (update.nexthopGroup.getNextHops().count(nexthop))
919919
{
920920
SWSS_LOG_NOTICE("Recover mirror session %s with next hop %s",
921921
name.c_str(), nexthop.to_string().c_str());
@@ -927,18 +927,18 @@ void MirrorOrch::updateNextHop(const NextHopUpdate& update)
927927
SWSS_LOG_NOTICE("Correct mirror session %s next hop from %s to %s",
928928
name.c_str(), session.nexthopInfo.nexthop.to_string().c_str(),
929929
nexthop.to_string().c_str());
930-
session.nexthopInfo.nexthop = *update.nexthopGroup.getIpAddresses().begin();
930+
session.nexthopInfo.nexthop = *update.nexthopGroup.getNextHops().begin();
931931
}
932932
}
933933
else
934934
{
935935
// Pick the first one from the next hop group
936-
session.nexthopInfo.nexthop = *update.nexthopGroup.getIpAddresses().begin();
936+
session.nexthopInfo.nexthop = *update.nexthopGroup.getNextHops().begin();
937937
}
938938
}
939939
else
940940
{
941-
session.nexthopInfo.nexthop = IpAddress(0);
941+
session.nexthopInfo.nexthop = NextHopKey("0.0.0.0", "");
942942
}
943943

944944
// Resolve the neighbor of the new next hop
@@ -960,7 +960,7 @@ void MirrorOrch::updateNeighbor(const NeighborUpdate& update)
960960
// Check if the session's destination IP matches the neighbor's update IP
961961
// or if the session's next hop IP matches the neighbor's update IP
962962
if (session.dstIp != update.entry.ip_address &&
963-
session.nexthopInfo.nexthop != update.entry.ip_address)
963+
session.nexthopInfo.nexthop.ip_address != update.entry.ip_address)
964964
{
965965
continue;
966966
}

orchagent/mirrororch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct MirrorEntry
3636
struct
3737
{
3838
IpPrefix prefix;
39-
IpAddress nexthop;
39+
NextHopKey nexthop;
4040
} nexthopInfo;
4141

4242
struct

0 commit comments

Comments
 (0)