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