/*
* Copyright (c) 2018 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 included_vnet_dhcp6_client_common_dp_h
#define included_vnet_dhcp6_client_common_dp_h
#include <vlib/vlib.h>
#include <vnet/dhcp/dhcp6_client_common_dp.h>
#include <vnet/dhcp/dhcp6_packet.h>
#include <vnet/vnet_msg_enum.h>
#include <vlibapi/api_common.h>
#include <vlibmemory/api.h>
#define vl_typedefs /* define message structures */
#include <vnet/vnet_all_api_h.h>
#undef vl_typedefs
#define vl_endianfun /* define message structures */
#include <vnet/vnet_all_api_h.h>
#undef vl_endianfun
/* instantiate all the print functions we know about */
#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include <vnet/vnet_all_api_h.h>
#undef vl_printfun
#include <vlibapi/api_helper_macros.h>
typedef struct
{
u32 sw_if_index;
u32 server_index;
u8 msg_type;
u32 T1;
u32 T2;
u16 inner_status_code;
u16 status_code;
u8 preference;
} dhcp6_report_common_t;
typedef struct
{
u8 *data;
u16 len;
} server_id_t;
typedef struct
{
server_id_t *server_ids;
} dhcp6_client_common_main_t;
extern dhcp6_client_common_main_t dhcp6_client_common_main;
typedef
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
#!/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
# from src/vnet/l2/l2_fib.h
MAC_EVENT_ACTION_ADD = 0
MAC_EVENT_ACTION_DELETE = 1
MAC_EVENT_ACTION_MOVE = 2
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.l2fib_flush_int(swif)
flushed[swif] = learned_hosts[swif]
learned_hosts[swif] = []
return flushed
def flush_bd(self, bd_id, learned_hosts):
"""
Flush bd_id L2 FIB entries.
:param int bd_id: Bridge Domain id.
"""
self.vapi.l2fib_flush_bd(bd_id)
flushed = dict()
ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
for pg_if in ifs:
swif = pg_if.sw_if_index
flushed[swif] = learned_hosts[swif]
learned_hosts[swif] = []
return flushed
def flush_all(self):
"""
Flush All L2 FIB entries.
"""
self.vapi.l2fib_flush_all()
def create_stream(self, src_if, packet_sizes, if_src_hosts, if_dst_hosts):
"""
Create input packet stream for defined interface using hosts or
deleted_hosts list.
:param object src_if: Interface to create packet stream for.
:param list packet_sizes: List of required packet sizes.
:param boolean deleted: Set to True if deleted_hosts list required.
:return: Stream of packets.
"""
src_hosts = if_src_hosts[src_if.sw_if_index]
if not src_hosts:
return []
pkts = []
for dst_if in self.flows[src_if]:
dst_swif = dst_if.sw_if_index
if dst_swif not in if_dst_hosts:
continue
dst_hosts = if_dst_hosts[dst_swif]
for dst_host in dst_hosts:
src_host = random.choice(src_hosts)
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) /
UDP(sport=1234, dport=1234) /
Raw(payload))
pkt_info.data = p.copy()
size = random.choice(packet_sizes)
self.extend_packet(p, size)
pkts.append(p)
return pkts
def verify_capture(self, pg_if, capture):
"""
Verify captured input packet stream for defined interface.
:param object pg_if: Interface to verify captured packet stream for.
:param list capture: Captured packet stream.
"""
last_info = dict()
for i in self.pg_interfaces:
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]))
try:
ip = packet[IP]
udp = packet[UDP]
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
(pg_if.name, payload_info.src, packet_index))
next_info = self.get_next_packet_info_for_interface2(
payload_info.src, dst_sw_if_index,
last_info[payload_info.src])
last_info[payload_info.src] = next_info
self.assertTrue(next_info is not None)
self.assertEqual(packet_index, next_info.index)
saved_packet = next_info.data
# Check standard fields
self.assertEqual(ip.src, saved_packet[IP].src)
self.assertEqual(ip.dst, saved_packet[IP].dst)
self.assertEqual(udp.sport, saved_packet[UDP].sport)
self.assertEqual(udp.dport, saved_packet[UDP].dport)
except:
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(
i, dst_sw_if_index, last_info[i.sw_if_index])
self.assertTrue(
remaining_packet is None,
"Port %u: Packet expected from source %u didn't arrive" %
(dst_sw_if_index, i.sw_if_index))
def run_verify_test(self, bd_id, src_hosts, dst_hosts):
# Test
# Create incoming packet streams for packet-generator interfaces
self.reset_packet_infos()
ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
for i in ifs:
pkts = self.create_stream(
i, self.pg_if_packet_sizes,
if_src_hosts=src_hosts,
if_dst_hosts=dst_hosts)
if pkts:
i.add_stream(pkts)
self.vapi.bridge_flags(bd_id, 0, 1)
# Enable packet capture and start packet sending
self.pg_enable_capture(ifs)
self.pg_start()
# Verify
# Verify outgoing packet streams per packet-generator interface
for i in ifs:
if not dst_hosts[i.sw_if_index]:
continue
capture = i.get_capture()
self.logger.info("Verifying capture on interface %s" % i.name)
self.verify_capture(i, capture)
def run_verify_negat_test(self, bd_id, src_hosts, dst_hosts):
# Test
# Create incoming packet streams for packet-generator interfaces for
# deleted MAC addresses
self.reset_packet_infos()
ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
for i in ifs:
pkts = self.create_stream(
i, self.pg_if_packet_sizes,
if_src_hosts=src_hosts,
if_dst_hosts=dst_hosts)
if pkts:
i.add_stream(pkts)
self.vapi.bridge_flags(bd_id, 0, 1)
# Enable packet capture and start packet sending
self.pg_enable_capture(ifs)
self.pg_start()
# Verify
# Verify outgoing packet streams per packet-generator interface
timeout = 1
for i in ifs:
i.get_capture(0, timeout=timeout)
i.assert_nothing_captured(remark="outgoing interface")
timeout = 0.1
def test_l2_fib_program100(self):
""" L2 FIB - program 100 MACs
"""
bd_id = 1
hosts = self.create_hosts(100, subnet=17)
self.config_l2_fib_entries(bd_id, hosts)
self.run_verify_test(bd_id, hosts, hosts)
def test_l2_fib_delete12(self):
""" L2 FIB - program 100 + delete 12 MACs
"""
bd_id = 1
hosts = self.create_hosts(100, subnet=17)
self.config_l2_fib_entries(bd_id, hosts)
del_hosts = self.split_hosts(hosts, 12)
self.delete_l2_fib_entry(bd_id, del_hosts)
self.run_verify_test(bd_id, hosts, hosts)
self.run_verify_negat_test(bd_id, hosts, del_hosts)
def test_l2_fib_add100_add100(self):
""" L2 FIB - program 100 + 100 MACs
"""
bd_id = 1
hosts = self.create_hosts(100, subnet=17)
self.config_l2_fib_entries(bd_id, hosts)
hosts2 = self.create_hosts(100, subnet=22)
self.config_l2_fib_entries(bd_id, hosts2)
self.run_verify_test(bd_id, hosts, hosts2)
def test_l2_fib_program10_learn10(self):
""" L2 FIB - Program 10 MACs, learn 10
"""
hosts = self.create_hosts(20, subnet=35)
lhosts = self.split_hosts(hosts, 10)
bd1 = 1
bd2 = 2
self.learn_hosts(bd1, lhosts)
self.learn_hosts(bd2, lhosts)
self.config_l2_fib_entries(bd1, hosts)
self.config_l2_fib_entries(bd2, hosts)
self.run_verify_test(bd1, lhosts, hosts)
self.run_verify_test(bd2, lhosts, hosts)
def test_l2_fib_flush_int(self):
""" L2 FIB - flush interface
"""
hosts = self.create_hosts(20, subnet=36)
lhosts = self.split_hosts(hosts, 10)
bd1 = 1
self.learn_hosts(bd1, lhosts)
self.config_l2_fib_entries(bd1, hosts)
self.run_verify_test(bd1, lhosts, hosts)
flushed = self.flush_int(self.pg_interfaces[0].sw_if_index, lhosts)
self.run_verify_test(bd1, hosts, lhosts)
self.run_verify_negat_test(bd1, hosts, flushed)
def test_l2_fib_flush_bd(self):
""" L2 FIB - flush BD
"""
hosts = self.create_hosts(20, subnet=37)
lhosts = self.split_hosts(hosts, 10)
bd1 = 1
self.learn_hosts(bd1, lhosts)
self.config_l2_fib_entries(bd1, hosts)
self.run_verify_test(bd1, lhosts, hosts)
flushed = self.flush_bd(bd1, lhosts)
self.run_verify_negat_test(bd1, hosts, flushed)
def test_l2_fib_flush_all(self):
""" L2 FIB - flush all
"""
hosts = self.create_hosts(20, subnet=38)
lhosts = self.split_hosts(hosts, 10)
bd1 = 1
bd2 = 2
self.learn_hosts(bd1, lhosts)
self.learn_hosts(bd2, lhosts)
self.config_l2_fib_entries(bd1, hosts)
self.config_l2_fib_entries(bd2, hosts)
self.run_verify_test(bd1, hosts, lhosts)
self.run_verify_test(bd2, hosts, lhosts)
self.flush_all()
self.run_verify_negat_test(bd1, hosts, lhosts)
self.run_verify_negat_test(bd2, hosts, lhosts)
def test_l2_fib_mac_learn_evs(self):
""" L2 FIB - mac learning events
"""
bd1 = 1
hosts = self.create_hosts(10, subnet=39)
self.vapi.want_macs_learn_events()
self.learn_hosts(bd1, hosts)
self.sleep(1)
self.logger.info(self.vapi.ppcli("show l2fib"))
evs = self.vapi.collect_events()
learned_macs = {
e.mac[i].mac_addr for e in evs for i in range(e.n_macs)
if e.mac[i].action == MAC_EVENT_ACTION_ADD}
macs = {h.bin_mac for swif in self.bd_ifs(bd1)
for h in hosts[self.pg_interfaces[swif].sw_if_index]}
self.vapi.want_macs_learn_events(enable_disable=0)
self.assertEqual(len(learned_macs ^ macs), 0)
def test_l2_fib_macs_learn_max(self):
""" L2 FIB - mac learning max macs in event
"""
bd1 = 1
hosts = self.create_hosts(10, subnet=40)
ev_macs = 1
self.vapi.want_macs_learn_events(max_macs_in_event=ev_macs)
self.learn_hosts(bd1, hosts)
self.sleep(1)
self.logger.info(self.vapi.ppcli("show l2fib"))
evs = self.vapi.collect_events()
self.vapi.want_macs_learn_events(enable_disable=0)
self.assertGreater(len(evs), 0)
learned_macs = {
e.mac[i].mac_addr for e in evs for i in range(e.n_macs)
if e.mac[i].action == MAC_EVENT_ACTION_ADD}
macs = {h.bin_mac for swif in self.bd_ifs(bd1)
for h in hosts[self.pg_interfaces[swif].sw_if_index]}
for e in evs:
self.assertLess(len(e), ev_macs * 10)
self.assertEqual(len(learned_macs ^ macs), 0)
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)