NS3网络仿真(4): DataRate属性
快乐虾
http://blog.csdn.net/lights_joy/
欢迎转载,但请保留作者信息
在first.py中创建了一个点到点的信道,且配置了两个属性:
pointToPoint = ns.point_to_point.PointToPointHelper()
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("2Mbps"))
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("100ms"))
在配置DataRate时。first.py传递了一个字符串”2Mbps”。这个字符串最后由以下的C++代码进行解析:
bool
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;
}
从这一段代码也能够明显看出NS3中速率字符串的表达方式及意义,比文档清晰多了,原来还不知道速率能够有这么多的表达方式,汗一个~~~~
从”DataRate”顺藤摸瓜。能够发现其他几个设备属性:
TypeId
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;
}
仅仅只是我们眼下暂且无论这些属性。
改动DataRate的值。能够发如今NetAnim中最明显的表现就是用以表示数据包的箭头的长度,当DataRate为2Mbps时:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
当DataRate变为200Kbps时就变成了:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
区别还是非常明显的!
NS3网络仿真(4): DataRate属性的更多相关文章
- NS3网络仿真(2):first.py
1 安装基本模块 11 安装Python 12 安装PTVS 13 加入对python-279的支持 2 在vs2013下编译NS3 3 编译NetAnim 4 在vs2 ...
- NS3网络仿真(6): 总线型网络
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载.但请保留作者信息 在NS3提供的第一个演示样例first.py中,模拟了一个点对点的网络,接下来的一个演示样例代码模 ...
- NS3网络仿真(7): Wifi节点
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在上一节中.我们仿真了一个总线型网络,这一节尝试将上一节中的n0变成一个无线的AP.再连上几个节点 ...
- NS3网络仿真(3): NetAnim
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在NS3提供的演示样例first.py中,并没有生成NetAnim所须要的xml文件,本节我们尝试 ...
- NS3网络仿真(12): ICMPv4协议
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 ICMP的全称是 Internet ControlMessage Protocol . 其目的就是 ...
- NS3网络仿真(9): 构建以太网帧
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在NS3使用了一个叫Packet的类来表示一个数据帧,本节尝试用它构造一个以太网帧. 以下是一个典 ...
- NS3网络仿真(11): ARP
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 ARP(Address ResolutionProtocol,地址解析协议)协议的基本功能就是通过 ...
- NS3网络仿真(10): 解析以太网帧
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载.但请保留作者信息 解析以太网帧的过程是构建以太网帧的逆过程,当我们接收到一个以太网帧时,仍然以上一节中的ARP帧为例 ...
- NS3网络仿真(5): 数据包分析
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在我们生成的xml文件里.是不包括生成的数据包的数据的,在我们的脚本中加入以下的语句: point ...
随机推荐
- 【URAL 1486】Equal Squares(二维哈希+二分)
Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...
- JSP指令学习
JSP 指令 JSP指令用来设置整个JSP页面相关的属性,如网页的编码方式和脚本语言.语法格式: <%@ page attribute="value"%> 指令可以有很 ...
- 大数据学习——mapreduce共同好友
数据 commonfriends.txt A:B,C,D,F,E,O B:A,C,E,K C:F,A,D,I D:A,E,F,L E:B,C,D,M,L F:A,B,C,D,E,O,M G:A,C,D ...
- 大数据学习——yum练习安装mysql
1. 安装mysql 服务器端: yum install mysql-server yum install mysql-devel 2. 安装mysql客户端: yum install mysql 3 ...
- spring的IOC和DI
https://blog.csdn.net/fuzhongmin05/article/details/55802816 (1)IOC:控制反转,把对象创建交给spring进行配置 (2)DI:依赖注入 ...
- Exact Change(01背包)
描述 Seller: That will be fourteen dollars. Buyer: Here's a twenty. Seller: Sorry, I don't have any ch ...
- [HDU2896]病毒侵袭(AC自动机)
传送门 题目中文描述,赞! 除了val记录id以外就是模板. 注意:每次数组都要清0.0 ——代码 #include <cstdio> #include <queue> #in ...
- SpringBoot自动配置的源码解析
首先,写源码分析真的很花时间,所以希望大家转的时候也请注明一下,Thanks♪(・ω・)ノ SpringBoot最大的好处就是对于很多框架都默认的配置,让我们开发的时候不必为了大一堆的配置文件头疼,关 ...
- 【POJ1743】Musical Theme(后缀数组,二分)
题意:求一个字符串的不重叠最长相同变化的子串 n<=20000 思路:这是一道论文题 我们将原串两两之间作差,可以发现所求的相同变化的子串作出的差相同 问题就转化成了不重叠的最长重复子串 显然答 ...
- CF671D:Roads in Yusland
n<=300000个点的树,给m<=300000条带权路径(ui,vi,保证vi是ui的祖先)求覆盖整棵树每条边的最小权和. 好题好姿势!直观的看到可以树形DP,f[i]表示把点i包括它爸 ...