Я только недавно запустил ns-3 и занимаюсь симуляцией протокола olsr. Я хочу использовать два канала, один для отправки сообщений управления маршрутизацией и один для отправки данных UDP, но после запуска следующего кода узел будет отправлять только сообщения Hello, которые я не могу установить sh соединение. Я хочу спросить, что мне делать?
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/yans-wifi-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("BeamTest");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nWifi = 5;
bool tracing = false;
CommandLine cmd;
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the bounding box" << std::endl;
return 1;
}
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
NodeContainer Nodes;
Nodes.Create(nWifi);
WifiHelper wifi;
WifiMacHelper mac;
mac.SetType("ns3::AdhocWifiMac");
YansWifiChannelHelper channel;// = YansWifiChannelHelper::Default();
channel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(100));
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel(channel.Create());
//first netdevice
NetDeviceContainer AdhocDevices = wifi.Install(phy,mac,Nodes);
//second netdevice
mac.SetType("ns3::AdhocWifiMac");
NetDeviceContainer secondDevices = wifi.Install(phy,mac,Nodes);
//mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (100.0),
"DeltaY", DoubleValue (100.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-500, 500, -500, 500)));
mobility.Install (Nodes);
//routing protocol
OlsrHelper olsr;
//Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
//list.Add (staticRouting, 0);
list.Add (olsr, 10);
InternetStackHelper stack;
stack.SetRoutingHelper(list);
stack.Install(Nodes);
//first interface
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interface1;
interface1 = address.Assign (AdhocDevices);
//second interface
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer interface2;
interface2 = address.Assign (secondDevices);
Simulator::Stop (Seconds (30.0));
if (tracing == true)
{
//stack.EnablePcapIpv4("myolsr",Nodes);
stack.EnablePcapIpv4All("beam");
//phy.EnablePcapAll("phy");
}
OnOffHelper onoff1 ("ns3::UdpSocketFactory",InetSocketAddress (interface2.GetAddress (nWifi-1), 9));
onoff1.SetConstantRate (DataRate("10kbps"));
onoff1.SetAttribute("OffTime",StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
onoff1.SetAttribute("PacketSize",UintegerValue(512));
ApplicationContainer onOffApp1 = onoff1.Install (Nodes.Get (0));
onOffApp1.Start (Seconds(0));
onOffApp1.Stop (Seconds (30.0));
PacketSinkHelper sink ("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), 9));
NodeContainer sinks = NodeContainer (Nodes.Get (nWifi-1));
ApplicationContainer sinkApps = sink.Install (sinks);
sinkApps.Start (Seconds(0));
sinkApps.Stop (Seconds (30.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}