ns-3中的LTE路由

时间:2018-07-02 13:29:35

标签: ns-3

我正在尝试在拓扑下面构建

/*
 Topology

 UE ----eNB----router----remotehost
 */

以下输出未显示有关服务器接收信息的任何信息。 有人可以帮我解决我的代码有什么问题吗?

附加以下代码:

using namespace ns3;
using namespace std;

NS_LOG_COMPONENT_DEFINE("LTEUdpEchoExample");

/*
 Topology

 UE ----eNB----router----remotehost

 */

int main(int argc, char *argv[]) {
NS_LOG_INFO("Create nodes.");

// Enabling logging components
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);

uint32_t node_router = 1;

// remote host node
NodeContainer remoteHost2;
remoteHost2.Create(2);

// ue client

NodeContainer ueNodes;
ueNodes.Create(1);

// create enb

NodeContainer enbNodes;
enbNodes.Create(1);

NodeContainer router_Nodes;
router_Nodes.Create(node_router);

// create lte helper
Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();

// create epc helper
Ptr<PointToPointEpcHelper> epcHelper =
        CreateObject<PointToPointEpcHelper>();
lteHelper->SetEpcHelper(epcHelper);

// path loss model
lteHelper->SetAttribute("PathlossModel",
        StringValue("ns3::FriisPropagationLossModel"));
// Get P-GW from EPC Helper
Ptr<Node> pgw = epcHelper->GetPgwNode();

NodeContainer pgw_router = NodeContainer(pgw, router_Nodes.Get(0));
NodeContainer router_remotehost2 = NodeContainer(router_Nodes.Get(0),
        remoteHost2.Get(0));

InternetStackHelper internet;
internet.Install(remoteHost2);
internet.Install(router_Nodes);

NS_LOG_INFO("Create channels.");

PointToPointHelper p2phlte;
p2phlte.SetDeviceAttribute("DataRate", DataRateValue(DataRate("1Gb/s")));
p2phlte.SetDeviceAttribute("Mtu", UintegerValue(4096));
p2phlte.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));

NetDeviceContainer internetDevices1 = p2phlte.Install(pgw_router);
NetDeviceContainer internetDevices2 = p2phlte.Install(router_remotehost2); // [P-GW] ------- [internet] ------ [remote host node]

Ipv4AddressHelper ipv4h;
ipv4h.SetBase("8.0.0.0", "255.255.255.0");
Ipv4InterfaceContainer internetIpIfaces1 = ipv4h.Assign(internetDevices1);

ipv4h.SetBase("9.0.0.0", "255.255.255.0");
Ipv4InterfaceContainer internetIpIfaces2 = ipv4h.Assign(internetDevices2);

Ipv4Address remoteHost2Addr;
remoteHost2Addr = internetIpIfaces2.GetAddress(1); // remote host ip adr

Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHost2StaticRouting =
        ipv4RoutingHelper.GetStaticRouting(
                remoteHost2.Get(1)->GetObject<Ipv4>());

// hardcoded UE addresses for now
remoteHost2StaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"),
        Ipv4Mask("255.255.255.0"), 1);

Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<
        ListPositionAllocator>();
enbPositionAlloc->Add(Vector(0.0, 0.0, 0.0));
enbPositionAlloc->Add(Vector(100, 0.0, 0.0));

MobilityHelper enbMobility;
enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
enbMobility.SetPositionAllocator(enbPositionAlloc);

enbMobility.Install(enbNodes);
NetDeviceContainer enbLteDev = lteHelper->InstallEnbDevice(enbNodes);

MobilityHelper ueMobility;

ueMobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator", "X",
        DoubleValue(0), "Y", DoubleValue(0), "rho", DoubleValue(100.0));
ueMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
ueMobility.Install(ueNodes);
NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);

InternetStackHelper internet2;
internet2.Install(ueNodes);

Ptr<Node> ue = ueNodes.Get(0);
Ptr<NetDevice> ueLteDevice = ueLteDevs.Get(0);
Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address(
        NetDeviceContainer(ueLteDevice));

// set the default gateway for the UE
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting(
        ue->GetObject<Ipv4>());
ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(),
        1);

// we can now attach the UE, which will also activate the default EPS bearer
lteHelper->Attach(ueLteDevice);

// Create a UdpEchoServer application

uint16_t port = 2122;
UdpEchoServerHelper server(port);
ApplicationContainer serverApps = server.Install(remoteHost2.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));

// Create a UdpEchoClient application to send UDP datagrams.

uint32_t packetSize = 1024;
uint32_t maxPacketCount = 1;
Time interPacketInterval = Seconds(0.2);
UdpEchoClientHelper client(remoteHost2Addr, port);
client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
client.SetAttribute("Interval", TimeValue(interPacketInterval));
client.SetAttribute("PacketSize", UintegerValue(packetSize));

ApplicationContainer clientApps = client.Install(ueNodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));

AsciiTraceHelper ascii;
p2phlte.EnableAsciiAll(ascii.CreateFileStream("lte-udp-echo.tr"));
p2phlte.EnablePcapAll("lte-udp-echo");

Ptr<FlowMonitor> flowmon;
FlowMonitorHelper flowmonHelper;
flowmon = flowmonHelper.InstallAll();

NS_LOG_INFO("Run Simulation.");

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

flowmon->SerializeToXmlFile("lte-udp-echo.flowmon", false, false);

Simulator::Destroy();
NS_LOG_INFO("Done.");
}

输出

  

[2717/2738]链接build / scratch / test2 Waf:离开目录   `/home/suresh/ns3-workspace/ns-allinone-3.28/ns-3.28/build'构建   命令将存储在build / compile_commands.json'build'中   成功完成(4.374s)   UdpEchoServerApplication:UdpEchoServer(0x55c5152e3d80)   UdpEchoClientApplication:UdpEchoClient(0x55c515245160)   UdpEchoClientApplication:SetDataSize(0x55c515245160,1024)   UdpEchoServerApplication:StartApplication(0x55c5152e3d80)   UdpEchoClientApplication:StartApplication(0x55c515245160)   UdpEchoClientApplication:ScheduleTransmit(0x55c515245160,+ 0.0ns)   UdpEchoClientApplication:Send(0x55c515245160)

     

在2秒钟时,客户端向9.0.0.2端口2122发送了1024个字节

     

UdpEchoServerApplication:DoDispose(0x55c5152e3d80)   UdpEchoClientApplication:DoDispose(0x55c515245160)   UdpEchoClientApplication:〜UdpEchoClient(0x55c515245160)   UdpEchoServerApplication:〜UdpEchoServer(0x55c5152e3d80)

0 个答案:

没有答案