Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/$ns3::OcbWifiMac/Txop/Queue/MaxSize", StringValue ("1p"));
I suspected that perhaps the above statement is not enough to
accomplish what you want, not because it looked wrong, but because
this is a complicated part of the ns-3 code to modify. So I gave
it a try myself to see what might be going wrong.
By default, when using the IP layer, a traffic control layer is inserted with Linux-like defaults. This will allow packets to queue up even if you make a small device queue. So, disable it after the IP addresses are set in your scenario:
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
+ TrafficControlHelper tch;
+ tch.Uninstall (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
If you place this Uninstall() method earlier in the scenario setup, it will cause an error.
Next, I tried your program but saw, as you did, that there are
still 10 packets getting through. It seemed like your
Config::Set() statement was OK, but I checked by using the
ConfigStore module to dump all of the attribute values in use.
If you add this include:
#include "ns3/config-store-module.h"
and then add this code just before Simulator::Run ():
AnimationInterface anim("first.xml");
+ Config::SetDefault ("ns3::ConfigStore::Filename", StringValue
("output-attributes.txt"));
+ Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue
("RawText"));
+ Config::SetDefault ("ns3::ConfigStore::Mode", StringValue
("Save"));
+ ConfigStore outputConfig;
+ outputConfig.ConfigureAttributes ();
Simulator::Run ();
Then it will dump out all of the attribute paths into a file
called 'output-attributes.txt'.
I checked this, and the path that you used seemed correct. You are using the Nqos configuration (non-QoS).
So I had to go into the C++ code to further debug this. I found a couple of things.
In the method
WifiMacQueue::Insert (ConstIterator pos,
Ptr<WifiMacQueueItem> item)
{
NS_LOG_FUNCTION (this << *item);
NS_ASSERT_MSG (GetMaxSize ().GetUnit () ==
QueueSizeUnit::PACKETS,
"WifiMacQueues must be in packet mode");
QueueBase::SetMaxSize (GetMaxQueueSize ()); //Make sure
QueueBase has the same maximum queue size
// insert the item if the queue is not full
if (QueueBase::GetNPackets () < GetMaxSize ().GetValue ())
there is an interesting statement to set the max size to some value GetMaxQueueSize(). This, I found, was an attribute on WifiMacQueue called 'MaxQueueSize', defaulting to 500p. When I stepped through this code, I found that the Config::Set had set the queue size to 1 packet, but then upon the first insertion, the queue size was reset to 500 packets based on this 'QueueBase::SetMaxSize (GetMaxQueueSize());' statement.
I then looked for the config path for MaxQueueSize in the output-attributes.txt file, and didn't find it. Puzzled, I went to the attribute definition, and found this:
.AddAttribute ("MaxQueueSize",There is a 'setter' but not a getter, for some reason. I added the getter:
.AddAttribute ("MaxQueueSize",
"The max queue size",
QueueSizeValue (QueueSize ("500p")),
- MakeQueueSizeAccessor
(&WifiMacQueue::SetMaxQueueSize),
+ MakeQueueSizeAccessor
(&WifiMacQueue::SetMaxQueueSize,
+
&WifiMacQueue::GetMaxQueueSize),
MakeQueueSizeChecker ())
I reran the program. Now, the MaxQueueSize values were dumped into the output-attributes.txt file. I found the config path that I wanted:
Config::Set
("/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::OcbWifiMac/Txop/$ns3::Txop/Queue/$ns3::WifiMacQueue/MaxQueueSize",
StringValue ("1p"));
Once I added this after your previous Config::Set statement, it started to work. It now lets through two packets, which I believe is because the first one is immediately dequeued for transmission at time 1s, the second one is queued in the single packet queue, and the rest are discarded.
See attached revised program.
So, I think there are two problems with ns-3:
1) MaxQueueSize is missing an attribute accessor
2) We need to review this interaction between MaxSize and MaxQueueSize because it is leading to unexpected behavior.
- Tom