policer: add api to bind policer to worker

Add a new api to allow a policer to be bound to
a specific worker thread for thread handoff.

Type: improvement
Signed-off-by: Brian Russell <brian@graphiant.com>
Change-Id: I2623a6827843c3d93c0d7b4ad7c2e13611ec1696
diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c
index 2c05ae2..8146d4b 100644
--- a/src/vnet/policer/policer.c
+++ b/src/vnet/policer/policer.c
@@ -13,6 +13,7 @@
  * limitations under the License.
  */
 #include <stdint.h>
+#include <stdbool.h>
 #include <vnet/policer/policer.h>
 #include <vnet/policer/police_inlines.h>
 #include <vnet/classify/vnet_classify.h>
@@ -133,6 +134,37 @@
   return 0;
 }
 
+int
+policer_bind_worker (u8 *name, u32 worker, bool bind)
+{
+  vnet_policer_main_t *pm = &vnet_policer_main;
+  policer_read_response_type_st *policer;
+  uword *p;
+
+  p = hash_get_mem (pm->policer_index_by_name, name);
+  if (p == 0)
+    {
+      return VNET_API_ERROR_NO_SUCH_ENTRY;
+    }
+
+  policer = &pm->policers[p[0]];
+
+  if (bind)
+    {
+      if (worker >= vlib_num_workers ())
+	{
+	  return VNET_API_ERROR_INVALID_WORKER;
+	}
+
+      policer->thread_index = vlib_get_worker_thread_index (worker);
+    }
+  else
+    {
+      policer->thread_index = ~0;
+    }
+  return 0;
+}
+
 u8 *
 format_policer_instance (u8 * s, va_list * va)
 {