def add_static_routes(sw1, sw2, step): # Interfaces to configure sw1_interfaces = [] # IPs to configure sw1_ifs_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4", "5.5.5.5"] # IPv6 addresses to configure sw1_ifs_ipv6s = [ "111:111::1", "222:222::2", "333:333::3", "444:444::4", "555:555::5" ] size = len(sw1_ifs_ips) # Adding interfaces, 4th and 5th IP are configured on the last interface, # so the last one is repeated on the array for i in range(size): if i is not size - 1: sw1_interfaces.append(sw1.ports["if0{}".format(i + 1)]) else: sw1_interfaces.append(sw1.ports["if0{}".format(i)]) sw1_mask = 24 sw1_ipv6_mask = 64 step("Configuring interfaces and IPs on SW1") sw1("configure terminal") for i in range(size): sw1("interface {}".format(sw1_interfaces[i])) if i is not size - 1: sw1("ip address {}/{}".format(sw1_ifs_ips[i], sw1_mask)) sw1("ipv6 address {}/{}".format(sw1_ifs_ipv6s[i], sw1_ipv6_mask)) else: sw1("ip address {}/{} secondary".format(sw1_ifs_ips[i], sw1_mask)) sw1("ipv6 address {}/{} secondary".format(sw1_ifs_ipv6s[i], sw1_ipv6_mask)) sw1("no shutdown") sw1("exit") output = sw1("do show running-config") assert "interface {}".format(sw1_interfaces[i]) in output assert "ip address {}/{}".format(sw1_ifs_ips[i], sw1_mask) in output assert "ipv6 address {}/{}".format(sw1_ifs_ipv6s[i], sw1_ipv6_mask) in output step("Cofiguring sw1 IPV4 static routes") # Routes to configure nexthops = ["1.1.1.2", "2", "3", "5.5.5.1"] for i in range(size - 1): sw1("ip route 123.0.0.1/32 {}".format(nexthops[i])) output = sw1("do show running-config") assert "ip route 123.0.0.1/32 {}".format(nexthops[i]) in output # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '4' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '1' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '1' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '1' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' rib_ipv4_static_route1['5.5.5.1'] = dict() rib_ipv4_static_route1['5.5.5.1']['Distance'] = '1' rib_ipv4_static_route1['5.5.5.1']['Metric'] = '0' rib_ipv4_static_route1['5.5.5.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. route_ipv4_static_route1 = rib_ipv4_static_route1 # Configure IPv4 route 143.0.0.1/32 with 1 next-hop. sw1("ip route 143.0.0.1/32 4.4.4.1") output = sw1("do show running-config") assert "ip route 143.0.0.1/32 4.4.4.1" in output # Populate the expected RIB ("show rib") route dictionary for the # route 143.0.0.1/32 and its next-hops. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' rib_ipv4_static_route2['NumberNexthops'] = '1' rib_ipv4_static_route2['4.4.4.1'] = dict() rib_ipv4_static_route2['4.4.4.1']['Distance'] = '1' rib_ipv4_static_route2['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route2['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 143.0.0.1/32 and its next-hops. route_ipv4_static_route2 = rib_ipv4_static_route2 # Configure IPv4 route 163.0.0.1/32 with 1 next-hop. sw1("ip route 163.0.0.1/32 2") output = sw1("do show running-config") assert "ip route 163.0.0.1/32 2" in output # Populate the expected RIB ("show rib") route dictionary for the # route 163.0.0.1/32 and its next-hops. rib_ipv4_static_route3 = dict() rib_ipv4_static_route3['Route'] = '163.0.0.1/32' rib_ipv4_static_route3['NumberNexthops'] = '1' rib_ipv4_static_route3['2'] = dict() rib_ipv4_static_route3['2']['Distance'] = '1' rib_ipv4_static_route3['2']['Metric'] = '0' rib_ipv4_static_route3['2']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 163.0.0.1/32 and its next-hops. route_ipv4_static_route3 = rib_ipv4_static_route3 for i in range(4): sw1("ipv6 route 1234:1234::1/128 {}".format(i + 1)) output = sw1("do show running-config") assert "ipv6 route 1234:1234::1/128 {}".format(i + 1) in output # Populate the expected RIB ("show rib") route dictionary for the # route 1234:1234::1/128 and its next-hops. rib_ipv6_static_route1 = dict() rib_ipv6_static_route1['Route'] = '1234:1234::1/128' rib_ipv6_static_route1['NumberNexthops'] = '4' rib_ipv6_static_route1['1'] = dict() rib_ipv6_static_route1['1']['Distance'] = '1' rib_ipv6_static_route1['1']['Metric'] = '0' rib_ipv6_static_route1['1']['RouteType'] = 'static' rib_ipv6_static_route1['2'] = dict() rib_ipv6_static_route1['2']['Distance'] = '1' rib_ipv6_static_route1['2']['Metric'] = '0' rib_ipv6_static_route1['2']['RouteType'] = 'static' rib_ipv6_static_route1['3'] = dict() rib_ipv6_static_route1['3']['Distance'] = '1' rib_ipv6_static_route1['3']['Metric'] = '0' rib_ipv6_static_route1['3']['RouteType'] = 'static' rib_ipv6_static_route1['4'] = dict() rib_ipv6_static_route1['4']['Distance'] = '1' rib_ipv6_static_route1['4']['Metric'] = '0' rib_ipv6_static_route1['4']['RouteType'] = 'static' # Populate the expected FIB ("show ipv6 route") route dictionary for the # route 1234:1234::1/128 and its next-hops. route_ipv6_static_route1 = rib_ipv6_static_route1 sw1("ipv6 route 2234:2234::1/128 4") output = sw1("do show running-config") assert "ipv6 route 2234:2234::1/128 4" in output # Populate the expected RIB ("show rib") route dictionary for the # route 2234:2234::1/128 and its next-hops. rib_ipv6_static_route2 = dict() rib_ipv6_static_route2['Route'] = '2234:2234::1/128' rib_ipv6_static_route2['NumberNexthops'] = '1' rib_ipv6_static_route2['4'] = dict() rib_ipv6_static_route2['4']['Distance'] = '1' rib_ipv6_static_route2['4']['Metric'] = '0' rib_ipv6_static_route2['4']['RouteType'] = 'static' # Populate the expected FIB ("show ipv6 route") route dictionary for the # route 2234:2234::1/128 and its next-hops. route_ipv6_static_route2 = rib_ipv6_static_route2 sw1("ipv6 route 3234:3234::1/128 2") output = sw1("do show running-config") assert "ipv6 route 3234:3234::1/128 2" in output # Populate the expected RIB ("show rib") route dictionary for the # route 3234:3234::1/128 and its next-hops. rib_ipv6_static_route3 = dict() rib_ipv6_static_route3['Route'] = '3234:3234::1/128' rib_ipv6_static_route3['NumberNexthops'] = '1' rib_ipv6_static_route3['2'] = dict() rib_ipv6_static_route3['2']['Distance'] = '1' rib_ipv6_static_route3['2']['Metric'] = '0' rib_ipv6_static_route3['2']['RouteType'] = 'static' # Populate the expected FIB ("show ipv6 route") route dictionary for the # route 3234:3234::1/128 and its next-hops. route_ipv6_static_route3 = rib_ipv6_static_route3 sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static routes on switch 1") # Verify route 123.0.0.1/32 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv4_static_route1["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='1.1.1.2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='3') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='5.5.5.1') # Verify route 143.0.0.1/32 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='143.0.0.1/32', nexthop='4.4.4.1') # Verify route 163.0.0.1/32 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv4_static_route3["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route3) aux_route = rib_ipv4_static_route3["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route3) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='163.0.0.1/32', nexthop='2') step("Verifying the IPv6 static routes on switch 1") # Verify route 1234:1234::1/128 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv6_static_route1["Route"] verify_show_ipv6_route(sw1, aux_route, 'static', route_ipv6_static_route1) aux_route = rib_ipv6_static_route1["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv6_static_route1) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='1') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='3') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='4') # Verify route 2234:2234::1/128 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv6_static_route2["Route"] verify_show_ipv6_route(sw1, aux_route, 'static', route_ipv6_static_route2) aux_route = rib_ipv6_static_route2["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv6_static_route2) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='2234:2234::1/128', nexthop='4') # Verify route 3234:3234::1/128 and next-hops in RIB, FIB and verify the # presence of all next-hops in running-config aux_route = route_ipv6_static_route3["Route"] verify_show_ipv6_route(sw1, aux_route, 'static', route_ipv6_static_route3) aux_route = rib_ipv6_static_route3["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv6_static_route3) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='3234:3234::1/128', nexthop='2')
def delete_static_routes(sw1, sw2, step): # Unconfiguring next-hop 5.5.5.1 for route 123.0.0.1/32 step("Unconfiguring next-hop 5.5.5.1 for route 123.0.0.1/32") sw1("no ip route 123.0.0.1/32 5.5.5.1") # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its remaining next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '3' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '1' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '1' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '1' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its remaining next-hops. route_ipv4_static_route1 = rib_ipv4_static_route1 # Unconfiguring next-hop 4.4.4.1 for route 143.0.0.1/32 step("Unconfiguring next-hop 4.4.4.1 for route 143.0.0.1/32") sw1("no ip route 143.0.0.1/32 4.4.4.1") # Populate the expected RIB ("show rib") route dictionary for the route # 143.0.0.1/32 and its remaining next-hops. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' # Populate the expected FIB ("show ip route") route dictionary for the # route 143.0.0.1/32 and its remaining next-hops. route_ipv4_static_route2 = rib_ipv4_static_route2 # Unconfiguring next-hop 2 for route 163.0.0.1/32 step("Unconfiguring next-hop 2 for route 163.0.0.1/32") sw1("no ip route 163.0.0.1/32 2") # Populate the expected RIB ("show rib") route dictionary for the route # 163.0.0.1/32 and its remaining next-hops. rib_ipv4_static_route3 = dict() rib_ipv4_static_route3['Route'] = '163.0.0.1/32' # Populate the expected FIB ("show ip route") route dictionary for the # route 163.0.0.1/32 and its remaining next-hops. route_ipv4_static_route3 = rib_ipv4_static_route3 # Unconfiguring next-hop 1 for route 1234:1234::1/128 step("Unconfiguring next-hop 1 for route 1234:1234::1/128") sw1("no ipv6 route 1234:1234::1/128 1") # Populate the expected RIB ("show rib") route dictionary for the route # 1234:1234::1/128 and its remaining next-hops. rib_ipv6_static_route1 = dict() rib_ipv6_static_route1['Route'] = '1234:1234::1/128' rib_ipv6_static_route1['NumberNexthops'] = '3' rib_ipv6_static_route1['4'] = dict() rib_ipv6_static_route1['4']['Distance'] = '1' rib_ipv6_static_route1['4']['Metric'] = '0' rib_ipv6_static_route1['4']['RouteType'] = 'static' rib_ipv6_static_route1['2'] = dict() rib_ipv6_static_route1['2']['Distance'] = '1' rib_ipv6_static_route1['2']['Metric'] = '0' rib_ipv6_static_route1['2']['RouteType'] = 'static' rib_ipv6_static_route1['3'] = dict() rib_ipv6_static_route1['3']['Distance'] = '1' rib_ipv6_static_route1['3']['Metric'] = '0' rib_ipv6_static_route1['3']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 1234:1234::1/128 and its remaining next-hops. route_ipv6_static_route1 = rib_ipv6_static_route1 # Unconfiguring next-hop 4 for route 2234:2234::1/128 step("Unconfiguring next-hop 4 for route 2234:2234::1/128") sw1("no ipv6 route 2234:2234::1/128 4") # Populate the expected RIB ("show rib") route dictionary for the route # 2234:2234::1/128 and its remaining next-hops. rib_ipv6_static_route2 = dict() rib_ipv6_static_route2['Route'] = '2234:2234::1/128' # Populate the expected FIB ("show ip route") route dictionary for the # route 2234:2234::1/128 and its remaining next-hops. route_ipv6_static_route2 = rib_ipv6_static_route2 sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static routes on switch 1") # Verify route 123.0.0.1/32 and next-hops in RIB, FIB and verify the # presence of active next-hops in running-config and absence of deleted # next-hops in running-config aux_route = route_ipv4_static_route1["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='1.1.1.2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='3') assert not route_and_nexthop_in_show_running_config( sw1=sw1, if_ipv4=True, route='123.0.0.1/32', nexthop='5.5.5.1') # Verify route 143.0.0.1/32 and next-hops in RIB, FIB and verify the # presence of active next-hops in running-config and absence of deleted # next-hops in running-config aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) assert not route_and_nexthop_in_show_running_config( sw1=sw1, if_ipv4=True, route='143.0.0.1/32', nexthop='4.4.4.1') # Verify route 163.0.0.1/32 and next-hops in RIB, FIB and verify # the presence of active next-hops in running-config and absence of # deleted next-hops in running-config aux_route = route_ipv4_static_route3["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route3) aux_route = rib_ipv4_static_route3["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route3) assert not route_and_nexthop_in_show_running_config( sw1=sw1, if_ipv4=True, route='163.0.0.1/32', nexthop='2') step("Verifying the IPv6 static routes on switch 1") # Verify route 1234:1234::1/128 and next-hops in RIB, FIB and verify the # presence of active next-hops in running-config and absence of deleted # next-hops in running-config aux_route = route_ipv6_static_route1["Route"] verify_show_ipv6_route(sw1, aux_route, 'static', route_ipv6_static_route1) aux_route = rib_ipv6_static_route1["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv6_static_route1) aux_route = '1234:1234::1/128' assert not route_and_nexthop_in_show_running_config( sw1=sw1, if_ipv4=False, route=aux_route, nexthop='1') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='2') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='3') assert route_and_nexthop_in_show_running_config(sw1=sw1, if_ipv4=False, route='1234:1234::1/128', nexthop='4') # Verify route 2234:2234::1/128 and next-hops in RIB, FIB and verify the # presence of active next-hops in running-config and absence of deleted # next-hops in running-config aux_route = route_ipv6_static_route2["Route"] verify_show_ipv6_route(sw1, aux_route, 'static', route_ipv6_static_route2) aux_route = rib_ipv6_static_route2["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv6_static_route2) aux_route = '2234:2234::1/128' assert not route_and_nexthop_in_show_running_config( sw1=sw1, if_ipv4=False, route=aux_route, nexthop='4')
def delete_static_bgp_routes(sw1, sw2, step): step("Testing the BGP and static route deletion on sw1") step("Deleting 123.0.0.0.1/32 BGP route on sw1") # Command to delete the BGP route 123.0.0.1/32. This should make the static # route more preferable in RIB. bgp_route_delete_command = "ovsdb-client transact \'[ \"OpenSwitch\",\ {\ \"op\" : \"delete\",\ \"table\" : \"Route\",\ \"where\":[[\"prefix\",\"==\",\"123.0.0.1/32\"],[\"from\",\"==\",\"bgp\"]]\ }\ ]\'" # Delete the BGP route for prefix 123.0.0.1/32 using ovsdb-client interface sw1(bgp_route_delete_command, shell='bash') # Delete the static route for 143.0.0.1/32 so that BGP route becomes the # more preferable route in RIB. step("Deleting 143.0.0.0.1/32 static route on sw1") sw1("no ip route 143.0.0.1/32 4.4.4.1") # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '4' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '10' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '10' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '10' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' rib_ipv4_static_route1['4.4.4.1'] = dict() rib_ipv4_static_route1['4.4.4.1']['Distance'] = '10' rib_ipv4_static_route1['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route1['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. route_ipv4_static_route1 = rib_ipv4_static_route1 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 123.0.0.1/32 and its next-hops. This should not be in RIB as it has been # deleted. rib_ipv4_bgp_route1 = dict() rib_ipv4_bgp_route1['Route'] = '123.0.0.1/32' # Populate the expected FIB ("show ip route") route dictionary for the BGP # route 123.0.0.1/32 and its next-hops. This should not be in FIB as it has # been deleted. route_ipv4_bgp_route1 = rib_ipv4_bgp_route1 # Populate the expected RIB ("show rib") route dictionary for the static # route 143.0.0.1/32 and its next-hops. This should not be in RIB as it has # been deleted. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' # Populate the expected RIB ("show rib") route dictionary for the static # route 143.0.0.1/32 and its next-hops. This should not be in FIB as it # has been deleted. route_ipv4_static_route2 = rib_ipv4_static_route2 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 123.0.0.1/32 and its next-hops. rib_ipv4_bgp_route2 = dict() rib_ipv4_bgp_route2['Route'] = '143.0.0.1/32' rib_ipv4_bgp_route2['NumberNexthops'] = '1' rib_ipv4_bgp_route2['1.1.1.5'] = dict() rib_ipv4_bgp_route2['1.1.1.5']['Distance'] = '6' rib_ipv4_bgp_route2['1.1.1.5']['Metric'] = '0' rib_ipv4_bgp_route2['1.1.1.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the BGP # route 123.0.0.1/32 and its next-hops. route_ipv4_bgp_route2 = rib_ipv4_bgp_route2 sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static and BGP " "routes on switch 1 after route deletes") # Verify the static/BGP routes in RIB and FIB aux_route = route_ipv4_static_route1["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) aux_route = route_ipv4_bgp_route1["Route"] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route1) aux_route = rib_ipv4_bgp_route1["Route"] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route1) aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2["Route"] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) aux_route = route_ipv4_bgp_route2["Route"] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route2) aux_route = rib_ipv4_bgp_route2["Route"] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route2)
def remove_nexthop_to_make_bgp_route_single(sw1, sw2, step): step("Removing a next-hop for IPv4 BGP route 123.0.0.1/32 on \ switch 1") nexthop_uuid = get_uuid_from_nexthop_table(sw1, "3.3.3.5", step) # Prepare string to remove a BGP next-hop for route 123.0.0.1/32 # using ovsdb-client. bpg_route_cmd_ipv4_route1 = """ovsdb-client transact '[ "OpenSwitch", { "op" : "update", "table" : "Route", "where":[["prefix","==","123.0.0.1/32"],["from","==","bgp"]], "row" : { "nexthops" : [ "set", [["uuid", "%s"] ]] } } ]'""" % nexthop_uuid # Configure the BGP next-hop for prefix 123.0.0.1/32 using ovsdb-client # interface sw1(bpg_route_cmd_ipv4_route1, shell='bash') # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '4' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '10' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '10' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '10' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' rib_ipv4_static_route1['4.4.4.1'] = dict() rib_ipv4_static_route1['4.4.4.1']['Distance'] = '10' rib_ipv4_static_route1['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route1['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. route_ipv4_static_route1 = dict() route_ipv4_static_route1['Route'] = '123.0.0.1/32' # Configure IPv4 route 143.0.0.1/32 with 1 next-hop. # Populate the expected RIB ("show rib") route dictionary for the # route 143.0.0.1/32 and its next-hops. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' rib_ipv4_static_route2['NumberNexthops'] = '1' rib_ipv4_static_route2['4.4.4.1'] = dict() rib_ipv4_static_route2['4.4.4.1']['Distance'] = '1' rib_ipv4_static_route2['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route2['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 143.0.0.1/32 and its next-hops. route_ipv4_static_route2 = rib_ipv4_static_route2 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 123.0.0.1/32 and its next-hops. rib_ipv4_bgp_route1 = dict() rib_ipv4_bgp_route1['Route'] = '123.0.0.1/32' rib_ipv4_bgp_route1['NumberNexthops'] = '1' rib_ipv4_bgp_route1['3.3.3.5'] = dict() rib_ipv4_bgp_route1['3.3.3.5']['Distance'] = '6' rib_ipv4_bgp_route1['3.3.3.5']['Metric'] = '0' rib_ipv4_bgp_route1['3.3.3.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the BGP # route 143.0.0.1/32 and its next-hops. route_ipv4_bgp_route1 = rib_ipv4_bgp_route1 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 143.0.0.1/32 and its next-hops. rib_ipv4_bgp_route2 = dict() rib_ipv4_bgp_route2['Route'] = '143.0.0.1/32' rib_ipv4_bgp_route2['NumberNexthops'] = '1' rib_ipv4_bgp_route2['1.1.1.5'] = dict() rib_ipv4_bgp_route2['1.1.1.5']['Distance'] = '6' rib_ipv4_bgp_route2['1.1.1.5']['Metric'] = '0' rib_ipv4_bgp_route2['1.1.1.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. route_ipv4_bgp_route2 = dict() route_ipv4_bgp_route2['Route'] = '143.0.0.1/32' sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static and BGP routes on switch 1") aux_route = route_ipv4_static_route1['Route'] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) aux_route = route_ipv4_bgp_route1['Route'] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route1) aux_route = rib_ipv4_bgp_route1['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route1) aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) aux_route = route_ipv4_bgp_route2["Route"] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route2) aux_route = rib_ipv4_bgp_route2['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route2)
def no_shutdown_static_bgp_routes_next_hop_interfaces(sw1, sw2, step): step("Testing the BGP and static route selection on no-shutting nexthop \ interfaces on sw1") # sHutdown next-hop interface 3 step("Shut down interface 3") sw1("configure terminal") sw1("interface 3") sw1("no shutdown") # Shutdown next-hop interface 4 step("Shut down interface 4") sw1("configure terminal") sw1("interface 4") sw1("no shutdown") # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '4' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '10' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '10' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '10' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' rib_ipv4_static_route1['4.4.4.1'] = dict() rib_ipv4_static_route1['4.4.4.1']['Distance'] = '10' rib_ipv4_static_route1['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route1['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. route_ipv4_static_route1 = dict() route_ipv4_static_route1['Route'] = '123.0.0.1/32' # Configure IPv4 route 143.0.0.1/32 with 1 next-hop. # Populate the expected RIB ("show rib") route dictionary for the # route 143.0.0.1/32 and its next-hops. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' rib_ipv4_static_route2['NumberNexthops'] = '1' rib_ipv4_static_route2['4.4.4.1'] = dict() rib_ipv4_static_route2['4.4.4.1']['Distance'] = '1' rib_ipv4_static_route2['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route2['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 143.0.0.1/32 and its next-hops. route_ipv4_static_route2 = rib_ipv4_static_route2 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 123.0.0.1/32 and its next-hops. rib_ipv4_bgp_route1 = dict() rib_ipv4_bgp_route1['Route'] = '123.0.0.1/32' rib_ipv4_bgp_route1['NumberNexthops'] = '1' rib_ipv4_bgp_route1['3.3.3.5'] = dict() rib_ipv4_bgp_route1['3.3.3.5']['Distance'] = '6' rib_ipv4_bgp_route1['3.3.3.5']['Metric'] = '0' rib_ipv4_bgp_route1['3.3.3.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the BGP # route 143.0.0.1/32 and its next-hops. route_ipv4_bgp_route1 = rib_ipv4_bgp_route1 # Populate the expected RIB ("show rib") route dictionary for the BGP route # 143.0.0.1/32 and its next-hops. rib_ipv4_bgp_route2 = dict() rib_ipv4_bgp_route2['Route'] = '143.0.0.1/32' rib_ipv4_bgp_route2['NumberNexthops'] = '1' rib_ipv4_bgp_route2['1.1.1.5'] = dict() rib_ipv4_bgp_route2['1.1.1.5']['Distance'] = '6' rib_ipv4_bgp_route2['1.1.1.5']['Metric'] = '0' rib_ipv4_bgp_route2['1.1.1.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. Since static is configured with a # lower administration distance than BGP route, so the BGP route cannot be # in FIB. route_ipv4_bgp_route2 = dict() route_ipv4_bgp_route2['Route'] = '143.0.0.1/32' sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static and BGP routes on switch 1") aux_route = route_ipv4_static_route1['Route'] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) aux_route = route_ipv4_bgp_route1['Route'] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route1) aux_route = rib_ipv4_bgp_route1['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route1) aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) aux_route = route_ipv4_bgp_route2["Route"] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route2) aux_route = rib_ipv4_bgp_route2['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route2)
def add_static_bgp_routes(sw1, sw2, step): # Interfaces to configure sw1_interfaces = [] # IPs to configure sw1_ifs_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4"] size = len(sw1_ifs_ips) # Adding interfaces to configure for i in range(size): sw1_interfaces.append(sw1.ports["if0{}".format(i + 1)]) sw1_mask = 24 step("Configuring interfaces and IPs on SW1") sw1("configure terminal") for i in range(size): sw1("interface {}".format(sw1_interfaces[i])) sw1("ip address {}/{}".format(sw1_ifs_ips[i], sw1_mask)) sw1("no shutdown") sw1("exit") output = sw1("do show running-config") assert "interface {}".format(sw1_interfaces[i]) in output assert "ip address {}/{}".format(sw1_ifs_ips[i], sw1_mask) in output step("Cofiguring sw1 IPV4 static routes") # Routes to configure nexthops = ["1.1.1.2", "2", "3", "4.4.4.1"] for i in range(size): sw1("ip route 123.0.0.1/32 {} 10".format(nexthops[i])) output = sw1("do show running-config") assert "ip route 123.0.0.1/32 {} 10".format(nexthops[i]) in output # Populate the expected RIB ("show rib") route dictionary for the route # 123.0.0.1/32 and its next-hops. rib_ipv4_static_route1 = dict() rib_ipv4_static_route1['Route'] = '123.0.0.1/32' rib_ipv4_static_route1['NumberNexthops'] = '4' rib_ipv4_static_route1['1.1.1.2'] = dict() rib_ipv4_static_route1['1.1.1.2']['Distance'] = '10' rib_ipv4_static_route1['1.1.1.2']['Metric'] = '0' rib_ipv4_static_route1['1.1.1.2']['RouteType'] = 'static' rib_ipv4_static_route1['2'] = dict() rib_ipv4_static_route1['2']['Distance'] = '10' rib_ipv4_static_route1['2']['Metric'] = '0' rib_ipv4_static_route1['2']['RouteType'] = 'static' rib_ipv4_static_route1['3'] = dict() rib_ipv4_static_route1['3']['Distance'] = '10' rib_ipv4_static_route1['3']['Metric'] = '0' rib_ipv4_static_route1['3']['RouteType'] = 'static' rib_ipv4_static_route1['4.4.4.1'] = dict() rib_ipv4_static_route1['4.4.4.1']['Distance'] = '10' rib_ipv4_static_route1['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route1['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. Since static is configured with a # higher administration distance than BGP route, so the static route # cannot be in FIB. route_ipv4_static_route1 = dict() route_ipv4_static_route1['Route'] = '123.0.0.1/32' sw1("ip route 143.0.0.1/32 4.4.4.1") output = sw1("do show running-config") assert "ip route 143.0.0.1/32 4.4.4.1" in output # Configure IPv4 route 143.0.0.1/32 with 1 next-hop. # Populate the expected RIB ("show rib") route dictionary for the # route 143.0.0.1/32 and its next-hops. rib_ipv4_static_route2 = dict() rib_ipv4_static_route2['Route'] = '143.0.0.1/32' rib_ipv4_static_route2['NumberNexthops'] = '1' rib_ipv4_static_route2['4.4.4.1'] = dict() rib_ipv4_static_route2['4.4.4.1']['Distance'] = '1' rib_ipv4_static_route2['4.4.4.1']['Metric'] = '0' rib_ipv4_static_route2['4.4.4.1']['RouteType'] = 'static' # Populate the expected FIB ("show ip route") route dictionary for the # route 143.0.0.1/32 and its next-hops. route_ipv4_static_route2 = rib_ipv4_static_route2 step("Configuring switch 1 IPv4 BGP routes") # Get the UUID od the default vrf on the sw1 vrf_uuid = get_vrf_uuid(sw1, "vrf_default", step) # Prepare string for a BGP route 123.0.0.1/32 using ovsdb-client with # lower administration distance as compared with the corresponding # static route.This makes the BGP route more preferable than the static # route. bpg_route_cmd_ipv4_route1 = "ovsdb-client transact \'[ \"OpenSwitch\",\ {\ \"op\" : \"insert\",\ \"table\" : \"Nexthop\",\ \"row\" : {\ \"ip_address\" : \"3.3.3.5\",\ \"weight\" : 3,\ \"selected\": true\ },\ \"uuid-name\" : \"nh01\"\ },\ {\ \"op\" : \"insert\",\ \"table\" : \"Route\",\ \"row\" : {\ \"prefix\":\"123.0.0.1/32\",\ \"from\":\"bgp\",\ \"vrf\":[\"uuid\",\"%s\"],\ \"address_family\":\"ipv4\",\ \"sub_address_family\":\"unicast\",\ \"distance\":6,\ \"nexthops\" : [\ \"set\",\ [\ [\ \"named-uuid\",\ \"nh01\"\ ]\ ]]\ }\ }\ ]\'" % vrf_uuid # Configure the BGP route for prefix 123.0.0.1/32 using ovsdb-client # interface sw1(bpg_route_cmd_ipv4_route1, shell='bash') # Populate the expected RIB ("show rib") route dictionary for the BGP route # 123.0.0.1/32 and its next-hops. rib_ipv4_bgp_route1 = dict() rib_ipv4_bgp_route1['Route'] = '123.0.0.1/32' rib_ipv4_bgp_route1['NumberNexthops'] = '1' rib_ipv4_bgp_route1['3.3.3.5'] = dict() rib_ipv4_bgp_route1['3.3.3.5']['Distance'] = '6' rib_ipv4_bgp_route1['3.3.3.5']['Metric'] = '0' rib_ipv4_bgp_route1['3.3.3.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the BGP # route 143.0.0.1/32 and its next-hops. route_ipv4_bgp_route1 = rib_ipv4_bgp_route1 # Prepare string for a BGP route 143.0.0.1/32 using ovsdb-client with # administration distance as greater than the corresponding static route. # This makes the BGP route less preferable than the corresponding # static route. bpg_route_command_ipv4_route2 = "ovsdb-client transact \'[ \"OpenSwitch\",\ {\ \"op\" : \"insert\",\ \"table\" : \"Nexthop\",\ \"row\" : {\ \"ip_address\" : \"1.1.1.5\",\ \"weight\" : 3,\ \"selected\": true\ },\ \"uuid-name\" : \"nh01\"\ },\ {\ \"op\" : \"insert\",\ \"table\" : \"Route\",\ \"row\" : {\ \"prefix\":\"143.0.0.1/32\",\ \"from\":\"bgp\",\ \"vrf\":[\"uuid\",\"%s\"],\ \"address_family\":\"ipv4\",\ \"sub_address_family\":\"unicast\",\ \"distance\":6,\ \"nexthops\" : [\ \"set\",\ [\ [\ \"named-uuid\",\ \"nh01\"\ ]\ ]]\ }\ }\ ]\'" % vrf_uuid # Configure the BGP route for prefix 143.0.0.1/32 using ovsdb-client # interface sw1(bpg_route_command_ipv4_route2, shell='bash') # Populate the expected RIB ("show rib") route dictionary for the BGP route # 143.0.0.1/32 and its next-hops. rib_ipv4_bgp_route2 = dict() rib_ipv4_bgp_route2['Route'] = '143.0.0.1/32' rib_ipv4_bgp_route2['NumberNexthops'] = '1' rib_ipv4_bgp_route2['1.1.1.5'] = dict() rib_ipv4_bgp_route2['1.1.1.5']['Distance'] = '6' rib_ipv4_bgp_route2['1.1.1.5']['Metric'] = '0' rib_ipv4_bgp_route2['1.1.1.5']['RouteType'] = 'bgp' # Populate the expected FIB ("show ip route") route dictionary for the # route 123.0.0.1/32 and its next-hops. Since static is configured with a # lower administration distance than BGP route, so the BGP route cannot be # in FIB. route_ipv4_bgp_route2 = dict() route_ipv4_bgp_route2['Route'] = '143.0.0.1/32' sleep(ZEBRA_TEST_SLEEP_TIME) step("Verifying the IPv4 static and BGP routes on switch 1") aux_route = route_ipv4_static_route1['Route'] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route1) aux_route = rib_ipv4_static_route1['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route1) aux_route = route_ipv4_bgp_route1['Route'] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route1) aux_route = rib_ipv4_bgp_route1['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route1) aux_route = route_ipv4_static_route2["Route"] verify_show_ip_route(sw1, aux_route, 'static', route_ipv4_static_route2) aux_route = rib_ipv4_static_route2['Route'] verify_show_rib(sw1, aux_route, 'static', rib_ipv4_static_route2) aux_route = route_ipv4_bgp_route2["Route"] verify_show_ip_route(sw1, aux_route, 'bgp', route_ipv4_bgp_route2) aux_route = rib_ipv4_bgp_route2['Route'] verify_show_rib(sw1, aux_route, 'bgp', rib_ipv4_bgp_route2)