FD.io VPP  v19.04.4-rc0-5-ge88582fac
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  vec_free (segments);
71 
72  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ADD_REPLY);
73 }
74 
75 static void
77 {
78  vl_api_sr_mpls_policy_mod_reply_t *rmp;
79 
80  mpls_label_t *segments = 0, *seg;
81  mpls_label_t this_address = 0;
82 
83  int i;
84  for (i = 0; i < mp->n_segments; i++)
85  {
86  vec_add2 (segments, seg, 1);
87  this_address = ntohl (mp->segments[i]);
88  clib_memcpy (seg, &this_address, sizeof (this_address));
89  }
90 
91  int rv = 0;
92  rv = sr_mpls_policy_mod (ntohl (mp->bsid),
93  mp->operation, segments, ntohl (mp->sl_index),
94  ntohl (mp->weight));
95  vec_free (segments);
96 
97  REPLY_MACRO (VL_API_SR_MPLS_POLICY_MOD_REPLY);
98 }
99 
100 static void
102 {
103  vl_api_sr_mpls_policy_del_reply_t *rmp;
104  int rv = 0;
105  rv = sr_mpls_policy_del (ntohl (mp->bsid));
106 
107  REPLY_MACRO (VL_API_SR_MPLS_POLICY_DEL_REPLY);
108 }
109 
112 {
113  vl_api_sr_mpls_steering_add_del_reply_t *rmp;
114  ip46_address_t prefix;
115  clib_memset (&prefix, 0, sizeof (ip46_address_t));
116  if (mp->traffic_type == SR_STEER_IPV4)
117  memcpy (&prefix.ip4, mp->prefix_addr, sizeof (prefix.ip4));
118  else
119  memcpy (&prefix, mp->prefix_addr, sizeof (prefix.ip6));
120 
121  int rv = 0;
122  if (mp->is_del)
123  rv = sr_mpls_steering_policy_del (&prefix,
124  ntohl (mp->mask_width),
125  mp->traffic_type,
126  ntohl (mp->table_id),
127  ntohl (mp->color));
128  else
129  rv = sr_mpls_steering_policy_add (ntohl (mp->bsid),
130  ntohl (mp->table_id),
131  &prefix,
132  ntohl (mp->mask_width),
133  mp->traffic_type,
134  (ip46_address_t *) & mp->next_hop,
135  mp->nh_type,
136  ntohl (mp->color), mp->co_bits,
137  ntohl (mp->vpn_label));
138 
139  REPLY_MACRO (VL_API_SR_MPLS_STEERING_ADD_DEL_REPLY);
140 }
141 
144 {
145  vl_api_sr_mpls_policy_assign_endpoint_color_reply_t *rmp;
146  int rv = 0;
147 
148  ip46_address_t endpoint;
149  clib_memset (&endpoint, 0, sizeof (ip46_address_t));
150  if (mp->endpoint_type == SR_STEER_IPV4)
151  memcpy (&endpoint.ip4, mp->endpoint, sizeof (endpoint.ip4));
152  else
153  memcpy (&endpoint, mp->endpoint, sizeof (endpoint.ip6));
154 
155  rv = sr_mpls_policy_assign_endpoint_color (ntohl (mp->bsid),
156  &endpoint, mp->endpoint_type,
157  ntohl (mp->color));
158 
159  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR_REPLY);
160 }
161 
162 /*
163  * sr_mpls_api_hookup Add vpe's API message handlers to the table. vlib has
164  * already mapped shared memory and added the client registration handlers.
165  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
166  */
167 #define vl_msg_name_crc_list
168 #include <vnet/vnet_all_api_h.h>
169 #undef vl_msg_name_crc_list
170 
171 static void
173 {
174 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
175  foreach_vl_msg_name_crc_sr_mpls;
176 #undef _
177 }
178 
179 static clib_error_t *
181 {
182  api_main_t *am = &api_main;
183 
184 #define _(N,n) \
185  vl_msg_api_set_handlers(VL_API_##N, #n, \
186  vl_api_##n##_t_handler, \
187  vl_noop_handler, \
188  vl_api_##n##_t_endian, \
189  vl_api_##n##_t_print, \
190  sizeof(vl_api_##n##_t), 1);
192 #undef _
193 
194  /*
195  * Manually register the sr policy add msg, so we trace enough bytes
196  * to capture a typical segment list
197  */
198  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_ADD,
199  "sr_mpls_policy_add",
202  vl_api_sr_mpls_policy_add_t_endian,
204 
205  /*
206  * Manually register the sr policy mod msg, so we trace enough bytes
207  * to capture a typical segment list
208  */
209  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_MOD,
210  "sr_mpls_policy_mod",
213  vl_api_sr_mpls_policy_mod_t_endian,
214  vl_api_sr_mpls_policy_mod_t_print, 256, 1);
215 
216  /*
217  * Set up the (msg_name, crc, message-id) table
218  */
220 
221  return 0;
222 }
223 
225 
226 /*
227  * fd.io coding-style-patch-verification: ON
228  *
229  * Local Variables: eval: (c-set-style "gnu") End:
230  */
static void * vl_api_sr_mpls_policy_add_t_print(vl_api_sr_mpls_policy_add_t *mp, void *handle)
Definition: custom_dump.c:967
#define SR_STEER_IPV4
Definition: sr_mpls.h:41
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void vl_noop_handler(void *mp)
Definition: api_shared.c:788
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:560
int i
MPLS SR steering add/del.
Definition: sr_mpls.api:89
MPLS SR policy modification.
Definition: sr_mpls.api:49
#define clib_memcpy(d, s, n)
Definition: string.h:180
static void vl_api_sr_mpls_policy_mod_t_handler(vl_api_sr_mpls_policy_mod_t *mp)
Definition: sr_mpls_api.c:76
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:111
static clib_error_t * sr_mpls_api_hookup(vlib_main_t *vm)
Definition: sr_mpls_api.c:180
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:172
#define REPLY_MACRO(t)
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:721
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:202
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void vl_api_sr_mpls_policy_del_t_handler(vl_api_sr_mpls_policy_del_t *mp)
Definition: sr_mpls_api.c:101
u32 segments[n_segments]
Definition: sr_mpls.api:58
u32 segments[n_segments]
Definition: sr_mpls.api:34
int sr_mpls_policy_del(mpls_label_t bsid)
Delete a SR policy.
MPLS SR policy add.
Definition: sr_mpls.api:26
#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:143
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:66
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.
typedef prefix
Definition: ip_types.api:35
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.
api_main_t api_main
Definition: api_shared.c:35