diff options
author | Tinku Mannan | 2014-08-14 08:49:12 -0500 |
---|---|---|
committer | Tinku Mannan | 2014-08-14 08:49:12 -0500 |
commit | 3029f8d01ff4cb0eb8aee734f8ec46211b3aaa23 (patch) | |
tree | 35284766773546f10b4299f95c705a733027212c | |
parent | 9de6e78e4e522f93557eaafd5e9de5f836473140 (diff) | |
parent | 730792e1367ee0e3212b36da150d3d8c6118eaed (diff) | |
download | netapi-3029f8d01ff4cb0eb8aee734f8ec46211b3aaa23.tar.gz netapi-3029f8d01ff4cb0eb8aee734f8ec46211b3aaa23.tar.xz netapi-3029f8d01ff4cb0eb8aee734f8ec46211b3aaa23.zip |
Merge remote branch 'origin/dpi_demo'
24 files changed, 2923 insertions, 11 deletions
diff --git a/ti/runtime/netapi/demo/build/Makefile b/ti/runtime/netapi/demo/build/Makefile new file mode 100755 index 0000000..164545a --- /dev/null +++ b/ti/runtime/netapi/demo/build/Makefile | |||
@@ -0,0 +1,122 @@ | |||
1 | # | ||
2 | empty = | ||
3 | space =$(empty) $(empty) | ||
4 | |||
5 | export ARMV7OBJDIR ?= ./obj | ||
6 | export ARMV7BINDIR ?= ./bin | ||
7 | export ARMV7LIBDIR ?= ./lib | ||
8 | export ARMV7SALIBDIR ?= ./lib | ||
9 | |||
10 | DPI_DEMO_SRC_DIR ?= $(PWD) | ||
11 | # INCLUDE Directories | ||
12 | SA_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/sa | ||
13 | QMSS_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/qmss | ||
14 | CPPI_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/cppi | ||
15 | RM_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/rm | ||
16 | NETAPI_SRC_DIR ?= $(TRANS_SDK_INSTALL_PATH)/ti/runtime/netapi | ||
17 | NETAPI_INC_DIR ?= $(TRANS_SDK_INSTALL_PATH) | ||
18 | HPLIB_INC_DIR ?= $(HPLIB_INSTALL_PATH) | ||
19 | NWAL_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/nwal | ||
20 | PKTLIB_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/runtime/pktlib | ||
21 | |||
22 | |||
23 | ifndef NAVL_INSTALL_PATH | ||
24 | $(error NAVL_INSTALL_PATH is undefined) | ||
25 | else | ||
26 | NAVL_INSTALL_PATH ?= /home/a0868410/git | ||
27 | NAVL_LIB_DIR ?= $(NAVL_INSTALL_PATH)/navl/lib | ||
28 | NAVL_INC_DIR ?= $(NAVL_INSTALL_PATH) | ||
29 | endif | ||
30 | |||
31 | #TRIE_OBJS=$(ARMV7OBJDIR)/netapi/test/trie.o | ||
32 | |||
33 | NT_RM_OBJS = $(ARMV7OBJDIR)/netapi/utils/sockutils.o $(ARMV7OBJDIR)/netapi/utils/netapi_util_rm.o | ||
34 | |||
35 | DPI_DEMO_OBJS= $(ARMV7OBJDIR)/netapi/demo/src/transport_dpi_demo.o $(ARMV7OBJDIR)/netapi/demo/src/navl_wrapper.o $(ARMV7OBJDIR)/netapi/demo/src/navl_external_posix.o | ||
36 | |||
37 | # Support Libraries used by dpi-demo | ||
38 | CSL_DEVICE ?= -DDEVICE_K2E -DNSS_GEN2 | ||
39 | QMSS_LIB = -lqmss | ||
40 | CPPI_LIB = -lcppi | ||
41 | PA_LIB = -lpa2 | ||
42 | NWAL_LIB = -lnwalsa_k2e | ||
43 | SA_LIB = -lsa | ||
44 | RM_LIB = -lrm | ||
45 | PKTLIB_LIB = -lpktlib | ||
46 | NETAPI_LIB =-lnetapi_k2e | ||
47 | HP_LIB = -lhplib_k2e | ||
48 | NAVL_LIB = -lnavl | ||
49 | |||
50 | local_base=/usr/local | ||
51 | LDFLAGS = -L. -L$(local_base)/lib | ||
52 | |||
53 | LIBS = -static $(QMSS_LIB) $(CPPI_LIB) $(PA_LIB) $(PKTLIB_LIB) $(NETAPI_LIB) $(HP_LIB) $(SA_LIB) $(NWAL_LIB) $(RM_LIB) -Wl,-Bdynamic | ||
54 | |||
55 | LIBS += $(NAVL_LIB) -lstdc++ -lgcc_s | ||
56 | |||
57 | SYSTYPE:=$(shell uname) | ||
58 | ifeq ($(SYSTYPE), Linux) | ||
59 | LIBS += -ldl -lm | ||
60 | else | ||
61 | LIBS += -lexecinfo | ||
62 | endif | ||
63 | |||
64 | ifdef CROSS_TOOL_INSTALL_PATH | ||
65 | ## Support backwards compatibility with KeyStone1 approach | ||
66 | CC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc | ||
67 | AC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)as | ||
68 | AR = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)ar | ||
69 | LD = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc | ||
70 | endif | ||
71 | |||
72 | INCLUDE = -I. -I$(local_base)/include -I../ -I$(HPLIB_INC_DIR) -I$(NETAPI_INC_DIR) -I$(PDK_INSTALL_PATH) -I$(NWAL_INSTALL_PATH) -I$(PKTLIB_INSTALL_PATH) -I$(SA_INSTALL_PATH) -I$(QMSS_INC_DIR) -I$(CPPI_INC_DIR) -I$(RM_INC_DIR) -I$(NAVL_INC_DIR) $(CSL_DEVICE) | ||
73 | |||
74 | CFLAGS += $(DEBUG_FLAG) -D__ARMv7 -D_VIRTUAL_ADDR_SUPPORT -D__LINUX_USER_SPACE -D_LITTLE_ENDIAN=1 -DNWAL_ENABLE_SA -DMAKEFILE_BUILD -D _GNU_SOURCE | ||
75 | # Linker options | ||
76 | INTERNALLINKDEFS = -Wl,--start-group $(LIBS) -Wl,--end-group -lrt -pthread -L$(ARMV7LIBDIR) -L$(ARMV7SALIBDIR) -L$(NAVL_LIB_DIR) | ||
77 | |||
78 | EXE_NAME=transport_dpi_demo | ||
79 | BIN_DIR = $(ARMV7BINDIR)/netapi/demo | ||
80 | all: demo install | ||
81 | |||
82 | demo: $(ARMV7BINDIR)/netapi/demo/.created $(BIN_DIR)/$(EXE_NAME) | ||
83 | |||
84 | clean: | ||
85 | rm -f $(ARMV7OBJDIR)/netapi/demo/src/*.o | ||
86 | rm -f $(ARMV7BINDIR)/netapi/demo/* | ||
87 | |||
88 | |||
89 | #$(ARMV7OBJDIR)/netapi/demo/src/%.o: %.c $(NETAPI_SRC_DIR)/demo/src/%.c $(ARMV7OBJDIR)/netapi/demo/src/.created | ||
90 | $(ARMV7OBJDIR)/netapi/demo/src/%.o: $(NETAPI_SRC_DIR)/demo/src/%.c $(ARMV7OBJDIR)/netapi/demo/src/.created | ||
91 | @echo compiling $< | ||
92 | $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@ | ||
93 | |||
94 | $(ARMV7OBJDIR)/netapi/demo/src/.created: | ||
95 | @mkdir -p $(ARMV7OBJDIR)/netapi/demo/src/ | ||
96 | |||
97 | $(ARMV7BINDIR)/netapi/demo/.created: | ||
98 | @mkdir -p $(ARMV7BINDIR)/netapi/demo/ | ||
99 | |||
100 | $(ARMV7BINDIR)/netapi/demo/$(EXE_NAME): $(NT_RM_OBJS) $(DPI_DEMO_OBJS) | ||
101 | $(CC) $(LDFLAGS) $(DPI_DEMO_OBJS) $(NT_RM_OBJS) $(INTERNALLINKDEFS) $(INCLUDE) -o $(BIN_DIR)/$(EXE_NAME) | ||
102 | |||
103 | |||
104 | $(ARMV7OBJDIR)/netapi/utils/%.o: $(NETAPI_SRC_DIR)/utils/%.c $(ARMV7OBJDIR)/netapi/utils/.created | ||
105 | @echo compiling $< | ||
106 | $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@ | ||
107 | |||
108 | $(ARMV7OBJDIR)/netapi/utils/.created: | ||
109 | @mkdir -p $(ARMV7OBJDIR)/netapi/utils/ | ||
110 | |||
111 | install: | ||
112 | install -d $(INSTALL_BIN_BASE_DIR) | ||
113 | install -c -m 755 $(BIN_DIR)/$(EXE_NAME) $(INSTALL_BIN_BASE_DIR)/$(EXE_NAME) | ||
114 | install -d $(SYSCONFDIR)/transportnetlib | ||
115 | install -c -m 755 demo/demo_setup_files/transport_dpi_demo_setup.sh $(SYSCONFDIR)/transportnetlib | ||
116 | install -c -m 755 demo/demo_setup_files/index.html $(SYSCONFDIR)/transportnetlib | ||
117 | install -c -m 755 demo/demo_setup_files/dpicgi1.sh $(SYSCONFDIR)/transportnetlib | ||
118 | install -c -m 755 demo/demo_setup_files/dpicgi2.sh $(SYSCONFDIR)/transportnetlib | ||
119 | install -c -m 755 demo/demo_setup_files/dpicgi3.sh $(SYSCONFDIR)/transportnetlib | ||
120 | install -c demo/demo_setup_files/stats1.awk $(SYSCONFDIR)/transportnetlib | ||
121 | install -c demo/demo_setup_files/stats2.awk $(SYSCONFDIR)/transportnetlib | ||
122 | install -c demo/demo_setup_files/stats3.awk $(SYSCONFDIR)/transportnetlib | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/dpicgi1.sh b/ti/runtime/netapi/demo/demo_setup_files/dpicgi1.sh new file mode 100755 index 0000000..e817deb --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/dpicgi1.sh | |||
@@ -0,0 +1,16 @@ | |||
1 | #!/bin/bash | ||
2 | #dump mac addresses from switch | ||
3 | echo Content-type: text/html | ||
4 | echo | ||
5 | echo | ||
6 | echo "<HTML>" | ||
7 | echo "<HEAD>" | ||
8 | echo "</HEAD>" | ||
9 | echo "<BODY>" | ||
10 | echo "<H2> MAC Addresses From Switch ALE </H2>" | ||
11 | echo "<PRE>" | ||
12 | cat /sys/devices/soc.0/24000000.netcp/ale_table | grep "touched" | grep "addr" | cut -d ' ' -f 10- | ||
13 | echo "</PRE>" | ||
14 | echo "<A href=\"\index.html\"> <p><u>RETURN</u></p> </A>" | ||
15 | echo "</BODY>" | ||
16 | echo "</HTML>" \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/dpicgi2.sh b/ti/runtime/netapi/demo/demo_setup_files/dpicgi2.sh new file mode 100755 index 0000000..a749a35 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/dpicgi2.sh | |||
@@ -0,0 +1,7 @@ | |||
1 | #!/bin/bash | ||
2 | echo Content-type: text/html | ||
3 | echo | ||
4 | echo | ||
5 | #dump proto seen stat | ||
6 | #awk -f ../stats1.awk ../stats2.txt | ||
7 | /usr/bin/transport_dpi_demo stats | awk -f ../stats1.awk | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/dpicgi3.sh b/ti/runtime/netapi/demo/demo_setup_files/dpicgi3.sh new file mode 100755 index 0000000..2df8654 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/dpicgi3.sh | |||
@@ -0,0 +1,7 @@ | |||
1 | #!/bin/bash | ||
2 | echo Content-type: text/html | ||
3 | echo | ||
4 | echo | ||
5 | #dump proto cycles stats | ||
6 | #awk -f ../stats2.awk ../stats1.txt | ||
7 | /usr/bin/transport_dpi_demo stats | awk -f ../stats2.awk | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/dpicgi4.sh b/ti/runtime/netapi/demo/demo_setup_files/dpicgi4.sh new file mode 100755 index 0000000..51ebca4 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/dpicgi4.sh | |||
@@ -0,0 +1,7 @@ | |||
1 | #!/bin/bash | ||
2 | echo Content-type: text/html | ||
3 | echo | ||
4 | echo | ||
5 | #dump mem stat | ||
6 | awk -f ../stats3.awk ../stats1.txt | ||
7 | #dpidemo stats | awk -f ../stats3.awk \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/index.html b/ti/runtime/netapi/demo/demo_setup_files/index.html new file mode 100644 index 0000000..9440abc --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/index.html | |||
@@ -0,0 +1,23 @@ | |||
1 | <html> | ||
2 | <script type="text/javascript"> | ||
3 | function hello(msg) { | ||
4 | var msg= "this is the net_test_dpi home page"; | ||
5 | document.open(); | ||
6 | document.write(msg); | ||
7 | document.writeln("<A href=\"/index.html\"> <p><u>RETURN</u></p> </A>"); | ||
8 | document.close(); | ||
9 | } | ||
10 | </script> | ||
11 | <head><title> NET_TEST_DPI </title></head> | ||
12 | <body > | ||
13 | <img src="tilogo.gif"> | ||
14 | <text> <p> Hi there. Welcome to the <b>Texas Instruments DPI</b> demo </p> | ||
15 | <p> | ||
16 | featuring <b> Procera Networks Deep Packet Inspection Library </b> and TI Transp | ||
17 | xt> | ||
18 | <A href="cgi-bin/dpicgi1.sh"> <p>List of Mac Addresses</p> </A> | ||
19 | <A href="cgi-bin/dpicgi5.sh"> <p>Packet Forwarding Stats</p> </A> | ||
20 | <A href="cgi-bin/dpicgi2.sh"> <p>Protocols Seen</p> </A> | ||
21 | <A href="cgi-bin/dpicgi3.sh"> <p>Cycles by Protocol</p> </A> | ||
22 | <A href="cgi-bin/dpicgi4.sh"> <p>Memory Usage</p> </A> | ||
23 | </body> \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/stats1.awk b/ti/runtime/netapi/demo/demo_setup_files/stats1.awk new file mode 100644 index 0000000..5fd71d8 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/stats1.awk | |||
@@ -0,0 +1,52 @@ | |||
1 | #-------------------------------------- | ||
2 | # awk script to process stats | ||
3 | # output from dpidemo and build | ||
4 | # web page | ||
5 | # stats1-> dump navl proto stats (part1) | ||
6 | #_____________________________________ | ||
7 | |||
8 | |||
9 | BEGIN { state=0; | ||
10 | printf("<HTML>\n"); | ||
11 | printf("</HEAD>\n"); | ||
12 | printf("<BODY>\n"); | ||
13 | printf("<H2> DPI Protocol Statistics </H2>\n"); | ||
14 | |||
15 | } | ||
16 | |||
17 | $0 ~ "NAVL DPI stats" { | ||
18 | if (state==0) | ||
19 | { | ||
20 | state=1; | ||
21 | printf("<table>\n"); | ||
22 | printf("<tr>\n"); | ||
23 | # printf("<th> colspan="6" <b>Results</b> </th> </tr> \n"); | ||
24 | } | ||
25 | } | ||
26 | // { | ||
27 | if ((state==1)&&(NF>=8)) | ||
28 | { | ||
29 | printf("<tr> "); | ||
30 | for(i=1;i<=6;i++) printf("<td> <b> %s </b> </td> ",$i); | ||
31 | printf("</tr> \n"); | ||
32 | } | ||
33 | else if ((state==2) && (NF>=6)) | ||
34 | { | ||
35 | printf("<tr> "); | ||
36 | for(i=1;i<=6;i++) if (i==1) printf("<td> <b>%s</b> </td> ", $i); else printf("<td> %s </td> ", $i); | ||
37 | printf("</tr> \n"); | ||
38 | } | ||
39 | } | ||
40 | /--------/ { if (state==1) state=2} | ||
41 | /packets captured/ {if (state==2) {state=3; printf("</table>\n");}} | ||
42 | |||
43 | |||
44 | |||
45 | END { | ||
46 | printf("</PRE>\n"); | ||
47 | printf("<A href=\"\\index.html\"> <p><u> RETURN </u> </p> </A>\n"); | ||
48 | printf("</BODY>\n"); | ||
49 | printf("</HTML>\n"); | ||
50 | |||
51 | |||
52 | } \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/stats2.awk b/ti/runtime/netapi/demo/demo_setup_files/stats2.awk new file mode 100644 index 0000000..a3431ef --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/stats2.awk | |||
@@ -0,0 +1,52 @@ | |||
1 | #-------------------------------------- | ||
2 | # awk script to process stats | ||
3 | # output from dpidemo and build | ||
4 | # web page | ||
5 | # stats2-> dump navl proto stats (part2) | ||
6 | #_____________________________________ | ||
7 | |||
8 | |||
9 | BEGIN { state=0; | ||
10 | printf("<HTML>\n"); | ||
11 | printf("</HEAD>\n"); | ||
12 | printf("<BODY>\n"); | ||
13 | printf("<H2> DPI Cycle Statistics by Protocol </H2>\n"); | ||
14 | |||
15 | } | ||
16 | |||
17 | $0 ~ "NAVL DPI stats" { | ||
18 | if (state==0) | ||
19 | { | ||
20 | state=1; | ||
21 | printf("<table>\n"); | ||
22 | printf("<tr>\n"); | ||
23 | # printf("<th> colspan="6" <b>Results</b> </th> </tr> \n"); | ||
24 | } | ||
25 | } | ||
26 | // { | ||
27 | if ((state==1)&&(NF>=8)) | ||
28 | { | ||
29 | printf("<tr> "); | ||
30 | printf("<td> <b> %s </b> </td> ",$1); | ||
31 | for(i=7;i<=19;i++) printf("<td> <b> %s </b> </td> ",$i); | ||
32 | printf("</tr> \n"); | ||
33 | } | ||
34 | else if ((state==2) && (NF>=6)) | ||
35 | { | ||
36 | printf("<tr> "); | ||
37 | printf("<td> <b> %s </b> </td> ",$1); | ||
38 | for(i=7;i<=19;i++) printf("<td> %s </td> ", $i); | ||
39 | printf("</tr> \n"); | ||
40 | } | ||
41 | } | ||
42 | /--------/ { if (state==1) state=2} | ||
43 | /packets captured/ {if (state==2) {state=3; printf("</table>\n");}} | ||
44 | |||
45 | |||
46 | |||
47 | END { | ||
48 | printf("</PRE>\n"); | ||
49 | printf("<A href=\"\\index.html\"> <p><u> RETURN </u> </p> </A>\n"); | ||
50 | printf("</BODY>\n"); | ||
51 | printf("</HTML>\n"); | ||
52 | } \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/stats3.awk b/ti/runtime/netapi/demo/demo_setup_files/stats3.awk new file mode 100644 index 0000000..4650d32 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/stats3.awk | |||
@@ -0,0 +1,62 @@ | |||
1 | #-------------------------------------- | ||
2 | # awk script to process stats | ||
3 | # output from dpidemo and build | ||
4 | # web page | ||
5 | # stats3-> dump navl mem stata | ||
6 | #_____________________________________ | ||
7 | |||
8 | |||
9 | BEGIN { state=0; | ||
10 | printf("<HTML>\n"); | ||
11 | printf("</HEAD>\n"); | ||
12 | printf("<BODY>\n"); | ||
13 | printf("<H2> DPI Memory Utilization Statistics </H2>\n"); | ||
14 | |||
15 | } | ||
16 | |||
17 | // { | ||
18 | if (state==1) | ||
19 | { | ||
20 | if ($0 ~"-------------") | ||
21 | { | ||
22 | } | ||
23 | else if (NF==1) | ||
24 | { | ||
25 | printf("<tr> "); | ||
26 | printf("<td> %s </td> ",$1); | ||
27 | printf("</tr> \n"); | ||
28 | } | ||
29 | else if (NF==3) | ||
30 | { | ||
31 | printf("<tr> "); | ||
32 | printf("<td> </td> \n"); | ||
33 | printf("<td> </td> \n"); | ||
34 | for(i=1;i<=NF;i++) { | ||
35 | printf("<td> <b> %s </b> </td> ",$i); | ||
36 | } | ||
37 | printf("</tr> \n"); | ||
38 | } | ||
39 | |||
40 | |||
41 | else | ||
42 | { | ||
43 | printf("<tr> "); | ||
44 | printf("<td> </td> \n"); | ||
45 | for(i=1;i<=NF;i++) { | ||
46 | printf("<td> %s </td> ",$i); | ||
47 | } | ||
48 | printf("</tr> \n"); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | /packets captured/ {if (state==0) {state=1; printf("<table>\n");}} | ||
53 | /Peak allocated/ {if(state==1) {state=2; printf("</table>");}} | ||
54 | |||
55 | |||
56 | |||
57 | END { | ||
58 | printf("</PRE>\n"); | ||
59 | printf("<A href=\"\\index.html\"> <p><u> RETURN </u> </p> </A>\n"); | ||
60 | printf("</BODY>\n"); | ||
61 | printf("</HTML>\n"); | ||
62 | } \ No newline at end of file | ||
diff --git a/ti/runtime/netapi/demo/demo_setup_files/transport_dpi_demo_setup.sh b/ti/runtime/netapi/demo/demo_setup_files/transport_dpi_demo_setup.sh new file mode 100755 index 0000000..0772a82 --- /dev/null +++ b/ti/runtime/netapi/demo/demo_setup_files/transport_dpi_demo_setup.sh | |||
@@ -0,0 +1,44 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | export KERNEL_VER=$(uname -r) | ||
4 | |||
5 | # configure thttpd to run cgi scripts | ||
6 | sed -e 's|8080|8080 -c cgi-bin/*|g' -i /etc/init.d/thttpd | ||
7 | # reload the thttpd server | ||
8 | cd /etc/init.d | ||
9 | ./thttpd restart | ||
10 | |||
11 | #copy over web files | ||
12 | |||
13 | cp /etc/transportnetlib/dpi_demo/index.html /srv/www/index.html | ||
14 | chmod -x /srv/www/index.html | ||
15 | cp /etc/transportnetlib/dpi_demo/stats1.awk /srv/www/stats1.awk | ||
16 | cp /etc/transportnetlib/dpi_demo/stats2.awk /srv/www/stats2.awk | ||
17 | cp /etc/transportnetlib/dpi_demo/stats3.awk /srv/www/stats3.awk | ||
18 | cp /etc/transportnetlib/dpi_demo/dpicgi1.sh /srv/www/cgi-bin/dpicgi1.sh | ||
19 | cp /etc/transportnetlib/dpi_demo/dpicgi2.sh /srv/www/cgi-bin/dpicgi2.sh | ||
20 | cp /etc/transportnetlib/dpi_demo/dpicgi3.sh /srv/www/cgi-bin/dpicgi3.sh | ||
21 | cp /etc/transportnetlib/dpi_demo/dpicgi4.sh /srv/www/cgi-bin/dpicgi4.sh | ||
22 | |||
23 | #install kernel module | ||
24 | echo $KERNEL_VER | ||
25 | insmod /lib/modules/$KERNEL_VER/extra/hplibmod.ko | ||
26 | # | ||
27 | # setup linux kernel bridge to handle broadcast packets | ||
28 | ifconfig eth0 0.0.0.0 | ||
29 | # | ||
30 | ifconfig eth1 0.0.0.0 | ||
31 | #create bridge | ||
32 | brctl addbr br0 | ||
33 | #add i/fs to bridge | ||
34 | brctl addif br0 eth0 | ||
35 | # | ||
36 | brctl addif br0 eth1 | ||
37 | # | ||
38 | dhclient br0 | ||
39 | # | ||
40 | ifconfig br0 | ||
41 | # run transport_dpi_demo application | ||
42 | cd /usr/bin | ||
43 | ./transport_dpi_demo | ||
44 | |||
diff --git a/ti/runtime/netapi/demo/makefile_armv7 b/ti/runtime/netapi/demo/makefile_armv7 new file mode 100755 index 0000000..7be82df --- /dev/null +++ b/ti/runtime/netapi/demo/makefile_armv7 | |||
@@ -0,0 +1,65 @@ | |||
1 | #******************************************************************************* | ||
2 | #* FILE PURPOSE: Top level makefile for Creating Component Libraries for ARM | ||
3 | #* architectures | ||
4 | #******************************************************************************* | ||
5 | #* FILE NAME: makefile | ||
6 | #* | ||
7 | #* DESCRIPTION: Defines Compiler tools paths, libraries , Build Options | ||
8 | #* | ||
9 | #* | ||
10 | #******************************************************************************* | ||
11 | #* | ||
12 | # (Mandatory) Specify where various tools are installed. | ||
13 | |||
14 | # Output for prebuilt generated libraries | ||
15 | export ARMV7LIBDIR ?= ./lib | ||
16 | |||
17 | #Enable the following to build for tci6614 | ||
18 | |||
19 | |||
20 | # ROOT Directory | ||
21 | export ROOTDIR := ../../.. | ||
22 | |||
23 | |||
24 | # INCLUDE Directory | ||
25 | export INCDIR := ../;$(PDK_INSTALL_PATH);$(ROOTDIR) | ||
26 | |||
27 | # Common Macros used in make | ||
28 | |||
29 | ifndef RM | ||
30 | export RM = rm -f | ||
31 | endif | ||
32 | |||
33 | ifndef CP | ||
34 | export CP = cp -p | ||
35 | endif | ||
36 | |||
37 | export MKDIR = mkdir -p | ||
38 | |||
39 | ifndef RMDIR | ||
40 | export RMDIR = rm -rf | ||
41 | endif | ||
42 | |||
43 | ifndef SED | ||
44 | export SED = sed | ||
45 | endif | ||
46 | |||
47 | ifndef MAKE | ||
48 | export MAKE = make | ||
49 | endif | ||
50 | |||
51 | |||
52 | # PHONY Targets | ||
53 | .PHONY: all install | ||
54 | |||
55 | # all rule | ||
56 | all: install | ||
57 | |||
58 | install: | ||
59 | install -d $(INSTALL_BIN_BASE_DIR)/plugins | ||
60 | $(CP) -r plugins/* $(INSTALL_INC_BASE_DIR)/plugins | ||
61 | install -d $(INSTALL_INC_BASE_DIR)/navl/include | ||
62 | $(CP) include/navl.h $(INSTALL_INC_BASE_DIR)/navl/include | ||
63 | install -d $(INSTALL_LIB_BASE_DIR) | ||
64 | $(CP) -rp lib/libnavl.so* $(INSTALL_LIB_BASE_DIR) | ||
65 | |||
diff --git a/ti/runtime/netapi/demo/src/Makefile b/ti/runtime/netapi/demo/src/Makefile new file mode 100755 index 0000000..aa84b3a --- /dev/null +++ b/ti/runtime/netapi/demo/src/Makefile | |||
@@ -0,0 +1,95 @@ | |||
1 | # | ||
2 | empty = | ||
3 | space =$(empty) $(empty) | ||
4 | |||
5 | export ARMV7OBJDIR ?= ./obj | ||
6 | export ARMV7BINDIR ?= ./bin | ||
7 | export ARMV7LIBDIR ?= ./lib | ||
8 | export ARMV7SALIBDIR ?= ./lib | ||
9 | |||
10 | DPI_DEMO_SRC_DIR ?= $(PWD) | ||
11 | # INCLUDE Directories | ||
12 | SA_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/sa | ||
13 | QMSS_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/qmss | ||
14 | CPPI_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/cppi | ||
15 | RM_INC_DIR ?= $(PDK_INSTALL_PATH)/ti/drv/rm | ||
16 | #NETAPI_INC_DIR ?= $(NETAPI_INSTALL_PATH)/ti/runtime/netapi | ||
17 | NETAPI_INC_DIR ?= $(NETAPI_INSTALL_PATH) | ||
18 | #HPLIB_INC_DIR ?= $(HPLIB_INSTALL_PATH)/ti/runtime/hplib | ||
19 | HPLIB_INC_DIR ?= $(HPLIB_INSTALL_PATH) | ||
20 | NWAL_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/drv/nwal | ||
21 | PKTLIB_INSTALL_PATH ?= $(PDK_INSTALL_PATH)/ti/runtime/pktlib | ||
22 | NAVL_LIB_DIR ?= $(DPI_DEMO_SRC_DIR)/../lib | ||
23 | # Set NETAPI INSTALL PATH to Transport SDK for default | ||
24 | |||
25 | #NT_RM_OBJS = $(ARMV7OBJDIR)/netapi/utils/sockutils.o $(ARMV7OBJDIR)/netapi/utils/netapi_util_rm.o | ||
26 | |||
27 | #TRIE_OBJS=$(ARMV7OBJDIR)/netapi/test/trie.o | ||
28 | |||
29 | |||
30 | DPI_DEMO_OBJS= $(ARMV7OBJDIR)/dpi_demo_git/src/dpi_demo.o $(ARMV7OBJDIR)/dpi_demo_git/src/navl_wrapper.o $(ARMV7OBJDIR)/dpi_demo_git/src/navl_external_posix.o | ||
31 | |||
32 | # Support Libraries used by dpi-demo | ||
33 | CSL_DEVICE ?= -DDEVICE_K2E -DNSS_GEN2 | ||
34 | QMSS_LIB = -lqmss | ||
35 | CPPI_LIB = -lcppi | ||
36 | PA_LIB = -lpa2 | ||
37 | NWAL_LIB = -lnwalsa_k2e | ||
38 | SA_LIB = -lsa | ||
39 | RM_LIB = -lrm | ||
40 | PKTLIB_LIB = -lpktlib | ||
41 | NETAPI_LIB =-lnetapi_k2e | ||
42 | HP_LIB = -lhplib_k2e | ||
43 | NAVL_LIB = -lnavl | ||
44 | |||
45 | local_base=/usr/local | ||
46 | LDFLAGS = -L. -L$(local_base)/lib | ||
47 | |||
48 | LIBS = -static $(QMSS_LIB) $(CPPI_LIB) $(PA_LIB) $(PKTLIB_LIB) $(NETAPI_LIB) $(HP_LIB) $(SA_LIB) $(NWAL_LIB) $(RM_LIB) -Wl,-Bdynamic | ||
49 | |||
50 | LIBS += $(NAVL_LIB) -lstdc++ -lgcc_s | ||
51 | EXE_EXTN = | ||
52 | |||
53 | SYSTYPE:=$(shell uname) | ||
54 | ifeq ($(SYSTYPE), Linux) | ||
55 | LIBS += -ldl -lm | ||
56 | else | ||
57 | LIBS += -lexecinfo | ||
58 | endif | ||
59 | |||
60 | ifdef CROSS_TOOL_INSTALL_PATH | ||
61 | ## Support backwards compatibility with KeyStone1 approach | ||
62 | CC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc | ||
63 | AC = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)as | ||
64 | AR = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)ar | ||
65 | LD = $(CROSS_TOOL_INSTALL_PATH)/$(CROSS_TOOL_PRFX)gcc | ||
66 | endif | ||
67 | |||
68 | INCLUDE = -I. -I$(local_base)/include -I../ -I$(HPLIB_INC_DIR) -I$(NETAPI_INC_DIR) -I$(PDK_INSTALL_PATH) -I$(NWAL_INSTALL_PATH) -I$(PKTLIB_INSTALL_PATH) -I$(SA_INSTALL_PATH) -I$(QMSS_INC_DIR) -I$(CPPI_INC_DIR) -I$(RM_INC_DIR) $(CSL_DEVICE) | ||
69 | |||
70 | CFLAGS += $(DEBUG_FLAG) -D__ARMv7 -D_VIRTUAL_ADDR_SUPPORT -D__LINUX_USER_SPACE -D_LITTLE_ENDIAN=1 -DNWAL_ENABLE_SA -DMAKEFILE_BUILD -D _GNU_SOURCE | ||
71 | # Linker options | ||
72 | INTERNALLINKDEFS = -Wl,--start-group $(LIBS) -Wl,--end-group -lrt -pthread -L$(ARMV7LIBDIR) -L$(ARMV7SALIBDIR) -L$(NAVL_LIB_DIR) | ||
73 | |||
74 | all: tests | ||
75 | |||
76 | tests: $(ARMV7BINDIR)/dpi_demo_git/demo/.created $(ARMV7BINDIR)/dpi_demo_git/demo/dpi_demo_$(DEVICE) | ||
77 | |||
78 | clean: | ||
79 | rm -f $(ARMV7OBJDIR)/dpi_demo/demo/*.o | ||
80 | rm -f $(ARMV7BINDIR)/dpi_demo/demo/* | ||
81 | |||
82 | $(ARMV7OBJDIR)/dpi_demo_git/src/%.o: %.c $(ARMV7OBJDIR)/dpi_demo_git/src/.created | ||
83 | @echo compiling $< | ||
84 | $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@ | ||
85 | |||
86 | $(ARMV7OBJDIR)/dpi_demo_git/src/.created: | ||
87 | @mkdir -p $(ARMV7OBJDIR)/dpi_demo_git/src/ | ||
88 | |||
89 | $(ARMV7BINDIR)/dpi_demo_git/demo/.created: | ||
90 | @mkdir -p $(ARMV7BINDIR)/dpi_demo_git/demo/ | ||
91 | |||
92 | $(ARMV7BINDIR)/dpi_demo_git/demo/dpi_demo_$(DEVICE): $(DPI_DEMO_OBJS) | ||
93 | echo 'test123' | ||
94 | #$(CC) $(LDFLAGS) $(DPI_DEMO_OBJS) $(INTERNALLINKDEFS) $(INCLUDE) -rdynamic ../lib/libnavl.so -o $(ARMV7BINDIR)/dpi_demo_git/demo/dpi_demo_$(DEVICE)$(EXE_EXTN) | ||
95 | $(CC) $(LDFLAGS) $(DPI_DEMO_OBJS) $(INTERNALLINKDEFS) $(INCLUDE) -o $(ARMV7BINDIR)/dpi_demo_git/demo/dpi_demo_$(DEVICE)$(EXE_EXTN) | ||
diff --git a/ti/runtime/netapi/demo/src/navl_external_posix.c b/ti/runtime/netapi/demo/src/navl_external_posix.c new file mode 100755 index 0000000..8ee00ab --- /dev/null +++ b/ti/runtime/netapi/demo/src/navl_external_posix.c | |||
@@ -0,0 +1,119 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <ctype.h> | ||
4 | #include <string.h> | ||
5 | #include <time.h> | ||
6 | #include <arpa/inet.h> | ||
7 | #include <sys/time.h> | ||
8 | #include <math.h> | ||
9 | #include <pthread.h> | ||
10 | #include <unistd.h> | ||
11 | #include <stdarg.h> | ||
12 | #include <sys/types.h> | ||
13 | #include <sys/socket.h> | ||
14 | #include <netinet/in.h> | ||
15 | #include <arpa/inet.h> | ||
16 | #include "navl/navl.h" | ||
17 | #include "navl_wrapper.h" | ||
18 | extern navl_global_dpi_stats *pDpiStats; | ||
19 | |||
20 | |||
21 | void* our_malloc(size_t n) | ||
22 | { | ||
23 | pDpiStats->malloc_inst+=1; | ||
24 | pDpiStats->malloc_bytes+= n; | ||
25 | return (malloc(n)); | ||
26 | } | ||
27 | int null_log_message(const char *level, const char *func, const char *format, ... ) | ||
28 | { | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | int printf_log_message(const char *level, const char *func, const char *format, ... ) | ||
33 | { | ||
34 | int res = 0; | ||
35 | char buf[4096]; | ||
36 | va_list va; | ||
37 | va_start(va, format); | ||
38 | |||
39 | res = snprintf(buf, 4096, "%s: %s: ", level, func); | ||
40 | res += vsnprintf(buf + res, 4096 - res, format, va); | ||
41 | navl_diag_printf(buf); | ||
42 | va_end(va); | ||
43 | return res; | ||
44 | } | ||
45 | |||
46 | void bind_navl_externals() | ||
47 | { | ||
48 | /* memory allocation */ | ||
49 | navl_malloc_local = our_malloc; | ||
50 | navl_free_local = free; | ||
51 | navl_malloc_shared = our_malloc; | ||
52 | navl_free_shared = free; | ||
53 | |||
54 | /* ctype */ | ||
55 | navl_islower = islower; | ||
56 | navl_isupper = isupper; | ||
57 | navl_tolower = tolower; | ||
58 | navl_toupper = toupper; | ||
59 | navl_isalnum = isalnum; | ||
60 | navl_isspace = isspace; | ||
61 | navl_isdigit = isdigit; | ||
62 | |||
63 | /* string functions */ | ||
64 | navl_atoi = atoi; | ||
65 | navl_memcpy = memcpy; | ||
66 | navl_memcmp = memcmp; | ||
67 | navl_memset = memset; | ||
68 | navl_strcasecmp = strcasecmp; | ||
69 | navl_strchr = (const char* (*)(const char*, int))strchr; | ||
70 | navl_strrchr = (const char* (*)(const char*, int))strrchr; | ||
71 | navl_strcmp = strcmp; | ||
72 | navl_strncmp = strncmp; | ||
73 | navl_strcpy = strcpy; | ||
74 | navl_strncpy = strncpy; | ||
75 | navl_strerror = strerror; | ||
76 | navl_strftime = (size_t (*)(char*, size_t, const char*, const struct navl_tm*))strftime; | ||
77 | navl_strlen = strlen; | ||
78 | navl_strpbrk = (const char* (*)(const char*, const char*))strpbrk; | ||
79 | navl_strstr = (const char* (*)(const char*, const char*))strstr; | ||
80 | navl_strtol = strtol; | ||
81 | |||
82 | /* input/output */ | ||
83 | navl_printf = printf; | ||
84 | navl_sprintf = sprintf; | ||
85 | navl_snprintf = snprintf; | ||
86 | navl_sscanf = sscanf; | ||
87 | navl_putchar = putchar; | ||
88 | navl_puts = puts; | ||
89 | navl_diag_printf = printf; | ||
90 | |||
91 | /* time */ | ||
92 | navl_gettimeofday = (int (*)(struct navl_timeval*, void*))gettimeofday; | ||
93 | navl_mktime = (navl_time_t (*)(struct navl_tm*))mktime; | ||
94 | |||
95 | /* math */ | ||
96 | navl_log = log; | ||
97 | navl_fabs = fabs; | ||
98 | |||
99 | #if 0 | ||
100 | /* network */ | ||
101 | #ifndef __mips__ | ||
102 | navl_htonl = htonl; | ||
103 | navl_htons = htons; | ||
104 | navl_ntohl = ntohl; | ||
105 | navl_ntohs = ntohs; | ||
106 | #endif | ||
107 | #endif | ||
108 | /* system */ | ||
109 | navl_abort = abort; | ||
110 | navl_get_thread_id = (unsigned long (*)(void))pthread_self; | ||
111 | |||
112 | /* navl specific */ | ||
113 | #ifdef DEBUG | ||
114 | navl_log_message = printf_log_message; | ||
115 | #else | ||
116 | navl_log_message = null_log_message; | ||
117 | #endif | ||
118 | } | ||
119 | |||
diff --git a/ti/runtime/netapi/demo/src/navl_wrapper.c b/ti/runtime/netapi/demo/src/navl_wrapper.c new file mode 100755 index 0000000..5c3737e --- /dev/null +++ b/ti/runtime/netapi/demo/src/navl_wrapper.c | |||
@@ -0,0 +1,892 @@ | |||
1 | #define __STDC_FORMAT_MACROS | ||
2 | #include <inttypes.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <signal.h> | ||
7 | #include <getopt.h> | ||
8 | #include <errno.h> | ||
9 | #include <assert.h> | ||
10 | #include <stdarg.h> | ||
11 | #include "ti/runtime/hplib/hplib.h" | ||
12 | #include "ti/runtime/netapi/netapi_types.h" | ||
13 | #include "navl_wrapper.h" | ||
14 | /* timing */ | ||
15 | |||
16 | #define netapi_timing_start hplib_mUtilGetPmuCCNT | ||
17 | |||
18 | navl_wrapper_cfg_info_t *pNavlCfg; | ||
19 | navl_global_dpi_stats *pDpiStats; | ||
20 | void* pShmBase; | ||
21 | void *pShmEntry; | ||
22 | |||
23 | //int free_inst=0; | ||
24 | |||
25 | static unsigned long long timing=0LL; | ||
26 | |||
27 | static char last_url[256]; | ||
28 | int class=0; | ||
29 | void clear_pkt_stats(); | ||
30 | void navl_clear_stats(void) | ||
31 | { | ||
32 | memset(pDpiStats, 0, sizeof(navl_global_dpi_stats)); | ||
33 | pDpiStats->min_time=100000000; | ||
34 | clear_pkt_stats(); | ||
35 | } | ||
36 | void navl_return_stats(int * Pn_ops, int * Pn_class, unsigned long * Pmin_time, unsigned long * Pmax_time, unsigned long long *Ptiming, int * Pmalloc_inst, int *Pmalloc_bytes, int * Pn_err, int *Pfree_inst, unsigned long *Pmalloc_cycles, unsigned long *Pfree_cycles) | ||
37 | { | ||
38 | *Pn_ops=pDpiStats->n_ops; | ||
39 | *Pn_class=pDpiStats->n_class; | ||
40 | *Pmin_time=pDpiStats->min_time; | ||
41 | *Pmax_time=pDpiStats->max_time; | ||
42 | *Ptiming=timing; | ||
43 | *Pmalloc_inst = pDpiStats->malloc_inst; | ||
44 | *Pmalloc_bytes= pDpiStats->malloc_bytes; | ||
45 | *Pn_err=pDpiStats->n_err; | ||
46 | *Pfree_inst = pDpiStats->free_inst; | ||
47 | *Pmalloc_cycles= pDpiStats->malloc_inst ? pDpiStats->malloc_cycles/pDpiStats->malloc_inst: 0; | ||
48 | *Pfree_cycles= pDpiStats->free_inst? pDpiStats->free_cycles/pDpiStats->free_inst : 0; | ||
49 | } | ||
50 | |||
51 | //#define MAX_BIN 10 | ||
52 | static long bins[MAX_BIN]={10000, 12500, 15000,17500,20000, 25000,30000,35000,40000,50000}; | ||
53 | static char* binStr[MAX_BIN]={"10K", "12.5K", "15K","17.5K","20K","25K","30K","35K","40K","50K"}; | ||
54 | |||
55 | void add2bin(long cycles, long p_bins[]) | ||
56 | { | ||
57 | int i; | ||
58 | for(i=0;i<MAX_BIN-1;i++) | ||
59 | if (cycles<bins[i]) {p_bins[i]+=1;return;} | ||
60 | p_bins[MAX_BIN-1] += 1; //max | ||
61 | } | ||
62 | |||
63 | |||
64 | |||
65 | navl_mcb_t *g_reader = NULL; | ||
66 | const char *g_exename = NULL; | ||
67 | |||
68 | static int navl_wrapper_init(int argc, char *argv[]); | ||
69 | static void *navl_wrapper_malloc(size_t); | ||
70 | static void navl_wrapper_free(void *); | ||
71 | static int navl_wrapper_log_message(const char *level, const char *func, const char *format, ...); | ||
72 | |||
73 | static int navl_classify_callback(navl_handle_t handle, navl_result_t result, navl_state_t state, navl_conn_t conn, void *arg, int error); | ||
74 | |||
75 | static void navl_wrapper_mem_stat_print(); | ||
76 | |||
77 | /* external definitions */ | ||
78 | void bind_navl_externals(); | ||
79 | |||
80 | void navl_set_verbose(void) | ||
81 | { | ||
82 | g_reader->option_verbose=!g_reader->option_verbose; | ||
83 | printf(">**DPI Now in %s mode\n",g_reader->option_verbose?"verbose":"nonverbose"); | ||
84 | } | ||
85 | void navl_dump_conn_info() | ||
86 | { | ||
87 | navl_diag(g_reader->navl, "TCP", NULL); | ||
88 | } | ||
89 | |||
90 | |||
91 | #define navl_wrapper_error() \ | ||
92 | do { \ | ||
93 | fprintf(stderr, "%s failed in %s:%u", g_exename, __FUNCTION__, __LINE__); \ | ||
94 | if (g_reader) { \ | ||
95 | if (g_reader->error_navl) \ | ||
96 | fprintf(stderr, " with navl error %s", get_error_string(navl_error_get(g_reader->navl))); \ | ||
97 | } \ | ||
98 | fprintf(stderr, "\n"); \ | ||
99 | } while (0) | ||
100 | |||
101 | int navl_setup(void) | ||
102 | { | ||
103 | return (navl_wrapper_init(0, NULL)); | ||
104 | } | ||
105 | |||
106 | |||
107 | static const char * | ||
108 | get_state_string(navl_state_t state) | ||
109 | { | ||
110 | switch (state) | ||
111 | { | ||
112 | case NAVL_STATE_INSPECTING: | ||
113 | return "INSPECTING"; | ||
114 | case NAVL_STATE_MONITORING: | ||
115 | return "MONITORING"; | ||
116 | case NAVL_STATE_CLASSIFIED: | ||
117 | return "CLASSIFIED"; | ||
118 | case NAVL_STATE_TERMINATED: | ||
119 | return "TERMINATED"; | ||
120 | default: | ||
121 | return "UNKNOWN"; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | static const char * | ||
126 | get_confidence_string(int confidence) | ||
127 | { | ||
128 | switch (confidence) | ||
129 | { | ||
130 | case 50: | ||
131 | return "PORT"; | ||
132 | case 100: | ||
133 | return "DPI"; | ||
134 | default: | ||
135 | return "NONE"; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | static const char * | ||
140 | get_error_string(int error) | ||
141 | { | ||
142 | switch (error) | ||
143 | { | ||
144 | case 0: | ||
145 | return "None"; | ||
146 | case ENOMEM: | ||
147 | return "No memory available"; | ||
148 | case EPROTO: | ||
149 | return "Protocol error"; | ||
150 | case ENOTCONN: | ||
151 | return "No connection allocated"; | ||
152 | case EEXIST: | ||
153 | return "Object exists"; | ||
154 | case EINVAL: | ||
155 | return "Invalid parameter"; | ||
156 | case ECANCELED: | ||
157 | return "Operation cancelled"; | ||
158 | case ENOENT: | ||
159 | return "No such file or directory"; | ||
160 | case EPROTONOSUPPORT: | ||
161 | return "Protocol not supported"; | ||
162 | default: | ||
163 | return "Unknown"; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | static int | ||
168 | navl_wrapper_init(int argc, char *argv[]) | ||
169 | { | ||
170 | static navl_mcb_t reader; | ||
171 | |||
172 | int ret; | ||
173 | int i; | ||
174 | |||
175 | g_reader = &reader; | ||
176 | |||
177 | g_reader->navl = -1; | ||
178 | |||
179 | g_reader->config_capfile = NULL; | ||
180 | g_reader->config_plugins = "plugins"; | ||
181 | g_reader->config_num_proto = 0; | ||
182 | g_reader->config_conn_id_attr = 0; | ||
183 | g_reader->config_http_attr = 0; | ||
184 | g_reader->config_num_memctx = NUM_MEM_CTX; | ||
185 | g_reader->config_num_memobj = NUM_MEM_OBJ; | ||
186 | |||
187 | g_reader->option_dpi = 1; | ||
188 | g_reader->option_simple = 0; | ||
189 | g_reader->option_track_memory = 1; | ||
190 | g_reader->option_limit_memory = 0; | ||
191 | g_reader->option_realtime_mode = 1; | ||
192 | g_reader->option_verbose = 0; | ||
193 | |||
194 | g_reader->error_navl = 0; | ||
195 | |||
196 | g_reader->stats_pkt[0] = NULL; | ||
197 | g_reader->stats_pkt[1] = NULL; | ||
198 | |||
199 | g_reader->stats_conns = 0; | ||
200 | |||
201 | g_reader->running = 1; | ||
202 | g_reader->alloc_curr = 0; | ||
203 | g_reader->alloc_peak = 0; | ||
204 | |||
205 | g_exename = "dpi_demo"; | ||
206 | |||
207 | |||
208 | /* allocate segment for shared memory for packet stats */ | ||
209 | /* allocate packet statistics */ | ||
210 | pShmBase = hplib_shmOpen(); | ||
211 | if (pShmBase) | ||
212 | { | ||
213 | pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_1); | ||
214 | pNavlCfg = (navl_wrapper_cfg_info_t*)pShmEntry; | ||
215 | memset(pNavlCfg, | ||
216 | 0, | ||
217 | sizeof(navl_wrapper_pkt_stat_t) * MAX_PROTOCOLS *NUM_FP_PROCS+ sizeof(navl_wrapper_cfg_info_t)); | ||
218 | pNavlCfg = (navl_wrapper_cfg_info_t*)pShmEntry; | ||
219 | pNavlCfg->num_protocols = g_reader->config_num_proto; | ||
220 | g_reader->stats_pkt[0] = pShmEntry + sizeof(navl_wrapper_cfg_info_t); | ||
221 | |||
222 | g_reader->stats_pkt[1] = pShmEntry + sizeof(navl_wrapper_cfg_info_t) + | ||
223 | (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS); | ||
224 | |||
225 | for(i=0;i< MAX_PROTOCOLS;i++) | ||
226 | { | ||
227 | g_reader->stats_pkt[0][i].cycles_min=10000000; | ||
228 | g_reader->stats_pkt[1][i].cycles_min=10000000; | ||
229 | g_reader->stats_pkt[0][i].cycles_max=0; | ||
230 | g_reader->stats_pkt[1][i].cycles_max=0; | ||
231 | } | ||
232 | |||
233 | pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_2); | ||
234 | pDpiStats = (navl_global_dpi_stats*) pShmEntry; | ||
235 | } | ||
236 | else | ||
237 | { | ||
238 | printf("navl_wrapper_init: hplib_shmOpen failure\n"); | ||
239 | return NETAPI_ERR_NOMEM; | ||
240 | } | ||
241 | |||
242 | /* EXTERNAL BINDINGS GO HERE */ | ||
243 | { | ||
244 | /* Bind the platform specific functions. */ | ||
245 | bind_navl_externals(); | ||
246 | |||
247 | /* Private overrides for this example application. */ | ||
248 | navl_log_message = navl_wrapper_log_message; | ||
249 | if (g_reader->option_track_memory) | ||
250 | { | ||
251 | navl_malloc_local = navl_wrapper_malloc; | ||
252 | navl_free_local = navl_wrapper_free; | ||
253 | navl_malloc_shared = navl_wrapper_malloc; | ||
254 | navl_free_shared = navl_wrapper_free; | ||
255 | |||
256 | memset(g_reader->stats_mem, 0, sizeof(g_reader->stats_mem)); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /* open the navl library */ | ||
261 | if ((g_reader->navl = navl_open(g_reader->config_plugins)) == -1) | ||
262 | navl_wrapper_error(); | ||
263 | |||
264 | /* set logging level to "error | fatal" */ | ||
265 | if (navl_config_set(g_reader->navl, "system.loglevel", "48") == -1) | ||
266 | navl_wrapper_error(); | ||
267 | |||
268 | /* determine the max protocol index */ | ||
269 | if ((ret = navl_proto_max_index(g_reader->navl)) == -1) | ||
270 | { | ||
271 | printf("navl_proto_max_index error\n"); | ||
272 | navl_wrapper_error(); | ||
273 | } | ||
274 | |||
275 | /* the number of protocols is the max + 1 */ | ||
276 | g_reader->config_num_proto = (ret + 1); | ||
277 | pNavlCfg->num_protocols = g_reader->config_num_proto; | ||
278 | |||
279 | return NETAPI_ERR_OK; | ||
280 | } | ||
281 | |||
282 | //per thread init. Call this in worker thread context | ||
283 | int navl_per_thread_init(uint32_t thread_num) | ||
284 | { | ||
285 | int ret; | ||
286 | int c; | ||
287 | |||
288 | /* initialize this thread for classification */ | ||
289 | if (navl_init(g_reader->navl)) | ||
290 | { | ||
291 | printf("navl_init error\n"); | ||
292 | navl_wrapper_error(); | ||
293 | } | ||
294 | #if 0 | ||
295 | /* enable connection tracking */ | ||
296 | if (navl_attr_enable(g_reader->navl, "conn.id", 1) == -1) | ||
297 | navl_wrapper_error(); | ||
298 | |||
299 | #ifdef HTTP_ATTRIB | ||
300 | /* enable http url */ | ||
301 | if (navl_attr_enable(g_reader->navl, "http.request.url",1) == -1) | ||
302 | navl_wrapper_error(); | ||
303 | #endif | ||
304 | |||
305 | /* lookup the key for conn.id */ | ||
306 | if ((g_reader->config_conn_id_attr = navl_attr_key_get(g_reader->navl, "conn.id")) == -1) | ||
307 | navl_wrapper_error(); | ||
308 | #ifdef HTTP_ATTRIB | ||
309 | /* lookup the key for http.request.host */ | ||
310 | if ((g_reader->config_http_attr = navl_attr_key_get(g_reader->navl, "http.request.url")) == -1) | ||
311 | navl_wrapper_error(); | ||
312 | #endif | ||
313 | #endif | ||
314 | /* simulated realtime */ | ||
315 | if (g_reader->option_realtime_mode == 2) | ||
316 | navl_clock_set_mode(g_reader->navl, 1); | ||
317 | |||
318 | |||
319 | #if 0 | ||
320 | /* determine the max protocol index */ | ||
321 | if ((ret = navl_proto_max_index(g_reader->navl)) == -1) | ||
322 | { | ||
323 | printf("navl_proto_max_index error\n"); | ||
324 | navl_wrapper_error(); | ||
325 | } | ||
326 | |||
327 | /* the number of protocols is the max + 1 */ | ||
328 | g_reader->config_num_proto = (ret + 1); | ||
329 | #endif | ||
330 | |||
331 | |||
332 | /* now fetch all the protocol name ahead of time do we don't have to lookup them up on each packet */ | ||
333 | for (ret = 0; ret != g_reader->config_num_proto; ret++) | ||
334 | navl_proto_get_name(g_reader->navl, ret, | ||
335 | g_reader->stats_pkt[thread_num-1][ret].name, | ||
336 | sizeof(g_reader->stats_pkt[thread_num-1][ret].name)); | ||
337 | |||
338 | |||
339 | /* fetch all the memory tag names */ | ||
340 | for (c = 0; c < NUM_MEM_CTX; c++) | ||
341 | navl_memory_ctx_name(g_reader->navl, c, g_reader->ctx_name[c], sizeof(g_reader->ctx_name[c])); | ||
342 | for (c = 0; c < NUM_MEM_OBJ; c++) | ||
343 | navl_memory_obj_name(g_reader->navl, c, g_reader->obj_name[c], sizeof(g_reader->obj_name[c])); | ||
344 | |||
345 | return 1; | ||
346 | } | ||
347 | |||
348 | |||
349 | static uint64_t | ||
350 | msec_time(struct timeval *tv) | ||
351 | { | ||
352 | return ((uint64_t)tv->tv_sec * 1000) + (tv->tv_usec / 1000); | ||
353 | } | ||
354 | |||
355 | static void | ||
356 | msec_delay(uint64_t msecs) | ||
357 | { | ||
358 | struct timeval tv = { msecs / 1000, (msecs % 1000) * 1000 }; | ||
359 | select(0, 0, 0, 0, &tv); | ||
360 | } | ||
361 | |||
362 | #if 1 | ||
363 | typedef struct | ||
364 | { | ||
365 | const uint8_t *data; | ||
366 | uint32_t size; | ||
367 | uint32_t sequence; | ||
368 | int32_t appidx; | ||
369 | uint64_t connid; | ||
370 | } navl_wrapper_packet_t; | ||
371 | #else | ||
372 | typedef struct | ||
373 | { | ||
374 | const uint8_t *data; | ||
375 | uint32_t size; | ||
376 | uint32_t sequence; | ||
377 | int32_t appidx; | ||
378 | int32_t num_cb; | ||
379 | } navl_wrapper_packet_t; | ||
380 | #endif | ||
381 | |||
382 | |||
383 | #if 1 | ||
384 | static int | ||
385 | navl_classify_callback(navl_handle_t handle, | ||
386 | navl_result_t result, | ||
387 | navl_state_t state, | ||
388 | navl_conn_t conn, | ||
389 | void *arg, | ||
390 | int error) | ||
391 | { | ||
392 | int idx, protoid = 0, confidence = 0; | ||
393 | char buf[256] = {0}; | ||
394 | navl_iterator_t it; | ||
395 | navl_wrapper_packet_t *packet = (navl_wrapper_packet_t *)arg; | ||
396 | int threadId =Osal_nwalGetProcId(); | ||
397 | |||
398 | packet->appidx = navl_app_get(g_reader->navl, result, &confidence); | ||
399 | if((state==NAVL_STATE_CLASSIFIED) || | ||
400 | (state==NAVL_STATE_TERMINATED) || | ||
401 | (state==NAVL_STATE_MONITORING)) | ||
402 | { | ||
403 | pDpiStats->n_class+=1; | ||
404 | class =1; | ||
405 | } | ||
406 | else | ||
407 | class=0; | ||
408 | #if 0 | ||
409 | if (navl_proto_find_index(g_reader->navl, "HTTP") == packet->appidx) | ||
410 | { | ||
411 | it = navl_proto_find(g_reader->navl, result, navl_proto_find_index(g_reader->navl, "HTTP")); | ||
412 | if (navl_proto_valid(g_reader->navl, it)) | ||
413 | navl_attr_get(g_reader->navl, | ||
414 | it, | ||
415 | g_reader->config_http_attr, | ||
416 | &last_url, | ||
417 | sizeof(last_url)); | ||
418 | } | ||
419 | #endif | ||
420 | if (g_reader->option_verbose) | ||
421 | { | ||
422 | /* Build the stack string */ | ||
423 | for (idx = 0, it = navl_proto_first(g_reader->navl, result); navl_proto_valid(g_reader->navl, it); navl_proto_next(g_reader->navl, it)) | ||
424 | { | ||
425 | protoid = navl_proto_get_index(g_reader->navl, it); | ||
426 | if (!packet->connid) | ||
427 | { | ||
428 | if (navl_proto_find_index(g_reader->navl, "IP") == protoid) | ||
429 | { | ||
430 | #if 0 | ||
431 | navl_attr_get(g_reader->navl, it, g_reader->config_conn_id_attr, &packet->connid, sizeof(packet->connid)); | ||
432 | if (packet->connid > g_reader->stats_conns) | ||
433 | g_reader->stats_conns = packet->connid; | ||
434 | #endif | ||
435 | } | ||
436 | } | ||
437 | idx += sprintf(&buf[idx], "/%s", g_reader->stats_pkt[threadId-1][protoid].name); | ||
438 | } | ||
439 | printf(" Pkt: %u (%u bytes), Conn: %" PRIu64 ", App: %s (%s), State: %s, Stack: %s, Error: %s\n", packet->sequence | ||
440 | , packet->size, packet->connid, g_reader->stats_pkt[threadId-1][packet->appidx].name | ||
441 | , get_confidence_string(confidence), get_state_string(state), buf, get_error_string(error)); | ||
442 | } | ||
443 | |||
444 | /* Continue tracking the flow */ | ||
445 | return 0; | ||
446 | } | ||
447 | #else | ||
448 | static int | ||
449 | navl_classify_callback(navl_handle_t handle, | ||
450 | navl_result_t result, | ||
451 | navl_state_t state, | ||
452 | navl_conn_t conn, | ||
453 | void *arg, | ||
454 | int error) | ||
455 | { | ||
456 | int idx, protoid = 0, confidence = 0; | ||
457 | char buf[256] = {0}; | ||
458 | navl_iterator_t it; | ||
459 | navl_conn_id_t conn_id = navl_conn_id_get(handle, conn); | ||
460 | navl_wrapper_packet_t *packet = (navl_wrapper_packet_t *)arg; | ||
461 | |||
462 | /* Always display the outer packet; optionally display encapsulated data */ | ||
463 | if (!packet->num_cb || g_reader->option_tunnel) | ||
464 | { | ||
465 | packet->appidx = navl_app_get(g_reader->navl, result, &confidence); | ||
466 | |||
467 | if (g_reader->option_verbose) | ||
468 | { | ||
469 | if (conn_id > g_reader->stats_conns) | ||
470 | g_reader->stats_conns = conn_id; | ||
471 | |||
472 | /* Build the stack string */ | ||
473 | for (idx = 0, it = navl_proto_first(g_reader->navl, result); navl_proto_valid(g_reader->navl, it); navl_proto_next(g_reader->navl, it)) | ||
474 | { | ||
475 | protoid = navl_proto_get_index(g_reader->navl, it); | ||
476 | idx += sprintf(&buf[idx], "/%s", g_reader->stats_pkt[fp_thread][protoid].name); | ||
477 | } | ||
478 | |||
479 | printf(" Pkt: %u (%u bytes), Conn: %" PRIu64 ", App: %s (%s), State: %s, Stack: %s, Error: %s\n" | ||
480 | , packet->sequence, packet->size, conn_id, g_reader->stats_pkt[fp_thread][packet->appidx].name | ||
481 | , get_confidence_string(confidence), get_state_string(state), buf, get_error_string(error)); | ||
482 | } | ||
483 | } | ||
484 | |||
485 | packet->num_cb++; | ||
486 | |||
487 | /* Continue tracking the flow */ | ||
488 | return 0; | ||
489 | } | ||
490 | #endif | ||
491 | |||
492 | //process the packet | ||
493 | __thread navl_wrapper_packet_t packet = { NULL, 0, 0 }; | ||
494 | int navl_process_pkt(unsigned char *p_pkt, int len) | ||
495 | { | ||
496 | volatile unsigned long v1; | ||
497 | volatile unsigned long v2; | ||
498 | unsigned long temp=0; | ||
499 | uint64_t last = 0; | ||
500 | uint64_t next = 0; | ||
501 | unsigned long long mf1; | ||
502 | unsigned long long mf2; | ||
503 | int threadId =Osal_nwalGetProcId(); | ||
504 | mf1= pDpiStats->malloc_cycles+pDpiStats->free_cycles; | ||
505 | |||
506 | v1 = netapi_timing_start(); | ||
507 | |||
508 | /* update the current packet */ | ||
509 | packet.sequence++; | ||
510 | packet.size = len; | ||
511 | packet.appidx = 0; | ||
512 | //packet.connid = 0; | ||
513 | packet.data=p_pkt; | ||
514 | |||
515 | /* "real" realtime */ | ||
516 | if (g_reader->option_realtime_mode == 1) | ||
517 | { | ||
518 | //next = msec_time(0LL);//dal -> get ts here | ||
519 | next=0LL; | ||
520 | if (last) | ||
521 | msec_delay(next - last); | ||
522 | last = next; | ||
523 | } | ||
524 | if (navl_classify(g_reader->navl, | ||
525 | NAVL_ENCAP_ETH, | ||
526 | packet.data, | ||
527 | packet.size, | ||
528 | NULL, | ||
529 | 0, | ||
530 | navl_classify_callback, | ||
531 | &packet) == -1) | ||
532 | printf(" Pkt: %u (%u bytes), Error: %s\n", packet.sequence, | ||
533 | packet.size, | ||
534 | get_error_string(navl_error_get(g_reader->navl))); | ||
535 | |||
536 | /* Update the stats. If classification was not enabled, then the appidx will be 0 and all packets | ||
537 | * captured will be accumulated there */ | ||
538 | g_reader->stats_pkt[threadId-1][packet.appidx].packets++; | ||
539 | g_reader->stats_pkt[threadId-1][packet.appidx].bytes += packet.size; | ||
540 | if(class) | ||
541 | g_reader->stats_pkt[threadId-1][packet.appidx].class++; | ||
542 | //update timing | ||
543 | v2 = netapi_timing_start(); | ||
544 | temp=v2-v1; | ||
545 | mf2= pDpiStats->malloc_cycles + pDpiStats->free_cycles; | ||
546 | timing+= (unsigned long long) temp; | ||
547 | g_reader->stats_pkt[threadId-1][packet.appidx].cycles += (unsigned long long) temp; | ||
548 | g_reader->stats_pkt[threadId-1][packet.appidx].cycles_nomem += ((unsigned long long) temp - (mf2-mf1)); | ||
549 | |||
550 | if (g_reader->stats_pkt[threadId-1][packet.appidx].cycles_min > temp) | ||
551 | g_reader->stats_pkt[threadId-1][packet.appidx].cycles_min = temp; | ||
552 | |||
553 | if (g_reader->stats_pkt[threadId-1][packet.appidx].cycles_max < temp) | ||
554 | { | ||
555 | g_reader->stats_pkt[threadId-1][packet.appidx].cycles_max = temp; | ||
556 | |||
557 | } | ||
558 | |||
559 | |||
560 | add2bin((temp - (unsigned long)(mf2-mf1)),&g_reader->stats_pkt[threadId-1][packet.appidx].bin_cycles[0]); | ||
561 | pDpiStats->n_ops+=1; | ||
562 | if (temp > pDpiStats->max_time) pDpiStats->max_time = temp; | ||
563 | if (temp< pDpiStats->min_time) pDpiStats->min_time = temp; | ||
564 | return 1; | ||
565 | } | ||
566 | |||
567 | int navl_done(void) | ||
568 | { | ||
569 | navl_fini(g_reader->navl); | ||
570 | navl_close(g_reader->navl); | ||
571 | return 1; | ||
572 | } | ||
573 | |||
574 | void navl_results(int fp_thread) | ||
575 | { | ||
576 | int idx; | ||
577 | int i; | ||
578 | uint64_t total_packets, total_bytes; | ||
579 | void* pShmEntry; | ||
580 | |||
581 | total_packets = 0; | ||
582 | total_bytes = 0; | ||
583 | |||
584 | if (g_reader->option_dpi) | ||
585 | { | ||
586 | printf("\n NAVL DPI stats for CORE ID %d\n", fp_thread + 1); | ||
587 | printf("\n AppProto Packets Class Bytes Cycles/Pkt Cyclesnomem/Pkt (min) (max) "); | ||
588 | for(i=0;i<MAX_BIN;i++) | ||
589 | printf("<%s ",binStr[i]); | ||
590 | printf("\n ----------------------------------------------------------------------------------------------------------------------------------------------------\n"); | ||
591 | } | ||
592 | |||
593 | //for (idx = 0; idx < g_reader->config_num_proto; idx++) | ||
594 | for (idx = 0; idx < pNavlCfg->num_protocols; idx++) | ||
595 | { | ||
596 | if (g_reader->option_dpi) | ||
597 | { | ||
598 | if (g_reader->stats_pkt[fp_thread][idx].packets) | ||
599 | { | ||
600 | /* We need to provide protocol definitions */ | ||
601 | printf(" %-12s%-12" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %ld %ld " , | ||
602 | g_reader->stats_pkt[fp_thread][idx].name, | ||
603 | g_reader->stats_pkt[fp_thread][idx].packets, | ||
604 | g_reader->stats_pkt[fp_thread][idx].class, | ||
605 | g_reader->stats_pkt[fp_thread][idx].bytes, | ||
606 | g_reader->stats_pkt[fp_thread][idx].cycles/g_reader->stats_pkt[fp_thread][idx].packets, | ||
607 | g_reader->stats_pkt[fp_thread][idx].cycles_nomem/g_reader->stats_pkt[fp_thread][idx].packets, | ||
608 | g_reader->stats_pkt[fp_thread][idx].cycles_min, | ||
609 | g_reader->stats_pkt[fp_thread][idx].cycles_max); | ||
610 | for(i=0;i<MAX_BIN;i++) printf("%ld ",g_reader->stats_pkt[fp_thread][idx].bin_cycles[i]); | ||
611 | printf("\n"); | ||
612 | } | ||
613 | } | ||
614 | |||
615 | total_packets += g_reader->stats_pkt[fp_thread][idx].packets; | ||
616 | total_bytes += g_reader->stats_pkt[fp_thread][idx].bytes; | ||
617 | } | ||
618 | |||
619 | if (!total_packets) | ||
620 | printf("\n No packets captured.\n"); | ||
621 | else | ||
622 | printf("\n %" PRIu64 " packets captured (%" PRIu64 " bytes)\n", total_packets, total_bytes); | ||
623 | |||
624 | if (g_reader->stats_conns) | ||
625 | printf(" %" PRIu64 " connections tracked\n", g_reader->stats_conns); | ||
626 | |||
627 | printf("\n"); | ||
628 | if (g_reader->option_track_memory) | ||
629 | navl_wrapper_mem_stat_print(); | ||
630 | |||
631 | |||
632 | if (pNavlCfg->alloc_curr != 0) | ||
633 | printf("Bytes not freed: %" PRIi64 "\n", pNavlCfg->alloc_curr); | ||
634 | |||
635 | if (g_reader->alloc_peak != 0) | ||
636 | printf("Peak allocated: %" PRIi64 "\n", g_reader->alloc_peak); | ||
637 | |||
638 | printf("attr test: last http utl= %s\n",last_url); | ||
639 | } | ||
640 | |||
641 | static void | ||
642 | navl_wrapper_mem_stat_print() | ||
643 | { | ||
644 | int i, j; | ||
645 | navl_wrapper_stat_t *stat; | ||
646 | char *name; | ||
647 | |||
648 | printf(" Curr Peak Fail \n"); | ||
649 | printf("-----------------------------------------------------------------------"); | ||
650 | |||
651 | for (i = 0; i < g_reader->config_num_memctx; i++) | ||
652 | { | ||
653 | stat = &g_reader->stats_mem[i][0]; | ||
654 | if (stat->peak == 0) | ||
655 | continue; | ||
656 | |||
657 | printf("\n\t%s\n", g_reader->ctx_name[i]); | ||
658 | |||
659 | for (j = g_reader->config_num_memobj - 1; j >= 0; j--) | ||
660 | { | ||
661 | navl_wrapper_stat_t *stat = &g_reader->stats_mem[i][j]; | ||
662 | if (stat->peak == 0) | ||
663 | continue; | ||
664 | |||
665 | name = j ? g_reader->obj_name[j] : (char *)"other"; | ||
666 | |||
667 | if (stat->peak || stat->fail) | ||
668 | printf("\t\t%-20s%10" PRIu64 "%10" PRIu64 "%10" PRIu64 "\n", name, stat->curr, stat->peak, stat->fail); | ||
669 | } | ||
670 | } | ||
671 | printf("\n\n"); | ||
672 | } | ||
673 | |||
674 | |||
675 | void navl_results2(int fp_thread) | ||
676 | { | ||
677 | int idx; | ||
678 | int i; | ||
679 | uint64_t total_packets, total_bytes; | ||
680 | void* pShmEntry; | ||
681 | void* pShmBase; | ||
682 | void* pTemp; | ||
683 | navl_wrapper_cfg_info_t *pNavlCfg; | ||
684 | navl_wrapper_pkt_stat_t *pStats1; | ||
685 | navl_wrapper_pkt_stat_t *pStats2; | ||
686 | navl_mcb_t g_reader; | ||
687 | |||
688 | pShmBase = hplib_shmOpen(); | ||
689 | if (pShmBase) | ||
690 | { | ||
691 | pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_1); | ||
692 | pNavlCfg = (navl_wrapper_cfg_info_t*)pTemp; | ||
693 | |||
694 | g_reader.stats_pkt[0] = pTemp + sizeof(navl_wrapper_cfg_info_t); | ||
695 | |||
696 | |||
697 | g_reader.stats_pkt[1] = pTemp + sizeof(navl_wrapper_cfg_info_t) + | ||
698 | (sizeof(navl_wrapper_pkt_stat_t)*pNavlCfg->num_protocols); | ||
699 | } | ||
700 | total_packets = 0; | ||
701 | total_bytes = 0; | ||
702 | |||
703 | //if (g_reader->option_dpi) | ||
704 | { | ||
705 | printf("\n NAVL DPI stats for CORE ID %d\n", fp_thread); | ||
706 | printf("\n AppProto Packets Class Bytes Cycles/Pkt Cyclesnomem/Pkt (min) (max) "); | ||
707 | for(i=0;i<MAX_BIN;i++) | ||
708 | printf("<%s ",binStr[i]); | ||
709 | printf("\n ----------------------------------------------------------------------------------------------------------------------------------------------------\n"); | ||
710 | } | ||
711 | |||
712 | //for (idx = 0; idx < g_reader->config_num_proto; idx++) | ||
713 | for (idx = 0; idx < pNavlCfg->num_protocols; idx++) | ||
714 | { | ||
715 | //if (g_reader->option_dpi) | ||
716 | { | ||
717 | if (g_reader.stats_pkt[fp_thread][idx].packets) | ||
718 | { | ||
719 | /* We need to provide protocol definitions */ | ||
720 | printf(" %-12s%-12" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %ld %ld " , | ||
721 | g_reader.stats_pkt[fp_thread][idx].name, | ||
722 | g_reader.stats_pkt[fp_thread][idx].packets, | ||
723 | g_reader.stats_pkt[fp_thread][idx].class, | ||
724 | g_reader.stats_pkt[fp_thread][idx].bytes, | ||
725 | g_reader.stats_pkt[fp_thread][idx].cycles/g_reader.stats_pkt[fp_thread][idx].packets, | ||
726 | g_reader.stats_pkt[fp_thread][idx].cycles_nomem/g_reader.stats_pkt[fp_thread][idx].packets, | ||
727 | g_reader.stats_pkt[fp_thread][idx].cycles_min, | ||
728 | g_reader.stats_pkt[fp_thread][idx].cycles_max); | ||
729 | for(i=0;i<MAX_BIN;i++) printf("%ld ",g_reader.stats_pkt[fp_thread][idx].bin_cycles[i]); | ||
730 | printf("\n"); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | total_packets += g_reader.stats_pkt[fp_thread][idx].packets; | ||
735 | total_bytes += g_reader.stats_pkt[fp_thread][idx].bytes; | ||
736 | } | ||
737 | |||
738 | if (!total_packets) | ||
739 | printf("\n No packets captured.\n"); | ||
740 | else | ||
741 | printf("\n %" PRIu64 " packets captured (%" PRIu64 " bytes)\n", total_packets, total_bytes); | ||
742 | |||
743 | #if 0 | ||
744 | if (g_reader.stats_conns) | ||
745 | printf(" %" PRIu64 " connections tracked\n", g_reader.stats_conns); | ||
746 | |||
747 | printf("\n"); | ||
748 | //if (g_reader.option_track_memory) | ||
749 | navl_wrapper_mem_stat_print(); | ||
750 | |||
751 | if (pNavlCfg->alloc_curr != 0) | ||
752 | printf("Bytes not freed: %" PRIi64 "\n", pNavlCfg->alloc_curr); | ||
753 | |||
754 | if (g_reader.alloc_peak != 0) | ||
755 | printf("Peak allocated: %" PRIi64 "\n", g_reader.alloc_peak); | ||
756 | |||
757 | printf("attr test: last http utl= %s\n",last_url); | ||
758 | #endif | ||
759 | } | ||
760 | |||
761 | |||
762 | |||
763 | /* Private memory stamp type for tracking memory with navl_wrapper_malloc/free */ | ||
764 | typedef struct | ||
765 | { | ||
766 | size_t size; /* size of allocation */ | ||
767 | short ctx_tag; /* ctx axis */ | ||
768 | short obj_tag; /* obj axis */ | ||
769 | char mem[0]; | ||
770 | } memstamp_t; | ||
771 | |||
772 | static void *navl_wrapper_malloc(size_t size) | ||
773 | { | ||
774 | navl_handle_t handle; | ||
775 | navl_wrapper_stat_t *stat_mem; | ||
776 | int tag; | ||
777 | int ctx_tag, obj_tag; | ||
778 | unsigned long t1; | ||
779 | unsigned long t2; | ||
780 | pDpiStats->malloc_inst+=1; | ||
781 | pDpiStats->malloc_bytes+=size; | ||
782 | t1=netapi_timing_start(); | ||
783 | |||
784 | assert(size); | ||
785 | |||
786 | /* In this context, the handle should be read using navl_handle_get() since | ||
787 | * the application cached handle (in this case g_reader->navl) will not be set | ||
788 | * until navl_open() returns. For this simple test we just assert that the handle | ||
789 | * is infact valid. */ | ||
790 | handle = navl_handle_get(); | ||
791 | assert(handle != 0); | ||
792 | |||
793 | /* Fetch the tags associated with this allocation. They will be used below to record | ||
794 | * statistics about allocations within the library on 2 axis. The upper 16 bits contain | ||
795 | * a memory obj tag and the lower 16 bits contain the allocation context tag. These | ||
796 | * tags are indices, the upper of which is available through navl_memory_ctx_num() | ||
797 | * and navl_memory_obj_num() resp. They are generated dynamically and may differ between | ||
798 | * configurations. These total number of indices are available ONLY AFTER navl_open() | ||
799 | * returns. | ||
800 | */ | ||
801 | tag = navl_memory_tag_get(handle); | ||
802 | obj_tag = (tag >> 16); | ||
803 | ctx_tag = (tag & 0x0000FFFF); | ||
804 | |||
805 | /* You could do something better here and reallocate the matrix */ | ||
806 | if (ctx_tag >= g_reader->config_num_memctx || obj_tag >= g_reader->config_num_memobj) | ||
807 | { | ||
808 | assert(0); | ||
809 | return NULL; | ||
810 | } | ||
811 | |||
812 | stat_mem = &g_reader->stats_mem[ctx_tag][obj_tag]; | ||
813 | |||
814 | /* check limits */ | ||
815 | if (!g_reader->option_limit_memory || (pNavlCfg->alloc_curr + size < g_reader->option_limit_memory)) | ||
816 | { | ||
817 | memstamp_t *ptr = (memstamp_t *)malloc(size + sizeof(memstamp_t)); | ||
818 | if (ptr) | ||
819 | { | ||
820 | /* track peak values */ | ||
821 | if ((pNavlCfg->alloc_curr += size) > g_reader->alloc_peak) | ||
822 | g_reader->alloc_peak = pNavlCfg->alloc_curr; | ||
823 | |||
824 | if ((stat_mem->curr += size) > stat_mem->peak) | ||
825 | stat_mem->peak = stat_mem->curr; | ||
826 | |||
827 | ptr->size = size; | ||
828 | ptr->ctx_tag = ctx_tag; | ||
829 | ptr->obj_tag = obj_tag; | ||
830 | t2=netapi_timing_start(); | ||
831 | pDpiStats->malloc_cycles += (unsigned long long) (t2-t1); | ||
832 | return ptr->mem; | ||
833 | } | ||
834 | } | ||
835 | stat_mem->fail += size; | ||
836 | return NULL; | ||
837 | } | ||
838 | |||
839 | static void | ||
840 | navl_wrapper_free(void *p) | ||
841 | { | ||
842 | unsigned long t1; | ||
843 | unsigned long t2; | ||
844 | pDpiStats->free_inst += 1; | ||
845 | t1=netapi_timing_start(); | ||
846 | if (!p) | ||
847 | return; | ||
848 | |||
849 | memstamp_t *ptr = (memstamp_t *)((char *)p - offsetof(memstamp_t, mem)); | ||
850 | navl_wrapper_stat_t *stat_mem = &g_reader->stats_mem[ptr->ctx_tag][ptr->obj_tag]; | ||
851 | |||
852 | assert(p == ptr->mem); | ||
853 | |||
854 | stat_mem->curr -= ptr->size; | ||
855 | pNavlCfg->alloc_curr -= ptr->size; | ||
856 | |||
857 | free(ptr); | ||
858 | t2=netapi_timing_start(); | ||
859 | pDpiStats->free_cycles += (unsigned long long) (t2-t1); | ||
860 | } | ||
861 | |||
862 | static int | ||
863 | navl_wrapper_log_message(const char *level, const char *func, const char *format, ... ) | ||
864 | { | ||
865 | int res = 0; | ||
866 | char buf[4096]; | ||
867 | va_list va; | ||
868 | va_start(va, format); | ||
869 | |||
870 | res = snprintf(buf, 4096, "%s: %s: ", level, func); | ||
871 | res += vsnprintf(buf + res, 4096 - res, format, va); | ||
872 | printf("%s\n", buf); | ||
873 | va_end(va); | ||
874 | return res; | ||
875 | } | ||
876 | |||
877 | //clear stats | ||
878 | void clear_pkt_stats() | ||
879 | { | ||
880 | int ret, i; | ||
881 | memset(g_reader->stats_pkt[0], 0, (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS)); | ||
882 | memset(g_reader->stats_pkt[1], 0, (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS)); | ||
883 | |||
884 | for (i=0;i < NUM_FP_PROCS;i++) | ||
885 | { | ||
886 | /* now fetch all the protocol name ahead of time do we don't have to lookup them up on each packet */ | ||
887 | for (ret = 0; ret != MAX_PROTOCOLS; ret++) | ||
888 | { | ||
889 | g_reader->stats_pkt[i][ret].cycles_min=10000000; | ||
890 | } | ||
891 | } | ||
892 | } | ||
diff --git a/ti/runtime/netapi/demo/src/navl_wrapper.h b/ti/runtime/netapi/demo/src/navl_wrapper.h new file mode 100755 index 0000000..9ba57b7 --- /dev/null +++ b/ti/runtime/netapi/demo/src/navl_wrapper.h | |||
@@ -0,0 +1,192 @@ | |||
1 | /****************************************************************************** | ||
2 | * FILE PURPOSE: User space access to transport resources on SOC | ||
3 | ****************************************************************************** | ||
4 | * FILE NAME: navl_wrapper.h | ||
5 | * | ||
6 | * DESCRIPTION: NAVL Wrapper definitions and data structures | ||
7 | * | ||
8 | * REVISION HISTORY: | ||
9 | * | ||
10 | * Copyright (c) Texas Instruments Incorporated 2014 | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * | ||
16 | * Redistributions of source code must retain the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer. | ||
18 | * | ||
19 | * Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the | ||
22 | * distribution. | ||
23 | * | ||
24 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
25 | * its contributors may be used to endorse or promote products derived | ||
26 | * from this software without specific prior written permission. | ||
27 | * | ||
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
39 | * | ||
40 | */ | ||
41 | /* ============================================================= */ | ||
42 | /** | ||
43 | * @file netapi.h | ||
44 | * | ||
45 | * path ti/runtime/netapi/demo/src/navl_wrapper.h | ||
46 | * | ||
47 | * @brief | ||
48 | * | ||
49 | */ | ||
50 | |||
51 | |||
52 | |||
53 | #ifndef __NAVL_WRAPPER_H | ||
54 | #define __NAVL_WRAPPER_H | ||
55 | |||
56 | #ifdef __cplusplus | ||
57 | extern "C" { | ||
58 | #endif | ||
59 | |||
60 | #include <stdio.h> | ||
61 | #include <stdint.h> | ||
62 | #include <stdlib.h> | ||
63 | #include <stddef.h> | ||
64 | #include <string.h> | ||
65 | #include <navl/navl.h> | ||
66 | |||
67 | #define NUM_PROCS 3 | ||
68 | |||
69 | #define NUM_FP_PROCS 2 | ||
70 | |||
71 | #define MAX_PROTOCOLS 1500 | ||
72 | |||
73 | #define MAX_BIN 10 | ||
74 | typedef struct | ||
75 | { | ||
76 | uint32_t num_threads; | ||
77 | uint32_t num_protocols; | ||
78 | uint32_t enable_dpi; | ||
79 | int64_t alloc_curr; | ||
80 | } navl_wrapper_cfg_info_t; | ||
81 | |||
82 | |||
83 | |||
84 | |||
85 | typedef struct | ||
86 | { | ||
87 | unsigned long n_ops; | ||
88 | unsigned long n_class; | ||
89 | unsigned long min_time; | ||
90 | unsigned long max_time; | ||
91 | unsigned long long tot; | ||
92 | unsigned long m_op; | ||
93 | unsigned long m_bytes; | ||
94 | unsigned long n_err; | ||
95 | unsigned long f_op; | ||
96 | unsigned long m_cycles; | ||
97 | unsigned long f_cycles; | ||
98 | unsigned long long malloc_cycles; | ||
99 | unsigned long long free_cycles; | ||
100 | int malloc_inst; | ||
101 | int malloc_bytes; | ||
102 | int free_inst; | ||
103 | } navl_global_dpi_stats; | ||
104 | |||
105 | |||
106 | |||
107 | |||
108 | /* for tracking packet stats */ | ||
109 | typedef struct | ||
110 | { | ||
111 | uint64_t packets; | ||
112 | uint64_t bytes; | ||
113 | char name[9]; | ||
114 | uint64_t cycles; | ||
115 | uint64_t cycles_nomem; | ||
116 | unsigned long cycles_max; | ||
117 | unsigned long cycles_min; | ||
118 | uint64_t class; //# packets classified | ||
119 | long bin_cycles[MAX_BIN]; | ||
120 | uint32_t pad[3]; | ||
121 | } navl_wrapper_pkt_stat_t; | ||
122 | |||
123 | |||
124 | |||
125 | /* for tracking packets per thread/core basis */ | ||
126 | typedef struct | ||
127 | { | ||
128 | navl_wrapper_cfg_info_t navl_cfg; | ||
129 | navl_wrapper_pkt_stat_t stats_pkt[2]; | ||
130 | } navl_wrapper_shm_pkt_stats_t; | ||
131 | |||
132 | |||
133 | |||
134 | |||
135 | /* for tracking memory stats */ | ||
136 | typedef struct | ||
137 | { | ||
138 | int64_t curr; | ||
139 | int64_t peak; | ||
140 | int64_t fail; | ||
141 | } navl_wrapper_stat_t; | ||
142 | |||
143 | |||
144 | |||
145 | #define NUM_MEM_CTX 50 | ||
146 | #define NUM_MEM_OBJ 50 | ||
147 | |||
148 | /* instance variables */ | ||
149 | typedef struct { | ||
150 | /* handles */ | ||
151 | navl_handle_t navl; | ||
152 | |||
153 | /* configuration */ | ||
154 | const char *config_capfile; | ||
155 | const char *config_plugins; | ||
156 | int config_num_proto; | ||
157 | int config_conn_id_attr; | ||
158 | int config_http_attr; | ||
159 | int config_num_memctx; | ||
160 | int config_num_memobj; | ||
161 | |||
162 | /* options */ | ||
163 | int option_dpi; | ||
164 | int option_simple; | ||
165 | int option_track_memory; | ||
166 | int option_limit_memory; | ||
167 | int option_tunnel; | ||
168 | int option_realtime_mode; | ||
169 | int option_verbose; | ||
170 | |||
171 | /* diagnostics */ | ||
172 | int error_navl; | ||
173 | |||
174 | /* statistics */ | ||
175 | //#define NUM_MEM_CTX 50 | ||
176 | //#define NUM_MEM_OBJ 50 | ||
177 | navl_wrapper_stat_t stats_mem[NUM_MEM_CTX][NUM_MEM_OBJ]; | ||
178 | char ctx_name[NUM_MEM_CTX][64]; | ||
179 | char obj_name[NUM_MEM_OBJ][64]; | ||
180 | navl_wrapper_pkt_stat_t *stats_pkt[2]; | ||
181 | uint64_t stats_conns; | ||
182 | |||
183 | /* misc vars */ | ||
184 | int running; | ||
185 | int64_t alloc_curr; | ||
186 | int64_t alloc_peak; | ||
187 | } navl_mcb_t; | ||
188 | |||
189 | #ifdef __cplusplus | ||
190 | } | ||
191 | #endif | ||
192 | #endif | ||
diff --git a/ti/runtime/netapi/demo/src/transport_dpi_demo.c b/ti/runtime/netapi/demo/src/transport_dpi_demo.c new file mode 100755 index 0000000..08c5791 --- /dev/null +++ b/ti/runtime/netapi/demo/src/transport_dpi_demo.c | |||
@@ -0,0 +1,1074 @@ | |||
1 | /****************************************** | ||
2 | * File: nt_bench.c | ||
3 | * Purpose: benchmarks for NT. | ||
4 | ************************************************************** | ||
5 | * FILE: nt_bench.c | ||
6 | * | ||
7 | * DESCRIPTION: netapi user space transport | ||
8 | * library test application : benchmarks | ||
9 | * | ||
10 | * REVISION HISTORY: rev 0.0.1 | ||
11 | * | ||
12 | * Copyright (c) Texas Instruments Incorporated 2010-2011 | ||
13 | * | ||
14 | * Redistribution and use in source and binary forms, with or without | ||
15 | * modification, are permitted provided that the following conditions | ||
16 | * are met: | ||
17 | * | ||
18 | * Redistributions of source code must retain the above copyright | ||
19 | * notice, this list of conditions and the following disclaimer. | ||
20 | * | ||
21 | * Redistributions in binary form must reproduce the above copyright | ||
22 | * notice, this list of conditions and the following disclaimer in the | ||
23 | * documentation and/or other materials provided with the | ||
24 | * distribution. | ||
25 | * | ||
26 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
27 | * its contributors may be used to endorse or promote products derived | ||
28 | * from this software without specific prior written permission. | ||
29 | * | ||
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
41 | |||
42 | *****************************************/ | ||
43 | |||
44 | #include <stdio.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <unistd.h> | ||
47 | #include <string.h> | ||
48 | #include <signal.h> | ||
49 | #include <pthread.h> | ||
50 | #include <sched.h> | ||
51 | |||
52 | //#include "trie.h" | ||
53 | #include <ti/runtime/netapi/netapi.h> | ||
54 | #include <ti/runtime/hplib/hplib.h> | ||
55 | #include "ti/runtime/netapi/pktio.h" | ||
56 | #include "transport_dpi_demo.h" | ||
57 | #include "navl_wrapper.h" | ||
58 | //#include "ti/runtime/netapi/test/net_test.h" | ||
59 | #include <ti/drv/sa/salld.h> | ||
60 | |||
61 | #include <ti/drv/qmss/device/k2e/src/qmss_device.c> | ||
62 | #include <ti/drv/cppi/device/k2e/src/cppi_device.c> | ||
63 | |||
64 | extern Rm_ServiceHandle *rmClientServiceHandle; | ||
65 | extern NETCP_CFG_EXCEPTION_PKT_T expPkt_appid; | ||
66 | |||
67 | |||
68 | #define netapi_timing_start hplib_mUtilGetPmuCCNT | ||
69 | |||
70 | navl_wrapper_cfg_info_t *pNavlCfg; | ||
71 | navl_wrapper_pkt_stat_t *pStats1; | ||
72 | navl_wrapper_pkt_stat_t *pStats2; | ||
73 | navl_global_dpi_stats *pGlobDpiStats; | ||
74 | void* pTemp; | ||
75 | |||
76 | |||
77 | STATS_T stats; | ||
78 | paSysStats_t netcp_stats; | ||
79 | //struct dpi_stats dpis; | ||
80 | |||
81 | #define VDPI | ||
82 | #ifdef VDPI | ||
83 | static int DPI=0; //1 to enable | ||
84 | static int DUMP_DPI_CONN=0; | ||
85 | #endif | ||
86 | |||
87 | |||
88 | void* pShmBase; | ||
89 | void *pShmEntry; | ||
90 | |||
91 | |||
92 | |||
93 | static int scnt=0; | ||
94 | volatile static int QUIT=0; | ||
95 | static int XMIT=0; | ||
96 | static int CAP=0; | ||
97 | volatile int RESET=0; //to reset stats | ||
98 | static int NTH=1; | ||
99 | volatile static int PKTGEN=0; | ||
100 | int pkt_len=64; | ||
101 | |||
102 | |||
103 | |||
104 | NETCP_CFG_MACIF_T mac[NUM_PROCS]; | ||
105 | NETCP_CFG_MACIF_T mac0; | ||
106 | NETCP_CFG_MACIF_T mac1; | ||
107 | |||
108 | hplib_spinLock_T dpi_demo_thread_lock; | ||
109 | |||
110 | |||
111 | static char usage[] = "usage: %s -s \n"; | ||
112 | |||
113 | |||
114 | |||
115 | |||
116 | //int procs =2; | ||
117 | |||
118 | #define HPLIB_THREADID 0 // for main: HPLIB THREAD INSTANCE | ||
119 | //__thread int our_core; | ||
120 | static unsigned char dummy_mac[]={0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00}; | ||
121 | |||
122 | void house(NETAPI_SCHED_HANDLE_T *s); | ||
123 | void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats); | ||
124 | void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats); | ||
125 | |||
126 | //sig handler | ||
127 | void netTest_utilMySig(int x) | ||
128 | { | ||
129 | QUIT=1; | ||
130 | scnt+=1; | ||
131 | printf(">net_test_dpi: recv'd signal %d cnt=%d\n",x,scnt); | ||
132 | if (scnt > 10) {printf(">dpi-demo: WARNING EXITING WITH PROPER SHUTDOWN LUTS LEFT ACTIVE\n");exit(1);} | ||
133 | |||
134 | } | ||
135 | |||
136 | |||
137 | void recv_cb_bridge(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[], | ||
138 | PKTIO_METADATA_T meta[], int n_pkts, | ||
139 | uint64_t ts ); | ||
140 | |||
141 | |||
142 | /*************debug********************/ | ||
143 | void netTest_utilDumpDescr(unsigned long *p, int n) | ||
144 | { | ||
145 | printf("--------dump of descriptor %d %x\n", n, (int) p); | ||
146 | printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]); | ||
147 | printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); | ||
148 | printf("-----------------------------\n"); | ||
149 | } | ||
150 | void netTest_utilDumpHeader(unsigned long *p, int n, int a, int r) | ||
151 | { | ||
152 | printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r); | ||
153 | printf("> %0x %0x %0x %0x %0x %0x %0x %0x\n", | ||
154 | ntohl(p[0]),ntohl(p[1]),ntohl(p[2]),ntohl(p[3]), | ||
155 | ntohl(p[4]),ntohl(p[5]),ntohl(p[6]),ntohl(p[7]) ); | ||
156 | #if 0 | ||
157 | printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); | ||
158 | printf("> %x %x %x %x %x %x %x %x\n",p[16],p[17],p[18],p[19],p[20],p[21],p[22],p[23]); | ||
159 | printf("> %x %x %x %x %x %x %x %x\n",p[24],p[25],p[26],p[27],p[28],p[29],p[30],p[31]); | ||
160 | #endif | ||
161 | printf("-----------------------------\n"); | ||
162 | } | ||
163 | /*****************************************/ | ||
164 | |||
165 | void house(NETAPI_SCHED_HANDLE_T * s) | ||
166 | { | ||
167 | int err; | ||
168 | NETAPI_SCHED_SHUTDOWN_T sched_shutdown; | ||
169 | int coreid; //who we are | ||
170 | NETAPI_T nh= netapi_schedGetHandle(s); | ||
171 | coreid=(int) netapi_getCookie(nh); | ||
172 | |||
173 | if (QUIT) | ||
174 | { | ||
175 | sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW; | ||
176 | netapi_schedClose(s,&sched_shutdown,&err); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | |||
181 | #ifdef VDPI | ||
182 | if (DUMP_DPI_CONN ) | ||
183 | navl_dump_conn_info(); | ||
184 | #endif | ||
185 | |||
186 | |||
187 | /* only slow path threads get netcp stats, this needs to be set in cookie | ||
188 | during slow path thread creation*/ | ||
189 | if (coreid & SP_THREAD_MASK) | ||
190 | { | ||
191 | netapi_netcpCfgReqStats(nh, our_stats_cb_mt, 0,&err); | ||
192 | } | ||
193 | |||
194 | } | ||
195 | |||
196 | unsigned long long CALIB=0; | ||
197 | unsigned long long calibrate_idle(void) | ||
198 | { | ||
199 | volatile unsigned long long at1; | ||
200 | volatile unsigned long long at2; | ||
201 | volatile unsigned long pt1; | ||
202 | volatile unsigned long pt2; | ||
203 | unsigned long long calib; | ||
204 | at1 = hplib_mUtilGetTimestamp(); | ||
205 | pt1=netapi_timing_start(); | ||
206 | for(;;) | ||
207 | { | ||
208 | pt2=netapi_timing_start() ; | ||
209 | if ((pt2-pt1) >= 100000) break; | ||
210 | } | ||
211 | at2 = hplib_mUtilGetTimestamp(); | ||
212 | |||
213 | calib = ((unsigned long long) (pt2-pt1))/(at2-at1); | ||
214 | printf("calibrate: arm time=%lld -> arm cycles=%d calib=%lld\n", at2-at1, pt2-pt1, calib); | ||
215 | |||
216 | return calib; | ||
217 | } | ||
218 | |||
219 | /******************************************* | ||
220 | *************NETAPI OBJECTS*************** | ||
221 | *****************************************/ | ||
222 | static NETAPI_CFG_T our_netapi_default_cfg= | ||
223 | { | ||
224 | TUNE_NETAPI_PERM_MEM_SZ, | ||
225 | 128, //start of packet offset for hw to place data on rx for default flow | ||
226 | TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system | ||
227 | TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use | ||
228 | TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap | ||
229 | 64, //#descriptors w/o buffers in default heap | ||
230 | TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap | ||
231 | 128, //tail room | ||
232 | 256, //extra room | ||
233 | 0, | ||
234 | NULL | ||
235 | }; | ||
236 | |||
237 | Pktlib_HeapHandle OurHeap; //default heap, used by producer | ||
238 | PKTIO_HANDLE_T * netcp_rx_chan; | ||
239 | PKTIO_HANDLE_T * netcp_rx_chan2; | ||
240 | PKTIO_HANDLE_T * netcp_tx_chan; | ||
241 | |||
242 | PKTIO_CFG_T our_chan_cfg={PKTIO_RX_TX, PKTIO_LOCAL, PKTIO_Q_ANY, 8}; | ||
243 | PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8}; | ||
244 | PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8}; | ||
245 | PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8}; | ||
246 | NETAPI_T netapi_handle; | ||
247 | NETAPI_SCHED_HANDLE_T * our_sched; | ||
248 | NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES]; | ||
249 | NETAPI_SCHED_CONFIG_T our_sched_cfg={ | ||
250 | NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops | ||
251 | }; | ||
252 | |||
253 | NETCP_CFG_IP_T ip_rule0; | ||
254 | NETCP_CFG_IP_T ip_rule1; | ||
255 | |||
256 | |||
257 | PKTIO_CFG_T direct_to_cpsw_cfg={PKTIO_TX, PKTIO_GLOBAL, 648, 8}; | ||
258 | PKTIO_HANDLE_T * cpsw_tx_chan; | ||
259 | |||
260 | PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL}; | ||
261 | PKTIO_CONTROL_T poll_cannel_control={PKTIO_SET_POLL_FLAGS, NULL, nwal_POLL_DEFAULT_GLOB_PKT_Q}; | ||
262 | |||
263 | //template for fast path | ||
264 | nwalTxPktInfo_t txPktInfoNoCrypto = | ||
265 | { | ||
266 | NULL, /* p_pkt */ | ||
267 | NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */ | ||
268 | 0, /* lpbackPass */ | ||
269 | 0, /* enetport */ | ||
270 | 0, /* msuSize */ | ||
271 | 0, /* startOffset */ | ||
272 | 0, /* saOffBytes */ | ||
273 | 0, /* saPayLoadLen */ | ||
274 | 0 , /* saAhIcvOffBytes */ | ||
275 | 0, /* saAhMacSize */ | ||
276 | 0, /* etherLenOffBytes */ | ||
277 | MAC_HEADER_LEN, /* ipOffBytes */ | ||
278 | MAC_HEADER_LEN + IP_HEADER_LEN, /* l4OffBytes */ | ||
279 | UDP_HEADER_LEN, /* l4HdrLen */ | ||
280 | 0, /* pseudoHdrChecksum */ | ||
281 | 0 /* pLoadLen */ | ||
282 | }; | ||
283 | |||
284 | |||
285 | NETCP_CFG_ROUTE_T test_route= | ||
286 | { | ||
287 | 0, | ||
288 | NULL, | ||
289 | NULL, | ||
290 | 0//* to be filled in | ||
291 | }; | ||
292 | |||
293 | NETCP_CFG_FLOW_HANDLE_T kernelFlow22; | ||
294 | NETCP_CFG_FLOW_HANDLE_T kernelFlow23; | ||
295 | |||
296 | /*************************END NETAPI OBJECTS***********************/ | ||
297 | |||
298 | static unsigned char all_mac[]={0,0,0,0,0,0}; | ||
299 | nwalIpAddr_t all_ip={0,0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
300 | |||
301 | |||
302 | static unsigned char all_dest[]={0xff,0xff,0xff,0xff,0xff,0xff}; | ||
303 | |||
304 | |||
305 | |||
306 | |||
307 | static unsigned long last_header[32/sizeof(unsigned long)]; | ||
308 | static unsigned long last_desc[64/sizeof(unsigned long)]; | ||
309 | |||
310 | //stats | ||
311 | #define MAX_CORE 4 | ||
312 | int pkt_rx[MAX_CORE]; | ||
313 | int pkt_tx[MAX_CORE]; | ||
314 | unsigned long long pkt_rx_cycles[MAX_CORE]={0L}; | ||
315 | unsigned long long pkt_tx_cycles[MAX_CORE]={0L}; | ||
316 | unsigned long long pkt_cb_cycles[MAX_CORE]={0L}; | ||
317 | unsigned long long idle_cycles[MAX_CORE]={0L}; | ||
318 | volatile unsigned long long start_time[MAX_CORE]; | ||
319 | unsigned long long end_time[MAX_CORE]; | ||
320 | unsigned long long pkt_stall[MAX_CORE]={0L}; | ||
321 | //********************************* | ||
322 | // packet generator | ||
323 | //********************************* | ||
324 | void gen_pkts(int np, int out_port); | ||
325 | |||
326 | /****************************************************** | ||
327 | * stats callback | ||
328 | *******************************************************/ | ||
329 | void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats) | ||
330 | { | ||
331 | stats.n_stats_cb +=1; | ||
332 | if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t)); | ||
333 | } | ||
334 | |||
335 | void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats) | ||
336 | { | ||
337 | uint32_t numFreeDataPackets; | ||
338 | uint32_t numZeroBufferPackets; | ||
339 | uint32_t numPacketsinGarbage; | ||
340 | Pktlib_HeapStats pktLibHeapStats; | ||
341 | int i,j; | ||
342 | unsigned long long bcpp; | ||
343 | unsigned long long bcpp_noc; | ||
344 | unsigned long long bcpp_app; | ||
345 | unsigned long long bcpp_tx; | ||
346 | unsigned long long npL; | ||
347 | unsigned long long cyclesL; | ||
348 | unsigned long long ccyclesL; //cache cycles | ||
349 | unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES]; | ||
350 | unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES]; | ||
351 | unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles | ||
352 | NETAPI_SA_STATS_T netapi_sa_stats; | ||
353 | |||
354 | printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats.n_stats_cb); | ||
355 | //printf("netcp_tx_handle check %x\n", netcp_tx_chan->back); | ||
356 | printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%d secRx=%d secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d sec_tx=%d min_rx=%d min_tx=%d ip=%d\n", | ||
357 | stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new, | ||
358 | stats.n_class0_rx, stats.n_class1_rx, | ||
359 | stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok, | ||
360 | stats.sec_tx, stats.rx_min, stats.tx_min, stats.ip); | ||
361 | printf(">if rx stats: %d %d %d\n",stats.if_rx[0],stats.if_rx[1],stats.if_rx[2]); | ||
362 | |||
363 | |||
364 | printf(">core rx stats: %d %d %d\n",stats.core_rx[1],stats.core_rx[2],stats.core_rx[3]); | ||
365 | |||
366 | |||
367 | for (j= 1;j < NUM_PROCS;j++) | ||
368 | { | ||
369 | tmp_npL[j]=0LL; tmp_cyclesL[j]=0LL; tmp_ccyclesL[j]=0LL; | ||
370 | netapi_schedGetStats(scheduler[j],&tmp_npL[j],&tmp_cyclesL[j],&tmp_ccyclesL[j]); | ||
371 | npL += tmp_npL[j]; | ||
372 | cyclesL += tmp_cyclesL[j]; | ||
373 | ccyclesL += tmp_ccyclesL[j]; | ||
374 | } | ||
375 | |||
376 | if (npL && stats.rx) | ||
377 | { | ||
378 | bcpp = cyclesL/npL; | ||
379 | bcpp_noc = (cyclesL-ccyclesL)/npL; | ||
380 | bcpp_app = (stats.app_cycles-stats.tx_cache_cycles)/stats.rx; | ||
381 | } | ||
382 | else {bcpp = bcpp_noc=bcpp_app=0L;} | ||
383 | if (stats.tx) | ||
384 | { | ||
385 | bcpp_tx = (stats.send_cycles-stats.tx_cache_cycles)/stats.tx; | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | bcpp_tx = 0L; | ||
390 | } | ||
391 | printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n", | ||
392 | bcpp,bcpp_noc,bcpp_app, bcpp_tx); | ||
393 | |||
394 | |||
395 | #ifdef VDPI | ||
396 | navl_return_stats( | ||
397 | &pGlobDpiStats->n_ops, | ||
398 | &pGlobDpiStats->n_class, | ||
399 | &pGlobDpiStats->min_time, | ||
400 | &pGlobDpiStats->max_time, | ||
401 | &pGlobDpiStats->tot, | ||
402 | &pGlobDpiStats->m_op, | ||
403 | &pGlobDpiStats->m_bytes, | ||
404 | &pGlobDpiStats->n_err, | ||
405 | &pGlobDpiStats->f_op, | ||
406 | &pGlobDpiStats->m_cycles, | ||
407 | &pGlobDpiStats->f_cycles); | ||
408 | |||
409 | printf("dpi stats: nops=%d nclass=%d min cycle=%d max cycle=%d ave cycle=%lld #mallocs=%d #mbytes=%d n_err=%d fops=%d mCycles=%d fCycles=%d\n", | ||
410 | pGlobDpiStats->n_ops, | ||
411 | pGlobDpiStats->n_class, | ||
412 | pGlobDpiStats->min_time, | ||
413 | pGlobDpiStats->max_time, | ||
414 | pGlobDpiStats->n_ops? pGlobDpiStats->tot/pGlobDpiStats->n_ops : 0, | ||
415 | pGlobDpiStats->m_op, | ||
416 | pGlobDpiStats->m_bytes, | ||
417 | pGlobDpiStats->n_err, | ||
418 | pGlobDpiStats->f_op, pGlobDpiStats->m_cycles, pGlobDpiStats->f_cycles); | ||
419 | for(i=0; i< NUM_FP_PROCS;i++) | ||
420 | { | ||
421 | navl_results(i); | ||
422 | } | ||
423 | #endif | ||
424 | if(pPaStats) | ||
425 | { | ||
426 | printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets); | ||
427 | printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets); | ||
428 | printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets); | ||
429 | printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets); | ||
430 | printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets); | ||
431 | printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail); | ||
432 | printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch); | ||
433 | printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch); | ||
434 | printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag); | ||
435 | printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow); | ||
436 | printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow); | ||
437 | printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow); | ||
438 | printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets); | ||
439 | printf("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail); | ||
440 | printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt); | ||
441 | printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag); | ||
442 | printf("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard); | ||
443 | printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl); | ||
444 | printf("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState); | ||
445 | printf("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail); | ||
446 | printf("C2 number Packets : %d\n",pPaStats->classify2.nPackets); | ||
447 | printf("C2 number udp : %d\n",pPaStats->classify2.nUdp); | ||
448 | printf("C2 number tcp : %d\n",pPaStats->classify2.nTcp); | ||
449 | printf("C2 number Custom : %d\n",pPaStats->classify2.nCustom); | ||
450 | printf("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard); | ||
451 | printf("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl); | ||
452 | printf("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail); | ||
453 | } | ||
454 | Pktlib_getHeapStats(OurHeap, &pktLibHeapStats); | ||
455 | |||
456 | printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets, | ||
457 | pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage); | ||
458 | printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", | ||
459 | pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter, | ||
460 | pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter); | ||
461 | } | ||
462 | |||
463 | NETAPI_T worker_nh[MAX_NUM_CORES]; | ||
464 | |||
465 | void slow_path_thread(uint32_t index) | ||
466 | { | ||
467 | int err, i;; | ||
468 | uint32_t thread_num; | ||
469 | cpu_set_t cpu_set; | ||
470 | |||
471 | /* index being passed in is the core we want to run the thread on */ | ||
472 | thread_num = index; | ||
473 | printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), thread_num); | ||
474 | |||
475 | CPU_ZERO( &cpu_set); | ||
476 | for (i = 0; i < 1;i++) | ||
477 | { | ||
478 | CPU_SET( i, &cpu_set); | ||
479 | } | ||
480 | hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL); | ||
481 | worker_nh[thread_num] = netapi_init(NETAPI_CORE_MASTER,NULL); | ||
482 | |||
483 | if (worker_nh[thread_num] == NULL) | ||
484 | { | ||
485 | printf("slow_path_thread: netapi_init failure, exiting\n"); | ||
486 | exit(1); | ||
487 | } | ||
488 | netapi_setCookie(worker_nh[thread_num],(void*)(thread_num | SP_THREAD_MASK)); | ||
489 | |||
490 | scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err); | ||
491 | if (!scheduler[thread_num]) | ||
492 | { | ||
493 | printf("sched create failed for core%d\n",thread_num); | ||
494 | goto ERR_slow_path_thread; | ||
495 | } | ||
496 | scheduler[thread_num]->config.yield = TRUE; | ||
497 | scheduler[thread_num]->config.pollGarbageQ = TRUE; | ||
498 | scheduler[thread_num]->config.pollCtrlQ = TRUE; | ||
499 | printf("Slow Path thread: %d setup complete, running on ARM CORE: %d\n", | ||
500 | index,index); | ||
501 | |||
502 | |||
503 | netapi_schedRun(scheduler[thread_num], &err); | ||
504 | |||
505 | ERR_slow_path_thread: | ||
506 | printf("slow_path_thread: calling netapi_shutdown\n"); | ||
507 | netapi_shutdown(worker_nh[thread_num]); | ||
508 | } | ||
509 | |||
510 | |||
511 | void fast_path_thread(uint32_t index) | ||
512 | { | ||
513 | int err, i; | ||
514 | PKTIO_HANDLE_T *rx_chan; | ||
515 | PKTIO_HANDLE_T *sb_rx_chan; | ||
516 | uint32_t thread_num; | ||
517 | int navlHandle; | ||
518 | |||
519 | |||
520 | cpu_set_t cpu_set; | ||
521 | |||
522 | CPU_ZERO( &cpu_set); | ||
523 | thread_num = index; | ||
524 | printf("fast_path_thread: core %d\n", index); | ||
525 | |||
526 | |||
527 | CPU_SET( thread_num, &cpu_set); | ||
528 | hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL); | ||
529 | |||
530 | |||
531 | hplib_mSpinLockLock(&dpi_demo_thread_lock); | ||
532 | worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL); | ||
533 | |||
534 | if (worker_nh[thread_num] == NULL) | ||
535 | { | ||
536 | printf("fast_path_thread: netapi_init failure, exiting\n"); | ||
537 | hplib_mSpinLockUnlock(&dpi_demo_thread_lock); | ||
538 | exit(1); | ||
539 | } | ||
540 | else | ||
541 | { | ||
542 | #ifdef VDPI | ||
543 | navlHandle = navl_per_thread_init(thread_num); | ||
544 | #endif | ||
545 | } | ||
546 | hplib_mSpinLockUnlock(&dpi_demo_thread_lock); | ||
547 | |||
548 | |||
549 | if (worker_nh[thread_num] == NULL) | ||
550 | { | ||
551 | printf("fast_path_thread: netapi_init failure, exiting\n"); | ||
552 | exit(1); | ||
553 | } | ||
554 | |||
555 | /* open netcp default RX channels*/ | ||
556 | rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb_bridge, &netcp_rx_cfg, &err); | ||
557 | |||
558 | |||
559 | netapi_setCookie(worker_nh[thread_num],(void*)thread_num); | ||
560 | |||
561 | scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num], | ||
562 | &our_sched_cfg, | ||
563 | &err); | ||
564 | if (!scheduler[thread_num]) | ||
565 | { | ||
566 | printf("sched create failed for core%d\n",thread_num); | ||
567 | goto ERR_fast_path_thread; | ||
568 | //exit(1); | ||
569 | } | ||
570 | |||
571 | |||
572 | scheduler[thread_num]->config.yield = FALSE; | ||
573 | scheduler[thread_num]->config.pollGarbageQ = FALSE; | ||
574 | scheduler[thread_num]->config.pollCtrlQ = FALSE; | ||
575 | /* Entry point to scheduler */ | ||
576 | |||
577 | |||
578 | printf("Fast Path thread: %d setup complete, running on ARM CORE: %d\n", | ||
579 | index,index); | ||
580 | netapi_schedRun(scheduler[thread_num], &err); | ||
581 | |||
582 | ERR_fast_path_thread: | ||
583 | #ifdef VDPI | ||
584 | navl_fini(navlHandle); | ||
585 | #endif | ||
586 | netapi_pktioClose(rx_chan, &err); | ||
587 | |||
588 | printf("fast_path_thread: calling netapi_shutdown\n"); | ||
589 | netapi_shutdown(worker_nh[thread_num]); | ||
590 | } | ||
591 | |||
592 | |||
593 | /****************************** | ||
594 | * main program | ||
595 | *****************************/ | ||
596 | int main(int argc, char **argv) | ||
597 | { | ||
598 | int err,i; | ||
599 | int j; | ||
600 | int32_t errCode; | ||
601 | Pktlib_HeapIfTable* pPktifTable; | ||
602 | Pktlib_HeapCfg heapCfg; | ||
603 | long t1, t2 ; | ||
604 | cpu_set_t cpu_set; | ||
605 | int c; | ||
606 | int statsQueryRequest = 0; | ||
607 | pthread_t *thrs; | ||
608 | int p; | ||
609 | |||
610 | #if 0 | ||
611 | if (initRm()) | ||
612 | { | ||
613 | printf("main: initRm() returned error\n"); | ||
614 | exit(1); | ||
615 | } | ||
616 | #endif | ||
617 | |||
618 | |||
619 | #if 1 | ||
620 | |||
621 | if (argc == 2) | ||
622 | { | ||
623 | printf("main: argument %s\n", argv[1]); | ||
624 | if(!(strcmp(argv[1], "stats"))) | ||
625 | { | ||
626 | statsQueryRequest =1; | ||
627 | printf("querying for stats\n"); | ||
628 | } | ||
629 | } | ||
630 | printf("statsQueryReqeust: %d\n", statsQueryRequest); | ||
631 | |||
632 | |||
633 | #endif | ||
634 | |||
635 | |||
636 | if (!statsQueryRequest) | ||
637 | { | ||
638 | signal(SIGINT,netTest_utilMySig); | ||
639 | CPU_ZERO( &cpu_set); | ||
640 | CPU_SET( 0, &cpu_set); | ||
641 | hplib_utilSetupThread(HPLIB_THREADID, &cpu_set, hplib_spinLock_Type_LOL); | ||
642 | |||
643 | /* create netapi */ | ||
644 | our_netapi_default_cfg.rmHandle = rmClientServiceHandle; | ||
645 | netapi_handle = netapi_init(NETAPI_SYS_MASTER, | ||
646 | &our_netapi_default_cfg); | ||
647 | if (netapi_handle == NULL) | ||
648 | { | ||
649 | printf("main: netapi_init failure, exiting\n"); | ||
650 | exit(1); | ||
651 | } | ||
652 | /* allocate segment for shared memory for packet stats */ | ||
653 | /* allocate packet statistics */ | ||
654 | pShmBase = hplib_shmOpen(); | ||
655 | if (pShmBase) | ||
656 | { | ||
657 | if (hplib_shmAddEntry(pShmBase, | ||
658 | sizeof(navl_wrapper_pkt_stat_t) | ||
659 | * MAX_PROTOCOLS *NUM_FP_PROCS + sizeof(navl_wrapper_cfg_info_t), | ||
660 | APP_ENTRY_1) != hplib_OK) | ||
661 | { | ||
662 | printf("main: hplib_shmAddEntry failure\n"); | ||
663 | return -1; | ||
664 | } | ||
665 | else | ||
666 | { | ||
667 | pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_1); | ||
668 | pNavlCfg = (navl_wrapper_cfg_info_t*)pShmEntry; | ||
669 | memset(pNavlCfg, | ||
670 | 0, | ||
671 | sizeof(navl_wrapper_pkt_stat_t) * MAX_PROTOCOLS *NUM_FP_PROCS+ sizeof(navl_wrapper_cfg_info_t)); | ||
672 | pNavlCfg = (navl_wrapper_cfg_info_t*)pShmEntry; | ||
673 | pNavlCfg->enable_dpi = 0; /* disable DPI by default */ | ||
674 | } | ||
675 | if (hplib_shmAddEntry(pShmBase, sizeof(navl_global_dpi_stats), APP_ENTRY_2) != hplib_OK) | ||
676 | { | ||
677 | printf("main: hplib_shmAddEntry failure\n"); | ||
678 | return -1; | ||
679 | } | ||
680 | else | ||
681 | { | ||
682 | pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_2); | ||
683 | pGlobDpiStats = (navl_global_dpi_stats*) pShmEntry; | ||
684 | memset(pGlobDpiStats, 0, sizeof(navl_global_dpi_stats)); | ||
685 | pGlobDpiStats->min_time=100000000; | ||
686 | } | ||
687 | } | ||
688 | else | ||
689 | { | ||
690 | printf("main: hplib_shmOpen failure, exiting\n"); | ||
691 | exit(1); | ||
692 | } | ||
693 | /* open the main heap */ | ||
694 | OurHeap = Pktlib_findHeapByName("netapi"); | ||
695 | if (!OurHeap) | ||
696 | { | ||
697 | printf("findheapbyname fail\n"); | ||
698 | exit(1); | ||
699 | } | ||
700 | |||
701 | //if we want to relay network packets, we create a handle to the | ||
702 | //default netcp receive queue here | ||
703 | netcp_rx_chan= netapi_pktioOpen(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_bridge, &netcp_rx_cfg, &err); | ||
704 | if (!netcp_rx_chan) | ||
705 | { | ||
706 | printf("pktio open RX failed err=%d\n",err); | ||
707 | exit(1); | ||
708 | } | ||
709 | |||
710 | netcp_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_TX, (PKTIO_CB) NULL, &netcp_tx_cfg, &err); | ||
711 | if (!netcp_tx_chan) | ||
712 | { | ||
713 | printf("pktio open TX failed err=%d\n",err); | ||
714 | exit(1); | ||
715 | } | ||
716 | else //install a fast path template into the NETCP TX channel | ||
717 | { | ||
718 | PKTIO_CONTROL_T control2; | ||
719 | control2.op = PKTIO_UPDATE_FAST_PATH; | ||
720 | PKTIO_CFG_T cfg2; | ||
721 | memset(&cfg2, 0, sizeof(PKTIO_CFG_T)); | ||
722 | cfg2.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT; | ||
723 | cfg2.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto; | ||
724 | netapi_pktioControl(netcp_tx_chan, NULL, &cfg2, &control2, &err); | ||
725 | } | ||
726 | |||
727 | |||
728 | if (navl_setup() < 0) | ||
729 | { | ||
730 | printf("main: navl_setup failure, exiting\n"); | ||
731 | exit(1); | ||
732 | } | ||
733 | |||
734 | /*********************************************/ | ||
735 | /*****************end NETAPI STARTUP**********/ | ||
736 | /*********************************************/ | ||
737 | |||
738 | //now creaate a simple netcp rule | ||
739 | //to get a lot of packets | ||
740 | mac0 = netapi_netcpCfgCreateMacInterface( | ||
741 | netapi_handle, | ||
742 | &all_mac[0], | ||
743 | NULL, | ||
744 | 0, | ||
745 | 1, | ||
746 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, | ||
747 | (NETCP_CFG_VLAN_T ) NULL , //future | ||
748 | 0x0800, | ||
749 | 1, | ||
750 | &err); | ||
751 | if (err) {printf("addmac0 failed %d\n",err); exit(1); } | ||
752 | else printf("addmac0 sucess\n"); | ||
753 | |||
754 | mac1 = netapi_netcpCfgCreateMacInterface( | ||
755 | netapi_handle, | ||
756 | &all_mac[0], | ||
757 | NULL, | ||
758 | 1, | ||
759 | 2, | ||
760 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, | ||
761 | (NETCP_CFG_VLAN_T ) NULL , //future | ||
762 | 0x0800, | ||
763 | 1, | ||
764 | &err); | ||
765 | if (err) {printf("addmac1 failed %d\n",err); exit(1); } | ||
766 | else printf("addmac1 sucess\n"); | ||
767 | |||
768 | //calibrate idle | ||
769 | CALIB = calibrate_idle(); | ||
770 | |||
771 | //************************************** | ||
772 | //Create a slow path thread | ||
773 | //*************************************** | ||
774 | thrs = malloc( sizeof( pthread_t ) * NUM_PROCS ); | ||
775 | if (thrs == NULL) | ||
776 | { | ||
777 | perror( "malloc" ); | ||
778 | return -1; | ||
779 | } | ||
780 | printf( "dpi-demo: Starting slow_path_thread on core 0\n"); | ||
781 | |||
782 | if (pthread_create( &thrs[0], NULL, (void*)slow_path_thread, | ||
783 | (void *)0 )) //start at core 0 | ||
784 | { | ||
785 | perror( "pthread_create" ); | ||
786 | exit(1); | ||
787 | } | ||
788 | |||
789 | |||
790 | for (j= 1;j < NUM_PROCS;j++) | ||
791 | { | ||
792 | printf( "dpi-demo: Starting fast_path_thread on core 1\n"); | ||
793 | if (pthread_create( &thrs[j], NULL, (void*)fast_path_thread, | ||
794 | (void *)j )) //start at core 1 | ||
795 | { | ||
796 | perror( "pthread_create" ); | ||
797 | exit(1); | ||
798 | } | ||
799 | } | ||
800 | } | ||
801 | else | ||
802 | { | ||
803 | |||
804 | pShmBase = hplib_shmOpen(); | ||
805 | if (pShmBase) | ||
806 | { | ||
807 | pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_1); | ||
808 | pNavlCfg = (navl_wrapper_cfg_info_t*)pTemp; | ||
809 | |||
810 | pStats1 = pTemp + sizeof(navl_wrapper_cfg_info_t); | ||
811 | |||
812 | |||
813 | pStats2 = pTemp + sizeof(navl_wrapper_cfg_info_t) + | ||
814 | (sizeof(navl_wrapper_pkt_stat_t)*pNavlCfg->num_protocols); | ||
815 | |||
816 | pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_2); | ||
817 | pGlobDpiStats = (struct dpi_stats*) pTemp; | ||
818 | |||
819 | printf("dpi stats: nops=%d nclass=%d min cycle=%d max cycle=%d ave cycle=%lld #mallocs=%d #mbytes=%d n_err=%d fops=%d mCycles=%d fCycles=%d\n", | ||
820 | pGlobDpiStats->n_ops, | ||
821 | pGlobDpiStats->n_class, | ||
822 | pGlobDpiStats->min_time, | ||
823 | pGlobDpiStats->max_time, | ||
824 | pGlobDpiStats->n_ops? pGlobDpiStats->tot/pGlobDpiStats->n_ops : 0, | ||
825 | pGlobDpiStats->m_op, | ||
826 | pGlobDpiStats->m_bytes, | ||
827 | pGlobDpiStats->n_err, | ||
828 | pGlobDpiStats->f_op, pGlobDpiStats->m_cycles, pGlobDpiStats->f_cycles); | ||
829 | for(i=0;i < NUM_FP_PROCS; i++) | ||
830 | { | ||
831 | navl_results2(i); | ||
832 | } | ||
833 | exit(1); | ||
834 | } | ||
835 | } | ||
836 | |||
837 | |||
838 | //this thread of execution (main) now just waits on user input | ||
839 | for(;;) | ||
840 | { | ||
841 | printf(">"); | ||
842 | c=getchar(); | ||
843 | if (c=='C') | ||
844 | { | ||
845 | CAP=!CAP; | ||
846 | printf("CAPTURE= %d\n", CAP); | ||
847 | } | ||
848 | else if (c=='q') {QUIT=1;break;} | ||
849 | else if (c=='s') | ||
850 | our_stats_cb(netapi_handle, &netcp_stats); | ||
851 | #ifdef VDPI | ||
852 | else if (c=='c') | ||
853 | {navl_clear_stats();printf("> Clearing DPI stats\n");} | ||
854 | else if (c=='v') navl_set_verbose(); | ||
855 | else if (c=='p') | ||
856 | {DUMP_DPI_CONN = !DUMP_DPI_CONN;printf("> **DPI CONN DUMP is %s ** \n", DUMP_DPI_CONN ?"enabled":"disabled");} | ||
857 | else if (c=='d') | ||
858 | { | ||
859 | pNavlCfg->enable_dpi = !pNavlCfg->enable_dpi; | ||
860 | printf("enable_dpi flag: %d\n", pNavlCfg->enable_dpi); | ||
861 | printf("> **DPI is %s ** \n", pNavlCfg->enable_dpi?"enabled":"disabled"); | ||
862 | } | ||
863 | #endif | ||
864 | else if (c=='!') {system("sh");} | ||
865 | |||
866 | else if ((c=='h')||(c=='?')) | ||
867 | { | ||
868 | printf("> 'q' to quit, 's' for stats,'d' to dump capture\n,> 'h' for help\n "); | ||
869 | } | ||
870 | #if 1 | ||
871 | else if (c=='r') | ||
872 | { | ||
873 | netTest_utilDumpHeader(&last_header[0], 0,0,0); | ||
874 | netTest_utilDumpDescr(&last_desc[0], 0); | ||
875 | } | ||
876 | #endif | ||
877 | } | ||
878 | |||
879 | |||
880 | |||
881 | #ifdef VDPI | ||
882 | navl_done(); | ||
883 | #endif | ||
884 | |||
885 | //wait for completion | ||
886 | printf("main task now pending on thread completion\n"); | ||
887 | for (i = 0; i < NUM_PROCS; i++) | ||
888 | pthread_join( thrs[i], NULL ); | ||
889 | |||
890 | free( thrs ); | ||
891 | |||
892 | /************************************************* | ||
893 | ************CLEAN UP**************************** | ||
894 | ************************************************/ | ||
895 | //get rid of rule, in the case that we are relaying packets | ||
896 | //also close our netcp rx channel | ||
897 | netapi_netcpCfgDelMac(netapi_handle,0,&err); | ||
898 | netapi_netcpCfgDelMac(netapi_handle,1,&err); | ||
899 | |||
900 | netapi_pktioClose(netcp_rx_chan,&err); | ||
901 | netapi_pktioClose(netcp_tx_chan,&err); | ||
902 | |||
903 | |||
904 | //done | ||
905 | netapi_shutdown(netapi_handle); | ||
906 | |||
907 | |||
908 | } | ||
909 | #if 1 | ||
910 | static inline void send_it(Ti_Pkt *tip, int len, int out_port) | ||
911 | { | ||
912 | int err=0; | ||
913 | PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0}; | ||
914 | nwalTxPktInfo_t meta_tx2={0}; | ||
915 | int coreid=Osal_nwalGetProcId(); | ||
916 | if (len<60) | ||
917 | { | ||
918 | unsigned int templen; | ||
919 | char * p_pkt; | ||
920 | len=60; | ||
921 | Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen | ||
922 | Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len); | ||
923 | } | ||
924 | Pktlib_setPacketLen(tip,len); | ||
925 | meta_tx2.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID; | ||
926 | meta_tx2.ploadLen = len ; | ||
927 | meta_tx2.enetPort=out_port; | ||
928 | meta2.u.tx_meta=&meta_tx2; | ||
929 | stats.tx+=1; | ||
930 | if(coreid<MAX_NUM_CORES) | ||
931 | pkt_tx[coreid]+=1; | ||
932 | netapi_pktioSend(netcp_tx_chan,tip,&meta2,&err); | ||
933 | } | ||
934 | #endif | ||
935 | void recv_cb_bridge(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[], | ||
936 | PKTIO_METADATA_T meta[], int n_pkts, | ||
937 | uint64_t ts ) | ||
938 | { | ||
939 | int i; | ||
940 | int len; | ||
941 | int p; | ||
942 | Ti_Pkt * tip; | ||
943 | unsigned int appid; | ||
944 | unsigned int templen; | ||
945 | char * p_pkt; | ||
946 | unsigned long t1; | ||
947 | unsigned long t2; | ||
948 | unsigned long long ct1; | ||
949 | unsigned long long ct2; | ||
950 | unsigned short ip_pl; | ||
951 | unsigned long long n_c_ops; | ||
952 | int ifno; | ||
953 | int out_port; | ||
954 | |||
955 | int coreid=Osal_nwalGetProcId(); | ||
956 | |||
957 | |||
958 | pasahoLongInfo_t* protoInfo; | ||
959 | |||
960 | t1=netapi_timing_start(); | ||
961 | ct1 =Osal_cache_op_measure(&n_c_ops); | ||
962 | for(i=0;i<n_pkts;i++) | ||
963 | { | ||
964 | |||
965 | tip = p_recv[i]; | ||
966 | appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000; | ||
967 | if (appid == NETAPI_NETCP_MATCH_GENERIC_IP) | ||
968 | { | ||
969 | stats.ip+=1; | ||
970 | } | ||
971 | |||
972 | protoInfo=nwal_mGetProtoInfo(tip); | ||
973 | ifno = nwal_mGetRxEmacPort( protoInfo); | ||
974 | if (ifno ==1) out_port=2; else out_port=1; | ||
975 | if(coreid<MAX_NUM_CORES) stats.core_rx[coreid]+=1; | ||
976 | if (ifno < MAX_NUM_INTERFACES) stats.if_rx[ifno]+=1; | ||
977 | Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen | ||
978 | if (CAP==coreid) | ||
979 | { | ||
980 | memcpy((unsigned char *)&last_header[0],p_pkt,32); | ||
981 | memcpy((unsigned char*)&last_desc[0],tip,64); | ||
982 | } | ||
983 | len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer | ||
984 | stats.rx+=1; | ||
985 | //printf("recv_cb_bridge: appId: 0x%x, out_port: %d\n", appid, out_port); | ||
986 | if (appid == NETAPI_NETCP_MATCH_GENERIC_MAC) | ||
987 | { | ||
988 | #ifdef VDPI | ||
989 | { | ||
990 | if (pNavlCfg->enable_dpi) | ||
991 | navl_process_pkt(p_pkt, len); | ||
992 | } | ||
993 | #endif | ||
994 | } | ||
995 | |||
996 | |||
997 | //printf("recv_cb_bridge: coreId: %d, outPort %d\n", coreid, out_port); | ||
998 | //Pktlib_freePacket(tip); | ||
999 | send_it(tip,len+4,out_port); | ||
1000 | } | ||
1001 | t2=netapi_timing_start(); | ||
1002 | ct2 =Osal_cache_op_measure(&n_c_ops); | ||
1003 | stats.app_cycles += (unsigned long long) (t2-t1); | ||
1004 | stats.tx_cache_cycles += (unsigned long long) (ct2-ct1); | ||
1005 | return; | ||
1006 | } | ||
1007 | |||
1008 | #define NTOPOP 150 | ||
1009 | volatile Ti_Pkt * pHd[NTOPOP]; | ||
1010 | |||
1011 | #define PKTGEN_PKT_LEN pkt_len | ||
1012 | #define MAXP 4 //max ports | ||
1013 | void gen_pkts(int np, int out_port) | ||
1014 | { | ||
1015 | int i; | ||
1016 | int p=0; | ||
1017 | unsigned long * pI ; | ||
1018 | Ti_Pkt * tip; | ||
1019 | int len; | ||
1020 | unsigned char * pData; | ||
1021 | int cstall=0; | ||
1022 | int coreid = Osal_nwalGetProcId(); | ||
1023 | for(i=0;i<np;) | ||
1024 | { | ||
1025 | //set out output port | ||
1026 | if (out_port) | ||
1027 | { | ||
1028 | p=out_port; | ||
1029 | } | ||
1030 | else //flip flop | ||
1031 | { | ||
1032 | p+=1; | ||
1033 | if(p>MAXP) p=1; | ||
1034 | } | ||
1035 | //get a packet | ||
1036 | tip=Pktlib_allocPacket(OurHeap,PKTGEN_PKT_LEN); | ||
1037 | pI = (unsigned long *) tip; | ||
1038 | if (!tip) | ||
1039 | { | ||
1040 | pkt_stall[coreid]+=1; | ||
1041 | cstall+=1; | ||
1042 | if (cstall >= 100000) | ||
1043 | { | ||
1044 | printf("worker core %d, max stall hit,, exiting.\n",coreid); | ||
1045 | return; | ||
1046 | } | ||
1047 | continue; | ||
1048 | } | ||
1049 | cstall=0; | ||
1050 | Pktlib_getDataBuffer(tip,&pData,&len); | ||
1051 | memcpy(pData,&dummy_mac,14); | ||
1052 | Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, pData,PKTGEN_PKT_LEN); | ||
1053 | Pktlib_setPacketLen(tip,PKTGEN_PKT_LEN); | ||
1054 | pI[1]=0x80000000; | ||
1055 | //pI[2] &= 0xfff0ffff ;move to pktio send function | ||
1056 | |||
1057 | //capture packet just in case | ||
1058 | if (CAP==coreid) | ||
1059 | { | ||
1060 | unsigned int templen; | ||
1061 | char * p_pkt; | ||
1062 | Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen | ||
1063 | memcpy((unsigned char *)&last_header[0],p_pkt,32); | ||
1064 | memcpy((unsigned char*)&last_desc[0],tip,64); | ||
1065 | } | ||
1066 | |||
1067 | //send packet | ||
1068 | send_it(tip, PKTGEN_PKT_LEN, p); | ||
1069 | pkt_tx[coreid]+=1; | ||
1070 | i+=1; | ||
1071 | } | ||
1072 | |||
1073 | return; | ||
1074 | } | ||
diff --git a/ti/runtime/netapi/demo/src/transport_dpi_demo.h b/ti/runtime/netapi/demo/src/transport_dpi_demo.h new file mode 100755 index 0000000..98b7f82 --- /dev/null +++ b/ti/runtime/netapi/demo/src/transport_dpi_demo.h | |||
@@ -0,0 +1,52 @@ | |||
1 | #include <stdlib.h> | ||
2 | |||
3 | #define MAC_HEADER_LEN 14 | ||
4 | #define IP_HEADER_LEN 20 | ||
5 | #define UDP_HEADER_LEN 8 | ||
6 | |||
7 | #define MAX_NUM_INTERFACES 64 | ||
8 | #define MAX_NUM_CORES 4 | ||
9 | |||
10 | #define SP_THREAD_MASK 0xF0000000 | ||
11 | #define THREAD_NUM_MASK 0x000000FF | ||
12 | |||
13 | |||
14 | typedef struct stats_t | ||
15 | { | ||
16 | long itx; //initially generated | ||
17 | long itx2; | ||
18 | long rx; | ||
19 | long tx; | ||
20 | long n_bad; | ||
21 | long n_new; | ||
22 | long n_class0_rx; //count of pkts classified | ||
23 | long n_class1_rx; //count of pkts classified | ||
24 | long n_class2_rx; //count of pkts classified | ||
25 | long n_t1; | ||
26 | long n_t2; | ||
27 | long n_t3; | ||
28 | long sec_tx; | ||
29 | long sec_rx; | ||
30 | long sb_tx; | ||
31 | long sb_rx; | ||
32 | long secp_rx; | ||
33 | long n_auth_ok; | ||
34 | unsigned long long app_cycles; | ||
35 | unsigned long long send_cycles; | ||
36 | unsigned long long tx_cache_cycles; | ||
37 | long rx_min; | ||
38 | long tx_min; | ||
39 | long if_rx[MAX_NUM_INTERFACES]; | ||
40 | long core_rx[MAX_NUM_CORES]; | ||
41 | long n_stats_cb; | ||
42 | long ip; | ||
43 | } STATS_T; | ||
44 | |||
45 | typedef struct head_t | ||
46 | { | ||
47 | long ip[5]; | ||
48 | long udp[2]; | ||
49 | } HEAD_T; | ||
50 | |||
51 | |||
52 | |||
diff --git a/ti/runtime/netapi/makefile_armv7 b/ti/runtime/netapi/makefile_armv7 index 87744b6..2a34e25 100755 --- a/ti/runtime/netapi/makefile_armv7 +++ b/ti/runtime/netapi/makefile_armv7 | |||
@@ -70,10 +70,10 @@ export CSL_DEVICE = -DDEVICE_K2E -DNSS_GEN2 | |||
70 | endif | 70 | endif |
71 | 71 | ||
72 | # PHONY Targets | 72 | # PHONY Targets |
73 | .PHONY: all clean lib tests examples install installbin | 73 | .PHONY: all clean lib tests examples install installbin demo installdemo |
74 | 74 | ||
75 | # all rule | 75 | # all rule |
76 | all: .executables install installbin | 76 | all: .executables install installbin installdemo |
77 | .executables: lib tests examples | 77 | .executables: lib tests examples |
78 | 78 | ||
79 | # Make rule to create $(ARMV7LIBDIR)/libnetapi.a library | 79 | # Make rule to create $(ARMV7LIBDIR)/libnetapi.a library |
@@ -112,15 +112,33 @@ installbin: | |||
112 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_loopback_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_loopback_$(DEVICE) | 112 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_loopback_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_loopback_$(DEVICE) |
113 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_router_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_router_$(DEVICE) | 113 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_router_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_router_$(DEVICE) |
114 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_bench_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_bench_$(DEVICE) | 114 | install -c -m 755 $(ARMV7BINDIR)/netapi/test/net_test_bench_$(DEVICE) $(INSTALL_BIN_BASE_DIR)/net_test_bench_$(DEVICE) |
115 | install -d $(SYSCONFDIR)/netapi | 115 | install -d $(SYSCONFDIR)/transportnetlib/test |
116 | $(CP) test/net_test_config.txt $(SYSCONFDIR)/netapi | 116 | $(CP) test/net_test_config.txt $(SYSCONFDIR)/transportnetlib/test |
117 | install -c -m 755 tools/net_test_loopback_setup.sh $(SYSCONFDIR)/netapi | 117 | install -c -m 755 tools/net_test_loopback_setup.sh $(SYSCONFDIR)/transportnetlib/test |
118 | install -c -m 755 tools/net_test_router_setup.sh $(SYSCONFDIR)/netapi | 118 | install -c -m 755 tools/net_test_router_setup.sh $(SYSCONFDIR)/transportnetlib/test |
119 | install -c -m 755 tools/irqset.sh $(SYSCONFDIR)/netapi | 119 | install -c -m 755 tools/irqset.sh $(SYSCONFDIR)/transportnetlib/test |
120 | install -c -m 755 tools/dsp_core_setup.sh $(SYSCONFDIR)/netapi | 120 | install -c -m 755 tools/dsp_core_setup.sh $(SYSCONFDIR)/transportnetlib/test |
121 | |||
122 | installdemo: | ||
123 | install -d $(INSTALL_BIN_BASE_DIR) | ||
124 | install -c -m 755 $(ARMV7BINDIR)/netapi/demo/transport_dpi_demo $(INSTALL_BIN_BASE_DIR)/ | ||
125 | install -d $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
126 | install -c -m 755 demo/demo_setup_files/transport_dpi_demo_setup.sh $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
127 | install -c -m 644 demo/demo_setup_files/index.html $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
128 | install -c -m 755 demo/demo_setup_files/dpicgi1.sh $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
129 | install -c -m 755 demo/demo_setup_files/dpicgi2.sh $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
130 | install -c -m 755 demo/demo_setup_files/dpicgi3.sh $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
131 | install -c demo/demo_setup_files/stats1.awk $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
132 | install -c demo/demo_setup_files/stats2.awk $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
133 | install -c demo/demo_setup_files/stats3.awk $(SYSCONFDIR)/transportnetlib/dpi_demo | ||
134 | |||
121 | # Make rule to create tests | 135 | # Make rule to create tests |
122 | tests: | 136 | tests: |
123 | -@echo compiling tests | 137 | -@echo compiling tests |
124 | @$(MAKE) -f ./test/build/Makefile $@ | 138 | @$(MAKE) -f ./test/build/Makefile $@ |
125 | 139 | ||
140 | # Make rule to create net_test_dpi_demo | ||
141 | demo: | ||
142 | -@echo compiling tests | ||
143 | @$(MAKE) -f ./demo/build/Makefile $@ | ||
126 | examples: | 144 | examples: |
diff --git a/ti/runtime/netapi/netcp_cfg.h b/ti/runtime/netapi/netcp_cfg.h index c6b8f14..5ad7b5b 100755 --- a/ti/runtime/netapi/netcp_cfg.h +++ b/ti/runtime/netapi/netcp_cfg.h | |||
@@ -630,6 +630,8 @@ void netapi_netcpCfgDelIp(NETAPI_T h, | |||
630 | * @param[in] switch_port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported currenly] | 630 | * @param[in] switch_port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported currenly] |
631 | * @param[in] route handle of a created route or NULL to use internal default route, @ref NETCP_CFG_ROUTE_HANDLE_T | 631 | * @param[in] route handle of a created route or NULL to use internal default route, @ref NETCP_CFG_ROUTE_HANDLE_T |
632 | * @param[in] vlan [future[ vlan configuration . Set to NULL, @ref NETCP_CFG_VLAN_T | 632 | * @param[in] vlan [future[ vlan configuration . Set to NULL, @ref NETCP_CFG_VLAN_T |
633 | * @param[in] etherType Ethertype field. | ||
634 | |||
633 | * @param[in] state [future] interface state (0=down, 1= up) | 635 | * @param[in] state [future] interface state (0=down, 1= up) |
634 | * @param[out] err pointer to error return | 636 | * @param[out] err pointer to error return |
635 | * @retval returns AppID for interface (this is returned in meta data for received packets matching this rule an no others, @ref NETCP_CFG_MACIF_T | 637 | * @retval returns AppID for interface (this is returned in meta data for received packets matching this rule an no others, @ref NETCP_CFG_MACIF_T |
@@ -642,6 +644,7 @@ NETCP_CFG_MACIF_T netapi_netcpCfgCreateMacInterface(NETAPI_T | |||
642 | int switch_port, | 644 | int switch_port, |
643 | NETCP_CFG_ROUTE_HANDLE_T route, | 645 | NETCP_CFG_ROUTE_HANDLE_T route, |
644 | NETCP_CFG_VLAN_T vlan, | 646 | NETCP_CFG_VLAN_T vlan, |
647 | uint16_t etherType, | ||
645 | int state, | 648 | int state, |
646 | int * err); | 649 | int * err); |
647 | 650 | ||
diff --git a/ti/runtime/netapi/src/netcp_cfg.c b/ti/runtime/netapi/src/netcp_cfg.c index 55a75bf..823b28b 100755 --- a/ti/runtime/netapi/src/netcp_cfg.c +++ b/ti/runtime/netapi/src/netcp_cfg.c | |||
@@ -782,6 +782,7 @@ NETCP_CFG_MACIF_T netapi_netcpCfgCreateMacInterface(NETAPI_T h, | |||
782 | int switch_port, | 782 | int switch_port, |
783 | NETCP_CFG_ROUTE_HANDLE_T route, | 783 | NETCP_CFG_ROUTE_HANDLE_T route, |
784 | NETCP_CFG_VLAN_T vlan, //future | 784 | NETCP_CFG_VLAN_T vlan, //future |
785 | uint16_t etherType, | ||
785 | int state, //0=down, 1=up //ignored | 786 | int state, //0=down, 1=up //ignored |
786 | int * err) | 787 | int * err) |
787 | { | 788 | { |
@@ -797,6 +798,7 @@ NETCP_CFG_MACIF_T netapi_netcpCfgCreateMacInterface(NETAPI_T h, | |||
797 | NWAL_NEXT_ROUTE_FAIL_ACTION_HOST, /* For next route fail action by default is route to host */ | 798 | NWAL_NEXT_ROUTE_FAIL_ACTION_HOST, /* For next route fail action by default is route to host */ |
798 | CPPI_PARAM_NOT_SPECIFIED, /* Use default flow configured to NWAL if packet is routed to host */ | 799 | CPPI_PARAM_NOT_SPECIFIED, /* Use default flow configured to NWAL if packet is routed to host */ |
799 | QMSS_PARAM_NOT_SPECIFIED, /* Use default queue configured to NWAL if packet is routed to host */ | 800 | QMSS_PARAM_NOT_SPECIFIED, /* Use default queue configured to NWAL if packet is routed to host */ |
801 | 0, | ||
800 | 0 | 802 | 0 |
801 | }; | 803 | }; |
802 | 804 | ||
@@ -831,7 +833,13 @@ NETCP_CFG_MACIF_T netapi_netcpCfgCreateMacInterface(NETAPI_T h, | |||
831 | if (switch_port) | 833 | if (switch_port) |
832 | { | 834 | { |
833 | macInfo.validParams |= NWAL_SET_MAC_VALID_PARAM_IFNUM ; | 835 | macInfo.validParams |= NWAL_SET_MAC_VALID_PARAM_IFNUM ; |
834 | macInfo.ifNum = switch_port; /* */ | 836 | macInfo.ifNum = switch_port; |
837 | } | ||
838 | |||
839 | if(etherType) | ||
840 | { | ||
841 | macInfo.validParams |= NWAL_SET_MAC_VALID_PARAM_ETHER_TYPE; | ||
842 | macInfo.etherType = etherType; | ||
835 | } | 843 | } |
836 | 844 | ||
837 | if (route != NULL) | 845 | if (route != NULL) |
diff --git a/ti/runtime/netapi/test/net_test_bench.c b/ti/runtime/netapi/test/net_test_bench.c index 37102ae..95aca32 100755 --- a/ti/runtime/netapi/test/net_test_bench.c +++ b/ti/runtime/netapi/test/net_test_bench.c | |||
@@ -379,6 +379,7 @@ netapi_netcpCfgCreateMacInterface( | |||
379 | 0,0, | 379 | 0,0, |
380 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, | 380 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, |
381 | (NETCP_CFG_VLAN_T ) NULL , //future | 381 | (NETCP_CFG_VLAN_T ) NULL , //future |
382 | 0, | ||
382 | 1, | 383 | 1, |
383 | &err); | 384 | &err); |
384 | 385 | ||
diff --git a/ti/runtime/netapi/test/net_test_utils.c b/ti/runtime/netapi/test/net_test_utils.c index 2980f12..4ac3aca 100755 --- a/ti/runtime/netapi/test/net_test_utils.c +++ b/ti/runtime/netapi/test/net_test_utils.c | |||
@@ -1325,6 +1325,7 @@ void netTest_utilCreateInterfaces(uint8_t num_macs, uint8_t num_ips) | |||
1325 | netTestCfg.switch_port[i], | 1325 | netTestCfg.switch_port[i], |
1326 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, | 1326 | (NETCP_CFG_ROUTE_HANDLE_T) NULL, |
1327 | (NETCP_CFG_VLAN_T ) NULL , //future | 1327 | (NETCP_CFG_VLAN_T ) NULL , //future |
1328 | 0, | ||
1328 | 1, | 1329 | 1, |
1329 | &err); | 1330 | &err); |
1330 | if (err) | 1331 | if (err) |
diff --git a/ti/runtime/netapi/tools/net_test_loopback_setup.sh b/ti/runtime/netapi/tools/net_test_loopback_setup.sh index a2e967e..fec25cd 100644 --- a/ti/runtime/netapi/tools/net_test_loopback_setup.sh +++ b/ti/runtime/netapi/tools/net_test_loopback_setup.sh | |||
@@ -9,4 +9,4 @@ devmem2 0x2090804 w 0x4 | |||
9 | # | 9 | # |
10 | # run net_test_loopback applicaton, default location of config file is in /etc/netapi, | 10 | # run net_test_loopback applicaton, default location of config file is in /etc/netapi, |
11 | # default config file name is net_test_config.txt | 11 | # default config file name is net_test_config.txt |
12 | /usr/bin/net_test_loopback /etc/netapi/net_test_config.txt | 12 | /usr/bin/net_test_loopback /etc/transportnetlib/test/net_test_config.txt |
diff --git a/ti/runtime/netapi/tools/net_test_router_setup.sh b/ti/runtime/netapi/tools/net_test_router_setup.sh index cad1b40..3debaf4 100644 --- a/ti/runtime/netapi/tools/net_test_router_setup.sh +++ b/ti/runtime/netapi/tools/net_test_router_setup.sh | |||
@@ -13,4 +13,4 @@ devmem2 0x2090804 w 0x4 | |||
13 | # | 13 | # |
14 | # run net_test_router applicaton, default location of config file is in /etc/netapi, | 14 | # run net_test_router applicaton, default location of config file is in /etc/netapi, |
15 | # default config file name is net_test_config.txt | 15 | # default config file name is net_test_config.txt |
16 | /usr/bin/net_test_router /etc/netapi/net_test_config.txt | 16 | /usr/bin/net_test_router /etc/transportnetlib/test/net_test_config.txt |