Skip to content

Instantly share code, notes, and snippets.

@kazuyas
Created March 11, 2012 15:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kazuyas/2016918 to your computer and use it in GitHub Desktop.
OpenWRT /lib/openflow/ofprotocol.sh
#!/bin/sh
# Copyright (C) 2009 OpenFlowSwitch.org
setup_ofprotocol() {
local config="$1"
local ofctl
local dp
[ -x "/usr/bin/ofprotocol" ] || ( echo "ofprotocol not executable" && return 0 )
config_get ofctl "$config" ofctl
config_get dp "$config" dp
config_get mode "$config" mode
pidfile="/var/run/ofprotocol.pid"
logfile="/var/log/ofprotocol.log"
# prevent ofprotocol from starting more than once
lock "/var/lock/ofprotocol"
pid="$(cat "$pidfile" 2>/dev/null)"
if [ -d "/proc/$pid" ] && grep ofprotocol "/proc/${pid}/cmdline" >/dev/null 2>/dev/null; then
lock -u "/var/lock/ofprotocol"
else
[ -z "$dp" -o -z "$ofctl" ] && echo "no controller specified" && return 1
if [[ "$mode" == "inband" ]]
then
ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail=open "-D" "--pidfile=$pidfile" --listen=ptcp: --log-file="/var/log/ofprotocol.log" "--inactivity-probe=90" &
else
ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail=open "-D" "--pidfile=$pidfile" --out-of-band --listen=ptcp: --log-file="/var/log/ofprotocol.log" "--inactivity-probe=90" &
fi
lock -u "/var/lock/ofprotocol"
fi
}
setup_box() {
local config="$1"
local mode
config_get mode "$config" mode
if [[ "$mode" == "inband" ]]
then
setup_inband_control "$1"
else
setup_outband_control "$1"
fi
}
setup_inband_control() {
local config="$1"
local ipaddr
local netmask
config_get ipaddr "$config" ipaddr
config_get netmask "$config" netmask
config_get gateway "$config" gateway
echo "Configuring local device with ip $ipaddr and netmask $netmask"
ifconfig tap0 $ipaddr netmask $netmask up
route add default gw $gateway
}
setup_outband_control() {
echo "No need for further configuration for out-of-band control"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment