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

get_capture returns only data capture #497

Open
dgalan-xxia opened this issue Mar 9, 2022 · 4 comments
Open

get_capture returns only data capture #497

dgalan-xxia opened this issue Mar 9, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@dgalan-xxia
Copy link

Version information
snappi-ixnetwork 0.7.5

Describe the bug
Enable capture now enables both data and control capture but get_capture returns only data capture

                    request = api.capture_request()
                    request.port_name = "SR Port 1"
                    pcap_bytes = api.get_capture(request)

@ANISH-GOTTAPU ANISH-GOTTAPU self-assigned this Mar 9, 2022
@ANISH-GOTTAPU ANISH-GOTTAPU moved this to In Progress in Open Traffic Generator Mar 9, 2022
@ANISH-GOTTAPU ANISH-GOTTAPU added the bug Something isn't working label Mar 9, 2022
@ANISH-GOTTAPU
Copy link
Contributor

ANISH-GOTTAPU commented Mar 9, 2022

@dgalan-xxia : Both captures worked for me, tested on 9.10 with Novus-100G. Control Capture tested with only Control packets without Data Traffic

Since you didn't have any packets in the request, I am suspecting a timing issue. If the below tests work with your hardware, try adding some sleep.

Control Capture Test:

import snappi
import dpkt
import time


def test_control_capture(api):
    """
    The test is to check if capture has control packets included.

    Validation: packet captures should have bgp packets
    """
    api = snappi.api(location="https://127.0.0.1", ext="ixnetwork")
    config = api.config()

    tx, rx = config.ports.port(
        name="tx", location="otg-novus100g.lbj.is.keysight.com;1;5"
    ).port(name="rx", location="otg-novus100g.lbj.is.keysight.com;1;6")

    config.options.port_options.location_preemption = True
    ly = config.layer1.layer1()[-1]
    ly.name = "ly"
    ly.port_names = [tx.name, rx.name]
    ly.ieee_media_defaults = False
    ly.auto_negotiate = False
    ly.speed = "speed_100_gbps"
    ly.media = "fiber"

    cap = config.captures.capture(name="c1")[-1]
    cap.port_names = [rx.name]
    cap.format = cap.PCAP

    tx_device, rx_device = config.devices.device(name="d1").device(name="d2")

    # tx_device config
    tx_eth = tx_device.ethernets.add()
    tx_eth.port_name = tx.name
    tx_eth.name = "tx_eth"
    tx_eth.mac = "00:00:00:00:00:aa"
    tx_ipv4 = tx_eth.ipv4_addresses.add()
    tx_ipv4.name = "tx_ipv4"
    tx_ipv4.address = "21.1.1.2"
    tx_ipv4.prefix = 24
    tx_ipv4.gateway = "21.1.1.1"
    tx_bgpv4 = tx_device.bgp
    tx_bgpv4.router_id = "192.0.0.1"
    tx_bgpv4_int = tx_bgpv4.ipv4_interfaces.add()
    tx_bgpv4_int.ipv4_name = tx_ipv4.name
    tx_bgpv4_peer = tx_bgpv4_int.peers.add()
    tx_bgpv4_peer.name = "tx_bgpv4"
    tx_bgpv4_peer.as_type = "ebgp"
    tx_bgpv4_peer.peer_address = "21.1.1.1"
    tx_bgpv4_peer.as_number = 65201

    # rx_device config
    rx_eth = rx_device.ethernets.add()
    rx_eth.port_name = rx.name
    rx_eth.name = "rx_eth"
    rx_eth.mac = "00:00:00:00:00:bb"
    rx_ipv4 = rx_eth.ipv4_addresses.add()
    rx_ipv4.name = "rx_ipv4"
    rx_ipv4.address = "21.1.1.1"
    rx_ipv4.prefix = 24
    rx_ipv4.gateway = "21.1.1.2"
    rx_bgpv4 = rx_device.bgp
    rx_bgpv4.router_id = "192.0.0.2"
    rx_bgpv4_int = rx_bgpv4.ipv4_interfaces.add()
    rx_bgpv4_int.ipv4_name = rx_ipv4.name
    rx_bgpv4_peer = rx_bgpv4_int.peers.add()
    rx_bgpv4_peer.name = "rx_bgpv4"
    rx_bgpv4_peer.as_type = "ebgp"
    rx_bgpv4_peer.peer_address = "21.1.1.2"
    rx_bgpv4_peer.as_number = 65200

    api.set_config(config)
    time.sleep(10)

    cs = api.capture_state()
    cs.state = cs.START
    api.set_capture_state(cs)

    print("Starting all protocols ...")
    ps = api.protocol_state()
    ps.state = ps.START
    api.set_protocol_state(ps)
    time.sleep(5)

    request = api.capture_request()
    request.port_name = "rx"
    pcap_bytes = api.get_capture(request)

    bgp_pkts = []
    for _, pkt in dpkt.pcap.Reader(pcap_bytes):
        eth = dpkt.ethernet.Ethernet(pkt)
        if getattr(eth.data, "tcp", None) is not None:
            if eth.data.tcp.sport == 179:
                bgp_pkts.append(eth.data)

    print(len(bgp_pkts))
    assert len(bgp_pkts) > 0

    print("Stop all protocols ...")
    ps = api.protocol_state()
    ps.state = ps.STOP
    api.set_protocol_state(ps)

Data Capture Test:

import snappi
import dpkt
import time

def test_data_capture(api):
    """
    The test is to check if capture has data packets included.

    Validation: packet captures should have packets with dst route range
                200.1.1.1
    """
    api = snappi.api(location="https://127.0.0.1", ext="ixnetwork")
    config = api.config()

    tx, rx = config.ports.port(
        name="tx", location="otg-novus100g.lbj.is.keysight.com;1;5"
    ).port(name="rx", location="otg-novus100g.lbj.is.keysight.com;1;6")

    config.options.port_options.location_preemption = True
    ly = config.layer1.layer1()[-1]
    ly.name = "ly"
    ly.port_names = [tx.name, rx.name]
    ly.ieee_media_defaults = False
    ly.auto_negotiate = False
    ly.speed = "speed_100_gbps"
    ly.media = "fiber"

    cap = config.captures.capture(name="c1")[-1]
    cap.port_names = [rx.name]
    cap.format = cap.PCAP

    tx_device, rx_device = config.devices.device(name="d1").device(name="d2")

    # tx_device config
    tx_eth = tx_device.ethernets.add()
    tx_eth.port_name = tx.name
    tx_eth.name = "tx_eth"
    tx_eth.mac = "00:00:00:00:00:aa"
    tx_ipv4 = tx_eth.ipv4_addresses.add()
    tx_ipv4.name = "tx_ipv4"
    tx_ipv4.address = "21.1.1.2"
    tx_ipv4.prefix = 24
    tx_ipv4.gateway = "21.1.1.1"
    tx_bgpv4 = tx_device.bgp
    tx_bgpv4.router_id = "192.0.0.1"
    tx_bgpv4_int = tx_bgpv4.ipv4_interfaces.add()
    tx_bgpv4_int.ipv4_name = tx_ipv4.name
    tx_bgpv4_peer = tx_bgpv4_int.peers.add()
    tx_bgpv4_peer.name = "tx_bgpv4"
    tx_bgpv4_peer.as_type = "ebgp"
    tx_bgpv4_peer.peer_address = "21.1.1.1"
    tx_bgpv4_peer.as_number = 65201
    tx_rr = tx_bgpv4_peer.v4_routes.add(name="tx_rr")
    tx_rr.addresses.add(address="100.1.1.1", prefix=32, count=1)

    # rx_device config
    rx_eth = rx_device.ethernets.add()
    rx_eth.port_name = rx.name
    rx_eth.name = "rx_eth"
    rx_eth.mac = "00:00:00:00:00:bb"
    rx_ipv4 = rx_eth.ipv4_addresses.add()
    rx_ipv4.name = "rx_ipv4"
    rx_ipv4.address = "21.1.1.1"
    rx_ipv4.prefix = 24
    rx_ipv4.gateway = "21.1.1.2"
    rx_bgpv4 = rx_device.bgp
    rx_bgpv4.router_id = "192.0.0.2"
    rx_bgpv4_int = rx_bgpv4.ipv4_interfaces.add()
    rx_bgpv4_int.ipv4_name = rx_ipv4.name
    rx_bgpv4_peer = rx_bgpv4_int.peers.add()
    rx_bgpv4_peer.name = "rx_bgpv4"
    rx_bgpv4_peer.as_type = "ebgp"
    rx_bgpv4_peer.peer_address = "21.1.1.2"
    rx_bgpv4_peer.as_number = 65200
    rx_rr = rx_bgpv4_peer.v4_routes.add(name="rx_rr")
    rx_rr.addresses.add(address="200.1.1.1", prefix=32, count=1)

    # flow config
    flow = config.flows.flow(name="flow1")[-1]

    flow.tx_rx.device.tx_names = [tx_rr.name]
    flow.tx_rx.device.rx_names = [rx_rr.name]

    flow.size.fixed = 1024
    flow.rate.percentage = 10
    flow.duration.fixed_packets.packets = 10
    flow.metrics.enable = True

    api.set_config(config)
    time.sleep(10)

    cs = api.capture_state()
    cs.state = cs.START
    api.set_capture_state(cs)

    print("Starting all protocols ...")
    ps = api.protocol_state()
    ps.state = ps.START
    api.set_protocol_state(ps)
    time.sleep(5)

    print("Starting transmit on all flows ...")
    ts = api.transmit_state()
    ts.state = ts.START
    api.set_transmit_state(ts)
    time.sleep(5)

    request = api.capture_request()
    request.port_name = "rx"
    pcap_bytes = api.get_capture(request)

    data_pkts = []
    for _, pkt in dpkt.pcap.Reader(pcap_bytes):
        eth = dpkt.ethernet.Ethernet(pkt)
        if isinstance(eth.data, dpkt.ip.IP):
            # b'\xc8\x01\x01\x01' is 200.1.1.1
            if eth.ip.dst == b"\xc8\x01\x01\x01":
                data_pkts.append(eth.data)

    print(len(data_pkts))
    assert len(data_pkts) == 10

    print("Stop all protocols ...")
    ps = api.protocol_state()
    ps.state = ps.STOP
    api.set_protocol_state(ps)```

@dgalan-xxia
Copy link
Author

Running with Novus 9.20. I will raise the issue with IxNetwork team as it seems that when the data capture is empty, the merged one is also empty (I manually downloaded all 3 captures).

@ANISH-GOTTAPU
Copy link
Contributor

Same issue as #487

@ANISH-GOTTAPU
Copy link
Contributor

@ASHNA-AGGARWAL-KEYSIGHT : can you please check with 9.20 and see if both cap and pcap works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Backlog
Development

No branches or pull requests

3 participants