#!/usr/bin/env python """L2BD Multi-instance Test Case HLD: **NOTES:** - higher number of pg-l2 interfaces causes problems => only 15 pg-l2 \ interfaces in 5 bridge domains are tested - jumbo packets in configuration with 14 l2-pg interfaces leads to \ problems too **config 1** - add 15 pg-l2 interfaces - configure one host per pg-l2 interface - configure 5 bridge domains (BD) - add 3 pg-l2 interfaces per BD **test 1** - send L2 MAC frames between all pg-l2 interfaces of all BDs **verify 1** - check BD data by parsing output of bridge_domain_dump API command - all packets received correctly **config 2** - update data of 5 BD - disable learning, forwarding, flooding and uu_flooding for BD1 - disable forwarding for BD2 - disable flooding for BD3 - disable uu_flooding for BD4 - disable learning for BD5 **verify 2** - check BD data by parsing output of bridge_domain_dump API command **config 3** - delete 2 BDs **test 3** - send L2 MAC frames between all pg-l2 interfaces of all BDs - send L2 MAC frames between all pg-l2 interfaces formerly assigned to \ deleted BDs **verify 3** - check BD data by parsing output of bridge_domain_dump API command - all packets received correctly on all 3 pg-l2 interfaces assigned to BDs - no packet received on all 3 pg-l2 interfaces of all deleted BDs **config 4** - add 2 BDs - add 3 pg-l2 interfaces per BD **test 4** - send L2 MAC frames between all pg-l2 interfaces of all BDs **verify 4** - check BD data by parsing output of bridge_domain_dump API command - all packets received correctly **config 5** - delete 5 BDs **verify 5** - check BD data by parsing output of bridge_domain_dump API command """ import unittest import random from scapy.packet import Raw from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP from framework import VppTestCase, VppTestRunner from util import Host, ppp @unittest.skip("Crashes VPP") class TestL2bdMultiInst(VppTestCase): """ L2BD Multi-instance Test Case """ @classmethod def setUpClass(cls): """ Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP. """ super(TestL2bdMultiInst, cls).setUpClass() try: # Create pg interfaces cls.create_pg_interfaces(range(15)) # Packet flows mapping pg0 -> pg1, pg2 etc. cls.flows = dict() for i in range(0, len(cls.pg_interfaces), 3): cls.flows[cls.pg_interfaces[i]] = [cls.pg_interfaces[i + 1], cls.pg_interfaces[i + 2]] cls.flows[cls.pg_interfaces[i + 1]] = [cls.pg_interfaces[i], cls.pg_interfaces[i + 2]] cls.flows[cls.pg_interfaces[i + 2]] = [cls.pg_interfaces[i], cls.pg_interfaces[i + 1]] # Mapping between packet-generator index and lists of test hosts cls.hosts_by_pg_idx = dict() for pg_if in cls.pg_interfaces: cls.hosts_by_pg_idx[pg_if.sw_if_index] = [] # Create test host entries cls.create_hosts(75) # Packet sizes - jumbo packet (9018 bytes) skipped cls.pg_if_packet_sizes = [64, 512, 1518] # Set up all interfaces for i in cls.pg_interfaces: i.admin_up() # Create list of BDs cls.bd_list = list() # Create list of deleted BDs cls.bd_deleted_list = list() # Create list of pg_interfaces in BDs cls.pg_in_bd = list() # Create list of pg_interfaces not in BDs cls.pg_not_in_bd = list() for pg_if in cls.pg_interfaces: cls.pg_not_in_bd.append(pg_if) except Exception: super(TestL2bdMultiInst, cls).tearDownClass() raise def setUp(self): """ Clear trace and packet infos before running each test. """ super(TestL2bdMultiInst, self).setUp() def tearDown(self): """ Show various debug prints after each test. """ super(TestL2bdMultiInst, self).tearDown() if not self.vpp_dead: self.logger.info(self.vapi.ppcli("show l2fib verbose")) self.logger.info(self.vapi.ppcli("show bridge-domain")) @classmethod def create_hosts(cls, count): """ Create required number of host MAC addresses and distribute them among interfaces. Create host IPv4 address for every host MAC address. :param int count: Number of hosts to create MAC/IPv4 addresses for. """ n_int = len(cls.pg_interfaces) macs_per_if = count / n_int i = -1 for pg_if in cls.pg_interfaces: i += 1 start_nr = macs_per_if * i end_nr = count if i == (n_int - 1) else macs_per_if * (i + 1) hosts = cls.hosts_by_pg_idx[pg_if.sw_if_index] for j in range(start_nr, end_nr): host = Host( "00:00:00:ff:%02x:%02x" % (pg_if.sw_if_index, j), "172.17.1%02u.%u" % (pg_if.sw_if_index, j)) hosts.append(host) def create_bd_and_mac_learn(self, count, start=1): """ Create required number of bridge domains with MAC learning enabled, put 3 l2-pg interfaces to every bridge domain and send MAC learning packets. :param int count: Number of bridge domains to be created. :param int start: Starting number of the bridge domain ID. (Default value = 1) """ for i in range(count): bd_id = i + start self.vapi.bridge_domain_add_del(bd_id=bd_id) self.logger.info("Bridge domain ID %d created" % bd_id) if self.bd_list.count(bd_id) == 0
from trex_stl_lib.api import *
class STLS1(object):
def create_stream (self):
base_pkt = Ether()/IP(src="2.2.0.1")/UDP(sport=12)
pad = Padding()
if len(base_pkt) < 64:
pad_len = 64 - len(base_pkt)
pad.load = '\x00' * pad_len
vm = STLVM()
vm.tuple_var(name="tuple", ip_min="173.16.1.3", ip_max="173.16.40.18", port_min=1025, port_max=1124, limit_flows = 1000000)
vm.write(fv_name="tuple.ip", pkt_offset="IP.dst")
vm.fix_chksum()
vm.write(fv_name="tuple.port", pkt_offset="UDP.dport")
pkt = STLPktBuilder(pkt