[英]Send a packet through UdpL4Protocol with NS3
I am trying to run a simulation in ns3(C++) in which a node sends a packet to another node with the method "Send"(included in the ns3 library). 我正在尝试在ns3(C ++)中运行模拟,其中一个节点使用“发送”方法(包含在ns3库中)将数据包发送到另一个节点。 The program builds properly but I get a segmentation fault when I run it. 该程序正确构建,但运行时出现分段错误。 I checked the parameters, I am not doing anything fancy with pointers. 我检查了参数,我对指针没有任何幻想。
It seems the error comes from the method "Send" but I can't figure out what exactly is the problem, I tried displaying the IP addresses and they seem to be alright, I tried to create the packet with the default constructor, with parameters. 似乎错误来自方法“ Send”,但我无法弄清楚到底是什么问题,我尝试显示IP地址,但似乎没问题,我尝试使用具有参数的默认构造函数创建数据包。 I also tried to use IPv6 addresses but it did not work neither. 我也尝试使用IPv6地址,但两者均无效。
Please help, I'm out of ideas 请帮忙,我没主意了
Here is my code : 这是我的代码:
#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.));
}
and the message i get from the debugger : 以及我从调试器得到的消息:
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);
Have you follow this belowing link procedure ? 您是否遵循以下链接程序? http://www.nsnam.org/wiki/HOWTO_understand_and_find_cause_of_terminated_with_signal_errors http://www.nsnam.org/wiki/HOWTO_understand_and_find_cause_of_terminated_with_signal_errors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.