How to set the transmission rate in a dynamic way ?

228 views
Skip to first unread message

Boong Baang

unread,
Mar 24, 2020, 11:21:19 AM3/24/20
to ns-3-users
In WAVE module, by default the packets are broadcast at 10 Hz. Now if I want to change this and set this rate based on some parameter that I calculate inside the simulation, how do i go about it ?
E.g. if I want my transmission rate to change based on PDR/throughput, how should I approach it ?

Gopal Rawat

unread,
Mar 26, 2020, 9:21:00 AM3/26/20
to ns-3-users
I am trying to work on somthing similar. The WAVE module is using bsm-application.cc and wave-bsm-helper.cc to achieve beaconing.

In wave-bsm-helper.cc (111-130) we have this section , i believe you are interested in modifying something here.

   // for each app, setup the app parameters
  int nodeId = 0;
  for (aci = bsmApps.Begin (); aci != bsmApps.End (); ++aci)
    {
      Ptr<BsmApplication> bsmApp = DynamicCast<BsmApplication> (*aci);
      bsmApp->Setup (i,
                     nodeId,
                     totalTime,
                     wavePacketSize,
                     waveInterval,
                     gpsAccuracyNs,
                     m_txSafetyRangesSq,
                     GetWaveBsmStats (),
                     &nodesMoving,
                     chAccessMode,
                     txMaxDelay);
      nodeId++;
    }
}

I am new to ns3 and still exploring it , the apps installed on each node would require some modification. As of now, i have no idea how we can achieve it.

Gopal Rawat

unread,
Mar 26, 2020, 1:39:59 PM3/26/20
to ns-3-users
Also , When closely looking at  bsm-application.cc it can be seen that the application starts and calculates the number of wave packets to be sent for the whole simulation. GenerateWaveTraffic works accordingly and thus limits the scope of dynamic waveInterval in the current  wave module.

So i think dynamic wave-interval functionality would require a lot of additional work in both these files. Correct me if i am wrong ?

Boong Baang

unread,
Mar 26, 2020, 9:09:30 PM3/26/20
to ns-3-users
I haven't looked in detail, and I was hoping there would be some trigger like functions available to start a transmission based on some satisfied criterias. Thanks for pointing out the relevant part of the code, will look into it and update if I make any progress.

Adil Alsuhaim

unread,
Mar 28, 2020, 11:06:06 AM3/28/20
to ns-3-users
If you have access to the WaveNetDevice pointer, you can call WaveNetDevice::SendX with specific TxInfo to specify the WifiMode per packet to one of the supported modes. It would look something like this:

TxInfo tx;
tx.channelNumber = CCH; 
tx.priority = 7; //highest priority.
tx.txPowerLevel = 7;
tx.dataRate = WifiMode("OfdmRate6MbpsBW10MHz"); // You can change this dynamically, per packet.
Ptr<Packet> packet = Create <Packet> (m_packetSize);

//Broadcast the packet as WSMP (0x88dc) where m_waveDevice is of type WaveNetDevice
m_waveDevice->SendX (packet, Mac48Address::GetBroadcast(), 0x88dc, tx);

I have an example that does that on my GitHub that creates a custom application (named CustomApplication) and uses WaveNetDevice to periodically send data. You can change the value of the WifiMode to any of the supported modes, like OfdmRate3MbpsBW10MHz or  OfdmRate27MbpsBW10MHz


Just download the CustomApplicationExample directory to scratch directory and run it with ./waf --run CustomApplicationExample

Cheers,

Adil


Gopal Rawat

unread,
Mar 28, 2020, 1:11:07 PM3/28/20
to ns-3-users
Hi Adil ,

Thanks for sharing your work , I want to know how can we change the beacon interval for an individual node ?

I assume we have to access the corresponding app and then access SetBroadcastInterval ( Time interval ) for the same. But  i am not able to access it ( if that's the correct way ).

Regards,
Gopal

Gopal Rawat

unread,
Mar 28, 2020, 2:54:44 PM3/28/20
to ns-3-users

I am trying something like this and the PhyTxBegin  traces suggest that the beacon interval is getting changed. So i assume this is one of the way.

 // for some condition
{
   NS_LOG_UNCOND("beacon interval is 0.5s ");
 
 
Ptr<Node> node;
 
for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
   
{
      node
= (*i);
     
for (uint32_t j = 0; j < node->GetNApplications (); j++)
       
{
         
Ptr<CustomApplication> app_i = DynamicCast<CustomApplication> (node->GetApplication (j));
          app_i
->SetBroadcastInterval (Seconds(0.5));
       
}
   
}
}


Gopal Rawat

unread,
Mar 30, 2020, 3:17:55 PM3/30/20
to ns-3-users
Hi Adil ,

When i try to change the Data rate for a particular node (let's say)  c , i am able to do it. However the problem is that it happens only once and if i try to schedule this event it happens twice (one with this Data rate and the other with Data rate when application was set up).

Is there any other way of changing the data rate of a node during the simulation ?  Am i missing something here ?

void changeDataRate(NodeContainer& nodes, uint32_t c)
{
  uint32_t m_packetSize
;

 
Ptr<Node> node;
 
for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
   
{
      node
= (*i);

 
if ( node->GetId() == c)
       
{
         
Ptr<NetDevice> dev = node->GetDevice (0);
         
Ptr<WaveNetDevice> m_waveDevice = DynamicCast <WaveNetDevice> (dev);    
         
//(3,6,9,12,18,24,27) for supported modes https://www.nsnam.org/doxygen/wifi-phy_8cc_source.html
         
         
TxInfo tx;
         tx
.dataRate = WifiMode("OfdmRate3MbpsBW10MHz");
         m_packetSize
= 200;
         
Ptr<Packet> packet = Create <Packet> (m_packetSize);

         m_waveDevice
->SendX (packet, Mac48Address::GetBroadcast(), 0x88dc, tx);


         NS_LOG_UNCOND
("tx data rate of node("<< node->GetId()<<") is" << " 3Mbps");
         
// Simulator::Schedule (Seconds(0.1), &changeDataRate,nodes,c);  
       
}
     
}
}


regards,
Gopal

On Saturday, 28 March 2020 20:36:06 UTC+5:30, Adil Alsuhaim wrote:

Boong Baang

unread,
Apr 21, 2020, 12:46:31 PM4/21/20
to ns-3-users
Hey Gopal, were you able to solve the problem of dynamic controlling of rates ?

Gopal Rawat

unread,
Apr 21, 2020, 1:02:47 PM4/21/20
to ns-3-users
Hi,

If you mean by using the default bsm-application then answer is no , but if you follow this thread i have posted the code using which you can change the beacon rate for a particular node ( its working ).

However if you are interested in changing the data rate , then i have posted the code for that too but it does change per packet (not working properly as i intend it to).
So for change in data rate i have no further progress.

Just to add, both the changes are performed on CustomApplication shared on this thread.

regards,
G.

Adil Alsuhaim

unread,
Apr 25, 2020, 1:05:20 PM4/25/20
to ns-3-users
Sorry for the late reply. I don't always check these forums, but you can always send me an email.

The method given changes the data rate on per-packet basis. If not specified, the default DataRate used for setup of WifiRemoteStationManager will be used. So this doesn't set the default rate (WifiMode) but rather sets it for one packet. I tried to to find a way to change the value after you have set it up, but couldn't find a way to do it. 

The way my method works is by creating an "Application" and then you can have a setter function (let's call it SetWifiMode or SetDataRate) which changes a class's instance variable for the next transmission. You would change CustomApplication like this:

class CustomApplication
{
 
public:
   
...
   
void SetWifiMode (WifiMode mode);
   
...
 
private:
     
WifiMode m_mode;
     
...
}

The .cc file
CustomApplication::SetWifiMode (WifiMode mode)
{
  m_mode
= mode
}
CustomApplication::BroadcastInformation ()
{
   
TxInfo tx;
    tx
.mode = m_mode;
   
...
   
// proceed to broadcast the packet (and subsequent packets) with this data rate until you call SetWifiMode with a different mode.
}

and then when you need to change the rate for the next broadcast, call CustomApplication's SetWifiMode. Let's say we want to change it for node 0
Ptr <Node> n = NodeList::GetNode (0); //you can also use the node container.
Ptr <CustomApplication> c_app = DynamicCast<CustomApplication> (n->GetApplication (0)); //assuming only one application installed in node.
c_app
->SetWifiMode ( WifiMode("OfdmRate3MbpsBw10MHz") );

Cheers,

Adil




Gopal Rawat

unread,
Apr 26, 2020, 7:56:32 AM4/26/20
to ns-3-users

Thanks Adil for this informative response. I made the changes and it works as intended.

For future references(minor correction): tx.dataRate = m_mode;  // instead of tx.mode = m_mode;

regards,
G.

Hemant Saini

unread,
Apr 28, 2020, 10:12:54 PM4/28/20
to ns-3-...@googlegroups.com
Hi gopal ji
Can you pl help in my other post for Manhattan grid mobility code for ns3

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/f0e72939-bde4-48a5-8796-b7ff82615a03%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages