diff options
author | Pablo Camarillo <pcamaril@cisco.com> | 2019-12-18 17:13:13 +0000 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2020-03-12 08:31:42 +0000 |
commit | 79bfd272546dd436a4d12f0ac98571194965dab0 (patch) | |
tree | 2610496dd4a94cf3c0d4a3da1b1e7cc5855d7c71 /src/plugins/srv6-un/un.c | |
parent | f2833e42c1e3721ce06b0f510447d8a6dd3e5eb4 (diff) |
sr: SRv6 uN behavior
Implements the uN behavior
Type: feature
Change-Id: Icb5efc560e09052cd183b468772cf7f799f81194
Signed-off-by: pcamaril <pcamaril@cisco.com>
Diffstat (limited to 'src/plugins/srv6-un/un.c')
-rw-r--r-- | src/plugins/srv6-un/un.c | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/src/plugins/srv6-un/un.c b/src/plugins/srv6-un/un.c new file mode 100644 index 00000000000..7fd02e2c934 --- /dev/null +++ b/src/plugins/srv6-un/un.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + *------------------------------------------------------------------ + * un.c - SRv6 Masquerading Proxy (AM) function + *------------------------------------------------------------------ + */ + +#include <vnet/vnet.h> +#include <vnet/adj/adj.h> +#include <vnet/plugin/plugin.h> +#include <vpp/app/version.h> +#include <srv6-un/un.h> + +unsigned char function_name[] = "SRv6-uN"; +unsigned char keyword_str[] = "uN(32b+16b)"; +unsigned char def_str[] = "SRv6 uSID uN"; +unsigned char params_str[] = ""; +u8 prefix_length = 48; + +srv6_un_main_t srv6_un_main; + +/*****************************************/ +/* SRv6 LocalSID instantiation and removal functions */ +static int +srv6_un_localsid_creation_fn (ip6_sr_localsid_t * localsid) +{ + srv6_un_localsid_t *ls_mem = localsid->plugin_mem; + //Nothing to do here. + ls_mem->shift = 16; + return 0; +} + +static int +srv6_un_localsid_removal_fn (ip6_sr_localsid_t * localsid) +{ + //Nothing to do here. + + /* Clean up local SID memory */ + clib_mem_free (localsid->plugin_mem); + + return 0; +} + +/**********************************/ +/* SRv6 LocalSID format functions */ +/* + * Prints nicely the parameters of a localsid + * Example: print "Table 5" + */ +u8 * +format_srv6_un_localsid (u8 * s, va_list * args) +{ + srv6_un_localsid_t *ls_mem = va_arg (*args, void *); + + return (format (s, "Shift:\t\t%u", ls_mem->shift)); +} + +/* + * Process the parameters of a localsid + * Example: process from: + * sr localsid address cafe::1 behavior new_srv6_localsid 5 + * everything from behavior on... so in this case 'new_srv6_localsid 5' + * Notice that it MUST match the keyword_str and params_str defined above. + */ +uword +unformat_srv6_un_localsid (unformat_input_t * input, va_list * args) +{ + void **plugin_mem_p = va_arg (*args, void **); + srv6_un_localsid_t *ls_mem; + + if (unformat (input, "uN(32b+16b)")) + { + /* Allocate a portion of memory */ + ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1); + + /* Set to zero the memory */ + clib_memset (ls_mem, 0, sizeof *ls_mem); + + /* Dont forget to add it to the localsid */ + *plugin_mem_p = ls_mem; + return 1; + } + return 0; +} + +/*************************/ +/* SRv6 LocalSID FIB DPO */ +static u8 * +format_srv6_un_dpo (u8 * s, va_list * args) +{ + index_t index = va_arg (*args, index_t); + CLIB_UNUSED (u32 indent) = va_arg (*args, u32); + + return (format (s, "SR: shift-and-forward 16b:[%u]", index)); +} + +void +srv6_un_dpo_lock (dpo_id_t * dpo) +{ +} + +void +srv6_un_dpo_unlock (dpo_id_t * dpo) +{ +} + +const static dpo_vft_t srv6_un_vft = { + .dv_lock = srv6_un_dpo_lock, + .dv_unlock = srv6_un_dpo_unlock, + .dv_format = format_srv6_un_dpo, +}; + +const static char *const srv6_un_ip6_nodes[] = { + "srv6-un-localsid", + NULL, +}; + +const static char *const *const srv6_un_nodes[DPO_PROTO_NUM] = { + [DPO_PROTO_IP6] = srv6_un_ip6_nodes, +}; + +/**********************/ +static clib_error_t * +srv6_un_init (vlib_main_t * vm) +{ + srv6_un_main_t *sm = &srv6_un_main; + int rv = 0; + + sm->vlib_main = vm; + sm->vnet_main = vnet_get_main (); + + /* Create DPO */ + sm->srv6_un16_dpo_type = + dpo_register_new_type (&srv6_un_vft, srv6_un_nodes); + + /* Register SRv6 LocalSID */ + rv = sr_localsid_register_function (vm, + function_name, + keyword_str, + def_str, + params_str, + prefix_length, + &sm->srv6_un16_dpo_type, + format_srv6_un_localsid, + unformat_srv6_un_localsid, + srv6_un_localsid_creation_fn, + srv6_un_localsid_removal_fn); + if (rv < 0) + clib_error_return (0, "SRv6 LocalSID function could not be registered."); + else + sm->srv6_localsid_behavior_id = rv; + + return 0; +} + + +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (srv6_un_init); + +VLIB_PLUGIN_REGISTER () = { + .version = VPP_BUILD_VER, + .description = "Segment Routing Shift And Forward uN 16b", +}; +/* *INDENT-ON* */ + +/* +* fd.io coding-style-patch-verification: ON +* +* Local Variables: +* eval: (c-set-style "gnu") +* End: +*/ |