From 88d7217018ee44bd41c95f169a1a0fb5ed744661 Mon Sep 17 00:00:00 2001 From: Davide Sanvito Date: Tue, 15 Nov 2016 09:40:52 -0800 Subject: [PATCH 1/2] Tests now use Mininet's BEBA node with max verbosity --- ryu/app/beba/test/InSP__ryu.py | 3 +- ryu/app/beba/test/beba.py | 44 +++++++++++++++++++ ryu/app/beba/test/ddos.py | 3 +- .../beba/test/experimenter_error_msg__ryu.py | 6 ++- .../test/forwarding_consistency_1_to_many.py | 3 +- ryu/app/beba/test/maclearning.py | 3 +- ryu/app/beba/test/portknocking.py | 3 +- ryu/app/beba/test/run_all.sh | 8 ++++ 8 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 ryu/app/beba/test/beba.py diff --git a/ryu/app/beba/test/InSP__ryu.py b/ryu/app/beba/test/InSP__ryu.py index fc183a611..dadb4f48b 100644 --- a/ryu/app/beba/test/InSP__ryu.py +++ b/ryu/app/beba/test/InSP__ryu.py @@ -16,6 +16,7 @@ from ryu.lib.packet import packet from ryu.lib.packet import ethernet from ryu.lib.packet import ether_types +from beba import BebaSwitchDbg LOG = logging.getLogger('app.beba.pkttmp') @@ -28,7 +29,7 @@ def __init__(self, *args, **kwargs): # Kill Mininet os.system("sudo mn -c 2> /dev/null") print 'Starting Mininet' - self.net = Mininet(topo=SingleSwitchTopo(2),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) + self.net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) self.net.start() self.test_id = 0 diff --git a/ryu/app/beba/test/beba.py b/ryu/app/beba/test/beba.py new file mode 100644 index 000000000..6f43086c5 --- /dev/null +++ b/ryu/app/beba/test/beba.py @@ -0,0 +1,44 @@ +""" +Custom BEBA node + +This script enables/disables switch max verbosity and debugging with Valgrind via Mininet CLI parameters. +(NB Mininet's verbosity is not affected and can be configured via --verbosity/-v parameter) + +The following command starts Mininet with minimum verbosity level (it's equivalent to --switch user) +sudo mn --topo single,4 --controller remote --mac --arp --custom beba.py --switch beba + +The following command starts Mininet with Valgrind and maximum verbosity level +sudo mn --topo single,4 --controller remote --mac --arp --custom beba.py --switch beba_dbg +""" + +from mininet.node import UserSwitch + +class BebaSwitchDbg( UserSwitch ): + def start( self, controllers ): + """Start OpenFlow reference user datapath. + Log to /tmp/sN-{ofd,ofp}.log. + controllers: list of controller objects""" + # Add controllers + clist = ','.join( [ 'tcp:%s:%d' % ( c.IP(), c.port ) + for c in controllers ] ) + ofdlog = '/tmp/' + self.name + '-ofd.log' + ofplog = '/tmp/' + self.name + '-ofp.log' + intfs = [ str( i ) for i in self.intfList() if not i.IP() ] + + print '[\x1b[31mVALGRIND\x1b[0m]' + self.cmd( 'valgrind --leak-check=full --show-leak-kinds=all --trace-children=yes --track-origins=yes ofdatapath -v -i ' + ','.join( intfs ) + + ' punix:/tmp/' + self.name + ' -d %s ' % self.dpid + + self.dpopts + + ' 1> ' + ofdlog + ' 2> ' + ofdlog + ' &' ) + self.cmd( 'ofprotocol unix:/tmp/' + self.name + + ' ' + clist + + ' --fail=closed ' + self.opts + + ' 1> ' + ofplog + ' 2>' + ofplog + ' &' ) + if "no-slicing" not in self.dpopts: + # Only TCReapply if slicing is enable + sleep(1) # Allow ofdatapath to start before re-arranging qdisc's + for intf in self.intfList(): + if not intf.IP(): + self.TCReapply( intf ) + +switches = {'beba':UserSwitch , 'beba_dbg':BebaSwitchDbg} diff --git a/ryu/app/beba/test/ddos.py b/ryu/app/beba/test/ddos.py index b7c02038c..c49a7cea1 100644 --- a/ryu/app/beba/test/ddos.py +++ b/ryu/app/beba/test/ddos.py @@ -6,6 +6,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm +from beba import BebaSwitchDbg if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -34,7 +35,7 @@ def wait_for_connection_expiration(max_time=5): os.system('ryu-manager ../ddos/ddos.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(2),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) +net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) net.start() time.sleep(3) diff --git a/ryu/app/beba/test/experimenter_error_msg__ryu.py b/ryu/app/beba/test/experimenter_error_msg__ryu.py index 3145c3c88..56c9a6980 100644 --- a/ryu/app/beba/test/experimenter_error_msg__ryu.py +++ b/ryu/app/beba/test/experimenter_error_msg__ryu.py @@ -30,6 +30,7 @@ import os,subprocess,time,sys from ryu.ofproto.ofproto_common import BEBA_EXPERIMENTER_ID import struct +from beba import BebaSwitchDbg class BebaErrorExperimenterMsg(app_manager.RyuApp): @@ -40,7 +41,7 @@ def __init__(self, *args, **kwargs): # Kill Mininet os.system("sudo mn -c 2> /dev/null") print 'Starting Mininet' - self.net = Mininet(topo=SingleSwitchTopo(7),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) + self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) self.net.start() self.last_error_queue = [] self.test_id = 0 @@ -818,5 +819,6 @@ def stop_test_and_gracefully_exit(self): def restart_mininet(self): print 'Restarting Mininet\n' os.system("sudo mn -c 2> /dev/null") - self.net = Mininet(topo=SingleSwitchTopo(7),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) + self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) self.net.start() + diff --git a/ryu/app/beba/test/forwarding_consistency_1_to_many.py b/ryu/app/beba/test/forwarding_consistency_1_to_many.py index dbda688bb..87470954b 100644 --- a/ryu/app/beba/test/forwarding_consistency_1_to_many.py +++ b/ryu/app/beba/test/forwarding_consistency_1_to_many.py @@ -6,6 +6,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm +from beba import BebaSwitchDbg if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -18,7 +19,7 @@ os.system('ryu-manager ../forwarding_consistency_1_to_many.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(4),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) +net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) net.start() time.sleep(5) diff --git a/ryu/app/beba/test/maclearning.py b/ryu/app/beba/test/maclearning.py index c92f44a3f..9307aa58c 100644 --- a/ryu/app/beba/test/maclearning.py +++ b/ryu/app/beba/test/maclearning.py @@ -5,6 +5,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm +from beba import BebaSwitchDbg if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -17,7 +18,7 @@ os.system('ryu-manager ../maclearning.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(4),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) +net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) net.start() time.sleep(6) diff --git a/ryu/app/beba/test/portknocking.py b/ryu/app/beba/test/portknocking.py index 822897e9d..e579758d9 100644 --- a/ryu/app/beba/test/portknocking.py +++ b/ryu/app/beba/test/portknocking.py @@ -5,6 +5,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm +from beba import BebaSwitchDbg if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -17,7 +18,7 @@ os.system('ryu-manager ../portknock.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(2),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) +net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) net.start() time.sleep(5) diff --git a/ryu/app/beba/test/run_all.sh b/ryu/app/beba/test/run_all.sh index 547bcd5a6..7fc1312bd 100755 --- a/ryu/app/beba/test/run_all.sh +++ b/ryu/app/beba/test/run_all.sh @@ -6,6 +6,10 @@ do then continue fi + if [ "$f" == "beba.py" ] + then + continue + fi echo -e "\n\x1b[33m[Testing $f]\x1b[0m"; sudo python $f; ret_values[$f]=$?; @@ -26,6 +30,10 @@ do then continue fi + if [ "$f" == "beba.py" ] + then + continue + fi if [[ ${ret_values[$f]} -eq 1 ]]; then echo -e "$f: \x1b[31mFAILED\x1b[0m"; else From 7aadd3d4b3ac69d1d333824209eefdea45ea8fe4 Mon Sep 17 00:00:00 2001 From: Davide Sanvito Date: Mon, 12 Dec 2016 12:55:55 -0800 Subject: [PATCH 2/2] Added custom BEBA host --- ryu/app/beba/test/InSP__ryu.py | 6 ++--- ryu/app/beba/test/beba.py | 26 +++++++++++++++++-- ryu/app/beba/test/ddos.py | 4 +-- .../beba/test/experimenter_error_msg__ryu.py | 6 ++--- .../test/forwarding_consistency_1_to_many.py | 4 +-- ryu/app/beba/test/maclearning.py | 4 +-- ryu/app/beba/test/portknocking.py | 4 +-- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/ryu/app/beba/test/InSP__ryu.py b/ryu/app/beba/test/InSP__ryu.py index dadb4f48b..b2692092c 100644 --- a/ryu/app/beba/test/InSP__ryu.py +++ b/ryu/app/beba/test/InSP__ryu.py @@ -16,7 +16,7 @@ from ryu.lib.packet import packet from ryu.lib.packet import ethernet from ryu.lib.packet import ether_types -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost LOG = logging.getLogger('app.beba.pkttmp') @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs): # Kill Mininet os.system("sudo mn -c 2> /dev/null") print 'Starting Mininet' - self.net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) + self.net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) self.net.start() self.test_id = 0 @@ -155,7 +155,7 @@ def _monitor1(self,datapath): def restart_mininet(self): print 'Restarting Mininet\n' os.system("sudo mn -c 2> /dev/null") - self.net = Mininet(topo=SingleSwitchTopo(2),switch=UserSwitch,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) + self.net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=False) self.net.start() def stop_test_and_gracefully_exit(self): diff --git a/ryu/app/beba/test/beba.py b/ryu/app/beba/test/beba.py index 6f43086c5..d346fdf06 100644 --- a/ryu/app/beba/test/beba.py +++ b/ryu/app/beba/test/beba.py @@ -1,5 +1,5 @@ """ -Custom BEBA node +Custom BEBA node and host This script enables/disables switch max verbosity and debugging with Valgrind via Mininet CLI parameters. (NB Mininet's verbosity is not affected and can be configured via --verbosity/-v parameter) @@ -9,9 +9,29 @@ The following command starts Mininet with Valgrind and maximum verbosity level sudo mn --topo single,4 --controller remote --mac --arp --custom beba.py --switch beba_dbg + +By adding the '--host=beba' option, it is possible to disable the Checksum Offloading for all the hosts +to solve some issues in ofsoftswitch13 checksum correctness. """ -from mininet.node import UserSwitch +from mininet.node import UserSwitch, Host + +class BebaHost(Host): + def config(self, **params): + r = super(Host, self).config(**params) + + self.defaultIntf().rename("eth0") + + for off in ["rx", "tx", "sg"]: + cmd = "/sbin/ethtool --offload eth0 %s off" % off + self.cmd(cmd) + + # disable IPv6 + self.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") + self.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") + self.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") + + return r class BebaSwitchDbg( UserSwitch ): def start( self, controllers ): @@ -42,3 +62,5 @@ def start( self, controllers ): self.TCReapply( intf ) switches = {'beba':UserSwitch , 'beba_dbg':BebaSwitchDbg} + +hosts = {'beba':BebaHost} diff --git a/ryu/app/beba/test/ddos.py b/ryu/app/beba/test/ddos.py index c49a7cea1..a9723fc2c 100644 --- a/ryu/app/beba/test/ddos.py +++ b/ryu/app/beba/test/ddos.py @@ -6,7 +6,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -35,7 +35,7 @@ def wait_for_connection_expiration(max_time=5): os.system('ryu-manager ../ddos/ddos.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) +net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) net.start() time.sleep(3) diff --git a/ryu/app/beba/test/experimenter_error_msg__ryu.py b/ryu/app/beba/test/experimenter_error_msg__ryu.py index 56c9a6980..d09e8b024 100644 --- a/ryu/app/beba/test/experimenter_error_msg__ryu.py +++ b/ryu/app/beba/test/experimenter_error_msg__ryu.py @@ -30,7 +30,7 @@ import os,subprocess,time,sys from ryu.ofproto.ofproto_common import BEBA_EXPERIMENTER_ID import struct -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost class BebaErrorExperimenterMsg(app_manager.RyuApp): @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs): # Kill Mininet os.system("sudo mn -c 2> /dev/null") print 'Starting Mininet' - self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) + self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) self.net.start() self.last_error_queue = [] self.test_id = 0 @@ -819,6 +819,6 @@ def stop_test_and_gracefully_exit(self): def restart_mininet(self): print 'Restarting Mininet\n' os.system("sudo mn -c 2> /dev/null") - self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) + self.net = Mininet(topo=SingleSwitchTopo(7),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) self.net.start() diff --git a/ryu/app/beba/test/forwarding_consistency_1_to_many.py b/ryu/app/beba/test/forwarding_consistency_1_to_many.py index 87470954b..2e881a393 100644 --- a/ryu/app/beba/test/forwarding_consistency_1_to_many.py +++ b/ryu/app/beba/test/forwarding_consistency_1_to_many.py @@ -6,7 +6,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -19,7 +19,7 @@ os.system('ryu-manager ../forwarding_consistency_1_to_many.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) +net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) net.start() time.sleep(5) diff --git a/ryu/app/beba/test/maclearning.py b/ryu/app/beba/test/maclearning.py index 9307aa58c..3f69bd1df 100644 --- a/ryu/app/beba/test/maclearning.py +++ b/ryu/app/beba/test/maclearning.py @@ -5,7 +5,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -18,7 +18,7 @@ os.system('ryu-manager ../maclearning.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) +net = Mininet(topo=SingleSwitchTopo(4),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634,autoStaticArp=True) net.start() time.sleep(6) diff --git a/ryu/app/beba/test/portknocking.py b/ryu/app/beba/test/portknocking.py index e579758d9..105c6422b 100644 --- a/ryu/app/beba/test/portknocking.py +++ b/ryu/app/beba/test/portknocking.py @@ -5,7 +5,7 @@ from mininet.topo import SingleSwitchTopo from mininet.node import UserSwitch,RemoteController from mininet.term import makeTerm -from beba import BebaSwitchDbg +from beba import BebaSwitchDbg,BebaHost if os.geteuid() != 0: exit("You need to have root privileges to run this script") @@ -18,7 +18,7 @@ os.system('ryu-manager ../portknock.py 2> /dev/null &') print 'Starting Mininet' -net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) +net = Mininet(topo=SingleSwitchTopo(2),switch=BebaSwitchDbg,host=BebaHost,controller=RemoteController,cleanup=True,autoSetMacs=True,listenPort=6634) net.start() time.sleep(5)