From 0a0139ea0f22ba560af1d6fd6886872bc79983ac Mon Sep 17 00:00:00 2001 From: luissequeira Date: Tue, 25 Oct 2016 18:29:45 +0200 Subject: [PATCH] Startup script update. --- .directory | 3 - scripts_start_ap_odin/init_cli.sh | 36 ------------ scripts_start_ap_odin/init_ovs.sh | 86 ----------------------------- scripts_start_ap_odin/start.sh | 74 +++++++++++++++++++++++++ scripts_start_ap_odin/start_odin.sh | 64 --------------------- 5 files changed, 74 insertions(+), 189 deletions(-) delete mode 100644 .directory delete mode 100644 scripts_start_ap_odin/init_cli.sh delete mode 100644 scripts_start_ap_odin/init_ovs.sh create mode 100644 scripts_start_ap_odin/start.sh delete mode 100644 scripts_start_ap_odin/start_odin.sh diff --git a/.directory b/.directory deleted file mode 100644 index 127b8ac..0000000 --- a/.directory +++ /dev/null @@ -1,3 +0,0 @@ -[Dolphin] -Timestamp=2016,4,11,13,41,28 -Version=3 diff --git a/scripts_start_ap_odin/init_cli.sh b/scripts_start_ap_odin/init_cli.sh deleted file mode 100644 index 1f3273a..0000000 --- a/scripts_start_ap_odin/init_cli.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -#Setup variables -# My local IP address, i.e. the one I am using to connect with the Odin Controller -MYIP=192.168.101.9 - -# This is the IP of the Odin Controller -CTLIP=192.168.101.129 - -# This is the TCP port number for the openvswitch database -TCP_PORT_OVS_DBASE=6632 - -# This is the TCP port number for the Click control socket (controlskt) -TCP_PORT_CLICK_CTRL_SOCKET=6777 - -# This is the name of the bridge that we are going to create -SW=br0 - - -# Start Click, using the correct name of the ALIGNED .cli file -./click a_agent.cli & - -# Wait some time -sleep 3 - -# Start the 'ap' interface created by Click -ifconfig ap up - -# Add the 'ap' interface to the openvswitch -ovs-vsctl --db=tcp:$MYIP:$TCP_PORT_OVS_DBASE add-port $SW ap - -# Wait some time -sleep 3 - -# Add an Openflow rule in the Controller, to manage the new flows of the Click control socket -ovs-ofctl add-flow $SW in_port=1,dl_type=0x0800,nw_src=$CTLIP,nw_dst=$MYIP,nw_proto=6,tp_dst=$TCP_PORT_CLICK_CTRL_SOCKET,actions=output:LOCAL \ No newline at end of file diff --git a/scripts_start_ap_odin/init_ovs.sh b/scripts_start_ap_odin/init_ovs.sh deleted file mode 100644 index b3bc482..0000000 --- a/scripts_start_ap_odin/init_ovs.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh -# This has been adapted from https://gist.github.com/marciolm/9f0ab13b877372d08e8f - -#Setup variables -#My local IP address is required for the ovsdb server. -MYIP=192.168.101.9 - -# This is the OpenFlow controller ID which we're going to load into the OVS -CTLIP=192.168.101.129 - -# This is our DataPath ID -DPID=0000000000000212 - -# This is the name of the bridge that we are going to create -SW=br0 - -# This is the TCP port number for the openvswitch database -TCP_PORT_OVS_DBASE=6632 - -# This is the TCP port number for the control of OpenFlow -TCP_PORT_OPENFLOW=6633 - -#What ports are we going to put in the OVS? -#DPPORTS="eth0.1 eth0.2 eth0.3 eth0.4 wlan0 wlan0-2 wlan0-3" -DPPORTS="eth1.1" - -#Alias some variables -VSCTL="ovs-vsctl --db=tcp:$MYIP:$TCP_PORT_OVS_DBASE" -OVSDB=/tmp/ovs-vswitchd.conf.db - -# Subroutine to wait until a port is ready -wait_port_listen() { - port=$1 - while ! `netstat -na | grep $port` ; do - echo -n . - sleep 1 - done -} - -# Kill off the servers and remove any stale lockfiles -/usr/bin/killall ovsdb-server -/usr/bin/killall ovs-vswitchd -rm /tmp/ovs-vswitchd.conf.db.~lock~ - -# Remove the OVS Database and then recreate. -rm -f $OVSDB - -# ovsdg-tool is the Open vSwitch database management utility -# if you use #ovsdb-tool create [DB [SCHEMA]], then you create a DB with the given SCHEMA -ovsdb-tool create $OVSDB /usr/share/openvswitch/vswitch.ovsschema - -# Start the OVSDB server and wait until it starts -ovsdb-server $OVSDB --remote=ptcp:$TCP_PORT_OVS_DBASE:$MYIP & -#wait_port_listen $TCP_PORT_OVS_DBASE -sleep 5 - -# Start vSwitchd -ovs-vswitchd tcp:$MYIP:$TCP_PORT_OVS_DBASE --pidfile=ovs-vswitchd.pid --overwrite-pidfile -- & - -# Create the bridge and pass in some configuration options -$VSCTL add-br $SW - -# In OpenWrt 15.05 the bridge is created down -ifconfig $SW up - -#optional: define the version of OpenFlow to be used -#$VSCTL set bridge $SW protocols=OpenFlow10 - -#Configure the switch to have an OpenFlow Controller. This will contact the controller. -$VSCTL set-controller $SW tcp:$CTLIP:$TCP_PORT_OPENFLOW - -# Turn off the fail-safe mode -$VSCTL set-fail-mode $SW secure - -#Cycle through the DataPath ports adding them to the switch -for i in $DPPORTS ; do - PORT=$i - ifconfig $PORT up - $VSCTL add-port $SW $PORT -done - -#Ensure that the switch has the correct DataPath ID -$VSCTL set bridge $SW other-config:datapath-id=$DPID - -#Set some parameters for sFlow traffic control (see sFlow in http://openvswitch.org/support/dist-docs/ovs-vsctl.8.txt) -#$VSCTL --id=@sflow create sflow agent=eth1.1 target=\"$CTLIP:6343\" sampling=2 polling=20 -- -- set bridge $SW sflow=@sflow diff --git a/scripts_start_ap_odin/start.sh b/scripts_start_ap_odin/start.sh new file mode 100644 index 0000000..22e56d0 --- /dev/null +++ b/scripts_start_ap_odin/start.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +## Variables +echo "Setting variables" +CTLIP=192.168.1.129 # Controller IP +SW=br0 +DPPORTS="eth1.2" # Ports for data plane +VSCTL="ovs-vsctl" + +## Setting interfaces +echo "Setting interfaces" +ifconfig wlan0 down # Main interface +ifconfig wlan1 down # Auxiliary interface +iw phy phy0 interface add mon0 type monitor +iw phy phy1 interface add mon1 type monitor +iw phy phy0 set retry short 4 +iw phy phy1 set retry short 4 +ifconfig mon0 up +ifconfig mon1 up +ifconfig wlan0 up +ifconfig wlan1 up +# add this route in order to permit control from Unizar networks +# traffic from these networks will not go through the default gateway +route add -net 155.210.158.0 netmask 255.255.255.0 gw 155.210.157.254 eth0 +route add -net 155.210.156.0 netmask 255.255.255.0 gw 155.210.157.254 eth0 +# set the default gateway where masquerading is being performed +#route del default gw 155.210.157.254 +#route add default gw 192.168.1.131 + +## We assume that OpenvSwitch runs when OpenWRT starts up +echo "Restarting OpenvSwitch daemon" +/etc/init.d/openvswitch stop +echo "Cleaning DB" +if [ -d "/etc/openvswitch" ]; then + rm -r /etc/openvswitch +fi +if [ -f "/var/run/db.sock" ]; then + rm /var/run/db.sock +fi +if [ -f "/var/run/ovsdb-server.pid" ]; then + rm /var/run/ovsdb-server.pid +fi +if [ -f "/var/run/ovs-vswitchd.pid" ]; then + rm /var/run/ovs-vswitchd.pid +fi +/etc/init.d/openvswitch start +echo "Configuring OpenvSwitch" +$VSCTL add-br $SW # Create the bridge +ifconfig $SW up # In OpenWrt 15.05 the bridge is created down +$VSCTL set-controller $SW tcp:$CTLIP:6633 # Configure the OpenFlow Controller. +for i in $DPPORTS ; do # Including ports to OVS + PORT=$i + ifconfig $PORT up + $VSCTL add-port $SW $PORT +done + +## Launch click +echo "Mounting USB" # Because we have click into the USB +if [ ! -d "/mnt/usb" ]; then + mkdir -p /mnt/usb +fi +mount /dev/sda1 /mnt/usb/ +cd /mnt/usb +sleep 1 +./click aagent9.cli & +sleep 1 +ifconfig ap up # Adding ap interface (click Interface) to OVS +$VSCTL add-port $SW ap +sleep 1 + +## OVS Rules +# DHCP rules needed by odin-wi5 controller +ovs-ofctl add-flow br0 in_port=2,dl_type=0x0800,nw_proto=17,tp_dst=67,actions=output:1,CONTROLLER +ovs-ofctl add-flow br0 in_port=1,dl_type=0x0800,nw_proto=17,tp_dst=68,actions=output:CONTROLLER,2 diff --git a/scripts_start_ap_odin/start_odin.sh b/scripts_start_ap_odin/start_odin.sh deleted file mode 100644 index 04ed575..0000000 --- a/scripts_start_ap_odin/start_odin.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -echo "interfaces" -#put wlan0 down before creating mon0 -ifconfig wlan0 down -#add the monitor device -iw phy phy0 interface add mon0 type monitor -#you should not define the channel here, so we have commented the next line -#iw dev wlan0 set channel 1 -#initiate mon0 -ifconfig mon0 up -#initiate wlan0. You must have it active, otherwise things do not work -ifconfig wlan0 up - -# add this route in order to permit control from Unizar networks -# traffic from these networks will not go through the default gateway -# NOTE: The next two lines are just for our Unizar setup, so you can remove them -route add -net 155.210.158.0 netmask 255.255.255.0 gw 155.210.157.254 eth0 -route add -net 155.210.156.0 netmask 255.255.255.0 gw 155.210.157.254 eth0 - -# set the default gateway where masquerading is being performed -# NOTE: This may vary according to your setup. Add your default gateway as needed -route del default gw 155.210.157.254 -<<<<<<< HEAD -route add default gw 192.168.1.129 - -# if you have put click and start-up scripts in a usb device, mount the USB -mkdir -p /mnt/usb -mount /dev/sda1 /mnt/usb/ -cd /mnt/usb/ - -# start ovs and click with the corresponding scripts -./script_start_ovs.sh -sleep 2 -./script_start_click.sh -======= -route add default gw 192.168.101.129 - -# this script assumes you have: -# - in the root directory (current): start_odin.sh -# - in the USB: -# - init_ovs.sh -# - init_cli.sh -# - click the compiled Click application -# - a_agent.cli the .cli file to be run by Click. It must be aligned - -# mount the USB -mkdir -p /mnt/usb -mount /dev/sda1 /mnt/usb/ #sda1 may have to be replaced by other device - - -# initiate openvswitch and click with the corresponding scripts: - -# move to /mnt/usb -cd /mnt/usb - -# initiate openvswitch (ovs) -./init_ovs.sh - -# wait some time -sleep 2 - -# initiate click (cli) -./init_cli.sh ->>>>>>> refs/heads/alpha_stats