def test_lacpd_ct_system_priority(topology, step):
    sw1 = topology.get('sw1')
    assert sw1 is not None

    # TODO: Is there a common way in LACP CT to make sure the system is ready?
    sleep(10)

    for intf in test_lag_ifs:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])

    sw_create_bond(sw1, test_lag, test_lag_ifs, lacp_mode='active')

    step('Verify interfaces are working')
    # TODO get code from Mario once it merges

    # Set sys_id and sys_pri
    for priority in range(500, 600):
        step("Set LACP system priority")
        set_system_lacp_config(sw1, [
            'lacp-system-id=' + system_mac,
            'lacp-system-priority=' + str(priority)
        ])

        step("Verify system lacp-system-priority was applied to the"
             " interfaces.\n")

        for intf in test_lag_ifs:
            verify_intf_lacp_status(
                sw1, intf,
                {"actor_system_id": str(priority) + "," + system_mac},
                "s1:" + intf)
def main_setup(request, topology):
    """Common tests configuration.

    This configuration will be applied for all Fallback test cases, enabled or
    not, and after each test case the configuration must remains the same to
    keep the atomicity of each test.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    # Create two dynamic LAG with two ports each.
    sw_create_bond(sw1, test_lag, intf_labels, lacp_mode='active')
    sw_create_bond(sw2, test_lag, intf_labels, lacp_mode='active')

    set_port_parameter(sw1, test_lag, ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, test_lag, ['other_config:lacp-time=fast'])

    # Enable both the interfaces.
    for intf in intf_labels:
        set_intf_parameter(
            sw1, intf,
            ['user_config:admin=up', 'other_config:lacp-aggregation-key=1'])
        set_intf_parameter(
            sw2, intf,
            ['user_config:admin=up', 'other_config:lacp-aggregation-key=1'])

    sw_wait_until_ready([sw1, sw2], intf_labels)

    print('Verify all interfaces SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)
Пример #3
0
def test_ovs_appctl_getlacpstate(topology):
    """
        Verify the correct format output of the ovs-appctl command
        getlacpstate <lag_name>.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name_1 = 'lag1'
    lag_name_2 = 'lag2'

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']

    """
    The expected output has this format:
    LAG lag_name:
     Configured interfaces:
      Interface: interface_number
        actor_oper_port_state
           lacp_activity:0 time_out:0 aggregation:0 sync:0 collecting:0
           distributing:0 defaulted:0 expired:0
        partner_oper_port_state
           lacp_activity:0 time_out:0 aggregation:0 sync:0 collecting:0
           distributing:0 defaulted:1 expired:0
        lacp_control
           begin:0 actor_churn:0 partner_churn:0 ready_n:0 selected:1
           port_moved:0 ntt:0 port_enabled:0
      Interface: interface_number
        actor_oper_port_state
           lacp_activity:0 time_out:0 aggregation:0 sync:0 collecting:0
           distributing:0 defaulted:0 expired:0
        partner_oper_port_state
           lacp_activity:0 time_out:0 aggregation:0 sync:0 collecting:0
           distributing:0 defaulted:0 expired:0
        lacp_control
           begin:0 actor_churn:0 partner_churn:0 ready_n:0 selected:0
           port_moved:0 ntt:0 port_enabled:0
    """
    expected_output = [lag_name_1, "Configured interfaces",
                       "Interface: " + p11, "Interface: " + p21,
                       "actor_oper_port_state", "partner_oper_port_state",
                       "lacp_control", "begin", "actor_churn", "partner_churn",
                       "ready_n", "selected", "port_moved", "ntt",
                       "port_enabled", "lacp_activity", "time_out",
                       "aggregation", "sync", "collecting", "distributing",
                       "defaulted", "expired"]

    print("Turning on all interfaces used in this test")
    ports_sw1 = [p11, p12, p13, p14]
    enable_intf_list(sw1, ports_sw1)
    ports_sw2 = [p21, p22, p23, p24]
    enable_intf_list(sw2, ports_sw2)

    print("Create LAGs in both switches")
    output = sw_create_bond(sw1, lag_name_1, ports_sw1[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s"
                          % (lag_name_1, output))
    output = sw_create_bond(sw2, lag_name_1, ports_sw2[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s"
                          % (lag_name_1, output))
    output = sw_create_bond(sw1, lag_name_2, ports_sw1[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s"
                          % (lag_name_2, output))
    output = sw_create_bond(sw2, lag_name_2, ports_sw2[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s"
                          % (lag_name_2, output))

    print("Execute getlacpstate command")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpstate"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[0:4]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)
    for expected_output_element in expected_output[4:15]:
        assert output.count(expected_output_element) == 2,\
            "Element: %s is not in output 2 times" % (expected_output_element)
    for expected_output_element in expected_output[15:23]:
        assert output.count(expected_output_element) == 4,\
            "Element: %s is not in output 4 times" % (expected_output_element)

    print("Execute getlacpstate command for lag1")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpstate lag1"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[0:4]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)
    for expected_output_element in expected_output[4:15]:
        assert output.count(expected_output_element) == 2,\
            "Element: %s is not in output 2 times" % (expected_output_element)
    for expected_output_element in expected_output[15:23]:
        assert output.count(expected_output_element) == 4,\
            "Element: %s is not in output 4 times" % (expected_output_element)

    print("Execute getlacpstate command with non existent lag")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpstate lag3"
    output = sw1(c, shell='bash')
    assert output == "", ("Error: getlacpstate command with non " +
                          "existent LAG returned %s" % (lag_name_2, output))

    print("Execute getlacpstate command with static lag")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpstate lag2"
    output = sw1(c, shell='bash')
    assert output == "", ("Error: getlacpstate command with non " +
                          "static LAG returned %s" % (lag_name_2, output))
def test_lag_bond_status(topology, step):
    """
        Verify correct LAG bond_status according to the status of member
        interfaces status.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name = 'lag1'

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']

    ports_sw1 = [p11, p12, p13, p14]
    ports_sw2 = [p21, p22, p23, p24]

    step("Turning on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)
    enable_intf_list(sw2, ports_sw2)

    step("Creating static lag with 4 interfaces")
    sw_create_bond(sw1, lag_name, ports_sw1)
    sw_create_bond(sw2, lag_name, ports_sw2)

    for intf in ports_sw1:
        verify_intf_status(sw1, intf, "link_state", "up")
    for intf in ports_sw2:
        verify_intf_status(sw2, intf, "link_state", "up")

    ###########################################################################
    # 1.  When all member interfaces have bond_status up.
    ###########################################################################

    step("Verify that all the interfaces are added to LAG and that "
         "bond_status is up.")
    for intf in ports_sw1:
        verify_intf_in_bond(sw1, intf, "Expected interfaces "
                            "to be added to static lag")

        verify_intf_bond_status(sw1, intf, "up", "Expected interfaces "
                                "to have bond status UP")

    step("Verify LAG bond status is UP when all the member  interfaces "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 2.  When at least 1 member interface has bond_status up.
    ###########################################################################

    step("Turning off all interfaces of LAG but one")
    disable_intf_list(sw1, ports_sw1[1:4])

    step("Verify that turned off interfaces bond_status is down")
    for intf in ports_sw1[1:4]:
        verify_intf_bond_status(sw1, intf, "down", "Expected turned off "
                                "interfaces to have bond status DOWN")

    step("Verify that on interface bond_status is up")
    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected turned on "
                            "interface to have bond status UP")

    step("Verify LAG bond status is UP when at least one member interface "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Turning back on interfaces")
    enable_intf_list(sw1, ports_sw1[1:4])

    ###########################################################################
    # 3.  Interfaces not member of LAG don't have bond_status.
    ###########################################################################

    step("Remove interface from LAG")
    remove_intf_from_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is not part of LAG and bond_status is empty.")
    verify_intf_not_in_bond(sw1, ports_sw1[0],
                            "Expected the interfaces to be removed "
                            "from static lag")
    verify_intf_bond_status_empty(sw1, ports_sw1[0], "Interface expected"
                                  " to have bond status EMPTY")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Add interface back to LAG")
    add_intf_to_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is part of LAG and bond_status is up.")
    verify_intf_in_bond(sw1, ports_sw1[0], "Interfaces is not "
                        "added back to the LAG.")

    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected interfaces "
                            "to have bond status UP")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 4.  When all member interfaces have bond_status down.
    ###########################################################################

    step("Turning off all interfaces used in this test")
    disable_intf_list(sw1, ports_sw1)

    step("Verify that interfaces are not added to LAG when they are disabled"
         "and interface bond status is set to down")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf, "Interfaces should not be part "
                                "of LAG when they are disabled.")

        verify_intf_bond_status(sw1, intf, "down", "Expected interfaces "
                                "to have bond status DOWN")

    step("Verify that when all interfaces have bond_status equal to down "
         "LAG bond_status is down")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")

    step("Turning back on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)

    ###########################################################################
    # 5. Not eligible interface have bond_status equal to blocked.
    ###########################################################################

    step("Remove all interfaces from LAG but one")
    for intf in ports_sw1[0:3]:
        remove_intf_from_bond(sw1, lag_name, intf)

    step("Change speed of interface 2 in switch 1")
    c = ('set interface ' + str(p12) + ' hw_intf_config:speeds="10000,1000" ' +
         'hw_intf_info:max_speed="10000" hw_intf_info:speeds="10000,1000"')
    sw1(c, shell='vsctl')
    c = ('set interface ' + str(p12) + ' user_config:speeds="10000"')
    sw1(c, shell='vsctl')

    step("Add interface 2 to LAG")
    add_intf_to_bond(sw1, lag_name, p12)

    # Now we have one LAG with two interfaces with different speed each.
    # One interface is eligible and the other is not, so only one should have
    # bond_status equal to blocked.
    number_no_blocked = 0
    try:
        verify_intf_bond_status(sw1, p12, "blocked", "Expected "
                                "interfaces to have bond status BLOCKED")
    except AssertionError:
        number_no_blocked += 1
    try:
        verify_intf_bond_status(sw1, p14, "blocked", "Expected "
                                "interfaces to have bond status BLOCKED")
    except AssertionError:
        number_no_blocked += 1

    assert number_no_blocked == 1, "Expected only one interface to have " +\
        "bond_status BLOCKED"

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 6. When LAG has no member interfaces.
    ###########################################################################

    step("Remove all interfaces from LAG")
    remove_all_intf_from_bond(sw1, lag_name)

    step("Verify interface is not part of LAG and bond_status is empty.")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf,
                                "Expected the interfaces to be removed "
                                "from static lag")
        verify_intf_bond_status_empty(sw1, intf, "Interfaces expected"
                                      " to have bond status EMPTY")

    step("Verify LAG bond status is DOWN when LAG has no interfaces")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")
def test_ovs_appctl_getlacpcounters(topology):
    """
        Verify the correct format output of the ovs-appctl command
        getlacpcounters <lag_name>.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name_1 = 'lag1'
    lag_name_2 = 'lag2'

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']
    """
    The expected output has this format:
    LAG lag_name:
     Configured interfaces:
      Interface: X
        lacp_pdus_sent: 0
        marker_response_pdus_sent: 0
        lacp_pdus_received: 0
        marker_pdus_received: 0
      Interface: Y
        lacp_pdus_sent: 0
        marker_response_pdus_sent: 0
        lacp_pdus_received: 0
        marker_pdus_received: 0
    """
    expected_output = [
        lag_name_1, "Configured interfaces", "Interface: " + p11,
        "Interface: " + p21, "lacp_pdus_sent", "marker_response_pdus_sent",
        "lacp_pdus_received", "marker_pdus_received"
    ]

    print("Turning on all interfaces used in this test")
    ports_sw1 = [p11, p12, p13, p14]
    enable_intf_list(sw1, ports_sw1)
    ports_sw2 = [p21, p22, p23, p24]
    enable_intf_list(sw2, ports_sw2)

    print("Create LAGs in both switches")
    output = sw_create_bond(sw1,
                            lag_name_1,
                            ports_sw1[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_1, output))
    output = sw_create_bond(sw2,
                            lag_name_1,
                            ports_sw2[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_1, output))
    output = sw_create_bond(sw1, lag_name_2, ports_sw1[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_2, output))
    output = sw_create_bond(sw2, lag_name_2, ports_sw2[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_2, output))

    print("Execute getlacpcounters command")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpcounters"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[0:4]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)
    for expected_output_element in expected_output[4:8]:
        assert output.count(expected_output_element) == 2,\
            "Element: %s is not twice in output" % (expected_output_element)

    print("Execute getlacpcounters command for lag1")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpcounters lag1"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[0:4]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)
    for expected_output_element in expected_output[4:8]:
        assert output.count(expected_output_element) == 2,\
            "Element: %s is not twice in output" % (expected_output_element)

    print("Execute getlacpcounters command with non existent lag")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpcounters lag3"
    output = sw1(c, shell='bash')
    assert output == "", ("Error: getlacpcounters command with non " +
                          "existent LAG returned %s" % (lag_name_2, output))

    print("Execute getlacpcounters command with static lag")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpcounters lag2"
    output = sw1(c, shell='bash')
    assert output == "", ("Error: getlacpcounters command with non " +
                          "static LAG returned %s" % (lag_name_2, output))
def test_ovs_appctl_getlacpinterfaces(topology):
    """
        Verify the correct format output of the ovs-appctl command
        getlacpinterfaces <lag_name>.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name_1 = 'lag1'
    lag_name_2 = 'lag2'
    """
    The expected output has this format:
    Port lag_name: lag_name
        configured_members   :
        eligible_members     :
        participant_members  :
    Port lag_name:
        configured_members   :
        eligible_members     :
        participant_members  :
    """
    expected_output = [
        lag_name_1, lag_name_2, "configured_members", "eligible_members",
        "participant_members"
    ]

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']

    print("Turning on all interfaces used in this test")
    ports_sw1 = [p11, p12, p13, p14]
    enable_intf_list(sw1, ports_sw1)
    ports_sw2 = [p21, p22, p23, p24]
    enable_intf_list(sw2, ports_sw2)

    print("Create LAGs in both switches")
    output = sw_create_bond(sw1,
                            lag_name_1,
                            ports_sw1[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_1, output))
    output = sw_create_bond(sw2,
                            lag_name_1,
                            ports_sw2[0:2],
                            lacp_mode="active")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_1, output))
    output = sw_create_bond(sw1, lag_name_2, ports_sw1[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_2, output))
    output = sw_create_bond(sw2, lag_name_2, ports_sw2[2:4], lacp_mode="off")
    assert output == "", ("Error creating LAG %s returned %s" %
                          (lag_name_2, output))

    print("Execute getlacpinterfaces command")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpinterfaces"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[0:2]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)
    for expected_output_element in expected_output[2:5]:
        assert output.count(expected_output_element) == 2,\
            "Element: %s is not twice in output" % (expected_output_element)

    print("Execute getlacpinterfaces command for lag2")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpinterfaces lag2"
    output = sw1(c, shell='bash')
    for expected_output_element in expected_output[1:5]:
        assert expected_output_element in output,\
            "Element: %s is not in output" % (expected_output_element)

    print("Execute getlacpinterfaces command with non existent lag")
    c = "ovs-appctl -t ops-lacpd lacpd/getlacpinterfaces lag3"
    output = sw1(c, shell='bash')
    assert output == "", ("Error: getlacpinterfaces command with non " +
                          "existent LAG returned %s" % (output))
Пример #7
0
def test_lacpd_lag_dynamic_partner_priority(topology, step, main_setup, setup):
    """
    Case 2:
        Test the port priority functionality of LACP by testing the partner
        port priority. If two interfaces have the same port priority, the
        decision is made using the partner port priority
        Two switches are connected with 4 interfaces
        In switch 1, LAG 1 is formed with interfaces 1 to 4.
        In switch 2, LAG 1 is formed with interfaces 1 and 2, LAG 2 is
        formed with interfaces 3 and 4
    """
    step("\n=========== lacpd dynamic LAG partner priority test ===========\n")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4] in all switches\n")
    for intf in sw_1g_intf[0:4]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches\n")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:4], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:2], lacp_mode="active")
    sw_create_bond(sw2, "lag2", sw_1g_intf[2:4], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches\n")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag2", ['other_config:lacp-time=fast'])

    step("Setting port priorities\n")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=100'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=1'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=1'])

    step("Waiting for LACP to complete negotiation\n")
    """
    Interface 3 and 4 in switch 2 have the higher priority, LAG 1 in switch 1
    will connect to the LAG 2 because the partner has higher priority

    In switch 1:
        Interface 1 must not be collecting and distributing
        Interface 2 must not be collecting and distributing
        Interface 3 must be collecting and distributing
        Interface 4 must be collecting and distributing
    In switch 2:
        Interface 1 must not be collecting and distributing
        Interface 2 must not be collecting and distributing
        Interface 3 must be collecting and distributing
        Interface 4 must be collecting and distributing
    """
    step("Verify state machines in all switches\n")
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[0:2],
                               active_different_lag_intf)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[2:4],
                               active_ready)

    # finish testing
    for intf in sw_1g_intf[0:4]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag2", shell='bash')
Пример #8
0
def test_lacpd_lag_dynamic_port_priority(topology, step, main_setup, setup):
    """
    Case 1:
        Test the port priority functionality of LACP by setting a lower
        priority to an interface and allowing other interfaces with higher
        priority to join the corresponding LAGs.
        Two switches are connected with five interfaces using 2 LAGs in active
        mode.
        In switch 1, LAG 1 is formed with interfaces 1 and 2, LAG 2 is
        formed with interfaces 3, 4 and 5
        In switch 2, LAG 1 is formed with interfaces 1, 2 and 3, LAG 2 is
        formed with interfaces 4 and 5
    """
    step("\n============ lacpd dynamic LAG port priority test ============\n")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4, 5] in all switches\n")
    for intf in sw_1g_intf[0:5]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches\n")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:2], lacp_mode="active")
    sw_create_bond(sw1, "lag2", sw_1g_intf[2:5], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:3], lacp_mode="active")
    sw_create_bond(sw2, "lag2", sw_1g_intf[3:5], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches\n")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw1, "lag2", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag2", ['other_config:lacp-time=fast'])

    step("Setting port priorities\n")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '5', ['lacp-port-priority=100'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '5', ['lacp-port-priority=100'])

    step("Waiting for LACP to complete negotiation\n")
    """
    Interface 3 has the lower priority, this allows other interfaces to
    agreggate to the LAGs
    In switch 1:
        Interface 1 must be collecting and distributing
        Interface 2 must be collecting and distributing
        Interface 3 must not be collecting and distributing
        Interface 4 must be collecting and distributing
        Interface 5 must be collecting and distributing
    In switch 2:
        Interface 1 must be collecting and distributing
        Interface 2 must be collecting and distributing
        Interface 3 must not be collecting and distributing
        Interface 4 must be collecting and distributing
        Interface 5 must be collecting and distributing
    """
    step("Verify state machines in all switches\n")
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[0:2],
                               active_ready)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[3:5],
                               active_ready)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[2],
                               active_different_lag_intf)

    # finish testing
    for intf in sw_1g_intf[0:5]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw1("ovs-vsctl del-port lag2", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag2", shell='bash')
def test_lacpd_lag_defaulted_port_priority(topology, step, main_setup, setup):
    """
    Case 1:
        Test the port priority functionality of LACP when an interface is
        sent to defaulted state by disabling the partner interface connected
        to the interface with higher port priortiy. Also test when a function
        is sent to defaulted state and all interfaces have the same priority.
        Two switches are connected with 4 interfaces using 2 LAGs in active
        mode.
        In switch 1, LAG 1 is formed with interfaces 1, 2, 3 and 4
        In switch 2, LAG 1 is formed with interfaces 1, 2, 4 and 4
    """
    step("\n============ lacpd dynamic LAG port priority test ============")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4] in all switches")
    for intf in sw_1g_intf[0:4]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:4], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:4], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])

    step("Setting port priorities")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=200'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=200'])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Shutdown interface with higher port priority [2] in switch 2")
    disable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify interfaces 1, 3 and 4 are still working in both switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0], active_ready)
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[2:4], active_ready)

    step("Verify interface 2 is in defaulted state in switch 1")
    sw_wait_until_all_sm_ready(
        [sw1], sw1_intf_labels_1G[1], active_defaulted)

    step("No shutdown interface with higher port priority [2] in switch 2")
    enable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Set same port priority to all interfaces")
    set_intf_other_config(sw1, '2', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=200'])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Shutdown interface 2 in switch 2")
    disable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify interfaces 1, 3 and 4 are still working in both switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0], active_ready)
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[2:4], active_ready)

    step("Verify interface 2 is in defaulted state in switch 1")
    sw_wait_until_all_sm_ready(
        [sw1], sw1_intf_labels_1G[1], active_defaulted)

    step("No shutdown interface 2 in switch 2")
    enable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Set same port priority to all interfaces")
    # finish testing
    for intf in sw_1g_intf[0:4]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority", shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority", shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
def test_lacp_bond_status(topology, step):
    """
        Verify correct LACP bond_status according to the status of member
        interfaces status.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name = 'lag1'

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']

    ports_sw1 = [p11, p12, p13, p14]
    ports_sw2 = [p21, p22, p23, p24]

    step("Turning on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)
    enable_intf_list(sw2, ports_sw2)

    step("Creating dynamic lag with 4 interfaces")
    sw_create_bond(sw1, lag_name, ports_sw1, lacp_mode='active')
    sw_create_bond(sw2, lag_name, ports_sw2, lacp_mode='active')

    step("Turning on all the interfaces used in this test")
    for intf in ports_sw1:
        verify_intf_status(sw1, intf, "link_state", "up")
    for intf in ports_sw2:
        verify_intf_status(sw2, intf, "link_state", "up")

    step('Setting LAGs lacp rate as fast in switches')
    set_port_parameter(sw1, lag_name, ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, lag_name, ['other_config:lacp-time=fast'])

    step('Verify state machines from interfaces on Switch 1')
    sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    step('Verify state machines from interfaces on Switch 2')
    sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 1.  When all member interfaces have bond_status up.
    ###########################################################################

    step("Verify that all the interfaces are added to LAG and that "
          "bond_status is up.")
    for intf in ports_sw1:
        verify_intf_in_bond(sw1, intf, "Expected interfaces "
                            "to be added to static lag")

        verify_intf_bond_status(sw1, intf, "up", "Expected interfaces "
                                "to have bond status UP")

    step("Verify LAG bond status is UP when all the member  interfaces "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 2.  When at least 1 member interface has bond_status up.
    ###########################################################################

    step("Turning off all interfaces of LAG but one")
    disable_intf_list(sw1, ports_sw1[1:4])

    step("Verify that turned off interfaces bond_status is down")
    for intf in ports_sw1[1:4]:
        verify_intf_bond_status(sw1, intf, "down", "Expected turned off "
                                "interfaces to have bond status DOWN")

    step("Verify that on interface bond_status is up")
    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected turned on "
                            "interface to have bond status UP")

    step("Verify LAG bond status is UP when at least one member interface "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Turning back on interfaces")
    enable_intf_list(sw1, ports_sw1[1:4])

    ###########################################################################
    # 3.  Interfaces not member of LAG don't have bond_status.
    ###########################################################################

    step("Remove interface from LAG")
    remove_intf_from_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is not part of LAG.")
    verify_intf_not_in_bond(sw1, ports_sw1[0],
                            "Expected the interfaces to be removed "
                            "from static lag")

    step("Verify that interface bond_status is empty.")
    verify_intf_bond_status_empty(sw1, ports_sw1[0], "Interface expected"
                                  " to have bond status EMPTY")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Add interface back to LAG")
    add_intf_to_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is part of LAG.")
    verify_intf_in_bond(sw1, ports_sw1[0], "Interfaces is not "
                        "added back to the LAG.")

    step("Verify that interface bond_status is up.")
    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected interfaces "
                            "to have bond status UP")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 4.  When all member interfaces have bond_status down.
    ###########################################################################

    step("Turning off all interfaces used in this test")
    disable_intf_list(sw1, ports_sw1)

    step("Verify that interfaces are not added to LAG when they are disabled"
         "and interface bond status is set to down")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf, "Interfaces should not be part "
                                "of LAG when they are disabled.")

        verify_intf_bond_status(sw1, intf, "down", "Expected interfaces "
                                "to have bond status DOWN")

    step("Verify that when all interfaces have bond_status equal to down "
         "LAG bond_status is down")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")

    step("Turning back on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)

    ###########################################################################
    # 5. Not eligible interface have bond_status equal to blocked.
    ###########################################################################

    step("Remove partner interfaces 2")
    remove_intf_from_bond(sw2, lag_name, p22)

    step("Verify that interface bond_status is blocked.")
    verify_intf_bond_status(sw1, p12, "blocked", "Expected "
                            "interfaces to have bond status BLOCKED")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Add partner interface back to LAG")
    add_intf_to_bond(sw2, lag_name, p22)

    '''
        Falbback functionality is still not merge in rel/dill, so we need to
        disable cases 6 and 7.
    '''
    ###########################################################################
    # 6. When lacp_status = defaulted and fallback = false.
    ###########################################################################

    # step('Disabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, disable_fallback)
    # set_port_parameter(sw2, lag_name, disable_fallback)

    # step('Shutting down LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, disable_lag)
    # step('Verify that all sw1 SMs are in "Defaulted and Expired"')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, active_no_fallback)

    # step("Verify LAG bond status is BLOCKED")
    # verify_port_bond_status(sw1, lag_name, "blocked", "Expected the LAG "
                            # "to have bond status BLOCKED")

    # step('Turning on LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, active_lag)

    # step('Verify state machines from interfaces on Switch 1')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    # step('Verify state machines from interfaces on Switch 2')
    # sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 7. When lacp_status = defaulted and fallback = true.
    ###########################################################################

    # step('Enabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, enable_fallback)
    # set_port_parameter(sw2, lag_name, enable_fallback)

    # step('Shutting down LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, disable_lag)
    # step('Verify that all sw1 SMs are in "Defaulted and Expired"')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, active_fallback)

    # step("Verify LAG bond status is UP")
    # verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            # "to have bond status UP")

    # step('Turning on LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, active_lag)

    # step('Disabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, disable_fallback)
    # set_port_parameter(sw2, lag_name, disable_fallback)

    # step('Verify state machines from interfaces on Switch 1')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    # step('Verify state machines from interfaces on Switch 2')
    # sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 8. When LAG has no member interfaces.
    ###########################################################################
    step("Remove all interfaces from LAG")
    remove_all_intf_from_bond(sw1, lag_name)

    step("Verify interface is not part of LAG and bond_status is empty.")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf,
                                "Expected the interfaces to be removed "
                                "from static lag")
        verify_intf_bond_status_empty(sw1, intf, "Interfaces expected"
                                      " to have bond status EMPTY")

    step("Verify LAG bond status is DOWN when LAG has no interfaces")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")