Skip to content

Commit

Permalink
Add scope attribute to VNET table. (sonic-net#954)
Browse files Browse the repository at this point in the history
* Add a global scope to VNet to consider default VRF

* Add VS test to validate default scope changes
  • Loading branch information
prsunny authored Aug 9, 2019
1 parent 2902ba0 commit 252e12c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
18 changes: 14 additions & 4 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern sai_neighbor_api_t* sai_neighbor_api;
extern sai_next_hop_api_t* sai_next_hop_api;
extern sai_bmtor_api_t* sai_bmtor_api;
extern sai_object_id_t gSwitchId;
extern sai_object_id_t gVirtualRouterId;
extern Directory<Orch*> gDirectory;
extern PortsOrch *gPortsOrch;
extern IntfsOrch *gIntfsOrch;
Expand Down Expand Up @@ -101,9 +102,13 @@ bool VNetVrfObject::createObj(vector<sai_attribute_t>& attrs)

for (auto vr_type : vr_cntxt)
{
sai_object_id_t router_id;
if (vr_type != VR_TYPE::VR_INVALID && l_fn(router_id))
sai_object_id_t router_id = gVirtualRouterId;
if (vr_type != VR_TYPE::VR_INVALID)
{
if (getScope() != "default")
{
l_fn(router_id);
}
SWSS_LOG_DEBUG("VNET vr_type %d router id %" PRIx64 " ", static_cast<int>(vr_type), router_id);
vr_ids_.insert(std::pair<VR_TYPE, sai_object_id_t>(vr_type, router_id));
}
Expand Down Expand Up @@ -1394,6 +1399,7 @@ bool VNetOrch::addOperation(const Request& request)
bool peer = false, create = false;
uint32_t vni=0;
string tunnel;
string scope;

for (const auto& name: request.getAttrFieldNames())
{
Expand All @@ -1417,6 +1423,10 @@ bool VNetOrch::addOperation(const Request& request)
{
tunnel = request.getAttrString("vxlan_tunnel");
}
else if (name == "scope")
{
scope = request.getAttrString("scope");
}
else
{
SWSS_LOG_INFO("Unknown attribute: %s", name.c_str());
Expand All @@ -1443,7 +1453,7 @@ bool VNetOrch::addOperation(const Request& request)

if (it == std::end(vnet_table_))
{
VNetInfo vnet_info = { tunnel, vni, peer_list };
VNetInfo vnet_info = { tunnel, vni, peer_list, scope };
obj = createObject<VNetVrfObject>(vnet_name, vnet_info, attrs);
create = true;
}
Expand All @@ -1470,7 +1480,7 @@ bool VNetOrch::addOperation(const Request& request)

if (it == std::end(vnet_table_))
{
VNetInfo vnet_info = { tunnel, vni, peer_list };
VNetInfo vnet_info = { tunnel, vni, peer_list, scope };
obj = createObject<VNetBitmapObject>(vnet_name, vnet_info, attrs);
create = true;
}
Expand Down
11 changes: 10 additions & 1 deletion orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const request_description_t vnet_request_description = {
{ "vni", REQ_T_UINT },
{ "peer_list", REQ_T_SET },
{ "guid", REQ_T_STRING },
{ "scope", REQ_T_STRING },
},
{ "vxlan_tunnel", "vni" } // mandatory attributes
};
Expand All @@ -49,6 +50,7 @@ struct VNetInfo
string tunnel;
uint32_t vni;
set<string> peers;
string scope;
};

typedef map<VR_TYPE, sai_object_id_t> vrid_list_t;
Expand All @@ -73,7 +75,8 @@ class VNetObject
VNetObject(const VNetInfo& vnetInfo) :
tunnel_(vnetInfo.tunnel),
peer_list_(vnetInfo.peers),
vni_(vnetInfo.vni)
vni_(vnetInfo.vni),
scope_(vnetInfo.scope)
{ }

virtual bool updateObj(vector<sai_attribute_t>&) = 0;
Expand All @@ -98,12 +101,18 @@ class VNetObject
return vni_;
}

string getScope() const
{
return scope_;
}

virtual ~VNetObject() noexcept(false) {};

private:
set<string> peer_list_ = {};
string tunnel_;
uint32_t vni_;
string scope_;
};

struct nextHop
Expand Down
40 changes: 37 additions & 3 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def delete_phy_interface(dvs, ifname, ipaddr):
time.sleep(2)


def create_vnet_entry(dvs, name, tunnel, vni, peer_list):
def create_vnet_entry(dvs, name, tunnel, vni, peer_list, scope=""):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

Expand All @@ -301,6 +301,9 @@ def create_vnet_entry(dvs, name, tunnel, vni, peer_list):
("peer_list", peer_list),
]

if scope:
attrs.append(('scope', scope))

# create the VXLAN tunnel Term entry in Config DB
create_entry_tbl(
conf_db,
Expand Down Expand Up @@ -520,6 +523,14 @@ def check_vnet_entry(self, dvs, name, peer_list=[]):
self.vnet_vr_ids.update(new_vr_ids)
self.vr_map[name] = { 'ing':new_vr_ids[0], 'egr':new_vr_ids[1], 'peer':peer_list }

def check_default_vnet_entry(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
#Check virtual router objects
assert how_many_entries_exist(asic_db, self.ASIC_VRF_TABLE) == (len(self.vnet_vr_ids)),\
"Some VR objects are created"
#Mappers for default VNET is created with default VR objects.
self.vr_map[name] = { 'ing':list(self.vnet_vr_ids)[0], 'egr':list(self.vnet_vr_ids)[0], 'peer':[] }

def check_del_vnet_entry(self, dvs, name):
# TODO: Implement for VRF VNET
return True
Expand Down Expand Up @@ -567,8 +578,12 @@ def check_router_interface(self, dvs, name, vlan_oid=0):
self.routes.update(new_route)

def check_del_router_interface(self, dvs, name):
# TODO: Implement for VRF VNET
return True
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

old_rif = get_deleted_entries(asic_db, self.ASIC_RIF_TABLE, self.rifs, 1)
check_deleted_object(asic_db, self.ASIC_RIF_TABLE, old_rif[0])

self.rifs.remove(old_rif[0])

def check_vnet_local_routes(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -800,6 +815,9 @@ def check_vnet_entry(self, dvs, name, peer_list=[]):
self.rifs = get_exist_entries(dvs, self.ASIC_RIF_TABLE)
self.vnet_map.update({name:{}})

def check_default_vnet_entry(self, dvs, name):
return self.check_vnet_entry(dvs, name)

def check_del_vnet_entry(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

Expand Down Expand Up @@ -1284,3 +1302,19 @@ def test_vnet_orch_4(self, dvs, testlog):

delete_vnet_entry(dvs, 'Vnet3001')
vnet_obj.check_del_vnet_entry(dvs, 'Vnet3001')

'''
Test 5 - Default VNet test
'''
def test_vnet_orch_5(self, dvs, testlog):
vnet_obj = self.get_vnet_obj()

tunnel_name = 'tunnel_5'

vnet_obj.fetch_exist_entries(dvs)

create_vxlan_tunnel(dvs, tunnel_name, '8.8.8.8')
create_vnet_entry(dvs, 'Vnet_5', tunnel_name, '4789', "", 'default')

vnet_obj.check_default_vnet_entry(dvs, 'Vnet_5')
vnet_obj.check_vxlan_tunnel_entry(dvs, tunnel_name, 'Vnet_5', '4789')

0 comments on commit 252e12c

Please sign in to comment.