Добавить приложение видеопотока в мою симуляцию LTE ns3 - PullRequest
0 голосов
/ 30 марта 2020

У меня есть симуляция LTE ns3, которая устанавливает некоторые eNodeB и UE и имитирует EP C, но у него нет никакой конфигурации, когда / как отправлять данные в UE. Я хотел бы добавить приложение потокового видео в симуляцию, но я не уверен, как поступить с того места, где я стою. Я заметил, что можно применить OnOffApplication, но я пробовал его, и у меня были проблемы с его построением.

Это текущий статус симуляции (незначительные изменения по сравнению с примером lena-simple-epc.cc):

/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */

#include "ns3/lte-helper.h"
#include "ns3/epc-helper.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/ipv4-global-routing-helper.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-helper.h"
#include <ns3/config-store-module.h>

using namespace ns3;

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

  uint16_t nEnbs = 7;
  uint16_t nUesPerEnb = 5;
  double simTime = 15;
  // double distance = 1000.0;
  double interPacketInterval = 100;
  // double packetSize = 64;

  Config::SetDefault("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(160));

  ConfigStore inputConfig;
  inputConfig.ConfigureDefaults();

  // parse again so you can override default values from the command line
  // cmd.Parse(argc, argv);

  Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
  lteHelper->SetEpcHelper(epcHelper);
  epcHelper->Initialize();

  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("250KB/s")));
  p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
  p2ph.SetChannelAttribute("Delay", TimeValue(MilliSeconds(10)));
  NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
  Ipv4AddressHelper ipv4h;
  ipv4h.SetBase("1.0.0.0", "255.0.0.0");
  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
  // interface 0 is localhost, 1 is the p2p device
  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress(1);

  Ipv4StaticRoutingHelper ipv4RoutingHelper;
  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
  remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);

  NodeContainer enbNodes;
  NodeContainer ueNodes;
  enbNodes.Create(nEnbs);
  ueNodes.Create(nEnbs * nUesPerEnb);

  // Install Mobility Model
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
  positionAlloc->Add(Vector(0, 1000, 0));
  positionAlloc->Add(Vector(1000, 1000, 0));
  positionAlloc->Add(Vector(2000, 1000, 0));
  positionAlloc->Add(Vector(500, 134, 0));
  positionAlloc->Add(Vector(500, 1866, 0));
  positionAlloc->Add(Vector(1500, 134, 0));
  positionAlloc->Add(Vector(1500, 1866, 0));

  MobilityHelper mobility;
  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  mobility.SetPositionAllocator(positionAlloc);
  mobility.Install(enbNodes);

  // mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel", "Bounds", RectangleValue(Rectangle(0, 2000, 0, 2000)));
  mobility.SetPositionAllocator("ns3::RandomDiscPositionAllocator",
                                "X", StringValue("1000.0"),
                                "Y", StringValue("1000.0"),
                                "Rho", StringValue("ns3::UniformRandomVariable[Min=0|Max=1000]"));
  mobility.Install(ueNodes);

  // Install LTE Devices to the nodes
  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);

  // Install the IP stack on the UEs
  internet.Install(ueNodes);
  Ipv4InterfaceContainer ueIpIface;
  ueIpIface = 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);
  }

  lteHelper->Attach(ueLteDevs);
  // side effects: 1) use idle mode cell selection, 2) activate default EPS bearer

  // 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(interPacketInterval / 1000.0));

  // Install and start applications on UEs and remote host
  uint16_t dlPort = 1234;
  uint16_t ulPort = 2000;
  for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
  {
    ++ulPort;
    ApplicationContainer clientApps;
    ApplicationContainer serverApps;

    PacketSinkHelper dlPacketSinkHelper("ns3::TcpSocketFactory", InetSocketAddress(Ipv4Address::GetAny(), dlPort));
    PacketSinkHelper ulPacketSinkHelper("ns3::TcpSocketFactory", InetSocketAddress(Ipv4Address::GetAny(), ulPort));
    serverApps.Add(dlPacketSinkHelper.Install(ueNodes.Get(u)));
    serverApps.Add(ulPacketSinkHelper.Install(remoteHost));

    UdpClientHelper dlClient(ueIpIface.GetAddress(u), dlPort);
    dlClient.SetAttribute("Interval", TimeValue(MilliSeconds(interPacketInterval)));
    dlClient.SetAttribute("MaxPackets", UintegerValue(1000000));

    UdpClientHelper ulClient(remoteHostAddr, ulPort);
    ulClient.SetAttribute("Interval", TimeValue(MilliSeconds(interPacketInterval)));
    ulClient.SetAttribute("MaxPackets", UintegerValue(1000000));

    clientApps.Add(dlClient.Install(remoteHost));
    clientApps.Add(ulClient.Install(ueNodes.Get(u)));

    serverApps.Start(Seconds(startTimeSeconds->GetValue()));
    clientApps.Start(Seconds(startTimeSeconds->GetValue()));
  }

  lteHelper->EnableTraces();

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

  Simulator::Destroy();
  return 0;
}
...