Packet generator: preserve pcap file timestamps
[vpp.git] / src / vnet / pg / cli.c
index f5896b4..745b9b2 100644 (file)
@@ -228,6 +228,7 @@ pg_pcap_read (pg_stream_t * s, char *file_name)
   pm.file_name = file_name;
   error = pcap_read (&pm);
   s->replay_packet_templates = pm.packets_read;
+  s->replay_packet_timestamps = pm.timestamps;
   s->min_packet_bytes = pm.min_packet_bytes;
   s->max_packet_bytes = pm.max_packet_bytes;
   s->buffer_bytes = pm.max_packet_bytes;
@@ -547,21 +548,30 @@ pg_capture_cmd_fn (vlib_main_t * vm,
       else
        {
          error = clib_error_create ("unknown input `%U'",
-                                    format_unformat_error, input);
-         return error;
+                                    format_unformat_error, line_input);
+         goto done;
        }
     }
 
   if (!hi)
-    return clib_error_return (0, "Please specify interface name");
+    {
+      error = clib_error_return (0, "Please specify interface name");
+      goto done;
+    }
 
   if (hi->dev_class_index != pg_dev_class.index)
-    return clib_error_return (0, "Please specify packet-generator interface");
+    {
+      error =
+       clib_error_return (0, "Please specify packet-generator interface");
+      goto done;
+    }
 
   if (!pcap_file_name && is_disable == 0)
-    return clib_error_return (0, "Please specify pcap file name");
+    {
+      error = clib_error_return (0, "Please specify pcap file name");
+      goto done;
+    }
 
-  unformat_free (line_input);
 
   pg_capture_args_t _a, *a = &_a;
 
@@ -572,6 +582,10 @@ pg_capture_cmd_fn (vlib_main_t * vm,
   a->count = count;
 
   error = pg_capture (a);
+
+done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -590,6 +604,7 @@ create_pg_if_cmd_fn (vlib_main_t * vm,
   pg_main_t *pg = &pg_main;
   unformat_input_t _line_input, *line_input = &_line_input;
   u32 if_id;
+  clib_error_t *error = NULL;
 
   if (!unformat_user (input, unformat_line_input, line_input))
     return 0;
@@ -600,14 +615,19 @@ create_pg_if_cmd_fn (vlib_main_t * vm,
        ;
 
       else
-       return clib_error_create ("unknown input `%U'",
-                                 format_unformat_error, input);
+       {
+         error = clib_error_create ("unknown input `%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
+  pg_interface_add_or_get (pg, if_id);
+
+done:
   unformat_free (line_input);
 
-  pg_interface_add_or_get (pg, if_id);
-  return 0;
+  return error;
 }
 
 /* *INDENT-OFF* */