#!/usr/bin/env python3 import unittest import binascii from socket import AF_INET6 from framework import VppTestCase, VppTestRunner from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto, VppIpTable from vpp_srv6 import ( SRv6LocalSIDBehaviors, VppSRv6LocalSID, VppSRv6Policy, SRv6PolicyType, VppSRv6Steering, SRv6PolicySteeringTypes, ) import scapy.compat from scapy.packet import Raw from scapy.layers.l2 import Ether, Dot1Q from scapy.layers.inet6 import IPv6, UDP, IPv6ExtHdrSegmentRouting from scapy.layers.inet import IP, UDP from util import ppp class TestSRv6As(VppTestCase): """SRv6 Static Proxy plugin Test Case""" @classmethod def setUpClass(self): super(TestSRv6As, self).setUpClass() @classmethod def tearDownClass(cls): super(TestSRv6As, cls).tearDownClass() def setUp(self): """Perform test setup before each test case.""" super(TestSRv6As, self).setUp() # packet sizes, inclusive L2 overhead self.pg_packet_sizes = [64, 512, 1518, 9018] # reset packet_infos self.reset_packet_infos() def tearDown(self): """Clean up test setup after each test case.""" self.teardown_interfaces() super(TestSRv6As, self).tearDown() def configure_interface( self, interface, ipv6=False, ipv4=False, ipv6_table_id=0, ipv4_table_id=0 ): """Configure interface. :param ipv6: configure IPv6 on interface :param ipv4: configure IPv4 on interface :param ipv6_table_id: FIB table_id for IPv6 :param ipv4_table_id: FIB table_id for IPv4 """ self.logger.debug("Configuring interface %s" % (interface.name)) if ipv6: self.logger.debug("Configuring IPv6") interface.set_table_ip6(ipv6_table_id) interface.config_ip6() interface.resolve_ndp(timeout=5) if ipv4: self.logger.debug("Configuring IPv4") interface.set_table_ip4(ipv4_table_id) interface.config_ip4() interface.resolve_arp() interface.admin_up() def setup_interfaces(self, ipv6=[], ipv4=[], ipv6_table_id=[], ipv4_table_id=[]): """Create and configure interfaces. :param ipv6: list of interface IPv6 capabilities :param ipv4: list of interface IPv4 capabilities :param ipv6_table_id: list of intf IPv6 FIB table_ids :param ipv4_table_id: list of intf IPv4 FIB table_ids :returns: List of created interfaces. """ # how many interfaces? if len(ipv6): count = len(ipv6) else: count = len(ipv4) self.logger.debug("Creating and configuring %d interfaces" % (count)) # fill up ipv6 and ipv4 lists if needed # not enabled (False) is the default if len(ipv6) < count: ipv6 += (count - len(ipv6)) * [False] if len(ipv4) < count: ipv4 += (count - len(ipv4)) * [False] # fill up table_id lists if needed # table_id 0 (global) is the default if len(ipv6_table_id) < count: ipv6_table_id += (count - len(ipv6_table_id)) * [0] if len(ipv4_table_id) < count: ipv4_table_id += (count - len(ipv4_table_id)) * [0] # create 'count' pg interfaces self.create_pg_interfaces(range(count)) # setup all interfaces for i in range(count): intf = self.pg_interfaces[i] self.configure_interface( intf, ipv6[i], ipv4[i], ipv6_table_id[i], ipv4_table_id[i] ) if any(ipv6): self.logger.debug(self.vapi.cli("show ip6 neighbors")) if any(ipv4): self.logger.debug(self.vapi.cli("show ip4 neighbors")) self.logger.debug(self.vapi.cli("show interface")) self.logger.debug(self.vapi.cli("show hardware")) return self.pg_interfaces def teardown_interfaces(self): """Unconfigure and bring down interface.""" self.logger.debug("Tearing down interfaces") # tear down all interfaces # AFAIK they cannot be deleted for i in self.pg_interfaces: self.logger.debug("Tear down interface %s" % (i.name)) i.admin_down() i.unconfig() i.set_table_ip4(0) i.set_table_ip6(0) def test_SRv6_End_AS_IPv6_noSRH(self): """Test SRv6 End.AS behavior with IPv6 traffic and no SRH rewrite.""" self.run_SRv6_End_AS_IPv6( sid_list=["a1::", "a2::a6", "a3::"], test_sid_index=1, rewrite_src_addr="a2::", ) def test_SRv6_End_AS_IPv6_SRH(self): """Test SRv6 End.AS behavior with IPv6 traffic and SRH rewrite.""" self.run_SRv6_End_AS_IPv6( sid_list=["a1::a6", "a2::", "a3::"], test_sid_index=0, rewrite_src_addr="a1::", ) def test_SRv6_End_AS_IPv4_noSRH(self): """Test SRv6 End.AS behavior with IPv4 traffic and no SRH rewrite.""" self.run_SRv6_End_AS_IPv4( sid_list=["a1::", "a2::a6", "a3::"], test_sid_index=1, rewrite_src_addr="a2::", ) def test_SRv6_End_AS_IPv4_SRH(self): """Test SRv6 End.AS behavior with IPv4 traffic and SRH rewrite.""" self.run_SRv6_End_AS_IPv4( si
/*
* Copyright (c) 2016 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
@dir
@brief Inband OAM (iOAM) implementation
*/