nat: fix busy ports of each thread

which can create dead loop in
nat_alloc_addr_and_port_default function

Change-Id: I468c25ce0f0a0b3f881de564623dea208b2ca700
Signed-off-by: dongjuan <dong.juan1@zte.com.cn>
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index fe6d6ca..ac81a99 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -816,6 +816,17 @@
   rp->is_add = is_add;
   rp->tag = vec_dup (tag);
 }
+                                       
+static u32 get_thread_idx_by_port(u16 e_port)
+{
+    snat_main_t * sm = &snat_main;
+    u32 thread_idx = sm->num_workers;
+    if (sm->num_workers > 1)
+    {
+        thread_idx = sm->first_worker_index + sm->workers[(e_port - 1024) / sm->port_per_thread];
+    }      
+    return thread_idx;
+}
 
 /**
  * @brief Add static mapping.
@@ -1003,7 +1014,7 @@
                       if (e_port > 1024) \
                         { \
                           a->busy_##n##_ports++; \
-                          a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \
+                          a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \
                         } \
                       break;
                       foreach_snat_protocol
@@ -1148,7 +1159,7 @@
                       if (e_port > 1024) \
                         { \
                           a->busy_##n##_ports--; \
-                          a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \
+                          a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \
                         } \
                       break;
                       foreach_snat_protocol
@@ -1320,7 +1331,7 @@
                       if (e_port > 1024) \
                         { \
                           a->busy_##n##_ports++; \
-                          a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \
+                          a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \
                         } \
                       break;
                       foreach_snat_protocol
@@ -1423,7 +1434,7 @@
                       if (e_port > 1024) \
                         { \
                           a->busy_##n##_ports--; \
-                          a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \
+                          a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \
                         } \
                       break;
                       foreach_snat_protocol