Skip to content

Commit

Permalink
[vnet]: Extend Bitmap VNET test with "remove" flows (#900)
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Samotiy <volodymyrs@mellanox.com>
  • Loading branch information
Volodymyr Samotiy authored and lguohan committed Jun 4, 2019
1 parent d616764 commit 8d520a6
Showing 1 changed file with 220 additions and 0 deletions.
220 changes: 220 additions & 0 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ def create_entry_pst(db, table, separator, key, pairs):
create_entry(tbl, key, pairs)


def delete_entry_tbl(db, table, key):
tbl = swsscommon.Table(db, table)
tbl._del(key)
time.sleep(1)


def delete_entry_pst(db, table, key):
tbl = swsscommon.ProducerStateTable(db, table)
tbl._del(key)
time.sleep(1)


def how_many_entries_exist(db, table):
tbl = swsscommon.Table(db, table)
return len(tbl.getKeys())
Expand Down Expand Up @@ -56,6 +68,15 @@ def get_created_entries(db, table, existed_entries, count):
return new_entries


def get_deleted_entries(db, table, existed_entries, count):
tbl = swsscommon.Table(db, table)
entries = set(tbl.getKeys())
old_entries = list(existed_entries - entries)
assert len(old_entries) == count, "Wrong number of deleted entries."
old_entries.sort()
return old_entries


def get_default_vr_id(dvs):
db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
table = 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER'
Expand Down Expand Up @@ -83,6 +104,11 @@ def check_object(db, table, key, expected_attributes):
assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \
(value, name, expected_attributes[name])

def check_deleted_object(db, table, key):
tbl = swsscommon.Table(db, table)
keys = tbl.getKeys()
assert key not in keys, "The desired key is not removed"


def create_vnet_local_routes(dvs, prefix, vnet_name, ifname):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
Expand All @@ -98,6 +124,14 @@ def create_vnet_local_routes(dvs, prefix, vnet_name, ifname):
time.sleep(2)


def delete_vnet_local_routes(dvs, prefix, vnet_name):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)

delete_entry_pst(app_db, "VNET_ROUTE_TABLE", "%s:%s" % (vnet_name, prefix))

time.sleep(2)


def create_vnet_routes(dvs, prefix, vnet_name, endpoint, mac="", vni=0):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)

Expand All @@ -120,6 +154,14 @@ def create_vnet_routes(dvs, prefix, vnet_name, endpoint, mac="", vni=0):
time.sleep(2)


def delete_vnet_routes(dvs, prefix, vnet_name):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)

delete_entry_pst(app_db, "VNET_ROUTE_TUNNEL_TABLE", "%s:%s" % (vnet_name, prefix))

time.sleep(2)


def create_vlan(dvs, vlan_name, vlan_ids):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -199,6 +241,14 @@ def create_vlan_interface(dvs, vlan_name, ifname, vnet_name, ipaddr):
return vlan_oid


def delete_vlan_interface(dvs, ifname, ipaddr):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

delete_entry_tbl(conf_db, "VLAN_INTERFACE", "%s|%s" % (ifname, ipaddr))

time.sleep(2)


def create_phy_interface(dvs, ifname, vnet_name, ipaddr):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

Expand Down Expand Up @@ -233,6 +283,14 @@ def create_phy_interface(dvs, ifname, vnet_name, ipaddr):
)


def delete_phy_interface(dvs, ifname, ipaddr):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

delete_entry_tbl(conf_db, "INTERFACE", "%s|%s" % (ifname, ipaddr))

time.sleep(2)


def create_vnet_entry(dvs, name, tunnel, vni, peer_list):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
Expand All @@ -253,6 +311,14 @@ def create_vnet_entry(dvs, name, tunnel, vni, peer_list):
time.sleep(2)


def delete_vnet_entry(dvs, name):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

delete_entry_tbl(conf_db, "VNET", "%s" % (name))

time.sleep(2)


def create_vxlan_tunnel(dvs, name, src_ip):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

Expand Down Expand Up @@ -454,6 +520,10 @@ 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_del_vnet_entry(self, dvs, name):
# TODO: Implement for VRF VNET
return True

def vnet_route_ids(self, dvs, name, local=False):
vr_set = set()

Expand Down Expand Up @@ -496,6 +566,10 @@ def check_router_interface(self, dvs, name, vlan_oid=0):
self.rifs.add(new_rif)
self.routes.update(new_route)

def check_del_router_interface(self, dvs, name):
# TODO: Implement for VRF VNET
return True

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

Expand All @@ -514,6 +588,10 @@ def check_vnet_local_routes(self, dvs, name):

self.routes.update(new_route)

def check_del_vnet_local_routes(self, dvs, name):
# TODO: Implement for VRF VNET
return True

def check_vnet_routes(self, dvs, name, endpoint, tunnel, mac="", vni=0):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

Expand Down Expand Up @@ -558,6 +636,10 @@ def check_vnet_routes(self, dvs, name, endpoint, tunnel, mac="", vni=0):

self.routes.update(new_route)

def check_del_vnet_routes(self, dvs, name):
# TODO: Implement for VRF VNET
return True


'''
Implements "check" APIs for the "bitmap" VNET feature.
Expand Down Expand Up @@ -718,6 +800,14 @@ 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_del_vnet_entry(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

old_bitmap_class_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, old_bitmap_class_id[0])

self.vnet_bitmap_class_ids.remove(old_bitmap_class_id[0])

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

Expand All @@ -744,6 +834,22 @@ def check_router_interface(self, dvs, name, vlan_oid=0):
self.vnet_bitmap_route_ids.update(new_bitmap_route)
self.vnet_bitmap_class_ids.update(new_bitmap_class_id)

def check_del_router_interface(self, dvs, name):
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])

old_bitmap_class_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, old_bitmap_class_id[0])

old_bitmap_route_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route_id[0])

self.rifs.remove(old_rif[0])
self.vnet_bitmap_class_ids.remove(old_bitmap_class_id[0])
self.vnet_bitmap_route_ids.remove(old_bitmap_route_id[0])

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

Expand All @@ -756,6 +862,14 @@ def check_vnet_local_routes(self, dvs, name):

self.vnet_bitmap_route_ids.update(new_bitmap_route)

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

old_bitmap_route = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route[0])

self.vnet_bitmap_route_ids.remove(old_bitmap_route[0])

def check_vnet_routes(self, dvs, name, endpoint, tunnel, mac="", vni=0):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

Expand Down Expand Up @@ -791,6 +905,15 @@ def check_vnet_routes(self, dvs, name, endpoint, tunnel, mac="", vni=0):
self.vnet_bitmap_route_ids.update(new_bitmap_route)


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

old_bitmap_route = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route[0])

self.vnet_bitmap_route_ids.remove(old_bitmap_route[0])


class TestVnetOrch(object):

def get_vnet_obj(self):
Expand Down Expand Up @@ -846,6 +969,38 @@ def test_vnet_orch_1(self, dvs, testlog):
create_vnet_local_routes(dvs, "100.102.1.0/24", 'Vnet_2001', 'Ethernet4')
vnet_obj.check_vnet_local_routes(dvs, 'Vnet_2001')

# Clean-up and verify remove flows

delete_vnet_local_routes(dvs, "100.100.3.0/24", 'Vnet_2000')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_2000')

delete_vnet_local_routes(dvs, "100.100.4.0/24", 'Vnet_2000')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_2000')

delete_vnet_local_routes(dvs, "100.102.1.0/24", 'Vnet_2001')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_2001')

delete_vnet_routes(dvs, "100.100.2.1/32", 'Vnet_2001')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_2001')

delete_vnet_routes(dvs, "100.100.1.1/32", 'Vnet_2000')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_2001')

delete_phy_interface(dvs, "Ethernet4", "100.102.1.1/24")
vnet_obj.check_del_router_interface(dvs, "Ethernet4")

delete_vlan_interface(dvs, "Vlan100", "100.100.3.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan100")

delete_vlan_interface(dvs, "Vlan101", "100.100.4.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan101")

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

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

'''
Test 2 - Two VNets, One HSMs per VNet
'''
Expand Down Expand Up @@ -900,6 +1055,44 @@ def test_vnet_orch_2(self, dvs, testlog):
create_vnet_local_routes(dvs, "2.2.10.0/24", 'Vnet_2', 'Vlan1002')
vnet_obj.check_vnet_local_routes(dvs, 'Vnet_2')

# Clean-up and verify remove flows

delete_vnet_local_routes(dvs, "2.2.10.0/24", 'Vnet_2')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_2')

delete_vnet_local_routes(dvs, "1.1.10.0/24", 'Vnet_1')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_1')

delete_vnet_routes(dvs, "2.2.2.11/32", 'Vnet_2')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_2')

delete_vnet_routes(dvs, "2.2.2.10/32", 'Vnet_2')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_2')

delete_vnet_routes(dvs, "1.1.1.14/32", 'Vnet_1')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_1')

delete_vnet_routes(dvs, "1.1.1.12/32", 'Vnet_1')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_1')

delete_vnet_routes(dvs, "1.1.1.11/32", 'Vnet_1')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_1')

delete_vnet_routes(dvs, "1.1.1.10/32", 'Vnet_1')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_1')

delete_vlan_interface(dvs, "Vlan1002", "2.2.10.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan1002")

delete_vlan_interface(dvs, "Vlan1001", "1.1.10.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan1001")

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

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

'''
Test 3 - Two VNets, One HSMs per VNet, Peering
'''
Expand Down Expand Up @@ -942,3 +1135,30 @@ def test_vnet_orch_3(self, dvs, testlog):

create_vnet_local_routes(dvs, "8.8.10.0/24", 'Vnet_20', 'Vlan2002')
vnet_obj.check_vnet_local_routes(dvs, 'Vnet_20')

# Clean-up and verify remove flows

delete_vnet_local_routes(dvs, "5.5.10.0/24", 'Vnet_10')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_10')

delete_vnet_local_routes(dvs, "8.8.10.0/24", 'Vnet_20')
vnet_obj.check_del_vnet_local_routes(dvs, 'Vnet_20')

delete_vnet_routes(dvs, "5.5.5.10/32", 'Vnet_10')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_10')

delete_vnet_routes(dvs, "8.8.8.10/32", 'Vnet_20')
vnet_obj.check_del_vnet_routes(dvs, 'Vnet_20')

delete_vlan_interface(dvs, "Vlan2001", "5.5.10.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan2001")

delete_vlan_interface(dvs, "Vlan2002", "8.8.10.1/24")
vnet_obj.check_del_router_interface(dvs, "Vlan2002")

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

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

0 comments on commit 8d520a6

Please sign in to comment.