nsh.h revision b412048c
1/*
2 * Copyright (c) 2015 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#ifndef included_nsh_h
16#define included_nsh_h
17
18#include <vnet/vnet.h>
19#include <nsh/nsh_packet.h>
20#include <vnet/ip/ip4_packet.h>
21
22typedef struct {
23
24  /** Key for nsh_header_t entry: 24bit NSP 8bit NSI */
25  u32 nsp_nsi;
26
27  /** Key for nsh_header_t entry to map to. : 24bit NSP 8bit NSI
28   *  This may be ~0 if next action is to decap to NSH next protocol
29   *  Note the following heuristic:
30   *  if nsp_nsi == mapped_nsp_nsi then use-case is like SFC SFF
31   *  if nsp_nsi != mapped_nsp_nsi then use-case is like SFC SF
32   *  Note: these are heuristics. Rules about NSI decrement are out of scope
33   */
34  u32 mapped_nsp_nsi;
35
36  /* NSH Header action: swap, push and pop */
37  u32 nsh_action;
38
39  /* vnet intfc sw_if_index */
40  u32 sw_if_index;
41
42  u32 next_node;
43
44} nsh_map_t;
45
46typedef struct {
47
48  u32 transport_type; /* 1:vxlan; */
49
50  u32 transport_index; /* transport's sw_if_index */
51
52} nsh_proxy_session_by_key_t;
53
54typedef struct {
55
56  /* 24bit NSP 8bit NSI */
57  u32 nsp_nsi;
58
59} nsh_proxy_session_t;
60
61typedef struct {
62  nsh_map_t map;
63  u8 is_add;
64} nsh_add_del_map_args_t;
65
66typedef struct {
67  u8 is_add;
68  nsh_header_t nsh;
69} nsh_add_del_entry_args_t;
70
71typedef struct {
72  /* API message ID base */
73  u16 msg_id_base;
74
75  /* vector of nsh_header entry instances */
76  nsh_header_t *nsh_entries;
77
78  /* hash lookup nsh header by key: {u32: nsp_nsi} */
79  uword * nsh_entry_by_key;
80
81  /* vector of nsh_mappings */
82  nsh_map_t *nsh_mappings;
83
84  /* hash lookup nsh mapping by key: {u32: nsp_nsi} */
85  uword * nsh_mapping_by_key;
86  uword * nsh_mapping_by_mapped_key; // for use in NSHSFC
87
88  /* vector of nsh_proxy */
89  nsh_proxy_session_t *nsh_proxy_sessions;
90
91  /* hash lookup nsh_proxy by key */
92  uword * nsh_proxy_session_by_key;
93
94  /* convenience */
95  vlib_main_t * vlib_main;
96  vnet_main_t * vnet_main;
97} nsh_main_t;
98
99nsh_main_t nsh_main;
100
101vlib_node_t * vxlan4_input_node = 0;
102vlib_node_t * vxlan6_input_node = 0;
103
104u8 * format_nsh_input_map_trace (u8 * s, va_list * args);
105u8 * format_nsh_header_with_length (u8 * s, va_list * args);
106
107/* Helper macros used in nsh.c and nsh_test.c */
108#define foreach_copy_nshhdr_field               \
109_(ver_o_c)					\
110_(length)					\
111_(md_type)					\
112_(next_protocol)				\
113_(nsp_nsi)					\
114_(c1)						\
115_(c2)						\
116_(c3)						\
117_(c4)
118/* TODO Temp killing tlvs as its causing pain - fix in NSH_SFC */
119#define foreach_32bit_field			\
120_(nsp_nsi)                                      \
121_(c1)                                           \
122_(c2)                                           \
123_(c3)                                           \
124_(c4)
125
126/* Statistics (not really errors) */
127#define foreach_nsh_node_error    \
128_(MAPPED, "NSH header found and mapped") \
129_(NO_MAPPING, "no mapping for nsh key") \
130_(NO_ENTRY, "no entry for nsh key") \
131_(NO_PROXY, "no proxy for transport key") \
132_(INVALID_NEXT_PROTOCOL, "invalid next protocol") \
133
134typedef enum {
135#define _(sym,str) NSH_NODE_ERROR_##sym,
136  foreach_nsh_node_error
137#undef _
138  NSH_NODE_N_ERROR,
139
140} nsh_input_error_t;
141
142#define foreach_nsh_node_next        \
143  _(DROP, "error-drop")			\
144  _(ENCAP_GRE, "gre-input" )		\
145  _(ENCAP_VXLANGPE, "vxlan-gpe-encap" ) \
146  _(ENCAP_VXLAN4, "vxlan4-encap" )  \
147  _(ENCAP_VXLAN6, "vxlan6-encap" )  \
148/* /\* TODO once moved to Project:NSH_SFC *\/ */
149  /* _(ENCAP_ETHERNET, "*** TX TO ETHERNET ***")   \ */
150/*   _(DECAP_ETHERNET_LOOKUP, "ethernet-input" )	\ */
151/*   _(DECAP_IP4_INPUT,  "ip4-input") \ */
152/*   _(DECAP_IP6_INPUT,  "ip6-input" ) \  */
153
154typedef enum {
155#define _(s,n) NSH_NODE_NEXT_##s,
156  foreach_nsh_node_next
157#undef _
158  NSH_NODE_N_NEXT,
159} nsh_node_next_t;
160
161typedef enum {
162  NSH_ACTION_SWAP,
163  NSH_ACTION_PUSH,
164  NSH_ACTION_POP
165};
166
167typedef enum {
168  NSH_INPUT_TYPE,
169  NSH_PROXY_TYPE
170};
171
172#endif /* included_nsh_h */
173