aboutsummaryrefslogtreecommitdiffstats
path: root/test/vpp_ipsec.py
blob: f50d491c3964c283ed0b628a5f09f0a372c9f4b7 (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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
from vpp_object import VppObject
from ipaddress import ip_address
from vpp_papi import VppEnum
from vpp_interface import VppInterface

try:
    text_type = unicode
except NameError:
    text_type = str


def mk_counter():
    return {"packets": 0, "bytes": 0}


class VppIpsecSpd(VppObject):
    """
    VPP SPD DB
    """

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

    def add_vpp_config(self):
        self.test.vapi.ipsec_spd_add_del(self.id)
        self.test.registry.register(self, self.test.logger)

    def remove_vpp_config(self):
        self.test.vapi.ipsec_spd_add_del(self.id, is_add=0)

    def object_id(self):
        return "ipsec-spd-%d" % self.id

    def query_vpp_config(self):
        spds = self.test.vapi.ipsec_spds_dump()
        for spd in spds:
            if spd.spd_id == self.id:
                return True
        return False


class VppIpsecSpdItfBinding(VppObject):
    """
    VPP SPD DB to interface binding
    (i.e. this SPD is used on this interface)
    """

    def __init__(self, test, spd, itf):
        self.test = test
        self.spd = spd
        self.itf = itf

    def add_vpp_config(self):
        self.test.vapi.ipsec_interface_add_del_spd(self.spd.id, self.itf.sw_if_index)
        self.test.registry.register(self, self.test.logger)

    def remove_vpp_config(self):
        self.test.vapi.ipsec_interface_add_del_spd(
            self.spd.id, self.itf.sw_if_index, is_add=0
        )

    def object_id(self):
        return "bind-%s-to-%s" % (self.spd.id, self.itf)

    def query_vpp_config(self):
        bs = self.test.vapi.ipsec_spd_interface_dump()
        for b in bs:
            if b.sw_if_index == self.itf.sw_if_index:
                return True
        return False


class VppIpsecSpdEntry(VppObject):
    """
    VPP SPD DB Entry
    """

    def __init__(
        self,
        test,
        spd,
        sa_id,
        local_start,
        local_stop,
        remote_start,
        remote_stop,
        proto=socket.IPPROTO_RAW,
        priority=100,
        policy=None,
        is_outbound=1,
        remote_port_start=0,
        remote_port_stop=65535,
        local_port_start=0,
        local_port_stop=65535,
    ):
        self.test = test
        self.spd = spd
        self.sa_id = sa_id
        self.local_start = ip_address(text_type(local_start))
        self.local_stop = ip_address(text_type(local_stop))
        self.remote_start = ip_address(text_type(remote_start))
        self.remote_stop = ip_address(text_type(remote_stop))
        self.proto = proto
        self.is_outbound = is_outbound
        self.priority = priority
        if not policy:
            self.policy = VppEnum.vl_api_ipsec_spd_action_t.IPSEC_API_SPD_ACTION_BYPASS
        else:
            self.policy = policy
        self.is_ipv6 = 0 if self.local_start.version == 4 else 1
        self.local_port_start = local_port_start
        self.local_port_stop = local_port_stop
        self.remote_port_start = remote_port_start
        self.remote_port_stop = remote_port_stop

    def add_vpp_config(self):
        rv = self.test.vapi.ipsec_spd_entry_add_del(
            self.spd.id,
            self.sa_id,
            self.local_start,
            self.local_stop,
            self.remote_start,
            self.remote_stop,
            protocol=self.proto,
            is_ipv6=self.is_ipv6,
            is_outbound=self.is_outbound,
            priority=self.priority,
            policy=self.policy,
            local_port_start=self.local_port_start,
            local_port_stop=self.local_port_stop,
            remote_port_start=self.remote_port_start,
            remote_port_stop=self.remote_port_stop,
        )
        self.stat_index = rv.stat_index
        self.test.registry.register(self, self.test.logger)
        return self

    def remove_vpp_config(self):
        self.test.vapi.ipsec_spd_entry_add_del(
            self.spd.id,
            self.sa_id,
            self.local_start,
            self.local_stop,
            self.remote_start,
            self.remote_stop,
            protocol=self.proto,
            is_ipv6=self.is_ipv6,
            is_outbound=self.is_outbound,
            priority=self.priority,
            policy=self.policy,
            local_port_start=self.local_port_start,
            local_port_stop=self.local_port_stop,
            remote_port_start=self.remote_port_start,
            remote_port_stop=self.remote_port_stop,
            is_add=0,
        )

    def object_id(self):
        return "spd-entry-%d-%d-%d-%d-%d-%d" % (
            self.spd.id,
            self.priority,
            self.policy,
            self.is_outbound,
            self.is_ipv6,
            self.remote_port_start,
        )

    def query_vpp_config(self):
        ss = self.test.vapi.ipsec_spd_dump(self.spd.id)
        for s in ss:
            if (
                s.entry.sa_id == self.sa_id
                and s.entry.is_outbound == self.is_outbound
                and s.entry.priority == self.priority
                and s.entry.policy == self.policy
                and s.entry.remote_address_start == self.remote_start
                and s.entry.remote_port_start == self.remote_port_start
            ):
                return True
        return False

    def get_stats(self, worker=None):
        c = self.test.statistics.get_counter("/net/ipsec/policy")
        if worker is None:
            total = mk_counter()
            for t in c:
                total["packets"] += t[self.stat_index]["packets"]
            return total
        else:
            # +1 to skip main thread
            return c[worker + 1][self.stat_index]


class VppIpsecSA(VppObject):
    """
    VPP SAD Entry
    """

    DEFAULT_UDP_PORT = 4500

    def __init__(
        self,
        test,
        id,
        spi,
        integ_alg,
        integ_key,
        crypto_alg,
        crypto_key,
        proto,
        tun_src=None,
        tun_dst=None,
        flags=None,
        salt=0,
        tun_flags=None,
        dscp=None,
        udp_src=None,
        udp_dst=None,
        hop_limit=None,
    ):
        e = VppEnum.vl_api_ipsec_sad_flags_t
        self.test = test
        self.id = id
        self.spi = spi
        self.integ_alg = integ_alg
        self.integ_key = integ_key
        self.crypto_alg = crypto_alg
        self.crypto_key = crypto_key
        self.proto = proto
        self.salt = salt

        self.table_id = 0
        self.tun_src = tun_src
        self.tun_dst = tun_dst
        if not flags:
            self.flags = e.IPSEC_API_SAD_FLAG_NONE
        else:
            self.flags = flags
        if tun_src:
            self.tun_src = ip_address(text_type(tun_src))
            self.flags = self.flags | e.IPSEC_API_SAD_FLAG_IS_TUNNEL
        if tun_dst:
            self.tun_dst = ip_address(text_type(tun_dst))
        self.udp_src = udp_src
        self.udp_dst = udp_dst
        self.tun_flags = (
            VppEnum.vl_api_tunnel_encap_decap_flags_t.TUNNEL_API_ENCAP_DECAP_FLAG_NONE
        )
        if tun_flags:
            self.tun_flags = tun_flags
        self.dscp = VppEnum.vl_api_ip_dscp_t.IP_API_DSCP_CS0
        if dscp:
            self.dscp = dscp
        self.hop_limit = 255
        if hop_limit:
            self.hop_limit = hop_limit

    def tunnel_encode(self):
        return {
            "src": (self.tun_src if self.tun_src else []),
            "dst": (self.tun_dst if self.tun_dst else []),
            "encap_decap_flags": self.tun_flags,
            "dscp": self.dscp,
            "hop_limit": self.hop_limit,
            "table_id": self.table_id,
        }

    def add_vpp_config(self):
        entry = {
            "sad_id": self.id,
            "spi": self.spi,
            "integrity_algorithm": self.integ_alg,
            "integrity_key": {
                "length": len(self.integ_key),
                "data": self.integ_key,
            },
            "crypto_algorithm": self.crypto_alg,
            "crypto_key": {
                "data": self.crypto_key,
                "length": len(self.crypto_key),
            },
            "protocol": self.proto,
            "tunnel": self.tunnel_encode(),
            "flags": self.flags,
            "salt": self.salt,
        }
        # don't explicitly send the defaults, let papi fill them in
        if self.udp_src:
            entry["udp_src_port"] = self.udp_src
        if self.udp_dst:
            entry["udp_dst_port"] = self.udp_dst
        r = self.test.vapi.ipsec_sad_entry_add(entry=entry)
        self.stat_index = r.stat_index
        self.test.registry.register(self, self.test.logger)
        return self

    def update_vpp_config(
        self, udp_src=None, udp_dst=None, is_tun=False, tun_src=None, tun_dst=None
    ):
        if is_tun:
            if tun_src:
                self.tun_src = ip_address(text_type(tun_src))
            if tun_dst:
                self.tun_dst = ip_address(text_type(tun_dst))
        if udp_src:
            self.udp_src = udp_src
        if udp_dst:
            self.udp_dst = udp_dst
        self.test.vapi.ipsec_sad_entry_update(
            sad_id=self.id,
            is_tun=is_tun,
            tunnel=self.tunnel_encode(),
            udp_src_port=udp_src,
            udp_dst_port=udp_dst,
        )

    def remove_vpp_config(self):
        self.test.vapi.ipsec_sad_entry_del(id=self.id)

    def object_id(self):
        return "ipsec-sa-%d" % self.id

    def query_vpp_config(self):
        e = VppEnum.vl_api_ipsec_sad_flags_t

        bs = self.test.vapi.ipsec_sa_v3_dump()
        for b in bs:
            if b.entry.sad_id == self.id:
                # if udp encap is configured then the ports should match
                # those configured or the default
                if self.flags & e.IPSEC_API_SAD_FLAG_UDP_ENCAP:
                    if not b.entry.flags & e.IPSEC_API_SAD_FLAG_UDP_ENCAP:
                        return False
                    if self.udp_src:
                        if self.udp_src != b.entry.udp_src_port:
                            return False
                    else:
                        if self.DEFAULT_UDP_PORT != b.entry.udp_src_port:
                            return False
                    if self.udp_dst:
                        if self.udp_dst != b.entry.udp_dst_port:
                            return False
                    else:
                        if self.DEFAULT_UDP_PORT != b.entry.udp_dst_port:
                            return False
                return True
        return False

    def get_stats(self, worker=None):
        c = self.test.statistics.get_counter("/net/ipsec/sa")
        if worker is None:
            total = mk_counter()
            for t in c:
                total["packets"] += t[self.stat_index]["packets"]
            return total
        else:
            # +1 to skip main thread
            return c[worker + 1][self.stat_index]

    def get_lost(self, worker=None):
        c = self.test.statistics.get_counter("/net/ipsec/sa/lost")
        if worker is None:
            total = 0
            for t in c:
                total += t[self.stat_index]
            return total
        else:
            # +1 to skip main thread
            return c[worker + 1][self.stat_index]


class VppIpsecTunProtect(VppObject):
    """
    VPP IPSEC tunnel protection
    """

    def __init__(self, test, itf, sa_out, sas_in, nh=None):
        self.test = test
        self.itf = itf
        self.sas_in = []
        for sa in sas_in:
            self.sas_in.append(sa.id)
        self.sa_out = sa_out.id
        self.nh = nh
        if not self.nh:
            self.nh = "0.0.0.0"

    def update_vpp_config(self, sa_out, sas_in):
        self.sas_in = []
        for sa in sas_in:
            self.sas_in.append(sa.id)
        self.sa_out = sa_out.id
        self.test.vapi.ipsec_tunnel_protect_update(
            tunnel={
                "sw_if_index": self.itf._sw_if_index,
                "n_sa_in": len(self.sas_in),
                "sa_out": self.sa_out,
                "sa_in": self.sas_in,
                "nh": self.nh,
            }
        )

    def object_id(self):
        return "ipsec-tun-protect-%s-%s" % (self.itf, self.nh)

    def add_vpp_config(self):
        self.test.vapi.ipsec_tunnel_protect_update(
            tunnel={
                "sw_if_index": self.itf._sw_if_index,
                "n_sa_in": len(self.sas_in),
                "sa_out": self.sa_out,
                "sa_in": self.sas_in,
                "nh": self.nh,
            }
        )
        self.test.registry.register(self, self.test.logger)

    def remove_vpp_config(self):
        self.test.vapi.ipsec_tunnel_protect_del(
            sw_if_index=self.itf.sw_if_index, nh=self.nh
        )

    def query_vpp_config(self):
        bs = self.test.vapi.ipsec_tunnel_protect_dump(sw_if_index=self.itf.sw_if_index)
        for b in bs:
            if b.tun.sw_if_index == self.itf.sw_if_index and self.nh == str(b.tun.nh):
                return True
        return False


class VppIpsecInterface(VppInterface):
    """
    VPP IPSec interface
    """

    def __init__(self, test, mode=None, instance=0xFFFFFFFF):
        super(VppIpsecInterface, self).__init__(test)

        self.mode = mode
        if not self.mode:
            self.mode = VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_P2P
        self.instance = instance

    def add_vpp_config(self):
        r = self.test.vapi.ipsec_itf_create(
            itf={
                "user_instance": self.instance,
                "mode": self.mode,
            }
        )
        self.set_sw_if_index(r.sw_if_index)
        self.test.registry.register(self, self.test.logger)
        ts = self.test.vapi.ipsec_itf_dump(sw_if_index=self._sw_if_index)
        self.instance = ts[0].itf.user_instance
        return self

    def remove_vpp_config(self):
        self.test.vapi.ipsec_itf_delete(sw_if_index=self._sw_if_index)

    def query_vpp_config(self):
        ts = self.test.vapi.ipsec_itf_dump(sw_if_index=0xFFFFFFFF)
        for t in ts:
            if t.itf.sw_if_index == self._sw_if_index:
                return True
        return False

    def __str__(self):
        return self.object_id()

    def object_id(self):
        return "ipsec%d" % self.instance
n> fei, u32 sw_if_index, mfib_itf_flags_t flags) { const mfib_entry_t *mfe; const mfib_itf_t *mfi; mfib_prefix_t pfx; int res; res = 0; mfe = mfib_entry_get(fei); mfi = mfib_entry_get_itf(mfe, sw_if_index); mfib_entry_get_prefix(fei, &pfx); MFIB_TEST_REP((NULL != mfi), "%U has interface %d", format_mfib_prefix, &pfx, sw_if_index); MFIB_TEST_REP((flags == mfi->mfi_flags), "%U interface %d has flags %U expect %U", format_mfib_prefix, &pfx, sw_if_index, format_mfib_itf_flags, flags, format_mfib_itf_flags, mfi->mfi_flags); return (res); } static int mfib_test_entry_no_itf (fib_node_index_t fei, u32 sw_if_index) { const mfib_entry_t *mfe; const mfib_itf_t *mfi; mfib_prefix_t pfx; int res; res = 0; mfe = mfib_entry_get(fei); mfi = mfib_entry_get_itf(mfe, sw_if_index); mfib_entry_get_prefix(fei, &pfx); MFIB_TEST_REP((NULL == mfi), "%U has no interface %d", format_mfib_prefix, &pfx, sw_if_index); return (res); } static int mfib_test_i (fib_protocol_t PROTO, vnet_link_t LINKT, const mfib_prefix_t *pfx_no_forward, const mfib_prefix_t *pfx_s_g, const mfib_prefix_t *pfx_star_g_1, const mfib_prefix_t *pfx_star_g_2, const mfib_prefix_t *pfx_star_g_3, const mfib_prefix_t *pfx_star_g_slash_m, const fib_prefix_t *pfx_itf, const ip46_address_t *addr_nbr1, const ip46_address_t *addr_nbr2) { fib_node_index_t mfei, mfei_dflt, mfei_no_f, mfei_s_g, mfei_g_1, mfei_g_2, mfei_g_3, mfei_g_m; u32 fib_index, n_entries, n_itfs, n_reps, n_pls; fib_node_index_t ai_1, ai_2, ai_3, ai_nbr1, ai_nbr2; test_main_t *tm; int res; mfib_prefix_t all_1s; memset(&all_1s, 0xfd, sizeof(all_1s)); res = 0; n_entries = pool_elts(mfib_entry_pool); n_itfs = pool_elts(mfib_itf_pool); n_reps = pool_elts(replicate_pool); n_pls = fib_path_list_pool_size(); tm = &test_main; ai_1 = adj_mcast_add_or_lock(PROTO, LINKT, tm->hw[1]->sw_if_index); ai_2 = adj_mcast_add_or_lock(PROTO, LINKT, tm->hw[2]->sw_if_index); ai_3 = adj_mcast_add_or_lock(PROTO, LINKT, tm->hw[3]->sw_if_index); ai_nbr1 = adj_nbr_add_or_lock(PROTO, LINKT, addr_nbr1, tm->hw[0]->sw_if_index); ai_nbr2 = adj_nbr_add_or_lock(PROTO, LINKT, addr_nbr2, tm->hw[0]->sw_if_index); MFIB_TEST(3 == adj_mcast_db_size(), "3 MCAST adjs"); /* Find or create FIB table 11 */ fib_index = mfib_table_find_or_create_and_lock(PROTO, 11, MFIB_SOURCE_API); fib_table_entry_update_one_path(0, pfx_itf, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_ATTACHED), DPO_PROTO_IP4, NULL, tm->hw[0]->sw_if_index, ~0, // invalid fib index 1, // weight NULL, FIB_ROUTE_PATH_FLAG_NONE); mfib_prefix_t pfx_dft = { .fp_len = 0, .fp_proto = PROTO, }; mfei_dflt = mfib_table_lookup_exact_match(fib_index, &pfx_dft); MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet"); MFIB_TEST(!mfib_test_entry(mfei_dflt, MFIB_ENTRY_FLAG_DROP, 0), "(*,*) no replcaitions"); MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet"); MFIB_TEST(!mfib_test_entry(mfei_dflt, MFIB_ENTRY_FLAG_DROP, 0), "(*,*) no replcaitions"); fib_route_path_t path_via_if0 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = zero_addr, .frp_sw_if_index = tm->hw[0]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; mfib_table_entry_path_update(fib_index, pfx_no_forward, MFIB_SOURCE_API, &path_via_if0, MFIB_ITF_FLAG_ACCEPT); mfei_no_f = mfib_table_lookup_exact_match(fib_index, pfx_no_forward); MFIB_TEST(!mfib_test_entry(mfei_no_f, MFIB_ENTRY_FLAG_NONE, 0), "%U no replcaitions", format_mfib_prefix, pfx_no_forward); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_no_f, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); fib_route_path_t path_via_if1 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = zero_addr, .frp_sw_if_index = tm->hw[1]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; fib_route_path_t path_via_if2 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = zero_addr, .frp_sw_if_index = tm->hw[2]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; fib_route_path_t path_via_if3 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = zero_addr, .frp_sw_if_index = tm->hw[3]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; fib_route_path_t path_for_us = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = zero_addr, .frp_sw_if_index = 0xffffffff, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = FIB_ROUTE_PATH_LOCAL, }; /* * An (S,G) with 1 accepting and 3 forwarding paths */ mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if0, MFIB_ITF_FLAG_ACCEPT); mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if1, MFIB_ITF_FLAG_FORWARD); mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if2, MFIB_ITF_FLAG_FORWARD); mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if3, (MFIB_ITF_FLAG_FORWARD | MFIB_ITF_FLAG_NEGATE_SIGNAL)); mfei_s_g = mfib_table_lookup_exact_match(fib_index, pfx_s_g); MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_s_g, "%U present", format_mfib_prefix, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei_s_g, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate ok", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[1]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[3]->sw_if_index, (MFIB_ITF_FLAG_FORWARD | MFIB_ITF_FLAG_NEGATE_SIGNAL))); /* * A (*,G), which the same G as the (S,G). * different paths. test our LPM. */ mfei_g_1 = mfib_table_entry_path_update(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_if0, MFIB_ITF_FLAG_ACCEPT); mfib_table_entry_path_update(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_if1, MFIB_ITF_FLAG_FORWARD); /* * test we find the *,G and S,G via LPM and exact matches */ mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1); MFIB_TEST(mfei == mfei_g_1, "%U found via exact match", format_mfib_prefix, pfx_star_g_1); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_MCAST, ai_1), "%U replicate ok", format_mfib_prefix, pfx_star_g_1); mfei = mfib_table_lookup(fib_index, pfx_star_g_1); MFIB_TEST(mfei == mfei_g_1, "%U found via LP match", format_mfib_prefix, pfx_star_g_1); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_MCAST, ai_1), "%U replicate ok", format_mfib_prefix, pfx_star_g_1); mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g); MFIB_TEST(mfei == mfei_s_g, "%U found via exact match", format_mfib_prefix, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); mfei = mfib_table_lookup(fib_index, pfx_s_g); MFIB_TEST(mfei == mfei_s_g, "%U found via LP match", format_mfib_prefix, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); /* * A (*,G/m), which the same root G as the (*,G). * different paths. test our LPM. */ mfei_g_m = mfib_table_entry_path_update(fib_index, pfx_star_g_slash_m, MFIB_SOURCE_API, &path_via_if2, MFIB_ITF_FLAG_ACCEPT); mfib_table_entry_path_update(fib_index, pfx_star_g_slash_m, MFIB_SOURCE_API, &path_via_if3, MFIB_ITF_FLAG_FORWARD); /* * test we find the (*,G/m), (*,G) and (S,G) via LPM and exact matches */ mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1); MFIB_TEST((mfei_g_1 == mfei), "%U found via DP LPM: %d", format_mfib_prefix, pfx_star_g_1, mfei); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_MCAST, ai_1), "%U replicate ok", format_mfib_prefix, pfx_star_g_1); mfei = mfib_table_lookup(fib_index, pfx_star_g_1); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_MCAST, ai_1), "%U replicate ok", format_mfib_prefix, pfx_star_g_1); mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); mfei = mfib_table_lookup(fib_index, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m); MFIB_TEST(mfei = mfei_g_m, "%U Found via exact match", format_mfib_prefix, pfx_star_g_slash_m); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_star_g_slash_m); MFIB_TEST(mfei_g_m == mfib_table_lookup(fib_index, pfx_star_g_slash_m), "%U found via LPM", format_mfib_prefix, pfx_star_g_slash_m); /* * Add a for-us path */ mfei = mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_for_us, MFIB_ITF_FLAG_FORWARD); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 4, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3, DPO_RECEIVE, 0), "%U replicate OK", format_mfib_prefix, pfx_s_g); /* * remove a for-us path */ mfib_table_entry_path_remove(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_for_us); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); /* * update an existing forwarding path to be only accepting * - expect it to be removed from the replication set. */ mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if3, MFIB_ITF_FLAG_ACCEPT); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 2, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2), "%U replicate OK", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); /* * Make the path forwarding again * - expect it to be added back to the replication set */ mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if3, (MFIB_ITF_FLAG_FORWARD | MFIB_ITF_FLAG_ACCEPT | MFIB_ITF_FLAG_NEGATE_SIGNAL)); mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index, (MFIB_ITF_FLAG_FORWARD | MFIB_ITF_FLAG_ACCEPT | MFIB_ITF_FLAG_NEGATE_SIGNAL))); /* * update flags on the entry */ mfib_table_entry_update(fib_index, pfx_s_g, MFIB_SOURCE_API, MFIB_RPF_ID_NONE, MFIB_ENTRY_FLAG_SIGNAL); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_SIGNAL, 3, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2, DPO_ADJACENCY_MCAST, ai_3), "%U replicate OK", format_mfib_prefix, pfx_s_g); /* * remove paths */ mfib_table_entry_path_remove(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if3); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_SIGNAL, 2, DPO_ADJACENCY_MCAST, ai_1, DPO_ADJACENCY_MCAST, ai_2), "%U replicate OK", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index)); mfib_table_entry_path_remove(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if1); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_SIGNAL, 1, DPO_ADJACENCY_MCAST, ai_2), "%U replicate OK", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_ACCEPT)); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index)); /* * remove the accpeting only interface */ mfib_table_entry_path_remove(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if0); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_SIGNAL, 1, DPO_ADJACENCY_MCAST, ai_2), "%U replicate OK", format_mfib_prefix, pfx_s_g); MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[0]->sw_if_index)); MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[1]->sw_if_index)); MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index)); /* * remove the last path, the entry still has flags so it remains */ mfib_table_entry_path_remove(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_if2); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_SIGNAL, 0), "%U no replications", format_mfib_prefix, pfx_s_g); /* * update flags on the entry */ mfib_table_entry_update(fib_index, pfx_s_g, MFIB_SOURCE_API, MFIB_RPF_ID_NONE, (MFIB_ENTRY_FLAG_SIGNAL | MFIB_ENTRY_FLAG_CONNECTED)); MFIB_TEST(!mfib_test_entry(mfei, (MFIB_ENTRY_FLAG_SIGNAL | MFIB_ENTRY_FLAG_CONNECTED), 0), "%U no replications", format_mfib_prefix, pfx_s_g); /* * An entry with a NS interface */ mfei_g_2 = mfib_table_entry_path_update(fib_index, pfx_star_g_2, MFIB_SOURCE_API, &path_via_if0, (MFIB_ITF_FLAG_ACCEPT | MFIB_ITF_FLAG_NEGATE_SIGNAL)); MFIB_TEST(!mfib_test_entry(mfei_g_2, MFIB_ENTRY_FLAG_NONE, 0), "%U No replications", format_mfib_prefix, pfx_star_g_2); /* * Simulate a signal from the data-plane */ { mfib_entry_t *mfe; mfib_itf_t *mfi; mfe = mfib_entry_get(mfei_g_2); mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index); mfib_signal_push(mfe, mfi, NULL); } /* * An entry with a NS interface */ mfei_g_3 = mfib_table_entry_path_update(fib_index, pfx_star_g_3, MFIB_SOURCE_API, &path_via_if0, (MFIB_ITF_FLAG_ACCEPT | MFIB_ITF_NEGATE_SIGNAL)); MFIB_TEST(!mfib_test_entry(mfei_g_3, MFIB_ENTRY_FLAG_NONE, 0), "%U No replications", format_mfib_prefix, pfx_star_g_3); /* * Simulate a signal from the data-plane */ { mfib_entry_t *mfe; mfib_itf_t *mfi; mfe = mfib_entry_get(mfei_g_3); mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index); mfib_signal_push(mfe, mfi, NULL); } if (FIB_PROTOCOL_IP6 == PROTO) { /* * All the entries are present. let's ensure we can find them all * via exact and longest prefix matches. */ /* * A source address we will never match */ ip6_address_t src = { .as_u64[0] = clib_host_to_net_u64(0x3001000000000000), .as_u64[1] = clib_host_to_net_u64(0xffffffffffffffff), }; /* * Find the (*,G/m) */ MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2( ip6_mfib_get(fib_index), &src, &pfx_star_g_slash_m->fp_grp_addr.ip6)), "%U found via DP LPM grp=%U", format_mfib_prefix, pfx_star_g_slash_m, format_ip6_address, &pfx_star_g_slash_m->fp_grp_addr.ip6); ip6_address_t tmp = pfx_star_g_slash_m->fp_grp_addr.ip6; tmp.as_u8[15] = 0xff; MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2( ip6_mfib_get(fib_index), &pfx_s_g->fp_src_addr.ip6, &tmp)), "%U found via DP LPM grp=%U", format_mfib_prefix, pfx_star_g_slash_m, format_ip6_address, &tmp); /* * Find the (S,G). */ mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index), &pfx_s_g->fp_src_addr.ip6, &pfx_s_g->fp_grp_addr.ip6); MFIB_TEST((mfei_s_g == mfei), "%U found via DP LPM: %d", format_mfib_prefix, pfx_s_g, mfei); /* * Find the 3 (*,G) s */ mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index), &src, &pfx_star_g_1->fp_grp_addr.ip6); MFIB_TEST((mfei_g_1 == mfei), "%U found via DP LPM: %d", format_mfib_prefix, pfx_star_g_1, mfei); mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index), &src, &pfx_star_g_2->fp_grp_addr.ip6); MFIB_TEST((mfei_g_2 == mfei), "%U found via DP LPM: %d", format_mfib_prefix, pfx_star_g_2, mfei); mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index), &src, &pfx_star_g_3->fp_grp_addr.ip6); MFIB_TEST((mfei_g_3 == mfei), "%U found via DP LPM: %d", format_mfib_prefix, pfx_star_g_3, mfei); } /* * remove flags on the entry. This is the last of the * state associated with the entry, so now it goes. */ mfib_table_entry_update(fib_index, pfx_s_g, MFIB_SOURCE_API, MFIB_RPF_ID_NONE, MFIB_ENTRY_FLAG_NONE); mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U gone", format_mfib_prefix, pfx_s_g); /* * remove the last path on the no forward entry - the last entry */ mfib_table_entry_path_remove(fib_index, pfx_no_forward, MFIB_SOURCE_API, &path_via_if0); mfei = mfib_table_lookup_exact_match(fib_index, pfx_no_forward); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U gone", format_mfib_prefix, pfx_no_forward); /* * hard delete the (*,232.1.1.1) */ mfib_table_entry_delete(fib_index, pfx_star_g_1, MFIB_SOURCE_API); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U gone", format_mfib_prefix, pfx_star_g_1); /* * remove the entry whilst the signal is pending */ mfib_table_entry_delete(fib_index, pfx_star_g_2, MFIB_SOURCE_API); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_2); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U Gone", format_mfib_prefix, pfx_star_g_2); mfib_table_entry_delete(fib_index, pfx_star_g_3, MFIB_SOURCE_API); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_3); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U Gone", format_mfib_prefix, pfx_star_g_3); mfib_table_entry_delete(fib_index, pfx_star_g_slash_m, MFIB_SOURCE_API); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U Gone", format_mfib_prefix, pfx_star_g_slash_m); /* * Entries with paths via unicast next-hops */ fib_route_path_t path_via_nbr1 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = *addr_nbr1, .frp_sw_if_index = tm->hw[0]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; fib_route_path_t path_via_nbr2 = { .frp_proto = fib_proto_to_dpo(PROTO), .frp_addr = *addr_nbr2, .frp_sw_if_index = tm->hw[0]->sw_if_index, .frp_fib_index = ~0, .frp_weight = 0, .frp_flags = 0, }; mfei_g_1 = mfib_table_entry_path_update(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_nbr1, (MFIB_ITF_FLAG_FORWARD)); mfei_g_1 = mfib_table_entry_path_update(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_nbr2, (MFIB_ITF_FLAG_FORWARD)); MFIB_TEST(!mfib_test_entry(mfei_g_1, MFIB_ENTRY_FLAG_NONE, 2, DPO_ADJACENCY_INCOMPLETE, ai_nbr1, DPO_ADJACENCY_INCOMPLETE, ai_nbr2), "%U replicate OK", format_mfib_prefix, pfx_star_g_1); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_g_1, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); mfib_table_entry_path_remove(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_nbr1); MFIB_TEST(!mfib_test_entry(mfei_g_1, MFIB_ENTRY_FLAG_NONE, 1, DPO_ADJACENCY_INCOMPLETE, ai_nbr2), "%U replicate OK", format_mfib_prefix, pfx_star_g_1); MFIB_TEST_NS(!mfib_test_entry_itf(mfei_g_1, tm->hw[0]->sw_if_index, MFIB_ITF_FLAG_FORWARD)); mfib_table_entry_path_remove(fib_index, pfx_star_g_1, MFIB_SOURCE_API, &path_via_nbr2); mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1); MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei, "%U Gone", format_mfib_prefix, pfx_star_g_1); /* * Add a prefix as a special/exclusive route */ dpo_id_t td = DPO_INVALID; index_t repi = replicate_create(1, fib_proto_to_dpo(PROTO)); dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_2); replicate_set_bucket(repi, 0, &td); mfei = mfib_table_entry_special_add(fib_index, pfx_star_g_3, MFIB_SOURCE_SRv6, MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF, repi); MFIB_TEST(!mfib_test_entry(mfei, (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF | MFIB_ENTRY_FLAG_EXCLUSIVE), 1, DPO_ADJACENCY_MCAST, ai_2), "%U exclusive replicate OK", format_mfib_prefix, pfx_star_g_3); /* * update a special/exclusive route */ index_t repi2 = replicate_create(1, fib_proto_to_dpo(PROTO)); dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_1); replicate_set_bucket(repi2, 0, &td); mfei = mfib_table_entry_special_add(fib_index, pfx_star_g_3, MFIB_SOURCE_SRv6, MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF, repi2); MFIB_TEST(!mfib_test_entry(mfei, (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF | MFIB_ENTRY_FLAG_EXCLUSIVE), 1, DPO_ADJACENCY_MCAST, ai_1), "%U exclusive update replicate OK", format_mfib_prefix, pfx_star_g_3); mfib_table_entry_delete(fib_index, pfx_star_g_3, MFIB_SOURCE_SRv6); dpo_reset(&td); /* * A Multicast LSP. This a mLDP head-end */ fib_node_index_t ai_mpls_10_10_10_1, lfei; ip46_address_t nh_10_10_10_1 = { .ip4 = { .as_u32 = clib_host_to_net_u32(0x0a0a0a01), }, }; ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_MPLS, &nh_10_10_10_1, tm->hw[0]->sw_if_index); fib_prefix_t pfx_3500 = { .fp_len = 21, .fp_proto = FIB_PROTOCOL_MPLS, .fp_label = 3500, .fp_eos = MPLS_EOS, .fp_payload_proto = DPO_PROTO_IP4, }; fib_test_rep_bucket_t mc_0 = { .type = FT_REP_LABEL_O_ADJ, .label_o_adj = { .adj = ai_mpls_10_10_10_1, .label = 3300, .eos = MPLS_EOS, }, }; fib_mpls_label_t *l3300 = NULL, fml3300 = { .fml_value = 3300, }; vec_add1(l3300, fml3300); /* * MPLS enable an interface so we get the MPLS table created */ mpls_table_create(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API, NULL); mpls_sw_interface_enable_disable(&mpls_main, tm->hw[0]->sw_if_index, 1, 0); lfei = fib_table_entry_update_one_path(0, // default MPLS Table &pfx_3500, FIB_SOURCE_API, FIB_ENTRY_FLAG_MULTICAST, DPO_PROTO_IP4, &nh_10_10_10_1, tm->hw[0]->sw_if_index, ~0, // invalid fib index 1, l3300, FIB_ROUTE_PATH_FLAG_NONE); MFIB_TEST(!fib_test_validate_entry(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS, 1, &mc_0), "3500 via replicate over 10.10.10.1"); /* * An (S,G) that resolves via the mLDP head-end */ fib_route_path_t path_via_mldp = { .frp_proto = DPO_PROTO_MPLS, .frp_local_label = pfx_3500.fp_label, .frp_eos = MPLS_EOS, .frp_sw_if_index = 0xffffffff, .frp_fib_index = 0, .frp_weight = 1, .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, }; dpo_id_t mldp_dpo = DPO_INVALID; fib_entry_contribute_forwarding(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS, &mldp_dpo); mfei = mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_via_mldp, MFIB_ITF_FLAG_FORWARD); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 1, DPO_REPLICATE, mldp_dpo.dpoi_index), "%U over-mLDP replicate OK", format_mfib_prefix, pfx_s_g); /* * add a for-us path. this tests two types of non-attached paths on one entry */ mfei = mfib_table_entry_path_update(fib_index, pfx_s_g, MFIB_SOURCE_API, &path_for_us, MFIB_ITF_FLAG_FORWARD); MFIB_TEST(!mfib_test_entry(mfei, MFIB_ENTRY_FLAG_NONE, 2, DPO_REPLICATE, mldp_dpo.dpoi_index, DPO_RECEIVE, 0), "%U mLDP+for-us replicate OK", format_mfib_prefix, pfx_s_g); mfib_table_entry_delete(fib_index, pfx_s_g, MFIB_SOURCE_API); fib_table_entry_delete(0, &pfx_3500, FIB_SOURCE_API); dpo_reset(&mldp_dpo); /* * Unlock the table - it's the last lock so should be gone thereafter */ mfib_table_unlock(fib_index, PROTO, MFIB_SOURCE_API); MFIB_TEST((FIB_NODE_INDEX_INVALID == mfib_table_find(PROTO, fib_index)), "MFIB table %d gone", fib_index); adj_unlock(ai_1); adj_unlock(ai_2); adj_unlock(ai_3); adj_unlock(ai_nbr1); adj_unlock(ai_nbr2); /* * MPLS disable the interface */ mpls_sw_interface_enable_disable(&mpls_main, tm->hw[0]->sw_if_index, 0, 0); mpls_table_delete(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API); /* * remove the connected */ fib_table_entry_delete(0, pfx_itf, FIB_SOURCE_INTERFACE); /* * test we've leaked no resources */ MFIB_TEST(0 == adj_mcast_db_size(), "%d MCAST adjs", adj_mcast_db_size()); MFIB_TEST(n_pls == fib_path_list_pool_size(), "%d=%d path-lists", n_pls, fib_path_list_pool_size()); MFIB_TEST(n_reps == pool_elts(replicate_pool), "%d=%d replicates", n_reps, pool_elts(replicate_pool)); MFIB_TEST(n_entries == pool_elts(mfib_entry_pool), " No more entries %d!=%d", n_entries, pool_elts(mfib_entry_pool)); MFIB_TEST(n_itfs == pool_elts(mfib_itf_pool), " No more Interfaces %d!=%d", n_itfs, pool_elts(mfib_itf_pool)); return (res); } static int mfib_test_v4 (void) { const mfib_prefix_t pfx_224_s_8 = { .fp_len = 8, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xe0000000), } }; const mfib_prefix_t pfx_1_1_1_1_c_239_1_1_1 = { .fp_len = 64, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xef010101), }, .fp_src_addr = { .ip4.as_u32 = clib_host_to_net_u32(0x01010101), }, }; const mfib_prefix_t pfx_239_1_1_1 = { .fp_len = 32, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xef010101), }, .fp_src_addr = { .ip4.as_u32 = 0, }, }; const mfib_prefix_t pfx_239_1_1_2 = { .fp_len = 32, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xef010102), }, .fp_src_addr = { .ip4.as_u32 = 0, }, }; const mfib_prefix_t pfx_239_1_1_3 = { .fp_len = 32, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xef010103), }, .fp_src_addr = { .ip4.as_u32 = 0, }, }; const mfib_prefix_t pfx_239 = { .fp_len = 8, .fp_proto = FIB_PROTOCOL_IP4, .fp_grp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0xef000000), }, .fp_src_addr = { .ip4.as_u32 = 0, }, }; const fib_prefix_t pfx_itf = { .fp_len = 24, .fp_proto = FIB_PROTOCOL_IP4, .fp_addr = { .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0a), }, }; const ip46_address_t nbr1 = { .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0b), }; const ip46_address_t nbr2 = { .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0c), }; return (mfib_test_i(FIB_PROTOCOL_IP4, VNET_LINK_IP4, &pfx_224_s_8, &pfx_1_1_1_1_c_239_1_1_1, &pfx_239_1_1_1, &pfx_239_1_1_2, &pfx_239_1_1_3, &pfx_239, &pfx_itf, &nbr1, &nbr2)); } static int mfib_test_v6 (void) { const mfib_prefix_t pfx_ffd_s_12 = { .fp_len = 12, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xffd0000000000000), } }; const mfib_prefix_t pfx_2001_1_c_ff_1 = { .fp_len = 256, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001), }, .fp_src_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001), }, }; const mfib_prefix_t pfx_ff_1 = { .fp_len = 128, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001), }, }; const mfib_prefix_t pfx_ff_2 = { .fp_len = 128, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002), }, }; const mfib_prefix_t pfx_ff_3 = { /* * this is the ALL DHCP routers address */ .fp_len = 128, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xff02000100000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002), }, }; const mfib_prefix_t pfx_ff = { .fp_len = 16, .fp_proto = FIB_PROTOCOL_IP6, .fp_grp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000000), }, }; const fib_prefix_t pfx_itf = { .fp_len = 64, .fp_proto = FIB_PROTOCOL_IP6, .fp_addr = { .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001), }, }; const ip46_address_t nbr1 = { .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002), }; const ip46_address_t nbr2 = { .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000), .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000003), }; return (mfib_test_i(FIB_PROTOCOL_IP6, VNET_LINK_IP6, &pfx_ffd_s_12, &pfx_2001_1_c_ff_1, &pfx_ff_1, &pfx_ff_2, &pfx_ff_3, &pfx_ff, &pfx_itf, &nbr1, &nbr2)); } static clib_error_t * mfib_test (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd_arg) { int res = 0; res += mfib_test_mk_intf(4); res += mfib_test_v4(); if (res) { return clib_error_return(0, "MFIB Unit Test Failed"); } res += mfib_test_v6(); if (res) { return clib_error_return(0, "MFIB Unit Test Failed"); } else { return (NULL); } } VLIB_CLI_COMMAND (test_fib_command, static) = { .path = "test mfib", .short_help = "mfib unit tests - DO NOT RUN ON A LIVE SYSTEM", .function = mfib_test, }; clib_error_t * mfib_test_init (vlib_main_t *vm) { return 0; } VLIB_INIT_FUNCTION (mfib_test_init);