aboutsummaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorPavel Kotucek <pkotucek@cisco.com>2016-07-12 10:18:26 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2016-07-21 09:34:27 +0000
commit9e6ed6e2e1b8af46a317f9448da2bca8d8c5395d (patch)
treebbbd95d27e2a23b18d276ffd82b5fc842d55933d /vnet
parent948b95a9a08d38e7f74a160c11193f73a90e98c9 (diff)
Add API calls for packet generator
Added new API to: - create packet generator interface - enable packet generator per stream or all - capture into file Change-Id: I0e6c1f28069853e4b26f0dc9d282353b0b7f6512 Signed-off-by: Pavel Kotucek <pkotucek@cisco.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/api_errno.h3
-rw-r--r--vnet/vnet/pg/cli.c89
-rw-r--r--vnet/vnet/pg/pg.h12
3 files changed, 70 insertions, 34 deletions
diff --git a/vnet/vnet/api_errno.h b/vnet/vnet/api_errno.h
index f16d9781bdc..2c247d451ff 100644
--- a/vnet/vnet/api_errno.h
+++ b/vnet/vnet/api_errno.h
@@ -82,7 +82,8 @@ _(FAILED_TO_ATTACH_TO_JAVA_THREAD, -88, "Failed to attach to Java thread") \
_(INVALID_WORKER, -89, "Invalid worker thread") \
_(LISP_DISABLED, -90, "LISP is disabled") \
_(CLASSIFY_TABLE_NOT_FOUND, -91, "Classify table not found") \
-_(INVALID_EID_TYPE, -92, "Unsupported LSIP EID type")
+_(INVALID_EID_TYPE, -92, "Unsupported LSIP EID type") \
+_(CANNOT_CREATE_PCAP_FILE, -93, "Cannot create pcap file")
typedef enum {
#define _(a,b,c) VNET_API_ERROR_##a = (b),
diff --git a/vnet/vnet/pg/cli.c b/vnet/vnet/pg/cli.c
index d73add1220d..96c20b70144 100644
--- a/vnet/vnet/pg/cli.c
+++ b/vnet/vnet/pg/cli.c
@@ -52,13 +52,58 @@ VLIB_CLI_COMMAND (vlib_cli_pg_command, static) = {
.short_help = "Packet generator commands",
};
+void pg_enable_disable (u32 stream_index, int is_enable)
+{
+ pg_main_t * pg = &pg_main;
+ pg_stream_t * s;
+
+ if (stream_index == ~0) {
+ /* No stream specified: enable/disable all streams. */
+ pool_foreach (s, pg->streams, ({
+ pg_stream_enable_disable (pg, s, is_enable);
+ }));
+ }
+ else
+ {
+ /* enable/disable specified stream. */
+ s = pool_elt_at_index (pg->streams, stream_index);
+ pg_stream_enable_disable (pg, s, is_enable);
+ }
+}
+
+clib_error_t * pg_capture (pg_capture_args_t *a)
+{
+ pg_main_t * pg = &pg_main;
+ pg_interface_t * pi;
+
+ if (a->is_enabled == 1)
+ {
+ struct stat sb;
+ if (stat ((char *) a->pcap_file_name, &sb) != -1)
+ return clib_error_return (0, "Cannot create pcap file");
+ }
+
+ pi = pool_elt_at_index (pg->interfaces, a->dev_instance);
+ vec_free (pi->pcap_file_name);
+ memset (&pi->pcap_main, 0, sizeof (pi->pcap_main));
+
+ if (a->is_enabled == 0)
+ return 0;
+
+ pi->pcap_file_name = a->pcap_file_name;
+ pi->pcap_main.file_name = (char *) pi->pcap_file_name;
+ pi->pcap_main.n_packets_to_capture = a->count;
+ pi->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
+
+ return 0;
+}
+
static clib_error_t *
enable_disable_stream (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
pg_main_t * pg = &pg_main;
- pg_stream_t * s;
int is_enable = cmd->function_arg != 0;
u32 stream_index = ~0;
@@ -71,18 +116,8 @@ enable_disable_stream (vlib_main_t * vm,
return clib_error_create ("unknown input `%U'",
format_unformat_error, input);
- /* No stream specified: enable/disable all streams. */
- if (stream_index == ~0)
- pool_foreach (s, pg->streams, ({
- pg_stream_enable_disable (pg, s, is_enable);
- }));
- else
- {
- /* enable/disable specified stream. */
- s = pool_elt_at_index (pg->streams, stream_index);
- pg_stream_enable_disable (pg, s, is_enable);
- }
-
+ pg_enable_disable (stream_index, is_enable);
+
return 0;
}
@@ -455,12 +490,10 @@ pg_capture_cmd_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- pg_main_t * pg = &pg_main;
clib_error_t * error = 0;
vnet_main_t * vnm = vnet_get_main();
unformat_input_t _line_input, * line_input = &_line_input;
vnet_hw_interface_t * hi = 0;
- pg_interface_t * pi;
u8 * pcap_file_name = 0;
u32 hw_if_index;
u32 is_disable = 0;
@@ -501,28 +534,18 @@ pg_capture_cmd_fn (vlib_main_t * vm,
if (!pcap_file_name && is_disable == 0)
return clib_error_return (0, "Please specify pcap file name");
- if (is_disable == 0)
- {
- struct stat sb;
- if (stat ((char *) pcap_file_name, &sb) != -1)
- return clib_error_return (0, "Cannot create pcap file");
- }
-
unformat_free (line_input);
- pi = pool_elt_at_index (pg->interfaces, hi->dev_instance);
- vec_free (pi->pcap_file_name);
- memset (&pi->pcap_main, 0, sizeof (pi->pcap_main));
+ pg_capture_args_t _a, *a=&_a;
- if (is_disable)
- return 0;
-
- pi->pcap_file_name = pcap_file_name;
- pi->pcap_main.file_name = (char *) pi->pcap_file_name;
- pi->pcap_main.n_packets_to_capture = count;
- pi->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
+ a->hw_if_index = hw_if_index;
+ a->dev_instance = hi->dev_instance;
+ a->is_enabled = !is_disable;
+ a->pcap_file_name = pcap_file_name;
+ a->count = count;
- return 0;
+ error = pg_capture (a);
+ return error;
}
VLIB_CLI_COMMAND (pg_capture_cmd, static) = {
diff --git a/vnet/vnet/pg/pg.h b/vnet/vnet/pg/pg.h
index 750e7f740b2..54c270ff0a8 100644
--- a/vnet/vnet/pg/pg.h
+++ b/vnet/vnet/pg/pg.h
@@ -352,4 +352,16 @@ void pg_edit_group_get_fixed_packet_data (pg_stream_t * s,
void * fixed_packet_data,
void * fixed_packet_data_mask);
+void pg_enable_disable (u32 stream_index, int is_enable);
+
+typedef struct {
+ u32 hw_if_index;
+ u32 dev_instance;
+ u8 is_enabled;
+ u8 * pcap_file_name;
+ u32 count;
+} pg_capture_args_t;
+
+clib_error_t * pg_capture (pg_capture_args_t *a);
+
#endif /* included_vlib_pg_h */