summaryrefslogtreecommitdiffstats
path: root/test/test_ipfix_export.py
blob: 7cdc14033304c4a86ac49144334c70a2085c3fe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
from framework import VppTestCase
from ipaddress import IPv4Address


class TestIpfixExporter(VppTestCase):
    """Ipfix Exporter Tests"""

    def setUp(self):
        super(TestIpfixExporter, self).setUp()
        self.create_pg_interfaces(range(4))
        for i in self.pg_interfaces:
            i.admin_up()
            i.config_ip4()
            i.resolve_arp()
            i.config_ip6()
            i.resolve_ndp()
            i.disable_ipv6_ra()

    def tearDown(self):
        super(TestIpfixExporter, self).tearDown()
        for i in self.pg_interfaces:
            i.unconfig_ip4()
            i.unconfig_ip6()
            i.admin_down()

    def find_exp_by_collector_addr(self, exporters, addr):
        """Find the exporter in the list of exportes with the given  addr"""

        for exp in exporters:
            if exp.collector_address == IPv4Address(addr):
                return exp
        return None

    def verify_exporter_detail(
        self, exp, collector_addr, src_addr, collector_port=4739, mtu=1400, interval=20
    ):
        self.assertTrue(exp is not None)
        self.assert_equal(exp.collector_address, collector_addr)
        self.assert_equal(exp.src_address, src_addr)
        self.assert_equal(exp.collector_port, collector_port)
        self.assert_equal(exp.path_mtu, mtu)
        self.assert_equal(exp.template_interval, interval)

    def test_create_multipe_exporters(self):
        """test that we can create and dump multiple exporters"""

        mtu = 1400
        interval = 20
        port = 4739

        # Old API - always gives us pool index 0.
        self.vapi.set_ipfix_exporter(
            collector_address=self.pg1.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu,
            template_interval=interval,
        )

        exporters = self.vapi.ipfix_exporter_dump()
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        # create a 2nd exporter
        self.vapi.ipfix_exporter_create_delete(
            collector_address=self.pg2.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu,
            template_interval=interval,
            is_create=True,
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        self.assertTrue(len(exporters) == 2)
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg2.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        # Create a 3rd exporter
        self.vapi.ipfix_exporter_create_delete(
            collector_address=self.pg3.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu,
            template_interval=interval,
            is_create=True,
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        self.assertTrue(len(exporters) == 3)
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg2.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        # Modify the 2nd exporter.
        self.vapi.ipfix_exporter_create_delete(
            collector_address=self.pg2.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu + 1,
            template_interval=interval + 1,
            is_create=True,
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        self.assertTrue(len(exporters) == 3)
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg2.remote_ip4)
        self.verify_exporter_detail(
            exp,
            IPv4Address(self.pg2.remote_ip4),
            IPv4Address(self.pg0.local_ip4),
            mtu=mtu + 1,
            interval=interval + 1,
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        # Delete 2nd exporter
        self.vapi.ipfix_exporter_create_delete(
            collector_address=self.pg2.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu,
            template_interval=interval,
            is_create=False,
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        self.assertTrue(len(exporters) == 2)
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )
        exp = self.find_exp_by_collector_addr(exporters, self.pg3.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg3.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )

        # Delete final exporter (exporter in slot 0 can not be deleted)
        self.vapi.ipfix_exporter_create_delete(
            collector_address=self.pg3.remote_ip4,
            src_address=self.pg0.local_ip4,
            collector_port=4739,
            path_mtu=mtu,
            template_interval=interval,
            is_create=False,
        )

        exporters = list(self.vapi.vpp.details_iter(self.vapi.ipfix_all_exporter_get))
        self.assertTrue(len(exporters) == 1)
        exp = self.find_exp_by_collector_addr(exporters, self.pg1.remote_ip4)
        self.verify_exporter_detail(
            exp, IPv4Address(self.pg1.remote_ip4), IPv4Address(self.pg0.local_ip4)
        )