diff --git a/scripts/dpdk.config b/scripts/dpdk.config new file mode 100644 index 00000000000..3c7c7a1d5b7 --- /dev/null +++ b/scripts/dpdk.config @@ -0,0 +1,9 @@ +mode=dpdk +netconfig=nmcli +eth=eth0 +eth_driver=ixgbevf +dpdk_build=../build/dpdk +dpdk_src=../dpdk +nr_hugepages=64 +program=../build/release/apps/httpd/httpd +args="--network-stack native --csum-offload off" diff --git a/scripts/get_conn_name.py b/scripts/get_conn_name.py new file mode 100755 index 00000000000..25470ac1145 --- /dev/null +++ b/scripts/get_conn_name.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 +# +# This file is open source software, licensed to you under the terms +# of the Apache License, Version 2.0 (the "License"). See the NOTICE file +# distributed with this work for additional information regarding copyright +# ownership. 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. +# +import dbus +import sys + +if len(sys.argv) < 2: + print("usage: %s [ifname]" % sys.argv[0]) + sys.exit(1) + +bus = dbus.SystemBus() +nm_proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") +nm_obj = dbus.Interface(nm_proxy, "org.freedesktop.NetworkManager") +for dev_path in nm_obj.GetDevices(): + dev_proxy = bus.get_object("org.freedesktop.NetworkManager", dev_path) + dev_obj = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") + dev_props = dev_obj.GetAll("org.freedesktop.NetworkManager.Device") + if sys.argv[1] != dev_props['Interface']: + continue + conn_proxy = bus.get_object("org.freedesktop.NetworkManager", dev_props['ActiveConnection']) + conn_obj = dbus.Interface(conn_proxy, "org.freedesktop.DBus.Properties") + conn_props = conn_obj.GetAll("org.freedesktop.NetworkManager.Connection.Active") + print(conn_props['Id']) + break diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 00000000000..ce58d6d3be7 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,43 @@ +#!/bin/sh -e +# +# This file is open source software, licensed to you under the terms +# of the Apache License, Version 2.0 (the "License"). See the NOTICE file +# distributed with this work for additional information regarding copyright +# ownership. 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. +# + +if [ $# -lt 1 ]; then + echo "usage: $0 [config]" + exit 1 +fi + +. ./$1 + +if [ "$mode" != "nat" ]; then + exit 0 +fi + +if [ "$netconfig" = "nmcli" ]; then + eth_conn_name=`./get_conn_name.py $eth` + if [ "$eth_conn_name" = "" ]; then + echo "Cannot detect $eth connection name" + exit 1 + fi + nmcli c add type bridge ifname $bridge + nmcli c mod bridge-$bridge bridge.stp no + nmcli c add type bridge-slave ifname $eth master bridge-$bridge + nmcli c del "$eth_conn_name" +fi +echo "net.ipv4.ip_local_port_range= $local_port_start $local_port_end" >> /etc/sysctl.conf +sysctl -p diff --git a/scripts/nat.config b/scripts/nat.config new file mode 100644 index 00000000000..9eea74f5800 --- /dev/null +++ b/scripts/nat.config @@ -0,0 +1,13 @@ +mode=nat +netconfig=seastar +eth=eth0 +eth_driver=ixgbevf +tap=tap0 +bridge=br0 +local_port_start=32768 +local_port_end=49152 +dpdk_build=../build/dpdk +dpdk_src=../dpdk +nr_hugepages=64 +program=../build/release/apps/httpd/httpd +args="--network-stack native --csum-offload off" diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 00000000000..f6fa831d068 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,75 @@ +#!/bin/sh -e +# +# This file is open source software, licensed to you under the terms +# of the Apache License, Version 2.0 (the "License"). See the NOTICE file +# distributed with this work for additional information regarding copyright +# ownership. 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. +# + +if [ $# -lt 1 ]; then + echo "usage: $0 [config]" + exit 1 +fi + +. ./$1 + +if [ "$mode" = "nat" ]; then + if [ "$netconfig" = "seastar" ]; then + if [ "`ip link show $bridge`" = "" ]; then + killall dhclient || true + eth_mac=`ip link show $eth |grep link|awk '{print $2}'` + eth_ip=`ip addr show $eth |grep 'inet '|awk '{print $2}'` + ip addr del $eth_ip dev $eth + ip link add name $bridge type bridge + ip link set $bridge address $eth_mac + ip link set dev $eth master $bridge + dhclient $bridge + fi + fi +fi + +if [ "$mode" = "dpdk" ] || [ "$mode" = "nat" ]; then + modprobe uio + if [ "`lsmod|grep igb_uio`" = "" ]; then + insmod $dpdk_build/kmod/igb_uio.ko + fi + $dpdk_src/tools/dpdk_nic_bind.py --force --bind=igb_uio $eth + mkdir -p /mnt/huge + mount -t hugetlbfs nodev /mnt/huge + echo $nr_hugepages > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages + args="$args --dpdk-pmd" +fi + +if [ "$mode" = "nat" ]; then + ip tuntap del mode tap dev $tap + ip tuntap add mode tap dev $tap one_queue vnet_hdr + ip link set dev $tap up + ip link set dev $tap master $bridge + modprobe vhost-net + chown $user.$user /dev/vhost-net + args="$args --nat-adapter" +fi + +if [ "$mode" = "virtio" ]; then + user=`whoami` + sudo ip tuntap del mode tap dev $tap + sudo ip tuntap add mode tap dev $tap user $user one_queue vnet_hdr + sudo ip link set dev $tap up + sudo ip link set dev $tap master $bridge + sudo modprobe vhost-net + sudo chown $user.$user /dev/vhost-net +fi + +export LD_LIBRARY_PATH=$dpdk_target/lib +$program $args diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100755 index 00000000000..a1664ec2366 --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e +# +# This file is open source software, licensed to you under the terms +# of the Apache License, Version 2.0 (the "License"). See the NOTICE file +# distributed with this work for additional information regarding copyright +# ownership. 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. +# + +if [ $# -lt 1 ]; then + echo "usage: $0 [config]" + exit 1 +fi + +. ./$1 + +if [ "$mode" = "nat" ]; then + ip tuntap del mode tap dev $tap +fi + +if [ "$mode" = "virtio" ]; then + sudo ip tuntap del mode tap dev $tap +fi + +if [ "$mode" = "dpdk" ] || [ "$mode" = "nat" ]; then + pci_id=`$dpdk_src/tools/dpdk_nic_bind.py --status|grep "igb_uio"|awk '{print $1}'` + if [ "$pci_id" != "" ]; then + $dpdk_src/tools/dpdk_nic_bind.py -u $pci_id + $dpdk_src/tools/dpdk_nic_bind.py -b $eth_driver $pci_id + rmmod igb_uio + fi + umount /mnt/huge + if [ "$netconfig" = "seastar" ]; then + brctl addif $bridge $eth + fi +fi diff --git a/scripts/test.py b/scripts/test.py new file mode 100644 index 00000000000..51720c28c7c --- /dev/null +++ b/scripts/test.py @@ -0,0 +1,15 @@ +import dbus +import pprint +import sys + +bus = dbus.SystemBus() +proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings") +settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings") +for path in settings.ListConnections(): + con_proxy = bus.get_object("org.freedesktop.NetworkManager", path) + conn = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection") + settings = conn.GetSettings() + print("path: %s" % path) + print(" id: %s" % settings['connection']['id']) + print(" uuid: %s" % settings['connection']['uuid']) + print(" type: %s" % settings['connection']['type']) diff --git a/scripts/tap.sh b/scripts/uninstall.sh old mode 100644 new mode 100755 similarity index 62% rename from scripts/tap.sh rename to scripts/uninstall.sh index 8a6ac55dd53..ad60a31e064 --- a/scripts/tap.sh +++ b/scripts/uninstall.sh @@ -1,3 +1,4 @@ +#!/bin/sh -e # # This file is open source software, licensed to you under the terms # of the Apache License, Version 2.0 (the "License"). See the NOTICE file @@ -16,16 +17,22 @@ # under the License. # -### Set up a tap device for seastar -tap=tap0 -bridge=virbr0 -user=`whoami` -sudo tunctl -d $tap -sudo ip tuntap add mode tap dev $tap user $user one_queue vnet_hdr -sudo ifconfig $tap up -sudo brctl addif $bridge $tap -sudo brctl stp $bridge off -sudo modprobe vhost-net -sudo chown $user.$user /dev/vhost-net -sudo brctl show $bridge -sudo ifconfig $bridge +if [ $# -lt 1 ]; then + echo "usage: $0 [config]" + exit 1 +fi + +. ./$1 + +if [ "$mode" != "nat" ]; then + exit 0 +fi + +if [ "$netconfig" = "nmcli" ]; then + nmcli c del bridge-slave-$eth + nmcli c del bridge-$bridge + nmcli c add type eth ifname $eth +fi +grep -v "net.ipv4.ip_local_port_range" /etc/sysctl.conf > /tmp/sysctl.conf +cp /tmp/sysctl.conf /etc +sysctl -w "net.ipv4.ip_local_port_range= 32768 61000" diff --git a/scripts/virtio.config b/scripts/virtio.config new file mode 100644 index 00000000000..104395bfbf1 --- /dev/null +++ b/scripts/virtio.config @@ -0,0 +1,10 @@ +mode=virtio +netconfig=nmcli +eth=eth0 +tap=tap0 +bridge=virbr0 +dpdk_build=../build/dpdk +dpdk_src=../dpdk +nr_hugepages=64 +program=../build/release/apps/httpd/httpd +args="--network-stack native --csum-offload off"