需要帮助将 p2p 设备连接到 ns3 中的 csma 设备

问题描述

我是 ns3 的初学者,在参考了多个资源后,我最终得到了以下代码。

int
main (int argc,char *argv[])
{
    // NodeContainer p2pNodes;
    // p2pNodes.Create (3);

    NodeContainer csmaNodes;
    // csmaNodes.Add (p2pNodes.Get(1));
    // csmaNodes.Add (p2pNodes.Get(2));
    csmaNodes.Create (3);


    // PointToPointHelper pointToPoint;
    // pointToPoint.SetDeviceAttribute ("DataRate",StringValue ("5Mbps"));
    // pointToPoint.SetChannelAttribute ("Delay",StringValue ("2ms"));
    // NetDeviceContainer p2pDevices;
    // p2pDevices = pointToPoint.Install(p2pNodes);


    CsmaHelper csma;
    csma.SetChannelAttribute ("DataRate",StringValue ("100Mbps"));
    csma.SetChannelAttribute ("Delay",TimeValue (NanoSeconds (6560)));
    NetDeviceContainer csmaDevices;
    csmaDevices = csma.Install (csmaNodes);

    
    InternetStackHelper stack;
    // stack.Install (p2pNodes.Get (0));
    stack.Install (csmaNodes);

    
    Ipv4AddressHelper address;
    // address.SetBase ("10.1.1.0","255.255.255.0");
    // Ipv4InterfaceContainer p2pInterfaces;
    // p2pInterfaces = address.Assign (p2pDevices);
   
    address.SetBase ("10.1.2.0","255.255.255.0");
    Ipv4InterfaceContainer csmaInterfaces;
    csmaInterfaces = address.Assign (csmaDevices);


    
    UdpEchoServerHelper echoServer (9);
    ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (2));
    serverApps.Start (Seconds (1.0));
    serverApps.Stop (Seconds (10.0));


    
    UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (2),9);
    echoClient.SetAttribute ("MaxPackets",UintegerValue (1));
    echoClient.SetAttribute ("Interval",TimeValue (Seconds (1.0)));
    echoClient.SetAttribute ("PacketSize",UintegerValue (1024));

    ApplicationContainer clientApps = echoClient.Install (csmaNodes.Get (0));
    clientApps.Start (Seconds (2.0));
    clientApps.Stop (Seconds (10.0));

    Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
    AnimationInterface anim("sample.xml");

    Simulator::Run ();
    Simulator::Destroy ();
    return 0;
}

我想实现的

// To re-create the following
//
// n1 ------- n2 ------- n3                 n4       n5        n6        
//            |           |                 |        |         |        
//            __________________________________________________
//
//

代码中被注释掉的部分是为了实现 p2p 系统,其余的 atm 正在实现 csma 系统。现在 csma 部分可以独立工作,但是当我注释掉注释部分时,出现错误

terminate called without an active exception
Command ['/opt/ns-allinone-3.31/ns-3.31/build/scratch/one'] terminated with signal SIGIOT. Run it under a debugger to get more information (./waf --run <program> --gdb")

现在我知道这意味着存在索引错误,但 csma 部分工作正常,所以它不应该是那个错误。任何帮助都非常感谢 atm。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)