3我现在正试图改变示例部分中的一些代码而没有任何成功。
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("FirstScriptExample");
int main(int argc, char *argv[]) {
Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create(2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes);
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign(devices);
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);
echoClient.SetAttribute("MaxPackets", UintegerValue(1));
echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient.SetAttribute("PacketSize", UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
这是第一个教程示例,我尝试创建4个节点,以便他们可以相互发送一些udp数据包。
有什么建议吗?
答案 0 :(得分:1)
根据您要使用的网络拓扑,有不同的方法。如果您想让四个节点共享同一个共享媒体,您只需执行node.Create (4)
并在CsmaHelper
上安装NodeContainer
,即可结帐 / examples / tutorial / second.cc 用于简单实现。
但是如果你想要一个类似于拓扑的哑铃,每侧有一个叶子节点和一个中央通道,你必须在每个上面安装PointToPointHelper创建三个NodeContainer
。
NodeContainer leftLeaf, rightLeaf, central;
leftLeaf.Create(2); //creates two left side node
rightLeaf.Create(2); //creates two right side node
central.Add(leftLeaf.Get(1)); //add one node from left in central link
central.Add(rightLeaf.Get(1)); //add one node from right in central link
您还必须为中央链接节点设置转发。
这样做是因为点对点链接必须有两个端点。对于此类拓扑,您甚至可以使用PointToPointDumbbellHelper
,其实现可在 src / traffic-control / examples / red-vs-ared.cc
答案 1 :(得分:0)
如果要创建4个节点,可以更改代码nodes.Create(2)
中的数字。但您必须通过PointToPointHelper
或CsmaHelper
关联这些节点。然后,您必须为每个接口提供IP地址。最后,您需要安装可在节点上自定义的UDP或TCP应用程序。
你的问题非常简单。但由于我的英语不好,我无法提供更多细节。
但我认为您可以看到ns3 tutorial,尤其是 A First ns-3 Script 部分。