How to change bandwidth (data rate) over time in a channel.

3,348 views
Skip to first unread message

Quang N. N.

unread,
Jan 16, 2016, 11:43:42 PM1/16/16
to ns-3-users
Hi all, 
I have a problem:

// Network topology
//
//  n0
//     \ local
//      \          a Mb/s, 30ms
//       n3 -------------------------n2
//      /
//     / local
//   n1
//
// - all links are point-to-point links with indicated one-way BW/delay
// - local mean: bw = infinite, delay = 0.
// - HTTP flows from n2 to n0, and from n2 to n1 (n2 is http server; n0 and n1 is http client).

My question is: 
How to set the n3-n2 channel bandwidth (bottleneck-link) with:
+ in the first 100s in simulation time, a = 3Mbps, 
+ in the remaining simulation time, a = 8Mbps.

This is my way but this doesn't work, 

void BandwidthTrace(PointToPointHelper &p2p, NodeContainer &nc, NetDeviceContainer &ndc) 
{
    double t;
    string s;
        
    t = Simulator::Now ().GetSeconds ();
    Simulator::Schedule (MilliSeconds(100) , &BandwidthTrace, p2p, nc, ndc);
    if ( t <= 100) {
          p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
          p2p.SetDeviceAttribute ("DataRate", StringValue ("3Mbps"));\
          ndc = p2p.Install (nc);
     }
    else {
          p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
          p2p.SetDeviceAttribute ("DataRate", StringValue ("8Mbps"));
          ndc = p2p.Install (nc);
    }
}

and in the main function:
NodeContainer c;
c.Create (4);
... 
NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));;
NetDeviceContainer d3d2;
...
BandwidthTrace ( p2p, n3n2, d3d2);

As i understand that 'DataRate' is bandwidth (unit: bps) of channel.
throughput is calculated independently by each client: thrp = (data downloaded in delta_t interval) / delta_t;

With 600s of simulation, client's throughput is about 1.5 Mbps, this mean when t > 100, the setup process doesn't affect.

Do you have any advice ? Thank you so much!

Tommaso Pecorella

unread,
Jan 17, 2016, 5:42:27 AM1/17/16
to ns-3-users
Hi,

your code contains two wrongdoings.
The first one is simple: you're installing over and over a new NetDevice on the links:
ndc = p2p.Install (nc);

This will only lead to an explosion of NetDevices, but only the first one you did create (at time zero) had IP installed. The others... well, it's complicated. Let's say that it's not a good idea to do it.

The second problem is that you don't need to schedule a function to repeat itself every 100 milliseconds just to check when time reaches 100 seconds. Just schedule it to be executed at time 100 !

Anyway, the point is: don't install new NetDevices. Change the attributes of the ones you already have.

T.

Quang N. N.

unread,
Jan 17, 2016, 12:15:31 PM1/17/16
to ns-3-users
At first, thank you Mr. Tommaso Pecorella for your reply.
Yes, you are right. This is not my optimal version. I only concentrate on change bandwidth of n3-n2 link.  
I tried some ways but these doesn't help. As your advice, I rewrite my code as below:

void BandwidthTrace(PointToPointHelper &p2p) 
{
    p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
    p2p.SetDeviceAttribute ("DataRate", StringValue ("8Mbps"));
}
 
in the main function:
p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
p2p.SetDeviceAttribute ("DataRate", StringValue ("3Mbps")); 
d3d2= p2p.Install (n3n2); 
Simulator::Schedule (Seconds(100) , &BandwidthTrace, p2p); // but as i read from point-to-point-helper.cc, we have to use point-to-point-helper::Install after set these attributes. 

I only focus on How to change bw from 3 -> 8 Mbps after 100s. But this still doesn't work.
Do you have any idea ? Thank you again.

BR.,
Quang


Vào 17:42:27 UTC+7 Chủ Nhật, ngày 17 tháng 1 năm 2016,

Konstantinos

unread,
Jan 17, 2016, 2:48:53 PM1/17/16
to ns-3-users
Hi Quang,

You should not use the P2P helper to change the attributes, as you have correctly identified that this will only take effect after an install.
What Tommaso tried to point you towards, was to use the attribute of the p2p NetDevice and p2p Channel.

You can use the Config::Set() method to change the attribute of the NetDevice (replace the red part to match the node/device of the node)

Config::Set("/NodeList/[i]/DeviceList/[i]/$ns3::PointToPointNetDevice/DataRate", StringValue(3Mbps) );

Similarly for the Channel use the config path
  • "/ChannelList/[i]/$ns3::PointToPointChannel/Delay"

Quang N. N.

unread,
Jan 19, 2016, 2:47:53 AM1/19/16
to ns-3-users
Many thanks Mr. Konstantinos,
Sorry for my late reply, 
I am successfully in changing bw (bps) of channel in case of 1 client-1 server with your solution. But I spent many hours in learning how to change bw in case of one more clients, Eg. 2 clients, I can't figure out why ?

- This is my code in case of 1 client:
// Network topology
//
/                  local               a Mb/s, 30ms
// (client) n0-------------- n2 -------------------------n1 (server)
                                      (I want this link is the bottle-neck link)

void BandwidthTrace()
{
  Config::Set("/NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/DataRate", StringValue("3Mbps") );
}
In main method:

p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
p2p.SetDeviceAttribute ("DataRate", StringValue ("8Mbps"));\
ndc = p2p.Install (nc);
Simulator::Schedule (Seconds(100) , &BandwidthTrace);

The result is what I want: measured throughput of client (node n0) is about 8Mbps from 0-100 s, decrease to 3Mbps at 100s.
(throughput is calculated independently by each client: thrp = (data downloaded in delta_t interval) / delta_t;)

- With the case of 2 clients:
// Network topology
//
//  n0
//     \ local
//      \          a Mb/s, 30ms
//       n3 -------------------------n2
//      /
//     / local
//   n1
// 

void BandwidthTrace()
{
  Config::Set("/NodeList/2/DeviceList/2/$ns3::PointToPointNetDevice/DataRate", StringValue("3Mbps") );
   // As I understand, this line will limit the rate device2 / node2 transmit data stream, in this case is the rate which server push data to the link n3-n2 ? 
}
In the main method:
p2p.SetChannelAttribute ("Delay", StringValue ("30ms"));
p2p.SetDeviceAttribute ("DataRate", StringValue ("8Mbps"));\
ndc = p2p.Install (nc);
Simulator::Schedule (Seconds(100) , &BandwidthTrace); (*)

 Why does this code not take any effect ? I mean that if I remove the line (*), there are no change of measured throughput of all clients.
What's wrong with this code?

Thank you for your help !

BR.,
Quang
 
Vào 02:48:53 UTC+7 Thứ Hai, ngày 18 tháng 1 năm 2016, Konstantinos đã viết:

Konstantinos

unread,
Jan 19, 2016, 3:36:47 AM1/19/16
to ns-3-users
Hi Quang,

The problem is in the numbering of your NetDevices.


  Config::Set("/NodeList/2/DeviceList/2/$ns3::PointToPointNetDevice/DataRate", StringValue("3Mbps") );
   // As I understand, this line will limit the rate device2 / node2 transmit data stream, in this case is the rate which server push data to the link n3-n2 ? 

That's partly correct.
NodeList/2 = this is the third node in your scenario, node_0 being the first. So node_2 is the third node.
DeviceList/2 = this is the third NetDevice installed on that particular node. In your scenario node_2 has only 1 NetDevice.

Note that the numbering follows the order of installing/creating the devices. 

Also, I would recommend to set the DataRate to 3Mbps also on the reverse parth, i.e. configure the NetDevice on both node_2 and node_3.

Regards,
K.

Quang Nguyen Ngoc

unread,
Jan 20, 2016, 5:17:54 AM1/20/16
to ns-3-...@googlegroups.com

Thank you so much Mr. Konstantinos and Mr. Tommaso for your help !
Finnally, my project is ran. Although this is just the first step, but this is very important.
It is certainly that I still need your help in the future. So I hope that you can still help more people as possible.
Thank you again and hope you healthy and happy !
BR.
Quang

Vào 19-01-2016 15:36, "Konstantinos" <dinos.k...@gmail.com> đã viết:
--
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 a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/rJaWMVixcmY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Wenkai Wan

unread,
Dec 16, 2016, 6:18:29 AM12/16/16
to ns-3-users
Hi, who can help me.
I have a problem about change bandwidth in a channel
I need to change bandwidth every 100ms, I get bandwidth from a downlink.txt,
and i did follow up methodology, but bandwidth in channel had not change.

//network topology
//                                            bandwidth                     
//                                                 |
//                                                 | change every 100ms
//                                                 |
// n2(source) - - - - n0(sender) - - -  - - - - n1(receiver) - - - - - n3(sink)

This is my part code, 

void BandwidthTrace (void);
void ScheduleBw (void);
string bandwidth = "2Mbps"
m_timer_value = 100

ifstream bwfile ("downlink.txt");

void BandwidthTrace (void)
{
     getline (bwfile, bandwidth);
     Config::Set ("/NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/DataRate", StringValue (bandwidth));
     if (!bwfile.eof ())
     {
           ScheduleBw ();
     }
}

void ScheduleBw (void)
{
     Simulator::Schedule (MilliSeconds (M_timer_value), BandwidthTrace);
}

int main ()
{
     string delay = "0.01"

     PointToPointHelper UnReLink;
     UnReLink.SetDeviceAttribute ("DataRate", StringValue (bandwidth));
     UnReLink.SetChannelAttribute ("Delay", StringValue (delay));
     InternetStackHelper stack;
     stack.InstallAll ();

     BandwidthTrace ();
}
Here have my all code. 

Tommaso Pecorella

unread,
Dec 21, 2016, 7:31:25 PM12/21/16
to ns-3-users
Small mistake. In your code you wrote:
Config::Set ("/NodeList/2/DeviceList/2/$ns3::PointToPointNetDevice/DataRate",StringValue (bandwidth));

Which means: 3rd created node (it's a sink only if num_flows is 1) and 3rd device on the node. However each node (except the gateway) has only 2 devices: the loopback and the p2p.

T.
Message has been deleted

Hiba Yousef

unread,
Jan 25, 2019, 6:45:58 AM1/25/19
to ns-3-users
thanks for the discussion.. 
I had the same problem and it is solved by:
Reply all
Reply to author
Forward
0 new messages