Exemple #1
0
def test_ospf_on_startup(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(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, SW1_ROUTER_ID)
    if retval:
        step('Adjacency formed between SW3 and SW1(router-id = 1.1.1.1)')
    else:
        cmd = 'show ip ospf neighbor'
        sw3(cmd.format(**locals()), shell='vtysh')
        assert False, "Failed to form adjacency between "
        "SW3 and SW1(router-id = %s)" % SW1_ROUTER_ID

    step('######Step 2 - Configuring sw1(DUT) as stub router '
         'using max-metric router-lsa on-startup ######')
    with sw1.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.max_metric_router_lsa_on_startup('10')

    step('#### Step 3 - Verifying whether not directly connected route is '
         'removed ####')
    retval = verify_route(sw2, '10.10.20.0', '24')
    if retval is True:
        sw2('show rib'.format(**locals()), shell='vtysh')
        assert False, "Failed to remove OSPF route 10.10.20.0"
    else:
        step('###### OSPF routes 10.10.20.0 has been removed ######')

    step('##### Step 4 - Waiting to verify if stub router '
         'has acts as normal router')
    # Wait to check if the router acts as normal router after startup
    time.sleep(10)
    step('##### Step 5 - Verifying whether not directly connected route is '
         'removed')
    retval = verify_route(sw2, '10.10.20.0', '24')
    if retval is True:
        step('#### Routes has been removed ####')
    else:
        sw2('show rib'.format(**locals()), shell='vtysh')
        assert False, "Failed to remove OSPF route 10.10.20.0."
    step('###### TEST CASE [10.02] PASSED ######')
Exemple #2
0
def test_ospf_redistribute_connected_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 - Redistibuting connected routes in sw1######')
    with sw1.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.redistribute_connected()

    # Waiting for connected route to get updated in show rib command
    time.sleep(10)
    step('######step 3 - Verifying the sw1 advertised routes in sw2 ######')
    retval = verify_route(sw2, '10.10.40.0', '24')
    if retval is True:
        step('sw1 connected routes successfully advertised to sw2')
    else:
        sw2('show rib'.format(**locals()), shell='vtysh')
        assert False, "sw1 connected routes not advertised to sw2"

    step('###### Step 4 - Disabling redistibution of connected '
         'route in sw1 ######')
    with sw1.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.no_redistribute_connected()

    step('########### TEST CASE [4.02] PASSED ###########')
def test_ospf_hello_timer(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 2 -  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

    step('######Step 3 -  Changing the hello-timer interval in sw2  ######')
    with sw2.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.ip_ospf_hello_interval('30')

    # Waiting for dead timer + 15(buffer) to expire
    # so that neighbor entry can be removed.
    time.sleep(55)

    step('######Step 4 - Verifying adjacency after changing hello-timer #####')
    retval = wait_for_adjacency(sw1, SW2_ROUTER_ID, False)
    if retval is True:
        cmd = 'show ip ospf neighbor'
        sw1(cmd.format(**locals()), shell='vtysh')
        assert False, "adjacency still exist  between"
        "SW1 and SW2(router-id = %s)" % SW2_ROUTER_ID
    else:
        step('Adjacency torn between SW1 and SW2(router-id = 2.2.2.2)')

    step('######Step 5 - Changing the hello-timers to original value ######')
    with sw2.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.ip_ospf_hello_interval('10')

    step('######Step 6 - Verifying adjacency by reverting hello timer ######')
    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('########### TEST CASE [2.04] PASSED ###########')
Exemple #4
0
def test_ospf_redistribute_default_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 - Configuring default routes in sw1 ######')
    with sw1.libs.vtysh.Configure() as ctx:
        ctx.ip_route('0.0.0.0/0', '1')

    step('######Step 3 - Redistibuting default routes in sw1 ######')
    with sw1.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.default_information_originate_always()

    # Waiting for default route to get updated in show rib command
    time.sleep(10)
    step('######step 4 - Verifying the sw1 default routes in sw2 ######')
    retval = verify_route(sw2, '0.0.0.0', '0')
    if retval is True:
        step('sw2 connected routes advertised to sw1')
    else:
        sw2('show rib'.format(**locals()), shell='vtysh')
        assert False, "sw2 connected routes not advertised to sw1"

    step('########### TEST CASE [4.04] PASSED ###########')
Exemple #5
0
def test_ospfv2_ft_election_dr_bdr(topology, configuration, step):
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    sw3 = topology.get('sw3')
    sw4 = topology.get('sw4')

    assert sw1 is not None
    assert sw2 is not None
    assert sw3 is not None
    assert sw4 is not None

    step('###### Step 1 - configuring sw4 as L2 switch ######')
    with sw4.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.no_routing()
        ctx.no_shutdown()

    with sw4.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.no_routing()
        ctx.no_shutdown()

    with sw4.libs.vtysh.ConfigInterface('3') as ctx:
        ctx.no_routing()
        ctx.no_shutdown()

    step('###### Step 2 - Verifying adjacency between switches ######')
    retval = wait_for_adjacency(sw3, SW2_ROUTER_ID)
    if retval:
        step('Adjacency formed between SW3 and SW2(router-id = 4.4.4.4)')
    else:
        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 = 4.4.4.4)')
    else:
        assert False, "Failed to form adjacency between"
        "SW1 and SW2(router-id = %s)" % SW2_ROUTER_ID

    step('###### Step 3 - Verifying states of switches ######')
    dr_present = False
    bdr_present = False
    dr_other_present = False

    retval = wait_for_2way_state(sw2, SW1_ROUTER_ID)
    if retval:
        state = get_neighbor_state(sw2, SW1_ROUTER_ID)
        if (state == "Backup"):
            step('Switch1 in DRBackup state')
            bdr_present = True
        elif (state == "DR"):
            step('Switch1 in DR state')
            dr_present = True
        elif (state == "DROther"):
            step('Switch1 in DROther state')
            dr_other_present = True
        else:
            step('Switch1 is not in correct state')
            assert False, "Switch1 is not in correct state"
    else:
        assert False, "SW1 is not in correct state"

    retval = wait_for_2way_state(sw3, SW2_ROUTER_ID)
    if retval:
        state = get_neighbor_state(sw3, SW2_ROUTER_ID)
        if (state == "Backup"):
            step('Switch2 in DRBackup state')
            bdr_present = True
        elif (state == "DR"):
            step('Switch2 in DR state')
            dr_present = True
        elif (state == "DROther"):
            step('Switch2 in DROther state')
            dr_other_present = True
        else:
            step('Switch2 is not in correct state')
            assert False, "Switch1 is not in correct state"
    else:
        assert False, "SW2 is not in correct state"

    retval = wait_for_2way_state(sw1, SW3_ROUTER_ID)
    if retval:
        state = get_neighbor_state(sw1, SW3_ROUTER_ID)
        if (state == "Backup"):
            step('Switch3 in DRBackup state')
            bdr_present = True
        elif (state == "DR"):
            step('Switch3 in DR state')
            dr_present = True
        elif (state == "DROther"):
            step('Switch3 in DROther state')
            dr_other_present = True
        else:
            step('Switch3 is not in correct state')
            assert False, "Switch3 is not in correct state"
    else:
        assert False, "SW3 is not in correct state"

    if (dr_present is False) or (bdr_present is False) or \
       (dr_other_present is False):
        assert False, "DR/BDR election failed"

    step('###### TC- 3.01  PASSED ######')

    # Test case [3.03] : Test case to verify that the BDR is
    # selected as DR when priority values are changed
    step('###### Step 4 - Changing ospf priority of sw1, sw2, sw3 to 0, 10'
         ' and 20 respectively ######')

    with sw1.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.ip_ospf_priority('0')

    with sw2.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.ip_ospf_priority('10')

    with sw3.libs.vtysh.ConfigInterface('1') as ctx:
        ctx.ip_ospf_priority('20')

    step('Step 5 - Verifying the priorities configured ' 'in sw1, sw2 and sw3')
    retval = verify_ospf_priority(sw1, '0')
    if retval is True:
        step('###### Priority value successfully updated '
             ' in OSPF interface of SW1')
    else:
        assert False, "Failed to update priority in SW1"

    retval = verify_ospf_priority(sw2, '10')
    if retval is True:
        step('###### Priority value successfully updated '
             ' in OSPF interface of SW2')
    else:
        assert False, "Failed to update priority in SW2"

    retval = verify_ospf_priority(sw3, '20')
    if retval is True:
        step('###### Priority value successfully updated '
             ' in OSPF interface of SW3')
    else:
        assert False, "Failed to update priority in SW3"
    step('###### TC- 3.03  PASSED ######')
def test_ospf_best_route(topology, configuration, step):

    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 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

    step('######Step 2 - Configuring external distance in SW1 ######')
    with sw1.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.distance_ospf_external('80')

    step('######Step 3 - Configuring static routes in SW2 ######')
    with sw2.libs.vtysh.Configure() as ctx:
        ctx.ip_route('192.168.1.0/24', '1')

    step('######Step 4 - Redistibuting static routes configured in SW2 ######')
    with sw2.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.redistribute_static()

    step('######step 5 - Verifying the static routes from sw2 is advertised in sw1 ######')
    retval = wait_for_route_distance(sw1, '192.168.1.0', '24', '80')
    if retval is True:
        step('Static route 192.168.1.0/24 with distance metrics "80" is'
             ' advertised to SW1')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.1.0/24 with distance metrics 80"
        " is not advertised to SW1"

    step('######step 6 - Configuring static routes in SW1 ######')
    with sw1.libs.vtysh.Configure() as ctx:
        ctx.ip_route('192.168.1.0/24', '1', '100')

    step('######step 7 - Verifying static route from show running config'
         ' ######')
    retval = verify_ip_route(sw1, '192.168.1.0', '24', '1')
    if retval is True:
        step('Static route 192.168.1.0/24 updated in running configuration')
    else:
        cmd = 'show_running_config'
        sw1(cmd.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.1.0/24 not found"

    step('######step 8 - Verifying statically configured '
         'local routes in SW1 ######')
    retval = wait_for_route_distance(sw1, '192.168.1.0', '24', '100')
    if retval is True:
        step('Static route 192.168.1.0/24 with distance metrics "100" is'
             ' updated in SW1 RIB table')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.1.0/24 with distance metrics 100"
        " is not updated in SW1 RIB table"

    step('######step 9 - Verifying the best route in SW1 ######')
    retval = wait_for_best_route(sw1, '192.168.1.0', '80', 'ospf')
    if retval is True:
        step('OSPF route 192.168.1.0/24 in SW1 with distance metrics *80* '
             'is selected as best route')
    else:
        sw1('show ip route'.format(**locals()), shell='vtysh')
        assert False, "OSPF route 192.168.1.0/24 in SW1 with "
        "distance metrics *80* failed to be selected as best route"

    step('########### TEST CASE [13.01] PASSED ###########')
Exemple #7
0
def test_ospf_network_betwn_areas(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('###### SW2 is ABR ######')
    else:
        cmd = 'show ip ospf'
        sw2(cmd.format(**locals()), shell='vtysh')
        assert False, 'SW2 failed to become ABR'

    retval = verify_router_type(sw3)
    if(retval == 2):
        step('###### SW3 is ABR ######')
    else:
        cmd = 'show ip ospf'
        sw3(cmd.format(**locals()), shell='vtysh')
        assert False, 'SW3 failed to become ABR'

    # Waiting time for routes to be updated in sw3
    time.sleep(20)
    step(
        '###### Step 3 - Verifying the connected routes to sw1 '
        'using show rib command ######'
        )
    retval = verify_route(sw3, '10.10.10.0', '24')
    if retval is True:
        step('###### Connected route 10.10.10.0/24 found in sw3 ######')
    else:
        sw3('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Failed to remove connected route 10.10.10.0/24 in sw3'

    retval = verify_route(sw4, '10.10.10.0', '24')
    if retval is True:
        step('###### Connected route 10.10.10.0/24 found in sw4 ######')
    else:
        sw4('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Failed to remove connected route 10.10.10.0/24 in sw4'

    # TODO:
    # Verifying using "show ip ospf database summary"
    # Command is not supported currently
    # step('###### Step 4 - Verifying sw1 learnt routes in sw3 and sw4 #####')

    step('###### Test Case- [6.03]---PASSED ######')
Exemple #8
0
def test_ospf_summarized_routes(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

    # TODO:Summarization is not yet supported
    '''
    step('###### Step2 - Verifying the connected routes in sw1 ######')
    retval = verify_route(sw1, '10.10.10.1', '24')
    if retval is True:
        step('###Switch1 has learnt the route--> 10.10.10.1/24 ###')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Switch1 failed to learn route ---> 10.10.10.1/24'

    retval = verify_route(sw1, '10.10.20.1', '24')
    if retval is True:
        step('###### Switch1 has learnt the route--> 10.10.20.1/24 ######')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Switch1 failed to learn route ---> 10.10.20.1/24'
    '''

    step('###### Step 3 - Verify if the switches are ABR ######')
    retval = verify_router_type(sw2)
    if retval == 2:
        step('###### SW2 is ABR ######')
    else:
        cmd = 'show ip ospf'
        sw2(cmd.format(**locals()), shell='vtysh')
        assert False, 'SW2 failed to become ABR'

    retval = verify_router_type(sw3)
    if retval == 2:
        step('###### SW3 is ABR ######')
    else:
        cmd = 'show ip ospf'
        sw3(cmd.format(**locals()), shell='vtysh')
        assert False, 'SW3 failed to become ABR'

    # TODO:Summarization is not yet supported
    '''
    step(
        '###### Step4 - Verifying the connected routes to sw1'
        'using show rib command ######'
        )
    retval = verify_route(sw3, '10.10.0.0', '16')
    if retval is True:
        step('###### Connected route from SW3 to SW1 is found ######')
    else:
        sw3('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Connected route from SW3 to SW1 not found'

    retval = verify_route(sw4, '10.10.0.0', '16')
    if retval is True:
        step('###### Connected route from SW4 to  SW1 is removed ######')
    else:
        sw4('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Failed to remove connected route from SW4 to SW1'
    '''
    step('###### Test Case- [6.04] PASSED ######')
Exemple #9
0
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 ######')
Exemple #10
0
def test_ospf_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 neighbor'
        sw2(cmd.format(**locals()), shell='vtysh')
        assert False, 'Switch2 failed to become 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 failed to become ABR'

    # Waiting time for routes of sw3 to be updated
    time.sleep(20)
    step(
        '###### Step 3 -Verifying connected routes to sw1 '
        'using show rib command ######'
        )
    retval = verify_route(sw3, '10.10.10.0', '24')
    if retval is True:
        step('###### Connected route 10.10.10.0/24 is found in sw3 ######')
    else:
        sw3('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Connected route 10.10.10.0/24 not found in sw3'

    retval = verify_route(sw4, '10.10.10.0', '24')
    if retval is True:
        step('###### Connected route 10.10.10.0/24 is found in sw4  ######')
    else:
        sw4('show rib'.format(**locals()), shell='vtysh')
        assert False, 'Connected route 10.10.10.0/24 failed '
        'to be removed'

    step('###### Test Case [6.01] 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 ######')
Exemple #12
0
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 ###########')
Exemple #13
0
def test_ospf_redistribute_static_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 - Configuring static routes in sw2 ######')
    with sw2.libs.vtysh.Configure() as ctx:
        ctx.ip_route('192.168.1.0/24', '1')
        ctx.ip_route('192.168.2.0/24', '1')
        ctx.ip_route('192.168.3.0/24', '1')

    step('######Step 3 - Redistibuting static routes configued in sw1 ######')
    with sw2.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.redistribute_static()

    # Waiting for static route to get updated in show rib command
    time.sleep(10)
    step('######step 4 - Verifying the sw2 advertised routes in sw1 ######')
    retval = verify_route(sw1, '192.168.1.0', '24')
    if retval is True:
        step('Static route 192.168.1.0 in SW2 is advertised to SW1')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.1.0 in SW2 is not"
        " advertised to SW1"

    retval = verify_route(sw1, '192.168.2.0', '24')
    if retval is True:
        step('Static route 192.168.2.0 in SW2 is advertised to SW1')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.2.0 in SW2 is not"
        " advertised to SW1"

    retval = verify_route(sw1, '192.168.3.0', '24')
    if retval is True:
        step('Static route 192.168.3.0 in SW2 is advertised to SW1')
    else:
        sw1('show rib'.format(**locals()), shell='vtysh')
        assert False, "Static route 192.168.3.0 in SW2 is not"
        " advertised to SW1"

    step('######Step 5 - Disabling static route redistribution '
         'on sw1######')
    with sw2.libs.vtysh.ConfigRouterOspf() as ctx:
        ctx.no_redistribute_static()

    step('########### TEST CASE [4.01] PASSED ###########')
def test_ospf_md_authentication(topology, configuration, step):

    sw2 = topology.get('sw2')
    sw3 = topology.get('sw3')

    assert sw2 is not None
    assert sw3 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

    step('######Step 2 - Configuring MD5 authentication in sw2 ######')
    with sw2.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.ip_ospf_authentication_message_digest()
    with sw2.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.ip_ospf_message_digest_key_md5(md5_key, md5_password)

    # Waiting for adjacency to be torn
    step('######Step 3 - Verifying whether adjacency is torn between '
         'sw2 and sw3 ######')
    retval = wait_for_adjacency(sw3, SW2_ROUTER_ID, False)
    if retval is True:
        cmd = 'show ip ospf neighbor'
        sw3(cmd.format(**locals()), shell='vtysh')
        assert False, "Failed to tear adjacency between"
        "SW3 and SW2(router-id = %s)" % SW2_ROUTER_ID
    else:
        step('Adjacency torn successfully between '
             'SW3 and SW2(router-id = 2.2.2.2)')

    step('######Step 4 - Configuring MD5 authentication in sw3 ######')
    with sw3.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.ip_ospf_authentication_message_digest()
        ctx.ip_ospf_message_digest_key_md5(md5_key, md5_password)

    # Waiting for adjacency to form again
    step('######Step 5 - Verifying whether adjacency is restored between '
         'sw2 and sw3 ######')
    retval = wait_for_adjacency(sw3, SW2_ROUTER_ID)
    if retval:
        step('Adjacency restored 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

    step('######Step 6 - Disabling OSPF '
         'authentication in SW2 and SW3 ######')
    with sw2.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.no_ip_ospf_authentication()
        ctx.no_ip_ospf_message_digest_key(md5_key)

    with sw3.libs.vtysh.ConfigInterface('2') as ctx:
        ctx.no_ip_ospf_authentication()
        ctx.no_ip_ospf_message_digest_key(md5_key)

    step('########### TEST CASE [7.01] PASSED ###########')