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 tag_fixme_vpp_workers
16 from framework import VppTestCase, VppTestRunner, running_extended_tests
17 from framework import tag_run_solo
18 from vpp_object import VppObject
19 from vpp_pg_interface import CaptureTimeoutError
21 from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
22 from vpp_ip_route import VppIpRoute, VppRoutePath
23 from vpp_papi.macaddress import mac_ntop
24 from socket import inet_ntop
25 from vpp_papi import VppEnum
28 class VppCFLOW(VppObject):
29 """CFLOW object for IPFIX exporter and Flowprobe feature"""
31 def __init__(self, test, intf='pg2', active=0, passive=0, timeout=100,
32 mtu=1024, datapath='l2', layer='l2 l3 l4'):
36 if passive == 0 or passive < active:
37 self._passive = active+1
39 self._passive = passive
40 self._datapath = datapath # l2 ip4 ip6
41 self._collect = layer # l2 l3 l4
42 self._timeout = timeout
44 self._configured = False
46 def add_vpp_config(self):
47 self.enable_exporter()
51 if 'l2' in self._collect.lower():
52 l2_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
53 FLOWPROBE_RECORD_FLAG_L2)
54 if 'l3' in self._collect.lower():
55 l3_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
56 FLOWPROBE_RECORD_FLAG_L3)
57 if 'l4' in self._collect.lower():
58 l4_flag = (VppEnum.vl_api_flowprobe_record_flags_t.
59 FLOWPROBE_RECORD_FLAG_L4)
60 self._test.vapi.flowprobe_params(
61 record_flags=(l2_flag | l3_flag | l4_flag),
62 active_timer=self._active, passive_timer=self._passive)
63 self.enable_flowprobe_feature()
64 self._test.vapi.cli("ipfix flush")
65 self._configured = True
67 def remove_vpp_config(self):
68 self.disable_exporter()
69 self.disable_flowprobe_feature()
70 self._test.vapi.cli("ipfix flush")
71 self._configured = False
73 def enable_exporter(self):
74 self._test.vapi.set_ipfix_exporter(
75 collector_address=self._test.pg0.remote_ip4,
76 src_address=self._test.pg0.local_ip4,
78 template_interval=self._timeout)
80 def enable_flowprobe_feature(self):
81 self._test.vapi.ppcli("flowprobe feature add-del %s %s" %
82 (self._intf, self._datapath))
84 def disable_exporter(self):
85 self._test.vapi.cli("set ipfix exporter collector 0.0.0.0")
87 def disable_flowprobe_feature(self):
88 self._test.vapi.cli("flowprobe feature add-del %s %s disable" %
89 (self._intf, self._datapath))
92 return "ipfix-collector-%s-%s" % (self._src, self.dst)
94 def query_vpp_config(self):
95 return self._configured
97 def verify_templates(self, decoder=None, timeout=1, count=3):
99 p = self._test.wait_for_cflow_packet(self._test.collector, 2, timeout)
100 self._test.assertTrue(p.haslayer(IPFIX))
101 if decoder is not None and p.haslayer(Template):
102 templates.append(p[Template].templateID)
103 decoder.add_template(p.getlayer(Template))
105 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
106 self._test.assertTrue(p.haslayer(IPFIX))
107 if decoder is not None and p.haslayer(Template):
108 templates.append(p[Template].templateID)
109 decoder.add_template(p.getlayer(Template))
111 p = self._test.wait_for_cflow_packet(self._test.collector, 2)
112 self._test.assertTrue(p.haslayer(IPFIX))
113 if decoder is not None and p.haslayer(Template):
114 templates.append(p[Template].templateID)
115 decoder.add_template(p.getlayer(Template))
119 class MethodHolder(VppTestCase):
120 """ Flow-per-packet plugin: test L2, IP4, IP6 reporting """
124 max_number_of_packets = 10
130 Perform standard class setup (defined by class method setUpClass in
131 class VppTestCase) before running the test case, set test case related
132 variables and configure VPP.
134 super(MethodHolder, cls).setUpClass()
136 # Create pg interfaces
137 cls.create_pg_interfaces(range(9))
140 cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
142 # Create BD with MAC learning and unknown unicast flooding disabled
143 # and put interfaces to this BD
144 cls.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1, learn=1)
145 cls.vapi.sw_interface_set_l2_bridge(
146 rx_sw_if_index=cls.pg1._sw_if_index, bd_id=1)
147 cls.vapi.sw_interface_set_l2_bridge(
148 rx_sw_if_index=cls.pg2._sw_if_index, bd_id=1)
150 # Set up all interfaces
151 for i in cls.pg_interfaces:
155 cls.pg0.configure_ipv4_neighbors()
156 cls.collector = cls.pg0
159 cls.pg1.resolve_arp()
161 cls.pg2.resolve_arp()
163 cls.pg3.resolve_arp()
165 cls.pg4.resolve_arp()
168 cls.pg8.configure_ipv4_neighbors()
171 cls.pg5.resolve_ndp()
172 cls.pg5.disable_ipv6_ra()
174 cls.pg6.resolve_ndp()
175 cls.pg6.disable_ipv6_ra()
177 super(MethodHolder, cls).tearDownClass()
181 def tearDownClass(cls):
182 super(MethodHolder, cls).tearDownClass()
184 def create_stream(self, src_if=None, dst_if=None, packets=None,
185 size=None, ip_ver='v4'):
186 """Create a packet stream to tickle the plugin
188 :param VppInterface src_if: Source interface for packet stream
189 :param VppInterface src_if: Dst interface for packet stream
197 packets = random.randint(1, self.max_number_of_packets)
199 for p in range(0, packets):
201 pkt_size = random.choice(self.pg_if_packet_sizes)
202 info = self.create_packet_info(src_if, dst_if)
203 payload = self.info_to_payload(info)
204 p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
206 p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
208 p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
209 p /= UDP(sport=1234, dport=4321)
212 self.extend_packet(p, pkt_size)
215 def verify_cflow_data(self, decoder, capture, cflow):
221 if cflow.haslayer(Data):
222 data = decoder.decode_data_set(cflow.getlayer(Set))
224 self.assertEqual(int(binascii.hexlify(record[1]), 16), octets)
225 self.assertEqual(int(binascii.hexlify(record[2]), 16), packets)
227 def send_packets(self, src_if=None, dst_if=None):
232 self.pg_enable_capture([dst_if])
233 src_if.add_stream(self.pkts)
235 return dst_if.get_capture(len(self.pkts))
237 def verify_cflow_data_detail(self, decoder, capture, cflow,
238 data_set={1: 'octets', 2: 'packets'},
241 print(capture[0].show())
242 if cflow.haslayer(Data):
243 data = decoder.decode_data_set(cflow.getlayer(Set))
247 ip_layer = capture[0][IP]
249 ip_layer = capture[0][IPv6]
250 if data_set is not None:
252 # skip flow if ingress/egress interface is 0
253 if int(binascii.hexlify(record[10]), 16) == 0:
255 if int(binascii.hexlify(record[14]), 16) == 0:
258 for field in data_set:
259 if field not in record.keys():
261 value = data_set[field]
262 if value == 'octets':
265 value += 40 # ??? is this correct
266 elif value == 'packets':
268 elif value == 'src_ip':
270 ip = socket.inet_pton(socket.AF_INET,
273 ip = socket.inet_pton(socket.AF_INET6,
275 value = int(binascii.hexlify(ip), 16)
276 elif value == 'dst_ip':
278 ip = socket.inet_pton(socket.AF_INET,
281 ip = socket.inet_pton(socket.AF_INET6,
283 value = int(binascii.hexlify(ip), 16)
284 elif value == 'sport':
285 value = int(capture[0][UDP].sport)
286 elif value == 'dport':
287 value = int(capture[0][UDP].dport)
288 self.assertEqual(int(binascii.hexlify(
292 def verify_cflow_data_notimer(self, decoder, capture, cflows):
295 if cflow.haslayer(Data):
296 data = decoder.decode_data_set(cflow.getlayer(Set))
298 raise Exception("No CFLOW data")
303 self.assertEqual(p[IP].len, int(
304 binascii.hexlify(rec[1]), 16))
305 self.assertEqual(1, int(
306 binascii.hexlify(rec[2]), 16))
307 self.assertEqual(len(capture), idx)
309 def wait_for_cflow_packet(self, collector_intf, set_id=2, timeout=1,
311 """ wait for CFLOW packet and verify its correctness
313 :param timeout: how long to wait
315 :returns: tuple (packet, time spent waiting for packet)
317 self.logger.info("IPFIX: Waiting for CFLOW packet")
318 deadline = time.time() + timeout
320 # self.logger.debug(self.vapi.ppcli("show flow table"))
324 self.assert_in_range(counter, 0, 100, "number of packets ignored")
325 time_left = deadline - time.time()
327 if time_left < 0 and expected:
328 # self.logger.debug(self.vapi.ppcli("show flow table"))
329 raise CaptureTimeoutError(
330 "Packet did not arrive within timeout")
331 p = collector_intf.wait_for_packet(timeout=time_left)
332 except CaptureTimeoutError:
334 # self.logger.debug(self.vapi.ppcli("show flow table"))
335 raise CaptureTimeoutError(
336 "Packet did not arrive within timeout")
340 raise CaptureTimeoutError("Packet arrived even not expected")
341 self.assertEqual(p[Set].setID, set_id)
342 # self.logger.debug(self.vapi.ppcli("show flow table"))
343 self.logger.debug(ppp("IPFIX: Got packet:", p))
349 @tag_fixme_vpp_workers
350 class Flowprobe(MethodHolder):
351 """Template verification, timer tests"""
355 super(Flowprobe, cls).setUpClass()
358 def tearDownClass(cls):
359 super(Flowprobe, cls).tearDownClass()
362 """ timer less than template timeout"""
363 self.logger.info("FFP_TEST_START_0001")
364 self.pg_enable_capture(self.pg_interfaces)
367 ipfix = VppCFLOW(test=self, active=2)
368 ipfix.add_vpp_config()
370 ipfix_decoder = IPFIXDecoder()
371 # template packet should arrive immediately
372 templates = ipfix.verify_templates(ipfix_decoder)
374 self.create_stream(packets=1)
376 capture = self.pg2.get_capture(1)
378 # make sure the one packet we expect actually showed up
379 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
380 self.verify_cflow_data(ipfix_decoder, capture, cflow)
382 ipfix.remove_vpp_config()
383 self.logger.info("FFP_TEST_FINISH_0001")
386 """ timer greater than template timeout"""
387 self.logger.info("FFP_TEST_START_0002")
388 self.pg_enable_capture(self.pg_interfaces)
391 ipfix = VppCFLOW(test=self, timeout=3, active=4)
392 ipfix.add_vpp_config()
394 ipfix_decoder = IPFIXDecoder()
395 # template packet should arrive immediately
396 ipfix.verify_templates()
398 self.create_stream(packets=2)
400 capture = self.pg2.get_capture(2)
402 # next set of template packet should arrive after 20 seconds
403 # template packet should arrive within 20 s
404 templates = ipfix.verify_templates(ipfix_decoder, timeout=5)
406 # make sure the one packet we expect actually showed up
407 cflow = self.wait_for_cflow_packet(self.collector, templates[1], 15)
408 self.verify_cflow_data(ipfix_decoder, capture, cflow)
410 ipfix.remove_vpp_config()
411 self.logger.info("FFP_TEST_FINISH_0002")
413 def test_cflow_packet(self):
414 """verify cflow packet fields"""
415 self.logger.info("FFP_TEST_START_0000")
416 self.pg_enable_capture(self.pg_interfaces)
419 ipfix = VppCFLOW(test=self, intf='pg8', datapath="ip4",
420 layer='l2 l3 l4', active=2)
421 ipfix.add_vpp_config()
423 route_9001 = VppIpRoute(self, "9.0.0.0", 24,
424 [VppRoutePath(self.pg8._remote_hosts[0].ip4,
425 self.pg8.sw_if_index)])
426 route_9001.add_vpp_config()
428 ipfix_decoder = IPFIXDecoder()
429 templates = ipfix.verify_templates(ipfix_decoder, count=1)
431 self.pkts = [(Ether(dst=self.pg7.local_mac,
432 src=self.pg7.remote_mac) /
433 IP(src=self.pg7.remote_ip4, dst="9.0.0.100") /
434 TCP(sport=1234, dport=4321, flags=80) /
437 nowUTC = int(time.time())
438 nowUNIX = nowUTC+2208988800
439 self.send_packets(src_if=self.pg7, dst_if=self.pg8)
441 cflow = self.wait_for_cflow_packet(self.collector, templates[0], 10)
442 self.collector.get_capture(2)
444 if cflow[0].haslayer(IPFIX):
445 self.assertEqual(cflow[IPFIX].version, 10)
446 self.assertEqual(cflow[IPFIX].observationDomainID, 1)
447 self.assertEqual(cflow[IPFIX].sequenceNumber, 0)
448 self.assertAlmostEqual(cflow[IPFIX].exportTime, nowUTC, delta=5)
449 if cflow.haslayer(Data):
450 record = ipfix_decoder.decode_data_set(cflow[0].getlayer(Set))[0]
452 self.assertEqual(int(binascii.hexlify(record[10]), 16), 8)
454 self.assertEqual(int(binascii.hexlify(record[14]), 16), 9)
456 self.assertEqual(int(binascii.hexlify(record[2]), 16), 1)
458 self.assertEqual(mac_ntop(record[56]), self.pg8.local_mac)
460 self.assertEqual(mac_ntop(record[80]), self.pg8.remote_mac)
461 flowTimestamp = int(binascii.hexlify(record[156]), 16) >> 32
462 # flow start timestamp
463 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
464 flowTimestamp = int(binascii.hexlify(record[157]), 16) >> 32
466 self.assertAlmostEqual(flowTimestamp, nowUNIX, delta=1)
468 self.assertEqual(int(binascii.hexlify(record[256]), 16), 8)
470 self.assertEqual(inet_ntop(socket.AF_INET, record[8]),
473 self.assertEqual(inet_ntop(socket.AF_INET, record[12]),
476 self.assertEqual(int(binascii.hexlify(record[4]), 16), 6)
478 self.assertEqual(int(binascii.hexlify(record[7]), 16), 1234)
480 self.assertEqual(int(binascii.hexlify(record[11]), 16), 4321)
482 self.assertEqual(int(binascii.hexlify(record[6]), 16), 80)
484 ipfix.remove_vpp_config()
485 self.logger.info("FFP_TEST_FINISH_0000")
488 @tag_fixme_vpp_workers
489 class Datapath(MethodHolder):
490 """collect information on Ethernet, IP4 and IP6 datapath (no timers)"""
494 super(Datapath, cls).setUpClass()
497 def tearDownClass(cls):
498 super(Datapath, cls).tearDownClass()
500 def test_templatesL2(self):
501 """ verify template on L2 datapath"""
502 self.logger.info("FFP_TEST_START_0000")
503 self.pg_enable_capture(self.pg_interfaces)
505 ipfix = VppCFLOW(test=self, layer='l2')
506 ipfix.add_vpp_config()
508 # template packet should arrive immediately
509 self.vapi.ipfix_flush()
510 ipfix.verify_templates(timeout=3, count=1)
511 self.collector.get_capture(1)
513 ipfix.remove_vpp_config()
514 self.logger.info("FFP_TEST_FINISH_0000")
516 def test_L2onL2(self):
517 """ L2 data on L2 datapath"""
518 self.logger.info("FFP_TEST_START_0001")
519 self.pg_enable_capture(self.pg_interfaces)
522 ipfix = VppCFLOW(test=self, layer='l2')
523 ipfix.add_vpp_config()
525 ipfix_decoder = IPFIXDecoder()
526 # template packet should arrive immediately
527 templates = ipfix.verify_templates(ipfix_decoder, count=1)
529 self.create_stream(packets=1)
530 capture = self.send_packets()
532 # make sure the one packet we expect actually showed up
533 self.vapi.ipfix_flush()
534 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
535 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
536 {2: 'packets', 256: 8})
537 self.collector.get_capture(2)
539 ipfix.remove_vpp_config()
540 self.logger.info("FFP_TEST_FINISH_0001")
542 def test_L3onL2(self):
543 """ L3 data on L2 datapath"""
544 self.logger.info("FFP_TEST_START_0002")
545 self.pg_enable_capture(self.pg_interfaces)
548 ipfix = VppCFLOW(test=self, layer='l3')
549 ipfix.add_vpp_config()
551 ipfix_decoder = IPFIXDecoder()
552 # template packet should arrive immediately
553 templates = ipfix.verify_templates(ipfix_decoder, count=2)
555 self.create_stream(packets=1)
556 capture = self.send_packets()
558 # make sure the one packet we expect actually showed up
559 self.vapi.ipfix_flush()
560 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
561 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
562 {2: 'packets', 4: 17,
563 8: 'src_ip', 12: 'dst_ip'})
565 self.collector.get_capture(3)
567 ipfix.remove_vpp_config()
568 self.logger.info("FFP_TEST_FINISH_0002")
570 def test_L4onL2(self):
571 """ L4 data on L2 datapath"""
572 self.logger.info("FFP_TEST_START_0003")
573 self.pg_enable_capture(self.pg_interfaces)
576 ipfix = VppCFLOW(test=self, layer='l4')
577 ipfix.add_vpp_config()
579 ipfix_decoder = IPFIXDecoder()
580 # template packet should arrive immediately
581 templates = ipfix.verify_templates(ipfix_decoder, count=2)
583 self.create_stream(packets=1)
584 capture = self.send_packets()
586 # make sure the one packet we expect actually showed up
587 self.vapi.ipfix_flush()
588 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
589 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
590 {2: 'packets', 7: 'sport', 11: 'dport'})
592 self.collector.get_capture(3)
594 ipfix.remove_vpp_config()
595 self.logger.info("FFP_TEST_FINISH_0003")
597 def test_templatesIp4(self):
598 """ verify templates on IP4 datapath"""
599 self.logger.info("FFP_TEST_START_0000")
601 self.pg_enable_capture(self.pg_interfaces)
603 ipfix = VppCFLOW(test=self, datapath='ip4')
604 ipfix.add_vpp_config()
606 # template packet should arrive immediately
607 self.vapi.ipfix_flush()
608 ipfix.verify_templates(timeout=3, count=1)
609 self.collector.get_capture(1)
611 ipfix.remove_vpp_config()
613 self.logger.info("FFP_TEST_FINISH_0000")
615 def test_L2onIP4(self):
616 """ L2 data on IP4 datapath"""
617 self.logger.info("FFP_TEST_START_0001")
618 self.pg_enable_capture(self.pg_interfaces)
621 ipfix = VppCFLOW(test=self, intf='pg4', layer='l2', datapath='ip4')
622 ipfix.add_vpp_config()
624 ipfix_decoder = IPFIXDecoder()
625 # template packet should arrive immediately
626 templates = ipfix.verify_templates(ipfix_decoder, count=1)
628 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
629 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
631 # make sure the one packet we expect actually showed up
632 self.vapi.ipfix_flush()
633 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
634 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
635 {2: 'packets', 256: 8})
637 # expected two templates and one cflow packet
638 self.collector.get_capture(2)
640 ipfix.remove_vpp_config()
641 self.logger.info("FFP_TEST_FINISH_0001")
643 def test_L3onIP4(self):
644 """ L3 data on IP4 datapath"""
645 self.logger.info("FFP_TEST_START_0002")
646 self.pg_enable_capture(self.pg_interfaces)
649 ipfix = VppCFLOW(test=self, intf='pg4', layer='l3', datapath='ip4')
650 ipfix.add_vpp_config()
652 ipfix_decoder = IPFIXDecoder()
653 # template packet should arrive immediately
654 templates = ipfix.verify_templates(ipfix_decoder, count=1)
656 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
657 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
659 # make sure the one packet we expect actually showed up
660 self.vapi.ipfix_flush()
661 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
662 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
663 {1: 'octets', 2: 'packets',
664 8: 'src_ip', 12: 'dst_ip'})
666 # expected two templates and one cflow packet
667 self.collector.get_capture(2)
669 ipfix.remove_vpp_config()
670 self.logger.info("FFP_TEST_FINISH_0002")
672 def test_L4onIP4(self):
673 """ L4 data on IP4 datapath"""
674 self.logger.info("FFP_TEST_START_0003")
675 self.pg_enable_capture(self.pg_interfaces)
678 ipfix = VppCFLOW(test=self, intf='pg4', layer='l4', datapath='ip4')
679 ipfix.add_vpp_config()
681 ipfix_decoder = IPFIXDecoder()
682 # template packet should arrive immediately
683 templates = ipfix.verify_templates(ipfix_decoder, count=1)
685 self.create_stream(src_if=self.pg3, dst_if=self.pg4, packets=1)
686 capture = self.send_packets(src_if=self.pg3, dst_if=self.pg4)
688 # make sure the one packet we expect actually showed up
689 self.vapi.ipfix_flush()
690 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
691 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
692 {2: 'packets', 7: 'sport', 11: 'dport'})
694 # expected two templates and one cflow packet
695 self.collector.get_capture(2)
697 ipfix.remove_vpp_config()
698 self.logger.info("FFP_TEST_FINISH_0003")
700 def test_templatesIP6(self):
701 """ verify templates on IP6 datapath"""
702 self.logger.info("FFP_TEST_START_0000")
703 self.pg_enable_capture(self.pg_interfaces)
705 ipfix = VppCFLOW(test=self, datapath='ip6')
706 ipfix.add_vpp_config()
708 # template packet should arrive immediately
709 ipfix.verify_templates(count=1)
710 self.collector.get_capture(1)
712 ipfix.remove_vpp_config()
714 self.logger.info("FFP_TEST_FINISH_0000")
716 def test_L2onIP6(self):
717 """ L2 data on IP6 datapath"""
718 self.logger.info("FFP_TEST_START_0001")
719 self.pg_enable_capture(self.pg_interfaces)
722 ipfix = VppCFLOW(test=self, intf='pg6', layer='l2', datapath='ip6')
723 ipfix.add_vpp_config()
725 ipfix_decoder = IPFIXDecoder()
726 # template packet should arrive immediately
727 templates = ipfix.verify_templates(ipfix_decoder, count=1)
729 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
731 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
733 # make sure the one packet we expect actually showed up
734 self.vapi.ipfix_flush()
735 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
736 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
737 {2: 'packets', 256: 56710},
740 # expected two templates and one cflow packet
741 self.collector.get_capture(2)
743 ipfix.remove_vpp_config()
744 self.logger.info("FFP_TEST_FINISH_0001")
746 def test_L3onIP6(self):
747 """ L3 data on IP6 datapath"""
748 self.logger.info("FFP_TEST_START_0002")
749 self.pg_enable_capture(self.pg_interfaces)
752 ipfix = VppCFLOW(test=self, intf='pg6', layer='l3', datapath='ip6')
753 ipfix.add_vpp_config()
755 ipfix_decoder = IPFIXDecoder()
756 # template packet should arrive immediately
757 templates = ipfix.verify_templates(ipfix_decoder, count=1)
759 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
761 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
763 # make sure the one packet we expect actually showed up
764 self.vapi.ipfix_flush()
765 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
766 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
768 27: 'src_ip', 28: 'dst_ip'},
771 # expected two templates and one cflow packet
772 self.collector.get_capture(2)
774 ipfix.remove_vpp_config()
775 self.logger.info("FFP_TEST_FINISH_0002")
777 def test_L4onIP6(self):
778 """ L4 data on IP6 datapath"""
779 self.logger.info("FFP_TEST_START_0003")
780 self.pg_enable_capture(self.pg_interfaces)
783 ipfix = VppCFLOW(test=self, intf='pg6', layer='l4', datapath='ip6')
784 ipfix.add_vpp_config()
786 ipfix_decoder = IPFIXDecoder()
787 # template packet should arrive immediately
788 templates = ipfix.verify_templates(ipfix_decoder, count=1)
790 self.create_stream(src_if=self.pg5, dst_if=self.pg6, packets=1,
792 capture = self.send_packets(src_if=self.pg5, dst_if=self.pg6)
794 # make sure the one packet we expect actually showed up
795 self.vapi.ipfix_flush()
796 cflow = self.wait_for_cflow_packet(self.collector, templates[0])
797 self.verify_cflow_data_detail(ipfix_decoder, capture, cflow,
798 {2: 'packets', 7: 'sport', 11: 'dport'},
801 # expected two templates and one cflow packet
802 self.collector.get_capture(2)
804 ipfix.remove_vpp_config()
805 self.logger.info("FFP_TEST_FINISH_0003")
808 """ no timers, one CFLOW packet, 9 Flows inside"""
809 self.logger.info("FFP_TEST_START_0001")
810 self.pg_enable_capture(self.pg_interfaces)
813 ipfix = VppCFLOW(test=self)
814 ipfix.add_vpp_config()
816 ipfix_decoder = IPFIXDecoder()
817 # template packet should arrive immediately
818 templates = ipfix.verify_templates(ipfix_decoder)
820 self.create_stream(packets=9)
821 capture = self.send_packets()
823 # make sure the one packet we expect actually showed up
824 self.vapi.ipfix_flush()
825 cflow = self.wait_for_cflow_packet(self.collector, templates[1])
826 self.verify_cflow_data_notimer(ipfix_decoder, capture, [cflow])
827 self.collector.get_capture(4)
829 ipfix.remove_vpp_config()
830 self.logger.info("FFP_TEST_FINISH_0001")
833 """ no timers, two CFLOW packets (mtu=256), 3 Flows in each"""
834 self.logger.info("FFP_TEST_START_0002")
835 self.pg_enable_capture(self.pg_interfaces)
838 ipfix = VppCFLOW(test=self, mtu=256)
839 ipfix.add_vpp_config()
841 ipfix_decoder = IPFIXDecoder()
842 # template packet should arrive immediately
843 self.vapi.ipfix_flush()
844 templates = ipfix.verify_templates(ipfix_decoder)
846 self.create_stream(packets=6)
847 capture = self.send_packets()
849 # make sure the one packet we expect actually showed up
851 self.vapi.ipfix_flush()
852 cflows.append(self.wait_for_cflow_packet(self.collector,
854 cflows.append(self.wait_for_cflow_packet(self.collector,
856 self.verify_cflow_data_notimer(ipfix_decoder, capture, cflows)
857 self.collector.get_capture(5)
859 ipfix.remove_vpp_config()
860 self.logger.info("FFP_TEST_FINISH_0002")
863 @unittest.skipUnless(running_extended_tests, "part of extended tests")
864 class DisableIPFIX(MethodHolder):
869 super(DisableIPFIX, cls).setUpClass()
872 def tearDownClass(cls):
873 super(DisableIPFIX, cls).tearDownClass()
876 """ disable IPFIX after first packets"""
877 self.logger.info("FFP_TEST_START_0001")
878 self.pg_enable_capture(self.pg_interfaces)
881 ipfix = VppCFLOW(test=self)
882 ipfix.add_vpp_config()
884 ipfix_decoder = IPFIXDecoder()
885 # template packet should arrive immediately
886 templates = ipfix.verify_templates(ipfix_decoder)
891 # make sure the one packet we expect actually showed up
892 self.vapi.ipfix_flush()
893 self.wait_for_cflow_packet(self.collector, templates[1])
894 self.collector.get_capture(4)
897 ipfix.disable_exporter()
898 self.pg_enable_capture([self.collector])
902 # make sure no one packet arrived in 1 minute
903 self.vapi.ipfix_flush()
904 self.wait_for_cflow_packet(self.collector, templates[1],
906 self.collector.get_capture(0)
908 ipfix.remove_vpp_config()
909 self.logger.info("FFP_TEST_FINISH_0001")
912 @unittest.skipUnless(running_extended_tests, "part of extended tests")
913 class ReenableIPFIX(MethodHolder):
914 """Re-enable IPFIX"""
918 super(ReenableIPFIX, cls).setUpClass()
921 def tearDownClass(cls):
922 super(ReenableIPFIX, cls).tearDownClass()
925 """ disable IPFIX after first packets and re-enable after few packets
927 self.logger.info("FFP_TEST_START_0001")
928 self.pg_enable_capture(self.pg_interfaces)
931 ipfix = VppCFLOW(test=self)
932 ipfix.add_vpp_config()
934 ipfix_decoder = IPFIXDecoder()
935 # template packet should arrive immediately
936 templates = ipfix.verify_templates(ipfix_decoder)
938 self.create_stream(packets=5)
941 # make sure the one packet we expect actually showed up
942 self.vapi.ipfix_flush()
943 self.wait_for_cflow_packet(self.collector, templates[1])
944 self.collector.get_capture(4)
947 ipfix.disable_exporter()
948 self.vapi.ipfix_flush()
949 self.pg_enable_capture([self.collector])
953 # make sure no one packet arrived in active timer span
954 self.vapi.ipfix_flush()
955 self.wait_for_cflow_packet(self.collector, templates[1],
957 self.collector.get_capture(0)
958 self.pg2.get_capture(5)
961 ipfix.enable_exporter()
963 capture = self.collector.get_capture(4)
967 self.assertTrue(p.haslayer(IPFIX))
968 if p.haslayer(Template):
970 self.assertTrue(nr_templates, 3)
972 self.assertTrue(p.haslayer(IPFIX))
975 self.assertTrue(nr_templates, 1)
977 ipfix.remove_vpp_config()
978 self.logger.info("FFP_TEST_FINISH_0001")
981 @unittest.skipUnless(running_extended_tests, "part of extended tests")
982 class DisableFP(MethodHolder):
983 """Disable Flowprobe feature"""
987 super(DisableFP, cls).setUpClass()
990 def tearDownClass(cls):
991 super(DisableFP, cls).tearDownClass()
994 """ disable flowprobe feature after first packets"""
995 self.logger.info("FFP_TEST_START_0001")
996 self.pg_enable_capture(self.pg_interfaces)
998 ipfix = VppCFLOW(test=self)
999 ipfix.add_vpp_config()
1001 ipfix_decoder = IPFIXDecoder()
1002 # template packet should arrive immediately
1003 templates = ipfix.verify_templates(ipfix_decoder)
1005 self.create_stream()
1008 # make sure the one packet we expect actually showed up
1009 self.vapi.ipfix_flush()
1010 self.wait_for_cflow_packet(self.collector, templates[1])
1011 self.collector.get_capture(4)
1014 ipfix.disable_flowprobe_feature()
1015 self.pg_enable_capture([self.collector])
1019 # make sure no one packet arrived in active timer span
1020 self.vapi.ipfix_flush()
1021 self.wait_for_cflow_packet(self.collector, templates[1],
1023 self.collector.get_capture(0)
1025 ipfix.remove_vpp_config()
1026 self.logger.info("FFP_TEST_FINISH_0001")
1029 @unittest.skipUnless(running_extended_tests, "part of extended tests")
1030 class ReenableFP(MethodHolder):
1031 """Re-enable Flowprobe feature"""
1034 def setUpClass(cls):
1035 super(ReenableFP, cls).setUpClass()
1038 def tearDownClass(cls):
1039 super(ReenableFP, cls).tearDownClass()
1041 def test_0001(self):
1042 """ disable flowprobe feature after first packets and re-enable
1043 after few packets """
1044 self.logger.info("FFP_TEST_START_0001")
1045 self.pg_enable_capture(self.pg_interfaces)
1048 ipfix = VppCFLOW(test=self)
1049 ipfix.add_vpp_config()
1051 ipfix_decoder = IPFIXDecoder()
1052 # template packet should arrive immediately
1053 self.vapi.ipfix_flush()
1054 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1056 self.create_stream()
1059 # make sure the one packet we expect actually showed up
1060 self.vapi.ipfix_flush()
1061 self.wait_for_cflow_packet(self.collector, templates[1], 5)
1062 self.collector.get_capture(4)
1064 # disable FPP feature
1065 ipfix.disable_flowprobe_feature()
1066 self.pg_enable_capture([self.collector])
1070 # make sure no one packet arrived in active timer span
1071 self.vapi.ipfix_flush()
1072 self.wait_for_cflow_packet(self.collector, templates[1], 5,
1074 self.collector.get_capture(0)
1076 # enable FPP feature
1077 ipfix.enable_flowprobe_feature()
1078 self.vapi.ipfix_flush()
1079 templates = ipfix.verify_templates(ipfix_decoder, timeout=3)
1083 # make sure the next packets (templates and data) we expect actually
1085 self.vapi.ipfix_flush()
1086 self.wait_for_cflow_packet(self.collector, templates[1], 5)
1087 self.collector.get_capture(4)
1089 ipfix.remove_vpp_config()
1090 self.logger.info("FFP_TEST_FINISH_0001")
1093 if __name__ == '__main__':
1094 unittest.main(testRunner=VppTestRunner)