]>
git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_nexthop.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2021 by Volta Networks, Inc.
13 static void test_run_first(void)
16 struct nexthop
*nh1
, *nh2
;
18 struct in6_addr addr6
;
19 mpls_label_t labels
[MPLS_MAX_LABELS
];
21 /* Test comparison apis */
23 /* ifindex comparisons */
24 nh1
= nexthop_from_ifindex(11, 0);
25 nh2
= nexthop_from_ifindex(12, 0);
27 ret
= nexthop_cmp_basic(nh1
, nh2
);
31 nh1
= nexthop_from_ifindex(12, 0);
33 ret
= nexthop_cmp_basic(nh1
, nh2
);
40 addr
.s_addr
= 0x04030201;
41 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
42 nh2
= nexthop_from_ipv4(&addr
, NULL
, 111);
44 ret
= nexthop_cmp_basic(nh1
, nh2
);
49 addr
.s_addr
= 0x04030202;
50 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
52 ret
= nexthop_cmp_basic(nh1
, nh2
);
57 addr
.s_addr
= 0x04030201;
58 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
60 ret
= nexthop_cmp_basic(nh1
, nh2
);
66 ret
= nexthop_cmp_basic(nh1
, nh2
);
73 memset(addr6
.s6_addr
, 0, sizeof(addr6
.s6_addr
));
74 nh1
= nexthop_from_ipv6(&addr6
, 0);
75 nh2
= nexthop_from_ipv6(&addr6
, 0);
77 ret
= nexthop_cmp_basic(nh1
, nh2
);
82 nh2
= nexthop_from_ipv6(&addr6
, 1);
84 ret
= nexthop_cmp_basic(nh1
, nh2
);
89 addr6
.s6_addr
[14] = 1;
90 addr6
.s6_addr
[15] = 1;
91 nh2
= nexthop_from_ipv6(&addr6
, 0);
93 ret
= nexthop_cmp_basic(nh1
, nh2
);
100 nh1
= nexthop_from_blackhole(BLACKHOLE_REJECT
, 0);
101 nh2
= nexthop_from_blackhole(BLACKHOLE_REJECT
, 0);
103 ret
= nexthop_cmp_basic(nh1
, nh2
);
108 nh2
= nexthop_from_blackhole(BLACKHOLE_NULL
, 0);
110 ret
= nexthop_cmp_basic(nh1
, nh2
);
114 addr
.s_addr
= 0x04030201;
115 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
116 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
118 memset(labels
, 0, sizeof(labels
));
122 nexthop_add_labels(nh1
, ZEBRA_LSP_STATIC
, 2, labels
);
124 ret
= nexthop_cmp_basic(nh1
, nh2
);
127 nexthop_add_labels(nh2
, ZEBRA_LSP_STATIC
, 2, labels
);
129 ret
= nexthop_cmp_basic(nh1
, nh2
);
134 /* LSP type isn't included */
135 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
136 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, 2, labels
);
138 ret
= nexthop_cmp_basic(nh1
, nh2
);
144 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
145 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, 3, labels
);
147 ret
= nexthop_cmp_basic(nh1
, nh2
);
153 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
154 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
156 for (i
= 0; i
< MPLS_MAX_LABELS
; i
++)
157 labels
[i
] = 111 * (i
+ 1);
159 nexthop_add_labels(nh1
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
160 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
162 ret
= nexthop_cmp_basic(nh1
, nh2
);
167 /* Test very last label in stack */
169 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
170 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
172 ret
= nexthop_cmp_basic(nh1
, nh2
);
180 int main(int argc
, char **argv
)
182 if (argc
>= 2 && !strcmp("-v", argv
[1]))
185 printf("Simple test passed.\n");