Exemple #1
0
def networkTest():
    "Create a network with some docker containers acting as hosts."
    info('*** Create the controller \n')
    c0 = POXBridge()
    net = Containernet(build=False)
    info('*** Creating the network\n')
    # Containers de imagenes con herramientas de red
    h1 = net.addDocker('h1', ip='10.0.0.100', dimage="ubuntu_net_tools")
    h2 = net.addDocker('h2', ip='10.0.0.101', dimage="ubuntu_net_tools")
    h3 = net.addDocker('h3', ip='10.0.0.102', dimage="ubuntu_net_tools")

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')

    info('*** Creating links\n')
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(s1, h3)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Build the network\n')
    net.build()

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

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

    info('*** Stopping network')
    net.stop()
Exemple #2
0
def topo():

    net = Containernet(controller=RemoteController,
                       link=TCLink,
                       switch=OVSKernelSwitch)
    info("*** Adding Controller ")
    c1 = net.addController('c1', ip='127.0.0.1', port=6633)
    info('*** Adding Switch')
    s2 = net.addSwitch('s2',
                       protocols='OpenFlow10',
                       listenPort=6670,
                       mac='00:00:00:00:00:02')
    s3 = net.addSwitch('s3',
                       protocols='OpenFlow10',
                       listenPort=6671,
                       mac='00:00:00:00:00:03')

    info('*** Adding Docker Containers')
    d4 = net.addDocker('d4',
                       mac='00:00:00:00:00:04',
                       ip='10.0.20.3/24',
                       dimage="ubuntu:trusty",
                       cpu_period=50000,
                       cpu_quota=25000)
    d5 = net.addDocker('d5',
                       mac='00:00:00:00:00:05',
                       ip='10.0.10.3/24',
                       dimage="ubuntu:trusty",
                       cpu_period=50000,
                       cpu_quota=25000)
    d6 = net.addDocker('d6',
                       mac='00:00:00:00:00:06',
                       ip='10.0.10.2/24',
                       dimage="ubuntu:trusty",
                       cpu_period=50000,
                       cpu_quota=25000)
    d7 = net.addDocker('d7',
                       mac='00:00:00:00:00:07',
                       ip='10.0.20.2/24',
                       dimage="ubuntu:trusty",
                       cpu_period=50000,
                       cpu_quota=25000)

    info('*** Adding links ')
    net.addLink(d4, s2, cls=TCLink, delay="5ms", bw=1, loss=0)
    net.addLink(d6, s2, cls=TCLink, delay="10ms", bw=10, loss=0)
    net.addLink(d7, s3, cls=TCLink, delay="5ms", bw=1, loss=0)
    net.addLink(d5, s3, cls=TCLink, delay="10ms", bw=10, loss=0)
    net.addLink(s2, s3, cls=TCLink, delay="100ms", bw=1, loss=0)

    info('*** Starting ')
    net.build()
    c1.start()
    s3.start([c1])
    s2.start([c1])

    CLI(net)
    net.stop()
Exemple #3
0
# Add switches
info('*** Adding switches\n')

s1 = net.addSwitch('s1', protocols='OpenFlow13')  #...
s2 = net.addSwitch('s2', protocols='OpenFlow13')  #...

# Add links
info('*** Creating links\n')
for i in range(num_machines // 2):
    links.append(net.addLink(hosts[i], s1, bw=10))

for i in range(num_machines // 2, num_machines):
    links.append(net.addLink(hosts[i], s2, bw=10))

links.append(net.addLink(s1, s2, bw=1000))

links.append(net.addLink(c_h100, s1))
links.append(net.addLink(s_h200, s2))

net.addController(c0)

# Build the network
info('*** Build the network\n')
net.build()
info('*** Starting network\n')
net.start()
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    net = Containernet(controller=Controller, switch=OVSSwitch, link=TCLink)

    info("*** Creating (reference) controllers\n")
    c = RemoteController('c', ip='172.17.0.1', port=6653)

    info("*** Creating switches\n")
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')

    info("*** Creating hosts\n")
    #agent1 = net.addHost('agent1', ip='10.0.0.11')
    #agent2 = net.addHost('agent2', ip='10.0.0.21')
    home_path = os.path.expanduser('~')
    agent1 = net.addDocker('agent1',
                           ip='10.0.0.11',
                           dimage="khayamgondal/sosagent:v4",
                           volumes=["" + home_path + "/SOSAgent:/sos-agent"])
    agent2 = net.addDocker('agent2',
                           ip='10.0.0.21',
                           dimage="khayamgondal/sosagent:v4",
                           volumes=["" + home_path + "/SOSAgent:/sos-agent"])
    client1 = net.addDocker('client1',
                            ip='10.0.0.111',
                            dimage="khayamgondal/sosagent:v4")
    server1 = net.addDocker('server1',
                            ip='10.0.0.211',
                            dimage="khayamgondal/sosagent:v4")

    #controller = net.addDocker('controller', ip='10.0.0.69', dimage="khayamgondal/sosagent:v4", volumes=["/home/ubuntu/sos-for-floodlight:/sos-for-floodlight"])
    #client1 = net.addHost('client1', ip='10.0.0.111')
    #server1 = net.addHost('server1', ip='10.0.0.211')

    info("*** Creating links\n")
    net.addLink(s1, client1, port1=1, port2=1)
    net.addLink(s1, agent1, port1=2, port2=1)

    net.addLink(s1, s2, delay='100ms', port1=3, port2=3)

    net.addLink(s2, server1, port1=1, port2=1)
    net.addLink(s2, agent2, port1=2, port2=1)

    #net.addLink(controller, s1, port1=0, port2=5)
    #net.addLink(controller, s2, port1=1, port2=5)

    info("*** Starting network\n")
    net.build()
    c.start()
    s1.start([c])
    s2.start([c])

    #info( "*** Testing network\n" )
    #net.pingAll()

    #info( "*** Running CLI\n" )
    CLI(net)

    #info( "*** Stopping network\n" )
    net.stop()
Exemple #5
0
def topology(num=100):
    info(
        "Creating a network with docker containers acting as hosts and wireless mesh network environment.\n"
    )

    net = Containernet(controller=Controller)

    info('*** Adding docker containers\n')
    ## In automated way will create Hosts
    dh = []

    listPos = positions(num)
    prepareGraph(num)
    sys.exit()
    print("** Creating %d Station(s) " % (num))

    for x in range(0, num):
        ip = (254 - x)
        posx, posy, posz, r = getPosition(listPos)
        ## This will create the hosts with image ubuntu:trusty, position and range of the device
        ## other information can be added later
        dh.append(
            net.addDocker('d' + str(x),
                          cls=Docker,
                          ip='10.0.0.' + str(ip),
                          dimage="ubuntu:trusty",
                          position=str(posx) + ',' + str(posy) + ',' +
                          str(posz),
                          range=r))
        d = dh[x]
        sys.stdout.write(str(d) + " ")
        sys.stdout.flush()

    info("\n** Adding nodes to Mesh\n")
    for x in dh:
        net.addMesh(x, ssid='meshNet')
    #pdb.set_trace()
    meshr = net.meshRouting("mesh")
    info("** Routing nodes through mesh\n")
    for x in dh:
        meshRouting.customMeshRouting(x, 0, net.wifiNodes)
        sys.stdout.write(str(x) + " ")
        sys.stdout.flush()

    info('\n*** Starting network\n')
    net.build(
    )  ## Build should do the same as start but it will interconnect hosts
    #net.start()

    seed_node = "10.0.0.254:5001"  ## seed will be always the first container!
    info("** Configuring node(s)\n")
    for d in dh:
        sys.stdout.write(str(d) + " - ")
        sys.stdout.flush()
        port = 5001
        dev = str(d) + "-mp0"
        ## Calling inside script to configure each container
        nn = d.cmd(
            "/bin/bash /home/config-serf.sh config rpc=127.0.0.1:7373 port=" +
            str(port) + " dev=" + str(dev) + " seed=" + str(seed_node))
        if nn:
            print("Configured for 10.0.0.%s:%d in device %s " %
                  (str(ip), port, dev))
            print("> %s " % (nn))
        else:
            print("Error in configuring %s " % (str(d)))

    info('*** Starting our simulation\n')

    slpv = 10 * num / 4  ### SLEEP VARIABLE!!!!
    #This will start our simulation of SERF+monitor
    #Calling our inside script to start the processes
    st = time.time()
    with open('/home/simul.' + str(num) + '-' + str(int(time.time())) + '.txt',
              "a+") as myfile:
        for d in range(0, num):
            dh[d].sendCmd("/bin/bash /home/config-serf.sh test " + str(slpv) +
                          " 2>&1 /dev/null &")
            see_pub(dh, out=myfile)
            #dh[d+1].cmd("/bin/bash /home/config-serf.sh test 50")
            time.sleep(1)  ## So that each will start after each other

        info("** All nodes have published services.\n")
        info("** waiting for them to end.")
        et = 0
        while ((st + slpv) - et) >= 0:  ## while within the time frame
            #for i in range(0,slpv):
            sys.stdout.write(".")
            sys.stdout.flush()
            see_pub(dh, out=myfile)
            #time.sleep(1)
            et = time.time()
        sys.stdout.flush()
        myfile.flush()
        print("\n")

    printTopo(net, num=num)
    info("*** Simulation has ended (?)\n")

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

    info('*** Stopping network')
    net.stop()