NetAnim2: Difference between revisions
Line 260: | Line 260: | ||
Example: | Example: | ||
<packet fromLp="0" fromId="1" fbTx="1" lbTx="1.000067199"><rx toLp="0" toId="0" fbRx="1.002" lbRx="1.002067199"/> | <packet fromLp="0" fromId="1" fbTx="1" lbTx="1.000067199"><rx toLp="0" toId="0" fbRx="1.002" lbRx="1.002067199"/> | ||
Packet over wired-links from Node 1 was received at Node 0. The first bit of the packet was transmitted at the 1th second, the last bit was transmitted at the | |||
1.000067199th second of the simulation | 1.000067199th second of the simulation | ||
Node 0 received the first bit of the packet at 1.002th second and the last bit of the packet at the 1.002067199th second of the simulation | Node 0 received the first bit of the packet at 1.002th second and the last bit of the packet at the 1.002067199th second of the simulation |
Revision as of 17:53, 21 August 2011
A simple animator is presented here, called NetAnim , based on the multi-platform QT4 GUI toolkit. NetAnim requires a custom trace file for animation. This trace file is generated by an animation interface and is included in the current version of ns-3.
Prerequisites
- mercurial
- QT4 development packages
- xerces-c++ development packages
Debian/Ubuntu Linux distribution:
- apt-get install mercurial
- apt-get install qt4-dev-tools
Red Hat/Fedora based distribution:
- yum install mercurial
- yum install qt4
- yum install qt4-devel
- yum install xerces-c
- yum install xerces-c-devel
Mac/OSX
- Qt4 : Install the binaries (including Qt Creator) from http://qt.nokia.com/downloads/
- Xerces-c++: http://xerces.apache.org/xerces-c/download.cgi
Downloading NetAnim
NetAnim 2.0:
hg clone http://code.nsnam.org/jabraham3/netanim
NetAnim 1.0:
click here. Untar it using:tar -xzvf NetAnim.tar.gz
Building NetAnim
NetAnim uses a QT4 build tool called qmake.
In General
cd netanim qmake NetAnim.pro make
DO NOT build NetAnim as a root-user or you might encounter the following error
GLib-GIO:ERROR:gdbusconnection.c:2279:initable_init: assertion failed: (connection->initialization_error == NULL) Aborted (core dumped)
On Mac OS X
The preferred Qt 4 version is Qt 4.7. Using "Qt Creator" to build NetAnim is usually fool-proof
cd netAnim /usr/local/Trolltech/Qt-4.x.y/bin/qmake NetAnim.pro make
Note that above, the x.y is the specific version of Qt4 you are running.
If the above steps do not work , please see the suggestion below from a user
1. Download Qt libraries for Mac from the page [http://qt.nokia.com/downloads/qt-for-open-source-cpp-development-on-mac-os-x] for example: [http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.2-debug-libs.dmg] 2. Download NetAnim from [http://www.nsnam.org/~jpelkey3/NetAnim.tar.gz] 3. $tar -xzvf NetAnim.tar.gz 4. $cd NetAnim 5. $/usr/bin/qmake-4.7 NetAnim.pro This will create xcode project NetAnim.xcodeproj 6. Open NetAnim.xcodeproj with xcode and build.You will get NetAnim executable.
Special note to Mac OS X Lion users as of July 30, 2011: In the latest build of Qt libraries, namely, http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.3.dmg, qmake generates Xcode .pbproj file instead of Makefile by default. The Xcode file, however, is incompatible to the Xcode tools (version 4.1) for Lion. To get the Makefile output from qmake, one can try the following after installed qt-mac-opensource-4.7.3.dmg:
$ cd /usr/local/Qt4.7/mkspecs/ $ sudo rm default $ sudo ln -s macx-g++ default
Then, qmake will use the GCC template instead of Xcode template for building Qt projects. You can then build NetAnim as usual, namely,
$ cd netanim $ qmake $ make
On Ubuntu/Debian
cd netanim qmake-qt4 NetAnim.pro make
Feature-set in NetAnim 2.0
- Basic
- Read offline XML trace file generated by ns-3's [ http://www.nsnam.org/doxygen/classns3_1_1_animation_interface.html AnimationInterface ]
- Ability to track Wired & Wireless transmission
- Any node having a mobility model can be seen on the Animation.
- Track mobility of nodes
- Record button to take periodic snapshots of the Animation
- Display Node Id on the Animation canvas, with zoom-in, zoom-out etc
- Advanced (Requires integration with ns-3 libraries.Not yet completely implemented)
- Plotting the animation while the simulation is running
- Logging statistics to select Logging Components individually and display them while the simulation is running
- Routing statistics to print Routing Tables and other Ipv4 statistics such as Tx,Rx,Drop counters while the simulation is running
- Feature removed
- Socket based communication between the Animator and ns-3
Feature-set in NetAnim 1.0
- Animate only Wired topology
- Read non-XML trace file generated by ns-3
Using ns3::AnimationInterface to generate Animation trace files
The NetAnim application requires a custom trace file for animation. This trace file is created by AnimationInterface in ns-3.
- Model is at: src/netanim/model
- Examples are at src/netanim/examples
NetAnim 2.0 supports only reading XML trace files.
NetAnim 1.0 can read only Non-XML traces.
AnimationInterface as of ns-3.12 generates only non-XML trace files by default. To generate XML trace files, use void ns3::AnimationInterface::SetXMLOutput() prior to StartAnimation. See the examples under "src/netanim/examples"
Recommended set of steps
Here is the recommended set of steps for generating XML Animation traces.They must be applied before the "Simulation::Run" statement.
NOTE: A node must have an associated mobility model in-order to be displayed on the animation. This applies for both stationary and mobile nodes (See notes below)
1. AnimationInterface anim; 2. anim.SetOutputFile ("animation.xml"); 3. anim.SetXMLOutput (); 4. anim.SetMobilityPollInterval (Seconds (1)); 5. anim.StartAnimation ();
where
1. Create an AnimationInterface object 2. Set the trace output file name 3. Enable XML output (Only when using NetAnim 2.0) 4. This statement is optional. It records the position of the nodes every 1 second. NOTE: Setting a low value may result in large XML files. If your topology is expected to be stationary, it will be good to set it to a very large value (so that no polling occurs). 5. Start recording traces
Running an Example File
The netanim example files are located under "src/netanim/examples"
./waf --run "dumbbell-animation --nLeftLeaf=5 --nRightLeaf=5 --animFile=dumbbell.xml" ./waf --run "grid-animation --xSize=5 --ySize=5 --animFile=grid.xml"
Setting the location of nodes
NetAnim requires a location to be assigned to each Node, in-order to be shown on the animation.
For stationary nodes:
- You should assign the ConstantPositionMobilityModel. Constant Position is a kind of mobility.
Here is an example:
1. Ptr<Node> n = nodecontainer.Get (1); 2. Ptr<ConstantPositionMobilityModel> Loc = n->GetObject<ConstantPositionMobilityModel> (); 3. if (Loc == 0) { 4. Loc = CreateObject<ConstantPositionMobilityModel> (); 5. n->AggregateObject (Loc); } 6. Vector vec (10, 20, 0); 7. Loc->SetPosition (vec);
where
1. Get a Ptr to Node from the node container 2. Get the aggregated ConstantPositionMobilityModel object from the node 3. If Loc ==0 , it indicates that this node is not aggregated with a mobility model.So we have to aggregate one. 4. Create a ConstantPositionMobilityModel object and assign it to Loc 5. Aggregate the mobility model "Loc" to the node 6. Create a position vector with 3-d co-ordinates x= 10, y= 20, z=0 7. Set the position vector to the mobility model
For mobile nodes
- You should assign any suitable Mobility model.
The examples for these are found in places such as src/mobility/examples or examples/routing/manet-routing-compare.cc etc
Understanding the XML trace file format
The ns3::AnimationInterface class is responsible for the creation of the xml trace files. Currently, in basic-mode, AnimationInterface records the position of the nodes at every periodic interval. This interval is 200 ms by default. This will become more efficient in future releases. This has the potential to cause a. Slowness in simulation b. Large XML trace files
Some ways to get around this is to identify if your topology has
- only stationary nodes and hence no mobility
- or slow-moving nodes
If the above is the case you should use AnimationInterface::SetMobilityPollInterval to set the poll interval to a high value.
Parts of the XML
The XML trace files has the following main sections
- Topology
- Nodes
- Links
- packets
- wpackets
XML tags
Nodes are identified by their unique Node id. The XML begins with the "information" element describing the rest of the elements
<anim> element
This is the XML root element. All other elements fall within this element
Attributes are: lp = Logical Processor Id (Used for distributed simulations only)
<topology> element
This elements contains the Node and Link elements.It describes, the co-ordinates of the canvas used for animation.
Attributes are: minX = minimum X coordinate of the animation canvas minY = minimum Y coordinate of the animation canvas maxX = maximum X coordinate of the animation canvas maxY = maximum Y coordinate of the animation canvas Example: <topology minX = "-6.42025" minY = "-6.48444" maxX = "186.187" maxY = "188.049">
<node> element
This element describes each Node's Id and X,Y co-ordinate (position)
Attributes are: lp = Logical Processor Id (Used for distributed simulations only) id = Node Id locX = X coordinate locY = Y coordinate
Example: <node lp = "0" id = "8" locX = "107.599" locY = "96.9366" />
<link> element
This element describes wired links between two nodes.
Attributes are: fromLp = From logical processor Id (Used for distributed simulations only) fromId = From Node Id (first node id) toLp = To logical processor Id toId = To Node Id (second node id) Example: <link fromLp="0" fromId="0" toLp="0" toId="1"/>
<packet> element
This element describes a packet over wired links being transmitted at some node and received at another The reception details is described in it associated rx element
Attributes are: fromLp = From logical processor Id (Used for distributed simulations only) fromId = Node Id transmitting the packet fbTx = First bit transmit time of the packet lbTx = Last bit transmit time of the packet
Example: <packet fromLp="0" fromId="1" fbTx="1" lbTx="1.000067199"><rx toLp="0" toId="0" fbRx="1.002" lbRx="1.002067199"/> Packet over wired-links from Node 1 was received at Node 0. The first bit of the packet was transmitted at the 1th second, the last bit was transmitted at the 1.000067199th second of the simulation Node 0 received the first bit of the packet at 1.002th second and the last bit of the packet at the 1.002067199th second of the simulation
<rx> element
This element describes the reception of a packet at a node
Attributes are: toLp = To logical processor Id toId = Node Id receiving the packet fbRx = First bit Reception Time of the packet lbRx = Last bit Reception Time of the packet
<wpacket> element
This element describes a packet over wireless links being transmitted at some node and received at another The reception details is described in it associated rx element
Attributes are: fromLp = From logical processor Id (Used in distributed simulations only) fromId = Node Id transmitting the packet fbTx = First bit transmit time of the packet lbTx = Last bit transmit time of the packet range = Range of the transmission
<rx> element
This element describes the reception details of the wireless packet
Attributes are: toLp = To logical processor Id (Used in distributed simulations only) toId = Receiving Node Id fbRx = First bit Reception time of the packet lbRx = Last bit Reception time of the packet
Creating Custom Scripts for Animation
If you would like to create custom scripts for animation because you need more than a simple dumbbell or grid topology, please keep in mind that nodes must be assigned locations for your animation to show up. Some example code for assigning node locations exists in point-to-point-grid-helper and point-to-point-dumbbell helper, specifically in the BoundingBox functions.