6b1627b6493005d8f0590079ea865d4ff8dd08b3
[vpp.git] / src / plugins / nsh / nsh-md2-ioam / export-nsh-md2-ioam / nsh_md2_ioam_node.c
1 /*
2  * Copyright (c) 2017 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 #include <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vnet/pg/pg.h>
18 #include <vppinfra/error.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/ip/ip.h>
21 #include <nsh/nsh.h>
22 #include <nsh/nsh_packet.h>
23 #include <ioam/export-common/ioam_export.h>
24
25 typedef struct
26 {
27   u32 next_index;
28   u32 flow_label;
29 } export_trace_t;
30
31 extern ioam_export_main_t nsh_md2_ioam_export_main;
32 vlib_node_registration_t export_node;
33 /* packet trace format function */
34 static u8 *
35 format_export_trace (u8 * s, va_list * args)
36 {
37   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
38   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
39   export_trace_t *t = va_arg (*args, export_trace_t *);
40
41   s = format (s, "EXPORT: flow_label %d, next index %d",
42               t->flow_label, t->next_index);
43   return s;
44 }
45
46 vlib_node_registration_t nsh_md2_ioam_export_node;
47
48 #define foreach_export_error \
49 _(RECORDED, "Packets recorded for export")
50
51 typedef enum
52 {
53 #define _(sym,str) EXPORT_ERROR_##sym,
54   foreach_export_error
55 #undef _
56     EXPORT_N_ERROR,
57 } export_error_t;
58
59 static char *export_error_strings[] = {
60 #define _(sym,string) string,
61   foreach_export_error
62 #undef _
63 };
64
65 typedef enum
66 {
67   EXPORT_NEXT_NSH_MD2_IOAM_INPUT,
68   EXPORT_N_NEXT,
69 } export_next_t;
70
71 always_inline void
72 copy3cachelines (void *dst, const void *src, size_t n)
73 {
74
75   u64 *copy_dst, *copy_src;
76   int i;
77   copy_dst = (u64 *) dst;
78   copy_src = (u64 *) src;
79   if (PREDICT_FALSE (n < DEFAULT_EXPORT_SIZE))
80     {
81       for (i = 0; i < n / 64; i++)
82         {
83           copy_dst[0] = copy_src[0];
84           copy_dst[1] = copy_src[1];
85           copy_dst[2] = copy_src[2];
86           copy_dst[3] = copy_src[3];
87           copy_dst[4] = copy_src[4];
88           copy_dst[5] = copy_src[5];
89           copy_dst[6] = copy_src[6];
90           copy_dst[7] = copy_src[7];
91           copy_dst += 8;
92           copy_src += 8;
93         }
94       return;
95     }
96   for (i = 0; i < 3; i++)
97     {
98       copy_dst[0] = copy_src[0];
99       copy_dst[1] = copy_src[1];
100       copy_dst[2] = copy_src[2];
101       copy_dst[3] = copy_src[3];
102       copy_dst[4] = copy_src[4];
103       copy_dst[5] = copy_src[5];
104       copy_dst[6] = copy_src[6];
105       copy_dst[7] = copy_src[7];
106       copy_dst += 8;
107       copy_src += 8;
108     }
109 }
110
111 static void
112 nsh_md2_ioam_export_fixup_func (vlib_buffer_t * export_buf,
113                                 vlib_buffer_t * pak_buf)
114 {
115   /* Todo: on implementing analyse */
116 }
117
118 static uword
119 nsh_md2_ioam_export_node_fn (vlib_main_t * vm,
120                              vlib_node_runtime_t * node, vlib_frame_t * frame)
121 {
122   ioam_export_main_t *em = &nsh_md2_ioam_export_main;
123   ioam_export_node_common (em, vm, node, frame, ip4_header_t, length,
124                            ip_version_and_header_length,
125                            EXPORT_NEXT_NSH_MD2_IOAM_INPUT,
126                            nsh_md2_ioam_export_fixup_func);
127   return frame->n_vectors;
128 }
129
130 /*
131  * Node for iOAM export
132  */
133 /* *INDENT-OFF* */
134 VLIB_REGISTER_NODE (nsh_md2_ioam_export_node) =
135 {
136   .function = nsh_md2_ioam_export_node_fn,
137   .name = "nsh-md2-ioam-export",
138   .vector_size = sizeof (u32),
139   .format_trace = format_export_trace,
140   .type = VLIB_NODE_TYPE_INTERNAL,
141   .n_errors = ARRAY_LEN (export_error_strings),
142   .error_strings = export_error_strings,
143   .n_next_nodes = EXPORT_N_NEXT,
144     /* edit / add dispositions here */
145     .next_nodes =
146   {[EXPORT_NEXT_NSH_MD2_IOAM_INPUT] = "nsh-pop"},
147 };
148 /* *INDENT-ON* */
149
150 /*
151  * fd.io coding-style-patch-verification: ON
152  *
153  * Local Variables:
154  * eval: (c-set-style "gnu")
155  * End:
156  */