问题
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.
回答1:
Referencing this: http://www.nsnam.org/docs/release/3.16/doxygen/classns3_1_1_ipv4_static_routing_helper.html#ae69a07ded3139dfd4e21bb7c10eba416
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
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)
.
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.
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);
}
Referencing this: http://www.nsnam.org/docs/release/3.16/doxygen/csma-multicast_8cc_source.html
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.
Referencing this: http:// www.nsnam.org/docs/release/3.16/doxygen/udp-echo-server_8cc_source.html
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 }
来源:https://stackoverflow.com/questions/15795069/how-do-i-implement-multicast-dynamic-join-prune-using-ns3