diff options
100 files changed, 2800 insertions, 360 deletions
diff --git a/app_example/func-test/CMakeLists.txt b/app_example/func-test/CMakeLists.txt index e6357b8..865eba5 100644 --- a/app_example/func-test/CMakeLists.txt +++ b/app_example/func-test/CMakeLists.txt @@ -15,4 +15,4 @@ ######################################################################### ADD_SUBDIRECTORY(fork) - +ADD_SUBDIRECTORY(file_transfer) diff --git a/app_example/func-test/file_transfer/CMakeLists.txt b/app_example/func-test/file_transfer/CMakeLists.txt new file mode 100644 index 0000000..408fc7a --- /dev/null +++ b/app_example/func-test/file_transfer/CMakeLists.txt @@ -0,0 +1,32 @@ +######################################################################### +# +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -fPIC -m64 -mssse3 -std=gnu89") + +LINK_DIRECTORIES(${LIB_PATH_SHARED} ${LIB_PATH_STATIC}) + +ADD_EXECUTABLE(vc_serv_file server_filetrans.c) +ADD_DEPENDENCIES(vc_serv_file nStackAPI) +TARGET_LINK_LIBRARIES(vc_serv_file libnStackAPI.so -lpthread -lrt) + +ADD_EXECUTABLE(vc_cli_file client_filetrans.c) +ADD_DEPENDENCIES(vc_cli_file nStackAPI) +TARGET_LINK_LIBRARIES(vc_cli_file libnStackAPI.so -lpthread -lrt) + +ADD_EXECUTABLE(kc_serv_file server_filetrans.c) +TARGET_LINK_LIBRARIES(kc_serv_file pthread) + +ADD_EXECUTABLE(kc_cli_file client_filetrans.c) +TARGET_LINK_LIBRARIES(kc_cli_file pthread)
\ No newline at end of file diff --git a/app_example/func-test/file_transfer/client_filetrans.c b/app_example/func-test/file_transfer/client_filetrans.c new file mode 100644 index 0000000..cc8386d --- /dev/null +++ b/app_example/func-test/file_transfer/client_filetrans.c @@ -0,0 +1,284 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <fcntl.h> +#include <netdb.h> +#include <ctype.h> +char *END_FLAG = "=================END"; +#define HEXCONVERT_COLS 8 +#define HEX_CONVERT 1 +//#define DEBUG 1 +#define out(fmt, arg...) (void)printf(fmt, ##arg) + +#ifdef DEBUG +#define DBG(fmt, arg...) do { \ + out("[Debug] " fmt, ##arg); \ + } while (0) +#else +#define DBG(fmt, arg...) ((void)0) +#endif + +void +error (const char *msg) +{ + perror (msg); + out + ("./client_tcp [server_ip_address] [port number] [filename] [client_ip_address]\n"); + exit (1); +} + +#if defined(HEX_CONVERT) && defined(DEBUG) +void +hexconvert (void *mem, unsigned int len) +{ + unsigned int i; + + for (i = 0; + i < + len + + ((len % HEXCONVERT_COLS) ? (HEXCONVERT_COLS - + len % HEXCONVERT_COLS) : 0); i++) + { + /* print offset */ + if (i % HEXCONVERT_COLS == 0) + { + DBG ("\n0x%06x: ", i); + } + + /*print hex data */ + if (i < len) + { + DBG ("%02x ", 0xFF & ((char *) mem)[i]); + } + else /* end of block, just aligning for ASCII dump */ + { + DBG ("\n"); + } + } +} +#endif + +void +tcp (char **pArgv) +{ + + int sockfd, portno; + char buff[1024]; + + struct sockaddr_in serv_addr, cli_addr; + struct hostent *server; + + sockfd = socket (AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) + { + error ("error in socket creation\n"); + } + out ("socket create successful\n"); + + portno = atoi (pArgv[2]); + server = gethostbyname (pArgv[1]); + + if (server == NULL) + { + fprintf (stderr, "error no such host\n"); + } + + bzero ((char *) &serv_addr, sizeof (serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy ((char *) server->h_addr, (char *) &serv_addr.sin_addr, + server->h_length); + serv_addr.sin_port = htons (portno); + bzero ((char *) &cli_addr, sizeof (serv_addr)); + + cli_addr.sin_family = AF_INET; + cli_addr.sin_addr.s_addr = inet_addr (pArgv[4]); + cli_addr.sin_port = htons (portno); + if (bind (sockfd, (struct sockaddr *) &cli_addr, sizeof (cli_addr)) < 0) + { + error ("bind fail"); + } + out ("Bind successful\n"); + + if (connect (sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < + 0) + { + error ("connection fail"); + } + out ("connection done\n"); + + FILE *file; + int filebyte = 0; + int lsize, totalsize = 0; + + file = fopen (pArgv[3], "r"); + fseek (file, 0, SEEK_END); + lsize = ftell (file); + rewind (file); + out ("Name of file: %s, Size of file : %d\n", pArgv[3], lsize); + if (write (sockfd, &lsize, sizeof (int)) == -1) + { + out ("error executing write\n"); + } + if (write (sockfd, pArgv[3], 255) == -1) + { + out ("error executing write\n"); + } + while (lsize > totalsize) + { + bzero (buff, 1024); + fseek (file, totalsize, SEEK_SET); + filebyte = fread (buff, 1, sizeof (buff), file); + if (filebyte == 0) + { + printf ("file End of file\n"); + break; + } + + if (filebyte < 0) + error ("error in reading file. \n"); +#if defined(HEX_CONVERT) && defined(DEBUG) + DBG ("=========================================\n"); + hexconvert (buff, filebyte); + DBG ("=========================================\n"); +#endif + + void *p = buff; + totalsize += filebyte; + + while (filebyte > 0) + { +#ifdef DEBUG + DBG ("=========================================\n"); + puts ((const char *) p); + DBG ("=========================================\n"); +#endif + int bytes_written = write (sockfd, p, filebyte); + if (bytes_written <= 0) + { + error ("error in Socket write.\n"); + } + + filebyte -= bytes_written; + p += bytes_written; +//#if DEBUG + DBG + ("Total size of file = %d, Total Bytes sent to socket = %d, bytes_written in each step = %d\n", + lsize, totalsize, bytes_written); +//#endif + } + } + out ("file has been sent successfully\n"); + out ("Final Total size of file = %d, Total Bytes sent to socket = %d\n", + lsize, totalsize); + + fclose (file); + sleep (60); + close (sockfd); + return; +} + +void +udp (char **pArgv) +{ + int sockfd, n, fd, sz, portno, MAXLINE; + FILE *fp; + struct sockaddr_in servaddr, cliaddr; + char *buf; + char *target, *path; + portno = atoi (pArgv[2]); + bzero (&servaddr, sizeof (servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons (portno); + servaddr.sin_addr.s_addr = inet_addr (pArgv[1]); + bzero (&cliaddr, sizeof (servaddr)); + cliaddr.sin_family = AF_INET; + cliaddr.sin_port = htons (portno); + cliaddr.sin_addr.s_addr = inet_addr (pArgv[3]); + sockfd = socket (AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + out ("error in socket creation\n"); + } + out ("socket create successful\n"); + + if (bind (sockfd, (struct sockaddr *) &cliaddr, sizeof (cliaddr)) < 0) + { + out ("bind fail"); + } + out ("Bind successful\n"); + + path = pArgv[4]; + target = pArgv[5]; + MAXLINE = atoi (pArgv[6]); + buf = malloc (MAXLINE * sizeof (int)); + fp = fopen (path, "r"); + fseek (fp, 0L, SEEK_END); + sz = ftell (fp); + out ("The size of the path file is %d", sz); + sendto (sockfd, target, strlen (target), 0, + (struct sockaddr *) &servaddr, sizeof (servaddr)); + n = recvfrom (sockfd, buf, MAXLINE, 0, NULL, NULL); + if (!strncmp (buf, "ok", 2)) + { + out ("Filename sent.\n"); + } + + fd = open (path, O_RDONLY); + while ((n = read (fd, buf, MAXLINE)) > 0) + { + sendto (sockfd, buf, n, 0, (struct sockaddr *) &servaddr, + sizeof (servaddr)); + } + sendto (sockfd, END_FLAG, strlen (END_FLAG), 0, + (struct sockaddr *) &servaddr, sizeof (servaddr)); + fclose (fp); + sleep (60); + close (sockfd); + return; +} + +int +main (int argc, char *argv[]) +{ + int i; + char **pArgv, str[10]; + pArgv = (char **) malloc (sizeof (char *) * 10); + for (i = 0; i < 10; i++) + { + pArgv[i] = (char *) malloc (sizeof (char) * 20); + } + printf ("%s", argv[1]); + + if (strcmp ("tcp", argv[1]) == 0) + { + strcpy (pArgv[0], "tcp"); + printf ("pArgv[0]=%s", pArgv[0]); + /* The arguments of tcp are [server_ip_address] [port number] [filename] [client_ip_address] */ + for (i = 1; i < 5; i++) + { + strcpy (pArgv[i], argv[i + 1]); + } + tcp (pArgv); + } + + else + { + strcpy (str, argv[1]); + if (strcmp ("udp", str) == 0) + { + strcpy (pArgv[0], "udp"); + printf ("pArgv[0]=%s", pArgv[0]); + /* The arguments of udp are [server_ip_address] [port number] [client_ip_address] [filename] [target_filename] [MAX_BUFFER_LENGTH] */ + for (i = 1; i < 7; i++) + { + strcpy (pArgv[i], argv[i + 1]); + } + udp (pArgv); + } + } + return 0; +} diff --git a/app_example/func-test/file_transfer/server_filetrans.c b/app_example/func-test/file_transfer/server_filetrans.c new file mode 100644 index 0000000..9463c70 --- /dev/null +++ b/app_example/func-test/file_transfer/server_filetrans.c @@ -0,0 +1,344 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <netdb.h> +#include <ctype.h> +#include <arpa/inet.h> +#include <fcntl.h> +char *END_FLAG = "=================END"; +#define HEXCONVERT_COLS 8 +#define HEX_CONVERT 1 +//#define DEBUG 1 +#define out(fmt, arg...) (void)printf(fmt, ##arg) + +#ifdef DEBUG +#define DBG(fmt, arg...) do { \ + out("[Debug] " fmt, ##arg); \ + } while (0) +#else +#define DBG(fmt, arg...) ((void)0) +#endif + +void +error (const char *msg) +{ + perror (msg); + out ("./server_tcp [server_ip_address] [port number]\n"); + exit (1); +} + +#if defined(HEX_CONVERT) && defined(DEBUG) +void +hexconvert (void *mem, unsigned int len) +{ + unsigned int i; + + for (i = 0; + i < + len + + ((len % HEXCONVERT_COLS) ? (HEXCONVERT_COLS - + len % HEXCONVERT_COLS) : 0); i++) + { + /* print offset */ + if (i % HEXCONVERT_COLS == 0) + { + DBG ("\n0x%06x: ", i); + } + + /*print hex data */ + if (i < len) + { + DBG ("%02x ", 0xFF & ((char *) mem)[i]); + } + else /* end of block, just aligning for ASCII dump */ + { + DBG ("\n"); + } + } +} +#endif +int +compareFiles (FILE * fp1, FILE * fp2) +{ + + char ch1 = getc (fp1); + char ch2 = getc (fp2); + int error = 0, pos = 0, line = 1; + + while (ch1 != EOF && ch2 != EOF) + { + pos++; + if (ch1 == '\n' && ch2 == '\n') + { + line++; + pos = 0; + } + + if (ch1 != ch2) + { + error++; + DBG ("Line Number : %d \tError" " Position :%d \n", line, pos); + } + + ch1 = getc (fp1); + ch2 = getc (fp2); + } + + //printf("Total Errors : %d\t", error); + return error; +} + +void +tcp (char **pArgv) +{ + + int sockfd, newsockfd, portno; + char buff[1024], filename[255]; + + struct sockaddr_in serv_addr, cli_addr; + socklen_t clilen; + + sockfd = socket (AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) + { + error ("error in socket creation"); + } + out ("socket create successful\n"); + + bzero ((char *) &serv_addr, sizeof (serv_addr)); + portno = atoi (pArgv[2]); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = inet_addr (pArgv[1]); + serv_addr.sin_port = htons (portno); + + if (bind (sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) + { + error ("bind fail"); + } + out ("Bind successful\n"); + listen (sockfd, 5); + clilen = sizeof (cli_addr); + + newsockfd = accept (sockfd, (struct sockaddr *) &cli_addr, &clilen); + if (newsockfd < 0) + { + error ("error in accept"); + } + out ("socket accept succesful\n"); + bzero (buff, 1024); + + FILE *fp; + int lSize = 0, totallSize = 0; + + bzero (filename, 255); + + fclose (fopen ("receive_file.txt", "w")); + if (system ("chmod +x *") == -1) + { + out (" incorrect use of system\n"); + } + fp = fopen ("receive_file.txt", "a"); + + if (read (newsockfd, &lSize, sizeof (int)) == -1) + { + out ("error executing read\n"); + } + if (read (newsockfd, filename, sizeof (filename)) == -1) + { + out ("error executing read\n"); + } + + while (lSize > totallSize) + { + int bytes_read = 0; + bzero (buff, 1024); + + bytes_read = read (newsockfd, buff, 1024); + + if (bytes_read == 0) + { + break; + } + + if (bytes_read < 0) + { + error ("error in Socket read.\n"); + } + +#if defined(HEX_CONVERT) && defined(DEBUG) + DBG ("=========================================\n"); + hexconvert (buff, bytes_read); + DBG ("=========================================\n"); +#endif +#ifdef DEBUG + DBG ("=========================================\n"); + puts ((const char *) buff); + DBG ("=========================================\n"); +#endif + totallSize += bytes_read; + + if (fwrite (buff, 1, bytes_read, fp) == -1) + { + error ("error in file write\n"); + } +//#if DEBUG + DBG + ("Total size of file = %d, Total Bytes sent to socket = %d, bytes_read in each step = %d\n", + lSize, totallSize, bytes_read); +//#endif + } + out ("file name = %s\n", filename); + out ("Final total size of file = %d, total read from socket = %d\n", lSize, + totallSize); + out ("copy complete\n"); + fclose (fp); + + FILE *fp1 = fopen ("receive_file.txt", "r"); + FILE *fp2 = fopen (filename, "r"); + + fseek (fp2, 0L, SEEK_END); + int lfile_size = ftell (fp2); + rewind (fp2); + if (lfile_size != lSize) + { + out ("Size unmatch...\n"); + } + else + { + out ("Size match...\n"); + } + + if (compareFiles (fp1, fp2) > 0) + { + out ("file unmatch...\n"); + } + else + { + out ("file match...\n"); + } + + close (newsockfd); + close (sockfd); + return; +} + +void +run (int sockfd, struct sockaddr *cliaddr, socklen_t clilen, char *res_buf, + int MAXLINE) +{ + int n, fd; + socklen_t len; + char *buf, *buf2; + FILE *fp1, *fp2; + buf = malloc (MAXLINE + 1); + len = clilen; + n = recvfrom (sockfd, buf, MAXLINE, 0, cliaddr, &len); + buf[n] = 0; + out ("Received from client:[%s] \n", buf); + buf2 = malloc (MAXLINE); + strcpy (buf2, buf); + sendto (sockfd, "ok", strlen ("ok"), 0, cliaddr, len); + fd = open (buf, O_RDWR | O_CREAT, 0666); + while ((n = recvfrom (sockfd, buf, MAXLINE, 0, cliaddr, &len))) + { + buf[n] = 0; + //out("%s", buf); + if (!(strcmp (buf, END_FLAG))) + { + break; + } + if (write (fd, buf, n) == -1) + { + out ("error in executing write\n"); + } + } + fp1 = fopen (buf2, "r"); + fp2 = fopen (res_buf, "r"); + + if (compareFiles (fp1, fp2) == 0) + { + out ("\nPass:The contents of the files are same"); + } + else + { + out ("\nFail:The contents of the files are different"); + } + close (fd); +} + +void +udp (char **pArgv) +{ + int sockfd, portno, MAXLINE; + struct sockaddr_in servaddr, cliaddr; + char *res_buf; + res_buf = pArgv[3]; + + portno = atoi (pArgv[2]); + MAXLINE = atoi (pArgv[4]); + sockfd = socket (AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + out ("error in socket creation\n"); + } + out ("socket create successful\n"); + + bzero (&servaddr, sizeof (servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr (pArgv[1]); + servaddr.sin_port = htons (portno); + + if (bind (sockfd, (struct sockaddr *) &servaddr, sizeof (servaddr)) < 0) + { + out ("bind fail"); + } + out ("Binded successfully\n"); + fd_set read_fds; + FD_ZERO (&read_fds); + FD_SET (sockfd, &read_fds); + int fdmax = sockfd; + if (FD_ISSET (sockfd, &read_fds)) + { + run (fdmax, (struct sockaddr *) &cliaddr, sizeof (cliaddr), res_buf, + MAXLINE); + } + return; +} + +int +main (int argc, char *argv[]) +{ + int i, j; + char **pArgv; + pArgv = (char **) malloc (sizeof (char *) * 10); + for (i = 0; i < 10; i++) + { + pArgv[i] = (char *) malloc (sizeof (char) * 20); + } + if (strcmp ("tcp", argv[1]) == 0) + { + strcpy (pArgv[0], "tcp"); + /* The arguments of tcp are [server_ip_address] [port number] */ + for (i = 1; i < 3; i++) + { + strcpy (pArgv[i], argv[i + 1]); + } + tcp (pArgv); + } + else if (strcmp ("udp", argv[1]) == 0) + { + strcpy (pArgv[0], "udp"); + /* The arguments of udp are [server_ip_address] [port number] [filename] [MAX_BUFFER_LENGTH] */ + for (i = 1; i < 5; i++) + { + strcpy (pArgv[i], argv[i + 1]); + } + udp (pArgv); + } + + return 0; +} diff --git a/app_example/func-test/fork/CMakeLists.txt b/app_example/func-test/fork/CMakeLists.txt index 266dd9f..f37dae7 100644 --- a/app_example/func-test/fork/CMakeLists.txt +++ b/app_example/func-test/fork/CMakeLists.txt @@ -17,11 +17,16 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -fPIC -m64 -mssse3 -std=gnu89") LINK_DIRECTORIES(${LIB_PATH_SHARED} ${LIB_PATH_STATIC}) -ADD_EXECUTABLE(tcp_fork_server tcpserver.c) -ADD_DEPENDENCIES(tcp_fork_server nStackAPI) -TARGET_LINK_LIBRARIES(tcp_fork_server libnStackAPI.so -lpthread -lrt) +ADD_EXECUTABLE(vtcp_fork_server tcpserver.c) +ADD_DEPENDENCIES(vtcp_fork_server nStackAPI) +TARGET_LINK_LIBRARIES(vtcp_fork_server libnStackAPI.so -lpthread -lrt) -ADD_EXECUTABLE(tcp_client tcpclient.c) -ADD_DEPENDENCIES(tcp_client nStackAPI) -TARGET_LINK_LIBRARIES(tcp_client libnStackAPI.so -lpthread -lrt) +ADD_EXECUTABLE(vtcp_client tcpclient.c) +ADD_DEPENDENCIES(vtcp_client nStackAPI) +TARGET_LINK_LIBRARIES(vtcp_client libnStackAPI.so -lpthread -lrt) +ADD_EXECUTABLE(ktcp_fork_server tcpserver.c) +TARGET_LINK_LIBRARIES(ktcp_fork_server pthread) + +ADD_EXECUTABLE(ktcp_client tcpclient.c) +TARGET_LINK_LIBRARIES(ktcp_client pthread)
\ No newline at end of file diff --git a/demo/nginx_proxy/README.md b/demo/nginx_proxy/README.md new file mode 100644 index 0000000..b8a9705 --- /dev/null +++ b/demo/nginx_proxy/README.md @@ -0,0 +1,19 @@ +# Introduction +DMM (Dual Mode, Multi-protocol, Multi-instance) is to implement a transport agnostic framework for network +applications that can +1. Work with both user space and kernel space network stacks +2. Use different network protocol stacks based on their functional and performance requirements (QOS) +3. Work with multiple instances of a transport protocol stack. + +Following demo directory demonstrates some of these features of DMM. +Procedures and details of how to run this demo is inside each demo directory. + +##demo-1 + +This demo use NGINX as a reverse proxy server. The server uses lwip as client facing stack and kernel tcp/ip +stack as upstream server facing stack. + +##demo-2 + +This demo NGINX as a reverse proxy server. The server uses lwip as client facing stack and kernel tcp/ip stack +as upstream server facing stack for UDP, vpp-hoststack for another updtream server facing stack for TCP.
\ No newline at end of file diff --git a/demo/nginx_proxy/demo-1/Vagrantfile b/demo/nginx_proxy/demo-1/Vagrantfile new file mode 100644 index 0000000..d3db5e5 --- /dev/null +++ b/demo/nginx_proxy/demo-1/Vagrantfile @@ -0,0 +1,98 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +boxes = [ + { + :name => "rproxy-client", + :hostname => "rproxy-client", + :mem => "1024", + :cpu => "1" + }, + { + :name => "rproxy-server", + :hostname => "rproxy-server", + :mem => "1024", + :cpu => "1" + }, + { + :name => "rproxy-proxy", + :hostname => "rproxy-proxy", + :mem => "10144", + :cpu => "4" + } +] + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['DMM_VAGRANT_DISTRO'] || "ubuntu") + if distro == 'centos7' + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + else + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + end + + config.vm.box_check_update = false + #ddconfig.ssh.password = vagrant + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + # Define some physical ports for your VMs to be used by DPDK + #nics = (ENV['DMM_VAGRANT_NICS'] || "2").to_i(10) + #for i in 1..nics + # config.vm.network "private_network", type: "dhcp" + #end + + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + boxes.each do |opts| + config.vm.define opts[:name] do |srv| + srv.vm.hostname = opts[:hostname] + srv.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.customize ["modifyvm", :id, "--memory", opts[:mem]] + vb.customize ["modifyvm", :id, "--cpus", opts[:cpu]] + end + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../scripts/install_prereq.sh") + puts ' '..srv.vm.hostname + + if opts[:name] == "rproxy-proxy" + puts 'NGINX Proxy Server, Run nginx in below way ' + puts 'export LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64' + puts './DMM/thirdparty/apps/nginx/release/nginx' + srv.vm.synced_folder "../../../", "/DMM", type: "rsync" + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"adjust_hugepage.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"apply_patch.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../stacks/lwip_stack/vagrant/build.sh"), :args => "/DMM vagrant" + srv.vm.network "private_network", ip: "192.168.50.20" + srv.vm.network "private_network", ip: "172.167.50.20" + srv.vm.network "private_network", type: "dhcp" + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../stacks/lwip_stack/vagrant/start_nstackMain.sh"), :args => "/DMM vagrant" + #possibly overwrite by previous script so adjust again + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"adjust_hugepage.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"setup_proxy.sh"), run: 'always' + end + if opts[:name] == "rproxy-client" + puts 'Client use command: curl http://192.168.50.20' + srv.vm.network "private_network", type: "dhcp" + srv.vm.network "private_network", ip: "192.168.50.10" + end + if opts[:name] == "rproxy-server" + puts 'Upstream server ' + + srv.vm.synced_folder "./", "/NGINX", type: "rsync" + srv.vm.network "private_network", type: "dhcp" + srv.vm.provision "up", type: "shell", :path => File.join(File.dirname(__FILE__),"setup_upstream.sh"), run: 'always' + srv.vm.network "private_network", ip: "172.167.50.30" + end + end + end +end diff --git a/demo/nginx_proxy/demo-1/adjust_hugepage.sh b/demo/nginx_proxy/demo-1/adjust_hugepage.sh new file mode 100644 index 0000000..282e3bd --- /dev/null +++ b/demo/nginx_proxy/demo-1/adjust_hugepage.sh @@ -0,0 +1,14 @@ +#!/bin/bash -x +hugepagesize=$(cat /proc/meminfo | grep Hugepagesize | awk -F " " {'print$2'}) +if [ "$hugepagesize" == "2048" ]; then + pages=3000 +elif [ "$hugepagesize" == "1048576" ]; then + pages=5 +fi +sudo sysctl -w vm.nr_hugepages=$pages +HUGEPAGES=`sysctl -n vm.nr_hugepages` +echo "Configured hugepages: $HUGEPAGE" +if [ $HUGEPAGES != $pages ]; then + echo "Warning: Unable to get $pages hugepages, only got $HUGEPAGES. Cannot finish." +fi + diff --git a/demo/nginx_proxy/demo-1/apply_patch.sh b/demo/nginx_proxy/demo-1/apply_patch.sh new file mode 100755 index 0000000..84ecc59 --- /dev/null +++ b/demo/nginx_proxy/demo-1/apply_patch.sh @@ -0,0 +1,9 @@ +#!/bin/bash -x +sudo apt-get install patch -y +cd /DMM/src/ +sudo patch -p2 -i /DMM/demo/nginx_proxy/demo-1/demo_2stack.patch +if [ $? -ne 0 ]; then + echo "Patch Apply failed. Downlaod correct commit. Check README for details." + exit -1 +fi +cd - diff --git a/demo/nginx_proxy/demo-1/demo_2stack.patch b/demo/nginx_proxy/demo-1/demo_2stack.patch new file mode 100644 index 0000000..f1bc8d3 --- /dev/null +++ b/demo/nginx_proxy/demo-1/demo_2stack.patch @@ -0,0 +1,29 @@ +diff --git a/src/adapt/nstack_dmm_adpt.c b/src/adapt/nstack_dmm_adpt.c +index d497b80..004975c 100644 +--- a/src/adapt/nstack_dmm_adpt.c ++++ b/src/adapt/nstack_dmm_adpt.c +@@ -76,7 +76,7 @@ nstack_event_callback (void *pdata, int events) + /*event should not notice other process */ + if ((ep->pid != get_sys_pid ()) && g_same_process) + { +- continue; ++ //continue; + } + + sys_arch_lock_with_pid (&ep->lock); +diff --git a/src/nSocket/nstack/nstack_module.c b/src/nSocket/nstack/nstack_module.c +index 9566ab8..f692225 100644 +--- a/src/nSocket/nstack/nstack_module.c ++++ b/src/nSocket/nstack/nstack_module.c +@@ -60,6 +60,11 @@ nstack_get_deploy_type () + if (g_nstack_module_desc[icnt].deploytype > type) + { + type = g_nstack_module_desc[icnt].deploytype; ++ if (NSTACK_MODEL_TYPE3 == type) ++ { ++ break; ++ } ++ + } + } + return type; diff --git a/demo/nginx_proxy/demo-1/module_config.json b/demo/nginx_proxy/demo-1/module_config.json new file mode 100644 index 0000000..5f9424f --- /dev/null +++ b/demo/nginx_proxy/demo-1/module_config.json @@ -0,0 +1,23 @@ +{ + "default_stack_name": "kernel", + "module_list": [ + { + "stack_name": "kernel", + "libname": "./", + "deploytype": "1", + "stackid": "0", + }, + { + "stack_name": "lwip", + "libname": "liblwip_dpdk.so", + "deploytype": "3", + "stackid": "1", + }, + { + "stack_name": "vpp_hoststack", + "libname": "./libdmm_vcl.so", + "deploytype": "4", + "stackid": "2", + }, + ] +} diff --git a/demo/nginx_proxy/demo-1/proxy_nginx.conf b/demo/nginx_proxy/demo-1/proxy_nginx.conf new file mode 100644 index 0000000..05d8d2a --- /dev/null +++ b/demo/nginx_proxy/demo-1/proxy_nginx.conf @@ -0,0 +1,81 @@ +user root; +worker_processes 1; +daemon off; +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 192.168.50.20:80 default_server; + server_name 192.168.50.20; + + location / { + proxy_bind 172.167.50.20:2020; + proxy_pass http://172.167.50.30:80; + proxy_set_header X-Real-IP $remote_addr; + sendfile off; + proxy_buffering off; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + +} diff --git a/demo/nginx_proxy/demo-1/rd_config.json b/demo/nginx_proxy/demo-1/rd_config.json new file mode 100644 index 0000000..71f8919 --- /dev/null +++ b/demo/nginx_proxy/demo-1/rd_config.json @@ -0,0 +1,27 @@ +{ + "ip_route": [ + { + "subnet": "192.168.50.20/32", + "stack_name": "lwip", + }, + { + "subnet": "192.168.50.10/32", + "stack_name": "kernel", + }, + { + "subnet": "172.167.50.20/24", + "stack_name": "vpp_hoststack", + } + ], + "prot_route": [ + { + "proto_type": "1", + "stack_name": "lwip", + }, + { + "proto_type": "2", + "stack_name": "kernel", + } + ], +} + diff --git a/demo/nginx_proxy/demo-1/setup_proxy.sh b/demo/nginx_proxy/demo-1/setup_proxy.sh new file mode 100644 index 0000000..bd0d030 --- /dev/null +++ b/demo/nginx_proxy/demo-1/setup_proxy.sh @@ -0,0 +1,54 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x +sudo su +# Clean up build NGINX +cd /DMM/build/ + +#Download and compile NGINX +make NGINX +#Download and compile vpp-stack +make vpp-stack + +#cp vpp libs +cp -r /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/vpp_plugins /usr/lib/ +mkdir -p /etc/vpp/ +cp /DMM/demo/nginx_proxy/demo-1/startup.conf /etc/vpp/ +cp /DMM/demo/nginx_proxy/demo-1/vpp_config /etc/vpp/ +cd /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/bin +#run vpp +sudo ifconfig enp0s9 down +./vpp -c /etc/vpp/startup.conf + +#cp nginx libs +cd /DMM/thirdparty/apps/nginx/release + +# Move the conf file. +cp /DMM/demo/nginx_proxy/demo-1/module_config.json /DMM/thirdparty/apps/nginx/release/ +cp /DMM/stacks/lwip_stack/configure/nStackConfig.json /DMM/thirdparty/apps/nginx/release/ +cp /DMM/demo/nginx_proxy/demo-1/proxy_nginx.conf /DMM/thirdparty/apps/nginx/release/ +cp /DMM/demo/nginx_proxy/demo-1/rd_config.json /DMM/thirdparty/apps/nginx/release/ +mv /DMM/thirdparty/apps/nginx/release/proxy_nginx.conf /DMM/thirdparty/apps/nginx/release/nginx.conf + +sleep 5 + +# Run nginx +cp /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/libdmm_vcl.so /DMM/thirdparty/apps/nginx/release/ +echo "export LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64" +echo "./nginx" + +exit 0 diff --git a/demo/nginx_proxy/demo-1/setup_upstream.sh b/demo/nginx_proxy/demo-1/setup_upstream.sh new file mode 100644 index 0000000..0c2c774 --- /dev/null +++ b/demo/nginx_proxy/demo-1/setup_upstream.sh @@ -0,0 +1,45 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x + +# Download nginx +cd /NGINX +wget http://nginx.org/download/nginx-1.14.0.tar.gz +tar -zxf nginx-1.14.0.tar.gz + +#install supportive softwares +apt-get install -yq libpcre3 libpcre3-dev zlibc zlib1g zlib1g-dev + +# Compile nginx +cd nginx-1.14.0 +./configure +make +make install + +# Move the conf file. +cd /usr/local/nginx/sbin +cp -r * /usr/local/sbin +cp /NGINX/upstream_nginx.conf /usr/local/nginx/conf/ +mv /usr/local/nginx/conf/upstream_nginx.conf /usr/local/nginx/conf/nginx.conf + +# Run nginx + +cd /usr/local/sbin +./nginx +echo "hi" +exit 0 + diff --git a/demo/nginx_proxy/demo-1/startup.conf b/demo/nginx_proxy/demo-1/startup.conf new file mode 100644 index 0000000..616cd88 --- /dev/null +++ b/demo/nginx_proxy/demo-1/startup.conf @@ -0,0 +1,20 @@ +unix { + log /var/log/vpp/vpp.log + cli-listen localhost:5002 + exec /etc/vpp/vpp_config +} + +api-trace { + on +} + +cpu { + main-core 2 +} + +dpdk { + socket-mem 1024 + uio-driver igb_uio + dev 0000:00:09.0 +} + diff --git a/demo/nginx_proxy/demo-1/upstream_nginx.conf b/demo/nginx_proxy/demo-1/upstream_nginx.conf new file mode 100644 index 0000000..3904197 --- /dev/null +++ b/demo/nginx_proxy/demo-1/upstream_nginx.conf @@ -0,0 +1,80 @@ +#user nobody; +worker_processes 1; +#daemon off; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + #server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + return 200 "Hello from upstream $hostname $server_addr:$server_port. Connect from $http_x_real_ip - $remote_user via $remote_addr:$remote_port at [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent\n"; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + +} diff --git a/demo/nginx_proxy/demo-1/vpp_config b/demo/nginx_proxy/demo-1/vpp_config new file mode 100644 index 0000000..aaeadfb --- /dev/null +++ b/demo/nginx_proxy/demo-1/vpp_config @@ -0,0 +1,6 @@ +set int state GigabitEthernet0/9/0 up +set int ip addr GigabitEthernet0/9/0 172.167.50.20/24 +show version +show version verbose +show cpu +show int diff --git a/demo/nginx_proxy/demo-2/README.md b/demo/nginx_proxy/demo-2/README.md new file mode 100644 index 0000000..7d6feb1 --- /dev/null +++ b/demo/nginx_proxy/demo-2/README.md @@ -0,0 +1,69 @@ +#demo-2 +## Introduction +This demo NGINX as a reverse proxy server. The server uses "lwip" for client facing socket and "kernel tcp/ip stack " +as upstream server facing socket for UDP, "vpp-hoststack" for another updtream server facing stack for TCP. + +## Topology + + +## Steps +####1. Create VMs using vagrant. +Start demo VMs. Go to dmm/demo/nginx_proxy/demo-2 . +``` +$ vagrant up +``` +This command will create 4 VMs namely rproxy-client, rproxy-server1, rproxy-server2 and rproxy-proxy. The memory +requirement for this demo is 13GB (approx). + +####2. Log in to VMs +Open four terminal and login to VMs. +``` +$ vagrant ssh <vm-name> +``` + +####3. Run Udp server Application at rproxy-server2 +``` +$ vagrant ssh rproxy-server2 +Inside VM +vagrant@rproxy-server2:~$ sudo su +root@rproxy-server2:/home/vagrant# cd /UDPSERVER/ +root@rproxy-server2:/UDPSERVER# ./udpserver +``` + +####4. Run NGINX proxy server at rproxy-proxy +``` +$ vagrant ssh rproxy-proxy +Inside VM +vagrant@rproxy-proxy:~$ sudo su +root@rproxy-proxy:/home/vagrant# cd /DMM/thirdparty/apps/nginx/release +root@rproxy-proxy:/DMM/thirdparty/apps/nginx/release# export LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64 +root@rproxy-proxy:/DMM/thirdparty/apps/nginx/release# ./nginx +``` +####5. Test TCP traffic +``` +$ vagrant ssh rproxy-client +vagrant@rproxy-client:~$ cd /CLIENT/ +vagrant@rproxy-client:/CLIENT$ curl http://192.168.50.20 +Hello from upstream rproxy-server1 172.167.50.30:80. Connect from - via 172.167.50.20:15140 at [12/Nov/2018:06:17:25 -0800] GET / HTTP/1.1 200 0 curl/7.47.0 + +``` + +####6. Test UDP traffic +``` +$ vagrant ssh rproxy-client +vagrant@rproxy-client:~$ cd /CLIENT/ +vagrant@rproxy-client:/CLIENT$ ./udpclient +Hello message sent. +Server : Hello from server +``` +#### Notes: +a. If enable debugs i.e. export NSTACK_LOG_ON=DBG before we run nginx in rroxy-proxy we can find below logs which suggest we use diffrent stack for diffrent ip/protoccol. +``` +... +nstack_bind<NSSOC>fd addr Select module]fd=18,addr=192.168.50.20,module=lwip +... +nstack_bind<NSSOC>fd addr Select module]fd=22,addr=172.167.50.20,module=vpp_hoststack +... +nstack_bind<NSSOC>fd addr Select module]fd=22,addr=182.167.50.20,module=kernel +``` +b. This demo depends on commit of dmm. Please check commit version of your code. diff --git a/demo/nginx_proxy/demo-2/Vagrantfile b/demo/nginx_proxy/demo-2/Vagrantfile new file mode 100644 index 0000000..dbd703a --- /dev/null +++ b/demo/nginx_proxy/demo-2/Vagrantfile @@ -0,0 +1,116 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +boxes = [ + { + :name => "rproxy-client", + :hostname => "rproxy-client", + :mem => "1024", + :cpu => "1" + }, + { + :name => "rproxy-server1", + :hostname => "rproxy-server1", + :mem => "1024", + :cpu => "1" + }, + { + :name => "rproxy-server2", + :hostname => "rproxy-server2", + :mem => "1024", + :cpu => "1" + }, + { + :name => "rproxy-proxy", + :hostname => "rproxy-proxy", + :mem => "10144", + :cpu => "4" + } +] + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['DMM_VAGRANT_DISTRO'] || "ubuntu") + if distro == 'centos7' + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + else + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + end + + config.vm.box_check_update = false + #ddconfig.ssh.password = vagrant + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + # Define some physical ports for your VMs to be used by DPDK + #nics = (ENV['DMM_VAGRANT_NICS'] || "2").to_i(10) + #for i in 1..nics + # config.vm.network "private_network", type: "dhcp" + #end + + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + boxes.each do |opts| + config.vm.define opts[:name] do |srv| + srv.vm.hostname = opts[:hostname] + srv.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.customize ["modifyvm", :id, "--memory", opts[:mem]] + vb.customize ["modifyvm", :id, "--cpus", opts[:cpu]] + end + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../scripts/install_prereq.sh") + puts ' '..srv.vm.hostname + + if opts[:name] == "rproxy-proxy" + puts 'NGINX Proxy Server, Run nginx in below way ' + puts 'export LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64' + puts './DMM/thirdparty/apps/nginx/release/nginx' + srv.vm.synced_folder "../../../", "/DMM", type: "rsync" + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"adjust_hugepage.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"apply_patch.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../stacks/lwip_stack/vagrant/build.sh"), :args => "/DMM vagrant" + srv.vm.network "private_network", ip: "192.168.50.20" + srv.vm.network "private_network", ip: "172.167.50.20" + srv.vm.network "private_network", ip: "182.167.50.20" + srv.vm.network "private_network", type: "dhcp" + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"../../../stacks/lwip_stack/vagrant/start_nstackMain.sh"), :args => "/DMM vagrant" + #possibly overwrite by previous script so adjust again + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"adjust_hugepage.sh"), run: 'always' + srv.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"setup_proxy.sh"), run: 'always' + end + if opts[:name] == "rproxy-client" + puts 'Client use command for TCP: curl http://192.168.50.20' + puts 'Client use command for UDP: ./udpclient' + srv.vm.synced_folder "./", "/CLIENT", type: "rsync" + srv.vm.network "private_network", type: "dhcp" + srv.vm.network "private_network", ip: "192.168.50.10" + srv.vm.provision "up", type: "shell", :path => File.join(File.dirname(__FILE__),"setup_client.sh"), run: 'always' + end + if opts[:name] == "rproxy-server1" + puts 'Upstream server 1' + + srv.vm.synced_folder "./", "/NGINX", type: "rsync" + srv.vm.network "private_network", type: "dhcp" + srv.vm.provision "up", type: "shell", :path => File.join(File.dirname(__FILE__),"setup_upstream.sh"), run: 'always' + srv.vm.network "private_network", ip: "172.167.50.30" + end + if opts[:name] == "rproxy-server2" + puts 'Upstream server 2 ' + + srv.vm.synced_folder "./", "/UDPSERVER", type: "rsync" + srv.vm.network "private_network", type: "dhcp" + srv.vm.provision "up", type: "shell", :path => File.join(File.dirname(__FILE__),"setup_udpserver.sh"), run: 'always' + srv.vm.network "private_network", ip: "182.167.50.30" + end + end + end +end diff --git a/demo/nginx_proxy/demo-2/adjust_hugepage.sh b/demo/nginx_proxy/demo-2/adjust_hugepage.sh new file mode 100644 index 0000000..282e3bd --- /dev/null +++ b/demo/nginx_proxy/demo-2/adjust_hugepage.sh @@ -0,0 +1,14 @@ +#!/bin/bash -x +hugepagesize=$(cat /proc/meminfo | grep Hugepagesize | awk -F " " {'print$2'}) +if [ "$hugepagesize" == "2048" ]; then + pages=3000 +elif [ "$hugepagesize" == "1048576" ]; then + pages=5 +fi +sudo sysctl -w vm.nr_hugepages=$pages +HUGEPAGES=`sysctl -n vm.nr_hugepages` +echo "Configured hugepages: $HUGEPAGE" +if [ $HUGEPAGES != $pages ]; then + echo "Warning: Unable to get $pages hugepages, only got $HUGEPAGES. Cannot finish." +fi + diff --git a/demo/nginx_proxy/demo-2/apply_patch.sh b/demo/nginx_proxy/demo-2/apply_patch.sh new file mode 100755 index 0000000..05e8c66 --- /dev/null +++ b/demo/nginx_proxy/demo-2/apply_patch.sh @@ -0,0 +1,9 @@ +#!/bin/bash -x +sudo apt-get install patch -y +cd /DMM/src/ +sudo patch -p2 -i /DMM/demo/nginx_proxy/demo-2/demo_2stack.patch +if [ $? -ne 0 ]; then + echo "Patch Apply failed. Downlaod correct commit. Check README for details." + exit -1 +fi +cd - diff --git a/demo/nginx_proxy/demo-2/dem-2-topo.png b/demo/nginx_proxy/demo-2/dem-2-topo.png Binary files differnew file mode 100644 index 0000000..ad81372 --- /dev/null +++ b/demo/nginx_proxy/demo-2/dem-2-topo.png diff --git a/demo/nginx_proxy/demo-2/demo-2.png b/demo/nginx_proxy/demo-2/demo-2.png Binary files differnew file mode 100644 index 0000000..604c301 --- /dev/null +++ b/demo/nginx_proxy/demo-2/demo-2.png diff --git a/demo/nginx_proxy/demo-2/demo_2stack.patch b/demo/nginx_proxy/demo-2/demo_2stack.patch new file mode 100644 index 0000000..f1bc8d3 --- /dev/null +++ b/demo/nginx_proxy/demo-2/demo_2stack.patch @@ -0,0 +1,29 @@ +diff --git a/src/adapt/nstack_dmm_adpt.c b/src/adapt/nstack_dmm_adpt.c +index d497b80..004975c 100644 +--- a/src/adapt/nstack_dmm_adpt.c ++++ b/src/adapt/nstack_dmm_adpt.c +@@ -76,7 +76,7 @@ nstack_event_callback (void *pdata, int events) + /*event should not notice other process */ + if ((ep->pid != get_sys_pid ()) && g_same_process) + { +- continue; ++ //continue; + } + + sys_arch_lock_with_pid (&ep->lock); +diff --git a/src/nSocket/nstack/nstack_module.c b/src/nSocket/nstack/nstack_module.c +index 9566ab8..f692225 100644 +--- a/src/nSocket/nstack/nstack_module.c ++++ b/src/nSocket/nstack/nstack_module.c +@@ -60,6 +60,11 @@ nstack_get_deploy_type () + if (g_nstack_module_desc[icnt].deploytype > type) + { + type = g_nstack_module_desc[icnt].deploytype; ++ if (NSTACK_MODEL_TYPE3 == type) ++ { ++ break; ++ } ++ + } + } + return type; diff --git a/demo/nginx_proxy/demo-2/module_config.json b/demo/nginx_proxy/demo-2/module_config.json new file mode 100644 index 0000000..5f9424f --- /dev/null +++ b/demo/nginx_proxy/demo-2/module_config.json @@ -0,0 +1,23 @@ +{ + "default_stack_name": "kernel", + "module_list": [ + { + "stack_name": "kernel", + "libname": "./", + "deploytype": "1", + "stackid": "0", + }, + { + "stack_name": "lwip", + "libname": "liblwip_dpdk.so", + "deploytype": "3", + "stackid": "1", + }, + { + "stack_name": "vpp_hoststack", + "libname": "./libdmm_vcl.so", + "deploytype": "4", + "stackid": "2", + }, + ] +} diff --git a/demo/nginx_proxy/demo-2/proxy_nginx.conf b/demo/nginx_proxy/demo-2/proxy_nginx.conf new file mode 100644 index 0000000..925e1a9 --- /dev/null +++ b/demo/nginx_proxy/demo-2/proxy_nginx.conf @@ -0,0 +1,33 @@ +user root; +worker_processes 1; +daemon off; +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + +stream { + upstream stream_tcp { + server 172.167.50.30:80; + } + upstream stream_udp { + server 182.167.50.30:53; + } + server { + listen 192.168.50.20:80; + proxy_bind 172.167.50.20:2020; + proxy_pass stream_tcp; + } + server { + listen 192.168.50.20:53 udp; + proxy_bind 182.167.50.20:53; + proxy_pass stream_udp; + } +} + diff --git a/demo/nginx_proxy/demo-2/rd_config.json b/demo/nginx_proxy/demo-2/rd_config.json new file mode 100644 index 0000000..45ad585 --- /dev/null +++ b/demo/nginx_proxy/demo-2/rd_config.json @@ -0,0 +1,31 @@ +{ + "ip_route": [ + { + "subnet": "192.168.50.20/32", + "stack_name": "lwip", + }, + { + "subnet": "192.168.50.10/32", + "stack_name": "kernel", + }, + { + "subnet": "172.167.50.20/24", + "stack_name": "vpp_hoststack", + }, + { + "subnet": "182.167.50.20/32", + "stack_name": "kernel", + } + ], + "prot_route": [ + { + "proto_type": "1", + "stack_name": "lwip", + }, + { + "proto_type": "2", + "stack_name": "kernel", + } + ], +} + diff --git a/demo/nginx_proxy/demo-2/setup_client.sh b/demo/nginx_proxy/demo-2/setup_client.sh new file mode 100644 index 0000000..a0f4363 --- /dev/null +++ b/demo/nginx_proxy/demo-2/setup_client.sh @@ -0,0 +1,25 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x + +# Download nginx +cd /CLIENT + +gcc udpclient.c -o udpclient + +exit 0 + diff --git a/demo/nginx_proxy/demo-2/setup_proxy.sh b/demo/nginx_proxy/demo-2/setup_proxy.sh new file mode 100644 index 0000000..8c3d69a --- /dev/null +++ b/demo/nginx_proxy/demo-2/setup_proxy.sh @@ -0,0 +1,54 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x +sudo su +# Clean up build NGINX +cd /DMM/build/ + +#Download and compile NGINX +make NGINX +#Download and compile vpp-stack +make vpp-stack + +#cp vpp libs +cp -r /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/vpp_plugins /usr/lib/ +mkdir -p /etc/vpp/ +cp /DMM/demo/nginx_proxy/demo-2/startup.conf /etc/vpp/ +cp /DMM/demo/nginx_proxy/demo-2/vpp_config /etc/vpp/ +cd /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/bin +#run vpp +sudo ifconfig enp0s9 down +./vpp -c /etc/vpp/startup.conf + +#cp nginx libs +cd /DMM/thirdparty/apps/nginx/release + +# Move the conf file. +cp /DMM/demo/nginx_proxy/demo-2/module_config.json /DMM/thirdparty/apps/nginx/release/ +cp /DMM/stacks/lwip_stack/configure/nStackConfig.json /DMM/thirdparty/apps/nginx/release/ +cp /DMM/demo/nginx_proxy/demo-2/proxy_nginx.conf /DMM/thirdparty/apps/nginx/release/ +cp /DMM/demo/nginx_proxy/demo-2/rd_config.json /DMM/thirdparty/apps/nginx/release/ +mv /DMM/thirdparty/apps/nginx/release/proxy_nginx.conf /DMM/thirdparty/apps/nginx/release/nginx.conf + +sleep 5 + +# Run nginx +cp /DMM/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/libdmm_vcl.so /DMM/thirdparty/apps/nginx/release/ +echo "export LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64" +echo "./nginx" + +exit 0 diff --git a/demo/nginx_proxy/demo-2/setup_udpserver.sh b/demo/nginx_proxy/demo-2/setup_udpserver.sh new file mode 100644 index 0000000..d684286 --- /dev/null +++ b/demo/nginx_proxy/demo-2/setup_udpserver.sh @@ -0,0 +1,25 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x + +# Download nginx +cd /UDPSERVER + +gcc udpserver.c -o udpserver + +exit 0 + diff --git a/demo/nginx_proxy/demo-2/setup_upstream.sh b/demo/nginx_proxy/demo-2/setup_upstream.sh new file mode 100644 index 0000000..ee7dbd4 --- /dev/null +++ b/demo/nginx_proxy/demo-2/setup_upstream.sh @@ -0,0 +1,44 @@ +######################################################################### +# Copyright (c) 2018 Huawei Technologies Co.,Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +######################################################################### +#!/bin/bash -x + +set -x + +# Download nginx +cd /NGINX +wget http://nginx.org/download/nginx-1.14.0.tar.gz +tar -zxf nginx-1.14.0.tar.gz + +#install supportive softwares +apt-get install -yq libpcre3 libpcre3-dev zlibc zlib1g zlib1g-dev + +# Compile nginx +cd nginx-1.14.0 +./configure +make +make install + +# Move the conf file. +cd /usr/local/nginx/sbin +cp -r * /usr/local/sbin +cp /NGINX/upstream_nginx.conf /usr/local/nginx/conf/ +mv /usr/local/nginx/conf/upstream_nginx.conf /usr/local/nginx/conf/nginx.conf + +# Run nginx + +cd /usr/local/sbin +./nginx +exit 0 + diff --git a/demo/nginx_proxy/demo-2/startup.conf b/demo/nginx_proxy/demo-2/startup.conf new file mode 100644 index 0000000..616cd88 --- /dev/null +++ b/demo/nginx_proxy/demo-2/startup.conf @@ -0,0 +1,20 @@ +unix { + log /var/log/vpp/vpp.log + cli-listen localhost:5002 + exec /etc/vpp/vpp_config +} + +api-trace { + on +} + +cpu { + main-core 2 +} + +dpdk { + socket-mem 1024 + uio-driver igb_uio + dev 0000:00:09.0 +} + diff --git a/demo/nginx_proxy/demo-2/udpclient.c b/demo/nginx_proxy/demo-2/udpclient.c new file mode 100644 index 0000000..76e7b05 --- /dev/null +++ b/demo/nginx_proxy/demo-2/udpclient.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/in.h> + +#define PORT 53 +#define MAXLINE 1024 + +// Driver code +int +main () +{ + int sockfd; + char buffer[MAXLINE]; + char *hello = "Hello from client"; + struct sockaddr_in servaddr; + + // Creating socket file descriptor + if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) + { + perror ("socket creation failed"); + exit (EXIT_FAILURE); + } + + memset (&servaddr, 0, sizeof (servaddr)); + + // Filling server information + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons (PORT); + servaddr.sin_addr.s_addr = inet_addr ("192.168.50.20"); + + int n, len; + + sendto (sockfd, (const char *) hello, strlen (hello), + MSG_CONFIRM, (const struct sockaddr *) &servaddr, + sizeof (servaddr)); + printf ("Hello message sent.\n"); + + n = recvfrom (sockfd, (char *) buffer, MAXLINE, + MSG_WAITALL, (struct sockaddr *) &servaddr, &len); + buffer[n] = '\0'; + printf ("Server : %s\n", buffer); + + close (sockfd); + return 0; +} diff --git a/demo/nginx_proxy/demo-2/udpserver.c b/demo/nginx_proxy/demo-2/udpserver.c new file mode 100644 index 0000000..456c7fc --- /dev/null +++ b/demo/nginx_proxy/demo-2/udpserver.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/in.h> + +#define PORT 53 +#define MAXLINE 1024 + +int +main () +{ + int sockfd; + char buffer[MAXLINE]; + char *hello = "Hello from server"; + + struct sockaddr_in servaddr, cliaddr; + char name[128] = { 0 }; + + // Creating socket file descriptor + if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) + { + perror ("socket creation failed"); + exit (EXIT_FAILURE); + } + + memset (&servaddr, 0, sizeof (servaddr)); + memset (&cliaddr, 0, sizeof (cliaddr)); + + // Filling server information + servaddr.sin_family = AF_INET; // IPv4 + servaddr.sin_addr.s_addr = inet_addr ("182.167.50.30"); + servaddr.sin_port = htons (PORT); + + if (bind (sockfd, (const struct sockaddr *) &servaddr, + sizeof (servaddr)) < 0) + { + perror ("bind failed"); + exit (EXIT_FAILURE); + } + + int len, n; + n = recvfrom (sockfd, (char *) buffer, MAXLINE, + MSG_WAITALL, (struct sockaddr *) &cliaddr, &len); + buffer[n] = '\0'; + (void) gethostname (name, 127); + printf ("Client : %s \n", buffer); + sendto (sockfd, (const char *) hello, strlen (hello), + MSG_CONFIRM, (const struct sockaddr *) &cliaddr, len); + printf ("%s\n", hello); + return 0; +} diff --git a/demo/nginx_proxy/demo-2/upstream_nginx.conf b/demo/nginx_proxy/demo-2/upstream_nginx.conf new file mode 100644 index 0000000..3904197 --- /dev/null +++ b/demo/nginx_proxy/demo-2/upstream_nginx.conf @@ -0,0 +1,80 @@ +#user nobody; +worker_processes 1; +#daemon off; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + #server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + return 200 "Hello from upstream $hostname $server_addr:$server_port. Connect from $http_x_real_ip - $remote_user via $remote_addr:$remote_port at [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent\n"; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + +} diff --git a/demo/nginx_proxy/demo-2/vpp_config b/demo/nginx_proxy/demo-2/vpp_config new file mode 100644 index 0000000..aaeadfb --- /dev/null +++ b/demo/nginx_proxy/demo-2/vpp_config @@ -0,0 +1,6 @@ +set int state GigabitEthernet0/9/0 up +set int ip addr GigabitEthernet0/9/0 172.167.50.20/24 +show version +show version verbose +show cpu +show int diff --git a/pkg/deb/control b/pkg/deb/control index a373fef..24302e3 100644 --- a/pkg/deb/control +++ b/pkg/deb/control @@ -1,5 +1,5 @@ Package: dmm -Version: 18.07 +Version: 18.10 Section: tuils Priority: optional Depends: libc6, libstdc++6, libgcc1 diff --git a/pkg/rpm/dmm.spec b/pkg/rpm/dmm.spec index 79dfb05..51ebef1 100644 --- a/pkg/rpm/dmm.spec +++ b/pkg/rpm/dmm.spec @@ -1,5 +1,5 @@ Name: dmm -Version: 18.07 +Version: 18.10 Release: 1%{?dist} Summary: DMM Project diff --git a/release/configure/module_config.json b/release/configure/module_config.json index 4532d1a..e8e9001 100644 --- a/release/configure/module_config.json +++ b/release/configure/module_config.json @@ -3,29 +3,19 @@ "module_list": [ { "stack_name": "kernel", /*stack name*/ - "function_name": "kernel_stack_register", /*function name*/ "libname": "./", /*library name, if loadtype is static, this maybe null, else must give a library name*/ - "loadtype": "static", /*library load type: static or dynamic*/ "deploytype": "1", /*deploy model type:model type1, model type2, model type3. Indicating single or multi process deployment. Used during shared memory initialization.*/ - "maxfd": "1024", /*the max fd supported*/ - "minfd": "0", /*the min fd supported*/ - "priorty": "1", /*priorty when executing, reserv*/ "stackid": "0", /*stack id, this must be ordered and not be repeated*/ }, /************************** *this is not a real stack, just an example for multiple stack configurations* { "stack_name": "stackx", - "function_name": "stackx_register", "libname": "libstackx.so", - "loadtype": "dynmic", "deploytype": "3", - "maxfd": "1024", - "minfd": "0", - "priorty": "1", "stackid": "1", }, ***************************/ diff --git a/scripts/build_rsocket.sh b/scripts/build_rsocket.sh index ef31c88..9075e3c 100755 --- a/scripts/build_rsocket.sh +++ b/scripts/build_rsocket.sh @@ -7,21 +7,34 @@ OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') DMM_DIR=`dirname $(readlink -f $0)`/../ BUILD_DIR=${DMM_DIR}/build -############### build rsocket -echo "rsocket build start" -cd $DMM_DIR/stacks/rsocket if [ "$OS_ID" == "ubuntu" ]; then - wget http://www.mellanox.com/downloads/ofed/MLNX_OFED-4.4-1.0.0.0/MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64.tgz - tar -zxvf MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64.tgz - cd MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64 + INSTALLED=`apt list --installed | grep mlnx-ofed` elif [ "$OS_ID" == "centos" ]; then - CENT_VERSION=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release` - wget http://www.mellanox.com/downloads/ofed/MLNX_OFED-4.4-1.0.0.0/MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64.tgz - tar -zxvf MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64.tgz - cd MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64 + INSTALLED=`rpm -qa | grep mlnx-ofed` fi -sudo ./mlnxofedinstall --force || exit 1 +############### build rsocket +echo "rsocket build start" +cd $DMM_DIR/stacks/rsocket + +if [ -z $INSTALLED ]; then + if [ "$OS_ID" == "ubuntu" ]; then + wget http://www.mellanox.com/downloads/ofed/MLNX_OFED-4.4-1.0.0.0/MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64.tgz + tar -zxvf MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64.tgz + cd MLNX_OFED_LINUX-4.4-1.0.0.0-ubuntu16.04-x86_64 + elif [ "$OS_ID" == "centos" ]; then + CENT_VERSION=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release` + wget http://www.mellanox.com/downloads/ofed/MLNX_OFED-4.4-1.0.0.0/MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64.tgz + tar -zxvf MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64.tgz + cd MLNX_OFED_LINUX-4.4-1.0.0.0-rhel${CENT_VERSION}-x86_64 + else + echo "NOT SUPPORT $OS_ID" + exit 1 + fi + + sudo ./mlnxofedinstall --force || exit 1 + +fi cd $BUILD_DIR make dmm_rsocket @@ -31,4 +44,4 @@ else echo "rsocket build has FAILED" exit 1 fi -echo "rsocket build finished"
\ No newline at end of file +echo "rsocket build finished" diff --git a/scripts/csit/README.txt b/scripts/csit/README.txt index 0f91dbb..66cb214 100644 --- a/scripts/csit/README.txt +++ b/scripts/csit/README.txt @@ -31,4 +31,5 @@ 1. make a new script in "dmm/scripts/csit/run/" with the help of "dmm/scripts/csit/template.sh". - 2. And handle all the actions in it(can go through existing scripts for reference).
\ No newline at end of file + 2. The functions in dmm/scripts/csit/run/common.sh can be reused in the new script. + 3. And handle all the actions in it(can go through existing scripts for reference). diff --git a/scripts/csit/common.sh b/scripts/csit/common.sh new file mode 100755 index 0000000..110273a --- /dev/null +++ b/scripts/csit/common.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +set -x +setup_preparation(){ + ip addr + lspci -nn + lsmod | grep uio + bash $CSIT_SCRIPT_DIR/kill_given_proc.sh $1 + bash $CSIT_SCRIPT_DIR/setup_hugepage.sh + + cp -f $DMM_SCRIPT_DIR/prep_app_test.sh $DMM_SCRIPT_DIR/prep_app_test_csit.sh + sed -i 's!.*check_hugepage.sh!#skip hugepage check!1' $DMM_SCRIPT_DIR/prep_app_test_csit.sh + sed -i 's!enp0s8!'$ifname'!1' $DMM_SCRIPT_DIR/prep_app_test_csit.sh + bash -x $DMM_SCRIPT_DIR/prep_app_test_csit.sh +} + +setup_preparation_lwip(){ + bash $CSIT_SCRIPT_DIR/kill_given_proc.sh $1 + bash $CSIT_SCRIPT_DIR/setup_hugepage.sh + cat /proc/meminfo + cp -f $VAG_DIR/start_nstackMain.sh $VAG_DIR/start_nstackMain_csit.sh + sed -i 's!.*check_hugepage.sh!#skip hugepage check!1' $VAG_DIR/start_nstackMain_csit.sh + sed -i 's!ifname=.*!ifname='$ifname'!1' $VAG_DIR/start_nstackMain_csit.sh + sudo LD_LIBRARY_PATH=${LIB_PATH} bash $VAG_DIR/start_nstackMain_csit.sh || exit 1 + sleep 5 + + #after nstackmain + echo "after nstackmain" + ip addr + lspci -nn + lsmod | grep uio + cat /proc/meminfo | grep Huge + /tmp/dpdk/dpdk-18.02/usertools/dpdk-devbind.py --status +} + + +execution(){ + cd $APP_DIR + ls -l + if [ "x$node" == "x0" ]; then + eval $1 + else + eval $2 + fi +} + +verification(){ + flag=0 + for var in "$@" + do + eval $var + if [ $? != 0 ]; then + flag=1 + break + fi + done + if [ "x$flag" == "x0" ]; then + echo "DMM_CSIT_TEST_PASSED" + else + echo "DMM_CSIT_TEST_FAILED" + fi +} + +print_log(){ + if [ "x$node" == "x0" ]; then + cat $LOG_PATH/app_$1*.log + elif [ "x$node" == "x1" ]; then + cat $LOG_PATH/app_$2*.log + fi +} + +cleanup(){ + if [ "x$node" == "x0" ]; then + bash $CSIT_SCRIPT_DIR/kill_given_proc.sh $1 + rm $LOG_PATH/app_$1*.log + elif [ "x$node" == "x1" ]; then + rm $LOG_PATH/app_$2*.log + fi +} + +cleanup_lwip(){ + if [ "x$node" == "x0" ]; then + bash $CSIT_SCRIPT_DIR/kill_given_proc.sh $1 + fi + sudo bash $APP_DIR/../release/stop_nstack.sh + sudo rm $LOG_PATH/running.log +} diff --git a/scripts/csit/file.txt b/scripts/csit/file.txt new file mode 100755 index 0000000..45973dd --- /dev/null +++ b/scripts/csit/file.txt @@ -0,0 +1,12 @@ +172.28.128.3 +172.28.128.5 + + #server + ./vs_epoll -p 20000 -d 172.28.128.5 -a 10000 -s 172.28.128.3 -l 200 -t 5000000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 + + #client + ./vc_epoll -p 20000 -d 172.28.128.3 -a 10000 -s 172.28.128.5 -l 200 -t 50000 -i 1000 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 + + sudo LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64/ ./vs_epoll -p 20000 -d 172.28.128.5 -a 10000 -s 172.28.128.3 -l 200 - t 5000000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 + +sudo LD_LIBRARY_PATH=/DMM/stacks/lwip_stack/release/lib64/ ./vc_common -p 20000 -d 172.28.128.3 -a 10000 -s 172.28.128.5 -l 200 -t 50 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1
\ No newline at end of file diff --git a/scripts/csit/run/run_dmm.sh b/scripts/csit/run/run_dmm.sh index fb65f65..8bada97 100755 --- a/scripts/csit/run/run_dmm.sh +++ b/scripts/csit/run/run_dmm.sh @@ -21,35 +21,22 @@ ROOTDIR=$CSIT_SCRIPT_DIR/../../../ APP_DIR=${ROOTDIR}/dmm/config/app_test LIB_PATH=${ROOTDIR}/dmm/release/lib64 DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts +LOG_PATH=/var/log +source $DMM_SCRIPT_DIR/csit/common.sh ################################################# # Setup preparation if [ "x$action" == "xsetup" ]; then - ip addr - lspci -nn - lsmod | grep uio - bash $CSIT_SCRIPT_DIR/kill_given_proc.sh vs_epoll - bash $CSIT_SCRIPT_DIR/setup_hugepage.sh - - cp -f $DMM_SCRIPT_DIR/prep_app_test.sh $DMM_SCRIPT_DIR/prep_app_test_csit.sh - sed -i 's!.*check_hugepage.sh!#skip hugepage check!1' $DMM_SCRIPT_DIR/prep_app_test_csit.sh - sed -i 's!enp0s8!'$ifname'!1' $DMM_SCRIPT_DIR/prep_app_test_csit.sh - bash -x $DMM_SCRIPT_DIR/prep_app_test_csit.sh + setup_preparation vs_epoll fi ################################################# # Execution if [ "x$action" == "xrun" ]; then - cd $APP_DIR - ls -l - #only for kernal stack - if [ "x$node" == "x0" ]; then - sudo LD_LIBRARY_PATH=${LIB_PATH} ./vs_epoll -p 20000 -d ${dut2_if_ip} -a 10000 -s ${dut1_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 - else - sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_common -p 20000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 - fi + execution "sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vs_epoll -p 20000 -d ${dut2_if_ip} -a 10000 -s ${dut1_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1" \ + "sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vc_common -p 20000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1" fi ################################################# @@ -57,14 +44,9 @@ fi if [ "x$action" == "xverify" ]; then if [ "x$node" == "x1" ]; then - sudo cat $RUN_DIR/log_$(basename $0).txt | grep "send 50000" - if [ $? == 0 ]; then - echo "DMM_CSIT_TEST_PASSED" - else - echo "DMM_CSIT_TEST_FAILED" - fi + verification "sudo cat $RUN_DIR/log_$(basename $0).txt | grep \"send 50000\"" elif [ "x$node" == "x0" ]; then - echo "DMM_CSIT_TEST_PASSED" + verification fi fi @@ -72,16 +54,14 @@ fi # Print Log if [ "x$action" == "xlog" ]; then - echo "print log" + print_log vs_epoll vc_common fi ################################################# # Cleanup if [ "x$action" == "xcleanup" ]; then - if [ "x$node" == "x0" ]; then - bash $CSIT_SCRIPT_DIR/kill_given_proc.sh vs_epoll - fi + cleanup vs_epoll vc_common fi exit 0
\ No newline at end of file diff --git a/scripts/csit/run/run_dmm_fork.sh b/scripts/csit/run/run_dmm_fork.sh new file mode 100755 index 0000000..b406ba5 --- /dev/null +++ b/scripts/csit/run/run_dmm_fork.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name when node is 0 /dut2 interface name when node is 1 +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/config/app_test +LIB_PATH=${ROOTDIR}/dmm/release/lib64 +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts +LOG_PATH=/var/log + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation vtcp_fork_server +fi + +################################################# +# Execution +#execution "sudo LD_LIBRARY_PATH=${LIB_PATH} ./ktcp_fork_server -a 10000 -s ${dut1_if_ip} -t 50000" +# "sudo LD_LIBRARY_PATH=${LIB_PATH} ./ktcp_client -p 10000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -t 50000" +if [ "x$action" == "xrun" ]; then + execution "sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vtcp_fork_server -a 10000 -s ${dut1_if_ip} -t 50000" \ + "sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vtcp_client -p 10000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -t 50000" +fi + +################################################# +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x1" ]; then + verification "sudo cat $RUN_DIR/log_$(basename $0).txt | grep \"Success\"" + elif [ "x$node" == "x0" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + print_log vtcp_fork_server vtcp_client +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup vtcp_fork_server vtcp_client +fi + +exit 0 diff --git a/scripts/csit/run/run_dmm_fork_with_lwip.sh b/scripts/csit/run/run_dmm_fork_with_lwip.sh new file mode 100755 index 0000000..0ee9d07 --- /dev/null +++ b/scripts/csit/run/run_dmm_fork_with_lwip.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments[action, node] + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name(when node is 0)/dut2 interface name(when node is 1) +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/app_test/ +LIB_PATH=${APP_DIR}/../release/lib64/ +VAG_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/vagrant +LOG_PATH=/var/log/nStack +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation_lwip vtcp_fork_server +fi + +################################################# +# Execution + +if [ "x$action" == "xrun" ]; then + execution "sudo LD_LIBRARY_PATH=${LIB_PATH} ./vtcp_fork_server -a 10000 -s ${dut1_if_ip} -t 50000" \ + "sudo LD_LIBRARY_PATH=${LIB_PATH} ./vtcp_client -p 10000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -t 50000" +fi + +################################################# +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x1" ]; then + verification "cat $RUN_DIR/log_$(basename $0).txt | grep \"Success\"" + elif [ "x$node" == "x0" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + cat $LOG_PATH/running.log +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup_lwip vtcp_fork_server +fi + +exit 0 diff --git a/scripts/csit/run/run_dmm_tcp_filetrans.sh b/scripts/csit/run/run_dmm_tcp_filetrans.sh new file mode 100755 index 0000000..fddc017 --- /dev/null +++ b/scripts/csit/run/run_dmm_tcp_filetrans.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name when node is 0 /dut2 interface name when node is 1 +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/config/app_test +LIB_PATH=${ROOTDIR}/dmm/release/lib64 +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts +LOG_PATH=/var/log + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation vc_serv_file +fi + +################################################# +# Execution + +if [ "x$action" == "xrun" ]; then + execution "cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vc_serv_file tcp ${dut1_if_ip} 1234" \ + "cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} NSTACK_LOG_FILE_FLAG=1 ./vc_cli_file tcp ${dut1_if_ip} 1234 file.txt ${dut2_if_ip}" +fi + +################################################# +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x0" ]; then + verification "diff $APP_DIR/file.txt $APP_DIR/receive_file.txt >/dev/null" + elif [ "x$node" == "x1" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + print_log vc_serv_file vc_cli_file +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup vc_serv_file vc_cli_file +fi + +exit 0
\ No newline at end of file diff --git a/scripts/csit/run/run_dmm_tcp_filetrans_with_lwip.sh b/scripts/csit/run/run_dmm_tcp_filetrans_with_lwip.sh new file mode 100755 index 0000000..5713d50 --- /dev/null +++ b/scripts/csit/run/run_dmm_tcp_filetrans_with_lwip.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments[action, node] + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name(when node is 0)/dut2 interface name(when node is 1) +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/app_test/ +LIB_PATH=${APP_DIR}/../release/lib64/ +VAG_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/vagrant +LOG_PATH=/var/log/nStack +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation_lwip vc_serv_file +fi + +################################################# +# Execution + +if [ "x$action" == "xrun" ]; then + execution "sudo cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_serv_file tcp ${dut1_if_ip} 1234" \ + "sudo cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_cli_file tcp ${dut1_if_ip} 1234 file.txt ${dut2_if_ip}" +fi + +################################################# + +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x0" ]; then + verification "diff $APP_DIR/file.txt $APP_DIR/receive_file.txt >/dev/null" + elif [ "x$node" == "x1" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + cat $LOG_PATH/running.log +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup_lwip vc_serv_file +fi + +exit 0 diff --git a/scripts/csit/run/run_dmm_udp_filetrans.sh b/scripts/csit/run/run_dmm_udp_filetrans.sh new file mode 100755 index 0000000..b8838bb --- /dev/null +++ b/scripts/csit/run/run_dmm_udp_filetrans.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name when node is 0 /dut2 interface name when node is 1 +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/config/app_test +LIB_PATH=${ROOTDIR}/dmm/release/lib64 +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts +LOG_PATH=/var/log + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation vc_serv_file +fi + +################################################# +# Execution + +if [ "x$action" == "xrun" ]; then + execution "cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_serv_file udp ${dut1_if_ip} 1235 file.txt 256" \ + "cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_cli_file udp ${dut1_if_ip} 1235 ${dut2_if_ip} file.txt receive_file.txt 256" +fi + +################################################# +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x0" ]; then + verification "diff $APP_DIR/file.txt $APP_DIR/receive_file.txt >/dev/null" + elif [ "x$node" == "x1" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + print_log vc_serv_file vc_cli_file +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup vc_serv_file vc_cli_file +fi + +exit 0
\ No newline at end of file diff --git a/scripts/csit/run/run_dmm_udp_filetrans_with_lwip.sh b/scripts/csit/run/run_dmm_udp_filetrans_with_lwip.sh new file mode 100755 index 0000000..b8310dd --- /dev/null +++ b/scripts/csit/run/run_dmm_udp_filetrans_with_lwip.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -x + +################################################# +# Store arguments values +# verify, log, cleanup actions gets first two arguments[action, node] + +action=$1 #action: [setup, run, verify, cleanup] +node=$2 #node: [0 - dut1 node, 1 - dut2 node] +ifname=$3 #dut1 interface name(when node is 0)/dut2 interface name(when node is 1) +dut1_if_ip=$4 #dut1 interface ip +dut2_if_ip=$5 #dut2 interface ip + +################################################# +# Get path details + +RUN_DIR=`dirname $(readlink -f $0)` +CSIT_SCRIPT_DIR=$RUN_DIR/.. +ROOTDIR=$CSIT_SCRIPT_DIR/../../../ +APP_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/app_test/ +LIB_PATH=${APP_DIR}/../release/lib64/ +VAG_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/vagrant +LOG_PATH=/var/log/nStack +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts + +source $DMM_SCRIPT_DIR/csit/common.sh +################################################# +# Setup preparation + +if [ "x$action" == "xsetup" ]; then + setup_preparation_lwip vc_serv_file + sudo sed -i '23s/kernel/lwip/' $APP_DIR/rd_config.json +fi + +################################################# +# Execution + +if [ "x$action" == "xrun" ]; then + execution "sudo cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_serv_file udp ${dut1_if_ip} 1236 file.txt 256" \ + "sudo cp -f $DMM_SCRIPT_DIR/csit/file.txt . ;sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_cli_file udp ${dut1_if_ip} 1236 ${dut2_if_ip} file.txt receive_file.txt 256" +fi + +################################################# + +# Verification + +if [ "x$action" == "xverify" ]; then + if [ "x$node" == "x0" ]; then + verification "diff $APP_DIR/file.txt $APP_DIR/receive_file.txt >/dev/null" + elif [ "x$node" == "x1" ]; then + verification + fi +fi + +################################################# +# Print Log + +if [ "x$action" == "xlog" ]; then + cat $LOG_PATH/running.log +fi + +################################################# +# Cleanup + +if [ "x$action" == "xcleanup" ]; then + cleanup_lwip vc_serv_file +fi + +exit 0 diff --git a/scripts/csit/run/run_dmm_with_lwip.sh b/scripts/csit/run/run_dmm_with_lwip.sh index 1174697..3b02e28 100755 --- a/scripts/csit/run/run_dmm_with_lwip.sh +++ b/scripts/csit/run/run_dmm_with_lwip.sh @@ -22,39 +22,22 @@ APP_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/app_test/ LIB_PATH=${APP_DIR}/../release/lib64/ VAG_DIR=${ROOTDIR}/dmm/stacks/lwip_stack/vagrant LOG_PATH=/var/log/nStack +DMM_SCRIPT_DIR=$ROOTDIR/dmm/scripts +source $DMM_SCRIPT_DIR/csit/common.sh ################################################# # Setup preparation if [ "x$action" == "xsetup" ]; then - bash $CSIT_SCRIPT_DIR/kill_given_proc.sh vs_epoll - bash $CSIT_SCRIPT_DIR/setup_hugepage.sh - cat /proc/meminfo - cp -f $VAG_DIR/start_nstackMain.sh $VAG_DIR/start_nstackMain_csit.sh - sed -i 's!.*check_hugepage.sh!#skip hugepage check!1' $VAG_DIR/start_nstackMain_csit.sh - sed -i 's!ifname=.*!ifname='$ifname'!1' $VAG_DIR/start_nstackMain_csit.sh - sudo LD_LIBRARY_PATH=${LIB_PATH} bash $VAG_DIR/start_nstackMain_csit.sh || exit 1 - sleep 5 - - #after nstackmain - echo "after nstackmain" - ip addr - lspci -nn - lsmod | grep uio - cat /proc/meminfo | grep Huge - /tmp/dpdk/dpdk-18.02/usertools/dpdk-devbind.py --status + setup_preparation_lwip vs_epoll fi ################################################# # Execution if [ "x$action" == "xrun" ]; then - cd ${APP_DIR} - if [ "x$node" == "x0" ]; then - sudo LD_LIBRARY_PATH=${LIB_PATH} ./vs_epoll -p 20000 -d ${dut2_if_ip} -a 10000 -s ${dut1_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 - else - sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_common -p 20000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -l 200 -t 50 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1 - fi + execution "sudo LD_LIBRARY_PATH=${LIB_PATH} ./vs_epoll -p 20000 -d ${dut2_if_ip} -a 10000 -s ${dut1_if_ip} -l 200 -t 50000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1" \ + "sudo LD_LIBRARY_PATH=${LIB_PATH} ./vc_common -p 20000 -d ${dut1_if_ip} -a 10000 -s ${dut2_if_ip} -l 200 -t 50 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 10000 -e 10 -x 1" fi ################################################# @@ -62,14 +45,9 @@ fi if [ "x$action" == "xverify" ]; then if [ "x$node" == "x1" ]; then - cat $RUN_DIR/log_$(basename $0).txt | grep "send 50" - if [ $? == 0 ]; then - echo "DMM_CSIT_TEST_PASSED" - else - echo "DMM_CSIT_TEST_FAILED" - fi + verification "cat $RUN_DIR/log_$(basename $0).txt | grep \"send 50\"" elif [ "x$node" == "x0" ]; then - echo "DMM_CSIT_TEST_PASSED" + verification fi fi @@ -84,11 +62,7 @@ fi # Cleanup if [ "x$action" == "xcleanup" ]; then - if [ "x$node" == "x0" ]; then - bash $CSIT_SCRIPT_DIR/kill_given_proc.sh vs_epoll - fi - sudo bash $APP_DIR/../release/stop_nstack.sh - sudo rm $LOG_PATH/running.log + cleanup_lwip vs_epoll fi exit 0 diff --git a/scripts/generate_dmm_rpm.sh b/scripts/generate_dmm_rpm.sh index 76d65a1..f43e8cf 100755 --- a/scripts/generate_dmm_rpm.sh +++ b/scripts/generate_dmm_rpm.sh @@ -17,7 +17,7 @@ cur_directory=${PWD} name="dmm" -version="18.07" +version="18.10" mkdir -p ~/rpmbuild/SOURCES diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1069e7f..0eca7a1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack -mcmodel=medium") SET(COMPLE_CONFIG ${PROJECT_SOURCE_DIR}/src/framework/common/include/compile_config.h) ADD_DEFINITIONS(-include ${COMM_CONFIG}) ADD_DEFINITIONS(-include ${COMPLE_CONFIG}) -ADD_DEFINITIONS(-D_GNU_SOURCE -DNSTACK_GETVER_VERSION="18.07") +ADD_DEFINITIONS(-D_GNU_SOURCE -DNSTACK_GETVER_VERSION="18.10") #LINK_DIRECTORIES(${LIB_PATH_SHARED} ${LIB_PATH_STATIC}) if(WITH_SECUREC_LIB) diff --git a/src/framework/hal/hal.c b/src/framework/hal/hal.c index 545c759..49b1fb7 100644 --- a/src/framework/hal/hal.c +++ b/src/framework/hal/hal.c @@ -312,7 +312,7 @@ hal_get_invalid_hdl () Called By : *****************************************************************************/ hal_hdl_t -hal_create (const char *name, hal_netif_config_t * conf) +hal_create (const char *name, const char *nic_type, hal_netif_config_t * conf) { int ret = -1; uint32_t netif_type; @@ -336,7 +336,7 @@ hal_create (const char *name, hal_netif_config_t * conf) /*open */ for (netif_type = 0; NULL != netif_ops_table[netif_type]; ++netif_type) { - ret = netif_ops_table[netif_type]->open (inst, name); + ret = netif_ops_table[netif_type]->open (inst, name, nic_type); if (0 == ret) { diff --git a/src/framework/hal/hal.h b/src/framework/hal/hal.h index 36ad79d..5a8f51e 100644 --- a/src/framework/hal/hal.h +++ b/src/framework/hal/hal.h @@ -66,6 +66,7 @@ typedef struct dpdk_if char pci_addr[HAL_MAX_PCI_ADDR_LEN]; char nic_name[HAL_MAX_NIC_NAME_LEN]; + char nic_type[HAL_MAX_NIC_NAME_LEN]; char driver_name[HAL_MAX_DRIVER_NAME_LEN]; } dpdk_if_t; @@ -93,7 +94,7 @@ typedef struct netif_ops const char *name; int (*init_global) (int argc, char **argv); int (*init_local) (void); - int (*open) (netif_inst_t * inst, const char *name); + int (*open) (netif_inst_t * inst, const char *name, const char *type); int (*close) (netif_inst_t * inst); int (*start) (netif_inst_t * inst); int (*stop) (netif_inst_t * inst); diff --git a/src/framework/include/hal_api.h b/src/framework/include/hal_api.h index 90c3100..a5d7725 100644 --- a/src/framework/include/hal_api.h +++ b/src/framework/include/hal_api.h @@ -110,7 +110,8 @@ typedef struct hal_netif_config int hal_init_global (int argc, char **argv); int hal_init_local (); -hal_hdl_t hal_create (const char *name, hal_netif_config_t * conf); +hal_hdl_t hal_create (const char *name, const char *nic_type, + hal_netif_config_t * conf); hal_hdl_t hal_bond (const char *bond_name, uint8_t slave_num, hal_hdl_t slave_hdl[]); diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c index 225c297..9d6a2ba 100644 --- a/src/nSocket/nstack/nstack.c +++ b/src/nSocket/nstack/nstack.c @@ -285,44 +285,8 @@ match_version (char *nstack_ver, char *my_ver) return 0; } - char *nstack_ver_head = NULL; - char *my_ver_head = NULL; - char nstack_version[NSTACK_VERSION_LEN] = { 0 }; - char my_version[NSTACK_VERSION_LEN] = { 0 }; - - // !!!STRTOK_S will modify the original string, so use use temp for parameter - /* use STRCPY_S instead of MEMCPY_S to avoid invalid memory visit */ - if (EOK != STRCPY_S (nstack_version, sizeof (nstack_version), nstack_ver)) - { - return 0; - } - - nstack_ver_head = get_ver_head (nstack_version); - if (NULL == nstack_ver_head) - { - return 0; - } - - /*use STRCPY_S instead of MEMCPY_S to avoid invalid memory visit */ - if (EOK != STRCPY_S (my_version, sizeof (my_version), my_ver)) - { - return 0; - } - - my_ver_head = get_ver_head (my_version); - if (NULL == my_ver_head) - { - return 0; - } - - if (strlen (my_ver_head) != strlen (nstack_ver_head)) - { - return 0; - } - - - if (0 != strncmp (nstack_ver_head, my_ver_head, strlen (nstack_ver_head))) + if (0 != strncmp (nstack_ver, my_ver, 5)) { return 0; } diff --git a/src/nSocket/nstack/nstack_info_parse.c b/src/nSocket/nstack/nstack_info_parse.c index 04abb4e..8b2d62f 100644 --- a/src/nSocket/nstack/nstack_info_parse.c +++ b/src/nSocket/nstack/nstack_info_parse.c @@ -66,8 +66,14 @@ } \ else \ { \ - NSSOC_LOGERR("can't get obj from %s index:%d", name, (index)); \ - goto RETURN_ERROR; \ + if (strcmp(name, "deploytype") == 0 || strcmp(name, "stackid") == 0) \ + { \ + NSSOC_LOGERR("can't get obj from %s index:%d", name, (index)); \ + } \ + else\ + { \ + NSSOC_LOGWAR("can't get obj from %s index:%d", name, (index)); \ + } \ } \ } while ( 0 ); @@ -85,6 +91,7 @@ nstack_parse_module_cfg_json (char *param) int ret = NSTACK_RETURN_FAIL; int index = 0; int icnt = 0; + int ret_val; if (!obj) { @@ -125,10 +132,21 @@ nstack_parse_module_cfg_json (char *param) NSTACK_JSON_PARSE_STRING (module_obj, "stack_name", MODULE_NAME_MAX, &(g_nstack_module_desc[icnt].modName[0]), index); - NSTACK_JSON_PARSE_STRING (module_obj, "function_name", - MODULE_NAME_MAX, - &(g_nstack_module_desc - [icnt].register_fn_name[0]), index); + STRCPY_S (&(g_nstack_module_desc[icnt].register_fn_name[0]), + sizeof (& + (g_nstack_module_desc[icnt].register_fn_name[0])), + &(g_nstack_module_desc[icnt].modName[0])); + ret_val = + STRCAT_S (&(g_nstack_module_desc[icnt].register_fn_name[0]), + sizeof (& + (g_nstack_module_desc[icnt].register_fn_name + [0])), "_stack_register"); + if (EOK != ret_val) + { + NSFW_LOGERR ("register_fn_name STRCAT_S failed]ret_val=%d", + ret_val); + return -1; + } NSTACK_JSON_PARSE_STRING (module_obj, "libname", MODULE_NAME_MAX, &(g_nstack_module_desc[icnt].libPath[0]), index); @@ -149,14 +167,28 @@ nstack_parse_module_cfg_json (char *param) } else { - NSSOC_LOGERR ("can't get value from loadtype index:%d", index); - goto RETURN_ERROR; + if (strcmp (g_nstack_module_desc[icnt].modName, "kernel") == 0) + { + g_nstack_module_desc[icnt].libtype = NSTACK_LIB_LOAD_STATIC; + } + else + { + g_nstack_module_desc[icnt].libtype = NSTACK_LIB_LOAD_DYN; + } + NSSOC_LOGWAR ("can't get the value of loadtype for module:%s", + g_nstack_module_desc[icnt].modName); } + NSSBR_LOGINF ("load type of %d has been chosen", + g_nstack_module_desc[icnt].libtype); NSTACK_JSON_PARSE_INT (module_obj, "deploytype", MODULE_NAME_MAX, g_nstack_module_desc[icnt].deploytype, index); NSTACK_JSON_PARSE_INT (module_obj, "maxfd", MODULE_NAME_MAX, g_nstack_module_desc[icnt].maxfdid, index); + if (g_nstack_module_desc[icnt].maxfdid == 0) + { + g_nstack_module_desc[icnt].maxfdid = 1024; + } NSTACK_JSON_PARSE_INT (module_obj, "minfd", MODULE_NAME_MAX, g_nstack_module_desc[icnt].minfdid, index); NSTACK_JSON_PARSE_INT (module_obj, "priorty", MODULE_NAME_MAX, diff --git a/src/nSocket/nstack/nstack_module.h b/src/nSocket/nstack/nstack_module.h index ec81ac1..40a2ef8 100644 --- a/src/nSocket/nstack/nstack_module.h +++ b/src/nSocket/nstack/nstack_module.h @@ -38,11 +38,6 @@ extern "C"{ #define NSTACK_MAX_MODULE_NUM 8 #define NSTACK_PRO_MODULE 1 -#define MIN_SOCK_FOR_STACKX 0 - -#define MOD_PRI_FOR_STACKX 1 -#define REG_FUN_FOR_STACKX "nstack_stack_register" - #define NSTACK_EP_FREE_NEED_REF 1 /*when epoll information free, need to wait that stack would not notify event */ #define NSTACK_EP_FREE_NONEED_REF 0 diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c index c967d64..210e29d 100644 --- a/src/nSocket/nstack/nstack_socket.c +++ b/src/nSocket/nstack/nstack_socket.c @@ -141,12 +141,10 @@ int nstack_socket (int domain, int itype, int protocol) { int ret = -1; //tmp ret of a Single proctol mode. - int rdret = -1; //the final Return judge vale. int modInx; nstack_socket_ops *ops; int ret_fd = -1; int protoFD[NSTACK_MAX_MODULE_NUM]; - nstack_rd_key rdkey = { 0 }; int selectmod = -1; /*check whether module init finish or not */ @@ -183,22 +181,6 @@ nstack_socket (int domain, int itype, int protocol) nstack_fd_local_lock_info_t *lock_info = get_fd_local_lock_info (ret_fd); LOCK_FOR_EP (lock_info); - - /*check wether select stack create success, if no return fail */ - rdkey.type = RD_DATA_TYPE_PROTO; - rdkey.proto_type = itype; - rdret = nstack_rd_get_stackid (&rdkey, &selectmod); - if ((0 != rdret) || (selectmod < 0) || (selectmod >= nstack_get_modNum ())) - { - NSSOC_LOGERR ("protocol:%d select stack fail", protocol); - selectmod = -1; - } - else - { - NSSOC_LOGINF ("Create socket of]select modName=%s", - nstack_get_module_name_by_idx (selectmod)); - } - /*create socket by calling select module or all module */ nstack_each_modOps (modInx, ops) { @@ -389,6 +371,26 @@ nstack_bind (int fd, const struct sockaddr *addr, socklen_t addrlen) nstack_get_module_name_by_idx (selectmod)); } + if (selectmod == -1) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGWAR + ("fd Can't select any module for]fd=%d,IP==%s using proto route", + fd, inet_ntoa ((iaddr->sin_addr))); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Bind socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } + retval = -1; nstack_each_modInx (modIdx) { @@ -902,6 +904,25 @@ nstack_connect (int fd, const struct sockaddr *addr, socklen_t addrlen) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval && selectmod >= 0) { NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", @@ -1385,6 +1406,25 @@ nstack_sendto (int fd, const void *buf, size_t len, int flags, rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("sendto socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if ((ns_success == retval) && (selectmod >= 0)) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", @@ -1472,6 +1512,25 @@ nstack_sendmsg (int fd, const struct msghdr * msg, int flags) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", diff --git a/src/nSocket/nstack_rd/nstack_rd_ip.c b/src/nSocket/nstack_rd/nstack_rd_ip.c index c9246c0..82035d1 100644 --- a/src/nSocket/nstack_rd/nstack_rd_ip.c +++ b/src/nSocket/nstack_rd/nstack_rd_ip.c @@ -64,12 +64,13 @@ nstack_rd_ip_item_insert (nstack_rd_list * hlist, void *rditem) nstack_rd_node *tempdata = NULL; struct hlist_node *tempnode = NULL; struct hlist_node *tem = NULL; - unsigned int ip_addr = 0; - unsigned int ip_masklen = 0; - unsigned int ip_maskv = MASK_V (ip_addr, ip_masklen); + unsigned int tempip_addr = 0; unsigned int tempip_masklen = 0; rd_data_item *pitem = (rd_data_item *) rditem; + unsigned int ip_addr = pitem->ipdata.addr; + unsigned int ip_masklen = pitem->ipdata.masklen; + unsigned int ip_maskv = MASK_V (ip_addr, ip_masklen); ip_masklen = pitem->ipdata.masklen; NSSOC_LOGDBG ("stackid:%d, ipaddr:%u.%u.%u.%u masklen:0x%x was inserted", diff --git a/stacks/lwip_stack/CMakeLists.txt b/stacks/lwip_stack/CMakeLists.txt index 3992f20..5a5ca94 100644 --- a/stacks/lwip_stack/CMakeLists.txt +++ b/stacks/lwip_stack/CMakeLists.txt @@ -65,7 +65,7 @@ execute_process( COMMAND sh ${CMAKE_CURRENT_LIST_DIR}/release/lwip_helper_files/download_lwip.sh ) -ADD_DEFINITIONS(-D_GNU_SOURCE -DNSTACK_GETVER_VERSION="18.07") +ADD_DEFINITIONS(-D_GNU_SOURCE -DNSTACK_GETVER_VERSION="18.10") SET(JSON_C_SRC ${CMAKE_CURRENT_LIST_DIR}/../../thirdparty/json/json-c-0.12.1) INCLUDE(ExternalProject) diff --git a/stacks/lwip_stack/app_conf/module_config.json b/stacks/lwip_stack/app_conf/module_config.json deleted file mode 100644 index f1b3458..0000000 --- a/stacks/lwip_stack/app_conf/module_config.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "default_stack_name": "kernel", - "module_list": [ - { - "stack_name": "kernel", - "function_name": "kernel_stack_register", - "libname": "./", - "loadtype": "static", - "deploytype": "1", - "maxfd": "1024", - "minfd": "0", - "priorty": "1", - "stackid": "0", - }, - { - "stack_name": "lwip", - "function_name": "nstack_stack_register", - "libname": "libnstack.so", - "loadtype": "dynmic", - "deploytype": "3", - "maxfd": "1024", - "minfd": "0", - "priorty": "1", - "stackid": "1", - }, - ] -} diff --git a/stacks/lwip_stack/configure/module_config.json b/stacks/lwip_stack/configure/module_config.json new file mode 100644 index 0000000..c9c872b --- /dev/null +++ b/stacks/lwip_stack/configure/module_config.json @@ -0,0 +1,17 @@ +{ + "default_stack_name": "kernel", + "module_list": [ + { + "stack_name": "kernel", + "libname": "./", + "deploytype": "1", + "stackid": "0", + }, + { + "stack_name": "lwip", + "libname": "liblwip_dpdk.so", + "deploytype": "3", + "stackid": "1", + }, + ] +} diff --git a/stacks/lwip_stack/app_conf/nStackConfig.json b/stacks/lwip_stack/configure/nStackConfig.json index 3cc54c5..3cc54c5 100644 --- a/stacks/lwip_stack/app_conf/nStackConfig.json +++ b/stacks/lwip_stack/configure/nStackConfig.json diff --git a/stacks/lwip_stack/app_conf/rd_config.json b/stacks/lwip_stack/configure/rd_config.json index 3109bcd..3109bcd 100644 --- a/stacks/lwip_stack/app_conf/rd_config.json +++ b/stacks/lwip_stack/configure/rd_config.json diff --git a/stacks/lwip_stack/doc/README.md b/stacks/lwip_stack/doc/README.md index e9bb31e..a76b18a 100644 --- a/stacks/lwip_stack/doc/README.md +++ b/stacks/lwip_stack/doc/README.md @@ -32,11 +32,11 @@ a birds eye view of lwip in DMM pipeline mode. ```sh #export LD_LIBRARY_PATH=${dmm}/stacks/lwip_stack/release/lib64/ #export LD_PRELOAD=${dmm}/release/lib64/libnStackAPI.so - #export NSTACK_MOD_CFG_FILE=${dmm}/stacks/lwip_stack/app_conf/module_config.json - #export NSTACK_MOD_CFG_RD=${dmm}/stacks/lwip_stack/app_conf/rd_config.json + #export NSTACK_MOD_CFG_FILE=${dmm}/stacks/lwip_stack/configure/module_config.json + #export NSTACK_MOD_CFG_RD=${dmm}/stacks/lwip_stack/configure/rd_config.json #export NSTACK_LOG_ON=DBG (optional enable debug) ``` -- Steps 2: Modify rd_config.json(located at dmm/stacks/lwip_stack/app_config/) +- Steps 2: Modify rd_config.json(located at dmm/stacks/lwip_stack/configure/) ```sh #vim rd_config.json Eg. set "subnet": "192.168.21.1/24" @@ -67,6 +67,11 @@ Run the process: #./start_nstack.sh ``` +If you want to run it with vhost-user, you can run the start_nstack.sh with parameters as follow. +``` + #./start_nstack.sh --vdev virtio_user,mac=fa:16:3e:5f:b3:08,path=/tmp/unix/sock1.sock,queues=8,queue_size=1024 --no-pci +``` + - Steps 4: Communication test between machine A(as server) with machine B (as client) diff --git a/stacks/lwip_stack/lwip_src/api/spl_api_msg.c b/stacks/lwip_stack/lwip_src/api/spl_api_msg.c index 1c9bf92..f437bce 100644 --- a/stacks/lwip_stack/lwip_src/api/spl_api_msg.c +++ b/stacks/lwip_stack/lwip_src/api/spl_api_msg.c @@ -22,6 +22,7 @@ //#include "sockets.h" #include <netinet/in.h> #include <errno.h> +#include <netinet/tcp.h> #include "stackx_prot_com.h" #include "spl_api.h" @@ -1572,6 +1573,7 @@ spl_do_connected (void *arg, struct tcp_pcb *pcb, err_t err) conn->state = SPL_NETCONN_NONE; SPL_NETCONN_SET_SAFE_ERR (conn, ERR_OK); + update_tcp_state (pcb->callback_arg, ESTABLISHED); SPL_API_EVENT (conn, SPL_NETCONN_EVT_SENDPLUS, 1); if (was_blocking && m != NULL) @@ -2523,7 +2525,12 @@ do_get_tcpproto_getsockopt_internal (struct common_pcb *cpcb, NSPOL_LOGDBG (SOCKETS_DEBUG, "]fd=%d,SPL_TCP_KEEPCNT=%d", cpcb->socket, *(int *) optval); break; - + case SPL_TCP_INFO: + ((struct tcp_info *) optval)->tcpi_total_retrans = (int) tpcb->nrtx; + ((struct tcp_info *) optval)->tcpi_snd_mss = (int) tpcb->mss; + ((struct tcp_info *) optval)->tcpi_rtt = (int) tpcb->sa; + ((struct tcp_info *) optval)->tcpi_snd_cwnd = (int) tpcb->cwnd; + break; default: NSPOL_LOGDBG (SOCKETS_DEBUG, "unsupported]optname=%d", optname); SET_MSG_ERR (m, EOPNOTSUPP); @@ -3316,5 +3323,7 @@ alloc_common_pcb (enum spl_netconn_type type) common_pcb_init (cpcb); cpcb->type = type; + + res_alloc (&cpcb->res_chk); return cpcb; } diff --git a/stacks/lwip_stack/lwip_src/api/spl_tcpip.c b/stacks/lwip_stack/lwip_src/api/spl_tcpip.c index b627bcf..b0b588a 100644 --- a/stacks/lwip_stack/lwip_src/api/spl_tcpip.c +++ b/stacks/lwip_stack/lwip_src/api/spl_tcpip.c @@ -61,7 +61,7 @@ #include "sys.h" -#define NSTACK_MAIN_MAX_PARA 19 +#define NSTACK_MAIN_MAX_PARA 32 #define NSTACK_MAIN_MIN_PARA 1 #define DPDK_DEFAULT_EAL_MEM_SIZE (1024) @@ -951,7 +951,7 @@ spl_tcpip_thread (void *arg) u16 task_loop; u16 num_recv_task = 0, num_send_timer_task = 0; u16 index_task = 0; - int tcpip_thread_sleep_interval = g_tcpip_thread_sleep_time * 1000; + //int tcpip_thread_sleep_interval = g_tcpip_thread_sleep_time * 1000; void *task_queue[TASK_BURST]; data_com_msg *msg; @@ -981,7 +981,7 @@ spl_tcpip_thread (void *arg) if (run_count++ > 20) { - sys_sleep_ns (0, tcpip_thread_sleep_interval); + //sys_sleep_ns (0, tcpip_thread_sleep_interval); } continue; } diff --git a/stacks/lwip_stack/lwip_src/common/stackx_common_opt.h b/stacks/lwip_stack/lwip_src/common/stackx_common_opt.h index d2d01e5..feccc3f 100644 --- a/stacks/lwip_stack/lwip_src/common/stackx_common_opt.h +++ b/stacks/lwip_stack/lwip_src/common/stackx_common_opt.h @@ -102,6 +102,7 @@ extern "C" { #define SPL_TCP_KEEPCNT 0x06 #define SPL_TCP_LINGER2 0x08 #define SPL_TCP_DEFER_ACCEPT 0x09 +#define SPL_TCP_INFO 0x0B typedef enum spl_netconn_type { diff --git a/stacks/lwip_stack/lwip_src/common/stackx_spl_msg.h b/stacks/lwip_stack/lwip_src/common/stackx_spl_msg.h index 119c26a..3088150 100644 --- a/stacks/lwip_stack/lwip_src/common/stackx_spl_msg.h +++ b/stacks/lwip_stack/lwip_src/common/stackx_spl_msg.h @@ -21,6 +21,7 @@ #include "stackx_spl_share.h" #include "stackx_common_opt.h" #include <sys/socket.h> +#include <netinet/tcp.h> #ifdef __cplusplus /* *INDENT-OFF* */ @@ -207,6 +208,7 @@ typedef struct //struct in_addr inaddr_optval; //struct linger _linger; struct timeval timeval_optval; + struct tcp_info tpinfo; //ipmreq ipmreq_optval; //Multicast support later } optval; diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h b/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h index 488e13e..acf5057 100644 --- a/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h +++ b/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h @@ -149,6 +149,7 @@ struct network_configuration struct ip_subnet *ip_subnet; char network_name[IP_MODULE_MAX_NAME_LEN]; char type_name[IP_MODULE_MAX_NAME_LEN]; + char nic_type_name[IP_MODULE_MAX_NAME_LEN]; network_buffer *buffer; }; diff --git a/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h b/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h index 0a92ea0..6230ed8 100644 --- a/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h +++ b/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h @@ -101,6 +101,7 @@ enum proc_run_type struct linux_port_info { char if_name[HAL_MAX_NIC_NAME_LEN]; + char if_type[HAL_MAX_NIC_NAME_LEN]; char ip_addr_linux[18]; //uint32_t ip_addr_linux; char mask_linux[18]; //uint32_t mask_linux; char bcast_linux[18]; //uint32_t bcast_linux; diff --git a/stacks/lwip_stack/lwip_src/ip_module/container_ip.c b/stacks/lwip_stack/lwip_src/ip_module/container_ip.c index decc52c..52f7c64 100644 --- a/stacks/lwip_stack/lwip_src/ip_module/container_ip.c +++ b/stacks/lwip_stack/lwip_src/ip_module/container_ip.c @@ -533,7 +533,7 @@ parse_container_ip_json (char *param) else { /* this mandatory parameter */ - goto RETURN_ERROR; + NSOPR_LOGWAR ("json_object_object_get_ex containerID failed"); } json_object_object_get_ex (obj, "ports_list", &ports_list_obj); diff --git a/stacks/lwip_stack/lwip_src/ip_module/network.c b/stacks/lwip_stack/lwip_src/ip_module/network.c index ef0d9a7..d7c9630 100644 --- a/stacks/lwip_stack/lwip_src/ip_module/network.c +++ b/stacks/lwip_stack/lwip_src/ip_module/network.c @@ -510,7 +510,8 @@ add_network_configuration (struct network_configuration while (pheader) { if (!spl_hal_is_nic_exist (pheader->nic_name) - && !nic_already_init (pheader->nic_name)) + && !nic_already_init (pheader->nic_name) + && strncmp (tmp->nic_type_name, "vhost", strlen ("vhost"))) { NSOPR_LOGERR ("Invalid configuration %s not exist Error! ", pheader->nic_name); @@ -584,7 +585,7 @@ parse_network_obj (struct json_object *network_obj) NULL, *type_name_obj = NULL; struct json_object *ref_nic_list_obj = NULL, *bond_mode_obj = NULL, *bond_name_obj = NULL, *ipam_obj = NULL; - struct json_object *subnet_obj = NULL; + struct json_object *subnet_obj = NULL, *nic_type_obj = NULL; if (!network_obj) { @@ -687,6 +688,44 @@ parse_network_obj (struct json_object *network_obj) goto RETURN_ERROR; } + json_object_object_get_ex (phy_obj, "nic_type", &nic_type_obj); /*lint !e534 no need to check return value */ + if (nic_type_obj) + { + const char *nic_type_name = + json_object_get_string (nic_type_obj); + if (strcmp (nic_type_name, "pci") != 0 + && strcmp (nic_type_name, "vhost") != 0) + { + NSOPR_LOGERR ("unsupported nic_type]nic_type=%s", + nic_type_name); + goto RETURN_ERROR; + } + + retVal = + STRCPY_S (pst_network_configuration->nic_type_name, + sizeof (pst_network_configuration->nic_type_name), + nic_type_name); + if (EOK != retVal) + { + NSOPR_LOGERR ("strcpy_s failed]ret=%d", retVal); + goto RETURN_ERROR; + } + } + else + { + NSOPR_LOGINF + ("nic_type not specified, use default type]defaul nic_type=pci"); + retVal = + STRCPY_S (pst_network_configuration->nic_type_name, + sizeof (pst_network_configuration->nic_type_name), + "pci"); + if (EOK != retVal) + { + NSOPR_LOGERR ("strcpy_s failed]ret=%d", retVal); + goto RETURN_ERROR; + } + } + json_object_object_get_ex (phy_obj, "ref_nic", &ref_nic_list_obj); if (ref_nic_list_obj) { diff --git a/stacks/lwip_stack/lwip_src/netif/spl_hal.c b/stacks/lwip_stack/lwip_src/netif/spl_hal.c index 596962e..db843d4 100644 --- a/stacks/lwip_stack/lwip_src/netif/spl_hal.c +++ b/stacks/lwip_stack/lwip_src/netif/spl_hal.c @@ -962,6 +962,23 @@ spl_hal_port_config (unsigned int *port_num) NSPOL_LOGINF (SC_DPDK_INFO, "if_name %s", p_stackx_port_zone-> stackx_one_port[port_index].linux_ip.if_name); + + retVal = + STRCPY_S (p_stackx_port_zone-> + stackx_one_port[port_index].linux_ip.if_type, + sizeof (p_stackx_port_zone-> + stackx_one_port[port_index].linux_ip.if_type), + network->nic_type_name); + if (EOK != retVal) + { + NSPOL_LOGERR ("strcpy_s failed]ret=%d.", retVal); + return -1; + } + + NSPOL_LOGINF (SC_DPDK_INFO, "if_type %s", + p_stackx_port_zone-> + stackx_one_port[port_index].linux_ip.if_type); + retVal = STRCPY_S (p_stackx_port_zone-> stackx_one_port[port_index].linux_ip.ip_addr_linux, @@ -1286,7 +1303,9 @@ spl_hal_port_start (uint16_t nic_id, struct stackx_port_info *p_port_info, conf.tx.ring_size[q] = HAL_TX_RING_SIZE; } - hdl = hal_create (p_port_info->linux_ip.if_name, &conf); + hdl = + hal_create (p_port_info->linux_ip.if_name, p_port_info->linux_ip.if_type, + &conf); if (!hal_is_valid (hdl)) { diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c b/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c index 3225c2f..8d57ba0 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c @@ -403,16 +403,7 @@ sbr_tcp_connect (sbr_socket_t * sk, const struct sockaddr *name, inet_addr_to_ipaddr (&remote_addr, &addr_in->sin_addr); u16 remote_port = addr_in->sin_port; - spl_ip_addr_t local_addr; - if (IPADDR_ANY == ss_get_local_ip (sbr_get_conn (sk))->addr) - { - if (sbr_get_src_ip (remote_addr.addr, &local_addr.addr) != 0) - { - sbr_set_sk_errno (sk, EHOSTUNREACH); - NSSBR_LOGERR ("get src ip failed]fd=%d", sk->fd); - return -1; - } - } + spl_ip_addr_t local_addr = { IPADDR_ANY }; if (sbr_handle_connect (sk, &remote_addr, ntohs (remote_port), &local_addr) != 0) @@ -498,6 +489,7 @@ sbr_getsockopt_ipproto_tcp (int optname, void *optval, socklen_t optlen) case SPL_TCP_KEEPIDLE: case SPL_TCP_KEEPINTVL: case SPL_TCP_KEEPCNT: + case SPL_TCP_INFO: break; default: err = ENOPROTOOPT; diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_udp.c b/stacks/lwip_stack/lwip_src/socket/stackx_udp.c index 69b822b..1f382cf 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_udp.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_udp.c @@ -182,16 +182,7 @@ sbr_udp_connect (sbr_socket_t * sk, const struct sockaddr *name, inet_addr_to_ipaddr (&remote_addr, &addr_in->sin_addr); u16 remote_port = addr_in->sin_port; - spl_ip_addr_t local_addr; - if (IPADDR_ANY == ss_get_local_ip (sbr_get_conn (sk))->addr) - { - if (sbr_get_src_ip (remote_addr.addr, &local_addr.addr) != 0) - { - sbr_set_sk_errno (sk, EHOSTUNREACH); - NSSBR_LOGERR ("get src ip failed]fd=%d", sk->fd); - return -1; - } - } + spl_ip_addr_t local_addr = { IPADDR_ANY }; return sbr_handle_connect (sk, &remote_addr, ntohs (remote_port), &local_addr); @@ -815,16 +806,7 @@ sbr_udp_senddata (sbr_socket_t * sk, const struct iovec *iov, int iovcnt, netbuf_fromport (&buf) = 0; } - spl_ip_addr_t local_ip; - if (IPADDR_ANY == ss_get_local_ip (sbr_get_conn (sk))->addr) - { - if (sbr_get_src_ip (buf.addr.addr, &local_ip.addr) != 0) - { - sbr_set_sk_io_errno (sk, EHOSTUNREACH); - NSSBR_LOGERR ("get src ip failed]fd=%d", sk->fd); - return -1; - } - } + spl_ip_addr_t local_ip = { IPADDR_ANY }; int err = ss_get_last_errno (sbr_get_conn (sk)); if (SPL_ERR_IS_FATAL (err)) diff --git a/stacks/lwip_stack/release/configure/ip_data.json b/stacks/lwip_stack/release/configure/ip_data.json index f29103e..1d52b77 100644 --- a/stacks/lwip_stack/release/configure/ip_data.json +++ b/stacks/lwip_stack/release/configure/ip_data.json @@ -1,31 +1,8 @@ { - "containerID": "9112d2b6aa31", - "primary_port": "PortA", "ports_list": [ { "port_name": "PortA", - "ref_nic": [ - "eth7" - ], - "mac": [ - "00:54:32:19:3d:19" - ], - "net_name": "IDX-M", - "ip_cidr": ["192.168.1.207/24"], - "multicast_id": [ - { - "group_id": "cast_group_1", - "group_ip": "239.0.0.1" - }, - { - "group_id": "cast_group_2", - "group_ip": "239.0.0.2" - } - ], - "vlan_id": 42, - "vlan_inside": true, - "vxlan_id": -1, - "vxlan_inside": false + "ip_cidr": ["192.168.1.207/24"] } ] } diff --git a/stacks/lwip_stack/release/configure/network_data_tonStack.json b/stacks/lwip_stack/release/configure/network_data_tonStack.json index 7c059ef..7b734b0 100644 --- a/stacks/lwip_stack/release/configure/network_data_tonStack.json +++ b/stacks/lwip_stack/release/configure/network_data_tonStack.json @@ -1,31 +1,15 @@ [ { - "cniVersion": "0.2.0", - "name": "IDX-M", - "multi_entry": "3", + "name": "network1", "type": "nstack-dpdk", - "vlanID": 42, - "vlan_inside": true, "ipam": { - "type": "canal-ipam", - "subnet": "192.168.1.1/24", - "gateway": "192.168.1.254", - "range-start": "192.168.1.198", - "range-end": "192.168.1.209", - "routes": [ - { - "dst": "192.168.1.0/24", - "gw": "192.168.1.254" - } - ] + "subnet": "192.168.1.1/24" }, "args": { "phynet": { "ref_nic": [ "eth7" - ], - "bond_name": "", - "bond_mode": -1 + ] } } }, diff --git a/stacks/lwip_stack/release/lwip_helper_files/download_lwip.sh b/stacks/lwip_stack/release/lwip_helper_files/download_lwip.sh index 316859b..bbb8afb 100755 --- a/stacks/lwip_stack/release/lwip_helper_files/download_lwip.sh +++ b/stacks/lwip_stack/release/lwip_helper_files/download_lwip.sh @@ -23,7 +23,7 @@ echo $LWIP_DOWNLOAD_DIR if [ ! -d "${LWIP_DOWNLOAD_DIR}/lwip/" ]; then mkdir -p ${LWIP_DOWNLOAD_DIR}/lwip/ cd ${LWIP_DOWNLOAD_DIR}/ - wget -N --no-check-certificate http://download.savannah.nongnu.org/releases/lwip/lwip-2.0.3.zip + wget -N --no-check-certificate http://download-mirror.savannah.nongnu.org/releases/lwip/lwip-2.0.3.zip unzip ${LWIP_DOWNLOAD_DIR}/lwip-2.0.3.zip "lwip-2.0.3/src/*" -d ${LWIP_DOWNLOAD_DIR}/lwip mv ${LWIP_DOWNLOAD_DIR}/lwip/lwip-2.0.3/src/* ${LWIP_DOWNLOAD_DIR}/lwip/ rm -rf ${LWIP_DOWNLOAD_DIR}/lwip/lwip-2.0.3/ @@ -32,4 +32,4 @@ if [ ! -d "${LWIP_DOWNLOAD_DIR}/lwip/" ]; then cp -r ${SCRIPT_DIR}/core/* ${LWIP_DOWNLOAD_DIR}/lwip/core/ cp -r ${SCRIPT_DIR}/include/* ${LWIP_DOWNLOAD_DIR}/lwip/include/lwip/ mv ${LWIP_DOWNLOAD_DIR}/lwip/include/lwip/errno.h ${LWIP_DOWNLOAD_DIR}/lwip/include/lwip/lwip_errno.h -fi
\ No newline at end of file +fi diff --git a/stacks/lwip_stack/release/script/nstack_fun.sh b/stacks/lwip_stack/release/script/nstack_fun.sh index 5e16283..fed3588 100755 --- a/stacks/lwip_stack/release/script/nstack_fun.sh +++ b/stacks/lwip_stack/release/script/nstack_fun.sh @@ -332,10 +332,10 @@ run_nStackMain() log $LINENO "$env DPDK_TOOL_DIR=$DPDK_TOOL_DIR" log $LINENO "$env LD_LIBRARY_PATH=$LD_LIBRARY_PATH" log $LINENO "$env DPDK_LIB_PATH=$DPDK_LIB_PATH" - log $LINENO "./nStackMain -c $1 -n 4 --huge-dir=$2 --proc-type=primary --file-prefix nStackMain -m $3 stack -c $4 -sleep $5 -bind_cpu $6" + log $LINENO "./nStackMain -c $1 -n 4 --huge-dir=$2 --proc-type=primary --file-prefix nStackMain -m $3 $7 $8 stack -c $4 -sleep $5 -bind_cpu $6" check_file_size $DPDK_FILE cd ..; cd bin/ - ./nStackMain -c $1 -n 4 --huge-dir=$2 --proc-type=primary --file-prefix nStackMain -m $3 stack -c $4 -sleep $5 -bind_cpu $6 >> $DPDK_FILE & + ./nStackMain -c $1 -n 4 --huge-dir=$2 --proc-type=primary --file-prefix nStackMain -m $3 $7 $8 stack -c $4 -sleep $5 -bind_cpu $6 >> $DPDK_FILE & } diff --git a/stacks/lwip_stack/release/script/nstack_var.sh b/stacks/lwip_stack/release/script/nstack_var.sh index 9a1c612..a654d34 100755 --- a/stacks/lwip_stack/release/script/nstack_var.sh +++ b/stacks/lwip_stack/release/script/nstack_var.sh @@ -50,8 +50,10 @@ DPDK_NIC_LIST_FILE=$RUNTIME_DIR/.nstack_dpdk_nic_list MAX_LOG_FILE_SIZE=52428800 HUGE_PAGES=2048 HUGE_DIR=/mnt/nstackhuge + SLEEP_INTERVAL=100 # tcpip thread sleep time, unit: us -BIND_CPU=0 +BIND_CPU=1 + MEM_SIZE=3072 RTP_CORE_MASK=2 diff --git a/stacks/lwip_stack/release/script/run_nstack_main.sh b/stacks/lwip_stack/release/script/run_nstack_main.sh index 2bd9e0d..9d6049a 100755 --- a/stacks/lwip_stack/release/script/run_nstack_main.sh +++ b/stacks/lwip_stack/release/script/run_nstack_main.sh @@ -20,7 +20,8 @@ init_network CORE_MASK=1 log $LINENO "start run nstackmain" log $LINENO "COREMASK=$CORE_MASK, HUGE_DIR=$1, MEM_SIZE=$2, RTP_CORE_MASK=$RTP_CORE_MASK, SLEEP_INTERVAL=$SLEEP_INTERVAL, BIND_CPU=$BIND_CPU" +log $LINENO "VDEV=$VDEV, NO_PCI=$NO_PCI" -run_nStackMain $CORE_MASK $1 $2 $RTP_CORE_MASK $SLEEP_INTERVAL $BIND_CPU +run_nStackMain $CORE_MASK $1 $2 $RTP_CORE_MASK $SLEEP_INTERVAL $BIND_CPU $3 $4 exit 0 diff --git a/stacks/lwip_stack/release/start_nstack.sh b/stacks/lwip_stack/release/start_nstack.sh index db0c084..35fe9df 100755 --- a/stacks/lwip_stack/release/start_nstack.sh +++ b/stacks/lwip_stack/release/start_nstack.sh @@ -16,16 +16,40 @@ fi ##get the log info from the parameter of ./start -l XXX -a XXX ### nstack_log_path="" hostinfo_path="" -while getopts "l:i:a:" arg +ARGS=`getopt -o "l:i:a:" -l "vdev:,file-prefix:,no-pci" -n "start_nstack.sh" -- "$@"` +eval set -- "${ARGS}" +while true do - case $arg in - l) - nstack_log_path="$OPTARG" - ;; - i) - hostinfo_path="$OPTARG" - ;; - esac + case "$1" in + -l) + nstack_log_path="$2" + shift 2 + ;; + -i) + hostinfo_path="$2" + shift 2 + ;; + --vdev) + VDEV="--vdev=$2" + shift 2 + ;; + --file-prefix) + FILE_PREFIX="--file-prefix=$2" + shift 2 + ;; + --no-pci) + NO_PCI="--no-pci" + shift 1 + ;; + --) + shift + break + ;; + *) + echo "Option illegal, please check input!" + exit 1 + ;; + esac done hostinfo_stat=0 @@ -116,8 +140,8 @@ install_config ######################################################## core_mask=1 START_TYPE="primary" -log $LINENO "./script/run_nstack_main.sh ${core_mask} $HUGE_DIR $MEM_SIZE $START_TYPE" -${script_path}/script/run_nstack_main.sh $HUGE_DIR $MEM_SIZE +log $LINENO "./script/run_nstack_main.sh ${core_mask} $HUGE_DIR $MEM_SIZE $START_TYPE $VDEV $NO_PCI" +${script_path}/script/run_nstack_main.sh $HUGE_DIR $MEM_SIZE $VDEV $NO_PCI print_pid=$(ps -ux | grep nStackMain | awk '{print $2}' | awk 'NR == 2') echo "nStackMain PID:$print_pid" diff --git a/stacks/lwip_stack/release_tar.sh b/stacks/lwip_stack/release_tar.sh index 6c2928f..d3cfa68 100644 --- a/stacks/lwip_stack/release_tar.sh +++ b/stacks/lwip_stack/release_tar.sh @@ -29,7 +29,7 @@ if [ -f "./nStackTools.tar.gz" ]; then fi mkdir ./nStackServer/lib64 -cp ./release/lib64/libnstack.so ./release/lib64/libnStackAPI.so ./release/lib64/libnstackcmd.so ./release/lib64/libsecurec.so ./nStackServer/lib64 +cp ./release/lib64/liblwip_dpdk.so ./release/lib64/libnStackAPI.so ./release/lib64/libnstackcmd.so ./release/lib64/libsecurec.so ./nStackServer/lib64 mkdir ./nStackServer/bin cp ./release/bin/nStackCtrl ./release/bin/nStackMain ./release/bin/nStackMaster ./release/bin/set_permission.sh ./nStackServer/bin mkdir ./nStackServer/conf @@ -47,7 +47,7 @@ dos2unix ./nStackServer/*.sh find ./nStackServer -type f | grep -E "*.sh|*.py" | xargs chmod +x mkdir ./nStackClient/lib64 -cp ./release/lib64/libnstack.so ./release/lib64/libnStackAPI.so ./release/lib64/libsecurec.so ./nStackClient/lib64 +cp ./release/lib64/liblwip_dpdk.so ./release/lib64/libnStackAPI.so ./release/lib64/libsecurec.so ./nStackClient/lib64 mkdir ./nStackClient/include cp ./release/include/nstack_custom_api.h ./nStackClient/include diff --git a/stacks/lwip_stack/src/io_adpt/dpdk.c b/stacks/lwip_stack/src/io_adpt/dpdk.c index d199513..8518112 100644 --- a/stacks/lwip_stack/src/io_adpt/dpdk.c +++ b/stacks/lwip_stack/src/io_adpt/dpdk.c @@ -190,6 +190,13 @@ NSTACK_STATIC struct rte_eth_conf port_conf_default_bond = { }, }; +NSTACK_STATIC struct rte_eth_conf port_conf_default_vhost = { + .rxmode = { + .hw_ip_checksum = 0, /* vhost nic doesn't support hw_ip_checksum and hw_vlan_filter */ + .hw_vlan_filter = 0, + } +}; + /***************************************************************************** * Prototype : dpdk_mbuf_to_file * Description : write the packet data into a file @@ -700,6 +707,39 @@ dpdk_set_port (netif_inst_t * inst, uint8_t port) } /***************************************************************************** + Prototype : dpdk_set_nic_type + Description : check and save nic type + Input : netif_inst_t* inst + const char* type + Output : None + Return Value : NSTACK_STATIC + Calls : + Called By : + +*****************************************************************************/ +NSTACK_STATIC int +dpdk_set_nic_type (netif_inst_t * inst, const char *type) +{ + int ret; + + ret = + STRCPY_S (inst->data.dpdk_if.nic_type, + sizeof (inst->data.dpdk_if.nic_type), type); + if (EOK != ret) + { + NSHAL_LOGERR ("strcpy_s set nic_type failed]ret=%d", ret); + return -1; + } + + /* + * *nic_type is first checked at read_ipmoduleoperateadd_configuration, + * *thus here we dont boring validating it once more and just return. + * */ + + return 0; +} + +/***************************************************************************** Prototype : dpdk_set_nic_name Description : check and save nic name Input : netif_inst_t* inst @@ -1433,10 +1473,25 @@ dpdk_probe_pci (netif_inst_t * inst) *****************************************************************************/ NSTACK_STATIC int -dpdk_open (netif_inst_t * inst, const char *name) +dpdk_open (netif_inst_t * inst, const char *name, const char *type) { int ret; + if ((inst == NULL) || (name == NULL) || (type == NULL)) + { + NSHAL_LOGERR + ("invaliad arguments]inst==NULL, nic_type==NULL or type==NULL"); + return -1; + } + + ret = dpdk_set_nic_type (inst, type); + + if (0 != ret) + { + NSHAL_LOGERR ("dpdk_set_nic_type fail]nic_type=%s, ret=%d", type, ret); + return -1; + } + ret = dpdk_set_nic_name (inst, name); if (0 != ret) @@ -1445,6 +1500,13 @@ dpdk_open (netif_inst_t * inst, const char *name) return -1; } + if (!strncmp (type, "vhost", strlen ("vhost"))) + { + /*for vhost-user device, the remaining steps is unnecessary, y0413485 */ + NSHAL_LOGERR ("initting vhost device]nic_name=%s type=%s", name, type); + return 0; + } + ret = dpdk_get_driver_name (inst); if (0 != ret) @@ -1588,6 +1650,11 @@ dpdk_get_port_conf (netif_inst_t * inst, struct rte_eth_conf **port_conf) { *port_conf = &port_conf_default_bond; } + else if (strncmp ("vhost", inst->data.dpdk_if.nic_type, (size_t) 5) == 0) + { + *port_conf = &port_conf_default_vhost; + return; + } else { *port_conf = &port_conf_default_normal; diff --git a/stacks/lwip_stack/src/nStackMain/main.c b/stacks/lwip_stack/src/nStackMain/main.c index 220d1f1..3bc0a3b 100644 --- a/stacks/lwip_stack/src/nStackMain/main.c +++ b/stacks/lwip_stack/src/nStackMain/main.c @@ -42,7 +42,7 @@ #define GlOBAL_HELP "--help" #define GLOBAL_Dpdk_ARG "dpdk" #define GLOBAL_STACK_PORT "-port" -#define NSTACK_MAIN_MAX_PARA 19 +#define NSTACK_MAIN_MAX_PARA 32 #define NSTACK_MAIN_MIN_PARA 1 #define MAX_MASTER_OPEN_FD 1024 diff --git a/stacks/lwip_stack/src/sbr/CMakeLists.txt b/stacks/lwip_stack/src/sbr/CMakeLists.txt index 42ab4a4..f324e5f 100644 --- a/stacks/lwip_stack/src/sbr/CMakeLists.txt +++ b/stacks/lwip_stack/src/sbr/CMakeLists.txt @@ -21,9 +21,9 @@ endif() FILE(GLOB SBR *.c) -ADD_LIBRARY(nstack SHARED ${SBR}) -TARGET_LINK_LIBRARIES(nstack -Wl,--whole-archive socket -Wl,--no-whole-archive dmm_api nStackMaintain) -ADD_DEPENDENCIES(nstack socket DPDK) +ADD_LIBRARY(lwip_dpdk SHARED ${SBR}) +TARGET_LINK_LIBRARIES(lwip_dpdk -Wl,--whole-archive socket -Wl,--no-whole-archive dmm_api nStackMaintain) +ADD_DEPENDENCIES(lwip_dpdk socket DPDK) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_LIST_DIR}/../include ${PAL_H_DIRECTORIES} diff --git a/stacks/lwip_stack/src/sbr/sbr_socket.c b/stacks/lwip_stack/src/sbr/sbr_socket.c index 6f867ab..69481b5 100644 --- a/stacks/lwip_stack/src/sbr/sbr_socket.c +++ b/stacks/lwip_stack/src/sbr/sbr_socket.c @@ -1249,7 +1249,7 @@ SBR_INTERCEPT (void, fork_free_fd, (int s, pid_t p, pid_t c)) * *****************************************************************************/ int -nstack_stack_register (nstack_proc_cb * ops, nstack_event_cb * val) +lwip_stack_register (nstack_proc_cb * ops, nstack_event_cb * val) { if (!ops || !val || !val->handle) { diff --git a/stacks/lwip_stack/vagrant/start_nstackMain.sh b/stacks/lwip_stack/vagrant/start_nstackMain.sh index 00d4370..674562a 100755 --- a/stacks/lwip_stack/vagrant/start_nstackMain.sh +++ b/stacks/lwip_stack/vagrant/start_nstackMain.sh @@ -68,21 +68,9 @@ chmod 775 * cp ./configure/*.json bin/ cd bin -if [ "$OS_ID" == "centos" ]; then - sed -i 's!eth7!'$ifname'!1' ip_data.json -elif [ "$OS_ID" == "ubuntu" ]; then - sed -i 's!eth7!'$ifname'!1' ip_data.json -fi - -sed -i 's!00:54:32:19:3d:19!'$ifmac'!1' ip_data.json sed -i 's!192.168.1.207!'$ifaddress1'!1' ip_data.json sed -i 's!192.168.1.1!'$ifaddresscut'.0!1' network_data_tonStack.json -sed -i 's!192.168.1.254!'$ifaddresscut'.1!1' network_data_tonStack.json -sed -i 's!192.168.1.098!'$ifaddresscut'.5!1' network_data_tonStack.json -sed -i 's!192.168.1.209!'$ifaddresscut'.254!1' network_data_tonStack.json -sed -i 's!192.168.1.0!'$ifaddresscut'.0!1' network_data_tonStack.json -sed -i 's!192.168.1.254!'$ifaddresscut'.1!1' network_data_tonStack.json if [ "$OS_ID" == "centos" ]; then sed -i 's!eth7!'$ifname'!1' network_data_tonStack.json @@ -94,7 +82,7 @@ sed -i 's!eth7!'$ifname'!1' network_data_tonStack.json cd $DMM_BUILD_SCRIPT_DIR/../release/bin cp -r . ../../stacks/lwip_stack/app_test cd $DMM_BUILD_SCRIPT_DIR/../stacks/lwip_stack/app_test -cp -r ../app_conf/*.json . +cp -r ../configure/*.json . sed -i 's!192.168.1.1!'$ifaddresscut'.0!1' rd_config.json diff --git a/stacks/rsocket/CMakeLists.txt b/stacks/rsocket/CMakeLists.txt index c1b2f18..6ba868b 100644 --- a/stacks/rsocket/CMakeLists.txt +++ b/stacks/rsocket/CMakeLists.txt @@ -17,7 +17,7 @@ SET(rdmacm_dir librdmacm-1.1.0) SET(dmm_inc_dir ${DMM_REL_INC_DIR}) -SET(RSOCKET_DEBUG 0) +SET(RSOCKET_DEBUG 1) ######################## diff --git a/stacks/rsocket/config/module_config.json b/stacks/rsocket/configure/module_config.json index 2df82cd..736de24 100644 --- a/stacks/rsocket/config/module_config.json +++ b/stacks/rsocket/configure/module_config.json @@ -3,27 +3,17 @@ "module_list": [ { "stack_name": "kernel", /*stack name*/ - "function_name": "kernel_stack_register", /*function name*/ "libname": "./", /*library name, if loadtype is static, this maybe null, else must give a library name*/ - "loadtype": "static", /*library load type: static or dynamic*/ "deploytype": "1", /*deploy model type:model type1, model type2, model type3. Indicating single or multi process deployment. Used during shared memory initialization.*/ - "maxfd": "1024", /*the max fd supported*/ - "minfd": "0", /*the min fd supported*/ - "priorty": "1", /*priorty when executing, reserv*/ "stackid": "0", /*stack id, this must be ordered and not be repeated*/ }, { "stack_name": "rsocket", - "function_name": "rsocket_stack_register", "libname": "libdmm_rsocket.so", - "loadtype": "dynmic", "deploytype": "1", - "maxfd": "1024", - "minfd": "0", - "priorty": "1", "stackid": "1", }, ] diff --git a/stacks/rsocket/config/rd_config.json b/stacks/rsocket/configure/rd_config.json index 5c6f861..5c6f861 100644 --- a/stacks/rsocket/config/rd_config.json +++ b/stacks/rsocket/configure/rd_config.json diff --git a/stacks/rsocket/doc/README.md b/stacks/rsocket/doc/README.md index 237db68..6cdacfb 100644 --- a/stacks/rsocket/doc/README.md +++ b/stacks/rsocket/doc/README.md @@ -34,10 +34,10 @@ dmm/release/lib64/libdmm_rsocket.so ```sh #export LD_LIBRARY_PATH=${dmm}/release/lib64 #export LD_PRELOAD=${dmm}/release/lib64/libnStackAPI.so - #export NSTACK_MOD_CFG_FILE=${dmm}/stacks/rsocket/config/module_config.json - #export NSTACK_MOD_CFG_RD=${dmm}/stacks/rsocket/config/rd_config.json + #export NSTACK_MOD_CFG_FILE=${dmm}/stacks/rsocket/configure/module_config.json + #export NSTACK_MOD_CFG_RD=${dmm}/stacks/rsocket/configure/rd_config.json ``` -- Steps 2: Modify rd_config.json(located at dmm/stacks/rsocket/config/) +- Steps 2: Modify rd_config.json(located at dmm/stacks/rsocket/configure/) ```sh #vim rd_config.json //set "subnet": "192.168.21.1/24" @@ -107,4 +107,4 @@ all using GSAPI macro control. https://wiki.fd.io/view/DMM https://github.com/ofiwg/librdmacm/blob/master/docs/rsocket https://github.com/rsocket/rsocket -http://www.mellanox.com/page/products_dyn?product_family=26
\ No newline at end of file +http://www.mellanox.com/page/products_dyn?product_family=26 diff --git a/stacks/rsocket/src/rsocket_adpt.c b/stacks/rsocket/src/rsocket_adpt.c index ea22c76..2839909 100644 --- a/stacks/rsocket/src/rsocket_adpt.c +++ b/stacks/rsocket/src/rsocket_adpt.c @@ -235,6 +235,7 @@ rsocket_stack_register (nstack_proc_cb * proc_fun, proc_fun->extern_ops.module_init = rsocket_init; proc_fun->extern_ops.ep_ctl = rsocket_ep_ctl; proc_fun->extern_ops.ep_getevt = NULL; + proc_fun->extern_ops.module_init_child = rsocket_init; g_rr_var.type = event_ops->type; g_rr_var.event_cb = event_ops->event_cb; diff --git a/stacks/vpp/adapt/dmm_vcl_adpt.c b/stacks/vpp/adapt/dmm_vcl_adpt.c index d4974e2..56f9033 100644 --- a/stacks/vpp/adapt/dmm_vcl_adpt.c +++ b/stacks/vpp/adapt/dmm_vcl_adpt.c @@ -143,7 +143,7 @@ dmm_vpphs_init () } int -vpphs_stack_register (nstack_proc_cb * ops, nstack_event_cb * val) +vpp_hoststack_stack_register (nstack_proc_cb * ops, nstack_event_cb * val) { #undef NSTACK_MK_DECL diff --git a/stacks/vpp/configure/module_config.json b/stacks/vpp/configure/module_config.json index 49b7ca9..fb73574 100644 --- a/stacks/vpp/configure/module_config.json +++ b/stacks/vpp/configure/module_config.json @@ -3,27 +3,17 @@ "module_list": [ { "stack_name": "kernel", /*stack name*/ - "function_name": "kernel_stack_register", /*function name*/ "libname": "./", /*library name, if loadtype is static, this maybe null, else must give a library name*/ - "loadtype": "static", /*library load type: static or dynamic*/ "deploytype": "1", /*deploy model type:model type1, model type2, model type3. Indicating single or multi process deployment. Used during shared memory initialization.*/ - "maxfd": "1024", /*the max fd supported*/ - "minfd": "0", /*the min fd supported*/ - "priorty": "1", /*priorty when executing, reserv*/ "stackid": "0", /*stack id, this must be ordered and not be repeated*/ }, { "stack_name": "vpp_hoststack", - "function_name": "vpphs_stack_register", "libname": "../lib64/libdmm_vcl.so", - "loadtype": "dynmic", "deploytype": "4", - "maxfd": "1024", - "minfd": "0", - "priorty": "1", "stackid": "1", }, ] diff --git a/thirdparty/apps/CMakeLists.txt b/thirdparty/apps/CMakeLists.txt index 2cf5240..0fffccd 100644 --- a/thirdparty/apps/CMakeLists.txt +++ b/thirdparty/apps/CMakeLists.txt @@ -28,18 +28,19 @@ endif() INCLUDE(ExternalProject) ExternalProject_Add( - NGINX - URL ${NGINX_URL} - DOWNLOAD_DIR ${NGINX_DOWNLOAD_DIR} - DOWNLOAD_COMMAND ${NGINX_DOWNLOAD_CMD} - BUILD_IN_SOURCE 1 - SOURCE_DIR ${NGINX_SRC} - PATCH_COMMAND echo "./configure --with-ld-opt=\"-L${LIB_PATH_SHARED}/ -lnStackAPI -Wl,-rpath=${LIB_PATH_SHARED}\" --sbin-path=${NGINX_RELEASE}/nginx --conf-path=${NGINX_RELEASE}/nginx.conf --pid-path=${NGINX_RELEASE}/nginx.pid " > configure.sh - COMMAND sed -i -e "48,49 s/^/#/" ${CMAKE_CURRENT_LIST_DIR}/nginx/nginx-1.12.2/auto/os/linux - CONFIGURE_COMMAND sh configure.sh - BUILD_COMMAND make - INSTALL_COMMAND make install - DEPENDS nStackAPI + NGINX + URL ${NGINX_URL} + DOWNLOAD_DIR ${NGINX_DOWNLOAD_DIR} + DOWNLOAD_COMMAND ${NGINX_DOWNLOAD_CMD} + BUILD_IN_SOURCE 1 + SOURCE_DIR ${NGINX_SRC} + PATCH_COMMAND echo "./configure --with-stream --with-ld-opt=\"-L${LIB_PATH_SHARED}/ -lnStackAPI -Wl,-rpath=${LIB_PATH_SHARED}\" --sbin-path=${NGINX_RELEASE}/nginx --conf-path=${NGINX_RELEASE}/nginx.conf --pid-path=${NGINX_RELEASE}/nginx.pid " > configure.sh + COMMAND sed -i -e "47 s/$/\"/" ${CMAKE_CURRENT_LIST_DIR}/nginx/nginx-1.12.2/auto/os/linux + COMMAND sed -i -e "48,49 s/^/#/" ${CMAKE_CURRENT_LIST_DIR}/nginx/nginx-1.12.2/auto/os/linux + CONFIGURE_COMMAND sh configure.sh + BUILD_COMMAND make + INSTALL_COMMAND make install + DEPENDS nStackAPI ) set_target_properties(NGINX PROPERTIES EXCLUDE_FROM_ALL TRUE) |