X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_punt.py;h=e6829d42bb3cc3684f66f9bef39f5123dabed27e;hb=728606591135982f4677e51f668e18bd1a3873bb;hp=f33ab4ce3d5a2e649e0419eecb3d9bc687ea7843;hpb=d9b0c6fbf7aa5bd9af84264105b39c82028a4a29;p=vpp.git diff --git a/test/test_punt.py b/test/test_punt.py index f33ab4ce3d5..e6829d42bb3 100644 --- a/test/test_punt.py +++ b/test/test_punt.py @@ -1,33 +1,28 @@ #!/usr/bin/env python3 -import binascii import random import socket import os import threading -import struct import copy import fcntl import time -from struct import unpack, unpack_from - try: import unittest2 as unittest except ImportError: import unittest -from util import ppp, ppc -from re import compile -import scapy.compat from scapy.packet import Raw from scapy.layers.l2 import Ether +from scapy.layers.l2 import Dot1Q from scapy.layers.inet import IP, UDP, ICMP from scapy.layers.ipsec import ESP import scapy.layers.inet6 as inet6 -from scapy.layers.inet6 import IPv6, ICMPv6DestUnreach +from scapy.layers.inet6 import IPv6 from scapy.contrib.ospf import OSPF_Hdr, OSPFv3_Hello -from framework import tag_fixme_vpp_workers -from framework import VppTestCase, VppTestRunner +from framework import VppTestCase +from asfframework import VppTestRunner, tag_fixme_vpp_workers +from vpp_sub_interface import VppDot1QSubint from vpp_ip import DpoProto from vpp_ip_route import VppIpRoute, VppRoutePath @@ -108,7 +103,7 @@ class TestPuntSocket(VppTestCase): @classmethod def setUpConstants(cls): - cls.extra_vpp_punt_config = [ + cls.extra_vpp_config = [ "punt", "{", "socket", @@ -1015,6 +1010,86 @@ class TestIpProtoPuntSocket(TestPuntSocket): self.vapi.punt_socket_deregister(punt_ospf) +class TestDot1QPuntSocket(TestPuntSocket): + """Punt Socket for 802.1Q (dot1q)""" + + def setUp(self): + super(TestDot1QPuntSocket, self).setUp() + + for i in self.pg_interfaces: + i.admin_up() + i.config_ip4() + i.resolve_arp() + + def tearDown(self): + super(TestDot1QPuntSocket, self).tearDown() + for i in self.pg_interfaces: + i.unconfig_ip4() + i.admin_down() + + def test_dot1q_header_punt(self): + """Punt socket traffic with Dot1q header""" + + port = self.ports[0] + pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 + punt_l4 = set_port(mk_vpp_cfg4(), port) + + # VLAN ID + vlan_id = 100 + + # Create a subinterface with the VLAN ID + subif = VppDot1QSubint(self, self.pg0, vlan_id) + subif.admin_up() + subif.config_ip4() + + # Configure an IP address on the subinterface + subif_ip4 = subif.local_ip4 + + p = ( + Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) + / Dot1Q(vlan=vlan_id) + / IP(src=self.pg0.remote_ip4, dst=subif_ip4) + / UDP(sport=9876, dport=port) + / Raw(b"\xa5" * 100) + ) + + pkts = p * self.nr_packets + + # Expect ICMP - port unreachable for all packets + rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) + + for p in rx: + self.assertEqual(int(p[IP].proto), 1) # ICMP + self.assertEqual(int(p[ICMP].code), 3) # unreachable + + # Configure a punt socket + self.socket_client_create("%s/socket_%d" % (self.tempdir, port)) + self.vapi.punt_socket_register(punt_l4, "%s/socket_%d" % (self.tempdir, port)) + punts = self.vapi.punt_socket_dump(type=pt_l4) + self.assertEqual(len(punts), 1) + + # Expect punt socket and no packets on pg0 + self.send_and_assert_no_replies(self.pg0, pkts) + rx = self.socket_client_close() + self.logger.info("RXPKT") + self.logger.info(rx) + self.verify_udp_pkts(rx, len(pkts), port) + for pkt in rx: + self.assertEqual(pkt[Ether].src, self.pg0.remote_mac) + self.assertEqual(pkt[Ether].dst, self.pg0.local_mac) + self.assertEqual(pkt[Dot1Q].vlan, 100) + + # Remove punt socket. Expect ICMP - port unreachable for all packets + self.vapi.punt_socket_deregister(punt_l4) + punts = self.vapi.punt_socket_dump(type=pt_l4) + self.assertEqual(len(punts), 0) + + rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) + for p in rx: + self.assertEqual(int(p[IP].proto), 1) # ICMP + self.assertEqual(int(p[ICMP].code), 3) # unreachable + + @tag_fixme_vpp_workers class TestPunt(VppTestCase): """Exception Punt Test Case"""