Ejemplo n.º 1
0
def emptyNet():

    net = Mininet(topo=None, build=False)
    c0 = Controller('c0', inNamespace=False)

    h1 = Host('h1')
    h2 = Host('h2')
    #intf1 = Intf("h1-eth1")
    #intf2 = Intf("h2-eth1")
    s1 = OVSSwitch('br0', inNamespace=False)

    Link(h1, s1)
    Link(h2, s1)

    c0.start()
    s1.start([c0])

    net.start()
    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    CLI(net)

    net.stop()
    h1.stop()
    h2.stop()
    s1.stop()
    c0.stop()
Ejemplo n.º 2
0
def add_root_node(net, first_two_octets, subnet):
    """
        add an extra node that is part of the root namespace
        and configure it to be accessible from the network
        Note that this host is not visible from inside mininet """

    base_ip = first_two_octets + '.' + str(subnet)
    root_node = Host('root', inNamespace=False, ip=base_ip + '.100/24')
    link = net.addLink(root_node,
                       net.getNodeByName('s7'),
                       txo=False,
                       rxo=False)
    link.intf1.setIP(base_ip + '.100', 24)
    root_node.cmd('ip route flush table main')
    # empty routing table
    root_node.cmd('route add -net ' + first_two_octets + '.' + str(subnet) +
                  '.0 netmask 255.255.255.0 dev ' + link.intf1.name)
    root_node.cmd('route add default gw ' + base_ip + '.1' + ' dev ' +
                  link.intf1.name)
    for x in range(subnet + 1, 25):  #host config is only for non-default route
        root_node.cmd('route add -net ' + first_two_octets + '.' + str(x) +
                      '.0' + ' netmask 255.255.255.0 gw ' + first_two_octets +
                      '.' + str(subnet) + '.254' + ' dev ' + link.intf1.name)
    # cross link between data and control planes
    root_node.cmd('route add -net ' + first_two_octets + '.' +
                  str(subnet - 10) + '.0' + ' netmask 255.255.255.0 gw ' +
                  first_two_octets + '.' + str(subnet) + '.250')
    root_node.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0 &')

    return root_node
Ejemplo n.º 3
0
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           protocol='tcp',
                           port=6653)

    info('*** Add switches\n')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    r3 = Host('r3', inNamespace=False, ip='0.0.0.0')
    # r3 = Host('r3', inNamespace=False, ip='10.0.0.1')
    # r3 = net.addHost('r3', cls=Host, ip='10.0.0.1/8')
    r3.cmd('sysctl -w net.ipv4.ip_forward=1')

    info('*** Add hosts\n')
    diel = net.addHost('diel',
                       cls=Host,
                       ip='10.0.1.2/16',
                       defaultRoute='0.0.0.0',
                       mac='00:00:00:00:00:01')

    alice = net.addHost('alice',
                        cls=Host,
                        ip='10.0.2.2/16',
                        defaultRoute='0.0.0.0',
                        mac='00:00:00:00:00:02')
    bob = net.addHost('bob',
                      cls=Host,
                      ip='10.0.2.3/16',
                      defaultRoute='0.0.0.0',
                      mac='00:00:00:00:00:03')

    info('*** Add links\n')
    net.addLink(r3, s1)
    net.addLink(r3, s2)

    net.addLink(s1, diel)
    net.addLink(s2, bob)
    net.addLink(s2, alice)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s2').start([c0])
    net.get('s1').start([c0])

    info('*** Post configure switches and hosts\n')
    r3.cmd('xterm &')
    CLI(net)
    net.stop()
 def AddHosts(self, net, numberOfHosts):
     global hostCounter
     hosts = []
     for i in range(0, numberOfHosts):
         host = Host(net.addHost("h%d" % (hostCounter)))
         hostCounter += 1
         hosts.append(host)
     return hosts
Ejemplo n.º 5
0
def add_host():
    num = len(hosts)
    string_h = 'h' + str(num)
    h = Host(string_h)
    # tmp = int(num) + 1
    # ip = '10.' + str(tmp) + '/8'
    # h.setIP(ip)
    hosts.append(h)
    return redirect(url_for('create'))
Ejemplo n.º 6
0
def lab11_main(options=None):
    net = get_default_net(options)

    hroot = Host('host', inNamespace=False)
    hred = standard_container(net, "red", {"cap_add":["CAP_NET_RAW"]})
    hgreen = standard_container(net, "green", {"cap_add":["CAP_NET_RAW"]})
    hblue = standard_container(net, "blue", {"cap_add":["CAP_NET_RAW"]})

    link_host_container(hroot, hred)
    link_host_container(hroot, hgreen)
    link_host_container(hroot, hblue)

    net.start()
    signal_topology_started()
Ejemplo n.º 7
0
def emptyNet():

    net = Mininet(switch=OVSSwitch, build=False)

    #c0 = net.addController('c0', controller=RemoteController, port=6633)
    #c1 = net.addController('c1', controller=RemoteController, port=6634)
    c0 = net.addController('c0', controller=Controller, port=6634)
    c1 = net.addController('c1', controller=Controller, port=6635)

    h1 = net.addHost('host1', ip='192.168.0.2/24', mac='00:1e:65:15:fc:01')
    h2 = net.addHost('host2', ip='192.168.0.3/24', mac='00:1e:65:15:fc:02')
    s1 = net.addSwitch('br0')
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    h3 = net.addHost('host3', ip='172.168.0.2/24', mac='00:1e:65:15:fc:03')
    h4 = net.addHost('host4', ip='172.168.0.3/24', mac='00:1e:65:15:fc:04')
    s2 = net.addSwitch('br1')
    net.addLink(h3, s2)
    net.addLink(h4, s2)

    # hide the gatway in net
    gateway = Host('gateway')
    net.addLink(s1, gateway)
    net.addLink(s2, gateway)
    gateway.intf("gateway-eth0").setIP('192.168.0.1/24')
    gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    # show gateway in net
    #gateway = net.addHost('gateway', ip='192.168.0.1/24')
    #net.addLink(s1, gateway)
    #net.addLink(s2, gateway)
    #gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    net.build()

    print h1.cmd('ip route add default via 192.168.0.1 dev host1-eth0')
    print h2.cmd('ip route add default via 192.168.0.1 dev host2-eth0')
    print h3.cmd('ip route add default via 172.168.0.1 dev host3-eth0')
    print h4.cmd('ip route add default via 172.168.0.1 dev host4-eth0')

    c0.start()
    c1.start()
    s1.start([c0])
    s2.start([c1])

    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    #s2.cmd('ovs-vsctl set bridge br1 protocols=OpenFlow13')
    CLI(net)
    net.stop()
Ejemplo n.º 8
0
def lab8_main(options=None):
    net = get_default_net(options)

    hroot = Host('host', inNamespace=False)
    hred = standard_container(net, "red")
    hgreen = standard_container(net, "green")
    hblue = standard_container(net, "blue")

    link_host_container(hroot, hred)
    link_host_container(hroot, hgreen)
    link_host_container(hroot, hblue)

    net.start()
    signal_topology_started()
Ejemplo n.º 9
0
def emptyNet():

    net = Mininet(controller=RemoteController)

    info('*** Adding controller\n')
    net.addController('c0',
                      controller=RemoteController,
                      ip="127.0.0.1",
                      port=6653)

    info('*** Adding hosts\n')
    #---------subnet1---------
    h1 = net.addHost('h1',
                     ip='10.0.0.1',
                     mac='00:00:00:00:00:01',
                     defaultRoute='via 10.0.0.254')
    h2 = net.addHost('h2',
                     ip='10.0.0.2',
                     mac='00:00:00:00:00:02',
                     defaultRoute='via 10.0.0.254')

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')
    info('*** Creating links\n')
    #---------subnet1---------
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    info('*** Adding gateway\n')
    gateway = Host('gateway')

    net.addLink(s1, gateway)
    gateway.intf("gateway-eth0").setIP('10.0.0.254/24')

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
Ejemplo n.º 10
0
    def __init__(self):
        "Create custom topo."

        # Initialize topology
        Topo.__init__(self)

        # Add hosts and switches
        h1 = Host('h1')
        self.addHost(h1)
        h2 = self.addHost('h2')
        h3 = self.addHost('h3')
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')
        h1.addIntf(self, 'h1-eth1')
        h1.setIP(self, '10.0.0.250', 8, 'h1-eth1')

        # Add links
        self.addLink(h1, s1)
        self.addLink(s1, s2)
        self.addLink(h2, s2)
        self.addLink(h3, s2)
Ejemplo n.º 11
0
#!/usr/bin/python

from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link

h1 = Host('h1')
h2 = Host('h2')
h3 = Host('h3')
h4 = Host('h4')
s1 = OVSSwitch('s1', inNamespace=False)
s2 = OVSSwitch('s2', inNamespace=False)
c0 = Controller('c0', inNamespace=False)
Link(h1, s1)
Link(h2, s1)
Link(h3, s2)
Link(h4, s2)
Link(s1, s2)
h1.setIP('10.0.0.1/24')
h2.setIP('10.0.0.2/24')
h3.setIP('10.0.0.3/24')
h4.setIP('10.0.0.4/24')
c0.start()
s1.start([c0])
s2.start([c0])
print h1.IP
print h2.IP
print h3.IP
print h4.IP
print 'Pinging ...'
print h1.cmd('ping -c3 ', h2.IP())
print h1.cmd('ping -c3 ', h3.IP())
Ejemplo n.º 12
0
#!/usr/bin/python

from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link

h1 = Host('h1')
h2 = Host('h2')
h3 = Host('h3')
h4 = Host('h4')
h5 = Host('h5')
h6 = Host('h6')
h7 = Host('h7')
h8 = Host('h8')
e1 = OVSSwitch('e1', inNamespace=False)
e2 = OVSSwitch('e2', inNamespace=False)
e3 = OVSSwitch('e3', inNamespace=False)
e4 = OVSSwitch('e4', inNamespace=False)
a1 = OVSSwitch('a1', inNamespace=False)
a2 = OVSSwitch('a2', inNamespace=False)
c1 = Controller('c1', inNamespace=False)
Link(h1, e1)
Link(h2, e1)
Link(h3, e2)
Link(h4, e2)
Link(h5, e3)
Link(h6, e3)
Link(h7, e4)
Link(h8, e4)
h1.setIP('10.0.0.1/24')
h2.setIP('10.0.0.2/24')
h3.setIP('10.0.0.3/24')
Ejemplo n.º 13
0
#!/usr/bin/python

"This example doesn't use OpenFlow, but attempts to run sshd in a namespace."

from __future__ import print_function
import sys

from mininet.node import Host
from mininet.util import ensureRoot, waitListening

ensureRoot()
timeout = 5

print("*** Creating nodes")
h1 = Host('h1')

root = Host('root', inNamespace=False)

print("*** Creating links")
h1.linkTo(root)

print(h1)

print("*** Configuring nodes")
h1.setIP('10.0.0.1', 8)
root.setIP('10.0.0.2', 8)

print("*** Creating banner file")
f = open('/tmp/%s.banner' % h1.name, 'w')
f.write('Welcome to %s at %s\n' % (h1.name, h1.IP()))
f.close()
Ejemplo n.º 14
0
def configLinkStatus(src, dst, status):
    connections = src.connectionsTo(dst)
    if len(connections) == 0:
        error('src and dst not connected: %s %s\n' % (src, dst))
    for srcIntf, dstIntf in connections:
        print srcIntf, dstIntf
        result = srcIntf.ifconfig(status)
        if result:
            error('link src status change failed: %s\n' % result)
        result = dstIntf.ifconfig(status)
        if result:
            error('link dst status change failed: %s\n' % result)


h0 = Host('h0')
h1 = Host('h1')
h2 = Host('h2')
h3 = Host('h3')

s0 = OVSKernelSwitch('s0', inNamespace=False)
s1 = OVSKernelSwitch('s1', inNamespace=False)
s2 = OVSKernelSwitch('s2', inNamespace=False)
s3 = OVSKernelSwitch('s3', inNamespace=False)

c0 = RemoteController('c0', ip='10.108.100.195')
c1 = RemoteController('c1', ip='10.108.100.248')
c2 = RemoteController('c2', ip='10.108.102.176')
c3 = RemoteController('c3', ip='10.108.101.48')

l1 = Link(h0, s1)
Ejemplo n.º 15
0
def HostPlacer(name, *args, **params):
    "Custom Host() constructor which places hosts on servers"
    if name in remoteHosts:
        return RemoteHost(name, *args, server=remoteServer, **params)
    else:
        return Host(name, *args, **params)
# 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,
              controller=lambda name: RemoteController(name, ip=options.ip))

for host in net.hosts:
    host.linkTo(root)

# Start the network
net.start()

# Waiting for apache starts
file_server = 0
Ejemplo n.º 17
0
    Link( c1, ai ) 
    i = i + 1
    
i = 1
count = 1
while( i <= n ** 2):                                                                                                         
    e1 = OVSSwitch( 'e%d', inNamespace=False ) % (i)
    Link( acount, ei ) 
    if i == n:
        count = count + 1    
    i = i + 1

i = 1
count = 1
while( i <= n ** 3) :    
    h1 = Host( 'h%d' ) % (i)
    Link( ecount, hi ) 
    hi.setIP( '10.0.0.1/24' )
    if i == n:
        count = count + 1    
    i = i + 1
                                                                                                                                                                                                                                                                        
c0.start()                                                                                                            
a1.start( [ c0 ] )
a2.start( [ c0 ] )                                                                                                    
print h1.IP
print h2.IP
print h3.IP
print h4.IP
print 'Pinging ...'
print h1.cmd( 'ping -c3 ', h2.IP() )     
Ejemplo n.º 18
0
#!/usr/bin/python

from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link

b1 = Host('b1')
b2 = Host('b2')
b3 = Host('b3')
b4 = Host('b4')
s1 = OVSSwitch('s1', inNamespace=False)
c0 = Controller('c0', inNamespace=False)
Link(b1, s1)
Link(b2, s1)
Link(b3, s1)
Link(b4, s1)

b1.setIP('10.0.0.1/24')
b1.setMAC('00.00.00.00.00.00')
b2.setIP('10.0.0.2/24')
b3.setIP('10.0.0.3/24')
b4.setIP('10.0.0.4/24')
c0.start()
s1.start([c0])

print b1.IP
print b2.IP
print b3.IP
print b4.IP
# print 'Pinging...'
# print b1.cmd('ping -c3 ', b2.IP() )
# print b1.cmd('ping -c3', b3.IP() )
Ejemplo n.º 19
0
def emptyNet():

    net = Mininet( controller=RemoteController )

    info( '*** Adding controller\n' )
    net.addController( 'c0', 
                       controller=RemoteController, 
                       ip = "127.0.0.1", 
                       port=6633 )

    info( '*** Adding hosts\n' )
    #---------subnet1---------
    h1 = net.addHost( 'h1', 
                      ip='10.0.0.1', 
                      mac='00:00:00:00:00:01',
                      defaultRoute='via 10.0.0.254')
    h2 = net.addHost( 'h2', 
                      ip='10.0.0.2',
                      mac='00:00:00:00:00:02',
                      defaultRoute='via 10.0.0.254')
    h3 = net.addHost( 'h3', 
                      ip='10.0.0.3', 
                      mac='00:00:00:00:00:03',
                      defaultRoute='via 10.0.0.254')
    #---------subnet2---------
    k4 = net.addHost( 'k4', 
                      ip='192.168.0.10', 
                      mac='00:00:00:00:00:10',
                      defaultRoute='via 192.168.0.254')
    k5 = net.addHost( 'k5',
                      ip='192.168.0.11',
                      mac='00:00:00:00:00:11',
                      defaultRoute='via 192.168.0.254')
    k6 = net.addHost( 'k6', 
                      ip='192.168.0.12', 
                      mac='00:00:00:00:00:12',
                      defaultRoute='via 192.168.0.254')
        
    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )
    info( '*** Creating links\n' )
    #---------subnet1---------
    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )
    #---------subnet2---------
    net.addLink( k4, s2 )
    net.addLink( k5, s2 )
    net.addLink( k6, s2 )
    #---------switch----------
    net.addLink( s1, s2 )

    info( '*** Adding gateway\n')
    gateway = Host('gateway')
    net.addLink(s1, gateway)
    net.addLink(s2, gateway)
    gateway.intf("gateway-eth0").setIP('10.0.0.254/24')
    gateway.intf("gateway-eth1").setIP('192.168.0.254/24')
    
    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Ejemplo n.º 20
0
#!/usr/bin/python

from mininet.topo import Topo
from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link

h1 = Host('h1')
h2 = Host('h2')
s1 = OVSSwitch('s1', inNamespace=False)
c0 = Controller('c0', inNamespace=False)
Link(h1, s1)
Link(h2, s1)
h1.setIP('10.1/8')
h2.setIP('10.2/8')
c0.start()
s1.start([c0])
print h1.cmd('ping -c1', h2.IP())
s1.stop()
c0.stop()