]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/commitdiff
Implemented multi-core/thread protections, implemented changes to have each core...
authorTinku Mannan <tmannan@ti.com>
Fri, 28 Dec 2012 16:28:50 +0000 (11:28 -0500)
committerTinku Mannan <tmannan@ti.com>
Fri, 28 Dec 2012 16:28:50 +0000 (11:28 -0500)
17 files changed:
ti/runtime/netapi/netapi.h
ti/runtime/netapi/netapi_err.h
ti/runtime/netapi/netapi_sched.h
ti/runtime/netapi/netapi_tune.h
ti/runtime/netapi/netapi_util.h
ti/runtime/netapi/pktio.h
ti/runtime/netapi/src/netapi.c
ti/runtime/netapi/src/netapi_init.c
ti/runtime/netapi/src/netapi_loc.h
ti/runtime/netapi/src/netapi_sched.c
ti/runtime/netapi/src/netapi_sec.c
ti/runtime/netapi/src/netcp_cfg.c
ti/runtime/netapi/src/pktio.c
ti/runtime/netapi/test/addsa_test.c
ti/runtime/netapi/test/build/Makefile
ti/runtime/netapi/test/mt_test.c [new file with mode: 0755]
ti/runtime/netapi/test/net_test.c

index 92ed153bf8a1eeedc9555b6a8bb507e04d6bc1a2..4ad0da297426e8295d47aa4f8779e4426818cd18 100755 (executable)
@@ -212,7 +212,7 @@ typedef void * NETAPI_T;
 
 /**
  * @def  NETAPI_NO_MASTER
 
 /**
  * @def  NETAPI_NO_MASTER
- *      This defines no mater, data only
+ *      This defines no master, data only
  */
 #define NETAPI_NO_MASTER   0  //data only
 
  */
 #define NETAPI_NO_MASTER   0  //data only
 
index 86c646cf5fb2543e030c4da3c45bb3f6ea5ae3ce..d36ee6cf9b5e166a2b9afe8be658ba08104ea6c0 100755 (executable)
@@ -58,7 +58,7 @@
 /**
  *  @def  NETAPI_ERR_NOMEM
  *  @ingroup netapi_errors
 /**
  *  @def  NETAPI_ERR_NOMEM
  *  @ingroup netapi_errors
- *  @brief   out of memory error  
+ *  @brief   out of memory error
  */
 #define NETAPI_ERR_NOMEM -1
 
  */
 #define NETAPI_ERR_NOMEM -1
 
@@ -99,7 +99,7 @@
 /**
  *  @def  NETAPI_ERR_NOT_IMLEMENTED_
  *  @ingroup netapi_errors
 /**
  *  @def  NETAPI_ERR_NOT_IMLEMENTED_
  *  @ingroup netapi_errors
- *  @brief   Feature not implemented in this version    
+ *  @brief   Feature not implemented in this version
  */
 #define NETAPI_ERR_NOT_IMPLEMENTED -7
 
  */
 #define NETAPI_ERR_NOT_IMPLEMENTED -7
 
  */
 #define NETAPI_ERR_NORES -8
 
  */
 #define NETAPI_ERR_NORES -8
 
+/**
+ *  @def  NETAPI_ERR_NORES
+ *  @ingroup netapi_errors
+ *  @brief   error returned by NETCP PA firmware
+ */
+#define NETAPI_ERR_PA_FW -9
+
+
 /**
  *  @def  NETAPI_ERR_ALREADY_CANCELLED
  *  @ingroup netapi_errors
 /**
  *  @def  NETAPI_ERR_ALREADY_CANCELLED
  *  @ingroup netapi_errors
 /**
  *  @def  NETAPI_ERR_NWAL_TX_ERR
  *  @ingroup netapi_errors
 /**
  *  @def  NETAPI_ERR_NWAL_TX_ERR
  *  @ingroup netapi_errors
- *  @brief   error trying to send to NWAL. 
+ *  @brief   error trying to send to NWAL.
  */
 #define NETAPI_ERR_NWAL_TX_ERR -65536
  */
 #define NETAPI_ERR_NWAL_TX_ERR -65536
+
+
 #endif
 #endif
index 8bf1287a45fa6650f1e22f4d7ebd9573ebf00dd6..a58edd24087674e383d08cd8899cc230d73490a5 100755 (executable)
@@ -152,6 +152,10 @@ typedef struct NETAPI_SCHED_CONFIG_Tag
 #define NETAPI_SCHED_POWER_ALWAYS_ON 100
 
     int idle_time;                          /**< idle time TBD */
 #define NETAPI_SCHED_POWER_ALWAYS_ON 100
 
     int idle_time;                          /**< idle time TBD */
+
+    Bool  yield;                /**< option of thread/core to yield in scheduling loop in no pkts from to process */
+    Bool pollCtrlQ;             /**< option to poll the control queue in scheduling loop */
+    Bool pollGarbageQ;          /**< option to poll the garbage  queue in scheduling loop */
 } NETAPI_SCHED_CONFIG_T;
 
 
 } NETAPI_SCHED_CONFIG_T;
 
 
index 7d319101e47bacbb82a1c91f15b95e1b84635e30..85d2b1d75ea3ca1d83736e875c26d2fdb5e7be52 100755 (executable)
@@ -97,7 +97,7 @@
 * @def TUNE_NETAPI_NUM_CORES
 *       This defines the number of cores (theads) 
  */
 * @def TUNE_NETAPI_NUM_CORES
 *       This defines the number of cores (theads) 
  */
-#define TUNE_NETAPI_NUM_CORES 4
+#define TUNE_NETAPI_NUM_CORES 5
 
 /**
  * @ingroup tune_parameters
 
 /**
  * @ingroup tune_parameters
index d0a289c969f8c83063a7e673b6f213982f461674..6ec7e45af22bc934fb7292dd943b04c22daca08f 100755 (executable)
@@ -53,15 +53,9 @@ extern uint8_t *netapi_VM_mem_end;
 extern uint8_t *netapi_VM_mem_start_phy;
 extern uint8_t *netapi_VM_mem_end_phy;
 
 extern uint8_t *netapi_VM_mem_start_phy;
 extern uint8_t *netapi_VM_mem_end_phy;
 
-/* timing */
-static inline unsigned long netapi_timing_start(void)
-{
-        volatile int vval;
-        //read clock
-        asm volatile("mrc p15, 0, %0, c9, c13, 0" :  "=r"(vval));
-        return vval;
-}
-#define netapi_timing_stop  netapi_timing_start
+
+#define netapi_timing_start hplib_mUtilGetPmuCCNT
+#define netapi_timing_stop  hplib_mUtilGetPmuCCNT
 
 //netapi kernel module access routines
 int  netapi_utilModInit(void);
 
 //netapi kernel module access routines
 int  netapi_utilModInit(void);
index 453a489914219dd215a28fdbefbcd24edc8955da..c584d5bd62b71d67a61a8219bcf999b998aa6ae1 100755 (executable)
@@ -58,6 +58,9 @@
 
 /*--------------------defines-----------------------*/
 
 
 /*--------------------defines-----------------------*/
 
+
+//#define PKTIO_GET_BENCHMARK
+
 /**
  * @def PKTIO_NOMEM
  * @ingroup pktio_constants
 /**
  * @def PKTIO_NOMEM
  * @ingroup pktio_constants
@@ -413,6 +416,18 @@ typedef struct PKTIO_HANDLE_Tag
     PKTIO_POLL _poll;               /**<pktio type specific POLL function */
     int poll_flags;
     char name[PKTIO_MAX_NAME+1];    /**< Name of pktio channel */
     PKTIO_POLL _poll;               /**<pktio type specific POLL function */
     int poll_flags;
     char name[PKTIO_MAX_NAME+1];    /**< Name of pktio channel */
+#ifdef PKTIO_GET_BENCHMARK
+    /* for benchmarking .. need to be defined somewhere */
+    unsigned int vv7p;
+    unsigned int vv8p;
+    unsigned int vv9p;
+    unsigned int vv10p;
+    unsigned int vv11p;
+    unsigned int vv12p;
+    unsigned int vv13p;  //rcv path
+    unsigned int vv14p;
+    unsigned int vv15p;
+#endif
 }  PKTIO_HANDLE_T;
 
 
 }  PKTIO_HANDLE_T;
 
 
index b9fcc578a4004254e56f46fbf049daa8a531ed8b..fc52ef4acbfdecb078cc8c497dec9ff3ac4f82dd 100755 (executable)
@@ -46,6 +46,7 @@
 #include <string.h>
 #include "netapi.h"
 
 #include <string.h>
 #include "netapi.h"
 
+
 typedef struct PRESET_Tag
 {
 #define KMAXQ 10
 typedef struct PRESET_Tag
 {
 #define KMAXQ 10
@@ -105,77 +106,101 @@ void netapi_zapQ(int queueNum);
  *-------------------------------------*/
 NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg)
 {
  *-------------------------------------*/
 NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg)
 {
- int i;
- int err;
- NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) calloc(1,sizeof(NETAPI_HANDLE_T));
- NETAPI_HANDLE_T * p_master;
- if (!p) return NULL;
- p->master = master;
-
- /* create space for our local pktios */
- for(i=0;i<NETAPI_MAX_PKTIO; i++)
- {
-   p->pktios[i] = calloc(1,sizeof(PKTIO_HANDLE_T));
-  if (!p->pktios[i]) return NULL;
- }
+    int i;
+    int err;
+    NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) calloc(1,sizeof(NETAPI_HANDLE_T));
+    NETAPI_HANDLE_T * p_master;
+    if (!p) return NULL;
+    p->master = master;
+
+    /* create space for our local pktios */
+    for(i=0;i<NETAPI_MAX_PKTIO; i++)
+    {
+        p->pktios[i] = calloc(1,sizeof(PKTIO_HANDLE_T));
+        if (!p->pktios[i])
+        {
+            return NULL;
+        }
+    }
 
 #ifdef NETAPI_INCLUDE_SCHED
 
 #ifdef NETAPI_INCLUDE_SCHED
- /* create space for scheduler */
- p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));
-#endif 
-
-
- /* global stuff (if master) */
- if (master==NETAPI_SYS_MASTER)
- {
-   if (p_cfg) memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T));
-   else      memcpy(&netapi_global.cfg,&netapi_default_cfg, sizeof(NETAPI_CFG_T));
-   for(i=0;i<NETAPI_MAX_PKTIO;i++) 
-   { 
-       netapi_global.pktios[i].qn.qNum=-1;
-        netapi_global.pktios[i].name[0]='\0';
-   }
- }   
- //this goes to shared memory eventually
- p->global = (void *) &netapi_global;
-
- //dalmt: save master's handle back in global; else for slave retrieve p_master
- if (master==NETAPI_SYS_MASTER)
- {
-    netapi_global.p_master = p;
- }
- else
- {
-    p_master=(NETAPI_HANDLE_T *)netapi_global.p_master;
- }
-
-   /* system init */
-   if(master==NETAPI_SYS_MASTER)
-   {
-      err = system_init(p);
-      if (err<0) 
-      {
-       //todo: cleanup
-       return NULL;
-      }
-      /* create pktio channels for tx,rx */
-   }
-   else if (master==NETAPI_NO_MASTER)
-   {
-   //dalmt ->simple trial.  Just copy master's packetio list for now
+    /* create space for scheduler */
+    p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));
+#endif
+
+
+    /* global stuff (if master) */
+    if (master==NETAPI_SYS_MASTER)
+    {
+        if (p_cfg)
+        {
+            memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T));
+        }
+        else
+        {
+            memcpy(&netapi_global.cfg,&netapi_default_cfg, sizeof(NETAPI_CFG_T));
+        }
+        for(i=0;i<NETAPI_MAX_PKTIO;i++) 
+        {
+            netapi_global.pktios[i].qn.qNum=-1;
+            netapi_global.pktios[i].name[0]='\0';
+        }
+    }
+    //this goes to shared memory eventually
+    p->global = (void *) &netapi_global;
+
+    //dalmt: save master's handle back in global; else for slave retrieve p_master
+    if (master==NETAPI_SYS_MASTER)
+    {
+        netapi_global.p_master = p;
+    }
+    else
+    {
+        /* get system master reqquired for core and no master */
+        p_master=(NETAPI_HANDLE_T *)netapi_global.p_master;
+    }
+
+    /* system init */
+    if(master==NETAPI_SYS_MASTER)
+    {
+        err = system_init(p);
+        if (err<0) 
+        {
+            //todo: cleanup
+            return NULL;
+        }
+    /* create pktio channels for tx,rx */
+    }
+    else if (master==NETAPI_NO_MASTER)
+    {
+        //dalmt ->simple trial.  Just copy master's packetio list for now
         p->n_pktios = p_master->n_pktios;
         memcpy(&p->pktios[0],&p_master->pktios[0],NETAPI_MAX_PKTIO*sizeof(PKTIO_HANDLE_T));
         p->nwal_local=p_master->nwal_local;
         p->n_pktios = p_master->n_pktios;
         memcpy(&p->pktios[0],&p_master->pktios[0],NETAPI_MAX_PKTIO*sizeof(PKTIO_HANDLE_T));
         p->nwal_local=p_master->nwal_local;
-   }
-   else
-   {
-       /*todo init for non-system cores/threads */
-       /* qm_start, */
-       /* attach to heaps */
-       /* nwal_start */
-   }
-  
-   return (NETAPI_T) p;
+    }
+    /* this is the NETAPI_CORE_MASTER case */
+     else if (master==NETAPI_CORE_MASTER)
+    {
+
+        /* Start the QMSS. */
+        if (netapi_start_qm() != 1)
+        {
+            return -1;
+        }
+        netapi_start_nwal(p_master->netcp_heap, 
+                                       p_master->netcp_control_rx_heap,
+                                       p_master->netcp_control_tx_heap, 
+                                       &p->nwal_local,
+                                       &netapi_global.cfg,
+                                       &netapi_global.nwal_context);
+    }
+    else
+    {
+        printf("netapi_init: no master specified\n");
+        return -1;
+    }
+//#endif
+    return (NETAPI_T) p;
 }
 
 /*-------------------------------
 }
 
 /*-------------------------------
@@ -188,7 +213,7 @@ void netapi_shutdown(NETAPI_T h)
        if (!p) return;
 
         printf(">netapi: WARNING shutdown may not be fully implemented\n");
        if (!p) return;
 
         printf(">netapi: WARNING shutdown may not be fully implemented\n");
-       if (p->master)
+       if (p->master ==NETAPI_SYS_MASTER)
         {
            /* close nwal */
            nwal_delete(netapi_global.nwal_context.nwalInstHandle);
         {
            /* close nwal */
            nwal_delete(netapi_global.nwal_context.nwalInstHandle);
@@ -236,6 +261,8 @@ static int system_init(NETAPI_HANDLE_T * handle)
     Pktlib_HeapHandle   controlRxHeapHandle,controlTxHeapHandle;    
     Pktlib_HeapCfg      heapCfg;
     int32_t             errCode;
     Pktlib_HeapHandle   controlRxHeapHandle,controlTxHeapHandle;    
     Pktlib_HeapCfg      heapCfg;
     int32_t             errCode;
+    int count=0;
+    
 #ifdef NETAPI_USE_DDR
     /* Init attributes for DDR */
     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
 #ifdef NETAPI_USE_DDR
     /* Init attributes for DDR */
     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
@@ -419,6 +446,14 @@ printf(">system_init: returned from netapi_qm_setup_mem_region\n");
     if (result<0) {printf(">netapi  init_nwal() failed\n"); return -1; }
  printf("system_init: returned from netapi_init_nwal\n");
     /* start NWAL */
     if (result<0) {printf(">netapi  init_nwal() failed\n"); return -1; }
  printf("system_init: returned from netapi_init_nwal\n");
     /* start NWAL */
+
+
+    /* Common Initialization for all cores */
+    while(count < TUNE_NETAPI_MAX_NUM_TRANS)
+    {
+        netapi_global.nwal_context.transInfos[count].transId = count;
+        count++;
+    }
     result = netapi_start_nwal(sharedHeapHandle, 
                                controlRxHeapHandle,
                                controlTxHeapHandle,
     result = netapi_start_nwal(sharedHeapHandle, 
                                controlRxHeapHandle,
                                controlTxHeapHandle,
index bad13f42d881fc1caa22aa71c6f502123504644f..b59ea2abe17272997118b8578f202705e20636a3 100755 (executable)
@@ -422,18 +422,12 @@ int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
                       NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context  )
 {
     nwalLocCfg_t    nwalLocCfg;
                       NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context  )
 {
     nwalLocCfg_t    nwalLocCfg;
-    int count;
+    int count=0;
+    static int first_time = 0;
     nwal_RetValue       nwalRetVal;
 
     memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
 
     nwal_RetValue       nwalRetVal;
 
     memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
 
-    /* Common Initialization for all cores */
-    while(count < TUNE_NETAPI_MAX_NUM_TRANS)
-    {
-        p_nwal_glob_context->transInfos[count].transId = count;
-        count++;
-    }
-
     /* Update the Start of Packet Offset for the default flows created 
      * by NWAL
      */
     /* Update the Start of Packet Offset for the default flows created 
      * by NWAL
      */
index 0c2d2aa813c35702aa8967e001c007b2e78c7082..1f1ed605de47a2e48d3a8a551df77911e96e1f6f 100755 (executable)
@@ -94,6 +94,7 @@ typedef struct {
 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING     1
 #define NETAPI_NWAL_HANDLE_STATE_OPEN             2
 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING    3
 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING     1
 #define NETAPI_NWAL_HANDLE_STATE_OPEN             2
 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING    3
+#define NETAPI_NWAL_HANDLE_STATE_ERR                        4
     nwal_Handle             handle;
     uint64_t                transId;
     NETAPI_T                netapi_handle; //the thread making the transaction
     nwal_Handle             handle;
     uint64_t                transId;
     NETAPI_T                netapi_handle; //the thread making the transaction
@@ -184,33 +185,32 @@ NETAPI_T p_master;  //DALMT save p'masters handle
  **************************************/
 typedef struct NETAPI_HANDLE_Tag
 {
  **************************************/
 typedef struct NETAPI_HANDLE_Tag
 {
-int master; //master type
+    int master; //master type
 
 
-void * global;  /* pointer to the global area */
+    void * global;  /* pointer to the global area */
 
 
-/* heap  handles */
-Pktlib_HeapHandle   netcp_heap;    /* internal default */
-Pktlib_HeapHandle   netcp_control_rx_heap; /* for control messages */
-Pktlib_HeapHandle   netcp_control_tx_heap; /* for control messages */
-Pktlib_HeapHandle  createdHeaps[TUNE_NETAPI_MAX_HEAPS];  /* created by app and registered */
+    /* heap  handles */
+    Pktlib_HeapHandle   netcp_heap;    /* internal default */
+    Pktlib_HeapHandle   netcp_control_rx_heap; /* for control messages */
+    Pktlib_HeapHandle   netcp_control_tx_heap; /* for control messages */
+    Pktlib_HeapHandle  createdHeaps[TUNE_NETAPI_MAX_HEAPS];  /* created by app and registered */
 
 
-/* pktios defined */
-int n_pktios; /* #of pktios that are active for this instance */
-void*  pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
+    /* pktios defined */
+    int n_pktios; /* #of pktios that are active for this instance */
+    void*  pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
 
 
-/* scheduler stuff.  unallocated if NETAPI_INCLUDE_SCHED not set */
-void * p_sched;
+    /* scheduler stuff.  unallocated if NETAPI_INCLUDE_SCHED not set */
+    void * p_sched;
 
 
-/* nwal local context */
-NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
+    /* nwal local context */
+    NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
 
 
-/* security stuff */
+    /* security stuff */
 
 
-/* timer stuff */
-
-/* thread cookie */
-void * cookie;  /*set by calling thread */
+    /* timer stuff */
 
 
+    /* thread cookie */
+    void * cookie;  /*set by calling thread */
 } NETAPI_HANDLE_T;
 
 
 } NETAPI_HANDLE_T;
 
 
@@ -378,6 +378,7 @@ void *netcp_cfgp_get_sa_handles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
                           int sa_slot, void ** p_sideband);
 void* netcp_cfgp_get_mac_handle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
 NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
                           int sa_slot, void ** p_sideband);
 void* netcp_cfgp_get_mac_handle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
 NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
+void netapip_FreeTransInfo(NetapiNwalTransInfo_t* pTransInfo);
 void *netcp_cfgp_get_policy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
                           int policy_slot);
 #endif
 void *netcp_cfgp_get_policy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
                           int policy_slot);
 #endif
index 1b5f5a2b1758e6baebb8e9ac7f38c0370dc2e847..cc5c657f8fc432f0fda7065a9f5018effbefec63 100755 (executable)
@@ -124,6 +124,10 @@ int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int *p_err)
      cache_op_b2= Osal_cache_op_measure(&n_c_ops);
      t1=hplib_mUtilGetPmuCCNT();
      pkts=pktio_pollAll((NETAPI_T) s->back, NULL, &err);
      cache_op_b2= Osal_cache_op_measure(&n_c_ops);
      t1=hplib_mUtilGetPmuCCNT();
      pkts=pktio_pollAll((NETAPI_T) s->back, NULL, &err);
+     if (!pkts  && (s->config.yield == TRUE))
+     {
+        sched_yield();
+     }
      t2=hplib_mUtilGetPmuCCNT();
      if (pkts)
      {
      t2=hplib_mUtilGetPmuCCNT();
      if (pkts)
      {
@@ -135,7 +139,10 @@ int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int *p_err)
 
 #ifndef NO_GARBAGE
     //poll pktlib garbage collections for registered heaps..
 
 #ifndef NO_GARBAGE
     //poll pktlib garbage collections for registered heaps..
-    netapi_pollHeapGarbage((NETAPI_T) s->back);
+    if (TRUE== s->config.pollGarbageQ)
+    {
+        netapi_pollHeapGarbage((NETAPI_T) s->back);
+     }
 #endif    
 
 #ifndef NO_TIMER
 #endif    
 
 #ifndef NO_TIMER
@@ -143,7 +150,10 @@ int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int *p_err)
     hplib_TimerPollAllGroups((NETAPI_T) s->back, HPLIB_TIMER_FITLER_ALL, 100000);
 #endif
     //poll NETCP/PA control channels 
     hplib_TimerPollAllGroups((NETAPI_T) s->back, HPLIB_TIMER_FITLER_ALL, 100000);
 #endif
     //poll NETCP/PA control channels 
-    netapi_netcpPoll((NETAPI_T) s->back);
+    if (TRUE== s->config.pollGarbageQ)
+    {
+        netapi_netcpPoll((NETAPI_T) s->back);
+    }
 
     //see if time to do a house keeping callback
      if ((s->config.valid_flags & NETAPI_SCHED_CBV) && s->config.house_cb)
 
     //see if time to do a house keeping callback
      if ((s->config.valid_flags & NETAPI_SCHED_CBV) && s->config.house_cb)
@@ -155,6 +165,7 @@ int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int *p_err)
     //see if we were closed and/or its time to close
     if (s->state!= NETAPI_SCHED_STATE_OPEN) 
          { s->state=NETAPI_SCHED_STATE_CLOSE; break;}
     //see if we were closed and/or its time to close
     if (s->state!= NETAPI_SCHED_STATE_OPEN) 
          { s->state=NETAPI_SCHED_STATE_CLOSE; break;}
+   
   }
   return 1;
 }
   }
   return 1;
 }
index 388e2e19052489a86ccd1ed8e4494c157f3fd486..7574bb8b47018f415c5f724ea401a7e0377743f6 100755 (executable)
@@ -58,40 +58,40 @@ NETCP_CFG_SA_T netapi_secAddSA(NETAPI_T h, //the  netapi handle
                                 void **p_inflow_mode_handle,
                                 int * perr)
 {
                                 void **p_inflow_mode_handle,
                                 int * perr)
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
-unsigned int appId = NETAPI_NETCP_MATCH_IPSEC | iface_no;
-int tunnelId;
-nwalSaIpSecId_t  saInfo;
-int have_to_wait=1;
-nwalCreateSAParams_t    createParam =
-{
-/* mac handle */
-       NULL,  //to be filled in
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
+    unsigned int appId = NETAPI_NETCP_MATCH_IPSEC | iface_no;
+    int tunnelId;
+    nwalSaIpSecId_t  saInfo;
+    int have_to_wait=1;
+    nwalCreateSAParams_t    createParam =
+    {
+        /* mac handle */
+        NULL,  //to be filled in
         4,
 
         4,
 
-/*nwalSaIpSecParam_t */  
-    {   
-        0,/* validParams */
-        nwal_SA_MODE_TUNNEL,  //update from input
-        64,/* replayWindow */
-        NWAL_SA_DIR_INBOUND,
-        0,
-        0,
-        NWAL_SA_AALG_HMAC_SHA1,                     /* update from input */
-        NWAL_SA_EALG_AES_CTR,                       /* update from input */
-        { 0x00},      /* remMacAddr:  NA */
-        12,                                                         /* update from input, mac size */
-        NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE,       /* Continue parsing to next route for match */
-        NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
-        CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
-        QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
-    },
-    /* nwalSaIpSecKeyParams_t */
-    {0}
-};
+        /*nwalSaIpSecParam_t */  
+            {   
+                0,/* validParams */
+                nwal_SA_MODE_TUNNEL,  //update from input
+                64,/* replayWindow */
+                NWAL_SA_DIR_INBOUND,
+                0,
+                0,
+                NWAL_SA_AALG_HMAC_SHA1,                     /* update from input */
+                NWAL_SA_EALG_AES_CTR,                       /* update from input */
+                { 0x00},      /* remMacAddr:  NA */
+                12,                                                         /* update from input, mac size */
+                NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE,       /* Continue parsing to next route for match */
+                NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
+                CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
+                QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
+        },
+        /* nwalSaIpSecKeyParams_t */
+        {0}
+    };
    void * mac_handle = netcp_cfgp_get_mac_handle(&netapi_get_global()->nwal_context,iface_no);
 
     *perr =0;
    void * mac_handle = netcp_cfgp_get_mac_handle(&netapi_get_global()->nwal_context,iface_no);
 
     *perr =0;
@@ -100,100 +100,119 @@ nwalCreateSAParams_t    createParam =
     //reserve a slot
     tunnelId = netcp_cfgp_find_sa_slot(&netapi_get_global()->nwal_context,
                            iface_no);
     //reserve a slot
     tunnelId = netcp_cfgp_find_sa_slot(&netapi_get_global()->nwal_context,
                            iface_no);
+
+    printf("netapi_secAddSA called for tunnelId %d\n", tunnelId);
     if (tunnelId <0) {*perr= NETAPI_ERR_NOMEM;  return -1; }
     appId |=  (tunnelId<<8);
 
     *p_data_mode_handle= NULL;  
     *p_inflow_mode_handle= NULL;  
 
     if (tunnelId <0) {*perr= NETAPI_ERR_NOMEM;  return -1; }
     appId |=  (tunnelId<<8);
 
     *p_data_mode_handle= NULL;  
     *p_inflow_mode_handle= NULL;  
 
-    if (inflow_mode & NETAPI_SEC_SA_INFLOW)    
+    if (inflow_mode & NETAPI_SEC_SA_INFLOW)
     {
     {
+        pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
+        if (!pTransInfo)
+        {
+            *perr =  NETAPI_ERR_BUSY;
+            netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
+            return -1;
+        }
+        pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA;
+        pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+        pTransInfo->inUse = nwal_TRUE;
+        pTransInfo->netapi_handle = h;
+
+        /* build SA parameters */
+        saInfo.spi = sa_info->spi;
+        memcpy(&saInfo.dst, &sa_info->dst, sizeof( nwalIpAddr_t));
+        memcpy(&saInfo.src, &sa_info->src, sizeof( nwalIpAddr_t));
+        saInfo.proto = sa_info->proto;
+        createParam.macHandle = mac_handle;
+        createParam.ipType = sa_info->ipType;
+        //memcpy(&createParam.saIpSecParam.src,&sa_info->src, sizeof(nwalIpAddr_t));
+        createParam.saIpSecParam.dir = sa_info->dir;
+        createParam.saIpSecParam.saMode = sa_info->saMode;
+        createParam.saIpSecParam.replayWindow = sa_info->replayWindow;
+        createParam.saIpSecParam.authMode = sa_info->authMode;
+        createParam.saIpSecParam.cipherMode = sa_info->cipherMode;
+        createParam.saIpSecParam.esnLo = sa_info->esnLo;
+        createParam.saIpSecParam.esnHi = sa_info->esnHi;
+        if ((sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || (sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
+        {
+            createParam.saIpSecParam.macSize = 16;
+        }
+        if  ((sa_info->authMode == NWAL_SA_AALG_NULL) && 
+            (!((sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || 
+               (sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))))
+        {
+            createParam.saIpSecParam.replayWindow = 0;
+            createParam.saIpSecParam.macSize = 0;
+        }
+        memcpy(&createParam.keyParam,key_params,sizeof(nwalSecKeyParams_t));
 
 
-    pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *perr =  NETAPI_ERR_BUSY;netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId); return -1;}
-    pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA;
-    pTransInfo->netapi_handle = h;
-
-    /* build SA parameters */
-    saInfo.spi = sa_info->spi;
-    memcpy(&saInfo.dst, &sa_info->dst, sizeof( nwalIpAddr_t));
-    memcpy(&saInfo.src, &sa_info->src, sizeof( nwalIpAddr_t));
-    saInfo.proto = sa_info->proto;
-    createParam.macHandle = mac_handle;
-    createParam.ipType = sa_info->ipType;
-    //memcpy(&createParam.saIpSecParam.src,&sa_info->src, sizeof(nwalIpAddr_t));
-    createParam.saIpSecParam.dir = sa_info->dir;
-    createParam.saIpSecParam.saMode = sa_info->saMode;
-    createParam.saIpSecParam.replayWindow = sa_info->replayWindow;
-    createParam.saIpSecParam.authMode = sa_info->authMode;
-    createParam.saIpSecParam.cipherMode = sa_info->cipherMode;
-    createParam.saIpSecParam.esnLo = sa_info->esnLo;
-    createParam.saIpSecParam.esnHi = sa_info->esnHi;
-    if ((sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || (sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
-    {
-       createParam.saIpSecParam.macSize = 16;
-    }
-    if  ((sa_info->authMode == NWAL_SA_AALG_NULL) && 
-        (!((sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || 
-           (sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))))
-    {
-        createParam.saIpSecParam.replayWindow = 0;
-        createParam.saIpSecParam.macSize = 0;
-    }
-    memcpy(&createParam.keyParam,key_params,sizeof(nwalSecKeyParams_t));
+        if (route != NULL)
+        {
+            netcp_cfgp_build_route(route,&createParam.saIpSecParam.appRxPktFlowId, 
+                                         &createParam.saIpSecParam.appRxPktQueue);
+        }
+        
+        //fire off config message
+        retValue = nwal_setSecAssoc (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
+                                        trans_id,
+                                        (nwal_AppId) appId,
+                                        &saInfo,
+                                        &createParam,
+                                        &pTransInfo->handle);
+        if(retValue == nwal_TRANS_COMPLETE)
+        {
+           have_to_wait=0;
+        }
+        else if(retValue !=  nwal_OK)
+        {
+            *perr = NETAPI_ERR_NWAL_ERR0;
+            printf ("netapi_secAddSA: ERROR: nwal_setSecAssoc returned Error Code %d\n",
+                        retValue);
+            netapip_FreeTransInfo(pTransInfo);
+            netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
+            return -1;
+        }
 
 
-    if (route != NULL)
-    {
-        netcp_cfgp_build_route(route,&createParam.saIpSecParam.appRxPktFlowId, 
-                                     &createParam.saIpSecParam.appRxPktQueue);
-    }
-    
-    //fire off config message
-    pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
-    retValue = nwal_setSecAssoc (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
-                                  trans_id,
-                                 (nwal_AppId) appId,
-                                  &saInfo,
-                                  &createParam,
-                                  &pTransInfo->handle);
-    if(retValue == nwal_TRANS_COMPLETE)
-    {
-       have_to_wait=0;
-    }
-    else if(retValue !=  nwal_OK)
-    {
-        *perr = NETAPI_ERR_NWAL_ERR0;
-        printf (">netapi_sec - ERROR: nwal_setSecAssoc returned Error Code %d\n",
-                    retValue);
-        pTransInfo->inUse = nwal_FALSE;
-        netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
-        return -1;
-    }
-    //pTransInfo->inUse = nwal_FALSE;
 
 
-    //wait here until its done since scheduler isn't running yet most likely..
-    // todo:  make this handled by scheduler poll later ??
-    if((trans_id != NWAL_TRANSID_SPIN_WAIT)&&(have_to_wait))
-    {
-        n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        //wait here until its done since scheduler isn't running yet most likely..
+        // todo:  make this handled by scheduler poll later ??
+        if((trans_id != NWAL_TRANSID_SPIN_WAIT)&&(have_to_wait))
         {
         {
-            // if response is there, then this poll squirts out in the CTl poll callback, 
-            // which handles the rest (including decrmenting #pending!!
-            nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+            n->nwal_local.numPendingCfg++;
+            
+            while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                    (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_OPEN))
+            {
+                // if response is there, then this poll squirts out in the CTl poll callback, 
+                // which handles the rest (including decrmenting #pending!!
+                nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+            }
+            if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+            {
+                pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_IDLE;
+                pTransInfo->inUse = nwal_FALSE;
+                *perr = NETAPI_ERR_PA_FW;
+                printf (">netapi_sec - ERROR returned by NETCP PA firmware %d\n",
+                        *perr);
+                
+                netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
+                return -1;
+            }
         }
         }
-    }
-    printf (">netapi sec: SA %d added to mac %d\n", tunnelId, iface_no);
+        printf ("netapi_secAddSA: SA %d added to mac %d\n", tunnelId, iface_no);
 
 
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    *p_inflow_mode_handle=pTransInfo->handle;  
-    pTransInfo->inUse = nwal_FALSE;
+        *p_inflow_mode_handle=pTransInfo->handle;
+        netapip_FreeTransInfo(pTransInfo);
     }
 
     //sideband mode
     if (inflow_mode &NETAPI_SEC_SA_SIDEBAND)
     {
     }
 
     //sideband mode
     if (inflow_mode &NETAPI_SEC_SA_SIDEBAND)
     {
-       nwalCreateDmSAParams_t  dmSaParam;
+        nwalCreateDmSAParams_t  dmSaParam;
         void * dm_handle;
         memset(&dmSaParam,0,sizeof(nwalCreateDmSAParams_t));
         dmSaParam.dmSaParam.dmChnType= (sa_info->dir==NWAL_SA_DIR_INBOUND)?  NWAL_DM_CHAN_DECRYPT: NWAL_DM_CHAN_ENCRYPT; /**direction*/ 
         void * dm_handle;
         memset(&dmSaParam,0,sizeof(nwalCreateDmSAParams_t));
         dmSaParam.dmSaParam.dmChnType= (sa_info->dir==NWAL_SA_DIR_INBOUND)?  NWAL_DM_CHAN_DECRYPT: NWAL_DM_CHAN_ENCRYPT; /**direction*/ 
@@ -228,16 +247,17 @@ nwalCreateSAParams_t    createParam =
                                   &dm_handle);
         if(retValue != nwal_OK)
         {
                                   &dm_handle);
         if(retValue != nwal_OK)
         {
-               *perr = NETAPI_ERR_NWAL_ERR0;
-               printf (">netapi_sec - ERROR: nwal_setDMSecAssoc returned Error Code %d\n",
-                    retValue);
-                netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
-                return -1;
+            *perr = NETAPI_ERR_NWAL_ERR0;
+            printf (">netapi_sec - ERROR: nwal_setDMSecAssoc returned Error Code %d\n",
+            retValue);
+            netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
+            return -1;
         }
         }
-        printf(">netapisec.  Creating sideband mode SA for %d ( mac %d)\n", tunnelId, iface_no); 
+        printf("netapi_secAddSA: Creating sideband mode SA for %d ( mac %d)\n", tunnelId, iface_no); 
         *p_data_mode_handle = dm_handle;
     }
     //save stuff
         *p_data_mode_handle = dm_handle;
     }
     //save stuff
+
     netcp_cfgp_insert_sa(&netapi_get_global()->nwal_context,
                            tunnelId,
                          (sa_info->dir ==   NWAL_SA_DIR_INBOUND) ? TRUE: FALSE,
     netcp_cfgp_insert_sa(&netapi_get_global()->nwal_context,
                            tunnelId,
                          (sa_info->dir ==   NWAL_SA_DIR_INBOUND) ? TRUE: FALSE,
@@ -259,14 +279,14 @@ void netapi_secInflowMode(int iface, NETCP_CFG_SA_T sa,  int on)
 //(internal version)
 static void netapi_secDelSA_internal(NETAPI_T h,int iface_no, NETCP_CFG_SA_T  sa_app_id, int flags, int *perr)
 {
 //(internal version)
 static void netapi_secDelSA_internal(NETAPI_T h,int iface_no, NETCP_CFG_SA_T  sa_app_id, int flags, int *perr)
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
-int tunnelId = (sa_app_id >>8) &0xffff;
-void * handle_inflow;
-void * handle_sideband;
-int have_to_wait = 1;
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
+    int tunnelId = (sa_app_id >>8) &0xffff;
+    void * handle_inflow;
+    void * handle_sideband;
+    int have_to_wait = 1;
 
     handle_inflow = netcp_cfgp_get_sa_handles(&netapi_get_global()->nwal_context,
                                           tunnelId, &handle_sideband);
 
     handle_inflow = netcp_cfgp_get_sa_handles(&netapi_get_global()->nwal_context,
                                           tunnelId, &handle_sideband);
@@ -275,48 +295,63 @@ int have_to_wait = 1;
     if(handle_inflow)
     {
     //get a transaction id
     if(handle_inflow)
     {
     //get a transaction id
-    pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *perr =  NETAPI_ERR_BUSY; return ;}
-    pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA;
-    pTransInfo->netapi_handle = h;
+        pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
+        if (!pTransInfo)
+        {
+            *perr =  NETAPI_ERR_BUSY;
+            return;
+        }
+        pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA;
+        pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING;
+        pTransInfo->inUse = nwal_TRUE;
+        pTransInfo->netapi_handle = h;
 
 
-    //issue request
-    retValue = nwal_delSecAssoc(
+        retValue = nwal_delSecAssoc(
                 ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                 trans_id,
                 handle_inflow);
                 ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                 trans_id,
                 handle_inflow);
-    if(retValue == nwal_TRANS_COMPLETE)
-    {
-       have_to_wait=0;
-    }
-    else
-    if(retValue !=  nwal_OK)
-    {
-        *perr = NETAPI_ERR_NWAL_ERR0;
-        printf (">netapi_sec  - ERROR: nwal_delSA returned Error Code %d\n",
-                    retValue);
-        pTransInfo->inUse = nwal_FALSE;
-        return ;
-    }
-    //wait here until its done since scheduler isn't running yet most likely..
-    // todo:  make this handled by scheduler poll later ??
-    if((trans_id != NWAL_TRANSID_SPIN_WAIT)&&(have_to_wait))
-    {   
-        n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        if(retValue == nwal_TRANS_COMPLETE)
         {
         {
-            // if response is there, then this poll squirts out in the CTl poll callback, 
-            // which handles the rest (including decrmenting #pending!!
-            nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+           have_to_wait=0;
+        }
+        else if(retValue !=  nwal_OK)
+        {
+                *perr = NETAPI_ERR_NWAL_ERR0;
+                printf (">netcp cfg - ERROR: netapi_secDelSA_internal returned Error Code %d\n",
+                            retValue);
+                netapip_FreeTransInfo(pTransInfo);
+                netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
+        }
+        //wait here until its done since scheduler isn't running yet most likely..
+        // todo:  make this handled by scheduler poll later ??
+        if((trans_id != NWAL_TRANSID_SPIN_WAIT)&&(have_to_wait))
+        {
+            n->nwal_local.numPendingCfg++;
+
+            while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                    (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_IDLE))
+            {
+                // if response is there, then this poll squirts out in the CTl poll callback, 
+                // which handles the rest (including decrmenting #pending!!
+                nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+            }
+            if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+            {
+                netapip_FreeTransInfo(pTransInfo);
+                *perr = NETAPI_ERR_PA_FW;
+                 if (!flags) 
+                    netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context, tunnelId);
+                printf (">netapi_sec - ERROR returned by NETCP PA firmware %d\n",
+                        *perr);
+                return;
+           }
         }
         }
-    }   
-    printf (">netapi sec: inflow tunnel %d (iface %d) deleted\n",tunnelId,iface_no);
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+        printf (">netapi sec: inflow tunnel %d (iface %d) deleted\n",tunnelId,iface_no);
+        netapip_FreeTransInfo(pTransInfo);
     }
     if (handle_sideband)
     {
     }
     if (handle_sideband)
     {
-       retValue=nwal_delDMSecAssoc( ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
+        retValue=nwal_delDMSecAssoc( ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                                     handle_sideband);
         if(retValue !=  nwal_OK)
         {
                                     handle_sideband);
         if(retValue !=  nwal_OK)
         {
@@ -325,16 +360,18 @@ int have_to_wait = 1;
                     retValue);
 
         }
                     retValue);
 
         }
-        else printf(">netapi_sec: Sideband SA deleted\n");
-     }
+        else 
+            printf(">netapi_sec: Sideband SA deleted\n");
+    }
    
     //zap the entry
    
     //zap the entry
-    if (!flags) netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context, tunnelId);
+    if (!flags)
+        netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context, tunnelId);
 }
 }
-//external version
+
 void netapi_secDelSA(NETAPI_T h,int iface_no, NETCP_CFG_SA_T  sa_app_id,  int *perr)
 {
 void netapi_secDelSA(NETAPI_T h,int iface_no, NETCP_CFG_SA_T  sa_app_id,  int *perr)
 {
-netapi_secDelSA_internal( h, iface_no,  sa_app_id, 0x00, perr);
+    netapi_secDelSA_internal( h, iface_no,  sa_app_id, 0x00, perr);
 }
 
 
 }
 
 
@@ -350,17 +387,17 @@ NETCP_CFG_IPSEC_POLICY_T netapi_secAddRxPolicy(NETAPI_T h, //the  netapi handle
                                 NETCP_CFG_ROUTE_HANDLE_T  route,  //Optional route
                                 int * perr)
 {
                                 NETCP_CFG_ROUTE_HANDLE_T  route,  //Optional route
                                 int * perr)
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
-unsigned int appId = NETAPI_NETCP_MATCH_IPSEC_POLICY | (sa&0xff);
-int policyId;
-int tunnelId= (sa>>8)&0xff;
-void * blah;
-int iface_no = sa&0xff;
-nwalSecPolParams_t createParam =
-{
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
+    unsigned int appId = NETAPI_NETCP_MATCH_IPSEC_POLICY | (sa&0xff);
+    int policyId;
+    int tunnelId= (sa>>8)&0xff;
+    void * blah;
+    int iface_no = sa&0xff;
+    nwalSecPolParams_t createParam =
+    {
         0,  /* handle */
         NWAL_SA_DIR_INBOUND,
         4,      /* IP Type */
         0,  /* handle */
         NWAL_SA_DIR_INBOUND,
         4,      /* IP Type */
@@ -371,18 +408,29 @@ nwalSecPolParams_t createParam =
         NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
         CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
         QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
         NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
         CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
         QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
-};
-void * sa_handle = NULL;
+    };
+    void * sa_handle = NULL;
 
     *perr =0;
     if ((!n) ) {*perr = NETAPI_ERR_BAD_INPUT; return -1;}
 
     sa_handle = netcp_cfgp_get_sa_handles(&netapi_get_global()->nwal_context,tunnelId,&blah);
 
     *perr =0;
     if ((!n) ) {*perr = NETAPI_ERR_BAD_INPUT; return -1;}
 
     sa_handle = netcp_cfgp_get_sa_handles(&netapi_get_global()->nwal_context,tunnelId,&blah);
-    if (!sa_handle) {*perr = NETAPI_ERR_BAD_INPUT; return -1;}
+    if (!sa_handle)
+    {
+        *perr = NETAPI_ERR_BAD_INPUT;
+        return -1;
+    }
 
 
+    //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *perr =  NETAPI_ERR_BUSY; return -1;}
+    if (!pTransInfo)
+    {
+        *perr =  NETAPI_ERR_BUSY;
+        return -1;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA_POLICY;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA_POLICY;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
     pTransInfo->netapi_handle = h;
     createParam.handle = sa_handle;
     createParam.ipType = ipType;
     pTransInfo->netapi_handle = h;
     createParam.handle = sa_handle;
     createParam.ipType = ipType;
@@ -397,11 +445,16 @@ void * sa_handle = NULL;
     //reserve a slot
     policyId = netcp_cfgp_find_policy_slot(&netapi_get_global()->nwal_context,
                            tunnelId);
     //reserve a slot
     policyId = netcp_cfgp_find_policy_slot(&netapi_get_global()->nwal_context,
                            tunnelId);
-    if (policyId <0) {*perr= NETAPI_ERR_NOMEM;  return -1; }
+    if (policyId <0) 
+    {
+        *perr= NETAPI_ERR_NOMEM;
+        netapip_FreeTransInfo(pTransInfo);
+        return -1;
+    }
     appId |=  (policyId<<8);
 
     //fire off config message
     appId |=  (policyId<<8);
 
     //fire off config message
-    pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+
 
     retValue = nwal_setSecPolicy (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                                   trans_id,
 
     retValue = nwal_setSecPolicy (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                                   trans_id,
@@ -413,23 +466,33 @@ void * sa_handle = NULL;
         *perr = NETAPI_ERR_NWAL_ERR0;
         printf (">netapi sec - ERROR: nwal_setPolicy returned Error Code %d\n",
                     retValue);
         *perr = NETAPI_ERR_NWAL_ERR0;
         printf (">netapi sec - ERROR: nwal_setPolicy returned Error Code %d\n",
                     retValue);
-        pTransInfo->inUse = nwal_FALSE;
+        netapip_FreeTransInfo(pTransInfo);
+        
         netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context,policyId);
         return -1;
     }
         netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context,policyId);
         return -1;
     }
-    //pTransInfo->inUse = nwal_FALSE;
 
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
 
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_OPEN))
         {
             // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
         {
             // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
+        if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+        {
+            netapip_FreeTransInfo(pTransInfo);
+            *perr = NETAPI_ERR_PA_FW;
+            printf (">netapi_sec - ERROR2: netapi_secAddRxPolicy returned Error Code %d\n",
+                    *perr);
+            netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context,policyId);
+            return -1;
+        }
     }
     printf (">netapi sec: SA %d added to tunnel %d  mac %d\n", policyId, tunnelId, iface_no);
 
     }
     printf (">netapi sec: SA %d added to tunnel %d  mac %d\n", policyId, tunnelId, iface_no);
 
@@ -439,8 +502,7 @@ void * sa_handle = NULL;
     netcp_cfgp_insert_policy(&netapi_get_global()->nwal_context,
                            policyId,
                           (void *) pTransInfo->handle);
     netcp_cfgp_insert_policy(&netapi_get_global()->nwal_context,
                            policyId,
                           (void *) pTransInfo->handle);
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+    netapip_FreeTransInfo(pTransInfo);
     return  (appId);
 }
 
     return  (appId);
 }
 
@@ -449,12 +511,12 @@ void * sa_handle = NULL;
 //***********************
 static void netapi_secDelRxPolicy_internal(NETAPI_T h, NETCP_CFG_IPSEC_POLICY_T policy_app_id, int flags, int *perr)
 {
 //***********************
 static void netapi_secDelRxPolicy_internal(NETAPI_T h, NETCP_CFG_IPSEC_POLICY_T policy_app_id, int flags, int *perr)
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
-int policyId = (policy_app_id >>8) &0xffff;
-void * handle_policy=NULL;
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
+    int policyId = (policy_app_id >>8) &0xffff;
+    void * handle_policy=NULL;
 
     handle_policy = netcp_cfgp_get_policy(&netapi_get_global()->nwal_context,policyId);
                                           ;
 
     handle_policy = netcp_cfgp_get_policy(&netapi_get_global()->nwal_context,policyId);
                                           ;
@@ -463,8 +525,14 @@ void * handle_policy=NULL;
 
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
 
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *perr =  NETAPI_ERR_BUSY; return ;}
+    if (!pTransInfo)
+    {
+        *perr =  NETAPI_ERR_BUSY;
+        return -1;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA_POLICY;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_SA_POLICY;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
     pTransInfo->netapi_handle = h;
 
     //issue request
     pTransInfo->netapi_handle = h;
 
     //issue request
@@ -475,9 +543,9 @@ void * handle_policy=NULL;
     if(retValue !=  nwal_OK)
     {
         *perr = NETAPI_ERR_NWAL_ERR0;
     if(retValue !=  nwal_OK)
     {
         *perr = NETAPI_ERR_NWAL_ERR0;
-        printf (">netsec  - ERROR: nwal_delSAPolicy returned Error Code %d\n",
+        printf (">netapi sec - ERROR: netapi_secDelRxPolicy_internal returned Error Code %d\n",
                     retValue);
                     retValue);
-        pTransInfo->inUse = nwal_FALSE;
+        netapip_FreeTransInfo(pTransInfo);
         return ;
     }
     //wait here until its done since scheduler isn't running yet most likely..
         return ;
     }
     //wait here until its done since scheduler isn't running yet most likely..
@@ -485,16 +553,28 @@ void * handle_policy=NULL;
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                    (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_IDLE))
         {
         {
-        // if response is there, then this poll squirts out in the CTl poll callback, 
+            // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
+        if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+        {
+            netapip_FreeTransInfo(pTransInfo);
+            *perr = NETAPI_ERR_PA_FW;
+            printf (">netapi_sec - ERROR2: netapi_secDelRxPolicy_internal returned Error Code %d\n",
+                    *perr);
+            //zap the entry
+            if (!flags)
+                netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context, policyId);
+            return -1;
+            
+        }
     }
     printf (">netapi sec: policy %d (iface %d) deleted\n",policyId,(policy_app_id&0xff));
     }
     printf (">netapi sec: policy %d (iface %d) deleted\n",policyId,(policy_app_id&0xff));
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+    netapip_FreeTransInfo(pTransInfo);
     //zap the entry
     if (!flags) netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context, policyId);
 }
     //zap the entry
     if (!flags) netcp_cfgp_delete_policy(&netapi_get_global()->nwal_context, policyId);
 }
@@ -504,7 +584,7 @@ void * handle_policy=NULL;
 //***********************
 void netapi_secDelRxPolicy(NETAPI_T h, NETCP_CFG_IPSEC_POLICY_T policy_app_id, int *perr)
 {
 //***********************
 void netapi_secDelRxPolicy(NETAPI_T h, NETCP_CFG_IPSEC_POLICY_T policy_app_id, int *perr)
 {
-netapi_secDelRxPolicy_internal(h,  policy_app_id, 0, perr);
+    netapi_secDelRxPolicy_internal(h,  policy_app_id, 0, perr);
 }
 
 
 }
 
 
index 0d0ed36e8a1981ced24e1c99aee3f73187f46855..957b53341b3cff1f365e059067891d7e42131b0e 100755 (executable)
@@ -51,7 +51,7 @@
 /******************************************************************
  ********************Utility*************************************
 *******************************************************************/
 /******************************************************************
  ********************Utility*************************************
 *******************************************************************/
-
+static hplib_spinLock_T netcp_cfg_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
 
 //get a free transaction id
 NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId)
 
 //get a free transaction id
 NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId)
@@ -59,23 +59,33 @@ NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwa
          uint16_t    count=0;
 
        count=0;
          uint16_t    count=0;
 
        count=0;
+            hplib_mSpinLockLock(&netcp_cfg_lock);
         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
         {
             if((p_global->nwal_context.transInfos[count].inUse) != nwal_TRUE)
             {
                 p_global->nwal_context.transInfos[count].inUse = nwal_TRUE;
                 *pTransId = count;
         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
         {
             if((p_global->nwal_context.transInfos[count].inUse) != nwal_TRUE)
             {
                 p_global->nwal_context.transInfos[count].inUse = nwal_TRUE;
                 *pTransId = count;
+                        hplib_mSpinLockUnlock(&netcp_cfg_lock);
                 return(&p_global->nwal_context.transInfos[count]);
             }
             count++;
         }
                 return(&p_global->nwal_context.transInfos[count]);
             }
             count++;
         }
-         
+         hplib_mSpinLockUnlock(&netcp_cfg_lock);
         /* trouble.  need to wait for one to free up*/
         /* to do: handle this by forcing a poll of cntrl queue*/
         printf(">netcp_cfg: trying to get free transaction slot but all full!!\n");
         /* trouble.  need to wait for one to free up*/
         /* to do: handle this by forcing a poll of cntrl queue*/
         printf(">netcp_cfg: trying to get free transaction slot but all full!!\n");
+                
         return NULL;
 
 }
         return NULL;
 
 }
+
+void netapip_FreeTransInfo(NetapiNwalTransInfo_t *pTransInfo)
+{
+    pTransInfo->inUse = nwal_FALSE;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_IDLE;
+    pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_NONE;
+}
 //internal: build route
 void netcp_cfgp_build_route(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow,  Qmss_QueueHnd * p_q)
 {
 //internal: build route
 void netcp_cfgp_build_route(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow,  Qmss_QueueHnd * p_q)
 {
@@ -96,6 +106,7 @@ int netcp_cfgp_find_policy_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int tunnel)
    int i;
    if ((tunnel <0 ) || (tunnel >=TUNE_NETAPI_MAX_SA)) return -1;
 
    int i;
    if ((tunnel <0 ) || (tunnel >=TUNE_NETAPI_MAX_SA)) return -1;
 
+        hplib_mSpinLockLock(&netcp_cfg_lock);
          //find a free entry
    for(i=0;i<TUNE_NETAPI_MAX_POLICY;i++)
    {
          //find a free entry
    for(i=0;i<TUNE_NETAPI_MAX_POLICY;i++)
    {
@@ -103,9 +114,11 @@ int netcp_cfgp_find_policy_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int tunnel)
        {
            p->policy[i].in_use = 2; //pending
            p->policy[i].tunnel= tunnel; //save tunnel this is linked to 
        {
            p->policy[i].in_use = 2; //pending
            p->policy[i].tunnel= tunnel; //save tunnel this is linked to 
+            hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+           hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
 
    return -1;
 }
 
@@ -152,6 +165,7 @@ int netcp_cfgp_find_sa_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int iface)
    {
    if ((iface <0 ) || (iface >=TUNE_NETAPI_MAX_NUM_MAC)) return -1;
    }
    {
    if ((iface <0 ) || (iface >=TUNE_NETAPI_MAX_NUM_MAC)) return -1;
    }
+           hplib_mSpinLockLock(&netcp_cfg_lock);
          //find a free entry
    for(i=0;i<TUNE_NETAPI_MAX_SA;i++)
    {                       
          //find a free entry
    for(i=0;i<TUNE_NETAPI_MAX_SA;i++)
    {                       
@@ -159,9 +173,11 @@ int netcp_cfgp_find_sa_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int iface)
        {
            p->tunnel[i].in_use = 2; //pending
            p->tunnel[i].iface= iface; //save iface
        {
            p->tunnel[i].in_use = 2; //pending
            p->tunnel[i].iface= iface; //save iface
+           hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+   hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
  //internal: delete an SAr from list 
    return -1;
 }
  //internal: delete an SAr from list 
@@ -212,14 +228,17 @@ static int netcp_cfgp_find_flow_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p)
 {
    int i;
          //find a free entry
 {
    int i;
          //find a free entry
+     hplib_mSpinLockLock(&netcp_cfg_lock);
    for(i=0;i<TUNE_NETAPI_MAX_FLOWS;i++)
    {
        if (!p->flows[i].in_use)
        {
            p->flows[i].in_use = 2; //pending
    for(i=0;i<TUNE_NETAPI_MAX_FLOWS;i++)
    {
        if (!p->flows[i].in_use)
        {
            p->flows[i].in_use = 2; //pending
+           hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+   hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
 
    return -1;
 }
 
@@ -250,14 +269,17 @@ static int netcp_cfgp_find_flow(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
 {
 int i;
    *handle=NULL;
 {
 int i;
    *handle=NULL;
+     hplib_mSpinLockLock(&netcp_cfg_lock);
    for(i=0;i<TUNE_NETAPI_MAX_FLOWS;i++)
    {
        if ((p->flows[i].in_use)&&(p->flows[i].flow.flowid == flowid))
        {
            *handle = p->flows[i].handle;
    for(i=0;i<TUNE_NETAPI_MAX_FLOWS;i++)
    {
        if ((p->flows[i].in_use)&&(p->flows[i].flow.flowid == flowid))
        {
            *handle = p->flows[i].handle;
+             hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+    hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
 
    return -1;
 }
 
@@ -271,14 +293,17 @@ static int netcp_cfgp_find_ip_slot(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
    int i;
 
    //find a free entry
    int i;
 
    //find a free entry
+    hplib_mSpinLockLock(&netcp_cfg_lock);
    for(i=0;i<TUNE_NETAPI_MAX_NUM_IP;i++)
    {
        if (!p->ips[i].in_use)
        {
            p->ips[i].in_use = 2; //pending
    for(i=0;i<TUNE_NETAPI_MAX_NUM_IP;i++)
    {
        if (!p->ips[i].in_use)
        {
            p->ips[i].in_use = 2; //pending
+            hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+    hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
 
    return -1;
 }
 
@@ -340,6 +365,7 @@ static void netcp_cfgp_insert_mac(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, unsigned char
         p->interfaces[iface_no].state = state;
         //todo p->interfaces[iface_no].vlan = vlan;
         p->interfaces[iface_no].nwal_handle = handle; //save handle assoicated with this rule
         p->interfaces[iface_no].state = state;
         //todo p->interfaces[iface_no].vlan = vlan;
         p->interfaces[iface_no].nwal_handle = handle; //save handle assoicated with this rule
+        printf("netcp_cfgp_insert_mac, global context 0x%x\n", p);
    }
    else printf(">netcp_cfg insert interface # out of range %d\n",iface_no);
 
    }
    else printf(">netcp_cfg insert interface # out of range %d\n",iface_no);
 
@@ -375,15 +401,18 @@ static void netcp_cfgp_delete_mac(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no)
 static int netcp_cfgp_find_class_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p)
 {
    int i;
 static int netcp_cfgp_find_class_slot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p)
 {
    int i;
-         //find a free entry
+         //find a free entry\
+    hplib_mSpinLockLock(&netcp_cfg_lock);
    for(i=0;i<TUNE_NETAPI_MAX_CLASSIFIERS;i++)
    {
        if (!p->classi[i].in_use)
        {
            p->classi[i].in_use = 2; //pending
    for(i=0;i<TUNE_NETAPI_MAX_CLASSIFIERS;i++)
    {
        if (!p->classi[i].in_use)
        {
            p->classi[i].in_use = 2; //pending
+            hplib_mSpinLockUnlock(&netcp_cfg_lock);
            return i;
        }
    }
            return i;
        }
    }
+    hplib_mSpinLockUnlock(&netcp_cfg_lock);
    return -1;
 }
 
    return -1;
 }
 
@@ -445,29 +474,29 @@ static void *netcp_cfgp_get_l3_handle( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
  ****************************************************************/
 void netcp_cfgReqStats(NETAPI_T  h, NETCP_CFG_STATS_CB cb, int doClear, int *err) 
 {
  ****************************************************************/
 void netcp_cfgReqStats(NETAPI_T  h, NETCP_CFG_STATS_CB cb, int doClear, int *err) 
 {
-nwal_RetValue ret;
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     transId;
-if ((!n) || (!cb)) {*err = NETAPI_ERR_BAD_INPUT; return ;}
-*err =0;
-
-
-pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &transId);
-if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return ;}
-pTransInfo->transType = NETAPI_NWAL_HANDLE_STAT_REQUEST;
-pTransInfo->netapi_handle = h;
-n->nwal_local.stats_cb = cb;
-ret = nwal_getPAStats( ((NETAPI_GLOBAL_T *) n->global)->nwal_context.nwalInstHandle,
-                          transId,
-                          NULL,
-                          doClear);
-if(ret !=  nwal_OK)
-{
-   pTransInfo->inUse = nwal_FALSE;
-   *err = NETAPI_ERR_BUSY;  //no resources??
-   printf("> netcp_cfg reqStats failed, err=%d\n",ret);
-}
+    nwal_RetValue ret;
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     transId;
+    if ((!n) || (!cb)) {*err = NETAPI_ERR_BAD_INPUT; return ;}
+    *err =0;
+
+
+    pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &transId);
+    if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return ;}
+    pTransInfo->transType = NETAPI_NWAL_HANDLE_STAT_REQUEST;
+    pTransInfo->netapi_handle = h;
+    n->nwal_local.stats_cb = cb;
+    ret = nwal_getPAStats( ((NETAPI_GLOBAL_T *) n->global)->nwal_context.nwalInstHandle,
+                              transId,
+                              NULL,
+                              doClear);
+    if(ret !=  nwal_OK)
+    {
+       pTransInfo->inUse = nwal_FALSE;
+       *err = NETAPI_ERR_BUSY;  //no resources??
+       printf("> netcp_cfg reqStats failed, err=%d\n",ret);
+    }
 
 }
 /*****************************************************************
 
 }
 /*****************************************************************
@@ -484,29 +513,36 @@ NETCP_CFG_MACIF_T  netcp_cfgCreateMacInterface(
                   int * err
                   )
 {
                   int * err
                   )
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-nwalMacParam_t   MacInfo= {
-    0,      /* validParams */
-    0,      /* ifNum */
-    0,      /* vlanId      */
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },      /* Local mac */
-    NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE,       /* Continue parsing to next route for match */
-    NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
-    CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
-    QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
-};
-
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    nwalMacParam_t   MacInfo=
+    {
+        0,      /* validParams */
+        0,      /* ifNum */
+        0,      /* vlanId      */
+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },      /* Local mac */
+        NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE,       /* Continue parsing to next route for match */
+        NWAL_NEXT_ROUTE_FAIL_ACTION_HOST,            /* For next route fail action by default is route to host */
+        CPPI_PARAM_NOT_SPECIFIED,                    /* Use default flow configured to NWAL  if packet is routed to host */
+        QMSS_PARAM_NOT_SPECIFIED                     /* Use default queue configured to NWAL if packet is routed to host */
+    };
+
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
 
     if ((!n) || (!p_mac)) {*err = NETAPI_ERR_BAD_INPUT; return -1;}
     *err =0;
 
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
 
     if ((!n) || (!p_mac)) {*err = NETAPI_ERR_BAD_INPUT; return -1;}
     *err =0;
 
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return -1;}
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY;
+        return -1;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_MAC;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_MAC;
-    pTransInfo->netapi_handle = h; 
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
+    pTransInfo->netapi_handle = h;
 
     /* set up MacInfo */
     memcpy(&MacInfo.macAddr,p_mac,6); 
 
     /* set up MacInfo */
     memcpy(&MacInfo.macAddr,p_mac,6); 
@@ -517,7 +553,6 @@ nwal_TransID_t     trans_id;
     {
         netcp_cfgp_build_route(route,&MacInfo.appRxPktFlowId, &MacInfo.appRxPktQueue);
     }
     {
         netcp_cfgp_build_route(route,&MacInfo.appRxPktFlowId, &MacInfo.appRxPktQueue);
     }
-    pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
     retValue = nwal_setMacIface( ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                                   trans_id,
                                   (nwal_AppId) (NETAPI_NETCP_MATCH_GENERIC_MAC | iface_no),
     retValue = nwal_setMacIface( ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                                   trans_id,
                                   (nwal_AppId) (NETAPI_NETCP_MATCH_GENERIC_MAC | iface_no),
@@ -525,32 +560,40 @@ nwal_TransID_t     trans_id;
                                   &pTransInfo->handle);
     if(retValue !=  nwal_OK)
     {
                                   &pTransInfo->handle);
     if(retValue !=  nwal_OK)
     {
-       *err = NETAPI_ERR_NWAL_ERR0;
+        *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg - ERROR: nwal_setMacIface returned Error Code %d\n",
                     retValue);
         printf (">netcp cfg - ERROR: nwal_setMacIface returned Error Code %d\n",
                     retValue);
-        pTransInfo->inUse = nwal_FALSE;
+        netapip_FreeTransInfo(pTransInfo);
         return -1;
     }
         return -1;
     }
-    //pTransInfo->inUse = nwal_FALSE;
 
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
 
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_OPEN))
         {
         {
-           // if response is there, then this poll squirts out in the CTl poll callback, 
+            // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
+        if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+        {
+            netapip_FreeTransInfo(pTransInfo);
+            *err = NETAPI_ERR_PA_FW;
+            printf (">netcp_cfgCreateMacInterface - ERROR returned by NETCP PA firmware %d\n",
+                    *err);
+            return -1;
+        }
+
     }
     printf (">netcp cfg: MAC i/f %d added\n", iface_no);
     netcp_cfgp_insert_mac(&netapi_get_global()->nwal_context, 
                           p_mac, iface_no, state,vlan,
                           (void *) pTransInfo->handle);
     }
     printf (">netcp cfg: MAC i/f %d added\n", iface_no);
     netcp_cfgp_insert_mac(&netapi_get_global()->nwal_context, 
                           p_mac, iface_no, state,vlan,
                           (void *) pTransInfo->handle);
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+    netapip_FreeTransInfo(pTransInfo);
     return  (NETAPI_NETCP_MATCH_GENERIC_MAC | iface_no);
 }
 
     return  (NETAPI_NETCP_MATCH_GENERIC_MAC | iface_no);
 }
 
@@ -574,9 +617,16 @@ void netcp_cfgDelMac(NETAPI_T h,int iface_no,  int *err)
     
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
     
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return ;}
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY;
+        return ;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_MAC;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_MAC;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
     pTransInfo->netapi_handle = h;
     pTransInfo->netapi_handle = h;
+
     //issue request
     ret = nwal_delMacIface(
                 ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
     //issue request
     ret = nwal_delMacIface(
                 ((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
@@ -587,24 +637,33 @@ void netcp_cfgDelMac(NETAPI_T h,int iface_no,  int *err)
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     ret);
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     ret);
-        pTransInfo->inUse = nwal_FALSE;
-        return ;
+        netapip_FreeTransInfo(pTransInfo);
+        return;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_IDLE))
         {
             // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
         {
             // if response is there, then this poll squirts out in the CTl poll callback, 
             // which handles the rest (including decrmenting #pending!!
             nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
         }
+        if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+        {
+            netapip_FreeTransInfo(pTransInfo);
+            *err = NETAPI_ERR_PA_FW;
+            printf (">netcp_cfgCreateMacInterface - ERROR returned by NETCP PA firmware %d\n",
+                    *err);
+              netcp_cfgp_delete_mac(&netapi_get_global()->nwal_context,  iface_no);
+            return -1;
+        }
     }
     printf (">netcp cfg: MAC i/f %d deleted\n",iface_no);
     }
     printf (">netcp cfg: MAC i/f %d deleted\n",iface_no);
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+    netapip_FreeTransInfo(pTransInfo);
     //zap the entry
     netcp_cfgp_delete_mac(&netapi_get_global()->nwal_context,  iface_no);
     return ;
     //zap the entry
     netcp_cfgp_delete_mac(&netapi_get_global()->nwal_context,  iface_no);
     return ;
@@ -650,9 +709,11 @@ NETCP_CFG_IP_T temp;
 
      if (iface_no != NETCP_CFG_NO_INTERFACE)
      {
 
      if (iface_no != NETCP_CFG_NO_INTERFACE)
      {
+        printf("netcp_cfgAddIpInternal, in_use %d\n", netapi_get_global()->nwal_context.interfaces[iface_no].in_use);
+        printf("netcp-cfgAddIpInternal, p 0x%x\n", &netapi_get_global()->nwal_context);
      if(netapi_get_global()->nwal_context.interfaces[iface_no].in_use)
      {
      if(netapi_get_global()->nwal_context.interfaces[iface_no].in_use)
      {
-       n_handle =  netapi_get_global()->nwal_context.interfaces[iface_no].nwal_handle;
+        n_handle =  netapi_get_global()->nwal_context.interfaces[iface_no].nwal_handle;
      }
      else
      {
      }
      else
      {
@@ -674,8 +735,20 @@ NETCP_CFG_IP_T temp;
 
      //get a transaction object for config action
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
 
      //get a transaction object for config action
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return -1;}
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY;
+        if (flag)
+        {
+            netcp_cfgp_delete_ip(&netapi_get_global()->nwal_context,
+                         iface_no,
+                         ip_slot);
+        }
+        return -1;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
     pTransInfo->netapi_handle = h;
 
      //build nwalIpParam
     pTransInfo->netapi_handle = h;
 
      //build nwalIpParam
@@ -698,7 +771,7 @@ NETCP_CFG_IP_T temp;
         ip_rule_id = (NETAPI_NETCP_MATCH_CLASS_L3 | iface_no);
 
      //perform config action
         ip_rule_id = (NETAPI_NETCP_MATCH_CLASS_L3 | iface_no);
 
      //perform config action
-     pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+
      retValue = nwal_setIPAddr(   netapi_get_global()->nwal_context.nwalInstHandle,
                                   trans_id,
                                   (nwal_AppId) (ip_rule_id),
      retValue = nwal_setIPAddr(   netapi_get_global()->nwal_context.nwalInstHandle,
                                   trans_id,
                                   (nwal_AppId) (ip_rule_id),
@@ -711,38 +784,46 @@ NETCP_CFG_IP_T temp;
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg: nwal_setIP returned Error Code %d\n",
                     retValue);
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg: nwal_setIP returned Error Code %d\n",
                     retValue);
-        pTransInfo->inUse = nwal_FALSE;
+        netapip_FreeTransInfo(pTransInfo);
         //zap the entry
         if (flag)
         {
         //zap the entry
         if (flag)
         {
-               netcp_cfgp_delete_ip(&netapi_get_global()->nwal_context,
+            netcp_cfgp_delete_ip(&netapi_get_global()->nwal_context,
                          iface_no,
                          ip_slot);
                          iface_no,
                          ip_slot);
-       }
+        }
         return -1;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         return -1;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
-        n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
-        {
-            // if response is there, then this poll squirts out in the CTl poll callback, 
-            // which handles the rest (including decrmenting #pending!!
-            nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
-        }
+            n->nwal_local.numPendingCfg++;
+            while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_OPEN))
+            {
+                // if response is there, then this poll squirts out in the CTl poll callback, 
+                // which handles the rest (including decrmenting #pending!!
+                nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+            }
+            if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+            {
+                netapip_FreeTransInfo(pTransInfo);
+                *err = NETAPI_ERR_PA_FW;
+                printf (">netcp_cfgAddIpInternal - ERROR returned by NETCP PA firmware %d\n", *err);
+                return -1;
+            }
     }
     if (flag)
     {
     }
     if (flag)
     {
-       printf (">netcp cfg: IP added to interface %d (slot%d)\n", iface_no, ip_slot);
-       netcp_cfgp_insert_ip(&netapi_get_global()->nwal_context, ipType, 
+        printf (">netcp cfg: IP added to interface %d (slot%d)\n", iface_no, ip_slot);
+        netcp_cfgp_insert_ip(&netapi_get_global()->nwal_context, ipType, 
                           ip_addr, ip_qualifiers, iface_no, ip_slot,
                           pTransInfo->handle);
     }
                           ip_addr, ip_qualifiers, iface_no, ip_slot,
                           pTransInfo->handle);
     }
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
+
     temp = (NETCP_CFG_IP_T) pTransInfo->handle;
     temp = (NETCP_CFG_IP_T) pTransInfo->handle;
-    pTransInfo->inUse = nwal_FALSE;
+    netapip_FreeTransInfo(pTransInfo);
     return  (flag ? ip_rule_id:  temp);
 }
 /*****************************************************************/
     return  (flag ? ip_rule_id:  temp);
 }
 /*****************************************************************/
@@ -798,8 +879,14 @@ static void netcp_cfgDelIpInternal(NETAPI_T h, int iface_no,  nwal_IpType ipType
 
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
 
     //get a transaction id
     pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-    if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return ;}
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY; 
+        return -1;
+    }
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP;
     pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
     pTransInfo->netapi_handle = h;
     //issue request
     ret = nwal_delIPAddr(
     pTransInfo->netapi_handle = h;
     //issue request
     ret = nwal_delIPAddr(
@@ -811,27 +898,35 @@ static void netcp_cfgDelIpInternal(NETAPI_T h, int iface_no,  nwal_IpType ipType
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     ret);
         *err = NETAPI_ERR_NWAL_ERR0;
         printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     ret);
-        pTransInfo->inUse = nwal_FALSE;
+        netapip_FreeTransInfo(pTransInfo);
         return ;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
         return ;
     }
     //wait here until its done since scheduler isn't running yet most likely..
     // todo:  make this handled by scheduler poll later ??
     if(trans_id != NWAL_TRANSID_SPIN_WAIT)
     {
-       n->nwal_local.numPendingCfg++;
-        while ((volatile) n->nwal_local.numPendingCfg)
-        {
-            // if response is there, then this poll squirts out in the CTl poll callback, 
-            // which handles the rest (including decrmenting #pending!!
-            nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
-        }
+        n->nwal_local.numPendingCfg++;
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_IDLE))
+            {
+                // if response is there, then this poll squirts out in the CTl poll callback, 
+                // which handles the rest (including decrmenting #pending!!
+                nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+            }
+            if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+            {
+                netapip_FreeTransInfo(pTransInfo);
+                *err = NETAPI_ERR_PA_FW;
+                printf (">netcp_cfgDelIpInternal - ERROR returned by NETCP PA firmware %d\n", *err);
+                return -1;
+            }
     }
     if (flag)
        printf (">netcp cfg: attached IP deleted\n");
     else
     }
     if (flag)
        printf (">netcp cfg: attached IP deleted\n");
     else
-       printf (">netcp cfg: Classifier IP rule deleted\n");
-    pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-    pTransInfo->inUse = nwal_FALSE;
+        printf (">netcp cfg: Classifier IP rule deleted\n");
+
+    netapip_FreeTransInfo(pTransInfo);
 
     //zap the entry
     if (flag)
 
     //zap the entry
     if (flag)
@@ -989,11 +1084,18 @@ case(NETCP_CFG_CLASS_TYPE_L4):
                netcp_cfgp_build_route(route,&tempCfg.appRxPktFlowId, &tempCfg.appRxPktQueue);
        }
 
                netcp_cfgp_build_route(route,&tempCfg.appRxPktFlowId, &tempCfg.appRxPktQueue);
        }
 
-        //get a transaction id
-        pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-        if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return -1 ;}
-        pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP; /* todo: fix this to TRANS_L4*/
-        pTransInfo->netapi_handle = h;
+
+    //get a transaction id
+    pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY; 
+        return -1;
+    }
+    pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_PORT;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
+    pTransInfo->netapi_handle = h;
         //issue request
         retValue = nwal_addConn(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                             trans_id,
         //issue request
         retValue = nwal_addConn(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                             trans_id,
@@ -1005,9 +1107,9 @@ case(NETCP_CFG_CLASS_TYPE_L4):
         if(retValue !=  nwal_OK)
         {
             *err = NETAPI_ERR_NWAL_ERR0;
         if(retValue !=  nwal_OK)
         {
             *err = NETAPI_ERR_NWAL_ERR0;
-            printf (">netcp cfg - ERROR: nwal_addConn returned Error Code %d\n",
+            printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     retValue);
                     retValue);
-            pTransInfo->inUse = nwal_FALSE;
+            netapip_FreeTransInfo(pTransInfo);
             netcp_cfgp_delete_class(&netapi_get_global()->nwal_context, class_slot);
             return -1;
         }
             netcp_cfgp_delete_class(&netapi_get_global()->nwal_context, class_slot);
             return -1;
         }
@@ -1015,23 +1117,33 @@ case(NETCP_CFG_CLASS_TYPE_L4):
         // todo:  make this handled by scheduler poll later ??
         if(trans_id != NWAL_TRANSID_SPIN_WAIT)
         {
         // todo:  make this handled by scheduler poll later ??
         if(trans_id != NWAL_TRANSID_SPIN_WAIT)
         {
-             n->nwal_local.numPendingCfg++;
-             while ((volatile) n->nwal_local.numPendingCfg)
+            n->nwal_local.numPendingCfg++;
+            while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_OPEN))
              {
                 // if response is there, then this poll squirts out in the CTl poll callback, 
                 // which handles the rest (including decrmenting #pending!!
                 nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
              }
              {
                 // if response is there, then this poll squirts out in the CTl poll callback, 
                 // which handles the rest (including decrmenting #pending!!
                 nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
              }
+            if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+            {
+                netapip_FreeTransInfo(pTransInfo);
+                *err = NETAPI_ERR_PA_FW;
+                 netcp_cfgp_delete_class(&netapi_get_global()->nwal_context, class_slot);
+                printf (">netcp_cfgAddClass - ERROR returned by NETCP PA firmware %d\n", *err);
+                return -1;
+            }
          }
          printf (">netcp cfg: L4 Classifer added to interface %d ip %d (slot%d)\n", iface_no, ip_slot, class_slot);
          netcp_cfgp_insert_class(&netapi_get_global()->nwal_context, 
                                    class_slot,
                                  p_class->classType, 
          }
          printf (">netcp cfg: L4 Classifer added to interface %d ip %d (slot%d)\n", iface_no, ip_slot, class_slot);
          netcp_cfgp_insert_class(&netapi_get_global()->nwal_context, 
                                    class_slot,
                                  p_class->classType, 
-                                 NULL,  //L2 we have
-                                 (p_class->classType== NETCP_CFG_CLASS_TYPE_L3_L4? l3_handle : NULL),
+                                NULL,  //L2 we have
+                                (p_class->classType== NETCP_CFG_CLASS_TYPE_L3_L4? l3_handle : NULL),
                                   pTransInfo->handle);
                                   pTransInfo->handle);
-         pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
-         return classHandle;
+
+    netapip_FreeTransInfo(pTransInfo);
+    return classHandle;
 } //end switch
 return -1;
 }
 } //end switch
 return -1;
 }
@@ -1041,15 +1153,15 @@ void netcp_cfgDelClass(NETAPI_T h,
                          NETCP_CFG_CLASS_T classId,
                          int *err)
 {
                          NETCP_CFG_CLASS_T classId,
                          int *err)
 {
-NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
-void * L4_handle;  //class handle -> L4
-void * L3_handle;  //class handle -> L3
-nwal_RetValue       retValue;
-NetapiNwalTransInfo_t *pTransInfo;
-nwal_TransID_t     trans_id;
-int class_slot=-1;
-//int iface;
-//int ip_slot;
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+    void * L4_handle;  //class handle -> L4
+    void * L3_handle;  //class handle -> L3
+    nwal_RetValue       retValue;
+    NetapiNwalTransInfo_t *pTransInfo;
+    nwal_TransID_t     trans_id;
+    int class_slot=-1;
+    //int iface;
+    //int ip_slot;
 
        class_slot = (classId>>8)&0xffff;
         L4_handle=netcp_cfgp_get_l4_handle(
 
        class_slot = (classId>>8)&0xffff;
         L4_handle=netcp_cfgp_get_l4_handle(
@@ -1065,10 +1177,16 @@ int class_slot=-1;
                         &netapi_get_global()->nwal_context,
                         class_slot );
         //get a transaction id
                         &netapi_get_global()->nwal_context,
                         class_slot );
         //get a transaction id
-        pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
-        if (!pTransInfo) { *err =  NETAPI_ERR_BUSY; return  ;}
-        pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP;
-        pTransInfo->netapi_handle = h;
+    pTransInfo = netapip_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id);
+    if (!pTransInfo)
+    {
+        *err =  NETAPI_ERR_BUSY; 
+        return -1;
+    }
+    pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_PORT;
+    pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING;
+    pTransInfo->inUse = nwal_TRUE;
+    pTransInfo->netapi_handle = h;
         //issue request for L4
         retValue = nwal_delConn(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                             trans_id,
         //issue request for L4
         retValue = nwal_delConn(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
                             trans_id,
@@ -1076,9 +1194,9 @@ int class_slot=-1;
         if(retValue !=  nwal_OK)
         {
             *err = NETAPI_ERR_NWAL_ERR0;
         if(retValue !=  nwal_OK)
         {
             *err = NETAPI_ERR_NWAL_ERR0;
-            printf (">netcp cfg - ERROR: nwal_delConn returned Error Code %d\n",
+            printf (">netcp cfg - ERROR: nwal_delMacIface returned Error Code %d\n",
                     retValue);
                     retValue);
-            pTransInfo->inUse = nwal_FALSE;
+            netapip_FreeTransInfo(pTransInfo);
             return ;  /* todo: what about the L3? */
         }
         //wait here until its done since scheduler isn't running yet most likely..
             return ;  /* todo: what about the L3? */
         }
         //wait here until its done since scheduler isn't running yet most likely..
@@ -1086,13 +1204,21 @@ int class_slot=-1;
         if(trans_id != NWAL_TRANSID_SPIN_WAIT)
         {
              n->nwal_local.numPendingCfg++;
         if(trans_id != NWAL_TRANSID_SPIN_WAIT)
         {
              n->nwal_local.numPendingCfg++;
-             while ((volatile) n->nwal_local.numPendingCfg)
+        while ((pTransInfo->state  !=NETAPI_NWAL_HANDLE_STATE_ERR) &&
+                (pTransInfo->state !=NETAPI_NWAL_HANDLE_STATE_IDLE))
              {
                 // if response is there, then this poll squirts out in the CTl poll callback, 
                 // which handles the rest (including decrmenting #pending!!
                 nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
              }
          }
              {
                 // if response is there, then this poll squirts out in the CTl poll callback, 
                 // which handles the rest (including decrmenting #pending!!
                 nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
              }
          }
+        if (pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_ERR)
+        {
+            netapip_FreeTransInfo(pTransInfo);
+            *err = NETAPI_ERR_PA_FW;
+             printf (">netcp_cfgDelClass - ERROR returned by NETCP PA firmware %d\n", *err);
+             return -1;
+            }
          printf (">netcp cfg: Classifer deleted\n");
          pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
          pTransInfo->inUse = nwal_FALSE;
          printf (">netcp cfg: Classifer deleted\n");
          pTransInfo->state =  NETAPI_NWAL_HANDLE_STATE_IDLE;
          pTransInfo->inUse = nwal_FALSE;
@@ -1103,8 +1229,9 @@ int class_slot=-1;
              netcp_cfgDelIpInternal( h, 0, 0,
                   NULL, NULL, 0,
                   err, L3_handle,  0);
              netcp_cfgDelIpInternal( h, 0, 0,
                   NULL, NULL, 0,
                   err, L3_handle,  0);
-         }
-         return ;
+        }
+        netapip_FreeTransInfo(pTransInfo);
+    return ;
 }
 
 
 }
 
 
@@ -1266,10 +1393,11 @@ void netapi_NWALCmdCallBack (nwal_AppId        appHandle,
 
     if(ret != nwal_OK)
     {
 
     if(ret != nwal_OK)
     {
-        printf (">netcp cfg : NWALCmdCallBack returned Error Code %d\n",
-                    ret);
+        printf (">netcp cfg : netapi_NWALCmdCallBack returned Error Code %d for trans_id %d\n",
+                    ret, trans_id);
         // update error code that is fialed  in p_trans */
        //todo: atomic inc
         // update error code that is fialed  in p_trans */
        //todo: atomic inc
+       p_trans->state = NETAPI_NWAL_HANDLE_STATE_ERR;
         netapi_get_global()->nwal_context.numCmdFail++;
     }
     else
         netapi_get_global()->nwal_context.numCmdFail++;
     }
     else
@@ -1294,7 +1422,7 @@ void netapi_NWALCmdCallBack (nwal_AppId        appHandle,
             {
                  if(p_trans->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING)
                 {
             {
                  if(p_trans->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING)
                 {
-                    p_trans->state =NETAPI_NWAL_HANDLE_STATE_OPEN;
+                    p_trans->state = NETAPI_NWAL_HANDLE_STATE_OPEN;
                 }
                 else if(p_trans->state == NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING)
                 {
                 }
                 else if(p_trans->state == NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING)
                 {
index 67578d039c6b559c07fbb71367a72a8f5a999d48..e6bc81c21d51fd3648db5476dbc0d543594932e4 100755 (executable)
 #include <unistd.h>
 #include <string.h>
 #include "netapi.h"
 #include <unistd.h>
 #include <string.h>
 #include "netapi.h"
+#include "pktio.h"
+#include "netapi_util.h"
+
+
 
 
-#ifdef PKTIO_GET_BENCHMARK
-/* for benchmarking .. need to be defined somewhere */
-unsigned int vv7p;
-unsigned int vv8p;
-unsigned int vv9p;
-unsigned int vv10p;
-unsigned int vv11p;
-unsigned int vv12p;
-unsigned int vv13p;  //rcv path
-unsigned int vv14p;
-unsigned int vv15p;
-#endif
+
+static hplib_spinLock_T pktio_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
 
 /*--------------------Utilites-----------------*/
 
 
 /*--------------------Utilites-----------------*/
 
@@ -70,7 +64,8 @@ static PKTIO_HANDLE_T * pktiop_get_free_channel_slot(NETAPI_T n)
        {
                if (pp[i]->inuse != PKTIO_INUSE)
                {
        {
                if (pp[i]->inuse != PKTIO_INUSE)
                {
-                       return pp[i];
+                       pp[i]->inuse = PKTIO_INUSE;
+                    return  pp[i];
                }
        }
        return NULL;
                }
        }
        return NULL;
@@ -89,12 +84,12 @@ static int pktio_send_ipc(struct PKTIO_HANDLE_tag * pp, Ti_Pkt *pkt, PKTIO_METAD
         PKTIO_HANDLE_T *p=(PKTIO_HANDLE_T*) pp;
         *err=0;
 #ifdef PKTIO_GET_BENCHMARK
         PKTIO_HANDLE_T *p=(PKTIO_HANDLE_T*) pp;
         *err=0;
 #ifdef PKTIO_GET_BENCHMARK
-        vv8p=netapi_timing_stop();
+        p->vv8p=netapi_timing_stop();
 #endif
         Qmss_queuePushDesc (p->q, (void*)pkt);
 
 #ifdef PKTIO_GET_BENCHMARK
 #endif
         Qmss_queuePushDesc (p->q, (void*)pkt);
 
 #ifdef PKTIO_GET_BENCHMARK
-        vv9p=netapi_timing_stop();
+        p->vv9p=netapi_timing_stop();
 #endif
        return 1;
 }
 #endif
        return 1;
 }
@@ -109,11 +104,11 @@ static int pktio_send_nwal(struct PKTIO_HANDLE_tag * pp, Ti_Pkt *pkt, PKTIO_META
        *err=0;
        pPktInfo->pPkt = pkt;
 #ifdef PKTIO_GET_BENCHMARK
        *err=0;
        pPktInfo->pPkt = pkt;
 #ifdef PKTIO_GET_BENCHMARK
-        vv11p=netapi_timing_stop();
+        p->vv11p=netapi_timing_stop();
 #endif
         res=nwal_send(p->nwalInstanceHandle, m->sa_handle,pPktInfo);
 #ifdef PKTIO_GET_BENCHMARK
 #endif
         res=nwal_send(p->nwalInstanceHandle, m->sa_handle,pPktInfo);
 #ifdef PKTIO_GET_BENCHMARK
-        vv12p=netapi_timing_stop();
+        p->vv12p=netapi_timing_stop();
 #endif
         if (res != nwal_OK) {  *err = NETAPI_ERR_NWAL_TX_ERR -res;}
         return 1;
 #endif
         if (res != nwal_OK) {  *err = NETAPI_ERR_NWAL_TX_ERR -res;}
         return 1;
@@ -164,12 +159,12 @@ n= (p->max_n< PKTIO_MAX_RECV) ? p->max_n : PKTIO_MAX_RECV;
 for(r=0;r<n;r++)
 {
 #ifdef PKTIO_GET_BENCHMARK
 for(r=0;r<n;r++)
 {
 #ifdef PKTIO_GET_BENCHMARK
-      if (r==0) vv7p=netapi_timing_stop();
+      if (r==0) p->vv7p=netapi_timing_stop();
 #endif
       temp=(Ti_Pkt*)(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));
 
 #ifdef PKTIO_GET_BENCHMARK
 #endif
       temp=(Ti_Pkt*)(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));
 
 #ifdef PKTIO_GET_BENCHMARK
-      if (r==0) vv10p=netapi_timing_stop();
+      if (r==0) p->vv10p=netapi_timing_stop();
 #endif
       if(!temp) break;
          /* process meta data */
 #endif
       if(!temp) break;
          /* process meta data */
@@ -190,7 +185,7 @@ PKTIO_HANDLE_T *p=(PKTIO_HANDLE_T*) pp;
         /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
          set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
         /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
          set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
-        vv13p=netapi_timing_stop();
+        p->vv13p=netapi_timing_stop();
 #endif
         r=nwal_pollPkt(p->nwalInstanceHandle,
                    p->poll_flags,
 #endif
         r=nwal_pollPkt(p->nwalInstanceHandle,
                    p->poll_flags,
@@ -228,7 +223,7 @@ PKTIO_HANDLE_T *p=(PKTIO_HANDLE_T*) pp;
         /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
          set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
         /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
          set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
-        vv14p=netapi_timing_stop();
+        p->vv14p=netapi_timing_stop();
 #endif
         r=nwal_pollPkt(p->nwalInstanceHandle,
                      nwal_POLL_APP_MANAGED_PKT_Q,
 #endif
         r=nwal_pollPkt(p->nwalInstanceHandle,
                      nwal_POLL_APP_MANAGED_PKT_Q,
@@ -273,9 +268,10 @@ if ((p_cfg->flags2 & PKTIO_SB) &&(p_cfg->flags1& PKTIO_W)) { *err=NETAPI_ERR_BAD
 
 /* get a free channel handle */
 p=pktiop_get_free_channel_slot(n);
 
 /* get a free channel handle */
 p=pktiop_get_free_channel_slot(n);
+
 if (!p) {*err = PKTIO_NOMEM; return (p); }
 
 if (!p) {*err = PKTIO_NOMEM; return (p); }
 
-p->inuse= PKTIO_INUSE;
+/* p->inuse= PKTIO_INUSE;   moved to pktiop_get_free_channel_slot */
 p->back = n;
 p->cb = cb;
 p->max_n = p_cfg->max_n;
 p->back = n;
 p->cb = cb;
 p->max_n = p_cfg->max_n;
@@ -324,9 +320,12 @@ memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));
        (strcmp(name,NETCP_SB_TX)) &&
        (p_cfg->flags1 & PKTIO_GLOBAL) )
    {
        (strcmp(name,NETCP_SB_TX)) &&
        (p_cfg->flags1 & PKTIO_GLOBAL) )
    {
-     //todo: make sure this succeeds..
-     r=netapi_add_global_pktio(n, name, &p->qInfo);
-   }
+         //todo: make sure this succeeds..
+        hplib_mSpinLockLock(&pktio_lock);
+        r=netapi_add_global_pktio(n, name, &p->qInfo);
+        hplib_mSpinLockUnlock(&pktio_lock);
+    }
+
   ((NETAPI_HANDLE_T *)n )->n_pktios+=1;
    return p;
 }
   ((NETAPI_HANDLE_T *)n )->n_pktios+=1;
    return p;
 }
@@ -347,7 +346,9 @@ Qmss_Queue *p_qnum;
 if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}
 
 /* get a free channel handle */
 if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}
 
 /* get a free channel handle */
+
 p=pktiop_get_free_channel_slot(n);
 p=pktiop_get_free_channel_slot(n);
+
 if (!p) {*err = PKTIO_NOMEM; return (p); }
 ((NETAPI_HANDLE_T *)n)->n_pktios+=1;
 
 if (!p) {*err = PKTIO_NOMEM; return (p); }
 ((NETAPI_HANDLE_T *)n)->n_pktios+=1;
 
@@ -362,10 +363,12 @@ memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));
 /* special handling of NETCP_RX, NETCP_TX */
 if( (!strcmp(name, NETCP_RX)) || (!strcmp(name,NETCP_TX)) )
 {
 /* special handling of NETCP_RX, NETCP_TX */
 if( (!strcmp(name, NETCP_RX)) || (!strcmp(name,NETCP_TX)) )
 {
+    printf("pktio_open: trace 1\n");
    /* these have already been opened internally, so don't search in global list */
     p->use_nwal = PKTIO_DEF_NWAL;
     p->q = 0;  
    /* these have already been opened internally, so don't search in global list */
     p->use_nwal = PKTIO_DEF_NWAL;
     p->q = 0;  
-    p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); 
+    p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n);
+    printf("pktio_open1: nwalInstanceHandle 0x%x\n", p->nwalInstanceHandle);
     if (!strcmp(name,NETCP_RX)) 
     {
        p->_poll=pktio_poll_nwal; 
     if (!strcmp(name,NETCP_RX)) 
     {
        p->_poll=pktio_poll_nwal; 
@@ -384,8 +387,12 @@ else if( (!strcmp(name, NETCP_SB_RX)) || (!strcmp(name,NETCP_SB_TX)) )
 }
 else
 {
 }
 else
 {
- /* find queue in global list */
- p_qnum = netapi_find_global_pktio(n, name);
+    hplib_mSpinLockLock(&pktio_lock); 
+    /* find queue in global list */
+    p_qnum = netapi_find_global_pktio(n, name);
+     printf("pktio_open: trace 2\n");
+    
+    hplib_mSpinLockUnlock(&pktio_lock);
  if (!p_qnum ) 
   {
         printf(">pktio_open: can't find %s\n",name);
  if (!p_qnum ) 
   {
         printf(">pktio_open: can't find %s\n",name);
@@ -405,11 +412,13 @@ else
         return NULL;
     }
     p->qInfo = Qmss_getQueueNumber(p->q);
         return NULL;
     }
     p->qInfo = Qmss_getQueueNumber(p->q);
+    printf("pktio_open: queueMgr %d\,  queueNum; %d\n", p->qInfo.qMgr, p->qInfo.qNum);
     if (p_cfg->flags2 & PKTIO_PKT)
     {
        p->use_nwal = PKTIO_4_ADJ_NWAL;  //additonal RX q for nwal
        p->_poll = pktio_poll_nwal_adj;
        p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); 
     if (p_cfg->flags2 & PKTIO_PKT)
     {
        p->use_nwal = PKTIO_4_ADJ_NWAL;  //additonal RX q for nwal
        p->_poll = pktio_poll_nwal_adj;
        p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); 
+       printf("pktio_open: nwalInstanceHandle 0x%x\n", p->nwalInstanceHandle);
     } 
     else if (p_cfg->flags2 & PKTIO_SB)
     {
     } 
     else if (p_cfg->flags2 & PKTIO_SB)
     {
@@ -431,7 +440,7 @@ else
                strlen(name):PKTIO_MAX_NAME);
 
 
                strlen(name):PKTIO_MAX_NAME);
 
 
-
+    printf("pktio_open: returning with sucess for name %s\n", p->name);
 return p;
 }
 
 return p;
 }
 
@@ -500,7 +509,9 @@ void pktio_delete(PKTIO_HANDLE_T * p, int * err)
        if(!p) { *err=1; return;}
        *err=0;
         /* remove from name list */
        if(!p) { *err=1; return;}
        *err=0;
         /* remove from name list */
+    hplib_mSpinLockLock(&pktio_lock);
         netapi_del_global_pktio((NETAPI_HANDLE_T *)p->back, p->name);
         netapi_del_global_pktio((NETAPI_HANDLE_T *)p->back, p->name);
+    hplib_mSpinLockUnlock(&pktio_lock);
         if((p->use_nwal != PKTIO_DEF_NWAL) && (p->use_nwal != PKTIO_DEF_SB)) 
        {
                 netapi_zapQ(p->q);   //since we are deleting, zap the queue 
         if((p->use_nwal != PKTIO_DEF_NWAL) && (p->use_nwal != PKTIO_DEF_SB)) 
        {
                 netapi_zapQ(p->q);   //since we are deleting, zap the queue 
@@ -526,11 +537,11 @@ int pktio_send_genric(PKTIO_HANDLE_T * p, Ti_Pkt *pkt, PKTIO_METADATA_T *m, int
     {
         pPktInfo->pPkt = pkt;
 #ifdef PKTIO_GET_BENCHMARK
     {
         pPktInfo->pPkt = pkt;
 #ifdef PKTIO_GET_BENCHMARK
-        vv11p=netapi_timing_stop();
+        p->vv11p=netapi_timing_stop();
 #endif
         res=nwal_send(p->nwalInstanceHandle, m->sa_handle,pPktInfo);
 #ifdef PKTIO_GET_BENCHMARK
 #endif
         res=nwal_send(p->nwalInstanceHandle, m->sa_handle,pPktInfo);
 #ifdef PKTIO_GET_BENCHMARK
-        vv12p=netapi_timing_stop();
+        p->vv12p=netapi_timing_stop();
 #endif
         if (res != nwal_OK) { printf("nwal send err= %d (%x)\n", res, res);  *err = NETAPI_ERR_NWAL_TX_ERR -res;}
     }
 #endif
         if (res != nwal_OK) { printf("nwal send err= %d (%x)\n", res, res);  *err = NETAPI_ERR_NWAL_TX_ERR -res;}
     }
@@ -546,12 +557,12 @@ int pktio_send_genric(PKTIO_HANDLE_T * p, Ti_Pkt *pkt, PKTIO_METADATA_T *m, int
                 /* tod: meta data for non netcp xfers */
             /* process meta data */
 #ifdef PKTIO_GET_BENCHMARK
                 /* tod: meta data for non netcp xfers */
             /* process meta data */
 #ifdef PKTIO_GET_BENCHMARK
-        vv8p=netapi_timing_stop();
+        p->vv8p=netapi_timing_stop();
 #endif
         Qmss_queuePushDesc (p->q, (void*)pkt);
 
 #ifdef PKTIO_GET_BENCHMARK
 #endif
         Qmss_queuePushDesc (p->q, (void*)pkt);
 
 #ifdef PKTIO_GET_BENCHMARK
-        vv9p=netapi_timing_stop();
+        p->vv9p=netapi_timing_stop();
 #endif
     }
     return 1;
 #endif
     }
     return 1;
@@ -620,7 +631,7 @@ uint64_t ts=0LL;
                /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
                    set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
                /* Poll for common L2/L3 packets and L4 class pkts (todo-> only do L4 if classifiers are
                    set.. optimizaion maybe? */
 #ifdef PKTIO_GET_BENCHMARK
-            vv13p=netapi_timing_stop();
+            p->vv13p=netapi_timing_stop();
 #endif
                r=nwal_pollPkt(p->nwalInstanceHandle,
                      p->poll_flags,
 #endif
                r=nwal_pollPkt(p->nwalInstanceHandle,
                      p->poll_flags,
@@ -634,7 +645,7 @@ uint64_t ts=0LL;
        {
                /* Poll an additional NETCP RX queue */
 #ifdef PKTIO_GET_BENCHMARK
        {
                /* Poll an additional NETCP RX queue */
 #ifdef PKTIO_GET_BENCHMARK
-               vv14p=netapi_timing_stop();
+               p->vv14p=netapi_timing_stop();
 #endif
                r=nwal_pollPkt(p->nwalInstanceHandle,
                      nwal_POLL_APP_MANAGED_PKT_Q,
 #endif
                r=nwal_pollPkt(p->nwalInstanceHandle,
                      nwal_POLL_APP_MANAGED_PKT_Q,
@@ -673,12 +684,12 @@ uint64_t ts=0LL;
                for(r=0;r<n;r++)
                {
 #ifdef PKTIO_GET_BENCHMARK
                for(r=0;r<n;r++)
                {
 #ifdef PKTIO_GET_BENCHMARK
-            if (r==0) vv7p=netapi_timing_stop();
+            if (r==0) p->vv7p=netapi_timing_stop();
 #endif
                        temp=(Ti_Pkt*)(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));
 
 #ifdef PKTIO_GET_BENCHMARK
 #endif
                        temp=(Ti_Pkt*)(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));
 
 #ifdef PKTIO_GET_BENCHMARK
-            if (r==0) vv10p=netapi_timing_stop();
+            if (r==0) p->vv10p=netapi_timing_stop();
 #endif
                        if(!temp) break;
                                 /* process meta data */
 #endif
                        if(!temp) break;
                                 /* process meta data */
@@ -728,7 +739,7 @@ Ti_Pkt * pkt_list[PKTIO_MAX_RECV];
 PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];
 
 #ifdef PKTIO_GET_BENCHMARK
 PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];
 
 #ifdef PKTIO_GET_BENCHMARK
-    vv15p=netapi_timing_stop();
+    p->vv15p=netapi_timing_stop();
 #endif
     for(r=0;r<numPkts;r++)
     {
 #endif
     for(r=0;r<numPkts;r++)
     {
index c7b13a20f45067482f59396f0a95c4df2f931afd..d5ef58af5a2d1c6326c342f9256ed8ebeea63f7e 100755 (executable)
@@ -1443,7 +1443,7 @@ int main(int argc, char **argv)
 #endif
 
 
 #endif
 
 
-    sleep(5);
+    sleep(1);
 #ifdef TEST_SA
 
     for (i = 0; i < SA_CREATE_LOOP_COUNT;i++)
 #ifdef TEST_SA
 
     for (i = 0; i < SA_CREATE_LOOP_COUNT;i++)
@@ -1466,25 +1466,10 @@ int main(int argc, char **argv)
             &(sa_info[i].rx_data_mode_handle),
             &(sa_info[i].rx_inflow_mode_handle),
             &err);
             &(sa_info[i].rx_data_mode_handle),
             &(sa_info[i].rx_inflow_mode_handle),
             &err);
-        if (err) {printf("addRxSa failed %d\n",err); exit(1);}
+        //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
+         if (err) {printf("addRxSa failed %d\n",err);}
+
 
 
-        if (config.ipsec_mode_rx == IPSEC_MODE_RX_INFLOW)
-        {
-            //assume inner and outer ip is the same
-            rx_policy[i]= netapi_secAddRxPolicy( netapi_handle,
-                             sa_info[i].rx_tunnel,  //link to tunnel above
-                             4,         //ipv4
-                             &config.remote_ipsec_ip, //src -> them
-                             &config.local_ipsec_ip,  //dst -> us
-                            NULL,  // no qualifiers
-                            NULL,  //default route
-                             &err);
-            if (err) {printf("addSaPolicy failed  %d, for index %d\n",err,i); exit(1);}
-        }
-        else 
-        {
-            rx_policy[i] = 0;
-                     }
     }
 //tx SA
 //security stuff 
     }
 //tx SA
 //security stuff 
index 33ecb1a222658d27acd03451839ea9798a917f61..57b5ae58807af0e5c3b96e7a71856b94def6d1b6 100755 (executable)
@@ -8,6 +8,7 @@ export NETAPI_INSTALL_PATH ?= $(TRANS_SDK_INSTALL_PATH)
 TRIE_OBJS=$(ARMV7OBJDIR)/netapi/test/trie.o
 NT_OBJS= $(ARMV7OBJDIR)/netapi/test/net_test.o  $(ARMV7OBJDIR)/netapi/test/stubs.o
 NTSA_OBJS= $(ARMV7OBJDIR)/netapi/test/addsa_test.o  $(ARMV7OBJDIR)/netapi/test/stubs.o
 TRIE_OBJS=$(ARMV7OBJDIR)/netapi/test/trie.o
 NT_OBJS= $(ARMV7OBJDIR)/netapi/test/net_test.o  $(ARMV7OBJDIR)/netapi/test/stubs.o
 NTSA_OBJS= $(ARMV7OBJDIR)/netapi/test/addsa_test.o  $(ARMV7OBJDIR)/netapi/test/stubs.o
+NTMT_OBJS= $(ARMV7OBJDIR)/netapi/test/mt_test.o  $(ARMV7OBJDIR)/netapi/test/stubs.o
 NTB_OBJS= $(ARMV7OBJDIR)/netapi/test/nt_bridge.o  $(ARMV7OBJDIR)/netapi/test/stubs.o  
 
 # INCLUDE Directories
 NTB_OBJS= $(ARMV7OBJDIR)/netapi/test/nt_bridge.o  $(ARMV7OBJDIR)/netapi/test/stubs.o  
 
 # INCLUDE Directories
@@ -50,7 +51,7 @@ INTERNALLINKDEFS = --start-group -L$(ARMV7LIBDIR) -L$(PDK_ARMV7LIBDIR) $(NETAPI_
 
 all: tests 
 
 
 all: tests 
 
-tests: $(ARMV7BINDIR)/netapi/test/.created $(ARMV7BINDIR)/netapi/test/net_test $(ARMV7BINDIR)/netapi/test/addsa_test
+tests: $(ARMV7BINDIR)/netapi/test/.created $(ARMV7BINDIR)/netapi/test/net_test $(ARMV7BINDIR)/netapi/test/addsa_test $(ARMV7BINDIR)/netapi/test/mt_test
 
 
 api_clean:
 
 
 api_clean:
@@ -62,6 +63,7 @@ clean:
        rm -f $(ARMV7LIBDIR)/libnetapi.a
        rm -f $(ARMV7BINDIR)/netapi/test/net_test 
        rm -f $(ARMV7BINDIR)/netapi/test/addsa_test
        rm -f $(ARMV7LIBDIR)/libnetapi.a
        rm -f $(ARMV7BINDIR)/netapi/test/net_test 
        rm -f $(ARMV7BINDIR)/netapi/test/addsa_test
+       rm -f $(ARMV7BINDIR)/netapi/test/mt_test
 
 
 $(ARMV7OBJDIR)/netapi/test/%.o:$(NETAPI_INC_DIR)/test/%.c $(ARMV7OBJDIR)/netapi/test/.created
 
 
 $(ARMV7OBJDIR)/netapi/test/%.o:$(NETAPI_INC_DIR)/test/%.c $(ARMV7OBJDIR)/netapi/test/.created
@@ -87,3 +89,6 @@ $(ARMV7BINDIR)/netapi/test/nt_bridge:  $(NTB_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/l
 $(ARMV7BINDIR)/netapi/test/addsa_test:  $(NTSA_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
        $(CC) $(LDFLAGS)  $(NTSA_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS)  -o $(ARMV7BINDIR)/netapi/test/addsa_test
 
 $(ARMV7BINDIR)/netapi/test/addsa_test:  $(NTSA_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
        $(CC) $(LDFLAGS)  $(NTSA_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS)  -o $(ARMV7BINDIR)/netapi/test/addsa_test
 
+$(ARMV7BINDIR)/netapi/test/mt_test:  $(NTMT_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
+       $(CC) $(LDFLAGS)  $(NTMT_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS)  -o $(ARMV7BINDIR)/netapi/test/mt_test
+
diff --git a/ti/runtime/netapi/test/mt_test.c b/ti/runtime/netapi/test/mt_test.c
new file mode 100755 (executable)
index 0000000..71ada42
--- /dev/null
@@ -0,0 +1,1840 @@
+/******************************************
+ * File: net_test.c
+ * Purpose: test app for netapi
+ **************************************************************
+ * FILE:  net_test.c
+ * 
+ * DESCRIPTION:  netapi user space transport
+ *               library  test application
+ * 
+ * REVISION HISTORY:  rev 0.0.1 
+ *
+ *  Copyright (c) Texas Instruments Incorporated 2010-2011
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ *****************************************/
+#define NWAL_ENABLE_SA
+
+//define this for multi-thread
+#define MULTI_THREAD
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include "trie.h"
+#include "string.h"
+#include "netapi.h"
+#include "pktio.h"
+#include <sys/resource.h>
+#include "net_test.h"
+#include <ti/drv/sa/salld.h>
+#include "ti/drv/nwal/nwal_util.h"
+
+
+
+
+#define TEST_SA
+//#define TEST_MAC_IP
+#define SA_CREATE_LOOP_COUNT 64
+#define IP_CREATE_LOOP_COUNT 64
+#define MAC_CREATE_LOOP_COUNT 59
+
+#ifdef MULTI_THREAD
+    //__thread int our_core;
+
+    cpu_set_t cpu_set;
+#endif
+
+long htonl(long x)
+{
+       long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 |  (x&0xff)<<24 ;
+       return temp;
+}
+
+/* net test default configuration */
+netTestConfig_t config =
+{
+    {0x00,0x01,0x02,0x03,0x05,0x05},
+    {0x00,0x01,0x02,0x03,0x05,0x06},
+    {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+    {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    IPSEC_MODE_RX_INFLOW,
+    IPSEC_MODE_TX_INFLOW,
+    0
+};
+
+#if 0
+netTestConfigMax_t configMax =
+{
+    {{0x00,0x00,0x02,0x03,0x05,0x07},
+    {  0x00,0x01,0x02,0x03,0x05,0x09}},
+    {{0x00,0x02,0x02,0x03,0x05,0x04},
+    {  0x00,0x03,0x02,0x03,0x05,0x03}},
+    {{0x00,0x04,0x02,0x03,0x05,0x07},
+    {  0x00,0x05,0x02,0x03,0x05,0x09}},
+    {{0x00,0x06,0x02,0x03,0x05,0x04},
+    {  0x00,0x07,0x02,0x03,0x05,0x03}},
+    {{0x00,0x08,0x02,0x03,0x05,0x07},
+    {  0x00,0x09,0x02,0x03,0x05,0x09}},
+    {{0x00,0x0a,0x02,0x03,0x05,0x04},
+    {  0x00,0x0b,0x02,0x03,0x05,0x03}},
+    {{0x00,0x0c,0x02,0x03,0x05,0x07},
+    {  0x00,0x0d,0x02,0x03,0x05,0x09}},
+    {{0x00,0x0e,0x02,0x03,0x05,0x04},
+    {  0x00,0x0f,0x02,0x03,0x05,0x03}},
+
+    
+    {{0x00,0x10,0x02,0x03,0x05,0x07},
+    {  0x00,0x11,0x02,0x03,0x05,0x09}},
+    {{0x00,0x12,0x02,0x03,0x05,0x04},
+    {  0x00,0x13,0x02,0x03,0x05,0x03}},
+    {{0x00,0x14,0x02,0x03,0x05,0x07},
+    {  0x00,0x15,0x02,0x03,0x05,0x09}},
+    {{0x00,0x16,0x02,0x03,0x05,0x04},
+    {  0x00,0x17,0x02,0x03,0x05,0x03}},
+    {{0x00,0x18,0x02,0x03,0x05,0x07},
+    {  0x00,0x19,0x02,0x03,0x05,0x09}},
+    {{0x00,0x1a,0x02,0x03,0x05,0x04},
+    {  0x00,0x1b,0x02,0x03,0x05,0x03}},
+    {{0x00,0x1c,0x02,0x03,0x05,0x07},
+    {  0x00,0x1d,0x02,0x03,0x05,0x09}},
+    {{0x00,0x1e,0x02,0x03,0x05,0x04},
+    {  0x00,0x1f,0x02,0x03,0x05,0x03}},
+
+     {{0x00,0x10,0x02,0x03,0x05,0x07},
+    {  0x00,0x11,0x02,0x03,0x05,0x09}},
+    {{0x00,0x12,0x02,0x03,0x05,0x04},
+    {  0x00,0x13,0x02,0x03,0x05,0x03}},
+    {{0x00,0x14,0x02,0x03,0x05,0x07},
+    {  0x00,0x15,0x02,0x03,0x05,0x09}},
+    {{0x00,0x16,0x02,0x03,0x05,0x04},
+    {  0x00,0x17,0x02,0x03,0x05,0x03}},
+    {{0x00,0x18,0x02,0x03,0x05,0x07},
+    {  0x00,0x19,0x02,0x03,0x05,0x09}},
+    {{0x00,0x1a,0x02,0x03,0x05,0x04},
+    {  0x00,0x1b,0x02,0x03,0x05,0x03}},
+    {{0x00,0x1c,0x02,0x03,0x05,0x07},
+    {  0x00,0x1d,0x02,0x03,0x05,0x09}},
+    {{0x00,0x1e,0x02,0x03,0x05,0x04},
+    {  0x00,0x1f,0x02,0x03,0x05,0x03}},
+
+    
+    {{10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+    {{10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {10, 0, 3, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+    {{10, 0, 4, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    {10, 0, 5, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+    {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+    {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    IPSEC_MODE_RX_INFLOW,
+    IPSEC_MODE_TX_INFLOW,
+    0
+};
+#endif
+
+
+
+
+Trie *p_trie_sa;
+
+static int scnt=0;
+static int QUIT=0;
+void mysig(int x)
+{
+  QUIT=1;
+  scnt+=1;
+  printf(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
+  if (scnt > 10) {printf(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");exit(1);}
+
+}
+
+/*******************************************
+ *************NETAPI OBJECTS***************
+ *****************************************/
+static NETAPI_CFG_T our_netapi_default_cfg=
+{
+TUNE_NETAPI_PERM_MEM_SZ,
+128,  //start of packet offset for hw to place data on rx for default flow
+TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
+TUNE_NETAPI_NUM_GLOBAL_DESC,        //total we will use
+TUNE_NETAPI_DEFAULT_NUM_BUFFERS,   //#descriptors+buffers in default heap
+64, //#descriptors w/o buffers in default heap
+TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
+128   ,  //tail room
+256      //extra room 
+};
+
+Pktlib_HeapHandle ourHeap;
+Pktlib_HeapHandle specialSmall;
+Pktlib_HeapHandle specialLarge;
+
+PKTIO_HANDLE_T *our_chan;
+PKTIO_HANDLE_T *netcp_rx_chan;
+PKTIO_HANDLE_T *netcp_rx_chan2;
+PKTIO_HANDLE_T *netcp_tx_chan;
+PKTIO_HANDLE_T *netcp_sb_tx_chan;
+PKTIO_HANDLE_T *netcp_sb_rx_chan;
+PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
+
+void house(NETAPI_SCHED_HANDLE_T *s);
+NETAPI_T netapi_handle;
+#ifdef MULTI_THREAD
+NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
+#endif
+NETAPI_SCHED_HANDLE_T * our_sched;
+
+NETAPI_SCHED_CONFIG_T our_sched_cfg={
+  NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000  //every 5000000 poll loops
+};
+
+
+NETCP_CFG_IP_T ip_rule0[IP_CREATE_LOOP_COUNT];
+NETCP_CFG_IP_T ip_rule1[IP_CREATE_LOOP_COUNT];
+//NETCP_CFG_IP_T ip_rule0;
+//NETCP_CFG_IP_T ip_rule1;
+
+NETCP_CFG_CLASS_T class_0;
+NETCP_CFG_CLASS_T class_1;
+NETCP_CFG_CLASS_T class_2;
+NETCP_CFG_FLOW_HANDLE_T specialFlow;
+
+
+NETCP_CFG_CLASSIFIER_T class_0_cfg=
+{
+   NETCP_CFG_CLASS_TYPE_L4,
+   {
+       .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
+   }
+};
+
+NETCP_CFG_CLASSIFIER_T class_1_cfg=
+{
+    NETCP_CFG_CLASS_TYPE_L4,
+    {
+       .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
+   }
+};
+
+NETCP_CFG_ROUTE_T  class2_route=
+{
+NULL, NULL  //* to be filled in
+};
+NETCP_CFG_CLASSIFIER_T class_2_cfg=  
+{
+   NETCP_CFG_CLASS_TYPE_L3_L4,
+   {
+        .c_l3_l4={0,  4 ,0/*fill in below*/ , NULL, NULL,          //L2/L3
+           NWAL_APP_PLOAD_PROTO_UDP, {2504}}   //L4
+   }
+};
+
+PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
+
+/* security objects. (for loopback mode) */
+netTestSA_t sa_info[SA_CREATE_LOOP_COUNT];
+
+NETCP_CFG_IPSEC_POLICY_T rx_policy[SA_CREATE_LOOP_COUNT];
+
+
+
+NETAPI_SEC_SA_INFO_T rx_sa [14] = {
+{
+    NWAL_SA_DIR_INBOUND,
+    0x11111111,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA1,
+    NWAL_SA_EALG_AES_CBC,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x22222222,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_AES_CTR,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x33333333,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_3DES_CBC,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x44444444,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_MD5,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x55555555,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_GCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x66666666,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_CCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x77777777,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_AES_XCBC,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x91111111,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA1,
+    NWAL_SA_EALG_AES_CBC,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x92222222,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_AES_CTR,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x93333333,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_3DES_CBC,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x94444444,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_HMAC_MD5,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x95555555,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_GCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x96666666,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_CCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_INBOUND,
+    0x97777777,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_AES_XCBC,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+}
+
+
+    
+};
+
+/*tx */
+NETAPI_SEC_SA_INFO_T tx_sa[14]= {
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x11111111,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA1,
+    NWAL_SA_EALG_AES_CBC,
+    0,0  //seq no
+},
+    {
+    NWAL_SA_DIR_OUTBOUND,
+    0x22222222,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_AES_CTR,
+    0,0  //seq no
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x33333333,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_3DES_CBC,
+    0,0  //seq no
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x44444444,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_MD5,
+    NWAL_SA_EALG_NULL,
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x55555555,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_GCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x66666666,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_CCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x77777777,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_AES_XCBC,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x91111111,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA1,
+    NWAL_SA_EALG_AES_CBC,
+    0,0  //seq no
+},
+    {
+    NWAL_SA_DIR_OUTBOUND,
+    0x92222222,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_AES_CTR,
+    0,0  //seq no
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x93333333,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_SHA2_256,
+    NWAL_SA_EALG_3DES_CBC,
+    0,0  //seq no
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x94444444,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (them) -> set below*/
+    64, /* NA replayWindow */
+    NWAL_SA_AALG_HMAC_MD5,
+    NWAL_SA_EALG_NULL,
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x95555555,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_GCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x96666666,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_NULL,
+    NWAL_SA_EALG_AES_CCM,
+    0,0  //na
+},
+{
+    NWAL_SA_DIR_OUTBOUND,
+    0x97777777,  //spi
+    nwal_IpSecProtoESP, //ESP mode
+    nwal_SA_MODE_TUNNEL,  //tunnel mode
+    nwal_IPV4, //v4
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* dst IP (us)-> set below*/
+    64,/* replayWindow */
+    NWAL_SA_AALG_AES_XCBC,
+    NWAL_SA_EALG_NULL,
+    0,0  //na
+}
+};
+
+
+static nwalSecKeyParams_t ourTXKeyParams[14] ={
+{
+    32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* NULL*/
+    16, /* MD5, 16 bytes */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
+    0, /* macKeySize: 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    0, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    16, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* NULL*/
+    16, /* MD5, 16 bytes */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
+    0, /* macKeySize: 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    0, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    16, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+}
+};
+
+/* these keys are for aes-ctr and hmac sha2_256 */
+static nwalSecKeyParams_t ourRXKeyParams[14] ={
+{
+    32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* NWAL_SA_EALG_NULL*/
+    16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
+    0, /* macKeySize: 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
+    0, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    16, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
+    32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* NWAL_SA_EALG_NULL*/
+    16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
+    NULL, //set below
+    NULL, //set below
+},
+{
+    20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
+    0, /* macKeySize: 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
+    0, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+},
+{
+    0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
+    16, /* macKeySize 0*/
+    NULL, //set below
+    NULL, //set below
+}
+};
+
+
+static uint8_t ourAuthKey[36] =
+        {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+         0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+         0x20, 0x21, 0x22, 0x23 };
+;
+
+static uint8_t ourEncrKey[36] = 
+        {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+         0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+         0x30, 0x31, 0x32, 0x33 }; 
+
+
+/*************************END NETAPI OBJECTS***********************/
+
+#define START_SRC_IP 0x0a00000a
+#define DST_IP       0xc0a80001
+#define NEW_START_SRC_IP 0x9eda000a
+#define DST_PORT 0x555 
+#define START_SRC_PORT 0x1234
+#define NEW_START_SRC_PORT 100
+void update_header(HEAD_T * p_head, int len)
+{
+   unsigned char *p = (unsigned char *) &p_head->udp[1];
+   len -= (20+14);
+   /* update ip checksum */
+   /* update udp checksum */
+   /* update length */
+   *p= (len&0xff00)>>8;
+   *(p+1) = len&0xff;
+}
+
+//===========stub transmitter==================
+void send_pkt(Ti_Pkt *pkt, int len)
+{
+//just free pkt.  Don't send
+Pktlib_freePacket((Ti_Pkt*)pkt);
+       return;
+}
+
+
+/* check header */
+struct LastPktInfo
+{
+int iface;
+int ipcsum;
+int l4csum;
+} ;
+static struct LastPktInfo lpInfo;
+
+
+void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+                         PKTIO_METADATA_T meta[], int n_pkts,
+                         uint64_t ts )
+{
+}
+
+/****************************************************************************************/
+/******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
+/******************  Handles Decrypt and Encrypt operation callbacks ******************/
+/******************************************************************************************/
+void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+                         PKTIO_METADATA_T meta[], int n_pkts,
+                         uint64_t ts )
+{
+}
+
+/******************************************************/
+/******************PKT RECEIVE HANDLER *************************/
+/******************************************************/
+void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+                         PKTIO_METADATA_T meta[], int n_pkts,
+                         uint64_t ts )
+{
+}
+
+//******************************************************
+//use scheduling housekeeping callback to generate pkts
+//******************************************************
+static int done_burst=0;
+void house(NETAPI_SCHED_HANDLE_T * s)
+{
+    int err;
+    if (QUIT) {netapi_schedShutdown(s,NULL,&err); return;}
+}
+
+void  build_sa_db(int i)
+{
+    long tmp_spi;
+    static uint32_t spi = 11111111;
+    if ((tx_sa[0].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[0].cipherMode == NWAL_SA_EALG_AES_CBC))
+    {
+        tx_sa[0].spi = rx_sa[0].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */         
+        sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_AES_CBC_IV_LEN;
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
+        sa_info[i].tx_payload_info.encSize = 0;   /* authSize - esp header size (always 8 bytes) */
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;     /* not being referenced in net_test */
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+
+        tmp_spi = htonl((long)(tx_sa[0].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+         
+         
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+        sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_AES_CTR_IV_LEN;
+
+
+
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+        sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_3DES_CBC_IV_LEN;
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+
+        sa_info[i].tx_payload_info.encOffset =         netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_NULL_IV_LEN;
+
+
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+        //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
+
+        sa_info[i].tx_payload_info.encOffset =         netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_AES_GCM_IV_LEN;
+
+
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        //sa_info[i].tx_payload_info.ploadLen = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        //sa_info[i].tx_payload_info.authIvSize = 0;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+
+        sa_info[i].tx_payload_info.encOffset =         netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_AES_CCM_IV_LEN;
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        //sa_info[i].tx_payload_info.ploadLen = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+        
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
+    {
+        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        /* static configuration, will not change */
+        sa_info[i].tx_payload_info.aadSize = 0;
+        sa_info[i].tx_payload_info.pAad = NULL;
+        sa_info[i].tx_payload_info.pAuthIV = NULL;
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+
+
+        sa_info[i].tx_payload_info.encOffset =         netTest_MAC_HEADER_LEN +
+                                                                     netTest_IP_HEADER_LEN +
+                                                                    netTest_ESP_HEADER_LEN +
+                                                                    netTest_NULL_IV_LEN;
+
+        /* dynamic configuration, will  be calculated on the fly */
+        sa_info[i].tx_payload_info.authSize = 0;
+        sa_info[i].tx_payload_info.encSize = 0;
+        //sa_info[i].tx_payload_info.ploadLen = 0;
+        sa_info[i].tx_payload_info.pEncIV = 0;
+        sa_info[i].tx_payload_info.pPkt = 0;
+
+        sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
+        sa_info[i].authMode = NWAL_SA_AALG_AES_XCBC;
+        sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].auth_tag_size = netTest_ICV_LEN;  /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
+
+        sa_info[i].tx_pkt_info.enetPort = 0;
+        sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
+        sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
+        sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.startOffset = 0;
+        sa_info[i].tx_pkt_info.lpbackPass = 0;
+        sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
+        sa_info[i].tx_pkt_info.pPkt = NULL;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saPayloadLen = 0;
+        sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
+       
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+        
+        tmp_spi = htonl((long)(tx_sa[i].spi));
+         trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
+    }
+    else
+        printf("build_sa_db(): invalid encryption/authentication combination selected\n");
+
+}
+
+
+
+#ifdef MULTI_THREAD
+NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
+void slow_path_thread(int coreid)
+{
+    int err, i, count=0;
+
+    PKTIO_HANDLE_T *our_chan;
+    PKTIO_HANDLE_T *rx_chan;
+    PKTIO_HANDLE_T *tx_chan;
+    PKTIO_HANDLE_T *sb_tx_chan;
+    PKTIO_HANDLE_T *sb_rx_chan;
+
+    
+
+    printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
+
+    CPU_ZERO( &cpu_set);
+#ifdef CORTEX_A15
+    CPU_SET( coreid, &cpu_set);
+    hplib_utilSetupCore(coreid, &cpu_set);
+#else
+      CPU_SET( 0, &cpu_set);
+    hplib_utilSetupCore(coreid+1, &cpu_set);
+#endif
+    worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
+
+
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
+
+   /* open netcp default tx, rx queues */
+    tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg,  &err);
+    
+    
+#ifdef EXPERIMENTAL
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
+#else
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+#endif
+    
+#ifndef EXPERIMENTAL
+    /* create a pktio channel for specially classified pkts */
+    /* open netcp default tx, rx queues for sideband crypto */
+     sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
+    
+    sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
+#endif
+
+
+
+
+
+    netapi_setCookie(worker_nh[coreid],coreid);
+    //our_core = coreid;
+      
+    scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
+    if (!scheduler[coreid]) 
+    {
+        printf("sched create failed for core%d\n",coreid); 
+        exit(1);
+    }
+      scheduler[coreid]->config.yield = FALSE;
+       scheduler[coreid]->config.pollGarbageQ = TRUE;
+        scheduler[coreid]->config.pollCtrlQ = TRUE;
+            /*********************************************/
+    /**************Entry point into scheduler ****/
+    /*********************************************/
+
+#ifdef TEST_MAC_IP
+   for (i = 0; i < 30 ;i++)
+    {
+    /* add mac intefaces */
+    netcp_cfgCreateMacInterface(
+                      worker_nh[coreid],
+                      &config.mac0[0],
+                      i,0,
+                      (NETCP_CFG_ROUTE_HANDLE_T)  NULL,
+                      (NETCP_CFG_VLAN_T ) NULL ,  //future
+                      1, 
+                      &err);
+    if (err) {printf("addmac0 failed %d\n",err); exit(1); }
+    else
+        {
+            printf("addmac0 passed for index %d, mac before %d\n",i, config.mac0[5]);
+            config.mac0[3]++;
+        }
+    }
+
+   for (i = 0; i < 30 ;i++)
+    {
+    //attach an IP to this interface
+    ip_rule0[i]=netcp_cfgAddIp(
+                      worker_nh[coreid],
+                      0,
+                      nwal_IPV4,
+                      &config.ip0,
+                      NULL,  //all IP
+                      (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+                      &err
+                      );
+    if (err) {printf("addip0 failed %d\n",err); exit(1); }
+        else
+        {
+            printf("addip0 passed for index%d ip[3] %d\n",i, config.ip0.ipv4[3]);
+            config.ip0.ipv4[3]++;
+        }
+
+    }
+sleep(1);
+    //delete IPs and MAC Interfacess
+    for (i = 0; i < 30;i++)
+    {
+         printf("calling netcp_cfgDelIp and  for index %d\n", i);
+        netcp_cfgDelIp(worker_nh[coreid], i, 0, NULL, NULL, ip_rule0[i], &err);
+        netcp_cfgDelMac(worker_nh[coreid],i,&err);
+    }
+    for (i = 0; i < 30;i++)
+    {
+         printf("calling  and netcp_cfgDelMac for index %d\n", i);
+         netcp_cfgDelMac(worker_nh[coreid],i,&err);
+    }
+#endif
+
+#ifdef TEST_SA
+    for (i = 0; i < 32;i++)
+    {
+        ourRXKeyParams[0].pEncKey = &ourEncrKey[0];
+        ourRXKeyParams[0].pAuthKey = &ourAuthKey[0];
+        memcpy(&(rx_sa[0].src), &config.remote_ipsec_ip,4);
+        memcpy(&(rx_sa[0].dst), &config.local_ipsec_ip,4);
+
+        build_sa_db(i);
+        count++;
+        //printf("thread: %d: calling netapi_secAddSA for rx, count = %d\n",coreid,  count);
+        sa_info[i].rx_tunnel = netapi_secAddSA(
+            worker_nh[coreid],
+            config.ipsec_if_no, //iface #0 
+            &rx_sa[0],
+            &ourRXKeyParams[0],
+            config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
+                NULL,  //use default route 
+            &(sa_info[i].rx_data_mode_handle),
+            &(sa_info[i].rx_inflow_mode_handle),
+            &err);
+        //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
+         if (err) {printf("addRxSa failed %d\n",err);}
+
+
+    }
+//tx SA
+//security stuff 
+    count = 0;
+    for (i = 0; i <32;i++)
+    {
+    ourTXKeyParams[0].pEncKey = &ourEncrKey[0];
+    ourTXKeyParams[0].pAuthKey = &ourAuthKey[0];
+    memcpy(&(tx_sa[0].src), &config.local_ipsec_ip,4);
+    memcpy(&(tx_sa[0].dst), &config.remote_ipsec_ip,4);
+         count++;
+        //printf("thread: %d: calling netapi_secAddSA for tx, count = %d\n",coreid,  count);
+    sa_info[i].tx_tunnel = netapi_secAddSA( worker_nh[coreid],
+                 0, //iface #0 
+                &tx_sa[0],
+                &ourTXKeyParams[0],
+                config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
+                NULL,  //use default route 
+                &(sa_info[i].tx_data_mode_handle),
+                &(sa_info[i].tx_inflow_mode_handle),
+                &err);
+    if (err) {printf("addTxSa failed %d\n",err); exit(1);}
+    }
+sleep(1);
+count = 0;
+#ifdef TEST_SA
+        for (i = 0; i < 32;i++)
+        {
+                if (rx_policy[i])
+                    netapi_secDelRxPolicy(worker_nh[coreid], rx_policy[i], &err);
+                count ++;
+                //delete tunnels
+                 printf("main: calling netapi_secDelSA for rx, count = %d\n", count);
+                netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].rx_tunnel, &err);
+                //sleep(1);
+                 //printf("main: calling netapi_secDelSA for tx, count = %d\n", count);
+                netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].tx_tunnel, &err);
+        }
+#endif
+#endif
+
+            
+    netapi_schedWaitForEvents(scheduler[coreid], &err);
+            
+    printf(">net_test: core %d worker thread done\n",coreid);
+    pktio_close(tx_chan, &err);
+    pktio_close(rx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    netapi_shutdown(worker_nh[coreid]);
+}
+
+void fast_path_thread(int coreid)
+{
+    int err, i, count=0;
+        PKTIO_HANDLE_T *our_chan;
+    PKTIO_HANDLE_T *rx_chan;
+    PKTIO_HANDLE_T *tx_chan;
+    PKTIO_HANDLE_T *sb_tx_chan;
+    PKTIO_HANDLE_T *sb_rx_chan;
+
+    printf("fast_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
+#ifdef CORTEX_A15
+    CPU_SET( coreid, &cpu_set);
+        hplib_utilSetupCore(coreid, &cpu_set);
+#else
+      CPU_SET( 0, &cpu_set);
+    hplib_utilSetupCore(coreid + 1, &cpu_set);
+#endif
+    worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
+
+
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
+
+   /* open netcp default tx, rx queues */
+    tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg,  &err);
+    
+    
+#ifdef EXPERIMENTAL
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
+#else
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+#endif
+    
+#ifndef EXPERIMENTAL
+    /* create a pktio channel for specially classified pkts */
+    /* open netcp default tx, rx queues for sideband crypto */
+     sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
+    
+    sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
+#endif
+
+    netapi_setCookie(worker_nh[coreid],coreid);
+    //our_core = coreid;
+    scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
+    if (!scheduler[coreid]) 
+        {
+        printf("sched create failed for core%d\n",coreid); 
+        exit(1);
+    }
+
+    /*********************************************/
+    /**************Entry point into scheduler ****/
+    /*********************************************/
+    scheduler[coreid]->config.yield = FALSE;
+     scheduler[coreid]->config.pollGarbageQ = FALSE;
+     scheduler[coreid]->config.pollCtrlQ = FALSE;
+     //sleep(100000);
+#ifdef TEST_MAC_IP
+   for (i = 30; i < MAC_CREATE_LOOP_COUNT ;i++)
+    {
+    /* add mac intefaces */
+    netcp_cfgCreateMacInterface(
+                      worker_nh[coreid],
+                      &config.mac0[0],
+                      i,0,
+                      (NETCP_CFG_ROUTE_HANDLE_T)  NULL,
+                      (NETCP_CFG_VLAN_T ) NULL ,  //future
+                      1, 
+                      &err);
+    if (err) {printf("addmac0 failed %d\n",err); exit(1); }
+    else
+        {
+            printf("addmac0 passed for index %d, mac before %d\n",i, config.mac0[5]);
+            config.mac0[3]++;
+        }
+    }
+
+   for (i = 30; i < IP_CREATE_LOOP_COUNT ;i++)
+    {
+    //attach an IP to this interface
+    ip_rule0[i]=netcp_cfgAddIp(
+                      worker_nh[coreid],
+                      30,
+                      nwal_IPV4,
+                      &config.ip0,
+                      NULL,  //all IP
+                      (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+                      &err
+                      );
+    if (err) {printf("addip0 failed %d\n",err); exit(1); }
+        else
+        {
+            printf("addip0 passed for index%d ip[3] %d\n",i, config.ip0.ipv4[3]);
+            config.ip0.ipv4[3]++;
+        }
+
+    }
+sleep(1);
+    //delete IPs and MAC Interfacess
+    for (i = 30; i < IP_CREATE_LOOP_COUNT;i++)
+    {
+         printf("calling netcp_cfgDelIp and  for index %d\n", i);
+        netcp_cfgDelIp(worker_nh[coreid], i, 0, NULL, NULL, ip_rule0[i], &err);
+        netcp_cfgDelMac(worker_nh[coreid],i,&err);
+    }
+    for (i = 30; i < MAC_CREATE_LOOP_COUNT;i++)
+    {
+         printf("calling  and netcp_cfgDelMac for index %d\n", i);
+         netcp_cfgDelMac(worker_nh[coreid],i,&err);
+    }
+#endif
+
+
+#ifdef TEST_SA
+    for (i = 32; i < SA_CREATE_LOOP_COUNT-1;i++)
+    {
+        ourRXKeyParams[0].pEncKey = &ourEncrKey[0];
+        ourRXKeyParams[0].pAuthKey = &ourAuthKey[0];
+        memcpy(&(rx_sa[0].src), &config.remote_ipsec_ip,4);
+        memcpy(&(rx_sa[0].dst), &config.local_ipsec_ip,4);
+
+        build_sa_db(i);
+        count++;
+        //printf("thread: %d: calling netapi_secAddSA for rx, count = %d\n",coreid,  count);
+        sa_info[i].rx_tunnel = netapi_secAddSA(
+            worker_nh[coreid],
+            config.ipsec_if_no, //iface #0 
+            &rx_sa[0],
+            &ourRXKeyParams[0],
+            config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
+                NULL,  //use default route 
+            &(sa_info[i].rx_data_mode_handle),
+            &(sa_info[i].rx_inflow_mode_handle),
+            &err);
+        //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
+         if (err) {printf("addRxSa failed %d\n",err);}
+
+
+    }
+    count = 0;
+//tx SA
+//security stuff 
+    for (i = 32; i <SA_CREATE_LOOP_COUNT-1;i++)
+    {
+    ourTXKeyParams[0].pEncKey = &ourEncrKey[0];
+    ourTXKeyParams[0].pAuthKey = &ourAuthKey[0];
+    memcpy(&(tx_sa[0].src), &config.local_ipsec_ip,4);
+    memcpy(&(tx_sa[0].dst), &config.remote_ipsec_ip,4);
+         count++;
+        //printf("thread: %d: calling netapi_secAddSA for tx, count = %d\n",coreid,  count);
+    sa_info[i].tx_tunnel = netapi_secAddSA( worker_nh[coreid],
+                 0, //iface #0 
+                &tx_sa[0],
+                &ourTXKeyParams[0],
+                config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
+                NULL,  //use default route 
+                &(sa_info[i].tx_data_mode_handle),
+                &(sa_info[i].tx_inflow_mode_handle),
+                &err);
+    if (err) {printf("addTxSa failed %d\n",err); exit(1);}
+    }
+
+sleep(1);
+        count = 0;
+//#ifdef TEST_SA
+        for (i = 32; i < SA_CREATE_LOOP_COUNT-1;i++)
+        {
+                if (rx_policy[i])
+                    netapi_secDelRxPolicy(worker_nh[coreid], rx_policy[i], &err);
+                count ++;
+                //delete tunnels
+                 //printf("main: calling netapi_secDelSA for rx, count = %d\n", count);
+                netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].rx_tunnel, &err);
+                //sleep(1);
+                 //printf("main: calling netapi_secDelSA for tx, count = %d\n", count);
+                netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].tx_tunnel, &err);
+        }
+#endif
+
+    netapi_schedWaitForEvents(scheduler[coreid], &err);
+    printf(">net_test: core %d worker thread done\n",coreid);
+    pktio_close(tx_chan, &err);
+    pktio_close(rx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    netapi_shutdown(worker_nh[coreid]);
+}
+
+#endif
+//#endif
+
+/***************************************
+ ********** test driver*****************
+ ***************************************/
+int main(int argc, char **argv)
+{
+    int err,i, j, count;
+    Pktlib_HeapCfg      heapCfg;
+    rlim_t oss,ss = 1024*1024;
+    struct rlimit rl;
+    int32_t             errCode;
+    Pktlib_HeapIfTable*  pPktifTable;
+    
+
+    FILE * fpr = NULL;
+
+    
+    err= getrlimit(RLIMIT_STACK,&rl);
+    if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
+
+
+    memset(&sa_info, 0, sizeof(sa_info));
+
+    /* create netapi */
+    netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
+
+    /* open the main heap */
+    ourHeap = Pktlib_findHeapByName("netapi");
+    if (!ourHeap)
+    {
+        printf("Pktlib_findHeapByName()  fail\n");
+        exit(1);
+    }
+
+    /* create two secondary heaps */
+    /* Initialize the heap configuration. */
+    memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
+
+    pPktifTable = netapi_getPktlibIfTable();
+    /* Populate the heap configuration */
+    heapCfg.name                = "netapi-small";
+    heapCfg.memRegion           = NETAPI_GLOBAL_REGION;
+    heapCfg.sharedHeap          = 1;
+    heapCfg.useStarvationQueue  = 0;
+    heapCfg.dataBufferSize      = 512;
+    heapCfg.numPkts             = 64;
+    heapCfg.numZeroBufferPackets= 0;
+    heapCfg.heapInterfaceTable.data_malloc  = pPktifTable->data_malloc;
+    heapCfg.heapInterfaceTable.data_free    = pPktifTable->data_free;
+    heapCfg.dataBufferPktThreshold   = 0;
+    heapCfg.zeroBufferPktThreshold   = 0;
+
+    specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
+    heapCfg.name                = "netapi-big";
+    heapCfg.dataBufferSize      = 1600;
+    specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
+    //register these heaps so poll routine will include their garbage queues.
+    netapi_registerHeap(netapi_handle, specialSmall);
+    netapi_registerHeap(netapi_handle, specialLarge);
+
+    /* create a pktio channel */
+    our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
+    if (!our_chan)
+    {
+        printf("pktio create failed err=%d\n",err);
+        exit(1);
+    }
+
+    /* open netcp default tx, rx queues */
+    netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
+    if (!netcp_tx_chan)
+    {
+        printf("pktio open TX failed err=%d\n",err);
+        exit(1);
+    }
+    netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+
+    if (!netcp_rx_chan)
+    {
+        printf("pktio open RX failed err=%d\n",err);
+        exit(1);
+    }
+
+    /* create a pktio channel for specially classified pkts */
+    netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2,  &err);
+    if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
+
+    /* open netcp default tx, rx queues for sideband crypto */
+    netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
+    if (!netcp_sb_tx_chan)
+    {
+        printf("pktio open SB TX failed err=%d\n",err);
+        exit(1);
+    }
+    netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
+    if (!netcp_sb_rx_chan)
+    {
+        printf("pktio open SB RX failed err=%d\n",err);
+        exit(1);
+    }
+
+    printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
+    /* create scheduler instance */
+    our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
+    if (!our_sched) {printf("sched create failed\n"); exit(1);}
+
+    //#define PROMISCUOUS
+#define ETH0 0
+#define ETH1 1
+
+//security stuff 
+    p_trie_sa = trie_new();
+   if (!p_trie_sa) {printf("trie alloc for SA  failed\n"); exit(1);}
+
+
+#ifdef MULTI_THREAD
+{
+        CPU_ZERO( &cpu_set );
+    pthread_t *thrs;
+        int procs =2;  //get this from config eventually
+        char c;
+        thrs = malloc( sizeof( pthread_t ) * procs );
+        if (thrs == NULL)
+        {
+                perror( "malloc" );
+                return -1;
+        }
+        printf( "Starting %d threads...\n", procs );
+
+        if (pthread_create( &thrs[0], NULL, slow_path_thread,
+                        (void *)0 ))
+        {
+                        perror( "pthread_create" );
+                        exit(1);
+        }
+        if (pthread_create( &thrs[1], NULL, fast_path_thread,
+                        (void *)1 ))
+        {
+                        perror( "pthread_create" );
+                        exit(1);
+        }
+
+        //this thread of execution (main) now just waits on user input
+        for(;;)
+        {
+           printf(">");
+           c=getchar();
+           if (c=='q') 
+           {
+                QUIT=1;
+                break;
+           }
+           //else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
+           else if (c=='h') printf("'q' to quit,  's' for stats, 'h' for help\n");
+        }
+
+        //wait for completion 
+        printf("main task now pending on slow/fast path completion\n");
+        for (i = 0; i < procs; i++)
+                pthread_join( thrs[i], NULL );
+
+        free( thrs );
+}
+#else
+    /*********************************************/
+    /**************Entry point into scheduler ****/
+    /*********************************************/
+    netapi_schedWaitForEvents(our_sched, &err);
+
+#endif
+
+
+
+
+
+
+
+
+
+#if 0
+    //create specialFlow for this classifier
+    {
+    Pktlib_HeapHandle heaps[2];
+    //int sizes[2];
+    heaps[0]= specialSmall;
+    heaps[1]= specialLarge;
+#define SPECIAL_SOP_OFF 128
+   // sizes[0]=512-SPECIAL_SOP_OFF;
+    //sizes[1]=1600-SPECIAL_SOP_OFF;
+    }
+#endif
+
+    count = 0;
+    //sleep(1);
+
+    /*************************************************
+     ************CLEAN UP****************************
+     ************************************************/
+
+    //delete Classifiers
+    netcp_cfgDelClass(netapi_handle, class_0, &err); 
+    netcp_cfgDelClass(netapi_handle, class_1, &err); 
+    //netcp_cfgDelClass(netapi_handle, class_2, &err); 
+
+        count = 0;
+    //close pktio channels we opened
+    printf("main: calling pktio_close for netcp_tx_chan\n");
+    pktio_close(netcp_tx_chan ,&err);
+    printf("main: calling pktio_close for netcp_rx_chan\n");
+    pktio_close(netcp_rx_chan ,&err);
+    printf("main: calling pktio_close for netcp_sb_tx_chan\n");
+    pktio_close(netcp_sb_tx_chan ,&err);
+    printf("main: calling pktio_close for netcp_sb_rx_chan\n");
+    pktio_close(netcp_sb_rx_chan ,&err);
+
+    //clear pktio channel we created
+    pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
+    pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
+
+    //delete pktio channels we created
+    pktio_delete(our_chan, &err);
+    pktio_delete(netcp_rx_chan2,&err);
+    netapi_shutdown(netapi_handle);
+
+}
+
+
+
+
index 50a73c3f8021463aef581e991ab6fd912b7d8d1e..33208dddeb9a17f29067f96793381b3d2ae61b76 100755 (executable)
@@ -40,6 +40,7 @@
  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
  *****************************************/
  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
  *****************************************/
+#define DAL_REVIEW
 //#define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #define NWAL_ENABLE_SA
 //#define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #define NWAL_ENABLE_SA
@@ -68,6 +69,7 @@ Trie * our_router;
 
 
 
 
 
 
+
 OUR_ROUTE_T routes[MAX_ROUTES]=
 {
 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
 OUR_ROUTE_T routes[MAX_ROUTES]=
 {
 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
@@ -81,7 +83,8 @@ unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc
 #endif
 
 #ifdef MULTI_THREAD
 #endif
 
 #ifdef MULTI_THREAD
-__thread int our_core;
+    //__thread int our_core;
+
     cpu_set_t cpu_set;
 #endif
 
     cpu_set_t cpu_set;
 #endif
 
@@ -876,7 +879,8 @@ static struct LastPktInfo lpInfo;
 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
 {
 #ifdef MULTI_THREAD
 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
 {
 #ifdef MULTI_THREAD
-    int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
     int coreid=0;
 #endif
 #else
     int coreid=0;
 #endif
@@ -927,19 +931,7 @@ unsigned int vv3;
 unsigned int vv4;
 unsigned int vv5;
 unsigned int vv6;
 unsigned int vv4;
 unsigned int vv5;
 unsigned int vv6;
-//these are updated by pktio.
-#ifdef PKTIO_GET_BENCHMARK
-extern unsigned int vv7p;
-extern unsigned int vv8p;
-extern unsigned int vv9p;
-extern unsigned int vv10p;
-extern unsigned int vv11p;
-extern unsigned int vv12p;
 
 
-extern unsigned int vv13p;  //rcv path
-extern unsigned int vv14p;
-extern unsigned int vv15p;
-#endif
 
 unsigned int vv11;
 
 
 unsigned int vv11;
 
@@ -1033,10 +1025,10 @@ for(i=0;i<ntrials;i++)
    timings[8]+=(vv11-vv6);
 
 #ifdef PKTIO_GET_BENCHMARK
    timings[8]+=(vv11-vv6);
 
 #ifdef PKTIO_GET_BENCHMARK
-   timings[2]+=(vv7p-vv4);
-   timings[4]+=(vv8p-vv3);
-   timings[6]+=(vv9p-vv8p);
-   timings[7]+=(vv10p-vv7p);
+   timings[2]+=(our_chan->vv7p-vv4);
+   timings[4]+=(our_chan->vv8p-vv3);
+   timings[6]+=(our_chan->vv9p-our_chan->vv8p);
+   timings[7]+=(our_chan->vv10p-our_chan->vv7p);
 #endif
 }
 
 #endif
 }
 
@@ -1132,7 +1124,8 @@ void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag)
     Cppi_HostDesc*          pPloadDesc;
 
 #ifdef MULTI_THREAD
     Cppi_HostDesc*          pPloadDesc;
 
 #ifdef MULTI_THREAD
-int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId(); //who we are(thread local)
+        //int coreid = our_core;
 #else
 int coreid=0;
 #endif
 #else
 int coreid=0;
 #endif
@@ -1418,7 +1411,8 @@ uint8_t *p_spi;
 netTestSA_t *p_sa_info;
 
 #ifdef MULTI_THREAD
 netTestSA_t *p_sa_info;
 
 #ifdef MULTI_THREAD
-int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
 int coreid=0;
 #endif
 #else
 int coreid=0;
 #endif
@@ -1566,7 +1560,8 @@ void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
     Cppi_HostDesc*          pPloadDesc;
     int ifno;
 #ifdef MULTI_THREAD
     Cppi_HostDesc*          pPloadDesc;
     int ifno;
 #ifdef MULTI_THREAD
-int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
 int coreid=0;
 #endif
 #else
 int coreid=0;
 #endif
@@ -1576,9 +1571,6 @@ int coreid=0;
     for(i=0;i<n_pkts;i++)
     {
         ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
     for(i=0;i<n_pkts;i++)
     {
         ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
-        if(coreid<TUNE_NETAPI_NUM_CORES) stats[coreid].rx+=1;
-        if (ifno < TUNE_NETAPI_MAX_NUM_MAC) stats[coreid].if_rx[ifno]+=1;
-
         tip = p_recv[i];
         
         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
         tip = p_recv[i];
         
         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
@@ -1593,7 +1585,11 @@ int coreid=0;
             printf(" rcv_cb, nexpkt != NULL");
         }
 
             printf(" rcv_cb, nexpkt != NULL");
         }
 
-        stats[coreid].rx+=1;
+        if(coreid<TUNE_NETAPI_NUM_CORES)
+            stats[coreid].rx+=1;
+        if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
+            stats[coreid].if_rx[ifno]+=1;
+
 
 #ifdef DEBUG_DESC
         if (stats[coreid].rx<16)
 
 #ifdef DEBUG_DESC
         if (stats[coreid].rx<16)
@@ -1793,7 +1789,8 @@ int cookie;
 int err;
 unsigned long long et;
 #ifdef MULTI_THREAD
 int err;
 unsigned long long et;
 #ifdef MULTI_THREAD
-    int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
     int coreid=0;
 #endif
 #else
     int coreid=0;
 #endif
@@ -1887,7 +1884,8 @@ void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
 {
 
 #ifdef MULTI_THREAD
 {
 
 #ifdef MULTI_THREAD
-int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
 int coreid=0;
 #endif
 #else
 int coreid=0;
 #endif
@@ -1955,8 +1953,8 @@ NETAPI_SA_STATS_T netapi_sa_stats;
     }
 
 #ifdef MULTI_THREAD
     }
 
 #ifdef MULTI_THREAD
-netapi_sched_get_stats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
-netapi_sched_get_stats(scheduler[1],&tmp_npL[1],&tmp_cyclesL[1],&tmp_ccyclesL[1]);
+    netapi_sched_get_stats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
+    netapi_sched_get_stats(scheduler[1],&tmp_npL[1],&tmp_cyclesL[1],&tmp_ccyclesL[1]);
 npL = tmp_npL[0]+tmp_npL[1];
 cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
 ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
 npL = tmp_npL[0]+tmp_npL[1];
 cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
 ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
@@ -2882,49 +2880,119 @@ void slow_path_thread(int coreid)
 {
     int err;
 
 {
     int err;
 
-    printf("slow_path_thread, mypid: %d\n", gettid());
+    PKTIO_HANDLE_T *our_chan;
+    PKTIO_HANDLE_T *rx_chan;
+    PKTIO_HANDLE_T *tx_chan;
+    PKTIO_HANDLE_T *sb_tx_chan;
+    PKTIO_HANDLE_T *sb_rx_chan;
+
+    
+
+    printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
 
     CPU_ZERO( &cpu_set);
 
     CPU_ZERO( &cpu_set);
-#ifdef CORTEX_15
+#ifdef CORTEX_A15
     CPU_SET( coreid, &cpu_set);
     hplib_utilSetupCore(coreid, &cpu_set);
 #else
       CPU_SET( 0, &cpu_set);
     CPU_SET( coreid, &cpu_set);
     hplib_utilSetupCore(coreid, &cpu_set);
 #else
       CPU_SET( 0, &cpu_set);
-    hplib_utilSetupCore(0, &cpu_set);
+    hplib_utilSetupCore(coreid+1, &cpu_set);
 #endif
 #endif
-    worker_nh[coreid]=netapi_init(NETAPI_NO_MASTER,NULL);
+    worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
+
+#ifdef DAL_REVIEW
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
+
+   /* open netcp default tx, rx queues */
+    tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg,  &err);
+    
+    
+#ifdef EXPERIMENTAL
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
+#else
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+#endif
+    
+#ifndef EXPERIMENTAL
+    /* create a pktio channel for specially classified pkts */
+    /* open netcp default tx, rx queues for sideband crypto */
+     sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
+    
+    sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
+#endif
+
+#endif
+
+
+
     netapi_setCookie(worker_nh[coreid],coreid);
     netapi_setCookie(worker_nh[coreid],coreid);
-    our_core=coreid;
+    //our_core = coreid;
+      
     scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
     if (!scheduler[coreid]) 
     {
         printf("sched create failed for core%d\n",coreid); 
         exit(1);
     }
     scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
     if (!scheduler[coreid]) 
     {
         printf("sched create failed for core%d\n",coreid); 
         exit(1);
     }
+      scheduler[coreid]->config.yield = FALSE;
+       scheduler[coreid]->config.pollGarbageQ = TRUE;
+        scheduler[coreid]->config.pollCtrlQ = TRUE;
             /*********************************************/
     /**************Entry point into scheduler ****/
     /*********************************************/
     netapi_schedWaitForEvents(scheduler[coreid], &err);
     printf(">net_test: core %d worker thread done\n",coreid);
             /*********************************************/
     /**************Entry point into scheduler ****/
     /*********************************************/
     netapi_schedWaitForEvents(scheduler[coreid], &err);
     printf(">net_test: core %d worker thread done\n",coreid);
+    pktio_close(tx_chan, &err);
+    pktio_close(rx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
     netapi_shutdown(worker_nh[coreid]);
 }
 
 void fast_path_thread(int coreid)
 {
     int err;
     netapi_shutdown(worker_nh[coreid]);
 }
 
 void fast_path_thread(int coreid)
 {
     int err;
+        PKTIO_HANDLE_T *our_chan;
+    PKTIO_HANDLE_T *rx_chan;
+    PKTIO_HANDLE_T *tx_chan;
+    PKTIO_HANDLE_T *sb_tx_chan;
+    PKTIO_HANDLE_T *sb_rx_chan;
 
 
-    #ifdef CORTEX_15
+#ifdef CORTEX_A15
     CPU_SET( coreid, &cpu_set);
         hplib_utilSetupCore(coreid, &cpu_set);
 #else
       CPU_SET( 0, &cpu_set);
     CPU_SET( coreid, &cpu_set);
         hplib_utilSetupCore(coreid, &cpu_set);
 #else
       CPU_SET( 0, &cpu_set);
-    hplib_utilSetupCore(0, &cpu_set);
+    hplib_utilSetupCore(coreid + 1, &cpu_set);
 #endif
 #endif
-    printf("fast_path_thread, mypid: %d\n", gettid());
-    hplib_utilSetupCore(coreid, &cpu_set);
-    worker_nh[coreid]=netapi_init(NETAPI_NO_MASTER,NULL);
+    worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
+
+#ifdef DAL_REVIEW
+    NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
+
+   /* open netcp default tx, rx queues */
+    tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg,  &err);
+    
+    
+#ifdef EXPERIMENTAL
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
+#else
+    rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+#endif
+    
+#ifndef EXPERIMENTAL
+    /* create a pktio channel for specially classified pkts */
+    /* open netcp default tx, rx queues for sideband crypto */
+     sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
+    
+    sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
+#endif
+
+#endif
+
+    
     netapi_setCookie(worker_nh[coreid],coreid);
     netapi_setCookie(worker_nh[coreid],coreid);
-    our_core=coreid;
+    //our_core = coreid;
     scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
     if (!scheduler[coreid]) 
         {
     scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
     if (!scheduler[coreid]) 
         {
@@ -2935,8 +3003,16 @@ void fast_path_thread(int coreid)
     /*********************************************/
     /**************Entry point into scheduler ****/
     /*********************************************/
     /*********************************************/
     /**************Entry point into scheduler ****/
     /*********************************************/
+    scheduler[coreid]->config.yield = FALSE;
+     scheduler[coreid]->config.pollGarbageQ = FALSE;
+     scheduler[coreid]->config.pollCtrlQ = FALSE;
+     //sleep(100000);
     netapi_schedWaitForEvents(scheduler[coreid], &err);
     printf(">net_test: core %d worker thread done\n",coreid);
     netapi_schedWaitForEvents(scheduler[coreid], &err);
     printf(">net_test: core %d worker thread done\n",coreid);
+    pktio_close(tx_chan, &err);
+    pktio_close(rx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
+    pktio_close(sb_tx_chan, &err);
     netapi_shutdown(worker_nh[coreid]);
 }
 
     netapi_shutdown(worker_nh[coreid]);
 }
 
@@ -3124,8 +3200,6 @@ exit(1);
 #define ETH1 1
 #endif
 
 #define ETH1 1
 #endif
 
-
-
     /* add mac intefaces */
     netcp_cfgCreateMacInterface(
                       netapi_handle,
     /* add mac intefaces */
     netcp_cfgCreateMacInterface(
                       netapi_handle,
@@ -3413,13 +3487,14 @@ srand((unsigned) np2process);
                         perror( "pthread_create" );
                         exit(1);
         }
                         perror( "pthread_create" );
                         exit(1);
         }
+#if 1
         if (pthread_create( &thrs[1], NULL, fast_path_thread,
                         (void *)1 ))
         {
                         perror( "pthread_create" );
                         exit(1);
         }
         if (pthread_create( &thrs[1], NULL, fast_path_thread,
                         (void *)1 ))
         {
                         perror( "pthread_create" );
                         exit(1);
         }
-
+#endif
         //this thread of execution (main) now just waits on user input
         for(;;)
         {
         //this thread of execution (main) now just waits on user input
         for(;;)
         {
@@ -3438,12 +3513,10 @@ srand((unsigned) np2process);
         free( thrs );
 }
 #else
         free( thrs );
 }
 #else
-
-
-/*********************************************/
-/**************Entry point into scheduler ****/
-/*********************************************/
-netapi_schedWaitForEvents(our_sched, &err);
+    /*********************************************/
+    /**************Entry point into scheduler ****/
+    /*********************************************/
+    netapi_schedWaitForEvents(our_sched, &err);
 
 #endif
 
 
 #endif
 
@@ -3797,7 +3870,8 @@ unsigned long long n_c_ops;
 int ifno;
 int out_port;
 #ifdef MULTI_THREAD
 int ifno;
 int out_port;
 #ifdef MULTI_THREAD
-int coreid=our_core;  //who we are(thread local)
+    int coreid=Osal_nwalGetProcId();  //who we are(thread local)
+    //int coreid = our_core;
 #else
 int coreid=0;
 #endif
 #else
 int coreid=0;
 #endif