aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vnet/CMakeLists.txt1
-rw-r--r--src/vnet/srmpls/sr_mpls_test.c174
-rw-r--r--src/vnet/srv6/sr_test.c195
3 files changed, 370 insertions, 0 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt
index 2dbde7c5259..7b01d941d38 100644
--- a/src/vnet/CMakeLists.txt
+++ b/src/vnet/CMakeLists.txt
@@ -1524,6 +1524,7 @@ add_vat_test_library(vnet
ip/ip_test.c
arp/arp_test.c
ip6-nd/ip6_nd_test.c
+ srmpls/sr_mpls_test.c
)
##############################################################################
diff --git a/src/vnet/srmpls/sr_mpls_test.c b/src/vnet/srmpls/sr_mpls_test.c
new file mode 100644
index 00000000000..e5d68462443
--- /dev/null
+++ b/src/vnet/srmpls/sr_mpls_test.c
@@ -0,0 +1,174 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2021 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.
+ *------------------------------------------------------------------
+ */
+#include <vat/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <vpp/api/types.h>
+
+#define __plugin_msg_base sr_mpls_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+/* Declare message IDs */
+#include <vnet/format_fns.h>
+#include <vnet/srmpls/sr_mpls.api_enum.h>
+#include <vnet/srmpls/sr_mpls.api_types.h>
+
+#define vl_endianfun /* define message structures */
+#include <vnet/srmpls/sr_mpls.api.h>
+#undef vl_endianfun
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ u32 ping_id;
+ vat_main_t *vat_main;
+} sr_mpls_test_main_t;
+
+static sr_mpls_test_main_t sr_mpls_test_main;
+
+static int
+api_sr_mpls_policy_mod (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_mpls_steering_add_del (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_mpls_policy_assign_endpoint_color (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_mpls_policy_add (vat_main_t *vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_sr_mpls_policy_add_t *mp;
+ u32 bsid = 0;
+ u32 weight = 1;
+ u8 type = 0;
+ u8 n_segments = 0;
+ u32 sid;
+ u32 *segments = NULL;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "bsid %d", &bsid))
+ ;
+ else if (unformat (i, "weight %d", &weight))
+ ;
+ else if (unformat (i, "spray"))
+ type = 1;
+ else if (unformat (i, "next %d", &sid))
+ {
+ n_segments += 1;
+ vec_add1 (segments, htonl (sid));
+ }
+ else
+ {
+ clib_warning ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (bsid == 0)
+ {
+ errmsg ("bsid not set");
+ return -99;
+ }
+
+ if (n_segments == 0)
+ {
+ errmsg ("no sid in segment stack");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
+
+ mp->bsid = htonl (bsid);
+ mp->weight = htonl (weight);
+ mp->is_spray = type;
+ mp->n_segments = n_segments;
+ memcpy (mp->segments, segments, sizeof (u32) * n_segments);
+ vec_free (segments);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static int
+api_sr_mpls_policy_del (vat_main_t *vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_sr_mpls_policy_del_t *mp;
+ u32 bsid = 0;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "bsid %d", &bsid))
+ ;
+ else
+ {
+ clib_warning ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (bsid == 0)
+ {
+ errmsg ("bsid not set");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (SR_MPLS_POLICY_DEL, mp);
+
+ mp->bsid = htonl (bsid);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+#include <vnet/srmpls/sr_mpls.api_test.c>
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/srv6/sr_test.c b/src/vnet/srv6/sr_test.c
new file mode 100644
index 00000000000..85f64e1e230
--- /dev/null
+++ b/src/vnet/srv6/sr_test.c
@@ -0,0 +1,195 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2021 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.
+ *------------------------------------------------------------------
+ */
+#include <vat/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <vpp/api/types.h>
+#include <vnet/ip/ip_types_api.h>
+
+#define __plugin_msg_base sr_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+/* Declare message IDs */
+#include <vnet/format_fns.h>
+#include <vnet/srv6/sr.api_enum.h>
+#include <vnet/srv6/sr.api_types.h>
+
+#define vl_endianfun /* define message structures */
+#include <vnet/srv6/sr.api.h>
+#undef vl_endianfun
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ u32 ping_id;
+ vat_main_t *vat_main;
+} sr_test_main_t;
+
+static sr_test_main_t sr_test_main;
+
+static int
+api_sr_steering_add_del (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_set_encap_hop_limit (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_set_encap_source (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_policy_del (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_policy_mod (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_policy_add (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_localsids_dump (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_policies_dump (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_policies_with_sl_index_dump (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+api_sr_steering_pol_dump (vat_main_t *vam)
+{
+ return -1;
+}
+
+static void
+vl_api_sr_policies_details_t_handler (vl_api_sr_policies_details_t *mp)
+{
+}
+
+static void
+vl_api_sr_localsids_details_t_handler (vl_api_sr_localsids_details_t *mp)
+{
+}
+
+static void
+vl_api_sr_policies_with_sl_index_details_t_handler (
+ vl_api_sr_policies_with_sl_index_details_t *mp)
+{
+}
+
+static void
+vl_api_sr_steering_pol_details_t_handler (vl_api_sr_steering_pol_details_t *mp)
+{
+}
+
+static int
+api_sr_localsid_add_del (vat_main_t *vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_sr_localsid_add_del_t *mp;
+
+ u8 is_del;
+ ip6_address_t localsid;
+ u8 end_psp = 0;
+ u8 behavior = ~0;
+ u32 sw_if_index;
+ u32 fib_table = ~(u32) 0;
+ ip46_address_t nh_addr;
+ clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
+
+ bool nexthop_set = 0;
+
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "del"))
+ is_del = 1;
+ else if (unformat (i, "address %U", unformat_ip6_address, &localsid))
+ ;
+ else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
+ nexthop_set = 1;
+ else if (unformat (i, "behavior %u", &behavior))
+ ;
+ else if (unformat (i, "sw_if_index %u", &sw_if_index))
+ ;
+ else if (unformat (i, "fib-table %u", &fib_table))
+ ;
+ else if (unformat (i, "end.psp %u", &behavior))
+ ;
+ else
+ break;
+ }
+
+ M (SR_LOCALSID_ADD_DEL, mp);
+
+ clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
+
+ if (nexthop_set)
+ {
+ clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
+ }
+ mp->behavior = behavior;
+ mp->sw_if_index = ntohl (sw_if_index);
+ mp->fib_table = ntohl (fib_table);
+ mp->end_psp = end_psp;
+ mp->is_del = is_del;
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+#include <vnet/srv6/sr.api_test.c>
+
+VAT_REGISTER_FEATURE_FUNCTION (vat_sr_plugin_register);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */