Skip to content

Commit

Permalink
Config default v4&v6 route
Browse files Browse the repository at this point in the history
Signed-off-by: zitingguo <[email protected]>
  • Loading branch information
Gfrom2016 committed Jul 5, 2022
1 parent c905295 commit bedcc33
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 21 deletions.
92 changes: 77 additions & 15 deletions test/sai_test/config/route_configer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@
#


from sai_test.constant import *
from sai_thrift.sai_adapter import *
from sai_utils import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

def t0_route_config_helper(test_obj, is_create_route_for_lag=True):
def t0_route_config_helper(test_obj, is_create_route=True, is_create_route_for_lag=True):
route_configer = RouteConfiger(test_obj)
vr_id = route_configer.create_vr_id()
# default_virtual_router_id = route_configer.get_default_virtual_router_id()

if is_create_route:
route_configer.create_default_route()

if is_create_route_for_lag:
ip_addr1 = '10.10.10.0'
mac_addr1 = '02:04:02:01:01:01'
route_configer.create_route_and_neighbor_entry_for_port(ip_addr=ip_addr1, mac_addr=mac_addr1, port_id=test_obj.lag1.lag_id, virtual_router_id=vr_id)
route_configer.create_route_and_neighbor_entry_for_port(ip_addr=ip_addr1,
mac_addr=mac_addr1,
port_id=test_obj.lag1.lag_id,
virtual_router_id=test_obj.default_vrf)

ip_addr2 = '10.1.2.100'
mac_addr2 = '02:04:02:01:02:01'
route_configer.create_route_and_neighbor_entry_for_port(ip_addr=ip_addr1, mac_addr=mac_addr2, port_id=test_obj.lag2.lag_id, virtual_router_id=vr_id)
route_configer.create_route_and_neighbor_entry_for_port(ip_addr=ip_addr1,
mac_addr=mac_addr2,
port_id=test_obj.lag2.lag_id,
virtual_router_id=test_obj.default_vrf)

test_obj.default_virtual_router_id = vr_id

class RouteConfiger(object):
"""
Expand All @@ -52,20 +59,75 @@ def __init__(self, test_obj) -> None:
"""
self.test_obj = test_obj
self.client = test_obj.client

def create_default_route(self):
self.create_default_route_intf()
self.create_default_v4_v6_route_entry()
self.create_local_v6_route()

def create_vr_id(self):
return sai_thrift_create_virtual_router(self.client)
def create_default_route_intf(self):
"""
Create default route interface on loop back interface.
"""
print("Create loop back interface...")
attr = sai_thrift_get_switch_attribute(self.client, default_virtual_router_id=True)
self.test_obj.assertNotEqual(attr['default_virtual_router_id'], 0)
self.test_obj.default_vrf = attr['default_virtual_router_id']

def get_default_virtual_router_id(self):
print("Get default router id")
def_attr = sai_thrift_get_switch_attribute(self.client, default_virtual_router_id=True)

self.test_obj.assertNotEqual(def_attr["SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID"], 0)
return def_attr["SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID"]
self.test_obj.loopback_intf = sai_thrift_create_router_interface(self.client,
type=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK, virtual_router_id=self.test_obj.default_vrf)
self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS)

def create_default_v4_v6_route_entry(self):
"""
Create default v4 and v6 route entry.
"""

print("Create default v4&v6 route entry...")
v6_default = sai_thrift_ip_prefix_t(addr_family=1,
addr=sai_thrift_ip_addr_t(ip6=DEFAULT_IP_V6_PREFIX),
mask=sai_thrift_ip_addr_t(ip6=DEFAULT_IP_V6_PREFIX))
entry = sai_thrift_route_entry_t(vr_id=self.test_obj.default_vrf,
destination=v6_default)
self.test_obj.default_ipv6_route_entry = sai_thrift_create_route_entry(
self.client,
route_entry=entry,
packet_action=SAI_PACKET_ACTION_DROP)
self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS)

entry = sai_thrift_route_entry_t(vr_id=self.test_obj.default_vrf,
destination=sai_ipprefix(DEFAULT_IP_V4_PREFIX))
self.test_obj.default_ipv4_route_entry = sai_thrift_create_route_entry(
self.client,
route_entry=entry,
packet_action=SAI_PACKET_ACTION_DROP)
self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS)

def create_local_v6_route(self):
"""
Create local v6 route base on the configuration of the actual switch.
"""

print("Create local v6 route...")
entry = sai_thrift_route_entry_t(vr_id=self.test_obj.default_vrf,
destination=sai_ipprefix(LOCAL_IP_10V6_PREFIX))
self.test_obj.local_10v6_route_entry = sai_thrift_create_route_entry(
self.client,
route_entry=entry,
packet_action=SAI_PACKET_ACTION_FORWARD)
self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS)

entry = sai_thrift_route_entry_t(vr_id=self.test_obj.default_vrf,
destination=sai_ipprefix(LOCAL_IP_128V6_PREFIX))
self.test_obj.local_128v6_route_entry = sai_thrift_create_route_entry(
self.client,
route_entry=entry,
packet_action=SAI_PACKET_ACTION_FORWARD)
self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS)

def create_route_and_neighbor_entry_for_port(self, ip_addr, mac_addr, port_id, virtual_router_id=None):
if virtual_router_id is None:
virtual_router_id = self.get_default_virtual_router_id()
virtual_router_id = self.test_obj.default_vrf

rif_id1 = sai_thrift_create_router_interface(self.client, virtual_router_id=virtual_router_id, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=port_id)

Expand Down
8 changes: 4 additions & 4 deletions test/sai_test/sai_lag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
T0TestBase.setUp(self)

def load_balance_on_src_ip(self):
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_virtual_router_id, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_vrf, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
router_mac = '00:77:66:55:44:00'
ip_src1 = '192.168.0.1'
ip_src2 = '192.168.0.2'
Expand Down Expand Up @@ -84,7 +84,7 @@ def setUp(self):
def runTest(self):
try:
print("Lag l3 load balancing test based on src port")
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_virtual_router_id, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_vrf, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
eth_src = '00:22:22:22:22:22'
eth_dst = '00:77:66:55:44:00'
ip_src = '192.168.0.1'
Expand Down Expand Up @@ -131,7 +131,7 @@ def setUp(self):
def runTest(self):
try:
print("Lag disable egress lag member test")
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_virtual_router_id, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_vrf, type=SAI_ROUTER_INTERFACE_TYPE_PORT, port_id=self.port_list[21])
eth_src = '00:22:22:22:22:22'
eth_dst = '00:77:66:55:44:00'
ip_src = '192.168.0.1'
Expand Down Expand Up @@ -202,7 +202,7 @@ def setUp(self):

def runTest(self):
try:
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_virtual_router_id, type=SAI_ROUTER_INTERFACE_TYPE_VLAN, vlan_id=10)
sai_thrift_create_router_interface(self.client, virtual_router_id=self.default_vrf, type=SAI_ROUTER_INTERFACE_TYPE_VLAN, vlan_id=10)
eth_src = '00:22:22:22:22:22'
eth_dst = '00:77:66:55:44:00'
ip_src = '192.168.0.1'
Expand Down
10 changes: 8 additions & 2 deletions test/sai_test/sai_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,17 @@ class T0TestBase(ThriftInterfaceDataPlane):
Set the following class attributes:
self.default_vlan_id
self.default_vrf
self.lookback_intf
self.default_ipv4_route_entry
self.default_ipv6_route_entry
self.local_10v6_route_entry
self.local_128v6_route_entry
self.default_1q_bridge
self.cpu_port_hdl
self.active_ports_no - number of active ports
self.port_list - list of all active port objects
self.portX objects for all active ports (where X is a port number)
self.lagX objects for all lag
self.default_virtual_router_id
"""

def setUp(self,
Expand All @@ -196,6 +200,7 @@ def setUp(self,
is_reset_default_vlan=True,
is_create_vlan=True,
is_create_fdb=True,
is_create_route=True,
is_create_lag=True,
is_create_route_for_lag=True,
wait_sec=5):
Expand All @@ -204,8 +209,8 @@ def setUp(self,
self.switch_configer = SwitchConfiger(self)
self.fdb_configer = FdbConfiger(self)
self.vlan_configer = VlanConfiger(self)
self.lag_configer = LagConfiger(self)
self.route_configer = RouteConfiger(self)
self.lag_configer = LagConfiger(self)

if force_config or not is_configured:
t0_switch_config_helper(self)
Expand All @@ -225,6 +230,7 @@ def setUp(self,
is_create_lag=is_create_lag)
t0_route_config_helper(
test_obj=self,
is_create_route=is_create_route,
is_create_route_for_lag=is_create_route_for_lag)

print("Waiting for switch to get ready before test, {} seconds ...".format(
Expand Down

0 comments on commit bedcc33

Please sign in to comment.