blob: df6b423069975b78873854c589684d9c0666e1a7 [file] [log] [blame]
Ole Troan5c749732017-03-13 13:39:52 +01001#!/usr/bin/env python
2import random
3import socket
4import unittest
5import time
Ole Troaned929252017-06-13 21:15:40 +02006import re
Ole Troan5c749732017-03-13 13:39:52 +01007
8from scapy.packet import Raw
9from scapy.layers.l2 import Ether
Ole Troaned929252017-06-13 21:15:40 +020010from scapy.layers.inet import IP, TCP, UDP
Ole Troan5c749732017-03-13 13:39:52 +010011from scapy.layers.inet6 import IPv6
12
Pavel Kotucek89111d02017-06-12 08:26:13 +020013from framework import VppTestCase, VppTestRunner, running_extended_tests
Ole Troan5c749732017-03-13 13:39:52 +010014from vpp_object import VppObject
15from vpp_pg_interface import CaptureTimeoutError
16from util import ppp
17from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
Ole Troaned929252017-06-13 21:15:40 +020018from vpp_ip_route import VppIpRoute, VppRoutePath
Ole Troan5c749732017-03-13 13:39:52 +010019
20
21class VppCFLOW(VppObject):
22 """CFLOW object for IPFIX exporter and Flowprobe feature"""
23
Pavel Kotucek89111d02017-06-12 08:26:13 +020024 def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100,
25 mtu=1024, datapath='l2', layer='l2 l3 l4'):
Ole Troan5c749732017-03-13 13:39:52 +010026 self._test = test
27 self._intf = intf
28 self._active = active
29 if passive == 0 or passive < active:
Pavel Kotucek89111d02017-06-12 08:26:13 +020030 self._passive = active+1
Ole Troan5c749732017-03-13 13:39:52 +010031 else:
32 self._passive = passive
33 self._datapath = datapath # l2 ip4 ip6
34 self._collect = layer # l2 l3 l4
35 self._timeout = timeout
36 self._mtu = mtu
37 self._configured = False
38
39 def add_vpp_config(self):
40 self.enable_exporter()
41 self._test.vapi.ppcli("flowprobe params record %s active %s "
42 "passive %s" % (self._collect, self._active,
43 self._passive))
44 self.enable_flowprobe_feature()
45 self._test.vapi.cli("ipfix flush")
46 self._configured = True
47
48 def remove_vpp_config(self):
49 self.disable_exporter()
50 self.disable_flowprobe_feature()
51 self._test.vapi.cli("ipfix flush")
52 self._configured = False
53
54 def enable_exporter(self):
55 self._test.vapi.set_ipfix_exporter(
56 collector_address=self._test.pg0.remote_ip4n,
57 src_address=self._test.pg0.local_ip4n,
58 path_mtu=self._mtu,
59 template_interval=self._timeout)
60
61 def enable_flowprobe_feature(self):
62 self._test.vapi.ppcli("flowprobe feature add-del %s %s" %
63 (self._intf, self._datapath))
64
65 def disable_exporter(self):
66 self._test.vapi.cli("set ipfix exporter collector 0.0.0.0")
67
68 def disable_flowprobe_feature(self):
69 self._test.vapi.cli("flowprobe feature add-del %s %s disable" %
70 (self._intf, self._datapath))
71
72 def object_id(self):
73 return "ipfix-collector-%s" % (self._src, self.dst)
74
75 def query_vpp_config(self):
76 return self._configured
77
78 def verify_templates(self, decoder=None, timeout=1, count=3):
79 templates = []
80 p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout)
81 self._test.assertTrue(p.haslayer(IPFIX))
82 if decoder is not None and p.haslayer(Template):
83 templates.append(p[Template].templateID)
84 decoder.add_template(p.getlayer(Template))
85 if count > 1:
86 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
87 self._test.assertTrue(p.haslayer(IPFIX))
88 if decoder is not None and p.haslayer(Template):
89 templates.append(p[Template].templateID)
90 decoder.add_template(p.getlayer(Template))
91 if count > 2:
92 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
93 self._test.assertTrue(p.haslayer(IPFIX))
94 if decoder is not None and p.haslayer(Template):
95 templates.append(p[Template].templateID)
96 decoder.add_template(p.getlayer(Template))
97 return templates
98
99
100class MethodHolder(VppTestCase):
101 """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """
102
103 # Test variables
104 debug_print = False
Pavel Kotucek89111d02017-06-12 08:26:13 +0200105 max_number_of_packets = 10
Ole Troan5c749732017-03-13 13:39:52 +0100106 pkts = []
107
108 @classmethod
109 def setUpClass(cls):
110 """
111 Perform standard class setup (defined by class method setUpClass in
112 class VppTestCase) before running the test case, set test case related
113 variables and configure VPP.
114 """
115 super(MethodHolder, cls).setUpClass()
116 try:
117 # Create pg interfaces
Ole Troaned929252017-06-13 21:15:40 +0200118 cls.create_pg_interfaces(range(9))
Ole Troan5c749732017-03-13 13:39:52 +0100119
120 # Packet sizes
121 cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
122
123 # Create BD with MAC learning and unknown unicast flooding disabled
124 # and put interfaces to this BD
125 cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1)
126 cls.vapi.sw_interface_set_l2_bridge(cls.pg1._sw_if_index, bd_id=1)
127 cls.vapi.sw_interface_set_l2_bridge(cls.pg2._sw_if_index, bd_id=1)
128
129 # Set up all interfaces
130 for i in cls.pg_interfaces:
131 i.admin_up()
132
133 cls.pg0.config_ip4()
134 cls.pg0.configure_ipv4_neighbors()
135 cls.collector = cls.pg0
136
137 cls.pg1.config_ip4()
138 cls.pg1.resolve_arp()
139 cls.pg2.config_ip4()
140 cls.pg2.resolve_arp()
141 cls.pg3.config_ip4()
142 cls.pg3.resolve_arp()
143 cls.pg4.config_ip4()
144 cls.pg4.resolve_arp()
Ole Troaned929252017-06-13 21:15:40 +0200145 cls.pg7.config_ip4()
146 cls.pg8.config_ip4()
147 cls.pg8.configure_ipv4_neighbors()
Ole Troan5c749732017-03-13 13:39:52 +0100148
149 cls.pg5.config_ip6()
150 cls.pg5.resolve_ndp()
151 cls.pg5.disable_ipv6_ra()
152 cls.pg6.config_ip6()
153 cls.pg6.resolve_ndp()
154 cls.pg6.disable_ipv6_ra()
155 except Exception:
156 super(MethodHolder, cls).tearDownClass()
157 raise
158
159 def create_stream(self, src_if=None, dst_if=None, packets=None,
160 size=None, ip_ver='v4'):
161 """Create a packet stream to tickle the plugin
162
163 :param VppInterface src_if: Source interface for packet stream
164 :param VppInterface src_if: Dst interface for packet stream
165 """
166 if src_if is None:
167 src_if = self.pg1
168 if dst_if is None:
169 dst_if = self.pg2
170 self.pkts = []
171 if packets is None:
172 packets = random.randint(1, self.max_number_of_packets)
173 pkt_size = size
174 for p in range(0, packets):
175 if size is None:
176 pkt_size = random.choice(self.pg_if_packet_sizes)
177 info = self.create_packet_info(src_if, dst_if)
178 payload = self.info_to_payload(info)
179 p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
180 if ip_ver == 'v4':
181 p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
182 else:
183 p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
Ole Troaned929252017-06-13 21:15:40 +0200184 p /= UDP(sport=1234, dport=4321)
185 p /= Raw(payload)
Ole Troan5c749732017-03-13 13:39:52 +0100186 info.data = p.copy()
187 self.extend_packet(p, pkt_size)
188 self.pkts.append(p)
189
190 def verify_cflow_data(self, decoder, capture, cflow):
191 octets = 0
192 packets = 0
193 for p in capture:
194 octets += p[IP].len
195 packets += 1
196 if cflow.haslayer(Data):
197 data = decoder.decode_data_set(cflow.getlayer(Set))
198 for record in data:
199 self.assertEqual(int(record[1].encode('hex'), 16), octets)
200 self.assertEqual(int(record[2].encode('hex'), 16), packets)
201
Pavel Kotucek89111d02017-06-12 08:26:13 +0200202 def send_packets(self, src_if=None, dst_if=None):
203 if src_if is None:
204 src_if = self.pg1
205 if dst_if is None:
206 dst_if = self.pg2
207 self.pg_enable_capture([dst_if])
208 src_if.add_stream(self.pkts)
209 self.pg_start()
210 return dst_if.get_capture(len(self.pkts))
211
Ole Troan5c749732017-03-13 13:39:52 +0100212 def verify_cflow_data_detail(self, decoder, capture, cflow,
213 data_set={1: 'octets', 2: 'packets'},
214 ip_ver='v4'):
215 if self.debug_print:
216 print capture[0].show()
217 if cflow.haslayer(Data):
218 data = decoder.decode_data_set(cflow.getlayer(Set))
219 if self.debug_print:
220 print data
221 if ip_ver == 'v4':
222 ip_layer = capture[0][IP]
223 else:
224 ip_layer = capture[0][IPv6]
225 if data_set is not None:
226 for record in data:
227 # skip flow if in/out gress interface is 0
228 if int(record[10].encode('hex'), 16) == 0:
229 continue
230 if int(record[14].encode('hex'), 16) == 0:
231 continue
232
233 for field in data_set:
234 if field not in record.keys():
235 continue
236 value = data_set[field]
237 if value == 'octets':
238 value = ip_layer.len
239 if ip_ver == 'v6':
240 value += 40 # ??? is this correct
241 elif value == 'packets':
242 value = 1
243 elif value == 'src_ip':
244 if ip_ver == 'v4':
245 ip = socket.inet_pton(socket.AF_INET,
246 ip_layer.src)
247 else:
248 ip = socket.inet_pton(socket.AF_INET6,
249 ip_layer.src)
250 value = int(ip.encode('hex'), 16)
251 elif value == 'dst_ip':
252 if ip_ver == 'v4':
253 ip = socket.inet_pton(socket.AF_INET,
254 ip_layer.dst)
255 else:
256 ip = socket.inet_pton(socket.AF_INET6,
257 ip_layer.dst)
258 value = int(ip.encode('hex'), 16)
259 elif value == 'sport':
260 value = int(capture[0][UDP].sport)
261 elif value == 'dport':
262 value = int(capture[0][UDP].dport)
263 self.assertEqual(int(record[field].encode('hex'), 16),
264 value)
265
266 def verify_cflow_data_notimer(self, decoder, capture, cflows):
267 idx = 0
268 for cflow in cflows:
269 if cflow.haslayer(Data):
270 data = decoder.decode_data_set(cflow.getlayer(Set))
271 else:
272 raise Exception("No CFLOW data")
273
274 for rec in data:
275 p = capture[idx]
276 idx += 1
277 self.assertEqual(p[IP].len, int(rec[1].encode('hex'), 16))
278 self.assertEqual(1, int(rec[2].encode('hex'), 16))
279 self.assertEqual(len(capture), idx)
280
281 def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1,
282 expected=True):
283 """ wait for CFLOW packet and verify its correctness
284
285 :param timeout: how long to wait
286
287 :returns: tuple (packet, time spent waiting for packet)
288 """
289 self.logger.info("IPFIX: Waiting for CFLOW packet")
290 deadline = time.time() + timeout
291 counter = 0
292 # self.logger.debug(self.vapi.ppcli("show flow table"))
293 while True:
294 counter += 1
295 # sanity check
296 self.assert_in_range(counter, 0, 100, "number of packets ignored")
297 time_left = deadline - time.time()
298 try:
299 if time_left < 0 and expected:
300 # self.logger.debug(self.vapi.ppcli("show flow table"))
301 raise CaptureTimeoutError(
302 "Packet did not arrive within timeout")
303 p = collector_intf.wait_for_packet(timeout=time_left)
304 except CaptureTimeoutError:
305 if expected:
306 # self.logger.debug(self.vapi.ppcli("show flow table"))
307 raise CaptureTimeoutError(
308 "Packet did not arrive within timeout")
309 else:
310 return
311 if not expected:
312 raise CaptureTimeoutError("Packet arrived even not expected")
313 self.assertEqual(p[Set].setID, set_id)
314 # self.logger.debug(self.vapi.ppcli("show flow table"))
315 self.logger.debug(ppp("IPFIX: Got packet:", p))
316 break
317 return p
318
Ole Troan5c749732017-03-13 13:39:52 +0100319
Ole Troaned929252017-06-13 21:15:40 +0200320class Flowprobe(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100321 """Template verification, timer tests"""
322
323 def test_0001(self):
Pavel Kotucek89111d02017-06-12 08:26:13 +0200324 """ timer less than template timeout"""
Ole Troaned929252017-06-13 21:15:40 +0200325 self.logger.info("FFP_TEST_START_0001")
Ole Troan5c749732017-03-13 13:39:52 +0100326 self.pg_enable_capture(self.pg_interfaces)
327 self.pkts = []
328
Pavel Kotucek89111d02017-06-12 08:26:13 +0200329 ipfix = VppCFLOW(test=self, active=2)
Ole Troan5c749732017-03-13 13:39:52 +0100330 ipfix.add_vpp_config()
331
332 ipfix_decoder = IPFIXDecoder()
333 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200334 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100335
Ole Troaned929252017-06-13 21:15:40 +0200336 self.create_stream(packets=1)
Pavel Kotucek89111d02017-06-12 08:26:13 +0200337 self.send_packets()
Ole Troaned929252017-06-13 21:15:40 +0200338 capture = self.pg2.get_capture(1)
Ole Troan5c749732017-03-13 13:39:52 +0100339
340 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200341 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
Ole Troan5c749732017-03-13 13:39:52 +0100342 self.verify_cflow_data(ipfix_decoder, capture, cflow)
343
344 ipfix.remove_vpp_config()
Ole Troaned929252017-06-13 21:15:40 +0200345 self.logger.info("FFP_TEST_FINISH_0001")
Ole Troan5c749732017-03-13 13:39:52 +0100346
Pavel Kotucek89111d02017-06-12 08:26:13 +0200347 def test_0002(self):
348 """ timer greater than template timeout"""
Ole Troaned929252017-06-13 21:15:40 +0200349 self.logger.info("FFP_TEST_START_0002")
Ole Troan5c749732017-03-13 13:39:52 +0100350 self.pg_enable_capture(self.pg_interfaces)
351 self.pkts = []
352
Pavel Kotucek89111d02017-06-12 08:26:13 +0200353 ipfix = VppCFLOW(test=self, timeout=3, active=4)
Ole Troan5c749732017-03-13 13:39:52 +0100354 ipfix.add_vpp_config()
355
356 ipfix_decoder = IPFIXDecoder()
357 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200358 ipfix.verify_templates()
Ole Troan5c749732017-03-13 13:39:52 +0100359
Pavel Kotucek89111d02017-06-12 08:26:13 +0200360 self.create_stream(packets=2)
361 self.send_packets()
362 capture = self.pg2.get_capture(2)
Ole Troan5c749732017-03-13 13:39:52 +0100363
364 # next set of template packet should arrive after 20 seconds
365 # template packet should arrive within 20 s
Pavel Kotucek89111d02017-06-12 08:26:13 +0200366 templates = ipfix.verify_templates(ipfix_decoder, timeout=5)
Ole Troan5c749732017-03-13 13:39:52 +0100367
368 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200369 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
Ole Troan5c749732017-03-13 13:39:52 +0100370 self.verify_cflow_data(ipfix_decoder, capture, cflow)
371
372 ipfix.remove_vpp_config()
Ole Troaned929252017-06-13 21:15:40 +0200373 self.logger.info("FFP_TEST_FINISH_0002")
374
375 def test_cflow_packet(self):
376 """verify cflow packet fields"""
377 self.logger.info("FFP_TEST_START_0000")
378 self.pg_enable_capture(self.pg_interfaces)
379 self.pkts = []
380
381 ipfix = VppCFLOW(test=self, intf='pg8', datapath="ip4",
382 layer='l2 l3 l4', active=2)
383 ipfix.add_vpp_config()
384
385 route_9001 = VppIpRoute(self, "9.0.0.0", 24,
386 [VppRoutePath(self.pg8._remote_hosts[0].ip4,
387 self.pg8.sw_if_index)])
388 route_9001.add_vpp_config()
389
390 ipfix_decoder = IPFIXDecoder()
391 templates = ipfix.verify_templates(ipfix_decoder, count=1)
392
393 self.pkts = [(Ether(dst=self.pg7.local_mac,
394 src=self.pg7.remote_mac) /
395 IP(src=self.pg7.remote_ip4, dst="9.0.0.100") /
396 TCP(sport=1234, dport=4321, flags=80) /
397 Raw('\xa5' * 100))]
398
399 nowUTC = int(time.time())
400 nowUNIX = nowUTC+2208988800
401 self.send_packets(src_if=self.pg7, dst_if=self.pg8)
402
403 cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10)
404 self.collector.get_capture(2)
405
406 if cflow[0].haslayer(IPFIX):
407 self.assertEqual(cflow[IPFIX].version, 10)
408 self.assertEqual(cflow[IPFIX].observationDomainID, 1)
409 self.assertEqual(cflow[IPFIX].sequenceNumber, 0)
410 self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5)
411 if cflow.haslayer(Data):
412 record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0]
413 # ingress interface
414 self.assertEqual(int(record[10].encode('hex'), 16), 8)
415 # egress interface
416 self.assertEqual(int(record[14].encode('hex'), 16), 9)
417 # packets
418 self.assertEqual(int(record[2].encode('hex'), 16), 1)
419 # src mac
420 self.assertEqual(':'.join(re.findall('..', record[56].encode(
421 'hex'))), self.pg8.local_mac)
422 # dst mac
423 self.assertEqual(':'.join(re.findall('..', record[80].encode(
424 'hex'))), self.pg8.remote_mac)
425 flowTimestamp = int(record[156].encode('hex'), 16) >> 32
426 # flow start timestamp
427 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
428 flowTimestamp = int(record[157].encode('hex'), 16) >> 32
429 # flow end timestamp
430 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
431 # ethernet type
432 self.assertEqual(int(record[256].encode('hex'), 16), 8)
433 # src ip
434 self.assertEqual('.'.join(re.findall('..', record[8].encode(
435 'hex'))),
436 '.'.join('{:02x}'.format(int(n)) for n in
437 self.pg7.remote_ip4.split('.')))
438 # dst ip
439 self.assertEqual('.'.join(re.findall('..', record[12].encode(
440 'hex'))),
441 '.'.join('{:02x}'.format(int(n)) for n in
442 "9.0.0.100".split('.')))
443 # protocol (TCP)
444 self.assertEqual(int(record[4].encode('hex'), 16), 6)
445 # src port
446 self.assertEqual(int(record[7].encode('hex'), 16), 1234)
447 # dst port
448 self.assertEqual(int(record[11].encode('hex'), 16), 4321)
449 # tcp flags
450 self.assertEqual(int(record[6].encode('hex'), 16), 80)
451
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
Pavel Kotucek89111d02017-06-12 08:26:13 +0200456class Datapath(MethodHolder):
457 """collect information on Ethernet, IP4 and IP6 datapath (no timers)"""
Ole Troan5c749732017-03-13 13:39:52 +0100458
Pavel Kotucek89111d02017-06-12 08:26:13 +0200459 def test_templatesL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100460 """ verify template on L2 datapath"""
461 self.logger.info("FFP_TEST_START_0000")
462 self.pg_enable_capture(self.pg_interfaces)
463
Pavel Kotucek89111d02017-06-12 08:26:13 +0200464 ipfix = VppCFLOW(test=self, layer='l2')
Ole Troan5c749732017-03-13 13:39:52 +0100465 ipfix.add_vpp_config()
466
467 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200468 self.vapi.cli("ipfix flush")
469 ipfix.verify_templates(timeout=3, count=1)
470 self.collector.get_capture(1)
Ole Troan5c749732017-03-13 13:39:52 +0100471
472 ipfix.remove_vpp_config()
473 self.logger.info("FFP_TEST_FINISH_0000")
474
Pavel Kotucek89111d02017-06-12 08:26:13 +0200475 def test_L2onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100476 """ L2 data on L2 datapath"""
477 self.logger.info("FFP_TEST_START_0001")
478 self.pg_enable_capture(self.pg_interfaces)
479 self.pkts = []
480
Pavel Kotucek89111d02017-06-12 08:26:13 +0200481 ipfix = VppCFLOW(test=self, layer='l2')
Ole Troan5c749732017-03-13 13:39:52 +0100482 ipfix.add_vpp_config()
483
484 ipfix_decoder = IPFIXDecoder()
485 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200486 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100487
488 self.create_stream(packets=1)
489 capture = self.send_packets()
490
491 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200492 self.vapi.cli("ipfix flush")
493 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100494 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
495 {2: 'packets', 256: 8})
Ole Troan5c749732017-03-13 13:39:52 +0100496 self.collector.get_capture(2)
497
498 ipfix.remove_vpp_config()
499 self.logger.info("FFP_TEST_FINISH_0001")
500
Pavel Kotucek89111d02017-06-12 08:26:13 +0200501 def test_L3onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100502 """ L3 data on L2 datapath"""
503 self.logger.info("FFP_TEST_START_0002")
504 self.pg_enable_capture(self.pg_interfaces)
505 self.pkts = []
506
Pavel Kotucek89111d02017-06-12 08:26:13 +0200507 ipfix = VppCFLOW(test=self, layer='l3')
Ole Troan5c749732017-03-13 13:39:52 +0100508 ipfix.add_vpp_config()
509
510 ipfix_decoder = IPFIXDecoder()
511 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200512 templates = ipfix.verify_templates(ipfix_decoder, count=2)
Ole Troan5c749732017-03-13 13:39:52 +0100513
514 self.create_stream(packets=1)
515 capture = self.send_packets()
516
517 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200518 self.vapi.cli("ipfix flush")
519 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100520 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
521 {2: 'packets', 4: 17,
522 8: 'src_ip', 12: 'dst_ip'})
523
Ole Troan5c749732017-03-13 13:39:52 +0100524 self.collector.get_capture(3)
525
526 ipfix.remove_vpp_config()
527 self.logger.info("FFP_TEST_FINISH_0002")
528
Pavel Kotucek89111d02017-06-12 08:26:13 +0200529 def test_L4onL2(self):
Ole Troan5c749732017-03-13 13:39:52 +0100530 """ L4 data on L2 datapath"""
531 self.logger.info("FFP_TEST_START_0003")
532 self.pg_enable_capture(self.pg_interfaces)
533 self.pkts = []
534
Pavel Kotucek89111d02017-06-12 08:26:13 +0200535 ipfix = VppCFLOW(test=self, layer='l4')
Ole Troan5c749732017-03-13 13:39:52 +0100536 ipfix.add_vpp_config()
537
538 ipfix_decoder = IPFIXDecoder()
539 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200540 templates = ipfix.verify_templates(ipfix_decoder, count=2)
Ole Troan5c749732017-03-13 13:39:52 +0100541
542 self.create_stream(packets=1)
543 capture = self.send_packets()
544
545 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200546 self.vapi.cli("ipfix flush")
547 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100548 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
549 {2: 'packets', 7: 'sport', 11: 'dport'})
550
Ole Troan5c749732017-03-13 13:39:52 +0100551 self.collector.get_capture(3)
552
553 ipfix.remove_vpp_config()
554 self.logger.info("FFP_TEST_FINISH_0003")
555
Pavel Kotucek89111d02017-06-12 08:26:13 +0200556 def test_templatesIp4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100557 """ verify templates on IP4 datapath"""
558 self.logger.info("FFP_TEST_START_0000")
559
560 self.pg_enable_capture(self.pg_interfaces)
561
Pavel Kotucek89111d02017-06-12 08:26:13 +0200562 ipfix = VppCFLOW(test=self, datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100563 ipfix.add_vpp_config()
564
565 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200566 self.vapi.cli("ipfix flush")
Ole Troan5c749732017-03-13 13:39:52 +0100567 ipfix.verify_templates(timeout=3, count=1)
568 self.collector.get_capture(1)
569
570 ipfix.remove_vpp_config()
571
572 self.logger.info("FFP_TEST_FINISH_0000")
573
Pavel Kotucek89111d02017-06-12 08:26:13 +0200574 def test_L2onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100575 """ L2 data on IP4 datapath"""
576 self.logger.info("FFP_TEST_START_0001")
577 self.pg_enable_capture(self.pg_interfaces)
578 self.pkts = []
579
Pavel Kotucek89111d02017-06-12 08:26:13 +0200580 ipfix = VppCFLOW(test=self, intf='pg4', layer='l2', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100581 ipfix.add_vpp_config()
582
583 ipfix_decoder = IPFIXDecoder()
584 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200585 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100586
587 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
588 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
589
590 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200591 self.vapi.cli("ipfix flush")
592 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100593 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
594 {2: 'packets', 256: 8})
595
596 # expected two templates and one cflow packet
597 self.collector.get_capture(2)
598
599 ipfix.remove_vpp_config()
600 self.logger.info("FFP_TEST_FINISH_0001")
601
Pavel Kotucek89111d02017-06-12 08:26:13 +0200602 def test_L3onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100603 """ L3 data on IP4 datapath"""
604 self.logger.info("FFP_TEST_START_0002")
605 self.pg_enable_capture(self.pg_interfaces)
606 self.pkts = []
607
Pavel Kotucek89111d02017-06-12 08:26:13 +0200608 ipfix = VppCFLOW(test=self, intf='pg4', layer='l3', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100609 ipfix.add_vpp_config()
610
611 ipfix_decoder = IPFIXDecoder()
612 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200613 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100614
615 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
616 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
617
618 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200619 self.vapi.cli("ipfix flush")
620 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100621 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
622 {1: 'octets', 2: 'packets',
623 8: 'src_ip', 12: 'dst_ip'})
624
625 # expected two templates and one cflow packet
626 self.collector.get_capture(2)
627
628 ipfix.remove_vpp_config()
629 self.logger.info("FFP_TEST_FINISH_0002")
630
Pavel Kotucek89111d02017-06-12 08:26:13 +0200631 def test_L4onIP4(self):
Ole Troan5c749732017-03-13 13:39:52 +0100632 """ L4 data on IP4 datapath"""
633 self.logger.info("FFP_TEST_START_0003")
634 self.pg_enable_capture(self.pg_interfaces)
635 self.pkts = []
636
Pavel Kotucek89111d02017-06-12 08:26:13 +0200637 ipfix = VppCFLOW(test=self, intf='pg4', layer='l4', datapath='ip4')
Ole Troan5c749732017-03-13 13:39:52 +0100638 ipfix.add_vpp_config()
639
640 ipfix_decoder = IPFIXDecoder()
641 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200642 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100643
644 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
645 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
646
647 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200648 self.vapi.cli("ipfix flush")
649 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100650 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
651 {2: 'packets', 7: 'sport', 11: 'dport'})
652
653 # expected two templates and one cflow packet
654 self.collector.get_capture(2)
655
656 ipfix.remove_vpp_config()
657 self.logger.info("FFP_TEST_FINISH_0003")
658
Pavel Kotucek89111d02017-06-12 08:26:13 +0200659 def test_templatesIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100660 """ verify templates on IP6 datapath"""
661 self.logger.info("FFP_TEST_START_0000")
662 self.pg_enable_capture(self.pg_interfaces)
663
Pavel Kotucek89111d02017-06-12 08:26:13 +0200664 ipfix = VppCFLOW(test=self, datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100665 ipfix.add_vpp_config()
666
667 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200668 ipfix.verify_templates(count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100669 self.collector.get_capture(1)
670
671 ipfix.remove_vpp_config()
672
673 self.logger.info("FFP_TEST_FINISH_0000")
674
Pavel Kotucek89111d02017-06-12 08:26:13 +0200675 def test_L2onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100676 """ L2 data on IP6 datapath"""
677 self.logger.info("FFP_TEST_START_0001")
678 self.pg_enable_capture(self.pg_interfaces)
679 self.pkts = []
680
Pavel Kotucek89111d02017-06-12 08:26:13 +0200681 ipfix = VppCFLOW(test=self, intf='pg6', layer='l2', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100682 ipfix.add_vpp_config()
683
684 ipfix_decoder = IPFIXDecoder()
685 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200686 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100687
688 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
689 ip_ver='IPv6')
690 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
691
692 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200693 self.vapi.cli("ipfix flush")
694 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100695 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
696 {2: 'packets', 256: 56710},
697 ip_ver='v6')
698
699 # expected two templates and one cflow packet
700 self.collector.get_capture(2)
701
702 ipfix.remove_vpp_config()
703 self.logger.info("FFP_TEST_FINISH_0001")
704
Pavel Kotucek89111d02017-06-12 08:26:13 +0200705 def test_L3onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100706 """ L3 data on IP6 datapath"""
707 self.logger.info("FFP_TEST_START_0002")
708 self.pg_enable_capture(self.pg_interfaces)
709 self.pkts = []
710
Pavel Kotucek89111d02017-06-12 08:26:13 +0200711 ipfix = VppCFLOW(test=self, intf='pg6', layer='l3', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100712 ipfix.add_vpp_config()
713
714 ipfix_decoder = IPFIXDecoder()
715 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200716 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100717
718 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
719 ip_ver='IPv6')
720 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
721
722 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200723 self.vapi.cli("ipfix flush")
724 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100725 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
726 {2: 'packets',
727 27: 'src_ip', 28: 'dst_ip'},
728 ip_ver='v6')
729
730 # expected two templates and one cflow packet
731 self.collector.get_capture(2)
732
733 ipfix.remove_vpp_config()
734 self.logger.info("FFP_TEST_FINISH_0002")
735
Pavel Kotucek89111d02017-06-12 08:26:13 +0200736 def test_L4onIP6(self):
Ole Troan5c749732017-03-13 13:39:52 +0100737 """ L4 data on IP6 datapath"""
738 self.logger.info("FFP_TEST_START_0003")
739 self.pg_enable_capture(self.pg_interfaces)
740 self.pkts = []
741
Pavel Kotucek89111d02017-06-12 08:26:13 +0200742 ipfix = VppCFLOW(test=self, intf='pg6', layer='l4', datapath='ip6')
Ole Troan5c749732017-03-13 13:39:52 +0100743 ipfix.add_vpp_config()
744
745 ipfix_decoder = IPFIXDecoder()
746 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200747 templates = ipfix.verify_templates(ipfix_decoder, count=1)
Ole Troan5c749732017-03-13 13:39:52 +0100748
749 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
750 ip_ver='IPv6')
751 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
752
753 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200754 self.vapi.cli("ipfix flush")
755 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
Ole Troan5c749732017-03-13 13:39:52 +0100756 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
757 {2: 'packets', 7: 'sport', 11: 'dport'},
758 ip_ver='v6')
759
760 # expected two templates and one cflow packet
761 self.collector.get_capture(2)
762
763 ipfix.remove_vpp_config()
764 self.logger.info("FFP_TEST_FINISH_0003")
765
Ole Troan5c749732017-03-13 13:39:52 +0100766 def test_0001(self):
767 """ no timers, one CFLOW packet, 9 Flows inside"""
768 self.logger.info("FFP_TEST_START_0001")
769 self.pg_enable_capture(self.pg_interfaces)
770 self.pkts = []
771
Pavel Kotucek89111d02017-06-12 08:26:13 +0200772 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100773 ipfix.add_vpp_config()
774
775 ipfix_decoder = IPFIXDecoder()
776 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200777 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100778
779 self.create_stream(packets=9)
780 capture = self.send_packets()
781
782 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200783 self.vapi.cli("ipfix flush")
784 cflow = self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100785 self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow])
Ole Troan5c749732017-03-13 13:39:52 +0100786 self.collector.get_capture(4)
787
788 ipfix.remove_vpp_config()
789 self.logger.info("FFP_TEST_FINISH_0001")
790
791 def test_0002(self):
792 """ no timers, two CFLOW packets (mtu=256), 3 Flows in each"""
793 self.logger.info("FFP_TEST_START_0002")
794 self.pg_enable_capture(self.pg_interfaces)
795 self.pkts = []
796
Pavel Kotucek89111d02017-06-12 08:26:13 +0200797 ipfix = VppCFLOW(test=self, mtu=256)
Ole Troan5c749732017-03-13 13:39:52 +0100798 ipfix.add_vpp_config()
799
800 ipfix_decoder = IPFIXDecoder()
801 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200802 self.vapi.cli("ipfix flush")
803 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100804
805 self.create_stream(packets=6)
806 capture = self.send_packets()
807
808 # make sure the one packet we expect actually showed up
809 cflows = []
Pavel Kotucek89111d02017-06-12 08:26:13 +0200810 self.vapi.cli("ipfix flush")
Ole Troan5c749732017-03-13 13:39:52 +0100811 cflows.append(self.wait_for_cflow_packet(self.collector,
Pavel Kotucek89111d02017-06-12 08:26:13 +0200812 templates[1]))
Ole Troan5c749732017-03-13 13:39:52 +0100813 cflows.append(self.wait_for_cflow_packet(self.collector,
Pavel Kotucek89111d02017-06-12 08:26:13 +0200814 templates[1]))
Ole Troan5c749732017-03-13 13:39:52 +0100815 self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows)
816 self.collector.get_capture(5)
817
818 ipfix.remove_vpp_config()
819 self.logger.info("FFP_TEST_FINISH_0002")
820
821
Pavel Kotucek89111d02017-06-12 08:26:13 +0200822@unittest.skipUnless(running_extended_tests(), "part of extended tests")
823class DisableIPFIX(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100824 """Disable IPFIX"""
825
826 def test_0001(self):
827 """ disable IPFIX after first packets"""
828 self.logger.info("FFP_TEST_START_0001")
829 self.pg_enable_capture(self.pg_interfaces)
830 self.pkts = []
831
Pavel Kotucek89111d02017-06-12 08:26:13 +0200832 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100833 ipfix.add_vpp_config()
834
835 ipfix_decoder = IPFIXDecoder()
836 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200837 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100838
839 self.create_stream()
840 self.send_packets()
841
842 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200843 self.vapi.cli("ipfix flush")
844 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100845 self.collector.get_capture(4)
846
847 # disble IPFIX
848 ipfix.disable_exporter()
849 self.pg_enable_capture([self.collector])
850
851 self.send_packets()
852
853 # make sure no one packet arrived in 1 minute
Pavel Kotucek89111d02017-06-12 08:26:13 +0200854 self.vapi.cli("ipfix flush")
855 self.wait_for_cflow_packet(self.collector, templates[1],
Ole Troan5c749732017-03-13 13:39:52 +0100856 expected=False)
857 self.collector.get_capture(0)
858
859 ipfix.remove_vpp_config()
860 self.logger.info("FFP_TEST_FINISH_0001")
861
862
Pavel Kotucek89111d02017-06-12 08:26:13 +0200863@unittest.skipUnless(running_extended_tests(), "part of extended tests")
864class ReenableIPFIX(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100865 """Re-enable IPFIX"""
866
Pavel Kotucek89111d02017-06-12 08:26:13 +0200867 def test_0011(self):
Ole Troan5c749732017-03-13 13:39:52 +0100868 """ disable IPFIX after first packets and re-enable after few packets
869 """
870 self.logger.info("FFP_TEST_START_0001")
871 self.pg_enable_capture(self.pg_interfaces)
872 self.pkts = []
873
Pavel Kotucek89111d02017-06-12 08:26:13 +0200874 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100875 ipfix.add_vpp_config()
876
877 ipfix_decoder = IPFIXDecoder()
878 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200879 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100880
Pavel Kotucek89111d02017-06-12 08:26:13 +0200881 self.create_stream(packets=5)
Ole Troan5c749732017-03-13 13:39:52 +0100882 self.send_packets()
883
884 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200885 self.vapi.cli("ipfix flush")
886 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100887 self.collector.get_capture(4)
888
889 # disble IPFIX
890 ipfix.disable_exporter()
Pavel Kotucek89111d02017-06-12 08:26:13 +0200891 self.vapi.cli("ipfix flush")
Ole Troan5c749732017-03-13 13:39:52 +0100892 self.pg_enable_capture([self.collector])
893
894 self.send_packets()
895
896 # make sure no one packet arrived in active timer span
Pavel Kotucek89111d02017-06-12 08:26:13 +0200897 self.vapi.cli("ipfix flush")
898 self.wait_for_cflow_packet(self.collector, templates[1],
Ole Troan5c749732017-03-13 13:39:52 +0100899 expected=False)
900 self.collector.get_capture(0)
Pavel Kotucek89111d02017-06-12 08:26:13 +0200901 self.pg2.get_capture(5)
Ole Troan5c749732017-03-13 13:39:52 +0100902
903 # enable IPFIX
904 ipfix.enable_exporter()
Ole Troan5c749732017-03-13 13:39:52 +0100905
Pavel Kotucek89111d02017-06-12 08:26:13 +0200906 capture = self.collector.get_capture(4)
907 nr_templates = 0
908 nr_data = 0
909 for p in capture:
910 self.assertTrue(p.haslayer(IPFIX))
911 if p.haslayer(Template):
912 nr_templates += 1
913 self.assertTrue(nr_templates, 3)
914 for p in capture:
915 self.assertTrue(p.haslayer(IPFIX))
916 if p.haslayer(Data):
917 nr_data += 1
918 self.assertTrue(nr_templates, 1)
Ole Troan5c749732017-03-13 13:39:52 +0100919
920 ipfix.remove_vpp_config()
921 self.logger.info("FFP_TEST_FINISH_0001")
922
923
Pavel Kotucek89111d02017-06-12 08:26:13 +0200924@unittest.skipUnless(running_extended_tests(), "part of extended tests")
925class DisableFP(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100926 """Disable Flowprobe feature"""
927
928 def test_0001(self):
929 """ disable flowprobe feature after first packets"""
930 self.logger.info("FFP_TEST_START_0001")
931 self.pg_enable_capture(self.pg_interfaces)
932 self.pkts = []
Pavel Kotucek89111d02017-06-12 08:26:13 +0200933 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100934 ipfix.add_vpp_config()
935
936 ipfix_decoder = IPFIXDecoder()
937 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200938 templates = ipfix.verify_templates(ipfix_decoder)
Ole Troan5c749732017-03-13 13:39:52 +0100939
940 self.create_stream()
941 self.send_packets()
942
943 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200944 self.vapi.cli("ipfix flush")
945 self.wait_for_cflow_packet(self.collector, templates[1])
Ole Troan5c749732017-03-13 13:39:52 +0100946 self.collector.get_capture(4)
947
948 # disble IPFIX
949 ipfix.disable_flowprobe_feature()
950 self.pg_enable_capture([self.collector])
951
952 self.send_packets()
953
954 # make sure no one packet arrived in active timer span
Pavel Kotucek89111d02017-06-12 08:26:13 +0200955 self.vapi.cli("ipfix flush")
956 self.wait_for_cflow_packet(self.collector, templates[1],
Ole Troan5c749732017-03-13 13:39:52 +0100957 expected=False)
958 self.collector.get_capture(0)
959
960 ipfix.remove_vpp_config()
961 self.logger.info("FFP_TEST_FINISH_0001")
962
963
Pavel Kotucek89111d02017-06-12 08:26:13 +0200964@unittest.skipUnless(running_extended_tests(), "part of extended tests")
965class ReenableFP(MethodHolder):
Ole Troan5c749732017-03-13 13:39:52 +0100966 """Re-enable Flowprobe feature"""
967
968 def test_0001(self):
969 """ disable flowprobe feature after first packets and re-enable
970 after few packets """
971 self.logger.info("FFP_TEST_START_0001")
972 self.pg_enable_capture(self.pg_interfaces)
973 self.pkts = []
974
Pavel Kotucek89111d02017-06-12 08:26:13 +0200975 ipfix = VppCFLOW(test=self)
Ole Troan5c749732017-03-13 13:39:52 +0100976 ipfix.add_vpp_config()
977
978 ipfix_decoder = IPFIXDecoder()
979 # template packet should arrive immediately
Pavel Kotucek89111d02017-06-12 08:26:13 +0200980 self.vapi.cli("ipfix flush")
Ole Troan5c749732017-03-13 13:39:52 +0100981 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
982
983 self.create_stream()
984 self.send_packets()
985
986 # make sure the one packet we expect actually showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +0200987 self.vapi.cli("ipfix flush")
988 self.wait_for_cflow_packet(self.collector, templates[1], 5)
Ole Troan5c749732017-03-13 13:39:52 +0100989 self.collector.get_capture(4)
990
991 # disble FPP feature
992 ipfix.disable_flowprobe_feature()
993 self.pg_enable_capture([self.collector])
994
995 self.send_packets()
996
997 # make sure no one packet arrived in active timer span
Pavel Kotucek89111d02017-06-12 08:26:13 +0200998 self.vapi.cli("ipfix flush")
999 self.wait_for_cflow_packet(self.collector, templates[1], 5,
Ole Troan5c749732017-03-13 13:39:52 +01001000 expected=False)
1001 self.collector.get_capture(0)
1002
1003 # enable FPP feature
1004 ipfix.enable_flowprobe_feature()
1005 self.vapi.cli("ipfix flush")
1006 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1007
1008 self.send_packets()
1009
1010 # make sure the next packets (templates and data) we expect actually
1011 # showed up
Pavel Kotucek89111d02017-06-12 08:26:13 +02001012 self.vapi.cli("ipfix flush")
1013 self.wait_for_cflow_packet(self.collector, templates[1], 5)
Ole Troan5c749732017-03-13 13:39:52 +01001014 self.collector.get_capture(4)
1015
1016 ipfix.remove_vpp_config()
1017 self.logger.info("FFP_TEST_FINISH_0001")
1018
1019
1020if __name__ == '__main__':
1021 unittest.main(testRunner=VppTestRunner)