2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
* Author: George F. Riley<riley@ece.gatech.edu>
16
* Modified by: John Abraham <john.abraham@gatech.edu>
19
// Interface between ns3 and the network animator
21
#ifndef ANIMATION_INTERFACE__H
22
#define ANIMATION_INTERFACE__H
28
#include "ns3/net-device.h"
29
#include "ns3/nstime.h"
31
#include "ns3/node-list.h"
32
#include "ns3/simulator.h"
33
#include "ns3/config.h"
34
#include "ns3/animation-interface-helper.h"
35
#include "ns3/mac48-address.h"
40
#define STDOUT_FILENO (SOCKET)GetStdHandle(STD_OUTPUT_HANDLE)
46
#define HANDLETYPE SOCKET
48
#include "ns3/netanim-config.h"
49
#define HANDLETYPE int
55
* \defgroup netanim Netanim
57
* This section documents the API of the ns-3 netanim module. For a generic functional description, please refer to the ns-3 manual.
63
* \brief Interface to network animator
65
* Provides functions that facilitate communications with an
66
* external or internal network animator.
68
class AnimationInterface
73
* \brief Construct the animator interface. No arguments needed.
76
AnimationInterface ();
79
* \brief Destructor for the animator interface.
82
~AnimationInterface ();
86
* \param filename The Filename for the trace file used by the Animator
87
* \param usingXML Set to true if XML output traces are required
90
AnimationInterface (const std::string filename, bool usingXML = true);
94
* \param port Port on which ns-3 should listen to for connection from the
95
* external netanim application
96
* \param usingXML Set to true if XML output traces are required
99
AnimationInterface (uint16_t port, bool usingXML = true);
102
* \brief Check if AnimationInterface is initialized
103
* \returns true if AnimationInterface was already initialized
106
static bool IsInitialized (void);
109
* \brief Specify that animation commands are to be written
110
* to the specified output file.
112
* This call is used to write the animation information to a text
113
* file that can later be used as input to the network animator tool.
115
* \param fn The name of the output file.
116
* \returns true if successful open.
119
bool SetOutputFile (const std::string& fn);
122
* \brief Specify that animation commands are to be written
128
void SetXMLOutput ();
131
* \brief (Deprecated) Specify that animation commands are to be written to
134
* This call is used to set the ns3 process in server mode, waiting
135
* for a TCP connection from the animator. This call will not
136
* return until the animator connects in, or if the bind to the
137
* specified port fails.
139
* \param port Port number to bind to.
140
* \returns true if connection created, false if bind failed.
143
bool SetServerPort (uint16_t port);
146
* \brief Writes the topology information and sets up the appropriate
147
* animation packet tx callback
149
* Writes the topology information to the appropriate output, depending
150
* on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
151
* Then creates the callbacks needed for the animator to start processing
155
void StartAnimation ();
158
* \brief Closes the interface to the animator.
161
void StopAnimation ();
164
* \brief Set mobility poll interval:WARNING: setting a low interval can
167
* \param t Time interval between fetching mobility/position information
171
void SetMobilityPollInterval (Time t);
174
* \brief Set random position if a Mobility Model does not exists for the node
176
* \param setRandPos True if a random position can be set for a node without a
180
void SetRandomPosition (bool setRandPos);
183
* \brief typedef for WriteCallBack used for listening to AnimationInterface
187
typedef void (*AnimWriteCallback) (const char * str);
190
* \brief Set a callback function to listen to AnimationInterface write events
192
* \param cb Address of callback function
195
void SetAnimWriteCallback (AnimWriteCallback cb);
198
* \brief Reset the write callback function
201
void ResetAnimWriteCallback ();
204
* \brief Helper function to set Constant Position for a given node
205
* \param n Ptr to the node
206
* \param x X co-ordinate of the node
207
* \param y Y co-ordinate of the node
208
* \param z Z co-ordinate of the node
211
void SetConstantPosition (Ptr <Node> n, double x, double y, double z=0);
214
* \brief Is AnimationInterface started
215
* \returns true if AnimationInterface was started
218
bool IsStarted (void);
222
int m_fHandle; // File handle for output (-1 if none)
223
// Write specified amount of data to the specified handle
224
int WriteN (int, const char*, uint32_t);
226
SOCKET m_fHandle; // File handle for output (-1 if none)
227
int WriteN (SOCKET, const char*, uint32_t);
229
bool m_xml; // True if xml format desired
230
Time mobilitypollinterval;
233
std::string outputfilename;
236
void DevTxTrace (std::string context,
242
void WifiPhyTxBeginTrace (std::string context,
243
Ptr<const Packet> p);
244
void WifiPhyTxEndTrace (std::string context,
245
Ptr<const Packet> p);
246
void WifiPhyTxDropTrace (std::string context,
247
Ptr<const Packet> p);
248
void WifiPhyRxBeginTrace (std::string context,
249
Ptr<const Packet> p);
250
void WifiPhyRxEndTrace (std::string context,
251
Ptr<const Packet> p);
252
void WifiMacRxTrace (std::string context,
253
Ptr<const Packet> p);
254
void WifiPhyRxDropTrace (std::string context,
255
Ptr<const Packet> p);
256
void WimaxTxTrace (std::string context,
258
const Mac48Address &);
259
void WimaxRxTrace (std::string context,
261
const Mac48Address &);
262
void CsmaPhyTxBeginTrace (std::string context,
263
Ptr<const Packet> p);
264
void CsmaPhyTxEndTrace (std::string context,
265
Ptr<const Packet> p);
266
void CsmaPhyRxEndTrace (std::string context,
267
Ptr<const Packet> p);
268
void CsmaMacRxTrace (std::string context,
269
Ptr<const Packet> p);
270
void MobilityCourseChangeTrace (Ptr <const MobilityModel> mob);
272
// Write a string to the specified handle;
273
int WriteN (int, const std::string&);
275
void OutputWirelessPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
276
void OutputCsmaPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
277
void MobilityAutoCheck ();
279
uint64_t gAnimUid ; // Packet unique identifier used by Animtion
281
std::map<uint64_t, AnimPacketInfo> pendingWifiPackets;
282
void AddPendingWifiPacket (uint64_t AnimUid, AnimPacketInfo&);
283
bool WifiPacketIsPending (uint64_t AnimUid);
285
std::map<uint64_t, AnimPacketInfo> pendingWimaxPackets;
286
void AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo&);
287
bool WimaxPacketIsPending (uint64_t AnimUid);
289
std::map<uint64_t, AnimPacketInfo> pendingCsmaPackets;
290
void AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo&);
291
bool CsmaPacketIsPending (uint64_t AnimUid);
293
uint64_t GetAnimUidFromPacket (Ptr <const Packet>);
295
std::map<uint32_t, Vector> nodeLocation;
296
Vector GetPosition (Ptr <Node> n);
297
Vector UpdatePosition (Ptr <Node> n);
298
Vector UpdatePosition (Ptr <Node> n, Vector v);
299
void WriteDummyPacket ();
300
bool NodeHasMoved (Ptr <Node> n, Vector newLocation);
303
void PurgePendingWifi ();
304
void PurgePendingWimax ();
305
void PurgePendingCsma ();
307
// Recalculate topology bounds
308
void RecalcTopoBounds (Vector v);
309
std::vector < Ptr <Node> > RecalcTopoBounds ();
312
AnimWriteCallback m_writeCallback;
313
void ConnectCallbacks ();
318
std::vector<std::string> GetElementsFromContext (std::string context);
319
Ptr <NetDevice> GetNetDeviceFromContext (std::string context);
322
std::string GetPreamble (void);
323
// Topology element dimensions
329
std::string GetXMLOpen_anim (uint32_t lp);
330
std::string GetXMLOpen_topology (double minX,double minY,double maxX,double maxY);
331
std::string GetXMLOpenClose_node (uint32_t lp,uint32_t id,double locX,double locY);
332
std::string GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId);
333
std::string GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, std::string auxInfo = "");
334
std::string GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx);
335
std::string GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, double range);
336
std::string GetXMLClose (std::string name) {return "</" + name + ">\n"; }
343
* \brief Byte tag using by Anim to uniquely identify packets
345
* When Anim receives a Tx Notification we tag the packet with a unique global uint64_t identifier
346
* before recording Tx information
347
* When Anim receives Rx notifications the tag is used to retrieve Tx information recorded earlier
351
class AnimByteTag : public Tag
360
static TypeId GetTypeId (void);
363
* \brief Get Instance Type Id
367
virtual TypeId GetInstanceTypeId (void) const;
370
* \brief Get Serialized Size
371
* \returns Serialized Size (i.e size of uint64_t)
374
virtual uint32_t GetSerializedSize (void) const;
377
* \brief Serialize function
378
* \param i Tag Buffer
381
virtual void Serialize (TagBuffer i) const;
384
* \brief Deserialize function
385
* \param i Tag Buffer
388
virtual void Deserialize (TagBuffer i);
391
* \brief Print tag info
392
* \param os Reference of ostream object
395
virtual void Print (std::ostream &os) const;
398
* \brief Set global Uid in tag
399
* \param AnimUid global Uid
402
void Set (uint64_t AnimUid);
405
* \brief Get Uid in tag
406
* \returns Uid in tag
409
uint64_t Get (void) const;