diff options
Diffstat (limited to 'demo/nginx_proxy/demo-1')
-rw-r--r-- | demo/nginx_proxy/demo-1/Vagrantfile | 98 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/adjust_hugepage.sh | 14 | ||||
-rwxr-xr-x | demo/nginx_proxy/demo-1/apply_patch.sh | 9 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/demo_2stack.patch | 29 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/module_config.json | 38 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/proxy_nginx.conf | 81 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/rd_config.json | 27 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/setup_proxy.sh | 54 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/setup_upstream.sh | 45 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/startup.conf | 20 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/upstream_nginx.conf | 80 | ||||
-rw-r--r-- | demo/nginx_proxy/demo-1/vpp_config | 6 |
12 files changed, 501 insertions, 0 deletions
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..93ef5f2 --- /dev/null +++ b/demo/nginx_proxy/demo-1/module_config.json @@ -0,0 +1,38 @@ +{ + "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", + }, + { + "stack_name": "vpp_hoststack", + "function_name": "vpphs_stack_register", + "libname": "./libdmm_vcl.so", + "loadtype": "dynmic", + "deploytype": "4", + "maxfd": "1024", + "minfd": "0", + "priorty": "1", + "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..7dc4fa3 --- /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/app_conf/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 |