blob: 5bafd39ecebd778ecb0a961e6e6cb1774a683196 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Paul Vinciguerra661f91f2018-11-28 19:06:41 -08002from __future__ import print_function
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -08003import binascii
Ole Troan5c749732017-03-13 13:39:52 +01004import random
5import socket
6import unittest
7import time
Ole Troaned929252017-06-13 21:15:40 +02008import re
Ole Troan5c749732017-03-13 13:39:52 +01009
10from scapy.packet import Raw
11from scapy.layers.l2 import Ether
Ole Troaned929252017-06-13 21:15:40 +020012from scapy.layers.inet import IP, TCP, UDP
Ole Troan5c749732017-03-13 13:39:52 +010013from scapy.layers.inet6 import IPv6
14
Klement Sekerab23ffd72021-05-31 16:08:53 +020015from config import config
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +000016from framework import tag_fixme_vpp_workers
Klement Sekerab23ffd72021-05-31 16:08:53 +020017from framework import VppTestCase, VppTestRunner
Andrew Yourtchenko06f32812021-01-14 10:19:08 +000018from framework import tag_run_solo
Ole Troan5c749732017-03-13 13:39:52 +010019from vpp_object import VppObject
20from vpp_pg_interface import CaptureTimeoutError
21from util import ppp
22from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
Ole Troaned929252017-06-13 21:15:40 +020023from vpp_ip_route import VppIpRoute, VppRoutePath
Ole Troanb0d83f12019-10-21 23:13:46 +020024from vpp_papi.macaddress import mac_ntop
25from socket import inet_ntop
Ole Troan3013e692019-12-09 15:51:44 +010026from vpp_papi import VppEnum
Ole Troan5c749732017-03-13 13:39:52 +010027
28
29class VppCFLOW(VppObject):
30 """CFLOW object for IPFIX exporter and Flowprobe feature"""
31
Pavel Kotucek89111d02017-06-12 08:26:13 +020032 def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100,
33 mtu=1024, datapath='l2', layer='l2 l3 l4'):
Ole Troan5c749732017-03-13 13:39:52 +010034 self._test = test
35 self._intf = intf
36 self._active = active
37 if passive == 0 or passive < active:
Pavel Kotucek89111d02017-06-12 08:26:13 +020038 self._passive = active+1
Ole Troan5c749732017-03-13 13:39:52 +010039 else:
40 self._passive = passive
41 self._datapath = datapath # l2 ip4 ip6
42 self._collect = layer # l2 l3 l4
43 self._timeout = timeout
44 self._mtu = mtu
45 self._configured = False
46
47 def add_vpp_config(self):
48 self.enable_exporter()
Ole Troan3013e692019-12-09 15:51:44 +010049 l2_flag = 0
50 l3_flag = 0
51 l4_flag = 0
52 if 'l2' in self._collect.lower():
53 l2_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
54 FLOWPROBE_RECORD_FLAG_L2)
55 if 'l3' in self._collect.lower():
56 l3_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
57 FLOWPROBE_RECORD_FLAG_L3)
58 if 'l4' in self._collect.lower():
59 l4_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
60 FLOWPROBE_RECORD_FLAG_L4)
Paul Vinciguerraec850a82019-03-19 08:07:53 -070061 self._test.vapi.flowprobe_params(
Ole Troan3013e692019-12-09 15:51:44 +010062 record_flags=(l2_flag | l3_flag | l4_flag),
Paul Vinciguerraec850a82019-03-19 08:07:53 -070063 active_timer=self._active, passive_timer=self._passive)
Ole Troan5c749732017-03-13 13:39:52 +010064 self.enable_flowprobe_feature()
65 self._test.vapi.cli("ipfix flush")
66 self._configured = True
67
68 def remove_vpp_config(self):
69 self.disable_exporter()
70 self.disable_flowprobe_feature()
71 self._test.vapi.cli("ipfix flush")
72 self._configured = False
73
74 def enable_exporter(self):
75 self._test.vapi.set_ipfix_exporter(
Jakub Grajciar2f71a882019-10-10 14:21:22 +020076 collector_address=self._test.pg0.remote_ip4,
77 src_address=self._test.pg0.local_ip4,
Ole Troan5c749732017-03-13 13:39:52 +010078 path_mtu=self._mtu,
79 template_interval=self._timeout)
80
81 def enable_flowprobe_feature(self):
82 self._test.vapi.ppcli("flowprobe feature add-del %s %s" %
83 (self._intf, self._datapath))
84
85 def disable_exporter(self):
86 self._test.vapi.cli("set ipfix exporter collector 0.0.0.0")
87
88 def disable_flowprobe_feature(self):
89 self._test.vapi.cli("flowprobe feature add-del %s %s disable" %
90 (self._intf, self._datapath))
91
92 def object_id(self):
Paul Vinciguerrae3a0e6e2019-03-14 08:46:52 -070093 return "ipfix-collector-%s-%s" % (self._src, self.dst)
Ole Troan5c749732017-03-13 13:39:52 +010094
95 def query_vpp_config(self):
96 return self._configured
97
98 def verify_templates(self, decoder=None, timeout=1, count=3):
99 templates = []
Klement Sekerac4794572021-09-08 15:15:59 +0200100 self._test.assertIn(count, (1, 2, 3))
101 for _ in range(count):
102 p = self._test.wait_for_cflow_packet(self._test.collector, 2,
103 timeout)
Ole Troan5c749732017-03-13 13:39:52 +0100104 self._test.assertTrue(p.haslayer(IPFIX))
105 if decoder is not None and p.haslayer(Template):
106 templates.append(p[Template].templateID)
107 decoder.add_template(p.getlayer(Template))
108 return templates
109
110
111class MethodHolder(VppTestCase):
112 """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """
113
114 # Test variables
115 debug_print = False
Pavel Kotucek89111d02017-06-12 08:26:13 +0200116 max_number_of_packets = 10
Ole Troan5c749732017-03-13 13:39:52 +0100117 pkts = []
118
119 @classmethod
120 def setUpClass(cls):
121 """
122 Perform standard class setup (defined by class method setUpClass in
123 class VppTestCase) before running the test case, set test case related
124 variables and configure VPP.
125 """
126 super(MethodHolder, cls).setUpClass()
127 try:
128 # Create pg interfaces
Ole Troaned929252017-06-13 21:15:40 +0200129 cls.create_pg_interfaces(range(9))
Ole Troan5c749732017-03-13 13:39:52 +0100130
131 # Packet sizes
132 cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
133
134 # Create BD with MAC learning and unknown unicast flooding disabled
135 # and put interfaces to this BD
136 cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1)
Ole Troana5b2eec2019-03-11 19:23:25 +0100137 cls.vapi.sw_interface_set_l2_bridge(
138 rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1)
139 cls.vapi.sw_interface_set_l2_bridge(
140 rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1)
Ole Troan5c749732017-03-13 13:39:52 +0100141
142 # Set up all interfaces
143 for i in cls.pg_interfaces:
144 i.admin_up()
145
146 cls.pg0.config_ip4()
147 cls.pg0.configure_ipv4_neighbors()
148 cls.collector = cls.pg0
149
150 cls.pg1.config_ip4()
151 cls.pg1.resolve_arp()
152 cls.pg2.config_ip4()
153 cls.pg2.resolve_arp()
154 cls.pg3.config_ip4()
155 cls.pg3.resolve_arp()
156 cls.pg4.config_ip4()
157 cls.pg4.resolve_arp()
Ole Troaned929252017-06-13 21:15:40 +0200158 cls.pg7.config_ip4()
159 cls.pg8.config_ip4()
160 cls.pg8.configure_ipv4_neighbors()
Ole Troan5c749732017-03-13 13:39:52 +0100161
162 cls.pg5.config_ip6()
163 cls.pg5.resolve_ndp()
164 cls.pg5.disable_ipv6_ra()
165 cls.pg6.config_ip6()
166 cls.pg6.resolve_ndp()
167 cls.pg6.disable_ipv6_ra()
168 except Exception:
169 super(MethodHolder, cls).tearDownClass()
170 raise
171
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800172 @classmethod
173 def tearDownClass(cls):
174 super(MethodHolder, cls).tearDownClass()
175
Ole Troan5c749732017-03-13 13:39:52 +0100176 def create_stream(self, src_if=None, dst_if=None, packets=None,
177 size=None, ip_ver='v4'):
178 """Create a packet stream to tickle the plugin
179
180 :param VppInterface src_if: Source interface for packet stream
181 :param VppInterface src_if: Dst interface for packet stream
182 """
183 if src_if is None:
184 src_if = self.pg1
185 if dst_if is None:
186 dst_if = self.pg2
187 self.pkts = []
188 if packets is None:
189 packets = random.randint(1, self.max_number_of_packets)
190 pkt_size = size
191 for p in range(0, packets):
192 if size is None:
193 pkt_size = random.choice(self.pg_if_packet_sizes)
194 info = self.create_packet_info(src_if, dst_if)
195 payload = self.info_to_payload(info)
196 p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
197 if ip_ver == 'v4':
198 p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
199 else:
200 p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
Ole Troaned929252017-06-13 21:15:40 +0200201 p /= UDP(sport=1234, dport=4321)
202 p /= Raw(payload)
Ole Troan5c749732017-03-13 13:39:52 +0100203 info.data = p.copy()
204 self.extend_packet(p, pkt_size)
205 self.pkts.append(p)
206
207 def verify_cflow_data(self, decoder, capture, cflow):
208 octets = 0
209 packets = 0
210 for p in capture:
211 octets += p[IP].len
212 packets += 1
213 if cflow.haslayer(Data):
214 data = decoder.decode_data_set(cflow.getlayer(Set))
215 for record in data:
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800216 self.assertEqual(int(binascii.hexlify(record[1]), 16), octets)
217 self.assertEqual(int(binascii.hexlify(record[2]), 16), packets)
Ole Troan5c749732017-03-13 13:39:52 +0100218
Pavel Kotucek89111d02017-06-12 08:26:13 +0200219 def send_packets(self, src_if=None, dst_if=None):
220 if src_if is None:
221 src_if = self.pg1
222 if dst_if is None:
223 dst_if = self.pg2
224 self.pg_enable_capture([dst_if])
225 src_if.add_stream(self.pkts)
226 self.pg_start()
227 return dst_if.get_capture(len(self.pkts))
228
Ole Troan5c749732017-03-13 13:39:52 +0100229 def verify_cflow_data_detail(self, decoder, capture, cflow,
230 data_set={1: 'octets', 2: 'packets'},
231 ip_ver='v4'):
232 if self.debug_print:
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800233 print(capture[0].show())
Ole Troan5c749732017-03-13 13:39:52 +0100234 if cflow.haslayer(Data):
235 data = decoder.decode_data_set(cflow.getlayer(Set))
236 if self.debug_print:
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800237 print(data)
Ole Troan5c749732017-03-13 13:39:52 +0100238 if ip_ver == 'v4':
239 ip_layer = capture[0][IP]
240 else:
241 ip_layer = capture[0][IPv6]
242 if data_set is not None:
243 for record in data:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700244 # skip flow if ingress/egress interface is 0
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800245 if int(binascii.hexlify(record[10]), 16) == 0:
Ole Troan5c749732017-03-13 13:39:52 +0100246 continue
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800247 if int(binascii.hexlify(record[14]), 16) == 0:
Ole Troan5c749732017-03-13 13:39:52 +0100248 continue
249
250 for field in data_set:
251 if field not in record.keys():
252 continue
253 value = data_set[field]
254 if value == 'octets':
255 value = ip_layer.len
256 if ip_ver == 'v6':
257 value += 40 # ??? is this correct
258 elif value == 'packets':
259 value = 1
260 elif value == 'src_ip':
261 if ip_ver == 'v4':
262 ip = socket.inet_pton(socket.AF_INET,
263 ip_layer.src)
264 else:
265 ip = socket.inet_pton(socket.AF_INET6,
266 ip_layer.src)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800267 value = int(binascii.hexlify(ip), 16)
Ole Troan5c749732017-03-13 13:39:52 +0100268 elif value == 'dst_ip':
269 if ip_ver == 'v4':
270 ip = socket.inet_pton(socket.AF_INET,
271 ip_layer.dst)
272 else:
273 ip = socket.inet_pton(socket.AF_INET6,
274 ip_layer.dst)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800275 value = int(binascii.hexlify(ip), 16)
Ole Troan5c749732017-03-13 13:39:52 +0100276 elif value == 'sport':
277 value = int(capture[0][UDP].sport)
278 elif value == 'dport':
279 value = int(capture[0][UDP].dport)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800280 self.assertEqual(int(binascii.hexlify(
281 record[field]), 16),
Klement Sekerac4794572021-09-08 15:15:59 +0200282 value)
Ole Troan5c749732017-03-13 13:39:52 +0100283
284 def verify_cflow_data_notimer(self, decoder, capture, cflows):
285 idx = 0
286 for cflow in cflows:
287 if cflow.haslayer(Data):
288 data = decoder.decode_data_set(cflow.getlayer(Set))
289 else:
290 raise Exception("No CFLOW data")
291
292 for rec in data:
293 p = capture[idx]
294 idx += 1
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800295 self.assertEqual(p[IP].len, int(
296 binascii.hexlify(rec[1]), 16))
297 self.assertEqual(1, int(
298 binascii.hexlify(rec[2]), 16))
Ole Troan5c749732017-03-13 13:39:52 +0100299 self.assertEqual(len(capture), idx)
300
Klement Sekerac4794572021-09-08 15:15:59 +0200301 def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1):
Ole Troan5c749732017-03-13 13:39:52 +0100302 """ wait for CFLOW packet and verify its correctness
303
304 :param timeout: how long to wait
305
Ole Troan5c749732017-03-13 13:39:52 +0100306 """
307 self.logger.info("IPFIX: Waiting for CFLOW packet")
Ole Troan5c749732017-03-13 13:39:52 +0100308 # self.logger.debug(self.vapi.ppcli("show flow table"))
Klement Sekerac4794572021-09-08 15:15:59 +0200309 p = collector_intf.wait_for_packet(timeout=timeout)
310 self.assertEqual(p[Set].setID, set_id)
311 # self.logger.debug(self.vapi.ppcli("show flow table"))
312 self.logger.debug(ppp("IPFIX: Got packet:", p))
Ole Troan5c749732017-03-13 13:39:52 +0100313 return p
314
Ole Troan5c749732017-03-13 13:39:52 +0100315
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000316@tag_run_solo
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +0000317@tag_fixme_vpp_workers
Ole Troaned929252017-06-13 21:15:40 +0200318class Flowprobe(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100319 """Template verification, timer tests"""
320
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800321 @classmethod
322 def setUpClass(cls):
323 super(Flowprobe, cls).setUpClass()
324
325 @classmethod
326 def tearDownClass(cls):
327 super(Flowprobe, cls).tearDownClass()
328
Ole Troan5c749732017-03-13 13:39:52 +0100329 def test_0001(self):
Pavel Kotucek89111d02017-06-12 08:26:13 +0200330 """ timer less than template timeout"""
Ole Troaned929252017-06-13 21:15:40 +0200331 self.logger.info("FFP_TEST_START_0001")
Ole Troan5c749732017-03-13 13:39:52 +0100332 self.pg_enable_capture(self.pg_interfaces)
333 self.pkts = []
334
Pavel Kotucek89111d02017-06-12 08:26:13 +0200335 ipfix = VppCFLOW(test=self, active=2)
Ole Troan5c749732017-03-13 13:39:52 +0100336 ipfix.add_vpp_config()
337
338 ipfix_decoder = IPFIXDecoder()
339 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200340 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100341
Ole Troaned929252017-06-13 21:15:40 +0200342 self.create_stream(packets=1)
Pavel Kotucek89111d02017-06-12 08:26:13 +0200343 self.send_packets()
Ole Troaned929252017-06-13 21:15:40 +0200344 capture = self.pg2.get_capture(1)
Ole Troan5c749732017-03-13 13:39:52 +0100345
346 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200347 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
Ole Troan5c749732017-03-13 13:39:52 +0100348 self.verify_cflow_data(ipfix_decoder, capture, cflow)
349
350 ipfix.remove_vpp_config()
Ole Troaned929252017-06-13 21:15:40 +0200351 self.logger.info("FFP_TEST_FINISH_0001")
Ole Troan5c749732017-03-13 13:39:52 +0100352
Pavel Kotucek89111d02017-06-12 08:26:13 +0200353 def test_0002(self):
354 """ timer greater than template timeout"""
Ole Troaned929252017-06-13 21:15:40 +0200355 self.logger.info("FFP_TEST_START_0002")
Ole Troan5c749732017-03-13 13:39:52 +0100356 self.pg_enable_capture(self.pg_interfaces)
357 self.pkts = []
358
Pavel Kotucek89111d02017-06-12 08:26:13 +0200359 ipfix = VppCFLOW(test=self, timeout=3, active=4)
Ole Troan5c749732017-03-13 13:39:52 +0100360 ipfix.add_vpp_config()
361
362 ipfix_decoder = IPFIXDecoder()
363 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200364 ipfix.verify_templates()
Ole Troan5c749732017-03-13 13:39:52 +0100365
Pavel Kotucek89111d02017-06-12 08:26:13 +0200366 self.create_stream(packets=2)
367 self.send_packets()
368 capture = self.pg2.get_capture(2)
Ole Troan5c749732017-03-13 13:39:52 +0100369
370 # next set of template packet should arrive after 20 seconds
371 # template packet should arrive within 20 s
Pavel Kotucek89111d02017-06-12 08:26:13 +0200372 templates = ipfix.verify_templates(ipfix_decoder, timeout=5)
Ole Troan5c749732017-03-13 13:39:52 +0100373
374 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200375 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
Ole Troan5c749732017-03-13 13:39:52 +0100376 self.verify_cflow_data(ipfix_decoder, capture, cflow)
377
378 ipfix.remove_vpp_config()
Ole Troaned929252017-06-13 21:15:40 +0200379 self.logger.info("FFP_TEST_FINISH_0002")
380
381 def test_cflow_packet(self):
382 """verify cflow packet fields"""
383 self.logger.info("FFP_TEST_START_0000")
384 self.pg_enable_capture(self.pg_interfaces)
385 self.pkts = []
386
387 ipfix = VppCFLOW(test=self, intf='pg8', datapath="ip4",
388 layer='l2 l3 l4', active=2)
389 ipfix.add_vpp_config()
390
391 route_9001 = VppIpRoute(self, "9.0.0.0", 24,
392 [VppRoutePath(self.pg8._remote_hosts[0].ip4,
393 self.pg8.sw_if_index)])
394 route_9001.add_vpp_config()
395
396 ipfix_decoder = IPFIXDecoder()
397 templates = ipfix.verify_templates(ipfix_decoder, count=1)
398
399 self.pkts = [(Ether(dst=self.pg7.local_mac,
400 src=self.pg7.remote_mac) /
401 IP(src=self.pg7.remote_ip4, dst="9.0.0.100") /
402 TCP(sport=1234, dport=4321, flags=80) /
Ole Troan770a0de2019-11-07 13:52:21 +0100403 Raw(b'\xa5' * 100))]
Ole Troaned929252017-06-13 21:15:40 +0200404
405 nowUTC = int(time.time())
406 nowUNIX = nowUTC+2208988800
407 self.send_packets(src_if=self.pg7, dst_if=self.pg8)
408
409 cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10)
410 self.collector.get_capture(2)
411
412 if cflow[0].haslayer(IPFIX):
413 self.assertEqual(cflow[IPFIX].version, 10)
414 self.assertEqual(cflow[IPFIX].observationDomainID, 1)
415 self.assertEqual(cflow[IPFIX].sequenceNumber, 0)
416 self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5)
417 if cflow.haslayer(Data):
418 record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0]
419 # ingress interface
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800420 self.assertEqual(int(binascii.hexlify(record[10]), 16), 8)
Ole Troaned929252017-06-13 21:15:40 +0200421 # egress interface
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800422 self.assertEqual(int(binascii.hexlify(record[14]), 16), 9)
Ole Troaned929252017-06-13 21:15:40 +0200423 # packets
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800424 self.assertEqual(int(binascii.hexlify(record[2]), 16), 1)
Ole Troaned929252017-06-13 21:15:40 +0200425 # src mac
Ole Troanb0d83f12019-10-21 23:13:46 +0200426 self.assertEqual(mac_ntop(record[56]), self.pg8.local_mac)
Ole Troaned929252017-06-13 21:15:40 +0200427 # dst mac
Ole Troanb0d83f12019-10-21 23:13:46 +0200428 self.assertEqual(mac_ntop(record[80]), self.pg8.remote_mac)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800429 flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32
Ole Troaned929252017-06-13 21:15:40 +0200430 # flow start timestamp
431 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800432 flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32
Ole Troaned929252017-06-13 21:15:40 +0200433 # flow end timestamp
434 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
435 # ethernet type
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800436 self.assertEqual(int(binascii.hexlify(record[256]), 16), 8)
Ole Troaned929252017-06-13 21:15:40 +0200437 # src ip
Ole Troanb0d83f12019-10-21 23:13:46 +0200438 self.assertEqual(inet_ntop(socket.AF_INET, record[8]),
439 self.pg7.remote_ip4)
Ole Troaned929252017-06-13 21:15:40 +0200440 # dst ip
Ole Troanb0d83f12019-10-21 23:13:46 +0200441 self.assertEqual(inet_ntop(socket.AF_INET, record[12]),
442 "9.0.0.100")
Ole Troaned929252017-06-13 21:15:40 +0200443 # protocol (TCP)
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800444 self.assertEqual(int(binascii.hexlify(record[4]), 16), 6)
Ole Troaned929252017-06-13 21:15:40 +0200445 # src port
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800446 self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234)
Ole Troaned929252017-06-13 21:15:40 +0200447 # dst port
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800448 self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321)
Ole Troaned929252017-06-13 21:15:40 +0200449 # tcp flags
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800450 self.assertEqual(int(binascii.hexlify(record[6]), 16), 80)
Ole Troaned929252017-06-13 21:15:40 +0200451
452 ipfix.remove_vpp_config()
453 self.logger.info("FFP_TEST_FINISH_0000")
Ole Troan5c749732017-03-13 13:39:52 +0100454
Ole Troan5c749732017-03-13 13:39:52 +0100455
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +0000456@tag_fixme_vpp_workers
Pavel Kotucek89111d02017-06-12 08:26:13 +0200457class Datapath(MethodHolder):
458 """collect information on Ethernet, IP4 and IP6 datapath (no timers)"""
Ole Troan5c749732017-03-13 13:39:52 +0100459
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800460 @classmethod
461 def setUpClass(cls):
462 super(Datapath, cls).setUpClass()
463
464 @classmethod
465 def tearDownClass(cls):
466 super(Datapath, cls).tearDownClass()
467
Pavel Kotucek89111d02017-06-12 08:26:13 +0200468 def test_templatesL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100469 """ verify template on L2 datapath"""
470 self.logger.info("FFP_TEST_START_0000")
471 self.pg_enable_capture(self.pg_interfaces)
472
Pavel Kotucek89111d02017-06-12 08:26:13 +0200473 ipfix = VppCFLOW(test=self, layer='l2')
Ole Troan5c749732017-03-13 13:39:52 +0100474 ipfix.add_vpp_config()
475
476 # template packet should arrive immediately
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400477 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200478 ipfix.verify_templates(timeout=3, count=1)
479 self.collector.get_capture(1)
Ole Troan5c749732017-03-13 13:39:52 +0100480
481 ipfix.remove_vpp_config()
482 self.logger.info("FFP_TEST_FINISH_0000")
483
Pavel Kotucek89111d02017-06-12 08:26:13 +0200484 def test_L2onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100485 """ L2 data on L2 datapath"""
486 self.logger.info("FFP_TEST_START_0001")
487 self.pg_enable_capture(self.pg_interfaces)
488 self.pkts = []
489
Pavel Kotucek89111d02017-06-12 08:26:13 +0200490 ipfix = VppCFLOW(test=self, layer='l2')
Ole Troan5c749732017-03-13 13:39:52 +0100491 ipfix.add_vpp_config()
492
493 ipfix_decoder = IPFIXDecoder()
494 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200495 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100496
497 self.create_stream(packets=1)
498 capture = self.send_packets()
499
500 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400501 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200502 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100503 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
504 {2: 'packets', 256: 8})
Ole Troan5c749732017-03-13 13:39:52 +0100505 self.collector.get_capture(2)
506
507 ipfix.remove_vpp_config()
508 self.logger.info("FFP_TEST_FINISH_0001")
509
Pavel Kotucek89111d02017-06-12 08:26:13 +0200510 def test_L3onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100511 """ L3 data on L2 datapath"""
512 self.logger.info("FFP_TEST_START_0002")
513 self.pg_enable_capture(self.pg_interfaces)
514 self.pkts = []
515
Pavel Kotucek89111d02017-06-12 08:26:13 +0200516 ipfix = VppCFLOW(test=self, layer='l3')
Ole Troan5c749732017-03-13 13:39:52 +0100517 ipfix.add_vpp_config()
518
519 ipfix_decoder = IPFIXDecoder()
520 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200521 templates = ipfix.verify_templates(ipfix_decoder, count=2)
Ole Troan5c749732017-03-13 13:39:52 +0100522
523 self.create_stream(packets=1)
524 capture = self.send_packets()
525
526 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400527 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200528 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100529 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
530 {2: 'packets', 4: 17,
531 8: 'src_ip', 12: 'dst_ip'})
532
Ole Troan5c749732017-03-13 13:39:52 +0100533 self.collector.get_capture(3)
534
535 ipfix.remove_vpp_config()
536 self.logger.info("FFP_TEST_FINISH_0002")
537
Pavel Kotucek89111d02017-06-12 08:26:13 +0200538 def test_L4onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100539 """ L4 data on L2 datapath"""
540 self.logger.info("FFP_TEST_START_0003")
541 self.pg_enable_capture(self.pg_interfaces)
542 self.pkts = []
543
Pavel Kotucek89111d02017-06-12 08:26:13 +0200544 ipfix = VppCFLOW(test=self, layer='l4')
Ole Troan5c749732017-03-13 13:39:52 +0100545 ipfix.add_vpp_config()
546
547 ipfix_decoder = IPFIXDecoder()
548 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200549 templates = ipfix.verify_templates(ipfix_decoder, count=2)
Ole Troan5c749732017-03-13 13:39:52 +0100550
551 self.create_stream(packets=1)
552 capture = self.send_packets()
553
554 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400555 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200556 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100557 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
558 {2: 'packets', 7: 'sport', 11: 'dport'})
559
Ole Troan5c749732017-03-13 13:39:52 +0100560 self.collector.get_capture(3)
561
562 ipfix.remove_vpp_config()
563 self.logger.info("FFP_TEST_FINISH_0003")
564
Pavel Kotucek89111d02017-06-12 08:26:13 +0200565 def test_templatesIp4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100566 """ verify templates on IP4 datapath"""
567 self.logger.info("FFP_TEST_START_0000")
568
569 self.pg_enable_capture(self.pg_interfaces)
570
Pavel Kotucek89111d02017-06-12 08:26:13 +0200571 ipfix = VppCFLOW(test=self, datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100572 ipfix.add_vpp_config()
573
574 # template packet should arrive immediately
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400575 self.vapi.ipfix_flush()
Ole Troan5c749732017-03-13 13:39:52 +0100576 ipfix.verify_templates(timeout=3, count=1)
577 self.collector.get_capture(1)
578
579 ipfix.remove_vpp_config()
580
581 self.logger.info("FFP_TEST_FINISH_0000")
582
Pavel Kotucek89111d02017-06-12 08:26:13 +0200583 def test_L2onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100584 """ L2 data on IP4 datapath"""
585 self.logger.info("FFP_TEST_START_0001")
586 self.pg_enable_capture(self.pg_interfaces)
587 self.pkts = []
588
Pavel Kotucek89111d02017-06-12 08:26:13 +0200589 ipfix = VppCFLOW(test=self, intf='pg4', layer='l2', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100590 ipfix.add_vpp_config()
591
592 ipfix_decoder = IPFIXDecoder()
593 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200594 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100595
596 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
597 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
598
599 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400600 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200601 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100602 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
603 {2: 'packets', 256: 8})
604
605 # expected two templates and one cflow packet
606 self.collector.get_capture(2)
607
608 ipfix.remove_vpp_config()
609 self.logger.info("FFP_TEST_FINISH_0001")
610
Pavel Kotucek89111d02017-06-12 08:26:13 +0200611 def test_L3onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100612 """ L3 data on IP4 datapath"""
613 self.logger.info("FFP_TEST_START_0002")
614 self.pg_enable_capture(self.pg_interfaces)
615 self.pkts = []
616
Pavel Kotucek89111d02017-06-12 08:26:13 +0200617 ipfix = VppCFLOW(test=self, intf='pg4', layer='l3', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100618 ipfix.add_vpp_config()
619
620 ipfix_decoder = IPFIXDecoder()
621 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200622 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100623
624 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
625 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
626
627 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400628 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200629 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100630 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
631 {1: 'octets', 2: 'packets',
632 8: 'src_ip', 12: 'dst_ip'})
633
634 # expected two templates and one cflow packet
635 self.collector.get_capture(2)
636
637 ipfix.remove_vpp_config()
638 self.logger.info("FFP_TEST_FINISH_0002")
639
Pavel Kotucek89111d02017-06-12 08:26:13 +0200640 def test_L4onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100641 """ L4 data on IP4 datapath"""
642 self.logger.info("FFP_TEST_START_0003")
643 self.pg_enable_capture(self.pg_interfaces)
644 self.pkts = []
645
Pavel Kotucek89111d02017-06-12 08:26:13 +0200646 ipfix = VppCFLOW(test=self, intf='pg4', layer='l4', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100647 ipfix.add_vpp_config()
648
649 ipfix_decoder = IPFIXDecoder()
650 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200651 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100652
653 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
654 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
655
656 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400657 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200658 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100659 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
660 {2: 'packets', 7: 'sport', 11: 'dport'})
661
662 # expected two templates and one cflow packet
663 self.collector.get_capture(2)
664
665 ipfix.remove_vpp_config()
666 self.logger.info("FFP_TEST_FINISH_0003")
667
Pavel Kotucek89111d02017-06-12 08:26:13 +0200668 def test_templatesIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100669 """ verify templates on IP6 datapath"""
670 self.logger.info("FFP_TEST_START_0000")
671 self.pg_enable_capture(self.pg_interfaces)
672
Pavel Kotucek89111d02017-06-12 08:26:13 +0200673 ipfix = VppCFLOW(test=self, datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100674 ipfix.add_vpp_config()
675
676 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200677 ipfix.verify_templates(count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100678 self.collector.get_capture(1)
679
680 ipfix.remove_vpp_config()
681
682 self.logger.info("FFP_TEST_FINISH_0000")
683
Pavel Kotucek89111d02017-06-12 08:26:13 +0200684 def test_L2onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100685 """ L2 data on IP6 datapath"""
686 self.logger.info("FFP_TEST_START_0001")
687 self.pg_enable_capture(self.pg_interfaces)
688 self.pkts = []
689
Pavel Kotucek89111d02017-06-12 08:26:13 +0200690 ipfix = VppCFLOW(test=self, intf='pg6', layer='l2', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100691 ipfix.add_vpp_config()
692
693 ipfix_decoder = IPFIXDecoder()
694 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200695 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100696
697 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
698 ip_ver='IPv6')
699 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
700
701 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400702 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200703 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100704 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
705 {2: 'packets', 256: 56710},
706 ip_ver='v6')
707
708 # expected two templates and one cflow packet
709 self.collector.get_capture(2)
710
711 ipfix.remove_vpp_config()
712 self.logger.info("FFP_TEST_FINISH_0001")
713
Pavel Kotucek89111d02017-06-12 08:26:13 +0200714 def test_L3onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100715 """ L3 data on IP6 datapath"""
716 self.logger.info("FFP_TEST_START_0002")
717 self.pg_enable_capture(self.pg_interfaces)
718 self.pkts = []
719
Pavel Kotucek89111d02017-06-12 08:26:13 +0200720 ipfix = VppCFLOW(test=self, intf='pg6', layer='l3', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100721 ipfix.add_vpp_config()
722
723 ipfix_decoder = IPFIXDecoder()
724 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200725 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100726
727 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
728 ip_ver='IPv6')
729 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
730
731 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400732 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200733 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100734 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
735 {2: 'packets',
736 27: 'src_ip', 28: 'dst_ip'},
737 ip_ver='v6')
738
739 # expected two templates and one cflow packet
740 self.collector.get_capture(2)
741
742 ipfix.remove_vpp_config()
743 self.logger.info("FFP_TEST_FINISH_0002")
744
Pavel Kotucek89111d02017-06-12 08:26:13 +0200745 def test_L4onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100746 """ L4 data on IP6 datapath"""
747 self.logger.info("FFP_TEST_START_0003")
748 self.pg_enable_capture(self.pg_interfaces)
749 self.pkts = []
750
Pavel Kotucek89111d02017-06-12 08:26:13 +0200751 ipfix = VppCFLOW(test=self, intf='pg6', layer='l4', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100752 ipfix.add_vpp_config()
753
754 ipfix_decoder = IPFIXDecoder()
755 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200756 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100757
758 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
759 ip_ver='IPv6')
760 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
761
762 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400763 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200764 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100765 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
766 {2: 'packets', 7: 'sport', 11: 'dport'},
767 ip_ver='v6')
768
769 # expected two templates and one cflow packet
770 self.collector.get_capture(2)
771
772 ipfix.remove_vpp_config()
773 self.logger.info("FFP_TEST_FINISH_0003")
774
Ole Troan5c749732017-03-13 13:39:52 +0100775 def test_0001(self):
776 """ no timers, one CFLOW packet, 9 Flows inside"""
777 self.logger.info("FFP_TEST_START_0001")
778 self.pg_enable_capture(self.pg_interfaces)
779 self.pkts = []
780
Pavel Kotucek89111d02017-06-12 08:26:13 +0200781 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100782 ipfix.add_vpp_config()
783
784 ipfix_decoder = IPFIXDecoder()
785 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200786 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100787
788 self.create_stream(packets=9)
789 capture = self.send_packets()
790
791 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400792 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200793 cflow = self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100794 self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow])
Ole Troan5c749732017-03-13 13:39:52 +0100795 self.collector.get_capture(4)
796
797 ipfix.remove_vpp_config()
798 self.logger.info("FFP_TEST_FINISH_0001")
799
800 def test_0002(self):
801 """ no timers, two CFLOW packets (mtu=256), 3 Flows in each"""
802 self.logger.info("FFP_TEST_START_0002")
803 self.pg_enable_capture(self.pg_interfaces)
804 self.pkts = []
805
Pavel Kotucek89111d02017-06-12 08:26:13 +0200806 ipfix = VppCFLOW(test=self, mtu=256)
Ole Troan5c749732017-03-13 13:39:52 +0100807 ipfix.add_vpp_config()
808
809 ipfix_decoder = IPFIXDecoder()
810 # template packet should arrive immediately
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400811 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200812 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100813
814 self.create_stream(packets=6)
815 capture = self.send_packets()
816
817 # make sure the one packet we expect actually showed up
818 cflows = []
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400819 self.vapi.ipfix_flush()
Ole Troan5c749732017-03-13 13:39:52 +0100820 cflows.append(self.wait_for_cflow_packet(self.collector,
Pavel Kotucek89111d02017-06-12 08:26:13 +0200821 templates[1]))
Ole Troan5c749732017-03-13 13:39:52 +0100822 cflows.append(self.wait_for_cflow_packet(self.collector,
Pavel Kotucek89111d02017-06-12 08:26:13 +0200823 templates[1]))
Ole Troan5c749732017-03-13 13:39:52 +0100824 self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows)
825 self.collector.get_capture(5)
826
827 ipfix.remove_vpp_config()
828 self.logger.info("FFP_TEST_FINISH_0002")
829
830
Klement Sekerab23ffd72021-05-31 16:08:53 +0200831@unittest.skipUnless(config.extended, "part of extended tests")
Pavel Kotucek89111d02017-06-12 08:26:13 +0200832class DisableIPFIX(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100833 """Disable IPFIX"""
834
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800835 @classmethod
836 def setUpClass(cls):
837 super(DisableIPFIX, cls).setUpClass()
838
839 @classmethod
840 def tearDownClass(cls):
841 super(DisableIPFIX, cls).tearDownClass()
842
Ole Troan5c749732017-03-13 13:39:52 +0100843 def test_0001(self):
844 """ disable IPFIX after first packets"""
845 self.logger.info("FFP_TEST_START_0001")
846 self.pg_enable_capture(self.pg_interfaces)
847 self.pkts = []
848
Pavel Kotucek89111d02017-06-12 08:26:13 +0200849 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100850 ipfix.add_vpp_config()
851
852 ipfix_decoder = IPFIXDecoder()
853 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200854 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100855
856 self.create_stream()
857 self.send_packets()
858
859 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400860 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200861 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100862 self.collector.get_capture(4)
863
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700864 # disable IPFIX
Ole Troan5c749732017-03-13 13:39:52 +0100865 ipfix.disable_exporter()
866 self.pg_enable_capture([self.collector])
867
868 self.send_packets()
869
870 # make sure no one packet arrived in 1 minute
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400871 self.vapi.ipfix_flush()
Klement Sekerac4794572021-09-08 15:15:59 +0200872 self.sleep(1, "wait before verifying no packets sent")
873 self.collector.assert_nothing_captured()
Ole Troan5c749732017-03-13 13:39:52 +0100874
875 ipfix.remove_vpp_config()
876 self.logger.info("FFP_TEST_FINISH_0001")
877
878
Klement Sekerab23ffd72021-05-31 16:08:53 +0200879@unittest.skipUnless(config.extended, "part of extended tests")
Pavel Kotucek89111d02017-06-12 08:26:13 +0200880class ReenableIPFIX(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100881 """Re-enable IPFIX"""
882
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800883 @classmethod
884 def setUpClass(cls):
885 super(ReenableIPFIX, cls).setUpClass()
886
887 @classmethod
888 def tearDownClass(cls):
889 super(ReenableIPFIX, cls).tearDownClass()
890
Pavel Kotucek89111d02017-06-12 08:26:13 +0200891 def test_0011(self):
Ole Troan5c749732017-03-13 13:39:52 +0100892 """ disable IPFIX after first packets and re-enable after few packets
893 """
894 self.logger.info("FFP_TEST_START_0001")
895 self.pg_enable_capture(self.pg_interfaces)
896 self.pkts = []
897
Pavel Kotucek89111d02017-06-12 08:26:13 +0200898 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100899 ipfix.add_vpp_config()
900
901 ipfix_decoder = IPFIXDecoder()
902 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200903 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100904
Pavel Kotucek89111d02017-06-12 08:26:13 +0200905 self.create_stream(packets=5)
Ole Troan5c749732017-03-13 13:39:52 +0100906 self.send_packets()
907
908 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400909 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200910 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100911 self.collector.get_capture(4)
912
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800913 # disable IPFIX
Ole Troan5c749732017-03-13 13:39:52 +0100914 ipfix.disable_exporter()
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400915 self.vapi.ipfix_flush()
Ole Troan5c749732017-03-13 13:39:52 +0100916 self.pg_enable_capture([self.collector])
917
918 self.send_packets()
919
920 # make sure no one packet arrived in active timer span
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400921 self.vapi.ipfix_flush()
Klement Sekerac4794572021-09-08 15:15:59 +0200922 self.sleep(1, "wait before verifying no packets sent")
923 self.collector.assert_nothing_captured()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200924 self.pg2.get_capture(5)
Ole Troan5c749732017-03-13 13:39:52 +0100925
926 # enable IPFIX
927 ipfix.enable_exporter()
Ole Troan5c749732017-03-13 13:39:52 +0100928
Pavel Kotucek89111d02017-06-12 08:26:13 +0200929 capture = self.collector.get_capture(4)
930 nr_templates = 0
931 nr_data = 0
932 for p in capture:
933 self.assertTrue(p.haslayer(IPFIX))
934 if p.haslayer(Template):
935 nr_templates += 1
936 self.assertTrue(nr_templates, 3)
937 for p in capture:
938 self.assertTrue(p.haslayer(IPFIX))
939 if p.haslayer(Data):
940 nr_data += 1
941 self.assertTrue(nr_templates, 1)
Ole Troan5c749732017-03-13 13:39:52 +0100942
943 ipfix.remove_vpp_config()
944 self.logger.info("FFP_TEST_FINISH_0001")
945
946
Klement Sekerab23ffd72021-05-31 16:08:53 +0200947@unittest.skipUnless(config.extended, "part of extended tests")
Pavel Kotucek89111d02017-06-12 08:26:13 +0200948class DisableFP(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100949 """Disable Flowprobe feature"""
950
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800951 @classmethod
952 def setUpClass(cls):
953 super(DisableFP, cls).setUpClass()
954
955 @classmethod
956 def tearDownClass(cls):
957 super(DisableFP, cls).tearDownClass()
958
Ole Troan5c749732017-03-13 13:39:52 +0100959 def test_0001(self):
960 """ disable flowprobe feature after first packets"""
961 self.logger.info("FFP_TEST_START_0001")
962 self.pg_enable_capture(self.pg_interfaces)
963 self.pkts = []
Pavel Kotucek89111d02017-06-12 08:26:13 +0200964 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100965 ipfix.add_vpp_config()
966
967 ipfix_decoder = IPFIXDecoder()
968 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200969 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100970
971 self.create_stream()
972 self.send_packets()
973
974 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400975 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200976 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100977 self.collector.get_capture(4)
978
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700979 # disable IPFIX
Ole Troan5c749732017-03-13 13:39:52 +0100980 ipfix.disable_flowprobe_feature()
981 self.pg_enable_capture([self.collector])
982
983 self.send_packets()
984
985 # make sure no one packet arrived in active timer span
Paul Vinciguerra21b83e92019-06-24 09:55:46 -0400986 self.vapi.ipfix_flush()
Klement Sekerac4794572021-09-08 15:15:59 +0200987 self.sleep(1, "wait before verifying no packets sent")
988 self.collector.assert_nothing_captured()
Ole Troan5c749732017-03-13 13:39:52 +0100989
990 ipfix.remove_vpp_config()
991 self.logger.info("FFP_TEST_FINISH_0001")
992
993
Klement Sekerab23ffd72021-05-31 16:08:53 +0200994@unittest.skipUnless(config.extended, "part of extended tests")
Pavel Kotucek89111d02017-06-12 08:26:13 +0200995class ReenableFP(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100996 """Re-enable Flowprobe feature"""
997
Paul Vinciguerra8d991d92019-01-25 14:05:48 -0800998 @classmethod
999 def setUpClass(cls):
1000 super(ReenableFP, cls).setUpClass()
1001
1002 @classmethod
1003 def tearDownClass(cls):
1004 super(ReenableFP, cls).tearDownClass()
1005
Ole Troan5c749732017-03-13 13:39:52 +01001006 def test_0001(self):
1007 """ disable flowprobe feature after first packets and re-enable
1008 after few packets """
1009 self.logger.info("FFP_TEST_START_0001")
1010 self.pg_enable_capture(self.pg_interfaces)
1011 self.pkts = []
1012
Pavel Kotucek89111d02017-06-12 08:26:13 +02001013 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +01001014 ipfix.add_vpp_config()
1015
1016 ipfix_decoder = IPFIXDecoder()
1017 # template packet should arrive immediately
Paul Vinciguerra21b83e92019-06-24 09:55:46 -04001018 self.vapi.ipfix_flush()
Ole Troan5c749732017-03-13 13:39:52 +01001019 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1020
1021 self.create_stream()
1022 self.send_packets()
1023
1024 # make sure the one packet we expect actually showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -04001025 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +02001026 self.wait_for_cflow_packet(self.collector, templates[1], 5)
Ole Troan5c749732017-03-13 13:39:52 +01001027 self.collector.get_capture(4)
1028
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001029 # disable FPP feature
Ole Troan5c749732017-03-13 13:39:52 +01001030 ipfix.disable_flowprobe_feature()
1031 self.pg_enable_capture([self.collector])
1032
1033 self.send_packets()
1034
1035 # make sure no one packet arrived in active timer span
Paul Vinciguerra21b83e92019-06-24 09:55:46 -04001036 self.vapi.ipfix_flush()
Klement Sekerac4794572021-09-08 15:15:59 +02001037 self.sleep(5, "wait before verifying no packets sent")
1038 self.collector.assert_nothing_captured()
Ole Troan5c749732017-03-13 13:39:52 +01001039
1040 # enable FPP feature
1041 ipfix.enable_flowprobe_feature()
Paul Vinciguerra21b83e92019-06-24 09:55:46 -04001042 self.vapi.ipfix_flush()
Ole Troan5c749732017-03-13 13:39:52 +01001043 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1044
1045 self.send_packets()
1046
1047 # make sure the next packets (templates and data) we expect actually
1048 # showed up
Paul Vinciguerra21b83e92019-06-24 09:55:46 -04001049 self.vapi.ipfix_flush()
Pavel Kotucek89111d02017-06-12 08:26:13 +02001050 self.wait_for_cflow_packet(self.collector, templates[1], 5)
Ole Troan5c749732017-03-13 13:39:52 +01001051 self.collector.get_capture(4)
1052
1053 ipfix.remove_vpp_config()
1054 self.logger.info("FFP_TEST_FINISH_0001")
1055
1056
1057if __name__ == '__main__':
1058 unittest.main(testRunner=VppTestRunner)