First.cc is not working correctly in NS3

74 views
Skip to first unread message

Imran

unread,
Oct 27, 2018, 6:49:28 AM10/27/18
to ns-3-users
The error is given below:
memran@Ubuntu-VM:~/tarballs/ns-allinone-3.29/ns-3.29$ ./waf --run examples/tutorial/first
Waf: Entering directory `/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build'
[2516/2732] Compiling examples/tutorial/first.cc
[2692/2732] Linking build/examples/tutorial/ns3.29-first-debug
examples/tutorial/first.cc.2.o: In function `main':
/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build/../examples/tutorial/first.cc:102: undefined reference to `ns3::AnimationInterface::AnimationInterface(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build/../examples/tutorial/first.cc:103: undefined reference to `ns3::AnimationInterface::SetConstantPosition(ns3::Ptr<ns3::Node>, double, double, double)'
/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build/../examples/tutorial/first.cc:104: undefined reference to `ns3::AnimationInterface::SetConstantPosition(ns3::Ptr<ns3::Node>, double, double, double)'
/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build/../examples/tutorial/first.cc:102: undefined reference to `ns3::AnimationInterface::~AnimationInterface()'
/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build/../examples/tutorial/first.cc:102: undefined reference to `ns3::AnimationInterface::~AnimationInterface()'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build'
Build failed
 -> task in 'first' failed with exit status 1 (run with -v to display more information)
memran@Ubuntu-VM:~/tarballs/ns-allinone-3.29/ns-3.29$
 

The first.cc code is given below:
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#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/netanim-module.h"
//define a namespace
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int
main (int argc, char *argv[])
{
//CommandLine is a class cmd is an object and Parse is a function 
  CommandLine cmd;
  cmd.Parse (argc, argv);
 
//Take Logs
  Time::SetResolution (Time::NS);
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

//Take n number of computer in this example, means creating two nodes one client and the other is server
//like this(Cient--------Server) with a link and then assign these nodes the IP addresses later below
//NodeContainer is a class, nodes is an object and Create is a function in that function, 2 is the parameter. 
  NodeContainer nodes;
  nodes.Create (2); //nodes.Get(0), nodes.Get(1) to access 1st and 2nd nodes we will use below these methods/function

//Choose your technology to communicate means create a point to point link between the above two created nodes client and server
//PointToPointHelper is a class which has an object pointToPoint
//and further uses the two methods of that class which are SetDeviceAttribute method to set the datarate attribute value of this link
//and SetChannelAttribute method to set the delay attribute value on this point to point link
  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
//Till here only the link is created having 5Mbps Datarate and 2ms of delay but yet the node are not connected together using this link 

//            5Mbps  Datarate
//         A------------------B     Network IP Address is 10.1.1.0 and subnet mask is 255.255.255.0
//     10.1.1.1 2ms delay 10.1.1.2
//      Client ---------->  Server
//      port 49153          port 9
//      Client <----------  Server
//Install technology on computers means the above created link will now connect the two devices
//NetDeviceContainer is a class, devices is an object for this class, pointToPoint is an object of PointToPointHelper class which uses the
//its function install and passes the nodes object of the NodeContainer class as an argument in the Install function call as a result a 
//point to point link between these two devices or nodes will be created
  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes);

//Asking to follow rules for communication
  InternetStackHelper stack;
  stack.Install (nodes);

//Ipv4AddressHelper is a class and address is an object which Assigns or sets the Network IP address and Subnet Mask to communicate
//SetBase is a method or function which sets the network address parameter of this class
  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");

  Ipv4InterfaceContainer interfaces;
  interfaces = address.Assign (devices);

//Create a x type of server on port x, actually UdpEchoServerHelper is a class which creates a server which listens on port 9
//with object echoServer
  UdpEchoServerHelper echoServer (9);

//Install server on a node then Start and Stop the server
//ApplicationContainer is a class which uses the object serverApps to install the server application on the echoServer
//as node 1 which is 2nd node
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

//Create x type of client and set its attributes
  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

//Install the client application on a node then start and stop the client application
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  AnimationInterface anim ("anim1.xml");
  anim.SetConstantPosition(nodes.Get(0), 1.0, 2.0);
  anim.SetConstantPosition(nodes.Get(1), 2.0, 3.0);
//Run the simulation by calling two functions of the Simulator class Run and Destroy
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

Tom Henderson

unread,
Oct 27, 2018, 11:44:48 AM10/27/18
to ns-3-...@googlegroups.com, Imran
The linker is complaining that it can't find symbols for the animation
components, probably because you added some code to first.cc to try to
enable Netanim but you did not express the library dependency in the
build script.

If you add 'netanim' to the list of dependencies in
examples/tutorial/wscript, such as:

obj = bld.create_ns3_program('first', ['core', 'point-to-point',
'internet', 'applications', 'netanim'])
obj.source = 'first.cc'

it may then work for you.
Message has been deleted

Imran

unread,
Oct 28, 2018, 4:10:18 AM10/28/18
to ns-3-users
Dear Tom Henderson,
I thnakful to you for your help and support it worked correctly but it gave the warning just have a look on it and guide:

memran@Ubuntu-VM:~/tarballs/ns-allinone-3.29/ns-3.29$ ./waf --run first
Waf: Entering directory `/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build'
[2517/2736] Linking build/examples/tutorial/ns3.29-first-debug
[2677/2736] Compiling scratch/first.cc
[2678/2736] Compiling scratch/subdir/scratch-simulator-subdir.cc
[2679/2736] Compiling scratch/wifiLte.cc
[2680/2736] Compiling scratch/myfirst.cc
[2681/2736] Compiling scratch/scratch-simulator.cc
[2692/2736] Linking build/scratch/first
[2693/2736] Linking build/scratch/subdir/subdir
[2694/2736] Linking build/scratch/wifiLte
[2695/2736] Linking build/scratch/myfirst
[2696/2736] Linking build/scratch/scratch-simulator
Waf: Leaving directory `/home/memran/tarballs/ns-allinone-3.29/ns-3.29/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (43.878s)
AnimationInterface WARNING:Node:0 Does not have a mobility model. Use SetConstantPosition if it is stationary
AnimationInterface WARNING:Node:1 Does not have a mobility model. Use SetConstantPosition if it is stationary
AnimationInterface WARNING:Node:0 Does not have a mobility model. Use SetConstantPosition if it is stationary
AnimationInterface WARNING:Node:1 Does not have a mobility model. Use SetConstantPosition if it is stationary
At time 2s client sent 1024 bytes to 10.1.1.2 port 9
At time 2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time 2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
At time 2.00737s client received 1024 bytes from 10.1.1.2 port 9
memran@Ubuntu-VM:~/tarballs/ns-allinone-3.29/ns-3.29$
Sincere Regards,
Imran
Reply all
Reply to author
Forward
Message has been deleted
0 new messages