2016-08-02 39 views
1

在這個ns-3示例中(first.cc)我從udp連接的另一個示例中輸入了一些代碼行(在斜槓之間複製)來計算udp連接的吞吐量,檢查並定義新添加的變量,並在運行後出現此錯誤:在ns-3中獲取udp吞吐量時出現聲明錯誤

'serverApp'未在此範圍內聲明 uint32_t totalPacketsThrough = DynamicCast(serverApp.Get(1)) - > GetReceived();

#include "ns3/core-module.h" 
#include "ns3/network-module.h" 
#include "ns3/internet-module.h" 
#include "ns3/point-to-point-module.h" 
#include "ns3/applications-module.h" 

using namespace ns3; 

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); 

int 
main (int argc, char *argv[]) 
{ 
    Time::SetResolution (Time::NS); 
    LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); 
    LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); 

    NodeContainer nodes; 
    nodes.Create (2); 

    PointToPointHelper pointToPoint; 
    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("1000Mbps")); 
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); 

    NetDeviceContainer devices; 
    devices = pointToPoint.Install (nodes); 

    InternetStackHelper stack; 
    stack.Install (nodes); 

    Ipv4AddressHelper address; 
    address.SetBase ("10.1.1.0", "255.255.255.0"); 

    Ipv4InterfaceContainer interfaces = address.Assign (devices); 

    UdpEchoServerHelper echoServer (9); 

    ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); 
    serverApps.Start (Seconds (1.0)); 
    serverApps.Stop (Seconds (10.0)); 

    UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); 
    echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); 
    echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); 
    echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); 

    ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); 
    clientApps.Start (Seconds (2.0)); 
    clientApps.Stop (Seconds (10.0)); 
    ////////////////////////////////////////////////////////////////////////// 

    uint32_t payloadSize = 1472; //1500 byte IP packet 
    double simulationTime = 10; //seconds 
    double throughput = 0; 
    uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get  (1))->GetReceived(); 
    throughput = totalPacketsThrough * payloadSize * 8/(simulationTime *  1000000.0); //Mbit/s 
    std::cout << " *throughput = " << throughput ;      

///////////////////////////////////////////////////////////////////// 
    Simulator::Run(); 
    Simulator::Destroy(); 
    return 0; 
} 

回答

1

我想你的錯誤是已經聲明serverApps沒有serverApp

+0

大聲笑...這是正確的,但現在我沒有得到任何結果,但這個: –

+0

Waf:進入目錄'/home/hamid/workspace/ns-allinone-3.25/ns-3.25/build' Waf:離開目錄'/home/hamid/workspace/ns-allinone-3.25/ns-3.25/build' 構建命令將存儲在build/compile_commands.json中 '構建'成功完成(1.496s) Command ['/ home /hamid/workspace/ns-allinone-3.25/ns-3.25/build/scratch/first']以信號SIGSEGV終止。在調試器下運行它以獲取更多信息(./waf --run --command-template =「gdb --args%s 」)。 –

+0

PLZ接受答案並創建一個新的SO – baddger964