Exemple #1
0
def start(ip="127.0.0.1",port=6633):

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

  topo = SingleSwitchTopo(2)
  net.buildFromTopo( topo )

  # Set up logging etc.
  lg.setLogLevel('info')
  lg.setLogLevel('output')

  # Start the network
  net.start()

  # Fork off Frenetic process
  frenetic_proc = Popen(['/home/vagrant/src/frenetic/frenetic.native', 'http-controller'])

  # And fork off application
  app_proc = Popen(['/usr/bin/python2.7/python','/home/vagrant/manual/programmers_guide/code/quick_start/repeater.py'])

  output("Pingall returned "+str(net.pingAll()))

  frenetic_proc.kill()
  app_proc.kill()
def test_pingall(topology):

    Network = Mininet()
    Network.buildFromTopo(topology)
    Network.start()
    result = Network.pingAll()
    Network.stop()
    if result == 0:
        return True
    else:
        return False
Exemple #3
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
Exemple #4
0
def main():
    t = TorusTopo(3, 3)
    # t = TreeTopo(3,3)
    prot = "OpenFlow13"
    net = Mininet()
    # net = Mininet(controller=RemoteController)
    c0 = net.addController('c0',
                           controller=RemoteController,
                           ip='192.168.31.158',
                           port=6653)
    net.buildFromTopo(t)

    topo = {}
    for link in t.links():
        info = t.linkInfo(link[0], link[1])
        n1 = info['node1']
        n2 = info['node2']
        p1 = info['port1']
        p2 = info['port2']

        t1 = int(net.getNodeByName(n1).dpid, 16) if t.isSwitch(n1) else 'host'
        t2 = int(net.getNodeByName(n2).dpid, 16) if t.isSwitch(n2) else 'host'

        if t1 != 'host':
            m1 = topo.setdefault(t1, {})
            m1[p1] = t2
        if t2 != 'host':
            m1 = topo.setdefault(t2, {})
            m1[p2] = t1

    hosts = t.hosts()
    switches = t.switches()

    def make_igmp_host(ho, hn):
        ho.cmd('route add -net 224.0.0.0 netmask 224.0.0.0 ' + hn + '-eth0')

    for hn in hosts:
        ho = net.get(hn)
        make_igmp_host(ho, hn)

    with open('topo.json', 'w') as f:
        dump(topo, f)

    net.build()
    net.start()

    for sn in switches:
        net.get(sn).cmd('ovs-vsctl set bridge ' + sn + ' protocols=OpenFlow13')

    CLI(net)
    net.stop()
Exemple #5
0
def runMininet(protocols, controller, topo, topo_arg, ovs_switch, pattern):
    # If no arguments passed, set the default values
    if protocols == None: protocols = "OpenFlow13"
    if controller == None: controller = ["127.0.0.1"]
    if topo == None: topo = "SwitchTopo"
    if topo_arg == None: topo_arg = [1]
    if ovs_switch == None: ovs_switch = "OVSSwitch"
    if pattern == None: pattern = "xscxx"

    # Create topology
    cur_topo = getattr(topology, topo)(*topo_arg)

    # Get switch type
    cur_switch = partial(getattr(switch, ovs_switch), protocols=protocols)

    # Prepare mininet
    net = None

    # Execute pattern
    delay = ""
    for c in pattern:
        if c == 's':
            # Create mininet object
            net = Mininet(switch=cur_switch, controller=None)
            net.buildFromTopo(cur_topo)

            # Create and add controllers
            for i, address in enumerate(controller):
                net.addController(
                    RemoteController('c{0}'.format(i), address, 6653))

            # Start connections to controllers
            net.start()
        elif c == 'c':
            if net != None: CLI(net)
        elif c == 'x':
            if net != None:
                net.stop()
                net = None
            else:
                cleanup()
        elif c.isdigit():
            delay += c
        elif c == 'd':
            if delay == "": delay = "1"
            print("*** Waiting " + delay + " seconds")
            sleep(float(delay))
            delay = ""
Exemple #6
0
def mnScript():
    "Creating a Mininet net"

    net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, autoSetMacs=True, listenPort=7001 )

    topo = MyTopo()
    
    #Build and Start
    net.buildFromTopo( topo )
    net.start()


    print "*** Starting Group ***"
    print "*** Socket"
    s = initsocket()
    
    request = Request()
    request.id = 1
    request.action = request.ACTION.GET_GROUP
    #request.action = request.ACTION.GET_COMPLETE_GROUP

    s.send (request.toJson() )
    jsonStr = s.recv()

    print "*** Group"
    group = GroupFactory().decodeJson(jsonStr)
    
    src = net.nameToNode[ "h" + str(group.source) ]
    print "*** Setup CA:FE ARP in source:", src.name
    src.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
    print "*** Start udpapp in source( " + src.name + " ) manually ;)"
    #src.cmd("udpapp -m &")
    
    for host in group.hosts:
        if host.id != group.source:
            h = net.nameToNode[ "h" + str(host.id) ]
            print "*** Setup CA:FE ARP in " + h.name
            h.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
            print "*** Starting udpapp in " + h.name
            #h.cmd("udpapp -c " + h.name  + " &")
            #sleep( 1 )

    print "*** Starting CLI ***"
    CLI( net )

    print "*** Stopping net ***"
    net.stop()
Exemple #7
0
def mnScript():
    "Creating a Mininet net"

    net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, autoSetMacs=True, listenPort=6634 )

    print "*** Creating Remote Controller"
    c0 = net.addController( 'c0' )

    topo = MyTopo()
    
    #Build and Start
    net.buildFromTopo( topo )
    net.start()


    print "*** Starting Group ***"
    print "*** Socket"
    s = initsocket()
    
    request = Request()
    request.id = 1
    request.action = request.ACTION.GET_GROUP

    s.send (request.toJson() )
    jsonStr = s.recv()

    print "*** Group"
    group = GroupFactory().decodeJson(jsonStr)
    
    src = net.nameToNode[ "h" + str(group.source) ]
    print "*** Setup CA:FE ARP in source"
    src.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
    print "*** Starting udpapp in source"
    cmdThread( src, "echo blah > /home/openflow/htest" ) #"udpapp -m > " + src.name + ".log" )

    for host in group.hosts:
        h = net.nameToNode[ "h" + str(host.id) ]
        print "*** Setup CA:FE ARP in " + h.name
        h.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
        print "*** Starting udpapp in " + h.name
        cmdThread( h, "ping 10.0.0.1 > " + h.name + ".log") #"udpapp -c > " + h.name + ".log" )

    print "*** Starting CLI ***"
    CLI( net )

    print "*** Stopping net ***"
    net.stop()
Exemple #8
0
def runJellyfishLink(remote_control=False):
    '''
    Create and run jellyfish network
    '''
    topo = JellyTopo(
        N=2,
        n=2,
        r=2,
        # topo = JellyTopo(N=3, n=3, r=3,
        # topo = JellyTopo(N=10, n=10, r=5,
        # topo = JellyTopo(N=5, n=4, r=3,
        graph_constructor=create_irregular_jellyfish_graph,
        verbose=True)
    if remote_control:
        net = Mininet(topo=None, build=False, host=CPULimitedHost, link=TCLink)
        net.addController('c0',
                          controller=RemoteController,
                          ip='127.0.0.1',
                          port=6633)
        net.buildFromTopo(topo)
    else:
        net = Mininet(topo=topo,
                      host=CPULimitedHost,
                      link=TCLink,
                      controller=JELLYPOX)

    print "Dumping switch connections"
    dumpNodeConnections(net.switches)

    # dhcp_script = create_dhcp_file(topo)
    # pdb.set_trace()
    net.start()
    # for i, h in enumerate(net.hosts):
    #     h.cmd('dhclient eth0')

    # CLI(net, script=dhcp_script)
    CLI(net)

    net.stop()
Exemple #9
0
 def buildFromTopo(self, *args, **kwargs):
     "Start network"
     info('*** Placing nodes\n')
     self.placeNodes()
     info('\n')
     Mininet.buildFromTopo(self, *args, **kwargs)
Exemple #10
0
                self.addLink(node, child)
        else:
            node = self.addHost("h%s" % self.hostNum)
            self.hostNum += 1
        return node


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

    topo = TreeTopo(depth=3, fanout=2)

    network = Mininet(switch=OVSKernelSwitch, controller=RemoteController)

    c0 = network.addController("c0", controller=RemoteController, ip="192.168.56.101", port=6633)

    network.buildFromTopo(topo)
    h1, h2, h3, h4, h5, h6, h7, h8 = network.getNodeByName("h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8")
    network.start()
    h1.cmd("iperf -s -u &")
    h8.cmd("iperf -c 10.0.0.1 -u -t 100 -b 10M &")
    h2.cmd("iperf -s -u &")
    h7.cmd("iperf -u -c 10.0.0.2 -t 100 -b 10M &")
    h3.cmd("iperf -s -u &")
    h6.cmd("iperf -u -c 10.0.0.3 -t 100 -b 10M &")
    h4.cmd("iperf -s -u &")
    h5.cmd("iperf -u -c 10.0.0.4 -t 100 -b 40M &")

    # network.run( CLI, network )
    CLI(network)
Exemple #11
0

if __name__ == '__main__':
    fname = "../samples/ExNetwithLoops1A.json"  # You can put your default file here
    remoteIP = "192.168.1.134"  # Put your default remote IP here
    # Using the nice Python argparse library to take in optional arguments
    # for file name and remote controller IP address
    parser = argparse.ArgumentParser()
    parser.add_argument("-f", "--fname", help="network graph file name")
    parser.add_argument("-ip",
                        "--remote_ip",
                        help="IP address of remote controller")
    args = parser.parse_args()
    if not args.fname:
        print "fname not specified using: {}".format(fname)
    else:
        fname = args.fname
    if not args.remote_ip:
        print "remote controller IP not specified using: {}".format(remoteIP)
    else:
        remoteIP = args.remote_ip
    topo = GraphTopoFixedAddrPorts.from_file(fname)
    lg.setLogLevel('info')
    network = Mininet(controller=RemoteController,
                      autoStaticArp=True,
                      link=TCLink)
    network.addController(controller=RemoteController, ip=remoteIP)
    network.buildFromTopo(topo=topo)
    network.start()
    CLI(network)
    network.stop()
Exemple #12
0
 def buildFromTopo( self, *args, **kwargs ):
     "Start network"
     info( '*** Placing nodes\n' )
     self.placeNodes()
     info( '\n' )
     Mininet.buildFromTopo( self, *args, **kwargs )
Exemple #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