#!/usr/bin/env python import unittest from socket import AF_INET6 from framework import VppTestCase, VppTestRunner from vpp_sub_interface import VppSubInterface, VppDot1QSubint from vpp_pg_interface import is_ipv6_misc from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \ VppMRoutePath, MRouteItfFlags, MRouteEntryFlags from vpp_neighbor import find_nbr, VppNeighbor from scapy.packet import Raw from scapy.layers.l2 import Ether, Dot1Q from scapy.layers.inet6 import IPv6, UDP, ICMPv6ND_NS, ICMPv6ND_RS, \ ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr, getmacbyip6, ICMPv6MRD_Solicitation, \ ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \ ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types from util import ppp from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \ in6_mactoifaceid, in6_ismaddr from scapy.utils import inet_pton, inet_ntop def mk_ll_addr(mac): euid = in6_mactoifaceid(mac) addr = "fe80::" + euid return addr class TestIPv6ND(VppTestCase): def validate_ra(self, intf, rx, dst_ip=None): if not dst_ip: dst_ip = intf.remote_ip6 # unicasted packets must come to the unicast mac self.assertEqual(rx[Ether].dst, intf.remote_mac) # and from the router's MAC self.assertEqual(rx[Ether].src, intf.local_mac) # the rx'd RA should be addressed to the sender's source self.assertTrue(rx.haslayer(ICMPv6ND_RA)) self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) # and come from the router's link local self.assertTrue(in6_islladdr(rx[IPv6].src)) self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(mk_ll_addr(intf.local_mac))) def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None): if not dst_ip: dst_ip = intf.remote_ip6 if not tgt_ip: dst_ip = intf.local_ip6 # unicasted packets must come to the unicast mac self.assertEqual(rx[Ether].dst, intf.remote_mac) # and from the router's MAC self.assertEqual(rx[Ether].src, intf.local_mac) # the rx'd NA should be addressed to the sender's source self.assertTrue(rx.haslayer(ICMPv6ND_NA)) self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) # and come from the target address self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip)) # Dest link-layer options should have the router's MAC dll = rx[ICMPv6NDOptDstLLAddr] self.assertEqual(dll.lladdr, intf.local_mac) def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, filter_out_fn=is_ipv6_misc): intf.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = intf.get_capture(1, filter_out_fn=filter_out_fn) self.assertEqual(len(rx), 1) rx = rx[0] self.validate_ra(intf, rx, dst_ip) def send_and_expect_na(self, intf, pkts, remark, dst_ip=None, tgt_ip=None, filter_out_fn=is_ipv6_misc): intf.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = intf.get_capture(1, filter_out_fn=filter_out_fn) self.assertEqual(len(rx), 1) rx = rx[0] self.validate_na(intf, rx, dst_ip, tgt_ip) def send_and_assert_no_replies(self, intf, pkts, remark): intf.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() for i in self.pg_interfaces: i.get_capture(0) i.assert_nothing_captured(remark=remark) class TestIPv6(TestIPv6ND): """ IPv6 Test Case """ @classmethod def setUpClass(cls): super(TestIPv6, cls).setUpClass() def setUp(self): """ Perform test setup before test case. **Config:** - create 3 pg interfaces - untagged pg0 interface - Dot1Q subinterface on pg1 - Dot1AD subinterface on pg2 - setup interfaces: - put it into UP state - set IPv6 addresses - resolve neighbor address using NDP - configure 200 fib entries :ivar list interfaces: pg interfaces and subinterfaces. :ivar dict flows: IPv4 packet flows in test. :ivar list pg_if_packet_sizes: packet sizes in test. *TODO:* Create AD sub interface """ super(TestIPv6, self).setUp() # create 3 pg interfaces self.create_pg_interfaces(range(3)) # create 2 subinterfaces for p1 and pg2 self.sub_interfaces = [ VppDot1QSubint(self, self.pg1, 100), VppDot1QSubint(self, self.pg2, 200) # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400) ] # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. self.flows = dict() self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] # packet sizes self.pg_if_packet_sizes = [64, 512, 1518, 9018] self.sub_if_packet_sizes = [64, 512, 1518 + 4, 9018 + 4] self.interfaces = list(self.pg_interfaces) self.interfaces.extend(self.sub_interfaces) # setup all interfaces for i in self.interfaces: i.admin_up() i.config_ip6() i.resolve_ndp() # config 2M FIB entries self.config_fib_entries(200) def tearDown(self): """Run standard test teardown and log ``show ip6 neighbors``.""" for i in self.sub_interfaces: i.unconfig_ip6() i.ip6_disable() i.admin_down() i.remove_vpp_config() super(TestIPv6, self).tearDown() if not self.vpp_dead: self.logger.info(self.vapi.cli("show ip6 neighbors")) # info(self.vapi.cli("show ip6 fib")) # many entries def config_fib_entries(self, count): """For each interface add to the FIB table *count* routes to "fd02::1/128" destination with interface's local address as next-hop address. :param int count: Number of FIB entries. - *TODO:* check if the next-hop address shouldn't be remote address instead of local address. """ n_int = len(self.interfaces) percent = 0 counter = 0.0 dest_addr = inet_pton(AF_INET6, "fd02::1") dest_addr_len = 128 for i in self.interfaces: next_hop_address = i.local_ip6n for j in range(count / n_int): self.vapi.ip_add_del_route( dest_addr, dest_addr_len, next_hop_address, is_ipv6=1) counter += 1 if counter / count * 100 > percent: self.logger.info("Configure %d FIB entries .. %d%% done" % (count, percent)) percent += 1 def create_stream(self, src_if, packet_sizes): """Create input packet stream for defined interface. :param VppInterface src_if: Interface to create packet stream for. :param list packet_sizes: Required packet sizes. """ pkts = [] for i in range(0, 257): dst_if = self.flows[src_if][i % 2] info = self.create_packet_info(src_if, dst_if) payload = self.info_to_payload(info) p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) / UDP(sport=1234, dport=1234) / Raw(payload)) info.data = p.copy() if isinstance(src_if, VppSubInterface): p = src_if.add_dot1_layer(p) size = packet_sizes[(i // 2) % len(packet_sizes)] self.extend_packet(p, size) pkts.append(p) return pkts def verify_capture(self, dst_if, capture): """Verify captured input packet stream for defined interface. :param VppInterface dst_if: Interface to verify captured packet stream for. :param list capture: Captured packet stream. """ self.logger.info("Verifying capture on interface %s" % dst_if.name) last_info = dict() for i in self.interfaces: last_info[i.sw_if_index] = None is_sub_if = False dst_sw_if_index = dst_if.sw_if_index if hasattr(dst_if, 'parent'): is_sub_if = True for packet in capture: if is_sub_if: # Check VLAN tags and Ethernet header packet = dst_if.remove_dot1_layer(packet) self.assertTrue(Dot1Q not in packet) try: ip = packet[IPv6] udp = packet[UDP] payload_info = self.payload_to_info(str(packet[Raw])) 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)" % (dst_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[IPv6].src) self.assertEqual(ip.dst, saved_packet[IPv6].dst) self.assertEqual(udp.sport, saved_packet[UDP].sport) self.assertEqual(
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/stable/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------

project = u'Vector Packet Processor'
copyright = u'2018, Linux Foundation'
author = u'John DeNisco'

# The short X.Y version
version = u''
# The full version, including alpha/beta/rc tags
release = u'1.0'


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = ['.rst', '.md']
source_parsers = {
   '.md': 'recommonmark.parser.CommonMarkParser',
}
# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'default'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#

# import sphinx_theme

html_theme = "sphinx_rtd_theme"
# html_theme = 'neo_rtd_theme'

html_theme_path = ["_themes", ]
# html_theme_path = [sphinx_theme.get_html_theme_path('neo-rtd-theme')]

# All available themes:
# print(sphinx_theme.THEME_LIST)
# >> ['stanford_theme', 'neo_rtd_theme']

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = '_static/fd-io_red_white.png'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

def setup(app):
    app.add_stylesheet('css/rules.css')

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Vector Packet Processor'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'Vector Packet Processor.tex', u'Vector Packet Processor Documentation',
     u'John DeNisco', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'Vector Packet Processor', u'Vector Packet Processor Documentation',
     [author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'Vector Packet Processor', u'Vector Packet Processor Documentation',
     author, 'Vector Packet Processor', 'One line description of project.',
     'Miscellaneous'),
]


# -- Extension configuration -------------------------------------------------
(self.pg1, ns_pg1, "NS to proxy entry", dst_ip=self.pg0._remote_hosts[2].ip6, tgt_ip=self.pg0.local_ip6) # # ... and that we have an entry in the ND cache # self.assertTrue(find_nbr(self, self.pg1.sw_if_index, self.pg0._remote_hosts[2].ip6, inet=AF_INET6)) # # ... and we can route traffic to it # t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0.remote_ip6) / UDP(sport=10000, dport=20000) / Raw('\xa5' * 100)) self.pg0.add_stream(t) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg1.get_capture(1) rx = rx[0] self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) self.assertEqual(rx[Ether].src, self.pg1.local_mac) self.assertEqual(rx[IPv6].src, t[IPv6].src) self.assertEqual(rx[IPv6].dst, t[IPv6].dst) # # Test we proxy for the host on the main interface # ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / IPv6(dst=d, src=self.pg0.remote_ip6) / ICMPv6ND_NS(tgt=self.pg0._remote_hosts[2].ip6) / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) self.send_and_expect_na(self.pg0, ns_pg0, "NS to proxy entry on main", tgt_ip=self.pg0._remote_hosts[2].ip6, dst_ip=self.pg0.remote_ip6) # # Setup and resolve proxy for another host on another interface # ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) / IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6) / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac)) self.vapi.ip6_nd_proxy( inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), self.pg2.sw_if_index) self.send_and_expect_na(self.pg2, ns_pg2, "NS to proxy entry other interface", dst_ip=self.pg0._remote_hosts[3].ip6, tgt_ip=self.pg0.local_ip6) self.assertTrue(find_nbr(self, self.pg2.sw_if_index, self.pg0._remote_hosts[3].ip6, inet=AF_INET6)) # # hosts can communicate. pg2->pg1 # t2 = (Ether(dst=self.pg2.local_mac, src=self.pg0.remote_hosts[3].mac) / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0._remote_hosts[3].ip6) / UDP(sport=10000, dport=20000) / Raw('\xa5' * 100)) self.pg2.add_stream(t2) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg1.get_capture(1) rx = rx[0] self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) self.assertEqual(rx[Ether].src, self.pg1.local_mac) self.assertEqual(rx[IPv6].src, t2[IPv6].src) self.assertEqual(rx[IPv6].dst, t2[IPv6].dst) # # remove the proxy configs # self.vapi.ip6_nd_proxy( inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), self.pg1.sw_if_index, is_del=1) self.vapi.ip6_nd_proxy( inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), self.pg2.sw_if_index, is_del=1) self.assertFalse(find_nbr(self, self.pg2.sw_if_index, self.pg0._remote_hosts[3].ip6, inet=AF_INET6)) self.assertFalse(find_nbr(self, self.pg1.sw_if_index, self.pg0._remote_hosts[2].ip6, inet=AF_INET6)) # # no longer proxy-ing... # self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured") self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured") self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured") # # no longer forwarding. traffic generates NS out of the glean/main # interface # self.pg2.add_stream(t2) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg0.get_capture(1) self.assertTrue(rx[0].haslayer(ICMPv6ND_NS)) class TestIPNull(VppTestCase): """ IPv6 routes via NULL """ def setUp(self): super(TestIPNull, self).setUp() # create 2 pg interfaces self.create_pg_interfaces(range(1)) for i in self.pg_interfaces: i.admin_up() i.config_ip6() i.resolve_ndp() def tearDown(self): super(TestIPNull, self).tearDown() for i in self.pg_interfaces: i.unconfig_ip6() i.admin_down() def test_ip_null(self): """ IP NULL route """ p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src=self.pg0.remote_ip6, dst="2001::1") / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) # # A route via IP NULL that will reply with ICMP unreachables # ip_unreach = VppIpRoute(self, "2001::", 64, [], is_unreach=1, is_ip6=1) ip_unreach.add_vpp_config() self.pg0.add_stream(p) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg0.get_capture(1) rx = rx[0] icmp = rx[ICMPv6DestUnreach] # 0 = "No route to destination" self.assertEqual(icmp.code, 0) # ICMP is rate limited. pause a bit self.sleep(1) # # A route via IP NULL that will reply with ICMP prohibited # ip_prohibit = VppIpRoute(self, "2001::1", 128, [], is_prohibit=1, is_ip6=1) ip_prohibit.add_vpp_config() self.pg0.add_stream(p) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg0.get_capture(1) rx = rx[0] icmp = rx[ICMPv6DestUnreach] # 1 = "Communication with destination administratively prohibited" self.assertEqual(icmp.code, 1) class TestIPDisabled(VppTestCase): """ IPv6 disabled """ def setUp(self): super(TestIPDisabled, self).setUp() # create 2 pg interfaces self.create_pg_interfaces(range(2)) # PG0 is IP enalbed self.pg0.admin_up() self.pg0.config_ip6() self.pg0.resolve_ndp() # PG 1 is not IP enabled self.pg1.admin_up() def tearDown(self): super(TestIPDisabled, self).tearDown() for i in self.pg_interfaces: i.unconfig_ip4() i.admin_down() def send_and_assert_no_replies(self, intf, pkts, remark): intf.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() for i in self.pg_interfaces: i.get_capture(0) i.assert_nothing_captured(remark=remark) def test_ip_disabled(self): """ IP Disabled """ # # An (S,G). # one accepting interface, pg0, 2 forwarding interfaces # route_ff_01 = VppIpMRoute( self, "::", "ffef::1", 128, MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, [VppMRoutePath(self.pg1.sw_if_index, MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), VppMRoutePath(self.pg0.sw_if_index, MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)], is_ip6=1) route_ff_01.add_vpp_config() pu = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IPv6(src="2001::1", dst=self.pg0.remote_ip6) / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) pm = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IPv6(src="2001::1", dst="ffef::1") / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) # # PG1 does not forward IP traffic # self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") # # IP enable PG1 # self.pg1.config_ip6() # # Now we get packets through # self.pg1.add_stream(pu) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg0.get_capture(1) self.pg1.add_stream(pm) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg0.get_capture(1) # # Disable PG1 # self.pg1.unconfig_ip6() # # PG1 does not forward IP traffic # self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") class TestIP6LoadBalance(VppTestCase): """ IPv6 Load-Balancing """ def setUp(self): super(TestIP6LoadBalance, self).setUp() self.create_pg_interfaces(range(5)) for i in self.pg_interfaces: i.admin_up() i.config_ip6() i.resolve_ndp() def tearDown(self): super(TestIP6LoadBalance, self).tearDown() for i in self.pg_interfaces: i.unconfig_ip6() i.admin_down() def send_and_expect_load_balancing(self, input, pkts, outputs): input.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() for oo in outputs: rx = oo._get_capture(1) self.assertNotEqual(0, len(rx)) def test_ip6_load_balance(self): """ IPv6 Load-Balancing """ # # An array of packets that differ only in the destination port # port_pkts = [] # # An array of packets that differ only in the source address # src_pkts = [] for ii in range(65): port_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(dst="3000::1", src="3000:1::1") / UDP(sport=1234, dport=1234 + ii) / Raw('\xa5' * 100))) src_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(dst="3000::1", src="3000:1::%d" % ii) / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100))) route_3000_1 = VppIpRoute(self, "3000::1", 128, [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index, is_ip6=1), VppRoutePath(self.pg2.remote_ip6, self.pg2.sw_if_index, is_ip6=1)], is_ip6=1) route_3000_1.add_vpp_config() # # inject the packet on pg0 - expect load-balancing across the 2 paths # - since the default hash config is to use IP src,dst and port # src,dst # We are not going to ensure equal amounts of packets across each link, # since the hash algorithm is statistical and therefore this can never # be guaranteed. But wuth 64 different packets we do expect some # balancing. So instead just ensure there is traffic on each link. # self.send_and_expect_load_balancing(self.pg0, port_pkts, [self.pg1, self.pg2]) self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg1, self.pg2]) # # change the flow hash config so it's only IP src,dst # - now only the stream with differing source address will # load-balance # self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=0, dport=0) self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg1, self.pg2]) self.pg0.add_stream(port_pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() rx = self.pg2.get_capture(len(port_pkts)) # # change the flow hash config back to defaults # self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=1, dport=1) # # Recursive prefixes # - testing that 2 stages of load-balancing occurs and there is no # polarisation (i.e. only 2 of 4 paths are used) # port_pkts = [] src_pkts = [] for ii in range(257): port_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(dst="4000::1", src="4000:1::1") / UDP(sport=1234, dport=1234 + ii) / Raw('\xa5' * 100))) src_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(dst="4000::1", src="4000:1::%d" % ii) / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100))) route_3000_2 = VppIpRoute(self, "3000::2", 128, [VppRoutePath(self.pg3.remote_ip6, self.pg3.sw_if_index, is_ip6=1), VppRoutePath(self.pg4.remote_ip6, self.pg4.sw_if_index, is_ip6=1)], is_ip6=1) route_3000_2.add_vpp_config() route_4000_1 = VppIpRoute(self, "4000::1", 128, [VppRoutePath("3000::1", 0xffffffff, is_ip6=1), VppRoutePath("3000::2", 0xffffffff, is_ip6=1)], is_ip6=1) route_4000_1.add_vpp_config() # # inject the packet on pg0 - expect load-balancing across all 4 paths # self.vapi.cli("clear trace") self.send_and_expect_load_balancing(self.pg0, port_pkts, [self.pg1, self.pg2, self.pg3, self.pg4]) self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4]) if __name__ == '__main__': unittest.main(testRunner=VppTestRunner)