Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
21 #ifndef HICN_BASE_H
22 #define HICN_BASE_H
23 
24 #include "common.h"
25 #ifdef _WIN32
26 #include <Winsock2.h>
27 #else
28 #include <netinet/in.h>
29 #endif
30 /* Default header fields */
31 #define HICN_DEFAULT_TTL 254
32 
33 typedef u32 hicn_faceid_t;
34 typedef u8 hicn_pathlabel_t;
35 typedef u32 hicn_lifetime_t;
36 
37 #define HICN_MAX_LIFETIME_SCALED 0xFFFF
38 #define HICN_MAX_LIFETIME_MULTIPLIER 0x0F /* 4 bits */
39 #define HICN_MAX_LIFETIME HICN_MAX_LIFETIME_SCALED << HICN_MAX_LIFETIME_MULTIPLIER
40 
56 typedef union
57 {
59  struct
60  {
61 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
62  u8 l1;
63  u8 l2;
64  u8 l3;
65  u8 l4;
66 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
67  u8 l4;
68  u8 l3;
69  u8 l2;
70  u8 l1;
71 #elif _WIN32 /* Windows is assumed little-endian */
72  u8 l1;
73  u8 l2;
74  u8 l3;
75  u8 l4;
76 #else
77 #error "Unsupported endianness"
78 #endif
79  };
81  u32 as_u32;
82 } hicn_type_t;
83 
84 /* Common protocol layers */
85 /* Common protocol layers */
86 #ifndef _WIN32
87 #define HICN_TYPE(x,y,z,t) (hicn_type_t) {{ .l1 = x, .l2 = y, .l3 = z, .l4 = t }}
88 #else
89 inline hicn_type_t
90 HICN_TYPE(int x, int y, int z, int t)
91 {
92  hicn_type_t type;
93  type.l1 = x;
94  type.l2 = y;
95  type.l3 = z;
96  type.l4 = t;
97  return type;
98 }
99 #endif
100 
101 #define HICN_TYPE_IPV4_TCP HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE)
102 #define HICN_TYPE_IPV4_ICMP HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE)
103 #define HICN_TYPE_IPV6_TCP HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE)
104 #define HICN_TYPE_IPV6_ICMP HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE)
105 #define HICN_TYPE_IPV4_TCP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE)
106 #define HICN_TYPE_IPV4_ICMP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE)
107 #define HICN_TYPE_IPV6_TCP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE)
108 #define HICN_TYPE_IPV6_ICMP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE)
109 #define HICN_TYPE_NONE HICN_TYPE(IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE)
110 
115 always_inline int
117 {
118  return (type.l1 == IPPROTO_NONE) && (type.l2 == IPPROTO_NONE) &&
119  (type.l3 == IPPROTO_NONE) && (type.l4 == IPPROTO_NONE);
120 }
121 
128 typedef enum
129 {
130  HPT_DATA = 0,
131  HPT_MANIFEST = 1,
132  HPT_UNSPEC = 999
134 
145 #define HICN_PATH_LABEL_MASK 0x000000ff
146 #define HICN_PATH_LABEL_SIZE 8
147 
156 always_inline void
157 update_pathlabel (hicn_pathlabel_t current_label, hicn_faceid_t face_id,
158  hicn_pathlabel_t * new_label)
159 {
160  hicn_pathlabel_t pl_face_id =
161  (hicn_pathlabel_t) (face_id & HICN_PATH_LABEL_MASK);
162 
163  *new_label =
164  ((current_label << 1) | (current_label >> (HICN_PATH_LABEL_SIZE - 1))) ^
165  pl_face_id;
166 }
167 
168 #endif /* HICN_BASE_H */
169 
170 /*
171  * fd.io coding-style-patch-verification: ON
172  *
173  * Local Variables:
174  * eval: (c-set-style "gnu")
175  * End:
176  */
HICN_PATH_LABEL_MASK
#define HICN_PATH_LABEL_MASK
Path label computations.
Definition: base.h:145
hicn_type_t
hICN packet format type
Definition: base.h:56
hicn_type_t::l4
u8 l4
Definition: base.h:65
hicn_type_t::l1
u8 l1
Definition: base.h:62
hicn_type_t::l3
u8 l3
Definition: base.h:64
hicn_payload_type_t
hicn_payload_type_t
hICN Payload type
Definition: base.h:128
update_pathlabel
always_inline void update_pathlabel(hicn_pathlabel_t current_label, hicn_faceid_t face_id, hicn_pathlabel_t *new_label)
Path label update.
Definition: base.h:157
hicn_type_is_none
always_inline int hicn_type_is_none(hicn_type_t type)
Check if type is none.
Definition: base.h:116
hicn_type_t::l2
u8 l2
Definition: base.h:63