Skip to content

Commit

Permalink
orchagent: Syncing lo address to ASIC (sonic-net#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguohan authored and Shuotian Cheng committed Oct 9, 2016
1 parent 5012a87 commit bb85db3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ void IntfsOrch::doTask(Consumer &consumer)
string alias(keys[0]);
IpPrefix ip_prefix(kfvKey(t).substr(kfvKey(t).find(':')+1));

/* TODO: Sync loopback address and trap all IP packets to loopback address */
if (alias == "lo" || alias == "eth0" || alias == "docker0")
if (alias == "eth0" || alias == "docker0")
{
it = consumer.m_toSync.erase(it);
continue;
Expand All @@ -64,6 +63,13 @@ void IntfsOrch::doTask(Consumer &consumer)
string op = kfvOp(t);
if (op == SET_COMMAND)
{
if (alias == "lo")
{
addIp2MeRoute(ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}

Port port;
if (!gPortsOrch->getPort(alias, port))
{
Expand All @@ -82,7 +88,7 @@ void IntfsOrch::doTask(Consumer &consumer)
m_syncdIntfses[alias] = intfs_entry;

addSubnetRoute(port, ip_prefix);
addIp2MeRoute(port, ip_prefix);
addIp2MeRoute(ip_prefix);

m_syncdIntfses[alias].ip_addresses.add(ip_prefix.getIp());
it = consumer.m_toSync.erase(it);
Expand All @@ -96,6 +102,13 @@ void IntfsOrch::doTask(Consumer &consumer)
}
else if (op == DEL_COMMAND)
{
if (alias == "lo")
{
removeIp2MeRoute(ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}

Port port;
if (!gPortsOrch->getPort(alias, port))
{
Expand All @@ -108,7 +121,7 @@ void IntfsOrch::doTask(Consumer &consumer)
if (m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp()))
{
removeSubnetRoute(port, ip_prefix);
removeIp2MeRoute(port, ip_prefix);
removeIp2MeRoute(ip_prefix);

m_syncdIntfses[alias].ip_addresses.remove(ip_prefix.getIp());
}
Expand Down Expand Up @@ -267,7 +280,7 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
decreaseRouterIntfsRefCount(port.m_alias);
}

void IntfsOrch::addIp2MeRoute(const Port &port, const IpPrefix &ip_prefix)
void IntfsOrch::addIp2MeRoute(const IpPrefix &ip_prefix)
{
sai_unicast_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = gVirtualRouterId;
Expand All @@ -292,10 +305,9 @@ void IntfsOrch::addIp2MeRoute(const Port &port, const IpPrefix &ip_prefix)
}

SWSS_LOG_NOTICE("Create IP2me route ip:%s", ip_prefix.getIp().to_string().c_str());
increaseRouterIntfsRefCount(port.m_alias);
}

void IntfsOrch::removeIp2MeRoute(const Port &port, const IpPrefix &ip_prefix)
void IntfsOrch::removeIp2MeRoute(const IpPrefix &ip_prefix)
{
sai_unicast_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = gVirtualRouterId;
Expand All @@ -309,5 +321,4 @@ void IntfsOrch::removeIp2MeRoute(const Port &port, const IpPrefix &ip_prefix)
}

SWSS_LOG_NOTICE("Remove packet action trap route ip:%s", ip_prefix.getIp().to_string().c_str());
decreaseRouterIntfsRefCount(port.m_alias);
}
4 changes: 2 additions & 2 deletions orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class IntfsOrch : public Orch
void addSubnetRoute(const Port &port, const IpPrefix &ip_prefix);
void removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix);

void addIp2MeRoute(const Port &port, const IpPrefix &ip_prefix);
void removeIp2MeRoute(const Port &port, const IpPrefix &ip_prefix);
void addIp2MeRoute(const IpPrefix &ip_prefix);
void removeIp2MeRoute(const IpPrefix &ip_prefix);
};

#endif /* SWSS_INTFSORCH_H */

0 comments on commit bb85db3

Please sign in to comment.