使用NS3提供的DSR MODEL,不能在不同的通道内进行通信

问题描述 投票:0回答:1

将3组节点放在三个adhoc通道中,这些节点在同一个IPV4网络中

这是问题所在:

assert failed. cond="mainVector.front () == source", file=../src/dsr/model/dsr-options.cc, line=908
terminate called without an active exception

我真的想知道你们如何在不同渠道之间进行交流?请帮助我摆脱这个(╥﹏╥)非常感谢

#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/netanim-module.h"
#include "ns3/olsr-module.h"
#include "ns3/dsr-module.h"
#include "ns3/dsdv-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
  Time::SetResolution (Time::NS);
  bool verbose = true;
  uint32_t nWifi = 3; //设置 无线站点个数
  //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.Parse (argc,argv);

  if (nWifi > 250)
    {
      std::cout << "Too many wifi or csma nodes, no more than 250 each." << std::endl;
      return 1;
    }
  if (verbose)
    {
      LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_ALL);
      LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_ALL);
    }

  NodeContainer wifiStaNodes;
  wifiStaNodes.Create (nWifi);  //创建无线站点STA的节点
  NodeContainer wifiApNode;
  wifiApNode.Create(1);   //创建一个AP节点
//**************************
  NodeContainer wifiStaNodes2;
  wifiStaNodes2.Create (5);  //创建无线站点STA的节点
  NodeContainer wifiApNode2;
  wifiApNode2.Create(1);   //创建一个AP节点
//****************************

  //*************************************************
  NodeContainer nodeall;
  nodeall.Add(wifiStaNodes);
  nodeall.Add(wifiStaNodes2);
  nodeall.Add(wifiApNode);
  nodeall.Add(wifiApNode2);
  //*************************************************

  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();   //使用默认的信道模型
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();  //使用默认的PHY模型
  phy.SetChannel (channel.Create ());  //创建通道对象并把他关联到物理层对象管理器
  WifiHelper wifi;
  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");  //设置wifi助手用AARF速率控制算法
 //*******************************************************
    YansWifiChannelHelper channel1 = YansWifiChannelHelper::Default ();   //使用默认的信道模型
     YansWifiPhyHelper phy1 = YansWifiPhyHelper::Default ();  //使用默认的PHY模型
     phy1.SetChannel (channel1.Create ());  //创建通道对象并把他关联到物理层对象管理器
     wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
     NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
     wifiMac.SetType ("ns3::AdhocWifiMac");
     NodeContainer mixnode1;
     mixnode1.Add(wifiStaNodes);
     mixnode1.Add(wifiApNode);
     NetDeviceContainer devices = wifi.Install (phy1, wifiMac, mixnode1);
 //*******************************************************
     YansWifiChannelHelper channel3 = YansWifiChannelHelper::Default ();   //使用默认的信道模型
      YansWifiPhyHelper phy3 = YansWifiPhyHelper::Default ();  //使用默认的PHY模型
      phy3.SetChannel (channel3.Create ());  //创建通道对象并把他关联到物理层对象管理器
      NodeContainer wifiDAP;
      wifiDAP.Add(wifiApNode2);
      wifiDAP.Add(wifiApNode);
      wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
      NqosWifiMacHelper wifiMac3 = NqosWifiMacHelper::Default ();
      wifiMac3.SetType ("ns3::AdhocWifiMac");
      NetDeviceContainer devices3 = wifi.Install (phy3, wifiMac3, wifiDAP);
 //*******************************************************
      YansWifiChannelHelper channel4 = YansWifiChannelHelper::Default ();   //使用默认的信道模型
       YansWifiPhyHelper phy4 = YansWifiPhyHelper::Default ();  //使用默认的PHY模型
       phy4.SetChannel (channel4.Create ());  //创建通道对象并把他关联到物理层对象管理器
       wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
       NqosWifiMacHelper wifiMac4 = NqosWifiMacHelper::Default ();
       wifiMac4.SetType ("ns3::AdhocWifiMac");
       NodeContainer mixnode2;
       mixnode2.Add(wifiStaNodes2);
       mixnode2.Add(wifiApNode2);
       NetDeviceContainer devices4 = wifi.Install (phy4, wifiMac4, mixnode2);
//******************************************************

  // 加入移动模型,让STA可以移动,AP固定
  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (5.0),
                                 "DeltaY", DoubleValue (10.0),
                                 "GridWidth", UintegerValue (3),
                                 "LayoutType", StringValue ("RowFirst"));
  //设置初始时,节点的摆放位置
  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",   //设置移动模式为"ns3::RandomWalk2dMobilityModel",随机移动
                             "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));   //移动范围
  mobility.Install (wifiStaNodes);
  //**********************************************
  mobility.Install (wifiStaNodes2);
  //**********************************************
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");  //设置AP的不能够移动的,"ns3::ConstantPositionMobilityModel"
  mobility.Install (wifiApNode);
  //**********************************************
  mobility.Install (wifiApNode2);
  //**********************************************
  //mobility.Install(nodeall);

  InternetStackHelper internet;
  DsrMainHelper dsrMain;
  DsrHelper dsr;
  internet.Install (nodeall);
  dsrMain.Install (dsr, nodeall);
/*
  InternetStackHelper stack;
  ns3::OlsrHelper Olsr;
  stack.SetRoutingHelper(Olsr);
  stack.Install(nodeall);
*/
   //********************************************************
  Ipv4AddressHelper address;
  address.SetBase ("198.1.2.0", "255.255.255.0");
  Ipv4InterfaceContainer wifiInterfaces3;
  wifiInterfaces3=address.Assign (devices3);
//*******************************************************
  address.SetBase ("198.1.0.0", "255.255.255.0");
  Ipv4InterfaceContainer mixInterfaces;
    mixInterfaces=address.Assign (devices);
 //********************************************************
    address.SetBase ("198.2.0.0", "255.255.255.0");
    Ipv4InterfaceContainer mixInterfaces4;
      mixInterfaces4=address.Assign (devices4);

      std::cout<<"mi "<<mixInterfaces4.GetAddress(5)<<std::endl;
 //********************************************************
  //安装UDP程序,使用UDP,与之前的UDP的使用方法一致
  UdpEchoServerHelper echoServer (9);
  ApplicationContainer serverApps = echoServer.Install (wifiStaNodes2.Get (0));//wifiApNode2
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (40.0));
  UdpEchoClientHelper echoClient (mixInterfaces4.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (10000));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds(1 / ((double) 20))));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
  ApplicationContainer clientApps =
    echoClient.Install (wifiStaNodes2.Get (1));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (40.0));

  //Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  phy4.EnablePcap("AAA",wifiStaNodes2);
  Simulator::Stop (Seconds (41.0));
  AnimationInterface anim("amix.xml");
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}
c++ adhoc ns-3
1个回答
0
投票

这个问题已经搁置了很长时间,没有人愿意帮助我,这可能是因为我的问题太简单了。

通过解释DSR源文件代码可以知道此问题。 NS3提供的DSR模块根本不提供跨网关功能,DSR在实现过程中不支持一个节点的多个接口。如果执行此操作,可能是因为您设置了接口的顺序,这会导致程序报告错误。

解决方案:

  1. 首先,我在dsr_routing文件中记录了每个节点的接口,然后每个接口处理rreq的转发,以便将rreq消息转发出网关。
  2. 当目标节点收到rreq消息时,它将回复。 Rrep消息,还需要注意nodelist中的地址是路由路径地址,但只代表一个节点的接口,因此您还需要定义一个全局映射。 该映射将记录哪个是与接口对应的节点,

上面提到了具体的想法,当然,没有提到许多细节。如果您想探索细节,可以与我联系。

© www.soinside.com 2019 - 2024. All rights reserved.