+int api_pg_create_interface (vat_main_t *vam)
+{
+ unformat_input_t * input = vam->input;
+ vl_api_pg_create_interface_t *mp;
+ f64 timeout;
+
+ u32 if_id = ~0;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (input, "if_id %d", &if_id))
+ ;
+ else
+ break;
+ }
+ if (if_id == ~0) {
+ errmsg ("missing pg interface index\n");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M(PG_CREATE_INTERFACE, pg_create_interface);
+ mp->context = 0;
+ mp->interface_id = ntohl(if_id);
+
+ S; W;
+ /* NOTREACHED */
+ return 0;
+}
+
+int api_pg_capture (vat_main_t *vam)
+{
+ unformat_input_t * input = vam->input;
+ vl_api_pg_capture_t *mp;
+ f64 timeout;
+
+ u32 if_id = ~0;
+ u8 enable = 1;
+ u32 count = 1;
+ u8 pcap_file_set = 0;
+ u8 * pcap_file = 0;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (input, "if_id %d", &if_id))
+ ;
+ else if (unformat (input, "pcap %s", &pcap_file))
+ pcap_file_set = 1;
+ else if (unformat (input, "count %d", &count))
+ ;
+ else if (unformat (input, "disable"))
+ enable = 0;
+ else
+ break;
+ }
+ if (if_id == ~0) {
+ errmsg ("missing pg interface index\n");
+ return -99;
+ }
+ if (pcap_file_set>0) {
+ if (vec_len (pcap_file) > 255) {
+ errmsg ("pcap file name is too long\n");
+ return -99;
+ }
+ }
+
+ u32 name_len = vec_len(pcap_file);
+ /* Construct the API message */
+ M(PG_CAPTURE, pg_capture);
+ mp->context = 0;
+ mp->interface_id = ntohl(if_id);
+ mp->is_enabled = enable;
+ mp->count = ntohl(count);
+ mp->pcap_name_length = ntohl(name_len);
+ if (pcap_file_set != 0) {
+ clib_memcpy(mp->pcap_file_name, pcap_file, name_len);
+ }
+ vec_free(pcap_file);
+
+ S; W;
+ /* NOTREACHED */
+ return 0;
+}
+
+int api_pg_enable_disable (vat_main_t *vam)
+{
+ unformat_input_t * input = vam->input;
+ vl_api_pg_enable_disable_t *mp;
+ f64 timeout;
+
+ u8 enable = 1;
+ u8 stream_name_set = 0;
+ u8 * stream_name = 0;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (input, "stream %s", &stream_name))
+ stream_name_set = 1;
+ else if (unformat (input, "disable"))
+ enable = 0;
+ else
+ break;
+ }
+
+ if (stream_name_set>0) {
+ if (vec_len (stream_name) > 255) {
+ errmsg ("stream name too long\n");
+ return -99;
+ }
+ }
+
+ u32 name_len = vec_len(stream_name);
+ /* Construct the API message */
+ M(PG_ENABLE_DISABLE, pg_enable_disable);
+ mp->context = 0;
+ mp->is_enabled = enable;
+ if (stream_name_set != 0) {
+ mp->stream_name_length = ntohl(name_len);
+ clib_memcpy(mp->stream_name, stream_name, name_len);
+ }
+ vec_free(stream_name);
+
+ S; W;
+ /* NOTREACHED */
+ return 0;
+}
+