]>
git.proxmox.com Git - mirror_ovs.git/blob - tests/test-packets.c
2 * Copyright (c) 2011 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
30 assert(ip_is_cidr(htonl(0x00000000)));
31 assert(ip_is_cidr(htonl(0x80000000)));
32 assert(ip_is_cidr(htonl(0xf0000000)));
33 assert(ip_is_cidr(htonl(0xffffffe0)));
34 assert(ip_is_cidr(htonl(0xffffffff)));
36 assert(!ip_is_cidr(htonl(0x00000001)));
37 assert(!ip_is_cidr(htonl(0x40000000)));
38 assert(!ip_is_cidr(htonl(0x0fffffff)));
39 assert(!ip_is_cidr(htonl(0xffffffd0)));
43 test_ipv6_static_masks(void)
45 /* The 'exact' and 'any' addresses should be identical to
46 * 'in6addr_exact' and 'in6addr_any' definitions, but we redefine
47 * them here since the pre-defined ones are used in the functions
49 struct in6_addr exact
= {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
50 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }}};
52 struct in6_addr any
= {{{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
53 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}};
55 struct in6_addr neither
= {{{ 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, \
56 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }}};
58 assert(ipv6_mask_is_exact(&exact
));
59 assert(!ipv6_mask_is_exact(&any
));
60 assert(!ipv6_mask_is_exact(&neither
));
62 assert(!ipv6_mask_is_any(&exact
));
63 assert(ipv6_mask_is_any(&any
));
64 assert(!ipv6_mask_is_any(&neither
));
73 struct in6_addr src
= {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
74 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}};
76 dest
= ipv6_create_mask(0);
77 assert(ipv6_mask_is_any(&dest
));
78 assert(ipv6_count_cidr_bits(&dest
) == 0);
79 assert(ipv6_is_cidr(&dest
));
81 dest
= ipv6_create_mask(128);
82 assert(ipv6_mask_is_exact(&dest
));
83 assert(ipv6_count_cidr_bits(&dest
) == 128);
84 assert(ipv6_is_cidr(&dest
));
86 dest
= ipv6_create_mask(1);
87 assert(ipv6_count_cidr_bits(&dest
) == 1);
88 assert(ipv6_is_cidr(&dest
));
90 dest
= ipv6_create_mask(13);
91 assert(ipv6_count_cidr_bits(&dest
) == 13);
92 assert(ipv6_is_cidr(&dest
));
94 dest
= ipv6_create_mask(64);
95 assert(ipv6_count_cidr_bits(&dest
) == 64);
96 assert(ipv6_is_cidr(&dest
));
98 dest
= ipv6_create_mask(95);
99 assert(ipv6_count_cidr_bits(&dest
) == 95);
100 assert(ipv6_is_cidr(&dest
));
102 dest
= ipv6_create_mask(96);
103 assert(ipv6_count_cidr_bits(&dest
) == 96);
104 assert(ipv6_is_cidr(&dest
));
106 dest
= ipv6_create_mask(97);
107 assert(ipv6_count_cidr_bits(&dest
) == 97);
108 assert(ipv6_is_cidr(&dest
));
110 dest
= ipv6_create_mask(127);
111 assert(ipv6_count_cidr_bits(&dest
) == 127);
112 assert(ipv6_is_cidr(&dest
));
114 src
.s6_addr
[8] = 0xf0;
115 assert(ipv6_is_cidr(&src
));
116 assert(ipv6_count_cidr_bits(&src
) == 68);
118 src
.s6_addr
[15] = 0x01;
119 assert(!ipv6_is_cidr(&src
));
120 src
.s6_addr
[15] = 0x00;
121 assert(ipv6_is_cidr(&src
));
123 src
.s6_addr
[8] = 0x0f;
124 assert(!ipv6_is_cidr(&src
));
129 test_ipv6_masking(void)
131 struct in6_addr dest
;
132 struct in6_addr mask
;
134 mask
= ipv6_create_mask(0);
135 dest
= ipv6_addr_bitand(&in6addr_exact
, &mask
);
136 assert(ipv6_count_cidr_bits(&dest
) == 0);
138 mask
= ipv6_create_mask(1);
139 dest
= ipv6_addr_bitand(&in6addr_exact
, &mask
);
140 assert(ipv6_count_cidr_bits(&dest
) == 1);
142 mask
= ipv6_create_mask(13);
143 dest
= ipv6_addr_bitand(&in6addr_exact
, &mask
);
144 assert(ipv6_count_cidr_bits(&dest
) == 13);
146 mask
= ipv6_create_mask(127);
147 dest
= ipv6_addr_bitand(&in6addr_exact
, &mask
);
148 assert(ipv6_count_cidr_bits(&dest
) == 127);
150 mask
= ipv6_create_mask(128);
151 dest
= ipv6_addr_bitand(&in6addr_exact
, &mask
);
152 assert(ipv6_count_cidr_bits(&dest
) == 128);
159 test_ipv6_static_masks();