FD.io VPP  v21.10.1-2-g0a485f517
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 #include <vnet/ip/ip_types_api.h>
27 
28 #include <vnet/format_fns.h>
29 #include <vnet/srmpls/sr_mpls.api_enum.h>
30 #include <vnet/srmpls/sr_mpls.api_types.h>
31 
32 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
33 
34 #define vl_api_version(n, v) static u32 api_version = v;
35 #include <vnet/srmpls/sr_mpls.api.h>
36 #undef vl_api_version
37 
38 #define vl_endianfun
39 #include <vnet/srmpls/sr_mpls.api.h>
40 #undef vl_endianfun
41 
42 #define vl_printfun
43 #include <vnet/srmpls/sr_mpls.api.h>
44 #undef vl_printfun
45 
46 #define vl_msg_name_crc_list
47 #include <vnet/srmpls/sr_mpls.api.h>
48 #undef vl_msg_name_crc_list
49 
50 #define REPLY_MSG_ID_BASE msg_id_base
52 
53 #define foreach_vpe_api_msg \
54 _(SR_MPLS_POLICY_DEL, sr_mpls_policy_del) \
55 _(SR_MPLS_STEERING_ADD_DEL, sr_mpls_steering_add_del) \
56 _(SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR, sr_mpls_policy_assign_endpoint_color)
57 
59 
60 static void
62 {
63  vl_api_sr_mpls_policy_add_reply_t *rmp;
64 
65  mpls_label_t *segments = 0, *seg;
66  mpls_label_t this_address = 0;
67 
68  int i;
69  for (i = 0; i < mp->n_segments; i++)
70  {
71  vec_add2 (segments, seg, 1);
72  this_address = ntohl (mp->segments[i]);
73  clib_memcpy (seg, &this_address, sizeof (this_address));
74  }
75 
76  int rv = 0;
77  rv = sr_mpls_policy_add (ntohl (mp->bsid),
78  segments, mp->is_spray, ntohl (mp->weight));
79  vec_free (segments);
80 
81  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ADD_REPLY);
82 }
83 
84 static void
86 {
87  vl_api_sr_mpls_policy_mod_reply_t *rmp;
88 
89  mpls_label_t *segments = 0, *seg;
90  mpls_label_t this_address = 0;
91 
92  int i;
93  for (i = 0; i < mp->n_segments; i++)
94  {
95  vec_add2 (segments, seg, 1);
96  this_address = ntohl (mp->segments[i]);
97  clib_memcpy (seg, &this_address, sizeof (this_address));
98  }
99 
100  int rv = 0;
101  rv = sr_mpls_policy_mod (ntohl (mp->bsid),
102  ntohl (mp->operation), segments,
103  ntohl (mp->sl_index), ntohl (mp->weight));
104  vec_free (segments);
105 
106  REPLY_MACRO (VL_API_SR_MPLS_POLICY_MOD_REPLY);
107 }
108 
109 static void
111 {
112  vl_api_sr_mpls_policy_del_reply_t *rmp;
113  int rv = 0;
114  rv = sr_mpls_policy_del (ntohl (mp->bsid));
115 
116  REPLY_MACRO (VL_API_SR_MPLS_POLICY_DEL_REPLY);
117 }
118 
121 {
122  vl_api_sr_mpls_steering_add_del_reply_t *rmp;
124  ip46_address_t next_hop;
125  clib_memset (&prefix, 0, sizeof (ip46_address_t));
126 
127  ip_prefix_decode (&mp->prefix, &prefix);
128  ip_address_decode (&mp->next_hop, &next_hop);
129 
130  int rv = 0;
131  if (mp->is_del)
133  prefix.fp_len,
134  ip46_address_is_ip4 (&prefix.fp_addr) ?
136  ntohl (mp->table_id),
137  ntohl (mp->color));
138  else
139  rv = sr_mpls_steering_policy_add (ntohl (mp->bsid),
140  ntohl (mp->table_id),
141  &prefix.fp_addr,
142  prefix.fp_len,
143  ip46_address_is_ip4 (&prefix.fp_addr) ?
145  &next_hop,
146  ip46_address_is_ip4 (&next_hop) ?
148  ntohl (mp->color), mp->co_bits,
149  ntohl (mp->vpn_label));
150 
151  REPLY_MACRO (VL_API_SR_MPLS_STEERING_ADD_DEL_REPLY);
152 }
153 
156 {
157  vl_api_sr_mpls_policy_assign_endpoint_color_reply_t *rmp;
158  int rv = 0;
159 
160  ip46_address_t endpoint;
161  clib_memset (&endpoint, 0, sizeof (ip46_address_t));
163 
165  &endpoint,
168  ntohl (mp->color));
169 
170  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR_REPLY);
171 }
172 
173 static void
175 {
176 #define _(id, n, crc) \
177  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + REPLY_MSG_ID_BASE);
178  foreach_vl_msg_name_crc_sr_mpls;
179 #undef _
180 }
181 
182 static clib_error_t *
184 {
186 
187  u8 *name = format (0, "sr_mpls_%08x%c", api_version, 0);
189  vl_msg_api_get_msg_ids ((char *) name, VL_MSG_SR_MPLS_LAST);
190  vec_free (name);
191 
192 #define _(N, n) \
193  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n, \
194  vl_api_##n##_t_handler, vl_noop_handler, \
195  vl_api_##n##_t_endian, vl_api_##n##_t_print, \
196  sizeof (vl_api_##n##_t), 1);
198 #undef _
199 
200  /*
201  * Manually register the sr policy add msg, so we trace enough bytes
202  * to capture a typical segment list
203  */
204  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_ADD,
205  "sr_mpls_policy_add",
207  vl_noop_handler, vl_api_sr_mpls_policy_add_t_endian,
208  vl_api_sr_mpls_policy_add_t_print, 256, 1);
209 
210  /*
211  * Manually register the sr policy mod msg, so we trace enough bytes
212  * to capture a typical segment list
213  */
214  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_MOD,
215  "sr_mpls_policy_mod",
217  vl_noop_handler, vl_api_sr_mpls_policy_mod_t_endian,
218  vl_api_sr_mpls_policy_mod_t_print, 256, 1);
219 
220  /*
221  * Set up the (msg_name, crc, message-id) table
222  */
224 
225  return 0;
226 }
227 
229 
230 /*
231  * fd.io coding-style-patch-verification: ON
232  *
233  * Local Variables: eval: (c-set-style "gnu") End:
234  */
vl_api_sr_mpls_policy_add_t::segments
u32 segments[n_segments]
Definition: sr_mpls.api:38
vl_api_sr_mpls_steering_add_del_t::is_del
bool is_del[default=false]
Definition: sr_mpls.api:94
api.h
sr_mpls_policy_assign_endpoint_color
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.
Definition: sr_mpls_policy.c:671
vl_api_sr_mpls_policy_add_t
MPLS SR policy add.
Definition: sr_mpls.api:30
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
vl_api_sr_mpls_steering_add_del_t::table_id
u32 table_id
Definition: sr_mpls.api:96
name
string name[64]
Definition: fib.api:25
vl_api_sr_mpls_steering_add_del_t_handler
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:120
vl_api_sr_mpls_policy_add_t::weight
u32 weight
Definition: sr_mpls.api:35
vl_api_sr_mpls_policy_del_t::bsid
u32 bsid
Definition: sr_mpls.api:74
ip46_address_is_ip4
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
sr_mpls.h
Segment Routing MPLS data structures definitions.
u16
unsigned short u16
Definition: types.h:57
am
app_main_t * am
Definition: application.c:489
vl_api_sr_mpls_policy_assign_endpoint_color_t
MPLS SR steering add/del.
Definition: sr_mpls.api:112
vl_api_sr_mpls_policy_mod_t_handler
static void vl_api_sr_mpls_policy_mod_t_handler(vl_api_sr_mpls_policy_mod_t *mp)
Definition: sr_mpls_api.c:85
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_api_sr_mpls_policy_mod_t::n_segments
u8 n_segments
Definition: sr_mpls.api:61
vl_msg_api_get_msg_ids
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:1047
ip_address_decode
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Decode/Encode for struct/union types.
Definition: ip_types_api.c:172
vl_api_sr_mpls_policy_assign_endpoint_color_t::endpoint
vl_api_address_t endpoint
Definition: sr_mpls.api:117
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: sr_mpls_api.c:50
vl_api_sr_mpls_policy_mod_t::sl_index
u32 sl_index
Definition: sr_mpls.api:59
vl_api_sr_mpls_steering_add_del_t::next_hop
vl_api_address_t next_hop
Definition: sr_mpls.api:99
vl_api_sr_mpls_steering_add_del_t
MPLS SR steering add/del.
Definition: sr_mpls.api:90
feature.h
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
vl_api_sr_mpls_policy_mod_t::weight
u32 weight
Definition: sr_mpls.api:60
sr_mpls_policy_add
int sr_mpls_policy_add(mpls_label_t bsid, mpls_label_t *segments, u8 behavior, u32 weight)
Create a new SR policy.
Definition: sr_mpls_policy.c:152
vl_api_sr_mpls_steering_add_del_t::co_bits
u8 co_bits
Definition: sr_mpls.api:101
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
sr_mpls_api_hookup
static clib_error_t * sr_mpls_api_hookup(vlib_main_t *vm)
Definition: sr_mpls_api.c:183
ip_prefix_decode
void ip_prefix_decode(const vl_api_prefix_t *in, fib_prefix_t *out)
Definition: ip_types_api.c:245
vl_api_sr_mpls_steering_add_del_t::bsid
u32 bsid
Definition: sr_mpls.api:95
vl_api_sr_mpls_policy_add_t::n_segments
u8 n_segments
Definition: sr_mpls.api:37
vl_api_sr_mpls_steering_add_del_t::color
u32 color
Definition: sr_mpls.api:100
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
SR_STEER_IPV4
#define SR_STEER_IPV4
Definition: sr_mpls.h:41
interface.h
vl_api_sr_mpls_policy_del_t_handler
static void vl_api_sr_mpls_policy_del_t_handler(vl_api_sr_mpls_policy_del_t *mp)
Definition: sr_mpls_api.c:110
vl_api_sr_mpls_policy_assign_endpoint_color_t::bsid
u32 bsid
Definition: sr_mpls.api:116
vl_api_sr_mpls_steering_add_del_t::vpn_label
u32 vpn_label
Definition: sr_mpls.api:102
msg_id_base
static u16 msg_id_base
Definition: sr_mpls_api.c:58
vl_api_sr_mpls_policy_add_t::bsid
u32 bsid
Definition: sr_mpls.api:34
sr_mpls_steering_policy_add
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.
Definition: sr_mpls_steering.c:380
vl_api_sr_mpls_policy_mod_t::bsid
u32 bsid
Definition: sr_mpls.api:57
vl_msg_api_set_handlers
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:872
vl_api_sr_mpls_policy_assign_endpoint_color_t_handler
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:155
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
vl_api_sr_mpls_policy_assign_endpoint_color_t::color
u32 color
Definition: sr_mpls.api:118
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
SR_STEER_IPV6
#define SR_STEER_IPV6
Definition: sr_mpls.h:42
format_fns.h
vl_noop_handler
void vl_noop_handler(void *mp)
Definition: api_shared.c:955
format
description fragment has unexpected format
Definition: map.api:433
vl_api_sr_mpls_policy_mod_t::operation
vl_api_sr_policy_op_t operation
Definition: sr_mpls.api:58
endpoint
vl_api_address_t endpoint
Definition: wireguard.api:103
vl_api_sr_mpls_policy_add_t_handler
static void vl_api_sr_mpls_policy_add_t_handler(vl_api_sr_mpls_policy_add_t *mp)
Definition: sr_mpls_api.c:61
foreach_vpe_api_msg
#define foreach_vpe_api_msg
Definition: sr_mpls_api.c:53
vl_api_sr_mpls_policy_del_t
MPLS SR policy deletion.
Definition: sr_mpls.api:70
api_helper_macros.h
sr_mpls_steering_policy_del
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.
Definition: sr_mpls_steering.c:547
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
i
int i
Definition: flowhash_template.h:376
vl_api_sr_mpls_policy_add_t::is_spray
bool is_spray
Definition: sr_mpls.api:36
mpls_label_t
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:26
rv
int __clib_unused rv
Definition: application.c:491
sr_mpls_policy_del
int sr_mpls_policy_del(mpls_label_t bsid)
Delete a SR policy.
Definition: sr_mpls_policy.c:207
vnet.h
api_errno.h
vl_api_sr_mpls_policy_mod_t::segments
u32 segments[n_segments]
Definition: sr_mpls.api:62
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(sr_mpls_api_hookup)
vl_api_sr_mpls_steering_add_del_t::prefix
vl_api_prefix_t prefix
Definition: sr_mpls.api:97
ip_types_api.h
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
vl_api_sr_mpls_policy_mod_t
MPLS SR policy modification.
Definition: sr_mpls.api:53
prefix
vl_api_prefix_t prefix
Definition: ip.api:175
sr_mpls_policy_mod
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.
Definition: sr_mpls_policy.c:299