Usage of Config::Set

240 views
Skip to first unread message

Harald Ott

unread,
Aug 6, 2016, 3:39:54 PM8/6/16
to ns-3-users
I'm trying to change the DataRate at runtime, but I just can't get it to work unfortunately.
Yes, I have read the documentation and other discussions in this forum, but I just can't apply it to my case.
Here's my main function:

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

 
CommandLine cmd;
  cmd
.AddValue ("useIpv6", "Use Ipv6", useV6);
  cmd
.Parse (argc, argv);

  NS_LOG_INFO
("Create nodes.");
 
NodeContainer n;
  n
.Create (4);

 
InternetStackHelper internet;
  internet
.Install (n);

  NS_LOG_INFO
("Create channels.");

 
CsmaHelper csma;
  csma
.SetChannelAttribute ("DataRate", DataRateValue (DataRate (10000)));
  csma
.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
  csma
.SetDeviceAttribute ("Mtu", UintegerValue (1400));
 
NetDeviceContainer d = csma.Install (n);

  NS_LOG_INFO
("Assign IP Addresses.");

     
Ipv4AddressHelper ipv4;
      ipv4
.SetBase ("10.1.1.0", "255.255.255.0");
     
Ipv4InterfaceContainer i = ipv4.Assign (d);
      serverAddress
= Address(i.GetAddress (1));


  NS_LOG_INFO
("Create Applications.");

  uint16_t port
= 9;  // well-known echo port number
 
TcpStreamServerHelper server (port);
 
ApplicationContainer apps = server.Install (n.Get (1));
  apps
.Start (Seconds (1.0));
  apps
.Stop (Seconds (10.0));


 
TcpStreamClientHelper client (serverAddress, port);
  apps
= client.Install (n.Get (0));

 
IntegerValue integerValueTemp;
 
GlobalValue::GetValueByName ("simulationStartTime", integerValueTemp);
  apps
.Start (MicroSeconds (integerValueTemp.Get ()));
  apps
.Stop (Seconds (5000.0));

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

I've left out the parts that are not of interest for the question.
I know that I need something like this:

Simulator::Schedule (Seconds(7.5), Config::Set, ".../<container name>/<index>/.../<attribute>/<attribute>",
 
DataRateValue (DataRate (1000)));

But I just don't know how I can access the channel attribute I've set at

csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (10000)));

through a path?
If someone could supply me with the exact path I need to specify, that would be great
Message has been deleted

Harald Ott

unread,
Aug 7, 2016, 7:51:40 AM8/7/16
to ns-3-users
In more detail:
What do I have to insert at
".../<container name>/<index>/.../<attribute>/<attribute>"
?

Konstantinos

unread,
Aug 8, 2016, 5:00:49 AM8/8/16
to ns-3-users
Hi Harald,

For the API you can find the correct config path

ns3::CsmaChannel is accessible through the following paths with Config::Set and Config::Connect:

  • "/ChannelList/[i]/$ns3::CsmaChannel"

I do not think you have multiple channels in your scenario, so '0' should work. Otherwise you can use the wildcard '*'. 
In terms of attributes, again from the API you have Delay and DataRate 
  • DataRate: The transmission data rate to be provided to devices connected to the channel
    • Set with class: DataRateValue
    • Underlying type: DataRate
    • Initial value: 4294967295bps
    • Flags: construct write read
  • Delay: Transmission delay through the channel
    • Set with class: ns3::TimeValue
    • Underlying type: Time –9223372036854775808.0ns:+9223372036854775807.0ns
    • Initial value: +0.0ns
    • Flags: construct write read

Regard,
K

Harald Ott

unread,
Aug 9, 2016, 12:31:09 PM8/9/16
to ns-3-users
Hi Konstantinos, thanks for your answer.
I've tried for example

Simulator::Schedule (Seconds(7.5), Config::Set, "/ChannelList/*/$ns3::CsmaChannel/DataRate", DataRateValue (DataRate (100)));


changing the original DataRate of 10000 to 100, looking at the debug output at ~7.5 seconds, no changes in throughput, so it doesn't seem to work unfortunately...

Konstantinos

unread,
Aug 9, 2016, 12:50:00 PM8/9/16
to ns-3-users
Hi,

Please study the documentation of the Simulator (https://www.nsnam.org/docs/manual/html/events.html#simulator) to understand how you use Schedule()

There are two basic ways to schedule events, with and without context. What does this mean?

Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj);

vs.

Simulator::ScheduleWithContext (uint32_t context, Time const &time, MEM mem_ptr, OBJ obj);

I would suggest to create a simple static method called "ChangeRate" 

static void ChangeRate()
{
 
Config::Set("/ChannelList/*/$ns3::CsmaChannel/DataRate", DataRateValue (DataRate (100)));
 
return;
}

then  use the Schedule to call that.

Simulator::Schedule (Seconds(7.5), &ChangeRate);

Harald Ott

unread,
Aug 9, 2016, 1:48:16 PM8/9/16
to ns-3-users
Hi Konstantinos,

I've implemented what you suggested, added a NS_LOG_CONFIG("TEST") to ChangeRate(), and it definitely gets called at 7.5 seconds, but I still can't see a change in the DataRate, looking at the file which keeps track of the throughput.
It should fall down at 7.5 seconds, because when I put it to 100 from the beginning, it stays down, but when I try to put it that low with simulator::schedule, it somehow doesn't change...

Harald Ott

unread,
Aug 10, 2016, 8:38:02 AM8/10/16
to ns-3-users
I've now also tried to set the Datarate at my

CsmaHelper csma;

not with (this way it works):

csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (1300)));

but instead directly with:

Config::Set("/ChannelList/*/$ns3::CsmaChannel/DataRate", DataRateValue (DataRate (1300)));

noticing, that the latter doesn't set the DataRate, but the DataRate seems to remain at the Initial value: 4294967295bps (according to API), so it doesn't do anything.
How is this possible ?

Reply all
Reply to author
Forward
0 new messages