Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 2 | from __future__ import print_function |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 3 | import binascii |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 4 | import random |
| 5 | import socket |
| 6 | import unittest |
| 7 | import time |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 8 | import re |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 9 | |
| 10 | from scapy.packet import Raw |
| 11 | from scapy.layers.l2 import Ether |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 12 | from scapy.layers.inet import IP, TCP, UDP |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 13 | from scapy.layers.inet6 import IPv6 |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 14 | from scapy.contrib.lacp import SlowProtocol, LACP |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 15 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 16 | from config import config |
Dave Wallace | 670724c | 2022-09-20 21:52:18 -0400 | [diff] [blame] | 17 | from framework import tag_fixme_vpp_workers, tag_fixme_ubuntu2204, tag_fixme_debian11 |
| 18 | from framework import is_distro_ubuntu2204, is_distro_debian11 |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 19 | from framework import VppTestCase, VppTestRunner |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 20 | from framework import tag_run_solo |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 21 | from vpp_object import VppObject |
| 22 | from vpp_pg_interface import CaptureTimeoutError |
| 23 | from util import ppp |
| 24 | from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 25 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Ole Troan | b0d83f1 | 2019-10-21 23:13:46 +0200 | [diff] [blame] | 26 | from vpp_papi.macaddress import mac_ntop |
| 27 | from socket import inet_ntop |
Ole Troan | 3013e69 | 2019-12-09 15:51:44 +0100 | [diff] [blame] | 28 | from vpp_papi import VppEnum |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 29 | |
| 30 | |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 31 | TMPL_COMMON_FIELD_COUNT = 6 |
| 32 | TMPL_L2_FIELD_COUNT = 3 |
| 33 | TMPL_L3_FIELD_COUNT = 4 |
| 34 | TMPL_L4_FIELD_COUNT = 3 |
| 35 | |
Alexander Chernavin | 21922ce | 2023-10-26 11:18:19 +0000 | [diff] [blame] | 36 | IPFIX_TCP_FLAGS_ID = 6 |
| 37 | IPFIX_SRC_TRANS_PORT_ID = 7 |
| 38 | IPFIX_DST_TRANS_PORT_ID = 11 |
| 39 | |
| 40 | TCP_F_FIN = 0x01 |
| 41 | TCP_F_SYN = 0x02 |
| 42 | TCP_F_RST = 0x04 |
| 43 | TCP_F_PSH = 0x08 |
| 44 | TCP_F_ACK = 0x10 |
| 45 | TCP_F_URG = 0x20 |
| 46 | TCP_F_ECE = 0x40 |
| 47 | TCP_F_CWR = 0x80 |
| 48 | |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 49 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 50 | class VppCFLOW(VppObject): |
| 51 | """CFLOW object for IPFIX exporter and Flowprobe feature""" |
| 52 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 53 | def __init__( |
| 54 | self, |
| 55 | test, |
| 56 | intf="pg2", |
| 57 | active=0, |
| 58 | passive=0, |
| 59 | timeout=100, |
| 60 | mtu=1024, |
| 61 | datapath="l2", |
| 62 | layer="l2 l3 l4", |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 63 | direction="tx", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 64 | ): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 65 | self._test = test |
| 66 | self._intf = intf |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 67 | self._intf_obj = getattr(self._test, intf) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 68 | self._active = active |
| 69 | if passive == 0 or passive < active: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 70 | self._passive = active + 1 |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 71 | else: |
| 72 | self._passive = passive |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 73 | self._datapath = datapath # l2 ip4 ip6 |
| 74 | self._collect = layer # l2 l3 l4 |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 75 | self._direction = direction # rx tx both |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 76 | self._timeout = timeout |
| 77 | self._mtu = mtu |
| 78 | self._configured = False |
| 79 | |
| 80 | def add_vpp_config(self): |
| 81 | self.enable_exporter() |
Ole Troan | 3013e69 | 2019-12-09 15:51:44 +0100 | [diff] [blame] | 82 | l2_flag = 0 |
| 83 | l3_flag = 0 |
| 84 | l4_flag = 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 85 | if "l2" in self._collect.lower(): |
| 86 | l2_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L2 |
| 87 | if "l3" in self._collect.lower(): |
| 88 | l3_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L3 |
| 89 | if "l4" in self._collect.lower(): |
| 90 | l4_flag = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L4 |
Alexander Chernavin | 86c7856 | 2022-05-12 14:56:24 +0000 | [diff] [blame] | 91 | self._test.vapi.flowprobe_set_params( |
Ole Troan | 3013e69 | 2019-12-09 15:51:44 +0100 | [diff] [blame] | 92 | record_flags=(l2_flag | l3_flag | l4_flag), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 93 | active_timer=self._active, |
| 94 | passive_timer=self._passive, |
| 95 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 96 | self.enable_flowprobe_feature() |
| 97 | self._test.vapi.cli("ipfix flush") |
| 98 | self._configured = True |
| 99 | |
| 100 | def remove_vpp_config(self): |
| 101 | self.disable_exporter() |
| 102 | self.disable_flowprobe_feature() |
| 103 | self._test.vapi.cli("ipfix flush") |
| 104 | self._configured = False |
| 105 | |
| 106 | def enable_exporter(self): |
| 107 | self._test.vapi.set_ipfix_exporter( |
Jakub Grajciar | 2f71a88 | 2019-10-10 14:21:22 +0200 | [diff] [blame] | 108 | collector_address=self._test.pg0.remote_ip4, |
| 109 | src_address=self._test.pg0.local_ip4, |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 110 | path_mtu=self._mtu, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 111 | template_interval=self._timeout, |
| 112 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 113 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 114 | def _enable_disable_flowprobe_feature(self, is_add): |
| 115 | which_map = { |
| 116 | "l2": VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_L2, |
| 117 | "ip4": VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_IP4, |
| 118 | "ip6": VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_IP6, |
| 119 | } |
| 120 | direction_map = { |
| 121 | "rx": VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_RX, |
| 122 | "tx": VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_TX, |
| 123 | "both": VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_BOTH, |
| 124 | } |
| 125 | self._test.vapi.flowprobe_interface_add_del( |
| 126 | is_add=is_add, |
| 127 | which=which_map[self._datapath], |
| 128 | direction=direction_map[self._direction], |
| 129 | sw_if_index=self._intf_obj.sw_if_index, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 130 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 131 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 132 | def enable_flowprobe_feature(self): |
| 133 | self._enable_disable_flowprobe_feature(is_add=True) |
| 134 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 135 | def disable_exporter(self): |
| 136 | self._test.vapi.cli("set ipfix exporter collector 0.0.0.0") |
| 137 | |
| 138 | def disable_flowprobe_feature(self): |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 139 | self._enable_disable_flowprobe_feature(is_add=False) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 140 | |
| 141 | def object_id(self): |
Paul Vinciguerra | e3a0e6e | 2019-03-14 08:46:52 -0700 | [diff] [blame] | 142 | return "ipfix-collector-%s-%s" % (self._src, self.dst) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 143 | |
| 144 | def query_vpp_config(self): |
| 145 | return self._configured |
| 146 | |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 147 | def verify_templates(self, decoder=None, timeout=1, count=3, field_count_in=None): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 148 | templates = [] |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 149 | self._test.assertIn(count, (1, 2, 3)) |
| 150 | for _ in range(count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 151 | p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 152 | self._test.assertTrue(p.haslayer(IPFIX)) |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 153 | self._test.assertTrue(p.haslayer(Template)) |
| 154 | if decoder is not None: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 155 | templates.append(p[Template].templateID) |
| 156 | decoder.add_template(p.getlayer(Template)) |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 157 | if field_count_in is not None: |
| 158 | self._test.assertIn(p[Template].fieldCount, field_count_in) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 159 | return templates |
| 160 | |
| 161 | |
| 162 | class MethodHolder(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 163 | """Flow-per-packet plugin: test L2, IP4, IP6 reporting""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 164 | |
| 165 | # Test variables |
| 166 | debug_print = False |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 167 | max_number_of_packets = 10 |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 168 | pkts = [] |
| 169 | |
| 170 | @classmethod |
| 171 | def setUpClass(cls): |
| 172 | """ |
| 173 | Perform standard class setup (defined by class method setUpClass in |
| 174 | class VppTestCase) before running the test case, set test case related |
| 175 | variables and configure VPP. |
| 176 | """ |
| 177 | super(MethodHolder, cls).setUpClass() |
Dave Wallace | 670724c | 2022-09-20 21:52:18 -0400 | [diff] [blame] | 178 | if (is_distro_ubuntu2204 == True or is_distro_debian11 == True) and not hasattr( |
| 179 | cls, "vpp" |
| 180 | ): |
| 181 | return |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 182 | try: |
| 183 | # Create pg interfaces |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 184 | cls.create_pg_interfaces(range(9)) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 185 | |
| 186 | # Packet sizes |
| 187 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 188 | |
| 189 | # Create BD with MAC learning and unknown unicast flooding disabled |
| 190 | # and put interfaces to this BD |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 191 | cls.vapi.bridge_domain_add_del_v2( |
| 192 | bd_id=1, uu_flood=1, learn=1, flood=1, forward=1, is_add=1 |
| 193 | ) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 194 | cls.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 195 | rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1 |
| 196 | ) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 197 | cls.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 198 | rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1 |
| 199 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 200 | |
| 201 | # Set up all interfaces |
| 202 | for i in cls.pg_interfaces: |
| 203 | i.admin_up() |
| 204 | |
| 205 | cls.pg0.config_ip4() |
| 206 | cls.pg0.configure_ipv4_neighbors() |
| 207 | cls.collector = cls.pg0 |
| 208 | |
| 209 | cls.pg1.config_ip4() |
| 210 | cls.pg1.resolve_arp() |
| 211 | cls.pg2.config_ip4() |
| 212 | cls.pg2.resolve_arp() |
| 213 | cls.pg3.config_ip4() |
| 214 | cls.pg3.resolve_arp() |
| 215 | cls.pg4.config_ip4() |
| 216 | cls.pg4.resolve_arp() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 217 | cls.pg7.config_ip4() |
| 218 | cls.pg8.config_ip4() |
| 219 | cls.pg8.configure_ipv4_neighbors() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 220 | |
| 221 | cls.pg5.config_ip6() |
| 222 | cls.pg5.resolve_ndp() |
| 223 | cls.pg5.disable_ipv6_ra() |
| 224 | cls.pg6.config_ip6() |
| 225 | cls.pg6.resolve_ndp() |
| 226 | cls.pg6.disable_ipv6_ra() |
| 227 | except Exception: |
| 228 | super(MethodHolder, cls).tearDownClass() |
| 229 | raise |
| 230 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 231 | @classmethod |
| 232 | def tearDownClass(cls): |
| 233 | super(MethodHolder, cls).tearDownClass() |
| 234 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 235 | def create_stream( |
| 236 | self, src_if=None, dst_if=None, packets=None, size=None, ip_ver="v4" |
| 237 | ): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 238 | """Create a packet stream to tickle the plugin |
| 239 | |
| 240 | :param VppInterface src_if: Source interface for packet stream |
| 241 | :param VppInterface src_if: Dst interface for packet stream |
| 242 | """ |
| 243 | if src_if is None: |
| 244 | src_if = self.pg1 |
| 245 | if dst_if is None: |
| 246 | dst_if = self.pg2 |
| 247 | self.pkts = [] |
| 248 | if packets is None: |
| 249 | packets = random.randint(1, self.max_number_of_packets) |
| 250 | pkt_size = size |
| 251 | for p in range(0, packets): |
| 252 | if size is None: |
| 253 | pkt_size = random.choice(self.pg_if_packet_sizes) |
| 254 | info = self.create_packet_info(src_if, dst_if) |
| 255 | payload = self.info_to_payload(info) |
| 256 | p = Ether(src=src_if.remote_mac, dst=src_if.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 257 | if ip_ver == "v4": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 258 | p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) |
| 259 | else: |
| 260 | p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 261 | p /= UDP(sport=1234, dport=4321) |
| 262 | p /= Raw(payload) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 263 | info.data = p.copy() |
| 264 | self.extend_packet(p, pkt_size) |
| 265 | self.pkts.append(p) |
| 266 | |
| 267 | def verify_cflow_data(self, decoder, capture, cflow): |
| 268 | octets = 0 |
| 269 | packets = 0 |
| 270 | for p in capture: |
| 271 | octets += p[IP].len |
| 272 | packets += 1 |
| 273 | if cflow.haslayer(Data): |
| 274 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 275 | for record in data: |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 276 | self.assertEqual(int(binascii.hexlify(record[1]), 16), octets) |
| 277 | self.assertEqual(int(binascii.hexlify(record[2]), 16), packets) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 278 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 279 | def send_packets(self, src_if=None, dst_if=None): |
| 280 | if src_if is None: |
| 281 | src_if = self.pg1 |
| 282 | if dst_if is None: |
| 283 | dst_if = self.pg2 |
| 284 | self.pg_enable_capture([dst_if]) |
| 285 | src_if.add_stream(self.pkts) |
| 286 | self.pg_start() |
| 287 | return dst_if.get_capture(len(self.pkts)) |
| 288 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 289 | def verify_cflow_data_detail( |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 290 | self, |
| 291 | decoder, |
| 292 | capture, |
| 293 | cflow, |
| 294 | data_set={1: "octets", 2: "packets"}, |
| 295 | ip_ver="v4", |
| 296 | field_count=None, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 297 | ): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 298 | if self.debug_print: |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 299 | print(capture[0].show()) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 300 | if cflow.haslayer(Data): |
| 301 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 302 | if self.debug_print: |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 303 | print(data) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 304 | if ip_ver == "v4": |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 305 | ip_layer = capture[0][IP] if capture[0].haslayer(IP) else None |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 306 | else: |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 307 | ip_layer = capture[0][IPv6] if capture[0].haslayer(IPv6) else None |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 308 | if data_set is not None: |
| 309 | for record in data: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 310 | # skip flow if ingress/egress interface is 0 |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 311 | if int(binascii.hexlify(record[10]), 16) == 0: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 312 | continue |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 313 | if int(binascii.hexlify(record[14]), 16) == 0: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 314 | continue |
| 315 | |
| 316 | for field in data_set: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 317 | value = data_set[field] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 318 | if value == "octets": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 319 | value = ip_layer.len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 320 | if ip_ver == "v6": |
| 321 | value += 40 # ??? is this correct |
| 322 | elif value == "packets": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 323 | value = 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 324 | elif value == "src_ip": |
| 325 | if ip_ver == "v4": |
| 326 | ip = socket.inet_pton(socket.AF_INET, ip_layer.src) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 327 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 328 | ip = socket.inet_pton(socket.AF_INET6, ip_layer.src) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 329 | value = int(binascii.hexlify(ip), 16) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 330 | elif value == "dst_ip": |
| 331 | if ip_ver == "v4": |
| 332 | ip = socket.inet_pton(socket.AF_INET, ip_layer.dst) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 333 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 334 | ip = socket.inet_pton(socket.AF_INET6, ip_layer.dst) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 335 | value = int(binascii.hexlify(ip), 16) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 336 | elif value == "sport": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 337 | value = int(capture[0][UDP].sport) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 338 | elif value == "dport": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 339 | value = int(capture[0][UDP].dport) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 340 | self.assertEqual( |
| 341 | int(binascii.hexlify(record[field]), 16), value |
| 342 | ) |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 343 | if field_count is not None: |
| 344 | for record in data: |
| 345 | self.assertEqual(len(record), field_count) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 346 | |
| 347 | def verify_cflow_data_notimer(self, decoder, capture, cflows): |
| 348 | idx = 0 |
| 349 | for cflow in cflows: |
| 350 | if cflow.haslayer(Data): |
| 351 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 352 | else: |
| 353 | raise Exception("No CFLOW data") |
| 354 | |
| 355 | for rec in data: |
| 356 | p = capture[idx] |
| 357 | idx += 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 358 | self.assertEqual(p[IP].len, int(binascii.hexlify(rec[1]), 16)) |
| 359 | self.assertEqual(1, int(binascii.hexlify(rec[2]), 16)) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 360 | self.assertEqual(len(capture), idx) |
| 361 | |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 362 | def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 363 | """wait for CFLOW packet and verify its correctness |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 364 | |
| 365 | :param timeout: how long to wait |
| 366 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 367 | """ |
| 368 | self.logger.info("IPFIX: Waiting for CFLOW packet") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 369 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 370 | p = collector_intf.wait_for_packet(timeout=timeout) |
| 371 | self.assertEqual(p[Set].setID, set_id) |
| 372 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
| 373 | self.logger.debug(ppp("IPFIX: Got packet:", p)) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 374 | return p |
| 375 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 376 | |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 377 | @tag_run_solo |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 378 | @tag_fixme_vpp_workers |
Dave Wallace | 670724c | 2022-09-20 21:52:18 -0400 | [diff] [blame] | 379 | @tag_fixme_ubuntu2204 |
| 380 | @tag_fixme_debian11 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 381 | class Flowprobe(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 382 | """Template verification, timer tests""" |
| 383 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 384 | @classmethod |
| 385 | def setUpClass(cls): |
| 386 | super(Flowprobe, cls).setUpClass() |
| 387 | |
| 388 | @classmethod |
| 389 | def tearDownClass(cls): |
| 390 | super(Flowprobe, cls).tearDownClass() |
| 391 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 392 | def test_0001(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 393 | """timer less than template timeout""" |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 394 | self.logger.info("FFP_TEST_START_0001") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 395 | self.pg_enable_capture(self.pg_interfaces) |
| 396 | self.pkts = [] |
| 397 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 398 | ipfix = VppCFLOW(test=self, active=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 399 | ipfix.add_vpp_config() |
| 400 | |
| 401 | ipfix_decoder = IPFIXDecoder() |
| 402 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 403 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 404 | |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 405 | self.create_stream(packets=1) |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 406 | self.send_packets() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 407 | capture = self.pg2.get_capture(1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 408 | |
| 409 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 410 | cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 411 | self.verify_cflow_data(ipfix_decoder, capture, cflow) |
| 412 | |
| 413 | ipfix.remove_vpp_config() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 414 | self.logger.info("FFP_TEST_FINISH_0001") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 415 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 416 | def test_0002(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 417 | """timer greater than template timeout""" |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 418 | self.logger.info("FFP_TEST_START_0002") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 419 | self.pg_enable_capture(self.pg_interfaces) |
| 420 | self.pkts = [] |
| 421 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 422 | ipfix = VppCFLOW(test=self, timeout=3, active=4) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 423 | ipfix.add_vpp_config() |
| 424 | |
| 425 | ipfix_decoder = IPFIXDecoder() |
| 426 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 427 | ipfix.verify_templates() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 428 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 429 | self.create_stream(packets=2) |
| 430 | self.send_packets() |
| 431 | capture = self.pg2.get_capture(2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 432 | |
| 433 | # next set of template packet should arrive after 20 seconds |
| 434 | # template packet should arrive within 20 s |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 435 | templates = ipfix.verify_templates(ipfix_decoder, timeout=5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 436 | |
| 437 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 438 | cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 439 | self.verify_cflow_data(ipfix_decoder, capture, cflow) |
| 440 | |
| 441 | ipfix.remove_vpp_config() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 442 | self.logger.info("FFP_TEST_FINISH_0002") |
| 443 | |
| 444 | def test_cflow_packet(self): |
| 445 | """verify cflow packet fields""" |
| 446 | self.logger.info("FFP_TEST_START_0000") |
| 447 | self.pg_enable_capture(self.pg_interfaces) |
| 448 | self.pkts = [] |
| 449 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 450 | ipfix = VppCFLOW( |
| 451 | test=self, intf="pg8", datapath="ip4", layer="l2 l3 l4", active=2 |
| 452 | ) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 453 | ipfix.add_vpp_config() |
| 454 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 455 | route_9001 = VppIpRoute( |
| 456 | self, |
| 457 | "9.0.0.0", |
| 458 | 24, |
| 459 | [VppRoutePath(self.pg8._remote_hosts[0].ip4, self.pg8.sw_if_index)], |
| 460 | ) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 461 | route_9001.add_vpp_config() |
| 462 | |
| 463 | ipfix_decoder = IPFIXDecoder() |
| 464 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
| 465 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 466 | self.pkts = [ |
| 467 | ( |
| 468 | Ether(dst=self.pg7.local_mac, src=self.pg7.remote_mac) |
| 469 | / IP(src=self.pg7.remote_ip4, dst="9.0.0.100") |
| 470 | / TCP(sport=1234, dport=4321, flags=80) |
| 471 | / Raw(b"\xa5" * 100) |
| 472 | ) |
| 473 | ] |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 474 | |
| 475 | nowUTC = int(time.time()) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 476 | nowUNIX = nowUTC + 2208988800 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 477 | self.send_packets(src_if=self.pg7, dst_if=self.pg8) |
| 478 | |
| 479 | cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10) |
| 480 | self.collector.get_capture(2) |
| 481 | |
| 482 | if cflow[0].haslayer(IPFIX): |
| 483 | self.assertEqual(cflow[IPFIX].version, 10) |
| 484 | self.assertEqual(cflow[IPFIX].observationDomainID, 1) |
| 485 | self.assertEqual(cflow[IPFIX].sequenceNumber, 0) |
| 486 | self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5) |
| 487 | if cflow.haslayer(Data): |
| 488 | record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0] |
| 489 | # ingress interface |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 490 | self.assertEqual(int(binascii.hexlify(record[10]), 16), 8) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 491 | # egress interface |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 492 | self.assertEqual(int(binascii.hexlify(record[14]), 16), 9) |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 493 | # direction |
| 494 | self.assertEqual(int(binascii.hexlify(record[61]), 16), 1) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 495 | # packets |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 496 | self.assertEqual(int(binascii.hexlify(record[2]), 16), 1) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 497 | # src mac |
Ole Troan | b0d83f1 | 2019-10-21 23:13:46 +0200 | [diff] [blame] | 498 | self.assertEqual(mac_ntop(record[56]), self.pg8.local_mac) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 499 | # dst mac |
Ole Troan | b0d83f1 | 2019-10-21 23:13:46 +0200 | [diff] [blame] | 500 | self.assertEqual(mac_ntop(record[80]), self.pg8.remote_mac) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 501 | flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 502 | # flow start timestamp |
| 503 | self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 504 | flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 505 | # flow end timestamp |
| 506 | self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1) |
| 507 | # ethernet type |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 508 | self.assertEqual(int(binascii.hexlify(record[256]), 16), 8) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 509 | # src ip |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 510 | self.assertEqual(inet_ntop(socket.AF_INET, record[8]), self.pg7.remote_ip4) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 511 | # dst ip |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 512 | self.assertEqual(inet_ntop(socket.AF_INET, record[12]), "9.0.0.100") |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 513 | # protocol (TCP) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 514 | self.assertEqual(int(binascii.hexlify(record[4]), 16), 6) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 515 | # src port |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 516 | self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 517 | # dst port |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 518 | self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 519 | # tcp flags |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 520 | self.assertEqual(int(binascii.hexlify(record[6]), 16), 80) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 521 | |
| 522 | ipfix.remove_vpp_config() |
| 523 | self.logger.info("FFP_TEST_FINISH_0000") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 524 | |
Alexander Chernavin | 21922ce | 2023-10-26 11:18:19 +0000 | [diff] [blame] | 525 | def test_flow_entry_reuse(self): |
| 526 | """Verify flow entry reuse doesn't accumulate meta info""" |
| 527 | self.pg_enable_capture(self.pg_interfaces) |
| 528 | self.pkts = [] |
| 529 | |
| 530 | # enable ip4 datapath for an interface |
| 531 | # set active and passive timers |
| 532 | ipfix = VppCFLOW( |
| 533 | test=self, |
| 534 | active=2, |
| 535 | passive=3, |
| 536 | intf="pg3", |
| 537 | layer="l3 l4", |
| 538 | datapath="ip4", |
| 539 | direction="rx", |
| 540 | mtu=100, |
| 541 | ) |
| 542 | ipfix.add_vpp_config() |
| 543 | |
| 544 | # template packet should arrive immediately |
| 545 | ipfix_decoder = IPFIXDecoder() |
| 546 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
| 547 | |
| 548 | # make a tcp packet |
| 549 | self.pkts = [ |
| 550 | ( |
| 551 | Ether(src=self.pg3.remote_mac, dst=self.pg4.local_mac) |
| 552 | / IP(src=self.pg3.remote_ip4, dst=self.pg4.remote_ip4) |
| 553 | / TCP(sport=1234, dport=4321) |
| 554 | / Raw(b"\xa5" * 50) |
| 555 | ) |
| 556 | ] |
| 557 | |
| 558 | # send the tcp packet two times, each time with new set of flags |
| 559 | tcp_flags = ( |
| 560 | TCP_F_SYN | TCP_F_ACK, |
| 561 | TCP_F_RST | TCP_F_PSH, |
| 562 | ) |
| 563 | for f in tcp_flags: |
| 564 | self.pkts[0][TCP].flags = f |
| 565 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 566 | |
| 567 | # verify meta info - packet/octet delta and tcp flags |
| 568 | cflow = self.wait_for_cflow_packet(self.collector, templates[0], timeout=6) |
| 569 | self.verify_cflow_data(ipfix_decoder, capture, cflow) |
| 570 | self.verify_cflow_data_detail( |
| 571 | ipfix_decoder, |
| 572 | capture, |
| 573 | cflow, |
| 574 | { |
| 575 | IPFIX_TCP_FLAGS_ID: f, |
| 576 | IPFIX_SRC_TRANS_PORT_ID: 1234, |
| 577 | IPFIX_DST_TRANS_PORT_ID: 4321, |
| 578 | }, |
| 579 | ) |
| 580 | |
| 581 | self.collector.get_capture(3) |
| 582 | |
| 583 | # cleanup |
| 584 | ipfix.remove_vpp_config() |
| 585 | |
Alexander Chernavin | 86c7856 | 2022-05-12 14:56:24 +0000 | [diff] [blame] | 586 | def test_interface_dump(self): |
| 587 | """Dump interfaces with IPFIX flow record generation enabled""" |
| 588 | self.logger.info("FFP_TEST_START_0003") |
| 589 | |
| 590 | # Enable feature for 3 interfaces |
| 591 | ipfix1 = VppCFLOW(test=self, intf="pg1", datapath="l2", direction="rx") |
| 592 | ipfix1.add_vpp_config() |
| 593 | |
| 594 | ipfix2 = VppCFLOW(test=self, intf="pg2", datapath="ip4", direction="tx") |
| 595 | ipfix2.enable_flowprobe_feature() |
| 596 | |
| 597 | ipfix3 = VppCFLOW(test=self, intf="pg3", datapath="ip6", direction="both") |
| 598 | ipfix3.enable_flowprobe_feature() |
| 599 | |
| 600 | # When request "all", dump should contain all enabled interfaces |
| 601 | dump = self.vapi.flowprobe_interface_dump() |
| 602 | self.assertEqual(len(dump), 3) |
| 603 | |
| 604 | # Verify 1st interface |
| 605 | self.assertEqual(dump[0].sw_if_index, self.pg1.sw_if_index) |
| 606 | self.assertEqual( |
| 607 | dump[0].which, VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_L2 |
| 608 | ) |
| 609 | self.assertEqual( |
| 610 | dump[0].direction, |
| 611 | VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_RX, |
| 612 | ) |
| 613 | |
| 614 | # Verify 2nd interface |
| 615 | self.assertEqual(dump[1].sw_if_index, self.pg2.sw_if_index) |
| 616 | self.assertEqual( |
| 617 | dump[1].which, VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_IP4 |
| 618 | ) |
| 619 | self.assertEqual( |
| 620 | dump[1].direction, |
| 621 | VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_TX, |
| 622 | ) |
| 623 | |
| 624 | # Verify 3rd interface |
| 625 | self.assertEqual(dump[2].sw_if_index, self.pg3.sw_if_index) |
| 626 | self.assertEqual( |
| 627 | dump[2].which, VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_IP6 |
| 628 | ) |
| 629 | self.assertEqual( |
| 630 | dump[2].direction, |
| 631 | VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_BOTH, |
| 632 | ) |
| 633 | |
| 634 | # When request 2nd interface, dump should contain only the specified interface |
| 635 | dump = self.vapi.flowprobe_interface_dump(sw_if_index=self.pg2.sw_if_index) |
| 636 | self.assertEqual(len(dump), 1) |
| 637 | |
| 638 | # Verify 2nd interface |
| 639 | self.assertEqual(dump[0].sw_if_index, self.pg2.sw_if_index) |
| 640 | self.assertEqual( |
| 641 | dump[0].which, VppEnum.vl_api_flowprobe_which_t.FLOWPROBE_WHICH_IP4 |
| 642 | ) |
| 643 | self.assertEqual( |
| 644 | dump[0].direction, |
| 645 | VppEnum.vl_api_flowprobe_direction_t.FLOWPROBE_DIRECTION_TX, |
| 646 | ) |
| 647 | |
| 648 | # When request 99th interface, dump should be empty |
| 649 | dump = self.vapi.flowprobe_interface_dump(sw_if_index=99) |
| 650 | self.assertEqual(len(dump), 0) |
| 651 | |
| 652 | ipfix1.remove_vpp_config() |
| 653 | ipfix2.remove_vpp_config() |
| 654 | ipfix3.remove_vpp_config() |
| 655 | self.logger.info("FFP_TEST_FINISH_0003") |
| 656 | |
| 657 | def test_get_params(self): |
| 658 | """Get IPFIX flow record generation parameters""" |
| 659 | self.logger.info("FFP_TEST_START_0004") |
| 660 | |
| 661 | # Enable feature for an interface with custom parameters |
| 662 | ipfix = VppCFLOW(test=self, active=20, passive=40, layer="l2 l3 l4") |
| 663 | ipfix.add_vpp_config() |
| 664 | |
| 665 | # Get and verify parameters |
| 666 | params = self.vapi.flowprobe_get_params() |
| 667 | self.assertEqual(params.active_timer, 20) |
| 668 | self.assertEqual(params.passive_timer, 40) |
| 669 | record_flags = VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L2 |
| 670 | record_flags |= VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L3 |
| 671 | record_flags |= VppEnum.vl_api_flowprobe_record_flags_t.FLOWPROBE_RECORD_FLAG_L4 |
| 672 | self.assertEqual(params.record_flags, record_flags) |
| 673 | |
| 674 | ipfix.remove_vpp_config() |
| 675 | self.logger.info("FFP_TEST_FINISH_0004") |
| 676 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 677 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 678 | class DatapathTestsHolder(object): |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 679 | """collect information on Ethernet, IP4 and IP6 datapath (no timers)""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 680 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 681 | @classmethod |
| 682 | def setUpClass(cls): |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 683 | super(DatapathTestsHolder, cls).setUpClass() |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 684 | |
| 685 | @classmethod |
| 686 | def tearDownClass(cls): |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 687 | super(DatapathTestsHolder, cls).tearDownClass() |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 688 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 689 | def test_templatesL2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 690 | """verify template on L2 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 691 | self.logger.info("FFP_TEST_START_0000") |
| 692 | self.pg_enable_capture(self.pg_interfaces) |
| 693 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 694 | ipfix = VppCFLOW( |
| 695 | test=self, intf=self.intf1, layer="l2", direction=self.direction |
| 696 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 697 | ipfix.add_vpp_config() |
| 698 | |
| 699 | # template packet should arrive immediately |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 700 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 701 | ipfix.verify_templates(timeout=3, count=1) |
| 702 | self.collector.get_capture(1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 703 | |
| 704 | ipfix.remove_vpp_config() |
| 705 | self.logger.info("FFP_TEST_FINISH_0000") |
| 706 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 707 | def test_L2onL2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 708 | """L2 data on L2 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 709 | self.logger.info("FFP_TEST_START_0001") |
| 710 | self.pg_enable_capture(self.pg_interfaces) |
| 711 | self.pkts = [] |
| 712 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 713 | ipfix = VppCFLOW( |
| 714 | test=self, intf=self.intf1, layer="l2", direction=self.direction |
| 715 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 716 | ipfix.add_vpp_config() |
| 717 | |
| 718 | ipfix_decoder = IPFIXDecoder() |
| 719 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 720 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 721 | |
| 722 | self.create_stream(packets=1) |
| 723 | capture = self.send_packets() |
| 724 | |
| 725 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 726 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 727 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 728 | self.verify_cflow_data_detail( |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 729 | ipfix_decoder, |
| 730 | capture, |
| 731 | cflow, |
| 732 | {2: "packets", 256: 8, 61: (self.direction == "tx")}, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 733 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 734 | self.collector.get_capture(2) |
| 735 | |
| 736 | ipfix.remove_vpp_config() |
| 737 | self.logger.info("FFP_TEST_FINISH_0001") |
| 738 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 739 | def test_L3onL2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 740 | """L3 data on L2 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 741 | self.logger.info("FFP_TEST_START_0002") |
| 742 | self.pg_enable_capture(self.pg_interfaces) |
| 743 | self.pkts = [] |
| 744 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 745 | ipfix = VppCFLOW( |
| 746 | test=self, intf=self.intf1, layer="l3", direction=self.direction |
| 747 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 748 | ipfix.add_vpp_config() |
| 749 | |
| 750 | ipfix_decoder = IPFIXDecoder() |
| 751 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 752 | templates = ipfix.verify_templates(ipfix_decoder, count=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 753 | |
| 754 | self.create_stream(packets=1) |
| 755 | capture = self.send_packets() |
| 756 | |
| 757 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 758 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 759 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 760 | self.verify_cflow_data_detail( |
| 761 | ipfix_decoder, |
| 762 | capture, |
| 763 | cflow, |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 764 | { |
| 765 | 2: "packets", |
| 766 | 4: 17, |
| 767 | 8: "src_ip", |
| 768 | 12: "dst_ip", |
| 769 | 61: (self.direction == "tx"), |
| 770 | }, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 771 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 772 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 773 | self.collector.get_capture(3) |
| 774 | |
| 775 | ipfix.remove_vpp_config() |
| 776 | self.logger.info("FFP_TEST_FINISH_0002") |
| 777 | |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 778 | def test_L234onL2(self): |
| 779 | """L2/3/4 data on L2 datapath""" |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 780 | self.pg_enable_capture(self.pg_interfaces) |
| 781 | self.pkts = [] |
| 782 | |
| 783 | ipfix = VppCFLOW( |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 784 | test=self, intf=self.intf1, layer="l2 l3 l4", direction=self.direction |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 785 | ) |
| 786 | ipfix.add_vpp_config() |
| 787 | |
| 788 | ipfix_decoder = IPFIXDecoder() |
| 789 | # template packet should arrive immediately |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 790 | tmpl_l2_field_count = TMPL_COMMON_FIELD_COUNT + TMPL_L2_FIELD_COUNT |
| 791 | tmpl_ip_field_count = ( |
| 792 | TMPL_COMMON_FIELD_COUNT |
| 793 | + TMPL_L2_FIELD_COUNT |
| 794 | + TMPL_L3_FIELD_COUNT |
| 795 | + TMPL_L4_FIELD_COUNT |
| 796 | ) |
| 797 | templates = ipfix.verify_templates( |
| 798 | ipfix_decoder, |
| 799 | count=3, |
| 800 | field_count_in=(tmpl_l2_field_count, tmpl_ip_field_count), |
| 801 | ) |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 802 | |
| 803 | # verify IPv4 and IPv6 flows |
| 804 | for ip_ver in ("v4", "v6"): |
| 805 | self.create_stream(packets=1, ip_ver=ip_ver) |
| 806 | capture = self.send_packets() |
| 807 | |
| 808 | # make sure the one packet we expect actually showed up |
| 809 | self.vapi.ipfix_flush() |
| 810 | cflow = self.wait_for_cflow_packet( |
| 811 | self.collector, templates[1 if ip_ver == "v4" else 2] |
| 812 | ) |
| 813 | src_ip_id = 8 if ip_ver == "v4" else 27 |
| 814 | dst_ip_id = 12 if ip_ver == "v4" else 28 |
| 815 | self.verify_cflow_data_detail( |
| 816 | ipfix_decoder, |
| 817 | capture, |
| 818 | cflow, |
| 819 | { |
| 820 | 2: "packets", |
| 821 | 256: 8 if ip_ver == "v4" else 56710, |
| 822 | 4: 17, |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 823 | 7: "sport", |
| 824 | 11: "dport", |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 825 | src_ip_id: "src_ip", |
| 826 | dst_ip_id: "dst_ip", |
| 827 | 61: (self.direction == "tx"), |
| 828 | }, |
| 829 | ip_ver=ip_ver, |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 830 | field_count=tmpl_ip_field_count, |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 831 | ) |
| 832 | |
| 833 | # verify non-IP flow |
| 834 | self.pkts = [ |
| 835 | ( |
| 836 | Ether(dst=self.pg2.local_mac, src=self.pg1.remote_mac) |
| 837 | / SlowProtocol() |
| 838 | / LACP() |
| 839 | ) |
| 840 | ] |
| 841 | capture = self.send_packets() |
| 842 | |
| 843 | # make sure the one packet we expect actually showed up |
| 844 | self.vapi.ipfix_flush() |
| 845 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
| 846 | self.verify_cflow_data_detail( |
| 847 | ipfix_decoder, |
| 848 | capture, |
| 849 | cflow, |
| 850 | {2: "packets", 256: 2440, 61: (self.direction == "tx")}, |
Alexander Chernavin | 6b027cf | 2023-10-17 08:54:33 +0000 | [diff] [blame] | 851 | field_count=tmpl_l2_field_count, |
Alexander Chernavin | 120095d | 2023-10-11 12:15:55 +0000 | [diff] [blame] | 852 | ) |
| 853 | |
| 854 | self.collector.get_capture(6) |
| 855 | |
| 856 | ipfix.remove_vpp_config() |
| 857 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 858 | def test_L4onL2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 859 | """L4 data on L2 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 860 | self.logger.info("FFP_TEST_START_0003") |
| 861 | self.pg_enable_capture(self.pg_interfaces) |
| 862 | self.pkts = [] |
| 863 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 864 | ipfix = VppCFLOW( |
| 865 | test=self, intf=self.intf1, layer="l4", direction=self.direction |
| 866 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 867 | ipfix.add_vpp_config() |
| 868 | |
| 869 | ipfix_decoder = IPFIXDecoder() |
| 870 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 871 | templates = ipfix.verify_templates(ipfix_decoder, count=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 872 | |
| 873 | self.create_stream(packets=1) |
| 874 | capture = self.send_packets() |
| 875 | |
| 876 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 877 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 878 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 879 | self.verify_cflow_data_detail( |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 880 | ipfix_decoder, |
| 881 | capture, |
| 882 | cflow, |
| 883 | {2: "packets", 7: "sport", 11: "dport", 61: (self.direction == "tx")}, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 884 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 885 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 886 | self.collector.get_capture(3) |
| 887 | |
| 888 | ipfix.remove_vpp_config() |
| 889 | self.logger.info("FFP_TEST_FINISH_0003") |
| 890 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 891 | def test_templatesIp4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 892 | """verify templates on IP4 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 893 | self.logger.info("FFP_TEST_START_0000") |
| 894 | |
| 895 | self.pg_enable_capture(self.pg_interfaces) |
| 896 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 897 | ipfix = VppCFLOW( |
| 898 | test=self, intf=self.intf1, datapath="ip4", direction=self.direction |
| 899 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 900 | ipfix.add_vpp_config() |
| 901 | |
| 902 | # template packet should arrive immediately |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 903 | self.vapi.ipfix_flush() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 904 | ipfix.verify_templates(timeout=3, count=1) |
| 905 | self.collector.get_capture(1) |
| 906 | |
| 907 | ipfix.remove_vpp_config() |
| 908 | |
| 909 | self.logger.info("FFP_TEST_FINISH_0000") |
| 910 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 911 | def test_L2onIP4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 912 | """L2 data on IP4 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 913 | self.logger.info("FFP_TEST_START_0001") |
| 914 | self.pg_enable_capture(self.pg_interfaces) |
| 915 | self.pkts = [] |
| 916 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 917 | ipfix = VppCFLOW( |
| 918 | test=self, |
| 919 | intf=self.intf2, |
| 920 | layer="l2", |
| 921 | datapath="ip4", |
| 922 | direction=self.direction, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 923 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 924 | ipfix.add_vpp_config() |
| 925 | |
| 926 | ipfix_decoder = IPFIXDecoder() |
| 927 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 928 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 929 | |
| 930 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 931 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 932 | |
| 933 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 934 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 935 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 936 | self.verify_cflow_data_detail( |
| 937 | ipfix_decoder, |
| 938 | capture, |
| 939 | cflow, |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 940 | {2: "packets", 256: 8, 61: (self.direction == "tx")}, |
| 941 | ) |
| 942 | |
| 943 | # expected two templates and one cflow packet |
| 944 | self.collector.get_capture(2) |
| 945 | |
| 946 | ipfix.remove_vpp_config() |
| 947 | self.logger.info("FFP_TEST_FINISH_0001") |
| 948 | |
| 949 | def test_L3onIP4(self): |
| 950 | """L3 data on IP4 datapath""" |
| 951 | self.logger.info("FFP_TEST_START_0002") |
| 952 | self.pg_enable_capture(self.pg_interfaces) |
| 953 | self.pkts = [] |
| 954 | |
| 955 | ipfix = VppCFLOW( |
| 956 | test=self, |
| 957 | intf=self.intf2, |
| 958 | layer="l3", |
| 959 | datapath="ip4", |
| 960 | direction=self.direction, |
| 961 | ) |
| 962 | ipfix.add_vpp_config() |
| 963 | |
| 964 | ipfix_decoder = IPFIXDecoder() |
| 965 | # template packet should arrive immediately |
| 966 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
| 967 | |
| 968 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 969 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 970 | |
| 971 | # make sure the one packet we expect actually showed up |
| 972 | self.vapi.ipfix_flush() |
| 973 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
| 974 | self.verify_cflow_data_detail( |
| 975 | ipfix_decoder, |
| 976 | capture, |
| 977 | cflow, |
| 978 | { |
| 979 | 1: "octets", |
| 980 | 2: "packets", |
| 981 | 8: "src_ip", |
| 982 | 12: "dst_ip", |
| 983 | 61: (self.direction == "tx"), |
| 984 | }, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 985 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 986 | |
| 987 | # expected two templates and one cflow packet |
| 988 | self.collector.get_capture(2) |
| 989 | |
| 990 | ipfix.remove_vpp_config() |
| 991 | self.logger.info("FFP_TEST_FINISH_0002") |
| 992 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 993 | def test_L4onIP4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 994 | """L4 data on IP4 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 995 | self.logger.info("FFP_TEST_START_0003") |
| 996 | self.pg_enable_capture(self.pg_interfaces) |
| 997 | self.pkts = [] |
| 998 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 999 | ipfix = VppCFLOW( |
| 1000 | test=self, |
| 1001 | intf=self.intf2, |
| 1002 | layer="l4", |
| 1003 | datapath="ip4", |
| 1004 | direction=self.direction, |
| 1005 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1006 | ipfix.add_vpp_config() |
| 1007 | |
| 1008 | ipfix_decoder = IPFIXDecoder() |
| 1009 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1010 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1011 | |
| 1012 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 1013 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 1014 | |
| 1015 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1016 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1017 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1018 | self.verify_cflow_data_detail( |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1019 | ipfix_decoder, |
| 1020 | capture, |
| 1021 | cflow, |
| 1022 | {2: "packets", 7: "sport", 11: "dport", 61: (self.direction == "tx")}, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1023 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1024 | |
| 1025 | # expected two templates and one cflow packet |
| 1026 | self.collector.get_capture(2) |
| 1027 | |
| 1028 | ipfix.remove_vpp_config() |
| 1029 | self.logger.info("FFP_TEST_FINISH_0003") |
| 1030 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1031 | def test_templatesIP6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1032 | """verify templates on IP6 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1033 | self.logger.info("FFP_TEST_START_0000") |
| 1034 | self.pg_enable_capture(self.pg_interfaces) |
| 1035 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1036 | ipfix = VppCFLOW( |
| 1037 | test=self, intf=self.intf1, datapath="ip6", direction=self.direction |
| 1038 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1039 | ipfix.add_vpp_config() |
| 1040 | |
| 1041 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1042 | ipfix.verify_templates(count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1043 | self.collector.get_capture(1) |
| 1044 | |
| 1045 | ipfix.remove_vpp_config() |
| 1046 | |
| 1047 | self.logger.info("FFP_TEST_FINISH_0000") |
| 1048 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1049 | def test_L2onIP6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1050 | """L2 data on IP6 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1051 | self.logger.info("FFP_TEST_START_0001") |
| 1052 | self.pg_enable_capture(self.pg_interfaces) |
| 1053 | self.pkts = [] |
| 1054 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1055 | ipfix = VppCFLOW( |
| 1056 | test=self, |
| 1057 | intf=self.intf3, |
| 1058 | layer="l2", |
| 1059 | datapath="ip6", |
| 1060 | direction=self.direction, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1061 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1062 | ipfix.add_vpp_config() |
| 1063 | |
| 1064 | ipfix_decoder = IPFIXDecoder() |
| 1065 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1066 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1067 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1068 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1069 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 1070 | |
| 1071 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1072 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1073 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1074 | self.verify_cflow_data_detail( |
| 1075 | ipfix_decoder, |
| 1076 | capture, |
| 1077 | cflow, |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1078 | {2: "packets", 256: 56710, 61: (self.direction == "tx")}, |
| 1079 | ip_ver="v6", |
| 1080 | ) |
| 1081 | |
| 1082 | # expected two templates and one cflow packet |
| 1083 | self.collector.get_capture(2) |
| 1084 | |
| 1085 | ipfix.remove_vpp_config() |
| 1086 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1087 | |
| 1088 | def test_L3onIP6(self): |
| 1089 | """L3 data on IP6 datapath""" |
| 1090 | self.logger.info("FFP_TEST_START_0002") |
| 1091 | self.pg_enable_capture(self.pg_interfaces) |
| 1092 | self.pkts = [] |
| 1093 | |
| 1094 | ipfix = VppCFLOW( |
| 1095 | test=self, |
| 1096 | intf=self.intf3, |
| 1097 | layer="l3", |
| 1098 | datapath="ip6", |
| 1099 | direction=self.direction, |
| 1100 | ) |
| 1101 | ipfix.add_vpp_config() |
| 1102 | |
| 1103 | ipfix_decoder = IPFIXDecoder() |
| 1104 | # template packet should arrive immediately |
| 1105 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
| 1106 | |
| 1107 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6") |
| 1108 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 1109 | |
| 1110 | # make sure the one packet we expect actually showed up |
| 1111 | self.vapi.ipfix_flush() |
| 1112 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
| 1113 | self.verify_cflow_data_detail( |
| 1114 | ipfix_decoder, |
| 1115 | capture, |
| 1116 | cflow, |
| 1117 | {2: "packets", 27: "src_ip", 28: "dst_ip", 61: (self.direction == "tx")}, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1118 | ip_ver="v6", |
| 1119 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1120 | |
| 1121 | # expected two templates and one cflow packet |
| 1122 | self.collector.get_capture(2) |
| 1123 | |
| 1124 | ipfix.remove_vpp_config() |
| 1125 | self.logger.info("FFP_TEST_FINISH_0002") |
| 1126 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1127 | def test_L4onIP6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1128 | """L4 data on IP6 datapath""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1129 | self.logger.info("FFP_TEST_START_0003") |
| 1130 | self.pg_enable_capture(self.pg_interfaces) |
| 1131 | self.pkts = [] |
| 1132 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1133 | ipfix = VppCFLOW( |
| 1134 | test=self, |
| 1135 | intf=self.intf3, |
| 1136 | layer="l4", |
| 1137 | datapath="ip6", |
| 1138 | direction=self.direction, |
| 1139 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1140 | ipfix.add_vpp_config() |
| 1141 | |
| 1142 | ipfix_decoder = IPFIXDecoder() |
| 1143 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1144 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1145 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1146 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, ip_ver="IPv6") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1147 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 1148 | |
| 1149 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1150 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1151 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1152 | self.verify_cflow_data_detail( |
| 1153 | ipfix_decoder, |
| 1154 | capture, |
| 1155 | cflow, |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1156 | {2: "packets", 7: "sport", 11: "dport", 61: (self.direction == "tx")}, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1157 | ip_ver="v6", |
| 1158 | ) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1159 | |
| 1160 | # expected two templates and one cflow packet |
| 1161 | self.collector.get_capture(2) |
| 1162 | |
| 1163 | ipfix.remove_vpp_config() |
| 1164 | self.logger.info("FFP_TEST_FINISH_0003") |
| 1165 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1166 | def test_0001(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1167 | """no timers, one CFLOW packet, 9 Flows inside""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1168 | self.logger.info("FFP_TEST_START_0001") |
| 1169 | self.pg_enable_capture(self.pg_interfaces) |
| 1170 | self.pkts = [] |
| 1171 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1172 | ipfix = VppCFLOW(test=self, intf=self.intf1, direction=self.direction) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1173 | ipfix.add_vpp_config() |
| 1174 | |
| 1175 | ipfix_decoder = IPFIXDecoder() |
| 1176 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1177 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1178 | |
| 1179 | self.create_stream(packets=9) |
| 1180 | capture = self.send_packets() |
| 1181 | |
| 1182 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1183 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1184 | cflow = self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1185 | self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1186 | self.collector.get_capture(4) |
| 1187 | |
| 1188 | ipfix.remove_vpp_config() |
| 1189 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1190 | |
| 1191 | def test_0002(self): |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1192 | """no timers, two CFLOW packets (mtu=260), 3 Flows in each""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1193 | self.logger.info("FFP_TEST_START_0002") |
| 1194 | self.pg_enable_capture(self.pg_interfaces) |
| 1195 | self.pkts = [] |
| 1196 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1197 | ipfix = VppCFLOW(test=self, intf=self.intf1, direction=self.direction, mtu=260) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1198 | ipfix.add_vpp_config() |
| 1199 | |
| 1200 | ipfix_decoder = IPFIXDecoder() |
| 1201 | # template packet should arrive immediately |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1202 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1203 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1204 | |
| 1205 | self.create_stream(packets=6) |
| 1206 | capture = self.send_packets() |
| 1207 | |
| 1208 | # make sure the one packet we expect actually showed up |
| 1209 | cflows = [] |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1210 | self.vapi.ipfix_flush() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1211 | cflows.append(self.wait_for_cflow_packet(self.collector, templates[1])) |
| 1212 | cflows.append(self.wait_for_cflow_packet(self.collector, templates[1])) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1213 | self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows) |
| 1214 | self.collector.get_capture(5) |
| 1215 | |
| 1216 | ipfix.remove_vpp_config() |
| 1217 | self.logger.info("FFP_TEST_FINISH_0002") |
| 1218 | |
| 1219 | |
Alexander Chernavin | 6f5ddf3 | 2022-05-06 11:35:59 +0000 | [diff] [blame] | 1220 | @tag_fixme_vpp_workers |
| 1221 | class DatapathTx(MethodHolder, DatapathTestsHolder): |
| 1222 | """Collect info on Ethernet, IP4 and IP6 datapath (TX) (no timers)""" |
| 1223 | |
| 1224 | intf1 = "pg2" |
| 1225 | intf2 = "pg4" |
| 1226 | intf3 = "pg6" |
| 1227 | direction = "tx" |
| 1228 | |
| 1229 | |
| 1230 | @tag_fixme_vpp_workers |
| 1231 | class DatapathRx(MethodHolder, DatapathTestsHolder): |
| 1232 | """Collect info on Ethernet, IP4 and IP6 datapath (RX) (no timers)""" |
| 1233 | |
| 1234 | intf1 = "pg1" |
| 1235 | intf2 = "pg3" |
| 1236 | intf3 = "pg5" |
| 1237 | direction = "rx" |
| 1238 | |
| 1239 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1240 | @unittest.skipUnless(config.extended, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1241 | class DisableIPFIX(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1242 | """Disable IPFIX""" |
| 1243 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1244 | @classmethod |
| 1245 | def setUpClass(cls): |
| 1246 | super(DisableIPFIX, cls).setUpClass() |
| 1247 | |
| 1248 | @classmethod |
| 1249 | def tearDownClass(cls): |
| 1250 | super(DisableIPFIX, cls).tearDownClass() |
| 1251 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1252 | def test_0001(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1253 | """disable IPFIX after first packets""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1254 | self.logger.info("FFP_TEST_START_0001") |
| 1255 | self.pg_enable_capture(self.pg_interfaces) |
| 1256 | self.pkts = [] |
| 1257 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1258 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1259 | ipfix.add_vpp_config() |
| 1260 | |
| 1261 | ipfix_decoder = IPFIXDecoder() |
| 1262 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1263 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1264 | |
| 1265 | self.create_stream() |
| 1266 | self.send_packets() |
| 1267 | |
| 1268 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1269 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1270 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1271 | self.collector.get_capture(4) |
| 1272 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1273 | # disable IPFIX |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1274 | ipfix.disable_exporter() |
| 1275 | self.pg_enable_capture([self.collector]) |
| 1276 | |
| 1277 | self.send_packets() |
| 1278 | |
| 1279 | # make sure no one packet arrived in 1 minute |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1280 | self.vapi.ipfix_flush() |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 1281 | self.sleep(1, "wait before verifying no packets sent") |
| 1282 | self.collector.assert_nothing_captured() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1283 | |
| 1284 | ipfix.remove_vpp_config() |
| 1285 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1286 | |
| 1287 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1288 | @unittest.skipUnless(config.extended, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1289 | class ReenableIPFIX(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1290 | """Re-enable IPFIX""" |
| 1291 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1292 | @classmethod |
| 1293 | def setUpClass(cls): |
| 1294 | super(ReenableIPFIX, cls).setUpClass() |
| 1295 | |
| 1296 | @classmethod |
| 1297 | def tearDownClass(cls): |
| 1298 | super(ReenableIPFIX, cls).tearDownClass() |
| 1299 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1300 | def test_0011(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1301 | """disable IPFIX after first packets and re-enable after few packets""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1302 | self.logger.info("FFP_TEST_START_0001") |
| 1303 | self.pg_enable_capture(self.pg_interfaces) |
| 1304 | self.pkts = [] |
| 1305 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1306 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1307 | ipfix.add_vpp_config() |
| 1308 | |
| 1309 | ipfix_decoder = IPFIXDecoder() |
| 1310 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1311 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1312 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1313 | self.create_stream(packets=5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1314 | self.send_packets() |
| 1315 | |
| 1316 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1317 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1318 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1319 | self.collector.get_capture(4) |
| 1320 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1321 | # disable IPFIX |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1322 | ipfix.disable_exporter() |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1323 | self.vapi.ipfix_flush() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1324 | self.pg_enable_capture([self.collector]) |
| 1325 | |
| 1326 | self.send_packets() |
| 1327 | |
| 1328 | # make sure no one packet arrived in active timer span |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1329 | self.vapi.ipfix_flush() |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 1330 | self.sleep(1, "wait before verifying no packets sent") |
| 1331 | self.collector.assert_nothing_captured() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1332 | self.pg2.get_capture(5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1333 | |
| 1334 | # enable IPFIX |
| 1335 | ipfix.enable_exporter() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1336 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1337 | capture = self.collector.get_capture(4) |
| 1338 | nr_templates = 0 |
| 1339 | nr_data = 0 |
| 1340 | for p in capture: |
| 1341 | self.assertTrue(p.haslayer(IPFIX)) |
| 1342 | if p.haslayer(Template): |
| 1343 | nr_templates += 1 |
| 1344 | self.assertTrue(nr_templates, 3) |
| 1345 | for p in capture: |
| 1346 | self.assertTrue(p.haslayer(IPFIX)) |
| 1347 | if p.haslayer(Data): |
| 1348 | nr_data += 1 |
| 1349 | self.assertTrue(nr_templates, 1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1350 | |
| 1351 | ipfix.remove_vpp_config() |
| 1352 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1353 | |
| 1354 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1355 | @unittest.skipUnless(config.extended, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1356 | class DisableFP(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1357 | """Disable Flowprobe feature""" |
| 1358 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1359 | @classmethod |
| 1360 | def setUpClass(cls): |
| 1361 | super(DisableFP, cls).setUpClass() |
| 1362 | |
| 1363 | @classmethod |
| 1364 | def tearDownClass(cls): |
| 1365 | super(DisableFP, cls).tearDownClass() |
| 1366 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1367 | def test_0001(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1368 | """disable flowprobe feature after first packets""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1369 | self.logger.info("FFP_TEST_START_0001") |
| 1370 | self.pg_enable_capture(self.pg_interfaces) |
| 1371 | self.pkts = [] |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1372 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1373 | ipfix.add_vpp_config() |
| 1374 | |
| 1375 | ipfix_decoder = IPFIXDecoder() |
| 1376 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1377 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1378 | |
| 1379 | self.create_stream() |
| 1380 | self.send_packets() |
| 1381 | |
| 1382 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1383 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1384 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1385 | self.collector.get_capture(4) |
| 1386 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1387 | # disable IPFIX |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1388 | ipfix.disable_flowprobe_feature() |
| 1389 | self.pg_enable_capture([self.collector]) |
| 1390 | |
| 1391 | self.send_packets() |
| 1392 | |
| 1393 | # make sure no one packet arrived in active timer span |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1394 | self.vapi.ipfix_flush() |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 1395 | self.sleep(1, "wait before verifying no packets sent") |
| 1396 | self.collector.assert_nothing_captured() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1397 | |
| 1398 | ipfix.remove_vpp_config() |
| 1399 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1400 | |
Alexander Chernavin | f68afe8 | 2023-10-03 12:45:51 +0000 | [diff] [blame] | 1401 | def test_no_leftover_flows_after_disabling(self): |
| 1402 | """disable flowprobe feature and expect no leftover flows""" |
| 1403 | self.pg_enable_capture(self.pg_interfaces) |
| 1404 | self.pkts = [] |
| 1405 | |
| 1406 | # enable ip4 datapath for an interface |
| 1407 | # set active and passive timers |
| 1408 | ipfix = VppCFLOW( |
| 1409 | test=self, |
| 1410 | active=3, |
| 1411 | passive=4, |
| 1412 | intf="pg3", |
| 1413 | layer="l3", |
| 1414 | datapath="ip4", |
| 1415 | direction="rx", |
| 1416 | mtu=100, |
| 1417 | ) |
| 1418 | ipfix.add_vpp_config() |
| 1419 | |
| 1420 | # template packet should arrive immediately |
| 1421 | ipfix.verify_templates(count=1) |
| 1422 | |
| 1423 | # send some ip4 packets |
| 1424 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=5) |
| 1425 | self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 1426 | |
| 1427 | # disable feature for the interface |
| 1428 | # currently stored ip4 flows should be removed |
| 1429 | ipfix.disable_flowprobe_feature() |
| 1430 | |
| 1431 | # no leftover ip4 flows are expected |
| 1432 | self.pg_enable_capture([self.collector]) |
| 1433 | self.sleep(12, "wait for leftover ip4 flows during three passive intervals") |
| 1434 | self.collector.assert_nothing_captured() |
| 1435 | |
| 1436 | # cleanup |
| 1437 | ipfix.disable_exporter() |
| 1438 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1439 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1440 | @unittest.skipUnless(config.extended, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1441 | class ReenableFP(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1442 | """Re-enable Flowprobe feature""" |
| 1443 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1444 | @classmethod |
| 1445 | def setUpClass(cls): |
| 1446 | super(ReenableFP, cls).setUpClass() |
| 1447 | |
| 1448 | @classmethod |
| 1449 | def tearDownClass(cls): |
| 1450 | super(ReenableFP, cls).tearDownClass() |
| 1451 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1452 | def test_0001(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1453 | """disable flowprobe feature after first packets and re-enable |
| 1454 | after few packets""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1455 | self.logger.info("FFP_TEST_START_0001") |
| 1456 | self.pg_enable_capture(self.pg_interfaces) |
| 1457 | self.pkts = [] |
| 1458 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1459 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1460 | ipfix.add_vpp_config() |
| 1461 | |
| 1462 | ipfix_decoder = IPFIXDecoder() |
| 1463 | # template packet should arrive immediately |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1464 | self.vapi.ipfix_flush() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1465 | templates = ipfix.verify_templates(ipfix_decoder, timeout=3) |
| 1466 | |
| 1467 | self.create_stream() |
| 1468 | self.send_packets() |
| 1469 | |
| 1470 | # make sure the one packet we expect actually showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1471 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1472 | self.wait_for_cflow_packet(self.collector, templates[1], 5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1473 | self.collector.get_capture(4) |
| 1474 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1475 | # disable FPP feature |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1476 | ipfix.disable_flowprobe_feature() |
| 1477 | self.pg_enable_capture([self.collector]) |
| 1478 | |
| 1479 | self.send_packets() |
| 1480 | |
| 1481 | # make sure no one packet arrived in active timer span |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1482 | self.vapi.ipfix_flush() |
Klement Sekera | c479457 | 2021-09-08 15:15:59 +0200 | [diff] [blame] | 1483 | self.sleep(5, "wait before verifying no packets sent") |
| 1484 | self.collector.assert_nothing_captured() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1485 | |
| 1486 | # enable FPP feature |
| 1487 | ipfix.enable_flowprobe_feature() |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1488 | self.vapi.ipfix_flush() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1489 | templates = ipfix.verify_templates(ipfix_decoder, timeout=3) |
| 1490 | |
| 1491 | self.send_packets() |
| 1492 | |
| 1493 | # make sure the next packets (templates and data) we expect actually |
| 1494 | # showed up |
Paul Vinciguerra | 21b83e9 | 2019-06-24 09:55:46 -0400 | [diff] [blame] | 1495 | self.vapi.ipfix_flush() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1496 | self.wait_for_cflow_packet(self.collector, templates[1], 5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1497 | self.collector.get_capture(4) |
| 1498 | |
| 1499 | ipfix.remove_vpp_config() |
| 1500 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1501 | |
| 1502 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1503 | if __name__ == "__main__": |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1504 | unittest.main(testRunner=VppTestRunner) |