2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2018-11-28 19:06:41 -08:00
|
|
|
from __future__ import print_function
|
2018-11-25 10:35:29 -08:00
|
|
|
import binascii
|
2017-03-13 13:39:52 +01:00
|
|
|
import random
|
|
|
|
import socket
|
|
|
|
import unittest
|
|
|
|
import time
|
2017-06-13 21:15:40 +02:00
|
|
|
import re
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
from scapy.packet import Raw
|
|
|
|
from scapy.layers.l2 import Ether
|
2017-06-13 21:15:40 +02:00
|
|
|
from scapy.layers.inet import IP, TCP, UDP
|
2017-03-13 13:39:52 +01:00
|
|
|
from scapy.layers.inet6 import IPv6
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
from config import config
|
2021-01-29 13:17:19 +00:00
|
|
|
from framework import tag_fixme_vpp_workers
|
2021-05-31 16:08:53 +02:00
|
|
|
from framework import VppTestCase, VppTestRunner
|
2021-01-14 10:19:08 +00:00
|
|
|
from framework import tag_run_solo
|
2017-03-13 13:39:52 +01:00
|
|
|
from vpp_object import VppObject
|
|
|
|
from vpp_pg_interface import CaptureTimeoutError
|
|
|
|
from util import ppp
|
|
|
|
from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
|
2017-06-13 21:15:40 +02:00
|
|
|
from vpp_ip_route import VppIpRoute, VppRoutePath
|
2019-10-21 23:13:46 +02:00
|
|
|
from vpp_papi.macaddress import mac_ntop
|
|
|
|
from socket import inet_ntop
|
2019-12-09 15:51:44 +01:00
|
|
|
from vpp_papi import VppEnum
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
class VppCFLOW(VppObject):
|
|
|
|
"""CFLOW object for IPFIX exporter and Flowprobe feature"""
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
test,
|
|
|
|
intf="pg2",
|
|
|
|
active=0,
|
|
|
|
passive=0,
|
|
|
|
timeout=100,
|
|
|
|
mtu=1024,
|
|
|
|
datapath="l2",
|
|
|
|
layer="l2 l3 l4",
|
|
|
|
):
|
2017-03-13 13:39:52 +01:00
|
|
|
self._test = test
|
|
|
|
self._intf = intf
|
|
|
|
self._active = active
|
|
|
|
if passive == 0 or passive < active:
|
2022-04-26 19:02:15 +02:00
|
|
|
self._passive = active + 1
|
2017-03-13 13:39:52 +01:00
|
|
|
else:
|
|
|
|
self._passive = passive
|
2022-04-26 19:02:15 +02:00
|
|
|
self._datapath = datapath # l2 ip4 ip6
|
|
|
|
self._collect = layer # l2 l3 l4
|
2017-03-13 13:39:52 +01:00
|
|
|
self._timeout = timeout
|
|
|
|
self._mtu = mtu
|
|
|
|
self._configured = False
|
|
|
|
|
|
|
|
def add_vpp_config(self):
|
|
|
|
self.enable_exporter()
|
2019-12-09 15:51:44 +01:00
|
|
|
l2_flag = 0
|
|
|
|
l3_flag = 0
|
|
|
|
l4_flag = 0
|
2022-04-26 19:02:15 +02:00
|
|
|
if "l2" in self._collect.lower():
|
|
|
|
l2_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L2
|
|
|
|
if "l3" in self._collect.lower():
|
|
|
|
l3_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L3
|
|
|
|
if "l4" in self._collect.lower():
|
|
|
|
l4_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L4
|
2019-03-19 08:07:53 -07:00
|
|
|
self._test.vapi.flowprobe_params(
|
2019-12-09 15:51:44 +01:00
|
|
|
record_flags=(l2_flag | l3_flag | l4_flag),
|
2022-04-26 19:02:15 +02:00
|
|
|
active_timer=self._active,
|
|
|
|
passive_timer=self._passive,
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.enable_flowprobe_feature()
|
|
|
|
self._test.vapi.cli("ipfix flush")
|
|
|
|
self._configured = True
|
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
|
|
|
self.disable_exporter()
|
|
|
|
self.disable_flowprobe_feature()
|
|
|
|
self._test.vapi.cli("ipfix flush")
|
|
|
|
self._configured = False
|
|
|
|
|
|
|
|
def enable_exporter(self):
|
|
|
|
self._test.vapi.set_ipfix_exporter(
|
2019-10-10 14:21:22 +02:00
|
|
|
collector_address=self._test.pg0.remote_ip4,
|
|
|
|
src_address=self._test.pg0.local_ip4,
|
2017-03-13 13:39:52 +01:00
|
|
|
path_mtu=self._mtu,
|
2022-04-26 19:02:15 +02:00
|
|
|
template_interval=self._timeout,
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
def enable_flowprobe_feature(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
self._test.vapi.ppcli(
|
|
|
|
"flowprobe feature add-del %s %s" % (self._intf, self._datapath)
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
def disable_exporter(self):
|
|
|
|
self._test.vapi.cli("set ipfix exporter collector 0.0.0.0")
|
|
|
|
|
|
|
|
def disable_flowprobe_feature(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
self._test.vapi.cli(
|
|
|
|
"flowprobe feature add-del %s %s disable" % (self._intf, self._datapath)
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
def object_id(self):
|
2019-03-14 08:46:52 -07:00
|
|
|
return "ipfix-collector-%s-%s" % (self._src, self.dst)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
|
|
|
return self._configured
|
|
|
|
|
|
|
|
def verify_templates(self, decoder=None, timeout=1, count=3):
|
|
|
|
templates = []
|
2021-09-08 15:15:59 +02:00
|
|
|
self._test.assertIn(count, (1, 2, 3))
|
|
|
|
for _ in range(count):
|
2022-04-26 19:02:15 +02:00
|
|
|
p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout)
|
2017-03-13 13:39:52 +01:00
|
|
|
self._test.assertTrue(p.haslayer(IPFIX))
|
|
|
|
if decoder is not None and p.haslayer(Template):
|
|
|
|
templates.append(p[Template].templateID)
|
|
|
|
decoder.add_template(p.getlayer(Template))
|
|
|
|
return templates
|
|
|
|
|
|
|
|
|
|
|
|
class MethodHolder(VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Flow-per-packet plugin: test L2, IP4, IP6 reporting"""
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# Test variables
|
|
|
|
debug_print = False
|
2017-06-12 08:26:13 +02:00
|
|
|
max_number_of_packets = 10
|
2017-03-13 13:39:52 +01:00
|
|
|
pkts = []
|
|
|
|
|
|
|
|
@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.
|
|
|
|
"""
|
|
|
|
super(MethodHolder, cls).setUpClass()
|
|
|
|
try:
|
|
|
|
# Create pg interfaces
|
2017-06-13 21:15:40 +02:00
|
|
|
cls.create_pg_interfaces(range(9))
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# Packet sizes
|
|
|
|
cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
|
|
|
|
|
|
|
|
# Create BD with MAC learning and unknown unicast flooding disabled
|
|
|
|
# and put interfaces to this BD
|
|
|
|
cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1)
|
2019-03-11 19:23:25 +01:00
|
|
|
cls.vapi.sw_interface_set_l2_bridge(
|
2022-04-26 19:02:15 +02:00
|
|
|
rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1
|
|
|
|
)
|
2019-03-11 19:23:25 +01:00
|
|
|
cls.vapi.sw_interface_set_l2_bridge(
|
2022-04-26 19:02:15 +02:00
|
|
|
rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# Set up all interfaces
|
|
|
|
for i in cls.pg_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
|
|
|
|
cls.pg0.config_ip4()
|
|
|
|
cls.pg0.configure_ipv4_neighbors()
|
|
|
|
cls.collector = cls.pg0
|
|
|
|
|
|
|
|
cls.pg1.config_ip4()
|
|
|
|
cls.pg1.resolve_arp()
|
|
|
|
cls.pg2.config_ip4()
|
|
|
|
cls.pg2.resolve_arp()
|
|
|
|
cls.pg3.config_ip4()
|
|
|
|
cls.pg3.resolve_arp()
|
|
|
|
cls.pg4.config_ip4()
|
|
|
|
cls.pg4.resolve_arp()
|
2017-06-13 21:15:40 +02:00
|
|
|
cls.pg7.config_ip4()
|
|
|
|
cls.pg8.config_ip4()
|
|
|
|
cls.pg8.configure_ipv4_neighbors()
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
cls.pg5.config_ip6()
|
|
|
|
cls.pg5.resolve_ndp()
|
|
|
|
cls.pg5.disable_ipv6_ra()
|
|
|
|
cls.pg6.config_ip6()
|
|
|
|
cls.pg6.resolve_ndp()
|
|
|
|
cls.pg6.disable_ipv6_ra()
|
|
|
|
except Exception:
|
|
|
|
super(MethodHolder, cls).tearDownClass()
|
|
|
|
raise
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(MethodHolder, cls).tearDownClass()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def create_stream(
|
|
|
|
self, src_if=None, dst_if=None, packets=None, size=None, ip_ver="v4"
|
|
|
|
):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Create a packet stream to tickle the plugin
|
|
|
|
|
|
|
|
:param VppInterface src_if: Source interface for packet stream
|
|
|
|
:param VppInterface src_if: Dst interface for packet stream
|
|
|
|
"""
|
|
|
|
if src_if is None:
|
|
|
|
src_if = self.pg1
|
|
|
|
if dst_if is None:
|
|
|
|
dst_if = self.pg2
|
|
|
|
self.pkts = []
|
|
|
|
if packets is None:
|
|
|
|
packets = random.randint(1, self.max_number_of_packets)
|
|
|
|
pkt_size = size
|
|
|
|
for p in range(0, packets):
|
|
|
|
if size is None:
|
|
|
|
pkt_size = random.choice(self.pg_if_packet_sizes)
|
|
|
|
info = self.create_packet_info(src_if, dst_if)
|
|
|
|
payload = self.info_to_payload(info)
|
|
|
|
p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
|
2022-04-26 19:02:15 +02:00
|
|
|
if ip_ver == "v4":
|
2017-03-13 13:39:52 +01:00
|
|
|
p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
|
|
|
|
else:
|
|
|
|
p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
|
2017-06-13 21:15:40 +02:00
|
|
|
p /= UDP(sport=1234, dport=4321)
|
|
|
|
p /= Raw(payload)
|
2017-03-13 13:39:52 +01:00
|
|
|
info.data = p.copy()
|
|
|
|
self.extend_packet(p, pkt_size)
|
|
|
|
self.pkts.append(p)
|
|
|
|
|
|
|
|
def verify_cflow_data(self, decoder, capture, cflow):
|
|
|
|
octets = 0
|
|
|
|
packets = 0
|
|
|
|
for p in capture:
|
|
|
|
octets += p[IP].len
|
|
|
|
packets += 1
|
|
|
|
if cflow.haslayer(Data):
|
|
|
|
data = decoder.decode_data_set(cflow.getlayer(Set))
|
|
|
|
for record in data:
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[1]), 16), octets)
|
|
|
|
self.assertEqual(int(binascii.hexlify(record[2]), 16), packets)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def send_packets(self, src_if=None, dst_if=None):
|
|
|
|
if src_if is None:
|
|
|
|
src_if = self.pg1
|
|
|
|
if dst_if is None:
|
|
|
|
dst_if = self.pg2
|
|
|
|
self.pg_enable_capture([dst_if])
|
|
|
|
src_if.add_stream(self.pkts)
|
|
|
|
self.pg_start()
|
|
|
|
return dst_if.get_capture(len(self.pkts))
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def verify_cflow_data_detail(
|
|
|
|
self, decoder, capture, cflow, data_set={1: "octets", 2: "packets"}, ip_ver="v4"
|
|
|
|
):
|
2017-03-13 13:39:52 +01:00
|
|
|
if self.debug_print:
|
2018-11-28 19:06:41 -08:00
|
|
|
print(capture[0].show())
|
2017-03-13 13:39:52 +01:00
|
|
|
if cflow.haslayer(Data):
|
|
|
|
data = decoder.decode_data_set(cflow.getlayer(Set))
|
|
|
|
if self.debug_print:
|
2018-11-28 19:06:41 -08:00
|
|
|
print(data)
|
2022-04-26 19:02:15 +02:00
|
|
|
if ip_ver == "v4":
|
2017-03-13 13:39:52 +01:00
|
|
|
ip_layer = capture[0][IP]
|
|
|
|
else:
|
|
|
|
ip_layer = capture[0][IPv6]
|
|
|
|
if data_set is not None:
|
|
|
|
for record in data:
|
2019-03-27 11:25:48 -07:00
|
|
|
# skip flow if ingress/egress interface is 0
|
2018-11-25 10:35:29 -08:00
|
|
|
if int(binascii.hexlify(record[10]), 16) == 0:
|
2017-03-13 13:39:52 +01:00
|
|
|
continue
|
2018-11-25 10:35:29 -08:00
|
|
|
if int(binascii.hexlify(record[14]), 16) == 0:
|
2017-03-13 13:39:52 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
for field in data_set:
|
|
|
|
if field not in record.keys():
|
|
|
|
continue
|
|
|
|
value = data_set[field]
|
2022-04-26 19:02:15 +02:00
|
|
|
if value == "octets":
|
2017-03-13 13:39:52 +01:00
|
|
|
value = ip_layer.len
|
2022-04-26 19:02:15 +02:00
|
|
|
if ip_ver == "v6":
|
|
|
|
value += 40 # ??? is this correct
|
|
|
|
elif value == "packets":
|
2017-03-13 13:39:52 +01:00
|
|
|
value = 1
|
2022-04-26 19:02:15 +02:00
|
|
|
elif value == "src_ip":
|
|
|
|
if ip_ver == "v4":
|
|
|
|
ip = socket.inet_pton(socket.AF_INET, ip_layer.src)
|
2017-03-13 13:39:52 +01:00
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
ip = socket.inet_pton(socket.AF_INET6, ip_layer.src)
|
2018-11-25 10:35:29 -08:00
|
|
|
value = int(binascii.hexlify(ip), 16)
|
2022-04-26 19:02:15 +02:00
|
|
|
elif value == "dst_ip":
|
|
|
|
if ip_ver == "v4":
|
|
|
|
ip = socket.inet_pton(socket.AF_INET, ip_layer.dst)
|
2017-03-13 13:39:52 +01:00
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
ip = socket.inet_pton(socket.AF_INET6, ip_layer.dst)
|
2018-11-25 10:35:29 -08:00
|
|
|
value = int(binascii.hexlify(ip), 16)
|
2022-04-26 19:02:15 +02:00
|
|
|
elif value == "sport":
|
2017-03-13 13:39:52 +01:00
|
|
|
value = int(capture[0][UDP].sport)
|
2022-04-26 19:02:15 +02:00
|
|
|
elif value == "dport":
|
2017-03-13 13:39:52 +01:00
|
|
|
value = int(capture[0][UDP].dport)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
int(binascii.hexlify(record[field]), 16), value
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
def verify_cflow_data_notimer(self, decoder, capture, cflows):
|
|
|
|
idx = 0
|
|
|
|
for cflow in cflows:
|
|
|
|
if cflow.haslayer(Data):
|
|
|
|
data = decoder.decode_data_set(cflow.getlayer(Set))
|
|
|
|
else:
|
|
|
|
raise Exception("No CFLOW data")
|
|
|
|
|
|
|
|
for rec in data:
|
|
|
|
p = capture[idx]
|
|
|
|
idx += 1
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p[IP].len, int(binascii.hexlify(rec[1]), 16))
|
|
|
|
self.assertEqual(1, int(binascii.hexlify(rec[2]), 16))
|
2017-03-13 13:39:52 +01:00
|
|
|
self.assertEqual(len(capture), idx)
|
|
|
|
|
2021-09-08 15:15:59 +02:00
|
|
|
def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""wait for CFLOW packet and verify its correctness
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
:param timeout: how long to wait
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.logger.info("IPFIX: Waiting for CFLOW packet")
|
|
|
|
# self.logger.debug(self.vapi.ppcli("show flow table"))
|
2021-09-08 15:15:59 +02:00
|
|
|
p = collector_intf.wait_for_packet(timeout=timeout)
|
|
|
|
self.assertEqual(p[Set].setID, set_id)
|
|
|
|
# self.logger.debug(self.vapi.ppcli("show flow table"))
|
|
|
|
self.logger.debug(ppp("IPFIX: Got packet:", p))
|
2017-03-13 13:39:52 +01:00
|
|
|
return p
|
|
|
|
|
|
|
|
|
2021-01-14 10:19:08 +00:00
|
|
|
@tag_run_solo
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2017-06-13 21:15:40 +02:00
|
|
|
class Flowprobe(MethodHolder):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Template verification, timer tests"""
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(Flowprobe, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(Flowprobe, cls).tearDownClass()
|
|
|
|
|
2017-03-13 13:39:52 +01:00
|
|
|
def test_0001(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""timer less than template timeout"""
|
2017-06-13 21:15:40 +02:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
2017-03-13 13:39:52 +01:00
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self, active=2)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2017-06-13 21:15:40 +02:00
|
|
|
self.create_stream(packets=1)
|
2017-06-12 08:26:13 +02:00
|
|
|
self.send_packets()
|
2017-06-13 21:15:40 +02:00
|
|
|
capture = self.pg2.get_capture(1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.verify_cflow_data(ipfix_decoder, capture, cflow)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
2017-06-13 21:15:40 +02:00
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_0002(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""timer greater than template timeout"""
|
2017-06-13 21:15:40 +02:00
|
|
|
self.logger.info("FFP_TEST_START_0002")
|
2017-03-13 13:39:52 +01:00
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self, timeout=3, active=4)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix.verify_templates()
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
self.create_stream(packets=2)
|
|
|
|
self.send_packets()
|
|
|
|
capture = self.pg2.get_capture(2)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# next set of template packet should arrive after 20 seconds
|
|
|
|
# template packet should arrive within 20 s
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, timeout=5)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.verify_cflow_data(ipfix_decoder, capture, cflow)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
2017-06-13 21:15:40 +02:00
|
|
|
self.logger.info("FFP_TEST_FINISH_0002")
|
|
|
|
|
|
|
|
def test_cflow_packet(self):
|
|
|
|
"""verify cflow packet fields"""
|
|
|
|
self.logger.info("FFP_TEST_START_0000")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(
|
|
|
|
test=self, intf="pg8", datapath="ip4", layer="l2 l3 l4", active=2
|
|
|
|
)
|
2017-06-13 21:15:40 +02:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
route_9001 = VppIpRoute(
|
|
|
|
self,
|
|
|
|
"9.0.0.0",
|
|
|
|
24,
|
|
|
|
[VppRoutePath(self.pg8._remote_hosts[0].ip4, self.pg8.sw_if_index)],
|
|
|
|
)
|
2017-06-13 21:15:40 +02:00
|
|
|
route_9001.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.pkts = [
|
|
|
|
(
|
|
|
|
Ether(dst=self.pg7.local_mac, src=self.pg7.remote_mac)
|
|
|
|
/ IP(src=self.pg7.remote_ip4, dst="9.0.0.100")
|
|
|
|
/ TCP(sport=1234, dport=4321, flags=80)
|
|
|
|
/ Raw(b"\xa5" * 100)
|
|
|
|
)
|
|
|
|
]
|
2017-06-13 21:15:40 +02:00
|
|
|
|
|
|
|
nowUTC = int(time.time())
|
2022-04-26 19:02:15 +02:00
|
|
|
nowUNIX = nowUTC + 2208988800
|
2017-06-13 21:15:40 +02:00
|
|
|
self.send_packets(src_if=self.pg7, dst_if=self.pg8)
|
|
|
|
|
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10)
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
if cflow[0].haslayer(IPFIX):
|
|
|
|
self.assertEqual(cflow[IPFIX].version, 10)
|
|
|
|
self.assertEqual(cflow[IPFIX].observationDomainID, 1)
|
|
|
|
self.assertEqual(cflow[IPFIX].sequenceNumber, 0)
|
|
|
|
self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5)
|
|
|
|
if cflow.haslayer(Data):
|
|
|
|
record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0]
|
|
|
|
# ingress interface
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[10]), 16), 8)
|
2017-06-13 21:15:40 +02:00
|
|
|
# egress interface
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[14]), 16), 9)
|
2017-06-13 21:15:40 +02:00
|
|
|
# packets
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[2]), 16), 1)
|
2017-06-13 21:15:40 +02:00
|
|
|
# src mac
|
2019-10-21 23:13:46 +02:00
|
|
|
self.assertEqual(mac_ntop(record[56]), self.pg8.local_mac)
|
2017-06-13 21:15:40 +02:00
|
|
|
# dst mac
|
2019-10-21 23:13:46 +02:00
|
|
|
self.assertEqual(mac_ntop(record[80]), self.pg8.remote_mac)
|
2018-11-25 10:35:29 -08:00
|
|
|
flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32
|
2017-06-13 21:15:40 +02:00
|
|
|
# flow start timestamp
|
|
|
|
self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
|
2018-11-25 10:35:29 -08:00
|
|
|
flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32
|
2017-06-13 21:15:40 +02:00
|
|
|
# flow end timestamp
|
|
|
|
self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
|
|
|
|
# ethernet type
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[256]), 16), 8)
|
2017-06-13 21:15:40 +02:00
|
|
|
# src ip
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(inet_ntop(socket.AF_INET, record[8]), self.pg7.remote_ip4)
|
2017-06-13 21:15:40 +02:00
|
|
|
# dst ip
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(inet_ntop(socket.AF_INET, record[12]), "9.0.0.100")
|
2017-06-13 21:15:40 +02:00
|
|
|
# protocol (TCP)
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[4]), 16), 6)
|
2017-06-13 21:15:40 +02:00
|
|
|
# src port
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234)
|
2017-06-13 21:15:40 +02:00
|
|
|
# dst port
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321)
|
2017-06-13 21:15:40 +02:00
|
|
|
# tcp flags
|
2018-11-25 10:35:29 -08:00
|
|
|
self.assertEqual(int(binascii.hexlify(record[6]), 16), 80)
|
2017-06-13 21:15:40 +02:00
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0000")
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2017-06-12 08:26:13 +02:00
|
|
|
class Datapath(MethodHolder):
|
|
|
|
"""collect information on Ethernet, IP4 and IP6 datapath (no timers)"""
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(Datapath, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(Datapath, cls).tearDownClass()
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_templatesL2(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""verify template on L2 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0000")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, layer="l2")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
# template packet should arrive immediately
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix.verify_templates(timeout=3, count=1)
|
|
|
|
self.collector.get_capture(1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0000")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L2onL2(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L2 data on L2 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, layer="l2")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(packets=1)
|
|
|
|
capture = self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder, capture, cflow, {2: "packets", 256: 8}
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L3onL2(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L3 data on L2 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0002")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, layer="l3")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=2)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(packets=1)
|
|
|
|
capture = self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder,
|
|
|
|
capture,
|
|
|
|
cflow,
|
|
|
|
{2: "packets", 4: 17, 8: "src_ip", 12: "dst_ip"},
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.collector.get_capture(3)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0002")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L4onL2(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L4 data on L2 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0003")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, layer="l4")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=2)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(packets=1)
|
|
|
|
capture = self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder, capture, cflow, {2: "packets", 7: "sport", 11: "dport"}
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.collector.get_capture(3)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0003")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_templatesIp4(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""verify templates on IP4 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0000")
|
|
|
|
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, datapath="ip4")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
# template packet should arrive immediately
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.verify_templates(timeout=3, count=1)
|
|
|
|
self.collector.get_capture(1)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0000")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L2onIP4(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L2 data on IP4 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg4", layer="l2", datapath="ip4")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
|
|
|
|
capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder, capture, cflow, {2: "packets", 256: 8}
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L3onIP4(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L3 data on IP4 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0002")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg4", layer="l3", datapath="ip4")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
|
|
|
|
capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder,
|
|
|
|
capture,
|
|
|
|
cflow,
|
|
|
|
{1: "octets", 2: "packets", 8: "src_ip", 12: "dst_ip"},
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0002")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L4onIP4(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L4 data on IP4 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0003")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg4", layer="l4", datapath="ip4")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
|
|
|
|
capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder, capture, cflow, {2: "packets", 7: "sport", 11: "dport"}
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0003")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_templatesIP6(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""verify templates on IP6 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0000")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, datapath="ip6")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix.verify_templates(count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(1)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0000")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L2onIP6(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L2 data on IP6 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg6", layer="l2", datapath="ip6")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6")
|
2017-03-13 13:39:52 +01:00
|
|
|
capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder, capture, cflow, {2: "packets", 256: 56710}, ip_ver="v6"
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L3onIP6(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L3 data on IP6 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0002")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg6", layer="l3", datapath="ip6")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6")
|
2017-03-13 13:39:52 +01:00
|
|
|
capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder,
|
|
|
|
capture,
|
|
|
|
cflow,
|
|
|
|
{2: "packets", 27: "src_ip", 28: "dst_ip"},
|
|
|
|
ip_ver="v6",
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0002")
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_L4onIP6(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L4 data on IP6 datapath"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0003")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ipfix = VppCFLOW(test=self, intf="pg6", layer="l4", datapath="ip6")
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, count=1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6")
|
2017-03-13 13:39:52 +01:00
|
|
|
capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[0])
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_cflow_data_detail(
|
|
|
|
ipfix_decoder,
|
|
|
|
capture,
|
|
|
|
cflow,
|
|
|
|
{2: "packets", 7: "sport", 11: "dport"},
|
|
|
|
ip_ver="v6",
|
|
|
|
)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# expected two templates and one cflow packet
|
|
|
|
self.collector.get_capture(2)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0003")
|
|
|
|
|
|
|
|
def test_0001(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""no timers, one CFLOW packet, 9 Flows inside"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(packets=9)
|
|
|
|
capture = self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
cflow = self.wait_for_cflow_packet(self.collector, templates[1])
|
2017-03-13 13:39:52 +01:00
|
|
|
self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow])
|
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
|
|
|
def test_0002(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""no timers, two CFLOW packets (mtu=256), 3 Flows in each"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0002")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self, mtu=256)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream(packets=6)
|
|
|
|
capture = self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
|
|
|
cflows = []
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2022-04-26 19:02:15 +02:00
|
|
|
cflows.append(self.wait_for_cflow_packet(self.collector, templates[1]))
|
|
|
|
cflows.append(self.wait_for_cflow_packet(self.collector, templates[1]))
|
2017-03-13 13:39:52 +01:00
|
|
|
self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows)
|
|
|
|
self.collector.get_capture(5)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0002")
|
|
|
|
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
@unittest.skipUnless(config.extended, "part of extended tests")
|
2017-06-12 08:26:13 +02:00
|
|
|
class DisableIPFIX(MethodHolder):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Disable IPFIX"""
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(DisableIPFIX, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(DisableIPFIX, cls).tearDownClass()
|
|
|
|
|
2017-03-13 13:39:52 +01:00
|
|
|
def test_0001(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""disable IPFIX after first packets"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream()
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.wait_for_cflow_packet(self.collector, templates[1])
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
2019-03-27 11:25:48 -07:00
|
|
|
# disable IPFIX
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.disable_exporter()
|
|
|
|
self.pg_enable_capture([self.collector])
|
|
|
|
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure no one packet arrived in 1 minute
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2021-09-08 15:15:59 +02:00
|
|
|
self.sleep(1, "wait before verifying no packets sent")
|
|
|
|
self.collector.assert_nothing_captured()
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
@unittest.skipUnless(config.extended, "part of extended tests")
|
2017-06-12 08:26:13 +02:00
|
|
|
class ReenableIPFIX(MethodHolder):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Re-enable IPFIX"""
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(ReenableIPFIX, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(ReenableIPFIX, cls).tearDownClass()
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
def test_0011(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""disable IPFIX after first packets and re-enable after few packets"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
self.create_stream(packets=5)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.wait_for_cflow_packet(self.collector, templates[1])
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
# disable IPFIX
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.disable_exporter()
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-03-13 13:39:52 +01:00
|
|
|
self.pg_enable_capture([self.collector])
|
|
|
|
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure no one packet arrived in active timer span
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2021-09-08 15:15:59 +02:00
|
|
|
self.sleep(1, "wait before verifying no packets sent")
|
|
|
|
self.collector.assert_nothing_captured()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.pg2.get_capture(5)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# enable IPFIX
|
|
|
|
ipfix.enable_exporter()
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
capture = self.collector.get_capture(4)
|
|
|
|
nr_templates = 0
|
|
|
|
nr_data = 0
|
|
|
|
for p in capture:
|
|
|
|
self.assertTrue(p.haslayer(IPFIX))
|
|
|
|
if p.haslayer(Template):
|
|
|
|
nr_templates += 1
|
|
|
|
self.assertTrue(nr_templates, 3)
|
|
|
|
for p in capture:
|
|
|
|
self.assertTrue(p.haslayer(IPFIX))
|
|
|
|
if p.haslayer(Data):
|
|
|
|
nr_data += 1
|
|
|
|
self.assertTrue(nr_templates, 1)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
@unittest.skipUnless(config.extended, "part of extended tests")
|
2017-06-12 08:26:13 +02:00
|
|
|
class DisableFP(MethodHolder):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Disable Flowprobe feature"""
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(DisableFP, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(DisableFP, cls).tearDownClass()
|
|
|
|
|
2017-03-13 13:39:52 +01:00
|
|
|
def test_0001(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""disable flowprobe feature after first packets"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2017-06-12 08:26:13 +02:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder)
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
self.create_stream()
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.wait_for_cflow_packet(self.collector, templates[1])
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
2019-03-27 11:25:48 -07:00
|
|
|
# disable IPFIX
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.disable_flowprobe_feature()
|
|
|
|
self.pg_enable_capture([self.collector])
|
|
|
|
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure no one packet arrived in active timer span
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2021-09-08 15:15:59 +02:00
|
|
|
self.sleep(1, "wait before verifying no packets sent")
|
|
|
|
self.collector.assert_nothing_captured()
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
@unittest.skipUnless(config.extended, "part of extended tests")
|
2017-06-12 08:26:13 +02:00
|
|
|
class ReenableFP(MethodHolder):
|
2017-03-13 13:39:52 +01:00
|
|
|
"""Re-enable Flowprobe feature"""
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(ReenableFP, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(ReenableFP, cls).tearDownClass()
|
|
|
|
|
2017-03-13 13:39:52 +01:00
|
|
|
def test_0001(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""disable flowprobe feature after first packets and re-enable
|
|
|
|
after few packets"""
|
2017-03-13 13:39:52 +01:00
|
|
|
self.logger.info("FFP_TEST_START_0001")
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pkts = []
|
|
|
|
|
2017-06-12 08:26:13 +02:00
|
|
|
ipfix = VppCFLOW(test=self)
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.add_vpp_config()
|
|
|
|
|
|
|
|
ipfix_decoder = IPFIXDecoder()
|
|
|
|
# template packet should arrive immediately
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-03-13 13:39:52 +01:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
|
|
|
|
|
|
|
|
self.create_stream()
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure the one packet we expect actually showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.wait_for_cflow_packet(self.collector, templates[1], 5)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
2019-03-27 11:25:48 -07:00
|
|
|
# disable FPP feature
|
2017-03-13 13:39:52 +01:00
|
|
|
ipfix.disable_flowprobe_feature()
|
|
|
|
self.pg_enable_capture([self.collector])
|
|
|
|
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure no one packet arrived in active timer span
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2021-09-08 15:15:59 +02:00
|
|
|
self.sleep(5, "wait before verifying no packets sent")
|
|
|
|
self.collector.assert_nothing_captured()
|
2017-03-13 13:39:52 +01:00
|
|
|
|
|
|
|
# enable FPP feature
|
|
|
|
ipfix.enable_flowprobe_feature()
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-03-13 13:39:52 +01:00
|
|
|
templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
|
|
|
|
|
|
|
|
self.send_packets()
|
|
|
|
|
|
|
|
# make sure the next packets (templates and data) we expect actually
|
|
|
|
# showed up
|
2019-06-24 09:55:46 -04:00
|
|
|
self.vapi.ipfix_flush()
|
2017-06-12 08:26:13 +02:00
|
|
|
self.wait_for_cflow_packet(self.collector, templates[1], 5)
|
2017-03-13 13:39:52 +01:00
|
|
|
self.collector.get_capture(4)
|
|
|
|
|
|
|
|
ipfix.remove_vpp_config()
|
|
|
|
self.logger.info("FFP_TEST_FINISH_0001")
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2017-03-13 13:39:52 +01:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|