Esempio n. 1
0
    def __init__(self, s=2, ctrl_addr='127.0.0.1:6633'):
	self.log = log
        self.k = s + 1
        self.topo = SingleSwitchTopo(k=self.k)

	ctrl_args = ctrl_addr.split(':')
	ctrl_ip = ctrl_args[0]
	ctrl_port = int(ctrl_args[1]) if len(ctrl_args) > 1 else 6633
	
	if self.log: sys.stderr.write('Starting the Multi-server network for Step-2\n')

	self.net = Mininet(topo=self.topo, controller=lambda x:
		RemoteController(x, ctrl_ip, ctrl_port),
		listenPort=6634, xterms=False, autoSetMacs=True)
        self.servers = [self.net.idToNode[s] for s in range(2, self.k -1 + 2)]
        self.client = self.net.idToNode[1+self.k]
        self.serverIP = '10.0.0.100'
        self.serverIPMask = 8
        for s in self.servers:
            # set server IP
            s.cmd('ifconfig', '%s:%d' % (s.intfs[0], 0), '%s/%d' % (self.serverIP, self.serverIPMask))
            # set static arp in servers for client IP
            s.cmd('arp', '-s', self.client.IP(), self.client.MAC())
            # start web server
	    if self.log: sys.stderr.write('Starting web server on server %s\n' % s.name)
            s.cmd('python', 'httpd.py', '80', '&')
        # set static arp in client for server IP
        self.client.cmd('arp', '-s', self.serverIP, 'FF:FF:FF:FF:FF:FF')
        self.net.start()
        # log server location
        self.log_server_loc('/tmp/server_loc.txt')
	self.log_topology('/tmp/topo.txt')
Esempio n. 2
0
# p4app Driver code, for starting a vanilla topology for debugging
# usage: p4app run AES.p4app
import os
os.environ["GC_INITIAL_HEAP_SIZE"]="20G"
os.environ["GC_MAX_HEAP_SIZE"]="50G"

from p4app import P4Mininet
from mininet.topo import SingleSwitchTopo

topo = SingleSwitchTopo(2)
net = P4Mininet(program='AES.p4', topo=topo)
net.start()

print("Minined started")

from mininet.cli import CLI
CLI(net)
Esempio n. 3
0
from mininet.net import Mininet
from mininet.node import Controller
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel

import os


class POXBridge(Controller):
    "Custom Controller class to invoke POX forwarding.l2_learning"

    def start(self):
        "Start POX learning switch"
        self.pox = '%s/pox/pox.py' % os.environ['HOME']
        self.cmd(self.pox, 'forwarding.l2_learning &')

    def stop(self):
        "Stop POX"
        self.cmd('kill %' + self.pox)


controllers = {'poxbridge': POXBridge}

if __name__ == '__main__':
    setLogLevel('info')
    net = Mininet(topo=SingleSwitchTopo(4), controller=POXBridge)
    net.start()
    net.pingAll()
    net.stop()
Esempio n. 4
0
def testCLI():
    net = alterNet(topo=SingleSwitchTopo())
    net.start()
    alterableCLI(net)
    net.stop()
Esempio n. 5
0
class StandaloneSwitch(OVSSwitch):
    def __init__(self, name, **params):
        OVSSwitch.__init__(self, name, failMode='standalone', **params)
    def start(self, controllers):
        return OVSSwitch.start(self, [ ])

if __name__ == '__main__':
    setLogLevel( 'info' )

    # Create rate limited interface
    intf = custom(TCIntf, bw=50)
    host = custom(CPULimitedHost, sched='cfs', cpu=0.1)

    # Create data network
    net = Mininet(topo=SingleSwitchTopo( k=5 ), switch=OVSSwitch,
            controller=RemoteController, intf=intf, host=host, 
            autoSetMacs=True, autoStaticArp=True,listenPort=6653)

    # Add management network
    s2 = net.addSwitch('s2', cls=StandaloneSwitch)
    for i in range(1, len(net.hosts)+1):
        host = net.get('h'+str(i))
        link = net.addLink(host, s2, intf=Intf)
        link.intf1.setIP('192.168.0.'+str(i), 24)
    gate = Node( 'gate', inNamespace=False )
    link = net.addLink(gate, s2)
    link.intf1.setIP('192.168.0.254', 24)

    # Set controller
    #c0 = RemoteController('c0', ip='127.0.0.1', port=6633)
Esempio n. 6
0
from mininet.log import setLogLevel, info
from mininet.net import Mininet
from mininet.topolib import TreeTopo
from mininet.cli import CLI
from mininet.topo import SingleSwitchTopo
from signal import SIGKILL
# We assume you are in the same directory as pox.py
# or that it is loadable via PYTHONPATH
from controlador import RYU,POX
import os
import subprocess

if __name__ == "__main__":
    setLogLevel( 'info' )
    # Creando la red: RYU + Single topo
    net = Mininet( topo=SingleSwitchTopo(k = 3), controller=RYU('c0'))
    # Obteniendo las interfaces de los switches
    net_sw = {}
    for k,v in net.items():
        if 's' in k:
            sw_int = []
            for i in range(1,len(v.ports)):
                sw_int.append(k + '-eth' + str(i))
            net_sw[k]=sw_int
            sw_int = []
    
    filename="monitoreo.csv"
    # Agrupando de insterfaces para pasar al comando bwm-ng
    list_interfaces = ''
    for k in net_sw:
        for int_sw in net_sw[k]:
Esempio n. 7
0
class MultiServerNet(object):
    global log

    def __init__(self, s=2, ctrl_addr='127.0.0.1:6633'):
	self.log = log
        self.k = s + 1
        self.topo = SingleSwitchTopo(k=self.k)

	ctrl_args = ctrl_addr.split(':')
	ctrl_ip = ctrl_args[0]
	ctrl_port = int(ctrl_args[1]) if len(ctrl_args) > 1 else 6633
	
	if self.log: sys.stderr.write('Starting the Multi-server network for Step-2\n')

	self.net = Mininet(topo=self.topo, controller=lambda x:
		RemoteController(x, ctrl_ip, ctrl_port),
		listenPort=6634, xterms=False, autoSetMacs=True)
        self.servers = [self.net.idToNode[s] for s in range(2, self.k -1 + 2)]
        self.client = self.net.idToNode[1+self.k]
        self.serverIP = '10.0.0.100'
        self.serverIPMask = 8
        for s in self.servers:
            # set server IP
            s.cmd('ifconfig', '%s:%d' % (s.intfs[0], 0), '%s/%d' % (self.serverIP, self.serverIPMask))
            # set static arp in servers for client IP
            s.cmd('arp', '-s', self.client.IP(), self.client.MAC())
            # start web server
	    if self.log: sys.stderr.write('Starting web server on server %s\n' % s.name)
            s.cmd('python', 'httpd.py', '80', '&')
        # set static arp in client for server IP
        self.client.cmd('arp', '-s', self.serverIP, 'FF:FF:FF:FF:FF:FF')
        self.net.start()
        # log server location
        self.log_server_loc('/tmp/server_loc.txt')
	self.log_topology('/tmp/topo.txt')

    def test(self):
	os.system('rm -rf /tmp/time_log.txt')
	time.sleep(1)
	if self.log: sys.stderr.write('Running test traffic...\n')
	for i in xrange(3):
	    output = self.client.cmd('./client/client.py',
		    'http://%s/cgi-bin/noop.py'%self.serverIP, '2', '1',
		    str(len(self.servers)))
	self.test_server_lb()

    def test_server_lb(self):
	print 'Testing server load-blancing...'
	p1 = True
	s = []
	srvrs = []
	tmp = []
	f = open('/tmp/time_log.txt', 'r')
	if self.log: sys.stderr.write('The client output...\n')
	for line in f:
	    resp = line.strip().split()
	    if self.log: sys.stderr.write(line)
	    s.append(resp[2])
	    tmp.append(resp[2])
	    if resp[2].lower() == 'unknown':
		p1 = False
	    if len(tmp) == len(self.servers):
		srvrs.append(tmp)
		tmp = []
	f.close()
	if self.log: sys.stderr.write('\n')

	if not p1:
	    print 'FAIL! At least one request failed to get a response!'
	    print 'Seen responses are from servers...'
	    print s

	if len(set(srvrs[0])) != len(self.servers):
	    print 'FAIL! All servers not used!'
	    print 'Seen responses are from servers...'
	    print s
	    p1 = False

	for i in range(1,len(srvrs)):
	    if srvrs[0] != srvrs[i]:
		print 'FAIL! Round robin scheme not used!'
		print 'Seen responses are from servers...'
		print s
		p1 = False
		break
	if p1:
	    print 'PASS! - Passed all server load-balancing tests'
	return True

    def log_server_loc(self, filename=None):
        f = None
        if filename is not None:
            try:
                f = open(filename, 'w')
            except IOError:
                print 'Could not open file %s for writing' % filename
                pass

	# log client information
	if self.log: sys.stderr.write('Client location:\n')
	client_id = self.k + 1
	switch = self.net.idToNode[1]
	log_str = '%s %s %d\n' % (self.client.MAC(), switch.defaultMAC,
		self.topo.port(client_id, 1)[1])
	if self.log: sys.stderr.write(log_str)
	if f is not None:
	    f.write(log_str)
	else:
	    print log_str,
	if self.log: sys.stderr.write('\n')

	# log server information
	if self.log: sys.stderr.write('Server location:\n')
        for server_id in range(2, self.k -1 + 2):
            s = self.net.idToNode[server_id]
            switch = self.net.idToNode[1]
            log_str = '%s %s %d\n' % (s.MAC(), switch.defaultMAC, self.topo.port(server_id, 1)[1])
	    if self.log: sys.stderr.write(log_str)
            if f is not None:
                f.write(log_str)
            else:
                print log_str,
        if f is not None:
            f.close()

    def log_topology(self, filename=None):

        f = None
        if filename is not None:
            try:
                f = open(filename, 'w')
            except IOError:
                print 'Could not open file %s for writing' % filename
                pass
	switch = self.net.idToNode[1]
	if f is not None:
	    f.write('%s\n'%switch.defaultMAC)
	    f.close()
Esempio n. 8
0
from mininet.cli import CLI
from mininet.log import info, output
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo


def ifconfigTest(net):
    "Run ifconfig on all hosts in net."
    hosts = net.hosts
    for host in hosts:
        output(host.cmd('ifconfig'))


if __name__ == '__main__':
    info("*** Creating network\n")
    #network = Mininet( TreeTopo( depth=2, fanout=2 ), ipBase= "100.0.0.0/24")
    #                 , switch=OVSKernelSwitch )
    network = Mininet(SingleSwitchTopo())
    info("*** Starting network\n")
    network.start()
    info("*** Running ping test\n")
    network.pingAll()
    network.iperf()
    info("*** Running ifconfig test\n")
    #ifconfigTest( network )
    info("*** Starting CLI (type 'exit' to exit)\n")
    CLI(network)
    info("*** Stopping network\n")
    network.stop()
Esempio n. 9
0
 def testMinimal( self ):
     "Ping test on minimal topology"
     mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller )
     dropped = mn.run( mn.ping )
     self.assertEqual( dropped, 0 )
#!/usr/bin/python
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.node import Controller
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel
import os

#setLoglevel('info')


class POXBridge(Controller):
    "Custom Controller class to invoke POX"

    def start(self):
        "Start POX learning switch"
        self.pox = '%s/pox/pox.py' % os.environ['HOME']
        self.cmd(self.pox, 'forwarding.l2_learning misc.firewall &')

    def stop(self):
        "Stop POX"
        self.cmd('kill %' + self.pox)


net = Mininet(topo=SingleSwitchTopo(8), controller=POXBridge, autoSetMacs=True)
net.start()
net.pingAll()
dumpNodeConnections(net.hosts)

net.stop()
Esempio n. 11
0
This can also be done from the Mininet CLI:
mininet> py [ h.cmd('arping -U -c 1 ' + h.IP()) for h in net.hosts ]
"""

from mininet.log import setLogLevel
from mininet.util import quietRun
from mininet.log import error
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo

if __name__ == '__main__':

    if not quietRun('which arping'):
        error("Cannot find command 'arping'\nThe package",
              "'iputils-arping' is required in Ubuntu or Debian\n")
        exit()

    setLogLevel('info')

    net = Mininet(topo=SingleSwitchTopo(k=10), waitConnected=True)
    net.start()

    for host in net.hosts:
        print host
        print host.cmd('arping -U -c 1 ' + host.IP())

    CLI(net)
    net.stop()
Esempio n. 12
0
def simple(cli, controllerIP):
    "Create and test SDX Simple Module"
    print "Creating the topology with one IXP switch and three participating ASs\n\n"
    topo = SingleSwitchTopo(k=4)
    net = Mininet(topo,
                  controller=lambda name: RemoteController('c0', controllerIP),
                  autoSetMacs=True)  #, autoStaticArp=True)
    net.start()
    hosts = net.hosts
    print "Configuring participating ASs\n\n"
    for host in hosts:
        if host.name == 'h1':
            host.cmd('ifconfig lo:40 110.0.0.1 netmask 255.255.255.0 up')
            host.cmd(
                'route add -net 120.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h1-eth0'
            )
            host.cmd(
                'route add -net 130.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h1-eth0'
            )
            host.cmd(
                'route add -net 140.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h1-eth0'
            )
        if host.name == 'h2':
            host.cmd(
                'route add -net 110.0.0.0 netmask 255.255.255.0 gw 10.0.0.1 h2-eth0'
            )
            host.cmd('ifconfig lo:40 120.0.0.1 netmask 255.255.255.0 up')
            host.cmd(
                'route add -net 130.0.0.0 netmask 255.255.255.0 gw 10.0.0.3 h2-eth0'
            )
            host.cmd(
                'route add -net 140.0.0.0 netmask 255.255.255.0 gw 10.0.0.4 h2-eth0'
            )
        if host.name == 'h3':
            host.cmd(
                'route add -net 110.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h3-eth0'
            )
            host.cmd(
                'route add -net 120.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h3-eth0'
            )
            host.cmd('ifconfig lo:40 130.0.0.1 netmask 255.255.255.0 up')
            host.cmd('ifconfig lo:41 140.0.0.1 netmask 255.255.255.0 up')
        if host.name == 'h4':
            host.cmd(
                'route add -net 110.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h4-eth0'
            )
            host.cmd(
                'route add -net 120.0.0.0 netmask 255.255.255.0 gw 10.0.0.2 h4-eth0'
            )
            host.cmd('ifconfig lo:40 130.0.0.1 netmask 255.255.255.0 up')
            host.cmd('ifconfig lo:41 140.0.0.1 netmask 255.255.255.0 up')

    if (cli):  # Running CLI
        CLI(net)
    else:
        print "Running the Ping Tests\n\n"
        for host in hosts:
            if host.name == 'h3':
                host.cmdPrint('ping -c 5 -I 130.0.0.1 110.0.0.1')
                host.cmdPrint('ping -c 5 -I 140.0.0.1 110.0.0.1')
            if host.name == 'h4':
                host.cmdPrint('ping -c 5 -I 130.0.0.1 110.0.0.1')
                host.cmdPrint('ping -c 5 -I 140.0.0.1 110.0.0.1')

    net.stop()
    print "\n\nExperiment Complete !\n\n"
Esempio n. 13
0
def pingall_test(folder,
                 exe,
                 topo=SingleSwitchTopo(4),
                 custom_topo=None,
                 custom_test=None,
                 expect_pct=0):

    ip = "127.0.0.1"
    port = 6633

    if not VERBOSE:
        lg.setLogLevel('critical')

    ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False)
    net = Mininet(switch=OVSSwitch,
                  controller=ctrlr,
                  autoStaticArp=False,
                  cleanup=True)
    c1 = net.addController('c1')

    if custom_topo:
        custom_topo.build(net)
    else:
        net.buildFromTopo(topo)

    # Start the network
    net.start()

    # Fork off Frenetic process
    devnull = None if VERBOSE else open(os.devnull, 'w')
    frenetic_proc = Popen([
        '/home/vagrant/src/frenetic/frenetic.native', 'http-controller',
        '--verbosity', 'debug'
    ],
                          stdout=devnull,
                          stderr=devnull)

    # Wait a few seconds for frenetic to initialize, otherwise
    time.sleep(5)

    # And fork off application
    app_proc = Popen(['/usr/bin/python2.7', exe],
                     stdout=devnull,
                     stderr=devnull,
                     cwd=CODE_ROOT + folder)

    if custom_test:
        got_pct = int(custom_test(net))
    else:
        got_pct = int(net.pingAll())

    expected_msg = " expected " + str(expect_pct) + "% dropped got " + str(
        got_pct) + "% dropped"
    print exe + ("...ok" if expect_pct == got_pct else expected_msg)

    frenetic_proc.kill()
    app_proc.kill()

    # Ocassionally shutting down the network throws an error, which is superfluous because
    # the net is already shut down.  So ignore.
    try:
        net.stop()
    except OSError:
        pass
Esempio n. 14
0
        successful_pings += 1
    return ((2 - successful_pings) / 2.0) * 100.0


if os.getenv("SUDO_USER") == None:
    print "This program need 'sudo'"
    exit()

# Clean up from the last disaster
Cleanup()
for proc in psutil.process_iter():
    if proc.name() == "frenetic.native" or proc.name() == "openflow.native":
        proc.kill()

# Test Suite
pingall_test("quick_start", "repeater.py", topo=SingleSwitchTopo(2))
pingall_test("netkat_principles", "repeater2.py", topo=SingleSwitchTopo(2))
pingall_test("netkat_principles", "repeater3.py", expect_pct=100)
pingall_test("netkat_principles", "repeater4.py")
pingall_test("netkat_principles", "repeater5.py")
pingall_test("l2_learning_switch", "learning1.py")
pingall_test("l2_learning_switch", "learning2.py", expect_pct=100)
pingall_test("l2_learning_switch", "learning3.py")
pingall_test("l2_learning_switch", "learning4.py")
pingall_test("handling_vlans", "vlan1.py", expect_pct=66)
sys.path.append("../handling_vlans")
from mn_custom_topo import VlanMininetBuilder
ct = VlanMininetBuilder()
pingall_test("handling_vlans", "vlan2.py", custom_topo=ct, expect_pct=83)
pingall_test("multiswitch_topologies", "multiswitch1.py", topo=TreeTopo(2, 4))
pingall_test("multiswitch_topologies", "multiswitch2.py", topo=TreeTopo(2, 4))
Esempio n. 15
0
 def testSingle5( self ):
     "Ping test with both datapaths on 5-host single-switch topology"
     for switch in SWITCHES.values():
         mn = Mininet( SingleSwitchTopo( k=5 ), switch, Host, Controller )
         dropped = mn.run( mn.ping )
         self.assertEqual( dropped, 0 )
Esempio n. 16
0
        info('output filename: {output}\n'.format(output=output))

        src, dst = self.get(kwargs['src'], kwargs['dst'])
        ping_cmd = 'ping -c {count} -i {interval} {dst_ip}'.format(
            dst_ip=dst.IP(), **kwargs)

        info('ping command: {cmd} &>{output} &\n'.format(cmd=ping_cmd,
                                                         output=output))
        src.sendCmd('{cmd} &>{output} &'.format(cmd=ping_cmd, output=output))
        # This is a patch to allow sendingCmd while ping is running in background.CONS: we can not know when
        # ping finishes and get its output
        src.waiting = False

    def start(self):
        super(Minievents, self).start()
        CLI(self) if self.scheduler.empty() else self.scheduler.run()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--events",
                        default="mininet/minievents.json",
                        help="json file with event descriptions")
    args = parser.parse_args()
    setLogLevel('info')
    net = Minievents(topo=SingleSwitchTopo(k=2),
                     link=TCLink,
                     controller=OVSController,
                     events_file=args.events)
    net.start()
parser = OptionParser()
parser.add_option("", "--ip", type="string", default="192.168.190.60")
parser.add_option("", "--topology", type="string", default="tree")
parser.add_option("", "--hosts", type="int", default=8)
parser.add_option("", "--depth", type="int", default=3)
parser.add_option("", "--fanout", type="int", default=2)
parser.add_option("", "--pods", type="int", default=4)

(options, args) = parser.parse_args()
print options

# Verifing topology type
if options.topology == 'tree':
    topo = TreeTopo(depth=options.depth, fanout=options.fanout)
elif options.topology == 'single':
    topo = SingleSwitchTopo(k=options.hosts)
elif options.topology == 'ufrgs':
    topo = UFRGSTopo()
elif options.topology == 'fattree':
    topo = FatTree(num_pods=options.pods)

# Setting mininet configuration
setLogLevel('info')

# Adding root host
root = Host('root', inNamespace=False)

# Adding the remote controller
net = Mininet(topo=topo,
              link=TCLink,
              autoSetMacs=True,
Esempio n. 18
0
 def testSingle5( self ):
     "Ping test on 5-host single-switch topology"
     mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host, Controller )
     dropped = mn.run( mn.ping )
     self.assertEqual( dropped, 0 )
Esempio n. 19
0
from mininet.topo import SingleSwitchTopo
from mininet.net import Mininet
from mininet.cli import CLI


def mycmd(self, line):
    "mycmd is an example command to extend the Mininet CLI"
    net = self.mn
    print('mycmd invoked for', net, 'with line', line, '\n')


CLI.do_mycmd = mycmd

net = Mininet(SingleSwitchTopo(2))
net.start()
CLI(net)
net.stop()
Esempio n. 20
0
import sys

def startMn( threadId, net ):
    net.start()
    
    h1, h2 = net.getNodeByName( 'h1', 'h2' )

    popens = {}
    popens[1] = h1.popen( "ping -c4 -D %s" % h2.IP() )
    popens[2] = h2.popen( "ping -c4 -D %s" % h1.IP() )
    
    popens[1].wait()
    popens[2].wait()
   

if __name__ == '__main__':
    mytopo = SingleSwitchTopo( 3 )
    net = Mininet( topo=mytopo )

    t1 = threading.Thread( target=startMn, args=( 1, net))
    t1.start()

    cli = CLI
    cli( net )
    sys.stdout = sys.__stdout__
    sys.stdin  = sys.__stdin__
    
    t1.join()

    net.stop() 
Esempio n. 21
0
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.node import OVSController
from mininet_rest import MininetRest
from mininet.topo import SingleSwitchTopo

net = Mininet(topo=SingleSwitchTopo(k=2),
              controller=OVSController,
              link=TCLink)

net.start()
mininet_rest = MininetRest(net)
mininet_rest.run()
net.stop()
         quietRun("pkill -9 -f webserver.py"), '\n')


if __name__ == '__main__':
    setLogLevel('info')

    # Create network
    if (len(sys.argv) != 2):
        print 'Specify topology single, tree, linear, assign1, triangle, mesh, or someloops'
        sys.exit(1)
    topoName = sys.argv[1]
    topoParts = topoName.split(',')
    if (topoParts[0] == "single"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = SingleSwitchTopo(k=int(topoParts[1]))
    elif (topoParts[0] == "tree"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = TreeTopo(depth=int(topoParts[1]))
    elif (topoParts[0] == "linear"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = LinearTopo(k=int(topoParts[1]))
    elif (topoParts[0] == "assign1"):
        topo = AssignOneTopo()
    elif (topoParts[0] == "triangle"):
        topo = TriangleTopo()
    elif (topoParts[0] == "mesh"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)