Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace swss;

#define VLAN_PREFIX "Vlan"
#define LAG_PREFIX "PortChannel"
#define VNET_PREFIX "Vnet"

IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
Orch(cfgDb, tableNames),
Expand All @@ -21,6 +22,7 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
m_stateVlanTable(stateDb, STATE_VLAN_TABLE_NAME),
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME)
{
}
Expand Down Expand Up @@ -63,6 +65,14 @@ bool IntfMgr::isIntfStateOk(const string &alias)
return true;
}
}
else if (!alias.compare(0, strlen(VNET_PREFIX), VNET_PREFIX))
{
if (m_stateVrfTable.get(alias, temp))
{
SWSS_LOG_DEBUG("Vnet %s is ready", alias.c_str());
return true;
}
}
else if (m_statePortTable.get(alias, temp))
{
SWSS_LOG_DEBUG("Port %s is ready", alias.c_str());
Expand All @@ -89,6 +99,19 @@ void IntfMgr::doTask(Consumer &consumer)
continue;
}

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

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

string alias(keys[0]);
IpPrefix ip_prefix(keys[1]);

Expand All @@ -107,6 +130,14 @@ void IntfMgr::doTask(Consumer &consumer)
it++;
continue;
}

if (!vnet_name.empty() && !isIntfStateOk(vnet_name))
{
SWSS_LOG_DEBUG("VRF is not ready, skipping %s", kfvKey(t).c_str());
it++;
continue;
}

setIntfIp(alias, "add", ip_prefix.to_string(), ip_prefix.isV4());
}
else if (op == DEL_COMMAND)
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IntfMgr : public Orch
private:
ProducerStateTable m_appIntfTableProducer;
Table m_cfgIntfTable, m_cfgVlanIntfTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable;

bool setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true);
void doTask(Consumer &consumer);
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int main(int argc, char **argv)
{
vector<string> cfg_intf_tables = {
CFG_INTF_TABLE_NAME,
CFG_VNET_INTF_TABLE_NAME,
CFG_LAG_INTF_TABLE_NAME,
CFG_VLAN_INTF_TABLE_NAME,
};
Expand Down
46 changes: 31 additions & 15 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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 @@ -114,6 +114,18 @@ 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));
const vector<FieldValueTuple>& data = kfvFieldsValues(t);
string vrf_name = "";

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

if (alias == "eth0" || alias == "docker0")
{
Expand All @@ -126,7 +138,7 @@ void IntfsOrch::doTask(Consumer &consumer)
{
if (alias == "lo")
{
addIp2MeRoute(ip_prefix);
addIp2MeRoute(vrf_name, ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}
Expand All @@ -149,7 +161,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_name, port))
{
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
Expand Down Expand Up @@ -198,7 +210,7 @@ void IntfsOrch::doTask(Consumer &consumer)
}

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

if (port.m_type == Port::VLAN && ip_prefix.isV4())
{
Expand All @@ -212,7 +224,7 @@ void IntfsOrch::doTask(Consumer &consumer)
{
if (alias == "lo")
{
removeIp2MeRoute(ip_prefix);
removeIp2MeRoute(vrf_name, ip_prefix);
it = consumer.m_toSync.erase(it);
continue;
}
Expand All @@ -230,7 +242,7 @@ void IntfsOrch::doTask(Consumer &consumer)
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
removeSubnetRoute(port, ip_prefix);
removeIp2MeRoute(ip_prefix);
removeIp2MeRoute(vrf_name, ip_prefix);
if(port.m_type == Port::VLAN && ip_prefix.isV4())
{
removeDirectedBroadcast(port, ip_prefix.getBroadcastIp());
Expand Down Expand Up @@ -262,7 +274,7 @@ void IntfsOrch::doTask(Consumer &consumer)
}
}

bool IntfsOrch::addRouterIntfs(Port &port)
bool IntfsOrch::addRouterIntfs(string& vrf_name, Port &port)
{
SWSS_LOG_ENTER();

Expand All @@ -274,12 +286,14 @@ bool IntfsOrch::addRouterIntfs(Port &port)
return true;
}

sai_object_id_t vr_id = m_vrfOrch->getVRFid(vrf_name);

/* Create router interface if the router interface doesn't exist */
sai_attribute_t attr;
vector<sai_attribute_t> attrs;

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

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

port.m_vr_id = vr_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 Down Expand Up @@ -370,7 +386,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 +429,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 +457,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(string &vrf_name, 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 = m_vrfOrch->getVRFid(vrf_name);;
copy(unicast_route_entry.destination, ip_prefix.getIp());

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

void IntfsOrch::removeIp2MeRoute(const IpPrefix &ip_prefix)
void IntfsOrch::removeIp2MeRoute(string &vrf_name, 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 = m_vrfOrch->getVRFid(vrf_name);
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(string &vrf_name, 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(string &vrf_name, const IpPrefix &ip_prefix);
void removeIp2MeRoute(string &vrf_name, const IpPrefix &ip_prefix);

void addDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
void removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
Expand Down
8 changes: 6 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ bool OrchDaemon::init()
gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME);
gPortsOrch = new PortsOrch(m_applDb, ports_tables);
gFdbOrch = new FdbOrch(m_applDb, APP_FDB_TABLE_NAME, gPortsOrch);
gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME);
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 All @@ -77,6 +80,8 @@ bool OrchDaemon::init()
gDirectory.set(vxlan_tunnel_orch);
VxlanTunnelMapOrch *vxlan_tunnel_map_orch = new VxlanTunnelMapOrch(m_configDb, CFG_VXLAN_TUNNEL_MAP_TABLE_NAME);
gDirectory.set(vxlan_tunnel_map_orch);
VxlanVrfMapOrch *vxlan_vrf_orch = new VxlanVrfMapOrch(m_applDb, APP_VXLAN_VRF_TABLE_NAME);
gDirectory.set(vxlan_vrf_orch);

vector<string> qos_tables = {
CFG_TC_TO_QUEUE_MAP_TABLE_NAME,
Expand Down Expand Up @@ -104,7 +109,6 @@ bool OrchDaemon::init()
TableConnector appDbMirrorSession(m_applDb, APP_MIRROR_SESSION_TABLE_NAME);
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
MirrorOrch *mirror_orch = new MirrorOrch(appDbMirrorSession, 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
1 change: 1 addition & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
23 changes: 22 additions & 1 deletion orchagent/request_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <exception>

#include "sai.h"
Expand Down Expand Up @@ -145,6 +144,9 @@ void Request::parseAttrs(const KeyOpFieldsValuesTuple& request)
case REQ_T_UINT:
attr_item_uint_[fvField(*i)] = parseUint(fvValue(*i));
break;
case REQ_T_SET:
attr_item_set_[fvField(*i)] = parseSet(fvValue(*i));
break;
default:
throw std::logic_error(std::string("Not implemented attribute type parser for attribute:") + fvField(*i));
}
Expand Down Expand Up @@ -207,6 +209,25 @@ IpAddress Request::parseIpAddress(const std::string& str)
}
}

set<string> Request::parseSet(const std::string& str)
{
try
{
set<string> str_set;
string substr;
std::istringstream iss(str);
while (getline(iss, substr, ','))
{
str_set.insert(str);
}
return str_set;
}
catch (std::invalid_argument& _)
{
throw std::invalid_argument(std::string("Invalid string set"));
}
}

uint64_t Request::parseUint(const std::string& str)
{
try
Expand Down
Loading