ns3で"ns3-hello-world.cc"というプログラムを実行したところ,
コンパイルはできるのですが,エラーが出てしまいます.
ソースコードは
/* -- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -- /
/ payload-test.cc: send a greeting message between two nodes
- F.Qian, Oct. 2013
- src(source) -----net(10Mbps,5ms)----- dst(destination)
-
192.168.1.0/24
*/
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/tcp-header.h"
#include "ns3/udp-header.h"
#define NET_MASK "255.255.255.0"
#define NET_ADDR "192.168.1.0"
#define FIRST_NO "0.0.0.1"
#define PORT 50000
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("PayloadTest");
void
ReceivePacket (Ptr<Socket> socket)
{
Ptr<Packet> packet;
Address from;
uint8_t buf[1024]; memset(buf, 0, sizeof(buf)); while ((packet = socket->RecvFrom (from))) { if (packet->GetSize () > 0) { packet->CopyData(buf, 1024); InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (from); char t[10]; sprintf(t,"%8.5f",Simulator::Now ().GetSeconds ()); std::cout << std::setw(10) << std::setprecision(4) << t << " received "<< packet->GetSize () << " bytes from: (" << iaddr.GetIpv4 () << ", " << iaddr.GetPort () << ")" << " --- " << buf << std::endl; } }
}
InetSocketAddress
setSocketAddress(Ptr<Node> node, uint32_t port)
{
Ipv4InterfaceAddress adr = node->GetObject <Ipv4> ()->GetAddress(1, 0);
return InetSocketAddress (Ipv4Address(adr.GetLocal()), port);
}
int main (int argc, char *argv[], char *envp[])
{
CommandLine cmd;
uint16_t times=1;
std::string greeting_msg = "hello ns3 world !!!";
//timesには送信する回数、greetingには送信するメッセージを指定する cmd.AddValue("times", "The number of times to send.", times); cmd.AddValue("greeting", "The greeting message from source to destination.", greeting_msg); cmd.Parse(argc, argv); //ノードを生成する NS_LOG_DEBUG("Creating Topology"); Ptr<Node> src = CreateObject<Node> (); Ptr<Node> dst = CreateObject<Node> (); NodeContainer net_nodes; net_nodes.Add (src); net_nodes.Add (dst); //データリンク層の設定を行う PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); p2p.SetQueue ("ns3::DropTailQueue"); NetDeviceContainer devices; devices = p2p.Install (net_nodes); //ネットワーク層の設定を行う InternetStackHelper stack; stack.InstallAll (); Ipv4AddressHelper address; address.SetBase (NET_ADDR, NET_MASK, FIRST_NO); Ipv4InterfaceContainer ifs = address.Assign (devices); NS_LOG_INFO ("Network : " << ifs.GetAddress(0, 0) << " - " << ifs.GetAddress(1, 0)); NS_LOG_INFO ("Initialize Global Routing."); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // あて先ノードのソケットを生成する TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); NS_LOG_INFO ("set destination's socket."); Ptr<Socket> sink_socket = Socket::CreateSocket (dst, tid); InetSocketAddress dstSocketAddr = setSocketAddress (dst, PORT); sink_socket->Bind (dstSocketAddr); sink_socket->SetRecvCallback (MakeCallback (ReceivePacket)); // ソースノードのソケットを生成する NS_LOG_INFO ("set source's socket."); Ptr<Socket> src_socket = Socket::CreateSocket (src, tid); InetSocketAddress srcSocketAddr = setSocketAddress (src, PORT); src_socket->Bind (srcSocketAddr); src_socket->SetAllowBroadcast (true); //あて先のピアアドレスに接続する src_socket->Connect (dstSocketAddr); // 送信するパケットを組み立てる uint8_t buf[1024]; uint16_t bufsize; bufsize = greeting_msg.size(); memcpy(buf, greeting_msg.c_str(),bufsize); Ptr<Packet> packet = Create<Packet> (buf, bufsize); //パケットを送信する for(uint16_t i=0;i<times;i++) src_socket->Send (packet); Simulator::Stop (Seconds(10.0)); Simulator::Run (); Simulator::Destroy (); return 0;
}
です.
コマンドは
./waf --run "ns3-hello-world"
エラーは
Waf: Entering directory /home/hatanaka/ns-allinone-3.26/ns-3.26/build' Waf: Leaving directory
/home/hatanaka/ns-allinone-3.26/ns-3.26/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (0.562s)
Command ['/home/hatanaka/ns-allinone-3.26/ns-3.26/build/scratch/ns3-hello-world'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").
です.