aboutsummaryrefslogtreecommitdiffstats
path: root/vpp
diff options
context:
space:
mode:
authorPavel Kotucek <pavel.kotucek@pantheon.tech>2016-06-07 14:44:26 +0200
committerKeith Burns <alagalah@gmail.com>2016-06-27 13:47:34 +0000
commit20c90f765dd0350892421e1dea544752108f4ce9 (patch)
treebc90a2cba4f365ec31b7db144412dd85fcd31147 /vpp
parent8e39bb402afd5908f5b2747bcbb0cc5ffd06bacf (diff)
VPP-108 : API calls to read classify table and sessions
Added new API calls to read - classify table ids as array - classify table ids for specified interface - classsify table info and to dump sessions of specified classify table. Change-Id: I089604fa98eea92866495089d76c2330ae7d850c Signed-off-by: Pavel Kotucek <pavel.kotucek@pantheon.tech>
Diffstat (limited to 'vpp')
-rw-r--r--vpp/api/api.c196
-rw-r--r--vpp/api/custom_dump.c52
-rw-r--r--vpp/api/vpe.api117
3 files changed, 363 insertions, 2 deletions
diff --git a/vpp/api/api.c b/vpp/api/api.c
index 1550dc89..302b7d4e 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -359,7 +359,12 @@ _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
_(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
_(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
-_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details)
+_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
+_(CLASSIFY_TABLE_IDS,classify_table_ids) \
+_(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
+_(CLASSIFY_TABLE_INFO,classify_table_info) \
+_(CLASSIFY_SESSION_DUMP,classify_session_dump) \
+_(CLASSIFY_SESSION_DETAILS,classify_session_details)
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
@@ -6661,6 +6666,195 @@ out:
vec_free(records);
}
+static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
+{
+ unix_shared_memory_queue_t * q;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ vnet_classify_main_t * cm = &vnet_classify_main;
+ vnet_classify_table_t * t;
+ u32 * table_ids = 0;
+ u32 count;
+
+ pool_foreach (t, cm->tables,
+ ({
+ vec_add1 (table_ids, ntohl(t - cm->tables));
+ }));
+ count = vec_len(table_ids);
+
+ vl_api_classify_table_ids_reply_t *rmp;
+ rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count);
+ rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
+ rmp->context = mp->context;
+ rmp->count = ntohl(count);
+ clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
+ rmp->retval = 0;
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+
+ vec_free (table_ids);
+}
+
+static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
+{
+ vl_api_classify_table_by_interface_reply_t *rmp;
+ int rv = 0;
+
+ u32 sw_if_index = ntohl(mp->sw_if_index);
+ u32 * acl = 0;
+
+ vec_validate (acl, INPUT_ACL_N_TABLES - 1);
+ vec_set (acl, ~0);
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+ input_acl_main_t * am = &input_acl_main;
+
+ int if_idx;
+ u32 type;
+
+ for (type = 0; type < INPUT_ACL_N_TABLES; type++)
+ {
+ u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
+ if (vec_len(vec_tbl)) {
+ for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
+ {
+ if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
+ continue;
+ }
+ acl[type] = vec_elt(vec_tbl, if_idx);
+ }
+ }
+ }
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
+ ({
+ rmp->sw_if_index = ntohl(sw_if_index);
+ rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
+ rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
+ rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
+ }));
+ vec_free(acl);
+}
+
+static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
+{
+ unix_shared_memory_queue_t * q;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ vl_api_classify_table_info_reply_t *rmp = 0;
+
+ vnet_classify_main_t * cm = &vnet_classify_main;
+ u32 table_id = ntohl(mp->table_id);
+ vnet_classify_table_t * t;
+
+ pool_foreach (t, cm->tables,
+ ({
+ if (table_id == t - cm->tables) {
+ rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
+ rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
+ rmp->context = mp->context;
+ rmp->table_id = ntohl(table_id);
+ rmp->nbuckets = ntohl(t->nbuckets);
+ rmp->match_n_vectors = ntohl(t->match_n_vectors);
+ rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
+ rmp->active_sessions = ntohl(t->active_elements);
+ rmp->next_table_index = ntohl(t->next_table_index);
+ rmp->miss_next_index = ntohl(t->miss_next_index);
+ rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
+ clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
+ rmp->retval = 0;
+ break;
+ }
+ }));
+
+ if (rmp == 0) {
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
+ rmp->context = mp->context;
+ rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
+ }
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+}
+
+static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
+{
+ clib_warning ("BUG");
+}
+
+static void send_classify_session_details (unix_shared_memory_queue_t * q,
+ u32 table_id,
+ u32 match_length,
+ vnet_classify_entry_t * e,
+ u32 context)
+{
+ vl_api_classify_session_details_t *rmp;
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
+ rmp->context = context;
+ rmp->table_id = ntohl(table_id);
+ rmp->hit_next_index = ntohl(e->next_index);
+ rmp->advance = ntohl(e->advance);
+ rmp->opaque_index = ntohl(e->opaque_index);
+ rmp->match_length = ntohl(match_length);
+ clib_memcpy(rmp->match, e->key, match_length);
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+}
+
+static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
+{
+ vnet_classify_main_t * cm = &vnet_classify_main;
+ unix_shared_memory_queue_t * q;
+
+ u32 table_id = ntohl(mp->table_id);
+ vnet_classify_table_t * t;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+
+ pool_foreach (t, cm->tables,
+ ({
+ if (table_id == t - cm->tables) {
+ vnet_classify_bucket_t * b;
+ vnet_classify_entry_t * v, * save_v;
+ int i, j, k;
+
+ for (i = 0; i < t->nbuckets; i++)
+ {
+ b = &t->buckets [i];
+ if (b->offset == 0)
+ continue;
+
+ save_v = vnet_classify_get_entry (t, b->offset);
+ for (j = 0; j < (1<<b->log2_pages); j++)
+ {
+ for (k = 0; k < t->entries_per_page; k++)
+ {
+ v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
+ if (vnet_classify_entry_is_free (v))
+ continue;
+
+ send_classify_session_details(q, table_id,
+ t->match_n_vectors * sizeof (u32x4), v, mp->context);
+ }
+ }
+ }
+ break;
+ }
+ }));
+}
+
#define BOUNCE_HANDLER(nn) \
static void vl_api_##nn##_t_handler ( \
vl_api_##nn##_t *mp) \
diff --git a/vpp/api/custom_dump.c b/vpp/api/custom_dump.c
index fa9dce6e..123883fb 100644
--- a/vpp/api/custom_dump.c
+++ b/vpp/api/custom_dump.c
@@ -1799,6 +1799,52 @@ static void *vl_api_mpls_fib_decap_dump_t_print
FINISH;
}
+static void *vl_api_classify_table_ids_t_print
+(vl_api_classify_table_ids_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: classify_table_ids ");
+
+ FINISH;
+}
+
+static void *vl_api_classify_table_by_interface_t_print
+(vl_api_classify_table_by_interface_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: classify_table_by_interface ");
+ if (mp->sw_if_index != ~0)
+ s = format (s, "sw_if_index %d ", ntohl(mp->sw_if_index));
+
+ FINISH;
+}
+
+static void *vl_api_classify_table_info_t_print
+(vl_api_classify_table_info_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: classify_table_info ");
+ if (mp->table_id != ~0)
+ s = format (s, "table_id %d ", ntohl(mp->table_id));
+
+ FINISH;
+}
+
+static void *vl_api_classify_session_dump_t_print
+(vl_api_classify_session_dump_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: classify_session_dump ");
+ if (mp->table_id != ~0)
+ s = format (s, "table_id %d ", ntohl(mp->table_id));
+
+ FINISH;
+}
+
#define foreach_custom_print_function \
_(CREATE_LOOPBACK, create_loopback) \
_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
@@ -1890,7 +1936,11 @@ _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
_(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
_(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
_(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
-_(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump)
+_(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
+_(CLASSIFY_TABLE_IDS,classify_table_ids) \
+_(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
+_(CLASSIFY_TABLE_INFO,classify_table_info) \
+_(CLASSIFY_SESSION_DUMP,classify_session_dump)
void vl_msg_api_custom_dump_configure (api_main_t *am)
{
diff --git a/vpp/api/vpe.api b/vpp/api/vpe.api
index f91dd871..a1ea1b2f 100644
--- a/vpp/api/vpe.api
+++ b/vpp/api/vpe.api
@@ -3835,3 +3835,120 @@ manual_java define mpls_fib_decap_details {
u32 tx_table_id;
u8 swif_tag[8];
};
+
+/** \brief Classify get table IDs request
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+*/
+define classify_table_ids {
+ u32 client_index;
+ u32 context;
+};
+
+/** \brief Reply for classify get table IDs request
+ @param context - sender context which was passed in the request
+ @param count - number of ids returned in response
+ @param ids - array of classify table ids
+*/
+manual_java define classify_table_ids_reply {
+ u32 context;
+ u32 retval;
+ u32 count;
+ u32 ids[0];
+};
+
+/** \brief Classify table ids by interface index request
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param sw_if_index - index of the interface
+*/
+define classify_table_by_interface {
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+};
+
+/** \brief Reply for classify table id by interface index request
+ @param context - sender context which was passed in the request
+ @param count - number of ids returned in response
+ @param sw_if_index - index of the interface
+ @param l2_table_id - l2 classify table index
+ @param ip4_table_id - ip4 classify table index
+ @param ip6_table_id - ip6 classify table index
+*/
+manual_java define classify_table_by_interface_reply {
+ u32 context;
+ u32 retval;
+ u32 sw_if_index;
+ u32 l2_table_id;
+ u32 ip4_table_id;
+ u32 ip6_table_id;
+};
+
+/** \brief Classify table info
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param table_id - classify table index
+*/
+define classify_table_info {
+ u32 client_index;
+ u32 context;
+ u32 table_id;
+};
+
+/** \brief Reply for classify table info request
+ @param context - sender context which was passed in the request
+ @param count - number of ids returned in response
+ @param table_id - classify table index
+ @param nbuckets - number of buckets when adding a table
+ @param match_n_vectors - number of match vectors
+ @param skip_n_vectors - number of skip_n_vectors
+ @param active_sessions - number of sessions (active entries)
+ @param next_table_index - index of next table
+ @param miss_next_index - index of miss table
+ @param mask[] - match mask
+*/
+manual_java define classify_table_info_reply {
+ u32 context;
+ i32 retval;
+ u32 table_id;
+ u32 nbuckets;
+ u32 match_n_vectors;
+ u32 skip_n_vectors;
+ u32 active_sessions;
+ u32 next_table_index;
+ u32 miss_next_index;
+ u32 mask_length;
+ u8 mask[0];
+};
+
+/** \brief Classify sessions dump request
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param table_id - classify table index
+*/
+define classify_session_dump {
+ u32 client_index;
+ u32 context;
+ u32 table_id;
+};
+
+/** \brief Reply for classify table session dump request
+ @param context - sender context which was passed in the request
+ @param count - number of ids returned in response
+ @param table_id - classify table index
+ @param hit_next_index - hit_next_index of session
+ @param opaque_index - for add, opaque_index of session
+ @param advance - advance value of session
+ @param match[] - match value for session
+*/
+manual_java define classify_session_details {
+ u32 context;
+ i32 retval;
+ u32 table_id;
+ u32 hit_next_index;
+ i32 advance;
+ u32 opaque_index;
+ u32 match_length;
+ u8 match[0];
+};