C++ NS-3中的节点和udp实现
我目前正在尝试修改示例部分中的一些代码,但没有成功C++ NS-3中的节点和udp实现,c++,ns-3,C++,Ns 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("FirstS
#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数据包
有什么建议吗?如果要创建4个节点,可以更改代码
节点中的编号。创建(2)
。但您必须通过点拓扑在LPER
或CsmaHelper
链接这些节点。然后,您必须为每个接口提供一个IP地址。最后,您需要安装可以在节点上自定义的UDP或TCP应用程序
你的问题很简单。但我不能提供更多的细节,因为我的英语很差
但是我认为您可以看到ns3,特别是第一个ns-3脚本部分。根据您想要处理的网络拓扑,有不同的方法来完成。如果您想让四个节点共享相同的共享介质,只需执行一个
node.Create(4)
并在NodeContainer
上安装一个CsmaHelper
,您就可以签出/examples/tutorial/second.cc来简单实现这一点
但是,如果您想要一个哑铃状拓扑,每侧有一个叶节点和一个中央通道,那么您必须创建三个NodeContainer
,每个节点上都安装了PointTopointAlper
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为代码段添加了适当的缩进谢谢!我还可以问另一个问题吗?如果我有两个节点,我将它们连接到point2point,如果我想有一个双工链接,以便这两个节点可以相互通信,我是否应该使用internet stack helper添加两个ip地址?否,您必须使用Ipv4AddressHelper提供单个地址子网,并将其分配给您将在节点上安装的NetDeviceContainer。哦,好的!然后,我只需要为这两个节点配置一个TCP源和接收器应用程序……对吗?是的,在设置internet堆栈之后,您只需要配置一个源和接收器应用程序