Skip to content
Open
234 changes: 234 additions & 0 deletions vppbld/patches/0012-sflow-report-linux-ifindex.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
diff --git a/src/plugins/sflow/sflow.api b/src/plugins/sflow/sflow.api
index 57a478b62..0031079a1 100644
--- a/src/plugins/sflow/sflow.api
+++ b/src/plugins/sflow/sflow.api
@@ -282,3 +282,15 @@ define sflow_interface_details
u32 context;
vl_api_interface_index_t hw_if_index;
};
+
+/** @brief API to enable linux ifindex reporting
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param enable - enable reporting
+*/
+
+autoreply define sflow_report_linux_ifindex_set {
+ u32 client_index;
+ u32 context;
+ bool enable;
+};
\ No newline at end of file
diff --git a/src/plugins/sflow/sflow.c b/src/plugins/sflow/sflow.c
index 3568114d1..e54e76b25 100644
--- a/src/plugins/sflow/sflow.c
+++ b/src/plugins/sflow/sflow.c
@@ -315,6 +315,38 @@ compose_trap_str (char *buf, int buf_len, char *str, int str_len)
return prefix_len + cont_len;
}

+static u32
+sflow_translate_ifindex(sflow_main_t *smp, u32 hw_if_index)
+{
+
+ if (!smp->report_linux_ifindex)
+ {
+ return hw_if_index;
+ }
+
+ if (!smp->lcp_itf_pair_get_vif_index_by_phy)
+ {
+ return hw_if_index;
+ }
+
+ vnet_hw_interface_t *hw = vnet_get_hw_interface(smp->vnet_main, hw_if_index);
+
+ if(!hw)
+ {
+ return hw_if_index;
+ }
+
+ u32 linux_if_index = (*smp->lcp_itf_pair_get_vif_index_by_phy) (hw->sw_if_index);
+
+ if (linux_if_index != INDEX_INVALID)
+ {
+ return linux_if_index;
+ }
+
+ return hw_if_index;
+
+}
+
static int
send_packet_sample (vlib_main_t *vm, sflow_main_t *smp, sflow_sample_t *sample)
{
@@ -342,11 +374,13 @@ send_packet_sample (vlib_main_t *vm, sflow_main_t *smp, sflow_sample_t *sample)
}
// TODO: is it always ethernet? (affects ifType counter as well)
u16 header_protocol = 1; /* ethernet */
+ u32 iifindex = sflow_translate_ifindex (smp, sample->input_if_index);
+ u32 oifindex = sample->output_if_index
+ ? sflow_translate_ifindex (smp, sample->output_if_index)
+ : 0;
SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_SAMPLE_GROUP, ps_group);
- SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_IIFINDEX,
- sample->input_if_index);
- SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_OIFINDEX,
- sample->output_if_index);
+ SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_IIFINDEX, iifindex);
+ SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_OIFINDEX, oifindex);
SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_ORIGSIZE,
sample->sampled_packet_size);
SFLOWPS_set_attr_int (pst, SFLOWPS_PSAMPLE_ATTR_GROUP_SEQ, seqNo);
@@ -410,7 +444,8 @@ send_discard_sample (vlib_main_t *vm, sflow_main_t *smp,
// TODO: read from header? (really just needs to be non-zero for hsflowd)
u16 proto = 0x0800;
SFLOWDM_set_attr_int (dmt, NET_DM_ATTR_PROTO, proto);
- SFLOWDM_set_attr_int (dmt, NET_DM_ATTR_IN_PORT, sample->input_if_index);
+ u32 in_port = sflow_translate_ifindex (smp, sample->input_if_index);
+ SFLOWDM_set_attr_int (dmt, NET_DM_ATTR_IN_PORT, in_port);
SFLOWDM_set_attr (dmt, NET_DM_ATTR_PAYLOAD, sample->header,
sample->header_bytes);
if (SFLOWDM_send (dmt) < 0)
@@ -873,6 +908,13 @@ sflow_enable_disable (sflow_main_t *smp, u32 sw_if_index, bool enable_disable)
return 0;
}

+int
+sflow_report_linux_ifindex(sflow_main_t *smp, bool enable)
+{
+ smp->report_linux_ifindex = enable;
+ return 0;
+}
+
static clib_error_t *
sflow_sampling_rate_command_fn (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
@@ -1086,6 +1128,32 @@ sflow_enable_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
return 0;
}

+static clib_error_t *
+sflow_report_linux_ifindex_command_fn (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ sflow_main_t *smp = &sflow_main;
+ bool enable = true;
+ int rv;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "disable")) enable = false;
+ else if (unformat (input, "enable")) enable = true;
+ else break;
+ }
+ rv = sflow_report_linux_ifindex (smp, enable);
+
+ switch (rv)
+ {
+ case 0:
+ break;
+ default:
+ return clib_error_return (0, "sflow_report_linux_ifindex %d", rv);
+ }
+ return 0;
+
+}
+
static const char *
sflow_direction_str (sflow_direction_t direction)
{
@@ -1178,6 +1246,12 @@ VLIB_CLI_COMMAND (sflow_drop_monitoring_command, static) = {
.function = sflow_drop_monitoring_command_fn,
};

+VLIB_CLI_COMMAND (sflow_report_linux_ifindex_command, static) = {
+ .path = "sflow report-linux-ifindex",
+ .short_help = "sflow report-linux-ifindex <enable|disable>",
+ .function = sflow_report_linux_ifindex_command_fn,
+};
+
VLIB_CLI_COMMAND (show_sflow_command, static) = {
.path = "show sflow",
.short_help = "show sflow",
@@ -1353,6 +1427,18 @@ vl_api_sflow_interface_dump_t_handler (vl_api_sflow_interface_dump_t *mp)
}
}

+static void
+vl_api_sflow_report_linux_ifindex_set_t_handler (
+ vl_api_sflow_report_linux_ifindex_set_t *mp)
+{
+ vl_api_sflow_report_linux_ifindex_set_reply_t *rmp;
+ sflow_main_t *smp = &sflow_main;
+ int rv;
+ rv = sflow_report_linux_ifindex (smp, mp->enable);
+ REPLY_MACRO (VL_API_SFLOW_REPORT_LINUX_IFINDEX_SET_REPLY);
+}
+
+
/* API definitions */
#include <sflow/sflow.api.c>

@@ -1374,6 +1460,8 @@ sflow_init (vlib_main_t *vm)
smp->headerB = SFLOW_DEFAULT_HEADER_BYTES;
smp->samplingD = SFLOW_DIRN_INGRESS;
smp->dropM = false;
+ smp->report_linux_ifindex = false;
+

/* Add our API messages to the global name_crc hash table */
smp->msg_id_base = setup_message_id_table ();
diff --git a/src/plugins/sflow/sflow.h b/src/plugins/sflow/sflow.h
index ca087e58e..4c69f631e 100644
--- a/src/plugins/sflow/sflow.h
+++ b/src/plugins/sflow/sflow.h
@@ -207,6 +207,7 @@ typedef struct
u32 headerB;
sflow_direction_t samplingD;
bool dropM;
+ bool report_linux_ifindex;
u32 total_threads;
sflow_per_interface_data_t *per_interface_data;
sflow_per_thread_data_t *per_thread_data;
diff --git a/src/plugins/sflow/sflow_test.c b/src/plugins/sflow/sflow_test.c
index cdf5a7f6d..1daf0478b 100644
--- a/src/plugins/sflow/sflow_test.c
+++ b/src/plugins/sflow/sflow_test.c
@@ -410,6 +410,37 @@ api_sflow_interface_dump (vat_main_t *vam)
return ret;
}

+static int
+api_sflow_report_linux_ifindex_set (vat_main_t *vam)
+{
+ unformat_input_t *i = vam->input;
+ bool enable = true;
+ vl_api_sflow_report_linux_ifindex_set_t *mp;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "disable"))
+ enable = false;
+ else if (unformat (i, "enable"))
+ enable = true;
+ else
+ break;
+ }
+
+ /* Construct the API message */
+ M (SFLOW_REPORT_LINUX_IFINDEX_SET, mp);
+ mp->enable = enable;
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
/*
* List of messages that the sflow test plugin sends,
* and that the data plane plugin processes
2 changes: 2 additions & 0 deletions vppbld/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
# scope. Existing hash-eth-l34 and IP_FLOW_HASH_DEFAULT are byte-for-byte
# unchanged.
0011-sonic-inner-aware-flow-hash.patch
# 12. Report Linux ifindex in sflow PSAMPLE/NET_DM samples
0012-sflow-report-linux-ifindex.patch