Skip to content

Commit

Permalink
Add scripts & config files for install / startup SeaStar instance
Browse files Browse the repository at this point in the history
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
  • Loading branch information
syuu1228 committed Jul 27, 2015
1 parent 4be1787 commit b648d92
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 13 deletions.
9 changes: 9 additions & 0 deletions scripts/dpdk.config
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 39 additions & 0 deletions scripts/get_conn_name.py
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions scripts/nat.config
Original file line number Diff line number Diff line change
@@ -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"
75 changes: 75 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions scripts/test.py
Original file line number Diff line number Diff line change
@@ -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'])
33 changes: 20 additions & 13 deletions scripts/tap.sh → scripts/uninstall.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
10 changes: 10 additions & 0 deletions scripts/virtio.config
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit b648d92

Please sign in to comment.