Skip to content

Commit

Permalink
VNET/VRF Changes (#632)
Browse files Browse the repository at this point in the history
* VNET/VRF Changes  (#6)

* VRF changes

* Fixed an IPv6 address parsing issue

* Updated logs, removed intfmgr changes in favour of PR #635

* Updated VRF table name

* Addressed review comment, test fixes

* Remove extra semi-colon

* Route handling, review comments (#8)

* Vnet route table handling

* Addressed review comments

* Fix for interface routes, add debug logs
  • Loading branch information
prsunny authored Oct 10, 2018
1 parent 3f7c431 commit 8d57ae0
Show file tree
Hide file tree
Showing 15 changed files with 1,054 additions and 49 deletions.
2 changes: 2 additions & 0 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ orchagent_SOURCES = \
vrforch.cpp \
countercheckorch.cpp \
vxlanorch.cpp \
vnetorch.cpp \
dtelorch.cpp \
flexcounterorch.cpp \
acltable.h \
Expand Down Expand Up @@ -74,6 +75,7 @@ orchagent_SOURCES = \
dtelorch.h \
countercheckorch.h \
vxlanorch.h \
vnetorch.h \
flexcounterorch.h \
$(top_srcdir)/warmrestart/warm_restart.cpp \
$(top_srcdir)/warmrestart/warm_restart.h
Expand Down
89 changes: 71 additions & 18 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#include "routeorch.h"
#include "crmorch.h"
#include "bufferorch.h"
#include "directory.h"
#include "vnetorch.h"

extern sai_object_id_t gVirtualRouterId;
extern Directory<Orch*> gDirectory;

extern sai_router_interface_api_t* sai_router_intfs_api;
extern sai_route_api_t* sai_route_api;
Expand All @@ -27,8 +30,8 @@ extern BufferOrch *gBufferOrch;

const int intfsorch_pri = 35;

IntfsOrch::IntfsOrch(DBConnector *db, string tableName) :
Orch(db, tableName, intfsorch_pri)
IntfsOrch::IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch) :
Orch(db, tableName, intfsorch_pri), m_vrfOrch(vrf_orch)
{
SWSS_LOG_ENTER();
}
Expand Down Expand Up @@ -113,20 +116,65 @@ void IntfsOrch::doTask(Consumer &consumer)

vector<string> keys = tokenize(kfvKey(t), ':');
string alias(keys[0]);
IpPrefix ip_prefix(kfvKey(t).substr(kfvKey(t).find(':')+1));
IpPrefix ip_prefix;
bool ip_prefix_in_key = false;

if (keys.size() > 1)
{
ip_prefix = kfvKey(t).substr(kfvKey(t).find(':')+1);
ip_prefix_in_key = true;
}

const vector<FieldValueTuple>& data = kfvFieldsValues(t);
string vrf_name = "", vnet_name = "";

for (auto idx : data)
{
const auto &field = fvField(idx);
const auto &value = fvValue(idx);
if (field == "vrf_name")
{
vrf_name = value;
}
else if (field == "vnet_name")
{
vnet_name = value;
}
}

if (alias == "eth0" || alias == "docker0")
{
it = consumer.m_toSync.erase(it);
continue;
}

sai_object_id_t vrf_id = gVirtualRouterId;
if (!vnet_name.empty())
{
VNetOrch* vnet_orch = gDirectory.get<VNetOrch*>();
if (!vnet_orch->isVnetExists(vnet_name))
{
it++;
continue;
}
vrf_id = vnet_orch->getVRid(vnet_name);
}
else if (!vrf_name.empty())
{
if (m_vrfOrch->isVRFexists(vrf_name))
{
it++;
continue;
}
vrf_id = m_vrfOrch->getVRFid(vrf_name);
}

string op = kfvOp(t);
if (op == SET_COMMAND)
{
if (alias == "lo")
{
addIp2MeRoute(ip_prefix);
addIp2MeRoute(vrf_id, ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}
Expand All @@ -149,7 +197,7 @@ void IntfsOrch::doTask(Consumer &consumer)
auto it_intfs = m_syncdIntfses.find(alias);
if (it_intfs == m_syncdIntfses.end())
{
if (addRouterIntfs(port))
if (addRouterIntfs(vrf_id, port))
{
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
Expand All @@ -162,9 +210,10 @@ void IntfsOrch::doTask(Consumer &consumer)
}
}

if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
vrf_id = port.m_vr_id;
if (!ip_prefix_in_key || m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
/* Duplicate entry */
/* Request to create router interface, no prefix present or Duplicate entry */
it = consumer.m_toSync.erase(it);
continue;
}
Expand Down Expand Up @@ -198,7 +247,7 @@ void IntfsOrch::doTask(Consumer &consumer)
}

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

if (port.m_type == Port::VLAN && ip_prefix.isV4())
{
Expand All @@ -212,7 +261,7 @@ void IntfsOrch::doTask(Consumer &consumer)
{
if (alias == "lo")
{
removeIp2MeRoute(ip_prefix);
removeIp2MeRoute(vrf_id, ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}
Expand All @@ -225,12 +274,13 @@ void IntfsOrch::doTask(Consumer &consumer)
continue;
}

vrf_id = port.m_vr_id;
if (m_syncdIntfses.find(alias) != m_syncdIntfses.end())
{
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
removeSubnetRoute(port, ip_prefix);
removeIp2MeRoute(ip_prefix);
removeIp2MeRoute(vrf_id, ip_prefix);
if(port.m_type == Port::VLAN && ip_prefix.isV4())
{
removeDirectedBroadcast(port, ip_prefix.getBroadcastIp());
Expand Down Expand Up @@ -262,7 +312,7 @@ void IntfsOrch::doTask(Consumer &consumer)
}
}

bool IntfsOrch::addRouterIntfs(Port &port)
bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
{
SWSS_LOG_ENTER();

Expand All @@ -279,7 +329,7 @@ bool IntfsOrch::addRouterIntfs(Port &port)
vector<sai_attribute_t> attrs;

attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID;
attr.value.oid = gVirtualRouterId;
attr.value.oid = vrf_id;
attrs.push_back(attr);

attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
Expand Down Expand Up @@ -334,6 +384,8 @@ bool IntfsOrch::addRouterIntfs(Port &port)
throw runtime_error("Failed to create router interface.");
}

port.m_vr_id = vrf_id;

gPortsOrch->setPort(port.m_alias, port);

SWSS_LOG_NOTICE("Create router interface %s MTU %u", port.m_alias.c_str(), port.m_mtu);
Expand All @@ -359,6 +411,7 @@ bool IntfsOrch::removeRouterIntfs(Port &port)
}

port.m_rif_id = 0;
port.m_vr_id = 0;
gPortsOrch->setPort(port.m_alias, port);

SWSS_LOG_NOTICE("Remove router interface for port %s", port.m_alias.c_str());
Expand All @@ -370,7 +423,7 @@ void IntfsOrch::addSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
{
sai_route_entry_t unicast_route_entry;
unicast_route_entry.switch_id = gSwitchId;
unicast_route_entry.vr_id = gVirtualRouterId;
unicast_route_entry.vr_id = port.m_vr_id;
copy(unicast_route_entry.destination, ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

Expand Down Expand Up @@ -413,7 +466,7 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
{
sai_route_entry_t unicast_route_entry;
unicast_route_entry.switch_id = gSwitchId;
unicast_route_entry.vr_id = gVirtualRouterId;
unicast_route_entry.vr_id = port.m_vr_id;
copy(unicast_route_entry.destination, ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

Expand Down Expand Up @@ -441,11 +494,11 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
gRouteOrch->notifyNextHopChangeObservers(ip_prefix, IpAddresses(), false);
}

void IntfsOrch::addIp2MeRoute(const IpPrefix &ip_prefix)
void IntfsOrch::addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
{
sai_route_entry_t unicast_route_entry;
unicast_route_entry.switch_id = gSwitchId;
unicast_route_entry.vr_id = gVirtualRouterId;
unicast_route_entry.vr_id = vrf_id;
copy(unicast_route_entry.destination, ip_prefix.getIp());

sai_attribute_t attr;
Expand Down Expand Up @@ -481,11 +534,11 @@ void IntfsOrch::addIp2MeRoute(const IpPrefix &ip_prefix)
}
}

void IntfsOrch::removeIp2MeRoute(const IpPrefix &ip_prefix)
void IntfsOrch::removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
{
sai_route_entry_t unicast_route_entry;
unicast_route_entry.switch_id = gSwitchId;
unicast_route_entry.vr_id = gVirtualRouterId;
unicast_route_entry.vr_id = vrf_id;
copy(unicast_route_entry.destination, ip_prefix.getIp());

sai_status_t status = sai_route_api->remove_route_entry(&unicast_route_entry);
Expand Down
10 changes: 6 additions & 4 deletions orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "orch.h"
#include "portsorch.h"
#include "vrforch.h"

#include "ipaddresses.h"
#include "ipprefix.h"
Expand All @@ -25,7 +26,7 @@ typedef map<string, IntfsEntry> IntfsTable;
class IntfsOrch : public Orch
{
public:
IntfsOrch(DBConnector *db, string tableName);
IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch);

sai_object_id_t getRouterIntfsId(const string&);

Expand All @@ -35,19 +36,20 @@ class IntfsOrch : public Orch
bool setRouterIntfsMtu(Port &port);
std::set<IpPrefix> getSubnetRoutes();
private:
VRFOrch *m_vrfOrch;
IntfsTable m_syncdIntfses;
void doTask(Consumer &consumer);

int getRouterIntfsRefCount(const string&);

bool addRouterIntfs(Port &port);
bool addRouterIntfs(sai_object_id_t vrf_id, Port &port);
bool removeRouterIntfs(Port &port);

void addSubnetRoute(const Port &port, const IpPrefix &ip_prefix);
void removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix);

void addIp2MeRoute(const IpPrefix &ip_prefix);
void removeIp2MeRoute(const IpPrefix &ip_prefix);
void addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix);
void removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix);

void addDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
void removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
Expand Down
2 changes: 2 additions & 0 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ void Orch2::doTask(Consumer &consumer)
try
{
request_.parse(it->second);
auto table_name = consumer.getTableName();
request_.setTableName(table_name);

auto op = request_.getOperation();
if (op == SET_COMMAND)
Expand Down
5 changes: 5 additions & 0 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class Orch2 : public Orch
{
}

Orch2(DBConnector *db, const vector<string> &tableNames, Request& request)
: Orch(db, tableNames), request_(request)
{
}

protected:
virtual void doTask(Consumer& consumer);

Expand Down
17 changes: 14 additions & 3 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,22 @@ bool OrchDaemon::init()

gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME);
gPortsOrch = new PortsOrch(m_applDb, ports_tables);

TableConnector applDbFdb(m_applDb, APP_FDB_TABLE_NAME);
TableConnector stateDbFdb(m_stateDb, STATE_FDB_TABLE_NAME);
gFdbOrch = new FdbOrch(applDbFdb, stateDbFdb, gPortsOrch);

gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME);
vector<string> vnet_tables = {
APP_VNET_RT_TABLE_NAME,
APP_VNET_RT_TUNNEL_TABLE_NAME
};
VNetOrch *vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME);
gDirectory.set(vnet_orch);
VNetRouteOrch *vnet_rt_orch = new VNetRouteOrch(m_applDb, vnet_tables, vnet_orch);
gDirectory.set(vnet_rt_orch);
VRFOrch *vrf_orch = new VRFOrch(m_applDb, APP_VRF_TABLE_NAME);
gDirectory.set(vrf_orch);

gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME, vrf_orch);
gNeighOrch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, gIntfsOrch);
gRouteOrch = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, gNeighOrch);
CoppOrch *copp_orch = new CoppOrch(m_applDb, APP_COPP_TABLE_NAME);
Expand Down Expand Up @@ -111,7 +121,6 @@ bool OrchDaemon::init()
TableConnector stateDbMirrorSession(m_stateDb, APP_MIRROR_SESSION_TABLE_NAME);
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
MirrorOrch *mirror_orch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch);
VRFOrch *vrf_orch = new VRFOrch(m_configDb, CFG_VRF_TABLE_NAME);

TableConnector confDbAclTable(m_configDb, CFG_ACL_TABLE_NAME);
TableConnector confDbAclRuleTable(m_configDb, CFG_ACL_RULE_TABLE_NAME);
Expand Down Expand Up @@ -178,6 +187,8 @@ bool OrchDaemon::init()
m_orchList.push_back(gFdbOrch);
m_orchList.push_back(mirror_orch);
m_orchList.push_back(gAclOrch);
m_orchList.push_back(vnet_orch);
m_orchList.push_back(vnet_rt_orch);
m_orchList.push_back(vrf_orch);
m_orchList.push_back(vxlan_tunnel_orch);
m_orchList.push_back(vxlan_tunnel_map_orch);
Expand Down
1 change: 1 addition & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "crmorch.h"
#include "vrforch.h"
#include "vxlanorch.h"
#include "vnetorch.h"
#include "countercheckorch.h"
#include "flexcounterorch.h"
#include "directory.h"
Expand Down
1 change: 1 addition & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Port
sai_object_id_t m_bridge_port_id = 0; // TODO: port could have multiple bridge port IDs
sai_vlan_id_t m_port_vlan_id = DEFAULT_PORT_VLAN_ID; // Port VLAN ID
sai_object_id_t m_rif_id = 0;
sai_object_id_t m_vr_id = 0;
sai_object_id_t m_hif_id = 0;
sai_object_id_t m_lag_id = 0;
sai_object_id_t m_lag_member_id = 0;
Expand Down
Loading

0 comments on commit 8d57ae0

Please sign in to comment.