2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/vnet.h>
17 #include <vppinfra/error.h>
18 #include <vnet/lisp-cp/lisp_types.h>
19 #include <vnet/lisp-cp/lisp_cp_messages.h>
22 error = CLIB_ERROR_ASSERT (e); \
26 static clib_error_t * test_locator_type (void)
28 clib_error_t * error = 0;
29 gid_address_t _gid_addr, * gid_addr = &_gid_addr;
30 gid_address_type(gid_addr) = IP_PREFIX;
31 gid_address_ippref_len(gid_addr) = 24;
32 ip_prefix_version(&gid_addr->ippref) = IP4;
33 gid_addr->ippref.addr.ip.v4.as_u32 = 0x20304050;
36 locator_t loc1, loc2 = {
45 locator_copy (&loc1, &loc2);
46 _assert (0 == locator_cmp (&loc1, &loc2));
50 loc2.address = gid_addr[0];
51 locator_copy(&loc1, &loc2);
53 _assert (0 == locator_cmp (&loc1, &loc2));
59 static clib_error_t * test_gid_parse ()
61 clib_error_t * error = 0;
65 static clib_error_t * test_format_unformat_gid_address (void)
68 clib_error_t * error = 0;
69 unformat_input_t _input;
70 unformat_input_t * input = &_input;
71 gid_address_t _gid_addr, * gid_addr = &_gid_addr;
72 gid_address_t unformated_gid;
74 /* format/unformat IPv4 global ID address */
75 gid_address_type(gid_addr) = IP_PREFIX;
76 gid_address_ippref_len(gid_addr) = 24;
77 ip_prefix_version(&gid_addr->ippref) = IP4;
78 gid_addr->ippref.addr.ip.v4.as_u32 = 0x20304050;
80 s = format(0, "%U", format_gid_address, gid_addr);
82 unformat_init_string(input, (char *)s, vec_len(s));
84 _assert (unformat(input, "%U",
85 unformat_gid_address, &unformated_gid));
86 _assert (0 == gid_address_cmp (&unformated_gid, gid_addr));
92 /* format/unformat IPv6 global ID address */
93 gid_address_type(gid_addr) = IP_PREFIX;
94 gid_address_ippref_len(gid_addr) = 64;
95 ip_prefix_version(&gid_addr->ippref) = IP6;
96 u8 ipv6[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
97 memcpy(gid_addr->ippref.addr.ip.v6.as_u8, ipv6, sizeof(ipv6));
99 s = format(0, "%U", format_gid_address, gid_addr);
101 unformat_init_string(input, (char *)s, vec_len(s));
103 _assert (unformat (input, "%U", unformat_gid_address,
105 _assert (0 == gid_address_cmp(&unformated_gid, gid_addr));
107 /* test address copy */
108 gid_address_t gid_addr_copy;
109 gid_address_copy(&gid_addr_copy, gid_addr);
110 _assert (0 == gid_address_cmp (&gid_addr_copy, gid_addr));
113 unformat_free(input);
118 #define foreach_test_case \
119 _(format_unformat_gid_address) \
125 clib_error_t * error;
127 #define _(_test_name) \
128 error = test_ ## _test_name (); \
131 clib_error_report (error); \