]>
git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_nexthop.c
4 * Copyright (C) 2021 by Volta Networks, Inc.
6 * This file is part of FRR.
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 static void test_run_first(void)
31 struct nexthop
*nh1
, *nh2
;
33 struct in6_addr addr6
;
34 mpls_label_t labels
[MPLS_MAX_LABELS
];
36 /* Test comparison apis */
38 /* ifindex comparisons */
39 nh1
= nexthop_from_ifindex(11, 0);
40 nh2
= nexthop_from_ifindex(12, 0);
42 ret
= nexthop_cmp_basic(nh1
, nh2
);
46 nh1
= nexthop_from_ifindex(12, 0);
48 ret
= nexthop_cmp_basic(nh1
, nh2
);
55 addr
.s_addr
= 0x04030201;
56 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
57 nh2
= nexthop_from_ipv4(&addr
, NULL
, 111);
59 ret
= nexthop_cmp_basic(nh1
, nh2
);
64 addr
.s_addr
= 0x04030202;
65 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
67 ret
= nexthop_cmp_basic(nh1
, nh2
);
72 addr
.s_addr
= 0x04030201;
73 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
75 ret
= nexthop_cmp_basic(nh1
, nh2
);
81 ret
= nexthop_cmp_basic(nh1
, nh2
);
88 memset(addr6
.s6_addr
, 0, sizeof(addr6
.s6_addr
));
89 nh1
= nexthop_from_ipv6(&addr6
, 0);
90 nh2
= nexthop_from_ipv6(&addr6
, 0);
92 ret
= nexthop_cmp_basic(nh1
, nh2
);
97 nh2
= nexthop_from_ipv6(&addr6
, 1);
99 ret
= nexthop_cmp_basic(nh1
, nh2
);
104 addr6
.s6_addr
[14] = 1;
105 addr6
.s6_addr
[15] = 1;
106 nh2
= nexthop_from_ipv6(&addr6
, 0);
108 ret
= nexthop_cmp_basic(nh1
, nh2
);
115 nh1
= nexthop_from_blackhole(BLACKHOLE_REJECT
);
116 nh2
= nexthop_from_blackhole(BLACKHOLE_REJECT
);
118 ret
= nexthop_cmp_basic(nh1
, nh2
);
123 nh2
= nexthop_from_blackhole(BLACKHOLE_NULL
);
125 ret
= nexthop_cmp_basic(nh1
, nh2
);
129 addr
.s_addr
= 0x04030201;
130 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
131 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
133 memset(labels
, 0, sizeof(labels
));
137 nexthop_add_labels(nh1
, ZEBRA_LSP_STATIC
, 2, labels
);
139 ret
= nexthop_cmp_basic(nh1
, nh2
);
142 nexthop_add_labels(nh2
, ZEBRA_LSP_STATIC
, 2, labels
);
144 ret
= nexthop_cmp_basic(nh1
, nh2
);
149 /* LSP type isn't included */
150 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
151 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, 2, labels
);
153 ret
= nexthop_cmp_basic(nh1
, nh2
);
159 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
160 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, 3, labels
);
162 ret
= nexthop_cmp_basic(nh1
, nh2
);
168 nh1
= nexthop_from_ipv4(&addr
, NULL
, 0);
169 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
171 for (i
= 0; i
< MPLS_MAX_LABELS
; i
++)
172 labels
[i
] = 111 * (i
+ 1);
174 nexthop_add_labels(nh1
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
175 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
177 ret
= nexthop_cmp_basic(nh1
, nh2
);
182 /* Test very last label in stack */
184 nh2
= nexthop_from_ipv4(&addr
, NULL
, 0);
185 nexthop_add_labels(nh2
, ZEBRA_LSP_LDP
, MPLS_MAX_LABELS
, labels
);
187 ret
= nexthop_cmp_basic(nh1
, nh2
);
195 int main(int argc
, char **argv
)
197 if (argc
>= 2 && !strcmp("-v", argv
[1]))
200 printf("Simple test passed.\n");