Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
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 |
| 14 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 15 | from framework import VppTestCase, VppTestRunner, running_extended_tests |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 16 | from vpp_object import VppObject |
| 17 | from vpp_pg_interface import CaptureTimeoutError |
| 18 | from util import ppp |
| 19 | from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 20 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class VppCFLOW(VppObject): |
| 24 | """CFLOW object for IPFIX exporter and Flowprobe feature""" |
| 25 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 26 | def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100, |
| 27 | mtu=1024, datapath='l2', layer='l2 l3 l4'): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 28 | self._test = test |
| 29 | self._intf = intf |
| 30 | self._active = active |
| 31 | if passive == 0 or passive < active: |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 32 | self._passive = active+1 |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 33 | else: |
| 34 | self._passive = passive |
| 35 | self._datapath = datapath # l2 ip4 ip6 |
| 36 | self._collect = layer # l2 l3 l4 |
| 37 | self._timeout = timeout |
| 38 | self._mtu = mtu |
| 39 | self._configured = False |
| 40 | |
| 41 | def add_vpp_config(self): |
| 42 | self.enable_exporter() |
| 43 | self._test.vapi.ppcli("flowprobe params record %s active %s " |
| 44 | "passive %s" % (self._collect, self._active, |
| 45 | self._passive)) |
| 46 | self.enable_flowprobe_feature() |
| 47 | self._test.vapi.cli("ipfix flush") |
| 48 | self._configured = True |
| 49 | |
| 50 | def remove_vpp_config(self): |
| 51 | self.disable_exporter() |
| 52 | self.disable_flowprobe_feature() |
| 53 | self._test.vapi.cli("ipfix flush") |
| 54 | self._configured = False |
| 55 | |
| 56 | def enable_exporter(self): |
| 57 | self._test.vapi.set_ipfix_exporter( |
| 58 | collector_address=self._test.pg0.remote_ip4n, |
| 59 | src_address=self._test.pg0.local_ip4n, |
| 60 | path_mtu=self._mtu, |
| 61 | template_interval=self._timeout) |
| 62 | |
| 63 | def enable_flowprobe_feature(self): |
| 64 | self._test.vapi.ppcli("flowprobe feature add-del %s %s" % |
| 65 | (self._intf, self._datapath)) |
| 66 | |
| 67 | def disable_exporter(self): |
| 68 | self._test.vapi.cli("set ipfix exporter collector 0.0.0.0") |
| 69 | |
| 70 | def disable_flowprobe_feature(self): |
| 71 | self._test.vapi.cli("flowprobe feature add-del %s %s disable" % |
| 72 | (self._intf, self._datapath)) |
| 73 | |
| 74 | def object_id(self): |
| 75 | return "ipfix-collector-%s" % (self._src, self.dst) |
| 76 | |
| 77 | def query_vpp_config(self): |
| 78 | return self._configured |
| 79 | |
| 80 | def verify_templates(self, decoder=None, timeout=1, count=3): |
| 81 | templates = [] |
| 82 | p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout) |
| 83 | self._test.assertTrue(p.haslayer(IPFIX)) |
| 84 | if decoder is not None and p.haslayer(Template): |
| 85 | templates.append(p[Template].templateID) |
| 86 | decoder.add_template(p.getlayer(Template)) |
| 87 | if count > 1: |
| 88 | p = self._test.wait_for_cflow_packet(self._test.collector, 2) |
| 89 | self._test.assertTrue(p.haslayer(IPFIX)) |
| 90 | if decoder is not None and p.haslayer(Template): |
| 91 | templates.append(p[Template].templateID) |
| 92 | decoder.add_template(p.getlayer(Template)) |
| 93 | if count > 2: |
| 94 | p = self._test.wait_for_cflow_packet(self._test.collector, 2) |
| 95 | self._test.assertTrue(p.haslayer(IPFIX)) |
| 96 | if decoder is not None and p.haslayer(Template): |
| 97 | templates.append(p[Template].templateID) |
| 98 | decoder.add_template(p.getlayer(Template)) |
| 99 | return templates |
| 100 | |
| 101 | |
| 102 | class MethodHolder(VppTestCase): |
| 103 | """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """ |
| 104 | |
| 105 | # Test variables |
| 106 | debug_print = False |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 107 | max_number_of_packets = 10 |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 108 | pkts = [] |
| 109 | |
| 110 | @classmethod |
| 111 | def setUpClass(cls): |
| 112 | """ |
| 113 | Perform standard class setup (defined by class method setUpClass in |
| 114 | class VppTestCase) before running the test case, set test case related |
| 115 | variables and configure VPP. |
| 116 | """ |
| 117 | super(MethodHolder, cls).setUpClass() |
| 118 | try: |
| 119 | # Create pg interfaces |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 120 | cls.create_pg_interfaces(range(9)) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 121 | |
| 122 | # Packet sizes |
| 123 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 124 | |
| 125 | # Create BD with MAC learning and unknown unicast flooding disabled |
| 126 | # and put interfaces to this BD |
| 127 | cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame^] | 128 | cls.vapi.sw_interface_set_l2_bridge( |
| 129 | rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1) |
| 130 | cls.vapi.sw_interface_set_l2_bridge( |
| 131 | rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 132 | |
| 133 | # Set up all interfaces |
| 134 | for i in cls.pg_interfaces: |
| 135 | i.admin_up() |
| 136 | |
| 137 | cls.pg0.config_ip4() |
| 138 | cls.pg0.configure_ipv4_neighbors() |
| 139 | cls.collector = cls.pg0 |
| 140 | |
| 141 | cls.pg1.config_ip4() |
| 142 | cls.pg1.resolve_arp() |
| 143 | cls.pg2.config_ip4() |
| 144 | cls.pg2.resolve_arp() |
| 145 | cls.pg3.config_ip4() |
| 146 | cls.pg3.resolve_arp() |
| 147 | cls.pg4.config_ip4() |
| 148 | cls.pg4.resolve_arp() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 149 | cls.pg7.config_ip4() |
| 150 | cls.pg8.config_ip4() |
| 151 | cls.pg8.configure_ipv4_neighbors() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 152 | |
| 153 | cls.pg5.config_ip6() |
| 154 | cls.pg5.resolve_ndp() |
| 155 | cls.pg5.disable_ipv6_ra() |
| 156 | cls.pg6.config_ip6() |
| 157 | cls.pg6.resolve_ndp() |
| 158 | cls.pg6.disable_ipv6_ra() |
| 159 | except Exception: |
| 160 | super(MethodHolder, cls).tearDownClass() |
| 161 | raise |
| 162 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 163 | @classmethod |
| 164 | def tearDownClass(cls): |
| 165 | super(MethodHolder, cls).tearDownClass() |
| 166 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 167 | def create_stream(self, src_if=None, dst_if=None, packets=None, |
| 168 | size=None, ip_ver='v4'): |
| 169 | """Create a packet stream to tickle the plugin |
| 170 | |
| 171 | :param VppInterface src_if: Source interface for packet stream |
| 172 | :param VppInterface src_if: Dst interface for packet stream |
| 173 | """ |
| 174 | if src_if is None: |
| 175 | src_if = self.pg1 |
| 176 | if dst_if is None: |
| 177 | dst_if = self.pg2 |
| 178 | self.pkts = [] |
| 179 | if packets is None: |
| 180 | packets = random.randint(1, self.max_number_of_packets) |
| 181 | pkt_size = size |
| 182 | for p in range(0, packets): |
| 183 | if size is None: |
| 184 | pkt_size = random.choice(self.pg_if_packet_sizes) |
| 185 | info = self.create_packet_info(src_if, dst_if) |
| 186 | payload = self.info_to_payload(info) |
| 187 | p = Ether(src=src_if.remote_mac, dst=src_if.local_mac) |
| 188 | if ip_ver == 'v4': |
| 189 | p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) |
| 190 | else: |
| 191 | p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 192 | p /= UDP(sport=1234, dport=4321) |
| 193 | p /= Raw(payload) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 194 | info.data = p.copy() |
| 195 | self.extend_packet(p, pkt_size) |
| 196 | self.pkts.append(p) |
| 197 | |
| 198 | def verify_cflow_data(self, decoder, capture, cflow): |
| 199 | octets = 0 |
| 200 | packets = 0 |
| 201 | for p in capture: |
| 202 | octets += p[IP].len |
| 203 | packets += 1 |
| 204 | if cflow.haslayer(Data): |
| 205 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 206 | for record in data: |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 207 | self.assertEqual(int(binascii.hexlify(record[1]), 16), octets) |
| 208 | self.assertEqual(int(binascii.hexlify(record[2]), 16), packets) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 209 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 210 | def send_packets(self, src_if=None, dst_if=None): |
| 211 | if src_if is None: |
| 212 | src_if = self.pg1 |
| 213 | if dst_if is None: |
| 214 | dst_if = self.pg2 |
| 215 | self.pg_enable_capture([dst_if]) |
| 216 | src_if.add_stream(self.pkts) |
| 217 | self.pg_start() |
| 218 | return dst_if.get_capture(len(self.pkts)) |
| 219 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 220 | def verify_cflow_data_detail(self, decoder, capture, cflow, |
| 221 | data_set={1: 'octets', 2: 'packets'}, |
| 222 | ip_ver='v4'): |
| 223 | if self.debug_print: |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 224 | print(capture[0].show()) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 225 | if cflow.haslayer(Data): |
| 226 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 227 | if self.debug_print: |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 228 | print(data) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 229 | if ip_ver == 'v4': |
| 230 | ip_layer = capture[0][IP] |
| 231 | else: |
| 232 | ip_layer = capture[0][IPv6] |
| 233 | if data_set is not None: |
| 234 | for record in data: |
| 235 | # skip flow if in/out gress interface is 0 |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 236 | if int(binascii.hexlify(record[10]), 16) == 0: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 237 | continue |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 238 | if int(binascii.hexlify(record[14]), 16) == 0: |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 239 | continue |
| 240 | |
| 241 | for field in data_set: |
| 242 | if field not in record.keys(): |
| 243 | continue |
| 244 | value = data_set[field] |
| 245 | if value == 'octets': |
| 246 | value = ip_layer.len |
| 247 | if ip_ver == 'v6': |
| 248 | value += 40 # ??? is this correct |
| 249 | elif value == 'packets': |
| 250 | value = 1 |
| 251 | elif value == 'src_ip': |
| 252 | if ip_ver == 'v4': |
| 253 | ip = socket.inet_pton(socket.AF_INET, |
| 254 | ip_layer.src) |
| 255 | else: |
| 256 | ip = socket.inet_pton(socket.AF_INET6, |
| 257 | ip_layer.src) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 258 | value = int(binascii.hexlify(ip), 16) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 259 | elif value == 'dst_ip': |
| 260 | if ip_ver == 'v4': |
| 261 | ip = socket.inet_pton(socket.AF_INET, |
| 262 | ip_layer.dst) |
| 263 | else: |
| 264 | ip = socket.inet_pton(socket.AF_INET6, |
| 265 | ip_layer.dst) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 266 | value = int(binascii.hexlify(ip), 16) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 267 | elif value == 'sport': |
| 268 | value = int(capture[0][UDP].sport) |
| 269 | elif value == 'dport': |
| 270 | value = int(capture[0][UDP].dport) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 271 | self.assertEqual(int(binascii.hexlify( |
| 272 | record[field]), 16), |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 273 | value) |
| 274 | |
| 275 | def verify_cflow_data_notimer(self, decoder, capture, cflows): |
| 276 | idx = 0 |
| 277 | for cflow in cflows: |
| 278 | if cflow.haslayer(Data): |
| 279 | data = decoder.decode_data_set(cflow.getlayer(Set)) |
| 280 | else: |
| 281 | raise Exception("No CFLOW data") |
| 282 | |
| 283 | for rec in data: |
| 284 | p = capture[idx] |
| 285 | idx += 1 |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 286 | self.assertEqual(p[IP].len, int( |
| 287 | binascii.hexlify(rec[1]), 16)) |
| 288 | self.assertEqual(1, int( |
| 289 | binascii.hexlify(rec[2]), 16)) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 290 | self.assertEqual(len(capture), idx) |
| 291 | |
| 292 | def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1, |
| 293 | expected=True): |
| 294 | """ wait for CFLOW packet and verify its correctness |
| 295 | |
| 296 | :param timeout: how long to wait |
| 297 | |
| 298 | :returns: tuple (packet, time spent waiting for packet) |
| 299 | """ |
| 300 | self.logger.info("IPFIX: Waiting for CFLOW packet") |
| 301 | deadline = time.time() + timeout |
| 302 | counter = 0 |
| 303 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
| 304 | while True: |
| 305 | counter += 1 |
| 306 | # sanity check |
| 307 | self.assert_in_range(counter, 0, 100, "number of packets ignored") |
| 308 | time_left = deadline - time.time() |
| 309 | try: |
| 310 | if time_left < 0 and expected: |
| 311 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
| 312 | raise CaptureTimeoutError( |
| 313 | "Packet did not arrive within timeout") |
| 314 | p = collector_intf.wait_for_packet(timeout=time_left) |
| 315 | except CaptureTimeoutError: |
| 316 | if expected: |
| 317 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
| 318 | raise CaptureTimeoutError( |
| 319 | "Packet did not arrive within timeout") |
| 320 | else: |
| 321 | return |
| 322 | if not expected: |
| 323 | raise CaptureTimeoutError("Packet arrived even not expected") |
| 324 | self.assertEqual(p[Set].setID, set_id) |
| 325 | # self.logger.debug(self.vapi.ppcli("show flow table")) |
| 326 | self.logger.debug(ppp("IPFIX: Got packet:", p)) |
| 327 | break |
| 328 | return p |
| 329 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 330 | |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 331 | class Flowprobe(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 332 | """Template verification, timer tests""" |
| 333 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 334 | @classmethod |
| 335 | def setUpClass(cls): |
| 336 | super(Flowprobe, cls).setUpClass() |
| 337 | |
| 338 | @classmethod |
| 339 | def tearDownClass(cls): |
| 340 | super(Flowprobe, cls).tearDownClass() |
| 341 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 342 | def test_0001(self): |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 343 | """ timer less than template timeout""" |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 344 | self.logger.info("FFP_TEST_START_0001") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 345 | self.pg_enable_capture(self.pg_interfaces) |
| 346 | self.pkts = [] |
| 347 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 348 | ipfix = VppCFLOW(test=self, active=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 349 | ipfix.add_vpp_config() |
| 350 | |
| 351 | ipfix_decoder = IPFIXDecoder() |
| 352 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 353 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 354 | |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 355 | self.create_stream(packets=1) |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 356 | self.send_packets() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 357 | capture = self.pg2.get_capture(1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 358 | |
| 359 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 360 | cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 361 | self.verify_cflow_data(ipfix_decoder, capture, cflow) |
| 362 | |
| 363 | ipfix.remove_vpp_config() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 364 | self.logger.info("FFP_TEST_FINISH_0001") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 365 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 366 | def test_0002(self): |
| 367 | """ timer greater than template timeout""" |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 368 | self.logger.info("FFP_TEST_START_0002") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 369 | self.pg_enable_capture(self.pg_interfaces) |
| 370 | self.pkts = [] |
| 371 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 372 | ipfix = VppCFLOW(test=self, timeout=3, active=4) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 373 | ipfix.add_vpp_config() |
| 374 | |
| 375 | ipfix_decoder = IPFIXDecoder() |
| 376 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 377 | ipfix.verify_templates() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 378 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 379 | self.create_stream(packets=2) |
| 380 | self.send_packets() |
| 381 | capture = self.pg2.get_capture(2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 382 | |
| 383 | # next set of template packet should arrive after 20 seconds |
| 384 | # template packet should arrive within 20 s |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 385 | templates = ipfix.verify_templates(ipfix_decoder, timeout=5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 386 | |
| 387 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 388 | cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 389 | self.verify_cflow_data(ipfix_decoder, capture, cflow) |
| 390 | |
| 391 | ipfix.remove_vpp_config() |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 392 | self.logger.info("FFP_TEST_FINISH_0002") |
| 393 | |
| 394 | def test_cflow_packet(self): |
| 395 | """verify cflow packet fields""" |
| 396 | self.logger.info("FFP_TEST_START_0000") |
| 397 | self.pg_enable_capture(self.pg_interfaces) |
| 398 | self.pkts = [] |
| 399 | |
| 400 | ipfix = VppCFLOW(test=self, intf='pg8', datapath="ip4", |
| 401 | layer='l2 l3 l4', active=2) |
| 402 | ipfix.add_vpp_config() |
| 403 | |
| 404 | route_9001 = VppIpRoute(self, "9.0.0.0", 24, |
| 405 | [VppRoutePath(self.pg8._remote_hosts[0].ip4, |
| 406 | self.pg8.sw_if_index)]) |
| 407 | route_9001.add_vpp_config() |
| 408 | |
| 409 | ipfix_decoder = IPFIXDecoder() |
| 410 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
| 411 | |
| 412 | self.pkts = [(Ether(dst=self.pg7.local_mac, |
| 413 | src=self.pg7.remote_mac) / |
| 414 | IP(src=self.pg7.remote_ip4, dst="9.0.0.100") / |
| 415 | TCP(sport=1234, dport=4321, flags=80) / |
| 416 | Raw('\xa5' * 100))] |
| 417 | |
| 418 | nowUTC = int(time.time()) |
| 419 | nowUNIX = nowUTC+2208988800 |
| 420 | self.send_packets(src_if=self.pg7, dst_if=self.pg8) |
| 421 | |
| 422 | cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10) |
| 423 | self.collector.get_capture(2) |
| 424 | |
| 425 | if cflow[0].haslayer(IPFIX): |
| 426 | self.assertEqual(cflow[IPFIX].version, 10) |
| 427 | self.assertEqual(cflow[IPFIX].observationDomainID, 1) |
| 428 | self.assertEqual(cflow[IPFIX].sequenceNumber, 0) |
| 429 | self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5) |
| 430 | if cflow.haslayer(Data): |
| 431 | record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0] |
| 432 | # ingress interface |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 433 | self.assertEqual(int(binascii.hexlify(record[10]), 16), 8) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 434 | # egress interface |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 435 | self.assertEqual(int(binascii.hexlify(record[14]), 16), 9) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 436 | # packets |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 437 | self.assertEqual(int(binascii.hexlify(record[2]), 16), 1) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 438 | # src mac |
| 439 | self.assertEqual(':'.join(re.findall('..', record[56].encode( |
| 440 | 'hex'))), self.pg8.local_mac) |
| 441 | # dst mac |
| 442 | self.assertEqual(':'.join(re.findall('..', record[80].encode( |
| 443 | 'hex'))), self.pg8.remote_mac) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 444 | flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 445 | # flow start timestamp |
| 446 | self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 447 | flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32 |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 448 | # flow end timestamp |
| 449 | self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1) |
| 450 | # ethernet type |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 451 | self.assertEqual(int(binascii.hexlify(record[256]), 16), 8) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 452 | # src ip |
| 453 | self.assertEqual('.'.join(re.findall('..', record[8].encode( |
| 454 | 'hex'))), |
| 455 | '.'.join('{:02x}'.format(int(n)) for n in |
| 456 | self.pg7.remote_ip4.split('.'))) |
| 457 | # dst ip |
| 458 | self.assertEqual('.'.join(re.findall('..', record[12].encode( |
| 459 | 'hex'))), |
| 460 | '.'.join('{:02x}'.format(int(n)) for n in |
| 461 | "9.0.0.100".split('.'))) |
| 462 | # protocol (TCP) |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 463 | self.assertEqual(int(binascii.hexlify(record[4]), 16), 6) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 464 | # src port |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 465 | self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 466 | # dst port |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 467 | self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 468 | # tcp flags |
Paul Vinciguerra | 6e4c6ad | 2018-11-25 10:35:29 -0800 | [diff] [blame] | 469 | self.assertEqual(int(binascii.hexlify(record[6]), 16), 80) |
Ole Troan | ed92925 | 2017-06-13 21:15:40 +0200 | [diff] [blame] | 470 | |
| 471 | ipfix.remove_vpp_config() |
| 472 | self.logger.info("FFP_TEST_FINISH_0000") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 473 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 474 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 475 | class Datapath(MethodHolder): |
| 476 | """collect information on Ethernet, IP4 and IP6 datapath (no timers)""" |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 477 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 478 | @classmethod |
| 479 | def setUpClass(cls): |
| 480 | super(Datapath, cls).setUpClass() |
| 481 | |
| 482 | @classmethod |
| 483 | def tearDownClass(cls): |
| 484 | super(Datapath, cls).tearDownClass() |
| 485 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 486 | def test_templatesL2(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 487 | """ verify template on L2 datapath""" |
| 488 | self.logger.info("FFP_TEST_START_0000") |
| 489 | self.pg_enable_capture(self.pg_interfaces) |
| 490 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 491 | ipfix = VppCFLOW(test=self, layer='l2') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 492 | ipfix.add_vpp_config() |
| 493 | |
| 494 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 495 | self.vapi.cli("ipfix flush") |
| 496 | ipfix.verify_templates(timeout=3, count=1) |
| 497 | self.collector.get_capture(1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 498 | |
| 499 | ipfix.remove_vpp_config() |
| 500 | self.logger.info("FFP_TEST_FINISH_0000") |
| 501 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 502 | def test_L2onL2(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 503 | """ L2 data on L2 datapath""" |
| 504 | self.logger.info("FFP_TEST_START_0001") |
| 505 | self.pg_enable_capture(self.pg_interfaces) |
| 506 | self.pkts = [] |
| 507 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 508 | ipfix = VppCFLOW(test=self, layer='l2') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 509 | ipfix.add_vpp_config() |
| 510 | |
| 511 | ipfix_decoder = IPFIXDecoder() |
| 512 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 513 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 514 | |
| 515 | self.create_stream(packets=1) |
| 516 | capture = self.send_packets() |
| 517 | |
| 518 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 519 | self.vapi.cli("ipfix flush") |
| 520 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 521 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 522 | {2: 'packets', 256: 8}) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 523 | self.collector.get_capture(2) |
| 524 | |
| 525 | ipfix.remove_vpp_config() |
| 526 | self.logger.info("FFP_TEST_FINISH_0001") |
| 527 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 528 | def test_L3onL2(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 529 | """ L3 data on L2 datapath""" |
| 530 | self.logger.info("FFP_TEST_START_0002") |
| 531 | self.pg_enable_capture(self.pg_interfaces) |
| 532 | self.pkts = [] |
| 533 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 534 | ipfix = VppCFLOW(test=self, layer='l3') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 535 | ipfix.add_vpp_config() |
| 536 | |
| 537 | ipfix_decoder = IPFIXDecoder() |
| 538 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 539 | templates = ipfix.verify_templates(ipfix_decoder, count=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 540 | |
| 541 | self.create_stream(packets=1) |
| 542 | capture = self.send_packets() |
| 543 | |
| 544 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 545 | self.vapi.cli("ipfix flush") |
| 546 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 547 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 548 | {2: 'packets', 4: 17, |
| 549 | 8: 'src_ip', 12: 'dst_ip'}) |
| 550 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 551 | self.collector.get_capture(3) |
| 552 | |
| 553 | ipfix.remove_vpp_config() |
| 554 | self.logger.info("FFP_TEST_FINISH_0002") |
| 555 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 556 | def test_L4onL2(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 557 | """ L4 data on L2 datapath""" |
| 558 | self.logger.info("FFP_TEST_START_0003") |
| 559 | self.pg_enable_capture(self.pg_interfaces) |
| 560 | self.pkts = [] |
| 561 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 562 | ipfix = VppCFLOW(test=self, layer='l4') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 563 | ipfix.add_vpp_config() |
| 564 | |
| 565 | ipfix_decoder = IPFIXDecoder() |
| 566 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 567 | templates = ipfix.verify_templates(ipfix_decoder, count=2) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 568 | |
| 569 | self.create_stream(packets=1) |
| 570 | capture = self.send_packets() |
| 571 | |
| 572 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 573 | self.vapi.cli("ipfix flush") |
| 574 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 575 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 576 | {2: 'packets', 7: 'sport', 11: 'dport'}) |
| 577 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 578 | self.collector.get_capture(3) |
| 579 | |
| 580 | ipfix.remove_vpp_config() |
| 581 | self.logger.info("FFP_TEST_FINISH_0003") |
| 582 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 583 | def test_templatesIp4(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 584 | """ verify templates on IP4 datapath""" |
| 585 | self.logger.info("FFP_TEST_START_0000") |
| 586 | |
| 587 | self.pg_enable_capture(self.pg_interfaces) |
| 588 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 589 | ipfix = VppCFLOW(test=self, datapath='ip4') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 590 | ipfix.add_vpp_config() |
| 591 | |
| 592 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 593 | self.vapi.cli("ipfix flush") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 594 | ipfix.verify_templates(timeout=3, count=1) |
| 595 | self.collector.get_capture(1) |
| 596 | |
| 597 | ipfix.remove_vpp_config() |
| 598 | |
| 599 | self.logger.info("FFP_TEST_FINISH_0000") |
| 600 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 601 | def test_L2onIP4(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 602 | """ L2 data on IP4 datapath""" |
| 603 | self.logger.info("FFP_TEST_START_0001") |
| 604 | self.pg_enable_capture(self.pg_interfaces) |
| 605 | self.pkts = [] |
| 606 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 607 | ipfix = VppCFLOW(test=self, intf='pg4', layer='l2', datapath='ip4') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 608 | ipfix.add_vpp_config() |
| 609 | |
| 610 | ipfix_decoder = IPFIXDecoder() |
| 611 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 612 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 613 | |
| 614 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 615 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 616 | |
| 617 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 618 | self.vapi.cli("ipfix flush") |
| 619 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 620 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 621 | {2: 'packets', 256: 8}) |
| 622 | |
| 623 | # expected two templates and one cflow packet |
| 624 | self.collector.get_capture(2) |
| 625 | |
| 626 | ipfix.remove_vpp_config() |
| 627 | self.logger.info("FFP_TEST_FINISH_0001") |
| 628 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 629 | def test_L3onIP4(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 630 | """ L3 data on IP4 datapath""" |
| 631 | self.logger.info("FFP_TEST_START_0002") |
| 632 | self.pg_enable_capture(self.pg_interfaces) |
| 633 | self.pkts = [] |
| 634 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 635 | ipfix = VppCFLOW(test=self, intf='pg4', layer='l3', datapath='ip4') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 636 | ipfix.add_vpp_config() |
| 637 | |
| 638 | ipfix_decoder = IPFIXDecoder() |
| 639 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 640 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 641 | |
| 642 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 643 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 644 | |
| 645 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 646 | self.vapi.cli("ipfix flush") |
| 647 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 648 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 649 | {1: 'octets', 2: 'packets', |
| 650 | 8: 'src_ip', 12: 'dst_ip'}) |
| 651 | |
| 652 | # expected two templates and one cflow packet |
| 653 | self.collector.get_capture(2) |
| 654 | |
| 655 | ipfix.remove_vpp_config() |
| 656 | self.logger.info("FFP_TEST_FINISH_0002") |
| 657 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 658 | def test_L4onIP4(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 659 | """ L4 data on IP4 datapath""" |
| 660 | self.logger.info("FFP_TEST_START_0003") |
| 661 | self.pg_enable_capture(self.pg_interfaces) |
| 662 | self.pkts = [] |
| 663 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 664 | ipfix = VppCFLOW(test=self, intf='pg4', layer='l4', datapath='ip4') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 665 | ipfix.add_vpp_config() |
| 666 | |
| 667 | ipfix_decoder = IPFIXDecoder() |
| 668 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 669 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 670 | |
| 671 | self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1) |
| 672 | capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4) |
| 673 | |
| 674 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 675 | self.vapi.cli("ipfix flush") |
| 676 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 677 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 678 | {2: 'packets', 7: 'sport', 11: 'dport'}) |
| 679 | |
| 680 | # expected two templates and one cflow packet |
| 681 | self.collector.get_capture(2) |
| 682 | |
| 683 | ipfix.remove_vpp_config() |
| 684 | self.logger.info("FFP_TEST_FINISH_0003") |
| 685 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 686 | def test_templatesIP6(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 687 | """ verify templates on IP6 datapath""" |
| 688 | self.logger.info("FFP_TEST_START_0000") |
| 689 | self.pg_enable_capture(self.pg_interfaces) |
| 690 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 691 | ipfix = VppCFLOW(test=self, datapath='ip6') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 692 | ipfix.add_vpp_config() |
| 693 | |
| 694 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 695 | ipfix.verify_templates(count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 696 | self.collector.get_capture(1) |
| 697 | |
| 698 | ipfix.remove_vpp_config() |
| 699 | |
| 700 | self.logger.info("FFP_TEST_FINISH_0000") |
| 701 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 702 | def test_L2onIP6(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 703 | """ L2 data on IP6 datapath""" |
| 704 | self.logger.info("FFP_TEST_START_0001") |
| 705 | self.pg_enable_capture(self.pg_interfaces) |
| 706 | self.pkts = [] |
| 707 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 708 | ipfix = VppCFLOW(test=self, intf='pg6', layer='l2', datapath='ip6') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 709 | ipfix.add_vpp_config() |
| 710 | |
| 711 | ipfix_decoder = IPFIXDecoder() |
| 712 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 713 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 714 | |
| 715 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, |
| 716 | ip_ver='IPv6') |
| 717 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 718 | |
| 719 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 720 | self.vapi.cli("ipfix flush") |
| 721 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 722 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 723 | {2: 'packets', 256: 56710}, |
| 724 | ip_ver='v6') |
| 725 | |
| 726 | # expected two templates and one cflow packet |
| 727 | self.collector.get_capture(2) |
| 728 | |
| 729 | ipfix.remove_vpp_config() |
| 730 | self.logger.info("FFP_TEST_FINISH_0001") |
| 731 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 732 | def test_L3onIP6(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 733 | """ L3 data on IP6 datapath""" |
| 734 | self.logger.info("FFP_TEST_START_0002") |
| 735 | self.pg_enable_capture(self.pg_interfaces) |
| 736 | self.pkts = [] |
| 737 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 738 | ipfix = VppCFLOW(test=self, intf='pg6', layer='l3', datapath='ip6') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 739 | ipfix.add_vpp_config() |
| 740 | |
| 741 | ipfix_decoder = IPFIXDecoder() |
| 742 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 743 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 744 | |
| 745 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, |
| 746 | ip_ver='IPv6') |
| 747 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 748 | |
| 749 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 750 | self.vapi.cli("ipfix flush") |
| 751 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 752 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 753 | {2: 'packets', |
| 754 | 27: 'src_ip', 28: 'dst_ip'}, |
| 755 | ip_ver='v6') |
| 756 | |
| 757 | # expected two templates and one cflow packet |
| 758 | self.collector.get_capture(2) |
| 759 | |
| 760 | ipfix.remove_vpp_config() |
| 761 | self.logger.info("FFP_TEST_FINISH_0002") |
| 762 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 763 | def test_L4onIP6(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 764 | """ L4 data on IP6 datapath""" |
| 765 | self.logger.info("FFP_TEST_START_0003") |
| 766 | self.pg_enable_capture(self.pg_interfaces) |
| 767 | self.pkts = [] |
| 768 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 769 | ipfix = VppCFLOW(test=self, intf='pg6', layer='l4', datapath='ip6') |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 770 | ipfix.add_vpp_config() |
| 771 | |
| 772 | ipfix_decoder = IPFIXDecoder() |
| 773 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 774 | templates = ipfix.verify_templates(ipfix_decoder, count=1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 775 | |
| 776 | self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1, |
| 777 | ip_ver='IPv6') |
| 778 | capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6) |
| 779 | |
| 780 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 781 | self.vapi.cli("ipfix flush") |
| 782 | cflow = self.wait_for_cflow_packet(self.collector, templates[0]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 783 | self.verify_cflow_data_detail(ipfix_decoder, capture, cflow, |
| 784 | {2: 'packets', 7: 'sport', 11: 'dport'}, |
| 785 | ip_ver='v6') |
| 786 | |
| 787 | # expected two templates and one cflow packet |
| 788 | self.collector.get_capture(2) |
| 789 | |
| 790 | ipfix.remove_vpp_config() |
| 791 | self.logger.info("FFP_TEST_FINISH_0003") |
| 792 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 793 | def test_0001(self): |
| 794 | """ no timers, one CFLOW packet, 9 Flows inside""" |
| 795 | self.logger.info("FFP_TEST_START_0001") |
| 796 | self.pg_enable_capture(self.pg_interfaces) |
| 797 | self.pkts = [] |
| 798 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 799 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 800 | ipfix.add_vpp_config() |
| 801 | |
| 802 | ipfix_decoder = IPFIXDecoder() |
| 803 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 804 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 805 | |
| 806 | self.create_stream(packets=9) |
| 807 | capture = self.send_packets() |
| 808 | |
| 809 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 810 | self.vapi.cli("ipfix flush") |
| 811 | cflow = self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 812 | self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 813 | self.collector.get_capture(4) |
| 814 | |
| 815 | ipfix.remove_vpp_config() |
| 816 | self.logger.info("FFP_TEST_FINISH_0001") |
| 817 | |
| 818 | def test_0002(self): |
| 819 | """ no timers, two CFLOW packets (mtu=256), 3 Flows in each""" |
| 820 | self.logger.info("FFP_TEST_START_0002") |
| 821 | self.pg_enable_capture(self.pg_interfaces) |
| 822 | self.pkts = [] |
| 823 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 824 | ipfix = VppCFLOW(test=self, mtu=256) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 825 | ipfix.add_vpp_config() |
| 826 | |
| 827 | ipfix_decoder = IPFIXDecoder() |
| 828 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 829 | self.vapi.cli("ipfix flush") |
| 830 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 831 | |
| 832 | self.create_stream(packets=6) |
| 833 | capture = self.send_packets() |
| 834 | |
| 835 | # make sure the one packet we expect actually showed up |
| 836 | cflows = [] |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 837 | self.vapi.cli("ipfix flush") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 838 | cflows.append(self.wait_for_cflow_packet(self.collector, |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 839 | templates[1])) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 840 | cflows.append(self.wait_for_cflow_packet(self.collector, |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 841 | templates[1])) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 842 | self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows) |
| 843 | self.collector.get_capture(5) |
| 844 | |
| 845 | ipfix.remove_vpp_config() |
| 846 | self.logger.info("FFP_TEST_FINISH_0002") |
| 847 | |
| 848 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 849 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 850 | class DisableIPFIX(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 851 | """Disable IPFIX""" |
| 852 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 853 | @classmethod |
| 854 | def setUpClass(cls): |
| 855 | super(DisableIPFIX, cls).setUpClass() |
| 856 | |
| 857 | @classmethod |
| 858 | def tearDownClass(cls): |
| 859 | super(DisableIPFIX, cls).tearDownClass() |
| 860 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 861 | def test_0001(self): |
| 862 | """ disable IPFIX after first packets""" |
| 863 | self.logger.info("FFP_TEST_START_0001") |
| 864 | self.pg_enable_capture(self.pg_interfaces) |
| 865 | self.pkts = [] |
| 866 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 867 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 868 | ipfix.add_vpp_config() |
| 869 | |
| 870 | ipfix_decoder = IPFIXDecoder() |
| 871 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 872 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 873 | |
| 874 | self.create_stream() |
| 875 | self.send_packets() |
| 876 | |
| 877 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 878 | self.vapi.cli("ipfix flush") |
| 879 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 880 | self.collector.get_capture(4) |
| 881 | |
| 882 | # disble IPFIX |
| 883 | ipfix.disable_exporter() |
| 884 | self.pg_enable_capture([self.collector]) |
| 885 | |
| 886 | self.send_packets() |
| 887 | |
| 888 | # make sure no one packet arrived in 1 minute |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 889 | self.vapi.cli("ipfix flush") |
| 890 | self.wait_for_cflow_packet(self.collector, templates[1], |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 891 | expected=False) |
| 892 | self.collector.get_capture(0) |
| 893 | |
| 894 | ipfix.remove_vpp_config() |
| 895 | self.logger.info("FFP_TEST_FINISH_0001") |
| 896 | |
| 897 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 898 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 899 | class ReenableIPFIX(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 900 | """Re-enable IPFIX""" |
| 901 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 902 | @classmethod |
| 903 | def setUpClass(cls): |
| 904 | super(ReenableIPFIX, cls).setUpClass() |
| 905 | |
| 906 | @classmethod |
| 907 | def tearDownClass(cls): |
| 908 | super(ReenableIPFIX, cls).tearDownClass() |
| 909 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 910 | def test_0011(self): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 911 | """ disable IPFIX after first packets and re-enable after few packets |
| 912 | """ |
| 913 | self.logger.info("FFP_TEST_START_0001") |
| 914 | self.pg_enable_capture(self.pg_interfaces) |
| 915 | self.pkts = [] |
| 916 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 917 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 918 | ipfix.add_vpp_config() |
| 919 | |
| 920 | ipfix_decoder = IPFIXDecoder() |
| 921 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 922 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 923 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 924 | self.create_stream(packets=5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 925 | self.send_packets() |
| 926 | |
| 927 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 928 | self.vapi.cli("ipfix flush") |
| 929 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 930 | self.collector.get_capture(4) |
| 931 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 932 | # disable IPFIX |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 933 | ipfix.disable_exporter() |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 934 | self.vapi.cli("ipfix flush") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 935 | self.pg_enable_capture([self.collector]) |
| 936 | |
| 937 | self.send_packets() |
| 938 | |
| 939 | # make sure no one packet arrived in active timer span |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 940 | self.vapi.cli("ipfix flush") |
| 941 | self.wait_for_cflow_packet(self.collector, templates[1], |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 942 | expected=False) |
| 943 | self.collector.get_capture(0) |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 944 | self.pg2.get_capture(5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 945 | |
| 946 | # enable IPFIX |
| 947 | ipfix.enable_exporter() |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 948 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 949 | capture = self.collector.get_capture(4) |
| 950 | nr_templates = 0 |
| 951 | nr_data = 0 |
| 952 | for p in capture: |
| 953 | self.assertTrue(p.haslayer(IPFIX)) |
| 954 | if p.haslayer(Template): |
| 955 | nr_templates += 1 |
| 956 | self.assertTrue(nr_templates, 3) |
| 957 | for p in capture: |
| 958 | self.assertTrue(p.haslayer(IPFIX)) |
| 959 | if p.haslayer(Data): |
| 960 | nr_data += 1 |
| 961 | self.assertTrue(nr_templates, 1) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 962 | |
| 963 | ipfix.remove_vpp_config() |
| 964 | self.logger.info("FFP_TEST_FINISH_0001") |
| 965 | |
| 966 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 967 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 968 | class DisableFP(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 969 | """Disable Flowprobe feature""" |
| 970 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 971 | @classmethod |
| 972 | def setUpClass(cls): |
| 973 | super(DisableFP, cls).setUpClass() |
| 974 | |
| 975 | @classmethod |
| 976 | def tearDownClass(cls): |
| 977 | super(DisableFP, cls).tearDownClass() |
| 978 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 979 | def test_0001(self): |
| 980 | """ disable flowprobe feature after first packets""" |
| 981 | self.logger.info("FFP_TEST_START_0001") |
| 982 | self.pg_enable_capture(self.pg_interfaces) |
| 983 | self.pkts = [] |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 984 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 985 | ipfix.add_vpp_config() |
| 986 | |
| 987 | ipfix_decoder = IPFIXDecoder() |
| 988 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 989 | templates = ipfix.verify_templates(ipfix_decoder) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 990 | |
| 991 | self.create_stream() |
| 992 | self.send_packets() |
| 993 | |
| 994 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 995 | self.vapi.cli("ipfix flush") |
| 996 | self.wait_for_cflow_packet(self.collector, templates[1]) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 997 | self.collector.get_capture(4) |
| 998 | |
| 999 | # disble IPFIX |
| 1000 | ipfix.disable_flowprobe_feature() |
| 1001 | self.pg_enable_capture([self.collector]) |
| 1002 | |
| 1003 | self.send_packets() |
| 1004 | |
| 1005 | # make sure no one packet arrived in active timer span |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1006 | self.vapi.cli("ipfix flush") |
| 1007 | self.wait_for_cflow_packet(self.collector, templates[1], |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1008 | expected=False) |
| 1009 | self.collector.get_capture(0) |
| 1010 | |
| 1011 | ipfix.remove_vpp_config() |
| 1012 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1013 | |
| 1014 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 1015 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1016 | class ReenableFP(MethodHolder): |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1017 | """Re-enable Flowprobe feature""" |
| 1018 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1019 | @classmethod |
| 1020 | def setUpClass(cls): |
| 1021 | super(ReenableFP, cls).setUpClass() |
| 1022 | |
| 1023 | @classmethod |
| 1024 | def tearDownClass(cls): |
| 1025 | super(ReenableFP, cls).tearDownClass() |
| 1026 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1027 | def test_0001(self): |
| 1028 | """ disable flowprobe feature after first packets and re-enable |
| 1029 | after few packets """ |
| 1030 | self.logger.info("FFP_TEST_START_0001") |
| 1031 | self.pg_enable_capture(self.pg_interfaces) |
| 1032 | self.pkts = [] |
| 1033 | |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1034 | ipfix = VppCFLOW(test=self) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1035 | ipfix.add_vpp_config() |
| 1036 | |
| 1037 | ipfix_decoder = IPFIXDecoder() |
| 1038 | # template packet should arrive immediately |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1039 | self.vapi.cli("ipfix flush") |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1040 | templates = ipfix.verify_templates(ipfix_decoder, timeout=3) |
| 1041 | |
| 1042 | self.create_stream() |
| 1043 | self.send_packets() |
| 1044 | |
| 1045 | # make sure the one packet we expect actually showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1046 | self.vapi.cli("ipfix flush") |
| 1047 | self.wait_for_cflow_packet(self.collector, templates[1], 5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1048 | self.collector.get_capture(4) |
| 1049 | |
| 1050 | # disble FPP feature |
| 1051 | ipfix.disable_flowprobe_feature() |
| 1052 | self.pg_enable_capture([self.collector]) |
| 1053 | |
| 1054 | self.send_packets() |
| 1055 | |
| 1056 | # make sure no one packet arrived in active timer span |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1057 | self.vapi.cli("ipfix flush") |
| 1058 | self.wait_for_cflow_packet(self.collector, templates[1], 5, |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1059 | expected=False) |
| 1060 | self.collector.get_capture(0) |
| 1061 | |
| 1062 | # enable FPP feature |
| 1063 | ipfix.enable_flowprobe_feature() |
| 1064 | self.vapi.cli("ipfix flush") |
| 1065 | templates = ipfix.verify_templates(ipfix_decoder, timeout=3) |
| 1066 | |
| 1067 | self.send_packets() |
| 1068 | |
| 1069 | # make sure the next packets (templates and data) we expect actually |
| 1070 | # showed up |
Pavel Kotucek | 89111d0 | 2017-06-12 08:26:13 +0200 | [diff] [blame] | 1071 | self.vapi.cli("ipfix flush") |
| 1072 | self.wait_for_cflow_packet(self.collector, templates[1], 5) |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 1073 | self.collector.get_capture(4) |
| 1074 | |
| 1075 | ipfix.remove_vpp_config() |
| 1076 | self.logger.info("FFP_TEST_FINISH_0001") |
| 1077 | |
| 1078 | |
| 1079 | if __name__ == '__main__': |
| 1080 | unittest.main(testRunner=VppTestRunner) |