X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_l2bd.py;h=5eca48c6e9b9c3103ad51684b19be1e6376c96b8;hb=7c0eb56f4;hp=46ba2e49c13a5cd258ba9552b297e9654c606087;hpb=49c0fcabada485d4f0e4bf9e2d5e26b79bbcc645;p=vpp.git diff --git a/test/test_l2bd.py b/test/test_l2bd.py index 46ba2e49c13..5eca48c6e9b 100644 --- a/test/test_l2bd.py +++ b/test/test_l2bd.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest import random @@ -8,7 +8,7 @@ from scapy.layers.l2 import Ether, Dot1Q from scapy.layers.inet import IP, UDP from framework import VppTestCase, VppTestRunner -from util import Host +from util import Host, ppp from vpp_sub_interface import VppDot1QSubint, VppDot1ADSubint @@ -75,7 +75,7 @@ class TestL2bd(VppTestCase): for pg_if in cls.pg_interfaces: sw_if_index = pg_if.sub_if.sw_if_index \ if hasattr(pg_if, 'sub_if') else pg_if.sw_if_index - cls.vapi.sw_interface_set_l2_bridge(sw_if_index, + cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=sw_if_index, bd_id=cls.bd_id) # setup all interfaces @@ -94,12 +94,16 @@ class TestL2bd(VppTestCase): super(TestL2bd, cls).tearDownClass() raise + @classmethod + def tearDownClass(cls): + super(TestL2bd, cls).tearDownClass() + def setUp(self): """ Clear trace and packet infos before running each test. """ super(TestL2bd, self).setUp() - self.packet_infos = {} + self.reset_packet_infos() def tearDown(self): """ @@ -109,7 +113,7 @@ class TestL2bd(VppTestCase): if not self.vpp_dead: self.logger.info(self.vapi.ppcli("show l2fib verbose")) self.logger.info(self.vapi.ppcli("show bridge-domain %s detail" % - self.bd_id)) + self.bd_id)) @classmethod def create_hosts_and_learn(cls, count): @@ -122,7 +126,7 @@ class TestL2bd(VppTestCase): :param count: Integer number of hosts to create MAC/IPv4 addresses for. """ n_int = len(cls.pg_interfaces) - macs_per_if = count / n_int + macs_per_if = count // n_int i = -1 for pg_if in cls.pg_interfaces: i += 1 @@ -158,8 +162,7 @@ class TestL2bd(VppTestCase): dst_if = self.flows[src_if][i % 2] dst_host = random.choice(self.hosts_by_pg_idx[dst_if.sw_if_index]) src_host = random.choice(self.hosts_by_pg_idx[src_if.sw_if_index]) - pkt_info = self.create_packet_info( - src_if.sw_if_index, dst_if.sw_if_index) + pkt_info = self.create_packet_info(src_if, dst_if) payload = self.info_to_payload(pkt_info) p = (Ether(dst=dst_host.mac, src=src_host.mac) / IP(src=src_host.ip4, dst=dst_host.ip4) / @@ -185,7 +188,7 @@ class TestL2bd(VppTestCase): last_info[i.sw_if_index] = None dst_sw_if_index = pg_if.sw_if_index for packet in capture: - payload_info = self.payload_to_info(str(packet[Raw])) + payload_info = self.payload_to_info(packet[Raw]) src_sw_if_index = payload_info.src src_if = None for ifc in self.pg_interfaces: @@ -217,8 +220,7 @@ class TestL2bd(VppTestCase): self.assertEqual(udp.sport, saved_packet[UDP].sport) self.assertEqual(udp.dport, saved_packet[UDP].dport) except: - self.logger.error("Unexpected or invalid packet:") - self.logger.error(packet.show()) + self.logger.error(ppp("Unexpected or invalid packet:", packet)) raise for i in self.pg_interfaces: remaining_packet = self.get_next_packet_info_for_interface2( @@ -254,7 +256,7 @@ class TestL2bd(VppTestCase): Test scenario: 1.config MAC learning enabled - learn 100 MAC enries + learn 100 MAC entries 3 interfaces: untagged, dot1q, dot1ad (dot1q used instead of dot1ad in the first version) @@ -271,7 +273,7 @@ class TestL2bd(VppTestCase): Test scenario: 1.config MAC learning enabled - learn 100 MAC enries + learn 100 MAC entries 3 interfaces: untagged, dot1q, dot1ad (dot1q used instead of dot1ad in the first version)