#!/usr/bin/env python """L2 FIB Test Case HLD: **config 1** - add 4 pg-l2 interfaces - configure them into l2bd - configure 100 MAC entries in L2 fib - 25 MACs per interface - L2 MAC learning and unknown unicast flooding disabled in l2bd - configure 100 MAC entries in L2 fib - 25 MACs per interface **test 1** - send L2 MAC frames between all 4 pg-l2 interfaces for all of 100 MAC \ entries in the FIB **verify 1** - all packets received correctly **config 2** - delete 12 MAC entries - 3 MACs per interface **test 2a** - send L2 MAC frames between all 4 pg-l2 interfaces for non-deleted MAC \ entries **verify 2a** - all packets received correctly **test 2b** - send L2 MAC frames between all 4 pg-l2 interfaces for all of 12 deleted \ MAC entries **verify 2b** - no packet received on all 4 pg-l2 interfaces **config 3** - configure new 100 MAC entries in L2 fib - 25 MACs per interface **test 3** - send L2 MAC frames between all 4 pg-l2 interfaces for all of 188 MAC \ entries in the FIB **verify 3** - all packets received correctly **config 4** - delete 160 MAC entries, 40 MACs per interface **test 4a** - send L2 MAC frames between all 4 pg-l2 interfaces for all of 28 \ non-deleted MAC entries **verify 4a** - all packets received correctly **test 4b** - try send L2 MAC frames between all 4 pg-l2 interfaces for all of 172 \ deleted MAC entries **verify 4b** - no packet received on all 4 pg-l2 interfaces """ 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 class TestL2fib(VppTestCase): """ L2 FIB Test Case """ @classmethod def bd_ifs(cls, bd_id): return range((bd_id - 1) * cls.n_ifs_per_bd, bd_id * cls.n_ifs_per_bd) @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. :var int bd_id: Bridge domain ID. """ super(TestL2fib, cls).setUpClass() try: n_brs = cls.n_brs = range(1, 3) cls.n_ifs_per_bd = 4 n_ifs = range(cls.n_ifs_per_bd * len(cls.n_brs)) # Create 4 pg interfaces cls.create_pg_interfaces(n_ifs) cls.flows = dict() for bd_id in n_brs: # Packet flows mapping pg0 -> pg1, pg2, pg3 etc. ifs = cls.bd_ifs(bd_id) for j in ifs: cls.flows[cls.pg_interfaces[j]] = [ cls.pg_interfaces[x] for x in ifs if x != j] # Packet sizes cls.pg_if_packet_sizes = [64, 512, 1518, 9018] for bd_id in n_brs: # Create BD with MAC learning and unknown unicast flooding # disabled and put interfaces to this BD cls.vapi.bridge_domain_add_del( bd_id=bd_id, uu_flood=0, learn=0) ifs = [cls.pg_interfaces[i] for i in cls.bd_ifs(bd_id)] for pg_if in ifs: cls.vapi.sw_interface_set_l2_bridge(pg_if.sw_if_index, bd_id=bd_id) # Set up all interfaces for i in cls.pg_interfaces: i.admin_up() except Exception: super(TestL2fib, cls).tearDownClass() raise def setUp(self): super(TestL2fib, self).setUp() self.reset_packet_infos() def tearDown(self): """ Show various debug prints after each test. """ super(TestL2fib, self).tearDown() if not self.vpp_dead: self.logger.info(self.vapi.ppcli("show l2fib verbose")) for bd_id in self.n_brs: self.logger.info(self.vapi.ppcli("show bridge-domain %s detail" % bd_id)) def create_hosts(self, n_hosts_per_if, subnet): """ Create required number of host MAC addresses and distribute them among interfaces. Create host IPv4 address for every host MAC address. :param int n_hosts_per_if: Number of per interface hosts to create MAC/IPv4 addresses for. """ hosts = dict() for pg_if in self.pg_interfaces: swif = pg_if.sw_if_index def mac(j): return "00:00:%02x:ff:%02x:%02x" % (subnet, swif, j) def ip(j): return "172.%02u.1%02x.%u" % (subnet, swif, j) def h(j): return Host(mac(j), ip(j)) hosts[swif] = [h(j) for j in range(n_hosts_per_if)] return hosts def split_hosts(self, hosts, n): splits = dict() for pg_if in self.pg_interfaces: swif = pg_if.sw_if_index splits[swif] = hosts[swif][:n] hosts[swif] = hosts[swif][n:] return splits def learn_hosts(self, bd_id, hosts): """ Create and send per interface L2 MAC broadcast packet stream to let the bridge domain learn these MAC addresses. :param int bd_id: BD to teach :param dict hosts: dict of hosts per interface """ self.vapi.bridge_flags(bd_id, 1, 1) ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] for pg_if in ifs: swif = pg_if.sw_if_index packets = [Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac) for host in hosts[swif]] pg_if.add_stream(packets) self.logger.info("Sending broadcast eth frames for MAC learning") self.pg_start() def config_l2_fib_entries(self, bd_id, hosts): """ Config required number of L2 FIB entries. :param int bd_id: BD's id :param int count: Number of L2 FIB entries to be created. :param int start: Starting index of the host list. (Default value = 0) """ ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] for pg_if in ifs: swif = pg_if.sw_if_index for host in hosts[swif]: self.vapi.l2fib_add_del( host.mac, bd_id, swif, static_mac=1) def delete_l2_fib_entry(self, bd_id, hosts): """ Delete required number of L2 FIB entries. :param int count: Number of L2 FIB entries to be created. """ ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] for pg_if in ifs: swif = pg_if.sw_if_index for host in hosts[swif]: self.vapi.l2fib_add_del( host.mac, bd_id, swif, is_add=0) def flush_int(self, swif, learned_hosts): """ Flush swif L2 FIB entries. :param int swif: sw if index. """ flushed = dict() self.vapi.l2
/*
* Copyright (c) 2019 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.
*/
#ifndef SRC_VNET_SESSION_APPLICATION_LOCAL_H_
#define SRC_VNET_SESSION_APPLICATION_LOCAL_H_
#include <vnet/session/application.h>
#include <vnet/session/transport.h>
#define foreach_ct_flags \
_ (CLIENT, "client") \
_ (HALF_OPEN, "half-open")
enum
{
#define _(sym, str) CT_CONN_BIT_F_##sym,
foreach_ct_flags
#undef _
};
typedef enum
{
#define _(sym, str) CT_CONN_F_##sym = 1 << CT_CONN_BIT_F_##sym,
fore