2013-10-14 63 views
1

我對NS3是全新的,我負責設置兩個eNB和它們之間的一個UE來演示x2切換,我已經成功設置了eNB和UE,併爲UE設置了移動模型,現在我想生成一個XML跟蹤文件對NetAnim,在運行時添加以下行到我的代碼在Ns3中聲明節點

AnimationInterface anim ("x2-handover-animation.xml"); 
anim.SetMobilityPollInterval (Seconds (0.3)); 

它也有兩個額外的節點,給我一共有5節點,而不是三(2個eNB的和1 UE)我宣佈。

您提供的援助是請求。

下面是我的源代碼

#include "ns3/core-module.h" 
#include "ns3/network-module.h" 
#include "ns3/internet-module.h" 
#include "ns3/mobility-module.h" 
#include "ns3/lte-module.h" 
#include "ns3/applications-module.h" 
#include "ns3/point-to-point-module.h" 
#include "ns3/config-store-module.h" 
#include "ns3/csma-module.h" 
#include "ns3/wifi-module.h" 
#include "ns3/netanim-module.h" 
#include "ns3/mobility-helper.h" 
#include "ns3/flow-monitor-module.h" 

using namespace ns3; 


void 
NotifyConnectionEstablishedUe (std::string context, 
          uint64_t imsi, 
          uint16_t cellid, 
          uint16_t rnti) 
{ 
std::cout << context 
     << " UE IMSI " << imsi 
     << ": connected to CellId " << cellid 
     << " with RNTI " << rnti 
     << std::endl; 
} 

void 
NotifyHandoverStartUe (std::string context, 
        uint64_t imsi, 
        uint16_t cellid, 
        uint16_t rnti, 
        uint16_t targetCellId) 
{ 
std::cout << context 
     << " UE IMSI " << imsi 
     << ": previously connected to CellId " << cellid 
     << " with RNTI " << rnti 
     << ", doing handover to CellId " << targetCellId 
     << std::endl; 
} 

void 
NotifyHandoverEndOkUe (std::string context, 
        uint64_t imsi, 
        uint16_t cellid, 
        uint16_t rnti) 
{ 
    std::cout << context 
     << " UE IMSI " << imsi 
     << ": successful handover to CellId " << cellid 
     << " with RNTI " << rnti 
     << std::endl; 
} 

void 
NotifyConnectionEstablishedEnb (std::string context, 
          uint64_t imsi, 
          uint16_t cellid, 
          uint16_t rnti) 
{ 
    std::cout << context 
     << " eNB CellId " << cellid 
     << ": successful connection of UE with IMSI " << imsi 
     << " RNTI " << rnti 
     << std::endl; 
} 

void 
NotifyHandoverStartEnb (std::string context, 
        uint64_t imsi, 
        uint16_t cellid, 
        uint16_t rnti, 
        uint16_t targetCellId) 
{ 
    std::cout << context 
     << " eNB CellId " << cellid 
     << ": start handover of UE with IMSI " << imsi 
     << " RNTI " << rnti 
     << " to CellId " << targetCellId 
     << std::endl; 
} 

void 
NotifyHandoverEndOkEnb (std::string context, 
        uint64_t imsi, 
        uint16_t cellid, 
        uint16_t rnti) 
{ 
    std::cout << context 
     << " eNB CellId " << cellid 
     << ": completed handover of UE with IMSI " << imsi 
     << " RNTI " << rnti 
     << std::endl; 
} 




/** 
* Sample simulation script for a X2-based handover. 
* It instantiates two eNodeB, attaches one UE to the 'source' eNB and 
* triggers a handover of the UE towards the 'target' eNB. 
*/ 
NS_LOG_COMPONENT_DEFINE ("EpcX2HandoverExample"); 

int 
main (int argc, char *argv[]) 
{ 

uint16_t numberOfUes = 1; // the 1 Ue i declared 
uint16_t numberOfEnbs = 2; // the 2 ENBs i declared 
uint16_t numBearersPerUe = 0; 
double simTime = 10.00; 


// change some default attributes so that they are reasonable for 
// this scenario, but do this before processing command line 
// arguments, so that the user is allowed to override these settings 
Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds(10))); 
Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue(1000000)); 
Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue(false)); 

    // Command line arguments 
CommandLine cmd; 
cmd.AddValue("numberOfUes", "Number of UEs", numberOfUes); 
cmd.AddValue("numberOfEnbs", "Number of eNodeBs", numberOfEnbs); 
cmd.AddValue("simTime", "Total duration of the simulation (in seconds)",simTime); 
    cmd.Parse(argc, argv); 


    Ptr<LteHelper> lteHelper = CreateObject<LteHelper>(); 
    Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper>(); 
    lteHelper->SetEpcHelper (epcHelper); 
    lteHelper->SetSchedulerType("ns3::RrFfMacScheduler"); 

    Ptr<Node> pgw = epcHelper->GetPgwNode(); 

    // Create a single RemoteHost 
    NodeContainer remoteHostContainer; 
    remoteHostContainer.Create (1); 
    Ptr<Node> remoteHost = remoteHostContainer.Get (0); 
    InternetStackHelper internet; 
    internet.Install (remoteHostContainer); 

    // Create the Internet 
    PointToPointHelper p2ph; 
    p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); 
    p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); 
    p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010))); 
    NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); 
    Ipv4AddressHelper ipv4h; 
    ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); 
    Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); 
    Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1); 


    // Routing of the Internet Host (towards the LTE network) 
    Ipv4StaticRoutingHelper ipv4RoutingHelper; 
    Ptr<Ipv4StaticRouting> remoteHostStaticRouting =pv4RoutingHelper.GetStaticRouting  (remoteHost->GetObject<Ipv4>()); 
    // interface 0 is localhost, 1 is the p2p device 
    remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1); 

    NodeContainer ueNodes; 
    NodeContainer enbNodes; 
    enbNodes.Create(numberOfEnbs); 
    ueNodes.Create(numberOfUes); 


AnimationInterface anim ("x2-handover-animation.xml"); //code i added to generate XML file 
anim.SetMobilityPollInterval (Seconds (0.3)); 

MobilityHelper mobility; 

    mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel", 
         "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50))); 
    mobility.Install (ueNodes); 
    mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); 
    mobility.Install (enbNodes); 

    // Install LTE Devices in eNB and UEs 
    NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes); 
    NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes); 

    // Install the IP stack on the UEs 
    internet.Install (ueNodes); 
    Ipv4InterfaceContainer ueIpIfaces; 
    ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs)); 
    // Assign IP address to UEs, and install applications 
    for (uint32_t u = 0; u < ueNodes.GetN(); ++u) 

    { 
     Ptr<Node> ueNode = ueNodes.Get (u); 
     // Set the default gateway for the UE 
     Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4>()); 
     ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress(), 1); 
    } 


    // Attach all UEs to the first eNodeB 
    for (uint16_t i = 0; i < numberOfUes; i++) 

    { 
     lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(0)); 
    } 


    NS_LOG_LOGIC ("setting up applications"); 

    // Install and start applications on UEs and remote host 
    uint16_t dlPort = 10000; 
    uint16_t ulPort = 20000; 

    // randomize a bit start times to avoid simulation artifacts 
    // (e.g., buffer overflows due to packet transmissions happening 
    // exactly at the same time) 
    Ptr<UniformRandomVariable> startTimeSeconds = CreateObject<UniformRandomVariable>(); 
    startTimeSeconds->SetAttribute ("Min", DoubleValue (0)); 
    startTimeSeconds->SetAttribute ("Max", DoubleValue (0.010)); 

    for (uint32_t u = 0; u < numberOfUes; ++u) 
    { 
     Ptr<Node> ue = ueNodes.Get (u); 
     // Set the default gateway for the UE 
     Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4>()); 
     ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress(), 1); 

     for (uint32_t b = 0; b < numBearersPerUe; ++b) 

    { 
     ++dlPort; 
     ++ulPort; 

     ApplicationContainer clientApps; 
     ApplicationContainer serverApps; 

     NS_LOG_LOGIC ("installing UDP DL app for UE " << u); 
     UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort); 
     clientApps.Add (dlClientHelper.Install (remoteHost)); 
     PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", 
              InetSocketAddress (Ipv4Address::GetAny(), dlPort)); 
     serverApps.Add (dlPacketSinkHelper.Install (ue)); 

     NS_LOG_LOGIC ("installing UDP UL app for UE " << u); 
     UdpClientHelper ulClientHelper (remoteHostAddr, ulPort); 
     clientApps.Add (ulClientHelper.Install (ue)); 
     PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", 
              InetSocketAddress (Ipv4Address::GetAny(), ulPort)); 
     serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); 

     Ptr<EpcTft> tft = Create<EpcTft>(); 
     EpcTft::PacketFilter dlpf; 
     dlpf.localPortStart = dlPort; 
     dlpf.localPortEnd = dlPort; 
     tft->Add (dlpf); 
     EpcTft::PacketFilter ulpf; 
     ulpf.remotePortStart = ulPort; 
     ulpf.remotePortEnd = ulPort; 
     tft->Add (ulpf); 
     EpsBearer bearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT); 
     lteHelper->ActivateDedicatedEpsBearer (ueLteDevs.Get (u), bearer, tft); 

     Time startTime = Seconds (startTimeSeconds->GetValue()); 
     serverApps.Start (startTime); 
     clientApps.Start (startTime); 

    } // end for b 
    } 


    // Add X2 inteface 
    lteHelper->AddX2Interface (enbNodes); 

    // X2-based Handover 
    lteHelper->HandoverRequest (Seconds (0.100), ueLteDevs.Get (0), enbLteDevs.Get (0), enbLteDevs.Get (1)); 


    // Uncomment to enable PCAP tracing 
    p2ph.EnablePcapAll("lena-x2-handover"); 

    lteHelper->EnableMacTraces(); 
    lteHelper->EnableRlcTraces(); 
    lteHelper->EnablePdcpTraces(); 
    Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats(); 
    rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.05))); 
    Ptr<RadioBearerStatsCalculator> pdcpStats = lteHelper->GetPdcpStats(); 
    pdcpStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.05))); 


    // connect custom trace sinks for RRC connection establishment and handover notification 
    Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/ConnectionEstablished", 
       MakeCallback (&NotifyConnectionEstablishedEnb)); 
    Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished", 
       MakeCallback (&NotifyConnectionEstablishedUe)); 
    Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart", 
       MakeCallback (&NotifyHandoverStartEnb)); 
    Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart", 
       MakeCallback (&NotifyHandoverStartUe)); 
    Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk", 
       MakeCallback (&NotifyHandoverEndOkEnb)); 
    Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk", 
       MakeCallback (&NotifyHandoverEndOkUe)); 


    Simulator::Stop(Seconds(simTime)); 
    Simulator::Run(); 

    // GtkConfigStore config; 
    // config.ConfigureAttributes(); 

    Simulator::Destroy(); 
    return 0; 

} 
+0

究竟是什麼問題? – DrakaSAN

回答

1

提取物正如我在你已經創建了5個節點不3.

第一個驗證碼看到的是PGW節點是和EPC實體

Ptr<Node> pgw = epcHelper->GetPgwNode(); 

第二個是一個遠程主機

remoteHostContainer.Create (1); 

這兩個節點連接點使用以下代碼

NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); 

的第三和第四節點是點ENB節點「numberOfEnbs = 2;」

enbNodes.Create(numberOfEnbs); 

第五個是Ue節點「numberOfUes = 1;」

ueNodes.Create(numberOfUes); 

因此,你應該有5個節點不是三:)

前兩個節點代表連接到您創建的LTE網絡的Internet連接。而最後3個節點代表您的LTE網絡。