提问者:小点点

使用NS3通过UDPL4协议发送数据包


我正在尝试在ns3(C++)中运行一个模拟,其中一个节点用方法“send(ns3库中包含的)向另一个节点发送数据包。程序构建正确,但运行时出现分段错误。我检查了参数,我没有做任何花哨的指针。

似乎错误来自方法“send”,但我不知道到底是什么问题,我试着显示IP地址,它们似乎没有问题,我试着用默认构造函数创建数据包,并带有参数。我也尝试使用IPv6地址,但也没有工作。

请帮帮我,我没主意了

下面是我的代码:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/wifi-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
#include <vector>
#include <string.h>

using namespace ns3;
void velocityHandler(Ptr<ConstantVelocityMobilityModel> vel, Vector3D vec) {
    vel->SetVelocity(vec);
}

void sendHandler(UdpL4Protocol* udp,NodeContainer nodes, Ptr<Packet> paquet) {


    Ptr<Ipv4> ipv4 = nodes.Get(1)->GetObject<Ipv4>();
    Ptr<Ipv4> ipv42 = nodes.Get(0)->GetObject<Ipv4>();

    Ipv4Address adr = ipv4->GetAddress(1,0).GetLocal();
    Ipv4Address adr2 = ipv42->GetAddress(1,0).GetLocal();

    udp->Send(paquet, adr,adr2,(uint16_t)50 ,(uint16_t)60/*,Ptr<Ipv4Route>(route)*/);


}

int main() {
    Time::SetResolution (Time::MS);
    //Creation des Noeuds
    NodeContainer nodes1, nodes2;
    nodes1.Create(1);
    nodes2.Create(2);


    //Positionnement des noeuds
    MobilityHelper mobility1, mobility2;
    mobility1.SetPositionAllocator("ns3::GridPositionAllocator","MinX",
                                DoubleValue(0.),"MinY",DoubleValue(6.));
    mobility2.SetPositionAllocator("ns3::GridPositionAllocator","MinX",
                                DoubleValue(2.),"MinY",DoubleValue(0.),
                                "DeltaX",DoubleValue(2.),"DeltaY",
                                DoubleValue(4.),"GridWidth",UintegerValue(1),
                                "LayoutType",StringValue("RowFirst"));

    //Deplacements des noeuds
    mobility1.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
    mobility1.Install(nodes1);
    Ptr<ConstantVelocityMobilityModel> velmodel = nodes1.Get(0)->GetObject<ConstantVelocityMobilityModel>();

    (*velmodel).SetVelocity(Vector3D(0.,0.,0.));


    mobility2.SetMobilityModel("ns3::ConstantPositionMobilityModel");
    mobility2.Install(nodes2);



    //liens

    PointToPointHelper p2p;
    p2p.SetDeviceAttribute("DataRate", StringValue ("2Mbps"));
    p2p.SetChannelAttribute("Delay", StringValue ("2ms"));


    //Interfaces
    NetDeviceContainer devices;
    devices = p2p.Install(nodes2);


    //Pile protocolaire
    InternetStackHelper stack;
    stack.Install(nodes2);



    //Adressage
    Ipv4AddressHelper address;
    address.SetBase("30.0.0.0","255.255.255.0");
    Ipv4InterfaceContainer interfaces = address.Assign(devices);


    //UDP
    UdpL4Protocol* udp = new UdpL4Protocol();


    udp->SetNode(nodes2.Get(0));
    udp->SetNode(nodes2.Get(1));




    //lancement de la simulation
    Packet a = Packet();
    AnimationInterface anim ("animudp.xml");
    Simulator::Schedule(Seconds(1.),&velocityHandler, velmodel, Vector3D(5.,0.,0.));
    Simulator::Schedule(Seconds(0.2),&sendHandler,udp, nodes2, Ptr<Packet>(&a));
    Simulator::Run();
    Simulator::Stop(Seconds(10.));



}

我从调试器得到的消息是:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5919900 in ns3::Callback<void, ns3::Ptr<ns3::Packet>, ns3::Ipv4Address, ns3::Ipv4Address, unsigned char, ns3::Ptr<ns3::Ipv4Route>, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator() (this=0x66aa40, a1=..., a2=..., a3=..., a4=17 '\021', a5=...)
    at ./ns3/callback.h:1077
1077        return (*(DoPeekImpl ()))(a1,a2,a3,a4,a5);

共1个答案

匿名用户

您是否遵循以下链接程序?http://www.nsnam.org/wiki/howto_understand_and_find_cause_of_terminated_with_signal_errors