2013-04-03 139 views

回答

0

引用此: http://www.nsnam.org/docs/release/3.16/doxygen/classns3_1_1_ipv4_static_routing_helper.html#ae69a07ded3139dfd4e21bb7c10eba416

在NS-3中,我们设置了节点的路由表中的默认组播路由执行SetDefaultMulticastRoute(dev,nd),其作为文档状态是等效于执行以下操作:

route add 224.0.0.0 netmask 240.0.0.0 dev nd 

当为物理世界中的Linux服务器设置多播时,我们需要为路由表中的多播地址设置路由。在ns-3仿真世界中,我们必须对使用SetDefaultMulticastRoute(dev,nd)创建的每个节点执行相同的操作。

静态组播路由用于从一个LAN路由到另一个。在现实世界中,我们需要一个知道如何路由多播的路由器。在ns-3仿真世界中,我们需要一个知道如何路由多播的路由器。因此,在ns-3中,我们需要使用AddMulticastRoute()从一个LAN到另一个LAN建立静态路由,该路由安装在充当路由器的模拟节点中。

如果有一个ns-3助手将会在NodeContainerNetDeviceContainer上安装默认多播路由将会很不错。但是,该方法需要一个节点及其相关联的NetDevice,因此您必须使用循环来设置它们全部,假设NodeContainer中的0..N节点与NetDeviceContainer中的0..N节点直接相关。

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

你可以看到组播数据包的发送者和接收者是如何设置。它包括两个局域网之间的静态路由。本例中的接收器没有默认的多播路由设置。内联注释表明,所有节点都将从源接收多播帧 - 源是我们为其执行SetDefaultMulticastRoute(source,sourceIf)的节点。

请注意,此代码的注释表明源接收它发送的多播帧。

引用这样的: 的http:// www.nsnam.org/docs/release/3.16/doxygen/udp-echo-server_8cc_source.html

你写不实际参与到多播组的NS3应用。

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  }