How to change CWmin and DIFS value for a particular wifi node

2,475 views
Skip to first unread message

Shahwaiz

unread,
Dec 23, 2013, 8:05:00 AM12/23/13
to ns-3-...@googlegroups.com
Hi Everyone,

I am a newbie to NS3. I am trying to formulate an infrastructural wifi scenario comprising of a cheater that could increase its throughput by decreasing its CWmin value and DIFS value. Can any one please give me a hint on how to modify these two parameters in NS3. I guess CWmin could be set through dca-txop.cc file but I am not sure about the DIFS value.

Furthermore, is it OK to define a separate MAC for the cheater before placing in the NetDeviceContainer? In this way I could set the values of these paramter seperatly for the cheating devise.

Regards,
Shahwaiz



Tommaso Pecorella

unread,
Dec 23, 2013, 1:44:33 PM12/23/13
to ns-3-...@googlegroups.com
Hi,

all the answers are in the code.

You don't need to define a separate (new) MAC, just to change the standard one parameters.

For the CwMin, you can use the DcaTxop::SetMinCw or EdcaTxopN::SetMinCw.
For the Difs there's an attribute in WifiMac.

Just pick a node, find the right object and change its parameters. How to do that, it' all in the tutoral and the manual.

Hope this helps,

T.

Shahwaiz

unread,
Jan 5, 2014, 3:24:28 PM1/5/14
to ns-3-...@googlegroups.com
Hello Everyone,

I would like to highlight one important thing. The method to change Cwmin posted on the following link works well in ns3.13.

https://groups.google.com/forum/#!searchin/ns-3-users/cwmin/ns-3-users/zhw7jbXNLUQ/nK_Uv8143GEJ

It does not work on the newer versions of ns3 (not even on ns3.16).

Regards,
Shahwaiz

Konstantinos

unread,
Jan 5, 2014, 3:44:52 PM1/5/14
to ns-3-...@googlegroups.com
Hi,

The structure of the classes has changed (I guess it was the addition of EDCA) or something else. You should look at the change-log to find out what it was exactly.

However, just search for the Dcf implementations because Dcf is an abstract class. You will find out that there is DcaTxop and EdcaTxopN

So the config path for DcaTxop is:
  • /NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop
Or for EdcaTxopN 
  • /NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_EdcaTxopN
  • /NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BK_EdcaTxopN
  • /NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/VI_EdcaTxopN
  • /NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/VO_EdcaTxopN
Depending on what type of WiFi you are using, you can set the corresponding attributes.

Regards,
K.

Shahwaiz Iqbal

unread,
Jan 5, 2014, 4:23:16 PM1/5/14
to ns-3-...@googlegroups.com
Hi K,

Thanks for your reply. Actually I have been spending alot of time on this problem. I was using ns3.18 and made the following modifications,


1. In dca-txop.cc
I added

.AddAttribute ("CwMin",
                   "Sets the minimum contention window.",
                   UintegerValue (),
                   MakeUintegerAccessor (&DcaTxop::SetMinCw),
                   MakeUintegerChecker<uint32_t> ())
2. In edca-txop-n.cc
I added

.AddAttribute ("CwMin",
                   "Sets the minimum contention window.",
                   UintegerValue (),
                   MakeUintegerAccessor (&EdcaTxopN::SetMinCw),
                   MakeUintegerChecker<uint32_t> ())

3. Then in the main code, I added the following lines after the wifi configurations,
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop/CwMin", UintegerValue(1));
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_EdcaTxopN/CwMin",UintegerValue(1));
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BK_EdcaTxopN/CwMin", UintegerValue(1));
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/VI_EdcaTxopN/CwMin", UintegerValue(1));
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/VO_EdcaTxopN/CwMin", UintegerValue(1));

(node 0 was the cheater, I was using infrastructural wifi scenario where node 5 was the AP)

After doing so, I do not seen any increase in the throughput of the node 0.

According to you suggestion, I did look at the dcf.cc, and found the following interesting attribute
.AddAttribute ("MinCw", "The minimum value of the contention window.",
UintegerValue (15),
MakeUintegerAccessor (&Dcf::SetMinCw,
                                   &Dcf::GetMinCw),

Can it be used to fix a CwMin value for a particular node? Do you have any other important suggestions?

For your convenience, I have also attacked my code that gives an output-attributes.txt file that indicates no change of CwMin value for the node 0.




--
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/nvIHlvQOqmo/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 http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/groups/opt_out.

wifitest5.cc

Tommaso Pecorella

unread,
Jan 5, 2014, 4:56:43 PM1/5/14
to ns-3-...@googlegroups.com
Hi,

just adding an Attribute won't work.

CwMin and CwMax are set by RegularWifiMac::FinishConfigureStandard (enum WifiPhyStandard standard)
To change them, you'll have to modify their values *after* the FinishConfigureStandard, or your values will be overwritten.

You can use the Attribute Set method to schedule a change at second 0.1, where for sure the FinishConfigureStandard will have been fired already.

Hope this helps,

T.

Konstantinos

unread,
Jan 5, 2014, 6:19:55 PM1/5/14
to ns-3-...@googlegroups.com
There was no need to add the attributes, since they are already implemented in the Dcf class and inherited by Txop and EdcaTxopN.
See the documentation here:

So, you just need to use the Attribute Set as Tommaso suggested.

Shahwaiz Iqbal

unread,
Jan 5, 2014, 6:25:29 PM1/5/14
to ns-3-...@googlegroups.com
Hi,
Thanks for you reply. Do you suggest that I should use the following command (by removing the attributes added in txops)?

Simulator::Schedule(Seconds(.1), Config::Set,"/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop/CwMin", UintegerValue(1));

where should I call this command?

Regards,
Shahwaiz

Konstantinos

unread,
Jan 5, 2014, 6:46:12 PM1/5/14
to ns-3-...@googlegroups.com
This may not work, just create a void function and put the Config::Set in that. Then schedule that function.

eg.
void SetCwMin(uint16_t cw)
{
   Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop/CwMin", UintegerValue(cw));
}

and call it like this:
Simulator::Schedule(Seconds(0.1), &SetCwMin, 1); 

Shahwaiz

unread,
Jan 6, 2014, 10:41:53 AM1/6/14
to ns-3-...@googlegroups.com
Hi K,

Thanks for your reply.

I added the following function within my code (before main),

void SetCwMin(uint16_t cw)
{
Config::Set("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop/CwMin", UintegerValue(cw));
}

and scheduled this before the simulator::run comand
Simulator::Schedule(Seconds(0.1),&SetCwMin,4);

But still there is no change in the Cwmin value and the throughput of node 0. Am I using it in a wrong way? should I add anything else?


Regards,
Shahwaiz


On Monday, 23 December 2013 14:05:00 UTC+1, Shahwaiz wrote:

Fadhil Firyaguna

unread,
Aug 1, 2014, 5:15:50 PM8/1/14
to ns-3-...@googlegroups.com
Hi everyone,

I got this solution for changing the CWmin, but for all nodes, not a particular one.
Basically, I force the cwmin value directly in RegularWifiMac through a DcaTxop attribute that I can handle in my script.

The changeset is below:
I am using ns-3.20.

cwmin modifier

diff -r d96b35dc7d26 -r 51f196560e79 model/dca-txop.cc
--- a/model/dca-txop.cc Fri Aug 01 18:11:06 2014 -0300
+++ b/model/dca-txop.cc Fri Aug 01 18:11:48 2014 -0300
@@ -132,6 +132,11 @@
                    PointerValue (),
                    MakePointerAccessor (&DcaTxop::GetQueue),
                    MakePointerChecker<WifiMacQueue> ())
+    .AddAttribute ("CwMin", 
+                   "Sets the minimum contention window.", 
+                   UintegerValue (31), 
+                   MakeUintegerAccessor (&DcaTxop::m_initMinCw), 
+                   MakeUintegerChecker<uint32_t> ())
   ;
   return tid;
 }
@@ -250,6 +255,13 @@
   return m_dcf->GetAifsn ();
 }
 
+uint32_t
+DcaTxop::GetInitialMinCw (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_initMinCw;
+}
+
 void
 DcaTxop::Queue (Ptr<const Packet> packet, const WifiMacHeader &hdr)
 {
diff -r d96b35dc7d26 -r 51f196560e79 model/dca-txop.h
--- a/model/dca-txop.h Fri Aug 01 18:11:06 2014 -0300
+++ b/model/dca-txop.h Fri Aug 01 18:11:48 2014 -0300
@@ -150,6 +150,8 @@
   * \return the number of stream indices assigned by this model
   */
   int64_t AssignStreams (int64_t stream);
+  
+  uint32_t GetInitialMinCw (void) const;
 
 private:
   class TransmissionListener;
@@ -324,6 +326,8 @@
   Ptr<const Packet> m_currentPacket;
   WifiMacHeader m_currentHdr;
   uint8_t m_fragmentNumber;
+  
+  uint32_t m_initMinCw;
 };
 
 } // namespace ns3
diff -r d96b35dc7d26 -r 51f196560e79 model/regular-wifi-mac.cc
--- a/model/regular-wifi-mac.cc Fri Aug 01 18:11:06 2014 -0300
+++ b/model/regular-wifi-mac.cc Fri Aug 01 18:11:48 2014 -0300
@@ -714,7 +714,8 @@
       break;
 
     case WIFI_PHY_STANDARD_80211b:
-      cwmin = 31;
+//       cwmin = 31;
+      cwmin = m_dca->GetInitialMinCw ();
       cwmax = 1023;
       break;
 

After applying those changes, I simply use this in my script:

Config::SetDefault ("ns3::DcaTxop::CwMin", UintegerValue (cwmin_value));

I hope it helps.
--

Aniesh Chawla

unread,
Nov 18, 2014, 2:12:08 AM11/18/14
to ns-3-...@googlegroups.com
Hi,
I am still not able to change the contention window on the run, I am using ns-3.21 and I am able to set the default value as said above, but I want to change the contention window of a particular node in the network.
I tried the above method Konstantinos has mentioned but it seems it is still being override. I checked the path to the variable as mentioned in https://groups.google.com/forum/#!searchin/ns-3-users/cwmin/ns-3-users/ESRL_7Uw2lo/mhGRpeu3760J
but the path is correct but the value is not changed during the simulation. I am attaching the files, please let me know where I am wrong.

Thanks a lot for your time

Regards
Aniesh Chawla
wifi-tcp-dynamic-contention.cc
dca-txop.cc

Aniesh Chawla

unread,
Nov 21, 2014, 12:33:07 AM11/21/14
to ns-3-...@googlegroups.com
Anyone any idea about this issue? How should I proceed in this. Earlier when I used ns-3.13 then I did it with pointers and it was working quite well but with the new release 3.21 I am not able to access the contention window of a single node. I am able to change the contention window of all the nodes.

Thanks
Aniesh

Yi Ling

unread,
May 10, 2016, 1:36:14 PM5/10/16
to ns-3-users
Hello Chawla,

I knew it is a little bit late. But I hope I can give some hints to someone who has the same question. What I did is modifying the DcaTxop::NotifyCollision. It is about the node start to backoff when there is a collision happen. Here is the code:

DcaTxop::NotifyCollision (void)
{
  //****patch 2016.5.5
  int32_t node_id = ns3::Simulator::GetContext();
  if(node_id==4){

    NS_LOG_FUNCTION (this);
    NS_LOG_DEBUG ("malicious nodes got small backoff time");
    m_dcf->StartBackoffNow (m_rng->GetNext (0, 2));
    RestartAccessIfNeeded ();

  }
  else{
    NS_LOG_FUNCTION (this);
    NS_LOG_DEBUG ("collision");
    m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
    RestartAccessIfNeeded ();
  }
  //******
  //original code
   // NS_LOG_FUNCTION (this);
   //  NS_LOG_DEBUG ("collision");
   //  m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
   //  RestartAccessIfNeeded ();
}

In my case, I want to change the contention window of node 4. So I put a condition there. I change the window size as a constant value 2.

Sampath Edirisinghe

unread,
Jul 11, 2017, 8:29:09 PM7/11/17
to ns-3-users
Hi Chawla,

Did you find a solution for this? I am also trying to change the CW of 802.11 protocol.
Thanks in advance.
Sampath

varsha chimalgikar

unread,
Oct 4, 2018, 1:59:24 AM10/4/18
to ns-3-users
Hi,
i am trying to change the cw for the laa-wifi-coexitance outdoor it showing an error!!! so what should i do?plz help me.
Reply all
Reply to author
Forward
0 new messages