VPP-203 Find the relative next node index by node names 22/2022/1
authorKeith Burns (alagalah) <alagalah@gmail.com>
Tue, 19 Jul 2016 21:47:43 +0000 (14:47 -0700)
committerKeith Burns (alagalah) <alagalah@gmail.com>
Tue, 19 Jul 2016 21:47:43 +0000 (14:47 -0700)
vat# get_next_index node-name vxlan4-input next-node-name l2-input
next node index 1

Change-Id: Ib71be8a408d08d59b0ed7dfb6ada9711cf29bd69
Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
vpp-api-test/vat/api_format.c
vpp/vpp-api/api.c
vpp/vpp-api/custom_dump.c
vpp/vpp-api/vpe.api

index 4c96cc1..5345076 100644 (file)
@@ -923,6 +923,38 @@ static void vl_api_get_node_index_reply_t_handler_json
     vam->result_ready = 1;
 }
 
+static void vl_api_get_next_index_reply_t_handler
+(vl_api_get_next_index_reply_t * mp)
+{
+    vat_main_t * vam = &vat_main;
+    i32 retval = ntohl(mp->retval);
+    if (vam->async_mode) {
+        vam->async_errors += (retval < 0);
+    } else {
+        vam->retval = retval;
+        if (retval == 0)
+            errmsg ("next node index %d\n", ntohl(mp->next_index));
+        vam->result_ready = 1;
+    }
+}
+
+static void vl_api_get_next_index_reply_t_handler_json
+(vl_api_get_next_index_reply_t * mp)
+{
+    vat_main_t * vam = &vat_main;
+    vat_json_node_t node;
+
+    vat_json_init_object(&node);
+    vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
+    vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
+
+    vat_json_print(vam->ofp, &node);
+    vat_json_free(&node);
+
+    vam->retval = ntohl(mp->retval);
+    vam->result_ready = 1;
+}
+
 static void vl_api_add_node_next_reply_t_handler
 (vl_api_add_node_next_reply_t * mp)
 {
@@ -3013,7 +3045,8 @@ _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply)                 \
 _(CLASSIFY_SESSION_DETAILS, classify_session_details)                   \
 _(IPFIX_ENABLE_REPLY, ipfix_enable_reply)                               \
-_(IPFIX_DETAILS, ipfix_details)
+_(IPFIX_DETAILS, ipfix_details)                                         \
+_(GET_NEXT_INDEX_REPLY, get_next_index_reply)
 
 /* M: construct, but don't yet send a message */
 
@@ -7661,6 +7694,49 @@ static int api_get_node_index (vat_main_t * vam)
     return 0;
 }
 
+static int api_get_next_index (vat_main_t * vam)
+{
+    unformat_input_t * i = vam->input;
+    vl_api_get_next_index_t * mp;
+    f64 timeout;
+    u8 * node_name = 0, * next_node_name = 0;
+
+    while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+        if (unformat (i, "node-name %s", &node_name))
+            ;
+        else if (unformat (i, "next-node-name %s", &next_node_name))
+            break;
+    }
+
+    if (node_name == 0) {
+        errmsg ("node name required\n");
+        return -99;
+    }
+    if (vec_len (node_name) >= ARRAY_LEN(mp->node_name)) {
+        errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
+        return -99;
+    }
+
+    if (next_node_name == 0) {
+        errmsg ("next node name required\n");
+        return -99;
+    }
+    if (vec_len (next_node_name) >= ARRAY_LEN(mp->next_name)) {
+        errmsg ("next node name too long, max %d\n", ARRAY_LEN(mp->next_name));
+        return -99;
+    }
+
+    M(GET_NEXT_INDEX, get_next_index);
+    clib_memcpy (mp->node_name, node_name, vec_len(node_name));
+    clib_memcpy (mp->next_name, next_node_name, vec_len(next_node_name));
+    vec_free(node_name);
+    vec_free(next_node_name);
+
+    S; W;
+    /* NOTREACHED */
+    return 0;
+}
+
 static int api_add_node_next (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
@@ -12702,7 +12778,8 @@ _(classify_session_dump, "table_id <nn>")                               \
 _(ipfix_enable, "collector_address <ip4> [collector_port <nn>] "        \
                 "src_address <ip4> [fib_id <nn>] [path_mtu <nn>] "      \
                 "[template_interval <nn>]")                             \
-_(ipfix_dump, "")
+_(ipfix_dump, "")                                                       \
+_(get_next_index, "node-name <node-name> next-node-name <node-name>")
 
 /* List of command functions, CLI names map directly to functions */
 #define foreach_cli_function                                    \
index f390928..f6b1b73 100644 (file)
@@ -368,7 +368,8 @@ _(CLASSIFY_TABLE_INFO,classify_table_info)                              \
 _(CLASSIFY_SESSION_DUMP,classify_session_dump)                          \
 _(CLASSIFY_SESSION_DETAILS,classify_session_details)                    \
 _(IPFIX_ENABLE,ipfix_enable)                                            \
-_(IPFIX_DUMP,ipfix_dump)
+_(IPFIX_DUMP,ipfix_dump)                                                \
+_(GET_NEXT_INDEX, get_next_index)
 
 #define QUOTE_(x) #x
 #define QUOTE(x) QUOTE_(x)
@@ -4243,6 +4244,48 @@ static void vl_api_get_node_index_t_handler
     }))
 }
 
+static void vl_api_get_next_index_t_handler
+(vl_api_get_next_index_t * mp)
+{
+    vlib_main_t * vm = vlib_get_main();
+    vl_api_get_next_index_reply_t * rmp;
+    vlib_node_t * node, * next_node;
+    int rv = 0;
+    u32 next_node_index = ~0, next_index = ~0;
+    uword * p;
+
+    node = vlib_get_node_by_name (vm, mp->node_name);
+
+    if (node == 0) {
+        rv = VNET_API_ERROR_NO_SUCH_NODE;
+        goto out;
+    }
+
+    next_node = vlib_get_node_by_name (vm, mp->next_name);
+
+    if (next_node == 0) {
+        rv = VNET_API_ERROR_NO_SUCH_NODE2;
+        goto out;
+    }
+    else
+        next_node_index = next_node->index;
+
+    p = hash_get (node->next_slot_by_node, next_node_index);
+
+    if (p == 0) {
+        rv = VNET_API_ERROR_NO_SUCH_ENTRY;
+        goto out;
+    }
+    else
+        next_index = p[0];
+
+ out:
+    REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
+    ({
+        rmp->next_index = ntohl(next_index);
+    }));
+}
+
 static void vl_api_add_node_next_t_handler
 (vl_api_add_node_next_t * mp)
 {
index 9967d5b..4e8b064 100644 (file)
@@ -1875,6 +1875,18 @@ static void *vl_api_ipfix_dump_t_print
     FINISH;
 }
 
+static void *vl_api_get_next_index_t_print
+(vl_api_get_next_index_t * mp, void *handle)
+{
+    u8 * s;
+
+    s = format (0, "SCRIPT: get_next_index ");
+    s = format (s, "node-name %s ", mp->node_name);
+    s = format (s, "next-node-name %s ", mp->next_name);
+
+    FINISH;
+}
+
 #define foreach_custom_print_function                                   \
 _(CREATE_LOOPBACK, create_loopback)                                     \
 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)                       \
@@ -1972,9 +1984,10 @@ _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface)             \
 _(CLASSIFY_TABLE_INFO,classify_table_info)                              \
 _(CLASSIFY_SESSION_DUMP,classify_session_dump)                          \
 _(IPFIX_ENABLE,ipfix_enable)                                            \
-_(IPFIX_DUMP,ipfix_dump)
+_(IPFIX_DUMP,ipfix_dump)                                                \
+_(GET_NEXT_INDEX, get_next_index)
 
-void vl_msg_api_custom_dump_configure (api_main_t *am) 
+void vl_msg_api_custom_dump_configure (api_main_t *am)
 {
 #define _(n,f) am->msg_print_handlers[VL_API_##n]       \
     = (void *) vl_api_##f##_t_print;
index dd50d84..25e6eba 100644 (file)
@@ -4087,3 +4087,27 @@ manual_java define ipfix_details {
     u32 path_mtu;
     u32 template_interval;
 };
+
+/** \brief Query relative index via node names
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param node_name - name of node to find relative index from
+    @param next_name - next node from node_name to find relative index of
+*/
+define get_next_index {
+    u32 client_index;
+    u32 context;
+    u8 node_name[64];
+    u8 next_name[64];
+};
+
+/** \brief Reply for get next node index
+    @param context - sender context which was passed in the request
+    @param retval - return value
+    @param next_index - index of the next_node
+*/
+define get_next_index_reply {
+    u32 context;
+    i32 retval;
+    u32 next_index;
+};