FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
sr_mpls_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. Licensed under the Apache
6  * License, Version 2.0 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations
15  * under the License.
16  * ------------------------------------------------------------------
17  */
18 
19 #include <vnet/vnet.h>
20 #include <vnet/srmpls/sr_mpls.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/feature/feature.h>
26 
27 #include <vnet/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 
45 #define foreach_vpe_api_msg \
46 _(SR_MPLS_POLICY_DEL, sr_mpls_policy_del) \
47 _(SR_MPLS_STEERING_ADD_DEL, sr_mpls_steering_add_del) \
48 _(SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR, sr_mpls_policy_assign_endpoint_color)
49 
50 
51 static void
53 {
54  vl_api_sr_mpls_policy_add_reply_t *rmp;
55 
56  mpls_label_t *segments = 0, *seg;
57  mpls_label_t this_address = 0;
58 
59  int i;
60  for (i = 0; i < mp->n_segments; i++)
61  {
62  vec_add2 (segments, seg, 1);
63  this_address = ntohl (mp->segments[i]);
64  clib_memcpy (seg, &this_address, sizeof (this_address));
65  }
66 
67  int rv = 0;
68  rv = sr_mpls_policy_add (ntohl (mp->bsid),
69  segments, mp->type, ntohl (mp->weight));
70 
71  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ADD_REPLY);
72 }
73 
74 static void
76 {
77  vl_api_sr_mpls_policy_mod_reply_t *rmp;
78 
79  mpls_label_t *segments = 0, *seg;
80  mpls_label_t this_address = 0;
81 
82  int i;
83  for (i = 0; i < mp->n_segments; i++)
84  {
85  vec_add2 (segments, seg, 1);
86  this_address = ntohl (mp->segments[i]);
87  clib_memcpy (seg, &this_address, sizeof (this_address));
88  }
89 
90  int rv = 0;
91  rv = sr_mpls_policy_mod (ntohl (mp->bsid),
92  mp->operation, segments, ntohl (mp->sl_index),
93  ntohl (mp->weight));
94 
95  REPLY_MACRO (VL_API_SR_MPLS_POLICY_MOD_REPLY);
96 }
97 
98 static void
100 {
101  vl_api_sr_mpls_policy_del_reply_t *rmp;
102  int rv = 0;
103  rv = sr_mpls_policy_del (ntohl (mp->bsid));
104 
105  REPLY_MACRO (VL_API_SR_MPLS_POLICY_DEL_REPLY);
106 }
107 
110 {
111  vl_api_sr_mpls_steering_add_del_reply_t *rmp;
112  ip46_address_t prefix;
113  memset (&prefix, 0, sizeof (ip46_address_t));
114  if (mp->traffic_type == SR_STEER_IPV4)
115  memcpy (&prefix.ip4, mp->prefix_addr, sizeof (prefix.ip4));
116  else
117  memcpy (&prefix, mp->prefix_addr, sizeof (prefix.ip6));
118 
119  int rv = 0;
120  if (mp->is_del)
121  rv = sr_mpls_steering_policy_del (&prefix,
122  ntohl (mp->mask_width),
123  mp->traffic_type,
124  ntohl (mp->table_id),
125  ntohl (mp->color));
126  else
127  rv = sr_mpls_steering_policy_add (ntohl (mp->bsid),
128  ntohl (mp->table_id),
129  &prefix,
130  ntohl (mp->mask_width),
131  mp->traffic_type,
132  (ip46_address_t *) & mp->next_hop,
133  mp->nh_type,
134  ntohl (mp->color), mp->co_bits,
135  ntohl (mp->vpn_label));
136 
137  REPLY_MACRO (VL_API_SR_MPLS_STEERING_ADD_DEL_REPLY);
138 }
139 
142 {
143  vl_api_sr_mpls_policy_assign_endpoint_color_reply_t *rmp;
144  int rv = 0;
145 
146  ip46_address_t endpoint;
147  memset (&endpoint, 0, sizeof (ip46_address_t));
148  if (mp->endpoint_type == SR_STEER_IPV4)
149  memcpy (&endpoint.ip4, mp->endpoint, sizeof (endpoint.ip4));
150  else
151  memcpy (&endpoint, mp->endpoint, sizeof (endpoint.ip6));
152 
153  rv = sr_mpls_policy_assign_endpoint_color (ntohl (mp->bsid),
154  &endpoint, mp->endpoint_type,
155  ntohl (mp->color));
156 
157  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR_REPLY);
158 }
159 
160 /*
161  * sr_mpls_api_hookup Add vpe's API message handlers to the table. vlib has
162  * alread mapped shared memory and added the client registration handlers.
163  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
164  */
165 #define vl_msg_name_crc_list
166 #include <vnet/vnet_all_api_h.h>
167 #undef vl_msg_name_crc_list
168 
169 static void
171 {
172 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
173  foreach_vl_msg_name_crc_sr_mpls;
174 #undef _
175 }
176 
177 static clib_error_t *
179 {
180  api_main_t *am = &api_main;
181 
182 #define _(N,n) \
183  vl_msg_api_set_handlers(VL_API_##N, #n, \
184  vl_api_##n##_t_handler, \
185  vl_noop_handler, \
186  vl_api_##n##_t_endian, \
187  vl_api_##n##_t_print, \
188  sizeof(vl_api_##n##_t), 1);
190 #undef _
191 
192  /*
193  * Manually register the sr policy add msg, so we trace enough bytes
194  * to capture a typical segment list
195  */
196  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_ADD,
197  "sr_mpls_policy_add",
200  vl_api_sr_mpls_policy_add_t_endian,
201  vl_api_sr_mpls_policy_add_t_print, 256, 1);
202 
203  /*
204  * Manually register the sr policy mod msg, so we trace enough bytes
205  * to capture a typical segment list
206  */
207  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_MOD,
208  "sr_mpls_policy_mod",
211  vl_api_sr_mpls_policy_mod_t_endian,
212  vl_api_sr_mpls_policy_mod_t_print, 256, 1);
213 
214  /*
215  * Set up the (msg_name, crc, message-id) table
216  */
218 
219  return 0;
220 }
221 
223 
224 /*
225  * fd.io coding-style-patch-verification: ON
226  *
227  * Local Variables: eval: (c-set-style "gnu") End:
228  */
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
#define SR_STEER_IPV4
Definition: sr_mpls.h:41
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:557
MPLS SR steering add/del.
Definition: sr_mpls.api:88
MPLS SR policy modification.
Definition: sr_mpls.api:48
static void vl_api_sr_mpls_policy_mod_t_handler(vl_api_sr_mpls_policy_mod_t *mp)
Definition: sr_mpls_api.c:75
static void vl_api_sr_mpls_steering_add_del_t_handler(vl_api_sr_mpls_steering_add_del_t *mp)
Definition: sr_mpls_api.c:109
static clib_error_t * sr_mpls_api_hookup(vlib_main_t *vm)
Definition: sr_mpls_api.c:178
int sr_mpls_policy_add(mpls_label_t bsid, mpls_label_t *segments, u8 behavior, u32 weight)
Create a new SR policy.
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:170
#define REPLY_MACRO(t)
int sr_mpls_steering_policy_del(ip46_address_t *prefix, u32 mask_width, u8 traffic_type, u32 table_id, u32 color)
Delete steering rule for an SR-MPLS policy.
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:198
api_main_t api_main
Definition: api_shared.c:35
vlib_main_t * vm
Definition: buffer.c:283
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:713
#define clib_memcpy(a, b, c)
Definition: string.h:75
void vl_noop_handler(void *mp)
Definition: api_shared.c:780
static void vl_api_sr_mpls_policy_del_t_handler(vl_api_sr_mpls_policy_del_t *mp)
Definition: sr_mpls_api.c:99
u32 segments[n_segments]
Definition: sr_mpls.api:57
u32 segments[n_segments]
Definition: sr_mpls.api:33
int sr_mpls_policy_del(mpls_label_t bsid)
Delete a SR policy.
MPLS SR policy add.
Definition: sr_mpls.api:25
#define foreach_vpe_api_msg
Definition: sr_mpls_api.c:45
static void vl_api_sr_mpls_policy_assign_endpoint_color_t_handler(vl_api_sr_mpls_policy_assign_endpoint_color_t *mp)
Definition: sr_mpls_api.c:141
VLIB_API_INIT_FUNCTION(sr_mpls_api_hookup)
static void vl_api_sr_mpls_policy_add_t_handler(vl_api_sr_mpls_policy_add_t *mp)
Definition: sr_mpls_api.c:52
MPLS SR policy deletion.
Definition: sr_mpls.api:65
int sr_mpls_policy_assign_endpoint_color(mpls_label_t bsid, ip46_address_t *endpoint, u8 endpoint_type, u32 color)
Update the Endpoint,Color tuple of an SR policy.
Segment Routing MPLS data structures definitions.
int sr_mpls_policy_mod(mpls_label_t bsid, u8 operation, mpls_label_t *segments, u32 sl_index, u32 weight)
Modify an existing SR policy.
int sr_mpls_steering_policy_add(mpls_label_t bsid, u32 table_id, ip46_address_t *prefix, u32 mask_width, u8 traffic_type, ip46_address_t *next_hop, u8 nh_type, u32 color, char co_bits, mpls_label_t vpn_label)
Steer traffic L3 traffic through a given SR-MPLS policy.