2 from __future__ import print_function
10 from scapy.packet import Raw
11 from scapy.layers.l2 import Ether
12 from scapy.layers.inet import IP, TCP, UDP
13 from scapy.layers.inet6 import IPv6
15 from framework import VppTestCase, VppTestRunner, running_extended_tests
16 from framework import tag_run_solo
17 from vpp_object import VppObject
18 from vpp_pg_interface import CaptureTimeoutError
20 from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
21 from vpp_ip_route import VppIpRoute, VppRoutePath
22 from vpp_papi.macaddress import mac_ntop
23 from socket import inet_ntop
24 from vpp_papi import VppEnum
27 class VppCFLOW(VppObject):
28 """CFLOW object for IPFIX exporter and Flowprobe feature"""
30 def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100,
31 mtu=1024, datapath='l2', layer='l2 l3 l4'):
35 if passive == 0 or passive < active:
36 self._passive = active+1
38 self._passive = passive
39 self._datapath = datapath # l2 ip4 ip6
40 self._collect = layer # l2 l3 l4
41 self._timeout = timeout
43 self._configured = False
45 def add_vpp_config(self):
46 self.enable_exporter()
50 if 'l2' in self._collect.lower():
51 l2_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
52 FLOWPROBE_RECORD_FLAG_L2)
53 if 'l3' in self._collect.lower():
54 l3_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
55 FLOWPROBE_RECORD_FLAG_L3)
56 if 'l4' in self._collect.lower():
57 l4_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
58 FLOWPROBE_RECORD_FLAG_L4)
59 self._test.vapi.flowprobe_params(
60 record_flags=(l2_flag | l3_flag | l4_flag),
61 active_timer=self._active, passive_timer=self._passive)
62 self.enable_flowprobe_feature()
63 self._test.vapi.cli("ipfix flush")
64 self._configured = True
66 def remove_vpp_config(self):
67 self.disable_exporter()
68 self.disable_flowprobe_feature()
69 self._test.vapi.cli("ipfix flush")
70 self._configured = False
72 def enable_exporter(self):
73 self._test.vapi.set_ipfix_exporter(
74 collector_address=self._test.pg0.remote_ip4,
75 src_address=self._test.pg0.local_ip4,
77 template_interval=self._timeout)
79 def enable_flowprobe_feature(self):
80 self._test.vapi.ppcli("flowprobe feature add-del %s %s" %
81 (self._intf, self._datapath))
83 def disable_exporter(self):
84 self._test.vapi.cli("set ipfix exporter collector 0.0.0.0")
86 def disable_flowprobe_feature(self):
87 self._test.vapi.cli("flowprobe feature add-del %s %s disable" %
88 (self._intf, self._datapath))
91 return "ipfix-collector-%s-%s" % (self._src, self.dst)
93 def query_vpp_config(self):
94 return self._configured
96 def verify_templates(self, decoder=None, timeout=1, count=3):
98 p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout)
99 self._test.assertTrue(p.haslayer(IPFIX))
100 if decoder is not None and p.haslayer(Template):
101 templates.append(p[Template].templateID)
102 decoder.add_template(p.getlayer(Template))
104 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
105 self._test.assertTrue(p.haslayer(IPFIX))
106 if decoder is not None and p.haslayer(Template):
107 templates.append(p[Template].templateID)
108 decoder.add_template(p.getlayer(Template))
110 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
111 self._test.assertTrue(p.haslayer(IPFIX))
112 if decoder is not None and p.haslayer(Template):
113 templates.append(p[Template].templateID)
114 decoder.add_template(p.getlayer(Template))
118 class MethodHolder(VppTestCase):
119 """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """
123 max_number_of_packets = 10
129 Perform standard class setup (defined by class method setUpClass in
130 class VppTestCase) before running the test case, set test case related
131 variables and configure VPP.
133 super(MethodHolder, cls).setUpClass()
135 # Create pg interfaces
136 cls.create_pg_interfaces(range(9))
139 cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
141 # Create BD with MAC learning and unknown unicast flooding disabled
142 # and put interfaces to this BD
143 cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1)
144 cls.vapi.sw_interface_set_l2_bridge(
145 rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1)
146 cls.vapi.sw_interface_set_l2_bridge(
147 rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1)
149 # Set up all interfaces
150 for i in cls.pg_interfaces:
154 cls.pg0.configure_ipv4_neighbors()
155 cls.collector = cls.pg0
158 cls.pg1.resolve_arp()
160 cls.pg2.resolve_arp()
162 cls.pg3.resolve_arp()
164 cls.pg4.resolve_arp()
167 cls.pg8.configure_ipv4_neighbors()
170 cls.pg5.resolve_ndp()
171 cls.pg5.disable_ipv6_ra()
173 cls.pg6.resolve_ndp()
174 cls.pg6.disable_ipv6_ra()
176 super(MethodHolder, cls).tearDownClass()
180 def tearDownClass(cls):
181 super(MethodHolder, cls).tearDownClass()
183 def create_stream(self, src_if=None, dst_if=None, packets=None,
184 size=None, ip_ver='v4'):
185 """Create a packet stream to tickle the plugin
187 :param VppInterface src_if: Source interface for packet stream
188 :param VppInterface src_if: Dst interface for packet stream
196 packets = random.randint(1, self.max_number_of_packets)
198 for p in range(0, packets):
200 pkt_size = random.choice(self.pg_if_packet_sizes)
201 info = self.create_packet_info(src_if, dst_if)
202 payload = self.info_to_payload(info)
203 p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
205 p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
207 p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
208 p /= UDP(sport=1234, dport=4321)
211 self.extend_packet(p, pkt_size)
214 def verify_cflow_data(self, decoder, capture, cflow):
220 if cflow.haslayer(Data):
221 data = decoder.decode_data_set(cflow.getlayer(Set))
223 self.assertEqual(int(binascii.hexlify(record[1]), 16), octets)
224 self.assertEqual(int(binascii.hexlify(record[2]), 16), packets)
226 def send_packets(self, src_if=None, dst_if=None):
231 self.pg_enable_capture([dst_if])
232 src_if.add_stream(self.pkts)
234 return dst_if.get_capture(len(self.pkts))
236 def verify_cflow_data_detail(self, decoder, capture, cflow,
237 data_set={1: 'octets', 2: 'packets'},
240 print(capture[0].show())
241 if cflow.haslayer(Data):
242 data = decoder.decode_data_set(cflow.getlayer(Set))
246 ip_layer = capture[0][IP]
248 ip_layer = capture[0][IPv6]
249 if data_set is not None:
251 # skip flow if ingress/egress interface is 0
252 if int(binascii.hexlify(record[10]), 16) == 0:
254 if int(binascii.hexlify(record[14]), 16) == 0:
257 for field in data_set:
258 if field not in record.keys():
260 value = data_set[field]
261 if value == 'octets':
264 value += 40 # ??? is this correct
265 elif value == 'packets':
267 elif value == 'src_ip':
269 ip = socket.inet_pton(socket.AF_INET,
272 ip = socket.inet_pton(socket.AF_INET6,
274 value = int(binascii.hexlify(ip), 16)
275 elif value == 'dst_ip':
277 ip = socket.inet_pton(socket.AF_INET,
280 ip = socket.inet_pton(socket.AF_INET6,
282 value = int(binascii.hexlify(ip), 16)
283 elif value == 'sport':
284 value = int(capture[0][UDP].sport)
285 elif value == 'dport':
286 value = int(capture[0][UDP].dport)
287 self.assertEqual(int(binascii.hexlify(
291 def verify_cflow_data_notimer(self, decoder, capture, cflows):
294 if cflow.haslayer(Data):
295 data = decoder.decode_data_set(cflow.getlayer(Set))
297 raise Exception("No CFLOW data")
302 self.assertEqual(p[IP].len, int(
303 binascii.hexlify(rec[1]), 16))
304 self.assertEqual(1, int(
305 binascii.hexlify(rec[2]), 16))
306 self.assertEqual(len(capture), idx)
308 def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1,
310 """ wait for CFLOW packet and verify its correctness
312 :param timeout: how long to wait
314 :returns: tuple (packet, time spent waiting for packet)
316 self.logger.info("IPFIX: Waiting for CFLOW packet")
317 deadline = time.time() + timeout
319 # self.logger.debug(self.vapi.ppcli("show flow table"))
323 self.assert_in_range(counter, 0, 100, "number of packets ignored")
324 time_left = deadline - time.time()
326 if time_left < 0 and expected:
327 # self.logger.debug(self.vapi.ppcli("show flow table"))
328 raise CaptureTimeoutError(
329 "Packet did not arrive within timeout")
330 p = collector_intf.wait_for_packet(timeout=time_left)
331 except CaptureTimeoutError:
333 # self.logger.debug(self.vapi.ppcli("show flow table"))
334 raise CaptureTimeoutError(
335 "Packet did not arrive within timeout")
339 raise CaptureTimeoutError("Packet arrived even not expected")
340 self.assertEqual(p[Set].setID, set_id)
341 # self.logger.debug(self.vapi.ppcli("show flow table"))
342 self.logger.debug(ppp("IPFIX: Got packet:", p))
348 class Flowprobe(MethodHolder):
349 """Template verification, timer tests"""
353 super(Flowprobe, cls).setUpClass()
356 def tearDownClass(cls):
357 super(Flowprobe, cls).tearDownClass()
360 """ timer less than template timeout"""
361 self.logger.info("FFP_TEST_START_0001")
362 self.pg_enable_capture(self.pg_interfaces)
365 ipfix = VppCFLOW(test=self, active=2)
366 ipfix.add_vpp_config()
368 ipfix_decoder = IPFIXDecoder()
369 # template packet should arrive immediately
370 templates = ipfix.verify_templates(ipfix_decoder)
372 self.create_stream(packets=1)
374 capture = self.pg2.get_capture(1)
376 # make sure the one packet we expect actually showed up
377 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
378 self.verify_cflow_data(ipfix_decoder, capture, cflow)
380 ipfix.remove_vpp_config()
381 self.logger.info("FFP_TEST_FINISH_0001")
384 """ timer greater than template timeout"""
385 self.logger.info("FFP_TEST_START_0002")
386 self.pg_enable_capture(self.pg_interfaces)
389 ipfix = VppCFLOW(test=self, timeout=3, active=4)
390 ipfix.add_vpp_config()
392 ipfix_decoder = IPFIXDecoder()
393 # template packet should arrive immediately
394 ipfix.verify_templates()
396 self.create_stream(packets=2)
398 capture = self.pg2.get_capture(2)
400 # next set of template packet should arrive after 20 seconds
401 # template packet should arrive within 20 s
402 templates = ipfix.verify_templates(ipfix_decoder, timeout=5)
404 # make sure the one packet we expect actually showed up
405 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
406 self.verify_cflow_data(ipfix_decoder, capture, cflow)
408 ipfix.remove_vpp_config()
409 self.logger.info("FFP_TEST_FINISH_0002")
411 def test_cflow_packet(self):
412 """verify cflow packet fields"""
413 self.logger.info("FFP_TEST_START_0000")
414 self.pg_enable_capture(self.pg_interfaces)
417 ipfix = VppCFLOW(test=self, intf='pg8', datapath="ip4",
418 layer='l2 l3 l4', active=2)
419 ipfix.add_vpp_config()
421 route_9001 = VppIpRoute(self, "9.0.0.0", 24,
422 [VppRoutePath(self.pg8._remote_hosts[0].ip4,
423 self.pg8.sw_if_index)])
424 route_9001.add_vpp_config()
426 ipfix_decoder = IPFIXDecoder()
427 templates = ipfix.verify_templates(ipfix_decoder, count=1)
429 self.pkts = [(Ether(dst=self.pg7.local_mac,
430 src=self.pg7.remote_mac) /
431 IP(src=self.pg7.remote_ip4, dst="9.0.0.100") /
432 TCP(sport=1234, dport=4321, flags=80) /
435 nowUTC = int(time.time())
436 nowUNIX = nowUTC+2208988800
437 self.send_packets(src_if=self.pg7, dst_if=self.pg8)
439 cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10)
440 self.collector.get_capture(2)
442 if cflow[0].haslayer(IPFIX):
443 self.assertEqual(cflow[IPFIX].version, 10)
444 self.assertEqual(cflow[IPFIX].observationDomainID, 1)
445 self.assertEqual(cflow[IPFIX].sequenceNumber, 0)
446 self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5)
447 if cflow.haslayer(Data):
448 record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0]
450 self.assertEqual(int(binascii.hexlify(record[10]), 16), 8)
452 self.assertEqual(int(binascii.hexlify(record[14]), 16), 9)
454 self.assertEqual(int(binascii.hexlify(record[2]), 16), 1)
456 self.assertEqual(mac_ntop(record[56]), self.pg8.local_mac)
458 self.assertEqual(mac_ntop(record[80]), self.pg8.remote_mac)
459 flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32
460 # flow start timestamp
461 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
462 flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32
464 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
466 self.assertEqual(int(binascii.hexlify(record[256]), 16), 8)
468 self.assertEqual(inet_ntop(socket.AF_INET, record[8]),
471 self.assertEqual(inet_ntop(socket.AF_INET, record[12]),
474 self.assertEqual(int(binascii.hexlify(record[4]), 16), 6)
476 self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234)
478 self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321)
480 self.assertEqual(int(binascii.hexlify(record[6]), 16), 80)
482 ipfix.remove_vpp_config()
483 self.logger.info("FFP_TEST_FINISH_0000")
486 class Datapath(MethodHolder):
487 """collect information on Ethernet, IP4 and IP6 datapath (no timers)"""
491 super(Datapath, cls).setUpClass()
494 def tearDownClass(cls):
495 super(Datapath, cls).tearDownClass()
497 def test_templatesL2(self):
498 """ verify template on L2 datapath"""
499 self.logger.info("FFP_TEST_START_0000")
500 self.pg_enable_capture(self.pg_interfaces)
502 ipfix = VppCFLOW(test=self, layer='l2')
503 ipfix.add_vpp_config()
505 # template packet should arrive immediately
506 self.vapi.ipfix_flush()
507 ipfix.verify_templates(timeout=3, count=1)
508 self.collector.get_capture(1)
510 ipfix.remove_vpp_config()
511 self.logger.info("FFP_TEST_FINISH_0000")
513 def test_L2onL2(self):
514 """ L2 data on L2 datapath"""
515 self.logger.info("FFP_TEST_START_0001")
516 self.pg_enable_capture(self.pg_interfaces)
519 ipfix = VppCFLOW(test=self, layer='l2')
520 ipfix.add_vpp_config()
522 ipfix_decoder = IPFIXDecoder()
523 # template packet should arrive immediately
524 templates = ipfix.verify_templates(ipfix_decoder, count=1)
526 self.create_stream(packets=1)
527 capture = self.send_packets()
529 # make sure the one packet we expect actually showed up
530 self.vapi.ipfix_flush()
531 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
532 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
533 {2: 'packets', 256: 8})
534 self.collector.get_capture(2)
536 ipfix.remove_vpp_config()
537 self.logger.info("FFP_TEST_FINISH_0001")
539 def test_L3onL2(self):
540 """ L3 data on L2 datapath"""
541 self.logger.info("FFP_TEST_START_0002")
542 self.pg_enable_capture(self.pg_interfaces)
545 ipfix = VppCFLOW(test=self, layer='l3')
546 ipfix.add_vpp_config()
548 ipfix_decoder = IPFIXDecoder()
549 # template packet should arrive immediately
550 templates = ipfix.verify_templates(ipfix_decoder, count=2)
552 self.create_stream(packets=1)
553 capture = self.send_packets()
555 # make sure the one packet we expect actually showed up
556 self.vapi.ipfix_flush()
557 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
558 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
559 {2: 'packets', 4: 17,
560 8: 'src_ip', 12: 'dst_ip'})
562 self.collector.get_capture(3)
564 ipfix.remove_vpp_config()
565 self.logger.info("FFP_TEST_FINISH_0002")
567 def test_L4onL2(self):
568 """ L4 data on L2 datapath"""
569 self.logger.info("FFP_TEST_START_0003")
570 self.pg_enable_capture(self.pg_interfaces)
573 ipfix = VppCFLOW(test=self, layer='l4')
574 ipfix.add_vpp_config()
576 ipfix_decoder = IPFIXDecoder()
577 # template packet should arrive immediately
578 templates = ipfix.verify_templates(ipfix_decoder, count=2)
580 self.create_stream(packets=1)
581 capture = self.send_packets()
583 # make sure the one packet we expect actually showed up
584 self.vapi.ipfix_flush()
585 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
586 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
587 {2: 'packets', 7: 'sport', 11: 'dport'})
589 self.collector.get_capture(3)
591 ipfix.remove_vpp_config()
592 self.logger.info("FFP_TEST_FINISH_0003")
594 def test_templatesIp4(self):
595 """ verify templates on IP4 datapath"""
596 self.logger.info("FFP_TEST_START_0000")
598 self.pg_enable_capture(self.pg_interfaces)
600 ipfix = VppCFLOW(test=self, datapath='ip4')
601 ipfix.add_vpp_config()
603 # template packet should arrive immediately
604 self.vapi.ipfix_flush()
605 ipfix.verify_templates(timeout=3, count=1)
606 self.collector.get_capture(1)
608 ipfix.remove_vpp_config()
610 self.logger.info("FFP_TEST_FINISH_0000")
612 def test_L2onIP4(self):
613 """ L2 data on IP4 datapath"""
614 self.logger.info("FFP_TEST_START_0001")
615 self.pg_enable_capture(self.pg_interfaces)
618 ipfix = VppCFLOW(test=self, intf='pg4', layer='l2', datapath='ip4')
619 ipfix.add_vpp_config()
621 ipfix_decoder = IPFIXDecoder()
622 # template packet should arrive immediately
623 templates = ipfix.verify_templates(ipfix_decoder, count=1)
625 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
626 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
628 # make sure the one packet we expect actually showed up
629 self.vapi.ipfix_flush()
630 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
631 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
632 {2: 'packets', 256: 8})
634 # expected two templates and one cflow packet
635 self.collector.get_capture(2)
637 ipfix.remove_vpp_config()
638 self.logger.info("FFP_TEST_FINISH_0001")
640 def test_L3onIP4(self):
641 """ L3 data on IP4 datapath"""
642 self.logger.info("FFP_TEST_START_0002")
643 self.pg_enable_capture(self.pg_interfaces)
646 ipfix = VppCFLOW(test=self, intf='pg4', layer='l3', datapath='ip4')
647 ipfix.add_vpp_config()
649 ipfix_decoder = IPFIXDecoder()
650 # template packet should arrive immediately
651 templates = ipfix.verify_templates(ipfix_decoder, count=1)
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)
656 # make sure the one packet we expect actually showed up
657 self.vapi.ipfix_flush()
658 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
659 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
660 {1: 'octets', 2: 'packets',
661 8: 'src_ip', 12: 'dst_ip'})
663 # expected two templates and one cflow packet
664 self.collector.get_capture(2)
666 ipfix.remove_vpp_config()
667 self.logger.info("FFP_TEST_FINISH_0002")
669 def test_L4onIP4(self):
670 """ L4 data on IP4 datapath"""
671 self.logger.info("FFP_TEST_START_0003")
672 self.pg_enable_capture(self.pg_interfaces)
675 ipfix = VppCFLOW(test=self, intf='pg4', layer='l4', datapath='ip4')
676 ipfix.add_vpp_config()
678 ipfix_decoder = IPFIXDecoder()
679 # template packet should arrive immediately
680 templates = ipfix.verify_templates(ipfix_decoder, count=1)
682 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
683 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
685 # make sure the one packet we expect actually showed up
686 self.vapi.ipfix_flush()
687 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
688 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
689 {2: 'packets', 7: 'sport', 11: 'dport'})
691 # expected two templates and one cflow packet
692 self.collector.get_capture(2)
694 ipfix.remove_vpp_config()
695 self.logger.info("FFP_TEST_FINISH_0003")
697 def test_templatesIP6(self):
698 """ verify templates on IP6 datapath"""
699 self.logger.info("FFP_TEST_START_0000")
700 self.pg_enable_capture(self.pg_interfaces)
702 ipfix = VppCFLOW(test=self, datapath='ip6')
703 ipfix.add_vpp_config()
705 # template packet should arrive immediately
706 ipfix.verify_templates(count=1)
707 self.collector.get_capture(1)
709 ipfix.remove_vpp_config()
711 self.logger.info("FFP_TEST_FINISH_0000")
713 def test_L2onIP6(self):
714 """ L2 data on IP6 datapath"""
715 self.logger.info("FFP_TEST_START_0001")
716 self.pg_enable_capture(self.pg_interfaces)
719 ipfix = VppCFLOW(test=self, intf='pg6', layer='l2', datapath='ip6')
720 ipfix.add_vpp_config()
722 ipfix_decoder = IPFIXDecoder()
723 # template packet should arrive immediately
724 templates = ipfix.verify_templates(ipfix_decoder, count=1)
726 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
728 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
730 # make sure the one packet we expect actually showed up
731 self.vapi.ipfix_flush()
732 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
733 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
734 {2: 'packets', 256: 56710},
737 # expected two templates and one cflow packet
738 self.collector.get_capture(2)
740 ipfix.remove_vpp_config()
741 self.logger.info("FFP_TEST_FINISH_0001")
743 def test_L3onIP6(self):
744 """ L3 data on IP6 datapath"""
745 self.logger.info("FFP_TEST_START_0002")
746 self.pg_enable_capture(self.pg_interfaces)
749 ipfix = VppCFLOW(test=self, intf='pg6', layer='l3', datapath='ip6')
750 ipfix.add_vpp_config()
752 ipfix_decoder = IPFIXDecoder()
753 # template packet should arrive immediately
754 templates = ipfix.verify_templates(ipfix_decoder, count=1)
756 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
758 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
760 # make sure the one packet we expect actually showed up
761 self.vapi.ipfix_flush()
762 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
763 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
765 27: 'src_ip', 28: 'dst_ip'},
768 # expected two templates and one cflow packet
769 self.collector.get_capture(2)
771 ipfix.remove_vpp_config()
772 self.logger.info("FFP_TEST_FINISH_0002")
774 def test_L4onIP6(self):
775 """ L4 data on IP6 datapath"""
776 self.logger.info("FFP_TEST_START_0003")
777 self.pg_enable_capture(self.pg_interfaces)
780 ipfix = VppCFLOW(test=self, intf='pg6', layer='l4', datapath='ip6')
781 ipfix.add_vpp_config()
783 ipfix_decoder = IPFIXDecoder()
784 # template packet should arrive immediately
785 templates = ipfix.verify_templates(ipfix_decoder, count=1)
787 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
789 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
791 # make sure the one packet we expect actually showed up
792 self.vapi.ipfix_flush()
793 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
794 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
795 {2: 'packets', 7: 'sport', 11: 'dport'},
798 # expected two templates and one cflow packet
799 self.collector.get_capture(2)
801 ipfix.remove_vpp_config()
802 self.logger.info("FFP_TEST_FINISH_0003")
805 """ no timers, one CFLOW packet, 9 Flows inside"""
806 self.logger.info("FFP_TEST_START_0001")
807 self.pg_enable_capture(self.pg_interfaces)
810 ipfix = VppCFLOW(test=self)
811 ipfix.add_vpp_config()
813 ipfix_decoder = IPFIXDecoder()
814 # template packet should arrive immediately
815 templates = ipfix.verify_templates(ipfix_decoder)
817 self.create_stream(packets=9)
818 capture = self.send_packets()
820 # make sure the one packet we expect actually showed up
821 self.vapi.ipfix_flush()
822 cflow = self.wait_for_cflow_packet(self.collector, templates[1])
823 self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow])
824 self.collector.get_capture(4)
826 ipfix.remove_vpp_config()
827 self.logger.info("FFP_TEST_FINISH_0001")
830 """ no timers, two CFLOW packets (mtu=256), 3 Flows in each"""
831 self.logger.info("FFP_TEST_START_0002")
832 self.pg_enable_capture(self.pg_interfaces)
835 ipfix = VppCFLOW(test=self, mtu=256)
836 ipfix.add_vpp_config()
838 ipfix_decoder = IPFIXDecoder()
839 # template packet should arrive immediately
840 self.vapi.ipfix_flush()
841 templates = ipfix.verify_templates(ipfix_decoder)
843 self.create_stream(packets=6)
844 capture = self.send_packets()
846 # make sure the one packet we expect actually showed up
848 self.vapi.ipfix_flush()
849 cflows.append(self.wait_for_cflow_packet(self.collector,
851 cflows.append(self.wait_for_cflow_packet(self.collector,
853 self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows)
854 self.collector.get_capture(5)
856 ipfix.remove_vpp_config()
857 self.logger.info("FFP_TEST_FINISH_0002")
860 @unittest.skipUnless(running_extended_tests, "part of extended tests")
861 class DisableIPFIX(MethodHolder):
866 super(DisableIPFIX, cls).setUpClass()
869 def tearDownClass(cls):
870 super(DisableIPFIX, cls).tearDownClass()
873 """ disable IPFIX after first packets"""
874 self.logger.info("FFP_TEST_START_0001")
875 self.pg_enable_capture(self.pg_interfaces)
878 ipfix = VppCFLOW(test=self)
879 ipfix.add_vpp_config()
881 ipfix_decoder = IPFIXDecoder()
882 # template packet should arrive immediately
883 templates = ipfix.verify_templates(ipfix_decoder)
888 # make sure the one packet we expect actually showed up
889 self.vapi.ipfix_flush()
890 self.wait_for_cflow_packet(self.collector, templates[1])
891 self.collector.get_capture(4)
894 ipfix.disable_exporter()
895 self.pg_enable_capture([self.collector])
899 # make sure no one packet arrived in 1 minute
900 self.vapi.ipfix_flush()
901 self.wait_for_cflow_packet(self.collector, templates[1],
903 self.collector.get_capture(0)
905 ipfix.remove_vpp_config()
906 self.logger.info("FFP_TEST_FINISH_0001")
909 @unittest.skipUnless(running_extended_tests, "part of extended tests")
910 class ReenableIPFIX(MethodHolder):
911 """Re-enable IPFIX"""
915 super(ReenableIPFIX, cls).setUpClass()
918 def tearDownClass(cls):
919 super(ReenableIPFIX, cls).tearDownClass()
922 """ disable IPFIX after first packets and re-enable after few packets
924 self.logger.info("FFP_TEST_START_0001")
925 self.pg_enable_capture(self.pg_interfaces)
928 ipfix = VppCFLOW(test=self)
929 ipfix.add_vpp_config()
931 ipfix_decoder = IPFIXDecoder()
932 # template packet should arrive immediately
933 templates = ipfix.verify_templates(ipfix_decoder)
935 self.create_stream(packets=5)
938 # make sure the one packet we expect actually showed up
939 self.vapi.ipfix_flush()
940 self.wait_for_cflow_packet(self.collector, templates[1])
941 self.collector.get_capture(4)
944 ipfix.disable_exporter()
945 self.vapi.ipfix_flush()
946 self.pg_enable_capture([self.collector])
950 # make sure no one packet arrived in active timer span
951 self.vapi.ipfix_flush()
952 self.wait_for_cflow_packet(self.collector, templates[1],
954 self.collector.get_capture(0)
955 self.pg2.get_capture(5)
958 ipfix.enable_exporter()
960 capture = self.collector.get_capture(4)
964 self.assertTrue(p.haslayer(IPFIX))
965 if p.haslayer(Template):
967 self.assertTrue(nr_templates, 3)
969 self.assertTrue(p.haslayer(IPFIX))
972 self.assertTrue(nr_templates, 1)
974 ipfix.remove_vpp_config()
975 self.logger.info("FFP_TEST_FINISH_0001")
978 @unittest.skipUnless(running_extended_tests, "part of extended tests")
979 class DisableFP(MethodHolder):
980 """Disable Flowprobe feature"""
984 super(DisableFP, cls).setUpClass()
987 def tearDownClass(cls):
988 super(DisableFP, cls).tearDownClass()
991 """ disable flowprobe feature after first packets"""
992 self.logger.info("FFP_TEST_START_0001")
993 self.pg_enable_capture(self.pg_interfaces)
995 ipfix = VppCFLOW(test=self)
996 ipfix.add_vpp_config()
998 ipfix_decoder = IPFIXDecoder()
999 # template packet should arrive immediately
1000 templates = ipfix.verify_templates(ipfix_decoder)
1002 self.create_stream()
1005 # make sure the one packet we expect actually showed up
1006 self.vapi.ipfix_flush()
1007 self.wait_for_cflow_packet(self.collector, templates[1])
1008 self.collector.get_capture(4)
1011 ipfix.disable_flowprobe_feature()
1012 self.pg_enable_capture([self.collector])
1016 # make sure no one packet arrived in active timer span
1017 self.vapi.ipfix_flush()
1018 self.wait_for_cflow_packet(self.collector, templates[1],
1020 self.collector.get_capture(0)
1022 ipfix.remove_vpp_config()
1023 self.logger.info("FFP_TEST_FINISH_0001")
1026 @unittest.skipUnless(running_extended_tests, "part of extended tests")
1027 class ReenableFP(MethodHolder):
1028 """Re-enable Flowprobe feature"""
1031 def setUpClass(cls):
1032 super(ReenableFP, cls).setUpClass()
1035 def tearDownClass(cls):
1036 super(ReenableFP, cls).tearDownClass()
1038 def test_0001(self):
1039 """ disable flowprobe feature after first packets and re-enable
1040 after few packets """
1041 self.logger.info("FFP_TEST_START_0001")
1042 self.pg_enable_capture(self.pg_interfaces)
1045 ipfix = VppCFLOW(test=self)
1046 ipfix.add_vpp_config()
1048 ipfix_decoder = IPFIXDecoder()
1049 # template packet should arrive immediately
1050 self.vapi.ipfix_flush()
1051 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1053 self.create_stream()
1056 # make sure the one packet we expect actually showed up
1057 self.vapi.ipfix_flush()
1058 self.wait_for_cflow_packet(self.collector, templates[1], 5)
1059 self.collector.get_capture(4)
1061 # disable FPP feature
1062 ipfix.disable_flowprobe_feature()
1063 self.pg_enable_capture([self.collector])
1067 # make sure no one packet arrived in active timer span
1068 self.vapi.ipfix_flush()
1069 self.wait_for_cflow_packet(self.collector, templates[1], 5,
1071 self.collector.get_capture(0)
1073 # enable FPP feature
1074 ipfix.enable_flowprobe_feature()
1075 self.vapi.ipfix_flush()
1076 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1080 # make sure the next packets (templates and data) we expect actually
1082 self.vapi.ipfix_flush()
1083 self.wait_for_cflow_packet(self.collector, templates[1], 5)
1084 self.collector.get_capture(4)
1086 ipfix.remove_vpp_config()
1087 self.logger.info("FFP_TEST_FINISH_0001")
1090 if __name__ == '__main__':
1091 unittest.main(testRunner=VppTestRunner)