ipsec: Add option to configure the hand-off worker queue size

Type: improvement

Change-Id: I252951d3ec01497c049ca0ffb7cb42aaf2efb965
Signed-off-by: Dau Do <daudo@yahoo.com>
diff --git a/src/vnet/ipsec/ah_decrypt.c b/src/vnet/ipsec/ah_decrypt.c
index 918ebf0..ec4db0f 100644
--- a/src/vnet/ipsec/ah_decrypt.c
+++ b/src/vnet/ipsec/ah_decrypt.c
@@ -500,10 +500,10 @@
 {
   ipsec_main_t *im = &ipsec_main;
 
-  im->ah4_dec_fq_index =
-    vlib_frame_queue_main_init (ah4_decrypt_node.index, 0);
-  im->ah6_dec_fq_index =
-    vlib_frame_queue_main_init (ah6_decrypt_node.index, 0);
+  im->ah4_dec_fq_index = vlib_frame_queue_main_init (ah4_decrypt_node.index,
+						     im->handoff_queue_size);
+  im->ah6_dec_fq_index = vlib_frame_queue_main_init (ah6_decrypt_node.index,
+						     im->handoff_queue_size);
 
   return 0;
 }
diff --git a/src/vnet/ipsec/ah_encrypt.c b/src/vnet/ipsec/ah_encrypt.c
index 960327f..8669466 100644
--- a/src/vnet/ipsec/ah_encrypt.c
+++ b/src/vnet/ipsec/ah_encrypt.c
@@ -490,10 +490,10 @@
 {
   ipsec_main_t *im = &ipsec_main;
 
-  im->ah4_enc_fq_index =
-    vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
-  im->ah6_enc_fq_index =
-    vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
+  im->ah4_enc_fq_index = vlib_frame_queue_main_init (ah4_encrypt_node.index,
+						     im->handoff_queue_size);
+  im->ah6_enc_fq_index = vlib_frame_queue_main_init (ah6_encrypt_node.index,
+						     im->handoff_queue_size);
 
   return 0;
 }
diff --git a/src/vnet/ipsec/esp_decrypt.c b/src/vnet/ipsec/esp_decrypt.c
index 26d8ca1..01b2d29 100644
--- a/src/vnet/ipsec/esp_decrypt.c
+++ b/src/vnet/ipsec/esp_decrypt.c
@@ -1675,14 +1675,14 @@
 {
   ipsec_main_t *im = &ipsec_main;
 
-  im->esp4_dec_fq_index =
-    vlib_frame_queue_main_init (esp4_decrypt_node.index, 0);
-  im->esp6_dec_fq_index =
-    vlib_frame_queue_main_init (esp6_decrypt_node.index, 0);
-  im->esp4_dec_tun_fq_index =
-    vlib_frame_queue_main_init (esp4_decrypt_tun_node.index, 0);
-  im->esp6_dec_tun_fq_index =
-    vlib_frame_queue_main_init (esp6_decrypt_tun_node.index, 0);
+  im->esp4_dec_fq_index = vlib_frame_queue_main_init (esp4_decrypt_node.index,
+						      im->handoff_queue_size);
+  im->esp6_dec_fq_index = vlib_frame_queue_main_init (esp6_decrypt_node.index,
+						      im->handoff_queue_size);
+  im->esp4_dec_tun_fq_index = vlib_frame_queue_main_init (
+    esp4_decrypt_tun_node.index, im->handoff_queue_size);
+  im->esp6_dec_tun_fq_index = vlib_frame_queue_main_init (
+    esp6_decrypt_tun_node.index, im->handoff_queue_size);
 
   return 0;
 }
diff --git a/src/vnet/ipsec/esp_encrypt.c b/src/vnet/ipsec/esp_encrypt.c
index dd47053..544ff7b 100644
--- a/src/vnet/ipsec/esp_encrypt.c
+++ b/src/vnet/ipsec/esp_encrypt.c
@@ -1445,16 +1445,16 @@
 {
   ipsec_main_t *im = &ipsec_main;
 
-  im->esp4_enc_fq_index =
-    vlib_frame_queue_main_init (esp4_encrypt_node.index, 0);
-  im->esp6_enc_fq_index =
-    vlib_frame_queue_main_init (esp6_encrypt_node.index, 0);
-  im->esp4_enc_tun_fq_index =
-    vlib_frame_queue_main_init (esp4_encrypt_tun_node.index, 0);
-  im->esp6_enc_tun_fq_index =
-    vlib_frame_queue_main_init (esp6_encrypt_tun_node.index, 0);
-  im->esp_mpls_enc_tun_fq_index =
-    vlib_frame_queue_main_init (esp_mpls_encrypt_tun_node.index, 0);
+  im->esp4_enc_fq_index = vlib_frame_queue_main_init (esp4_encrypt_node.index,
+						      im->handoff_queue_size);
+  im->esp6_enc_fq_index = vlib_frame_queue_main_init (esp6_encrypt_node.index,
+						      im->handoff_queue_size);
+  im->esp4_enc_tun_fq_index = vlib_frame_queue_main_init (
+    esp4_encrypt_tun_node.index, im->handoff_queue_size);
+  im->esp6_enc_tun_fq_index = vlib_frame_queue_main_init (
+    esp6_encrypt_tun_node.index, im->handoff_queue_size);
+  im->esp_mpls_enc_tun_fq_index = vlib_frame_queue_main_init (
+    esp_mpls_encrypt_tun_node.index, im->handoff_queue_size);
 
   return 0;
 }
diff --git a/src/vnet/ipsec/ipsec.c b/src/vnet/ipsec/ipsec.c
index f8c39c3..8b43dd2 100644
--- a/src/vnet/ipsec/ipsec.c
+++ b/src/vnet/ipsec/ipsec.c
@@ -663,6 +663,7 @@
   u32 ipsec_spd_fp_num_buckets;
   bool fp_spd_ip4_enabled = false;
   bool fp_spd_ip6_enabled = false;
+  u32 handoff_queue_size;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -758,6 +759,11 @@
 
 	  ipsec_tun_table_init (AF_IP6, table_size, n_buckets);
 	}
+      else if (unformat (input, "async-handoff-queue-size %d",
+			 &handoff_queue_size))
+	{
+	  im->handoff_queue_size = handoff_queue_size;
+	}
       else
 	return clib_error_return (0, "unknown input `%U'",
 				  format_unformat_error, input);
diff --git a/src/vnet/ipsec/ipsec.h b/src/vnet/ipsec/ipsec.h
index 4aa09d7..9ab054c 100644
--- a/src/vnet/ipsec/ipsec.h
+++ b/src/vnet/ipsec/ipsec.h
@@ -248,6 +248,8 @@
   u32 esp4_dec_tun_fq_index;
   u32 esp6_dec_tun_fq_index;
 
+  u32 handoff_queue_size;
+
   /* Number of buckets for flow cache */
   u32 ipsec4_out_spd_hash_num_buckets;
   u32 ipsec4_out_spd_flow_cache_entries;