Add interface rx mode commands, unify rx mode and placement CLI

Change-Id: Ib506c3e9d66170f29e3266ad6dc4d32b829befba
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 6f51ff6..2d21bfd 100755
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -704,8 +704,8 @@
 
       sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->hw_if_index);
       xd->vlib_sw_if_index = sw->sw_if_index;
-      vnet_set_device_input_node (dm->vnet_main, xd->hw_if_index,
-				  dpdk_input_node.index);
+      vnet_hw_interface_set_input_node (dm->vnet_main, xd->hw_if_index,
+					dpdk_input_node.index);
 
       if (devconf->workers)
 	{
@@ -713,7 +713,7 @@
 	  q = 0;
 	  /* *INDENT-OFF* */
 	  clib_bitmap_foreach (i, devconf->workers, ({
-	    vnet_device_input_assign_thread (dm->vnet_main, xd->hw_if_index, q++,
+	    vnet_hw_interface_assign_rx_thread (dm->vnet_main, xd->hw_if_index, q++,
 					     vdm->first_worker_thread_index + i);
 	  }));
 	  /* *INDENT-ON* */
@@ -721,8 +721,8 @@
       else
 	for (q = 0; q < xd->rx_q_used; q++)
 	  {
-	    vnet_device_input_assign_thread (dm->vnet_main, xd->hw_if_index, q,	/* any */
-					     ~1);
+	    vnet_hw_interface_assign_rx_thread (dm->vnet_main, xd->hw_if_index, q,	/* any */
+						~1);
 	  }
 
       hi = vnet_get_hw_interface (dm->vnet_main, xd->hw_if_index);
diff --git a/src/vnet/api_errno.h b/src/vnet/api_errno.h
index 0d5b222..b87c197 100644
--- a/src/vnet/api_errno.h
+++ b/src/vnet/api_errno.h
@@ -109,7 +109,8 @@
 _(SVM_SEGMENT_CREATE_FAIL, -117, "svm segment create fail")		\
 _(APPLICATION_NOT_ATTACHED, -118, "application not attached")           \
 _(BD_ALREADY_EXISTS, -119, "Bridge domain already exists")              \
-_(BD_IN_USE, -120, "Bridge domain has member interfaces")
+_(BD_IN_USE, -120, "Bridge domain has member interfaces")		\
+_(UNSUPPORTED, -121, "Unsupported")
 
 typedef enum
 {
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index 92bd109..cb52e6d 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -195,6 +195,7 @@
   u8 hw_addr[6];
   clib_error_t *error;
   vnet_sw_interface_t *sw;
+  vnet_hw_interface_t *hw;
   vlib_thread_main_t *tm = vlib_get_thread_main ();
   vnet_main_t *vnm = vnet_get_main ();
   uword *p;
@@ -294,17 +295,21 @@
     }
 
   sw = vnet_get_hw_sw_interface (vnm, apif->hw_if_index);
+  hw = vnet_get_hw_interface (vnm, apif->hw_if_index);
   apif->sw_if_index = sw->sw_if_index;
-  vnet_set_device_input_node (vnm, apif->hw_if_index,
-			      af_packet_input_node.index);
-  vnet_device_input_assign_thread (vnm, apif->hw_if_index, 0,	/* queue */
-				   ~0 /* any cpu */ );
-  vnet_device_input_set_mode (vnm, apif->hw_if_index, 0,
-			      VNET_DEVICE_INPUT_MODE_INTERRUPT);
+  vnet_hw_interface_set_input_node (vnm, apif->hw_if_index,
+				    af_packet_input_node.index);
 
+  vnet_hw_interface_assign_rx_thread (vnm, apif->hw_if_index, 0,	/* queue */
+				      ~0 /* any cpu */ );
+
+  hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
   vnet_hw_interface_set_flags (vnm, apif->hw_if_index,
 			       VNET_HW_INTERFACE_FLAG_LINK_UP);
 
+  vnet_hw_interface_set_rx_mode (vnm, apif->hw_if_index, 0,
+				 VNET_HW_INTERFACE_RX_MODE_INTERRUPT);
+
   mhash_set_mem (&apm->if_index_by_host_if_name, host_if_name_dup, &if_index,
 		 0);
   if (sw_if_index)
@@ -340,6 +345,7 @@
 
   /* bring down the interface */
   vnet_hw_interface_set_flags (vnm, apif->hw_if_index, 0);
+  vnet_hw_interface_unassign_rx_thread (vnm, apif->hw_if_index, 0);
 
   /* clean up */
   if (apif->unix_file_index != ~0)
diff --git a/src/vnet/devices/devices.c b/src/vnet/devices/devices.c
index 2f55adc..d75d905 100644
--- a/src/vnet/devices/devices.c
+++ b/src/vnet/devices/devices.c
@@ -119,8 +119,8 @@
 }
 
 void
-vnet_device_input_assign_thread (vnet_main_t * vnm, u32 hw_if_index,
-				 u16 queue_id, uword thread_index)
+vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
+				    u16 queue_id, uword thread_index)
 {
   vnet_device_main_t *vdm = &vnet_device_main;
   vlib_main_t *vm;
@@ -149,16 +149,19 @@
   dq->hw_if_index = hw_if_index;
   dq->dev_instance = hw->dev_instance;
   dq->queue_id = queue_id;
+  dq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
 
   vnet_device_queue_update (vnm, rt);
   vec_validate (hw->input_node_thread_index_by_queue, queue_id);
+  vec_validate (hw->rx_mode_by_queue, queue_id);
   hw->input_node_thread_index_by_queue[queue_id] = thread_index;
+  hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_POLLING;
   vlib_node_set_state (vm, hw->input_node_index, rt->enabled_node_state);
 }
 
 int
-vnet_device_input_unassign_thread (vnet_main_t * vnm, u32 hw_if_index,
-				   u16 queue_id, uword thread_index)
+vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
+				      u16 queue_id)
 {
   vlib_main_t *vm;
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
@@ -190,6 +193,7 @@
 deleted:
 
   vnet_device_queue_update (vnm, rt);
+  hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
 
   if (vec_len (rt->devices_and_queues) == 0)
     vlib_node_set_state (vm, hw->input_node_index, VLIB_NODE_STATE_DISABLED);
@@ -199,21 +203,28 @@
 
 
 int
-vnet_device_input_set_mode (vnet_main_t * vnm, u32 hw_if_index, u16 queue_id,
-			    vnet_device_input_mode_t mode)
+vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
+			       u16 queue_id, vnet_hw_interface_rx_mode mode)
 {
   vlib_main_t *vm;
   uword thread_index;
   vnet_device_and_queue_t *dq;
   vlib_node_state_t enabled_node_state;
-  ASSERT (mode < VNET_DEVICE_INPUT_N_MODES);
+  ASSERT (mode < VNET_HW_INTERFACE_NUM_RX_MODES);
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   vnet_device_input_runtime_t *rt;
   int is_polling = 0;
 
-  if (hw->input_node_thread_index_by_queue == 0)
+  if (hw->input_node_thread_index_by_queue == 0 || hw->rx_mode_by_queue == 0)
     return VNET_API_ERROR_INVALID_INTERFACE;
 
+  if (hw->rx_mode_by_queue[queue_id] == mode)
+    return 0;
+
+  if (mode != VNET_HW_INTERFACE_RX_MODE_POLLING &&
+      (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE) == 0)
+    return VNET_API_ERROR_UNSUPPORTED;
+
   thread_index = hw->input_node_thread_index_by_queue[queue_id];
   vm = vlib_mains[thread_index];
 
@@ -223,7 +234,7 @@
   {
     if (dq->hw_if_index == hw_if_index && dq->queue_id == queue_id)
       dq->mode = mode;
-    if (dq->mode == VNET_DEVICE_INPUT_MODE_POLLING)
+    if (dq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
       is_polling = 1;
   }
 
@@ -244,8 +255,8 @@
 }
 
 int
-vnet_device_input_get_mode (vnet_main_t * vnm, u32 hw_if_index, u16 queue_id,
-			    vnet_device_input_mode_t * mode)
+vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
+			       u16 queue_id, vnet_hw_interface_rx_mode * mode)
 {
   vlib_main_t *vm;
   uword thread_index;
@@ -271,146 +282,7 @@
   return VNET_API_ERROR_INVALID_INTERFACE;
 }
 
-static clib_error_t *
-show_device_placement_fn (vlib_main_t * vm, unformat_input_t * input,
-			  vlib_cli_command_t * cmd)
-{
-  u8 *s = 0;
-  vnet_main_t *vnm = vnet_get_main ();
-  vnet_device_input_runtime_t *rt;
-  vnet_device_and_queue_t *dq;
-  vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
-  uword si;
-  int index = 0;
 
-  /* *INDENT-OFF* */
-  foreach_vlib_main (({
-    clib_bitmap_foreach (si, pn->sibling_bitmap,
-      ({
-        rt = vlib_node_get_runtime_data (this_vlib_main, si);
-
-        if (vec_len (rt->devices_and_queues))
-          s = format (s, "  node %U:\n", format_vlib_node_name, vm, si);
-
-        vec_foreach (dq, rt->devices_and_queues)
-	  {
-	    s = format (s, "    %U queue %u (%s)\n",
-			format_vnet_sw_if_index_name, vnm, dq->hw_if_index,
-			dq->queue_id,
-			dq->mode == VNET_DEVICE_INPUT_MODE_POLLING ?
-			"polling" : "interrupt");
-	  }
-      }));
-    if (vec_len (s) > 0)
-      {
-        vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
-			vlib_worker_threads[index].name, s);
-        vec_reset_length (s);
-      }
-    index++;
-  }));
-  /* *INDENT-ON* */
-
-  vec_free (s);
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (memif_delete_command, static) = {
-  .path = "show interface placement",
-  .short_help = "show interface placement",
-  .function = show_device_placement_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-set_device_placement (vlib_main_t * vm, unformat_input_t * input,
-		      vlib_cli_command_t * cmd)
-{
-  clib_error_t *error = 0;
-  unformat_input_t _line_input, *line_input = &_line_input;
-  vnet_main_t *vnm = vnet_get_main ();
-  vnet_device_main_t *vdm = &vnet_device_main;
-  vnet_device_input_mode_t mode;
-  u32 hw_if_index = (u32) ~ 0;
-  u32 queue_id = (u32) 0;
-  u32 thread_index = (u32) ~ 0;
-  int rv;
-
-  if (!unformat_user (input, unformat_line_input, line_input))
-    return 0;
-
-  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat
-	  (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
-	;
-      else if (unformat (line_input, "queue %d", &queue_id))
-	;
-      else if (unformat (line_input, "main", &thread_index))
-	thread_index = 0;
-      else if (unformat (line_input, "worker %d", &thread_index))
-	thread_index += vdm->first_worker_thread_index;
-      else
-	{
-	  error = clib_error_return (0, "parse error: '%U'",
-				     format_unformat_error, line_input);
-	  unformat_free (line_input);
-	  return error;
-	}
-    }
-
-  unformat_free (line_input);
-
-  if (hw_if_index == (u32) ~ 0)
-    return clib_error_return (0, "please specify valid interface name");
-
-  if (thread_index > vdm->last_worker_thread_index)
-    return clib_error_return (0,
-			      "please specify valid worker thread or main");
-
-  rv = vnet_device_input_get_mode (vnm, hw_if_index, queue_id, &mode);
-
-  if (rv)
-    return clib_error_return (0, "not found");
-
-  rv = vnet_device_input_unassign_thread (vnm, hw_if_index, queue_id,
-					  thread_index);
-
-  if (rv)
-    return clib_error_return (0, "not found");
-
-  vnet_device_input_assign_thread (vnm, hw_if_index, queue_id, thread_index);
-  vnet_device_input_set_mode (vnm, hw_if_index, queue_id, mode);
-
-  return 0;
-}
-
-/*?
- * This command is used to assign a given interface, and optionally a
- * given queue, to a different thread. If the '<em>queue</em>' is not provided,
- * it defaults to 0.
- *
- * @cliexpar
- * Example of how to display the interface placement:
- * @cliexstart{show interface placement}
- * Thread 1 (vpp_wk_0):
- *   GigabitEthernet0/8/0 queue 0
- *   GigabitEthernet0/9/0 queue 0
- * Thread 2 (vpp_wk_1):
- *   GigabitEthernet0/8/0 queue 1
- *   GigabitEthernet0/9/0 queue 1
- * @cliexend
- * Example of how to assign a interface and queue to a thread:
- * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
-?*/
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (cmd_set_dpdk_if_placement,static) = {
-    .path = "set interface placement",
-    .short_help = "set interface placement <interface> [queue <n>] [thread <n> | main]",
-    .function = set_device_placement,
-};
-/* *INDENT-ON* */
 
 static clib_error_t *
 vnet_device_init (vlib_main_t * vm)
diff --git a/src/vnet/devices/devices.h b/src/vnet/devices/devices.h
index baf03b7..f1f7e77 100644
--- a/src/vnet/devices/devices.h
+++ b/src/vnet/devices/devices.h
@@ -55,19 +55,12 @@
   uword next_worker_thread_index;
 } vnet_device_main_t;
 
-typedef enum
-{
-  VNET_DEVICE_INPUT_MODE_POLLING = 0,
-  VNET_DEVICE_INPUT_MODE_INTERRUPT,
-  VNET_DEVICE_INPUT_N_MODES,
-} vnet_device_input_mode_t;
-
 typedef struct
 {
   u32 hw_if_index;
   u32 dev_instance;
   u16 queue_id;
-  vnet_device_input_mode_t mode;
+  vnet_hw_interface_rx_mode mode;
   uword interrupt_pending;
 } vnet_device_and_queue_t;
 
@@ -82,22 +75,23 @@
 extern const u32 device_input_next_node_advance[];
 
 static inline void
-vnet_set_device_input_node (vnet_main_t * vnm, u32 hw_if_index,
-			    u32 node_index)
+vnet_hw_interface_set_input_node (vnet_main_t * vnm, u32 hw_if_index,
+				  u32 node_index)
 {
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   hw->input_node_index = node_index;
 }
 
-void vnet_device_input_assign_thread (vnet_main_t * vnm, u32 hw_if_index,
-				      u16 queue_id, uword thread_index);
-int vnet_device_input_unassign_thread (vnet_main_t * vnm, u32 hw_if_index,
-				       u16 queue_id, uword thread_index);
-int vnet_device_input_set_mode (vnet_main_t * vnm, u32 hw_if_index,
-				u16 queue_id, vnet_device_input_mode_t mode);
-int vnet_device_input_get_mode (vnet_main_t * vnm, u32 hw_if_index,
-				u16 queue_id,
-				vnet_device_input_mode_t * mode);
+void vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
+					 u16 queue_id, uword thread_index);
+int vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
+					  u16 queue_id);
+int vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
+				   u16 queue_id,
+				   vnet_hw_interface_rx_mode mode);
+int vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
+				   u16 queue_id,
+				   vnet_hw_interface_rx_mode * mode);
 
 static inline u64
 vnet_get_aggregate_rx_packets (void)
@@ -161,7 +155,7 @@
 #define foreach_device_and_queue(var,vec) \
   for (var = (vec); var < vec_end (vec); var++)			\
     if (clib_smp_swap (&((var)->interrupt_pending), 0) ||	\
-	var->mode == VNET_DEVICE_INPUT_MODE_POLLING)
+	var->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
 
 #endif /* included_vnet_vnet_device_h */
 
diff --git a/src/vnet/interface.h b/src/vnet/interface.h
index 9c22304..2344348 100644
--- a/src/vnet/interface.h
+++ b/src/vnet/interface.h
@@ -405,6 +405,9 @@
 #define VNET_HW_INTERFACE_FLAG_L2OUTPUT_SHIFT	9
 #define VNET_HW_INTERFACE_FLAG_L2OUTPUT_MAPPED	(1 << 9)
 
+  /* rx mode flags */
+#define VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE (1 << 10)
+
   /* Hardware address as vector.  Zero (e.g. zero-length vector) if no
      address for this class (e.g. PPP). */
   u8 *hw_address;
@@ -470,6 +473,9 @@
   /* input node cpu index by queue */
   u32 *input_node_thread_index_by_queue;
 
+  /* vnet_hw_interface_rx_mode by queue */
+  u8 *rx_mode_by_queue;
+
   /* device input device_and_queue runtime index */
   uword *dq_runtime_index_by_queue;
 
@@ -486,6 +492,15 @@
   VNET_SW_INTERFACE_TYPE_SUB,
 } vnet_sw_interface_type_t;
 
+typedef enum
+{
+  VNET_HW_INTERFACE_RX_MODE_UNKNOWN,
+  VNET_HW_INTERFACE_RX_MODE_POLLING,
+  VNET_HW_INTERFACE_RX_MODE_INTERRUPT,
+  VNET_HW_INTERFACE_RX_MODE_ADAPTIVE,
+  VNET_HW_INTERFACE_NUM_RX_MODES,
+} vnet_hw_interface_rx_mode;
+
 typedef struct
 {
   /*
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 94eb7ea..bfce03e 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -1175,7 +1175,245 @@
 };
 /* *INDENT-ON* */
 
+static clib_error_t *
+set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
+		       vlib_cli_command_t * cmd)
+{
+  clib_error_t *error = 0;
+  unformat_input_t _line_input, *line_input = &_line_input;
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_hw_interface_t *hw;
+  u32 hw_if_index = (u32) ~ 0;
+  u32 queue_id = (u32) ~ 0;
+  vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
+  int i, rv = 0;
 
+  if (!unformat_user (input, unformat_line_input, line_input))
+    return 0;
+
+  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat
+	  (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
+	;
+      else if (unformat (line_input, "queue %d", &queue_id))
+	;
+      else if (unformat (line_input, "polling"))
+	mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
+      else if (unformat (line_input, "interrupt"))
+	mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
+      else if (unformat (line_input, "adaptive"))
+	mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
+      else
+	{
+	  error = clib_error_return (0, "parse error: '%U'",
+				     format_unformat_error, line_input);
+	  unformat_free (line_input);
+	  return error;
+	}
+    }
+
+  unformat_free (line_input);
+
+  if (hw_if_index == (u32) ~ 0)
+    return clib_error_return (0, "please specify valid interface name");
+
+  if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
+    return clib_error_return (0, "please specify valid rx-mode");
+
+  hw = vnet_get_hw_interface (vnm, hw_if_index);
+
+  if (queue_id == ~0)
+    for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
+      {
+	rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, i, mode);
+	if (rv)
+	  goto error;
+      }
+  else
+    rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
+
+  if (rv)
+    goto error;
+
+  return 0;
+
+error:
+  if (rv == VNET_API_ERROR_UNSUPPORTED)
+    return clib_error_return (0, "unsupported");
+
+  if (rv == VNET_API_ERROR_INVALID_INTERFACE)
+    return clib_error_return (0, "invalid interfaace");
+
+  return clib_error_return (0, "unknown error");
+}
+
+/*?
+ * This command is used to assign a given interface, and optionally a
+ * given queue, to a different thread. If the '<em>queue</em>' is not provided,
+ * it defaults to 0.
+ *
+ * @cliexpar
+ * Example of how to display the interface placement:
+ * @cliexstart{show interface rx-placement}
+ * Thread 1 (vpp_wk_0):
+ *   GigabitEthernet0/8/0 queue 0
+ *   GigabitEthernet0/9/0 queue 0
+ * Thread 2 (vpp_wk_1):
+ *   GigabitEthernet0/8/0 queue 1
+ *   GigabitEthernet0/9/0 queue 1
+ * @cliexend
+ * Example of how to assign a interface and queue to a thread:
+ * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
+?*/
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
+    .path = "set interface rx-mode",
+    .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
+    .function = set_interface_rx_mode,
+};
+/* *INDENT-ON* */
+
+static clib_error_t *
+show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
+				vlib_cli_command_t * cmd)
+{
+  u8 *s = 0;
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_device_input_runtime_t *rt;
+  vnet_device_and_queue_t *dq;
+  vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
+  uword si;
+  int index = 0;
+
+  /* *INDENT-OFF* */
+  foreach_vlib_main (({
+    clib_bitmap_foreach (si, pn->sibling_bitmap,
+      ({
+        rt = vlib_node_get_runtime_data (this_vlib_main, si);
+
+        if (vec_len (rt->devices_and_queues))
+          s = format (s, "  node %U:\n", format_vlib_node_name, vm, si);
+
+        vec_foreach (dq, rt->devices_and_queues)
+	  {
+	    s = format (s, "    %U queue %u (%U)\n",
+			format_vnet_sw_if_index_name, vnm, dq->hw_if_index,
+			dq->queue_id,
+			format_vnet_hw_interface_rx_mode, dq->mode);
+	  }
+      }));
+    if (vec_len (s) > 0)
+      {
+        vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
+			vlib_worker_threads[index].name, s);
+        vec_reset_length (s);
+      }
+    index++;
+  }));
+  /* *INDENT-ON* */
+
+  vec_free (s);
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
+  .path = "show interface rx-placement",
+  .short_help = "show interface rx-placement",
+  .function = show_interface_rx_placement_fn,
+};
+/* *INDENT-ON* */
+
+static clib_error_t *
+set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
+			    vlib_cli_command_t * cmd)
+{
+  clib_error_t *error = 0;
+  unformat_input_t _line_input, *line_input = &_line_input;
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_device_main_t *vdm = &vnet_device_main;
+  vnet_hw_interface_rx_mode mode;
+  u32 hw_if_index = (u32) ~ 0;
+  u32 queue_id = (u32) 0;
+  u32 thread_index = (u32) ~ 0;
+  int rv;
+
+  if (!unformat_user (input, unformat_line_input, line_input))
+    return 0;
+
+  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat
+	  (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
+	;
+      else if (unformat (line_input, "queue %d", &queue_id))
+	;
+      else if (unformat (line_input, "main", &thread_index))
+	thread_index = 0;
+      else if (unformat (line_input, "worker %d", &thread_index))
+	thread_index += vdm->first_worker_thread_index;
+      else
+	{
+	  error = clib_error_return (0, "parse error: '%U'",
+				     format_unformat_error, line_input);
+	  unformat_free (line_input);
+	  return error;
+	}
+    }
+
+  unformat_free (line_input);
+
+  if (hw_if_index == (u32) ~ 0)
+    return clib_error_return (0, "please specify valid interface name");
+
+  if (thread_index > vdm->last_worker_thread_index)
+    return clib_error_return (0,
+			      "please specify valid worker thread or main");
+
+  rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
+
+  if (rv)
+    return clib_error_return (0, "not found");
+
+  rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
+
+  if (rv)
+    return clib_error_return (0, "not found");
+
+  vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
+				      thread_index);
+  vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
+
+  return 0;
+}
+
+/*?
+ * This command is used to assign a given interface, and optionally a
+ * given queue, to a different thread. If the '<em>queue</em>' is not provided,
+ * it defaults to 0.
+ *
+ * @cliexpar
+ * Example of how to display the interface placement:
+ * @cliexstart{show interface placement}
+ * Thread 1 (vpp_wk_0):
+ *   GigabitEthernet0/8/0 queue 0
+ *   GigabitEthernet0/9/0 queue 0
+ * Thread 2 (vpp_wk_1):
+ *   GigabitEthernet0/8/0 queue 1
+ *   GigabitEthernet0/9/0 queue 1
+ * @cliexend
+ * Example of how to assign a interface and queue to a thread:
+ * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
+?*/
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
+    .path = "set interface rx-placement",
+    .short_help = "set interface rx-placement <hw-interface> [queue <n>] [thread <n> | main]",
+    .function = set_interface_rx_placement,
+};
+
+/* *INDENT-ON* */
 /*
  * fd.io coding-style-patch-verification: ON
  *
diff --git a/src/vnet/interface_format.c b/src/vnet/interface_format.c
index b961c77..03caf5c 100644
--- a/src/vnet/interface_format.c
+++ b/src/vnet/interface_format.c
@@ -59,6 +59,23 @@
 }
 
 u8 *
+format_vnet_hw_interface_rx_mode (u8 * s, va_list * args)
+{
+  vnet_hw_interface_rx_mode mode = va_arg (*args, vnet_hw_interface_rx_mode);
+
+  if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
+    return format (s, "polling");
+
+  if (mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT)
+    return format (s, "interrupt");
+
+  if (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE)
+    return format (s, "adaptive");
+
+  return format (s, "unknown");
+}
+
+u8 *
 format_vnet_hw_interface (u8 * s, va_list * args)
 {
   vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h
index b3aca2f..999b72e 100644
--- a/src/vnet/interface_funcs.h
+++ b/src/vnet/interface_funcs.h
@@ -277,6 +277,7 @@
 
 /* Formats sw/hw interface. */
 format_function_t format_vnet_hw_interface;
+format_function_t format_vnet_hw_interface_rx_mode;
 format_function_t format_vnet_sw_interface;
 format_function_t format_vnet_sw_interface_name;
 format_function_t format_vnet_sw_interface_name_override;