Feature (contd.): Device Emulatiom - converted emulation tests to use the py.test framework
This commit is contained in:
parent
3a5396c865
commit
cad62c1fd7
@ -75,6 +75,7 @@ message Ip6Emulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extend OstProto.DeviceGroup {
|
extend OstProto.DeviceGroup {
|
||||||
|
// FIXME: add directly to DeviceGroup in protocol.proto
|
||||||
optional EncapEmulation encap = 2000;
|
optional EncapEmulation encap = 2000;
|
||||||
|
|
||||||
optional MacEmulation mac = 2001;
|
optional MacEmulation mac = 2001;
|
||||||
|
@ -300,7 +300,8 @@ message DeviceGroupIdList {
|
|||||||
message DeviceGroup {
|
message DeviceGroup {
|
||||||
required DeviceGroupId device_group_id = 1;
|
required DeviceGroupId device_group_id = 1;
|
||||||
optional DeviceGroupCore core = 2;
|
optional DeviceGroupCore core = 2;
|
||||||
optional uint32 device_count = 3 [default = 1];
|
// FIXME: add Encap here
|
||||||
|
optional uint32 device_count = 3 [default = 1]; // per-encap
|
||||||
|
|
||||||
extensions 2000 to 5999; // For use by Protocol Emulations
|
extensions 2000 to 5999; // For use by Protocol Emulations
|
||||||
}
|
}
|
||||||
|
559
test/emultest.py
559
test/emultest.py
@ -8,8 +8,10 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from fabric.api import run, env, sudo
|
from fabric.api import run, env, sudo
|
||||||
from harness import Test, TestSuite, TestPreRequisiteError
|
#from harness import Test, TestSuite, TestPreRequisiteError
|
||||||
|
|
||||||
sys.path.insert(1, '../binding')
|
sys.path.insert(1, '../binding')
|
||||||
from core import ost_pb, emul, DroneProxy
|
from core import ost_pb, emul, DroneProxy
|
||||||
@ -18,25 +20,21 @@ from protocols.mac_pb2 import mac, Mac
|
|||||||
from protocols.ip4_pb2 import ip4, Ip4
|
from protocols.ip4_pb2 import ip4, Ip4
|
||||||
from protocols.vlan_pb2 import vlan
|
from protocols.vlan_pb2 import vlan
|
||||||
|
|
||||||
use_defaults = False
|
use_defaults = True
|
||||||
|
|
||||||
# initialize defaults - drone
|
|
||||||
host_name = '127.0.0.1'
|
|
||||||
tx_port_number = -1
|
|
||||||
rx_port_number = -1
|
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
tshark = r'C:\Program Files\Wireshark\tshark.exe'
|
tshark = r'C:\Program Files\Wireshark\tshark.exe'
|
||||||
else:
|
else:
|
||||||
tshark = 'tshark'
|
tshark = 'tshark'
|
||||||
|
|
||||||
|
# initialize defaults - drone
|
||||||
|
host_name = '127.0.0.1'
|
||||||
|
|
||||||
# initialize defaults - DUT
|
# initialize defaults - DUT
|
||||||
env.use_shell = False
|
env.use_shell = False
|
||||||
env.user = 'tc'
|
env.user = 'tc'
|
||||||
env.password = 'tc'
|
env.password = 'tc'
|
||||||
env.host_string = 'localhost:50022'
|
env.host_string = 'localhost:50022'
|
||||||
dut_rx_port = 'eth1'
|
|
||||||
dut_tx_port = 'eth2'
|
|
||||||
|
|
||||||
dut_dst_mac = 0x0800278df2b4 #FIXME: hardcoding
|
dut_dst_mac = 0x0800278df2b4 #FIXME: hardcoding
|
||||||
|
|
||||||
@ -55,8 +53,7 @@ if len(sys.argv) > 1:
|
|||||||
print(' -h --help show this help')
|
print(' -h --help show this help')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print('')
|
print('This module uses the following topology -')
|
||||||
print('This test uses the following topology -')
|
|
||||||
print('')
|
print('')
|
||||||
print(' +-------+ +-------+')
|
print(' +-------+ +-------+')
|
||||||
print(' | |Tx--->---Rx|-+ |')
|
print(' | |Tx--->---Rx|-+ |')
|
||||||
@ -69,16 +66,18 @@ print('are expected to be forwarded by the DUT and received back on the')
|
|||||||
print('Rx port')
|
print('Rx port')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
suite = TestSuite()
|
|
||||||
if not use_defaults:
|
if not use_defaults:
|
||||||
s = raw_input('Drone\'s Hostname/IP [%s]: ' % (host_name))
|
s = raw_input('Drone\'s Hostname/IP [%s]: ' % (host_name))
|
||||||
host_name = s or host_name
|
host_name = s or host_name
|
||||||
s = raw_input('DUT\'s Hostname/IP [%s]: ' % (env.host_string))
|
s = raw_input('DUT\'s Hostname/IP [%s]: ' % (env.host_string))
|
||||||
env.host_string = s or env.host_string
|
env.host_string = s or env.host_string
|
||||||
|
# FIXME: get inputs for dut rx/tx ports
|
||||||
|
|
||||||
drone = DroneProxy(host_name)
|
# ================================================================= #
|
||||||
|
# ----------------------------------------------------------------- #
|
||||||
try:
|
# FIXTURES
|
||||||
|
# ----------------------------------------------------------------- #
|
||||||
|
# ================================================================= #
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# Baseline Configuration for subsequent testcases
|
# Baseline Configuration for subsequent testcases
|
||||||
# NOTES
|
# NOTES
|
||||||
@ -87,119 +86,181 @@ try:
|
|||||||
# the devices to check
|
# the devices to check
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def drone(request):
|
||||||
|
drn = DroneProxy(host_name)
|
||||||
|
|
||||||
# FIXME: get inputs for dut rx/tx ports
|
log.info('connecting to drone(%s:%d)' % (drn.hostName(), drn.portNumber()))
|
||||||
|
drn.connect()
|
||||||
|
|
||||||
# Enable IP forwarding on the DUT (aka make it a router)
|
def fin():
|
||||||
sudo('sysctl -w net.ipv4.ip_forward=1')
|
drn.disconnect()
|
||||||
|
request.addfinalizer(fin)
|
||||||
|
|
||||||
# connect to drone
|
return drn
|
||||||
log.info('connecting to drone(%s:%d)'
|
|
||||||
% (drone.hostName(), drone.portNumber()))
|
|
||||||
drone.connect()
|
|
||||||
|
|
||||||
# retreive port id list
|
@pytest.fixture(scope='module')
|
||||||
log.info('retreiving port list')
|
def ports(request, drone):
|
||||||
port_id_list = drone.getPortIdList()
|
port_id_list = drone.getPortIdList()
|
||||||
|
|
||||||
# retreive port config list
|
|
||||||
log.info('retreiving port config for all ports')
|
|
||||||
port_config_list = drone.getPortConfig(port_id_list)
|
port_config_list = drone.getPortConfig(port_id_list)
|
||||||
|
assert len(port_config_list.port) != 0
|
||||||
if len(port_config_list.port) == 0:
|
|
||||||
log.warning('drone has no ports!')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# print port list and find default tx/rx ports
|
# print port list and find default tx/rx ports
|
||||||
|
tx_number = -1
|
||||||
|
rx_number = -1
|
||||||
|
print port_config_list
|
||||||
print('Port List')
|
print('Port List')
|
||||||
print('---------')
|
print('---------')
|
||||||
for port in port_config_list.port:
|
for port in port_config_list.port:
|
||||||
print('%d.%s (%s)' % (port.port_id.id, port.name, port.description))
|
print('%d.%s (%s)' % (port.port_id.id, port.name, port.description))
|
||||||
# use a vhost port as default tx/rx port
|
# use a vhost port as default tx/rx port
|
||||||
if ('vhost' in port.name or 'sun' in port.description.lower()):
|
if ('vhost' in port.name or 'sun' in port.description.lower()):
|
||||||
if tx_port_number < 0:
|
if tx_number < 0:
|
||||||
tx_port_number = port.port_id.id
|
tx_number = port.port_id.id
|
||||||
elif rx_port_number < 0:
|
elif rx_number < 0:
|
||||||
rx_port_number = port.port_id.id
|
rx_number = port.port_id.id
|
||||||
if ('eth1' in port.name):
|
if ('eth1' in port.name):
|
||||||
tx_port_number = port.port_id.id
|
tx_number = port.port_id.id
|
||||||
if ('eth2' in port.name):
|
if ('eth2' in port.name):
|
||||||
rx_port_number = port.port_id.id
|
rx_number = port.port_id.id
|
||||||
|
|
||||||
if not use_defaults:
|
assert tx_number >= 0
|
||||||
p = raw_input('Tx Port Id [%d]: ' % (tx_port_number))
|
assert rx_number >= 0
|
||||||
if p:
|
|
||||||
tx_port_number = int(p)
|
|
||||||
|
|
||||||
p = raw_input('Rx Port Id [%d]: ' % (rx_port_number))
|
print('Using port %d as tx port(s)' % tx_number)
|
||||||
if p:
|
print('Using port %d as rx port(s)' % rx_number)
|
||||||
rx_port_number = int(p)
|
|
||||||
|
|
||||||
if tx_port_number < 0 or rx_port_number < 0:
|
ports.tx = ost_pb.PortIdList()
|
||||||
log.warning('invalid tx/rx port')
|
ports.tx.port_id.add().id = tx_number;
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print('Using port %d as tx port(s)' % tx_port_number)
|
ports.rx = ost_pb.PortIdList()
|
||||||
print('Using port %d as rx port(s)' % rx_port_number)
|
ports.rx.port_id.add().id = rx_number;
|
||||||
|
return ports
|
||||||
|
|
||||||
tx_port = ost_pb.PortIdList()
|
@pytest.fixture(scope='module')
|
||||||
tx_port.port_id.add().id = tx_port_number;
|
def dut(request):
|
||||||
|
# Enable IP forwarding on the DUT (aka make it a router)
|
||||||
|
sudo('sysctl -w net.ipv4.ip_forward=1')
|
||||||
|
|
||||||
rx_port = ost_pb.PortIdList()
|
@pytest.fixture(scope='module')
|
||||||
rx_port.port_id.add().id = rx_port_number;
|
def dut_ports(request):
|
||||||
|
dut_ports.rx = 'eth1'
|
||||||
|
dut_ports.tx = 'eth2'
|
||||||
|
|
||||||
|
# delete all configuration on the DUT interfaces
|
||||||
|
sudo('ip address flush dev ' + dut_ports.rx)
|
||||||
|
sudo('ip address flush dev ' + dut_ports.tx)
|
||||||
|
return dut_ports
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def emul_ports(request, drone, ports):
|
||||||
|
emul_ports = ost_pb.PortIdList()
|
||||||
|
emul_ports.port_id.add().id = ports.tx.port_id[0].id;
|
||||||
|
emul_ports.port_id.add().id = ports.rx.port_id[0].id;
|
||||||
|
return emul_ports
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def dgid_list(request, drone, ports):
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# create emulated device(s) on tx/rx ports - each test case will
|
# create emulated device(s) on tx/rx ports - each test case will
|
||||||
# modify and reuse these devices as per its needs
|
# modify and reuse these devices as per its needs
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
emul_ports = ost_pb.PortIdList()
|
|
||||||
emul_ports.port_id.add().id = tx_port_number;
|
|
||||||
emul_ports.port_id.add().id = rx_port_number;
|
|
||||||
|
|
||||||
# delete existing devices, if any, on tx port
|
# delete existing devices, if any, on tx port
|
||||||
tx_dgid_list = drone.getDeviceGroupIdList(tx_port.port_id[0])
|
dgid_list.tx = drone.getDeviceGroupIdList(ports.tx.port_id[0])
|
||||||
drone.deleteDeviceGroup(tx_dgid_list)
|
drone.deleteDeviceGroup(dgid_list.tx)
|
||||||
|
|
||||||
# add a emulated device on tx port
|
# add a emulated device group on tx port
|
||||||
tx_dgid_list = ost_pb.DeviceGroupIdList()
|
dgid_list.tx = ost_pb.DeviceGroupIdList()
|
||||||
tx_dgid_list.port_id.CopyFrom(tx_port.port_id[0])
|
dgid_list.tx.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
tx_dgid_list.device_group_id.add().id = 1
|
dgid_list.tx.device_group_id.add().id = 1
|
||||||
log.info('adding tx device_group %d' % tx_dgid_list.device_group_id[0].id)
|
log.info('adding tx device_group %d' % dgid_list.tx.device_group_id[0].id)
|
||||||
drone.addDeviceGroup(tx_dgid_list)
|
drone.addDeviceGroup(dgid_list.tx)
|
||||||
|
|
||||||
# delete existing devices, if any, on rx port
|
# delete existing devices, if any, on rx port
|
||||||
rx_dgid_list = drone.getDeviceGroupIdList(rx_port.port_id[0])
|
dgid_list.rx = drone.getDeviceGroupIdList(ports.rx.port_id[0])
|
||||||
drone.deleteDeviceGroup(rx_dgid_list)
|
drone.deleteDeviceGroup(dgid_list.rx)
|
||||||
|
|
||||||
# add a emulated device on rx port
|
# add a emulated device group on rx port
|
||||||
rx_dgid_list = ost_pb.DeviceGroupIdList()
|
dgid_list.rx = ost_pb.DeviceGroupIdList()
|
||||||
rx_dgid_list.port_id.CopyFrom(rx_port.port_id[0])
|
dgid_list.rx.port_id.CopyFrom(ports.rx.port_id[0])
|
||||||
rx_dgid_list.device_group_id.add().id = 1
|
dgid_list.rx.device_group_id.add().id = 1
|
||||||
log.info('adding rx device_group %d' % rx_dgid_list.device_group_id[0].id)
|
log.info('adding rx device_group %d' % dgid_list.rx.device_group_id[0].id)
|
||||||
drone.addDeviceGroup(rx_dgid_list)
|
drone.addDeviceGroup(dgid_list.rx)
|
||||||
|
|
||||||
|
def fin():
|
||||||
|
dgid_list = drone.getDeviceGroupIdList(ports.tx.port_id[0])
|
||||||
|
drone.deleteDeviceGroup(dgid_list)
|
||||||
|
dgid_list = drone.getDeviceGroupIdList(ports.rx.port_id[0])
|
||||||
|
drone.deleteDeviceGroup(dgid_list)
|
||||||
|
request.addfinalizer(fin)
|
||||||
|
|
||||||
|
return dgid_list
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def stream_id(request, drone, ports):
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# create stream on tx port - each test case will modify and reuse
|
# create stream on tx port - each test case will modify and reuse
|
||||||
# this stream as per its needs
|
# this stream as per its needs
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
# delete existing streams, if any, on tx port
|
# delete existing streams, if any, on tx port
|
||||||
sid_list = drone.getStreamIdList(tx_port.port_id[0])
|
sid_list = drone.getStreamIdList(ports.tx.port_id[0])
|
||||||
drone.deleteStream(sid_list)
|
drone.deleteStream(sid_list)
|
||||||
|
|
||||||
# add a stream
|
# add a stream
|
||||||
stream_id = ost_pb.StreamIdList()
|
stream_id = ost_pb.StreamIdList()
|
||||||
stream_id.port_id.CopyFrom(tx_port.port_id[0])
|
stream_id.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
stream_id.stream_id.add().id = 1
|
stream_id.stream_id.add().id = 1
|
||||||
log.info('adding tx_stream %d' % stream_id.stream_id[0].id)
|
log.info('adding tx_stream %d' % stream_id.stream_id[0].id)
|
||||||
drone.addStream(stream_id)
|
drone.addStream(stream_id)
|
||||||
|
|
||||||
# ----------------------------------------------------------------- #
|
def fin():
|
||||||
# delete all configuration on the DUT interfaces
|
drone.deleteStream(stream_id)
|
||||||
# ----------------------------------------------------------------- #
|
request.addfinalizer(fin)
|
||||||
sudo('ip address flush dev ' + dut_rx_port)
|
|
||||||
sudo('ip address flush dev ' + dut_tx_port)
|
return stream_id
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dut_vlans(request, dut_ports):
|
||||||
|
num_vlans = getattr(request.function, 'num_vlans')
|
||||||
|
vlan_base = getattr(request.function, 'vlan_base')
|
||||||
|
for i in range(num_vlans):
|
||||||
|
vlan_id = vlan_base+i
|
||||||
|
vrf = 'v' + str(vlan_id)
|
||||||
|
vlan_rx_dev = dut_ports.rx + '.' + str(vlan_id)
|
||||||
|
vlan_tx_dev = dut_ports.tx + '.' + str(vlan_id)
|
||||||
|
|
||||||
|
sudo('ip netns add ' + vrf)
|
||||||
|
|
||||||
|
sudo('ip link add link ' + dut_ports.rx
|
||||||
|
+ ' name ' + vlan_rx_dev
|
||||||
|
+ ' type vlan id ' + str(vlan_id))
|
||||||
|
sudo('ip link set ' + vlan_rx_dev
|
||||||
|
+ ' netns ' + vrf)
|
||||||
|
sudo('ip netns exec ' + vrf
|
||||||
|
+ ' ip addr add 10.1.1.1/24'
|
||||||
|
+ ' dev ' + vlan_rx_dev)
|
||||||
|
sudo('ip netns exec ' + vrf
|
||||||
|
+ ' ip link set ' + vlan_rx_dev + ' up')
|
||||||
|
|
||||||
|
sudo('ip link add link ' + dut_ports.tx
|
||||||
|
+ ' name ' + vlan_tx_dev
|
||||||
|
+ ' type vlan id ' + str(vlan_id))
|
||||||
|
sudo('ip link set ' + vlan_tx_dev
|
||||||
|
+ ' netns ' + vrf)
|
||||||
|
sudo('ip netns exec ' + vrf
|
||||||
|
+ ' ip addr add 10.1.2.1/24'
|
||||||
|
+ ' dev ' + vlan_tx_dev)
|
||||||
|
sudo('ip netns exec ' + vrf
|
||||||
|
+ ' ip link set ' + vlan_tx_dev + ' up')
|
||||||
|
|
||||||
|
def fin():
|
||||||
|
for i in range(num_vlans):
|
||||||
|
vlan_id = vlan_base + i
|
||||||
|
vrf = 'v' + str(vlan_id)
|
||||||
|
sudo('ip netns delete ' + vrf)
|
||||||
|
request.addfinalizer(fin)
|
||||||
|
|
||||||
# ================================================================= #
|
# ================================================================= #
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
@ -207,6 +268,8 @@ try:
|
|||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# ================================================================= #
|
# ================================================================= #
|
||||||
|
|
||||||
|
def test_multiEmulDevNoVlan(drone, ports, dut, dut_ports, stream_id,
|
||||||
|
emul_ports, dgid_list):
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# TESTCASE: Emulate multiple IPv4 devices (no vlans)
|
# TESTCASE: Emulate multiple IPv4 devices (no vlans)
|
||||||
# DUT
|
# DUT
|
||||||
@ -218,20 +281,17 @@ try:
|
|||||||
# Host1(s) Host2(s)
|
# Host1(s) Host2(s)
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
passed = False
|
|
||||||
suite.test_begin('multiEmulDevNoVlan')
|
|
||||||
|
|
||||||
num_devs = 5
|
num_devs = 5
|
||||||
try:
|
|
||||||
# configure the DUT
|
# configure the DUT
|
||||||
sudo('ip address add 10.10.1.1/24 dev ' + dut_rx_port)
|
sudo('ip address add 10.10.1.1/24 dev ' + dut_ports.rx)
|
||||||
sudo('ip address add 10.10.2.1/24 dev ' + dut_tx_port)
|
sudo('ip address add 10.10.2.1/24 dev ' + dut_ports.tx)
|
||||||
|
|
||||||
# configure the tx device(s)
|
# configure the tx device(s)
|
||||||
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
||||||
devgrp_cfg.port_id.CopyFrom(tx_port.port_id[0])
|
devgrp_cfg.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
dg = devgrp_cfg.device_group.add()
|
dg = devgrp_cfg.device_group.add()
|
||||||
dg.device_group_id.id = tx_dgid_list.device_group_id[0].id
|
dg.device_group_id.id = dgid_list.tx.device_group_id[0].id
|
||||||
dg.core.name = "Host1"
|
dg.core.name = "Host1"
|
||||||
dg.device_count = num_devs
|
dg.device_count = num_devs
|
||||||
dg.Extensions[emul.mac].address = 0x000102030a01
|
dg.Extensions[emul.mac].address = 0x000102030a01
|
||||||
@ -244,9 +304,9 @@ try:
|
|||||||
|
|
||||||
# configure the rx device(s)
|
# configure the rx device(s)
|
||||||
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
||||||
devgrp_cfg.port_id.CopyFrom(rx_port.port_id[0])
|
devgrp_cfg.port_id.CopyFrom(ports.rx.port_id[0])
|
||||||
dg = devgrp_cfg.device_group.add()
|
dg = devgrp_cfg.device_group.add()
|
||||||
dg.device_group_id.id = rx_dgid_list.device_group_id[0].id
|
dg.device_group_id.id = dgid_list.rx.device_group_id[0].id
|
||||||
dg.core.name = "Host1"
|
dg.core.name = "Host1"
|
||||||
dg.device_count = num_devs
|
dg.device_count = num_devs
|
||||||
dg.Extensions[emul.mac].address = 0x000102030b01
|
dg.Extensions[emul.mac].address = 0x000102030b01
|
||||||
@ -259,11 +319,11 @@ try:
|
|||||||
|
|
||||||
# configure the tx stream
|
# configure the tx stream
|
||||||
stream_cfg = ost_pb.StreamConfigList()
|
stream_cfg = ost_pb.StreamConfigList()
|
||||||
stream_cfg.port_id.CopyFrom(tx_port.port_id[0])
|
stream_cfg.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
s = stream_cfg.stream.add()
|
s = stream_cfg.stream.add()
|
||||||
s.stream_id.id = stream_id.stream_id[0].id
|
s.stream_id.id = stream_id.stream_id[0].id
|
||||||
s.core.is_enabled = True
|
s.core.is_enabled = True
|
||||||
s.control.packets_per_sec = 20
|
s.control.packets_per_sec = 100
|
||||||
s.control.num_packets = 10
|
s.control.num_packets = 10
|
||||||
|
|
||||||
# setup stream protocols as mac:eth2:ip4:udp:payload
|
# setup stream protocols as mac:eth2:ip4:udp:payload
|
||||||
@ -291,27 +351,24 @@ try:
|
|||||||
log.info('configuring tx_stream %d' % stream_id.stream_id[0].id)
|
log.info('configuring tx_stream %d' % stream_id.stream_id[0].id)
|
||||||
drone.modifyStream(stream_cfg)
|
drone.modifyStream(stream_cfg)
|
||||||
|
|
||||||
# clear tx/rx stats
|
# FIXME(needed?): clear tx/rx stats
|
||||||
log.info('clearing tx/rx stats')
|
log.info('clearing tx/rx stats')
|
||||||
drone.clearStats(tx_port)
|
drone.clearStats(ports.tx)
|
||||||
drone.clearStats(rx_port)
|
drone.clearStats(ports.rx)
|
||||||
|
|
||||||
# clear arp on DUT
|
# clear arp on DUT
|
||||||
sudo('ip neigh flush all')
|
sudo('ip neigh flush all')
|
||||||
arp_cache = run('ip neigh show')
|
arp_cache = run('ip neigh show')
|
||||||
if re.search('10.10.2.10[1-5].*lladdr', arp_cache):
|
assert re.search('10.10.2.10[1-5].*lladdr', arp_cache) == None
|
||||||
raise TestPreRequisiteError('ARP cache not cleared')
|
|
||||||
|
|
||||||
# resolve ARP on tx/rx ports
|
# resolve ARP on tx/rx ports
|
||||||
log.info('resolving Neighbors on tx/rx ports ...')
|
log.info('resolving Neighbors on tx/rx ports ...')
|
||||||
drone.startCapture(emul_ports)
|
drone.startCapture(emul_ports)
|
||||||
drone.clearDeviceNeighbors(emul_ports)
|
drone.clearDeviceNeighbors(emul_ports)
|
||||||
drone.resolveDeviceNeighbors(emul_ports)
|
drone.resolveDeviceNeighbors(emul_ports)
|
||||||
time.sleep(10)
|
time.sleep(3)
|
||||||
drone.stopCapture(emul_ports)
|
drone.stopCapture(emul_ports)
|
||||||
|
|
||||||
fail = 0
|
|
||||||
|
|
||||||
# verify ARP Requests sent out from tx port
|
# verify ARP Requests sent out from tx port
|
||||||
buff = drone.getCaptureBuffer(emul_ports.port_id[0])
|
buff = drone.getCaptureBuffer(emul_ports.port_id[0])
|
||||||
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||||
@ -325,8 +382,7 @@ try:
|
|||||||
' && (arp.src.proto_ipv4 == 10.10.1.'+str(101+i)+')'
|
' && (arp.src.proto_ipv4 == 10.10.1.'+str(101+i)+')'
|
||||||
' && (arp.dst.proto_ipv4 == 10.10.1.1)'])
|
' && (arp.dst.proto_ipv4 == 10.10.1.1)'])
|
||||||
print(cap_pkts)
|
print(cap_pkts)
|
||||||
if cap_pkts.count('\n') != 1:
|
assert cap_pkts.count('\n') == 1
|
||||||
fail = fail + 1
|
|
||||||
|
|
||||||
# verify *no* ARP Requests sent out from rx port
|
# verify *no* ARP Requests sent out from rx port
|
||||||
buff = drone.getCaptureBuffer(emul_ports.port_id[1])
|
buff = drone.getCaptureBuffer(emul_ports.port_id[1])
|
||||||
@ -341,8 +397,7 @@ try:
|
|||||||
' && (arp.src.proto_ipv4 == 10.10.2.'+str(101+i)+')'
|
' && (arp.src.proto_ipv4 == 10.10.2.'+str(101+i)+')'
|
||||||
' && (arp.dst.proto_ipv4 == 10.10.2.1)'])
|
' && (arp.dst.proto_ipv4 == 10.10.2.1)'])
|
||||||
print(cap_pkts)
|
print(cap_pkts)
|
||||||
if cap_pkts.count('\n') != 0:
|
assert cap_pkts.count('\n') == 0
|
||||||
fail = fail + 1
|
|
||||||
|
|
||||||
# retrieve and verify ARP Table on tx/rx ports
|
# retrieve and verify ARP Table on tx/rx ports
|
||||||
log.info('retrieving ARP entries on tx port')
|
log.info('retrieving ARP entries on tx port')
|
||||||
@ -359,8 +414,7 @@ try:
|
|||||||
(dev_cfg.ip4, arp.ip4, arp.mac))
|
(dev_cfg.ip4, arp.ip4, arp.mac))
|
||||||
if (arp.ip4 == dev_cfg.ip4_default_gateway) and (arp.mac):
|
if (arp.ip4 == dev_cfg.ip4_default_gateway) and (arp.mac):
|
||||||
resolved = True
|
resolved = True
|
||||||
if not resolved:
|
assert resolved
|
||||||
fail = fail + 1
|
|
||||||
|
|
||||||
log.info('retrieving ARP entries on rx port')
|
log.info('retrieving ARP entries on rx port')
|
||||||
device_list = drone.getDeviceList(emul_ports.port_id[0])
|
device_list = drone.getDeviceList(emul_ports.port_id[0])
|
||||||
@ -370,21 +424,21 @@ try:
|
|||||||
log.info('ARP Table on rx port')
|
log.info('ARP Table on rx port')
|
||||||
for dev_cfg, device in zip(device_config, devices):
|
for dev_cfg, device in zip(device_config, devices):
|
||||||
# verify *no* ARPs learnt on rx port
|
# verify *no* ARPs learnt on rx port
|
||||||
if len(device.arp):
|
assert len(device.arp) == 0
|
||||||
fail = fail + 1
|
|
||||||
for arp in device.arp:
|
for arp in device.arp:
|
||||||
# TODO: pretty print ip and mac
|
# TODO: pretty print ip and mac
|
||||||
print('%08x: %08x %012x' %
|
print('%08x: %08x %012x' %
|
||||||
(dev_cfg.ip4, arp.ip4, arp.mac))
|
(dev_cfg.ip4, arp.ip4, arp.mac))
|
||||||
|
|
||||||
drone.startCapture(rx_port)
|
# We are all set now - so transmit the stream now
|
||||||
drone.startTransmit(tx_port)
|
drone.startCapture(ports.rx)
|
||||||
|
drone.startTransmit(ports.tx)
|
||||||
log.info('waiting for transmit to finish ...')
|
log.info('waiting for transmit to finish ...')
|
||||||
time.sleep(7)
|
time.sleep(3)
|
||||||
drone.stopTransmit(tx_port)
|
drone.stopTransmit(ports.tx)
|
||||||
drone.stopCapture(rx_port)
|
drone.stopCapture(ports.rx)
|
||||||
|
|
||||||
buff = drone.getCaptureBuffer(rx_port.port_id[0])
|
buff = drone.getCaptureBuffer(ports.rx.port_id[0])
|
||||||
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||||
log.info('dumping Rx capture buffer (all)')
|
log.info('dumping Rx capture buffer (all)')
|
||||||
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
||||||
@ -397,27 +451,18 @@ try:
|
|||||||
' && (eth.dst == 00:01:02:03:0b:'
|
' && (eth.dst == 00:01:02:03:0b:'
|
||||||
+ format(1+i, '02x')+')'])
|
+ format(1+i, '02x')+')'])
|
||||||
print(cap_pkts)
|
print(cap_pkts)
|
||||||
if cap_pkts.count('\n') != s.control.num_packets/ip.src_ip_count:
|
assert cap_pkts.count('\n') == s.control.num_packets/ip.src_ip_count
|
||||||
fail = fail + 1
|
|
||||||
if fail == 0:
|
|
||||||
passed = True
|
|
||||||
else:
|
|
||||||
log.info('failed checks: %d' % fail)
|
|
||||||
os.remove('capture.pcap')
|
os.remove('capture.pcap')
|
||||||
except RpcError as e:
|
|
||||||
raise
|
drone.stopTransmit(ports.tx)
|
||||||
finally:
|
|
||||||
drone.stopTransmit(tx_port)
|
|
||||||
run('ip neigh show')
|
run('ip neigh show')
|
||||||
|
|
||||||
# unconfigure DUT
|
# unconfigure DUT
|
||||||
sudo('ip address delete 10.10.1.1/24 dev ' + dut_rx_port)
|
sudo('ip address delete 10.10.1.1/24 dev ' + dut_ports.rx)
|
||||||
sudo('ip address delete 10.10.2.1/24 dev ' + dut_tx_port)
|
sudo('ip address delete 10.10.2.1/24 dev ' + dut_ports.tx)
|
||||||
suite.test_end(passed)
|
|
||||||
|
|
||||||
sys.exit(1)
|
|
||||||
# FIXME: update the below test cases to resolve Neighbors and streams
|
|
||||||
# to derive src/dst mac from device
|
|
||||||
|
|
||||||
|
def test_multiEmulDevPerVlan(request, drone, ports, dut, dut_ports, stream_id,
|
||||||
|
emul_ports, dgid_list):
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
# TESTCASE: Emulate multiple IPv4 device per multiple single-tag VLANs
|
# TESTCASE: Emulate multiple IPv4 device per multiple single-tag VLANs
|
||||||
#
|
#
|
||||||
@ -431,80 +476,48 @@ try:
|
|||||||
# Host1(s) Host2(s)
|
# Host1(s) Host2(s)
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
passed = False
|
test_multiEmulDevPerVlan.num_vlans = num_vlans = 5
|
||||||
suite.test_begin('multiEmulDevPerVlan')
|
test_multiEmulDevPerVlan.vlan_base = vlan_base = 201
|
||||||
|
num_devs_per_vlan = 3
|
||||||
num_vlans = 5
|
tx_ip_base = 0x0a010165
|
||||||
vlan_base = 201
|
rx_ip_base = 0x0a010265
|
||||||
num_devs = 3
|
|
||||||
dev_ip_base = 101
|
|
||||||
try:
|
|
||||||
# configure the DUT
|
|
||||||
for i in range(num_vlans):
|
|
||||||
vlan_id = vlan_base+i
|
|
||||||
vrf = 'v' + str(vlan_id)
|
|
||||||
vlan_rx_dev = dut_rx_port + '.' + str(vlan_id)
|
|
||||||
vlan_tx_dev = dut_tx_port + '.' + str(vlan_id)
|
|
||||||
|
|
||||||
sudo('ip netns add ' + vrf)
|
|
||||||
|
|
||||||
sudo('ip link add link ' + dut_rx_port
|
|
||||||
+ ' name ' + vlan_rx_dev
|
|
||||||
+ ' type vlan id ' + str(vlan_id))
|
|
||||||
sudo('ip link set ' + vlan_rx_dev
|
|
||||||
+ ' netns ' + vrf)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip addr add 10.1.1.1/24'
|
|
||||||
+ ' dev ' + vlan_rx_dev)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip link set ' + vlan_rx_dev + ' up')
|
|
||||||
|
|
||||||
sudo('ip link add link ' + dut_tx_port
|
|
||||||
+ ' name ' + vlan_tx_dev
|
|
||||||
+ ' type vlan id ' + str(vlan_id))
|
|
||||||
sudo('ip link set ' + vlan_tx_dev
|
|
||||||
+ ' netns ' + vrf)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip addr add 10.1.2.1/24'
|
|
||||||
+ ' dev ' + vlan_tx_dev)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip link set ' + vlan_tx_dev + ' up')
|
|
||||||
|
|
||||||
|
# configure vlans on the DUT
|
||||||
|
dut_vlans(request, dut_ports)
|
||||||
|
|
||||||
# configure the tx device(s)
|
# configure the tx device(s)
|
||||||
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
||||||
devgrp_cfg.port_id.CopyFrom(tx_port.port_id[0])
|
devgrp_cfg.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
dg = devgrp_cfg.device_group.add()
|
dg = devgrp_cfg.device_group.add()
|
||||||
dg.device_group_id.id = tx_dgid_list.device_group_id[0].id
|
dg.device_group_id.id = dgid_list.tx.device_group_id[0].id
|
||||||
dg.core.name = "Host1"
|
dg.core.name = "Host1"
|
||||||
v = dg.Extensions[emul.vlan].stack.add()
|
v = dg.Extensions[emul.encap].vlan.stack.add()
|
||||||
v.vlan_tag = vlan_base
|
v.vlan_tag = vlan_base
|
||||||
v.count = num_vlans
|
v.count = num_vlans
|
||||||
d = dg.Extensions[emul.device]
|
dg.device_count = num_devs_per_vlan
|
||||||
d.count = num_devs
|
dg.Extensions[emul.mac].address = 0x000102030a01
|
||||||
d.mac.address = 0x000102030a01
|
ip = dg.Extensions[emul.ip4]
|
||||||
d.ip4.address = 0x0a010165
|
ip.address = tx_ip_base
|
||||||
d.ip4.prefix_length = 24
|
ip.prefix_length = 24
|
||||||
d.ip4.default_gateway = 0x0a0a0101
|
ip.default_gateway = (tx_ip_base & 0xffffff00) | 0x01
|
||||||
|
|
||||||
drone.modifyDeviceGroup(devgrp_cfg)
|
drone.modifyDeviceGroup(devgrp_cfg)
|
||||||
|
|
||||||
# configure the rx device(s)
|
# configure the rx device(s)
|
||||||
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
devgrp_cfg = ost_pb.DeviceGroupConfigList()
|
||||||
devgrp_cfg.port_id.CopyFrom(rx_port.port_id[0])
|
devgrp_cfg.port_id.CopyFrom(ports.rx.port_id[0])
|
||||||
dg = devgrp_cfg.device_group.add()
|
dg = devgrp_cfg.device_group.add()
|
||||||
dg.device_group_id.id = rx_dgid_list.device_group_id[0].id
|
dg.device_group_id.id = dgid_list.rx.device_group_id[0].id
|
||||||
dg.core.name = "Host1"
|
dg.core.name = "Host1"
|
||||||
v = dg.Extensions[emul.vlan].stack.add()
|
v = dg.Extensions[emul.encap].vlan.stack.add()
|
||||||
v.vlan_tag = vlan_base
|
v.vlan_tag = vlan_base
|
||||||
v.count = num_vlans
|
v.count = num_vlans
|
||||||
d = dg.Extensions[emul.device]
|
dg.device_count = num_devs_per_vlan
|
||||||
d.count = num_devs
|
dg.Extensions[emul.mac].address = 0x000102030b01
|
||||||
#d.mode = emul.Device.kNoRepeat
|
ip = dg.Extensions[emul.ip4]
|
||||||
d.mac.address = 0x000102030b01
|
ip.address = rx_ip_base
|
||||||
d.ip4.address = 0x0a010265
|
ip.prefix_length = 24
|
||||||
d.ip4.prefix_length = 24
|
ip.default_gateway = (rx_ip_base & 0xffffff00) | 0x01
|
||||||
d.ip4.default_gateway = 0x0a0a0201
|
|
||||||
|
|
||||||
drone.modifyDeviceGroup(devgrp_cfg)
|
drone.modifyDeviceGroup(devgrp_cfg)
|
||||||
|
|
||||||
@ -516,7 +529,7 @@ try:
|
|||||||
drone.deleteStream(stream_id)
|
drone.deleteStream(stream_id)
|
||||||
|
|
||||||
stream_id = ost_pb.StreamIdList()
|
stream_id = ost_pb.StreamIdList()
|
||||||
stream_id.port_id.CopyFrom(tx_port.port_id[0])
|
stream_id.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
for i in range(num_vlans):
|
for i in range(num_vlans):
|
||||||
stream_id.stream_id.add().id = i
|
stream_id.stream_id.add().id = i
|
||||||
log.info('adding tx_stream %d' % stream_id.stream_id[i].id)
|
log.info('adding tx_stream %d' % stream_id.stream_id[i].id)
|
||||||
@ -524,20 +537,20 @@ try:
|
|||||||
drone.addStream(stream_id)
|
drone.addStream(stream_id)
|
||||||
|
|
||||||
stream_cfg = ost_pb.StreamConfigList()
|
stream_cfg = ost_pb.StreamConfigList()
|
||||||
stream_cfg.port_id.CopyFrom(tx_port.port_id[0])
|
stream_cfg.port_id.CopyFrom(ports.tx.port_id[0])
|
||||||
for i in range(num_vlans):
|
for i in range(num_vlans):
|
||||||
s = stream_cfg.stream.add()
|
s = stream_cfg.stream.add()
|
||||||
s.stream_id.id = stream_id.stream_id[i].id
|
s.stream_id.id = stream_id.stream_id[i].id
|
||||||
s.core.is_enabled = True
|
s.core.is_enabled = True
|
||||||
s.core.ordinal = i
|
s.core.ordinal = i
|
||||||
s.control.packets_per_sec = 10
|
s.control.packets_per_sec = 100
|
||||||
s.control.num_packets = num_devs
|
s.control.num_packets = num_devs_per_vlan
|
||||||
|
|
||||||
# setup stream protocols as mac:vlan:eth2:ip4:udp:payload
|
# setup stream protocols as mac:vlan:eth2:ip4:udp:payload
|
||||||
p = s.protocol.add()
|
p = s.protocol.add()
|
||||||
p.protocol_id.id = ost_pb.Protocol.kMacFieldNumber
|
p.protocol_id.id = ost_pb.Protocol.kMacFieldNumber
|
||||||
p.Extensions[mac].dst_mac = dut_dst_mac
|
p.Extensions[mac].dst_mac_mode = Mac.e_mm_resolve
|
||||||
p.Extensions[mac].src_mac = 0x00aabbccddee
|
p.Extensions[mac].src_mac_mode = Mac.e_mm_resolve
|
||||||
|
|
||||||
p = s.protocol.add()
|
p = s.protocol.add()
|
||||||
p.protocol_id.id = ost_pb.Protocol.kVlanFieldNumber
|
p.protocol_id.id = ost_pb.Protocol.kVlanFieldNumber
|
||||||
@ -549,10 +562,12 @@ try:
|
|||||||
p = s.protocol.add()
|
p = s.protocol.add()
|
||||||
p.protocol_id.id = ost_pb.Protocol.kIp4FieldNumber
|
p.protocol_id.id = ost_pb.Protocol.kIp4FieldNumber
|
||||||
ip = p.Extensions[ip4]
|
ip = p.Extensions[ip4]
|
||||||
ip.src_ip = 0x0a010165
|
ip.src_ip = tx_ip_base
|
||||||
ip.src_ip_mode = Ip4.e_im_inc_host
|
ip.src_ip_mode = Ip4.e_im_inc_host
|
||||||
ip.dst_ip = 0x0a010265
|
ip.src_ip_count = num_devs_per_vlan
|
||||||
|
ip.dst_ip = rx_ip_base
|
||||||
ip.dst_ip_mode = Ip4.e_im_inc_host
|
ip.dst_ip_mode = Ip4.e_im_inc_host
|
||||||
|
ip.dst_ip_count = num_devs_per_vlan
|
||||||
|
|
||||||
p = s.protocol.add()
|
p = s.protocol.add()
|
||||||
p.protocol_id.id = ost_pb.Protocol.kUdpFieldNumber
|
p.protocol_id.id = ost_pb.Protocol.kUdpFieldNumber
|
||||||
@ -563,69 +578,119 @@ try:
|
|||||||
|
|
||||||
drone.modifyStream(stream_cfg)
|
drone.modifyStream(stream_cfg)
|
||||||
|
|
||||||
# clear tx/rx stats
|
|
||||||
log.info('clearing tx/rx stats')
|
|
||||||
drone.clearStats(tx_port)
|
|
||||||
drone.clearStats(rx_port)
|
|
||||||
|
|
||||||
# clear arp on DUT
|
# clear arp on DUT
|
||||||
for i in range(num_vlans):
|
for i in range(num_vlans):
|
||||||
vlan_id = vlan_base + i
|
vlan_id = vlan_base + i
|
||||||
vrf = 'v' + str(vlan_id)
|
vrf = 'v' + str(vlan_id)
|
||||||
vlan_rx_dev = dut_rx_port + '.' + str(vlan_id)
|
vlan_rx_dev = dut_ports.rx + '.' + str(vlan_id)
|
||||||
vlan_tx_dev = dut_tx_port + '.' + str(vlan_id)
|
vlan_tx_dev = dut_ports.tx + '.' + str(vlan_id)
|
||||||
|
|
||||||
sudo('ip netns exec ' + vrf
|
sudo('ip netns exec ' + vrf
|
||||||
+ ' ip neigh flush dev ' + vlan_rx_dev)
|
+ ' ip neigh flush all')
|
||||||
sudo('ip netns exec ' + vrf
|
arp_cache = sudo('ip netns exec ' + vrf
|
||||||
+ ' ip neigh flush dev ' + vlan_tx_dev)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip neigh show')
|
+ ' ip neigh show')
|
||||||
|
assert re.search('10.1.[1-2].20[1-5].*lladdr', arp_cache) == None
|
||||||
|
|
||||||
drone.startCapture(rx_port)
|
# resolve ARP on tx/rx ports
|
||||||
drone.startTransmit(tx_port)
|
log.info('resolving Neighbors on tx/rx ports ...')
|
||||||
log.info('waiting for transmit to finish ...')
|
drone.startCapture(emul_ports)
|
||||||
time.sleep(5)
|
drone.clearDeviceNeighbors(emul_ports)
|
||||||
drone.stopTransmit(tx_port)
|
drone.resolveDeviceNeighbors(emul_ports)
|
||||||
drone.stopCapture(rx_port)
|
time.sleep(3)
|
||||||
|
drone.stopCapture(emul_ports)
|
||||||
|
|
||||||
buff = drone.getCaptureBuffer(rx_port.port_id[0])
|
# verify ARP Requests sent out from tx port
|
||||||
|
buff = drone.getCaptureBuffer(emul_ports.port_id[0])
|
||||||
|
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||||
|
log.info('dumping Tx capture buffer (all)')
|
||||||
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
||||||
|
print(cap_pkts)
|
||||||
|
log.info('dumping Tx capture buffer (filtered)')
|
||||||
|
for i in range(num_vlans):
|
||||||
|
for j in range(num_devs_per_vlan):
|
||||||
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap',
|
||||||
|
'-R', '(vlan.id == '+str(vlan_base+i)+')'
|
||||||
|
' && (arp.opcode == 1)'
|
||||||
|
' && (arp.src.proto_ipv4 == 10.1.1.'
|
||||||
|
+str(101+j)+')'
|
||||||
|
' && (arp.dst.proto_ipv4 == 10.1.1.1)'])
|
||||||
|
print(cap_pkts)
|
||||||
|
assert cap_pkts.count('\n') == 1
|
||||||
|
|
||||||
|
# verify *no* ARP Requests sent out from rx port
|
||||||
|
buff = drone.getCaptureBuffer(emul_ports.port_id[1])
|
||||||
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||||
log.info('dumping Rx capture buffer (all)')
|
log.info('dumping Rx capture buffer (all)')
|
||||||
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
||||||
print(cap_pkts)
|
print(cap_pkts)
|
||||||
log.info('dumping Rx capture buffer (filtered)')
|
log.info('dumping Rx capture buffer (filtered)')
|
||||||
fail = 0
|
|
||||||
for i in range(num_vlans):
|
for i in range(num_vlans):
|
||||||
for j in range(num_devs):
|
for j in range(num_devs_per_vlan):
|
||||||
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap',
|
||||||
|
'-R', '(vlan.id == '+str(vlan_base+i)+')'
|
||||||
|
' && (arp.opcode == 1)'
|
||||||
|
' && (arp.src.proto_ipv4 == 10.10.2.'
|
||||||
|
+str(101+j)+')'
|
||||||
|
' && (arp.dst.proto_ipv4 == 10.10.2.1)'])
|
||||||
|
print(cap_pkts)
|
||||||
|
assert cap_pkts.count('\n') == 0
|
||||||
|
|
||||||
|
# retrieve and verify ARP Table on tx/rx ports
|
||||||
|
log.info('retrieving ARP entries on tx port')
|
||||||
|
device_list = drone.getDeviceList(emul_ports.port_id[0])
|
||||||
|
device_config = device_list.Extensions[emul.port_device]
|
||||||
|
neigh_list = drone.getDeviceNeighbors(emul_ports.port_id[0])
|
||||||
|
devices = neigh_list.Extensions[emul.devices]
|
||||||
|
log.info('ARP Table on tx port')
|
||||||
|
for dev_cfg, device in zip(device_config, devices):
|
||||||
|
resolved = False
|
||||||
|
for arp in device.arp:
|
||||||
|
# TODO: pretty print ip and mac
|
||||||
|
print('v%d|%08x: %08x %012x' %
|
||||||
|
(dev_cfg.vlan[0] & 0xffff, dev_cfg.ip4, arp.ip4, arp.mac))
|
||||||
|
if (arp.ip4 == dev_cfg.ip4_default_gateway) and (arp.mac):
|
||||||
|
resolved = True
|
||||||
|
assert resolved
|
||||||
|
|
||||||
|
log.info('retrieving ARP entries on rx port')
|
||||||
|
device_list = drone.getDeviceList(emul_ports.port_id[0])
|
||||||
|
device_config = device_list.Extensions[emul.port_device]
|
||||||
|
neigh_list = drone.getDeviceNeighbors(emul_ports.port_id[1])
|
||||||
|
devices = neigh_list.Extensions[emul.devices]
|
||||||
|
log.info('ARP Table on rx port')
|
||||||
|
for dev_cfg, device in zip(device_config, devices):
|
||||||
|
# verify *no* ARPs learnt on rx port
|
||||||
|
assert len(device.arp) == 0
|
||||||
|
for arp in device.arp:
|
||||||
|
# TODO: pretty print ip and mac
|
||||||
|
print('v%d|%08x: %08x %012x' %
|
||||||
|
(dev_cfg.vlan[0] & 0xffff, dev_cfg.ip4, arp.ip4, arp.mac))
|
||||||
|
|
||||||
|
drone.startCapture(ports.rx)
|
||||||
|
drone.startTransmit(ports.tx)
|
||||||
|
log.info('waiting for transmit to finish ...')
|
||||||
|
time.sleep(5)
|
||||||
|
drone.stopTransmit(ports.tx)
|
||||||
|
drone.stopCapture(ports.rx)
|
||||||
|
|
||||||
|
buff = drone.getCaptureBuffer(ports.rx.port_id[0])
|
||||||
|
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||||
|
log.info('dumping Rx capture buffer (all)')
|
||||||
|
cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap'])
|
||||||
|
print(cap_pkts)
|
||||||
|
log.info('dumping Rx capture buffer (filtered)')
|
||||||
|
for i in range(num_vlans):
|
||||||
|
for j in range(num_devs_per_vlan):
|
||||||
cap_pkts = subprocess.check_output(
|
cap_pkts = subprocess.check_output(
|
||||||
[tshark, '-nr', 'capture.pcap',
|
[tshark, '-nr', 'capture.pcap',
|
||||||
'-R', '(vlan.id == ' + str(201+i) + ')'
|
'-R', '(vlan.id == ' + str(vlan_base+i) + ')'
|
||||||
' && (ip.src == 10.1.1.' + str(101+j) + ') '
|
' && (ip.src == 10.1.1.' + str(101+j) + ') '
|
||||||
' && (ip.dst == 10.1.2.' + str(101+j) + ')'
|
' && (ip.dst == 10.1.2.' + str(101+j) + ')'
|
||||||
' && (eth.dst == 00:01:02:03:0b:'
|
' && (eth.dst == 00:01:02:03:0b:'
|
||||||
+ format(1+j, '02x')+')'])
|
+ format(1+j, '02x')+')'])
|
||||||
print(cap_pkts)
|
print(cap_pkts)
|
||||||
if cap_pkts.count('\n') != 1:
|
assert cap_pkts.count('\n') == 1
|
||||||
fail = fail + 1
|
|
||||||
if fail == 0:
|
|
||||||
passed = True
|
|
||||||
os.remove('capture.pcap')
|
os.remove('capture.pcap')
|
||||||
except RpcError as e:
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
drone.stopTransmit(tx_port)
|
|
||||||
# show arp on DUT
|
|
||||||
for i in range(num_vlans):
|
|
||||||
vrf = 'v' + str(vlan_base + i)
|
|
||||||
sudo('ip netns exec ' + vrf
|
|
||||||
+ ' ip neigh show')
|
|
||||||
# un-configure the DUT
|
|
||||||
for i in range(num_vlans):
|
|
||||||
vlan_id = vlan_base + i
|
|
||||||
vrf = 'v' + str(vlan_id)
|
|
||||||
sudo('ip netns delete ' + vrf)
|
|
||||||
suite.test_end(passed)
|
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
@ -639,26 +704,4 @@ try:
|
|||||||
# vlanMode: no-repeat; ip4Mode: no-repeat
|
# vlanMode: no-repeat; ip4Mode: no-repeat
|
||||||
# ----------------------------------------------------------------- #
|
# ----------------------------------------------------------------- #
|
||||||
|
|
||||||
suite.complete()
|
|
||||||
|
|
||||||
# delete stream(s)
|
|
||||||
log.info('deleting tx_stream %d' % stream_id.stream_id[0].id)
|
|
||||||
drone.deleteStream(stream_id)
|
|
||||||
|
|
||||||
# delete device(s)
|
|
||||||
dgid_list = drone.getDeviceGroupIdList(tx_port.port_id[0])
|
|
||||||
drone.deleteDeviceGroup(dgid_list)
|
|
||||||
dgid_list = drone.getDeviceGroupIdList(rx_port.port_id[0])
|
|
||||||
drone.deleteDeviceGroup(dgid_list)
|
|
||||||
|
|
||||||
# bye for now
|
|
||||||
drone.disconnect()
|
|
||||||
#disconnect_all()
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
log.exception(ex)
|
|
||||||
|
|
||||||
finally:
|
|
||||||
suite.report()
|
|
||||||
if not suite.passed:
|
|
||||||
sys.exit(2);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user