How to see Animation in Clustering for Vehicular Ad-hoc Nework

494 views
Skip to first unread message

Justin

unread,
Apr 11, 2017, 1:12:14 AM4/11/17
to ns-3-users
Dear Sir,

I intended to add Animation in this code. I already added "#include "ns3/netanim-module.h"" and "AnimationInterface anim ("v2v.xml");" to create "v2v.xml" file. However, I can not see the "v2v.xml" file in "ns3" folder. The following is the code:

#include "ns3/core-module.h"
#include "ns3/ocb-wifi-mac.h"
#include "ns3/network-module.h"
#include "ns3/wave-mac-helper.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/wifi-80211p-helper.h"
#include "ns3/applications-module.h"
#include "ns3/config-store-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/v2v-control-client-helper.h"
#include "ns3/v2v-mobility-model.h"

#include "ns3/netanim-module.h"


#define SIMULATION_TIME_FORMAT(s) Seconds(s)


using namespace ns3;
NS_LOG_COMPONENT_DEFINE("V2vClusteringExample");


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

    /*--------------------- Logging System Configuration -------------------*/
    LogLevel logLevel = (LogLevel) (LOG_PREFIX_ALL | LOG_LEVEL_WARN);
    LogComponentEnable("V2vClusteringExample", logLevel);
    LogComponentEnable("V2vControlClient", logLevel);

    NS_LOG_INFO("/------------------------------------------------\\");
    NS_LOG_INFO(" - V2vClusteringExample [Example] -> Cluster vehicles communication");
    NS_LOG_INFO("\\------------------------------------------------/");
    /*----------------------------------------------------------------------*/

    /*---------------------- Simulation Default Values ---------------------*/
    std::string phyMode ("OfdmRate6MbpsBW10MHz");

    uint16_t numberOfUes = 10;

    double minimumTdmaSlot = 0.001;         /// Time difference between 2 transmissions
    double clusterTimeMetric = 3.0;         /// Clustering Time Metric for Waiting Time calculation
    double speedVariation = 5.0;
    double incidentWindow = 30.0;

    double simTime = 30.0;
    /*----------------------------------------------------------------------*/


    /*-------------------- Set explicitly default values -------------------*/
    Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
                            StringValue ("2200"));
    // turn off RTS/CTS for frames below 2200 bytes
    Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
                            StringValue ("2200"));
    // Fix non-unicast data rate to be the same as that of unicast
    Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
                            StringValue (phyMode));
    /*----------------------------------------------------------------------*/


    /*-------------------- Command Line Argument Values --------------------*/
    CommandLine cmd;
    cmd.AddValue("ueNumber", "Number of UE", numberOfUes);
    cmd.AddValue("simTime", "Simulation Time in Seconds", simTime);

    NS_LOG_INFO("");
    NS_LOG_INFO("|---"<< " SimTime -> " << simTime <<" ---|\n");
    NS_LOG_INFO("|---"<< " Number of UE -> " << numberOfUes <<" ---|\n");
    /*----------------------------------------------------------------------*/


    /*------------------------- Create UEs-EnodeBs -------------------------*/
    NodeContainer ueNodes;
    ueNodes.Create(numberOfUes);

    InternetStackHelper internet;
    internet.Install(ueNodes);
    /*----------------------------------------------------------------------*/


    /*-------------------- Install Mobility Model in Ue --------------------*/
    MobilityHelper ueMobility;
    ueMobility.SetMobilityModel ("ns3::V2vMobilityModel",
         "Mode", StringValue ("Time"),
         "Time", StringValue ("40s"),
         "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=30.0]"),
         "Bounds", RectangleValue (Rectangle (0, 10000, -1000, 1000)));
    ueMobility.Install(ueNodes);

    /// Create a 3 line grid of vehicles
    for (uint16_t i = 0; i < numberOfUes; i++)
    {
        if(i % 3 == 0){
            ueNodes.Get (i)->GetObject<MobilityModel> ()->SetPosition (Vector (i*5, 0, 0));
        }
        else if(i % 3 == 1){
            ueNodes.Get (i)->GetObject<MobilityModel> ()->SetPosition (Vector (i*5, 3, 0));
        }
        else{
            ueNodes.Get (i)->GetObject<MobilityModel> ()->SetPosition (Vector (i*5, 6, 0));
        }

    }
    /*----------------------------------------------------------------------*/


    /*-------------------------- Setup Wifi nodes --------------------------*/
    // The below set of helpers will help us to put together the wifi NICs we want
    YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
    Ptr<YansWifiChannel> channel = wifiChannel.Create ();

    YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
    wifiPhy.SetChannel (channel);
    wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11);
    wifiPhy.Set ("TxPowerStart", DoubleValue(32));
    wifiPhy.Set ("TxPowerEnd", DoubleValue(32));
    wifiPhy.Set ("TxGain", DoubleValue(12));
    wifiPhy.Set ("RxGain", DoubleValue(12));
    wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue(-61.8));
    wifiPhy.Set ("CcaMode1Threshold", DoubleValue(-64.8));

    NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
    Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
    //wifi80211p.EnableLogComponents ();

    wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                      "DataMode",StringValue (phyMode),
                                      "ControlMode",StringValue (phyMode));
    NetDeviceContainer wifiDevices1 = wifi80211p.Install (wifiPhy, wifi80211pMac, ueNodes);

    NS_LOG_INFO ("Assign IP Addresses.");
    Ipv4AddressHelper ipv4h;
    ipv4h.SetBase ("10.1.1.0", "255.255.255.0");
    Ipv4InterfaceContainer i1 = ipv4h.Assign (wifiDevices1);

    uint16_t controlPort = 3999;
    ApplicationContainer controlApps;

    /**
     * Setting Control Channel
     */
    for (uint32_t u = 0; u < ueNodes.GetN(); ++u) {

        //!< Initial TDMA UE synchronization Function
        double tdmaStart = (u+1)*minimumTdmaSlot;

        Ptr<V2vMobilityModel> mobilityModel = ueNodes.Get(u)->GetObject<V2vMobilityModel>();
        mobilityModel->SetSpeedVariation(speedVariation);
        V2vControlClientHelper ueClient("ns3::UdpSocketFactory", Address(InetSocketAddress(Ipv4Address::GetBroadcast(), controlPort)),
                "ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(), controlPort),
                mobilityModel, tdmaStart, numberOfUes, minimumTdmaSlot, clusterTimeMetric);
        ueClient.SetAttribute ("IncidentWindow", DoubleValue(incidentWindow));
        controlApps.Add(ueClient.Install(ueNodes.Get(u)));
    }

    controlApps.Start (Seconds(0.1));
    controlApps.Stop (Seconds(simTime-0.1));

    AsciiTraceHelper ascii;
    wifiPhy.EnableAsciiAll(ascii.CreateFileStream ("src/v2v/examples/output/socket-options-ipv4.txt"));
    wifiPhy.EnablePcapAll ("src/v2v/examples/output/socket.pcap", false);

    /*----------------------------------------------------------------------*/

   
    /*---------------------- Simulation Stopping Time ----------------------*/
    Simulator::Stop(SIMULATION_TIME_FORMAT(simTime));
    /*----------------------------------------------------------------------*/
    AnimationInterface anim ("v2v.xml");
    /*--------------------------- Simulation Run ---------------------------*/
    Simulator::Run();
    Simulator::Destroy();
    /*----------------------------------------------------------------------*/

    return EXIT_SUCCESS;
}



Could you help me to solve this problem ?
Thank you for your help.

Konstantinos

unread,
Apr 11, 2017, 4:43:36 AM4/11/17
to ns-3-users
Dear Justin,

We can not run your scenario as it involves proprietary codes (v2v-mobility, v2v-controller etc).
The file should be generated in the folder that you run /waf, i.e. in the ns3 base.

Regards

Justin

unread,
Apr 11, 2017, 7:52:31 AM4/11/17
to ns-3-users
Dear Sir,

Enclosed is all the file I used. The code is run successfully. I already checked carefully but I can not find "v2v.xml" file.
Could you help me to check it ?

Thank you for your help.

Vào 17:43:36 UTC+9 Thứ Ba, ngày 11 tháng 4 năm 2017, Konstantinos đã viết:
v2v.rar

Konstantinos

unread,
Apr 11, 2017, 9:30:56 AM4/11/17
to ns-3-users
Dear Justin,

I can not run your code. There are several error related to random-variable. 
Apparently you are using an out-dated ns-3 release. 
RandomVariable class has been replaced by RandomVariableStream, and that's not just now.... it's been for several releases.

v2v-mobility-model.cc:27:10: fatal error: 'ns3/random-variable.h' file not found

#include "ns3/random-variable.h"

         ^

1 error generated.


v2v-control-client.cc:42:10: fatal error: 'ns3/random-variable.h' file not found

#include "ns3/random-variable.h"

         ^

1 error generated.

Konstantinos

unread,
Apr 11, 2017, 9:33:54 AM4/11/17
to ns-3-users
Also, if you are running your example as it is (not in scratch) you will need to NetAnim dependency in the wscript file as explained in the documentation
Mandatory
 0. Ensure that your wscript includes the "netanim" module. Example as in: src/netanim/examples/wscript. 
 1. Also include the header [#include "ns3/netanim-module.h"] in your test program
 2. Add the statement "AnimationInterface anim ("animation.xml");" before Simulator::Run()

Justin

unread,
Apr 12, 2017, 3:35:05 AM4/12/17
to ns-3-users
Dear Sir,

I already inserted in wscript file in src/v2v folder  "netanim" module. Before I inserted, it was follows

def build(bld):
    module = bld.create_ns3_module('v2v', ['core', 'internet','wave'])
    module.source = [
        'model/v2v-control-client.cc',
        'model/v2v-cluster-sap.cc',
        'model/v2v-cluster-header.cc',
        'model/v2v-mobility-model.cc',
        'helper/v2v-control-client-helper.cc'
        ]

After I inserted "netanim" module

  def build(bld):
    module = bld.create_ns3_module('v2v', ['netanim','core', 'internet','wave'])
    module.source = [
        'model/v2v-control-client.cc',
        'model/v2v-cluster-sap.cc',
        'model/v2v-cluster-header.cc',
        'model/v2v-mobility-model.cc',
        'helper/v2v-control-client-helper.cc'
        ]

I already used "./waf configure --enable-examples --enable-tests" and "./waf build" to make this changed. However, I also haven't received "v2v.xml" file.

Could you show me if I added "netanim" is correct ?

Thank you for your help.
Vào 22:33:54 UTC+9 Thứ Ba, ngày 11 tháng 4 năm 2017, Konstantinos đã viết:
wscript

Justin

unread,
Apr 12, 2017, 4:03:18 AM4/12/17
to ns-3-users
Dear Sir,

I also inserted in wscript file in src/v2v/examples folder  "netanim" module. Before I inserted, it was follows

    def build(bld):
    obj = bld.create_ns3_program('v2v-clustering-example', ['v2v'])
    obj.source = 'v2v-clustering-example.cc'


After I inserted "netanim" module

    def build(bld):
    obj = bld.create_ns3_program('v2v-clustering-example', ['v2v','netanim'])
    obj.source = 'v2v-clustering-example.cc'


I already used "./waf configure --enable-examples --enable-tests" and "./waf build" to make this changed. However, I also haven't received "v2v.xml" file.

Could you show me if I added "netanim" is correct ?

Thank you for your help.

Vào 22:33:54 UTC+9 Thứ Ba, ngày 11 tháng 4 năm 2017, Konstantinos đã viết:
wscript

Konstantinos

unread,
Apr 12, 2017, 4:40:38 AM4/12/17
to ns-3-users
That looks correct, but as I said in my previous post, I can not run your scenario in the current ns-3 release due to errors coming from the RandomVariable.
Upgrade your ns-3 and your scripts to run in the latest ns-3 and if there is still an issue, I could give it another try.

Regards,
K

Justin

unread,
Apr 12, 2017, 8:09:45 AM4/12/17
to ns-3-users
Dear Sir,

Thank you very much for your help. I already saw 'v2v.xml' file.

Vào 17:40:38 UTC+9 Thứ Tư, ngày 12 tháng 4 năm 2017, Konstantinos đã viết:

Krichen Maryem

unread,
Apr 13, 2017, 9:41:11 AM4/13/17
to ns-3-users
Hi I had the same issue of the old randomVariale.h , so i changed it to include the new RandomVariableStream , i had some troubles changing the code to use the new RandomStream library.

Did anyone change it ? or does anyone have another solution to get random doubles ?
Reply all
Reply to author
Forward
0 new messages