Exemple #1
0
def main():

    net = Mininet()
    """ Uncomment following lines to add controller """
    # net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)

    sw0 = net.addSwitch('sw0', ip=None, failMode='standalone')
    ap0 = net.addSwitch('ap0', ip=None, failMode='standalone')
    ap1 = net.addSwitch('ap1', ip=None, failMode='standalone')
    sta0 = net.addHost('sta0', ip="10.0.0.1")
    sta1 = net.addHost('sta1', ip="10.0.0.2")

    wifi = WIFISegment()
    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()
Exemple #2
0
def emptyNet():
 
    "Create an empty network and add nodes to it."
    "[h1]<---wifi-network---> [h0:AP] <---wired-link ---> [s0] <---wired-link--->[h3]"
    "[h2]<---wifi-network--->         "

    net = Mininet( controller=OVSController )

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

    info( '*** Adding switch\n' )
    s0 = net.addSwitch( 's0' )
    s0.listenPort = 6634

    h0 = net.addHost( 'h0' ) 
    h1 = net.addHost( 'h1', ip='192.168.0.2' ) 
    h2 = net.addHost( 'h2', ip='192.168.0.3' ) 
    h3 = net.addHost( 'h3', ip='10.0.0.2' ) 
    linkopts=dict( bw=100, delay='1ms', loss=0 )
    TCLink( s0, h3, **linkopts )
    TCLink( h0, s0, **linkopts )
    
    wifi = WIFISegment()

    wifi.addAp( h0 )
    wifi.addSta( h1 )
    wifi.addSta( h2 )

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

    h0.cmdPrint ( "ifconfig h0-eth0 10.0.0.1 netmask 255.255.255.0" )
    h0.cmdPrint ( "ifconfig h0-eth1 192.168.0.1 netmask 255.255.255.0" )
    h0.cmdPrint ( "sudo echo 1 > /proc/sys/net/ipv4/ip_forward" )
    h1.cmdPrint ( "route add default gw 192.168.0.1" )
    h2.cmdPrint ( "route add default gw 192.168.0.1" )
    h3.cmdPrint ( "route add default gw 10.0.0.1" )
 
    info( '*** Testing network connectivity\n' )
    net.pingAll()

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

    info( '*** Stopping network' )
    mininet.ns3.stop()
    mininet.ns3.clear()                     # line added
    net.stop()
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()
Exemple #4
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 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()
Exemple #6
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()
Exemple #7
0
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()
Exemple #8
0
def staticEventNet():

    net = Mininet()

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

    sw0 = net.addSwitch('sw0', ip=None, failMode='standalone')
    ap0 = net.addSwitch('ap0', ip=None, failMode='standalone')
    ap1 = net.addSwitch('ap1', ip=None, failMode='standalone')
    ap2 = net.addSwitch('ap2', ip=None, failMode='standalone')

    info('*** Creating Network\n')
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    wifi = WIFISegment()
    wifi.addAp(ap0, channelNumber=11, ssid="opennet_0")
    wifi.addAp(ap1, channelNumber=11, ssid="opennet_1")
    wifi.addAp(ap2, channelNumber=11, ssid="opennet_2")

    wifi.addAdhoc(h0)
    wifi.addAdhoc(h1)
    wifi.addAdhoc(h2)

    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')

    mininet.ns3.setPosition(ap0, 100, 100, 100)
    mininet.ns3.setPosition(ap1, 200, 100, 100)
    mininet.ns3.setPosition(ap2, 300, 100, 100)

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

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

    print(mininet.ns3.getPosition(ap0))

    CLI(net)

    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
Exemple #9
0
def Start(GI=False, MCS=2, Bandwidth=20, UDP=True, TP=20, PCAP=False):
    setLogLevel('info')
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    h4 = net.addHost('h4')
    h5 = net.addHost('h5')

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    gi = GI  #0,1
    bandwidth = Bandwidth  #20,40,80
    mcs = MCS  #2,4,7

    if udp == False:
        #TCP
        payloadSize = 1448  #bytes
        ns.core.Config.SetDefault("ns3::TcpSocket::SegmentSize",
                                  ns.core.UintegerValue(payloadSize))
    else:
        payloadSize = 1472

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211ac)

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))

    DataRate = "VhtMcs" + str(mcs)

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                            "DataMode",
                                            ns.core.StringValue(DataRate),
                                            "ControlMode",
                                            ns.core.StringValue(DataRate))

    wifi.machelper = ns.wifi.WifiMacHelper()

    Sssid = "wifi-80211ac"

    wifi.addSta(h0, ssid=Sssid)
    wifi.addSta(h1, ssid=Sssid)
    wifi.addSta(h2, ssid=Sssid)
    wifi.addSta(h3, ssid=Sssid)
    wifi.addSta(h4, ssid=Sssid)
    wifi.addAp(h5, ssid=Sssid)

    # set channel bandwidth
    ns.core.Config.Set(
        "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth",
        ns.core.UintegerValue(bandwidth))

    if PCAP == True:
        wifi.phyhelper.EnablePcap("80211ac_Sta1.pcap", h0.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211ac_Sta2.pcap", h1.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211ac_Sta3.pcap", h2.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211ac_Sta4.pcap", h3.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211ac_Sta5.pcap", h4.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211ac_Ap.pcap", h5.nsNode.GetDevice(0),
                                  True, True)

    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')
    h3.setIP('192.168.123.4/24')
    h4.setIP('192.168.123.5/24')
    h5.setIP('192.168.123.6/24')

    mininet.ns3.start()

    #info( '\n *** Testing network connectivity\n' )
    net.pingFull([h0, h5])
    #net.pingFull([h1,h2])
    #net.pingFull([h0,h1])
    info('*** Starting UDP iperf server on AP(h5)\n')
    h5.sendCmd("iperf -s -i 1 -u")
    info('*** Testing bandwidth between h0 and h5 none is transmitting\n')
    val = "iperf -c 192.168.123.6 -u -b " + str(TP) + "M"
    h0.cmdPrint(val)
    info(
        '*** Testing bandwidth between h0 and h5 while everyone transmitting\n'
    )
    val = "iperf -c 192.168.123.6 -u -b " + str(TP) + "M"
    h1.sendCmd(val)
    h2.sendCmd(val)
    h3.sendCmd(val)
    h0.sendCmd(val)
    h4.cmdPrint(val)
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()
Exemple #11
0
def Start(OFDM_R=9, UDP=True, TP=9, PCAP=False):
    setLogLevel('info')
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    h4 = net.addHost('h4')
    h5 = net.addHost('h5')

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    bandwidth = 20
    ofdm_r = "OfdmRate" + str(OFDM_R) + "Mbps"
    OfdmRate = ofdm_r  #9,24,48
    if udp == False:
        #TCP
        payloadSize = 1448  #bytes
        ns.core.Config.SetDefault("ns3::TcpSocket::SegmentSize",
                                  ns.core.UintegerValue(payloadSize))
    else:
        payloadSize = 1472

    wifi = WIFISegment()

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211a)

    wifi.wifihelper.SetRemoteStationManager(
        "ns3::ConstantRateWifiManager", "DataMode",
        ns.core.StringValue(OfdmRate), "ControlMode",
        ns.core.StringValue("OfdmRate9Mbps"))

    Sssid = "wifi-80211a"

    wifi.addSta(h0, ssid=Sssid)
    wifi.addSta(h1, ssid=Sssid)
    wifi.addSta(h2, ssid=Sssid)
    wifi.addSta(h3, ssid=Sssid)
    wifi.addSta(h4, ssid=Sssid)
    wifi.addAp(h5, ssid=Sssid)

    # set channel bandwidth
    ns.core.Config.Set(
        "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth",
        ns.core.UintegerValue(bandwidth))

    if PCAP == True:
        wifi.phyhelper.EnablePcap("80211a_sta1.pcap", h0.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211a_sta2.pcap", h1.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211a_sta3.pcap", h2.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211a_sta4.pcap", h3.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211a_sta5.pcap", h4.nsNode.GetDevice(0),
                                  True, True)
        wifi.phyhelper.EnablePcap("80211a_ap.pcap", h5.nsNode.GetDevice(0),
                                  True, True)

    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')
    h3.setIP('192.168.123.4/24')
    h4.setIP('192.168.123.5/24')
    h5.setIP('192.168.123.6/24')

    mininet.ns3.start()

    #info( '\n *** Testing network connectivity\n' )
    net.pingFull([h0, h5])
    #net.pingFull([h1,h2])
    #net.pingFull([h0,h1])
    info('*** Starting UDP iperf server on AP(h5)\n')
    h5.sendCmd("iperf -s -i 1 -u")
    info(
        '*** Testing bandwidth between h0 and h5 while others stas are not transmitting\n'
    )
    val = "iperf -c 192.168.123.6 -u -b " + str(TP) + "M"
    h0.cmdPrint(val)
    info(
        '*** Testing bandwidth between h0 and h5 while all stats are also transmitting\n'
    )
    val = "iperf -c 192.168.123.6 -u -b " + str(TP) + "M"
    h0.sendCmd(val)
    h1.sendCmd(val)
    h2.sendCmd(val)
    h3.sendCmd(val)
    h4.cmdPrint(val)
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()
Exemple #13
0
def Start(GI=False, MCS=3, Bandwidth=40, UDP=True, TP=54, PCAP=False):
    setLogLevel('info')
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost('h0')
    #h1 = net.addHost( 'h1' )
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    h4 = net.addHost('h4')
    #h5 = net.addHost( 'h5' )
    #h6 = net.addHost( 'h6' )
    h7 = net.addHost('h7')
    h8 = net.addHost('h8')

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    gi = GI  #0,1
    bandwidth = Bandwidth  #20,40,80
    mcs = MCS  #2,4,7

    # if udp == False:
    #     #TCP
    #     payloadSize = 1448  #bytes
    #     ns.core.Config.SetDefault ("ns3::TcpSocket::SegmentSize", ns.core.UintegerValue (payloadSize))
    # else:
    #     payloadSize = 1472

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211ac)

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))

    DataRate = "VhtMcs" + str(mcs)

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                            "DataMode",
                                            ns.core.StringValue(DataRate),
                                            "ControlMode",
                                            ns.core.StringValue("VhtMcs0"))

    wifi.machelper = ns.wifi.WifiMacHelper()

    #wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager",
    #                                         "DataMode", ns.core.StringValue ("VhtMcs8"), "ControlMode", ns.core.StringValue ("VhtMcs8") )

    Sssid = "wifi-80211acCA"

    wifi.addSta(h0, ext="ac", ssid=Sssid, port=9977, qosSupported=True)
    wifi.addSta(h3, ext="ac", ssid=Sssid, port=9998, qosSupported=True)
    wifi.addSta(h4, ext="ac", ssid=Sssid, port=9994, qosSupported=True)
    #wifi.addSta( h5,ext="ac", ssid=Sssid, port=9993, qosSupported=True)
    #wifi.addSta( h6,ext="ac", ssid=Sssid, port=9992, qosSupported=True)
    wifi.addSta(h7, ext="ac", ssid=Sssid, port=9977, qosSupported=True)
    wifi.addSta(h8, ext="ac", ssid=Sssid, port=9966, qosSupported=True)

    wifi.addAp(h2, ext="ac", ssid=Sssid, port=9999, qosSupported=True)

    # set channel bandwidth
    ns.core.Config.Set(
        "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth",
        ns.core.UintegerValue(bandwidth))

    if PCAP == True:
        wifi.phyhelper.SetPcapDataLinkType(
            ns.wifi.WifiPhyHelper.DLT_IEEE802_11_RADIO)
        wifi.phyhelper.EnablePcap("80211ac_Sta1.pcap", h0.nsNode.GetDevice(0),
                                  True, True)
        #wifi.phyhelper.EnablePcap( "Ap-h1.pcap", h1.nsNode.GetDevice( 1 ), True, True );
        wifi.phyhelper.EnablePcap("80211ac_Ap.pcap", h2.nsNode.GetDevice(0),
                                  True, True)

    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    h2.setIP('192.168.123.3/24')
    h3.setIP('192.168.123.4/24')
    h4.setIP('192.168.123.5/24')
    #h5.setIP('192.168.123.6/24')
    #h6.setIP('192.168.123.7/24')
    h7.setIP('192.168.123.8/24')
    h8.setIP('192.168.123.9/24')

    mininet.ns3.start()

    time.sleep(2)

    info('\n *** Testing network connectivity\n')
    #net.pingFull()

    info('*** Start capturing pcaps\n')
    #h0.cmd("tcpdump -i h0-eth9998 -w h0_test.pcap & ")
    h2.cmd("tcpdump -i h2-eth9999 -w h2_test_multiSTA.pcap & ")

    time.sleep(2)

    # info( '*** Video measurement\n' )
    h0.cmd("iperf3 -s -i 1 -p 9999 --cport 9999 | tee sta_VI_CBR_h0.txt &")
    time.sleep(2)
    val = "iperf3 -c 192.168.123.1 -b 20m -M 1024 -Z -p 9999 -t 30 -i 1 --cport 9999 -S 0x4 &"
    h2.cmd(val)

    time.sleep(3)

    info('*** Voice measurement\n')
    h3.cmd("iperf3 -s -i 1 -p 9998 | tee sta_VO_CBR_h3.txt &")
    h2.cmd("iperf3 -s -i 1 -p 9989 | tee ap_VO_CBR_h4.txt &")
    h4.cmd("iperf3 -s -i 1 -p 9994 | tee sta_VO_CBR_h4.txt &")
    #h2.cmd( "iperf3 -s -i 1 -p 9949 | tee ap_VO_CBR_h5.txt &" )
    # h5.cmd( "iperf3 -s -i 1 -p 9993 | tee sta_VO_CBR_h5.txt &" )
    #h2.cmd( "iperf3 -s -i 1 -p 9939 | tee ap_VO_CBR_h6.txt &" )
    # h6.cmd( "iperf3 -s -i 1 -p 9992 | tee sta_VO_CBR_h6.txt &" )
    h2.cmd("iperf3 -s -i 1 -p 9929 | tee ap_VO_CBR_h3.txt &")

    time.sleep(2)

    val = "iperf3 -c 192.168.123.4 -u -b 64k -Z --length 160 -p 9998 -t 25 -i 1 --cport 9998 -S 0x6 &"
    h2.cmd(val)
    val = "iperf3 -c 192.168.123.3 -u -b 64k -Z --length 160 -p 9929 -t 25 -i 1 --cport 9929 -S 0x6 &"
    h3.cmd(val)
    # val = "iperf3 -c 192.168.123.7 -u -b 64k -Z --length 160 -p 9992 -t 25 -i 1 --cport 9992 -S 0x6 &"
    # h2.cmd(val)
    #val = "iperf3 -c 192.168.123.3 -u -b 6.4m -Z --length 160 -p 9939 -t 25 -i 1 --cport 9939 -S 0x6 &"
    #h6.cmd(val)
    # val = "iperf3 -c 192.168.123.6 -u -b 64k -Z --length 160 -p 9993 -t 25 -i 1 --cport 9993 -S 0x6 &"
    # h2.cmd(val)
    #val = "iperf3 -c 192.168.123.3 -u -b 6.4m -Z --length 160 -p 9949 -t 25 -i 1 --cport 9949 -S 0x6 &"
    #h5.cmd(val)
    val = "iperf3 -c 192.168.123.5 -u -b 64k -Z --length 160 -p 9994 -t 25 -i 1 --cport 9994 -S 0x6 &"
    h2.cmd(val)
    val = "iperf3 -c 192.168.123.3 -u -b 64k -Z --length 160 -p 9989 -t 25 -i 1 --cport 9989 -S 0x6 &"
    h4.cmd(val)

    time.sleep(3)

    info('*** BE&BK measurement\n')
    h7.cmd("iperf3 -s -i 1 -p 9977 | tee sta_BE_CBR_h7.txt &")
    h2.cmd("iperf3 -s -i 1 -p 9979 | tee ap_BE_CBR_h8.txt &")
    h8.cmd("iperf3 -s -i 1 -p 9966 | tee sta_BK_CBR_h8.txt &")
    h2.cmd("iperf3 -s -i 1 -p 9969 | tee ap_BK_CBR_h7.txt &")

    time.sleep(2)

    val = "iperf3 -c 192.168.123.3 -M 750 -l 750 -Z -b 250k -p 9969 -t 20 --cport 9666 -i 1 -S 0x1 &"
    h7.cmd(val)
    val = "iperf3 -c 192.168.123.9 -M 750 -l 750 -Z -b 250k -p 9966 -t 20 --cport 9996 -i 1 -S 0x1 &"
    h2.cmd(val)
    val = "iperf3 -c 192.168.123.3 -M 501 -l 501 -Z -b 161k -p 9979 -t 20 --cport 9777 -i 1 -S 0x0 &"
    h8.cmd(val)
    val = "iperf3 -c 192.168.123.8 -M 501 -l 501 -Z -b 161k -p 9977 -t 20 --cport 9997 -i 1 -S 0x0 &"
    h2.cmd(val)

    time.sleep(10)
    #CLI(net)

    info("***Ending TCPDump and cleaning up***\n")
    h3.cmd("killall tcpdump")
    h4.cmd("killall tcpdump")
    #h5.cmd("killall tcpdump")
    #h6.cmd("killall tcpdump")
    h2.cmd("killall tcpdump")
    h0.cmd("killall tcpdump")
    h7.cmd("killall tcpdump")
    h8.cmd("killall tcpdump")

    h3.cmd("killall iperf3")
    h4.cmd("killall iperf3")
    #h5.cmd("killall iperf3")
    #h6.cmd("killall iperf3")
    h2.cmd("killall iperf3")
    h0.cmd("killall iperf3")
    h7.cmd("killall iperf3")
    h8.cmd("killall iperf3")

    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
Exemple #14
0
def WifiNet():

    net = Mininet()
    """ Uncomment following lines to add controller """
    # info( '*** Adding controller\n' )
    # net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633 )
    """ Initialize WifiSegment
        Reference mininet/ns3.py for more detail of WIFISegment class """
    wifi = WIFISegment()
    """ Node names """
    hosts = ['h1', 'h2']
    switches = ['s1', 's2', 's3', 's4', 's5', 's6', 's7']
    """ Links between APs """
    links = [['s1', 's2'], ['s1', 's3'], ['s1', 's4'], ['s1', 's5'],
             ['s1', 's6'], ['s1', 's7']]
    """ IP address of hosts """
    ip = {'h1': '10.0.0.1', 'h2': '10.0.0.2'}
    """ Wi-Fi channels """
    channels = {
        'h1': 1,
        'h2': 11,
        's1': 1,
        's2': 6,
        's3': 11,
        's4': 11,
        's5': 6,
        's6': 11,
        's7': 11
    }
    """ This rectangle is the bounds of mobility model """
    rectangle = ns.mobility.RectangleValue(
        ns.mobility.Rectangle(-150, 150, -150, 150))
    """ The mobility helpers of hosts """
    mobility_helpers = {
        'h1':
        mininet.ns3.createMobilityHelper("ns3::RandomWalk2dMobilityModel",
                                         n0="Bounds",
                                         v0=rectangle),
        'h2':
        mininet.ns3.createMobilityHelper("ns3::RandomWalk2dMobilityModel",
                                         n0="Bounds",
                                         v0=rectangle)
    }

    list_position = {
        'h1': mininet.ns3.createListPositionAllocate(x1=0, y1=10, z1=0),
        'h2': mininet.ns3.createListPositionAllocate(x1=150, y1=30, z1=0)
    }
    """ Mobility models of hosts """
    mobility_models = {
        'h1':
        mininet.ns3.setListPositionAllocate(mobility_helpers['h1'],
                                            list_position['h1']),
        'h2':
        mininet.ns3.setListPositionAllocate(mobility_helpers['h2'],
                                            list_position['h2'])
    }
    """ Positions of APs """
    positions = {
        's1': (0, 0, 0),
        's2': (120, 0, 0),
        's3': (60, 60 * (3**0.5), 0),
        's4': (60, -60 * (3**0.5), 0),
        's5': (-120, 0, 0),
        's6': (-60, 60 * (3**0.5), 0),
        's7': (-60, -60 * (3**0.5), 0)
    }
    """ Container of nodes """
    nodes = {}
    """ Initialize Stations """
    for host in hosts:
        node = net.addHost(host, ip=ip[host])
        mininet.ns3.setMobilityModel(node, mobility_models.get(host))
        wifi.addSta(node, channelNumber=channels.get(host), ssid='opennet')
        nodes[host] = node
    """ Initialize APs """
    for switch in switches:
        node = net.addSwitch(switch, ip=None, failMode='standalone')
        mininet.ns3.setMobilityModel(node, None)
        pos_tuple = positions.get(switch)
        mininet.ns3.setPosition(node, pos_tuple[0], pos_tuple[1], pos_tuple[2])
        wifi.addAp(node, channelNumber=channels.get(switch), ssid='opennet')
        nodes[switch] = node
    """ Add links between APs """
    for link in links:
        name1, name2 = link[0], link[1]
        node1, node2 = nodes[name1], nodes[name2]
        net.addLink(node1, node2)
    """ Enable Pcap output """
    pcap = Pcap()
    pcap.enable()
    print pcap
    """ Enable netanim output """
    anim = Netanim("/tmp/xml/wifi-wired-bridged4.xml", nodes)
    print anim
    """ Update node descriptions in the netanim """
    for key in nodes.keys():
        node = nodes[key]
        description = "{0}-{1}".format(str(node), str(node.nsNode.GetId()))
        anim.UpdateNodeDescription(node.nsNode, description)
        if isinstance(node, OVSSwitch):
            color = (0, 255, 0)
        elif isinstance(node, Host):
            color = (0, 0, 255)
        anim.UpdateNodeColor(node.nsNode, color[0], color[1], color[2])
    """ Start the simulation """
    info('*** Starting network\n')
    net.start()
    mininet.ns3.start()

    info('Testing network connectivity\n')
    nodes['h1'].cmdPrint('ping 10.0.0.2 -c 3')

    CLI(net)

    info('*** Stopping network\n')
    mininet.ns3.stop()
    info('*** mininet.ns3.stop()\n')
    mininet.ns3.clear()
    info('*** mininet.ns3.clear()\n')
    net.stop()
    info('*** net.stop()\n')
Exemple #15
0
def Start(GI=False, MCS=3, Bandwidth=40, UDP=True, TP=54, PCAP=False):
    setLogLevel('info')
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost('h0')
    #h1 = net.addHost( 'h1' )
    h2 = net.addHost('h2')

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    gi = GI  #0,1
    bandwidth = Bandwidth  #20,40,80
    mcs = MCS  #2,4,7

    # ns.core.Config.SetDefault ("ns3::TcpSocket::SegmentSize", ns.core.UintegerValue (payloadSize))

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211ac)

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))

    DataRate = "VhtMcs" + str(mcs)

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                            "DataMode",
                                            ns.core.StringValue(DataRate),
                                            "ControlMode",
                                            ns.core.StringValue(DataRate))

    wifi.machelper = ns.wifi.WifiMacHelper()

    Sssid = "wifi-80211ac"

    wifi.addSta(h0, ssid=Sssid, qosSupported=True, ext="ac")
    wifi.addAp(h2, ssid=Sssid, qosSupported=True, ext="ac")

    # mininet.ns3.setPosition( h0, 10.0, 10.0, 0.0)
    # mininet.ns3.setPosition( h2, 5.0, 5.0, 0.0)

    # set channel bandwidth
    ns.core.Config.Set(
        "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth",
        ns.core.UintegerValue(bandwidth))

    if PCAP == True:
        wifi.phyhelper.SetPcapDataLinkType(
            ns.wifi.WifiPhyHelper.DLT_IEEE802_11_RADIO)
        wifi.phyhelper.EnablePcap("Scen1_STA_VLCNS3MN.pcap",
                                  h0.nsNode.GetDevice(0), True, True)
        #wifi.phyhelper.EnablePcap( "Ap-h1.pcap", h1.nsNode.GetDevice( 1 ), True, True );
        wifi.phyhelper.EnablePcap("Scen1_AP_VLCNS3MN.pcap",
                                  h2.nsNode.GetDevice(0), True, True)

    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    #h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')

    ns.core.Config.SetDefault("ns3::ConfigStore::Filename",
                              ns.core.StringValue("output-attr.xml"))
    ns.core.Config.SetDefault("ns3::ConfigStore::FileFormat",
                              ns.core.StringValue("Xml"))
    ns.core.Config.SetDefault("ns3::ConfigStore::Mode",
                              ns.core.StringValue("Save"))
    outputConfig = ns.config_store.ConfigStore()
    outputConfig.ConfigureDefaults()
    outputConfig.ConfigureAttributes()

    mininet.ns3.start()

    h2.cmd("iptables -t mangle -N mark-tos")
    h2.cmd("iptables -t mangle -A OUTPUT -j mark-tos")
    h2.cmd(
        "iptables -t mangle -A mark-tos -p tcp --sport 5004 -j TOS --set-tos 0x05"
    )
    h2.cmd(
        "iptables -t mangle -A mark-tos -p tcp --dport 5004 -j TOS --set-tos 0x05"
    )
    h2.cmd(
        "iptables -t mangle -A mark-tos -p tcp --sport 5005 -j TOS --set-tos 0x04"
    )
    h2.cmd(
        "iptables -t mangle -A mark-tos -p tcp --dport 5005 -j TOS --set-tos 0x04"
    )

    h0.cmd("iptables -t mangle -N mark-tos")
    h0.cmd("iptables -t mangle -A OUTPUT -j mark-tos")
    h0.cmd(
        "iptables -t mangle -A mark-tos -p tcp --sport 5004 -j TOS --set-tos 0x05"
    )
    h0.cmd(
        "iptables -t mangle -A mark-tos -p tcp --dport 5004 -j TOS --set-tos 0x05"
    )
    h0.cmd(
        "iptables -t mangle -A mark-tos -p tcp --sport 5005 -j TOS --set-tos 0x04"
    )
    h0.cmd(
        "iptables -t mangle -A mark-tos -p tcp --dport 5005 -j TOS --set-tos 0x04"
    )

    h0.cmd("ifconfig h0-eth0 mtu 1452 ")
    h2.cmd("ifconfig h2-eth0 mtu 1452 ")

    info('*** Testing network connectivity \n')
    h0.cmdPrint("ping 192.168.123.3 -c 3")

    # info( '*** Testing network connectivity\n' )
    # h0.cmd("tcpdump -i h0-eth0 -w h0_test.pcap & ")
    # h2.cmd("tcpdump -i h2-eth0 -w h2_test.pcap & ")

    #info( '***Position of our architecture***\n')
    #info( 'STA:', mininet.ns3.getPosition( h0 ), '\n')
    #info( 'AP:', mininet.ns3.getPosition( h2 ), '\n')

    info('**Opening stream of Video Bunny Rabbit in HQ from AP to STA***\n')
    h2.cmd(
        " $(echo Y3ZsYyBmaWxlOi8vL2hvbWUvb3Nib3hlcy9Eb3dubG9hZHMvYmJiX3N1bmZsb3dlcl8yMTYwcF82MGZwc19ub3JtYWwubXA0IC0tc291dD0jaHR0cHttdXg9ZmZtcGVne211eD1mbHZ9LGRzdD06NTAwNC99IC0tbm8tc291dC1hbGwgLS1zb3V0LWtlZXAK | base64 -d) &"
    )

    time.sleep(0.5)

    info('**Opening HTTP stream on STA***\n')
    #Use h0 vlc-wrapper to open VLC on host 0
    h0.cmdPrint("cvlc http://192.168.123.3:5004/ &")

    time.sleep(40)

    info("***Ending TCPDump and cleaning up***\n")
    h0.cmd("killall tcpdump")
    h2.cmd("killall tcpdump")
    h0.cmd("pkill -9 vlc")
    h2.cmd("pkill -9 vlc")

    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
Exemple #16
0
def Start(GI=False, MCS=2, Bandwidth=20, UDP=True, TP=20, PCAP=False):
    setLogLevel( 'info' )
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost( 'h0' )
    #h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2' )

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    gi = GI #0,1
    bandwidth = Bandwidth #20,40
    mcs = MCS #2,4,7
 
    info( '*** Creating Network\n' )
    h0 = net.addHost( 'h0' )
    #h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2' )

    if udp == False:
        #TCP
        payloadSize = 1448  #bytes
        ns.core.Config.SetDefault ("ns3::TcpSocket::SegmentSize", ns.core.UintegerValue (payloadSize))
    else:
        payloadSize = 1472

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211n_5GHZ)

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))
    
    wifi.machelper = ns.wifi.WifiMacHelper ()
    
    DataRate = "HtMcs"+str(mcs)

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager",
                                             "DataMode", ns.core.StringValue (DataRate), "ControlMode", ns.core.StringValue ("HtMcs0") )
    
        
    Sssid = "wifi-80211n"
    wifi.addSta( h0, ext="n", ca=True, ssid=Sssid )

    wifi.addAp( h2, ext="n", ca=True, ssid=Sssid  )

    # set channel bandwidth
    ns.core.Config.Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns.core.UintegerValue (bandwidth))
    
    if PCAP == True:
        wifi.phyhelper.EnablePcap( "80211nCA_Sta1.pcap", h0.nsNode.GetDevice( 0 ), True, True );
        #wifi.phyhelper.EnablePcap( "Ap-h1.pcap", h1.nsNode.GetDevice( 1 ), True, True );
        wifi.phyhelper.EnablePcap( "80211nCA_Ap.pcap", h2.nsNode.GetDevice( 0 ), True, True );
   
    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    #h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')

    mininet.ns3.start()

    info( '\n *** Testing network connectivity\n' )
    h0.cmdPrint("ping 192.168.123.3 -c 10")
    info( '*** Testing bandwidth between h0 and h2 while h1 is not transmitting\n' )
    h2.sendCmd( "iperf -s -i 1 -u" )
    val = "iperf -c 192.168.123.3 -u -b "+str(TP)+"M"
    h0.cmdPrint(val)
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()