NS3 Network Simulation: DataRate Attribute

Foreword Preface

This is not a correspondent, but also to see the magic of this communication! Because SRTP project is a communication project, so this period of time, has been in contact with the NS3-related knowledge, come in and have a brief chat with you...

text

  • First, we need to create a point-to-point channel in the first.py file and configure two properties:
PointToPoint = ns.point_to_point.PointToPointHelper()
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("10Mbps"))
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("100ms"))
  • When we configure the attributes of DataRate, first.py passes in a string of "10Mbps" (while passing in a string of "100ms" to the value of the "Delay" attribute, which is an incoming delay, which is not discussed), and the string is finally parsed by C++ code:
DataRate::DoParse (const std::string s, uint64_t *v)  
{  
  NS_LOG_FUNCTION (s << v);  
  std::string::size_type n = s.find_first_not_of ("0123456789.");  
  if (n != std::string::npos)  
    { // Found non-numeric  
      std::istringstream iss;  
      iss.str (s.substr (0, n));  
      double r;  
      iss >> r;  
      std::string trailer = s.substr (n, std::string::npos);  
      if (trailer == "bps")  
        {  
          // bit/s  
          *v = (uint64_t)r;  
        }  
      else if (trailer == "b/s")  
        {  
          // bit/s  
          *v = (uint64_t)r;  
        }  
      else if (trailer == "Bps")  
        {  
          // byte/s  
          *v = (uint64_t)(r * 8);  
        }  
      else if (trailer == "B/s")  
        {  
          // byte/s  
          *v = (uint64_t)(r * 8);  
        }  
      else if (trailer == "kbps")  
        {  
          // kilobits/s  
          *v = (uint64_t)(r * 1000);  
        }  
      else if (trailer == "kb/s")  
        {  
          // kilobits/s  
          *v = (uint64_t)(r * 1000);  
        }  
      else if (trailer == "Kbps")  
        {  
          // kilobits/s  
          *v = (uint64_t)(r * 1000);  
        }  
      else if (trailer == "Kb/s")  
        {  
          // kilobits/s  
          *v = (uint64_t)(r * 1000);  
        }  
      else if (trailer == "kBps")  
        {  
          // kiloByte/s  
          *v = (uint64_t)(r * 8000);  
        }  
      else if (trailer == "kB/s")  
        {  
          // KiloByte/s  
          *v = (uint64_t)(r * 8000);  
        }  
      else if (trailer == "KBps")  
        {  
          // kiloByte/s  
          *v = (uint64_t)(r * 8000);  
        }  
      else if (trailer == "KB/s")  
        {  
          // KiloByte/s  
          *v = (uint64_t)(r * 8000);  
        }  
      else if (trailer == "Kib/s")  
        {  
          // kibibit/s  
          *v = (uint64_t)(r * 1024);  
        }  
      else if (trailer == "KiB/s")  
        {  
          // kibibyte/s  
          *v = (uint64_t)(r * 8192);  
        }  
      else if (trailer == "Mbps")  
        {  
          // MegaBits/s  
          *v = (uint64_t)(r * 1000000);  
        }  
      else if (trailer == "Mb/s")  
        {  
          // MegaBits/s  
          *v = (uint64_t)(r * 1000000);  
        }  
      else if (trailer == "MBps")  
        {  
          // MegaBytes/s  
          *v = (uint64_t)(r * 8000000);  
        }  
      else if (trailer == "MB/s")  
        {  
          // MegaBytes/s  
          *v = (uint64_t)(r * 8000000);  
        }  
      else if (trailer == "Mib/s")  
        {  
          // MebiBits/s  
          *v = (uint64_t)(r * 1048576);  
        }  
      else if (trailer == "MiB/s")  
        {  
          // MebiByte/s  
          *v = (uint64_t)(r * 1048576 * 8);  
        }  
      else if (trailer == "Gbps")  
        {  
          // GigaBit/s  
          *v = (uint64_t)(r * 1000000000);  
        }  
      else if (trailer == "Gb/s")  
        {  
          // GigaBit/s  
          *v = (uint64_t)(r * 1000000000);  
        }  
      else if (trailer == "GBps")  
        {  
          // GigaByte/s  
          *v = (uint64_t)(r * 8*1000000000);  
        }  
      else if (trailer == "GB/s")  
        {  
          // GigaByte/s  
          *v = (uint64_t)(r * 8*1000000000);  
        }  
      else if (trailer == "Gib/s")  
        {  
          // GibiBits/s  
          *v = (uint64_t)(r * 1048576 * 1024);  
        }  
      else if (trailer == "GiB/s")  
        {  
          // GibiByte/s  
          *v = (uint64_t)(r * 1048576 * 1024 * 8);  
        }  
      else  
        {  
          return false;  
        }  
      return true;  
    }  
  std::istringstream iss;  
  iss.str (s);  
  iss >> *v;  
  return true;  
}  

From this code, we can clearly see the expression of the rate string in NS3 and its significance.
- We can find the attributes of several other devices through the attribute of "DataRate". By the way,

SimpleNetDevice::GetTypeId (void)  
{  
  static TypeId tid = TypeId ("ns3::SimpleNetDevice")  
    .SetParent<NetDevice> ()  
    .SetGroupName("Network")   
    .AddConstructor<SimpleNetDevice> ()  
    .AddAttribute ("ReceiveErrorModel",  
                   "The receiver error model used to simulate packet loss",  
                   PointerValue (),  
                   MakePointerAccessor (&SimpleNetDevice::m_receiveErrorModel),  
                   MakePointerChecker<ErrorModel> ())  
    .AddAttribute ("PointToPointMode",  
                   "The device is configured in Point to Point mode",  
                   BooleanValue (false),  
                   MakeBooleanAccessor (&SimpleNetDevice::m_pointToPointMode),  
                   MakeBooleanChecker ())  
    .AddAttribute ("TxQueue",  
                   "A queue to use as the transmit queue in the device.",  
                   StringValue ("ns3::DropTailQueue"),  
                   MakePointerAccessor (&SimpleNetDevice::m_queue),  
                   MakePointerChecker<Queue> ())  
    .AddAttribute ("DataRate",  
                   "The default data rate for point to point links. Zero means infinite",  
                   DataRateValue (DataRate ("0b/s")),  
                   MakeDataRateAccessor (&SimpleNetDevice::m_bps),  
                   MakeDataRateChecker ())  
    .AddTraceSource ("PhyRxDrop",  
                     "Trace source indicating a packet has been dropped "  
                     "by the device during reception",  
                     MakeTraceSourceAccessor (&SimpleNetDevice::m_phyRxDropTrace),  
                     "ns3::Packet::TracedCallback")  
  ;  
  return tid;  
}  

This is also the NS3 simulation process several more important attributes, later we will have a detailed introduction, here to find out for everyone to discuss...

  • adopt NetAnim Dynamic Demonstration Tool (I'll talk about NetAnim later.) Let's modify the attribute values of DataRate to find out the similarities and differences:
    • When the value of DataRate is: 10Mbps
    • When the value of DataRate is: 200Mbps
  • Analysis: We can find that the most obvious observation in NetAnim is the length of the arrow used to represent the data packet. When the value of DataRate is changed to 200 Mbps, the arrow is obviously longer, which is growing in a positive proportion way.

Well, today's simple sharing is over, want to learn NS3 children's shoes, we can learn together yo, refuel!!!

Keywords: Attribute network

Added by bubbasheeko on Fri, 17 May 2019 17:32:04 +0300