Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dualtor] Add server traffic utility #3098

Merged
merged 2 commits into from
Mar 9, 2021

Conversation

lolyu
Copy link
Contributor

@lolyu lolyu commented Mar 5, 2021

Add server traffic utility to check the traffic between the selected ToR
and the server.

Signed-off-by: Longxiang Lyu [email protected]

Description of PR

Summary:
Fixes #2805

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Approach

What is the motivation for this PR?

Add util to verify the traffic between ToR and servers.

How did you do it?

Add a context manager class to dump the traffic between ToR and server(from the vlan interface on vm host server) and
check if there are expected packets out of captured packets.

How did you verify/test it?

  • demo testcase
import logging
import pytest
import random
import time

from scapy.all import IP, Ether
from ptf import testutils, mask
from tests.common.dualtor.dual_tor_mock import *
from tests.common.dualtor.tunnel_traffic_utils import tunnel_traffic_monitor
from tests.common.dualtor.dual_tor_utils import get_t1_ptf_ports, rand_selected_interface, flush_neighbor
from tests.common.dualtor.server_traffic_utils import ServerTrafficMonitor


pytestmark = [
    pytest.mark.topology("t0")
]


@pytest.fixture(scope="function")
def build_packet_to_server(rand_selected_interface, ptfadapter, rand_selected_dut, tunnel_traffic_monitor):
    """Build packet destinated to server selected by test_interface."""
    tor = rand_selected_dut
    _, server_details = rand_selected_interface
    server_ipv4 = server_details["server_ipv4"].split("/")[0]
    pkt_dscp = random.choice(range(0, 33))
    pkt_ttl = random.choice(range(3, 65))
    pkt = testutils.simple_ip_packet(
        eth_dst=tor.facts["router_mac"],
        eth_src=ptfadapter.dataplane.get_mac(0, 0),
        ip_src="1.1.1.1",
        ip_dst=server_ipv4,
        ip_dscp=pkt_dscp,
        ip_ttl=pkt_ttl
    )
    logging.info("the packet destinated to server %s:\n%s", server_ipv4, tunnel_traffic_monitor._dump_show_str(pkt))
    return pkt


@pytest.fixture(scope="function")
def stop_garp_service(ptfhost):
    ptfhost.shell("supervisorctl stop garp_service")
    yield
    ptfhost.shell("supervisorctl start garp_service")


def test_standby_tor_remove_neighbor_downstream_standby(
    apply_mock_dual_tor_tables,
    apply_mock_dual_tor_kernel_configs,
    apply_standby_state_to_orchagent,
    conn_graph_facts, tbinfo,
    build_packet_to_server, rand_selected_interface, ptfadapter,
    rand_selected_dut, tunnel_traffic_monitor, vmhost,
    stop_garp_service, rand_unselected_dut
):

    def build_exp_pkt(packet):
        exp_pkt = mask.Mask(packet)
        exp_pkt.set_do_not_care_scapy(Ether, "dst")
        exp_pkt.set_do_not_care_scapy(Ether, "src")
        exp_pkt.set_do_not_care_scapy(IP, "tos")
        exp_pkt.set_do_not_care_scapy(IP, "ttl")
        exp_pkt.set_do_not_care_scapy(IP, "chksum")
        return exp_pkt

    tor = rand_selected_dut
    tor = rand_unselected_dut
    pkt = build_packet_to_server
    iface, server_details = rand_selected_interface
    server_ipv4 = server_details["server_ipv4"].split("/")[0]

    exp_pkt = build_exp_pkt(pkt)

    ptfadapter.before_send = lambda *args, **kwargs: time.sleep(0.5)

    ptf_t1_intf = random.choice(get_t1_ptf_ports(tor, tbinfo))
    logging.info("send traffic to server %s from ptf t1 interface %s", server_ipv4, ptf_t1_intf)
    with flush_neighbor(tor, server_ipv4):
        with tunnel_traffic_monitor(tor, existing=False):
            with ServerTrafficMonitor(tor, vmhost, iface, conn_graph_facts, exp_pkt, existing=False):
                testutils.send(ptfadapter, int(ptf_t1_intf.strip("eth")), pkt, count=10)


def test_active_tor_downstream_active(
    apply_mock_dual_tor_tables,
    apply_mock_dual_tor_kernel_configs,
    apply_active_state_to_orchagent,
    conn_graph_facts, tbinfo,
    build_packet_to_server, rand_selected_interface, ptfadapter,
    rand_selected_dut, vmhost,
):

    def build_exp_pkt(packet):
        exp_pkt = mask.Mask(packet)
        exp_pkt.set_do_not_care_scapy(Ether, "dst")
        exp_pkt.set_do_not_care_scapy(Ether, "src")
        exp_pkt.set_do_not_care_scapy(IP, "tos")
        exp_pkt.set_do_not_care_scapy(IP, "ttl")
        exp_pkt.set_do_not_care_scapy(IP, "chksum")
        return exp_pkt

    tor = rand_selected_dut
    pkt = build_packet_to_server
    iface, server_details = rand_selected_interface
    server_ipv4 = server_details["server_ipv4"].split("/")[0]

    exp_pkt = build_exp_pkt(pkt)

    ptf_t1_intf = random.choice(get_t1_ptf_ports(tor, tbinfo))
    logging.info("send traffic to server %s from ptf t1 interface %s", server_ipv4, ptf_t1_intf)
    with ServerTrafficMonitor(tor, vmhost, iface, conn_graph_facts, exp_pkt, existing=True):
        testutils.send(ptfadapter, int(ptf_t1_intf.strip("eth")), pkt, count=10)
        time.sleep(1)
  • result
dualtor/test_vmhost.py::test_standby_tor_remove_neighbor_downstream_standby PASSED                                                                                                             [ 50%]
dualtor/test_vmhost.py::test_active_tor_downstream_active PASSED                                                                                                                               [100%]

===================================================================================== 2 passed in 45.65 seconds ======================================================================================

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

Add server traffic utility to check the traffic between the selected ToR
and the server.

Signed-off-by: Longxiang Lyu <[email protected]>
@lolyu lolyu requested a review from a team as a code owner March 5, 2021 03:31
@lolyu lolyu added the Dual ToR Orchagent Test Dev ⭕ Action item for orchagent-specific tests for dual ToR label Mar 5, 2021
@lgtm-com
Copy link

lgtm-com bot commented Mar 5, 2021

This pull request introduces 1 alert when merging 2594da0 into 6429d31 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lolyu
Copy link
Contributor Author

lolyu commented Mar 5, 2021

/AZP run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Longxiang Lyu <[email protected]>
@lgtm-com
Copy link

lgtm-com bot commented Mar 5, 2021

This pull request introduces 1 alert when merging 1f4566a into 60d73a0 - view on LGTM.com

new alerts:

  • 1 for Unused import

Copy link
Collaborator

@wangxin wangxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. BTW, can you address the LGTM alert?

@lolyu lolyu merged commit b4b6d21 into sonic-net:master Mar 9, 2021
@lolyu lolyu deleted the add_server_traffic_utility branch March 9, 2021 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dual ToR Orchagent Test Dev ⭕ Action item for orchagent-specific tests for dual ToR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Neighbor Entry Test Case
2 participants