Last active
August 2, 2016 09:13
-
-
Save songritk/9277b7267f7755b3a71cf7a35c55b6d5 to your computer and use it in GitHub Desktop.
scbc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | |
/* | |
* Copyright (c) 2009 The Boeing Company | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License version 2 as | |
* published by the Free Software Foundation; | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
* | |
*/ | |
// | |
// This script configures two nodes on an 802.11b physical layer, with | |
// 802.11b NICs in infrastructure mode, and by default, the station sends | |
// one packet of 1000 (application) bytes to the access point. The | |
// physical layer is configured | |
// to receive at a fixed RSS (regardless of the distance and transmit | |
// power); therefore, changing position of the nodes has no effect. | |
// | |
// There are a number of command-line options available to control | |
// the default behavior. The list of available command-line options | |
// can be listed with the following command: | |
// ./waf --run "wifi-simple-infra --help" | |
// | |
// For instance, for this configuration, the physical layer will | |
// stop successfully receiving packets when rss drops below -97 dBm. | |
// To see this effect, try running: | |
// | |
// ./waf --run "wifi-simple-infra --rss=-97 --numPackets=20" | |
// ./waf --run "wifi-simple-infra --rss=-98 --numPackets=20" | |
// ./waf --run "wifi-simple-infra --rss=-99 --numPackets=20" | |
// | |
// Note that all ns-3 attributes (not just the ones exposed in the below | |
// script) can be changed at command line; see the documentation. | |
// | |
// This script can also be helpful to put the Wifi layer into verbose | |
// logging mode; this command will turn on all wifi logging: | |
// | |
// ./waf --run "wifi-simple-infra --verbose=1" | |
// | |
// When you are done, you will notice two pcap trace files in your directory. | |
// If you have tcpdump installed, you can try this: | |
// | |
// tcpdump -r wifi-simple-infra-0-0.pcap -nn -tt | |
// | |
#include "ns3/core-module.h" | |
#include "ns3/network-module.h" | |
#include "ns3/mobility-module.h" | |
#include "ns3/config-store-module.h" | |
#include "ns3/wifi-module.h" | |
#include "ns3/internet-module.h" | |
#include "ns3/csma-module.h" | |
#include "ns3/applications-module.h" | |
#include "ns3/stats-module.h" | |
#include "ns3/flow-monitor-module.h" | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <string> | |
using namespace ns3; | |
NS_LOG_COMPONENT_DEFINE ("scbc"); | |
// packet size generated at the AP | |
static const uint32_t packetSize = 1000; | |
class NodeStatistics | |
{ | |
public: | |
NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas); | |
void CheckStatistics (double time); | |
void PhyCallback (std::string path, Ptr<const Packet> packet); | |
void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from); | |
void PowerCallback (std::string path, uint8_t power, Mac48Address dest); | |
void RateCallback (std::string path, uint32_t rate, Mac48Address dest); | |
void StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state); | |
Gnuplot2dDataset GetDatafile (); | |
Gnuplot2dDataset GetPowerDatafile (); | |
Gnuplot2dDataset GetIdleDatafile (); | |
Gnuplot2dDataset GetBusyDatafile (); | |
Gnuplot2dDataset GetTxDatafile (); | |
Gnuplot2dDataset GetRxDatafile (); | |
double GetBusyTime (); | |
private: | |
typedef std::vector<std::pair<Time,WifiMode> > TxTime; | |
void SetupPhy (Ptr<WifiPhy> phy); | |
Time GetCalcTxTime (WifiMode mode); | |
std::map<Mac48Address, double> actualPower; | |
std::map<Mac48Address, WifiMode> actualMode; | |
uint32_t m_bytesTotal; | |
double totalEnergy; | |
double totalTime; | |
double busyTime; | |
double idleTime; | |
double txTime; | |
double rxTime; | |
double totalBusyTime; | |
double totalIdleTime; | |
double totalTxTime; | |
double totalRxTime; | |
Ptr<WifiPhy> myPhy; | |
TxTime timeTable; | |
Gnuplot2dDataset m_output; | |
Gnuplot2dDataset m_output_power; | |
Gnuplot2dDataset m_output_idle; | |
Gnuplot2dDataset m_output_busy; | |
Gnuplot2dDataset m_output_rx; | |
Gnuplot2dDataset m_output_tx; | |
}; | |
NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) | |
{ | |
Ptr<NetDevice> device = aps.Get (0); | |
Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device); | |
Ptr<WifiPhy> phy = wifiDevice->GetPhy (); | |
myPhy = phy; | |
SetupPhy (phy); | |
for (uint32_t j = 0; j < stas.GetN (); j++) | |
{ | |
Ptr<NetDevice> staDevice = stas.Get (j); | |
Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice); | |
Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress (); | |
actualPower[addr] = 17; | |
actualMode[addr] = phy->GetMode (0); | |
} | |
actualMode[Mac48Address ("ff:ff:ff:ff:ff:ff")] = phy->GetMode (0); | |
totalEnergy = 0; | |
totalTime = 0; | |
busyTime = 0; | |
idleTime = 0; | |
txTime = 0; | |
rxTime = 0; | |
totalBusyTime = 0; | |
totalIdleTime = 0; | |
totalTxTime = 0; | |
totalRxTime = 0; | |
m_bytesTotal = 0; | |
m_output.SetTitle ("Throughput Mbits/s"); | |
m_output_idle.SetTitle ("Idle Time"); | |
m_output_busy.SetTitle ("Busy Time"); | |
m_output_rx.SetTitle ("RX Time"); | |
m_output_tx.SetTitle ("TX Time"); | |
} | |
void | |
NodeStatistics::SetupPhy (Ptr<WifiPhy> phy) | |
{ | |
uint32_t nModes = phy->GetNModes (); | |
for (uint32_t i = 0; i < nModes; i++) | |
{ | |
WifiMode mode = phy->GetMode (i); | |
WifiTxVector txVector; | |
txVector.SetMode (mode); | |
timeTable.push_back (std::make_pair (phy->CalculateTxDuration (packetSize, txVector, WIFI_PREAMBLE_LONG, phy->GetFrequency ()), mode)); | |
} | |
} | |
Time | |
NodeStatistics::GetCalcTxTime (WifiMode mode) | |
{ | |
for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++) | |
{ | |
if (mode == i->second) | |
{ | |
return i->first; | |
} | |
} | |
NS_ASSERT (false); | |
return Seconds (0); | |
} | |
void | |
NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet) | |
{ | |
WifiMacHeader head; | |
packet->PeekHeader (head); | |
Mac48Address dest = head.GetAddr1 (); | |
if (head.GetType() == WIFI_MAC_DATA) | |
{ | |
totalEnergy += pow (10.0, actualPower[dest] / 10.0) * GetCalcTxTime (actualMode[dest]).GetSeconds (); | |
totalTime += GetCalcTxTime (actualMode[dest]).GetSeconds (); | |
} | |
} | |
void | |
NodeStatistics::PowerCallback (std::string path, uint8_t power, Mac48Address dest) | |
{ | |
double txPowerBaseDbm = myPhy->GetTxPowerStart (); | |
double txPowerEndDbm = myPhy->GetTxPowerEnd (); | |
uint32_t nTxPower = myPhy->GetNTxPower (); | |
double dbm; | |
if (nTxPower > 1) | |
{ | |
dbm = txPowerBaseDbm + power * (txPowerEndDbm - txPowerBaseDbm) / (nTxPower - 1); | |
} | |
else | |
{ | |
NS_ASSERT_MSG (txPowerBaseDbm == txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1"); | |
dbm = txPowerBaseDbm; | |
} | |
actualPower[dest] = dbm; | |
} | |
void | |
NodeStatistics::RateCallback (std::string path, uint32_t rate, Mac48Address dest) | |
{ | |
actualMode[dest] = myPhy->GetMode (rate); | |
} | |
void | |
NodeStatistics::StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state) | |
{ | |
if (state == WifiPhy::CCA_BUSY) | |
{ | |
busyTime += duration.GetSeconds (); | |
totalBusyTime += duration.GetSeconds (); | |
} | |
else if (state == WifiPhy::IDLE) | |
{ | |
idleTime += duration.GetSeconds (); | |
totalIdleTime += duration.GetSeconds (); | |
} | |
else if (state == WifiPhy::TX) | |
{ | |
txTime += duration.GetSeconds (); | |
totalTxTime += duration.GetSeconds (); | |
} | |
else if (state == WifiPhy::RX) | |
{ | |
rxTime += duration.GetSeconds (); | |
totalRxTime += duration.GetSeconds (); | |
} | |
} | |
void | |
NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from) | |
{ | |
m_bytesTotal += packet->GetSize (); | |
} | |
void | |
NodeStatistics::CheckStatistics (double time) | |
{ | |
double mbs = ((m_bytesTotal * 8.0) / (1000000 * time)); | |
m_bytesTotal = 0; | |
double atp = totalEnergy / time; | |
totalEnergy = 0; | |
totalTime = 0; | |
m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp); | |
m_output.Add ((Simulator::Now ()).GetSeconds (), mbs); | |
m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100); | |
m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100); | |
m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100); | |
m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100); | |
busyTime = 0; | |
idleTime = 0; | |
txTime = 0; | |
rxTime = 0; | |
Simulator::Schedule (Seconds (time), &NodeStatistics::CheckStatistics, this, time); | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetDatafile () | |
{ | |
return m_output; | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetPowerDatafile () | |
{ | |
return m_output_power; | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetIdleDatafile () | |
{ | |
return m_output_idle; | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetBusyDatafile () | |
{ | |
return m_output_busy; | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetRxDatafile () | |
{ | |
return m_output_rx; | |
} | |
Gnuplot2dDataset | |
NodeStatistics::GetTxDatafile () | |
{ | |
return m_output_tx; | |
} | |
double | |
NodeStatistics::GetBusyTime () | |
{ | |
return totalBusyTime + totalRxTime; | |
} | |
void PowerCallback (std::string path, uint8_t power, Mac48Address dest) | |
{ | |
NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Power " << (int)power); | |
// end PowerCallback | |
} | |
void RateCallback (std::string path, uint32_t rate, Mac48Address dest) | |
{ | |
NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Rate " << rate); | |
// end PowerCallback | |
} | |
int main (int argc, char *argv[]) | |
{ | |
Time datarate=Seconds(0.01); // เปิดรับพารามิเตอร์ ว่า ช่วงระยะห่างระหว่างเพกเกจ <ยิ่งเลขน้อยเพกเกจยิ่งถูกส่งเยอะ> | |
std::string phyMode ("DsssRate1Mbps"); | |
double rss = -80; // -dBm | |
uint32_t packetSize = 1000; // bytes // เปิดรับพารามิเตอร์ ว่า ขนาดของเพกเกจที่ส่งมีขนาดเท่าไหร่ <หน่วยเป็น bytes> | |
uint32_t numPackets = 100; // เปิดรับพารามิเตอร์ ว่า จำนวนของเพกเกจที่ส่งมีมากเท่าไหร่ | |
double interval = 1.0; // seconds | |
bool verbose = false; | |
Address serverAddress; | |
std::string manager = "ns3::ConstantSpeedPropagationDelayModel"; | |
bool stat=true; | |
CommandLine cmd; | |
// สำหรับไว้รับ parameter | |
//cmd.AddValue ("useIpv6", "Use Ipv6", useV6); | |
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode); | |
cmd.AddValue ("rss", "received signal strength", rss); | |
cmd.AddValue ("packetSize", "size of application packet sent", packetSize); | |
cmd.AddValue ("numPackets", "number of packets generated", numPackets); | |
cmd.AddValue ("interval", "interval (seconds) between packets", interval); | |
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); | |
cmd.AddValue ("datarate", "UDP datarate", datarate); | |
// cmd.AddValue ("packetSize", "UDP packetSize", packetSize); | |
cmd.AddValue ("stat", "statistic measurement ", stat); | |
cmd.Parse (argc, argv); | |
// Convert to time object | |
Time interPacketInterval = Seconds (interval); | |
// disable fragmentation for frames below 2200 bytes | |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); | |
// turn off RTS/CTS for frames below 2200 bytes | |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); | |
// Fix non-unicast data rate to be the same as that of unicast | |
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", | |
StringValue (phyMode)); | |
NodeContainer car; | |
car.Create (1); | |
NodeContainer rsu_cloud; | |
rsu_cloud.Create (3); | |
InternetStackHelper internet; | |
internet.Install (car); | |
internet.Install (rsu_cloud); | |
// The below set of helpers will help us to put together the wifi NICs we want | |
WifiHelper wifiL,wifiR,wifiC; | |
if (verbose) | |
{ | |
wifiL.EnableLogComponents (); // Turn on all Wifi logging | |
wifiR.EnableLogComponents (); | |
wifiC.EnableLogComponents (); | |
} | |
wifiL.SetStandard (WIFI_PHY_STANDARD_80211b); | |
wifiR.SetStandard (WIFI_PHY_STANDARD_80211b); | |
wifiC.SetStandard (WIFI_PHY_STANDARD_80211b); | |
// เพิ่ม channel | |
YansWifiPhyHelper wifiPhyL = YansWifiPhyHelper::Default (); | |
YansWifiPhyHelper wifiPhyR = YansWifiPhyHelper::Default (); | |
YansWifiPhyHelper wifiPhyC = YansWifiPhyHelper::Default (); | |
wifiPhyL.Set ("RxGain", DoubleValue (0) ); | |
wifiPhyL.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); | |
wifiPhyR.Set ("RxGain", DoubleValue (0) ); | |
wifiPhyR.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); | |
wifiPhyC.Set ("RxGain", DoubleValue (0) ); | |
wifiPhyC.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); | |
YansWifiChannelHelper wifiChannelL; | |
wifiChannelL.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); | |
wifiChannelL.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss)); | |
wifiPhyL.SetChannel (wifiChannelL.Create ()); | |
YansWifiChannelHelper wifiChannelR; | |
wifiChannelR.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); | |
wifiChannelR.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss)); | |
wifiPhyR.SetChannel (wifiChannelR.Create ()); | |
YansWifiChannelHelper wifiChannelC; | |
wifiChannelC.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); | |
wifiChannelC.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss)); | |
wifiPhyC.SetChannel (wifiChannelC.Create ()); | |
// Add a mac and disable rate control | |
WifiMacHelper wifiMacL,wifiMacR,wifiMacC; | |
Ssid ssidL = Ssid ("wifi-default-left"); | |
Ssid ssidR = Ssid ("wifi-default-right"); | |
Ssid ssidC = Ssid ("wifi-default-center"); | |
wifiL.SetRemoteStationManager ("ns3::ConstantRateWifiManager", | |
"DataMode",StringValue (phyMode), | |
"ControlMode",StringValue (phyMode)); | |
// Setup the rest of the mac | |
// setup sta. | |
wifiMacL.SetType ("ns3::StaWifiMac", | |
"Ssid", SsidValue (ssidL), | |
"ActiveProbing", BooleanValue (false)); | |
NetDeviceContainer staDevice0 = wifiL.Install (wifiPhyL, wifiMacL, car.Get (0)); | |
// setup ap. | |
wifiMacL.SetType ("ns3::ApWifiMac", | |
"Ssid", SsidValue (ssidL)); | |
NetDeviceContainer apDeviceL = wifiL.Install (wifiPhyL, wifiMacL, rsu_cloud.Get (0)); | |
/* | |
wifiMacR.SetType ("ns3::StaWifiMac", | |
"Ssid", SsidValue (ssidR), | |
"ActiveProbing", BooleanValue (false)); | |
NetDeviceContainer staDevice3 = wifiR.Install (wifiPhyR, wifiMacR, c.Get (5)); | |
wifiMacR.SetType ("ns3::ApWifiMac", | |
"Ssid", SsidValue (ssidR)); | |
NetDeviceContainer apDeviceR = wifiR.Install (wifiPhyR, wifiMacR, c.Get (1)); | |
*/ | |
wifiMacC.SetType ("ns3::StaWifiMac", | |
"Ssid", SsidValue (ssidC), | |
"ActiveProbing", BooleanValue (false)); | |
NetDeviceContainer staDevice1 = wifiC.Install (wifiPhyC, wifiMacC, rsu_cloud.Get (0)); | |
NetDeviceContainer staDevice2 = wifiC.Install (wifiPhyC, wifiMacC, rsu_cloud.Get (1)); | |
NetDeviceContainer staDevice3 = wifiC.Install (wifiPhyC, wifiMacC, rsu_cloud.Get (2)); | |
//NetDeviceContainer devices = staDevice; | |
/* | |
wifiMacC.SetType ("ns3::ApWifiMac", | |
"Ssid", SsidValue (ssidC)); | |
NetDeviceContainer apDeviceC = wifiC.Install (wifiPhyC, wifiMacC, cloud.Get (0)); | |
*/ | |
// Note that with FixedRssLossModel, the positions below are not | |
// used for received signal strength. | |
MobilityHelper mobility; | |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); | |
//Car | |
positionAlloc->Add (Vector (-10.0, 0.0, 0.0)); | |
//RSU Cloud | |
positionAlloc->Add (Vector (0.0, -50.0, 0.0)); | |
positionAlloc->Add (Vector (100.0, -50.0, 0.0)); | |
positionAlloc->Add (Vector (200.0, -50.0, 0.0)); | |
mobility.SetPositionAllocator (positionAlloc); | |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | |
mobility.Install (car); | |
mobility.Install (rsu_cloud); | |
//Statistics counter | |
NodeStatistics atpCounter = NodeStatistics (apDeviceL, staDevice0); | |
// ทำให้ node ได้รับ ip | |
Ipv4AddressHelper ipv4L,ipv4R,ipv4C; | |
NS_LOG_INFO ("Assign IP Addresses. Left"); | |
ipv4L.SetBase ("10.1.1.0", "255.255.255.0"); | |
Ipv4InterfaceContainer i0 = ipv4L.Assign (staDevice0); // 0 | |
Ipv4InterfaceContainer iL = ipv4L.Assign (apDeviceL); // 1 | |
/* | |
NS_LOG_INFO ("Assign IP Addresses. Right"); | |
ipv4R.SetBase ("10.1.2.0", "255.255.255.0"); | |
Ipv4InterfaceContainer i3 = ipv4R.Assign (staDevice3); //5 | |
Ipv4InterfaceContainer i4 = ipv4R.Assign (staDevice4); //6 | |
Ipv4InterfaceContainer i5 = ipv4R.Assign (staDevice5); //7 | |
Ipv4InterfaceContainer iR = ipv4R.Assign (apDeviceR); //1 | |
*/ | |
NS_LOG_INFO ("Assign IP Addresses.TOP"); | |
ipv4C.SetBase ("10.1.3.0", "255.255.255.0"); | |
Ipv4InterfaceContainer i1 = ipv4C.Assign (staDevice1); //1 | |
Ipv4InterfaceContainer i2 = ipv4C.Assign (staDevice2); //2 | |
Ipv4InterfaceContainer i3 = ipv4C.Assign (staDevice3); //3 | |
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); | |
/* | |
//received | |
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (2), tid); | |
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); | |
recvSink->Bind (local); | |
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); | |
//จุดร transmit | |
Ptr<Socket> source = Socket::CreateSocket (cloud.Get(0), tid); | |
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("10.1.1.1"), 80); // ปลายทาง | |
source->SetAllowBroadcast (true); | |
source->Connect (remote); | |
*/ | |
//source1->SetAllowBroadcast (true); | |
//source1->Connect (remote); | |
// Tracing | |
wifiPhyL.EnablePcap ("scbc", staDevice0); // =ชื่อของ Node ที่จะจับ | |
//wifiPhyL.EnablePcap ("scbc", staDevice1); | |
//wifiPhyL.EnablePcap ("scbc", staDevice2); | |
//wifiPhyL.EnablePcap ("scbc", staDevice3); | |
wifiPhyL.EnablePcap ("scbc", apDeviceL); | |
// Output what we are doing | |
NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss ); | |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); | |
/* | |
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), | |
Seconds (1.0), &GenerateTraffic, | |
source, packetSize, numPackets, interPacketInterval); | |
*/ | |
NS_LOG_INFO ("Create Applications."); | |
// | |
// Create one udpServer applications on node one. | |
// | |
/* | |
uint16_t port = 4000; | |
UdpServerHelper server (port); | |
ApplicationContainer apps = server.Install (c.Get (2)); | |
apps.Start (Seconds (1.0)); | |
apps.Stop (Seconds (10.0)); | |
// | |
// Create one UdpTraceClient application to send UDP datagrams from node zero to | |
// node one. | |
// | |
uint32_t MaxPacketSize = 1472; // Back off 20 (IP) + 8 (UDP) bytes from MTU | |
UdpTraceClientHelper client (Ipv4Address ("10.1.1.1"), port,""); | |
client.SetAttribute ("MaxPacketSize", UintegerValue (MaxPacketSize)); | |
apps = client.Install (cloud.Get (0)); | |
apps.Start (Seconds (2.0)); | |
apps.Stop (Seconds (10.0)); | |
*/ | |
//UDP flow | |
int simulationTime=5; | |
/* Setting applications */ | |
ApplicationContainer serverApp, sinkApp; | |
UdpServerHelper myServer (9); | |
serverApp = myServer.Install (rsu_cloud.Get (0)); // node ปลายทาง | |
serverApp.Start (Seconds (0.0)); | |
serverApp.Stop (Seconds (simulationTime + 1)); | |
UdpClientHelper myClient (iL.GetAddress (0), 9); // ip ปลายทาง | |
myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u)); | |
myClient.SetAttribute ("Interval", TimeValue (Time (datarate))); | |
myClient.SetAttribute ("PacketSize", UintegerValue (packetSize)); | |
ApplicationContainer clientApp = myClient.Install (car.Get (0)); // node ต้นทาง | |
clientApp.Start (Seconds (1.0)); | |
clientApp.Stop (Seconds (simulationTime + 1)); | |
//Flowmon | |
FlowMonitorHelper flowmon; | |
Ptr<FlowMonitor> monitor = flowmon.InstallAll (); | |
Simulator::Stop (Seconds (simulationTime)); | |
Simulator::Run (); | |
Simulator::Destroy (); | |
if(stat) | |
{ | |
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ()); | |
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats (); | |
std::cout<<"Stat\t\t\t"<<"txBytes\t"<<"rxByte\t"<<"Avg.delay(s)\t"<<"Avg.jitter\t"<<"Throughput" <<std::endl; | |
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator istat = stats.begin (); istat != stats.end (); ++istat) | |
{ | |
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (istat->first); | |
if ((t.sourceAddress == "10.1.1.1" && t.destinationAddress == "10.1.1.2")) | |
{ | |
std::cout<<"staDevice0->apDeviceL\t"<<istat->second.txBytes<<"\t"<<istat->second.rxBytes<<"\t"<<istat->second.delaySum.GetSeconds () / istat->second.rxPackets<<"\t"<<istat->second.jitterSum.GetSeconds () / (istat->second.rxPackets - 1)<<"\t"<<istat->second.rxBytes * 8.0 / (istat->second.timeLastRxPacket.GetSeconds () - istat->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 <<std::endl; | |
} | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment