У меня есть проблема в цикле моделирования с другой переменной - PullRequest
0 голосов
/ 07 апреля 2020

У меня есть небольшая проблема, когда я не могу выполнить симуляцию oop, так как мне нужно несколько раз изменить переменную. В настоящее время я пытаюсь l oop примеры из NS3 mmwave ep c tdma с различными скоростями передачи данных для ссылки. Кто-нибудь может направить меня через это? Ваша помощь будет очень ценится. У меня есть фрагмент моего кода ниже, чтобы вы, ребята, прокомментировали

#include "ns3/mmwave-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/applications-module.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/config-store.h"
#include "ns3/mmwave-point-to-point-epc-helper.h"
#include "ns3/rng-seed-manager.h"
//#include "ns3/gtk-config-store.h"
#include <sstream>
#include <string>
#include "ns3/netanim-module.h"
#include "ns3/log.h"
#include "ns3/flow-monitor-module.h"

using namespace ns3;
using namespace mmwave;

/**
 * It instantiates several eNodeB,
 * attaches one UE per eNodeB starts a flow for each UE to  and from a remote host.
 * It also  starts yet another flow between each UE pair.
 */
NS_LOG_COMPONENT_DEFINE ("MmWaveEpcTdma");
int
main (int argc, char *argv[])
{
    //LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
    //LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
    //    LogComponentEnable("mmWavePointToPointEpcHelper",LOG_LEVEL_ALL);
    //    LogComponentEnable("EpcUeNas",LOG_LEVEL_ALL);
//        LogComponentEnable ("MmWaveSpectrumPhy", LOG_LEVEL_DEBUG);
//    LogComponentEnable ("MmWaveBeamforming", LOG_LEVEL_DEBUG);
//    LogComponentEnable ("MmWaveUePhy", LOG_LEVEL_DEBUG);
//    LogComponentEnable ("MmWaveEnbPhy", LOG_LEVEL_DEBUG); //
//    LogComponentEnable ("MmWaveFlexTtiMacScheduler", LOG_LEVEL_DEBUG);
//    LogComponentEnable ("MmWaveFlexTtiMaxWeightMacScheduler", LOG_LEVEL_DEBUG);
    //LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
//    LogComponentEnable ("LteRlcAm", LOG_LEVEL_LOGIC);
    //LogComponentEnable ("LteRlcUm", LOG_LEVEL_LOGIC);
    //LogComponentEnable ("MmWaveUeMac", LOG_LEVEL_LOGIC);
    //LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
//    LogComponentEnable ("TcpClient", LOG_LEVEL_INFO);
    //LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
    //LogComponentEnable("PropagationLossModel",LOG_LEVEL_ALL);
    double ULdataRateMB = 900e6;  // 100 Mbps
    double DLdataRateMB = 100e6;  // 100 Mbps
//    int ta = 1;
for (int ta = 1; ta < 11; ta++)

    {
    uint16_t numEnb = 1;
    uint16_t numUe = 1;
    double simTime = 5.0;  //5.0
    double interPacketInterval = 100;  // 500 microseconds
    double minDistance = 10.0;  // eNB-UE distance in meters
    double maxDistance = 200.0;  // eNB-UE distance in meters
    bool harqEnabled = true;
    bool rlcAmEnabled = false; //false
    bool fixedTti = false;
    unsigned symPerSf = 14;
    double sfPeriod = 1000.0;
    unsigned run = 0;


    // Command line arguments
    CommandLine cmd;
    cmd.AddValue("numEnb", "Number of eNBs", numEnb);
    cmd.AddValue("numUe", "Number of UEs per eNB", numUe);
    cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime);
    cmd.AddValue("interPacketInterval", "Inter-packet interval [us])", interPacketInterval);
    cmd.AddValue("harq", "Enable Hybrid ARQ", harqEnabled);
    cmd.AddValue("rlcAm", "Enable RLC-AM", rlcAmEnabled);
    cmd.AddValue("symPerSf", "OFDM symbols per subframe", symPerSf);
    cmd.AddValue("sfPeriod", "Subframe period = 4.16 * symPerSf", sfPeriod);
    cmd.AddValue("fixedTti", "Fixed TTI scheduler", fixedTti);
    cmd.AddValue("run", "run for RNG (for generating different deterministic sequences for different drops)", fixedTti);
    cmd.Parse(argc, argv);

    Config::SetDefault ("ns3::MmWaveHelper::RlcAmEnabled", BooleanValue(rlcAmEnabled));
    Config::SetDefault ("ns3::MmWaveHelper::HarqEnabled", BooleanValue(harqEnabled));
    Config::SetDefault ("ns3::MmWaveFlexTtiMacScheduler::HarqEnabled", BooleanValue(harqEnabled));
    Config::SetDefault ("ns3::MmWaveFlexTtiMaxWeightMacScheduler::HarqEnabled", BooleanValue(harqEnabled));
    Config::SetDefault ("ns3::MmWaveFlexTtiMaxWeightMacScheduler::FixedTti", BooleanValue(fixedTti));
    Config::SetDefault ("ns3::MmWaveFlexTtiMaxWeightMacScheduler::SymPerSlot", UintegerValue(6));
    Config::SetDefault ("ns3::MmWavePhyMacCommon::ResourceBlockNum", UintegerValue(1));
    Config::SetDefault ("ns3::MmWavePhyMacCommon::ChunkPerRB", UintegerValue(72));
    Config::SetDefault ("ns3::MmWavePhyMacCommon::SymbolsPerSubframe", UintegerValue(symPerSf));
    Config::SetDefault ("ns3::MmWavePhyMacCommon::SubframePeriod", DoubleValue(sfPeriod));
    Config::SetDefault ("ns3::MmWavePhyMacCommon::TbDecodeLatency", UintegerValue(200.0));
    Config::SetDefault ("ns3::MmWaveBeamforming::LongTermUpdatePeriod", TimeValue (MilliSeconds (100000.0)));
    Config::SetDefault ("ns3::LteEnbRrc::SystemInformationPeriodicity", TimeValue (MilliSeconds (5.0)));
    //Config::SetDefault ("ns3::MmWavePropagationLossModel::ChannelStates", StringValue ("n"));////////////////////////////////////////////////can be comment
    Config::SetDefault ("ns3::LteRlcAm::ReportBufferStatusTimer", TimeValue(MicroSeconds(100.0)));
    Config::SetDefault ("ns3::LteRlcUmLowLat::ReportBufferStatusTimer", TimeValue(MicroSeconds(100.0)));
    Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue (320));
    Config::SetDefault ("ns3::LteEnbRrc::FirstSibTime", UintegerValue (2));

    // the applications on this example start very early.
    // Use the IDEAL mode in RRC (no radio messages are exchanged for RRC control ops)
    // and set to the minimum the latency on the S1-AP link to speed up the link and bearers setup
    Config::SetDefault ("ns3::MmWaveHelper::UseIdealRrc", BooleanValue(false)); //false
    Config::SetDefault ("ns3::MmWavePointToPointEpcHelper::S1apLinkDelay", TimeValue(Seconds(0)));

    RngSeedManager::SetSeed (1234);
    RngSeedManager::SetRun (run);

    Ptr<MmWaveHelper> mmwaveHelper = CreateObject<MmWaveHelper> ();
    mmwaveHelper->SetSchedulerType ("ns3::MmWaveFlexTtiMaxWeightMacScheduler");
    //mmwaveHelper->SetSchedulerType ("ns3::MmWaveFlexTtiMacScheduler");
    Ptr<MmWavePointToPointEpcHelper>  epcHelper = CreateObject<MmWavePointToPointEpcHelper> ();
    mmwaveHelper->SetEpcHelper (epcHelper);
    mmwaveHelper->SetHarqEnabled (harqEnabled);

    ConfigStore inputConfig;
    inputConfig.ConfigureDefaults();

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

    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 ("10Gb/s")));
    p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
    p2ph.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (100.0)));
    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 ueNodes;
    NodeContainer enbNodes;
    enbNodes.Create(numEnb);
    ueNodes.Create(numUe);

    // Install Mobility Model
    Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<ListPositionAllocator> ();
    enbPositionAlloc->Add (Vector (0.0, 0.0, 0.0));
    MobilityHelper enbmobility;
    enbmobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
    enbmobility.SetPositionAllocator(enbPositionAlloc);
    enbmobility.Install (enbNodes);

    MobilityHelper uemobility;
    Ptr<ListPositionAllocator> uePositionAlloc = CreateObject<ListPositionAllocator> ();
    Ptr<UniformRandomVariable> distRv = CreateObject<UniformRandomVariable> ();

    for (unsigned i = 0; i < numUe; i++)
    {
        double dist = distRv->GetValue (minDistance, maxDistance);
        uePositionAlloc->Add (Vector (dist, 0.0, 0.0));
    }
    uemobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
    uemobility.SetPositionAllocator(uePositionAlloc);
    uemobility.Install (ueNodes);

    // Install mmWave Devices to the nodes
    NetDeviceContainer enbmmWaveDevs = mmwaveHelper->InstallEnbDevice (enbNodes);
    NetDeviceContainer uemmWaveDevs = mmwaveHelper->InstallUeDevice (ueNodes);

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

    mmwaveHelper->AttachToClosestEnb (uemmWaveDevs, enbmmWaveDevs);

    // Install and start applications on UEs and remote host
    uint16_t dlPort = 1234;
    uint16_t ulPort = 2000;
    uint16_t otherPort = 3000;
    ApplicationContainer clientApps;
    ApplicationContainer serverApps;
    uint32_t packetSize = 1400;
    double onTimeSec = 5e-6; // packetSize / dataRateMB;
    std::stringstream ss;
    ss << "ns3::ConstantRandomVariable[Constant=" << onTimeSec << "]";
    std::cout << "OnTime == " << ss.str() << std::endl;
    OnOffHelper dlClient ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
    OnOffHelper ulClient ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
    dlClient.SetAttribute ("PacketSize", UintegerValue (packetSize));
    ulClient.SetAttribute ("PacketSize", UintegerValue (packetSize));
    dlClient.SetAttribute ("DataRate", DataRateValue (8*DLdataRateMB));
    ulClient.SetAttribute ("DataRate", DataRateValue (8*ULdataRateMB));
    dlClient.SetAttribute ("OnTime", StringValue (ss.str ()));
    ulClient.SetAttribute ("OnTime", StringValue (ss.str ()));
    ss.str("");
    ss << "ns3::ExponentialRandomVariable[Mean=" << interPacketInterval*1e-6 << "]";
    std::cout << "OffTime == " << ss.str() << std::endl;
    dlClient.SetAttribute ("OffTime", StringValue (ss.str ()));
    ulClient.SetAttribute ("OffTime", StringValue (ss.str ()));

    for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
    {
        ++ulPort;
        ++otherPort;
        PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
        PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", 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 (MicroSeconds(interPacketInterval)));
        // dlClient.SetAttribute ("MaxPackets", UintegerValue(1000000));
        // dlClient.SetAttribute ("PacketSize", UintegerValue(packetSize));

        // UdpClientHelper ulClient (remoteHostAddr, ulPort);
         // ulClient.SetAttribute ("Interval", TimeValue (MicroSeconds(interPacketInterval)));
        // ulClient.SetAttribute ("MaxPackets", UintegerValue(1000000));
        // ulClient.SetAttribute ("PacketSize", UintegerValue(packetSize));

        UdpClientHelper client (ueIpIface.GetAddress (u), otherPort);
        client.SetAttribute ("Interval", TimeValue (MicroSeconds(interPacketInterval)));
        client.SetAttribute ("MaxPackets", UintegerValue(1000000));
        dlClient.SetAttribute ("Remote", AddressValue (InetSocketAddress (ueIpIface.GetAddress (u), dlPort)));
        ulClient.SetAttribute ("Remote", AddressValue (InetSocketAddress (remoteHostAddr, ulPort)));

        clientApps.Add (dlClient.Install (remoteHost));
        clientApps.Add (ulClient.Install (ueNodes.Get(u)));
        if (u+1 < ueNodes.GetN ())
        {
            clientApps.Add (client.Install (ueNodes.Get(u+1)));
        }
        else
        {
            clientApps.Add (client.Install (ueNodes.Get(0)));
        }
    }
    serverApps.Start (Seconds (0.003));
    clientApps.Start (Seconds (0.003));
    mmwaveHelper->EnableTraces ();


    // 8. Install FlowMonitor on all nodes
  //FlowMonitorHelper flowmon;
  //Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

    Ptr <FlowMonitor> monitor;
    FlowMonitorHelper flowmon;
    monitor = flowmon.Install (ueNodes);
    monitor = flowmon.Install (remoteHostContainer);

    // Uncomment to enable PCAP tracing
    std::string s = "caseUDP Bi-directional Adjusted Case"+ std::to_string(ta);
     p2ph.EnablePcapAll(s);
    AnimationInterface anim("animcaseUDP02TrialBidirectional");
    Simulator::Stop(Seconds(simTime));
    Simulator::Run();

    //flow monitor
  monitor->CheckForLostPackets ();
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
    {
      if (i->first > 0)
        {
          Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
          std::cout << "Flow " << i->first - 0 << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
          std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";
          std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";
          std::cout << "  Tx Packets:   " << i->second.txPackets << "\n";
          std::cout << "  Rx Packets:   " << i->second.rxPackets << "\n";
          std::cout << "  Lost Packets:   " << i->second.txPackets - i->second.rxPackets << "\n";
          std::cout << "  Throughput:   " << (i->second.txBytes - i->second.rxBytes)* 8.0 / 10.0 / 1000 / 1000  << " Mbytes\n";
          std::cout << "  Times Forwarded:   " << float(i->second.timesForwarded) << "\n";
          std::cout << "  Mean Hop Count:   " << float(i->second.timesForwarded) /  (i->second.txBytes - i->second.rxBytes)  + 1 << "\n";
          std::cout << "  Mean Delay:   " << i->second.delaySum.GetSeconds() / (i->second.txBytes - i->second.rxBytes) << "\n";
          std::cout << "  Sum Delay:   " << i->second.delaySum.GetSeconds() << "\n";
          std::cout << "  Mean Jitter:   " << i->second.jitterSum.GetSeconds() / (i->second.rxPackets-1)<< "\n";
          std::cout << "  Last Delay:   " << i->second.lastDelay.GetSeconds() << "\n";
          std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / 10.0 / 1000 / 1000  << " Mbytes\n";
          std::cout << "  Delay Histogram:   " << i->second.delayHistogram.GetNBins ()  << "\n";
          std::cout << "  Jitter Histogram:   " << i->second.jitterHistogram.GetNBins ()  << "\n";
          std::cout << "  Packet Size Histogram:   " << i->second.packetSizeHistogram.GetNBins ()  << "\n";
          std::cout << "  Flow Interruptions Histogram:   " << i->second.flowInterruptionsHistogram.GetNBins ()  << "\n";            
        }
    }
    /*GtkConfigStore config;
  config.ConfigureAttributes();*/

    ULdataRateMB=ULdataRateMB-100e6;
    DLdataRateMB=DLdataRateMB+100e6;
    return ULdataRateMB;
    return DLdataRateMB;
    // return 0;
    Simulator::Destroy();
}}
...