session: api to add new transport types
[vpp.git] / src / plugins / hs_apps / sapi / vpp_echo.c
index 0550006..d6f0b28 100644 (file)
@@ -151,6 +151,10 @@ print_global_json_stats (echo_main_t * em)
           end_evt_missing ? "True" : "False");
   fformat (stdout, "  \"rx_data\": %lld,\n", em->stats.rx_total);
   fformat (stdout, "  \"tx_data\": %lld,\n", em->stats.tx_total);
+  fformat (stdout, "  \"rx_bits_per_second\": %.1f,\n",
+          em->stats.rx_total * 8 / deltat);
+  fformat (stdout, "  \"tx_bits_per_second\": %.1f,\n",
+          em->stats.tx_total * 8 / deltat);
   fformat (stdout, "  \"closing\": {\n");
   fformat (stdout, "    \"reset\": { \"q\": %d, \"s\": %d },\n",
           em->stats.reset_count.q, em->stats.reset_count.s);
@@ -158,15 +162,15 @@ print_global_json_stats (echo_main_t * em)
           em->stats.close_count.q, em->stats.close_count.s);
   fformat (stdout, "    \"send evt\": { \"q\": %d, \"s\": %d },\n",
           em->stats.active_count.q, em->stats.active_count.s);
-  fformat (stdout, "    \"clean\": { \"q\": %d, \"s\": %d }\n",
+  fformat (stdout, "    \"clean\": { \"q\": %d, \"s\": %d },\n",
           em->stats.clean_count.q, em->stats.clean_count.s);
-  fformat (stdout, "    \"accepted\": { \"q\": %d, \"s\": %d }\n",
+  fformat (stdout, "    \"accepted\": { \"q\": %d, \"s\": %d },\n",
           em->stats.accepted_count.q, em->stats.accepted_count.s);
   fformat (stdout, "    \"connected\": { \"q\": %d, \"s\": %d }\n",
           em->stats.connected_count.q, em->stats.connected_count.s);
-  fformat (stdout, "  }\n");
+  fformat (stdout, "  },\n");
   fformat (stdout, "  \"results\": {\n");
-  fformat (stdout, "    \"has_failed\": \"%d\"\n", em->has_failed);
+  fformat (stdout, "    \"has_failed\": \"%d\",\n", em->has_failed);
   fformat (stdout, "    \"fail_descr\": \"%v\"\n", em->fail_descr);
   fformat (stdout, "  }\n");
   fformat (stdout, "}\n");
@@ -498,6 +502,8 @@ session_unlisten_handler (session_unlisten_reply_msg_t * mp)
   echo_main_t *em = &echo_main;
 
   ls = echo_get_session_from_handle (em, mp->handle);
+  if (!ls)
+    return;
   em->proto_cb_vft->cleanup_cb (ls, 0 /* parent_died */ );
   ls->session_state = ECHO_SESSION_STATE_CLOSED;
   if (--em->listen_session_cnt == 0)
@@ -783,6 +789,12 @@ del_segment_handler (session_app_del_segment_msg_t * mp)
   ECHO_LOG (2, "Unmaped segment 0x%lx", mp->segment_handle);
 }
 
+static void
+cleanup_handler (session_cleanup_msg_t * mp)
+{
+  ECHO_LOG (1, "Cleanup confirmed for 0x%lx", mp->handle);
+}
+
 static void
 handle_mq_event (session_event_t * e)
 {
@@ -808,6 +820,9 @@ handle_mq_event (session_event_t * e)
     case SESSION_CTRL_EVT_APP_DEL_SEGMENT:
       del_segment_handler ((session_app_del_segment_msg_t *) e->data);
       break;
+    case SESSION_CTRL_EVT_CLEANUP:
+      cleanup_handler ((session_cleanup_msg_t *) e->data);
+      break;
     case SESSION_IO_EVT_RX:
       break;
     default:
@@ -1037,7 +1052,7 @@ print_usage_and_exit (void)
           "  nthreads N          Use N busy loop threads for data [in addition to main & msg queue]\n"
           "  TX=1337[K|M|G]|RX   Send 1337 [K|M|G]bytes, use TX=RX to reflect the data\n"
           "  RX=1337[K|M|G]      Expect 1337 [K|M|G]bytes\n" "\n");
-  for (i = 0; i < TRANSPORT_N_PROTO; i++)
+  for (i = 0; i < vec_len (em->available_proto_cb_vft); i++)
     {
       echo_proto_cb_vft_t *vft = em->available_proto_cb_vft[i];
       if (vft && vft->print_usage_cb)
@@ -1054,7 +1069,7 @@ echo_process_each_proto_opts (unformat_input_t * a)
 {
   echo_main_t *em = &echo_main;
   int i, rv;
-  for (i = 0; i < TRANSPORT_N_PROTO; i++)
+  for (i = 0; i < vec_len (em->available_proto_cb_vft); i++)
     {
       echo_proto_cb_vft_t *vft = em->available_proto_cb_vft[i];
       if (vft && vft->process_opts_cb)
@@ -1068,7 +1083,7 @@ static void
 echo_set_each_proto_defaults_before_opts (echo_main_t * em)
 {
   int i;
-  for (i = 0; i < TRANSPORT_N_PROTO; i++)
+  for (i = 0; i < vec_len (em->available_proto_cb_vft); i++)
     {
       echo_proto_cb_vft_t *vft = em->available_proto_cb_vft[i];
       if (vft && vft->set_defaults_before_opts_cb)
@@ -1430,6 +1445,7 @@ exit_on_error:
   else
     print_global_stats (em);
   vec_free (em->fail_descr);
+  vec_free (em->available_proto_cb_vft);
   exit (em->has_failed);
 }