Bug Summary

File:/tmp/asd-nat/home/nat/Work/ns-3-dev-git/build/../src/netanim/model/animation-interface.cc
Location:line 560, column 5
Description:Value stored to 'pos2' is never read

Annotated Source Code

1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation;
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Author: George F. Riley<riley@ece.gatech.edu>
17 * Modified by: John Abraham <john.abraham@gatech.edu>
18 * Contributions: Eugene Kalishenko <ydginster@gmail.com> (Open Source and Linux Laboratory http://dev.osll.ru/)
19 */
20
21// Interface between ns-3 and the network animator
22
23
24
25#include <cstdio>
26#include <unistd.h>
27#include <sstream>
28#include <fstream>
29#include <string>
30#include <iomanip>
31#include <map>
32
33// ns3 includes
34#include "ns3/animation-interface.h"
35#include "ns3/channel.h"
36#include "ns3/config.h"
37#include "ns3/node.h"
38#include "ns3/mobility-model.h"
39#include "ns3/packet.h"
40#include "ns3/simulator.h"
41#include "ns3/wifi-mac-header.h"
42#include "ns3/wimax-mac-header.h"
43#include "ns3/wifi-net-device.h"
44#include "ns3/wifi-mac.h"
45#include "ns3/constant-position-mobility-model.h"
46#include "ns3/lte-ue-phy.h"
47#include "ns3/lte-enb-phy.h"
48#include "ns3/uan-net-device.h"
49#include "ns3/uan-mac.h"
50#include "ns3/ipv4.h"
51#include "ns3/ipv4-routing-protocol.h"
52#include "ns3/energy-source-container.h"
53
54namespace ns3 {
55
56NS_LOG_COMPONENT_DEFINE ("AnimationInterface")static ns3::LogComponent g_log = ns3::LogComponent ("AnimationInterface"
, "../src/netanim/model/animation-interface.cc")
;
57
58// Globals
59
60static bool initialized = false;
61
62
63// Public methods
64
65AnimationInterface::AnimationInterface (const std::string fn)
66 : m_f (0),
67 m_routingF (0),
68 m_mobilityPollInterval (Seconds (0.25)),
69 m_outputFileName (fn),
70 gAnimUid (0),
71 m_writeCallback (0),
72 m_started (false),
73 m_enablePacketMetadata (false),
74 m_startTime (Seconds (0)),
75 m_stopTime (Seconds (3600 * 1000)),
76 m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE100000),
77 m_originalFileName (fn),
78 m_routingStopTime (Seconds (0)),
79 m_routingFileName (""),
80 m_routingPollInterval (Seconds (5)),
81 m_trackPackets (true)
82{
83 initialized = true;
84 StartAnimation ();
85}
86
87AnimationInterface::~AnimationInterface ()
88{
89 StopAnimation ();
90}
91
92void
93AnimationInterface::SkipPacketTracing ()
94{
95 m_trackPackets = false;
96}
97
98void
99AnimationInterface::EnableWifiPhyCounters (Time startTime, Time stopTime, Time pollInterval)
100{
101 m_wifiPhyCountersStopTime = stopTime;
102 m_wifiPhyCountersPollInterval = pollInterval;
103 m_wifiPhyTxDropCounterId = AddNodeCounter ("WifiPhy TxDrop", AnimationInterface::DOUBLE_COUNTER);
104 m_wifiPhyRxDropCounterId = AddNodeCounter ("WifiPhy RxDrop", AnimationInterface::DOUBLE_COUNTER);
105 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
106 {
107 Ptr<Node> n = *i;
108 m_nodeWifiPhyTxDrop[n->GetId ()] = 0;
109 m_nodeWifiPhyRxDrop[n->GetId ()] = 0;
110 UpdateNodeCounter (m_wifiPhyTxDropCounterId, n->GetId (), 0);
111 UpdateNodeCounter (m_wifiPhyRxDropCounterId, n->GetId (), 0);
112 }
113 Simulator::Schedule (startTime, &AnimationInterface::TrackWifiPhyCounters, this);
114
115}
116
117void
118AnimationInterface::EnableWifiMacCounters (Time startTime, Time stopTime, Time pollInterval)
119{
120 m_wifiMacCountersStopTime = stopTime;
121 m_wifiMacCountersPollInterval = pollInterval;
122 m_wifiMacTxCounterId = AddNodeCounter ("WifiMac Tx", AnimationInterface::DOUBLE_COUNTER);
123 m_wifiMacTxDropCounterId = AddNodeCounter ("WifiMac TxDrop", AnimationInterface::DOUBLE_COUNTER);
124 m_wifiMacRxCounterId = AddNodeCounter ("WifiMac Rx", AnimationInterface::DOUBLE_COUNTER);
125 m_wifiMacRxDropCounterId = AddNodeCounter ("WifiMac RxDrop", AnimationInterface::DOUBLE_COUNTER);
126 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
127 {
128 Ptr<Node> n = *i;
129 m_nodeWifiMacTx[n->GetId ()] = 0;
130 m_nodeWifiMacTxDrop[n->GetId ()] = 0;
131 m_nodeWifiMacRx[n->GetId ()] = 0;
132 m_nodeWifiMacRxDrop[n->GetId ()] = 0;
133 UpdateNodeCounter (m_wifiMacTxCounterId, n->GetId (), 0);
134 UpdateNodeCounter (m_wifiMacTxDropCounterId, n->GetId (), 0);
135 UpdateNodeCounter (m_wifiMacRxCounterId, n->GetId (), 0);
136 UpdateNodeCounter (m_wifiMacRxDropCounterId, n->GetId (), 0);
137 }
138 Simulator::Schedule (startTime, &AnimationInterface::TrackWifiMacCounters, this);
139}
140
141void
142AnimationInterface::EnableQueueCounters (Time startTime, Time stopTime, Time pollInterval)
143{
144 m_queueCountersStopTime = stopTime;
145 m_queueCountersPollInterval = pollInterval;
146 m_queueEnqueueCounterId = AddNodeCounter ("Enqueue", AnimationInterface::DOUBLE_COUNTER);
147 m_queueDequeueCounterId = AddNodeCounter ("Dequeue", AnimationInterface::DOUBLE_COUNTER);
148 m_queueDropCounterId = AddNodeCounter ("Queue Drop", AnimationInterface::DOUBLE_COUNTER);
149 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
150 {
151 Ptr<Node> n = *i;
152 m_nodeQueueEnqueue[n->GetId ()] = 0;
153 m_nodeQueueDequeue[n->GetId ()] = 0;
154 m_nodeQueueDrop[n->GetId ()] = 0;
155 UpdateNodeCounter (m_queueEnqueueCounterId, n->GetId (), 0);
156 UpdateNodeCounter (m_queueDequeueCounterId, n->GetId (), 0);
157 UpdateNodeCounter (m_queueDropCounterId, n->GetId (), 0);
158 }
159 Simulator::Schedule (startTime, &AnimationInterface::TrackQueueCounters, this);
160}
161
162void
163AnimationInterface::EnableIpv4L3ProtocolCounters (Time startTime, Time stopTime, Time pollInterval)
164{
165 m_ipv4L3ProtocolCountersStopTime = stopTime;
166 m_ipv4L3ProtocolCountersPollInterval = pollInterval;
167 m_ipv4L3ProtocolTxCounterId = AddNodeCounter ("Ipv4 Tx", AnimationInterface::DOUBLE_COUNTER);
168 m_ipv4L3ProtocolRxCounterId = AddNodeCounter ("Ipv4 Rx", AnimationInterface::DOUBLE_COUNTER);
169 m_ipv4L3ProtocolDropCounterId = AddNodeCounter ("Ipv4 Drop", AnimationInterface::DOUBLE_COUNTER);
170 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
171 {
172 Ptr<Node> n = *i;
173 m_nodeIpv4Tx[n->GetId ()] = 0;
174 m_nodeIpv4Rx[n->GetId ()] = 0;
175 m_nodeIpv4Drop[n->GetId ()] = 0;
176 UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, n->GetId (), 0);
177 UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, n->GetId (), 0);
178 UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, n->GetId (), 0);
179 }
180 Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4L3ProtocolCounters, this);
181}
182
183AnimationInterface &
184AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, Time pollInterval)
185{
186 SetOutputFile (fileName, true);
187 m_routingStopTime = stopTime;
188 m_routingPollInterval = pollInterval;
189 WriteXmlAnim (true);
190 Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4Route, this);
191 return *this;
192}
193
194AnimationInterface &
195AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, NodeContainer nc, Time pollInterval)
196{
197 m_routingNc = nc;
198 return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
199}
200
201AnimationInterface &
202AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
203{
204 Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
205 m_ipv4RouteTrackElements.push_back (element);
206 return *this;
207}
208
209void
210AnimationInterface::SetStartTime (Time t)
211{
212 m_startTime = t;
213}
214
215void
216AnimationInterface::SetStopTime (Time t)
217{
218 m_stopTime = t;
219}
220
221void
222AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile)
223{
224 m_maxPktsPerFile = maxPacketsPerFile;
225}
226
227uint32_t
228AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType)
229{
230 m_nodeCounters.push_back (counterName);
231 uint32_t counterId = m_nodeCounters.size () - 1; // counter ID is zero-indexed
232 WriteXmlAddNodeCounter (counterId, counterName, counterType);
233 return counterId;
234}
235
236uint32_t
237AnimationInterface::AddResource (std::string resourcePath)
238{
239 m_resources.push_back (resourcePath);
240 uint32_t resourceId = m_resources.size () - 1; // resource ID is zero-indexed
241 WriteXmlAddResource (resourceId, resourcePath);
242 return resourceId;
243}
244
245void
246AnimationInterface::EnablePacketMetadata (bool enable)
247{
248 m_enablePacketMetadata = enable;
249 if (enable)
250 {
251 Packet::EnablePrinting ();
252 }
253}
254
255bool
256AnimationInterface::IsInitialized ()
257{
258 return initialized;
259}
260
261bool
262AnimationInterface::IsStarted ()
263{
264 return m_started;
265}
266
267void
268AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb)
269{
270 m_writeCallback = cb;
271}
272
273void
274AnimationInterface::ResetAnimWriteCallback ()
275{
276 m_writeCallback = 0;
277}
278
279void
280AnimationInterface::SetMobilityPollInterval (Time t)
281{
282 m_mobilityPollInterval = t;
283}
284
285
286void
287AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
288{
289 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 289 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
290 Ptr<ConstantPositionMobilityModel> loc = n->GetObject<ConstantPositionMobilityModel> ();
291 if (loc == 0)
292 {
293 loc = CreateObject<ConstantPositionMobilityModel> ();
294 n->AggregateObject (loc);
295 }
296 Vector hubVec (x, y, z);
297 loc->SetPosition (hubVec);
298 NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Node:" <<
n->GetId () << " Position set to:(" << x <<
"," << y << "," << z << ")" <<
std::endl; } } while (false)
;
299
300}
301
302void
303AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
304{
305 NS_LOG_INFO ("Setting node image for Node Id:" << nodeId)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Setting node image for Node Id:"
<< nodeId << std::endl; } } while (false)
;
306 if (resourceId > (m_resources.size ()-1))
307 {
308 NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?")do { std::cerr << "msg=\"" << "Resource Id:" <<
resourceId << " not found. Did you use AddResource?" <<
"\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 308 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } while (false)
;
309 }
310 WriteXmlUpdateNodeImage (nodeId, resourceId);
311}
312
313void
314AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter)
315{
316 if (nodeCounterId > (m_nodeCounters.size () - 1))
317 {
318 NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?")do { std::cerr << "msg=\"" << "NodeCounter Id:" <<
nodeCounterId << " not found. Did you use AddNodeCounter?"
<< "\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 318 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } while (false)
;
319 }
320 WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter);
321}
322
323void
324AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
325{
326 if ((opacity < 0) || (opacity > 1))
327 {
328 NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0")do { std::cerr << "msg=\"" << "Opacity must be between 0.0 and 1.0"
<< "\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 328 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } while (false)
;
329 }
330 WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
331}
332
333void
334AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height)
335{
336 AnimationInterface::NodeSize s = { width, height };
337 m_nodeSizes[nodeId] = s;
338 WriteXmlUpdateNodeSize (nodeId, s.width, s.height);
339}
340
341void
342AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
343{
344 UpdateNodeColor (n->GetId (), r, g, b);
345}
346
347void
348AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
349{
350 NS_ASSERT (NodeList::GetNode (nodeId))do { if (!(NodeList::GetNode (nodeId))) { std::cerr << "assert failed. cond=\""
<< "NodeList::GetNode (nodeId)" << "\", "; do { std
::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 350 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
351 NS_LOG_INFO ("Setting node color for Node Id:" << nodeId)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Setting node color for Node Id:"
<< nodeId << std::endl; } } while (false)
;
352 Rgb rgb = {r, g, b};
353 m_nodeColors[nodeId] = rgb;
354 WriteXmlUpdateNodeColor (nodeId, r, g, b);
355}
356
357void
358AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
359 std::string linkDescription)
360{
361 WriteXmlUpdateLink (fromNode, toNode, linkDescription);
362}
363
364void
365AnimationInterface::UpdateLinkDescription (Ptr <Node> fromNode, Ptr <Node> toNode,
366 std::string linkDescription)
367{
368 NS_ASSERT (fromNode)do { if (!(fromNode)) { std::cerr << "assert failed. cond=\""
<< "fromNode" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 368 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
369 NS_ASSERT (toNode)do { if (!(toNode)) { std::cerr << "assert failed. cond=\""
<< "toNode" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 369 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
370 WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription);
371}
372
373void
374AnimationInterface::UpdateNodeDescription (Ptr <Node> n, std::string descr)
375{
376 UpdateNodeDescription (n->GetId (), descr);
377}
378
379void
380AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
381{
382 NS_ASSERT (NodeList::GetNode (nodeId))do { if (!(NodeList::GetNode (nodeId))) { std::cerr << "assert failed. cond=\""
<< "NodeList::GetNode (nodeId)" << "\", "; do { std
::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 382 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
383 m_nodeDescriptions[nodeId] = descr;
384 WriteXmlUpdateNodeDescription (nodeId);
385}
386
387// Private methods
388
389
390double
391AnimationInterface::GetNodeEnergyFraction (Ptr <const Node> node) const
392{
393 const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
394 NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ())do { if (!(fractionIter != m_nodeEnergyFraction.end ())) { std
::cerr << "assert failed. cond=\"" << "fractionIter != m_nodeEnergyFraction.end ()"
<< "\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 394 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
395 return fractionIter->second;
396}
397
398void
399AnimationInterface::MobilityCourseChangeTrace (Ptr <const MobilityModel> mobility)
400{
401 CHECK_STARTED_INTIMEWINDOW{if (!m_started || !IsInTimeWindow ()) return;};
402 Ptr <Node> n = mobility->GetObject <Node> ();
403 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 403 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
404 Vector v ;
405 if (!mobility)
406 {
407 v = GetPosition (n);
408 }
409 else
410 {
411 v = mobility->GetPosition ();
412 }
413 UpdatePosition (n, v);
414 WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y);
415}
416
417bool
418AnimationInterface::NodeHasMoved (Ptr <Node> n, Vector newLocation)
419{
420 Vector oldLocation = GetPosition (n);
421 bool moved = true;
422 if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
423 (ceil (oldLocation.y) == ceil (newLocation.y)))
424 {
425 moved = false;
426 }
427 else
428 {
429 moved = true;
430 }
431 return moved;
432}
433
434void
435AnimationInterface::MobilityAutoCheck ()
436{
437 CHECK_STARTED_INTIMEWINDOW{if (!m_started || !IsInTimeWindow ()) return;};
438 std::vector <Ptr <Node> > MovedNodes = GetMovedNodes ();
439 for (uint32_t i = 0; i < MovedNodes.size (); i++)
440 {
441 Ptr <Node> n = MovedNodes [i];
442 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 442 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
443 Vector v = GetPosition (n);
444 WriteXmlUpdateNodePosition (n->GetId () , v.x, v.y);
445 }
446 if (!Simulator::IsFinished ())
447 {
448 PurgePendingPackets (AnimationInterface::WIFI);
449 PurgePendingPackets (AnimationInterface::WIMAX);
450 PurgePendingPackets (AnimationInterface::LTE);
451 PurgePendingPackets (AnimationInterface::CSMA);
452 Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this);
453 }
454}
455
456std::vector <Ptr <Node> >
457AnimationInterface::GetMovedNodes ()
458{
459 std::vector < Ptr <Node> > movedNodes;
460 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
461 {
462 Ptr<Node> n = *i;
463 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 463 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
464 Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
465 Vector newLocation;
466 if (!mobility)
467 {
468 newLocation = GetPosition (n);
469 }
470 else
471 {
472 newLocation = mobility->GetPosition ();
473 }
474 if (!NodeHasMoved (n, newLocation))
475 {
476 continue; //Location has not changed
477 }
478 else
479 {
480 UpdatePosition (n, newLocation);
481 movedNodes.push_back (n);
482 }
483 }
484 return movedNodes;
485}
486
487int
488AnimationInterface::WriteN (const std::string& st, FILE * f)
489{
490 if (!f)
491 {
492 return 0;
493 }
494 if (m_writeCallback)
495 {
496 m_writeCallback (st.c_str ());
497 }
498 return WriteN (st.c_str (), st.length (), f);
499}
500
501int
502AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
503{
504 if (!f)
505 {
506 return 0;
507 }
508 // Write count bytes to h from data
509 uint32_t nLeft = count;
510 const char* p = data;
511 uint32_t written = 0;
512 while (nLeft)
513 {
514 int n = std::fwrite (p, 1, nLeft, f);
515 if (n <= 0)
516 {
517 return written;
518 }
519 written += n;
520 nLeft -= n;
521 p += n;
522 }
523 return written;
524}
525
526void
527AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
528{
529 NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Writing Route Path From :"
<< nodeId << " To: " << destination.c_str (
) << std::endl; } } while (false)
;
530 WriteXmlRp (nodeId, destination, rpElements);
531 /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
532 i != rpElements.end ();
533 ++i)
534 {
535 Ipv4RoutePathElement rpElement = *i;
536 NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
537 WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
538
539 }
540 */
541}
542
543void
544AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
545{
546 WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType);
547}
548
549const std::vector<std::string>
550AnimationInterface::GetElementsFromContext (const std::string& context) const
551{
552 std::vector <std::string> elements;
553 size_t pos1=0, pos2;
554 while (pos1 != context.npos)
555 {
556 pos1 = context.find ("/",pos1);
557 pos2 = context.find ("/",pos1+1);
558 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
559 pos1 = pos2;
560 pos2 = context.npos;
Value stored to 'pos2' is never read
561 }
562 return elements;
563}
564
565Ptr <Node>
566AnimationInterface::GetNodeFromContext (const std::string& context) const
567{
568 // Use "NodeList/*/ as reference
569 // where element [1] is the Node Id
570
571 std::vector <std::string> elements = GetElementsFromContext (context);
572 Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
573 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 573 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
574
575 return n;
576}
577
578Ptr <NetDevice>
579AnimationInterface::GetNetDeviceFromContext (std::string context)
580{
581 // Use "NodeList/*/DeviceList/*/ as reference
582 // where element [1] is the Node Id
583 // element [2] is the NetDevice Id
584
585 std::vector <std::string> elements = GetElementsFromContext (context);
586 Ptr <Node> n = GetNodeFromContext (context);
587
588 return n->GetDevice (atoi (elements.at (3).c_str ()));
589}
590
591uint64_t
592AnimationInterface::GetAnimUidFromPacket (Ptr <const Packet> p)
593{
594 AnimByteTag tag;
595 TypeId tid = tag.GetInstanceTypeId ();
596 ByteTagIterator i = p->GetByteTagIterator ();
597 bool found = false;
598 while (i.HasNext ())
599 {
600 ByteTagIterator::Item item = i.Next ();
601 if (tid == item.GetTypeId ())
602 {
603 item.GetTag (tag);
604 found = true;
605 }
606 }
607 if (found)
608 {
609 return tag.Get ();
610 }
611 else
612 {
613 return 0;
614 }
615}
616
617void
618AnimationInterface::AddByteTag (uint64_t animUid, Ptr<const Packet> p)
619{
620 AnimByteTag tag;
621 tag.Set (animUid);
622 p->AddByteTag (tag);
623}
624
625void
626AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
627{
628 CHECK_STARTED_INTIMEWINDOW{if (!m_started || !IsInTimeWindow ()) return;};
629 const Ptr <const Node> node = GetNodeFromContext (context);
630 const uint32_t nodeId = node->GetId ();
631
632 NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Remaining energy on one of sources on node "
<< nodeId << ": " << currentEnergy <<
std::endl; } } while (false)
;
633
634 const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
635
636 NS_ASSERT (energySource)do { if (!(energySource)) { std::cerr << "assert failed. cond=\""
<< "energySource" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 636 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
637 // Don't call GetEnergyFraction () because of recursion
638 const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
639
640 NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Total energy fraction on node "
<< nodeId << ": " << energyFraction <<
std::endl; } } while (false)
;
641
642 m_nodeEnergyFraction[nodeId] = energyFraction;
643 UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction);
644}
645
646void
647AnimationInterface::WifiPhyTxDropTrace (std::string context, Ptr<const Packet> p)
648{
649 const Ptr <const Node> node = GetNodeFromContext (context);
650 ++m_nodeWifiPhyTxDrop[node->GetId ()];
651}
652
653void
654AnimationInterface::WifiPhyRxDropTrace (std::string context, Ptr<const Packet> p)
655{
656 const Ptr <const Node> node = GetNodeFromContext (context);
657 ++m_nodeWifiPhyRxDrop[node->GetId ()];
658}
659
660void
661AnimationInterface::WifiMacTxTrace (std::string context, Ptr<const Packet> p)
662{
663 const Ptr <const Node> node = GetNodeFromContext (context);
664 ++m_nodeWifiMacTx[node->GetId ()];
665}
666
667void
668AnimationInterface::WifiMacTxDropTrace (std::string context, Ptr<const Packet> p)
669{
670 const Ptr <const Node> node = GetNodeFromContext (context);
671 ++m_nodeWifiMacTxDrop[node->GetId ()];
672}
673
674void
675AnimationInterface::WifiMacRxTrace (std::string context, Ptr<const Packet> p)
676{
677 const Ptr <const Node> node = GetNodeFromContext (context);
678 ++m_nodeWifiMacRx[node->GetId ()];
679}
680
681void
682AnimationInterface::WifiMacRxDropTrace (std::string context, Ptr<const Packet> p)
683{
684 const Ptr <const Node> node = GetNodeFromContext (context);
685 ++m_nodeWifiMacRxDrop[node->GetId ()];
686}
687
688void
689AnimationInterface::Ipv4TxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
690{
691 const Ptr <const Node> node = GetNodeFromContext (context);
692 ++m_nodeIpv4Tx[node->GetId ()];
693}
694
695void
696AnimationInterface::Ipv4RxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
697{
698 const Ptr <const Node> node = GetNodeFromContext (context);
699 ++m_nodeIpv4Rx[node->GetId ()];
700}
701
702void
703AnimationInterface::Ipv4DropTrace (std::string context,
704 const Ipv4Header & ipv4Header,
705 Ptr<const Packet> p,
706 Ipv4L3Protocol::DropReason dropReason,
707 Ptr<Ipv4> ipv4,
708 uint32_t)
709{
710 const Ptr <const Node> node = GetNodeFromContext (context);
711 ++m_nodeIpv4Drop[node->GetId ()];
712}
713
714void
715AnimationInterface::EnqueueTrace (std::string context,
716 Ptr<const Packet> p)
717{
718 const Ptr <const Node> node = GetNodeFromContext (context);
719 ++m_nodeQueueEnqueue[node->GetId ()];
720}
721
722void
723AnimationInterface::DequeueTrace (std::string context,
724 Ptr<const Packet> p)
725{
726 const Ptr <const Node> node = GetNodeFromContext (context);
727 ++m_nodeQueueDequeue[node->GetId ()];
728}
729
730void
731AnimationInterface::QueueDropTrace (std::string context,
732 Ptr<const Packet> p)
733{
734 const Ptr <const Node> node = GetNodeFromContext (context);
735 ++m_nodeQueueDrop[node->GetId ()];
736}
737
738void
739AnimationInterface::DevTxTrace (std::string context,
740 Ptr<const Packet> p,
741 Ptr<NetDevice> tx,
742 Ptr<NetDevice> rx,
743 Time txTime,
744 Time rxTime)
745{
746 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
747 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
748 NS_ASSERT (tx)do { if (!(tx)) { std::cerr << "assert failed. cond=\""
<< "tx" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 748 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
749 NS_ASSERT (rx)do { if (!(rx)) { std::cerr << "assert failed. cond=\""
<< "rx" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 749 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
750 Time now = Simulator::Now ();
751 double fbTx = now.GetSeconds ();
752 double lbTx = (now + txTime).GetSeconds ();
753 double fbRx = (now + rxTime - txTime).GetSeconds ();
754 double lbRx = (now + rxTime).GetSeconds ();
755 CheckMaxPktsPerTraceFile ();
756 WriteXmlP ("p",
757 tx->GetNode ()->GetId (),
758 fbTx,
759 lbTx,
760 rx->GetNode ()->GetId (),
761 fbRx,
762 lbRx,
763 m_enablePacketMetadata? GetPacketMetadata (p):"");
764}
765
766void
767AnimationInterface::GenericWirelessTxTrace (std::string context, Ptr<const Packet> p, ProtocolType protocolType)
768{
769 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
770 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
771 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
772 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 772 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
773 UpdatePosition (ndev);
774
775 ++gAnimUid;
776 NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessTxTrace for packet:" << gAnimUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << ProtocolTypeToString
(protocolType).c_str () << " GenericWirelessTxTrace for packet:"
<< gAnimUid << std::endl; } } while (false)
;
777 AddByteTag (gAnimUid, p);
778 AnimPacketInfo pktInfo (ndev, Simulator::Now ());
779 AddPendingPacket (protocolType, gAnimUid, pktInfo);
780
781 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
782 if (netDevice)
783 {
784 Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
785 std::ostringstream oss;
786 oss << nodeAddr;
787 Ptr <Node> n = netDevice->GetNode ();
788 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 788 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
789 m_macToNodeIdMap[oss.str ()] = n->GetId ();
790 NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()])do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Added Mac" <<
oss.str () << " node:" <<m_macToNodeIdMap[oss.str
()] << std::endl; } } while (false)
;
791 }
792 AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
793 OutputWirelessPacketTxInfo (p, pendingPackets->at (gAnimUid), gAnimUid);
794}
795
796void
797AnimationInterface::GenericWirelessRxTrace (std::string context, Ptr<const Packet> p, ProtocolType protocolType)
798{
799 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
800 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
801 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
802 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 802 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
803 UpdatePosition (ndev);
804 uint64_t animUid = GetAnimUidFromPacket (p);
805 NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " for packet:" << animUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << ProtocolTypeToString
(protocolType).c_str () << " for packet:" << animUid
<< std::endl; } } while (false)
;
806 if (!IsPacketPending (animUid, protocolType))
807 {
808 NS_LOG_WARN (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << ProtocolTypeToString
(protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid"
<< std::endl; } } while (false)
;
809 return;
810 }
811 AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
812 pendingPackets->at (animUid).ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
813 OutputWirelessPacketRxInfo (p, pendingPackets->at (animUid), animUid);
814}
815
816void
817AnimationInterface::UanPhyGenTxTrace (std::string context, Ptr<const Packet> p)
818{
819 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
820 return GenericWirelessTxTrace (context, p, AnimationInterface::UAN);
821}
822
823void
824AnimationInterface::UanPhyGenRxTrace (std::string context, Ptr<const Packet> p)
825{
826 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
827 return GenericWirelessRxTrace (context, p, AnimationInterface::UAN);
828}
829
830void
831AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr<const Packet> p)
832{
833 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
834 return GenericWirelessTxTrace (context, p, AnimationInterface::WIFI);
835}
836
837void
838AnimationInterface::WifiPhyRxBeginTrace (std::string context, Ptr<const Packet> p)
839{
840 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
841 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
842 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
843 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 843 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
844 UpdatePosition (ndev);
845 uint64_t animUid = GetAnimUidFromPacket (p);
846 NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Wifi RxBeginTrace for packet:"
<< animUid << std::endl; } } while (false)
;
847 if (!IsPacketPending (animUid, AnimationInterface::WIFI))
848 {
849 NS_ASSERT (0)do { if (!(0)) { std::cerr << "assert failed. cond=\"" <<
"0" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 849 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
850 NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "WifiPhyRxBeginTrace: unknown Uid"
<< std::endl; } } while (false)
;
851 std::ostringstream oss;
852 WifiMacHeader hdr;
853 if (!p->PeekHeader (hdr))
854 {
855 NS_LOG_WARN ("WifiMacHeader not present")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "WifiMacHeader not present"
<< std::endl; } } while (false)
;
856 return;
857 }
858 oss << hdr.GetAddr2 ();
859 if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
860 {
861 NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Transmitter Mac address "
<< oss.str () << " never seen before. Skipping" <<
std::endl; } } while (false)
;
862 return;
863 }
864 Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
865 UpdatePosition (txNode);
866 AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
867 AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
868 NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet"
<< std::endl; } } while (false)
;
869 }
870 /// \todo NS_ASSERT (WifiPacketIsPending (animUid) == true);
871 m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
872 OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid);
873}
874
875void
876AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
877{
878 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
879 return GenericWirelessTxTrace (context, p, AnimationInterface::WIMAX);
880}
881
882
883void
884AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
885{
886 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
887 return GenericWirelessRxTrace (context, p, AnimationInterface::WIMAX);
888}
889
890void
891AnimationInterface::LteTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
892{
893 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
894 return GenericWirelessTxTrace (context, p, AnimationInterface::LTE);
895}
896
897void
898AnimationInterface::LteRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
899{
900 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
901 return GenericWirelessRxTrace (context, p, AnimationInterface::LTE);
902}
903
904void
905AnimationInterface::LteSpectrumPhyTxStart (std::string context, Ptr<const PacketBurst> pb)
906{
907 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
908 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
909 if (!pb)
910 {
911 NS_LOG_WARN ("pb == 0. Not yet supported")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "pb == 0. Not yet supported"
<< std::endl; } } while (false)
;
912 return;
913 }
914 context = "/" + context;
915 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
916 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 916 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
917 UpdatePosition (ndev);
918
919 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
920 for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
921 i != pbList.end ();
922 ++i)
923 {
924 Ptr <Packet> p = *i;
925 ++gAnimUid;
926 NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "LteSpectrumPhyTxTrace for packet:"
<< gAnimUid << std::endl; } } while (false)
;
927 AnimPacketInfo pktInfo (ndev, Simulator::Now ());
928 AddByteTag (gAnimUid, p);
929 AddPendingPacket (AnimationInterface::LTE, gAnimUid, pktInfo);
930 OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
931 }
932}
933
934void
935AnimationInterface::LteSpectrumPhyRxStart (std::string context, Ptr<const PacketBurst> pb)
936{
937 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
938 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
939 if (!pb)
940 {
941 NS_LOG_WARN ("pb == 0. Not yet supported")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "pb == 0. Not yet supported"
<< std::endl; } } while (false)
;
942 return;
943 }
944 context = "/" + context;
945 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
946 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 946 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
947 UpdatePosition (ndev);
948
949 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
950 for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
951 i != pbList.end ();
952 ++i)
953 {
954 Ptr <Packet> p = *i;
955 uint64_t animUid = GetAnimUidFromPacket (p);
956 NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "LteSpectrumPhyRxTrace for packet:"
<< gAnimUid << std::endl; } } while (false)
;
957 if (!IsPacketPending (animUid, AnimationInterface::LTE))
958 {
959 NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "LteSpectrumPhyRxTrace: unknown Uid"
<< std::endl; } } while (false)
;
960 return;
961 }
962 AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
963 pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
964 OutputWirelessPacketRxInfo (p, pktInfo, animUid);
965 }
966}
967
968void
969AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr<const Packet> p)
970{
971 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
972 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
973 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
974 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 974 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
975 UpdatePosition (ndev);
976 ++gAnimUid;
977 NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "CsmaPhyTxBeginTrace for packet:"
<< gAnimUid << std::endl; } } while (false)
;
978 AddByteTag (gAnimUid, p);
979 UpdatePosition (ndev);
980 AnimPacketInfo pktInfo (ndev, Simulator::Now ());
981 AddPendingPacket (AnimationInterface::CSMA, gAnimUid, pktInfo);
982
983
984}
985
986void
987AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr<const Packet> p)
988{
989 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
990 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
991 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
992 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 992 << std::endl; ::ns3::FatalImpl::
FlushStreams (); if (true) std::terminate (); } while (false)
; } } while (false)
;
993 UpdatePosition (ndev);
994 uint64_t animUid = GetAnimUidFromPacket (p);
995 NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "CsmaPhyTxEndTrace for packet:"
<< animUid << std::endl; } } while (false)
;
996 if (!IsPacketPending (animUid, AnimationInterface::CSMA))
997 {
998 NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "CsmaPhyTxEndTrace: unknown Uid"
<< std::endl; } } while (false)
;
999 NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid")do { std::cerr << "msg=\"" << "CsmaPhyTxEndTrace: unknown Uid"
<< "\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 999 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } while (false)
;
1000 AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1001 AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1002 NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Unknown Uid, but adding Csma Packet anyway"
<< std::endl; } } while (false)
;
1003 }
1004 /// \todo NS_ASSERT (IsPacketPending (AnimUid) == true);
1005 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1006 pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1007}
1008
1009void
1010AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr<const Packet> p)
1011{
1012 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
1013 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
1014 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1015 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 1015 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
1016 UpdatePosition (ndev);
1017 uint64_t animUid = GetAnimUidFromPacket (p);
1018 if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1019 {
1020 NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "CsmaPhyRxEndTrace: unknown Uid"
<< std::endl; } } while (false)
;
1021 return;
1022 }
1023 /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1024 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1025 pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1026 NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "CsmaPhyRxEndTrace for packet:"
<< animUid << std::endl; } } while (false)
;
1027 NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "CsmaPhyRxEndTrace for packet:"
<< animUid << " complete" << std::endl; } }
while (false)
;
1028 OutputCsmaPacket (p, pktInfo);
1029}
1030
1031void
1032AnimationInterface::CsmaMacRxTrace (std::string context,
1033 Ptr<const Packet> p)
1034{
1035 NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; std::clog << g_log.Name () << ":" <<
__FUNCTION__ << "("; ns3::ParameterLogger (std::clog) <<
this; std::clog << ")" << std::endl; } } while (
false)
;
1036 CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS{if (!m_started || !IsInTimeWindow () || !m_trackPackets) return
;}
;
1037 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1038 NS_ASSERT (ndev)do { if (!(ndev)) { std::cerr << "assert failed. cond=\""
<< "ndev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 1038 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
1039 uint64_t animUid = GetAnimUidFromPacket (p);
1040 if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1041 {
1042 NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "CsmaMacRxTrace: unknown Uid"
<< std::endl; } } while (false)
;
1043 return;
1044 }
1045 /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1046 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1047 NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "MacRxTrace for packet:"
<< animUid << " complete" << std::endl; } }
while (false)
;
1048 OutputCsmaPacket (p, pktInfo);
1049}
1050
1051void
1052AnimationInterface::OutputWirelessPacketTxInfo (Ptr<const Packet> p, AnimPacketInfo &pktInfo, uint64_t animUid)
1053{
1054 CheckMaxPktsPerTraceFile ();
1055 uint32_t nodeId = 0;
1056 if (pktInfo.m_txnd)
1057 {
1058 nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1059 }
1060 else
1061 {
1062 nodeId = pktInfo.m_txNodeId;
1063 }
1064 WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1065}
1066
1067void
1068AnimationInterface::OutputWirelessPacketRxInfo (Ptr<const Packet> p, AnimPacketInfo & pktInfo, uint64_t animUid)
1069{
1070 CheckMaxPktsPerTraceFile ();
1071 uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1072 WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1073}
1074
1075void
1076AnimationInterface::OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo &pktInfo)
1077{
1078 CheckMaxPktsPerTraceFile ();
1079 NS_ASSERT (pktInfo.m_txnd)do { if (!(pktInfo.m_txnd)) { std::cerr << "assert failed. cond=\""
<< "pktInfo.m_txnd" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1079 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } } while (false)
;
1080 uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1081 uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1082
1083 WriteXmlP ("p",
1084 nodeId,
1085 pktInfo.m_fbTx,
1086 pktInfo.m_lbTx,
1087 rxId,
1088 pktInfo.m_fbRx,
1089 pktInfo.m_lbRx,
1090 m_enablePacketMetadata? GetPacketMetadata (p):"");
1091}
1092
1093void
1094AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1095{
1096 AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1097 NS_ASSERT (pendingPackets)do { if (!(pendingPackets)) { std::cerr << "assert failed. cond=\""
<< "pendingPackets" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1097 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } } while (false)
;
1098 pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1099}
1100
1101bool
1102AnimationInterface::IsPacketPending (uint64_t animUid, AnimationInterface::ProtocolType protocolType)
1103{
1104 AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1105 NS_ASSERT (pendingPackets)do { if (!(pendingPackets)) { std::cerr << "assert failed. cond=\""
<< "pendingPackets" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1105 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } } while (false)
;
1106 return (pendingPackets->find (animUid) != pendingPackets->end ());
1107}
1108
1109void
1110AnimationInterface::PurgePendingPackets (AnimationInterface::ProtocolType protocolType)
1111{
1112 AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1113 NS_ASSERT (pendingPackets)do { if (!(pendingPackets)) { std::cerr << "assert failed. cond=\""
<< "pendingPackets" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1113 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } } while (false)
;
1114 if (pendingPackets->empty ())
1115 {
1116 return;
1117 }
1118 std::vector <uint64_t> purgeList;
1119 for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1120 i != pendingPackets->end ();
1121 ++i)
1122 {
1123
1124 AnimPacketInfo pktInfo = i->second;
1125 double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1126 if (delta > PURGE_INTERVAL5)
1127 {
1128 purgeList.push_back (i->first);
1129 }
1130 }
1131 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1132 i != purgeList.end ();
1133 ++i)
1134 {
1135 pendingPackets->erase (*i);
1136 }
1137}
1138
1139AnimationInterface::AnimUidPacketInfoMap *
1140AnimationInterface::ProtocolTypeToPendingPackets (AnimationInterface::ProtocolType protocolType)
1141{
1142 AnimUidPacketInfoMap * pendingPackets = 0;
1143 switch (protocolType)
1144 {
1145 case AnimationInterface::WIFI:
1146 {
1147 pendingPackets = &m_pendingWifiPackets;
1148 break;
1149 }
1150 case AnimationInterface::UAN:
1151 {
1152 pendingPackets = &m_pendingUanPackets;
1153 break;
1154 }
1155 case AnimationInterface::CSMA:
1156 {
1157 pendingPackets = &m_pendingCsmaPackets;
1158 break;
1159 }
1160 case AnimationInterface::WIMAX:
1161 {
1162 pendingPackets = &m_pendingWimaxPackets;
1163 break;
1164 }
1165 case AnimationInterface::LTE:
1166 {
1167 pendingPackets = &m_pendingLtePackets;
1168 break;
1169 }
1170 }
1171 return pendingPackets;
1172
1173}
1174
1175std::string
1176AnimationInterface::ProtocolTypeToString (AnimationInterface::ProtocolType protocolType)
1177{
1178 std::string result = "Unknown";
1179 switch (protocolType)
1180 {
1181 case AnimationInterface::WIFI:
1182 {
1183 result = "WIFI";
1184 break;
1185 }
1186 case AnimationInterface::UAN:
1187 {
1188 result = "UAN";
1189 break;
1190 }
1191 case AnimationInterface::CSMA:
1192 {
1193 result = "CSMA";
1194 break;
1195 }
1196 case AnimationInterface::WIMAX:
1197 {
1198 result = "WIMAX";
1199 break;
1200 }
1201 case AnimationInterface::LTE:
1202 {
1203 result = "LTE";
1204 break;
1205 }
1206 }
1207 return result;
1208}
1209
1210// Counters
1211
1212std::string
1213AnimationInterface::CounterTypeToString (CounterType counterType)
1214{
1215 std::string typeString = "unknown";
1216 switch (counterType)
1217 {
1218 case UINT32_COUNTER:
1219 {
1220 typeString = "UINT32";
1221 break;
1222 }
1223 case DOUBLE_COUNTER:
1224 {
1225 typeString = "DOUBLE";
1226 break;
1227 }
1228 }
1229 return typeString;
1230}
1231
1232// General
1233
1234std::string
1235AnimationInterface::GetPacketMetadata (Ptr<const Packet> p)
1236{
1237 std::ostringstream oss;
1238 p->Print (oss);
1239 return oss.str ();
1240}
1241
1242uint64_t
1243AnimationInterface::GetTracePktCount ()
1244{
1245 return m_currentPktCount;
1246}
1247
1248void
1249AnimationInterface::StopAnimation (bool onlyAnimation)
1250{
1251 m_started = false;
1252 NS_LOG_INFO ("Stopping Animation")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Stopping Animation"
<< std::endl; } } while (false)
;
1253 ResetAnimWriteCallback ();
1254 if (m_f)
1255 {
1256 // Terminate the anim element
1257 WriteXmlClose ("anim");
1258 std::fclose (m_f);
1259 m_f = 0;
1260 }
1261 if (onlyAnimation)
1262 {
1263 return;
1264 }
1265 if (m_routingF)
1266 {
1267 WriteXmlClose ("anim", true);
1268 std::fclose (m_routingF);
1269 m_routingF = 0;
1270 }
1271}
1272
1273void
1274AnimationInterface::StartAnimation (bool restart)
1275{
1276 m_currentPktCount = 0;
1277 m_started = true;
1278 SetOutputFile (m_outputFileName);
1279 WriteXmlAnim ();
1280 WriteNodes ();
1281 WriteNodeColors ();
1282 WriteLinkProperties ();
1283 WriteNodeSizes ();
1284 WriteNodeEnergies ();
1285 if (!restart)
1286 {
1287 Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this);
1288 ConnectCallbacks ();
1289 }
1290}
1291
1292void
1293AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1294{
1295 m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1296}
1297
1298
1299// Callbacks
1300void
1301AnimationInterface::ConnectLteEnb (Ptr <Node> n, Ptr <LteEnbNetDevice> nd, uint32_t devIndex)
1302{
1303
1304 Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1305 Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1306 Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1307 std::ostringstream oss;
1308 //NodeList/*/DeviceList/*/
1309 oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1310 if (dlPhy)
1311 {
1312 dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1313 dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1314 }
1315 if (ulPhy)
1316 {
1317 ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1318 ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1319 }
1320}
1321
1322
1323
1324void
1325AnimationInterface::ConnectLteUe (Ptr <Node> n, Ptr <LteUeNetDevice> nd, uint32_t devIndex)
1326{
1327
1328 Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1329 Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1330 Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1331 std::ostringstream oss;
1332 //NodeList/*/DeviceList/*/
1333 oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1334 if (dlPhy)
1335 {
1336 dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1337 dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1338 }
1339 if (ulPhy)
1340 {
1341 ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1342 ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1343 }
1344}
1345
1346void
1347AnimationInterface::ConnectLte ()
1348{
1349
1350 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1351 {
1352 Ptr<Node> n = *i;
1353 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 1353 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
1354 uint32_t nDevices = n->GetNDevices ();
1355 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1356 {
1357 Ptr <NetDevice> nd = n->GetDevice (devIndex);
1358 if (!nd)
1359 continue;
1360 Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1361 if (lteUeNetDevice)
1362 {
1363 ConnectLteUe (n, lteUeNetDevice, devIndex);
1364 continue;
1365 }
1366 Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1367 if (lteEnbNetDevice)
1368 ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1369 }
1370
1371 }
1372}
1373
1374void
1375AnimationInterface::ConnectCallbacks ()
1376{
1377 // Connect the callbacks
1378 Config::Connect ("/ChannelList/*/TxRxPointToPoint",
1379 MakeCallback (&AnimationInterface::DevTxTrace, this));
1380 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
1381 MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace, this));
1382 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1383 MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this));
1384 Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1385 MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this));
1386 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1387 MakeCallback (&AnimationInterface::WimaxTxTrace, this));
1388 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1389 MakeCallback (&AnimationInterface::WimaxRxTrace, this));
1390 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1391 MakeCallback (&AnimationInterface::LteTxTrace, this));
1392 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1393 MakeCallback (&AnimationInterface::LteRxTrace, this));
1394 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1395 MakeCallback (&AnimationInterface::CsmaPhyTxBeginTrace, this));
1396 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1397 MakeCallback (&AnimationInterface::CsmaPhyTxEndTrace, this));
1398 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1399 MakeCallback (&AnimationInterface::CsmaPhyRxEndTrace, this));
1400 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1401 MakeCallback (&AnimationInterface::CsmaMacRxTrace, this));
1402 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1403 MakeCallback (&AnimationInterface::UanPhyGenTxTrace, this));
1404 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1405 MakeCallback (&AnimationInterface::UanPhyGenRxTrace, this));
1406 Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1407 MakeCallback (&AnimationInterface::RemainingEnergyTrace, this));
1408
1409 ConnectLte ();
1410
1411 Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1412 MakeCallback (&AnimationInterface::Ipv4TxTrace, this));
1413 Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1414 MakeCallback (&AnimationInterface::Ipv4RxTrace, this));
1415 Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1416 MakeCallback (&AnimationInterface::Ipv4DropTrace, this));
1417
1418 // Queue Enqueues
1419
1420 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1421 MakeCallback (&AnimationInterface::EnqueueTrace, this));
1422 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1423 MakeCallback (&AnimationInterface::EnqueueTrace, this));
1424 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1425 MakeCallback (&AnimationInterface::EnqueueTrace, this));
1426
1427 // Queue Dequeues
1428
1429 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1430 MakeCallback (&AnimationInterface::DequeueTrace, this));
1431 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1432 MakeCallback (&AnimationInterface::DequeueTrace, this));
1433 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1434 MakeCallback (&AnimationInterface::DequeueTrace, this));
1435
1436 // Queue Drops
1437
1438 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1439 MakeCallback (&AnimationInterface::QueueDropTrace, this));
1440 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1441 MakeCallback (&AnimationInterface::QueueDropTrace, this));
1442 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1443 MakeCallback (&AnimationInterface::QueueDropTrace, this));
1444
1445
1446 // Wifi Mac
1447 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1448 MakeCallback (&AnimationInterface::WifiMacTxTrace, this));
1449 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1450 MakeCallback (&AnimationInterface::WifiMacTxDropTrace, this));
1451 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1452 MakeCallback (&AnimationInterface::WifiMacRxTrace, this));
1453 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1454 MakeCallback (&AnimationInterface::WifiMacRxDropTrace, this));
1455
1456 // Wifi Phy
1457 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1458 MakeCallback (&AnimationInterface::WifiPhyTxDropTrace, this));
1459 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1460 MakeCallback (&AnimationInterface::WifiPhyRxDropTrace, this));
1461}
1462
1463Vector
1464AnimationInterface::UpdatePosition (Ptr <Node> n)
1465{
1466 Ptr<MobilityModel> loc = n->GetObject<MobilityModel> ();
1467 if (loc)
1468 {
1469 m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1470 }
1471 else
1472 {
1473 NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary")do { std::clog << "AnimationInterface WARNING:Node:" <<
n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"
<< std::endl; } while (false)
;
1474 m_nodeLocation[n->GetId ()] = Vector (0, 0, 0);
1475 }
1476 return m_nodeLocation[n->GetId ()];
1477}
1478
1479Vector
1480AnimationInterface::UpdatePosition (Ptr <Node> n, Vector v)
1481{
1482 m_nodeLocation[n->GetId ()] = v;
1483 return v;
1484}
1485
1486Vector
1487AnimationInterface::UpdatePosition (Ptr <NetDevice> ndev)
1488{
1489 Ptr <Node> n = ndev->GetNode ();
1490 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 1490 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
1491 return UpdatePosition (n);
1492}
1493
1494Vector
1495AnimationInterface::GetPosition (Ptr <Node> n)
1496{
1497 if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1498 {
1499 NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table")do { std::cerr << "msg=\"" << "Node:" <<n->
GetId () << " not found in Location table" << "\", "
; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1499 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1500 }
1501 return m_nodeLocation[n->GetId ()];
1502}
1503
1504
1505std::string
1506AnimationInterface::GetMacAddress (Ptr <NetDevice> nd)
1507{
1508 Address nodeAddr = nd->GetAddress ();
1509 std::ostringstream oss;
1510 oss << nodeAddr;
1511 return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1512}
1513
1514std::string
1515AnimationInterface::GetIpv4Address (Ptr <NetDevice> nd)
1516{
1517 Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1518 if (!ipv4)
1519 {
1520 NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Node: " <<
nd->GetNode ()->GetId () << " No ipv4 object found"
<< std::endl; } } while (false)
;
1521 return "0.0.0.0";
1522 }
1523 int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1524 if (ifIndex == -1)
1525 {
1526 NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Node :" <<
nd->GetNode ()->GetId () << " Could not find index of NetDevice"
<< std::endl; } } while (false)
;
1527 return "0.0.0.0";
1528 }
1529 Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1530 std::ostringstream oss;
1531 oss << addr.GetLocal ();
1532 return oss.str ();
1533}
1534
1535void
1536AnimationInterface::WriteLinkProperties ()
1537{
1538 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1539 {
1540 Ptr<Node> n = *i;
1541 UpdatePosition (n);
1542 uint32_t n1Id = n->GetId ();
1543 uint32_t nDev = n->GetNDevices (); // Number of devices
1544 for (uint32_t i = 0; i < nDev; ++i)
1545 {
1546 Ptr<NetDevice> dev = n->GetDevice (i);
1547 NS_ASSERT (dev)do { if (!(dev)) { std::cerr << "assert failed. cond=\""
<< "dev" << "\", "; do { std::cerr << "file="
<< "../src/netanim/model/animation-interface.cc" <<
", line=" << 1547 << std::endl; ::ns3::FatalImpl
::FlushStreams (); if (true) std::terminate (); } while (false
); } } while (false)
;
1548 Ptr<Channel> ch = dev->GetChannel ();
1549 if (!ch)
1550 {
1551 NS_LOG_DEBUG ("No channel can't be a p2p device")do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_DEBUG) << "] "; }; std::clog << "No channel can't be a p2p device"
<< std::endl; } } while (false)
;
1552 // Try to see if it is an LTE NetDevice, which does not return a channel
1553 if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1554 (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1555 (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1556 {
1557 WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
1558 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ());
1559 }
1560 continue;
1561 }
1562 std::string channelType = ch->GetInstanceTypeId ().GetName ();
1563 NS_LOG_DEBUG ("Got ChannelType" << channelType)do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_DEBUG) << "] "; }; std::clog << "Got ChannelType"
<< channelType << std::endl; } } while (false)
;
1564 if (channelType == std::string ("ns3::PointToPointChannel"))
1565 { // Since these are duplex links, we only need to dump
1566 // if srcid < dstid
1567 uint32_t nChDev = ch->GetNDevices ();
1568 for (uint32_t j = 0; j < nChDev; ++j)
1569 {
1570 Ptr<NetDevice> chDev = ch->GetDevice (j);
1571 uint32_t n2Id = chDev->GetNode ()->GetId ();
1572 if (n1Id < n2Id)
1573 {
1574 // ouptut the p2p link
1575 NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << ":" << GetMacAddress (dev) << "----" << GetIpv4Address (chDev) << ":" << GetMacAddress (chDev))do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Link:" <<
GetIpv4Address (dev) << ":" << GetMacAddress (dev
) << "----" << GetIpv4Address (chDev) << ":"
<< GetMacAddress (chDev) << std::endl; } } while
(false)
;
1576 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n1Id);
1577 AddToIpv4AddressNodeIdTable (GetIpv4Address (chDev), n2Id);
1578 P2pLinkNodeIdPair p2pPair;
1579 p2pPair.fromNode = n1Id;
1580 p2pPair.toNode = n2Id;
1581 LinkProperties lp = {GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), ""};
1582 m_linkProperties[p2pPair] = lp;
1583 WriteXmlLink (n1Id, 0, n2Id);
1584 }
1585 }
1586 }
1587 else
1588 {
1589 NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << " Channel Type:" << channelType << " Mac: " << GetMacAddress (dev))do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Link:" <<
GetIpv4Address (dev) << " Channel Type:" << channelType
<< " Mac: " << GetMacAddress (dev) << std::
endl; } } while (false)
;
1590 WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1591 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ());
1592 }
1593 }
1594 }
1595 m_linkProperties.clear ();
1596}
1597
1598void
1599AnimationInterface::WriteNodes ()
1600{
1601 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1602 {
1603 Ptr<Node> n = *i;
1604 NS_LOG_INFO ("Update Position for Node: " << n->GetId ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Update Position for Node: "
<< n->GetId () << std::endl; } } while (false
)
;
1605 Vector v = UpdatePosition (n);
1606 WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
1607 }
1608}
1609
1610void
1611AnimationInterface::WriteNodeColors ()
1612{
1613 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1614 {
1615 Ptr<Node> n = *i;
1616 Rgb rgb = {255, 0, 0};
1617 if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
1618 {
1619 m_nodeColors[n->GetId ()] = rgb;
1620 }
1621 UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
1622 }
1623}
1624
1625void
1626AnimationInterface::WriteNodeSizes ()
1627{
1628 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1629 {
1630 Ptr<Node> n = *i;
1631 NS_LOG_INFO ("Update Size for Node: " << n->GetId ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Update Size for Node: "
<< n->GetId () << std::endl; } } while (false
)
;
1632 AnimationInterface::NodeSize s = { 1, 1 };
1633 m_nodeSizes[n->GetId ()] = s;
1634 UpdateNodeSize (n->GetId (), s.width, s.height);
1635 }
1636}
1637
1638void
1639AnimationInterface::WriteNodeEnergies ()
1640{
1641 m_remainingEnergyCounterId = AddNodeCounter ("RemainingEnergy", AnimationInterface::DOUBLE_COUNTER);
1642 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1643 {
1644 Ptr<Node> n = *i;
1645 if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
1646 {
1647 UpdateNodeCounter (m_remainingEnergyCounterId, n->GetId (), 1);
1648 }
1649 }
1650}
1651
1652bool
1653AnimationInterface::IsInTimeWindow ()
1654{
1655 if ((Simulator::Now () >= m_startTime) &&
1656 (Simulator::Now () <= m_stopTime))
1657 return true;
1658 else
1659 return false;
1660}
1661
1662void
1663AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
1664{
1665 if (!routing && m_f)
1666 {
1667 return;
1668 }
1669 if (routing && m_routingF)
1670 {
1671 NS_FATAL_ERROR ("SetRoutingOutputFile already used once")do { std::cerr << "msg=\"" << "SetRoutingOutputFile already used once"
<< "\", "; do { std::cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1671 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1672 return;
1673 }
1674
1675 NS_LOG_INFO ("Creating new trace file:" << fn.c_str ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Creating new trace file:"
<< fn.c_str () << std::endl; } } while (false)
;
1676 FILE * f = 0;
1677 f = std::fopen (fn.c_str (), "w");
1678 if (!f)
1679 {
1680 NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ())do { std::cerr << "msg=\"" << "Unable to open output file:"
<< fn.c_str () << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1680 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1681 return; // Can't open output file
1682 }
1683 if (routing)
1684 {
1685 m_routingF = f;
1686 m_routingFileName = fn;
1687 }
1688 else
1689 {
1690 m_f = f;
1691 m_outputFileName = fn;
1692 }
1693 return;
1694}
1695
1696void
1697AnimationInterface::CheckMaxPktsPerTraceFile ()
1698{
1699 // Start a new trace file if the current packet count exceeded nax packets per file
1700 ++m_currentPktCount;
1701 if (m_currentPktCount <= m_maxPktsPerFile)
1702 {
1703 return;
1704 }
1705 NS_LOG_UNCOND ("Max Packets per trace file exceeded")do { std::clog << "Max Packets per trace file exceeded"
<< std::endl; } while (false)
;
1706 StopAnimation (true);
1707}
1708
1709std::string
1710AnimationInterface::GetNetAnimVersion ()
1711{
1712 return NETANIM_VERSION"netanim-3.106";
1713}
1714
1715
1716void
1717AnimationInterface::TrackQueueCounters ()
1718{
1719 if (Simulator::Now () > m_queueCountersStopTime)
1720 {
1721 NS_LOG_INFO ("TrackQueueCounters Completed")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "TrackQueueCounters Completed"
<< std::endl; } } while (false)
;
1722 return;
1723 }
1724 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1725 {
1726 uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1727 UpdateNodeCounter (m_queueEnqueueCounterId, nodeId, m_nodeQueueEnqueue[nodeId]);
1728 UpdateNodeCounter (m_queueDequeueCounterId, nodeId, m_nodeQueueDequeue[nodeId]);
1729 UpdateNodeCounter (m_queueDropCounterId, nodeId, m_nodeQueueDrop[nodeId]);
1730 }
1731 Simulator::Schedule (m_queueCountersPollInterval, &AnimationInterface::TrackQueueCounters, this);
1732}
1733
1734void
1735AnimationInterface::TrackWifiMacCounters ()
1736{
1737 if (Simulator::Now () > m_wifiMacCountersStopTime)
1738 {
1739 NS_LOG_INFO ("TrackWifiMacCounters Completed")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "TrackWifiMacCounters Completed"
<< std::endl; } } while (false)
;
1740 return;
1741 }
1742 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1743 {
1744 uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1745 UpdateNodeCounter (m_wifiMacTxCounterId, nodeId, m_nodeWifiMacTx[nodeId]);
1746 UpdateNodeCounter (m_wifiMacTxDropCounterId, nodeId, m_nodeWifiMacTxDrop[nodeId]);
1747 UpdateNodeCounter (m_wifiMacRxCounterId, nodeId, m_nodeWifiMacRx[nodeId]);
1748 UpdateNodeCounter (m_wifiMacRxDropCounterId, nodeId, m_nodeWifiMacRxDrop[nodeId]);
1749 }
1750 Simulator::Schedule (m_wifiMacCountersPollInterval, &AnimationInterface::TrackWifiMacCounters, this);
1751}
1752
1753void
1754AnimationInterface::TrackWifiPhyCounters ()
1755{
1756 if (Simulator::Now () > m_wifiPhyCountersStopTime)
1757 {
1758 NS_LOG_INFO ("TrackWifiPhyCounters Completed")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "TrackWifiPhyCounters Completed"
<< std::endl; } } while (false)
;
1759 return;
1760 }
1761 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1762 {
1763 uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1764 UpdateNodeCounter (m_wifiPhyTxDropCounterId, nodeId, m_nodeWifiPhyTxDrop[nodeId]);
1765 UpdateNodeCounter (m_wifiPhyRxDropCounterId, nodeId, m_nodeWifiPhyRxDrop[nodeId]);
1766 }
1767 Simulator::Schedule (m_wifiPhyCountersPollInterval, &AnimationInterface::TrackWifiPhyCounters, this);
1768}
1769
1770void
1771AnimationInterface::TrackIpv4L3ProtocolCounters ()
1772{
1773 if (Simulator::Now () > m_ipv4L3ProtocolCountersStopTime)
1774 {
1775 NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "TrackIpv4L3ProtocolCounters Completed"
<< std::endl; } } while (false)
;
1776 return;
1777 }
1778 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1779 {
1780 uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1781 UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, nodeId, m_nodeIpv4Tx[nodeId]);
1782 UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, nodeId, m_nodeIpv4Rx[nodeId]);
1783 UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, nodeId, m_nodeIpv4Drop[nodeId]);
1784 }
1785 Simulator::Schedule (m_ipv4L3ProtocolCountersPollInterval, &AnimationInterface::TrackIpv4L3ProtocolCounters, this);
1786}
1787
1788
1789
1790
1791
1792/***** Routing-related *****/
1793
1794void
1795AnimationInterface::TrackIpv4RoutePaths ()
1796{
1797 if (m_ipv4RouteTrackElements.empty ())
1798 {
1799 return;
1800 }
1801 for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
1802 i != m_ipv4RouteTrackElements.end ();
1803 ++i)
1804 {
1805 Ipv4RouteTrackElement trackElement = *i;
1806 Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
1807 if (!fromNode)
1808 {
1809 NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found")do { std::cerr << "msg=\"" << "Node: " << trackElement
.fromNodeId << " Not found" << "\", "; do { std::
cerr << "file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1809 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1810 continue;
1811 }
1812 Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1813 if (!ipv4)
1814 {
1815 NS_LOG_WARN ("ipv4 object not found")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "ipv4 object not found"
<< std::endl; } } while (false)
;
1816 continue;
1817 }
1818 Ptr <Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
1819 if (!rp)
1820 {
1821 NS_LOG_WARN ("Routing protocol object not found")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Routing protocol object not found"
<< std::endl; } } while (false)
;
1822 continue;
1823 }
1824 NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId)do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Begin Track Route for: "
<< trackElement.destination.c_str () << " From:"
<< trackElement.fromNodeId << std::endl; } } while
(false)
;
1825 Ptr<Packet> pkt = Create<Packet> ();
1826 Ipv4Header header;
1827 header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
1828 Socket::SocketErrno sockerr;
1829 Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1830 Ipv4RoutePathElements rpElements;
1831 if (!rt)
1832 {
1833 NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "No route to :"
<< trackElement.destination.c_str () << std::endl
; } } while (false)
;
1834 Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1835 rpElements.push_back (elem);
1836 WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1837 continue;
1838 }
1839 std::ostringstream oss;
1840 oss << rt->GetGateway ();
1841 NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Node:" <<
trackElement.fromNodeId << "-->" << rt->GetGateway
() << std::endl; } } while (false)
;
1842 if (rt->GetGateway () == "0.0.0.0")
1843 {
1844 Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
1845 rpElements.push_back (elem);
1846 if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
1847 {
1848 Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
1849 rpElements.push_back (elem2);
1850 }
1851 }
1852 else if (rt->GetGateway () == "127.0.0.1")
1853 {
1854 Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1855 rpElements.push_back (elem);
1856 }
1857 else
1858 {
1859 Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
1860 rpElements.push_back (elem);
1861 }
1862 RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
1863 WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1864 }
1865
1866}
1867
1868void
1869AnimationInterface::TrackIpv4Route ()
1870{
1871 if (Simulator::Now () > m_routingStopTime)
1872 {
1873 NS_LOG_INFO ("TrackIpv4Route completed")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "TrackIpv4Route completed"
<< std::endl; } } while (false)
;
1874 return;
1875 }
1876 if (m_routingNc.GetN ())
1877 {
1878 for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
1879 {
1880 Ptr <Node> n = *i;
1881 WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
1882 }
1883 }
1884 else
1885 {
1886 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1887 {
1888 Ptr <Node> n = *i;
1889 WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
1890 }
1891 }
1892 TrackIpv4RoutePaths ();
1893 Simulator::Schedule (m_routingPollInterval, &AnimationInterface::TrackIpv4Route, this);
1894}
1895
1896std::string
1897AnimationInterface::GetIpv4RoutingTable (Ptr <Node> n)
1898{
1899
1900 NS_ASSERT (n)do { if (!(n)) { std::cerr << "assert failed. cond=\"" <<
"n" << "\", "; do { std::cerr << "file=" <<
"../src/netanim/model/animation-interface.cc" << ", line="
<< 1900 << std::endl; ::ns3::FatalImpl::FlushStreams
(); if (true) std::terminate (); } while (false); } } while (
false)
;
1901 Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
1902 if (!ipv4)
1903 {
1904 NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Node " <<
n->GetId () << " Does not have an Ipv4 object" <<
std::endl; } } while (false)
;
1905 return "";
1906 }
1907 std::stringstream stream;
1908 Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
1909 ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
1910 return stream.str ();
1911
1912}
1913
1914void
1915AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
1916{
1917 NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "RecursiveIpv4RoutePathSearch from:"
<< from.c_str () << " to:" << to.c_str () <<
std::endl; } } while (false)
;
1918 if ((from == "0.0.0.0") || (from == "127.0.0.1"))
1919 {
1920 NS_LOG_INFO ("Got " << from.c_str () << " End recursion")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Got " <<
from.c_str () << " End recursion" << std::endl; }
} while (false)
;
1921 return;
1922 }
1923 Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
1924 Ptr <Node> toNode = NodeList::GetNode (m_ipv4ToNodeIdMap[to]);
1925 if (fromNode->GetId () == toNode->GetId ())
1926 {
1927 Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
1928 rpElements.push_back (elem);
1929 return;
1930 }
1931 if (!fromNode)
1932 {
1933 NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found")do { std::cerr << "msg=\"" << "Node: " << m_ipv4ToNodeIdMap
[from] << " Not found" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1933 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1934 return;
1935 }
1936 if (!toNode)
1937 {
1938 NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found")do { std::cerr << "msg=\"" << "Node: " << m_ipv4ToNodeIdMap
[to] << " Not found" << "\", "; do { std::cerr <<
"file=" << "../src/netanim/model/animation-interface.cc"
<< ", line=" << 1938 << std::endl; ::ns3::
FatalImpl::FlushStreams (); if (true) std::terminate (); } while
(false); } while (false)
;
1939 return;
1940 }
1941 Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1942 if (!ipv4)
1943 {
1944 NS_LOG_WARN ("ipv4 object not found")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "ipv4 object not found"
<< std::endl; } } while (false)
;
1945 return;
1946 }
1947 Ptr <Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
1948 if (!rp)
1949 {
1950 NS_LOG_WARN ("Routing protocol object not found")do { if (g_log.IsEnabled (ns3::LOG_WARN)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_WARN) << "] "; }; std::clog << "Routing protocol object not found"
<< std::endl; } } while (false)
;
1951 return;
1952 }
1953 Ptr<Packet> pkt = Create<Packet> ();
1954 Ipv4Header header;
1955 header.SetDestination (Ipv4Address (to.c_str ()));
1956 Socket::SocketErrno sockerr;
1957 Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1958 if (!rt)
1959 {
1960 return;
1961 }
1962 NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ())do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_DEBUG) << "] "; }; std::clog << "Node: " <<
fromNode->GetId () << " G:" << rt->GetGateway
() << std::endl; } } while (false)
;
1963 std::ostringstream oss;
1964 oss << rt->GetGateway ();
1965 if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
1966 {
1967 NS_LOG_INFO ("Null gw")do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Null gw" <<
std::endl; } } while (false)
;
1968 Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
1969 rpElements.push_back (elem);
1970 if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
1971 {
1972 Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
1973 rpElements.push_back (elem2);
1974 }
1975 return;
1976 }
1977 NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ())do { if (g_log.IsEnabled (ns3::LOG_INFO)) { if (g_log.IsEnabled
(ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3::
LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog
); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE
)) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();
if (printer != 0) { (*printer)(std::clog); std::clog <<
" "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std
::clog << g_log.Name () << ":" << __FUNCTION__
<< "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL
)) { std::clog << "[" << g_log.GetLevelLabel (ns3
::LOG_INFO) << "] "; }; std::clog << "Node:" <<
fromNode->GetId () << "-->" << rt->GetGateway
() << std::endl; } } while (false)
;
1978 Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
1979 rpElements.push_back (elem);
1980 RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
1981
1982}
1983
1984
1985
1986/***** WriteXml *****/
1987
1988void
1989AnimationInterface::WriteXmlAnim (bool routing)
1990{
1991 AnimXmlElement element ("anim");
1992 element.AddAttribute ("ver", GetNetAnimVersion ());
1993 FILE * f = m_f;
1994 if (!routing)
1995 {
1996 element.AddAttribute ("filetype", "animation");
1997 }
1998 else
1999 {
2000 element.AddAttribute ("filetype", "routing");
2001 f = m_routingF;
2002 }
2003 element.Close ();
2004 WriteN (element.GetElementString (), f);
2005}
2006
2007void
2008AnimationInterface::WriteXmlClose (std::string name, bool routing)
2009{
2010 std::string closeString = "</" + name + ">\n";
2011 if (!routing)
2012 {
2013 WriteN (closeString, m_f);
2014 }
2015 else
2016 {
2017 WriteN (closeString, m_routingF);
2018 }
2019}
2020
2021void
2022AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2023{
2024 AnimXmlElement element ("node");
2025 element.AddAttribute ("id", id);
2026 element.AddAttribute ("sysId", sysId);
2027 element.AddAttribute ("locX", locX);
2028 element.AddAttribute ("locY", locY);
2029 element.CloseElement ();
2030 WriteN (element.GetElementString (), m_f);
2031}
2032
2033void
2034AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2035{
2036 AnimXmlElement element ("linkupdate");
2037 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2038 element.AddAttribute ("fromId", fromId);
2039 element.AddAttribute ("toId", toId);
2040 element.AddAttribute ("ld", linkDescription, true);
2041 element.CloseElement ();
2042 WriteN (element.GetElementString (), m_f);
2043}
2044
2045void
2046AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2047{
2048 AnimXmlElement element ("link");
2049 element.AddAttribute ("fromId", fromId);
2050 element.AddAttribute ("toId", toId);
2051
2052 LinkProperties lprop ;
2053 lprop.fromNodeDescription = "";
2054 lprop.toNodeDescription = "";
2055 lprop.linkDescription = "";
2056
2057 P2pLinkNodeIdPair p1 = { fromId, toId };
2058 P2pLinkNodeIdPair p2 = { toId, fromId };
2059 if (m_linkProperties.find (p1) != m_linkProperties.end ())
2060 {
2061 lprop = m_linkProperties[p1];
2062 }
2063 else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2064 {
2065 lprop = m_linkProperties[p2];
2066 }
2067
2068 element.AddAttribute ("fd", lprop.fromNodeDescription, true);
2069 element.AddAttribute ("td", lprop.toNodeDescription, true);
2070 element.AddAttribute ("ld", lprop.linkDescription, true);
2071 element.CloseElement ();
2072 WriteN (element.GetElementString (), m_f);
2073}
2074
2075void
2076AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2077{
2078 AnimXmlElement element ("rt");
2079 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2080 element.AddAttribute ("id", nodeId);
2081 element.AddAttribute ("info", routingInfo.c_str (), true);
2082 element.CloseElement ();
2083 WriteN (element.GetElementString (), m_routingF);
2084}
2085
2086void
2087AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2088{
2089 std::string tagName = "rp";
2090 AnimXmlElement element (tagName, false);
2091 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2092 element.AddAttribute ("id", nodeId);
2093 element.AddAttribute ("d", destination.c_str ());
2094 element.AddAttribute ("c", rpElements.size ());
2095 element.CloseTag ();
2096 element.AddLineBreak ();
2097 for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2098 i != rpElements.end ();
2099 ++i)
2100 {
2101 Ipv4RoutePathElement rpElement = *i;
2102 AnimXmlElement rpeElement ("rpe");
2103 rpeElement.AddAttribute ("n", rpElement.nodeId);
2104 rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2105 rpeElement.CloseElement ();
2106 element.Add (rpeElement);
2107 }
2108 element.CloseElement ();
2109 WriteN (element.GetElementString (), m_routingF);
2110}
2111
2112
2113void
2114AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2115{
2116 AnimXmlElement element ("pr");
2117 element.AddAttribute ("uId", animUid);
2118 element.AddAttribute ("fId", fId);
2119 element.AddAttribute ("fbTx", fbTx);
2120 if (!metaInfo.empty ())
2121 {
2122 element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2123 }
2124 element.CloseElement ();
2125 WriteN (element.GetElementString (), m_f);
2126}
2127
2128void
2129AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2130{
2131 AnimXmlElement element (pktType);
2132 element.AddAttribute ("uId", animUid);
2133 element.AddAttribute ("tId", tId);
2134 element.AddAttribute ("fbRx", fbRx);
2135 element.AddAttribute ("lbRx", lbRx);
2136 element.CloseElement ();
2137 WriteN (element.GetElementString (), m_f);
2138}
2139
2140void
2141AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2142 uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2143{
2144 AnimXmlElement element (pktType);
2145 element.AddAttribute ("fId", fId);
2146 element.AddAttribute ("fbTx", fbTx);
2147 element.AddAttribute ("lbTx", lbTx);
2148 if (!metaInfo.empty ())
2149 {
2150 element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2151 }
2152 element.AddAttribute ("tId", tId);
2153 element.AddAttribute ("fbRx", fbRx);
2154 element.AddAttribute ("lbRx", lbRx);
2155 element.CloseElement ();
2156 WriteN (element.GetElementString (), m_f);
2157}
2158
2159void
2160AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2161{
2162 AnimXmlElement element ("ncs");
2163 element.AddAttribute ("ncId", nodeCounterId);
2164 element.AddAttribute ("n", counterName);
2165 element.AddAttribute ("t", CounterTypeToString (counterType));
2166 element.CloseElement ();
2167 WriteN (element.GetElementString (), m_f);
2168}
2169
2170void
2171AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2172{
2173 AnimXmlElement element ("res");
2174 element.AddAttribute ("rid", resourceId);
2175 element.AddAttribute ("p", resourcePath);
2176 element.CloseElement ();
2177 WriteN (element.GetElementString (), m_f);
2178}
2179
2180void
2181AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2182{
2183 AnimXmlElement element ("nu");
2184 element.AddAttribute ("p", "i");
2185 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2186 element.AddAttribute ("id", nodeId);
2187 element.AddAttribute ("rid", resourceId);
2188 element.CloseElement ();
2189 WriteN (element.GetElementString (), m_f);
2190}
2191
2192void
2193AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2194{
2195 AnimXmlElement element ("nu");
2196 element.AddAttribute ("p", "s");
2197 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2198 element.AddAttribute ("id", nodeId);
2199 element.AddAttribute ("w", width);
2200 element.AddAttribute ("h", height);
2201 element.CloseElement ();
2202 WriteN (element.GetElementString (), m_f);
2203}
2204
2205void
2206AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2207{
2208 AnimXmlElement element ("nu");
2209 element.AddAttribute ("p", "p");
2210 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2211 element.AddAttribute ("id", nodeId);
2212 element.AddAttribute ("x", x);
2213 element.AddAttribute ("y", y);
2214 element.CloseElement ();
2215 WriteN (element.GetElementString (), m_f);
2216}
2217
2218void
2219AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2220{
2221 AnimXmlElement element ("nu");
2222 element.AddAttribute ("p", "c");
2223 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2224 element.AddAttribute ("id", nodeId);
2225 element.AddAttribute ("r", (uint32_t) r);
2226 element.AddAttribute ("g", (uint32_t) g);
2227 element.AddAttribute ("b", (uint32_t) b);
2228 element.CloseElement ();
2229 WriteN (element.GetElementString (), m_f);
2230}
2231
2232void
2233AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId)
2234{
2235 AnimXmlElement element ("nu");
2236 element.AddAttribute ("p", "d");
2237 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2238 element.AddAttribute ("id", nodeId);
2239 if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2240 {
2241 element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
2242 }
2243 element.CloseElement ();
2244 WriteN (element.GetElementString (), m_f);
2245}
2246
2247
2248void
2249AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2250{
2251 AnimXmlElement element ("nc");
2252 element.AddAttribute ("c", nodeCounterId);
2253 element.AddAttribute ("i", nodeId);
2254 element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2255 element.AddAttribute ("v", counterValue);
2256 element.CloseElement ();
2257 WriteN (element.GetElementString (), m_f);
2258}
2259
2260void
2261AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2262{
2263 AnimXmlElement element ("bg");
2264 element.AddAttribute ("f", fileName);
2265 element.AddAttribute ("x", x);
2266 element.AddAttribute ("y", y);
2267 element.AddAttribute ("sx", scaleX);
2268 element.AddAttribute ("sy", scaleY);
2269 element.AddAttribute ("o", opacity);
2270 element.CloseElement ();
2271 WriteN (element.GetElementString (), m_f);
2272}
2273
2274void
2275AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2276{
2277 AnimXmlElement element ("nonp2plinkproperties");
2278 element.AddAttribute ("id", id);
2279 element.AddAttribute ("ipv4Address", ipv4Address);
2280 element.AddAttribute ("channelType", channelType);
2281 element.CloseElement ();
2282 WriteN (element.GetElementString (), m_f);
2283}
2284
2285
2286
2287/***** AnimXmlElement *****/
2288
2289AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool emptyElement):
2290 m_tagName (tagName),
2291 m_emptyElement (emptyElement)
2292{
2293 m_elementString = "<" + tagName + " ";
2294}
2295
2296template <typename T>
2297void
2298AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape)
2299{
2300 std::ostringstream oss;
2301 oss << std::setprecision (10);
2302 oss << value;
2303 m_elementString += attribute.c_str ();
2304 if (xmlEscape)
2305 {
2306 m_elementString += "=\"";
2307 std::string valueStr = oss.str ();
2308 for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it)
2309 {
2310 switch (*it)
2311 {
2312 case '&':
2313 m_elementString += "&amp;";
2314 break;
2315 case '\"':
2316 m_elementString += "&quot;";
2317 break;
2318 case '\'':
2319 m_elementString += "&apos;";
2320 break;
2321 case '<':
2322 m_elementString += "&lt;";
2323 break;
2324 case '>':
2325 m_elementString += "&gt;";
2326 break;
2327 default:
2328 m_elementString += *it;
2329 break;
2330 }
2331 }
2332 m_elementString += "\" ";
2333 }
2334 else
2335 {
2336 m_elementString += "=\"" + oss.str () + "\" ";
2337 }
2338}
2339
2340void
2341AnimationInterface::AnimXmlElement::Close ()
2342{
2343 m_elementString += ">\n";
2344}
2345
2346void
2347AnimationInterface::AnimXmlElement::CloseElement ()
2348{
2349 if (m_emptyElement)
2350 {
2351 m_elementString += "/>\n";
2352 }
2353 else
2354 {
2355 m_elementString += "</" + m_tagName + ">\n";
2356 }
2357}
2358
2359void
2360AnimationInterface::AnimXmlElement::CloseTag ()
2361{
2362 m_elementString += ">";
2363}
2364
2365void
2366AnimationInterface::AnimXmlElement::AddLineBreak ()
2367{
2368 m_elementString += "\n";
2369}
2370
2371void
2372AnimationInterface::AnimXmlElement::Add (AnimXmlElement e)
2373{
2374 m_elementString += e.GetElementString ();
2375}
2376
2377std::string
2378AnimationInterface::AnimXmlElement::GetElementString ()
2379{
2380 return m_elementString;
2381}
2382
2383
2384
2385
2386/***** AnimByteTag *****/
2387
2388TypeId
2389AnimByteTag::GetTypeId (void)
2390{
2391 static TypeId tid = TypeId ("ns3::AnimByteTag")
2392 .SetParent<Tag> ()
2393 .SetGroupName ("NetAnim")
2394 .AddConstructor<AnimByteTag> ()
2395 ;
2396 return tid;
2397}
2398
2399TypeId
2400AnimByteTag::GetInstanceTypeId (void) const
2401{
2402 return GetTypeId ();
2403}
2404
2405uint32_t
2406AnimByteTag::GetSerializedSize (void) const
2407{
2408 return sizeof (uint64_t);
2409}
2410
2411void
2412AnimByteTag::Serialize (TagBuffer i) const
2413{
2414 i.WriteU64 (m_AnimUid);
2415}
2416
2417void
2418AnimByteTag::Deserialize (TagBuffer i)
2419{
2420 m_AnimUid = i.ReadU64 ();
2421}
2422
2423void
2424AnimByteTag::Print (std::ostream &os) const
2425{
2426 os << "AnimUid=" << m_AnimUid;
2427}
2428
2429void
2430AnimByteTag::Set (uint64_t AnimUid)
2431{
2432 m_AnimUid = AnimUid;
2433}
2434
2435uint64_t
2436AnimByteTag::Get (void) const
2437{
2438 return m_AnimUid;
2439}
2440
2441AnimationInterface::AnimPacketInfo::AnimPacketInfo ()
2442 : m_txnd (0),
2443 m_txNodeId (0),
2444 m_fbTx (0),
2445 m_lbTx (0),
2446 m_lbRx (0)
2447{
2448}
2449
2450AnimationInterface::AnimPacketInfo::AnimPacketInfo (const AnimPacketInfo & pInfo)
2451{
2452 m_txnd = pInfo.m_txnd;
2453 m_txNodeId = pInfo.m_txNodeId;
2454 m_fbTx = pInfo.m_fbTx;
2455 m_lbTx = pInfo.m_lbTx;
2456 m_lbRx = pInfo.m_lbRx;
2457}
2458
2459AnimationInterface::AnimPacketInfo::AnimPacketInfo (Ptr <const NetDevice> txnd,
2460 const Time fbTx,
2461 uint32_t txNodeId)
2462 : m_txnd (txnd),
2463 m_txNodeId (0),
2464 m_fbTx (fbTx.GetSeconds ()),
2465 m_lbTx (0),
2466 m_lbRx (0)
2467{
2468 if (!m_txnd)
2469 m_txNodeId = txNodeId;
2470}
2471
2472void
2473AnimationInterface::AnimPacketInfo::ProcessRxBegin (Ptr<const NetDevice> nd, const double fbRx)
2474{
2475 Ptr <Node> n = nd->GetNode ();
2476 m_fbRx = fbRx;
2477 m_rxnd = nd;
2478}
2479
2480} // namespace ns3