def configuration(topology, request): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') assert sw1 is not None assert sw2 is not None assert sw3 is not None # Configuring ip address for sw1, sw2 and sw3 configure_interface(sw1, SW1_INTF1, SW1_INTF1_IPV4_ADDR) configure_interface(sw1, SW1_INTF2, SW1_INTF2_IPV4_ADDR) configure_interface(sw2, SW2_INTF1, SW2_INTF1_IPV4_ADDR) configure_interface(sw3, SW3_INTF1, SW3_INTF1_IPV4_ADDR) ports_sw1 = [sw1.ports[SW1_INTF1], sw1.ports[SW1_INTF2]] verify_turn_on_interfaces(sw1, ports_sw1) verify_turn_on_interfaces(sw2, [sw2.ports[SW2_INTF1]]) verify_turn_on_interfaces(sw3, [sw3.ports[SW3_INTF1]]) # Configuring ospf with network command in sw1, sw2 and sw3 configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF1_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF2_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF1_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw3, SW3_ROUTER_ID, SW3_INTF1_IPV4_ADDR, OSPF_AREA_1)
def configuration(topology, request): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') hs1 = topology.get('hs1') hs2 = topology.get('hs2') assert sw1 is not None assert sw2 is not None assert sw3 is not None assert hs1 is not None assert hs2 is not None # Configuring ip address for sw2 and sw3 configure_interface(sw1, SW1_INTF1, SW1_INTF1_IPV4_ADDR) configure_interface(sw1, SW1_INTF2, SW1_INTF2_IPV4_ADDR) configure_interface(sw2, SW2_INTF1, SW2_INTF1_IPV4_ADDR) configure_interface(sw2, SW2_INTF2, SW2_INTF2_IPV4_ADDR) configure_interface(sw3, SW3_INTF1, SW3_INTF1_IPV4_ADDR) configure_interface(sw3, SW3_INTF2, SW3_INTF2_IPV4_ADDR) ports_sw1 = [sw1.ports[SW1_INTF1], sw1.ports[SW1_INTF2]] verify_turn_on_interfaces(sw1, ports_sw1) ports_sw2 = [sw2.ports[SW2_INTF1], sw2.ports[SW2_INTF2]] verify_turn_on_interfaces(sw2, ports_sw2) ports_sw3 = [sw3.ports[SW3_INTF1], sw3.ports[SW3_INTF2]] verify_turn_on_interfaces(sw3, ports_sw3) # Configure IP and bring UP host 1 interfaces hs1.libs.ip.interface('1', addr='10.10.40.2/24', up=True) # Configure IP and bring UP host 2 interfaces hs2.libs.ip.interface('1', addr='10.10.30.2/24', up=True) # Configuring ospf with network command in sw2 and sw3 configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF1_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF1_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF2_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw3, SW3_ROUTER_ID, SW3_INTF2_IPV4_ADDR, OSPF_AREA_1)
def configuration(topology, request): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') sw4 = topology.get('sw4') sw5 = topology.get('sw5') assert sw1 is not None assert sw2 is not None assert sw3 is not None assert sw4 is not None assert sw5 is not None configure_interface(sw1, SW1_INTF1, SW1_INTF1_IPV4_ADDR) configure_interface(sw1, SW1_INTF2, SW1_INTF2_IPV4_ADDR) configure_interface(sw2, SW2_INTF1, SW2_INTF1_IPV4_ADDR) configure_interface(sw2, SW2_INTF2, SW2_INTF2_IPV4_ADDR) configure_interface(sw3, SW3_INTF1, SW3_INTF1_IPV4_ADDR) configure_interface(sw3, SW3_INTF2, SW3_INTF2_IPV4_ADDR) configure_interface(sw4, SW4_INTF1, SW4_INTF1_IPV4_ADDR) configure_interface(sw5, SW5_INTF2, SW5_INTF2_IPV4_ADDR) ports_sw1 = [sw1.ports[SW1_INTF1], sw1.ports[SW1_INTF2]] verify_turn_on_interfaces(sw1, ports_sw1) ports_sw2 = [sw2.ports[SW2_INTF1], sw2.ports[SW2_INTF2]] verify_turn_on_interfaces(sw2, ports_sw2) ports_sw3 = [sw3.ports[SW3_INTF1], sw3.ports[SW3_INTF2]] verify_turn_on_interfaces(sw3, ports_sw3) ports_sw4 = [sw4.ports[SW4_INTF1]] verify_turn_on_interfaces(sw4, ports_sw4) ports_sw5 = [sw5.ports[SW5_INTF2]] verify_turn_on_interfaces(sw5, ports_sw5) # Configuring ospf with network command in sw1, sw2, sw3, sw4 and sw5 configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF1_IPV4_ADDR, OSPF_AREA_100) configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF2_IPV4_ADDR, OSPF_AREA_100) configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF1_IPV4_ADDR, OSPF_AREA_100) configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF2_IPV4_ADDR, OSPF_AREA_0) configure_ospf_router(sw3, SW3_ROUTER_ID, SW3_INTF1_IPV4_ADDR, OSPF_AREA_200) configure_ospf_router(sw3, SW3_ROUTER_ID, SW3_INTF2_IPV4_ADDR, OSPF_AREA_0) configure_ospf_router(sw4, SW4_ROUTER_ID, SW4_INTF1_IPV4_ADDR, OSPF_AREA_200) configure_ospf_router(sw5, SW5_ROUTER_ID, SW5_INTF2_IPV4_ADDR, OSPF_AREA_100)
def test_ospf_routes_abr(topology, configuration, step): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') sw4 = topology.get('sw4') sw5 = topology.get('sw5') assert sw1 is not None assert sw2 is not None assert sw3 is not None assert sw4 is not None assert sw5 is not None step('###### Step 1 - Verifying adjacency between switches ######') retval = wait_for_adjacency(sw2, SW1_ROUTER_ID) if retval: step('Adjacency formed between SW2 and SW1(router-id = 1.1.1.1)') else: cmd = 'show ip ospf neighbor' sw2(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW2 and SW1(router-id = %s)" % SW1_ROUTER_ID retval = wait_for_adjacency(sw3, SW2_ROUTER_ID) if retval: step('Adjacency formed between SW3 and SW2(router-id = 2.2.2.2)') else: cmd = 'show ip ospf neighbor' sw3(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW3 and SW2(router-id = %s)" % SW2_ROUTER_ID retval = wait_for_adjacency(sw5, SW1_ROUTER_ID) if retval: step('Adjacency formed between SW5 and SW1(router-id = 1.1.1.1)') else: cmd = 'show ip ospf neighbor' sw5(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW5 and SW1(router-id = %s)" % SW1_ROUTER_ID step('###### Step 2 - Verify if SW2 and SW3 are acting as ABR ######') retval = verify_router_type(sw2) if retval == 2: step('###### Switch2 is ABR ######') else: cmd = 'show ip ospf' sw2(cmd.format(**locals()), shell='vtysh') assert False, 'Switch2 not acting as ABR' retval = verify_router_type(sw3) if retval == 2: step('###### Switch3 is ABR ######') else: cmd = 'show ip ospf' sw3(cmd.format(**locals()), shell='vtysh') assert False, 'Switch3 not acting as ABR' step('###### Step 3 - Disabling ospf process in switch1 ######') with sw1.libs.vtysh.Configure() as ctx: ctx.no_router_ospf() # Waiting time for routes of sw3 to be updated time.sleep(40) step( '###### Step 4 - Verifying whether connected route 10.10.10.0/24 ' 'is removed from sw3 using show rib command ######' ) retval = verify_route(sw3, '10.10.10.0', '24') if retval is True: sw3('show rib'.format(**locals()), shell='vtysh') assert False, 'Failed to remove connected route from 10.10.10.0/24' else: step( '###### Connected route 10.10.10.0/24 is removed ' 'from sw3 after disabling OSPF in sw1 ######' ) retval = verify_route(sw4, '10.10.10.0', '24') if retval is True: sw4('show rib'.format(**locals()), shell='vtysh') assert False, 'Failed to remove connected route 10.10.10.0 from sw4' else: step( '###### Connected route 10.10.10.0/24 is removed ' 'from sw4 after disabling OSPF in switch1 ######' ) # Enabling OSPF in sw1 configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF1_IPV4_ADDR, OSPF_AREA_100) configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF2_IPV4_ADDR, OSPF_AREA_100) step('###### Test Case [6.02] PASSED ######')
def test_ospf_process(topology, configuration, step): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') assert sw1 is not None assert sw2 is not None assert sw3 is not None step('######Step 1 - Verifying adjacency between switches ######') retval = wait_for_adjacency(sw1, SW2_ROUTER_ID) if retval: step('Adjacency formed between SW1 and SW2(router-id = 2.2.2.2)') else: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW1 and SW2(router-id = %s)" % SW2_ROUTER_ID retval = wait_for_adjacency(sw2, SW3_ROUTER_ID) if retval: step('Adjacency formed between SW2 and SW3(router-id = 3.3.3.3)') else: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW2 and SW3(router-id = %s)" % SW3_ROUTER_ID step('###### Step 2 - Disabling ospf process in switch1 ######') with sw1.libs.vtysh.Configure() as ctx: ctx.no_router_ospf() step('######Step 3 - Verifying whether SW3 router-id is present' ' in SW2 neighbor table ######') retval = wait_for_adjacency(sw2, SW3_ROUTER_ID) if retval: step('SW3(router-id = 3.3.3.3) is present in SW2 neighbor table') else: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "SW1(router-id = %s) is removed from " "SW2 neighbor table" % SW3_ROUTER_ID step('######Step 4 - Verifying whether SW1 entry is removed' ' from SW2 neighbor table ######') retval = wait_for_adjacency(sw2, SW1_ROUTER_ID, False) if retval is True: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "SW1(router-id = %s) is not removed in " "SW2 neighbor table" % SW1_ROUTER_ID else: step('SW1(router-id = 1.1.1.1)is removed from SW2 neighbor table') # Configuring the OSPF process in SW1 configure_ospf_router(sw1, SW1_ROUTER_ID, SW1_INTF1_IPV4_ADDR, OSPF_AREA_1) step('###### Step 5 - Verifying whether SW1 is updated' 'in SW2 neighbor table ######') retval = wait_for_adjacency(sw2, SW1_ROUTER_ID) if retval: step('SW1(router-id = 1.1.1.1) updated in SW2 neigbhor table') else: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW1 and SW2(router-id = %s)" % SW2_ROUTER_ID step('###### TC 2.02 PASSED ######')
def test_ospf_redistribute_bgp_routes(topology, configuration, step): sw1 = topology.get('sw1') sw2 = topology.get('sw2') sw3 = topology.get('sw3') hs1 = topology.get('hs1') hs2 = topology.get('hs2') assert sw1 is not None assert sw2 is not None assert sw3 is not None assert hs1 is not None assert hs2 is not None step('######Step 1 - Verifying adjacency between switches ######') retval = wait_for_adjacency(sw3, SW2_ROUTER_ID) if retval: step('Adjacency formed between SW3 and SW2(router-id = 2.2.2.2)') else: cmd = 'show ip ospf neighbor' sw3(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW3 and SW2(router-id = %s)" % SW2_ROUTER_ID retval = wait_for_adjacency(sw1, SW2_ROUTER_ID) if retval: step('Adjacency formed between SW1 and SW2(router-id = 2.2.2.2)') else: cmd = 'show ip ospf neighbor' sw1(cmd.format(**locals()), shell='vtysh') assert False, "Failed to form adjacency between" "SW1 and SW2(router-id = %s)" % SW2_ROUTER_ID step('###### Step 2 - Disabling OSPF process in sw3 ######') with sw3.libs.vtysh.Configure() as ctx: ctx.no_router_ospf() step('###### Step 3 - Disabling OSPF configuration from ' 'sw2 ---> interface 2 ######') unconfigure_ospf_network(sw2, SW2_INTF2_IPV4_ADDR, OSPF_AREA_1) step('######Step 4 - Redistibuting BGP routes to sw1######') with sw2.libs.vtysh.ConfigRouterOspf() as ctx: ctx.redistribute_bgp() step('######Step 5 - Configuring BGP in sw2 and sw3') configure_bgp_network(sw2, ASN_2, SW2_ROUTER_ID, SW2_INTF1_IPV4_ADDR, SW2_NEIGHBOR, ASN_3) configure_bgp_network(sw3, ASN_3, SW3_ROUTER_ID, SW3_INTF1_IPV4_ADDR, SW3_NEIGHBOR, ASN_2) # Waiting for BGP routes to be updated in show rib command time.sleep(20) step('###### Verifying the redistributed BGP route ' 'in sw3 from sw1 ######') retval = verify_route(sw1, '10.10.30.0', '24') if retval is True: step('###### Redistributed bgp route present in sw1 ######') else: sw1('show rib'.format(**locals()), shell='vtysh') assert False, 'sw2 Failed to redistribute BGP routes' step('###### Step 6 - Disabling BGP process in sw2 and sw3 ######') with sw2.libs.vtysh.Configure() as ctx: ctx.no_router_bgp(ASN_2) with sw3.libs.vtysh.Configure() as ctx: ctx.no_router_bgp(ASN_3) step('###### Step 7 - Enabling OSPF configurations ' 'in sw2 and sw3 ######') configure_ospf_router(sw2, SW2_ROUTER_ID, SW2_INTF2_IPV4_ADDR, OSPF_AREA_1) configure_ospf_router(sw3, SW3_ROUTER_ID, SW3_INTF2_IPV4_ADDR, OSPF_AREA_1) step('########### TEST CASE [4.03] PASSED ###########')