如何使用ns3实现组播动态加入/剪枝 [英] How do I implement multicast dynamic join/prune using ns3
问题描述
是否有一种方法来实现使用ns3的多播网络中的节点的动态修剪/移植。
Is there a way to implement the dynamic prune/graft of nodes in a multicast network using ns3. The resources I could find all implements only static routing for multicast networks.
推荐答案
在ns-3中,我们为节点的路由表设置一个默认的多播路由 SetDefaultMulticastRoute )
,其文档状态等效于执行以下命令:
In ns-3 we set a default multicast route for the node's routing table executing SetDefaultMulticastRoute(dev,nd)
, which as the documentation states is equivalent to executing the following:
route add 224.0.0.0 netmask 240.0.0.0 dev nd
在物理世界中为linux服务器设置多播时,以具有用于路由表中的多播地址的路由。在ns-3模拟世界中,我们对于使用 SetDefaultMulticastRoute(dev,nd)
创建的每个节点都必须这样做。
When setting up multicast for a linux server in the physical world, we need to have a route for the multicast addresses in the routing table. In ns-3 simulation world we have to do the same for each node we create using SetDefaultMulticastRoute(dev,nd)
.
静态多播路由用于从一个LAN路由到另一个LAN。在现实世界中,我们需要有一个知道如何路由多播的路由器。在ns-3模拟世界中,我们需要一个知道如何路由多播的路由器。因此,在ns-3中,我们需要使用安装在充当路由器的模拟中的节点上的 AddMulticastRoute()
建立从一个LAN到另一个LAN的静态路由。
The static multicast routes are for routing from one LAN to another. In the real world, we need to have a router that knows how to route multicast. In the ns-3 simulation world, we need a router that knows how to route multicast. So in ns-3 we need to setup a static route from one LAN to another using AddMulticastRoute()
that is installed on the node in the simulation that is acting as the router.
这将是一个很好的有一个ns-3助手将安装默认多路由路由在 NodeContainer
NetDeviceContainer
。但是,该方法需要一个节点及其关联的 NetDevice
,因此您必须使用一个循环来设置它们,假设 0..N $
NodeContainer
中的中的
。 0..N
节点直接相关> NetDeviceContainer
It would be nice to have an ns-3 helper that would install the Default Multicast route on a NodeContainer
and NetDeviceContainer
. However, the method wants one Node and its associated NetDevice
, so you have to use a loop to set them all assuming 0..N
nodes in the NodeContainer
are directly related to 0..N
nodes in the NetDeviceContainer
.
for (int i = 0; i < N; i++) {
Ptr<Node> sender = nodecontainer.Get (i);
Ptr<NetDevice> senderIf = netdevicecontainer.Get (i);
multicast.SetDefaultMulticastRoute (sender, senderIf);
}
引用此:
http://www.nsnam.org/docs/release/3.16/doxygen/csma-multicast_8cc_source.html
您可以看到如何设置组播数据包的发送者和接收者。它包括两个LAN之间的静态路由。此示例中的接收器不具有默认多播路由建立。内联注释声明所有节点将从源接收多播帧 - 源是我们在其中执行 SetDefaultMulticastRoute(source,sourceIf)
You can see how the sender and receiver of multicast packets is setup. It does include a static route between two LANs. The receiver in this example does not have a default multicast route setup. The inline comments state that all nodes will receive the multicast frame from the source - the source being the node in which we execute SetDefaultMulticastRoute(source,sourceIf)
for.
请注意,此代码的注释表示源接收其发送的多播帧。
Note that the comments for this code indicate that the source receives the multicast frame it sends.
引用此:
http:// www.nsnam.org/docs/release/3.16/doxygen/udp-echo-server_8cc_source.html
Referencing this: http:// www.nsnam.org/docs/release/3.16/doxygen/udp-echo-server_8cc_source.html
您编写的ns3应用程序会执行实际连接到组播组。
The ns3 Application you write does the actual join to the Multicast group.
78 if (m_socket == 0)
79 {
80 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
81 m_socket = Socket::CreateSocket (GetNode (), tid);
82 InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
83 m_socket->Bind (local);
84 if (addressUtils::IsMulticast (m_local))
85 {
86 Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
87 if (udpSocket)
88 {
89 // equivalent to setsockopt (MCAST_JOIN_GROUP)
90 udpSocket->MulticastJoinGroup (0, m_local);
91 }
92 else
93 {
94 NS_FATAL_ERROR ("Error: Failed to join multicast group");
95 }
96 }
97 }
这篇关于如何使用ns3实现组播动态加入/剪枝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!