FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
sr_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * sr_api.c - ipv6 segment routing api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vnet/sr/sr.h>
22 #include <vlibmemory/api.h>
23 
24 #include <vnet/interface.h>
25 #include <vnet/api_errno.h>
26 #include <vnet/feature/feature.h>
27 
28 #include <vnet/vnet_msg_enum.h>
29 
30 #define vl_typedefs /* define message structures */
31 #include <vnet/vnet_all_api_h.h>
32 #undef vl_typedefs
33 
34 #define vl_endianfun /* define message structures */
35 #include <vnet/vnet_all_api_h.h>
36 #undef vl_endianfun
37 
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
40 #define vl_printfun
41 #include <vnet/vnet_all_api_h.h>
42 #undef vl_printfun
43 
45 
46 #define foreach_vpe_api_msg \
47 _(SR_LOCALSID_ADD_DEL, sr_localsid_add_del) \
48 _(SR_POLICY_DEL, sr_policy_del) \
49 _(SR_STEERING_ADD_DEL, sr_steering_add_del)
50 //_(SR_LOCALSIDS, sr_localsids_dump)
51 //_(SR_LOCALSID_BEHAVIORS, sr_localsid_behaviors_dump)
52 
55 {
57  int rv = 0;
58 /*
59  * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr,
60  * char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table,
61  * ip46_address_t *nh_addr, void *ls_plugin_mem)
62  */
63  rv = sr_cli_localsid (mp->is_del,
64  (ip6_address_t *) & mp->localsid_addr,
65  mp->end_psp,
66  mp->behavior,
67  ntohl (mp->sw_if_index),
68  ntohl (mp->vlan_index),
69  ntohl (mp->fib_table),
70  (ip46_address_t *) & mp->nh_addr, NULL);
71 
72  REPLY_MACRO (VL_API_SR_LOCALSID_ADD_DEL_REPLY);
73 }
74 
75 static void
77 {
79  ip6_address_t *segments = 0, *seg;
80  ip6_address_t *this_address = (ip6_address_t *) mp->segments;
81 
82  int i;
83  for (i = 0; i < mp->n_segments; i++)
84  {
85  vec_add2 (segments, seg, 1);
86  clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
87  this_address++;
88  }
89 
90 /*
91  * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
92  * u32 weight, u8 behavior, u32 fib_table, u8 is_encap)
93  */
94  int rv = 0;
95  rv = sr_policy_add ((ip6_address_t *) & mp->bsid_addr,
96  segments,
97  ntohl (mp->weight),
98  mp->type, ntohl (mp->fib_table), mp->is_encap);
99 
100  REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY);
101 }
102 
103 static void
105 {
107 
108  ip6_address_t *segments = 0, *seg;
109  ip6_address_t *this_address = (ip6_address_t *) mp->segments;
110 
111  int i;
112  for (i = 0; i < mp->n_segments; i++)
113  {
114  vec_add2 (segments, seg, 1);
115  clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
116  this_address++;
117  }
118 
119  int rv = 0;
120 /*
121  * int
122  * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table,
123  * u8 operation, ip6_address_t *segments, u32 sl_index,
124  * u32 weight, u8 is_encap)
125  */
126  rv = sr_policy_mod ((ip6_address_t *) & mp->bsid_addr,
127  ntohl (mp->sr_policy_index),
128  ntohl (mp->fib_table),
129  mp->operation,
130  segments, ntohl (mp->sl_index), ntohl (mp->weight));
131 
132  REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY);
133 }
134 
135 static void
137 {
139  int rv = 0;
140 /*
141  * int
142  * sr_policy_del (ip6_address_t *bsid, u32 index)
143  */
144  rv = sr_policy_del ((ip6_address_t *) & mp->bsid_addr,
145  ntohl (mp->sr_policy_index));
146 
147  REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY);
148 }
149 
152 {
154  int rv = 0;
155 /*
156  * int
157  * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index,
158  * u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index,
159  * u8 traffic_type)
160  */
161  rv = sr_steering_policy (mp->is_del,
162  (ip6_address_t *) & mp->bsid_addr,
163  ntohl (mp->sr_policy_index),
164  ntohl (mp->table_id),
165  (ip46_address_t *) & mp->prefix_addr,
166  ntohl (mp->mask_width),
167  ntohl (mp->sw_if_index), mp->traffic_type);
168 
169  REPLY_MACRO (VL_API_SR_STEERING_ADD_DEL_REPLY);
170 }
171 
172 /*
173  * sr_api_hookup
174  * Add vpe's API message handlers to the table.
175  * vlib has alread mapped shared memory and
176  * added the client registration handlers.
177  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
178  */
179 #define vl_msg_name_crc_list
180 #include <vnet/vnet_all_api_h.h>
181 #undef vl_msg_name_crc_list
182 
183 static void
185 {
186 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
187  foreach_vl_msg_name_crc_sr;
188 #undef _
189 }
190 
191 static clib_error_t *
193 {
194  api_main_t *am = &api_main;
195 
196 #define _(N,n) \
197  vl_msg_api_set_handlers(VL_API_##N, #n, \
198  vl_api_##n##_t_handler, \
199  vl_noop_handler, \
200  vl_api_##n##_t_endian, \
201  vl_api_##n##_t_print, \
202  sizeof(vl_api_##n##_t), 1);
204 #undef _
205 
206  /*
207  * Manually register the sr policy add msg, so we trace
208  * enough bytes to capture a typical segment list
209  */
210  vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD,
211  "sr_policy_add",
214  vl_api_sr_policy_add_t_endian,
216 
217  /*
218  * Manually register the sr policy mod msg, so we trace
219  * enough bytes to capture a typical segment list
220  */
221  vl_msg_api_set_handlers (VL_API_SR_POLICY_MOD,
222  "sr_policy_mod",
225  vl_api_sr_policy_mod_t_endian,
227 
228  /*
229  * Set up the (msg_name, crc, message-id) table
230  */
232 
233  return 0;
234 }
235 
237 
238 /*
239  * fd.io coding-style-patch-verification: ON
240  *
241  * Local Variables:
242  * eval: (c-set-style "gnu")
243  * End:
244  */
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
int sr_cli_localsid(char is_del, ip6_address_t *localsid_addr, char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, ip46_address_t *nh_addr, void *ls_plugin_mem)
SR localsid add/del.
Definition: sr_localsid.c:66
u8 as_u8[16]
Definition: ip6_packet.h:48
int sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index, u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index, u8 traffic_type)
Steer traffic L2 and L3 traffic through a given SR policy.
Definition: sr_steering.c:60
#define NULL
Definition: clib.h:55
u8 bsid_addr[16]
Definition: sr.api:66
static void vl_api_sr_policy_add_t_handler(vl_api_sr_policy_add_t *mp)
Definition: sr_api.c:76
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:561
IPv6 SR Policy modification request response.
Definition: sr.api:115
api_main_t api_main
Definition: api_shared.c:35
static void vl_api_sr_steering_add_del_t_handler(vl_api_sr_steering_add_del_t *mp)
Definition: sr_api.c:151
static void * vl_api_sr_policy_add_t_print(vl_api_sr_policy_add_t *mp, void *handle)
Definition: custom_dump.c:1083
void vl_msg_api_set_handlers(int msg_id, char *msg_name, void *handler, void *cleanup, void *endian, void *print, int msg_size, int traced)
Definition: api_shared.c:684
static void vl_api_sr_policy_mod_t_handler(vl_api_sr_policy_mod_t *mp)
Definition: sr_api.c:104
static void setup_message_id_table(api_main_t *am)
Definition: sr_api.c:184
#define REPLY_MACRO(t)
VLIB_API_INIT_FUNCTION(sr_api_hookup)
vlib_main_t * vm
Definition: buffer.c:276
int sr_policy_del(ip6_address_t *bsid, u32 index)
Delete a SR policy.
IPv6 SR Policy add request response.
Definition: sr.api:79
int sr_policy_add(ip6_address_t *bsid, ip6_address_t *segments, u32 weight, u8 behavior, u32 fib_table, u8 is_encap)
Create a new SR policy.
#define clib_memcpy(a, b, c)
Definition: string.h:69
IPv6 SR steering add/del.
Definition: sr.api:157
IPv6 SR LocalSID add/del request response.
Definition: sr.api:46
IPv6 SR policy deletion.
Definition: sr.api:127
#define foreach_vpe_api_msg
Definition: sr_api.c:46
static void * vl_api_sr_policy_mod_t_print(vl_api_sr_policy_mod_t *mp, void *handle)
Definition: custom_dump.c:1125
IPv6 SR steering add/del request response.
Definition: sr.api:175
IPv6 SR policy add.
Definition: sr.api:62
IPv6 SR Policy deletion request response.
Definition: sr.api:139
static void vl_api_sr_policy_del_t_handler(vl_api_sr_policy_del_t *mp)
Definition: sr_api.c:136
static clib_error_t * sr_api_hookup(vlib_main_t *vm)
Definition: sr_api.c:192
Segment Routing data structures definitions.
void vl_noop_handler(void *mp)
Definition: api_shared.c:739
IPv6 SR policy modification.
Definition: sr.api:97
static void vl_api_sr_localsid_add_del_t_handler(vl_api_sr_localsid_add_del_t *mp)
Definition: sr_api.c:54
IPv6 SR LocalSID add/del request.
Definition: sr.api:28
int sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table, u8 operation, ip6_address_t *segments, u32 sl_index, u32 weight)
Modify an existing SR policy.