1

ルーター経由で接続されたサーバーとクライアントを含む非常に単純なトポロジを作成しようとしています。GUIを介して取得した次のコード。実行しようとしていますが、長いエラーがスローされます。ns-3 は初めてなので、ご容赦ください。

#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/global-route-manager.h"
#include "ns3/helper-module.h"
#include "ns3/bridge-module.h"

using namespace ns3;

int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);

/* Configuration. */

/* Build nodes. */
NodeContainer term_0;
term_0.Create (1);
NodeContainer term_1;
term_1.Create (1);
NodeContainer router_0;
router_0.Create (1);

/* Build link. */
CsmaHelper csma_hub_0;
csma_hub_0.SetChannelAttribute ("DataRate", DataRateValue (100000000));
csma_hub_0.SetChannelAttribute ("Delay",  TimeValue (MilliSeconds (10000)));
CsmaHelper csma_hub_1;
csma_hub_1.SetChannelAttribute ("DataRate", DataRateValue (100000000));
csma_hub_1.SetChannelAttribute ("Delay",  TimeValue (MilliSeconds (10000)));

/* Build link net device container. */
NodeContainer all_hub_0;
all_hub_0.Add (router_0);
all_hub_0.Add (term_0);
NetDeviceContainer ndc_hub_0 = csma_hub_0.Install (all_hub_0);
NodeContainer all_hub_1;
all_hub_1.Add (router_0);
all_hub_1.Add (term_1);
NetDeviceContainer ndc_hub_1 = csma_hub_1.Install (all_hub_1);

/* Install the IP stack. */
InternetStackHelper internetStackH;
internetStackH.Install (term_0);
internetStackH.Install (term_1);
internetStackH.Install (router_0);

/* IP assign. */
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
Ipv4InterfaceContainer iface_ndc_hub_0 = ipv4.Assign (ndc_hub_0);
ipv4.SetBase ("10.0.1.0", "255.255.255.0");
Ipv4InterfaceContainer iface_ndc_hub_1 = ipv4.Assign (ndc_hub_1);

/* Generate Route. */
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

/* Generate Application. */
uint16_t port_udpEcho_0 = 9;
UdpEchoServerHelper server_udpEcho_0 (port_udpEcho_0);
ApplicationContainer apps_udpEcho_0 = server_udpEcho_0.Install (term_1.Get(0));
apps_udpEcho_0.Start (Seconds (0.0));
apps_udpEcho_0.Stop (Seconds (2.0));
Time interPacketInterval_udpEcho_0 = Seconds (1.0);
UdpEchoClientHelper client_udpEcho_0 (iface_ndc_hub_1.GetAddress(1), 9);
client_udpEcho_0.SetAttribute ("MaxPackets", UintegerValue (1));
client_udpEcho_0.SetAttribute ("Interval", TimeValue (interPacketInterval_udpEcho_0));
client_udpEcho_0.SetAttribute ("PacketSize", UintegerValue (1024));
apps_udpEcho_0 = client_udpEcho_0.Install (term_0.Get (0));
apps_udpEcho_0.Start (Seconds (0.1));
apps_udpEcho_0.Stop (Seconds (2.0));

/* Simulation. */
/* Pcap output. */
/* Stop the simulation after x seconds. */
uint32_t stopTime = 3;
Simulator::Stop (Seconds (stopTime));
/* Start and clean simulation. */
Simulator::Run ();
Simulator::Destroy ();
}
4

1 に答える 1

3

初めての方は、ns-3 で既に提供されている例を参照してプログラムを開始する必要があります。このように: https://www.nsnam.org/doxygen/simple-routing-ping6_8cc_source.html . ネットワークトポロジを見ると、それはあなたが望むものです。

コードを実行しようとして、コンパイルするために多くのヘッダーを変更する必要がありました (時間を考えると、バージョンが異なるか、GUI が古くなっている可能性があります)。あなたのものを削除して、これらを入れてください:

#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/csma-helper.h"

そして最後に、あなたは何も印刷しなかったので、あなたが何をしようとしているのかわかりません. UdpEchoClientHelper と UdpEchoServerHelper を使用しているため、それらのログを有効にすることをお勧めします。次の 2 行でこれを行うことができます。

/* Configuration. */
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

私も初心者で、あなたが何をしようとしているのかわかりません。ですから、ここで私の答えを止めます。幸運を。

于 2015-02-27T00:14:36.753 に答える