Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 3
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()
Exemplo n.º 4
0
if __name__ == '__main__':
    setLogLevel( 'info' )
    info( '*** ns-3 network demo\n' )
    net = Mininet()

    info( '*** Creating Network\n' )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )

    net.hosts.append( h0 )
    net.hosts.append( h1 )
    net.hosts.append( h2 )

    wifi = WIFISegment()

    wifi.addAp( h0 )
    wifi.addSta( h1 )
    wifi.addSta( h2 )
    
    wifi.phyhelper.EnablePcap( "Ap-trace.pcap", h0.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()

Exemplo n.º 5
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)
Exemplo n.º 6
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()
Exemplo n.º 7
0
from mininet.ns3 import WIFISegment

import ns.core
import ns.wifi

if __name__ == '__main__':
    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()

    wifi.machelper.SetType("ns3::AdhocWifiMac")

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

    # set datarate for node h1
    wifi.wifihelper.SetRemoteStationManager(
        "ns3::ConstantRateWifiManager", "DataMode",
        ns.core.StringValue("OfdmRate6Mbps"))
    wifi.add(h1)
Exemplo n.º 8
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)
Exemplo n.º 9
0
import mininet.ns3
from mininet.ns3 import WIFISegment


if __name__ == '__main__':
    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()

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



    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()

Exemplo n.º 10
0
from mininet.link import Link, Intf
from mininet.log import setLogLevel, info
from mininet.cli import CLI

import mininet.ns3
from mininet.ns3 import WIFISegment

if __name__ == '__main__':
    setLogLevel('info')
    info('*** ns-3 network demo\n')
    net = Mininet()

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

    wifi.add(h0)
    wifi.add(h1)

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

    mininet.ns3.start()

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

    info('*** Nodes positions: \n')
    info('h0:', mininet.ns3.getPosition(h0), '\n')
Exemplo n.º 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)
Exemplo n.º 12
0
from mininet.log import setLogLevel, info
from mininet.cli import CLI

import mininet.ns3
from mininet.ns3 import WIFISegment


if __name__ == '__main__':
    setLogLevel( 'info' )
    info( '*** ns-3 network demo\n' )
    net = Mininet()

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

    wifi.add( h0 )
    wifi.add( h1 )



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

    mininet.ns3.start()


    info( '*** Testing network connectivity\n' )
    net.pingAll()
Exemplo n.º 13
0
from mininet.cli import CLI

import mininet.ns3
from mininet.ns3 import WIFISegment

if __name__ == '__main__':
    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()

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

    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('*** Network state:\n')
    for node in h0, h1, h2:
        info(str(node) + '\n')
Exemplo n.º 14
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()
Exemplo n.º 15
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')