nsh.h revision e556e7c0
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  nsh_map_t map;
48  u8 is_add;
49} nsh_add_del_map_args_t;
50
51typedef struct {
52  u8 is_add;
53  nsh_header_t nsh;
54} nsh_add_del_entry_args_t;
55
56typedef struct {
57  /* API message ID base */
58  u16 msg_id_base;
59
60  /* vector of nsh_header entry instances */
61  nsh_header_t *nsh_entries;
62
63  /* hash lookup nsh header by key: {u32: nsp_nsi} */
64  uword * nsh_entry_by_key;
65
66  /* vector of nsh_mappings */
67  nsh_map_t *nsh_mappings;
68
69  /* hash lookup nsh mapping by key: {u32: nsp_nsi} */
70  uword * nsh_mapping_by_key;
71  uword * nsh_mapping_by_mapped_key; // for use in NSHSFC
72
73  /* convenience */
74  vlib_main_t * vlib_main;
75  vnet_main_t * vnet_main;
76} nsh_main_t;
77
78nsh_main_t nsh_main;
79
80u8 * format_nsh_input_map_trace (u8 * s, va_list * args);
81u8 * format_nsh_header_with_length (u8 * s, va_list * args);
82
83/* Helper macros used in nsh.c and nsh_test.c */
84#define foreach_copy_nshhdr_field               \
85_(ver_o_c)					\
86_(length)					\
87_(md_type)					\
88_(next_protocol)				\
89_(nsp_nsi)					\
90_(c1)						\
91_(c2)						\
92_(c3)						\
93_(c4)
94/* TODO Temp killing tlvs as its causing pain - fix in NSH_SFC */
95#define foreach_32bit_field			\
96_(nsp_nsi)                                      \
97_(c1)                                           \
98_(c2)                                           \
99_(c3)                                           \
100_(c4)
101
102/* Statistics (not really errors) */
103#define foreach_nsh_input_error    \
104_(MAPPED, "NSH header found and mapped") \
105_(NO_MAPPING, "no mapping for nsh key") \
106_(NO_ENTRY, "no entry for nsh key") \
107_(INVALID_NEXT_PROTOCOL, "invalid next protocol") \
108
109typedef enum {
110#define _(sym,str) NSH_INPUT_ERROR_##sym,
111    foreach_nsh_input_error
112#undef _
113  NSH_INPUT_N_ERROR,
114
115} nsh_input_error_t;
116
117#define foreach_nsh_input_next        \
118  _(DROP, "error-drop")			\
119  _(ENCAP_GRE, "gre-input" )		\
120  _(ENCAP_VXLANGPE, "vxlan-gpe-encap" ) \
121/* /\* TODO once moved to Project:NSH_SFC *\/ */
122  /* _(ENCAP_ETHERNET, "*** TX TO ETHERNET ***")   \ */
123/*   _(DECAP_ETHERNET_LOOKUP, "ethernet-input" )	\ */
124/*   _(DECAP_IP4_INPUT,  "ip4-input") \ */
125/*   _(DECAP_IP6_INPUT,  "ip6-input" ) \  */
126
127typedef enum {
128#define _(s,n) NSH_INPUT_NEXT_##s,
129  foreach_nsh_input_next
130#undef _
131  NSH_INPUT_N_NEXT,
132} nsh_input_next_t;
133
134typedef enum {
135  NSH_ACTION_SWAP,
136  NSH_ACTION_PUSH,
137  NSH_ACTION_POP
138};
139
140#endif /* included_nsh_h */
141