summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1f7190a)
raw | patch | inline | side by side (parent: 1f7190a)
author | Tinku Mannan <tmannan@ti.com> | |
Tue, 5 Feb 2013 19:01:47 +0000 (14:01 -0500) | ||
committer | Tinku Mannan <tmannan@ti.com> | |
Tue, 5 Feb 2013 19:01:47 +0000 (14:01 -0500) |
16 files changed:
index 40eb7b81d419cea0b84077a1172f9a829934f334..336c0bf78c853a1e97a7b893ee7b5242d48663bf 100755 (executable)
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;
- chunk for buffers, descriptors
- memory mapped peripherals we use, such as QMSS, PA, etc */
result = hplib_vmInit(&netapi_VM_VirtAddr[0], 2, &netapi_VM_MempoolAttr[0]);
+
/* TODO: at this point, we need to create the QM regions which need to moved out of the above
netapi_VM_memory_setup() call, also need to move out the SA context stuff */
index c0128ff641f51db3378e75f01714f412588e993f..4c6356f601736d844a1733c1e0ffe3ff55486ba3 100755 (executable)
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 $(ARMV7OBJDIR)/netapi/test/net_test_util.o
+NT_OBJS= $(ARMV7OBJDIR)/netapi/test/net_test.o $(ARMV7OBJDIR)/netapi/test/stubs.o $(ARMV7OBJDIR)/netapi/test/net_test_util.o $(ARMV7OBJDIR)/netapi/test/net_test_sa_utils.o
+NT_ROUTER_OBJS= $(ARMV7OBJDIR)/netapi/test/net_test_router.o $(ARMV7OBJDIR)/netapi/test/stubs.o $(ARMV7OBJDIR)/netapi/test/net_test_util.o $(ARMV7OBJDIR)/netapi/test/net_test_sa_utils.o
NTB_OBJS= $(ARMV7OBJDIR)/netapi/test/nt_bridge.o $(ARMV7OBJDIR)/netapi/test/stubs.o
# INCLUDE Directories
all: tests
-tests: $(ARMV7BINDIR)/netapi/test/.created $(ARMV7BINDIR)/netapi/test/net_test
+tests: $(ARMV7BINDIR)/netapi/test/.created $(ARMV7BINDIR)/netapi/test/net_test $(ARMV7BINDIR)/netapi/test/net_test_router
api_clean:
rm -f $(ARMV7OBJDIR)/netapi/test/*.o
rm -f $(ARMV7LIBDIR)/libnetapi.a
rm -f $(ARMV7BINDIR)/netapi/test/net_test
+ rm -f $(ARMV7BINDIR)/netapi/test/net_test_router
$(ARMV7OBJDIR)/netapi/test/%.o:$(NETAPI_INC_DIR)/test/%.c $(ARMV7OBJDIR)/netapi/test/.created
$(ARMV7BINDIR)/netapi/test/net_test: $(NT_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
$(CC) $(LDFLAGS) $(NT_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS) -o $(ARMV7BINDIR)/netapi/test/net_test
+$(ARMV7BINDIR)/netapi/test/net_test_router: $(NT_ROUTER_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
+ $(CC) $(LDFLAGS) $(NT_ROUTER_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS) -o $(ARMV7BINDIR)/netapi/test/net_test_router
+
$(ARMV7BINDIR)/netapi/test/nt_bridge: $(NTB_OBJS) $(TRIE_OBJS) $(ARMV7LIBDIR)/libnetapi.a
$(CC) $(LDFLAGS) $(NTB_OBJS) $(TRIE_OBJS) $(INTERNALLINKDEFS) -o $(ARMV7BINDIR)/netapi/test/nt_bridge
index 3b8441eca1f9229315e2bc5c6c29bd55a9ea983b..ebfabd2eef6357ae6eb4bb8a1329ca6e1f19be2b 100755 (executable)
#include <ti/drv/pa/pa.h>
#include "net_test_util.h"
+#include "router.h"
extern int QUIT;
-
+extern STATS_T stats[TUNE_NETAPI_NUM_CORES];
+extern paSysStats_t netcp_stats;
/* Global definitions */
#ifdef MULTI_THREAD
cpu_set_t cpu_set;
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;
Trie *p_trie_sa_rx;
Trie *p_trie_sa_tx;
-//#define EXPERIMENTAL
-#ifdef EXPERIMENTAL
-#include "router.c"
-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},
-{0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
-{0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
-{0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
-{0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
-
-unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
-#endif
-
-static unsigned char all_mac[]={0,0,0,0,0,0};
-
-
-
-//************for multi pkt burst xfer test in loopback mode
-#define TX_BURST 700
-int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
-nwalTxPSCmdInfo_t flowPSCmdInfo;
-
-
-/* Local Per Process default resourcese maintained at NWAL */
-//nwalLocCxtInfo_t nwalLocCxt;
-
-//this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
-
-//test packet, setup for loopback (so dest is ourself)
-static uint8_t testPkt[] = {
-
- /* MAC header */
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
- 0x08, 0x00,
-
- /* IP header */
- 0x45, 0x00,
- 0x00, 0x6c, /* Length (including this header) */
- 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
- 0x00, 0x00, /* Header checksum */
- 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
-
- /* UDP header */
- 0x12, 0x34, 0x05, 0x55,
- 0x00, 0x58, /* Length, including this header */
- 0x00, 0x00, /* Header checksum */
-
- /* Payload */
- 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
- 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
- 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
- 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
- 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
- 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
- 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
- 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
-
-};
-
-#define TEST_PAYLOAD_LEN 80
-
-#define TEST_PKT_IP_OFFSET_BYTES 14
-#define TEST_PKT_UDP_OFFSET_BYTES 34
-#define TEST_PKT_PLOAD_OFFSET_BYTES 42
-#define TEST_PKT_UDP_HDR_LEN 8
-/* Offsets to length fields */
-#define TEST_PKT_OFFSET_IP_LEN 16
-#define TEST_PKT_OFFSET_UDP_LEN 38
-
-#define TEST_PKT_LEN 122
-
-/* The pseudo header checksum of the packet except for the 16 bit length */
-#define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
-
-void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts);
-void example_fast_pushpop(Pktlib_HeapHandle p_heap, int ntrials);
-
-void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
- PKTIO_METADATA_T meta[], int n_pkts,
- uint64_t ts );
-
-
-#if 0
-/* net test default configuration */
-netTestConfig_t config =
-{
- {
- {0x00,0x01,0x02,0x03,0x05,0x05},
- {0x00,0x01,0x02,0x03,0x05,0x06}
- },
- 0,0,
- {
- {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_SIDEBAND,
- IPSEC_MODE_TX_SIDEBAND,
- 0,
- {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 },
- {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 }
-};
-#endif
-
-#if 1 //goes with real tx (to laptop)
-unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
- 0x00,0x01,0x02,0x03,0x04,0x05,
- 0x08,0x00};
-unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
-#endif
-
-#if 0 //goes with loopback
-unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
- 0x00,0x11,0x22,0x33,0x44,0x55,
- 0x08,0x00};
-#endif
-#define NE 65536
-HEAD_T *nat;
-
-#define NP 5000
-int n_pkt = NP;
-STATS_T stats[TUNE_NETAPI_NUM_CORES];
-paSysStats_t netcp_stats;
-
-
-HEAD_T pkts[NP];
-#define PERSLOW 10 //% of pkts that will not be fastpath'd
-int perslow= PERSLOW;
/*******************************************
*************NETAPI OBJECTS***************
256 //extra room
};
-
-
-void house(NETAPI_SCHED_HANDLE_T *s);
NETAPI_T netapi_handle;
NETAPI_SCHED_HANDLE_T * our_sched;
#ifdef MULTI_THREAD
NETAPI_SCHED_CONFIG_T our_sched_cfg={
NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
};
-void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
-void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
-
-#ifdef TEST_TIMERS
-HPLIB_TIMER_GROUP_HANDLE_T ourTimerBlock;
-HPLIB_TIMER_T t1;
-HPLIB_TIMER_T t2;
-HPLIB_TIMER_T t3;
-
-void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
- int n_fired, //# timers fired
- HPLIB_TIMER_LIST_T fired_list,
- uint64_t currentTime);
-#endif
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[MAX_SEC_INDEX];
-int netapi_algorithm_set = 0;
-int netapi_sec_sa_mode = 2;
NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
-
-#if 0
-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 };
-#endif
-
-/*************************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;
-}
-
-#if 0
-void gen_pkts(int np)
-{
-int i;
-int ip = START_SRC_IP &0xff;
-int port= START_SRC_PORT;
-//HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
-// {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
-HEAD_T temp;
-memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
-
-for(i=0;(i<np) && (i<NP);i++)
- {
- memcpy(&pkts[i],&temp,sizeof(temp));
- update_header(&pkts[i],512); /* update checksums etc */
- /* change template for new pkt */
- ip+=1;
- if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
- temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
- temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
- temp.udp[1] = htonl(temp.udp[1]);
-
- }
- n_pkt=np;
-}
-#endif
-
-void build_table(Trie * p_trie)
-{
-int i;
-int sport=NEW_START_SRC_PORT;
-HEAD_T temp,temp2;
-KEY_T key;
-
-memcpy(&temp,&testPkt[14],sizeof(temp));
-
- //insert entry into trie
-key.src_ip = temp.ip[3];
-key.dst_ip = temp.ip[4];
-key.src_port= (temp.udp[0]&0xffff0000)>>16;
-key.dst_port= (temp.udp[0]&0x0000ffff);
-trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
-
-//build nat table
-for(i=0;i<100;i++)
-{
- memcpy(&temp2,&testPkt[14],sizeof(temp));
- temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
- memcpy(&nat[i], &temp2, sizeof(temp2));
- sport+= 1;
-}
-}
-
-//===========stub transmitter==================
-void send_pkt(Ti_Pkt *pkt, int len)
-{
-//just free pkt. Don't send
-Pktlib_freePacket((Ti_Pkt*)pkt);
- return;
-}
-
-//==========stub slow path============
-void slow_path(Ti_Pkt *pkt, int len)
-{
-// debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
- {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
-//just free pkt
-Pktlib_freePacket((Ti_Pkt*)pkt);
- return;
-}
-/* check header */
-struct LastPktInfo
-{
-int iface;
-int ipcsum;
-int l4csum;
-} ;
-static struct LastPktInfo lpInfo;
-
-int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
-{
-#ifdef MULTI_THREAD
- int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
-#else
- int coreid=0;
-#endif
-if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
-{
- lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
- lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
- lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MASK )== ((NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_ACK) << NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_SHIFT) ? 1 : 0;
- if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
- {
- stats[coreid].sec_rx++;
- }
- if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
- {
- stats[coreid].secp_rx++;
- }
-
- if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
- {
- int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
- if (c==0) stats[coreid].n_class0_rx +=1;
- else if (c==1) stats[coreid].n_class1_rx +=1;
- else if (c==2) stats[coreid].n_class2_rx +=1;
- else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
-}
-}
-
- return 1;
-}
-
-#define PKT_LEN 1400
-void test_alloc_free(int n)
-{
-int i;
-Ti_Pkt * b;
-
-for(i=0;i<n;i++)
-{
- b=Pktlib_allocPacket(ourHeap,PKT_LEN);
- Pktlib_freePacket(b);
-}
-}
-
-//measurement test points
-unsigned int vv1;
-unsigned int vv2;
-unsigned int vv3;
-unsigned int vv4;
-unsigned int vv5;
-unsigned int vv6;
-
-
-unsigned int vv11;
-
-extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
-
-//#define REASSEMBLE_BENCH
-#ifdef REASSEMBLE_BENCH
-#include <ti/drv/pa/example/reassemLib/reassemLib.h>
-/*--------------reassembly benchmark--------------------------------*/
-void our_reassemble_bench(int nfrags)
-{
-paIPReassemblyConfig_t Config={5,128,10000 };
-int i,j;
-int len;
-Ti_Pkt tip;
-char *buffer;
-unsigned long v1;
-unsigned long v2;
-unsigned long sum1=0;
-unsigned long sum2=0;
-paEx_reassemLibInit(&Config);
-for(j=0;j<200/nfrags;j++)
-{
- for(i=0;i<nfrags;i++)
- {
- short temp;
- tip=Pktlib_allocPacket(ourHeap,PKT_LEN);
- Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
- memcpy(&buffer[0],&testPkt[14],20); //IP header
- if (i < (nfrags-1)) buffer[6] = 0x20;
- temp = i*40;
- buffer[6]|= (temp&0x1f00)>>8;
- buffer[7]= (temp&0xff);
- temp = 20+40*8;
- buffer[2]= (temp&0xff00)>>8;
- buffer[3]= (temp&0xff);
- Pktlib_setPacketLen(tip, temp);
- v1= hplib_mUtilGetPmuCCNT();
- paEx_reassemLibProc(tip, 0xffff);
- v2= hplib_mUtilGetPmuCCNT();
- sum1+= v2-v1;
- }
- sum2 += v2-v1;
-}
-printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
-}
-#endif
-
-/*--------------basic pktio send/recv benchmark----------------------*/
-unsigned int timings[10];
-void our_pktio_bench(int ntrials)
-{
-int i;
-#define NBATCH 8
-Ti_Pkt tip;
-unsigned char * pData;
-int len;
-int n;
-int err;
-int sum =0;
-
- Osal_cache_op_measure_reset();
- for(i=0;i<10;i++) timings[i]=0;
- printf("calibration loop .. ");
- for(i=0;i<1000;i++)
- {
- vv1= hplib_mUtilGetPmuCCNT();
- vv2= hplib_mUtilGetPmuCCNT();
- sum+=(vv2-vv1);
- }
- printf(" accuracy = +- %d cycles\n", sum/1000);
- sleep(1);
-
-PKTIO_METADATA_T meta[10]={0};
-//send single, recv single
-for(i=0;i<ntrials;i++)
-{
- vv1= hplib_mUtilGetPmuCCNT();
- tip=Pktlib_allocPacket(ourHeap,PKT_LEN);
- vv2= hplib_mUtilGetPmuCCNT();
- Pktlib_getDataBuffer(tip,&pData,&len);
- vv3= hplib_mUtilGetPmuCCNT();
- pktio_send(our_chan,tip,&meta[0],&err);
- vv4= hplib_mUtilGetPmuCCNT();
- n=pktio_poll(our_chan,NULL , &err);
- vv5= hplib_mUtilGetPmuCCNT();
- timings[0]+=(vv6-vv4);
- timings[1]+=(vv5-vv4);
- timings[3]+=(vv4-vv3);
- timings[5]+=(vv3-vv1);
- timings[8]+=(vv11-vv6);
-
-#ifdef PKTIO_GET_BENCHMARK
- timings[2]+=(our_chan->stats.vv7p-vv4);
- timings[4]+=(our_chan->stats.vv8p-vv3);
- timings[6]+=(our_chan->stats.vv9p-our_chan->stats.vv8p);
- timings[7]+=(our_chan->stats.vv10p-our_chan->stats.vv7p);
-#endif
-}
-
-#ifdef PKTIO_GET_BENCHMARK
- printf("pktio bench. rx=%d (wcb%d) (toqm%d) tx=%d (toqm%d) alloc=%d qpush=%d qpop=%d free=%d\n", timings[0]/ntrials,
- timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
- timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
- {
- unsigned long long ccycles;
- unsigned long long n_c_ops;
- ccycles =Osal_cache_op_measure(&n_c_ops);
- printf("n_c_ops=%lld cache_op_time=%lld (total) = %lld (pp)\n", n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops)) : 0);
- }
-#endif
-
-}
/*-----------test driver: gen an input pkt------- */
//char buffer[sizeof(HEAD_T)+PKT_LEN];
Ti_Pkt * get_pkt(int n, unsigned int *p_len, Pktlib_HeapHandle heap2use, int size, unsigned char * buf2cpy, int copy_size)
{
- int ind;
- long long temp;
- Ti_Pkt * b;
- char * buffer;
- unsigned int len;
-
- if (pktloopback==0)
- {
- if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
- //our mac is valid
- }
- b=Pktlib_allocPacket(heap2use,size);
- if (!b)
- {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
+ int ind;
+ long long temp;
+ Ti_Pkt * b;
+ char * buffer;
+ unsigned int len;
- //debug - way to validate descriptor
- {Ti_Pkt* k= Pktlib_getNextPacket(b);
- if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
+ b=Pktlib_allocPacket(heap2use,size);
+ if (!b)
+ {
+ Debug_printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n);
+ return NULL;
+ }
- //get pointer to buffer area of packet
- Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
- if (!buffer)
- {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
+ //debug - way to validate descriptor
+ {Ti_Pkt* k= Pktlib_getNextPacket(b);
+ if(k != 0) {Debug_printf(" genpkt, nexpkt != NULL");}}
-#if 0
-if (pktloopback==0)
-{
- temp = (long long) rand();
- temp *= PKT_LEN;
- temp /= RAND_MAX;
- temp +=2;
- *p_len = (int) temp;
- *p_len = *p_len &0xfffffffe;
- temp = (long long) rand();
- temp *= n_pkt;
- temp /= RAND_MAX;
- ind = (int) temp;
- update_header(&pkts[ind],*p_len);
- //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
- memcpy(&buffer[0], &mac_header[0],14);
- memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
-}
-else
-#endif
- //copy test packet into buffer
-{
- memcpy(&buffer[0], buf2cpy, copy_size);
+ //get pointer to buffer area of packet
+ Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
+ if (!buffer)
+ {
+ Debug_printf("net_test: get_pkt() heap returned empty buffer %d \n", n);
+ return NULL;
+ }
+ //copy test packet into buffer
+ {
+ memcpy(&buffer[0], buf2cpy, copy_size);
*p_len = copy_size;
}
return b;
}
-static int eof=0;
/*--------------------------------------------------------------
*----------utility to flip a packet and send
*--------------------back to source----------------------------
}
else
{
- printf("flip_and_send_pkt: un-supported IPSEC protocol\n");
+ Debug_printf("flip_and_send_pkt: un-supported IPSEC protocol\n");
Pktlib_freePacket(tip);
return;
}
#endif
-#if 1
- //p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_tx, (char *)p_spi ,4);
p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
-#endif
if (p_sa_info == NULL)
{
- printf("flip_and_send_pkt(): trie_lookup() failed\n");
+ Debug_printf("flip_and_send_pkt(): trie_lookup() failed\n");
Pktlib_freePacket(tip);
return;
}
-
-#if 1
tunnel_id = p_sa_info->tunnel_id;
p_sa_info_tx = (netTestSA_t *) trie_lookup(p_trie_sa_tx, (char *)&tunnel_id ,4);
if (p_sa_info_tx == NULL)
{
- printf("flip_and_send_pkt(): trie_lookup() failed\n");
+ Debug_printf("flip_and_send_pkt(): trie_lookup() failed\n");
Pktlib_freePacket(tip);
return;
}
-#endif
-
//just drop non-udp packet
if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
{
memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
-
-#if tmannan
- /* this code may break everything for now */
- memcpy(&p_pkt[14+20],&p_sa_info_tx->spi,4);
-
-#endif
-
-
-
if (netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
{
- /* inner ip checksum : leave alone */
- /* outer ip, set to 0 (we will compute on way out */
+ /* inner ip checksum : leave alone, outer ip, set to 0 (we will compute on way out */
memset(&p_pkt[14+10],0,2);
}
- else
- {
- //#else //inflow, don't touch outer , clear inner
- //DALmemset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
- //outer ip checksum : leave alone
- }
}
else
{
int err;
nwalDmTxPayloadInfo_t meta_tx={0};
meta.sa_handle=p_sa_info_tx->tx_data_mode_handle; //use TX SA context
-
memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
meta_tx.appCtxId = (nwal_AppId)p_sa_info_tx;
-
- meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
- meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
-
-#if 0
- printf("flip_and_send_pkt(): encOffset %d\n", meta_tx.encOffset);
- printf("flip_and_send_pkt():authOffset %d\n", meta_tx.authOffset);
- printf("flip_and_send_pkt(): encSize %d\n", meta_tx.encSize);
- printf("flip_and_send_pkt(): authSize %d\n", meta_tx.authSize);
-#endif
-
+ meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
+ meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
meta_tx.pAuthIV=NULL;
meta_tx.aadSize=0;
meta_tx.pAad=NULL;
if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
{
- memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
+ memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
p_iv[12] = 0;
p_iv[13] = 0;
p_iv[15] = 1;
meta_tx.pEncIV = &p_iv[0];
}
- else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
- (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
+ else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
{
memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
meta_tx.pEncIV = &p_iv[0];
{
meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
}
- //meta_tx.authIvSize=0;
-
/* post it to netcp sb tx channel*/
- //meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetPmuCCNT();
meta.u.tx_sb_meta=&meta_tx;
#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
NWAL_DESC_SIZE);
#else
- pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
+ pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
#endif
}
else
{
- //INFLOW TX *******************
- //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
+ //INFLOW TX, send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
int err;
nwalTxPktInfo_t meta_tx={0};
-#define USE_COPY
-#ifdef USE_COPY
-//debug: see if re-using RX descriptor for TX is causing our SA lockup
- {
- int new_len=0;
- Ti_Pkt new_tip = get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0] , len);
- if (!new_tip)
- {
- printf("net_test> new_tip NULL\n");
- }
- else
- {
- Pktlib_setPacketLen(new_tip,new_len);
- Pktlib_freePacket(tip);
- tip=new_tip;
- Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len); //reset p_pkt to point to new buffer as its used below
-// Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats[coreid].sec_tx);
- }
- }
- if (len <1500)
- {
- eof+=1;
- }
-#endif
-
meta.sa_handle=p_sa_info_tx->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset;
}
else
{
- printf("flip_and_send_pkt: invalid ESP protocol\n");
+ Debug_printf("flip_and_send_pkt: invalid ESP protocol\n");
return;
}
}
-
-
-/***************************************
- benchmark receive handler
-****************************************/
-void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
- PKTIO_METADATA_T meta[], int n_pkts,
- uint64_t ts )
-{
- int i;
- vv6= hplib_mUtilGetPmuCCNT();
- for (i=0;i<n_pkts; i++)
- {
- Pktlib_freePacket(p_recv[i]);
- }
- vv11 = hplib_mUtilGetPmuCCNT();
-}
-
/****************************************************************************************/
/******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
/****************** Handles Decrypt and Encrypt operation callbacks ******************/
PKTIO_METADATA_T meta[], int n_pkts,
uint64_t ts )
{
-int i;
-int len;
-int p;
-HEAD_T * p_res;
-Ti_Pkt * tip;
-unsigned int templen;
-int err;
-KEY_T key;
-char * p_pkt;
-HEAD_T * p_head;
-HEAD_T temp_head;
-int tag_cmp=0;
-unsigned int hash[4];
-uint8_t *p_spi;
-netTestSA_t *p_sa_info;
+ int i;
+ int len;
+ int p;
+ HEAD_T * p_res;
+ Ti_Pkt * tip;
+ unsigned int templen;
+ int err;
+ KEY_T key;
+ char * p_pkt;
+ HEAD_T * p_head;
+ HEAD_T temp_head;
+ int tag_cmp=0;
+ unsigned int hash[4];
+ uint8_t *p_spi;
+ netTestSA_t *p_sa_info;
#ifdef MULTI_THREAD
int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
#else
-int coreid=0;
+ int coreid=0;
#endif
-//nwal_AppId time;
-unsigned long time, delta_time;
- /* loop over received pkts */
- for(i=0;i<n_pkts;i++)
+ //nwal_AppId time;
+ unsigned long time, delta_time;
+ /* loop over received pkts */
+ for(i=0;i<n_pkts;i++)
{
tip = p_recv[i];
Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
len = Pktlib_getPacketLen(tip);//real length
-
/*p_sa_info is for rx context */
p_sa_info = (netTestSA_t*)meta[i].u.rx_sb_meta->appCtxId;
if (p_sa_info == NULL)
{
- printf("recv_sb_cb(): trie_lookup failed\n");
+ Debug_printf("recv_sb_cb(): trie_lookup failed\n");
continue;
}
-
-
//is this a decrypt (rx_tunnel) complete
if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
{
-
//time = hplib_mUtilGetPmuCCNT();
- //delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
+ //delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
stats[coreid].total_decrypt_time += delta_time;
stats[coreid].sb_rx+=1;
- //copy hash out of meta data (for some reason it needs endian conversion)
- hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
- hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
- hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
- hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
- if(stats[coreid].sb_rx<=16)
- {
- char *tp = (char *) &hash[0];
- //dump_header((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
-#if 0
- printf("decrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
- p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
- p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
- p_pkt[len-7],p_pkt[len-6],
- p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
- printf("decrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
- tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
- tp[6],tp[7],tp[8],tp[9],tp[10],tp[11],tp[12],tp[13],tp[14],tp[15]);
-
- // netapi_dump_buf((long*)p_pkt,len);
-#endif
- }
- //check tag
- //printf("recv_sb_cb(); auth tag size %d\n", p_sa_info->auth_tag_size);
- tag_cmp = memcmp(&p_pkt[len-p_sa_info->auth_tag_size],(char*) &hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
- stats[coreid].n_auth_ok += !(tag_cmp);
-
+ //copy hash out of meta data (for some reason it needs endian conversion)
+ hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
+ hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
+ hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
+ hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
+ if(stats[coreid].sb_rx<=16)
+ {
+ char *tp = (char *) &hash[0];
+ //dump_header((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
+ }
+ tag_cmp = memcmp(&p_pkt[len-p_sa_info->auth_tag_size],(char*) &hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
+ stats[coreid].n_auth_ok += !(tag_cmp);
flip_and_send_pkt(tip, p_pkt, len,1, 0); //flip packet to echo back and send
}
//this is an encrypt (tx tunnel) complete
else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
{
- hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
- hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
- hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
- hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
- stats[coreid].sb_tx+=1;
- if(stats[coreid].sb_tx<=16)
- {
- char *tp1 = (char *) &hash[0];
- //dump_header((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
-#if 0
- printf("encrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
- p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
- p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
- p_pkt[len-7],p_pkt[len-6],
- p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
- printf("encrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
- tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
- tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11],tp1[12],tp1[13],tp1[14],tp1[15]);
- //netapi_dump_buf((long*)p_pkt,len);
-#endif
- }
- //put the computed tag in the packet
- memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
-// printf("recv_sb_cb(): dumping pkt after updating computed tag, len %d, auth tag size %d\n", len, p_sa_info->auth_tag_size);
- //netapi_dump_buf(p_pkt, len);
- {
- PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
- nwalTxPktInfo_t meta_tx={0};
- // now send directly
- meta2.sa_handle=nwal_HANDLE_INVALID;
- meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted
- meta_tx.startOffset = 0;
- meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
- //not used
- meta_tx.l4OffBytes = 0;
- meta_tx.l4HdrLen = 0;
- meta_tx.ploadLen = 0;
- time = hplib_mUtilGetPmuCCNT();
- delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
- stats[coreid].total_encrypt_time += delta_time;
-
-
- /* post it to netcp tx channel*/
- meta2.u.tx_meta=&meta_tx;
-// printf("recv_sb_cb(): calling pktio send to send it to network\n");
- pktio_send(netcp_tx_chan,tip,&meta2,&err);
- hplib_cacheWbInv(p_pkt,len);
- stats[coreid].tx +=1;
- }
+ hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
+ hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
+ hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
+ hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
+ stats[coreid].sb_tx+=1;
+ if(stats[coreid].sb_tx<=16)
+ {
+ //dump_header((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
+ }
+ //put the computed tag in the packet
+ memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
+ {
+ PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
+ nwalTxPktInfo_t meta_tx={0};
+ // now send directly
+ meta2.sa_handle=nwal_HANDLE_INVALID;
+ meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted
+ meta_tx.startOffset = 0;
+ meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
+ meta_tx.l4OffBytes = 0;
+ meta_tx.l4HdrLen = 0;
+ meta_tx.ploadLen = 0;
+ time = hplib_mUtilGetPmuCCNT();
+ delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
+ stats[coreid].total_encrypt_time += delta_time;
+
+ /* post it to netcp tx channel*/
+ meta2.u.tx_meta=&meta_tx;
+ pktio_send(netcp_tx_chan,tip,&meta2,&err);
+ hplib_cacheWbInv(p_pkt,len);
+ stats[coreid].tx +=1;
+ }
}
- else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
+ else Debug_printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
}
}
/* loop over received pkts */
for(i=0;i<n_pkts;i++)
{
- printf("recv_cb: appId 0x%x\n", meta[i].u.rx_meta->appId);
+ Debug_printf("recv_cb: appId 0x%x\n", meta[i].u.rx_meta->appId);
ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
enet_port = meta[i].u.rx_meta->enetPort;
if(((unsigned int)meta[i].u.rx_meta->appId) == expPkt_appid)
{
- printf("recv_cb: received exception packet\n");
+ Debug_printf("recv_cb: received exception packet\n");
Pktlib_freePacket(tip);
if(((unsigned int)meta[i].u.rx_meta->rxFlag1 & NWAL_RX_IP_FRAGMENT_PKT) ==
NWAL_RX_IP_FRAGMENT_PKT)
{
- printf("recv_cb: received fragmented packet\n");
+ Debug_printf("recv_cb: received fragmented packet\n");
stats[coreid].exceptionPktsFrag+=1;
}
else
{
- printf("recv_cb: received exception packet but not fragmented packet\n");
+ Debug_printf("recv_cb: received exception packet but not fragmented packet\n");
stats[coreid].exceptionPktsOther+=1;
}
continue;
//debug: validate descriptor */
if(Pktlib_getNextPacket(tip) != 0)
{
- printf(" rcv_cb, nexpkt != NULL");
+ Debug_printf(" rcv_cb, nexpkt != NULL");
}
if(coreid<TUNE_NETAPI_NUM_CORES)
#ifdef DEBUG_DESC
if (stats[coreid].rx<16)
{
- printf(">rx dmp..");
+ Debug_printf(">rx dmp..");
dump_descr((long *) tip, stats[coreid].rx);
}
else if (stats[coreid].rx>99)
{
- printf(">rx dmp..");
+ Debug_printf(">rx dmp..");
dump_descr((long *) tip,stats[coreid].rx);
}
#endif
memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
/* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
- if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
+ if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
{
if (!check_header(p_head,&meta[i]))
{
p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
if (p_sa_info == NULL)
{
- printf("recv_cb(): trie_lookup() failed\n");
+ Debug_printf("recv_cb(): trie_lookup() failed\n");
continue;
}
memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
- //meta_tx.ploadLen = len;
-
-
-
- meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
- meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
-
-
-
-#if 0
- printf("recv_cb(): packet length %d\n", len);
- printf("recv_cb(): encOffset %d\n", meta_tx.encOffset);
- printf("recv_cb():authOffset %d\n", meta_tx.authOffset);
- printf("recv_cb(): encSize %d\n", meta_tx.encSize);
- printf("recv_cb(): authSize %d\n", meta_tx.authSize);
-#endif
+ meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
+ meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
{
}
meta_tx.appCtxId = (nwal_AppId)p_sa_info;
- //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
+ //Debug_printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
/* post it to netcp sb tx channel*/
meta2.u.tx_sb_meta=&meta_tx;
* Application can use below rxSbSaQ for polling packets back from
* SA
*/
- nwalRetVal =
- nwal_getLocCxtInfo(pktio_mGetNwalInstance(netcp_sb_tx_chan),
+ nwalRetVal =
+ nwal_getLocCxtInfo(pktio_mGetNwalInstance(netcp_sb_tx_chan),
&nwalLocCxt);
- if(nwalRetVal == nwal_OK)
- {
- p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
- }
- nwal_mCmdDMUpdate(tip,
+ if(nwalRetVal == nwal_OK)
+ {
+ p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
+ }
+ nwal_mCmdDMUpdate(tip,
&p_sa_info->rx_dmPSCmdInfo,
meta_tx.appCtxId,
meta_tx.encOffset,
@@ -1436,1087 +809,54 @@ void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
meta_tx.pAuthIV,
meta_tx.aadSize,
meta_tx.pAad);
- pPloadDesc = Pktlib_getDescFromPacket(tip);
- pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
- Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
- pPloadDesc,
- NWAL_DESC_SIZE);
+ pPloadDesc = Pktlib_getDescFromPacket(tip);
+ pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
+ Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
+ pPloadDesc,
+ NWAL_DESC_SIZE);
#else
- pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
+ pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
#endif
- continue;
+ continue;
+ }
+ else
+ {
+ //inflow mode. flip and send
+ flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
+ }
}
- else
+ else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
{
- //inflow mode. flip and send
- flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
+ stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
}
- }
- else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
- {
- stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
- }
- else //non ipsec
- {
- if (!check_header(p_head,&meta[i]))
+ else //non ipsec
{
- stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
- continue;
- }
-
-#if 0
- /* lookup flow */
- key.src_ip = p_head->ip[3];
- key.dst_ip = p_head->ip[4];
- key.src_port= (p_head->udp[0]&0xffff0000)>>16;
- key.dst_port= (p_head->udp[0]&0x0000ffff);
- p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
- if (!p_res) { stats[coreid].n_new+=1; slow_path(tip, len); continue;}
-
- /* copy header */
- memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
-
- memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
- /* update_mac(&p_pkt[0]); */
-
- /* 'simulate' send pkt */
- send_pkt(tip,len);
-#endif
- //just flip and send
+ if (!check_header(p_head,&meta[i]))
+ {
+ stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
+ continue;
+ }
+ //just flip and send
flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
}
}
- //printf("recv done\n");
}
-#ifdef TEST_TIMERS
-//timer callback
-void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
- int n_fired, //# timers fired
- HPLIB_TIMER_LIST_T fired_list,
- uint64_t currentTime)
-{
-int i;
-HPLIB_TIMER_T tx;
-int cookie;
-int err;
-unsigned long long et;
-#ifdef MULTI_THREAD
- int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
-#else
- int coreid=0;
-#endif
-//DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
-tx = hplib_Timer_GetFirst(fired_list);
-for(i=0;i<n_fired;i++)
-{
- cookie = (int) hplib_Time_rGetCookie(tx);
- et = hplib_Timer_GetTs(tx); //debug
- //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
- if (cookie ==1)
- {
- stats[coreid].n_t1+=1;
- t1 = hplib_Timer_Start(
- th,
- (void *) 1,
- 100LL, //timer group tics
- &err);
- }
- else if (cookie ==2)
- {
- stats[coreid].n_t2+=1;
- t2 = hplib_Timer_Start(
- th,
- (void *) 2,
- 200LL, //timer group ticks
- &err);
- }
- else
- {
- stats[coreid].n_t3+=1;
- t3 = hplib_Timer_Start(
- th,
- (void *) 3,
- 300LL, //timer group ticks
- &err);
- //cancel 1 and restart 1
- hplib_Timer_Cancel(th,t1,&err);
- t1 = hplib_Timer_Start(
- th,
- (void *) 1,
- 100LL, //timer group ticks
- &err);
- }
- tx = hplib_Timer_GetNext(fired_list,tx);
-}
-}
-#endif
-void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
-{
-#if 0
- if(retVal != nwal_OK)
- {
- System_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
- retVal);
- return(nwal_FALSE);
- }
- if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
- {
- printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
- }
- else
- {
- printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
- }
-#endif
- printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
- printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
- p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
- printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
- p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
- p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
-}
-
-void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
-{
-
- printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
- printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
- p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
-}
-
-
-
-
-static int np2process = NP;
-/******************************************************
- * stats callback
- *******************************************************/
-void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
-{
-
-#ifdef MULTI_THREAD
- int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
-#else
-int coreid=0;
-#endif
-
- stats[coreid].n_stats_cb +=1;
- if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
-}
-void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
-{
-uint32_t numFreeDataPackets;
-uint32_t numZeroBufferPackets;
-uint32_t numPacketsinGarbage;
-Pktlib_HeapStats pktLibHeapStats;
-int i;
-unsigned long long bcpp;
-unsigned long long bcpp_noc;
-unsigned long long bcpp_app;
-unsigned long long bcpp_tx;
-unsigned long long npL;
-unsigned long long cyclesL;
-unsigned long long ccyclesL; //cache cycles
-unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
-unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
-unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
-NETAPI_SA_STATS_T netapi_sa_stats;
-
- for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
- {
- printf("Per Core Statistics for CORE %d\n", i);
- printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
- printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%dsecRx=%d\t"
- "secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d sec_tx=%d min_rx=%d min_tx=%d fragPkt=%d, exceptionPktOther=%d\n",
- stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new,
- stats[i].n_class0_rx, stats[i].n_class1_rx, stats[i].n_class2_rx, stats[i].sec_rx,
- stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
- stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min, stats[i].exceptionPktsFrag, stats[i].exceptionPktsOther);
- printf(">if rx stats: %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
- printf(">core rx stats: %d \n",stats[i].core_rx);
-
- if (stats[i].rx && stats[i].tx)
- printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
- (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
-
-
- if (npL && stats[i].rx)
- {
- bcpp = cyclesL/npL;
- bcpp_noc = (cyclesL-ccyclesL)/npL;
- bcpp_app = (stats[i].app_cycles-stats[i].tx_cache_cycles)/stats[i].rx;
- }
- else
- {
- bcpp = bcpp_noc=bcpp_app=0L;
- }
- if (stats[i].tx)
- {
- bcpp_tx = (stats[i].send_cycles-stats[i].tx_cache_cycles)/stats[i].tx;
- }
- else
- {
- bcpp_tx = 0L;
- }
- printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
- bcpp,bcpp_noc,bcpp_app, bcpp_tx);
- printf("\n");
- }
-
-#ifdef MULTI_THREAD
- netapi_schedGetStats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
- netapi_schedGetStats(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];
-#else
-netapi_schedGetStats(our_sched, &npL,&cyclesL,&ccyclesL);
-#endif
-
-if(pPaStats)
-{
- printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
- printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
- printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
- printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
- printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
- printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
- printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
- printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
- printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
- printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
- printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
- printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
- printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
- printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
- printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
- printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
- printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
- printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
- printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
- printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
- printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
- printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
- printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
- printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
- printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
- printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
- printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
-}
-Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
-printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
-
-Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
-printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
-
-
-Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
-printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
-
-
-#if 0
-printf("pa2sa descriptor area dump\n");
-for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
-{
- extern long * pa2sa_descr_base;
- long * tip= &pa2sa_descr_base[32*i];
- dump_descr(tip, i);
-}
-printf("sa2pa descriptor area dump\n");
-for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
-{
- extern long * sa2pa_descr_base;
- long * tip= &sa2pa_descr_base[32*i];
- dump_descr(tip, i);
-}
-#endif
-#ifdef TEST_TIMERS
-//debug = dump timer polling stats
- dump_poll_stats();
-//debug = dump timer polling stats
-//dump_poll_stats();
-#endif
-
- for (i = 0; i < MAX_SEC_INDEX; i++)
- {
- /* Statistics for RX Tunnel */
- memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
- if (sa_info[i].dir ==NWAL_SA_DIR_INBOUND )
- {
- netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
- if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
- {
- print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
- sa_info[i].authMode,
- sa_info[i].cipherMode);
- }
- if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
- {
- print_datamode_stats(&(netapi_sa_stats.dataModeStats),
- sa_info[i].authMode,
- sa_info[i].cipherMode);
- }
- }
- else if (sa_info[i].dir ==NWAL_SA_DIR_OUTBOUND)
- {
- netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
- if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
- {
- print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
- sa_info[i].authMode,
- sa_info[i].cipherMode);
- }
- if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
- {
- print_datamode_stats(&(netapi_sa_stats.dataModeStats),
- sa_info[i].authMode,
- sa_info[i].cipherMode);
- }
- }
- else
- printf("our_stats_cb: invalid SA direction\n");
- }
- netapi_dump_internal_heap_stats();
-}
-
-//******************************************************
-//use scheduling housekeeping callback to generate pkts
-//******************************************************
-static int done_burst=0;
-void house(NETAPI_SCHED_HANDLE_T * s)
-{
-Ti_Pkt * tip;
-unsigned int len;
-nwalTxPktInfo_t meta_tx = {0};
-PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
-int err;
-static int house_pkts_gened=0;
-int p;
-unsigned char * pIpHdr,* pData;
-unsigned int vv1,vv2,vv3;
-unsigned int sum_vv1=0;
-unsigned int sum_vv2=0;
-unsigned int sum_vv3=0;
-unsigned int sum_vv4=0;
-unsigned int sum_vv5=0;
-
-unsigned int nwal_flow_vv1,nwal_flow_vv2;
-unsigned int nwal_sum_vv1=0;
-unsigned int nwal_sum_vv2=0;
-unsigned int nwal_sum_vv3=0;
-unsigned int nwal_sum_vv4=0;
-unsigned int nwal_sum_vv5=0;
-unsigned int nwal_sum_vv6=0;
-
-unsigned int nwal_sum_flow_vv1=0;
-unsigned int nwal_sum_flow_vv2=0;
-unsigned long long cache_op_b1;
-unsigned long long cache_op_b2;
-unsigned long long n_c_ops;
-static int first =0;
-Cppi_HostDesc* pPktDesc;
-
-int coreid = 0; //who we are
-#ifdef MULTI_THREAD
-NETAPI_T nh= netapi_schedGetHandle(s);
-coreid=(int) netapi_getCookie(nh);
-
-if (QUIT) {netapi_schedClose(s,NULL,&err); return;}
-
-if (coreid==0) //slave
-{
- netcp_cfgReqStats(nh, our_stats_cb_mt, 0,&err);
-}
-#else
-if(done_burst)
-{
- house_pkts_gened+=TX_BURST;
- printf("net_test> request stats at n=%d \n",house_pkts_gened);
- netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
- if (err!=0) {printf("stats req failed\n");}
- if (house_pkts_gened >= np2process+ 100)
- {
- netapi_schedClose(s,NULL,&err);
- }
- return;
-}
-done_burst=1;
-Osal_cache_op_measure_reset();
-memset(&meta_tx,0,sizeof(meta_tx));
-for(p=0;p<TX_BURST;p++) {
-//reguest stats
-if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
-{
- printf("net_test> request stats at n=%d \n",house_pkts_gened);
- netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
- if (err!=0) {printf("stats req failed\n");}
-}
-
-
- if (house_pkts_gened >= np2process+ 100)
- {
- //shutdown
- netapi_schedClose(s,NULL,&err);
- continue;
- }
-
- else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
-
-
-/* manufacture a pkt to transmit */
- tip = get_pkt(house_pkts_gened, &len, ourHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
- if(!tip) { house_pkts_gened +=1; continue; }
-
-
- /* set the pkt length */
- vv1 = hplib_mUtilGetPmuCCNT();
- Pktlib_setPacketLen(tip, len);
-
- /* set up meta data */
- meta.sa_handle=nwal_HANDLE_INVALID;
- /* #define BENCH_UDP_SEND */
-#ifdef BEND_UDP_SEND
- meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
- meta_tx.startOffset = 0;
- /* GONE in V2 meta_tx.pktLen = len; */
- meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
- meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
- meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
- //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
- meta_tx.ploadLen = TEST_PAYLOAD_LEN;
-
- Pktlib_getDataBuffer(tip,&pData,&len);
- if(house_pkts_gened &0x1)
- {
- memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
- }
- pIpHdr = pData + meta_tx.ipOffBytes;
- meta_tx.pseudoHdrChecksum =
- test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
-#else
- Pktlib_getDataBuffer(tip,&pData,&len);
- if(house_pkts_gened &0x1)
- {
- memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
- }
- meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
- meta_tx.startOffset = 0;
- meta_tx.ploadLen = TEST_PAYLOAD_LEN;
-#endif
- /* post it to netcp tx channel*/
- meta.u.tx_meta=&meta_tx;
-#ifdef DEBUG_DESC
- if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
- else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
-#endif
-
- if(!first)
- {
- first++;
- nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
- if(nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
- &meta_tx,
- &flowPSCmdInfo) != nwal_OK)
- {
- printf("nwal_initPSCmdInfo() ERROR \n");
- }
- nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
- nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
- nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
- }
-
- cache_op_b1= Osal_cache_op_measure(&n_c_ops);
- vv2= hplib_mUtilGetPmuCCNT();
-#ifdef BEND_UDP_SEND
- nwal_mCmdSetL4CkSumPort( tip,
- &flowPSCmdInfo,
- TEST_PKT_UDP_OFFSET_BYTES,
- (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
- meta_tx.pseudoHdrChecksum,
- meta_tx.enetPort);
-#else
- nwal_mCmdSetPort (tip,
- &flowPSCmdInfo, //could be NULL
- 0); //port 0 -> switch decides
-
-#endif
-
- pPktDesc = Pktlib_getDescFromPacket(tip);
- /* Send the packet out to transmit Q*/
- Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
- pPktDesc,
- NWAL_DESC_SIZE);
- vv3= hplib_mUtilGetPmuCCNT();
- cache_op_b2= Osal_cache_op_measure(&n_c_ops);
-
- sum_vv1 += (vv2-vv1);
- if(!house_pkts_gened)
- {
- /* first packet. Take out the PS command label creation cost */
- sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
- }
-
- sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
-
- // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
-
-
- stats[coreid].itx +=1;
- house_pkts_gened +=1;
- }
-{
- unsigned long long ccycles;
- ccycles =Osal_cache_op_measure(&n_c_ops);
- if (sum_vv1)
- {
- printf("BURST NWAL Fast send %d pkts. metadata=%d Cmd Label Creation Cost=%d nwal Fast Send Cost (less cacheop)= %d n_c_ops=%lld cache_op_time=%lld (pp-> %d)\n",
- stats[coreid].itx, sum_vv1/stats[coreid].itx, nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx,
- n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
-#if 0
- printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
- nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
- nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
-
-#endif
-
- if(stats[core_id].itx2)
- {
- printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
- nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
- }
-
- }
-}
-#endif
-}
-
-void build_sa_db(int i)
-{
- long tmp_spi;
- long tmp_tunnel;
- if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA1) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CBC))
- {
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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].iv_len=16;
- sa_info[i].bl=16;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- 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 ;
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
-
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA2_256) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CTR))
- {
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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].iv_len=8;
- sa_info[i].bl=8;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- 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].key_params = &netTestCfg.key_params[i];
-
- 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 ;
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA2_256) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
- {
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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].iv_len=8;
- sa_info[i].bl=8;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- 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 ;
-
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_MD5) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
- {
- /* 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 + 24; /*done: same for all cipher suites */
- sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN;
-
- sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
- netTest_IP_HEADER_LEN +
- netTest_NULL_ESP_HEADER_LEN +
- netTest_NULL_IV_LEN +
- 24;
- sa_info[i].iv_len=0;
- sa_info[i].bl=4;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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;
- 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_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID ;
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_NULL) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_GCM))
- {
- /* 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;
-
- sa_info[i].iv_len=0;
- sa_info[i].bl=4;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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 ;
-
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_NULL) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CCM))
- {
- /* 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;
-
- sa_info[i].iv_len=0;
- sa_info[i].bl=4;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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 ;
-
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_AES_XCBC) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
- {
- /* 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;
-
- sa_info[i].iv_len=0;
- sa_info[i].bl=4;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- /* 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 = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- 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 ;
-
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_GMAC) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
- {
- /* 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_AES_GMAC_IV_LEN;
-
- sa_info[i].iv_len=0;
- sa_info[i].bl=4;
- sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
- sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
-
- /* 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.pAuthIV = 0;
- sa_info[i].tx_payload_info.pPkt = 0;
-
- sa_info[i].cipherMode = netTestCfg.sa_info[i].cipherMode;
- sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
- sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
- sa_info[i].auth_tag_size = netTest_AES_GMAC_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 ;
-
- sa_info[i].dir =netTestCfg.sa_info[i].dir;
- tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
- tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
- sa_info[i].spi =tmp_spi;
- sa_info[i].tunnel_id = tmp_tunnel;
-
- if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
- }
- else
- {
- trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
- printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
- }
- }
- else
- printf("build_sa_db(): invalid encryption/authentication combination selected\n");
-
- //printf("sa_build_db(): authOffset %d, innerIpOffset %d, encOffset %d\n", sa_info[i].tx_payload_info.authOffset, sa_info[i].inner_ip_offset, sa_info[i].tx_payload_info.encOffset);
-
-
-}
-
-
-
-
+
+
#ifdef MULTI_THREAD
NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
void slow_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;
-
-
- printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
+ Debug_printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
CPU_ZERO( &cpu_set);
#ifdef CORTEX_A15
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],(void*) coreid);
-
- 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);
+ Debug_printf("sched create failed for core%d\n",coreid);
exit(1);
}
scheduler[coreid]->config.yield = FALSE;
/**************Entry point into scheduler ****/
/*********************************************/
netapi_schedRun(scheduler[coreid], &err);
- printf(">net_test: core %d worker thread done\n",coreid);
+ Debug_printf(">net_test: core %d worker thread done\n",coreid);
pktio_close(tx_chan, &err);
pktio_close(rx_chan, &err);
-#ifndef EXPERIMENTAL
pktio_close(sb_tx_chan, &err);
pktio_close(sb_tx_chan, &err);
-#endif
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;
/* 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);
+ netapi_setCookie(worker_nh[coreid],(void*)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);
+ Debug_printf("sched create failed for core%d\n",coreid);
exit(1);
}
scheduler[coreid]->config.pollCtrlQ = FALSE;
//sleep(100000);
netapi_schedRun(scheduler[coreid], &err);
- printf(">net_test: core %d worker thread done\n",coreid);
+ Debug_printf(">net_test: core %d worker thread done\n",coreid);
pktio_close(tx_chan, &err);
pktio_close(rx_chan, &err);
-#ifndef EXPERIMENTAL
pktio_close(sb_tx_chan, &err);
pktio_close(sb_tx_chan, &err);
-#endif
netapi_shutdown(worker_nh[coreid]);
}
Pktlib_HeapIfTable* pPktifTable;
/* Local Per Process default resourcese maintained at NWAL */
nwalLocCxtInfo_t nwalLocCxt;
-
+ //nwalSaIpSecId_t nwalSaIpSecId;
FILE * fpr = NULL;
- nwalSaIpSecId_t nwalSaIpSecId;
-
err= getrlimit(RLIMIT_STACK,&rl);
- if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
+ if (!err) Debug_printf(" stack limit = %d\n",rl.rlim_cur); else Debug_printf("getrlimit failed\n");
- if (argc>=2) np2process = atoi(argv[1]);
- printf("*************** np2process %d\n", np2process);
- if (np2process<0) np2process = NP; /* default */
- if (argc==3) perslow = atoi(argv[2]);
- if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
- if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
/* install signal handler for ^c */
signal(SIGINT,mysig);
fpr = fopen(input_file_name, "r");
if (fpr == NULL)
{
- printf("Error in opening %s input file\n", input_file_name);
+ Debug_printf("Error in opening %s input file\n", input_file_name);
exit(1);
}
else
memset(&sa_info, 0, sizeof(sa_info));
- //real mode, so update our test packet mac header and ip header
- if (pktloopback==0)
- {
- memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
- memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
- }
#ifdef MULTI_THREAD
/* assign main net_test thread to run on core 0 */
CPU_SET( 0, &cpu_set);
hplib_utilSetupCore(0, &cpu_set);
#endif
+
/* create netapi */
netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
ourHeap = Pktlib_findHeapByName("netapi");
if (!ourHeap)
{
- printf("Pktlib_findHeapByName() fail\n");
+ Debug_printf("Pktlib_findHeapByName() fail\n");
exit(1);
}
netapi_registerHeap(netapi_handle, specialSmall);
netapi_registerHeap(netapi_handle, specialLarge);
-#ifdef REASSEMBLE_BENCH
- our_reassemble_bench(2);
-exit(1);
-#endif
-#ifndef EXPERIMENTAL
- /* 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);
- }
-#endif
/* 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);
+ Debug_printf("pktio open TX failed err=%d\n",err);
exit(1);
}
-#ifdef EXPERIMENTAL
- netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
-#else
netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
-#endif
if (!netcp_rx_chan)
{
- printf("pktio open RX failed err=%d\n",err);
+ Debug_printf("pktio open RX failed err=%d\n",err);
exit(1);
}
-#ifndef EXPERIMENTAL
/* 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);}
+ if (!netcp_rx_chan2) {Debug_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);
+ Debug_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);
+ Debug_printf("pktio open SB RX failed err=%d\n",err);
exit(1);
}
-#endif
- printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
+ Debug_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);}
+ if (!our_sched) {Debug_printf("sched create failed\n"); exit(1);}
-#if 0
- /********************************************
- * Basic pkt loopback test
- *********************************************/
- printf("...running pure push/pop benchmark\n");
- our_pktio_bench(1000);
- our_pktio_bench(1000);
- our_pktio_bench(1000);
- our_pktio_bench(1000);
- our_pktio_bench(1000);
- /*********************************************/
-#endif
- //#define PROMISCUOUS
-#ifdef PROMISCUOUS
-#define ETH0 1
-#define ETH1 2
- printf(">net_test: WARNING, ADDING RULE FOR PROMISCUOUS THAT WILL BREAK LINUX STACK\n");
- netcp_cfgCreateMacInterface(
- netapi_handle,
- &all_mac[0],
- 0,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
-#define ETH0 0
-#define ETH1 1
-#endif
-
- /* add mac intefaces */
- printf("main, switch port0 %d\n", netTestCfg.switch_port[0]);
- netcp_cfgCreateMacInterface(
- netapi_handle,
- &netTestCfg.mac[0][0],
- ETH0,
- netTestCfg.switch_port[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); }
-
- //attach an IP to this interface
- ip_rule0=netcp_cfgAddIp(
- netapi_handle,
- ETH0,
- nwal_IPV4,
- &netTestCfg.ip[0].ipv4[0],
- NULL, //all IP
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,
- &err
- );
- if (err) {printf("addip0 failed %d\n",err); exit(1); }
-
- //create a 2nd mac instance
- printf("main, switch port1 %d\n", netTestCfg.switch_port[1]);
- netcp_cfgCreateMacInterface(
- netapi_handle,
- &netTestCfg.mac[1][0],
- ETH1,
- netTestCfg.switch_port[1],
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,
- (NETCP_CFG_VLAN_T ) NULL , //future
- 1,
- &err);
- if (err) {printf("addmac1 failed %d\n",err); exit(1); }
-
- //attach an IP to this interface
- ip_rule1=netcp_cfgAddIp(
- netapi_handle,
- ETH1,
- nwal_IPV4,
- &netTestCfg.ip[1].ipv4[0],
- NULL, //all IP
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,
- &err
- );
- if (err) {printf("add ip1 failed %d\n",err); exit(1); }
-
-#ifndef EXPERIMENTAL
- //attach 2 classifiers to iface 0, ip0
- class_0_cfg.u.c_l4.ip = ip_rule0;
- class_0 = netcp_cfgAddClass(netapi_handle,
- &class_0_cfg,
- NULL,
- NETCP_CFG_ACTION_TO_SW,
- &err);
- if (err) {printf("addclass0 failed %d\n",err); exit(1);}
-
- class_1_cfg.u.c_l4.ip = ip_rule0;
- class_1 = netcp_cfgAddClass(netapi_handle,
- &class_1_cfg,
- NULL,
- NETCP_CFG_ACTION_TO_SW,
- &err);
- if (err) {printf("addclass1 failed %d\n",err); exit(1);}
-
-
- //3rd classifier has a different IP and route
- class_2_cfg.u.c_l3_l4.ip_addr= &netTestCfg.ip[2].ipv4[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;
-#if 0
- specialFlow = netcp_cfgAddFlow( netapi_handle,
- 2,
- heaps,
- sizes,
- SPECIAL_SOP_OFF, //offset to start rx is 128
- &err);
- if (err) {printf("add flow failed\n", err); exit(1);}
-#endif
- }
-#if 0
-//special route for this classifier: different flow + destination q
-class2_route.p_dest_q = netcp_rx_chan2;
-class2_route.p_flow = specialFlow;
-class_2 = netcp_cfgAddClass(netapi_handle,
- &class_2_cfg,
- (void*) &class2_route,
- NETCP_CFG_ACTION_TO_SW,
- &err);
-if (err) {printf("addclass2 failed %d\n",err); exit(1);}
-#endif
-
-#endif
-//security stuff
+ /*create net_test MAC interfaces, attach IP to created MAC interfaces */
+ create_interfaces(&ip_rule0, &ip_rule1);
+
p_trie_sa_rx = trie_new();
p_trie_sa_tx = trie_new();
if (!p_trie_sa_rx || !p_trie_sa_tx)
- {printf("trie alloc for SA failed\n"); exit(1);}
+ {Debug_printf("trie alloc for SA failed\n"); exit(1);}
- for (i=0; i < MAX_SEC_INDEX;i++)
- {
- if(netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- build_sa_db(i);
- sa_info[i].rx_tunnel = netapi_secAddSA(
- netapi_handle,
- netTestCfg.ipsec_if_no, //iface #0
- &netTestCfg.sa_info[i],
- &netTestCfg.key_params[i],
- netTestCfg.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 (netTestCfg.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
- &netTestCfg.sa_info[i].src,
- &netTestCfg.sa_info[i].dst,
- 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;
- }
-
-#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
- /* Remember the NetCP Command Label so save cycles per Crypto
- * operation */
- if(netTestCfg.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
- {
- nwalRetVal =
- nwal_initDMPSCmdInfo(pktio_mGetNwalInstance(netcp_sb_rx_chan),
- sa_info[i].rx_data_mode_handle,
- &sa_info[i].rx_dmPSCmdInfo);
- }
-#endif
- }
-//tx SA security stuff
- //for (i=0; i < (MAX_SEC_INDEX+1);i++)
- if(netTestCfg.sa_info[i].dir == NWAL_SA_DIR_OUTBOUND)
- {
- build_sa_db(i);
- sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
- 0, //iface #0
- &netTestCfg.sa_info[i],
- &netTestCfg.key_params[i],
- netTestCfg.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);}
-
-#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
- /* Remember the NetCP Command Label so save cycles per Crypto
- * operation */
- if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
- {
- nwalRetVal =
- nwal_initDMPSCmdInfo(pktio_mGetNwalInstance(netcp_sb_tx_chan),
- sa_info[i].tx_data_mode_handle,
- &sa_info[i].tx_dmPSCmdInfo);
- }
-#endif
-
-#ifdef NET_TEST_ENABLE_INFLOW_LOW_LEVEL_API
- if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
- {
- memset(&nwalSaIpSecId, 0, sizeof(nwalSaIpSecId_t));
- nwalSaIpSecId.spi = netTestCfg.sa_info[i].spi;
- memcpy(&(nwalSaIpSecId.src), &netTestCfg.sa_info[i].src,sizeof( nwalIpAddr_t));
- memcpy(&(nwalSaIpSecId.dst), &netTestCfg.sa_info[i].dst,sizeof( nwalIpAddr_t));
- nwalSaIpSecId.proto = netTestCfg.sa_info[i].proto;
-
- nwalRetVal = nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
- &sa_info[i].tx_pkt_info,
- &sa_info[i].tx_psCmdInfo);
-
- if (nwalRetVal == nwal_OK)
- {
- if (nwal_getSecAssoc(pktio_mGetNwalInstance(netcp_tx_chan),
- &nwalSaIpSecId,
- NWAL_SA_DIR_OUTBOUND,
- &(sa_info[i].tx_inflow_mode_handle),
- &sa_info[i].swInfo0,
- &sa_info[i].swInfo1) != nwal_TRUE)
- {
- printf("main: nwal_getSecAssoc failed\n");
- exit (1);
- }
- }
- else
- {
- printf("main: nwal_initPSCmdInfo failed\n");
- exit (1);
- }
- }
-#endif
- }
- }
-#ifdef TEST_TIMERS
-//timers
-ourTimerBlock = hplib_Timer_CreateGroup(
- netapi_handle,
- "our1sttimer",
- our_timer_cb,
- 0, //1 if timers local to thread
- 0, //1 if expect to cancel
- hplib_getTicksPerSec()/1000, /* 1 msc resolution for these timers */
- hplib_getTicksPerSec()/5000, /* would like .5 msc tolerence */
- 10); //small # of timers to test garbage collection
-if (err) {printf("hplib_Timer_CreateGroup() failed %d\n",err); exit(1);}
-
-//start a couple of timers
-t1 = hplib_Timer_Start(
- ourTimerBlock,
- (void *) 1,
- 100LL, //timer group ticks
- &err);
-if (err) {printf("timerstart failed %d\n");}
-t2 = hplib_Timer_Start(
- ourTimerBlock,
- (void *) 2,
- 200LL, //timer group ticks
- &err);
-if (err) {printf("timerstart failed %d\n");}
-t3 = hplib_Timer_Start(
- ourTimerBlock,
- (void *) 3,
- 300LL, //timer group ticks
- &err);
-if (err) {printf("timerstart failed %d\n");}
-#endif
-#if 0
-netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
-if (err!=0) {printf("stats req failed\n");}
-#endif
-/*********************************************/
-/*****************end NETAPI STARTUP**********/
-/*********************************************/
-
-
-#if 0
-/********************************************
-* Basic pkt loopback test
-*********************************************/
-printf("...runnining pure push/pop benchmark\n");
-our_pktio_bench(100);
-#endif
-
-/**************unused stuff******************/
-#if 0
-/* create TRIE */
-P_trie = trie_new();
-if (!P_trie) {printf("trie alloc failed\n"); exit(1);}
-
-nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));
-if (!nat) {printf("malloc of nat table failed\n"); exit(1);}
-
-//gen_pkts(np2process<NP ? np2process:NP);
-n_pkt= np2process;
-
-/* build table */
-build_table(P_trie);
-
-
-/* processing loop: get pkt, check it, look up in table, copy new header,
- send packet */
-srand((unsigned) np2process);
-#endif
+ /* Create RX SA's, RX Policy and TX SA's */
+ create_sec_associations(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
#ifdef MULTI_THREAD
{
- CPU_ZERO( &cpu_set );
+ CPU_ZERO( &cpu_set );
pthread_t *thrs;
- int procs =2; //get this from config eventually
+ 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 );
+ Debug_printf( "Starting %d threads...\n", procs );
- if (pthread_create( &thrs[0], NULL, slow_path_thread,
+ if (pthread_create( &thrs[0], NULL, (void*)slow_path_thread,
(void *)0 ))
{
perror( "pthread_create" );
exit(1);
}
-#if 1
- if (pthread_create( &thrs[1], NULL, fast_path_thread,
+
+ if (pthread_create( &thrs[1], NULL, (void*)fast_path_thread,
(void *)1 ))
{
perror( "pthread_create" );
exit(1);
}
-#endif
//this thread of execution (main) now just waits on user input
for(;;)
{
- printf(">");
+ Debug_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");
+ else if (c=='h') Debug_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");
+ Debug_printf("main task now pending on slow/fast path completion\n");
for (i = 0; i < procs; i++)
pthread_join( thrs[i], NULL );
/**************Entry point into scheduler ****/
/*********************************************/
netapi_schedRun(our_sched, &err);
-
#endif
-/* done */
-our_stats_cb(netapi_handle, NULL);
+ /* done */
+ our_stats_cb(netapi_handle, NULL);
+
-#define DO_FAST_POLL
-#ifdef DO_FAST_POLL
-//example_fast_pushpop(ourHeap, 500);
-//example_fast_poll(netcp_rx_chan,20000);
-#endif
/*************************************************
************CLEAN UP****************************
************************************************/
+ delete_sec_associations();
-#ifndef EXPERIMENTAL
-//delete Classifiers
-netcp_cfgDelClass(netapi_handle, class_0, &err);
-netcp_cfgDelClass(netapi_handle, class_1, &err);
-//netcp_cfgDelClass(netapi_handle, class_2, &err);
-
-#if 0
-//delete flow
-netcp_cfgDelFlow(netapi_handle, specialFlow, &err);
-#endif
-#endif
- for (i=0; i < MAX_SEC_INDEX;i++)
- {
- if(sa_info[i].dir == NWAL_SA_DIR_INBOUND)
- {
- if (rx_policy[i])
- netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
- //delete tunnels
- netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
- }
-
- if(sa_info[i].dir == NWAL_SA_DIR_OUTBOUND)
- {
- netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
- }
- }
-//delete IPs and MAC Interfacess
-netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);
-netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);
-netcp_cfgDelMac(netapi_handle,0,&err);
-netcp_cfgDelMac(netapi_handle,1,&err);
-#ifdef PROMISCUOUS
-netcp_cfgDelMac(netapi_handle,2,&err);
-#endif
+ delete_interfaces( &ip_rule0, &ip_rule1);
-//close pktio channels we opened
-pktio_close(netcp_tx_chan ,&err);
-pktio_close(netcp_rx_chan ,&err);
-#ifndef EXPERIMENTAL
-pktio_close(netcp_sb_tx_chan ,&err);
-pktio_close(netcp_sb_rx_chan ,&err);
+ //close pktio channels we opened
+ pktio_close(netcp_tx_chan ,&err);
+ pktio_close(netcp_rx_chan ,&err);
+ pktio_close(netcp_sb_tx_chan ,&err);
+ 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);
+ //clear pktio channel we created
+ 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);
-#endif
-netapi_shutdown(netapi_handle);
-
-}
+ //delete pktio channels we created
+ pktio_delete(netcp_rx_chan2,&err);
+ netapi_shutdown(netapi_handle);
-//EXAMPLE FAST POLL
-/* PLD */
-void netapi_pld(void * x)
-{
- asm volatile("pld [r0]");
}
-#define M 1008
-static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], len[M] ;
-static nwal_AppId appid[M];
-static unsigned char * buf[M];
-#define N2POLL 8 //batch size
-#define NTOPOP 190
-Ti_Pkt * pHd[NTOPOP];
-void example_fast_pushpop(Pktlib_HeapHandle h , int n_trials)
+/* Stub functions */
+Trie * route_init(void)
{
-int i,j;
-unsigned long t1;
-unsigned long t2;
-unsigned long sumf=0;
-unsigned long sumt=0;
-unsigned long sump=0;
-#define NTOPOP 190
-Ti_Pkt * tempVA;
-Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
-
-//n_trials of NTOPOP actions
-for(i=0;i<n_trials;i++)
-{
- //raw pop
- t1= hplib_mUtilGetPmuCCNT();
- pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (freeQ));
- for(j=1;j<NTOPOP;j++)
- {
- tempVA = hplib_mVMPhyToVirt(pHd[j-1]);
- netapi_pld(tempVA);
- //__builtin_prefetch(tempVA);
- pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (freeQ));
- sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
- ((Cppi_HostDesc *) tempVA)->buffPtr);
- }
- tempVA = hplib_mVMPhyToVirt(pHd[j-1]);
- sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
- ((Cppi_HostDesc *) tempVA)->buffPtr);
- t2=hplib_mUtilGetPmuCCNT();
- sumt+= (t2-t1);
-
- //invalidate/wb
- for(j=0;j<NTOPOP;j++)
- {
- tempVA = hplib_mVMPhyToVirt(pHd[j]);
- hplib_cacheWbInv(tempVA,128);
- }
-
- //raw push
- t1=hplib_mUtilGetPmuCCNT();
- for(j=0;j<NTOPOP;j++)
- {
- pktio_mQmssQueuePushDescSizeRaw (freeQ,
- (void *) pHd[j],
- 128);
- }
- t2=hplib_mUtilGetPmuCCNT();
- sump += (t2-t1);
}
-printf("\nfast poppush: np=%d pop=%d push=%d sumf=%d\n", (n_trials*NTOPOP),
- sumt/(n_trials*NTOPOP), sump/(n_trials*NTOPOP), sumf);
-sleep(1);
-return;
-}
-
-
-
-void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts)
-{
-int j=0;
-int jj=0;
-int i,k,l=0,ltot=0;
-int n= N2POLL; //max # of pkts to poll
-Ti_Pkt * tempVA;
-pasahoLongInfo_t* pinfo;
-unsigned long t1;
-unsigned long t2;
-unsigned long t11;
-unsigned long t12;
-unsigned long np;
-unsigned long sumt=0;
-unsigned long sumf=0;
-unsigned long sump=0;
-unsigned long totlen=0;
-int max_batch=0;
-
-//this should be done once and saved
-Qmss_QueueHnd rxQ= pktio_mGetDefaultNetCpQ(p_pktio);
-Qmss_QueueHnd freeQ;
-//loop forever
-for(;max_pkts>0;)
+void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
{
- t1= hplib_mUtilGetPmuCCNT();
- pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (rxQ));
- if (!pHd[0]) continue;
- //got pkt
- for(i=1;(i<n) && (pHd[i-1]);i++)
- {
- //convert previous descriptor PA -> VA
- tempVA = hplib_mVMPhyToVirt(pHd[i-1]);
-
- //try and preload desriptor
- __builtin_prefetch(tempVA);
- //netapi_pld(tempVA);
-
- //read next descriptor from queue
- pHd[i] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (rxQ));
-#if 1
- /* extract some meta data */
- Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
- pinfo = nwal_mGetProtoInfo(tempVA);
- l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
- l4_off[jj]= nwal_mGetL4Offset(pinfo);
- if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
- {
- printf("ERROR!!!! AppID not available in incoming packet \n");
- }
-//#define VERIFY_SOP
-#ifdef VERIFY_SOP
- if (sump < 200) printf("..sop off=%d\n", (int) buf[jj]-
- (int) ((Cppi_HostDesc *) tempVA)->origBuffPtr) ;
-#endif
-#endif
- jj+=1;
- }
- //finish last pkt in burst
- if(pHd[i-1])
- {
- //convert previous descriptor PA -> VA
- tempVA = hplib_mVMPhyToVirt(pHd[i-1]);
-
- /* extract some meta data */
-#if 1
- pinfo = nwal_mGetProtoInfo(tempVA);
- l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
- l4_off[jj]= nwal_mGetL4Offset(pinfo);
- if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
- {
- printf("ERROR!!!! AppID not available in incoming packet \n");
- }
-#endif
- //get ptr (Physical address) and length of associate buffer
- Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
- jj+=1;
- }
- t2= hplib_mUtilGetPmuCCNT();
- j+=(pHd[i-1]? i: (i-1)) ;
- if (jj>(M-n)) jj=0;
- l+=1; //n batches
- ltot+=1;
- if(pHd[i-1])
- {
- if (i>max_batch) max_batch= i;
- }
- else
- {
- if( (i-1) >max_batch) max_batch = i-1;
- }
-
- //cleanup
- //printf("cleanup %d\n",i);
- for(k=0;k<i;k++)
- {
- //cleanup. need to covert all of desriptor to VA so that i can use freePacket()
- //alternative would be to just do cache ops plus descriptor raw push to pktlib
- // heap free queue
- if(pHd[k])
- {
-
- //tempVA=Qmss_osalConvertDescPhyToVirt(pHd[k]);
- tempVA = hplib_mVMPhyToVirt(pHd[k]);
- freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
- hplib_cacheWbInv(tempVA,128);
- //would need to wbInv buffer also in practice. Also need to walk
- // descriptor chain
- t11= hplib_mUtilGetPmuCCNT();
- // Pktlib_freePacket(tempVA);
- pktio_mQmssQueuePushDescSizeRaw (freeQ,
- (void *) pHd[k],
- 128);
-
- t12= hplib_mUtilGetPmuCCNT();
- sumf += (t12-t11);
- }
- }
- sumt += (t2-t1);
- sump +=(pHd[i-1]? i: (i-1));
- max_pkts -= (pHd[i-1]? i: (i-1));
-
- //printf("end cleanup %d %d %d\n",sumt,sumf,sump );
- if (sump > 10000) {
- printf("pkts rx %d batches=%d appid=%x l3_off=%d l4_off=%d len=%d buf=0x%x rxcycle= %d pkts/batchx1000=%d maxbatch=%d cycles per rawpush = %d\n",
- j,ltot, appid[j%M],
- l3_off[j%M],l4_off[j%M],
- len[j%M],buf[j%M],
- sumt/sump, (sump*1000)/l, max_batch,
- sumf/sump);
- sumt=sump=sumf=0;
- l=0;
- }
-}
-
- //cleanup any remaining buffers
- for(;;)
- {
- pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (rxQ));
- if(!pHd[0]) break;
- tempVA = Osal_qmssPhyToVirt(pHd[0]);
- freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
- hplib_cacheWbInv(tempVA,128);
- pktio_mQmssQueuePushDescSizeRaw (freeQ,
- (void *) pHd[0],
- 128);
- }
-}
-
-#ifdef EXPERIMENTAL
-
-static inline void send_it(Ti_Pkt *tip, int len, ROUTE_SEC_T * p_sec, int out_port)
-{
- unsigned long st1;
- unsigned long st2;
- int err=0;
- PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
- nwalTxPktInfo_t meta_tx2={0};
- st1=hplib_mUtilGetPmuCCNT();
-#ifdef MULTI_THREAD
- int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
-#else
- int coreid=0;
-#endif
- if (len<60)
- {
- unsigned int templen;
- char * p_pkt;
- len=60;
- Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
- Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
- stats[coreid].tx_min+=1;
- }
- Pktlib_setPacketLen(tip,len);
- meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
- meta_tx2.startOffset = 0;
- meta_tx2.ipOffBytes = 14;
- meta_tx2.ploadLen = len ;
- meta_tx2.enetPort=out_port;
- if(p_sec)
- {
- meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
- meta2.sa_handle=p_sec->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
- meta_tx2.saOffBytes=14+20;
- meta_tx2.saPayloadLen=len-14-20; //don't include tag, mac and outer header
- stats[coreid].sec_tx+=1;
- }
- meta2.u.tx_meta=&meta_tx2;
- pktio_send(netcp_tx_chan,tip,&meta2,&err);
- stats[coreid].tx +=1;
- st2=hplib_mUtilGetPmuCCNT();
- stats[coreid].send_cycles += (unsigned long long) (st2-st1);
-}
-void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
- PKTIO_METADATA_T meta[], int n_pkts,
- uint64_t ts )
-{
-int i;
-int len;
-int p;
-Ti_Pkt * tip;
-unsigned int templen;
-char * p_pkt;
-HEAD_T temp_head;
-unsigned int appid;
-IP_HEAD_T th;
-ROUTE_SEC_T *sec_data=NULL;
-unsigned long t1;
-unsigned long t2;
-unsigned long long ct1;
-unsigned long long ct2;
-unsigned short ip_pl;
-unsigned long long n_c_ops;
-int ifno;
-int out_port;
-#ifdef MULTI_THREAD
- int coreid=Osal_nwalGetProcId(); //who we are(thread local)
- //int coreid = our_core;
-#else
-int coreid=0;
-#endif
-t1=hplib_mUtilGetPmuCCNT();
-ct1 =Osal_cache_op_measure(&n_c_ops);
-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
- len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
- stats[coreid].rx+=1;
- appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
- switch(appid)
- {
- case(NETAPI_NETCP_MATCH_IPSEC):
- case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
- {
- int tailen=12+2;
- memcpy(&temp_head,&p_pkt[14],sizeof(HEAD_T));
- if (!check_header(&temp_head,&meta[i])) {
- stats[coreid].n_bad+=1;
- Pktlib_freePacket(tip);
- continue;
- }
- tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
- p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
- len -= (8+16+20+tailen); //16= iv len should come from sec ptr
-
- //now check inner headder.
- memcpy(&th,&p_pkt[14],20);
- if (!check_header(&temp_head,&meta[i])) {
- stats[coreid].n_bad+=1;
- Pktlib_freePacket(tip);
- continue;
- }
- Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
- Pktlib_setPacketLen(tip,len);
-
- if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
- {
- stats[coreid].n_bad+=1;
- Pktlib_freePacket(tip);
- }
- else
- {
- send_it(tip,len,sec_data,out_port);
- }
- break;
- }
- case(NETAPI_NETCP_MATCH_GENERIC_MAC):
- if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
- {
- stats[coreid].n_new+=1;
- Pktlib_freePacket(tip);
- continue;
- }
- if (!check_header(&temp_head,&meta[i]))
- {
- stats[coreid].n_bad+=1;
- Pktlib_freePacket(tip);
- continue;
- }
- memcpy(&th,&p_pkt[14],20);
- ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
- if ((ip_pl+14)<60)
- {
- len-= (60-(ip_pl+14));
- stats[coreid].rx_min+=1;
- }
- Pktlib_setPacketLen(tip,len);
- if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
- {
- stats[coreid].n_bad+=1;
- Pktlib_freePacket(tip);
- }
- else
- {
- send_it(tip,len,sec_data,out_port);
- }
- break;
- case(NETAPI_NETCP_MATCH_GENERIC_IP):
- Pktlib_freePacket(tip);
- stats[coreid].n_new=1;
- break;
- default:
- stats[coreid].n_new+=1;
- Pktlib_freePacket(tip);
- break;
- }
}
-t2=hplib_mUtilGetPmuCCNT();
-ct2 =Osal_cache_op_measure(&n_c_ops);
-stats[coreid].app_cycles += (unsigned long long) (t2-t1);
-stats[coreid].tx_cache_cycles += (unsigned long long) (ct2-ct1);
-return;
-}
-#endif
index 102f63128fa1fe353387e79edb1cfc749f1f8c0b..e504c99199c0db2d47acc18e8b5ad5ccb6d5a4c8 100755 (executable)
#define MULTI_THREAD
-//#define EXPERIMENTAL
+#define EXPERIMENTAL
#include "netapi.h"
ROUTE_SEC_T * sec_ptr;
} OUR_ROUTE_T;
-
-
+#ifdef MULTI_THREAD
+void slow_path_thread(int coreid);
+void fast_path_thread(int coreid);
+#endif
#endif
diff --git a/ti/runtime/netapi/test/net_test_config.txt b/ti/runtime/netapi/test/net_test_config.txt
index 6e89ff593f35208c493d783f2ee6aa201cd964d5..e6610e42f6635f375767cac816be49fb201821be 100644 (file)
-mac0 = 00-01-02-03-05-05 0
-mac1 = 00-01-02-03-05-06 1
-ip0 = 10.0.0.100
-ip1 = 10.0.1.100
-ip2 = 10.0.2.100
+#mac0 = mac-address switch-port
+mac0 = 00-01-02-03-05-05 sp0
+mac1 = 00-01-02-03-05-06 sp1
+#ip0 = ip-address mac-interface
+ip0 = 10.0.0.100 mac0
+ip1 = 10.0.1.100 mac0
+ip2 = 10.0.2.100 mac0
local_ipsec_ip = 192.168.1.100
remote_ipsec_ip = 192.168.1.10
ipsec_if = 0
#ipsec_mode_tx = SIDEBAND
ipsec_mode_rx = INFLOW
ipsec_mode_tx = INFLOW
-route0 = MAC00-23-24-08-67-46 1
-route1 = MAC00-22-33-44-55-56 2
+route0 = MAC00-23-24-08-67-46 0
+route1 = MAC00-22-33-44-55-56 1
dstip0 = 10.1.0.100 route1
dspip1 = 10.0.0.10 route0
diff --git a/ti/runtime/netapi/test/net_test_router.c b/ti/runtime/netapi/test/net_test_router.c
--- /dev/null
@@ -0,0 +1,630 @@
+/******************************************
+ * 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.
+
+ *****************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include "net_test.h"
+#include "trie.h"
+#include "string.h"
+
+#include <sys/resource.h>
+
+#include <ti/drv/sa/salld.h>
+#include <ti/drv/pa/pa.h>
+
+#include "net_test_util.h"
+
+extern int QUIT;
+
+/* Global definitions */
+#ifdef MULTI_THREAD
+ cpu_set_t cpu_set;
+#endif
+
+netTestConfig_t netTestCfg;
+static netTestConfigFile_t config_file;
+
+char input_file_name[] = "net_test_config.txt";
+
+nwal_RetValue nwalRetVal;
+Pktlib_HeapHandle ourHeap;
+Pktlib_HeapHandle specialSmall;
+Pktlib_HeapHandle specialLarge;
+
+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_RX_TX, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
+
+NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
+static hplib_spinLock_T stats_lock;
+
+Trie * P_trie;
+Trie *p_trie_sa_rx;
+Trie *p_trie_sa_tx;
+
+
+#include "router.c"
+extern Trie * our_router;
+extern OUR_ROUTE_T routes[];
+
+unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
+
+void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T meta[], int n_pkts,
+ uint64_t ts );
+
+
+extern STATS_T stats[TUNE_NETAPI_NUM_CORES];
+extern paSysStats_t netcp_stats;
+
+/*******************************************
+ *************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
+};
+
+
+
+void house(NETAPI_SCHED_HANDLE_T *s);
+NETAPI_T netapi_handle;
+NETAPI_SCHED_HANDLE_T * our_sched;
+#ifdef MULTI_THREAD
+NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
+#endif
+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;
+NETCP_CFG_IP_T ip_rule1;
+
+PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
+
+/* security objects. (for loopback mode) */
+netTestSA_t sa_info[MAX_SEC_INDEX];
+
+
+NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
+
+
+
+
+/*************************END NETAPI OBJECTS***********************/
+
+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;
+}
+
+#ifdef MULTI_THREAD
+NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
+void slow_path_thread(int coreid)
+{
+ int err;
+ PKTIO_HANDLE_T *rx_chan;
+ PKTIO_HANDLE_T *tx_chan;
+ PKTIO_HANDLE_T *sb_tx_chan;
+ PKTIO_HANDLE_T *sb_rx_chan;
+
+
+
+ Debug_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);
+
+ rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
+
+
+
+ netapi_setCookie(worker_nh[coreid],(void*)coreid);
+
+ scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
+ if (!scheduler[coreid])
+ {
+ Debug_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_schedRun(scheduler[coreid], &err);
+ Debug_printf(">net_test: core %d worker thread done\n",coreid);
+
+ pktio_close(tx_chan, &err);
+ pktio_close(rx_chan, &err);
+ netapi_shutdown(worker_nh[coreid]);
+}
+
+void fast_path_thread(int coreid)
+{
+ int err;
+ PKTIO_HANDLE_T *rx_chan;
+ PKTIO_HANDLE_T *tx_chan;
+ PKTIO_HANDLE_T *sb_tx_chan;
+ PKTIO_HANDLE_T *sb_rx_chan;
+
+#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);
+
+
+ rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
+ netapi_setCookie(worker_nh[coreid],(void*)coreid);
+
+ scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
+ if (!scheduler[coreid])
+ {
+ Debug_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);
+ netapi_schedRun(scheduler[coreid], &err);
+ Debug_printf(">net_test: core %d worker thread done\n",coreid);
+ pktio_close(tx_chan, &err);
+ pktio_close(rx_chan, &err);
+ netapi_shutdown(worker_nh[coreid]);
+\r}
+
+#endif
+
+/***************************************
+ ********** test driver*****************
+ ***************************************/
+int main(int argc, char **argv)
+{
+ int err,i;
+ Pktlib_HeapCfg heapCfg;
+ rlim_t oss,ss = 1024*1024;
+ struct rlimit rl;
+ int32_t errCode;
+ Pktlib_HeapIfTable* pPktifTable;
+/* Local Per Process default resourcese maintained at NWAL */
+ nwalLocCxtInfo_t nwalLocCxt;
+
+ FILE * fpr = NULL;
+
+
+ err= getrlimit(RLIMIT_STACK,&rl);
+ if (!err) Debug_printf(" stack limit = %d\n",rl.rlim_cur); else Debug_printf("getrlimit failed\n");
+
+ /* install signal handler for ^c */
+ signal(SIGINT,mysig);
+
+ fpr = fopen(input_file_name, "r");
+ if (fpr == NULL)
+ {
+ Debug_printf("Error in opening %s input file\n", input_file_name);
+ exit(1);
+ }
+ else
+ {
+ memset(&config_file, 0, sizeof(netTestConfigFile_t));
+ memset(&netTestCfg, 0, sizeof(netTestConfig_t));
+ parse_config_file(fpr,&config_file);
+ }
+
+ memset(&sa_info, 0, sizeof(sa_info));
+
+#ifdef MULTI_THREAD
+ /* assign main net_test thread to run on core 0 */
+ CPU_ZERO( &cpu_set);
+ CPU_SET( 0, &cpu_set);
+ hplib_utilSetupCore(0, &cpu_set);
+#endif
+ /* create netapi */
+ netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
+
+ netcp_cfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
+ expPkt_appid = netcp_cfgExceptions(netapi_handle, 7, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
+
+ /* open the main heap */
+ ourHeap = Pktlib_findHeapByName("netapi");
+ if (!ourHeap)
+ {
+ Debug_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);
+
+ /* open netcp default tx, rx queues */
+ netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
+ if (!netcp_tx_chan)
+ {
+ Debug_printf("pktio open TX failed err=%d\n",err);
+ exit(1);
+ }
+ netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
+ if (!netcp_rx_chan)
+ {
+ Debug_printf("pktio open RX failed err=%d\n",err);
+ exit(1);
+ }
+
+ Debug_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) {Debug_printf("sched create failed\n"); exit(1);}
+
+
+ /*create net_test MAC interfaces, attach IP to created MAC interfaces */
+ create_interfaces(&ip_rule0, &ip_rule1);
+
+ p_trie_sa_rx = trie_new();
+ p_trie_sa_tx = trie_new();
+ if (!p_trie_sa_rx || !p_trie_sa_tx)
+ {Debug_printf("trie alloc for SA failed\n"); exit(1);}
+
+ /* Create RX SA's, RX Policy and TX SA's */
+ create_sec_associations(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
+
+
+#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;
+ }
+ Debug_printf( "Starting %d threads...\n", procs );
+
+ if (pthread_create( &thrs[0], NULL, (void*)slow_path_thread,
+ (void *)0 ))
+ {
+ perror( "pthread_create" );
+ exit(1);
+ }
+#if 1
+ if (pthread_create( &thrs[1], NULL, (void*)fast_path_thread,
+ (void *)1 ))
+ {
+ perror( "pthread_create" );
+ exit(1);
+ }
+#endif
+ //this thread of execution (main) now just waits on user input
+ for(;;)
+ {
+ Debug_printf(">");
+ c=getchar();
+ if (c=='q') {QUIT=1;break;}
+ else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
+ else if (c=='h') Debug_printf("'q' to quit, 's' for stats, 'h' for help\n");
+ }
+
+ //wait for completion
+ Debug_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_schedRun(our_sched, &err);
+
+#endif
+
+/* done */
+our_stats_cb(netapi_handle, NULL);
+
+
+
+/*************************************************
+ ************CLEAN UP****************************
+ ************************************************/
+
+
+ delete_sec_associations();
+ delete_interfaces( &ip_rule0, &ip_rule1);
+
+//close pktio channels we opened
+pktio_close(netcp_tx_chan ,&err);
+pktio_close(netcp_rx_chan ,&err);
+netapi_shutdown(netapi_handle);
+}
+
+static inline void send_it(Ti_Pkt *tip, int len, ROUTE_SEC_T * p_sec, int out_port)
+{
+ unsigned long st1;
+ unsigned long st2;
+ int err=0;
+ PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
+ nwalTxPktInfo_t meta_tx2={0};
+ st1=hplib_mUtilGetPmuCCNT();
+#ifdef MULTI_THREAD
+ int coreid=Osal_nwalGetProcId(); //who we are(thread local)
+ //int coreid = our_core;
+#else
+ int coreid=0;
+#endif
+ if (len<60)
+ {
+ unsigned int templen;
+ char * p_pkt;
+ len=60;
+ Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
+ Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
+ stats[coreid].tx_min+=1;
+ }
+ Pktlib_setPacketLen(tip,len);
+ meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
+ meta_tx2.startOffset = 0;
+ meta_tx2.ipOffBytes = 14;
+ meta_tx2.ploadLen = len ;
+ meta_tx2.enetPort=out_port;
+ if(p_sec)
+ {
+ meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
+ meta2.sa_handle=p_sec->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
+ meta_tx2.saOffBytes=14+20;
+ meta_tx2.saPayloadLen=len-14-20; //don't include tag, mac and outer header
+ stats[coreid].sec_tx+=1;
+ }
+ meta2.u.tx_meta=&meta_tx2;
+ pktio_send(netcp_tx_chan,tip,&meta2,&err);
+ stats[coreid].tx +=1;
+ st2=hplib_mUtilGetPmuCCNT();
+ stats[coreid].send_cycles += (unsigned long long) (st2-st1);
+}
+void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T meta[], int n_pkts,
+ uint64_t ts )
+{
+ int i;
+ int len;
+ int p;
+ Ti_Pkt * tip;
+ unsigned int templen;
+ char * p_pkt;
+ HEAD_T temp_head;
+ unsigned int appid;
+ IP_HEAD_T th;
+ ROUTE_SEC_T *sec_data=NULL;
+ unsigned long t1;
+ unsigned long t2;
+ unsigned long long ct1;
+ unsigned long long ct2;
+ unsigned short ip_pl;
+ unsigned long long n_c_ops;
+ int ifno;
+ int out_port;
+#ifdef MULTI_THREAD
+ int coreid=Osal_nwalGetProcId(); //who we are(thread local)
+ //int coreid = our_core;
+#else
+ int coreid=0;
+#endif
+ t1=hplib_mUtilGetPmuCCNT();
+ ct1 =Osal_cache_op_measure(&n_c_ops);
+ 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
+ len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
+ stats[coreid].rx+=1;
+ appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
+ switch(appid)
+ {
+ case(NETAPI_NETCP_MATCH_IPSEC):
+ case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
+ {
+ int tailen=12+2;
+ memcpy(&temp_head,&p_pkt[14],sizeof(HEAD_T));
+ if (!check_header(&temp_head,&meta[i])) {
+ stats[coreid].n_bad+=1;
+ Pktlib_freePacket(tip);
+ continue;
+ }
+ tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
+ p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
+ len -= (8+16+20+tailen); //16= iv len should come from sec ptr
+
+ //now check inner headder.
+ memcpy(&th,&p_pkt[14],20);
+ if (!check_header(&temp_head,&meta[i])) {
+ stats[coreid].n_bad+=1;
+ Pktlib_freePacket(tip);
+ continue;
+ }
+ Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
+ Pktlib_setPacketLen(tip,len);
+
+ if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
+ {
+ stats[coreid].n_bad+=1;
+ Pktlib_freePacket(tip);
+ }
+ else
+ {
+ send_it(tip,len,sec_data,out_port);
+ }
+ break;
+ }
+ case(NETAPI_NETCP_MATCH_GENERIC_MAC):
+ if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
+ {
+ stats[coreid].n_new+=1;
+ Pktlib_freePacket(tip);
+ continue;
+ }
+ if (!check_header(&temp_head,&meta[i]))
+ {
+ stats[coreid].n_bad+=1;
+ Pktlib_freePacket(tip);
+ continue;
+ }
+ memcpy(&th,&p_pkt[14],20);
+ ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
+ if ((ip_pl+14)<60)
+ {
+ len-= (60-(ip_pl+14));
+ stats[coreid].rx_min+=1;
+ }
+ Pktlib_setPacketLen(tip,len);
+ if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
+ {
+ stats[coreid].n_bad+=1;
+ Pktlib_freePacket(tip);
+ }
+ else
+ {
+ send_it(tip,len,sec_data,out_port);
+ }
+ break;
+ case(NETAPI_NETCP_MATCH_GENERIC_IP):
+ Pktlib_freePacket(tip);
+ stats[coreid].n_new=1;
+ break;
+ default:
+ stats[coreid].n_new+=1;
+ Pktlib_freePacket(tip);
+ break;
+ }
+}
+t2=hplib_mUtilGetPmuCCNT();
+ct2 =Osal_cache_op_measure(&n_c_ops);
+stats[coreid].app_cycles += (unsigned long long) (t2-t1);
+stats[coreid].tx_cache_cycles += (unsigned long long) (ct2-ct1);
+return;
+}
+
+
+
diff --git a/ti/runtime/netapi/test/net_test_sa_utils.c b/ti/runtime/netapi/test/net_test_sa_utils.c
--- /dev/null
@@ -0,0 +1,712 @@
+/******************************************
+ * 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.
+
+ *****************************************/
+
+#include "net_test_util.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <pthread.h>
+#include "trie.h"
+#include "router.h"
+
+#include <ti/drv/sa/salld.h>
+#include <ti/drv/pa/pa.h>
+
+extern NETAPI_T netapi_handle;
+extern netTestConfig_t netTestCfg;
+extern netTestConfig_t config;
+extern netTestSA_t sa_info[];
+extern NETCP_CFG_IPSEC_POLICY_T rx_policy[];
+
+//extern NETAPI_SCHED_HANDLE_T * scheduler[];
+//extern Pktlib_HeapHandle ourHeap;
+//extern Pktlib_HeapHandle specialSmall;
+//extern Pktlib_HeapHandle specialLarge;
+
+extern Trie *p_trie_sa_rx;
+extern Trie *p_trie_sa_tx;
+
+
+
+void build_sa_db(int i)
+{
+ long tmp_spi;
+ long tmp_tunnel;
+ if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA1) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CBC))
+ {
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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].iv_len=16;
+ sa_info[i].bl=16;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ 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 ;
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA2_256) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CTR))
+ {
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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].iv_len=8;
+ sa_info[i].bl=8;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ 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].key_params = &netTestCfg.key_params[i];
+
+ 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 ;
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_SHA2_256) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
+ {
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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].iv_len=8;
+ sa_info[i].bl=8;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ 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 ;
+
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_HMAC_MD5) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
+ {
+ /* 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 + 24; /*done: same for all cipher suites */
+ sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN;
+
+ sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
+ netTest_IP_HEADER_LEN +
+ netTest_NULL_ESP_HEADER_LEN +
+ netTest_NULL_IV_LEN +
+ 24;
+ sa_info[i].iv_len=0;
+ sa_info[i].bl=4;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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;
+ 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_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID ;
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_NULL) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_GCM))
+ {
+ /* 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;
+
+ sa_info[i].iv_len=0;
+ sa_info[i].bl=4;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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 ;
+
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_NULL) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_AES_CCM))
+ {
+ /* 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;
+
+ sa_info[i].iv_len=0;
+ sa_info[i].bl=4;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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 ;
+
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_AES_XCBC) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
+ {
+ /* 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;
+
+ sa_info[i].iv_len=0;
+ sa_info[i].bl=4;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ /* 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 = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ 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 ;
+
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else if ((netTestCfg.sa_info[i].authMode== NWAL_SA_AALG_GMAC) && (netTestCfg.sa_info[i].cipherMode == NWAL_SA_EALG_NULL))
+ {
+ /* 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_AES_GMAC_IV_LEN;
+
+ sa_info[i].iv_len=0;
+ sa_info[i].bl=4;
+ sa_info[i].src = *((unsigned int *)(&netTestCfg.sa_info[i].src));
+ sa_info[i].dst =*((unsigned int *)(&netTestCfg.sa_info[i].dst));
+
+ /* 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.pAuthIV = 0;
+ sa_info[i].tx_payload_info.pPkt = 0;
+
+ sa_info[i].cipherMode = netTestCfg.sa_info[i].cipherMode;
+ sa_info[i].authMode = netTestCfg.sa_info[i].authMode;
+ sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
+ sa_info[i].auth_tag_size = netTest_AES_GMAC_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 ;
+
+ sa_info[i].dir =netTestCfg.sa_info[i].dir;
+ tmp_spi = htonl((long)(netTestCfg.sa_info[i].spi));
+ tmp_tunnel = htonl((long)(netTestCfg.tunnel_id[i]));
+ sa_info[i].spi =tmp_spi;
+ sa_info[i].tunnel_id = tmp_tunnel;
+
+ if (netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ trie_insert(p_trie_sa_rx,(char *)&tmp_spi,4, (void *) &sa_info[i]);
+ }
+ else
+ {
+ trie_insert(p_trie_sa_tx,(char *)&tmp_tunnel,4, (void *) &sa_info[i]);
+ printf("**************************build_sa_db: tunnel id %d\n", tmp_tunnel);
+ }
+ }
+ else
+ printf("build_sa_db(): invalid encryption/authentication combination selected\n");
+
+ //printf("sa_build_db(): authOffset %d, innerIpOffset %d, encOffset %d\n", sa_info[i].tx_payload_info.authOffset, sa_info[i].inner_ip_offset, sa_info[i].tx_payload_info.encOffset);
+
+
+}
+int create_sec_associations(PKTIO_HANDLE_T* netcp_sb_rx_chan,
+ PKTIO_HANDLE_T* netcp_sb_tx_chan,
+ PKTIO_HANDLE_T *netcp_tx_chan)
+{
+ nwal_RetValue nwalRetVal;
+ int err,i;
+ nwalSaIpSecId_t nwalSaIpSecId;
+ for (i=0; i < MAX_SEC_INDEX;i++)
+ {
+ err = 0;
+ if(netTestCfg.sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ build_sa_db(i);
+ sa_info[i].rx_tunnel = netapi_secAddSA(
+ netapi_handle,
+ netTestCfg.ipsec_if_no, //iface #0
+ &netTestCfg.sa_info[i],
+ &netTestCfg.key_params[i],
+ netTestCfg.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 (netTestCfg.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
+ &netTestCfg.sa_info[i].src,
+ &netTestCfg.sa_info[i].dst,
+ NULL, // no qualifiers
+ NULL, //default route
+ &err);
+ if (err)
+ {
+ printf("addSaPolicy failed %d, for index %d\n",err,i);
+ exit(1);
+ }
+ else
+ printf("addSA policy pass for %d\n", i);
+ }
+ else
+ {
+ rx_policy[i] = 0;
+ }
+
+#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
+ /* Remember the NetCP Command Label so save cycles per Crypto
+ * operation */
+ if(netTestCfg.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
+ {
+ nwalRetVal =
+ nwal_initDMPSCmdInfo(pktio_mGetNwalInstance(netcp_sb_rx_chan),
+ sa_info[i].rx_data_mode_handle,
+ &sa_info[i].rx_dmPSCmdInfo);
+ }
+#endif
+ }
+ //tx SA security stuff
+ if(netTestCfg.sa_info[i].dir == NWAL_SA_DIR_OUTBOUND)
+ {
+ build_sa_db(i);
+ sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
+ 0, //iface #0
+ &netTestCfg.sa_info[i],
+ &netTestCfg.key_params[i],
+ netTestCfg.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);}
+
+#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
+ /* Remember the NetCP Command Label so save cycles per Crypto
+ * operation */
+ if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
+ {
+ nwalRetVal =
+ nwal_initDMPSCmdInfo(pktio_mGetNwalInstance(netcp_sb_tx_chan),
+ sa_info[i].tx_data_mode_handle,
+ &sa_info[i].tx_dmPSCmdInfo);
+ }
+#endif
+
+#ifdef NET_TEST_ENABLE_INFLOW_LOW_LEVEL_API
+ if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
+ {
+ memset(&nwalSaIpSecId, 0, sizeof(nwalSaIpSecId_t));
+ nwalSaIpSecId.spi = netTestCfg.sa_info[i].spi;
+ memcpy(&(nwalSaIpSecId.src), &netTestCfg.sa_info[i].src,sizeof( nwalIpAddr_t));
+ memcpy(&(nwalSaIpSecId.dst), &netTestCfg.sa_info[i].dst,sizeof( nwalIpAddr_t));
+ nwalSaIpSecId.proto = netTestCfg.sa_info[i].proto;
+
+ nwalRetVal = nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
+ &sa_info[i].tx_pkt_info,
+ &sa_info[i].tx_psCmdInfo);
+
+ if (nwalRetVal == nwal_OK)
+ {
+ if (nwal_getSecAssoc(pktio_mGetNwalInstance(netcp_tx_chan),
+ &nwalSaIpSecId,
+ NWAL_SA_DIR_OUTBOUND,
+ &(sa_info[i].tx_inflow_mode_handle),
+ &sa_info[i].swInfo0,
+ &sa_info[i].swInfo1) != nwal_TRUE)
+ {
+ printf("main: nwal_getSecAssoc failed\n");
+ exit (1);
+ }
+ }
+ else
+ {
+ printf("main: nwal_initPSCmdInfo failed\n");
+ exit (1);
+ }
+ }
+#endif
+ }
+ }
+}
+
+
+void delete_sec_associations()
+{
+ int err,i;
+ for (i=0; i < MAX_SEC_INDEX;i++)
+ {
+ err = 0;
+ if(sa_info[i].dir == NWAL_SA_DIR_INBOUND)
+ {
+ if (rx_policy[i])
+ netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
+ if (err == 0) printf("polcicy deleted %d\n", i );
+ //delete tunnels
+ netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
+ }
+
+ if(sa_info[i].dir == NWAL_SA_DIR_OUTBOUND)
+ {
+ netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ti/runtime/netapi/test/net_test_sa_utils.h b/ti/runtime/netapi/test/net_test_sa_utils.h
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __NET_TEST_UTIL_H__
+#define __NET_TEST_UTIL_H__
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+
+#include "net_test.h"
+
+void build_sa_db(int i);
+int create_sec_associations(PKTIO_HANDLE_T* netcp_sb_rx_chan,
+ PKTIO_HANDLE_T* netcp_sb_tx_chan,
+ PKTIO_HANDLE_T *netcp_tx_chan);
+
+void void delete_sec_associations(void);
+
+#endif
index 5d3aaa41077cee7b87d44aaabb60e6f14d5ce0f1..92fac7eaecc3f4ae5e8897d0c74a7244358c39c7 100755 (executable)
#include <signal.h>
#include <pthread.h>
#include "trie.h"
+#include "router.h"
#include <ti/drv/sa/salld.h>
#include <ti/drv/pa/pa.h>
-
+extern NETAPI_T netapi_handle;
extern netTestConfig_t netTestCfg;
extern netTestConfig_t config;
extern netTestSA_t sa_info[];
-extern Trie * our_router;
-#ifdef EXPERIMENTAL
-extern OUR_ROUTE_T routes[];
+extern NETAPI_SCHED_HANDLE_T * scheduler[];
+extern Pktlib_HeapHandle ourHeap;
+extern Pktlib_HeapHandle specialSmall;
+extern Pktlib_HeapHandle specialLarge;
+extern NETCP_CFG_IP_T ip_rule0;
+extern NETCP_CFG_IP_T ip_rule1;
+
+Trie * our_router;
+STATS_T stats[TUNE_NETAPI_NUM_CORES];
+paSysStats_t netcp_stats;
+
+//#include "router.c"
+
+
+
+
+OUR_ROUTE_T routes[MAX_ROUTES]=
+{
+{0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
+{0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
+{0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
+{0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
+{0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
+
+static struct LastPktInfo lpInfo;
+int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
+{
+#ifdef MULTI_THREAD
+ int coreid=Osal_nwalGetProcId(); //who we are(thread local)
+ //int coreid = our_core;
+#else
+ int coreid=0;
#endif
+if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
+{
+ lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
+ lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
+ lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MASK )== ((NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_ACK) << NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_SHIFT) ? 1 : 0;
+ if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
+ {
+ stats[coreid].sec_rx++;
+ }
+ if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
+ {
+ stats[coreid].secp_rx++;
+ }
+
+ if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
+ {
+ int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
+ if (c==0) stats[coreid].n_class0_rx +=1;
+ else if (c==1) stats[coreid].n_class1_rx +=1;
+ else if (c==2) stats[coreid].n_class2_rx +=1;
+ else Debug_printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
+}
+}
+
+ return 1;
+}
+
static int scnt=0;
int QUIT;
#define CHECK_SET_PARAM(ARG1, ARG2) \
do { \
if(strcmp(key, ARG1) == 0) { \
- if(data)strncpy(ARG2,data,CONFIG_STRING_LEN); \
- printf("CHECK_SET_PARM, match found, input cong string %s\n", ARG2); \
+ if(d1)strncpy(ARG2,d1,CONFIG_STRING_LEN); \
continue; \
} \
} while(0)
#define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
do { \
if(strcmp(key, ARG1) == 0) { \
- if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
- if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
- printf("CHECK_SET_PARM2, match found, input cong string %s %s\n", ARG2, ARG3); \
+ if(d1) strncpy(ARG2,d1,CONFIG_STRING_LEN); \
+ if(d2) strncpy(ARG3,d2,CONFIG_STRING_LEN); \
continue; \
} \
} while(0)
ARG6, ARG7, ARG8, ARG9, ARG10, \
ARG11, ARG12,ARG13, ARG14, ARG15, ARG16,ARG17, ARG18) \
do { \
- if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
- if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
+ if(d1) strncpy(ARG2,d1,CONFIG_STRING_LEN); \
+ if(d2) strncpy(ARG3,d2,CONFIG_STRING_LEN); \
if(d3) strncpy(ARG4,d3,CONFIG_STRING_LEN); \
if(d4) strncpy(ARG5,d4,CONFIG_STRING_LEN); \
if(d5) strncpy(ARG6, d5,CONFIG_STRING_LEN); \
if(d15) strncpy(ARG16,d15,CONFIG_STRING_LEN); \
if(d16) strncpy(ARG17,d16,CONFIG_STRING_LEN); \
if(d17) strncpy(ARG18,d17,CONFIG_STRING_LEN); \
- printf("CHECK_SET_PARMSA, match found, input cong string %s %s %s %s\n", ARG2, ARG3, ARG4, ARG5); \
- printf("CHECK_SET_PARMSA, match found, input cong string %s %s %s %s\n", ARG6, ARG7, ARG8, ARG9); \
- printf("CHECK_SET_PARMSA, match found, input cong string %s %s %s %s\n", ARG10, ARG11, ARG12, ARG13); \
- printf("CHECK_SET_PARMSA, match found, input cong string %s %s\n", ARG14, ARG15); \
- printf("CHECK_SET_PARMSA, match found, encrykey: %s\n", ARG16); \
- printf("CHECK_SET_PARMSA, match found, authkey :%s\n", ARG17); \
- printf("CHECK_SET_PARMSA, match found, tunnel_id :%s\n", ARG18); \
continue; \
} while(0)
+void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
+{
+#if 0
+ if(retVal != nwal_OK)
+ {
+ System_System_Debug_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
+ retVal);
+ return(nwal_FALSE);
+ }
+ if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
+ {
+ Debug_printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
+ }
+ else
+ {
+ printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
+ }
+#endif
+ printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
+ printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
+ p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
+ printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
+ p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
+ p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
+}
+
+void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
+{
+
+ printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
+ printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
+ p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
+}
+
+/******************************************************
+ * stats callback
+ *******************************************************/
+void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
+{
+
+#ifdef MULTI_THREAD
+ int coreid=Osal_nwalGetProcId(); //who we are(thread local)
+ //int coreid = our_core;
+#else
+int coreid=0;
+#endif
+
+ stats[coreid].n_stats_cb +=1;
+ if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
+}
+void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
+{
+uint32_t numFreeDataPackets;
+uint32_t numZeroBufferPackets;
+uint32_t numPacketsinGarbage;
+Pktlib_HeapStats pktLibHeapStats;
+int i;
+unsigned long long bcpp;
+unsigned long long bcpp_noc;
+unsigned long long bcpp_app;
+unsigned long long bcpp_tx;
+unsigned long long npL;
+unsigned long long cyclesL;
+unsigned long long ccyclesL; //cache cycles
+unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
+unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
+unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
+NETAPI_SA_STATS_T netapi_sa_stats;
+
+ for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
+ {
+ printf("Per Core Statistics for CORE %d\n", i);
+ printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
+ printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%dsecRx=%d\t"
+ "secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d sec_tx=%d min_rx=%d min_tx=%d fragPkt=%d, exceptionPktOther=%d\n",
+ stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new,
+ stats[i].n_class0_rx, stats[i].n_class1_rx, stats[i].n_class2_rx, stats[i].sec_rx,
+ stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
+ stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min, stats[i].exceptionPktsFrag, stats[i].exceptionPktsOther);
+ printf(">if rx stats: %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
+ printf(">core rx stats: %d \n",stats[i].core_rx);
+
+ if (stats[i].rx && stats[i].tx)
+ printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
+ (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
+
+
+ if (npL && stats[i].rx)
+ {
+ bcpp = cyclesL/npL;
+ bcpp_noc = (cyclesL-ccyclesL)/npL;
+ bcpp_app = (stats[i].app_cycles-stats[i].tx_cache_cycles)/stats[i].rx;
+ }
+ else
+ {
+ bcpp = bcpp_noc=bcpp_app=0L;
+ }
+ if (stats[i].tx)
+ {
+ bcpp_tx = (stats[i].send_cycles-stats[i].tx_cache_cycles)/stats[i].tx;
+ }
+ else
+ {
+ bcpp_tx = 0L;
+ }
+ printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
+ bcpp,bcpp_noc,bcpp_app, bcpp_tx);
+ printf("\n");
+ }
+
+#ifdef MULTI_THREAD
+ netapi_schedGetStats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
+ netapi_schedGetStats(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];
+#else
+netapi_schedGetStats(our_sched, &npL,&cyclesL,&ccyclesL);
+#endif
+
+if(pPaStats)
+{
+ printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
+ printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
+ printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
+ printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
+ printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
+ printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
+ printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
+ printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
+ printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
+ printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
+ printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
+ printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
+ printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
+ printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
+ printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
+ printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
+ printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
+ printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
+ printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
+ printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
+ printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
+ printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
+ printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
+ printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
+ printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
+ printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
+ printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
+}
+Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
+printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
+ pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
+printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
+ pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
+ pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
+
+Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
+printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
+ pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
+printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
+ pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
+ pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
+Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
+printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
+ pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
+printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
+ pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
+ pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
+
+
+#if 0
+printf("pa2sa descriptor area dump\n");
+for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
+{
+ extern long * pa2sa_descr_base;
+ long * tip= &pa2sa_descr_base[32*i];
+ dump_descr(tip, i);
+}
+printf("sa2pa descriptor area dump\n");
+for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
+{
+ extern long * sa2pa_descr_base;
+ long * tip= &sa2pa_descr_base[32*i];
+ dump_descr(tip, i);
+}
+#endif
+ for (i = 0; i < MAX_SEC_INDEX; i++)
+ {
+ /* Statistics for RX Tunnel */
+ memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
+ if (sa_info[i].dir ==NWAL_SA_DIR_INBOUND )
+ {
+ netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
+ if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
+ {
+ print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
+ sa_info[i].authMode,
+ sa_info[i].cipherMode);
+ }
+ if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
+ {
+ print_datamode_stats(&(netapi_sa_stats.dataModeStats),
+ sa_info[i].authMode,
+ sa_info[i].cipherMode);
+ }
+ }
+ else if (sa_info[i].dir ==NWAL_SA_DIR_OUTBOUND)
+ {
+ netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
+ if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
+ {
+ print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
+ sa_info[i].authMode,
+ sa_info[i].cipherMode);
+ }
+ if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
+ {
+ print_datamode_stats(&(netapi_sa_stats.dataModeStats),
+ sa_info[i].authMode,
+ sa_info[i].cipherMode);
+ }
+ }
+ else
+ printf("our_stats_cb: invalid SA direction\n");
+ }
+ netapi_dump_internal_heap_stats();
+}
+
void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
{
while (pch != NULL)
{
- printf ("parse_one_mac %s\n",pch);
- p_mac[index] = hex2dec(pch);
- index++;
- pch = strtok (NULL,"-");
+ p_mac[index] = hex2dec(pch);
+ index++;
+ pch = strtok (NULL,"-");
}
}
int i;
char * pch = strtok (&p_key_str[0],",");
- //printf("parse_one_key %s\n", p_key_str);
while (pch != NULL)
{
- //printf ("%s\n",pch);
- p_key[index] = hex2dec(pch);
- index++;
- pch = strtok (NULL,",");
+ p_key[index] = hex2dec(pch);
+ index++;
+ pch = strtok (NULL,",");
}
}
int i;
char * pch = strtok (&p_ip_addr_str[0],".");
- printf("parse_one_ip: ip string %s\n", p_ip_addr_str);
while (pch != NULL)
- {
- // printf ("xxxxx: %s\n",pch);
+ {
p_ip[index] = atoi(pch);
index++;
pch = strtok (NULL,".");
}
- //printf("index value : %d\n", index);
- for (i=0; i<4;i++)
- printf("parse_one_ipip[%d]: 0x%x\n",i, p_ip[i]);
}
void parse_mac_address(netTestConfigFile_t *pConfig)
{
int i;
int port = 0;
- for(i=0;i<2;i++)
+ for(i=0;i<NET_TEST_MAX_MAC;i++)
{
- parse_one_mac(&pConfig->mac[i][0],&netTestCfg.mac[i][0]);
- netTestCfg.switch_port[i] = atoi(&pConfig->switch_port[i][0]);
- printf("parse_mac_address mac port %d\n", netTestCfg.switch_port[i]);
+ if (strlen(&pConfig->mac[i][0]))
+ {
+ netTestCfg.num_macs++;
+ parse_one_mac(&pConfig->mac[i][0],&netTestCfg.mac[i][0]);
+ sscanf(&pConfig->switch_port[i][0],"sp%d",&netTestCfg.switch_port[i]);
+ }
}
+ Debug_printf("parse_mac_address: number of mac address %d\n", netTestCfg.num_macs);
}
void parse_ip_address(netTestConfigFile_t *pConfig)
{
int i;
- for(i=0;i<3;i++)
+
+ for(i=0;i<NET_TEST_MAX_IP;i++)
{
if (strlen(&pConfig->ip[i][0]))
{
- //printf("parse_ip: ip length %d\n", strlen(&pConfig->ip[i][0]));
- parse_one_ip(&pConfig->ip[i][0],&netTestCfg.ip[i].ipv4[0]);
+ netTestCfg.num_ips++;
+ parse_one_ip(&pConfig->ip[i][0],&netTestCfg.ip[i].ipv4[0]);
+ sscanf(&pConfig->attach_iface[i][0],"mac%d",&netTestCfg.attach_iface[i]);
}
}
+ Debug_printf("parse_ip_address: number of ip address %d\n", netTestCfg.num_ips);
}
void parse_ipsec_mode(netTestConfigFile_t *pConfig)
{
if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
{
netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
- //config.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
}
else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
{
netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
}
- //else
- // printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
+ else
+ {
+ Debug_printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
+ }
}
if (strlen(&pConfig->ipsec_mode_tx[0]))
{
netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
}
- //else
- //printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
+ else
+ {
+ Debug_printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
+ }
}
- // printf("parse_ipsec_mode(): RX mode %d\n", config.ipsec_mode_rx);
- // printf("parse_ipsec_mode(): TX mode %d\n", config.ipsec_mode_tx);
-
}
void parse_auth_mode(char *auth_mode_str, nwal_saAALG *auth_mode)
{
if (strlen(auth_mode_str))
{
- printf("strlen of auth_mode_str is %d\n", strlen(auth_mode_str));
+ Debug_printf("strlen of auth_mode_str is %d\n", strlen(auth_mode_str));
if (strcmp(auth_mode_str, "NULL") == 0)
{
*auth_mode= NWAL_SA_AALG_AES_XCBC;
}
else
- printf("parse_auth_mode: invalid auth mode specified\n");
-
- printf("parse_auth_mode(): setting to %s, auth_mode: %d\n", auth_mode_str, *auth_mode);
+ {
+ Debug_printf("parse_auth_mode: invalid auth mode specified\n");
}
-
+ }
}
void parse_encr_mode(char *ency_mode_str, nwal_saEALG*encr_mode)
{
if (strlen(ency_mode_str))
{
- printf("strlen of encr_mode_str is %d\n", strlen(ency_mode_str));
-
if (strcmp(ency_mode_str, "NULL") == 0)
{
*encr_mode= NWAL_SA_EALG_NULL;
*encr_mode= NWAL_SA_AALG_AES_XCBC;
}
else
- printf("parse_encr_mode: invalid auth mode specified\n");
-
- printf("parse_encr_mode(): setting to %s, encr_mode: %d\n", ency_mode_str, *encr_mode);
+ {
+ Debug_printf("parse_encr_mode: invalid auth mode specified\n");
}
-
+ }
}
void parse_proto(char *proto_str, nwal_IpSecProto *proto)
{
if (strlen(proto_str))
{
- printf("strlen of proto is %d\n", strlen(proto_str));
if (strcmp(proto_str, "ESP") == 0)
{
*proto= nwal_IpSecProtoESP;
- printf("parse_proto(): setting proto to ESP\n");
+ Debug_printf("parse_proto(): setting proto to ESP\n");
}
else if (strcmp(proto_str, "AH") == 0)
{
*proto = nwal_IpSecProtoAH;
- printf("parse_proto(): setting proto to AH\n");
+ Debug_printf("parse_proto(): setting proto to AH\n");
+ }
+ else
+ {
+ Debug_printf("parse_proto(), invalid RX ipsec mode in config file \n");
}
- //else
- // printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
}
}
{
if (strlen(mode_str))
{
- printf("strlen of mode is %d\n", strlen(mode_str));
if (strcmp(mode_str, "TUNNEL") == 0)
{
*mode= nwal_SA_MODE_TUNNEL;
- printf("parse_mode(): setting proto to TUNNEL\n");
}
else if (strcmp(mode_str, "TRANSPORT") == 0)
{
*mode = nwal_SA_MODE_TRANSPORT;
- printf("parse_mode(): setting proto to TUNNEL\n");
}
- //else
- // printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
+ else
+ {
+ Debug_printf("parse_mode(), invalid RX ipsec mode in config file \n");
+ }
}
}
{
if (strlen(ip_type_str))
{
- printf("strlen of ipType is %d\n", strlen(ip_type_str));
if (strcmp(ip_type_str, "IPV4") == 0)
{
*ipType= nwal_IPV4;
- printf("parse_ipType(): setting proto to IPV4\n");
}
else if (strcmp(ip_type_str, "IPV6") == 0)
{
*ipType = nwal_IPV6;
- printf("parse_ipType(): setting proto to IPV6\n");
}
- //else
- // printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
+ else
+ {
+ Debug_printf("parse_ipType(), invalid RX ipsec mode in config file \n");
+ }
}
}
{
if (strlen(spi_str))
{
- printf("strlen of spi is %d\n", strlen(spi_str));
*spi = (int)strtol(spi_str, NULL, 0);
- printf("parse_sa: spi 0x%x\n", spi);
}
}
void parse_replayWindow(char *replay_window_str, uint32_t *replay_window)
{
*replay_window = atoi(replay_window_str);
- printf("parse_replayWindow: %d\n", *replay_window);
-
}
void parse_esn(char *esn_str, uint32_t *esn)
{
*esn = atoi(esn_str);
- printf("parse_esn: %d\n", *esn);
}
-void parse_key_size(char *key_size_str, uint32_t *key_size)
+void parse_key_size(char *key_size_str, uint16_t *key_size)
{
*key_size = atoi(key_size_str);
- printf("parse_key_size: %d\n", *key_size);
}
void parse_tunnel_id(char * tunnel_id_str, uint32_t *tunnel_id)
{
if (strlen(tunnel_id_str))
{
- printf("strlen of tunnel is %d\n", strlen(tunnel_id_str));
*tunnel_id = (int)strtol(tunnel_id_str, NULL, 0);
- printf("***********************parse_tunnel_id spi 0x%x\n", tunnel_id);
}
}
{
if (strlen(dir_str))
{
- printf("strlen of dir is %d\n", strlen(dir_str));
if (strcmp(dir_str, "INBOUND") == 0)
{
*dir= NWAL_SA_DIR_INBOUND;
- printf("parse_dir(): setting dir to inbound\n");
}
else if (strcmp(dir_str, "OUTBOUND") == 0)
{
*dir = NWAL_SA_DIR_OUTBOUND;
- printf("parse_dir(): setting dir to outbount\n");
}
else
- printf("parse_dir: invalid direction\n");
+ Debug_printf("parse_dir: invalid direction\n");
}
}
void parse_sa(netTestConfigFile_t *pConfig, int i)
{
parse_dir((char*) &pConfig->sa_config[i].dir, &netTestCfg.sa_info[i].dir);
- parse_spi(&pConfig->sa_config[i].spi, &netTestCfg.sa_info[i].spi);
- parse_proto(&pConfig->sa_config[i].proto, &netTestCfg.sa_info[i].proto);
- parse_mode(&pConfig->sa_config[i].saMode, &netTestCfg.sa_info[i].saMode);
- parse_ipType(&pConfig->sa_config[i].ipType, &netTestCfg.sa_info[i].ipType);
- parse_one_ip(&pConfig->sa_config[i].src, &netTestCfg.sa_info[i].src);
- parse_one_ip(&pConfig->sa_config[i].dst, &netTestCfg.sa_info[i].dst);
- parse_replayWindow(&pConfig->sa_config[i].replayWindow, &netTestCfg.sa_info[i].replayWindow);
- parse_auth_mode(&pConfig->sa_config[i].authMode, &netTestCfg.sa_info[i].authMode);
- parse_encr_mode(&pConfig->sa_config[i].cipherMode, &netTestCfg.sa_info[i].cipherMode);
- parse_esn(&pConfig->sa_config[i].esnLo, &netTestCfg.sa_info[i].esnLo);
- parse_esn(&pConfig->sa_config[i].esnHi, &netTestCfg.sa_info[i].esnHi);
- parse_key_size(&pConfig->sa_config[i].encKeySize, &netTestCfg.key_params[i].encKeySize);
- parse_key_size(&pConfig->sa_config[i].macKeySize, &netTestCfg.key_params[i].macKeySize);
-
-
- parse_one_key(&pConfig->sa_config[i].encr_key, &netTestCfg.encr_key[i][0]);
+ parse_spi((char*)&pConfig->sa_config[i].spi, &netTestCfg.sa_info[i].spi);
+ parse_proto((char*)&pConfig->sa_config[i].proto, &netTestCfg.sa_info[i].proto);
+ parse_mode((char*)&pConfig->sa_config[i].saMode, &netTestCfg.sa_info[i].saMode);
+ parse_ipType((char*)&pConfig->sa_config[i].ipType, &netTestCfg.sa_info[i].ipType);
+ parse_one_ip((char*)&pConfig->sa_config[i].src, (unsigned char *)&netTestCfg.sa_info[i].src);
+ parse_one_ip((char*)&pConfig->sa_config[i].dst, (unsigned char *)&netTestCfg.sa_info[i].dst);
+ parse_replayWindow((char*)&pConfig->sa_config[i].replayWindow, &netTestCfg.sa_info[i].replayWindow);
+ parse_auth_mode((char*)&pConfig->sa_config[i].authMode, &netTestCfg.sa_info[i].authMode);
+ parse_encr_mode((char*)&pConfig->sa_config[i].cipherMode, &netTestCfg.sa_info[i].cipherMode);
+ parse_esn((char*)&pConfig->sa_config[i].esnLo, &netTestCfg.sa_info[i].esnLo);
+ parse_esn((char*)&pConfig->sa_config[i].esnHi, &netTestCfg.sa_info[i].esnHi);
+ parse_key_size((char*)&pConfig->sa_config[i].encKeySize, &netTestCfg.key_params[i].encKeySize);
+ parse_key_size((char*)&pConfig->sa_config[i].macKeySize, &netTestCfg.key_params[i].macKeySize);
+
+
+ parse_one_key((char*) &pConfig->sa_config[i].encr_key, &netTestCfg.encr_key[i][0]);
netTestCfg.key_params[i].pEncKey = (uint8_t*)&netTestCfg.encr_key[i][0];
- parse_one_key(&pConfig->sa_config[i].auth_key, &netTestCfg.auth_key[i][0]);
+ parse_one_key((char*)&pConfig->sa_config[i].auth_key, &netTestCfg.auth_key[i][0]);
netTestCfg.key_params[i].pAuthKey= (uint8_t*)&netTestCfg.auth_key[i][0];
- parse_tunnel_id(&pConfig->sa_config[i].tunnel_id, &netTestCfg.tunnel_id[i]);
+ parse_tunnel_id((char*)&pConfig->sa_config[i].tunnel_id, &netTestCfg.tunnel_id[i]);
}
-#ifdef EXPERIMENTAL
+
int n_routes=0;
int n_dst_ips=0;
void parse_routes(netTestConfigFile_t *pConfig)
{
-int i;
-int said=0;
-for(i=0;i<MAX_ROUTES;i++)
-{
- int port;
- if (pConfig->routes[i][0])
- {
- port=atoi(&pConfig->ports[i][0]);
- if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
- if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
+ int i;
+ int said=0;
+ for(i=0;i<MAX_ROUTES;i++)
+ {
+ int port;
+ if (pConfig->routes[i][0])
+ {
+ port=atoi(&pConfig->ports[i][0]);
+ if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
+ Debug_printf("parse_routes [%d]: %s\n", i, &pConfig->routes[i][0]);
+ if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
+ {
+ routes[i].out_port = port;
+ parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
+ //memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
+ memcpy(&routes[i].out_mac[6], ((port==1) ?&netTestCfg.mac[0][0]: &netTestCfg.mac[1][0] ),6);
+ routes[i].out_mac[12]=0x08;
+ routes[i].out_mac[13]=0x00;
+ routes[i].sec_ptr=NULL;
+ n_routes+=1;
+ }
+ else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
+ {
+ said=atoi(&pConfig->routes[i][2]) ;
+ routes[i].sec_ptr=&sa_info[said];
+ n_routes+=1;
+ }
+ }
+ }
+ our_router = route_init();
+ for (i=0;i<MAX_ROUTES;i++)
+ {
+ unsigned long ip_be;
+ int route_index;
+ if (pConfig->dst_ips[i][0])
{
- routes[i].out_port = port;
- parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
- //memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
- routes[i].out_mac[12]=0x08;
- routes[i].out_mac[13]=0x00;
- routes[i].sec_ptr=NULL;
- n_routes+=1;
- }
- else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
- {
- said=atoi(&pConfig->routes[i][2]) ;
- routes[i].sec_ptr=&sa_info[said];
- n_routes+=1;
+ parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
+ sscanf(&pConfig->paths[i][0],"route%d",&route_index);
+ route_add(our_router,&ip_be,(void*)&routes[route_index]);
+ n_dst_ips+=1;
}
- }
-}
-our_router = route_init();
-for (i=0;i<MAX_ROUTES;i++)
-{
- unsigned long ip_be;
- int route_index;
- if (pConfig->dst_ips[i][0])
- {
- parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
- sscanf(&pConfig->paths[i][0],"route%d",&route_index);
- route_add(our_router,&ip_be,&routes[route_index]);
- n_dst_ips+=1;
- }
-}
-//printf(">Route DB built. %d entries\n",n_dst_ips);
+ }
+//Debug_printf(">Route DB built. %d entries\n",n_dst_ips);
}
-#endif
-
void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
{
int i;
static int sa_count = 0;
- char *key, *data, *ep, *data2;
+ char *key, *ep;
char * d1, *d2, *d3, *d4;
char * d5, *d6, *d7, *d8;
char * d9, *d10, *d11, *d12;
continue; //skip comment
key = (char *)strtok(line, tokens);
- data = (char *)strtok(NULL, tokens);
+ d1 = (char *)strtok(NULL, tokens);
if (!key)
continue;
- if (!data)
+ if (!d1)
continue;
- if(strlen(data) == 0)
+ if(strlen(d1) == 0)
{
continue;
}
- //printf("d1: %s\n", data);
- data2 = (char *)strtok(NULL, tokens);
- //printf("d2: %s\n", data2);
+
+ d2 = (char *)strtok(NULL, tokens);
d3 = (char *)strtok(NULL, tokens);
- //printf("d3: %s\n", d3);
d4 = (char *)strtok(NULL, tokens);
- //printf("d4: %s\n", d4);
d5 = (char *)strtok(NULL, tokens);
- //printf("d5: %s\n", d5);
d6 = (char *)strtok(NULL, tokens);
- // printf("d6: %s\n", d6);
d7 = (char *)strtok(NULL, tokens);
- // printf("d7: %s\n", d7);
d8 = (char *)strtok(NULL, tokens);
- //printf("d8: %s\n", d8);
d9 = (char *)strtok(NULL, tokens);
- //printf("d9: %s\n", d9);
d10 = (char *)strtok(NULL, tokens);
- // printf("d10: %s\n", d10);
d11 = (char *)strtok(NULL, tokens);
- // printf("d11: %s\n", d11);
d12 = (char *)strtok(NULL, tokens);
- //printf("d12: %s\n", d12);
d13 = (char *)strtok(NULL, tokens);
- // printf("d13: %s\n", d13);
d14 = (char *)strtok(NULL, tokens);
- // printf("d14: %s\n", d14);
d15 = (char *)strtok(NULL, tokens);
- // printf("d15: %s\n", d15);
d16 = (char *)strtok(NULL, tokens);
d17 = (char *)strtok(NULL, tokens);
- // printf("d16: %s\n", d16);
CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
sprintf(temp_str,"sa%d",sa_count);
if(strcmp(key, temp_str) == 0)
{
- printf("parse_config_file, temp_str %s, sa_count: %d\n", temp_str, sa_count);
+ Debug_printf("parse_config_file, temp_str %s, sa_count: %d\n", temp_str, sa_count);
CHECK_SET_PARAM_SA(temp_str,
- &pConfig->sa_config[sa_count].dir,
- &pConfig->sa_config[sa_count].spi,
- &pConfig->sa_config[sa_count].proto,
- &pConfig->sa_config[sa_count].saMode,
- &pConfig->sa_config[sa_count].ipType,
- &pConfig->sa_config[sa_count].src,
- &pConfig->sa_config[sa_count].dst,
- &pConfig->sa_config[sa_count].replayWindow,
- &pConfig->sa_config[sa_count].authMode,
- &pConfig->sa_config[sa_count].cipherMode,
- &pConfig->sa_config[sa_count].esnLo,
- &pConfig->sa_config[sa_count].esnHi,
- &pConfig->sa_config[sa_count].encKeySize,
- &pConfig->sa_config[sa_count].macKeySize,
- &pConfig->sa_config[sa_count].encr_key,
- &pConfig->sa_config[sa_count].auth_key,
- &pConfig->sa_config[sa_count].tunnel_id);
+ (char*)&pConfig->sa_config[sa_count].dir,
+ (char*)&pConfig->sa_config[sa_count].spi,
+ (char*)&pConfig->sa_config[sa_count].proto,
+ (char*)&pConfig->sa_config[sa_count].saMode,
+ (char*)&pConfig->sa_config[sa_count].ipType,
+ (char*)&pConfig->sa_config[sa_count].src,
+ (char*)&pConfig->sa_config[sa_count].dst,
+ (char*)&pConfig->sa_config[sa_count].replayWindow,
+ (char*)&pConfig->sa_config[sa_count].authMode,
+ (char*)&pConfig->sa_config[sa_count].cipherMode,
+ (char*)&pConfig->sa_config[sa_count].esnLo,
+ (char*)&pConfig->sa_config[sa_count].esnHi,
+ (char*)&pConfig->sa_config[sa_count].encKeySize,
+ (char*)&pConfig->sa_config[sa_count].macKeySize,
+ (char*)&pConfig->sa_config[sa_count].encr_key,
+ (char*)&pConfig->sa_config[sa_count].auth_key,
+ (char*)&pConfig->sa_config[sa_count].tunnel_id);
parse_sa(pConfig,sa_count);
sa_count++;
//parse_sa(pConfig,i);
CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
}
#endif
- for(i=0;i<2;i++)
+ for(i=0;i<NET_TEST_MAX_MAC;i++)
{
sprintf(temp_str,"mac%d",i);
//CHECK_SET_PARAM(temp_str,&(pConfig->mac[i][0]));
CHECK_SET_PARAM2(temp_str,&pConfig->mac[i][0],&pConfig->switch_port[i][0] );
}
- for(i=0;i<3;i++)
+ for(i=0;i<NET_TEST_MAX_IP;i++)
{
sprintf(temp_str,"ip%d",i);
- CHECK_SET_PARAM(temp_str,&pConfig->ip[i][0]);
+ CHECK_SET_PARAM2(temp_str,&pConfig->ip[i][0], &pConfig->attach_iface[i][0]);
}
}
parse_mac_address(pConfig);
parse_ipsec_mode(pConfig);
- //parse_key(pConfig);
-
-#if 0
- for (i=0; i < sa_count;i++)
- {
- printf("parse_config_file, calling parsing sa for sa_count %d\n", sa_count);
- parse_sa(pConfig,i);
- }
-#endif
if (strlen(&pConfig->ipsec_if_no[0]))
{
}
+//******************************************************
+//use scheduling housekeeping callback to generate pkts
+//******************************************************
+static int done_burst=0;
+void house(NETAPI_SCHED_HANDLE_T * s)
+{
+ Ti_Pkt * tip;
+ unsigned int len;
+ nwalTxPktInfo_t meta_tx = {0};
+ PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
+ int err;
+ static int house_pkts_gened=0;
+ int p;
+ unsigned char * pIpHdr,* pData;
+ unsigned int vv1,vv2,vv3;
+ unsigned int sum_vv1=0;
+ unsigned int sum_vv2=0;
+ unsigned int sum_vv3=0;
+ unsigned int sum_vv4=0;
+ unsigned int sum_vv5=0;
+
+ unsigned int nwal_flow_vv1,nwal_flow_vv2;
+ unsigned int nwal_sum_vv1=0;
+ unsigned int nwal_sum_vv2=0;
+ unsigned int nwal_sum_vv3=0;
+ unsigned int nwal_sum_vv4=0;
+ unsigned int nwal_sum_vv5=0;
+ unsigned int nwal_sum_vv6=0;
+
+ unsigned int nwal_sum_flow_vv1=0;
+ unsigned int nwal_sum_flow_vv2=0;
+ unsigned long long cache_op_b1;
+ unsigned long long cache_op_b2;
+ unsigned long long n_c_ops;
+ static int first =0;
+ Cppi_HostDesc* pPktDesc;
+
+ int coreid = 0; //who we are
+#ifdef MULTI_THREAD
+ NETAPI_T nh= netapi_schedGetHandle(s);
+ coreid=(int) netapi_getCookie(nh);
+
+ if (QUIT) {netapi_schedClose(s,NULL,&err); return;}
+
+ if (coreid==0) //slave
+ {
+ netcp_cfgReqStats(nh, our_stats_cb_mt, 0,&err);
+ }
+#else
+ if(done_burst)
+ {
+ house_pkts_gened+=TX_BURST;
+ Debug_printf("net_test> request stats at n=%d \n",house_pkts_gened);
+ netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
+ if (err!=0) {Debug_printf("stats req failed\n");}
+ if (house_pkts_gened >= np2process+ 100)
+ {
+ netapi_schedClose(s,NULL,&err);
+ }
+ return;
+ }
+ done_burst=1;
+ Osal_cache_op_measure_reset();
+ memset(&meta_tx,0,sizeof(meta_tx));
+ for(p=0;p<TX_BURST;p++) {
+ //reguest stats
+ if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
+ {
+ Debug_printf("net_test> request stats at n=%d \n",house_pkts_gened);
+ netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
+ if (err!=0) {Debug_printf("stats req failed\n");}
+ }
+
+
+ if (house_pkts_gened >= np2process+ 100)
+ {
+ //shutdown
+ netapi_schedClose(s,NULL,&err);
+ continue;
+ }
+
+ else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
+
+ /* manufacture a pkt to transmit */
+ tip = get_pkt(house_pkts_gened, &len, ourHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
+ if(!tip) { house_pkts_gened +=1; continue; }
+ /* set the pkt length */
+ vv1 = hplib_mUtilGetPmuCCNT();
+ Pktlib_setPacketLen(tip, len);
+ /* set up meta data */
+ meta.sa_handle=nwal_HANDLE_INVALID;
+ /* #define BENCH_UDP_SEND */
+#ifdef BEND_UDP_SEND
+ meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
+ meta_tx.startOffset = 0;
+ /* GONE in V2 meta_tx.pktLen = len; */
+ meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
+ meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
+ meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
+ //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
+ meta_tx.ploadLen = TEST_PAYLOAD_LEN;
+
+ Pktlib_getDataBuffer(tip,&pData,&len);
+ if(house_pkts_gened &0x1)
+ {
+ memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
+ }
+ pIpHdr = pData + meta_tx.ipOffBytes;
+ meta_tx.pseudoHdrChecksum =
+ test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
+#else
+ Pktlib_getDataBuffer(tip,&pData,&len);
+ if(house_pkts_gened &0x1)
+ {
+ memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
+ }
+ meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
+ meta_tx.startOffset = 0;
+ meta_tx.ploadLen = TEST_PAYLOAD_LEN;
+#endif
+ /* post it to netcp tx channel*/
+ meta.u.tx_meta=&meta_tx;
+#ifdef DEBUG_DESC
+ if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
+ else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
+#endif
+
+ if(!first)
+ {
+ first++;
+ nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
+ if(nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
+ &meta_tx,
+ &flowPSCmdInfo) != nwal_OK)
+ {
+ Debug_printf("nwal_initPSCmdInfo() ERROR \n");
+ }
+ nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
+ nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
+ nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
+ }
+ cache_op_b1= Osal_cache_op_measure(&n_c_ops);
+ vv2= hplib_mUtilGetPmuCCNT();
+#ifdef BEND_UDP_SEND
+ nwal_mCmdSetL4CkSumPort( tip,
+ &flowPSCmdInfo,
+ TEST_PKT_UDP_OFFSET_BYTES,
+ (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
+ meta_tx.pseudoHdrChecksum,
+ meta_tx.enetPort);
+#else
+ nwal_mCmdSetPort (tip,
+ &flowPSCmdInfo, //could be NULL
+ 0); //port 0 -> switch decides
+
+#endif
+
+ pPktDesc = Pktlib_getDescFromPacket(tip);
+ /* Send the packet out to transmit Q*/
+ Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
+ pPktDesc,
+ NWAL_DESC_SIZE);
+ vv3= hplib_mUtilGetPmuCCNT();
+ cache_op_b2= Osal_cache_op_measure(&n_c_ops);
+
+ sum_vv1 += (vv2-vv1);
+ if(!house_pkts_gened)
+ {
+ /* first packet. Take out the PS command label creation cost */
+ sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
+ }
+
+ sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
+
+ // Debug_printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
+ stats[coreid].itx +=1;
+ house_pkts_gened +=1;
+ }
+ {
+ unsigned long long ccycles;
+ ccycles =Osal_cache_op_measure(&n_c_ops);
+ if (sum_vv1)
+ {
+ printf("BURST NWAL Fast send %d pkts. metadata=%d Cmd Label Creation Cost=%d nwal Fast Send Cost (less cacheop)= %d n_c_ops=%lld cache_op_time=%lld (pp-> %d)\n",
+ stats[coreid].itx, sum_vv1/stats[coreid].itx, nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx,
+ n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
+#if 0
+ Debug_printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
+ nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
+ nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
+
+#endif
+
+ if(stats[core_id].itx2)
+ {
+ printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
+ nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
+ }
+ }
+ }
+#endif
+}
+
+void create_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1)
+{
+ int err, i;
+
+ for (i = 0; i < netTestCfg.num_macs; i++)
+ {
+ /* add mac intefaces */
+ netcp_cfgCreateMacInterface(
+ netapi_handle,
+ &netTestCfg.mac[i][0],
+ //ETH0,
+ i,
+ netTestCfg.switch_port[i],
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ (NETCP_CFG_VLAN_T ) NULL , //future
+ 1,
+ &err);
+ if (err)
+ {
+ printf("addmac %d failed %d\n",i, err);
+ //exit(1);
+ }
+ else
+ printf("create_interfaces, added mac sucess\n");
+ }
+ for (i = 0; i < netTestCfg.num_ips; i++)
+ {
+ //attach an IP to this interface
+ *ip_rule0=netcp_cfgAddIp(
+ netapi_handle,
+ //ETH0,
+ netTestCfg.attach_iface[i],
+ nwal_IPV4,
+ (nwalIpAddr_t *)&netTestCfg.ip[i].ipv4[0],
+ NULL, //all IP
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ &err
+ );
+ if (err) {
+ printf("addip %d failed %d\n", i, err);
+ //exit(1);
+ }
+ else
+ printf("create_interfaces, added ip sucess\n");
+ }
+}
+
+void delete_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1)
+{
+ int err;
+ //delete IPs and MAC Interfacess
+ netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, *ip_rule0, &err);
+ netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, *ip_rule1, &err);
+ netcp_cfgDelMac(netapi_handle,0,&err);
+ netcp_cfgDelMac(netapi_handle,1,&err);
+#ifdef PROMISCUOUS
+ netcp_cfgDelMac(netapi_handle,2,&err);
+#endif
+}
index 1b6c26efda53876ddef9d487b0e07694d9583126..2068815c186fa2174a5f1e28926e75404a7d7f97 100755 (executable)
#include "net_test.h"
+#ifdef __LINUX_USER_SPACE
+#define Debug_printf
+#else
+#define Debug_printf
+#endif
-#define MAX_SEC_INDEX 16
+#define MAX_SEC_INDEX 16
+#define NET_TEST_MAX_MAC 10
+#define NET_TEST_MAX_IP 10
#define MAX_LINE_LENGTH 512
#define MAX_ROUTES 16
-/* The input strings for the input config file is given below */
-#define INIT_CONFIG_MAC0 "mac0"
-#define INIT_CONFIG_MAC1 "mac1"
-#define INIT_CONFIG_IP0 "ip0"
-#define INIT_CONFIG_IP1 "ip1"
-#define INIT_CONFIG_IP2 "ip2"
-#define INIT_CONFIG_LOCAL_IPSEC_IP "local_ipsec_ip"
-#define INIT_CONFIG_REMOTE_IPSEC_IP "remote_ipsec_ip"
+
+/* The input strings requird for parsing certain configuration
+ * paremeters from the config file */
#define INIT_CONFIG_IPSEC_MODE_RX "ipsec_mode_rx"
#define INIT_CONFIG_IPSEC_MODE_TX "ipsec_mode_tx"
#define INIT_CONFIG_IPSEC_IF_NO "ipsec_if"
-#define INIT_CONFIG_AUTH_KEY "authkey"
-#define INIT_CONFIG_ENCR_KEY "encrkey"
#define CONFIG_STRING_LEN 128
//IPSEC MODE(only choose one rx and one tx)
#define IPSEC_MODE_RX_SIDEBAND 3
#define IPSEC_MODE_TX_SIDEBAND 4
+#define PKT_LEN 1400
typedef struct {
- unsigned char mac[2][6];
- uint8_t switch_port[2];
- unsigned char mac1[2][6];
- nwalIpAddr_t ip[3];
- nwalIpAddr_t ip1;
- nwalIpAddr_t ip2;
+ unsigned char mac[NET_TEST_MAX_MAC][6];
+ uint8_t num_macs;
+ uint8_t switch_port[NET_TEST_MAX_MAC];
+ nwalIpAddr_t ip[NET_TEST_MAX_IP];
+ uint8_t num_ips;
+ uint8_t attach_iface[NET_TEST_MAX_IP];
nwalIpAddr_t local_ipsec_ip;
nwalIpAddr_t remote_ipsec_ip;
uint8_t ipsec_mode_rx;
int ipsec_if_no;
uint8_t auth_key[MAX_SEC_INDEX][36];
uint8_t encr_key[MAX_SEC_INDEX][36];
- uint32_t tunnel_id[MAX_SEC_INDEX];
+ uint32_t tunnel_id[MAX_SEC_INDEX];
NETAPI_SEC_SA_INFO_T sa_info[MAX_SEC_INDEX];
nwalSecKeyParams_t key_params[MAX_SEC_INDEX];
} netTestConfigSA_t;
typedef struct{
- char mac[2][CONFIG_STRING_LEN];
- char switch_port[2][CONFIG_STRING_LEN];
- char ip[3][CONFIG_STRING_LEN];
+ char mac[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
+ char switch_port[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
+ char ip[NET_TEST_MAX_IP][CONFIG_STRING_LEN];
+ char attach_iface [NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
char ipsec_mode_rx[CONFIG_STRING_LEN];
char ipsec_mode_tx[CONFIG_STRING_LEN];
char routes[MAX_ROUTES][CONFIG_STRING_LEN];
} netTestConfigFile_t;
+struct LastPktInfo
+{
+int iface;
+int ipcsum;
+int l4csum;
+} ;
+int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta);
void mysig(int x);
unsigned long peek(unsigned long * p);
uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2);
uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords);
uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen);
+void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher);
+void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher);
+void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
+void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
void parse_one_mac(char * p_mac_str, unsigned char *p_mac);
void parse_one_key(char *p_key_str, unsigned char *p_key);
void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip);
void parse_spi(char *spi_str, uint32_t *spi);
void parse_replayWindow(char *replay_window_str, uint32_t *replay_window);
void parse_esn(char *esn_str, uint32_t *esn);
-void parse_key_size(char *key_size_str, uint32_t *key_size);
+void parse_key_size(char *key_size_str, uint16_t *key_size);
void parse_tunnel_id(char * tunnel_id_str, uint32_t *tunnel_id);
void parse_dir(char* dir_str, nwal_SaDir *dir);
void parse_sa(netTestConfigFile_t *pConfig, int i);
void parse_routes(netTestConfigFile_t *pConfig);
#endif
void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig);
+
+void house(NETAPI_SCHED_HANDLE_T *s);
+
+void create_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
+void delete_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
#endif
+
index 4f6f88bb73f2e59698d4044d682df12e16dfd140..3cfb0870d1e48a44eb6f56d52f92f3ddd91eccbe 100755 (executable)
#include "trie.h"
#include "net_test.h"
+#include "router.h"
#if 0
#endif
Trie * route_init(void)
-
{
-
-Trie *Pt = trie_new();
-
-return Pt;
-
+ Trie *Pt = trie_new();
+ return Pt;
}
-void route_add(Trie * Pt, unsigned int * Pdest_ipBE, void * Pour_route)
+void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
{
trie_insert(Pt,(char *)Pdest_ipBE, sizeof(int), Pour_route);
// lookup next hop in route trie
int route_pkt(Trie *Pt, void * Ppkt, IP_HEAD_T *Phead, unsigned char * Pbuf, int * Plen, ROUTE_SEC_T **Prs, int *PoutPort)
{
- OUR_ROUTE_T *Pr;
- int ret;
- Pr = trie_lookup(Pt, (char *) &Phead->dst, 4);
- if (!Pr ) return -1; //can't route
- if (Pr->sec_ptr)
- {
- if(!Prs) return -3;
- //tunnel i/f
- ret=process_tunnel(Pt, Ppkt, Phead, Pbuf, Plen, Pr,*PoutPort);
- *Prs = Pr->sec_ptr;
- return ret;
- }
- if (Prs) *Prs=NULL;
- //simple route
- //copy new mac
+ OUR_ROUTE_T *Pr;
+ int ret;
+ Pr = trie_lookup(Pt, (char *) &Phead->dst, 4);
+ if (!Pr ) return -1; //can't route
+ if (Pr->sec_ptr)
+ {
+ if(!Prs) return -3;
+ //tunnel i/f
+ ret=process_tunnel(Pt, Ppkt, Phead, Pbuf, Plen, Pr, PoutPort);
+ *Prs = Pr->sec_ptr;
+ return ret;
+ }
+ if (Prs) *Prs=NULL;
+ //simple route
+ //copy new mac
memcpy(Pbuf,Pr->out_mac,14);
Pbuf[14+8]-=1; //ttl--
//todo do check ttl!
Pbuf[14+10]=0; Pbuf[14+11]=0; //zap [outer] header checksum
- if(PoutPort) *PoutPort=Pr->out_port;
- return 1;
+ if(PoutPort) *PoutPort=Pr->out_port;
+ return 1;
}
int process_tunnel(Trie *Pt, void *Ppkt, IP_HEAD_T * Phead,
diff --git a/ti/runtime/netapi/test/router.h b/ti/runtime/netapi/test/router.h
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __ROUTER_H__
+#define __ROUTER_H__
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+
+#include "net_test.h"
+
+
+Trie * route_init(void);
+void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route);
+
+
+int route_pkt(Trie *Pt, void * Ppkt, IP_HEAD_T *Phead, unsigned char * Pbuf, int * Plen, ROUTE_SEC_T **Prs, int *PoutPort);
+int process_tunnel(Trie *Pt, void *Ppkt, IP_HEAD_T * Phead,
+ unsigned char * Pbuf, int* Plen, OUR_ROUTE_T * Proute,
+ int * PoutPort);
+
+#endif
diff --git a/ti/runtime/netapi/tools/module/Makefile b/ti/runtime/netapi/tools/module/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# File Name: Makefile
-#
-# Description: Makefile to build kernel netapi utility module.
-#
-# Copyright (C) 2012 Texas Instruments, Incorporated
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation version 2.
-#
-# This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
-# whether express or implied; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-
-KDIR ?= ~/linux-appleton
-
-obj-m += netapimod.o
-
-default all:
- make -C $(KDIR) M=$$PWD modules
-
-clean:
- make -C $(KDIR) M=$$PWD clean
-
diff --git a/ti/runtime/netapi/tools/module/netapimod.c b/ti/runtime/netapi/tools/module/netapimod.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- * File name: netapimod.c
- *
- * Description: NETAPI utility module.
- *
- * Copyright (C) 2012 Texas Instruments, Incorporated
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
- * whether express or implied; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
-
-/* TODO:
- - 64bit DMA address
-*/
-
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/proc_fs.h>
-
-#include <linux/version.h>
-#include <linux/unistd.h>
-#include <asm/unistd.h>
-#include <linux/wait.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/string.h>
-#include <linux/if.h>
-
-#include <asm/uaccess.h>
-#include <linux/dma-mapping.h>
-
-#include <asm/irq.h>
-#include <linux/clk.h>
-
-#include <asm/mach/map.h>
-
-#include <mach/common.h>
-#include <mach/time.h>
-#include <mach/cputype.h>
-#include <mach/psc.h>
-#include <mach/cp_intc.h>
-#include <mach/irqs.h>
-#include <mach/gpio.h>
-#include <mach/hardware.h>
-#include <mach/cp_intd.h>
-#include <mach/tci6614.h>
-#include <linux/hrtimer.h>
-
-#include "netapimod.h"
-
-#include <asm/pgtable.h>
-
-//#define NETAPIMOD_DEBUG
-
-#define NETAPIMOD_DEVNAME "netapi"
-
-#ifdef NETAPIMOD_DEBUG
-# define __D(fmt, args...) printk(KERN_DEBUG "NETAPI Debug: " fmt, ## args)
-#else
-# define __D(fmt, args...)
-#endif
-
-#define __E(fmt, args...) printk(KERN_ERR "NETAPI Error: " fmt, ## args)
-
-static struct class *netapimod_class;
-static int netapimod_major;
-static atomic_t reference_count = ATOMIC_INIT(0);
-
-static dma_addr_t dmaAddr; // physical address of region
-static void * cpuAddr=NULL; //va for above
-static void * userVmaStart = NULL;
-static unsigned int memSize = NETAPIMOD_MEMSZ;
-
-//extern long davinci_ck_get_arm_rate(void);
-static void MPU_Enable_userModeAccess(void)
-{
- unsigned int reg_addr,i,count,defRegVal;
- void __iomem * temp_reg;
- defRegVal = 0x3FFFFFF;
- reg_addr = 0x2368208;
- count = 5;
-
- for(i=1;i<=count;i++)
- {
- temp_reg= ioremap(reg_addr, 4);
- __raw_writel(defRegVal, temp_reg) ;
- iounmap(temp_reg);
- //*((unsigned int*)(reg_addr)) = defRegVal;
- reg_addr = reg_addr + 0x10;
- }
-
- reg_addr = 0x2370208;
- count = 16;
-
- for(i=1;i<=count;i++)
- {
- temp_reg= ioremap(reg_addr, 4);
- __raw_writel(defRegVal,temp_reg) ;
- iounmap(temp_reg);
- // *((unsigned int*)(reg_addr)) = defRegVal;
- reg_addr = reg_addr + 0x10;
- }
-
- reg_addr = 0x2378208;
- count = 1;
-
- for(i=1;i<=count;i++)
- {
- temp_reg= ioremap(reg_addr, 4);
- __raw_writel(defRegVal, temp_reg) ;
- iounmap(temp_reg);
-
-// *((unsigned int*)(reg_addr)) = defRegVal;
- reg_addr = reg_addr + 0x10;
- }
-}
-
-/*********************************************************************************
-* FUNCTION: netapimod_init_proc
-*
-**********************************************************************************
-*
-* DESCRIPTION: Forms output for /proc/netapi file
-*********************************************************************************/
-static int netapimod_init_proc(char *buf, char **start, off_t offset,
- int count, int *eof, void *data)
-{
- unsigned long val;
- int len=0;
- struct clk *clk = clk_get((struct device *) NULL,"main_div_chip_clk1");
- ktime_t temp1, temp2;
- temp1 = ktime_get();
- temp2 = ktime_get_real();
-
- //enable user access to qmss h/w
- MPU_Enable_userModeAccess();
-
- //pmcr <- single clock, reset, enable
- val = 0x4|0x1;
- asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(val));
-
- //userenr <- enable user space access [this won't work from user space obviously!]
- val = 1;
- asm volatile("mcr p15, 0, %0, c9, c14, 0" : : "r"(val));
-
- //start things
- val = 0x80000000;
- asm volatile("mcr p15, 0, %0, c9, c12, 1" :: "r"(val));
-
- len += sprintf(buf + len, "netapi proc entry\n");
- len += sprintf(buf + len, "===========================\n");
- len += sprintf(buf + len, "enabled PMU for user space\n");
- asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(val));
- len += sprintf(buf + len,"current ccnt = %ld\n", val);
- len += sprintf(buf + len,"arm cpu freq = %d \n", clk? (int) clk_get_rate(clk): -1);
- *eof = 1;
-
- return len;
-}
-
-
-#if 0
-/*********************************************************************************
-* FUNCTION: netapimod_stats_proc
-*
-**********************************************************************************
-*
-* DESCRIPTION: Forms output for /proc/netapi_stats file
-*********************************************************************************/
-static int netapimod_stats_proc(char *buf, char **start, off_t offset,
- int count, int *eof, void *data)
-{
-
- int len = 0;
- len += sprintf(buf + len, "NETAPI Stats:\n");
- len += sprintf(buf + len, "=============================================\n");
- len += sprintf(buf + len, "...coming...\n");
- *eof = 1;
- return len;
-}
-#endif
-
-static long netapimod_ioctl(struct file *filp, unsigned int cmd, unsigned long args)
-{
- unsigned int __user *argp = (unsigned int __user *) args;
- struct netapimod_block block;
- unsigned long physp;
-
- if (_IOC_TYPE(cmd) != _IOC_TYPE(NETAPIMOD_IOCMAGIC)) {
- __E("ioctl(): bad command type 0x%x (should be 0x%x)\n",
- _IOC_TYPE(cmd), _IOC_TYPE(NETAPIMOD_IOCMAGIC));
- }
-
- switch (cmd & NETAPIMOD_IOCCMDMASK) {
- case NETAPIMOD_IOCGETPHYS:
- __D("GETPHYS ioctl received.\n");
-
- if (put_user((unsigned long)dmaAddr, argp)) {
- return -EFAULT;
- }
-
- __D("GETPHYS returning %#1x\n", (unsigned int)dmaAddr);
- break;
-
- case NETAPIMOD_IOCCACHE:
- __D("CACHE%s%s ioctl received.\n",
- cmd & NETAPIMOD_WB ? "WB" : "", cmd & NETAPIMOD_INV ? "INV" : "");
-
- if (copy_from_user(&block, argp, sizeof(block))) {
- return -EFAULT;
- }
-
- physp = (unsigned long)dmaAddr +
- (block.addr - (unsigned long)userVmaStart);
-
- switch (cmd & ~NETAPIMOD_IOCMAGIC) {
- case NETAPIMOD_IOCCACHEWB:
- dma_sync_single_for_device(NULL, (dma_addr_t)physp,
- block.size, DMA_TO_DEVICE);
- break;
-
- case NETAPIMOD_IOCCACHEINV:
- dma_sync_single_for_cpu(NULL, (dma_addr_t)physp,
- block.size, DMA_FROM_DEVICE);
- break;
-
- case NETAPIMOD_IOCCACHEWBINV:
- dma_sync_single_for_device(NULL, (dma_addr_t)physp,
- block.size, DMA_TO_DEVICE);
- dma_sync_single_for_cpu(NULL, (dma_addr_t)physp,
- block.size, DMA_FROM_DEVICE);
- break;
-
- } /* switch cmd */
-
- __D("CACHE%s%s ioctl returned vaddr=0x%p size=0x%x paddr=0x%p.\n",
- cmd & NETAPIMOD_WB ? "WB" : "",
- cmd & NETAPIMOD_INV ? "INV" : "",
- (void *)block.addr, block.size, (void *)physp);
- break;
-
- case NETAPIMOD_IOCGETSIZE:
- __D("GETSIZE ioctl received.\n");
-
- if (put_user((unsigned long)memSize, argp)) {
- return -EFAULT;
- }
-
- __D("GETSIZE returning %#1x\n", (unsigned int)memSize);
- break;
-
- default:
- __E("Unknown ioctl received.\n");
- return -EINVAL;
-
- } /* switch base cmd */
-
- return 0;
-}
-
-#define PROT_PTE_DEVICE (L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN)
-
-#define netapimod_pgprot_dev_buffer(prot) \
- __pgprot_modify(prot, L_PTE_MT_MASK, PROT_PTE_DEVICE | \
- L_PTE_MT_DEV_SHARED | L_PTE_SHARED)
-
-static int netapimod_mmap(struct file *filp, struct vm_area_struct *vma)
-{
- size_t size = vma->vm_end - vma->vm_start;
-
- __D("mmap: vma->vm_start = %#lx\n", vma->vm_start);
- __D("mmap: vma->vm_pgoff = %#lx\n", vma->vm_pgoff);
- __D("mmap: vma->vm_end = %#lx\n", vma->vm_end);
- __D("mmap: size = 0x%x\n", size);
-
- switch ((vma->vm_pgoff << PAGE_SHIFT)) {
- case NETAPIMOD_MMAP_DMA_MEM_OFFSET:
- userVmaStart = (void *)vma->vm_start;
- return dma_mmap_coherent(NULL, vma, cpuAddr, dmaAddr, size);
- break;
-
- case NETAPIMOD_MMAP_QM_DATA_REG_MEM_OFFSET:
- vma->vm_page_prot = netapimod_pgprot_dev_buffer(vma->vm_page_prot);
- if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size,
- vma->vm_page_prot)) {
- return -EAGAIN;
- }
- __D("mmap: page_prot=0x%x\n", vma->vm_page_prot);
- return 0;
- break;
-
- default:
- return -EINVAL;
- }
-}
-
-static int netapimod_open(struct inode *inode, struct file *filp)
-{
- __D("open: called.\n");
-
- if (atomic_read(&reference_count)) {
- __E("open: device already in use.\n");
- return -EBUSY;
- }
-
- atomic_inc(&reference_count);
- return 0;
-}
-
-static int netapimod_release(struct inode *inode, struct file *filp)
-{
- __D("close: called.\n");
-
- atomic_dec(&reference_count);
- return 0;
-}
-
-static struct file_operations netapimod_fxns = {
- owner: THIS_MODULE,
- unlocked_ioctl: netapimod_ioctl,
- mmap: netapimod_mmap,
- open: netapimod_open,
- release: netapimod_release
-};
-
-/*********************************************************************************
-* FUNCTION: netapimod_init_module
-*
-* DESCRIPTION:Initialization routine for netapi kernel device
-*********************************************************************************/
-static int __init netapimod_init_module(void)
-{
- void * priv = NULL;
- int ret;
-
- __D("init\n");
-
- create_proc_read_entry(NETAPIMOD_DEVNAME, 0, NULL, netapimod_init_proc,
- (void *)priv);
-
- //enable user access to qmss h/w
- MPU_Enable_userModeAccess();
-
- /* allocate space from CMA */
- cpuAddr = dma_alloc_coherent(NULL, memSize, &dmaAddr, GFP_KERNEL);
-
- if (!cpuAddr) {
- __E("Error allocating from CMA.\n");
- ret = -ENOMEM;
- goto cleanup_proc;
- } else {
- __D("Allocated 0x%x size memory from CMA.\n",memSize);
- }
-
- netapimod_major = register_chrdev(0, NETAPIMOD_DEVNAME, &netapimod_fxns);
-
- if (netapimod_major < 0) {
- __E("Failed to allocate major number.\n");
- ret = -ENODEV;
- goto cleanup_mem;
- }
-
- __D("Allocated major number: %d\n", netapimod_major);
-
- netapimod_class = class_create(THIS_MODULE, NETAPIMOD_DEVNAME);
- if (IS_ERR(netapimod_class)) {
- __E("Error creating netapi device class.\n");
- ret = PTR_ERR(netapimod_class);
- goto cleanup_dev;
- }
-
- device_create(netapimod_class, NULL, MKDEV(netapimod_major, 0), NULL,
- NETAPIMOD_DEVNAME);
-
- __D("module loaded\n");
- return 0;
-
-cleanup_dev:
- unregister_chrdev(netapimod_major, NETAPIMOD_DEVNAME);
-cleanup_mem:
- dma_free_coherent(NULL, memSize, cpuAddr, dmaAddr);
-cleanup_proc:
- remove_proc_entry(NETAPIMOD_DEVNAME, NULL);
-
- return ret;
-}
-
-/*********************************************************************************
- * FUNCTION: netapimod_cleanup_module
- *
- * DESCRIPTION:
- *********************************************************************************/
-static void __exit netapimod_cleanup_module(void)
-{
- if (atomic_read(&reference_count)) {
- __E("netapi device still in use");
- }
-
- /* Remove netapi device */
- device_destroy(netapimod_class, MKDEV(netapimod_major, 0));
- unregister_chrdev(netapimod_major, NETAPIMOD_DEVNAME);
- class_destroy(netapimod_class);
-
- /* Free CMA buffer */
- dma_free_coherent(NULL, memSize, cpuAddr, dmaAddr);
-
- /* Remove netapi proc entry */
- remove_proc_entry(NETAPIMOD_DEVNAME, NULL);
-
- __D("module unloaded\n");
- return;
-}
-
-module_init(netapimod_init_module);
-module_exit(netapimod_cleanup_module);
-
-MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Texas Instruments Incorporated");
-MODULE_DESCRIPTION("TI NETAPI core module.");
-MODULE_SUPPORTED_DEVICE("Texas Instruments netapi");
-module_param(memSize, uint, 0);
-MODULE_PARM_DESC(memSize, "Size of DMA coherent memory to be allocated");
-
diff --git a/ti/runtime/netapi/tools/module/netapimod.h b/ti/runtime/netapi/tools/module/netapimod.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * File name: netapimod.h
- *
- * Description: NETAPI utility module header file.
- *
- * Copyright (C) 2012 Texas Instruments, Incorporated
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
- * whether express or implied; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
-
-#ifndef __TI_NETAPIMOD_H__
-#define __TI_NETAPIMOD_H__
-
-#define NETAPIMOD_IOCMAGIC 0x0000fe00
-
-/* Supported "base" ioctl cmds for the driver. */
-#define NETAPIMOD_IOCGETPHYS 1
-#define NETAPIMOD_IOCGETSIZE 2
-#define NETAPIMOD_IOCCACHE 3
-
-/* ioctl cmd "flavors" */
-#define NETAPIMOD_WB 0x00010000
-#define NETAPIMOD_INV 0x00020000
-
-/* Supported "flavors" to "base" ioctl cmds for the driver. */
-#define NETAPIMOD_IOCCACHEWBINV NETAPIMOD_IOCCACHE | NETAPIMOD_WB | NETAPIMOD_INV
-#define NETAPIMOD_IOCCACHEWB NETAPIMOD_IOCCACHE | NETAPIMOD_WB
-#define NETAPIMOD_IOCCACHEINV NETAPIMOD_IOCCACHE | NETAPIMOD_INV
-
-#define NETAPIMOD_IOCCMDMASK 0x000000ff
-
-/* Default size of DMA coherent memory to be allocated */
-#define NETAPIMOD_MEMSZ 0xf00000
-
-/* MMAP offsets */
-/* Offset to map CMA allocated memory */
-#define NETAPIMOD_MMAP_DMA_MEM_OFFSET 0
-/* Offset to map QMSS Data register region */
-#define NETAPIMOD_MMAP_QM_DATA_REG_MEM_OFFSET 0x44020000
-
-struct netapimod_block {
- unsigned long addr;
- size_t size;
-};
-
-#endif /*__TI_NETAPIMOD_H__ */
-
diff --git a/ti/runtime/netapi/tools/netapimod_test.c b/ti/runtime/netapi/tools/netapimod_test.c
+++ /dev/null
@@ -1,340 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-
-#include "module/netapimod.h"
-#include "netapi_util.h"
-
-#define AVOID_MMAP
-#ifdef AVOID_MMAP
-static int fd;
-#endif
-//#define __DEBUG
-
-#ifdef __DEBUG
-#define __D(fmt, args...) fprintf(stdout, "NETAPIMODTEST Debug: " fmt, ## args)
-#else
-#define __D(fmt, args...)
-#endif
-
-#define __E(fmt, args...) fprintf(stderr, "NETAPIMODTEST Error: " fmt, ## args)
-
-static int netapi_fd;
-
-int netapimod_init(void)
-{
- netapi_fd = open("/dev/netapi", O_RDWR);
-
- if (netapi_fd == -1) {
- __E("init: failed to open /dev/netapi: '%s'\n", strerror(errno));
- return -1;
- }
-
- __D("init: successfully open /dev/netapi.\n");
- return 0;
-}
-
-void netapimod_close(void)
-{
- close(netapi_fd);
-
-#ifdef AVOID_MMAP
- close(fd);
-#endif
-}
-
-static inline unsigned long netapimod_getPhys(void)
-{
- unsigned long physp;
-
- if (ioctl(netapi_fd, NETAPIMOD_IOCGETPHYS | NETAPIMOD_IOCMAGIC, &physp) == -1) {
- __E("getPhys: Failed to get physical address.\n");
- return 0;
- }
-
- __D("getPhys: exiting, ioctl NETAPIMOD_IOCGETPHYS succeeded, returning %#lx\n",
- physp);
-
- return physp;
-}
-
-static inline unsigned long netapimod_getSize(void)
-{
- unsigned long size;
-
- if (ioctl(netapi_fd, NETAPIMOD_IOCGETSIZE | NETAPIMOD_IOCMAGIC, &size) == -1) {
- __E("getSize: Failed to get size.\n");
- return 0;
- }
-
- __D("getSize: exiting, ioctl NETAPIMOD_IOCGETSIZE succeeded, returning 0x%x\n", size);
-
- return size;
-}
-
-static inline int netapimod_cacheWb(void *ptr, size_t size)
-{
- struct netapimod_block block;
-
- __D("cacheWb: entered w/ addr %p, size %p\n", ptr, size);
-
- block.addr = (unsigned long)ptr;
- block.size = size;
-
- if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEWB | NETAPIMOD_IOCMAGIC, &block) == -1) {
- __E("cacheWb: Failed to writeback %p\n", ptr);
-
- return -1;
- }
-
- __D("cacheWb: exiting, ioctl NETAPIMOD_IOCCACHEWB succeeded, returning 0\n");
-
- return 0;
-}
-
-static inline int netapimod_cacheWbInv(void *ptr, size_t size)
-{
- struct netapimod_block block;
-
- __D("cacheWbInv: entered w/ addr %p, size %p\n", ptr, size);
-
- block.addr = (unsigned long)ptr;
- block.size = size;
-
- if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEWBINV | NETAPIMOD_IOCMAGIC, &block) == -1) {
- __E("cacheWbInv: Failed to writeback & invalidate %p\n", ptr);
-
- return -1;
- }
-
- __D("cacheWbInv: exiting, ioctl NETAPIMOD_IOCCACHEWBINV succeeded, returning 0\n");
-
- return 0;
-}
-
-static inline int netapimod_cacheInv(void *ptr, size_t size)
-{
- struct netapimod_block block;
-
- __D("cacheInv: entered w/ addr %p, size %p\n", ptr, size);
-
- block.addr = (unsigned long)ptr;
- block.size = size;
-
- if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEINV | NETAPIMOD_IOCMAGIC, &block) == -1) {
- __E("cacheInv: Failed to invalidate %p\n", ptr);
-
- return -1;
- }
-
- __D("cacheInv: exiting, ioctl NETAPIMOD_IOCCACHEINV succeeded, returning 0\n");
-
- return 0;
-}
-
-static inline unsigned long netapimod_mmap(void * phys, int sz)
-{
- void *userp;
-#ifdef AVOID_MMAP
- if( (fd = open("/dev/mem", O_RDWR )) == -1) return (unsigned long) NULL;
- printf("/dev/mem opened.\n");
-
- /* Map sz bytes` */
- userp = mmap(0,sz , PROT_READ | PROT_WRITE, MAP_SHARED, fd, phys);
- if(userp == (void *) -1) exit(1);
- printf("Memory mapped at address %p. (cached=%d)\n", userp,1);
-
-#else
- /* Map the physical address to user space */
- userp = mmap(0, // Preferred start address
- sz, // Length to be mapped
- PROT_WRITE | PROT_READ, // Read and write access
- MAP_SHARED, // Shared memory
- netapi_fd, // File descriptor
- 0); // The byte offset from fd
-#endif
- if (userp == MAP_FAILED) {
- __E("allocHeap: Failed to mmap.\n");
- return 0;
- }
-
- __D("mmap succeeded, returning virt buffer %p\n", userp);
-
- return (unsigned long)userp;
-}
-
-long buffer[10000];
-
-int main()
-{
- unsigned long physp, virtp, size;
- int i,j,k;
- register unsigned long v1;
- register unsigned long v2;
- register unsigned long v3;
- register unsigned long v4;
- register long sum=0;
- register long *p;
- int c;
- v1 = netapi_timing_start();
- sleep(1);
- v2 = netapi_timing_stop();
- printf("PMU time calibrate : 1 sec = %d tics\n", v2-v1);
-
-
- if (netapimod_init()) return -1;
- if (!(physp = netapimod_getPhys())) return -1;
- if (!(size = netapimod_getSize())) return -1;
- v1 = netapi_timing_start();
- for(i=0;i<10000;i++)
- {
- if (!(size = netapimod_getSize())) return -1;
- }
- v2 = netapi_timing_stop();
- printf("getSize: (pure ioctl) %d cycles \n", (v2-v1)/10000 );
- sleep(1);
-
- if (!(virtp = netapimod_mmap(physp,size))) return 1;
- printf("virtp = %x phys=%x sz=%d\n",virtp, physp, size) ;
- sleep(1);
-
- p = (long*) virtp;
- v1 = netapi_timing_start();
- for(i=0;i<10000;i++)
- {
- sum += p[i];
- }
- v2 = netapi_timing_stop();
- printf("read mmap'd ddr buffer: %d cycles for size = 10000 words sum=%d\n", (v2-v1)/10000,sum);
- sleep(1);
-
-//repeat with regular memory
- p = (long*) &buffer[0];
- v1 = netapi_timing_start();
- for(i=0;i<10000;i++)
- {
- sum += p[i];
- }
- v2 = netapi_timing_stop();
- printf("static ddr buffer: %d cycles for size = 10000 words sum=%d\n", (v2-v1)/10000,sum);
- sleep(1);
-
-
-
-#ifdef AVOID_MMAP
-p = (long*) virtp;
-for(j=1;j<50;j++)
-{
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheWb((void *)physp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("wb (clean): %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
- sleep(1);
- sum=0;
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- v3 = netapi_timing_stop();
- for(k=0;k<j*2;k++) p[64*k] = i;
- v4 = netapi_timing_stop();
- sum += (v4-v3);
- if (netapimod_cacheWb((void *)physp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
-
- printf("wb (dirty): %d cycles for size = %d\n", (v2-v1-sum)/1000, 128*j);
- sleep(1);
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheInv((void *)physp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("Inv (no wb): %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
- sleep(1);
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheWbInv((void *)physp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("wbInv (clean): %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
- sleep(1);
- sum=0;
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- v3 = netapi_timing_stop();
- for(k=0;k<j*2;k++) p[64*k] = i;
- v4 = netapi_timing_stop();
- sum += (v4-v3);
- if (netapimod_cacheWbInv((void *)physp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("wbInv (dirty): %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
-}
-
-//stress test
-printf("stress test..\n");
-{
-volatile char *pp = (char*) physp;
-volatile char *vp = (char*) virtp;
-v1 = netapi_timing_start();
-for(i=0,c=0;c<1000000000;c++)
-{
- memcpy(vp,(char *)&i,4);
- memcpy(vp+64,(char *) &c,4);
- if (netapimod_cacheWbInv((void *)pp, 128)) return -1;
- if (!(c%0xc0000)) {
- v2 = netapi_timing_stop();
- printf("%d ; ok %d cycles per wbinv call (128 bytes) %x %x\n",c, (v2-v1)/0xc0000, pp,vp);
- v1 = netapi_timing_start();
- }
- if (i*128 > size-128){ i=0; pp = (char*) physp; vp = (char *) virtp;}
- else {i+=128; pp+=128; vp+=128;}
-}
-}
-#else
-for(j=1;j<50;j++)
-{
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheWb((void *)virtp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("wb: %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
- sleep(1);
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheInv((void *)virtp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("Inv: %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
- sleep(1);
-
- v1 = netapi_timing_start();
- for(i=0;i<1000;i++)
- {
- if (netapimod_cacheWbInv((void *)virtp, 128*j)) return -1;
- }
- v2 = netapi_timing_stop();
- printf("wbInv: %d cycles for size = %d\n", (v2-v1)/1000, 128*j);
-}
-#endif
- netapimod_close();
-
- return 0;
-}
-
-