2013-04-03 128 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  }