blob: 7cdc14033304c4a86ac49144334c70a2085c3fe0 [file] [log] [blame]
Paul Atkins0352ea02021-09-23 10:43:44 +01001#!/usr/bin/env python3
Dave Wallace8800f732023-08-31 00:47:44 -04002from framework import VppTestCase
3from ipaddress import IPv4Address
Paul Atkins0352ea02021-09-23 10:43:44 +01004
5
6class TestIpfixExporter(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02007 """Ipfix Exporter Tests"""
Paul Atkins0352ea02021-09-23 10:43:44 +01008
9 def setUp(self):
10 super(TestIpfixExporter, self).setUp()
11 self.create_pg_interfaces(range(4))
12 for i in self.pg_interfaces:
13 i.admin_up()
14 i.config_ip4()
15 i.resolve_arp()
16 i.config_ip6()
17 i.resolve_ndp()
18 i.disable_ipv6_ra()
19
20 def tearDown(self):
21 super(TestIpfixExporter, self).tearDown()
22 for i in self.pg_interfaces:
23 i.unconfig_ip4()
24 i.unconfig_ip6()
25 i.admin_down()
26
27 def find_exp_by_collector_addr(self, exporters, addr):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 """Find the exporter in the list of exportes with the given addr"""
Paul Atkins0352ea02021-09-23 10:43:44 +010029
30 for exp in exporters:
31 if exp.collector_address == IPv4Address(addr):
32 return exp
33 return None
34
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 def verify_exporter_detail(
36 self, exp, collector_addr, src_addr, collector_port=4739, mtu=1400, interval=20
37 ):
Paul Atkins0352ea02021-09-23 10:43:44 +010038 self.assertTrue(exp is not None)
39 self.assert_equal(exp.collector_address, collector_addr)
40 self.assert_equal(exp.src_address, src_addr)
41 self.assert_equal(exp.collector_port, collector_port)
42 self.assert_equal(exp.path_mtu, mtu)
43 self.assert_equal(exp.template_interval, interval)
44
45 def test_create_multipe_exporters(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020046 """test that we can create and dump multiple exporters"""
Paul Atkins0352ea02021-09-23 10:43:44 +010047
48 mtu = 1400
49 interval = 20
50 port = 4739
51
52 # Old API - always gives us pool index 0.
53 self.vapi.set_ipfix_exporter(
54 collector_address=self.pg1.remote_ip4,
55 src_address=self.pg0.local_ip4,
56 collector_port=4739,
57 path_mtu=mtu,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020058 template_interval=interval,
59 )
Paul Atkins0352ea02021-09-23 10:43:44 +010060
61 exporters = self.vapi.ipfix_exporter_dump()
62 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020063 self.verify_exporter_detail(
64 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
65 )
Paul Atkins0352ea02021-09-23 10:43:44 +010066
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020067 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +010068 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020069 self.verify_exporter_detail(
70 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
71 )
Paul Atkins0352ea02021-09-23 10:43:44 +010072
73 # create a 2nd exporter
74 self.vapi.ipfix_exporter_create_delete(
75 collector_address=self.pg2.remote_ip4,
76 src_address=self.pg0.local_ip4,
77 collector_port=4739,
78 path_mtu=mtu,
79 template_interval=interval,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020080 is_create=True,
81 )
Paul Atkins0352ea02021-09-23 10:43:44 +010082
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020083 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +010084 self.assertTrue(len(exporters) == 2)
85 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020086 self.verify_exporter_detail(
87 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
88 )
Paul Atkins0352ea02021-09-23 10:43:44 +010089 exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020090 self.verify_exporter_detail(
91 exp, IPv4Address(self.pg2.remote_ip4), IPv4Address(self.pg0.local_ip4)
92 )
Paul Atkins0352ea02021-09-23 10:43:44 +010093
94 # Create a 3rd exporter
95 self.vapi.ipfix_exporter_create_delete(
96 collector_address=self.pg3.remote_ip4,
97 src_address=self.pg0.local_ip4,
98 collector_port=4739,
99 path_mtu=mtu,
100 template_interval=interval,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200101 is_create=True,
102 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100103
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200104 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +0100105 self.assertTrue(len(exporters) == 3)
106 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200107 self.verify_exporter_detail(
108 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
109 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100110 exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200111 self.verify_exporter_detail(
112 exp, IPv4Address(self.pg2.remote_ip4), IPv4Address(self.pg0.local_ip4)
113 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100114 exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200115 self.verify_exporter_detail(
116 exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
117 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100118
119 # Modify the 2nd exporter.
120 self.vapi.ipfix_exporter_create_delete(
121 collector_address=self.pg2.remote_ip4,
122 src_address=self.pg0.local_ip4,
123 collector_port=4739,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200124 path_mtu=mtu + 1,
125 template_interval=interval + 1,
126 is_create=True,
127 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100128
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200129 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +0100130 self.assertTrue(len(exporters) == 3)
131 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200132 self.verify_exporter_detail(
133 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
134 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100135 exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200136 self.verify_exporter_detail(
137 exp,
138 IPv4Address(self.pg2.remote_ip4),
139 IPv4Address(self.pg0.local_ip4),
140 mtu=mtu + 1,
141 interval=interval + 1,
142 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100143 exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200144 self.verify_exporter_detail(
145 exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
146 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100147
148 # Delete 2nd exporter
149 self.vapi.ipfix_exporter_create_delete(
150 collector_address=self.pg2.remote_ip4,
151 src_address=self.pg0.local_ip4,
152 collector_port=4739,
153 path_mtu=mtu,
154 template_interval=interval,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200155 is_create=False,
156 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100157
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200158 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +0100159 self.assertTrue(len(exporters) == 2)
160 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200161 self.verify_exporter_detail(
162 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
163 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100164 exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200165 self.verify_exporter_detail(
166 exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
167 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100168
169 # Delete final exporter (exporter in slot 0 can not be deleted)
170 self.vapi.ipfix_exporter_create_delete(
171 collector_address=self.pg3.remote_ip4,
172 src_address=self.pg0.local_ip4,
173 collector_port=4739,
174 path_mtu=mtu,
175 template_interval=interval,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200176 is_create=False,
177 )
Paul Atkins0352ea02021-09-23 10:43:44 +0100178
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200179 exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
Paul Atkins0352ea02021-09-23 10:43:44 +0100180 self.assertTrue(len(exporters) == 1)
181 exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200182 self.verify_exporter_detail(
183 exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
184 )