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