Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
parser.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 
16 #ifndef __HICN_PARSER_H__
17 #define __HICN_PARSER_H__
18 
19 #include <vlib/vlib.h>
20 
21 #include "hicn.h"
22 #include "error.h"
23 
28 /*
29  * Key type codes for header, header tlvs, body tlvs, and child tlvs
30  */
31 
32 // FIXME(reuse lib struct, no more control ?)
33 enum hicn_pkt_type_e
34 {
35  HICN_PKT_TYPE_INTEREST = 0,
36  HICN_PKT_TYPE_CONTENT = 1,
37 };
38 
48 always_inline int
49 hicn_interest_parse_pkt (vlib_buffer_t *pkt, hicn_name_t *name, u16 *namelen,
50  hicn_header_t **pkt_hdrp, u8 *isv6)
51 {
52  if (pkt == NULL)
53  return HICN_ERROR_PARSER_PKT_INVAL;
54  hicn_header_t *pkt_hdr = vlib_buffer_get_current (pkt);
55  *pkt_hdrp = pkt_hdr;
56  u8 *ip_pkt = vlib_buffer_get_current (pkt);
57  *isv6 = hicn_is_v6 (pkt_hdr);
58  u8 ip_proto = (*isv6) * IPPROTO_IPV6;
59  u8 next_proto_offset = 6 + (1 - *isv6) * 3;
60  // in the ipv6 header the next header field is at byte 6
61  // in the ipv4 header the protocol field is at byte 9
62  hicn_type_t type = (hicn_type_t){ { .l4 = IPPROTO_NONE,
63  .l3 = IPPROTO_NONE,
64  .l2 = ip_pkt[next_proto_offset],
65  .l1 = ip_proto } };
66  hicn_get_buffer (pkt)->type = type;
67 
68  hicn_ops_vft[type.l1]->get_interest_name (type, &pkt_hdr->protocol, name);
69  *namelen = (1 - (*isv6)) * HICN_V4_NAME_LEN + (*isv6) * HICN_V6_NAME_LEN;
70 
71  return HICN_ERROR_NONE;
72 }
73 
83 always_inline int
84 hicn_data_parse_pkt (vlib_buffer_t *pkt, hicn_name_t *name, u16 *namelen,
85  hicn_header_t **pkt_hdrp, u8 *isv6)
86 {
87  if (pkt == NULL)
88  return HICN_ERROR_PARSER_PKT_INVAL;
89  hicn_header_t *pkt_hdr = vlib_buffer_get_current (pkt);
90  *pkt_hdrp = pkt_hdr;
91  *pkt_hdrp = pkt_hdr;
92  u8 *ip_pkt = vlib_buffer_get_current (pkt);
93  *isv6 = hicn_is_v6 (pkt_hdr);
94  u8 ip_proto = (*isv6) * IPPROTO_IPV6;
95  /*
96  * in the ipv6 header the next header field is at byte 6 in the ipv4
97  * header the protocol field is at byte 9
98  */
99  u8 next_proto_offset = 6 + (1 - *isv6) * 3;
100  hicn_type_t type = (hicn_type_t){ { .l4 = IPPROTO_NONE,
101  .l3 = IPPROTO_NONE,
102  .l2 = ip_pkt[next_proto_offset],
103  .l1 = ip_proto } };
104  hicn_get_buffer (pkt)->type = type;
105  hicn_ops_vft[type.l1]->get_data_name (type, &pkt_hdr->protocol, name);
106  *namelen = (1 - (*isv6)) * HICN_V4_NAME_LEN + (*isv6) * HICN_V6_NAME_LEN;
107 
108  return HICN_ERROR_NONE;
109 }
110 
111 #endif /* // __HICN_PARSER_H__ */
112 
113 /*
114  * fd.io coding-style-patch-verification: ON
115  *
116  * Local Variables: eval: (c-set-style "gnu") End:
117  */
hicn_ops_s::get_interest_name
int(* get_interest_name)(hicn_type_t type, const hicn_protocol_t *h, hicn_name_t *name)
Retrieves an Interest name.
Definition: ops.h:74
hicn_header_t
Definition: header.h:91
hicn.h
hicn_type_t
hICN packet format type
Definition: base.h:56
error.h
hicn_data_parse_pkt
always_inline int hicn_data_parse_pkt(vlib_buffer_t *pkt, hicn_name_t *name, u16 *namelen, hicn_header_t **pkt_hdrp, u8 *isv6)
Parse a data packet.
Definition: parser.h:84
hicn_type_t::l4
u8 l4
Definition: base.h:65
hicn_type_t::l1
u8 l1
Definition: base.h:62
hicn_name_t
Definition: name.h:115
hicn_interest_parse_pkt
always_inline int hicn_interest_parse_pkt(vlib_buffer_t *pkt, hicn_name_t *name, u16 *namelen, hicn_header_t **pkt_hdrp, u8 *isv6)
Parse an interest packet.
Definition: parser.h:49
hicn_ops_s::get_data_name
int(* get_data_name)(hicn_type_t type, const hicn_protocol_t *h, hicn_name_t *name)
Retrieves a Data name.
Definition: ops.h:158