summaryrefslogtreecommitdiffstats
path: root/test/vpp_bier.py
blob: 8e27f25d10fcfcf7c424fc55736b9d93007f0791 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
"""
  BIER Tables and Routes
"""

import socket
from vpp_object import VppObject
from vpp_ip_route import MPLS_LABEL_INVALID, VppRoutePath, VppMplsLabel


class BIER_HDR_PAYLOAD:
    BIER_HDR_PROTO_MPLS_DOWN_STREAM = 1
    BIER_HDR_PROTO_MPLS_UP_STREAM = 2
    BIER_HDR_PROTO_ETHERNET = 3
    BIER_HDR_PROTO_IPV4 = 4
    BIER_HDR_PROTO_IPV6 = 5
    BIER_HDR_PROTO_VXLAN = 6
    BIER_HDR_PROTO_CTRL = 7
    BIER_HDR_PROTO_OAM = 8


class VppBierTableID():
    def __init__(self, sub_domain_id, set_id, hdr_len_id):
        self.set_id = set_id
        self.sub_domain_id = sub_domain_id
        self.hdr_len_id = hdr_len_id


def find_bier_table(test, bti):
    tables = test.vapi.bier_table_dump()
    for t in tables:
        if bti.set_id == t.bt_tbl_id.bt_set \
           and bti.sub_domain_id == t.bt_tbl_id.bt_sub_domain \
           and bti.hdr_len_id == t.bt_tbl_id.bt_hdr_len_id:
            return True
    return False


def find_bier_route(test, bti, bp):
    routes = test.vapi.bier_route_dump(bti)
    for r in routes:
        if bti.set_id == r.br_tbl_id.bt_set \
           and bti.sub_domain_id == r.br_tbl_id.bt_sub_domain \
           and bti.hdr_len_id == r.br_tbl_id.bt_hdr_len_id \
           and bp == r.br_bp:
            return True
    return False


def find_bier_disp_table(test, bdti):
    tables = test.vapi.bier_disp_table_dump()
    for t in tables:
        if bdti == t.bdt_tbl_id:
            return True
    return False


def find_bier_disp_entry(test, bdti, bp):
    entries = test.vapi.bier_disp_entry_dump(bdti)
    for e in entries:
        if bp == e.bde_bp \
           and bdti == e.bde_tbl_id:
            return True
    return False


def find_bier_imp(test, bti, bp):
    imps = test.vapi.bier_imp_dump()
    for i in imps:
        if bti.set_id == i.bi_tbl_id.bt_set \
           and bti.sub_domain_id == i.bi_tbl_id.bt_sub_domain \
           and bti.hdr_len_id == i.bi_tbl_id.bt_hdr_len_id \
           and bp == i.bi_src:
            return True
    return False


class VppBierTable(VppObject):
    """
    BIER Table
    """

    def __init__(self, test, id, mpls_label):
        self._test = test
        self.id = id
        self.mpls_label = mpls_label

    def add_vpp_config(self):
        self._test.vapi.bier_table_add_del(
            self.id,
            self.mpls_label,
            is_add=1)
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self._test.vapi.bier_table_add_del(
            self.id,
            self.mpls_label,
            is_add=0)

    def object_id(self):
        return "bier-table;[%d:%d:%d]" % (self.id.set_id,
                                          self.id.sub_domain_id,
                                          self.id.hdr_len_id)

    def query_vpp_config(self):
        return find_bier_table(self._test, self.id)


class VppBierRoute(VppObject):
    """
    BIER route
    """

    def __init__(self, test, tbl_id, bp, paths):
        self._test = test
        self.tbl_id = tbl_id
        self.bp = bp
        self.paths = paths

    def encode_path(self, p):
        lstack = []
        for l in p.nh_labels:
            if type(l) == VppMplsLabel:
                lstack.append(l.encode())
            else:
                lstack.append({'label': l, 'ttl': 255})
        n_labels = len(lstack)
        while (len(lstack) < 16):
            lstack.append({})
        return {'next_hop': p.nh_addr,
                'weight': 1,
                'afi': p.proto,
                'sw_if_index': 0xffffffff,
                'preference': 0,
                'table_id': p.nh_table_id,
                'next_hop_id': p.next_hop_id,
                'is_udp_encap': p.is_udp_encap,
                'n_labels': n_labels,
                'label_stack': lstack}

    def encode_paths(self):
        br_paths = []
        for p in self.paths:
            br_paths.append(self.encode_path(p))
        return br_paths

    def add_vpp_config(self):
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            self.encode_paths(),
            is_add=1)
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            self.encode_paths(),
            is_add=0)

    def update_paths(self, paths):
        self.paths = paths
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            self.encode_paths(),
            is_replace=1)

    def add_path(self, path):
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            [self.encode_path(path)],
            is_add=1,
            is_replace=0)
        self.paths.append(path)
        self._test.registry.register(self, self._test.logger)

    def remove_path(self, path):
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            [self.encode_path(path)],
            is_add=0,
            is_replace=0)
        self.paths.remove(path)

    def remove_all_paths(self):
        self._test.vapi.bier_route_add_del(
            self.tbl_id,
            self.bp,
            [],
            is_add=0,
            is_replace=1)
        self.paths = []

    def object_id(self):
        return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
                                             self.tbl_id.sub_domain_id,
                                             self.tbl_id.hdr_len_id,
                                             self.bp)

    def query_vpp_config(self):
        return find_bier_route(self._test, self.tbl_id, self.bp)


class VppBierImp(VppObject):
    """
    BIER route
    """

    def __init__(self, test, tbl_id, src, ibytes):
        self._test = test
        self.tbl_id = tbl_id
        self.ibytes = ibytes
        self.src = src

    def add_vpp_config(self):
        res = self._test.vapi.bier_imp_add(
            self.tbl_id,
            self.src,
            self.ibytes)
        self.bi_index = res.bi_index
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self._test.vapi.bier_imp_del(
            self.bi_index)

    def object_id(self):
        return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
                                           self.tbl_id.sub_domain_id,
                                           self.tbl_id.hdr_len_id,
                                           self.src)

    def query_vpp_config(self):
        return find_bier_imp(self._test, self.tbl_id, self.src)


class VppBierDispTable(VppObject):
    """
    BIER Disposition Table
    """

    def __init__(self, test, id):
        self._test = test
        self.id = id

    def add_vpp_config(self):
        self._test.vapi.bier_disp_table_add_del(
            self.id,
            is_add=1)
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self._test.vapi.bier_disp_table_add_del(
            self.id,
            is_add=0)

    def object_id(self):
        return "bier-disp-table;[%d]" % (self.id)

    def query_vpp_config(self):
        return find_bier_disp_table(self._test, self.id)


class VppBierDispEntry(VppObject):
    """
    BIER Disposition Entry
    """

    def __init__(self, test, tbl_id, bp, payload_proto, nh_proto,
                 nh, nh_tbl, rpf_id=~0):
        self._test = test
        self.tbl_id = tbl_id
        self.nh_tbl = nh_tbl
        self.nh_proto = nh_proto
        self.bp = bp
        self.payload_proto = payload_proto
        self.rpf_id = rpf_id
        self.nh = socket.inet_pton(socket.AF_INET, nh)

    def add_vpp_config(self):
        self._test.vapi.bier_disp_entry_add_del(
            self.tbl_id,
            self.bp,
            self.payload_proto,
            self.nh_proto,
            self.nh,
            self.nh_tbl,
            self.rpf_id,
            is_add=1)
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        self._test.vapi.bier_disp_entry_add_del(
            self.tbl_id,
            self.bp,
            self.payload_proto,
            self.nh_proto,
            self.nh,
            self.nh_tbl,
            self.rpf_id,
            is_add=0)

    def object_id(self):
        return "bier-disp-entry;[%d:%d]" % (self.tbl_id,
                                            self.bp)

    def query_vpp_config(self):
        return find_bier_disp_entry(self._test, self.tbl_id, self.bp)
"cm">/* Check with invalid parameter */ if (rte_kni_unregister_handlers(NULL) == 0) { exit(-1); } /** * Handle the request of setting MTU, * without registered handlers. */ for (i = 0; i < TEST_KNI_HANDLE_REQ_COUNT; i++) { rte_kni_handle_request(kni); if (kni_pkt_mtu != 0) break; rte_delay_ms(TEST_KNI_HANDLE_REQ_INTERVAL); } if (kni_pkt_mtu != 0) { printf("MTU shouldn't be set\n"); exit(-1); } exit(0); } else { int p_ret, status; rte_delay_ms(1000); if (system(IFCONFIG TEST_KNI_PORT " mtu" TEST_KNI_MTU_STR) == -1) return -1; rte_delay_ms(1000); if (system(IFCONFIG TEST_KNI_PORT " mtu" TEST_KNI_MTU_STR) == -1) return -1; p_ret = wait(&status); if (!WIFEXITED(status)) { printf("Child process (%d) exit abnormally\n", p_ret); return -1; } if (WEXITSTATUS(status) != 0) { printf("Child process exit with failure\n"); return -1; } } return 0; } static int test_kni_processing(uint16_t port_id, struct rte_mempool *mp) { int ret = 0; unsigned i; struct rte_kni *kni; struct rte_kni_conf conf; struct rte_eth_dev_info info; struct rte_kni_ops ops; if (!mp) return -1; memset(&conf, 0, sizeof(conf)); memset(&info, 0, sizeof(info)); memset(&ops, 0, sizeof(ops)); rte_eth_dev_info_get(port_id, &info); conf.addr = info.pci_dev->addr; conf.id = info.pci_dev->id; snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT); /* core id 1 configured for kernel thread */ conf.core_id = 1; conf.force_bind = 1; conf.mbuf_size = MAX_PACKET_SZ; conf.group_id = port_id; ops = kni_ops; ops.port_id = port_id; /* basic test of kni processing */ kni = rte_kni_alloc(mp, &conf, &ops); if (!kni) { printf("fail to create kni\n"); return -1; } test_kni_ctx = kni; test_kni_processing_flag = 0; stats.ingress = 0; stats.egress = 0; /** * Check multiple processes support on * registerring/unregisterring handlers. */ if (test_kni_register_handler_mp() < 0) { printf("fail to check multiple process support\n"); ret = -1; goto fail_kni; } rte_eal_mp_remote_launch(test_kni_loop, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(i) { if (rte_eal_wait_lcore(i) < 0) { ret = -1; goto fail_kni; } } /** * Check if the number of mbufs received from kernel space is equal * to that of transmitted to kernel space */ if (stats.ingress < KNI_NUM_MBUF_THRESHOLD || stats.egress < KNI_NUM_MBUF_THRESHOLD) { printf("The ingress/egress number should not be " "less than %u\n", (unsigned)KNI_NUM_MBUF_THRESHOLD); ret = -1; goto fail_kni; } if (rte_kni_release(kni) < 0) { printf("fail to release kni\n"); return -1; } test_kni_ctx = NULL; /* test of releasing a released kni device */ if (rte_kni_release(kni) == 0) { printf("should not release a released kni device\n"); return -1; } /* test of reusing memzone */ kni = rte_kni_alloc(mp, &conf, &ops); if (!kni) { printf("fail to create kni\n"); return -1; } /* Release the kni for following testing */ if (rte_kni_release(kni) < 0) { printf("fail to release kni\n"); return -1; } return ret; fail_kni: if (rte_kni_release(kni) < 0) { printf("fail to release kni\n"); ret = -1; } return ret; } static int test_kni(void) { int ret = -1; uint16_t nb_ports, port_id; struct rte_kni *kni; struct rte_mempool *mp; struct rte_kni_conf conf; struct rte_eth_dev_info info; struct rte_kni_ops ops; /* Initialize KNI subsytem */ rte_kni_init(KNI_TEST_MAX_PORTS); if (test_kni_allocate_lcores() < 0) { printf("No enough lcores for kni processing\n"); return -1; } mp = test_kni_create_mempool(); if (!mp) { printf("fail to create mempool for kni\n"); return -1; } nb_ports = rte_eth_dev_count(); if (nb_ports == 0) { printf("no supported nic port found\n"); return -1; } /* configuring port 0 for the test is enough */ port_id = 0; ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); if (ret < 0) { printf("fail to configure port %d\n", port_id); return -1; } ret = rte_eth_rx_queue_setup(port_id, 0, NB_RXD, SOCKET, &rx_conf, mp); if (ret < 0) { printf("fail to setup rx queue for port %d\n", port_id); return -1; } ret = rte_eth_tx_queue_setup(port_id, 0, NB_TXD, SOCKET, &tx_conf); if (ret < 0) { printf("fail to setup tx queue for port %d\n", port_id); return -1; } ret = rte_eth_dev_start(port_id); if (ret < 0) { printf("fail to start port %d\n", port_id); return -1; } rte_eth_promiscuous_enable(port_id); /* basic test of kni processing */ ret = test_kni_processing(port_id, mp); if (ret < 0) goto fail; /* test of allocating KNI with NULL mempool pointer */ memset(&info, 0, sizeof(info)); memset(&conf, 0, sizeof(conf)); memset(&ops, 0, sizeof(ops)); rte_eth_dev_info_get(port_id, &info); conf.addr = info.pci_dev->addr; conf.id = info.pci_dev->id; conf.group_id = port_id; conf.mbuf_size = MAX_PACKET_SZ; ops = kni_ops; ops.port_id = port_id; kni = rte_kni_alloc(NULL, &conf, &ops); if (kni) { ret = -1; printf("unexpectedly creates kni successfully with NULL " "mempool pointer\n"); goto fail; } /* test of allocating KNI without configurations */ kni = rte_kni_alloc(mp, NULL, NULL); if (kni) { ret = -1; printf("Unexpectedly allocate KNI device successfully " "without configurations\n"); goto fail; } /* test of allocating KNI without a name */ memset(&conf, 0, sizeof(conf)); memset(&info, 0, sizeof(info)); memset(&ops, 0, sizeof(ops)); rte_eth_dev_info_get(port_id, &info); conf.addr = info.pci_dev->addr; conf.id = info.pci_dev->id; conf.group_id = port_id; conf.mbuf_size = MAX_PACKET_SZ; ops = kni_ops; ops.port_id = port_id; kni = rte_kni_alloc(mp, &conf, &ops); if (kni) { ret = -1; printf("Unexpectedly allocate a KNI device successfully " "without a name\n"); goto fail; } /* test of releasing NULL kni context */ ret = rte_kni_release(NULL); if (ret == 0) { ret = -1; printf("unexpectedly release kni successfully\n"); goto fail; } /* test of handling request on NULL device pointer */ ret = rte_kni_handle_request(NULL); if (ret == 0) { ret = -1; printf("Unexpectedly handle request on NULL device pointer\n"); goto fail; } /* test of getting KNI device with pointer to NULL */ kni = rte_kni_get(NULL); if (kni) { ret = -1; printf("Unexpectedly get a KNI device with " "NULL name pointer\n"); goto fail; } /* test of getting KNI device with an zero length name string */ memset(&conf, 0, sizeof(conf)); kni = rte_kni_get(conf.name); if (kni) { ret = -1; printf("Unexpectedly get a KNI device with " "zero length name string\n"); goto fail; } /* test of getting KNI device with an invalid string name */ memset(&conf, 0, sizeof(conf)); snprintf(conf.name, sizeof(conf.name), "testing"); kni = rte_kni_get(conf.name); if (kni) { ret = -1; printf("Unexpectedly get a KNI device with " "a never used name string\n"); goto fail; } ret = 0; fail: rte_eth_dev_stop(port_id); return ret; } REGISTER_TEST_COMMAND(kni_autotest, test_kni);