Skip to content

Commit

Permalink
Merge branch 'Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenmunilla committed Jul 7, 2017
2 parents d9b0b7e + c11543e commit 65f0e28
Show file tree
Hide file tree
Showing 7 changed files with 819 additions and 270 deletions.
98 changes: 57 additions & 41 deletions agent-click-file-gen.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/usr/bin/python

# This script creates a .click file which can then be run using the click modular router.
# This script creates a .cli file which can then be run using the Click modular router.
# http://read.cs.ucla.edu/click/click
# https://github.com/kohler/click
#
# it requires that you have installed the OdinAgent module within your click installation
# it requires that you have installed the odinagent.cc module within your Click installation
# https://github.com/Wi5/odin-wi5-agent/tree/master/src
#
# it also requires that you have patched the ath9k driver. This is the only driver supported currently
# it also requires that you have patched the ath9k driver.
# About the driver patch see:
# https://github.com/Wi5/odin-wi5/tree/master/odin-patch-driver-ath9k

import sys

if (len(sys.argv) != 14):
if (len(sys.argv) != 18):
print 'Usage:'
print ''
print '%s <AP_CHANNEL> <QUEUE_SIZE> <MAC_ADDR_AP> <ODIN_MASTER_IP> <ODIN_MASTER_PORT> <DEBUGFS_FILE> <SSIDAGENT> <ODIN_AGENT_IP> <DEBUG_CLICK> <DEBUG_ODIN> <TX_RATE> <TX_POWER> <HIDDEN>' %(sys.argv[0])
print '%s <AP_CHANNEL> <QUEUE_SIZE> <MAC_ADDR_AP> <ODIN_MASTER_IP> <ODIN_MASTER_PORT> <DEBUGFS_FILE> <SSIDAGENT> <ODIN_AGENT_IP> <DEBUG_CLICK> <DEBUG_ODIN> <TX_RATE> <TX_POWER> <HIDDEN> <MULTICHANNEL_AGENTS> <DEFAULT_BEACON_INTERVAL> <BURST_BEACON_INTERVAL> <MEASUREMENT_BEACON_INTERVAL>' %(sys.argv[0])
print ''
print 'AP_CHANNEL: it must be the same where mon0 of the AP is placed. To avoid problems at init time, it MUST be the same channel specified in the /etc/config/wireless file of the AP'
print 'QUEUE_SIZE: you can use the size 50'
print 'MAC_ADDR_AP: the MAC of the wireless interface mon0 of the AP. e.g. 74-F0-6E-20-D4-74'
print 'MAC_ADDR_AP: the MAC of the wireless interface mon0 of the AP. e.g. 60:E3:27:4F:C7:E1'
print 'ODIN_MASTER_IP is the IP of the openflow controller where Odin master is running'
print 'ODIN_MASTER_PORT should be 2819 by default'
print 'DEBUGFS_FILE is the path of the bssid_extra file created by the ath9k patch'
print ' it can be /sys/kernel/debug/ieee80211/phy0/ath9k/bssid_extra'
print 'SSIDAGENT is the name of the SSID of this Odin agent'
print 'ODIN_AGENT_IP is the IP address of the AP where this script is running (the IP used for communicating with the controller)'
print 'ODIN_AGENT_IP is the IP address of the AP where this script is running (the control plane ethernet IP, used for communicating with the controller)'
print 'DEBUG_CLICK: "0" no info displayed; "1" only basic info displayed; "2" all the info displayed'
print 'DEBUG_ODIN: "00" no info displayed; "01" only basic info displayed; "02" all the info displayed; "11" or "12": demo mode (more separators)'
print 'TX_RATE: it is an integer, and the rate is obtained by its product with 500kbps. e.g. if it is 108, this means 108*500kbps = 54Mbps'
Expand All @@ -35,35 +35,44 @@
print ' for getting the value, use e.g. $# iw dev mon0 info'
print 'HIDDEN: If HIDDEN is 1, then the AP will only send responses to the active scans targetted to the SSID of Odin'
print ' If HIDDEN is 0, then the AP will also send responses to active scans with an empty SSID'
print 'MULTICHANNEL_AGENTS: If MULTICHANNEL_AGENTS is 1, it means that the APs can be in different channels'
print ' If MULTICHANNEL_AGENTS is 0, it means that all the APs are in the same channel'
print 'DEFAULT_BEACON_INTERVAL: Time between beacons (in milliseconds). Recommended values: 20-100'
print 'BURST_BEACON_INTERVAL: Time between beacons when a burst of CSAs is sent after a handoff (in milliseconds). Recommended values: 5-10'
print 'MEASUREMENT_BEACON_INTERVAL: Time between measurement beacons (in milliseconds). Used for measuring the distance in dBs between APs. Recommended values: 20-100'
print ''
print 'Example:'
print '$ python agent-click-file-gen.py 9 50 60:E3:27:4F:C7:E1 192.168.1.129 2819 /sys/kernel/debug/ieee80211/phy0/ath9k/bssid_extra wi5-demo 192.168.1.9 1 01 108 25 0 > agent.cli' %(sys.argv[0])
print '$ python %s 9 50 60:E3:27:4F:C7:E1 192.168.1.129 2819 /sys/kernel/debug/ieee80211/phy0/ath9k/bssid_extra wi5-demo 192.168.1.9 0 01 108 25 0 1 100 10 100 > agent.cli' %(sys.argv[0])
print ''
print 'and then run the .click file you have generated'
print 'click$ ./bin/click agent.click'
print 'and then run the .cli file you have generated'
print 'click$ ./bin/click agent.cli'
sys.exit(0)

# Read the arguments
AP_CHANNEL = sys.argv[1]
QUEUE_SIZE = sys.argv[2]
AP_UNIQUE_BSSID = sys.argv[3] # MAC address of the wlan0 interface of the router where Click runs (in monitor mode). It seems it does not matter.
AP_UNIQUE_BSSID = sys.argv[3] # FIXME. It seems it does not matter. Remove this parameter?
ODIN_MASTER_IP = sys.argv[4]
ODIN_MASTER_PORT = sys.argv[5]
DEBUGFS_FILE = sys.argv[6]
SSIDAGENT = sys.argv[7]
DEFAULT_GW = sys.argv[8] #the IP address of the Access Point.
AP_UNIQUE_IP = sys.argv[8] # IP address of the wlan0 interface of the router where Click runs (in monitor mode). It seems it does not matter.
DEFAULT_GW = sys.argv[8]
AP_UNIQUE_IP = sys.argv[8] # FIXME. It seems this parameter does not matter. Remove this line?
DEBUG_CLICK = int(sys.argv[9])
DEBUG_ODIN = int(sys.argv[10])
TX_RATE = int(sys.argv[11])
TX_POWER = int(sys.argv[12])
HIDDEN = int(sys.argv[13])

MULTICHANNEL_AGENTS = int(sys.argv[14])
DEFAULT_BEACON_INTERVAL = int(sys.argv[15])
BURST_BEACON_INTERVAL = int(sys.argv[16])
MEASUREMENT_BEACON_INTERVAL = int(sys.argv[17])

# Set the value of some constants
NETWORK_INTERFACE_NAMES = "mon" # beginning of the network interface names in monitor mode. e.g. mon
TAP_INTERFACE_NAME = "ap" # name of the TAP device that Click will create in the
STA_IP = "192.168.1.11" # IP address of the STA in the LVAP tuple. It only works for a single client without DHCP
STA_MAC = "74:F0:6D:20:D4:74" # MAC address of the STA in the LVAP tuple. It only works for a single client without DHCP
NETWORK_INTERFACE_NAMES = "mon" # beginning of the network interface names in monitor mode. e.g. mon
TAP_INTERFACE_NAME = "ap" # name of the TAP device that Click will create in the Access Point
STA_IP = "192.168.1.11" # IP address of the STA in the LVAP tuple. It is only necessary for a single client without DHCP
STA_MAC = "74:F0:6D:20:D4:74" # MAC address of the STA in the LVAP tuple. It is only necessary for a single client without DHCP

print '''
// This is the scheme:
Expand All @@ -78,17 +87,15 @@
// | ^ | ^
// to device | | | | to device
// V | V |
// 'mon0' 'mon1' interfaces in the machine that runs Click. Must be in monitor mode
//
'''
// 'mon0' 'mon1' interfaces in the machine that runs Click. They must be in monitor mode
//'''

print '''
// call OdinAgent::configure to create and configure an Odin agent:
odinagent::OdinAgent(HWADDR %s, RT rates, CHANNEL %s, DEFAULT_GW %s, DEBUGFS %s, SSIDAGENT %s, DEBUG_ODIN %s, TX_RATE %s, TX_POWER %s, HIDDEN %s)
''' % (AP_UNIQUE_BSSID, AP_CHANNEL, DEFAULT_GW, DEBUGFS_FILE, SSIDAGENT, DEBUG_ODIN, TX_RATE, TX_POWER, HIDDEN )
odinagent::OdinAgent(HWADDR %s, RT rates, CHANNEL %s, DEFAULT_GW %s, DEBUGFS %s, SSIDAGENT %s, DEBUG_ODIN %s, TX_RATE %s, TX_POWER %s, HIDDEN %s, MULTICHANNEL_AGENTS %s, DEFAULT_BEACON_INTERVAL %s, BURST_BEACON_INTERVAL %s, MEASUREMENT_BEACON_INTERVAL %s)
''' % (AP_UNIQUE_BSSID, AP_CHANNEL, DEFAULT_GW, DEBUGFS_FILE, SSIDAGENT, DEBUG_ODIN, TX_RATE, TX_POWER, HIDDEN, MULTICHANNEL_AGENTS, DEFAULT_BEACON_INTERVAL, BURST_BEACON_INTERVAL, MEASUREMENT_BEACON_INTERVAL)

print '''
// send a ping to odinsocket every 2 seconds
print '''// send a ping to odinsocket every 2 seconds
TimedSource(2, "ping\n")-> odinsocket::Socket(UDP, %s, %s, CLIENT true)
''' % (ODIN_MASTER_IP, ODIN_MASTER_PORT)

Expand All @@ -110,10 +117,9 @@
#of router chatter traffic. The "server" (that is, the ChatterSocket element)
#simply echoes any messages generated by the router configuration to any
#existing clients.
print '''
// output 3 of odinagent goes to odinsocket
print '''// output 3 of odinagent goes to odinsocket
odinagent[3] -> odinsocket
rates :: AvailableRates(DEFAULT 12 18 24 36 48 72 96 108); // wifi rates in multiples of 500kbps
rates :: AvailableRates(DEFAULT 12 18 24 36 48 72 96 108); // wifi rates in multiples of 500kbps. This will be announced in the beacons sent by the AP
control :: ControlSocket("TCP", 6777);
chatter :: ChatterSocket("TCP", 6778);
'''
Expand Down Expand Up @@ -161,17 +167,31 @@
print ''' -> [1]odinagent'''

print '''
// create a queue and connect it to SetTXRate-RadiotapEncap and send it to the network interface
// create a queue 'q' for transmission of packets by the primary interface (mon0) and connect it to SetTXRate-RadiotapEncap
q :: Queue(%s)
-> SetTXRate (%s) // e.g. if it is 108, this means 54Mbps=108*500kbps
-> RadiotapEncap()
-> to_dev :: ToDevice (%s0);
''' % (QUEUE_SIZE, TX_RATE, NETWORK_INTERFACE_NAMES )


print ''' odinagent[2]
-> q'''



print '''
// create a queue 'q2' for transmission of packets by the secondary interface (mon1) and connect it to SetTXRate-RadiotapEncap
q2 :: Queue(%s)
-> SetTXRate (%s) // e.g. if it is 108, this means 54Mbps=108*500kbps
-> RadiotapEncap()
-> to_dev2 :: ToDevice (%s1);
''' % (QUEUE_SIZE, TX_RATE, NETWORK_INTERFACE_NAMES )

print '''
odinagent[2]
-> q
'''
odinagent[4]
-> q2'''


print '''
// ----------------Packets coming up (from the STA to the AP) go to the input 0 of the Odin Agent
Expand All @@ -182,8 +202,7 @@
-> tx_filter :: FilterTX()
-> dupe :: WifiDupeFilter() // Filters out duplicate 802.11 packets based on their sequence number
// click/elements/wifi/wifidupefilter.hh
-> [0]odinagent
''' % ( NETWORK_INTERFACE_NAMES )
-> [0]odinagent''' % ( NETWORK_INTERFACE_NAMES )

print '''
// ----------------Packets coming up (from the STA to the AP) go to the input 0 of the Odin Agent
Expand All @@ -194,13 +213,10 @@
-> tx_filter1 :: FilterTX()
-> dupe1 :: WifiDupeFilter() // Filters out duplicate 802.11 packets based on their sequence number
// click/elements/wifi/wifidupefilter.hh
-> [2]odinagent
''' % ( NETWORK_INTERFACE_NAMES )
-> [2]odinagent''' % ( NETWORK_INTERFACE_NAMES )

print '''
odinagent[0]
-> q
'''
print '''odinagent[0]
-> q'''

print '''
// Data frames
Expand Down Expand Up @@ -249,4 +265,4 @@
if (DEBUG_CLICK > 0):
print ''' -> Print("[Click] ARP Fast path fail")'''

print ''' -> ToHost(%s)''' % ( TAP_INTERFACE_NAME )
print ''' -> ToHost(%s)''' % ( TAP_INTERFACE_NAME )
Binary file added click_binary_file/click-align_for_AR71xx
Binary file not shown.
Binary file added click_binary_file/click_for_AR71xx
Binary file not shown.
19 changes: 19 additions & 0 deletions scripts_start_ap_odin/check-ovs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# This script gives periodical information about the status of the OpenVSwitch bridge br0
# It is useful for debugging purposes

while :
do
echo "Testing: ovs-vsctl show"
ovs-vsctl show
echo " "
echo "Testing: ovs-ofctl dump-flows br0"
ovs-ofctl dump-flows br0
echo " "
echo "Testing: ovs-ofctl dump-ports br0"
ovs-ofctl dump-ports br0
echo " "
echo "Please type ^C to quit"
sleep 1
done
99 changes: 67 additions & 32 deletions scripts_start_ap_odin/start.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,57 @@
#!/bin/sh

# In order to adapt this script to your setup, you must:
# - modify the IP address of the controller (CTLIP)
# - adapt the names of your wireless devices: wlan0-phy0-mon0; wlan1-phy1-mon1
# - add some routes if you need them (route add)
# - mount the USB (or not) if you need (or not) to use some files from it
# - modify the name and the route of the .cli script to be used
# - modify the port used by OpenFlow (6633 by default)

# The order is:
# 1.- Launch this script in all the APs. You will see a message "Now you can launch the controller and press Enter"
# 2.- Launch the Wi-5 odin controller
# 3.- Press ENTER on each of the APs

## Variables
echo "Setting variables"
CTLIP=192.168.1.129 # Controller IP
SW=br0
DPPORTS="eth1.2" # Ports for data plane
VSCTL="ovs-vsctl"
CTLIP=192.168.1.129 # Controller IP address
SW=br0 # Name of the bridge
DPPORTS="eth1.2" # Port for data plane
VSCTL="ovs-vsctl" # Command to be used to invoke openvswitch

## Setting interfaces
echo "Setting interfaces"
ifconfig wlan0 down
ifconfig wlan1 down
iw phy phy0 interface add mon0 type monitor
iw phy phy1 interface add mon1 type monitor
iw phy phy0 set retry short 4
#iw dev wlan0 set channel 1
ifconfig mon0 up
ifconfig mon1 up
ifconfig mon0 mtu 1532
ifconfig mon1 mtu 1532
ifconfig wlan0 up
ifconfig wlan1 up
# add this route in order to permit control from Unizar networks

## Routes
# add these routes in order to permit control from other networks (this is very particular of Unizar)
# 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

## Mount USB
echo "Mounting USB"
if [ ! -d "/mnt/usb" ]; then
mkdir -p /mnt/usb
fi
mount /dev/sda1 /mnt/usb/

## OVS
echo "Restarting OpenvSwitch"
/etc/init.d/openvswitch stop
sleep 1
echo "Cleaning DB"
# The next line is added in order to start the controller after stopping openvswitch
read -p "Now you can launch the Wi-5 odin controller and press Enter" pause

# Clean the OpenVSwitch database
echo "Cleaning OpenVSwitch database"
if [ -d "/etc/openvswitch" ]; then
rm -r /etc/openvswitch
fi
Expand All @@ -51,31 +64,53 @@ fi
if [ -f "/var/run/ovs-vswitchd.pid" ]; then
rm /var/run/ovs-vswitchd.pid
fi
echo "Lanching OVS"

# Launch OpenVSwitch
echo "Launching OpenVSwitch"
/etc/init.d/openvswitch start
$VSCTL add-br $SW # Create the bridge

# Create the bridge
$VSCTL add-br $SW
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

# Configure the OpenFlow Controller
$VSCTL set-controller $SW tcp:$CTLIP:6633

# Add the data plane ports to OpenVSwitch
for i in $DPPORTS ; do
PORT=$i
ifconfig $PORT up
$VSCTL add-port $SW $PORT
done

## Launch click
echo "Lanching Click"
sleep 3
echo "Launching Click"

# Mount USB if you need it for putting the Click ('click') and Click-align ('click-al') binaries
echo "Mounting USB"
if [ ! -d "/mnt/usb" ]; then
mkdir -p /mnt/usb
fi
mount /dev/sda1 /mnt/usb/

cd /mnt/usb
./click < click-al agent.cli & # This makes the alignment and calls Click at the same time
#./click aagent.cli & # Old command, which required an aligned version of the .cli file
sleep 1
./click aagent9.cli &
sleep 1
# Add ap to OVS
echo "Adding Click interface to OVS"
ifconfig ap up # Adding ap interface (click Interface) to OVS
$VSCTL add-port $SW ap
# From this moment, a new tap interface called 'ap' will be created by Click

# Add the 'ap' interface to OpenVSwitch
echo "Adding Click interface 'ap' to OVS"
ifconfig ap up # Putting the interface 'ap' up
$VSCTL add-port $SW ap # Adding 'ap' interface (click Interface) to OVS
sleep 1

## OVS Rules
# DHCP rules needed by odin-wi5 controller
## OpenVSwitch Rules
# OpenFlow rules needed to make it possible for DHCP traffic to arrive to the Wi-5 odin controller
# It may happen that 'eth1.2' is port 1 and 'ap' is port 2
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

# It may happen that 'eth1.2' is port 2 and 'ap' is port 1
ovs-ofctl add-flow br0 in_port=1,dl_type=0x0800,nw_proto=17,tp_dst=67,actions=output:2,CONTROLLER
ovs-ofctl add-flow br0 in_port=2,dl_type=0x0800,nw_proto=17,tp_dst=68,actions=output:CONTROLLER,1
Loading

0 comments on commit 65f0e28

Please sign in to comment.