NS3-Durchsatz-Berechnung
Ich versuche zurzeit mit der Netzwerk-simulator NS3-tests durchgeführt eine stationäre access point übertragen von Daten zu einem mobilen Knoten (mit 802.11 a, TCP).
Der code scheint zu kompilieren feinen und früher war die Ausgabe korrekt aussehende Daten, so konnte ich Plotten den Durchsatz der beweglichen Knoten im Vergleich zu seiner Entfernung zum AP und dann, wie das modulationsschema der AP ändert sich je nach der Entfernung der mobilen Knoten.
Machte ich eine kleine änderung an der ThroughputPerSecond-Methode und jetzt die simulation ist fest in einer Endlosschleife (es hört nicht auf, nach 240 Sekunden) und gibt nur Nullen. Ich bin so frustriert, dass sah Sie an dem code versuchen, änderungen zu machen, um die kleinen Dinge, die für die letzten 6 Stunden und ich dachte, vielleicht hat jemand mehr Erfahrung als ich nehmen könnte einen Blick auf Sie und sehen, ob es etwas extrem offensichtlich bin ich vermisst?
Ich angehängt habe alle von meinem code, aber ich denke, dass das problem nur darin liegt, dass kleine ThroughputPerSecond Methode, obwohl ich nicht verstehen kann, wo.
Jede Hilfe wird sehr geschätzt.
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/athstats-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/internet-module.h"
#include <iostream>
using namespace ns3;
static bool g_verbose = true;
void
PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
{
if (g_verbose)
{
//Output the data rates for each data packet received
std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
}
}
static void
SetPosition (Ptr<Node> node, Vector position)
{
//Set node's initial position
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
mobility->SetPosition (position);
}
static Vector
GetPosition (Ptr<Node> node)
{
//get node's current position
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
return mobility->GetPosition ();
}
static void
AdvancePosition (Ptr<Node> node)
{
//advance node's position
Vector pos = GetPosition (node);
pos.x += 1.0;
if (pos.x >= 120.0){
return;
}
SetPosition (node, pos);
if (g_verbose){
//std::cout << "x="<<pos.x << std::endl;
}
//Reschedule AdvancePosition
Simulator::Schedule (Seconds (0.1), &AdvancePosition, node);
}
void
ThroughputPerSecond (Ptr<Application> sink1Apps, int totalPacketsThrough, Ptr<Node> node)
{
double throughput = 0.0;
Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sink1Apps);
//Calculate and output throughput per second
totalPacketsThrough = sink1->GetTotalRx ();
throughput = totalPacketsThrough*8/((237.0)*1000000.0);
std::cout << throughput;
//Reschedule ThroughputPerSecond
//
Simulator::Schedule (Seconds (0.0), &ThroughputPerSecond, sink1Apps, totalPacketsThrough, node);
}
int main (int argc, char *argv[])
{
Packet::EnablePrinting();
CommandLine cmd;
cmd.AddValue ("verbose", "Print trace information if true", g_verbose);
cmd.Parse (argc, argv);
//disable RTS/CTS.
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("99999999"));
//disable fragmentation
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2222200"));
WifiHelper wifi = WifiHelper::Default ();
MobilityHelper mobility;
NodeContainer stas;
NodeContainer ap;
NetDeviceContainer staDevs,apDevs;
Time interPacketInterval;
//Create 1 node, playing the role of the mobile node and 1 node, playing the role of the AP
stas.Create(1);
ap.Create(1);
//Create and setup the wifi Channel, wifi physical and MAC layers for the nodes
wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
interPacketInterval = Seconds (0.00015); //802.11a & 802.11g speeds
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("wifi-default");
//setup the mobile node and the AP (install net devices)
wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false));
staDevs = wifi.Install(wifiPhy, wifiMac, stas);
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));
apDevs = wifi.Install(wifiPhy, wifiMac, ap);
//Setup the mobility model for the mobile node and the AP
mobility.Install (ap);
mobility.Install (stas);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
//Set initial positions of both nodes
SetPosition (ap.Get(0), Vector (0.0, 0.0, 0.0));
SetPosition (stas.Get(0), Vector (-120.0, -20.0, 0.0));
//Start moving the mobile node at Second 0.5 by calling AdvancePostion function
Simulator::Schedule (Seconds (0.5), &AdvancePosition, stas.Get(0));
//Add the Internet Stack and assign IPs for the mobile node and AP
InternetStackHelper internet;
internet.Install (ap);
internet.Install (stas);
Ipv4AddressHelper address;
address.SetBase("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer apConnection = address.Assign(apDevs);
Ipv4InterfaceContainer staConnection = address.Assign(staDevs);
//Ipv4Address serverAddress = Ipv4Address(apConnection.GetAddress(0,0));
//
//Create application pairs for TCP or UDP using information in the spec
//setting AP as the data source and the mobile node as the receiver of this data
//
uint16_t port = 9; //Typical port
BulkSendHelper source ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
source.SetAttribute ("MaxBytes", UintegerValue(0)); //0 is maximum
ApplicationContainer sourceApps = source.Install(ap.Get(0));
sourceApps.Start (Seconds (0.0));
sourceApps.Stop (Seconds (240.0));
PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
ApplicationContainer sinkApps = sink.Install(stas.Get(0));
sinkApps.Start (Seconds (0.0));
sinkApps.Stop (Seconds (240.0));
//This line triggers the calculation of throughput per second, starting at second 0.
Simulator::Schedule (Seconds (0.0), &ThroughputPerSecond, sinkApps.Get(0), 0 , stas.Get(0));
//This line triggers the tracing of the modulation scheme (to get the data rate)
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace));
Simulator::Stop (Seconds (240.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
InformationsquelleAutor Sarah P | 2014-11-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich bin nicht vertraut mit NS3 wirklich, aber nach einem Blick durch den code, vielleicht, wenn Sie änderungen an dieser Zeile
zu
oder was auch immer Wert, den Sie vergrößern möchten Sekunden durch, es vielleicht nicht unendlich-Schleife.
Warum bist du immer fehlerhafte Daten; ich fürchte, wie ich oben sagte, ich bin nicht allzu vertraut mit NS3 so nicht weiter helfen.
InformationsquelleAutor Rachel