Move iOAM Trace as a plugin
[vpp.git] / vnet / vnet / ip / ip6_hop_by_hop.h
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_ip6_hop_by_hop_ioam_h__
16 #define __included_ip6_hop_by_hop_ioam_h__
17
18 #include <vnet/ip/ip6_hop_by_hop.h>
19 #include <vnet/ip/ip6_hop_by_hop_packet.h>
20 #include <vnet/ip/ip.h>
21
22 typedef struct {
23   /* The current rewrite we're using */
24   u8 * rewrite;
25
26   /* Trace data processing callback */
27   void *ioam_end_of_path_cb;
28   /* Configuration data */
29   /* Adjacency */
30   ip6_address_t adj;
31 #define IOAM_HBYH_ADD  0
32 #define IOAM_HBYH_MOD  1
33 #define IOAM_HBYH_POP  2
34   u8 ioam_flag;
35   /* time scale transform. Joy. */
36   u32 unix_time_0;
37   f64 vlib_time_0;
38
39
40   /* Trace option */
41   u8 has_trace_option;
42
43   /* Pot option */
44   u8 has_pot_option;
45
46 #define PPC_NONE  0
47 #define PPC_ENCAP 1
48 #define PPC_DECAP 2
49   u8 has_ppc_option;
50
51 #define TSP_SECONDS              0
52 #define TSP_MILLISECONDS         1
53 #define TSP_MICROSECONDS         2
54 #define TSP_NANOSECONDS          3
55   
56   /* Array of function pointers to ADD and POP HBH option handling routines */
57   u8 options_size[256];
58   int (*add_options[256])(u8 *rewrite_string, u8 *rewrite_size);
59   int (*pop_options[256])(ip6_header_t *ip, ip6_hop_by_hop_option_t *opt);
60   int (*get_sizeof_options[256])(u32 *rewrite_size);
61   
62   /* convenience */
63   vlib_main_t * vlib_main;
64   vnet_main_t * vnet_main;
65 } ip6_hop_by_hop_ioam_main_t;
66
67 extern ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
68
69 extern u8 * format_path_map(u8 * s, va_list * args);
70 extern clib_error_t *
71 ip6_ioam_enable(int has_trace_option, int has_pot_option,
72                            int has_e2e_option);
73 extern int ip6_ioam_set_destination (ip6_address_t *addr, u32 mask_width,
74                   u32 vrf_id, int is_add, int is_pop, int is_none);
75
76 extern clib_error_t * clear_ioam_rewrite_fn(void);
77
78 static inline u8 is_zero_ip4_address (ip4_address_t *a)
79 {
80   return (a->as_u32 == 0);
81 }
82
83 static inline void copy_ip6_address (ip6_address_t *dst, ip6_address_t *src)
84 {
85   dst->as_u64[0] = src->as_u64[0];
86   dst->as_u64[1] = src->as_u64[1];
87 }
88
89 static inline void set_zero_ip6_address (ip6_address_t *a)
90 {
91   a->as_u64[0] = 0;
92   a->as_u64[1] = 0;
93 }
94
95 static inline u8 cmp_ip6_address (ip6_address_t *a1, ip6_address_t *a2)
96 {
97   return ((a1->as_u64[0] == a2->as_u64[0]) && (a1->as_u64[1] == a2->as_u64[1]));
98 }
99 static inline u8 is_zero_ip6_address (ip6_address_t *a)
100 {
101   return ((a->as_u64[0] == 0) && (a->as_u64[1] == 0));
102 }
103
104 int ip6_hbh_add_register_option (u8 option,
105                                  u8 size,
106                                  int rewrite_options(u8 *rewrite_string, u8 *size));
107 int ip6_hbh_add_unregister_option (u8 option);
108
109 int ip6_hbh_pop_register_option (u8 option,
110                                  int options(ip6_header_t *ip, ip6_hop_by_hop_option_t *opt));
111 int ip6_hbh_pop_unregister_option (u8 option);
112
113 int
114 ip6_hbh_get_sizeof_register_option (u8 option,
115                             int get_sizeof_hdr_options(u32 *rewrite_size));
116
117 int
118 ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option,
119                       int has_pot_option, int has_ppc_option);
120 #endif /* __included_ip6_hop_by_hop_ioam_h__ */