2 * BIRD Library -- Flow specification (RFC 5575) Tests
4 * (c) 2016 CZ.NIC z.s.p.o.
6 * Can be freely distributed and used under the terms of the GNU GPL.
9 #include "test/birdtest.h"
10 #include "lib/flowspec.h"
12 #define NET_ADDR_FLOW4_(what,prefix,pxlen,data_) \
15 what = alloca(sizeof(net_addr_flow4) + 128); \
16 *what = NET_ADDR_FLOW4(prefix, pxlen, sizeof(data_)); \
17 memcpy(what->data, &(data_), sizeof(data_)); \
20 #define NET_ADDR_FLOW6_(what,prefix,pxlen,data_) \
23 what = alloca(sizeof(net_addr_flow6) + 128); \
24 *what = NET_ADDR_FLOW6(prefix, pxlen, sizeof(data_)); \
25 memcpy(what->data, &(data_), sizeof(data_)); \
31 byte data
[] = { 0xcc, 0xcc, 0xcc };
33 for (uint expect
= 0; expect
< 0xf0; expect
++)
36 uint get
= flow_read_length(data
);
37 bt_assert_msg(get
== expect
, "Testing get length 0x%02x (get 0x%02x)", expect
, get
);
40 for (uint expect
= 0; expect
<= 0xfff; expect
++)
42 put_u16(data
, expect
| 0xf000);
43 uint get
= flow_read_length(data
);
44 bt_assert_msg(get
== expect
, "Testing get length 0x%03x (get 0x%03x)", expect
, get
);
53 byte data
[] = { 0xcc, 0xcc, 0xcc };
55 for (uint expect
= 0; expect
<= 0xfff; expect
++)
57 uint offset
= flow_write_length(data
, expect
);
59 uint set
= (expect
< 0xf0) ? *data
: (get_u16(data
) & 0x0fff);
60 bt_assert_msg(set
== expect
, "Testing set length 0x%03x (set 0x%03x)", expect
, set
);
61 bt_assert(offset
== (expect
< 0xf0 ? 1 : 2));
71 NET_ADDR_FLOW4_(f
, ip4_build(10,0,0,1), 24, ((byte
[]) { 0x00, 0x00, 0xab }));
73 const byte
*under240
= &f
->data
[1];
74 const byte
*above240
= &f
->data
[2];
77 bt_assert(flow4_first_part(f
) == NULL
);
81 bt_assert(flow4_first_part(f
) == under240
);
85 bt_assert(flow4_first_part(f
) == under240
);
89 bt_assert(flow4_first_part(f
) == NULL
);
93 bt_assert(flow4_first_part(f
) == above240
);
98 bt_assert(flow4_first_part(f
) == above240
);
107 NET_ADDR_FLOW4_(f
, ip4_build(5,6,7,0), 24, ((byte
[]) {
109 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
110 FLOW_TYPE_SRC_PREFIX
, 32, 10, 11, 12, 13,
111 FLOW_TYPE_IP_PROTOCOL
, 0x81, 0x06,
112 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
113 FLOW_TYPE_TCP_FLAGS
, 0x80, 0x55,
116 const byte
*start
= f
->data
;
117 const byte
*p1_dst_pfx
= &f
->data
[1];
118 const byte
*p2_src_pfx
= &f
->data
[6];
119 const byte
*p3_ip_proto
= &f
->data
[12];
120 const byte
*p4_port
= &f
->data
[15];
121 const byte
*p5_tcp_flags
= &f
->data
[23];
122 const byte
*end
= &f
->data
[25];
124 bt_assert(flow_read_length(f
->data
) == (end
-start
));
125 bt_assert(flow4_first_part(f
) == p1_dst_pfx
);
127 bt_assert(flow4_next_part(p1_dst_pfx
, end
) == p2_src_pfx
);
128 bt_assert(flow4_next_part(p2_src_pfx
, end
) == p3_ip_proto
);
129 bt_assert(flow4_next_part(p3_ip_proto
, end
) == p4_port
);
130 bt_assert(flow4_next_part(p4_port
, end
) == p5_tcp_flags
);
131 bt_assert(flow4_next_part(p5_tcp_flags
, end
) == NULL
);
140 NET_ADDR_FLOW6_(f
, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte
[]) {
142 FLOW_TYPE_DST_PREFIX
, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
143 FLOW_TYPE_SRC_PREFIX
, 0x08, 0x0, 0xc0,
144 FLOW_TYPE_NEXT_HEADER
, 0x81, 0x06,
145 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
146 FLOW_TYPE_LABEL
, 0x80, 0x55,
149 const byte
*start
= f
->data
;
150 const byte
*p1_dst_pfx
= &f
->data
[1];
151 const byte
*p2_src_pfx
= &f
->data
[9];
152 const byte
*p3_next_header
= &f
->data
[13];
153 const byte
*p4_port
= &f
->data
[16];
154 const byte
*p5_label
= &f
->data
[24];
155 const byte
*end
= &f
->data
[26];
157 bt_assert(flow_read_length(f
->data
) == (end
-start
));
158 bt_assert(flow6_first_part(f
) == p1_dst_pfx
);
160 bt_assert(flow6_next_part(p1_dst_pfx
, end
) == p2_src_pfx
);
161 bt_assert(flow6_next_part(p2_src_pfx
, end
) == p3_next_header
);
162 bt_assert(flow6_next_part(p3_next_header
, end
) == p4_port
);
163 bt_assert(flow6_next_part(p4_port
, end
) == p5_label
);
164 bt_assert(flow6_next_part(p5_label
, end
) == NULL
);
173 NET_ADDR_FLOW4_(f
, ip4_build(5,6,7,0), 24, ((byte
[]) {
175 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
176 FLOW_TYPE_SRC_PREFIX
, 32, 10, 11, 12, 13,
177 FLOW_TYPE_IP_PROTOCOL
, 0x81, 0x06,
178 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
179 FLOW_TYPE_TCP_FLAGS
, 0x80, 0x55,
182 const byte
*p1_dst_px
= &f
->data
[1];
183 const ip4_addr p1_dst_addr
= ip4_build(5,6,7,0);
185 const byte
*p2_src_px
= &f
->data
[6];
186 const ip4_addr p2_src_addr
= ip4_build(10,11,12,13);
188 bt_assert(ip4_equal(flow_read_ip4_part(p1_dst_px
), p1_dst_addr
));
189 bt_assert(ip4_equal(flow_read_ip4_part(p2_src_px
), p2_src_addr
));
198 NET_ADDR_FLOW6_(f
, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte
[]) {
200 FLOW_TYPE_DST_PREFIX
, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
201 FLOW_TYPE_SRC_PREFIX
, 0x08, 0x0, 0xc0,
202 FLOW_TYPE_NEXT_HEADER
, 0x81, 0x06,
203 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
204 FLOW_TYPE_LABEL
, 0x80, 0x55,
207 const byte
*p1_dst_px
= &f
->data
[1];
208 const ip6_addr p1_dst_addr
= ip6_build(0,0,0x12345678,0x9a000000);
210 const byte
*p2_src_px
= &f
->data
[9];
211 const ip6_addr p2_src_addr
= ip6_build(0xc0000000, 0, 0, 0);
213 bt_assert(ip6_equal(flow_read_ip6_part(p1_dst_px
), p1_dst_addr
));
214 bt_assert(ip6_equal(flow_read_ip6_part(p2_src_px
), p2_src_addr
));
222 enum flow_validated_state res
;
225 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
226 FLOW_TYPE_SRC_PREFIX
, 32, 10, 11, 12, 13,
227 FLOW_TYPE_IP_PROTOCOL
, 0x81, 0x06,
228 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
229 FLOW_TYPE_TCP_FLAGS
, 0x80, 0x55,
233 res
= flow4_validate(nlri1
, 0);
234 bt_assert(res
== FLOW_ST_VALID
);
236 /* Valid / Not Complete testing */
237 uint valid_sizes
[] = {5, 11, 14, 22, 25, 0};
239 for (uint size
= 1; size
<= sizeof(nlri1
); size
++)
241 res
= flow4_validate(nlri1
, size
);
242 bt_debug("size %u, result: %s\n", size
, flow_validated_state_str(res
));
243 if (size
== valid_sizes
[valid_idx
])
246 bt_assert(res
== FLOW_ST_VALID
);
250 bt_assert(res
== FLOW_ST_NOT_COMPLETE
);
257 enum flow_validated_state expect
;
263 #define TS(type, msg, data) ((struct tset) {type, msg, sizeof(data), (data)})
264 struct tset tset
[] = {
266 FLOW_ST_EXCEED_MAX_PREFIX_LENGTH
,
267 "33-length IPv4 prefix",
269 FLOW_TYPE_DST_PREFIX
, 33, 5, 6, 7, 8, 9
273 FLOW_ST_BAD_TYPE_ORDER
,
274 "Bad flowspec component type order",
276 FLOW_TYPE_SRC_PREFIX
, 32, 10, 11, 12, 13,
277 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
281 FLOW_ST_BAD_TYPE_ORDER
,
282 "Doubled destination prefix component",
284 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
285 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
289 FLOW_ST_AND_BIT_SHOULD_BE_UNSET
,
290 "The first numeric operator has set the AND bit",
292 FLOW_TYPE_PORT
, 0x43, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
296 FLOW_ST_ZERO_BIT_SHOULD_BE_UNSED
,
297 "Set zero bit in operand to one",
299 FLOW_TYPE_IP_PROTOCOL
, 0x89, 0x06,
303 FLOW_ST_UNKNOWN_COMPONENT
,
304 "Unknown component of type number 13",
306 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
307 FLOW_TYPE_TCP_FLAGS
, 0x80, 0x55,
308 13 /*something new*/, 0x80, 0x55,
314 for (uint tcase
= 0; tcase
< ARRAY_SIZE(tset
); tcase
++)
316 res
= flow4_validate(tset
[tcase
].nlri
, tset
[tcase
].size
);
317 bt_assert_msg(res
== tset
[tcase
].expect
, "Assertion (%s == %s) %s", flow_validated_state_str(res
), flow_validated_state_str(tset
[tcase
].expect
), tset
[tcase
].description
);
326 enum flow_validated_state res
;
329 FLOW_TYPE_DST_PREFIX
, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
330 FLOW_TYPE_SRC_PREFIX
, 8, 0, 0xc0,
331 FLOW_TYPE_NEXT_HEADER
, 0x81, 0x06,
332 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
333 FLOW_TYPE_LABEL
, 0x80, 0x55,
336 /* Isn't included destination prefix */
337 res
= flow6_validate(nlri1
, 0);
338 bt_assert(res
== FLOW_ST_VALID
);
340 /* Valid / Not Complete testing */
341 uint valid_sizes
[] = {0, 9, 13, 16, 24, 27, 0};
343 for (uint size
= 0; size
<= sizeof(nlri1
); size
++)
345 res
= flow6_validate(nlri1
, size
);
346 bt_debug("size %u, result: %s\n", size
, flow_validated_state_str(res
));
347 if (size
== valid_sizes
[valid_idx
])
350 bt_assert(res
== FLOW_ST_VALID
);
354 bt_assert(res
== FLOW_ST_NOT_COMPLETE
);
361 enum flow_validated_state expect
;
367 #define TS(type, msg, data) ((struct tset) {type, msg, sizeof(data), (data)})
368 struct tset tset
[] = {
370 FLOW_ST_EXCEED_MAX_PREFIX_LENGTH
,
371 "129-length IPv6 prefix",
373 FLOW_TYPE_DST_PREFIX
, 129, 64, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
377 FLOW_ST_EXCEED_MAX_PREFIX_OFFSET
,
378 "Prefix offset is higher than prefix length",
380 FLOW_TYPE_DST_PREFIX
, 48, 64, 0x40, 0x12, 0x34
384 FLOW_ST_BAD_TYPE_ORDER
,
385 "Bad flowspec component type order",
387 FLOW_TYPE_NEXT_HEADER
, 0x81, 0x06,
388 FLOW_TYPE_SRC_PREFIX
, 8, 0, 0xc0,
392 FLOW_ST_BAD_TYPE_ORDER
,
393 "Doubled destination prefix component",
395 FLOW_TYPE_DST_PREFIX
, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
396 FLOW_TYPE_DST_PREFIX
, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
400 FLOW_ST_AND_BIT_SHOULD_BE_UNSET
,
401 "The first numeric operator has set the AND bit",
403 FLOW_TYPE_PORT
, 0x43, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90
407 FLOW_ST_ZERO_BIT_SHOULD_BE_UNSED
,
408 "Set zero bit in operand to one",
410 FLOW_TYPE_NEXT_HEADER
, 0x89, 0x06
415 "Component of type number 13 (Label) is well-known in IPv6",
417 FLOW_TYPE_LABEL
, 0x80, 0x55
421 FLOW_ST_UNKNOWN_COMPONENT
,
422 "Unknown component of type number 14",
424 FLOW_TYPE_LABEL
, 0x80, 0x55,
425 14 /*something new*/, 0x80, 0x55,
431 for (uint tcase
= 0; tcase
< ARRAY_SIZE(tset
); tcase
++)
433 res
= flow6_validate(tset
[tcase
].nlri
, tset
[tcase
].size
);
434 bt_assert_msg(res
== tset
[tcase
].expect
, "Assertion (%s == %s) %s", flow_validated_state_str(res
), flow_validated_state_str(tset
[tcase
].expect
), tset
[tcase
].description
);
451 struct flow_builder
*fb
= flow_builder_init(&root_pool
);
452 linpool
*lp
= lp_new_default(&root_pool
);
456 static byte nlri
[] = {
458 FLOW_TYPE_DST_PREFIX
, 24, 5, 6, 7,
459 FLOW_TYPE_SRC_PREFIX
, 32, 10, 11, 12, 13,
460 FLOW_TYPE_IP_PROTOCOL
, 0x80, 0x06,
461 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
462 FLOW_TYPE_TCP_FLAGS
, 0x80, 0x55
465 net_addr_flow4
*expect
;
466 NET_ADDR_FLOW4_(expect
, ip4_build(5, 6, 7, 0), 24, nlri
);
471 net_fill_ip4((net_addr
*) &n1
, ip4_build(5,6,7,0), 24);
472 flow_builder_set_type(fb
, FLOW_TYPE_DST_PREFIX
);
473 flow_builder4_add_pfx(fb
, &n1
);
476 net_fill_ip4((net_addr
*) &n2
, ip4_build(10,11,12,13), 32);
477 flow_builder_set_type(fb
, FLOW_TYPE_SRC_PREFIX
);
478 flow_builder4_add_pfx(fb
, &n2
);
480 flow_builder_set_type(fb
, FLOW_TYPE_IP_PROTOCOL
);
481 flow_builder_add_op_val(fb
, 0, 0x06);
483 flow_builder_set_type(fb
, FLOW_TYPE_PORT
);
484 flow_builder_add_op_val(fb
, 0x03, 0x89);
485 flow_builder_add_op_val(fb
, 0x45, 0x8b);
486 flow_builder_add_op_val(fb
, 0x01, 0x1f90);
488 /* Try put a component twice time */
489 flow_builder_set_type(fb
, FLOW_TYPE_IP_PROTOCOL
);
490 flow_builder_add_op_val(fb
, 0, 0x06);
492 flow_builder_set_type(fb
, FLOW_TYPE_TCP_FLAGS
);
493 flow_builder_add_op_val(fb
, 0, 0x55);
495 net_addr_flow4
*res
= flow_builder4_finalize(fb
, lp
);
497 bt_assert(memcmp(res
, expect
, expect
->length
) == 0);
501 flow_builder_clear(fb
);
503 flow_builder_set_type(fb
, FLOW_TYPE_TCP_FLAGS
);
504 flow_builder_add_op_val(fb
, 0, 0x55);
506 flow_builder_set_type(fb
, FLOW_TYPE_PORT
);
507 flow_builder_add_op_val(fb
, 0x03, 0x89);
508 flow_builder_add_op_val(fb
, 0x45, 0x8b);
509 flow_builder_add_op_val(fb
, 0x01, 0x1f90);
511 flow_builder_set_type(fb
, FLOW_TYPE_IP_PROTOCOL
);
512 flow_builder_add_op_val(fb
, 0, 0x06);
514 net_fill_ip4((net_addr
*) &n2
, ip4_build(10,11,12,13), 32);
515 flow_builder_set_type(fb
, FLOW_TYPE_SRC_PREFIX
);
516 flow_builder4_add_pfx(fb
, &n2
);
518 net_fill_ip4((net_addr
*) &n1
, ip4_build(5,6,7,0), 24);
519 flow_builder_set_type(fb
, FLOW_TYPE_DST_PREFIX
);
520 flow_builder4_add_pfx(fb
, &n1
);
522 bt_assert(memcmp(res
, expect
, expect
->length
) == 0);
533 linpool
*lp
= lp_new_default(&root_pool
);
534 struct flow_builder
*fb
= flow_builder_init(&root_pool
);
541 FLOW_TYPE_DST_PREFIX
, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
542 FLOW_TYPE_SRC_PREFIX
, 8, 0, 0xc0,
543 FLOW_TYPE_NEXT_HEADER
, 0x80, 0x06,
544 FLOW_TYPE_PORT
, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
545 FLOW_TYPE_LABEL
, 0x80, 0x55,
548 net_addr_flow6
*expect
;
549 NET_ADDR_FLOW6_(expect
, ip6_build(0, 1, 0x12345678, 0x98000000), 103, nlri
);
553 net_fill_ip6((net_addr
*) &ip
, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
554 flow_builder_set_type(fb
, FLOW_TYPE_DST_PREFIX
);
555 flow_builder6_add_pfx(fb
, &ip
, 61);
557 /* Try put a component twice time */
558 net_fill_ip6((net_addr
*) &ip
, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
559 flow_builder_set_type(fb
, FLOW_TYPE_DST_PREFIX
);
560 bt_assert(flow_builder6_add_pfx(fb
, &ip
, 61) == 0);
562 net_fill_ip6((net_addr
*) &ip
, ip6_build(0xc0000000,0,0,0), 8);
563 flow_builder_set_type(fb
, FLOW_TYPE_SRC_PREFIX
);
564 flow_builder6_add_pfx(fb
, &ip
, 0);
566 flow_builder_set_type(fb
, FLOW_TYPE_NEXT_HEADER
);
567 flow_builder_add_op_val(fb
, 0, 0x06);
569 flow_builder_set_type(fb
, FLOW_TYPE_PORT
);
570 flow_builder_add_op_val(fb
, 0x03, 0x89);
571 flow_builder_add_op_val(fb
, 0x45, 0x8b);
572 flow_builder_add_op_val(fb
, 0x01, 0x1f90);
574 flow_builder_set_type(fb
, FLOW_TYPE_LABEL
);
575 flow_builder_add_op_val(fb
, 0, 0x55);
577 net_addr_flow6
*res
= flow_builder6_finalize(fb
, lp
);
578 bt_assert(memcmp(res
, expect
, expect
->length
) == 0);
582 flow_builder_clear(fb
);
585 flow_builder_set_type(fb
, FLOW_TYPE_LABEL
);
586 flow_builder_add_op_val(fb
, 0, 0x55);
588 flow_builder_set_type(fb
, FLOW_TYPE_PORT
);
589 flow_builder_add_op_val(fb
, 0x03, 0x89);
590 flow_builder_add_op_val(fb
, 0x45, 0x8b);
591 flow_builder_add_op_val(fb
, 0x01, 0x1f90);
593 flow_builder_set_type(fb
, FLOW_TYPE_NEXT_HEADER
);
594 flow_builder_add_op_val(fb
, 0, 0x06);
596 net_fill_ip6((net_addr
*) &ip
, ip6_build(0xc0000000,0,0,0), 8);
597 flow_builder_set_type(fb
, FLOW_TYPE_SRC_PREFIX
);
598 flow_builder6_add_pfx(fb
, &ip
, 0);
600 net_fill_ip6((net_addr
*) &ip
, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
601 flow_builder_set_type(fb
, FLOW_TYPE_DST_PREFIX
);
602 flow_builder6_add_pfx(fb
, &ip
, 61);
604 res
= flow_builder6_finalize(fb
, lp
);
605 bt_assert(memcmp(res
, expect
, expect
->length
) == 0);
617 FLOW_TYPE_DST_PREFIX
, 0x08, 10,
618 FLOW_TYPE_IP_PROTOCOL
, 0x81, 23,
619 FLOW_TYPE_DST_PORT
, 0x02, 24, 0x44, 30, 0x03, 40, 0x45, 50, 0x03, 60, 0x45, 70, 0x01, 80, 0xc3, 90,
620 FLOW_TYPE_SRC_PORT
, 0x02, 24, 0x44, 0x1e, 0x01, 0x28, 0x01, 0x32, 0x03, 0x3c, 0x45, 0x46, 0x81, 0x50,
621 FLOW_TYPE_ICMP_TYPE
, 0x81, 0x50,
622 FLOW_TYPE_ICMP_CODE
, 0x81, 0x5a,
623 FLOW_TYPE_TCP_FLAGS
, 0x01, 0x03, 0xc2, 0x0c,
624 FLOW_TYPE_PACKET_LENGTH
, 0x03, 0, 0xd5, 0xff, 0xff,
625 FLOW_TYPE_DSCP
, 0x81, 63,
626 FLOW_TYPE_FRAGMENT
, 0x01, 0x01, 0x82, 0x02
628 *nlri
= (u8
) sizeof(nlri
);
630 net_addr_flow4
*input
;
631 NET_ADDR_FLOW4_(input
, ip4_build(5, 6, 7, 0), 24, nlri
);
633 const char *expect
= "flow4 { dst 10.0.0.0/8; proto 23; dport > 24 && < 30 || 40..50,60..70,80 && >= 90; sport > 24 && < 30 || 40,50,60..70,80; icmp type 80; icmp code 90; tcp flags 0x3/0x3 && 0x0/0xc; length 0..65535; dscp 63; fragment dont_fragment || !is_fragment; }";
635 bt_assert(flow4_net_format(b
, sizeof(b
), input
) == strlen(expect
));
636 bt_debug(" expect: '%s',\n output: '%s'\n", expect
, b
);
637 bt_assert(strcmp(b
, expect
) == 0);
649 FLOW_TYPE_DST_PREFIX
, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
650 FLOW_TYPE_SRC_PREFIX
, 8, 0, 0xc0,
651 FLOW_TYPE_NEXT_HEADER
, 0x81, 0x06,
652 FLOW_TYPE_PORT
, 0x03, 20, 0x45, 40, 0x91, 0x01, 0x11,
653 FLOW_TYPE_LABEL
, 0xa4, 0x00, 0x07, 0xa1, 0x20,
655 *nlri
= (u8
) sizeof(nlri
);
657 net_addr_flow6
*input
;
658 NET_ADDR_FLOW6_(input
, ip6_build(0, 1, 0x12345678, 0x98000000), 103, nlri
);
660 const char *expect
= "flow6 { dst ::1:1234:5678:9800:0/103 offset 61; src c000::/8; next header 6; port 20..40,273; label < 500000; }";
662 bt_assert(flow6_net_format(b
, sizeof(b
), input
) == strlen(expect
));
663 bt_debug(" expect: '%s',\n output: '%s'\n", expect
, b
);
664 bt_assert(strcmp(b
, expect
) == 0);
670 main(int argc
, char *argv
[])
674 bt_test_suite(t_read_length
, "Testing get NLRI length");
675 bt_test_suite(t_write_length
, "Testing set NLRI length");
676 bt_test_suite(t_first_part
, "Searching first part in net_addr_flow");
677 bt_test_suite(t_iterators4
, "Testing iterators (IPv4)");
678 bt_test_suite(t_iterators6
, "Testing iterators (IPv6)");
679 bt_test_suite(t_accessors4
, "Testing accessors (IPv4)");
680 bt_test_suite(t_accessors6
, "Testing accessors (IPv6)");
681 bt_test_suite(t_validation4
, "Testing validation (IPv4)");
682 bt_test_suite(t_validation6
, "Testing validation (IPv6)");
683 bt_test_suite(t_builder4
, "Inserting components into existing Flow Specification (IPv4)");
684 bt_test_suite(t_builder6
, "Inserting components into existing Flow Specification (IPv6)");
685 bt_test_suite(t_formatting4
, "Formatting Flow Specification (IPv4) into text representation");
686 bt_test_suite(t_formatting6
, "Formatting Flow Specification (IPv6) into text representation");
688 return bt_exit_value();