test cases added for whitelisting and specific traffic filter tap test scripts

parent d22515a6
......@@ -223,7 +223,7 @@ def start_deidtect_server(port):
print "Server : DEIDtect Core Stopped"
def deidtectScaling(dic, start_response, environ):
print "got whitelist route update"
print "got scaling cpu usage update"
print dic
usage = dic.get('usage',None)
......@@ -238,6 +238,8 @@ def deidtectScaling(dic, start_response, environ):
if usageData > 75:
responseData = 'cluster'
print "Sending to set the state to %s" % responseData
return sendText(start_response, responseData);
def deidtectWhitelist(dic, start_response, environ):
......
......@@ -31,7 +31,7 @@ def sendOK(start_response, msg=None):
start_response("200 OK", [('Content-type', 'text/plain')])
if msg is None:
return ['OK']
else
else:
return [msg]
def sendError(start_response):
......@@ -158,7 +158,7 @@ def actionIDS(start_response, cmd, name, vlan, tunid, switchid=None, ryuip=None,
r = requests.get(computeurl)
print r.status_code
if cmd ="add":
if cmd =="add":
floating_ip = ids.addresses['test-net-1'][1]['addr']
return sendOK(start_response, floating_ip);
return sendOK(start_response);
......
......@@ -2,7 +2,7 @@
csv_input=$1
declare -a arr=("s1-eth1" "s1-eth3" "s2-eth1" "s2-eth2" "s2-eth3" "s3-eth2")
declare -a arr=("s1-eth1" "s1-eth2" "s1-eth3" "s2-eth1" "s2-eth2" "s2-eth3" "s3-eth2")
start_timestamp=`head -1 $csv_input | cut -d',' -f1`
export start_timestamp
......
......@@ -34,7 +34,7 @@ def parseOptions():
parser.add_option( '-r', '--runs', dest='runs',
type='int', default=1, help='specify number of runs of each test' )
parser.add_option( '-b', '--bw', dest='bw',
type='int', default=0, help='use bandwidth limiting' )
type='int', default=5, help='use bandwidth limiting' )
parser.add_option( '-c', '--cip', dest='cip',
type='string', default="localhost", help='controller IP' )
parser.add_option( '-p', '--cpu', dest='cpu',
......@@ -46,6 +46,8 @@ def parseOptions():
type='int', default=30, help='duration for which to run the experiment' )
parser.add_option( '-q', '--queue', dest='queue',
type='int', default=100, help='set switch buffer sizes' )
parser.add_option( '-m', '--mode', dest='mode',
type='string', default="all", help='set type of tap traffic to moniotor' )
( options, args ) = parser.parse_args()
return options, args
......@@ -86,7 +88,7 @@ def bandwidthTopo(bw, controllerip):
# Add links
srcLink( attacker, topSwitch )
otherLink( topSwitch, brosys )
srcLink( topSwitch, brosys )
otherLink( topSwitch, bottomSwitch)
otherLink( bottomSwitch, brosys2 )
otherLink( bottomSwitch, lvl2Switch )
......@@ -149,6 +151,10 @@ def bandwidthTest(bw=5, controllerip="localhost"):
h1 = net.getNodeByName('h1')
print h1.name
h2 = net.getNodeByName('h2')
print h2.name
h3 = net.getNodeByName('h3')
print h3.name
......@@ -170,9 +176,13 @@ def bandwidthTest(bw=5, controllerip="localhost"):
#CLI(net)
#start the traffic generation wait for 5 seconds (H1->H3)
tg_cmd = 'mz h1-eth0 -c 0 -t udp sp=49 -A 10.0.0.1 -B 10.0.0.3 -P \"Hello World\" &'
h1_tg_cmd = 'mz h1-eth0 -c 0 -t udp sp=49 -A 10.0.0.1 -B 10.0.0.3 -P \"H1 Hello World\" &'
h2_tg_cmd = 'mz h2-eth0 -c 0 -t tcp dp=80 -A 10.0.0.2 -B 10.0.0.3 -P \"H2 Hello World\" &'
print "Traffic generation from H1 started"
h1.cmd(tg_cmd)
h1.cmd(h1_tg_cmd)
if opts.mode != "all":
h2.cmd(h2_tg_cmd);
sleep_time = 20
print "Sleeping for %d seconds before TAP is applied" % sleep_time
......@@ -180,12 +190,29 @@ def bandwidthTest(bw=5, controllerip="localhost"):
#create the tap for s2-port(3)
#wait for 2 minutes for the rate-limiter to grow
p = Popen("./bwTestTapFlow.sh", shell=True)
sleep_time = 360
if opts.mode == "tcp":
print "Tap created for TCP traffic"
scriptName = "./bwTestTCPTapFlow.sh"
elif opts.mode == "udp":
print "Tap created for UDP traffic"
scriptName = "./bwTestUDPTapFlow.sh"
else:
print "Tap created for all traffic"
scriptName = "./bwTestTapFlow.sh"
p = Popen(scriptName, shell=True)
sleep_time = 150
i = 10;
while ( i < sleep_time):
print s1.cmd('dpctl unix:/tmp/s1 meter-config')
if opts.mode == "all":
print s1.cmd('dpctl unix:/tmp/s1 meter-config')
else:
print s1.cmd('dpctl unix:/tmp/s2 meter-config')
if sleep_time == 50:
print "Stop TCP traffic alone @50s"
h2.cmd("killall mz")
h1.cmd(h1_tg_cmd)
#print s1.cmd('dpctl unix:/tmp/s1 stats-meter')
print "[%d] Sleeping for %d seconds for rate-limiters to grow" \
%( sleep_time/i, i)
......@@ -196,6 +223,9 @@ def bandwidthTest(bw=5, controllerip="localhost"):
#stop the traffic generation
h1.cmd('killall mz')
if opts.mode != "all":
h2.cmd('killall mz')
print "Stopped traffic generation"
#generate the graph
......
#!/bin/sh -x
HOST="localhost"
CMD="add"
TAPID=3
curl -d "{\
'dpid':'0000000000000002',\
'output':2,\
'vlan_id':100,\
'traffic':'tcp',\
'tapID': $TAPID \
}" http://$HOST:8080/policy/tap/e2etunnel/{$CMD}
#!/bin/sh -x
HOST="localhost"
if [ $# -eq 1 ]
then
HOST="$1";
else
HOST="localhost"
fi
CMD="add"
TAPID=3
curl -d "{\
......
#!/bin/sh -x
HOST="localhost"
CMD="add"
TAPID=3
curl -d "{\
'dpid':'0000000000000002',\
'output':2,\
'vlan_id':100,\
'traffic':'udp',\
'tapID': $TAPID \
}" http://$HOST:8080/policy/tap/e2etunnel/{$CMD}
#!/bin/bash -x
echo "Running TCP tap test"
python bw-test.py -m tcp
cp -rv result/bw/5 result/tcpbw/
echo "Running UDP tap test"
python bw-test.py -m udp
cp -rv result/bw/5 result/udpbw/
<?xml version="1.0"?>
<data>
<switch>
<name>switcha</name>
<dpid>0000000000000001</dpid>
</switch>
<switch>
<name>switchb</name>
<dpid>0000000000000002</dpid>
</switch>
<switch>
<name>switchc</name>
<dpid>0000000000000003</dpid>
</switch>
<links>
<src>0000000000000001</src>
<dst>0000000000000002</dst>
<port>3</port>
<emulabvlan>369</emulabvlan>
</links>
<links>
<src>0000000000000002</src>
<dst>0000000000000001</dst>
<port>1</port>
<emulabvlan>369</emulabvlan>
</links>
<links>
<src>0000000000000002</src>
<dst>0000000000000003</dst>
<port>3</port>
<emulabvlan>368</emulabvlan>
</links>
<links>
<src>0000000000000003</src>
<dst>0000000000000002</dst>
<port>1</port>
<emulabvlan>368</emulabvlan>
</links>
<host>
<name>h1</name>
<mac>00:00:00:00:00:21</mac>
<switch>0000000000000001</switch>
<port>1</port>
<emulabvlan>366</emulabvlan>
</host>
<host>
<name>h2</name>
<mac>00:00:00:00:00:22</mac>
<switch>0000000000000001</switch>
<port>2</port>
<emulabvlan>370</emulabvlan>
</host>
<host>
<name>h3</name>
<mac>00:00:00:00:00:23</mac>
<switch>0000000000000002</switch>
<port>2</port>
<emulabvlan>367</emulabvlan>
</host>
<localcloudgateway>
<name>switchc</name>
<switchdpid>0000000000000003</switchdpid>
<outport>2</outport>
<emulabvlan>371</emulabvlan>
</localcloudgateway>
</data>
#!/usr/bin/python
"""
Run deidtect to study the bandwdith sharing behaviour between
service traffic and tap traffic going through a common port.
Praveen Kumar Shanmugam
"""
import sys
sys.path = ['../'] + sys.path
import os
import random
import json
from time import sleep
from optparse import OptionParser
from subprocess import Popen, PIPE
import multiprocessing
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, UserSwitch, CPULimitedHost
from mininet.link import TCLink, Intf
from mininet.cli import CLI
from mininet.log import setLogLevel, info, warn, error, debug
from mininet.util import custom, quietRun, run
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
#Parse command line options and dump results
def parseOptions():
"Parse command line options"
parser = OptionParser()
parser.add_option( '-i', '--infile', dest='infile',
default=None, help='traffic gen input file' )
parser.add_option( '-r', '--runs', dest='runs',
type='int', default=1, help='specify number of runs of each test' )
parser.add_option( '-b', '--bw', dest='bw',
type='int', default=0, help='use bandwidth limiting' )
parser.add_option( '-c', '--cip', dest='cip',
type='string', default="localhost", help='controller IP' )
parser.add_option( '-p', '--cpu', dest='cpu',
type='float', default=-1, help='cpu fraction to allocate to each host' )
parser.add_option( '-s', '--static', dest='static',
default=False, action='store_true',
help='statically allocate CPU to each host' )
parser.add_option( '-t', '--time', dest='time',
type='int', default=30, help='duration for which to run the experiment' )
parser.add_option( '-q', '--queue', dest='queue',
type='int', default=100, help='set switch buffer sizes' )
( options, args ) = parser.parse_args()
return options, args
opts, args = parseOptions()
def clean():
'''Clean any running instance of mininet and ryu'''
p = Popen("ps aux | grep 'ryu' | awk '{print $2}'",
stdout=PIPE, shell=True)
p.wait()
procs = (p.communicate()[0]).split('\n')
for pid in procs:
try:
pid = int(pid)
Popen('kill %d' % pid, shell=True).wait()
except:
pass
os.system('sudo mn -c')
#Creat a topology with 10 Mbs links except the one with the src host
#connected to the network, configure that with bw
def bandwidthTopo(bw, controllerip):
net = Mininet(controller=RemoteController, switch=UserSwitch)
c0 = net.addController('c0', ip=controllerip, port=6633 )
srcLink = custom(TCLink, bw=bw)
otherLink = custom(TCLink, bw=10)
"Create custom topo."
attacker = net.addHost( 'h1', mac='00:00:00:00:00:21')
brosys = net.addHost( 'h2', mac='00:00:00:00:00:22')
brosys2 = net.addHost( 'h3', mac='00:00:00:00:00:23')
topSwitch = net.addSwitch( 's1' )
bottomSwitch = net.addSwitch( 's2' )
lvl2Switch = net.addSwitch( 's3' )
# Add links
srcLink( attacker, topSwitch )
srcLink( topSwitch, brosys )
otherLink( topSwitch, bottomSwitch)
otherLink( bottomSwitch, brosys2 )
otherLink( bottomSwitch, lvl2Switch )
intf = Intf('s3-eth2', node=lvl2Switch)
net.build()
c0.start()
topSwitch.start([c0])
bottomSwitch.start([c0])
lvl2Switch.start([c0])
ryu_c = Popen("./ryu_init.sh %s %d 1> ryu.out 2> /tmp/ryu.out" % (controllerip, 3), shell=True)
print "wait 5 sec for controller to connect"
sleep(5)
return net, ryu_c
def hostArray( net ):
"Return array[1..N] of net.hosts"
try:
host_array = sorted(net.hosts, key=lambda x: int(x.name))
except:
host_array = sorted(net.hosts, key=lambda x: x.name)
return host_array
def monitor_devs_ifstat(fname="rate.csv"):
if_cmd = 'ifstat -a -t > %s &' % (fname)
print if_cmd
Popen(if_cmd, shell=True).wait()
def monitor_devs_ng(fname="txrate.csv" , interval_sec=0.01):
"""Uses bwm-ng tool to collect iface tx rate stats. Very reliable."""
cmd = ("sleep 1; bwm-ng -t %s -o csv "
"-u bytes -T rate -C ',' > %s" %
(interval_sec * 1000, fname))
Popen(cmd, shell=True).wait()
def monitorInterfacesInit(net, outfile):
monitors = []
#monitors.append(multiprocessing.Process(target=monitor_devs_ifstat,
# args=("rate.csv",)))
os.system("rm -f %s" % outfile)
monitors.append(multiprocessing.Process(target=monitor_devs_ng,
args=(outfile, 1,)))
return monitors
def bandwidthTest(bw=5, controllerip="localhost"):
print bw
print controllerip
net, ryu_c = bandwidthTopo(bw,controllerip)
hosts = hostArray(net)
#for h in hosts:
# print "Host : %s\n" % (h.name)
h1 = net.getNodeByName('h1')
print h1.name
h2 = net.getNodeByName('h2')
print h2.name
h3 = net.getNodeByName('h3')
print h3.name
s1 = net.getNodeByName('s1')
s1.cmd("ifconfig s1-eth1 mtu 900")
s2 = net.getNodeByName('s2')
s3 = net.getNodeByName('s3')
print s1.name
#populate l3 routes
net.pingAll();
#bandwidth = net.iperf( [ h1, h3], udpBw='%sM' % bw, seconds=5 )
#print bandwidth
outfile="txrate%s.csv" % bw
monitors = monitorInterfacesInit(net,outfile);
for m in monitors:
m.start();
#start the traffic generation wait for 5 seconds (H1->H3)
server_start = 'vsftpd &'
h1_tg_cmd = 'mz h1-eth0 -c 0 -t udp sp=49 -A 10.0.0.1 -B 10.0.0.3 -P \"Hello World\" &'
h2_tg_cmd = 'mz h2-eth0 -c 0 -t udp sp=51 -A 10.0.0.2 -B 10.0.0.3 -P \"Hello World\" &'
print "Traffic generation from H1,H2 -> H3 started"
h1.cmd(h1_tg_cmd)
h2.cmd(h2_tg_cmd)
print "sFTP server started @ H3"
h3.cmd(server_start)
h1.cmd('sudo ethtool -K h1-eth0 tso off')
h1.cmd("ifconfig h1-eth0 mtu 900")
h2.cmd('sudo ethtool -K h2-eth0 tso off')
h2.cmd("ifconfig h2-eth0 mtu 900")
h3.cmd('sudo ethtool -K h3-eth0 tso off')
h3.cmd("ifconfig h3-eth0 mtu 900")
#CLI(net)
sleep_time = 20
print "Sleeping for %d seconds before TAP is applied" % sleep_time
sleep(sleep_time)
p = Popen(("./bwTestTapFlow.sh %s" % controllerip), shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out
print err
print "TAP create complete.."
sleep_time = 40
print "Sleeping for %d seconds before FTP request is sent H1->H3" % sleep_time
sleep(sleep_time)
print "Stop H2 -> H3 traffic"
h2.cmd('killall mz')
print "FTP start.."
h1.cmd("../scripts/testFTP.sh")
print "FTP complete.."
h1.cmd(h1_tg_cmd)
sleep_time = 150
print "Sleep for %d seconds to show the effect of whitelist of H1->H3 [IP]" \
% sleep_time
sleep(sleep_time)
#stop the traffic generation
h1.cmd('killall mz')
h3.cmd('killall vsftpd')
print "Stopped traffic generation"
print "Stopped sFTP server"
#generate the graph
for m in monitors:
m.terminate();
net.stop();
return
def drawGraph(directory, infile):
Popen(("mkdir -p result/bw/%s" % directory), shell=True).wait() ;
Popen(("cp -v ../graphScripts/drawBwGraph.sh drawBwGraph.sh"),
shell=True).wait();
Popen(("cp -v ../graphScripts/gnu_deidtect_bw.scr gnu_deidtect_bw.scr"),
shell=True).wait();
Popen(("./drawBwGraph.sh %s" % infile), shell=True).wait();
Popen(("mv -v *.pdf result/bw/%s/" % directory), shell=True).wait();
Popen(("rm -v drawBwGraph.sh gnu_deidtect_bw.scr"), shell=True).wait();
print "Graph Generated for BW = %d " % directory
def setupGreTunnelPort():
Popen(("./localGreInit.sh"), shell=True).wait();
print "GRE port initialised.."
def DEIDtectBWTest(opts):
bw = opts.bw
controllerip=get_ip_address('eth0')
Popen('cp -vf whitelist-test-input.xml input.xml', shell=True).wait()
print "Rollback to known state"
clean();
setupGreTunnelPort();
bandwidthTest(bw=bw,controllerip=controllerip)
print "Cleanup the process"
clean();
infile="txrate%s.csv" % bw
drawGraph(bw, infile);
if __name__ == '__main__':
#global opts
DEIDtectBWTest(opts);
#!/usr/bin/expect
spawn ftp 10.0.0.3
expect "):"
send "ftp\r"
expect "ftp>"
send "lcd \/tmp\r"
send "get time1.log\r"
send "get time2.log\r"
expect "ftp>"
send "bye\r"
interact
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment