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 ...
随机推荐
- ASP.NET MVC中如何在客户端进行必要的判断
背景:在开发网站时,往往需要对用户的输入进行合法性检查,如果验证工作都放在服务器端,势必将影响网页的响应速度,同时给用户不好的体验.本篇随笔即是使用JQuery在客户端进行必要的合法检测. JS代码如 ...
- CodeForces 610B-Vika and Squares,有坑点,不是很难~~
B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- PTA 04-树6 Complete Binary Search Tree (30分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/669 5-7 Complete Binary Search Tree (30分) A ...
- [luoguP2129] L国的战斗续之多路出击(模拟 || 矩阵)
传送门 1.模拟 easy #include <cstdio> #define N 500001 int n, m; int X[N], Y[N], x[N], y[N], a = 1, ...
- [luoguP2073] 送花(set)
传送门 set #include <set> #include <cstdio> #include <iostream> #define LL long long ...
- Monkey King(左偏树)
洛谷传送门 每次给出要争吵的猴子a和b,用并查集判断如果他们是朋友输出-1 如果不是,找出a,b在的堆的根A,B,分别合并A,B的左右孩子,再合并一下. 之后把A,B的数据更改一下:权值除以2,左右孩 ...
- HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://xxxxxx
读取T卡文件里的域名,HTTP请求出现如下错误 java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ...
- python学习之-项目开发目录规范
软件目录结构规范有什么好处: 通过规范化,能够更好的控制软件结构,让程序具有更高的可读性. 项目目录组织结构如下: Foo/ # 项目名 --bin/ # 可执行文件目录 --foo # 可执行程序 ...
- Codeforces 659F Polycarp and Hay【BFS】
有毒,自从上次选拔赛(哭哭)一个垃圾bfs写错之后,每次写bfs都要WA几发...好吧,其实也就这一次... 小白说的对,还是代码能力不足... 非常不足... 题目链接: http://codefo ...
- [Poj3744]Scout YYF I (概率dp + 矩阵乘法)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9552 Accepted: 2793 Descr ...