Beispiel #1
0
def main():

    net = Mininet()
    net.addController("c0", controller=RemoteController, ip="127.0.0.1", port=6633)

    wifi = WifiSegment()

    # About AP
    ap0 = net.addAP("ap0")
    mininet.ns3.setMobilityModel(ap0, None)
    mininet.ns3.setPosition(ap0, 0, 0, 0)
    wifi.addAp(ap0, channelNumber=6, ssid="opennet_ap")

    # Check mininet.node.AP
    if isinstance(ap0, mininet.node.AP):
        print("I'm a AP")

    # About Station
    sta0 = net.addStation("sta0")
    mininet.ns3.setMobilityModel(sta0, None)
    mininet.ns3.setPosition(sta0, 0, 0, 0)
    wifi.addSta(sta0, channelNumber=6, ssid="opennet_ap")

    # Check mininet.node.Station
    if isinstance(sta0, mininet.node.Station):
        print("I'm a station")

    print("APs list: {0}\nSTAs list: {1}\n".format(wifi.aps, wifi.stas))

    # About OVSSwitch
    s0 = net.addSwitch("s0")

    # About Host
    h0 = net.addHost("h0", ip="1.1.1.1")

    # Ignore warning message: "defaultIntf: warning: h0 has no interfaces"
    net.addLink(s0, h0)

    print("Switches list: {0}\nHosts list: {1}\n".format(net.switches, net.hosts))

    mininet.ns3.start()
    net.start()

    mininet.ns3.stop()
    net.stop()
Beispiel #2
0
def main():

    net = Mininet()
    net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)

    sw0 = net.addSwitch('sw0', ip=None)

    ap0 = net.addAP('ap0', ip=None)
    mininet.ns3.setMobilityModel(ap0, None)
    mininet.ns3.setPosition(ap0, 0, 0, 0)

    ap1 = net.addAP('ap1', ip=None)
    mininet.ns3.setMobilityModel(ap1, None)
    mininet.ns3.setPosition(ap1, 10, 10, 0)

    sta0 = net.addStation('sta0', ip="10.0.0.1")
    mininet.ns3.setMobilityModel(sta0, None)
    mininet.ns3.setVelocity(sta0, 0, 5, 0)

    sta1 = net.addStation('sta1', ip="10.0.0.2")
    mininet.ns3.setMobilityModel(sta1, None)
    mininet.ns3.setVelocity(sta1, 5, 0, 0)

    wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)
    wifi.addAp(ap0, channelNumber=11, ssid="opennet_0")
    wifi.addAp(ap1, channelNumber=11, ssid="opennet_1")

    wifi.addSta(sta0, channelNumber=11, ssid="opennet_0")
    wifi.addSta(sta1, channelNumber=11, ssid="opennet_1")

    net.addLink(sw0, ap0)
    net.addLink(sw0, ap1)

    net.start()
    mininet.ns3.start()

    sta0.cmdPrint('ping -c2 ' + sta1.IP())
    sta1.cmdPrint('ping -c2 ' + sta0.IP())

    CLI(net)

    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
def demo():
    CONTROLLER_IP="192.168.59.100"
    CONTROLLER_PORT=6633
    servers = [ 'mininet1', 'mininet2' ]

    wifi = WifiSegment()
    net = MininetCluster( controller=RemoteController, servers=servers)
    c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT)

    # In mininet1
    # ap1
    ap1 = net.addSwitch('ap1')
    mininet.ns3.setMobilityModel(ap1, None)
    mininet.ns3.setPosition(ap1, 0, 0, 0)
    wifi.addAp(ap1, channelNumber=6, ssid="opennet_ap")

    # sta1
    sta1 = net.addHost('sta1', ip="10.0.0.1")
    mininet.ns3.setMobilityModel(sta1, None)
    mininet.ns3.setPosition(sta1, 0, 0, 0)
    wifi.addSta(sta1, channelNumber=6, ssid="opennet_ap")

    # In mininet2
    s2 = net.addSwitch('s2', server="mininet2")
    h2 = net.addHost('h2', ip="10.0.0.2", server="mininet2")
    net.addLink(s2, h2)

    # Cross-link between mininet1 and mininet2
    net.addLink(ap1, s2)

    net.start()
    mininet.ns3.start()

    print("Opennet is running on {hostname}".format(hostname=quietRun('hostname').strip()))
    for node in c0, ap1, sta1, h2, s2:
        print("Node {nodename} is running on {servername}".format(nodename=node, servername=node.cmd('hostname').strip()))

    net.pingAll()
    CLI( net )

    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
def main():
    net = Mininet()
    net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)
    natIP="10.0.0.220"
    cpu = 0.1

    wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)
    #Added for NAT
    hostConfig = {'cpu': cpu, 'defaultRoute': 'via ' + natIP }

    print("Building Switch")
    # About OVSSwitch
    s0 = net.addSwitch('s0', ip=None) 

    print ("Building APs")
    # About AP
    
    ap0 = net.addAP('ap0', ip=None)
    mininet.ns3.setMobilityModel(ap0, None)
    mininet.ns3.setPosition(ap0, 10, 0, 20)

    ap1 = net.addAP('ap1', ip=None)
    mininet.ns3.setMobilityModel(ap1, None)
    mininet.ns3.setPosition(ap1, 10, 10, 0)

    # Check mininet.node.AP
    if isinstance(ap0, mininet.node.AP):
        print("I'm AP 2")
    if isinstance(ap1, mininet.node.AP):
        print("I'm AP 1")   

    print("Building Hosts")
    # About Host
    #h0 = net.addHost('h0', ip="10.1.1.1")
    h0 = net.addHost('h0', mac='00:00:00:00:00:01', ip="10.0.0.1", **hostConfig)
    h1 = net.addHost('h1', mac='00:00:00:00:00:02', ip="10.0.0.2", **hostConfig)
    
    print "Building Stations"
    # About Station
##    sta0 = net.addStation('sta0', ip="10.1.1.5", **hostConfig)
    sta0 = net.addStation('sta0', ip='192.168.1.100/24',
                    defaultRoute='via 192.168.1.1')
    mininet.ns3.setMobilityModel(sta0, None)
    mininet.ns3.setPosition(sta0, 10, 0, 20)

##    sta1 = net.addStation('sta1', ip="10.1.1.6", **hostConfig)
    sta1 = net.addStation('sta1', ip='192.168.1.101/24',
                    defaultRoute='via 192.168.1.1')
    mininet.ns3.setMobilityModel(sta1, None)
    mininet.ns3.setPosition(sta1, 10, 0, 15)

##    sta2 = net.addStation('sta2', ip="10.1.1.7", **hostConfig)
    sta2 = net.addStation('sta2', ip='192.168.1.102/24',
                    defaultRoute='via 192.168.1.1')    
    mininet.ns3.setMobilityModel(sta2, None)
    mininet.ns3.setPosition(sta2, 10, 0, 25)
    
##    sta3 = net.addStation('sta3', ip="10.1.1.8", **hostConfig)
    sta3 = net.addStation('sta3', ip='192.168.2.100/24',
                    defaultRoute='via 192.168.2.1')
    mininet.ns3.setMobilityModel(sta3, None)
    mininet.ns3.setPosition(sta3, 10, 10, 0)
    
    sta4 = net.addStation('sta4', ip='192.168.2.101/24',
                    defaultRoute='via 192.168.2.1')
    mininet.ns3.setMobilityModel(sta4, None)
    mininet.ns3.setPosition(sta4, 10, 10, 5)
    
    sta5 = net.addStation('sta5', ip='192.168.2.102/24',
                    defaultRoute='via 192.168.2.1')
    mininet.ns3.setMobilityModel(sta5, None)
    mininet.ns3.setPosition(sta5, 10, 10, 10)
    #Check mininet.node.Station
    if isinstance(sta0, mininet.node.Station):
        print("I'm station 0")       
    if isinstance(sta1, mininet.node.Station):
        print("I'm station 1")        
    if isinstance(sta2, mininet.node.Station):
        print("I'm station 2")        
    if isinstance(sta3, mininet.node.Station):
        print("I'm station 3")
    if isinstance(sta4, mininet.node.Station):
        print("I'm station 4")
    if isinstance(sta5, mininet.node.Station):
        print("I'm station 5")   
        
    print("****Preparing to list devices***")
    print("APs list: {0}\nSTAs list: {1}\n".format(wifi.aps, wifi.stas))

    wifi.addAp(ap0, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta0, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta1, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta2, channelNumber=6, ssid="opennet_0")
    wifi.addAp(ap1, channelNumber=11, ssid="opennet_1")
    wifi.addSta(sta3, channelNumber=11,  ssid="opennet_1")
    wifi.addSta(sta4, channelNumber=11,  ssid="opennet_1")
    wifi.addSta(sta5, channelNumber=11,  ssid="opennet_1")    

    #Building NATs
    print("Building NAT")
    nat = net.addHost('nat', cls=NAT, mac='00:00:00:00:00:20', ip=natIP, inNamespace=False)
    nat1 = net.addHost('nat1', cls=NAT, mac='00:00:00:00:00:03', ip='10.0.0.3', subnet='192.168.1.0/24',
                       inetIntf='nat1-eth0', localIntf='nat1-eth1', **hostConfig)
    nat2 = net.addHost('nat2', cls=NAT, mac='00:00:00:00:00:04', ip='10.0.0.4', subnet='192.168.2.0/24',
                       inetIntf='nat2-eth0', localIntf='nat2-eth1', **hostConfig)

    print("Building Links")
    # Ignore warning message: "defaultIntf: warning: h0 has no interfaces"
    #add NAT link s0->nat, nat1->s0, nat2->s0, h0->s0, and h1->s0
    net.addLink(s0, nat)
    net.addLink(s0, nat1, intfName1='nat1-eth0')
    net.addLink(s0, nat2, intfName1='nat2-eth0')
    net.addLink(s0, h0)
    net.addLink(s0, h1)
    # ap0->na1 and ap1->nat2
    net.addLink(nat1, ap0, intfName1='nat1-eth1', params1={'ip' : '192.168.1.1/24'})
    net.addLink(nat2, ap1, intfName1='nat2-eth1', params1={'ip' : '192.168.2.1/24'})

##    print("Switches list: {0}\nHosts list: {1}\n".format(net.switches, net.hosts))

    info('***Starting Network***\n')
    mininet.ns3.start()
    net.start()
    
    info( 'Testing network connectivity\n' )
##    print ( '\n\nTesting h0 -> h1 \n\n' )
##    h0.cmdPrint( 'ping 10.1.1.2 -c2' )
##    print ( '\n\nTesting h0 -> sta0 \n\n')
##    h0.cmdPrint( 'ping 10.1.1.5 -c2' )    
##    print ( '\n\nTesting h0 -> sta1 \n\n')
##    h0.cmdPrint( 'ping 10.1.1.6 -c2' )
##    print ( '\n\nTesting h0 -> sta2 \n\n')
##    h0.cmdPrint( 'ping 10.1.1.7 -c2' )    
##    print ( '\n\nTesting h0 -> sta3 \n\n')
##    h0.cmdPrint( 'ping 10.1.1.8 -c2' )
##    print ( '\n\nTesting sta0 -> sta3 \n\n')    
##    sta0.cmdPrint('ping -c2 ' + sta3.IP())
##    sta0.cmdPrint('ping -c2 ' + sta2.IP())   
##    sta0.cmdPrint('ping -c2 ' + sta3.IP())

    CLI(net)

    mininet.ns3.stop()
    net.stop()
def main():

    net = Mininet()
    net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)

    wifi = WifiSegment()

    print "Building APs"
    # About AP
    ap0 = net.addAP('ap0', ip="10.1.1.3")
    mininet.ns3.setMobilityModel(ap0, None)
    mininet.ns3.setPosition(ap0, 0, 0, 0)
    wifi.addAp(ap0, channelNumber=11, ssid="opennet_ap")

    ap1 = net.addAP('ap1', ip="10.1.1.4")
    mininet.ns3.setMobilityModel(ap1, None)
    mininet.ns3.setPosition(ap1, 10, 10, 10)
    wifi.addAp(ap1, channelNumber=1, ssid="opennet_ap2")

    # Check mininet.node.AP
    if isinstance(ap0, mininet.node.AP):
        print("I'm an AP")
    if isinstance(ap1, mininet.node.AP):
        print("I'm an AP also")    

    print "Building Stations"
    # About Station
    sta0 = net.addStation('sta0', ip="10.1.2.1")
    mininet.ns3.setMobilityModel(sta0, None)
    mininet.ns3.setPosition(sta0, 0, 0, 0)
    wifi.addSta(sta0, channelNumber=11, ssid="opennet_ap")

    sta1 = net.addStation('sta1', ip="10.1.2.2")
    mininet.ns3.setMobilityModel(sta1, None)
    mininet.ns3.setPosition(sta1, 0, 0, 5)
    wifi.addSta(sta1, channelNumber=11, ssid="opennet_ap")

    sta2 = net.addStation('sta2', ip="10.1.2.3")
    mininet.ns3.setMobilityModel(sta2, None)
    mininet.ns3.setPosition(sta2, 0, 5, 0)
    wifi.addSta(sta2, channelNumber=11, ssid="opennet_ap")

    sta3 = net.addStation('sta3', ip="10.1.3.1")
    mininet.ns3.setMobilityModel(sta3, None)
    mininet.ns3.setPosition(sta3, 10, 10, 10)
    wifi.addSta(sta3, channelNumber=1, ssid="opennet_ap2")

    #Check mininet.node.Station
    if isinstance(sta0, mininet.node.Station):
        print("I'm a station")

    if isinstance(sta1, mininet.node.Station):
        print("I'm a station also")

    print("****Preparing to list devices***")

    print("APs list: {0}\nSTAs list: {1}\n".format(wifi.aps, wifi.stas))

    print("Building Switch")
    # About OVSSwitch
    s0 = net.addSwitch('s0')

    print("Building Hosts")
    # About Host
    h0 = net.addHost('h0', ip="10.1.1.1")
    h1 = net.addHost('h1', ip="10.1.1.2")

    print("Building Links")
    # Ignore warning message: "defaultIntf: warning: h0 has no interfaces"
    net.addLink(s0, h0)
    net.addLink(s0, h1)
    net.addLink(s0, ap0)
    net.addLink(s0, ap1)

    print("Switches list: {0}\nHosts list: {1}\n".format(net.switches, net.hosts))

    info('***Starting Network***\n')
    mininet.ns3.start()
    net.start()
    
    info( 'Testing network connectivity\n' )
    h0.cmdPrint( 'ping 10.1.1.2 -c3' )
    sta0.cmdPrint('ping -c2 ' + sta3.IP())
    sta1.cmdPrint('ping -c2 ' + sta3.IP())

    CLI(net)

    mininet.ns3.stop()
    net.stop()
def main():

    net = Mininet()
    net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)

    wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)

    print("Building Switch")
    # About OVSSwitch
    s0 = net.addSwitch('s0', ip=None)

    print("Building Hosts")
    # About Host
    h0 = net.addHost('h0', ip="10.1.1.1")
    h1 = net.addHost('h1', ip="10.1.1.2")    

    print ("Building APs")
    # About AP
    
    ap0 = net.addAP('ap0', ip=None)
    mininet.ns3.setMobilityModel(ap0, None)
    mininet.ns3.setPosition(ap0, 10, 0, 20)

    ap1 = net.addAP('ap1', ip=None)
    mininet.ns3.setMobilityModel(ap1, None)
    mininet.ns3.setPosition(ap1, 10, 10, 0)

    # Check mininet.node.AP
    if isinstance(ap0, mininet.node.AP):
        print("I'm AP 2")
    if isinstance(ap1, mininet.node.AP):
        print("I'm AP 1")    

    print "Building Stations"
    # About Station
    sta0 = net.addStation('sta0', ip="10.1.1.5")
    mininet.ns3.setMobilityModel(sta0, None)
    mininet.ns3.setPosition(sta0, 10, 0, 20)

    sta1 = net.addStation('sta1', ip="10.1.1.6")
    mininet.ns3.setMobilityModel(sta1, None)
    mininet.ns3.setPosition(sta1, 10, 0, 15)

    sta2 = net.addStation('sta2', ip="10.1.1.7")
    mininet.ns3.setMobilityModel(sta2, None)
    mininet.ns3.setPosition(sta2, 10, 0, 25)
    
    sta3 = net.addStation('sta3', ip="10.1.1.8")
    mininet.ns3.setMobilityModel(sta3, None)
    mininet.ns3.setPosition(sta3, 10, 10, 0)


    #Check mininet.node.Station
    if isinstance(sta0, mininet.node.Station):
        print("I'm station 0")
        
    if isinstance(sta1, mininet.node.Station):
        print("I'm station 1")        

    if isinstance(sta2, mininet.node.Station):
        print("I'm station 2")        

    if isinstance(sta3, mininet.node.Station):
        print("I'm station 3")

    print("****Preparing to list devices***")

    print("APs list: {0}\nSTAs list: {1}\n".format(wifi.aps, wifi.stas))

    print("Building Links")
    # Ignore warning message: "defaultIntf: warning: h0 has no interfaces"
    net.addLink(s0, h0)
    net.addLink(s0, h1)

    wifi.addAp(ap0, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta0, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta1, channelNumber=6, ssid="opennet_0")
    wifi.addSta(sta2, channelNumber=6, ssid="opennet_0")
    wifi.addAp(ap1, channelNumber=11, ssid="opennet_1")
    wifi.addSta(sta3, channelNumber=11,  ssid="opennet_1")

    net.addLink(s0, ap0)
    net.addLink(s0, ap1)
    
    print("Switches list: {0}\nHosts list: {1}\n".format(net.switches, net.hosts))

    info('***Starting Network***\n')
    mininet.ns3.start()
    net.start()
    
    info( 'Testing network connectivity\n' )
    print ( '\n\nTesting h0 -> h1 \n\n' )
    h0.cmdPrint( 'ping 10.1.1.2 -c2' )
    print ( '\n\nTesting h0 -> sta0 \n\n')
    h0.cmdPrint( 'ping 10.1.1.5 -c2' )    
    print ( '\n\nTesting h0 -> sta1 \n\n')
    h0.cmdPrint( 'ping 10.1.1.6 -c2' )
    print ( '\n\nTesting h0 -> sta2 \n\n')
    h0.cmdPrint( 'ping 10.1.1.7 -c2' )    
    print ( '\n\nTesting h0 -> sta3 \n\n')
    h0.cmdPrint( 'ping 10.1.1.8 -c2' )
    print ( '\n\nTesting sta0 -> sta3 \n\n')    
    sta0.cmdPrint('ping -c2 ' + sta3.IP())
##    sta0.cmdPrint('ping -c2 ' + sta2.IP())   
##    sta0.cmdPrint('ping -c2 ' + sta3.IP())

    CLI(net)

    mininet.ns3.stop()
    net.stop()