NS-3中Config::Connect与Config::ConnectWithoutContext的区别
来源:互联网 发布:工大高新 人工智能 编辑:程序博客网 时间:2024/05/29 12:28
This function will attempt to find all trace sources which match the input path and will then connect the input callback to them.
void ns3::Config::Connect (std::string path,const CallbackBase &cb )
This function will attempt to find all trace sources which match the input path and will then connect the input callback to them in such a way that the callback will receive an extra context string upon trace event notification.
以一个csma网络 ping的例子来解释,见: /src/csma/examples/csma-ping.cc
V4Ping : http://www.nsnam.org/doxygen/classns3_1_1_v4_ping.html#af207b6dc0ed793798083c34a1c388770
TraceSources defined for this type:
- Rtt: The rtt calculated by the ping.
This object is accessible through the following paths with Config::Set andConfig::Connect:
- /NodeList/[i]/ApplicationList/[i]/$ns3::V4Ping
PacketSink :http://www.nsnam.org/doxygen/classns3_1_1_packet_sink.html
TraceSources defined for this type:
- Rx: A packet has been received
This object is accessible through the following paths with Config::Set andConfig::Connect:
- /NodeList/[i]/ApplicationList/[i]/$ns3::PacketSink
// Network topology
//
// n0 n1 n2 n3
// | | | |
// =====================
//
// node n0,n1,n3 pings to node n2
// node n0 generates protocol 2 (IGMP) to node n3
...
static void SinkRx (Ptr<const Packet> p, const Address &ad)
{
std::cout << *p << std::endl;
}
static void PingRtt (std::string context, Time rtt)
{
std::cout << context << " " << rtt << std::endl;
}
...
int main (int argc, char * argv[])
{
...
// then, print what the packet sink receives.
Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
MakeCallback (&SinkRx));
// finally, print the ping rtts.
Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
MakeCallback (&PingRtt));
...
}
执行: gpf@guopengfei:~/ns-312/ns-allinone-3.12.1/ns-3.12.1$ ./waf --run src/csma/examples/csma-ping
结果:
Waf: Entering directory `/home/gpf/ns-312/ns-allinone-3.12.1/ns-3.12.1/build'
Waf: Leaving directory `/home/gpf/ns-312/ns-allinone-3.12.1/ns-3.12.1/build'
'build' finished successfully (5.522s)
ns3::Ipv4Header (tos 0x0 ttl 64 id 0 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
/NodeList/0/ApplicationList/1/$ns3::V4Ping/Rtt +12766594.0ns
/NodeList/1/ApplicationList/0/$ns3::V4Ping/Rtt +25762594.0ns
/NodeList/3/ApplicationList/1/$ns3::V4Ping/Rtt +38792594.0ns
ns3::Ipv4Header (tos 0x0 ttl 64 id 2 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 3 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
/NodeList/0/ApplicationList/1/$ns3::V4Ping/Rtt +4352998.0ns
/NodeList/1/ApplicationList/0/$ns3::V4Ping/Rtt +8709998.0ns
/NodeList/3/ApplicationList/1/$ns3::V4Ping/Rtt +13800998.0ns
ns3::Ipv4Header (tos 0x0 ttl 64 id 5 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
/NodeList/0/ApplicationList/1/$ns3::V4Ping/Rtt +4352998.0ns
/NodeList/1/ApplicationList/0/$ns3::V4Ping/Rtt +9059998.0ns
/NodeList/3/ApplicationList/1/$ns3::V4Ping/Rtt +13493998.0ns
ns3::Ipv4Header (tos 0x0 ttl 64 id 7 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 8 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 9 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 10 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 11 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 12 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 13 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 14 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 15 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
ns3::Ipv4Header (tos 0x0 ttl 64 id 16 protocol 2 offset (bytes) 0 flags [none] length: 1220 192.168.1.1 > 192.168.1.4) Payload (size=1200)
- NS-3中Config::Connect与Config::ConnectWithoutContext的区别
- WEB.config中appsetting和connectionstrings的区别与写法
- Web.config 和 App.config 的区别
- redis中关于config get、config set与config rewrite
- web.config中AppSettings和Connect…
- spring配置中annotation-config与component-scan区别
- web.config中AppSettings和ConnectionStrings的配置与区别及获取
- Qt工程文件中QT -= core gui与Config-=qt的区别
- ASP.NET 中 整个站点web.config 与 不同文件夹下的web.config 的 多web.config 相关配置
- ASP.NET 中 整个站点web.config 与 不同文件夹下的web.config 的 多web.config 相关配置
- ACL match-order 中的 config 与 auto 的应用区别
- annotation-driven,annotation-config,component-scan的区别与作用
- annotation-driven,annotation-config,component-scan的区别与作用
- <context:annotation-config> 与 <mvc:annotation-driven>间的区别
- YUM config/make install 与apt-gethi中间的区别
- web.config中AppSettings和ConnectionStrings的区别
- web.config中AppSettings和ConnectionStrings的区别
- web.config中AppSettings和ConnectionStrings的区别
- c# 控件随窗体大小改变
- 经典的编程引言
- Java 算法
- 消息处理-很好的系统函数
- makefile 中使用include
- NS-3中Config::Connect与Config::ConnectWithoutContext的区别
- linux计划任务
- NLB
- 程序自动更新模块
- nmon文件存放的路径
- JRE, JDK, JVM
- java session HttpSessionListener、HttpSessionBindingListener使用区别,实现在线人数统计以及踢出用户
- 第二天
- Linux下非Oracle数据库安装用户执行OCCI程序