A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
animation-interface.cc
Go to the documentation of this file.
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 
54 NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
55 
56 namespace ns3 {
57 
58 // Globals
59 
60 static bool initialized = false;
61 
62 
63 // Public methods
64 
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_FILE),
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 
88 {
89  StopAnimation ();
90 }
91 
92 void
94 {
95  m_trackPackets = false;
96 }
97 
98 void
100 {
102  m_wifiPhyCountersPollInterval = pollInterval;
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;
112  }
114 
115 }
116 
117 void
119 {
121  m_wifiMacCountersPollInterval = pollInterval;
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;
137  }
139 }
140 
141 void
143 {
145  m_queueCountersPollInterval = pollInterval;
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;
158  }
160 }
161 
162 void
164 {
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;
179  }
181 }
182 
185 {
186  SetOutputFile (fileName, true);
188  m_routingPollInterval = pollInterval;
189  WriteXmlAnim (true);
191  return *this;
192 }
193 
196 {
197  m_routingNc = nc;
198  return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
199 }
200 
202 AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
203 {
204  Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
205  m_ipv4RouteTrackElements.push_back (element);
206  return *this;
207 }
208 
209 void
211 {
212  m_startTime = t;
213 }
214 
215 void
217 {
218  m_stopTime = t;
219 }
220 
221 void
222 AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile)
223 {
224  m_maxPktsPerFile = maxPacketsPerFile;
225 }
226 
227 uint32_t
228 AnimationInterface::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 
236 uint32_t
237 AnimationInterface::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 
245 void
247 {
248  m_enablePacketMetadata = enable;
249  if (enable)
250  {
252  }
253 }
254 
255 bool
257 {
258  return initialized;
259 }
260 
261 bool
263 {
264  return m_started;
265 }
266 
267 void
269 {
270  m_writeCallback = cb;
271 }
272 
273 void
275 {
276  m_writeCallback = 0;
277 }
278 
279 void
281 {
283 }
284 
285 
286 void
287 AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
288 {
289  NS_ASSERT (n);
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 << ")");
299 
300 }
301 
302 void
303 AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
304 {
305  NS_LOG_INFO ("Setting node image for Node Id:" << nodeId);
306  if (resourceId > (m_resources.size ()-1))
307  {
308  NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?");
309  }
310  WriteXmlUpdateNodeImage (nodeId, resourceId);
311 }
312 
313 void
314 AnimationInterface::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?");
319  }
320  WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter);
321 }
322 
323 void
324 AnimationInterface::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");
329  }
330  WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
331 }
332 
333 void
334 AnimationInterface::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 
341 void
342 AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
343 {
344  UpdateNodeColor (n->GetId (), r, g, b);
345 }
346 
347 void
348 AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
349 {
350  NS_ASSERT (NodeList::GetNode (nodeId));
351  NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
352  Rgb rgb = {r, g, b};
353  m_nodeColors[nodeId] = rgb;
354  WriteXmlUpdateNodeColor (nodeId, r, g, b);
355 }
356 
357 void
358 AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
359  std::string linkDescription)
360 {
361  WriteXmlUpdateLink (fromNode, toNode, linkDescription);
362 }
363 
364 void
366  std::string linkDescription)
367 {
368  NS_ASSERT (fromNode);
369  NS_ASSERT (toNode);
370  WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription);
371 }
372 
373 void
375 {
376  UpdateNodeDescription (n->GetId (), descr);
377 }
378 
379 void
380 AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
381 {
382  NS_ASSERT (NodeList::GetNode (nodeId));
383  m_nodeDescriptions[nodeId] = descr;
385 }
386 
387 // Private methods
388 
389 
390 double
392 {
393  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
394  NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ());
395  return fractionIter->second;
396 }
397 
398 void
400 {
401  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
402  return;
403  Ptr <Node> n = mobility->GetObject <Node> ();
404  NS_ASSERT (n);
405  Vector v ;
406  if (!mobility)
407  {
408  v = GetPosition (n);
409  }
410  else
411  {
412  v = mobility->GetPosition ();
413  }
414  UpdatePosition (n, v);
415  WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y);
416 }
417 
418 bool
420 {
421  Vector oldLocation = GetPosition (n);
422  if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
423  (ceil (oldLocation.y) == ceil (newLocation.y)))
424  {
425  return false;
426  }
427  else
428  {
429  return true;
430  }
431 }
432 
433 void
435 {
436  if (!m_started || !IsInTimeWindow ())
437  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);
443  Vector v = GetPosition (n);
444  WriteXmlUpdateNodePosition (n->GetId () , v.x, v.y);
445  }
446  if (!Simulator::IsFinished ())
447  {
453  }
454 }
455 
456 std::vector <Ptr <Node> >
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);
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 
487 int
488 AnimationInterface::WriteN (const std::string& st, FILE * f)
489 {
490  if (!f)
491  return 0;
492  if (m_writeCallback)
493  {
494  m_writeCallback (st.c_str ());
495  }
496  return WriteN (st.c_str (), st.length (), f);
497 }
498 
499 int
500 AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
501 {
502  if (!f)
503  return 0;
504  // Write count bytes to h from data
505  uint32_t nLeft = count;
506  const char* p = data;
507  uint32_t written = 0;
508  while (nLeft)
509  {
510  int n = std::fwrite (p, 1, nLeft, f);
511  if (n <= 0)
512  {
513  return written;
514  }
515  written += n;
516  nLeft -= n;
517  p += n;
518  }
519  return written;
520 }
521 
522 void
523 AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
524 {
525  NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ());
526  WriteXmlRp (nodeId, destination, rpElements);
527  /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
528  i != rpElements.end ();
529  ++i)
530  {
531  Ipv4RoutePathElement rpElement = *i;
532  NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
533  WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
534 
535  }
536  */
537 }
538 
539 void
540 AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
541 {
542  WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType);
543 }
544 
545 const std::vector<std::string>
546 AnimationInterface::GetElementsFromContext (const std::string& context) const
547 {
548  std::vector <std::string> elements;
549  size_t pos1=0, pos2;
550  while (pos1 != context.npos)
551  {
552  pos1 = context.find ("/",pos1);
553  pos2 = context.find ("/",pos1+1);
554  elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
555  pos1 = pos2;
556  pos2 = context.npos;
557  }
558  return elements;
559 }
560 
562 AnimationInterface::GetNodeFromContext (const std::string& context) const
563 {
564  // Use "NodeList/*/ as reference
565  // where element [1] is the Node Id
566 
567  std::vector <std::string> elements = GetElementsFromContext (context);
568  Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
569  NS_ASSERT (n);
570 
571  return n;
572 }
573 
576 {
577  // Use "NodeList/*/DeviceList/*/ as reference
578  // where element [1] is the Node Id
579  // element [2] is the NetDevice Id
580 
581  std::vector <std::string> elements = GetElementsFromContext (context);
582  Ptr <Node> n = GetNodeFromContext (context);
583 
584  return n->GetDevice (atoi (elements.at (3).c_str ()));
585 }
586 
587 uint64_t
589 {
590  AnimByteTag tag;
591  TypeId tid = tag.GetInstanceTypeId ();
593  bool found = false;
594  while (i.HasNext ())
595  {
596  ByteTagIterator::Item item = i.Next ();
597  if (tid == item.GetTypeId ())
598  {
599  item.GetTag (tag);
600  found = true;
601  }
602  }
603  if (found)
604  {
605  return tag.Get ();
606  }
607  else
608  {
609  return 0;
610  }
611 }
612 
613 void
615 {
616  AnimByteTag tag;
617  tag.Set (animUid);
618  p->AddByteTag (tag);
619 }
620 
621 void
622 AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
623 {
624  if (!m_started || !IsInTimeWindow ())
625  return;
626 
627  const Ptr <const Node> node = GetNodeFromContext (context);
628  const uint32_t nodeId = node->GetId ();
629 
630  NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
631 
632  const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
633 
634  NS_ASSERT (energySource);
635  // Don't call GetEnergyFraction () because of recursion
636  const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
637 
638  NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction);
639 
640  m_nodeEnergyFraction[nodeId] = energyFraction;
641  UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction);
642 }
643 
644 void
646 {
647  const Ptr <const Node> node = GetNodeFromContext (context);
648  ++m_nodeWifiPhyTxDrop[node->GetId ()];
649 }
650 
651 void
653 {
654  const Ptr <const Node> node = GetNodeFromContext (context);
655  ++m_nodeWifiPhyRxDrop[node->GetId ()];
656 }
657 
658 void
660 {
661  const Ptr <const Node> node = GetNodeFromContext (context);
662  ++m_nodeWifiMacTx[node->GetId ()];
663 }
664 
665 void
667 {
668  const Ptr <const Node> node = GetNodeFromContext (context);
669  ++m_nodeWifiMacTxDrop[node->GetId ()];
670 }
671 
672 void
674 {
675  const Ptr <const Node> node = GetNodeFromContext (context);
676  ++m_nodeWifiMacRx[node->GetId ()];
677 }
678 
679 void
681 {
682  const Ptr <const Node> node = GetNodeFromContext (context);
683  ++m_nodeWifiMacRxDrop[node->GetId ()];
684 }
685 
686 void
687 AnimationInterface::Ipv4TxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
688 {
689  const Ptr <const Node> node = GetNodeFromContext (context);
690  ++m_nodeIpv4Tx[node->GetId ()];
691 }
692 
693 void
694 AnimationInterface::Ipv4RxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
695 {
696  const Ptr <const Node> node = GetNodeFromContext (context);
697  ++m_nodeIpv4Rx[node->GetId ()];
698 }
699 
700 void
701 AnimationInterface::Ipv4DropTrace (std::string context,
702  const Ipv4Header & ipv4Header,
704  Ipv4L3Protocol::DropReason dropReason,
705  Ptr<Ipv4> ipv4,
706  uint32_t)
707 {
708  const Ptr <const Node> node = GetNodeFromContext (context);
709  ++m_nodeIpv4Drop[node->GetId ()];
710 }
711 
712 void
713 AnimationInterface::EnqueueTrace (std::string context,
715 {
716  const Ptr <const Node> node = GetNodeFromContext (context);
717  ++m_nodeQueueEnqueue[node->GetId ()];
718 }
719 
720 void
721 AnimationInterface::DequeueTrace (std::string context,
723 {
724  const Ptr <const Node> node = GetNodeFromContext (context);
725  ++m_nodeQueueDequeue[node->GetId ()];
726 }
727 
728 void
731 {
732  const Ptr <const Node> node = GetNodeFromContext (context);
733  ++m_nodeQueueDrop[node->GetId ()];
734 }
735 
736 void
737 AnimationInterface::DevTxTrace (std::string context,
739  Ptr<NetDevice> tx,
740  Ptr<NetDevice> rx,
741  Time txTime,
742  Time rxTime)
743 {
744  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
745  return;
746  NS_ASSERT (tx);
747  NS_ASSERT (rx);
748  Time now = Simulator::Now ();
749  double fbTx = now.GetSeconds ();
750  double lbTx = (now + txTime).GetSeconds ();
751  double fbRx = (now + rxTime - txTime).GetSeconds ();
752  double lbRx = (now + rxTime).GetSeconds ();
754  WriteXmlP ("p",
755  tx->GetNode ()->GetId (),
756  fbTx,
757  lbTx,
758  rx->GetNode ()->GetId (),
759  fbRx,
760  lbRx,
762 }
763 
764 void
766 {
767  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
768  return;
769  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
770  NS_ASSERT (ndev);
771  Ptr <Node> n = ndev->GetNode ();
772  NS_ASSERT (n);
773  ++gAnimUid;
774  NS_LOG_INFO ("Uan TxBeginTrace for packet:" << gAnimUid);
775  AddByteTag (gAnimUid, p);
776  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
779 }
780 
781 void
783 {
784  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
785  return;
786  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
787  NS_ASSERT (ndev);
788  Ptr <Node> n = ndev->GetNode ();
789  NS_ASSERT (n);
790  uint64_t animUid = GetAnimUidFromPacket (p);
791  NS_LOG_INFO ("UanPhyGenRxTrace for packet:" << animUid);
793  {
794  NS_LOG_WARN ("UanPhyGenRxBeginTrace: unknown Uid");
795  return;
796  }
797  m_pendingUanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ());
798  m_pendingUanPackets[animUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
799  OutputWirelessPacketRxInfo (p, m_pendingUanPackets[animUid].GetRxInfo (ndev), animUid);
800 }
801 
802 
803 void
806 {
807  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
808  return;
809  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
810  NS_ASSERT (ndev);
811  Ptr <Node> n = ndev->GetNode ();
812  NS_ASSERT (n);
813  ++gAnimUid;
814  NS_LOG_INFO ("Wifi TxBeginTrace for packet:" << gAnimUid);
815  AddByteTag (gAnimUid, p);
816  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
818  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
819  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
820  std::ostringstream oss;
821  oss << nodeAddr;
822  m_macToNodeIdMap[oss.str ()] = n->GetId ();
823  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
825 }
826 
827 void
830 {
831  //NS_LOG_UNCOND ("Context:" << context.c_str ());
832  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
833  return;
834  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
835  NS_ASSERT (ndev);
836  Ptr <Node> n = ndev->GetNode ();
837  NS_ASSERT (n);
838  uint64_t animUid = GetAnimUidFromPacket (p);
839  NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid);
841  {
842  NS_ASSERT (0);
843  NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
844  std::ostringstream oss;
845  WifiMacHeader hdr;
846  if (!p->PeekHeader (hdr))
847  {
848  NS_LOG_WARN ("WifiMacHeader not present");
849  return;
850  }
851  oss << hdr.GetAddr2 ();
852  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
853  {
854  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
855  return;
856  }
857  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
858  AnimPacketInfo pktInfo (0, Simulator::Now (), Simulator::Now (), UpdatePosition (txNode), m_macToNodeIdMap[oss.str ()]);
859  AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
860  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
861  }
863  m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ());
864  m_pendingWifiPackets[animUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
865  OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid].GetRxInfo (ndev), animUid);
866 }
867 
868 void
870 {
871  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
872  return;
873  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
874  NS_ASSERT (ndev);
875  Ptr <Node> n = ndev->GetNode ();
876  NS_ASSERT (n);
877  ++gAnimUid;
878  NS_LOG_INFO ("WimaxTxTrace for packet:" << gAnimUid);
879  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
881  AddByteTag (gAnimUid, p);
883  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
884 }
885 
886 
887 void
889 {
890  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
891  return;
892  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
893  NS_ASSERT (ndev);
894  Ptr <Node> n = ndev->GetNode ();
895  NS_ASSERT (n);
896  uint64_t animUid = GetAnimUidFromPacket (p);
897  NS_LOG_INFO ("WimaxRxTrace for packet:" << animUid);
899  AnimPacketInfo& pktInfo = m_pendingWimaxPackets[animUid];
900  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
901  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
903  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
904  OutputWirelessPacketRxInfo (p, pktrxInfo, animUid);
905 }
906 
907 void
909 {
910  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
911  return;
912  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
913  NS_ASSERT (ndev);
914  Ptr <Node> n = ndev->GetNode ();
915  NS_ASSERT (n);
916  ++gAnimUid;
917  NS_LOG_INFO ("LteTxTrace for packet:" << gAnimUid);
918  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
920  AddByteTag (gAnimUid, p);
922  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
923 }
924 
925 
926 void
928 {
929  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
930  return;
931  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
932  NS_ASSERT (ndev);
933  Ptr <Node> n = ndev->GetNode ();
934  NS_ASSERT (n);
935  uint64_t animUid = GetAnimUidFromPacket (p);
936  NS_LOG_INFO ("LteRxTrace for packet:" << gAnimUid);
938  {
939  NS_LOG_WARN ("LteRxTrace: unknown Uid");
940  return;
941  }
942  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
943  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
944  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
946  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
947  OutputWirelessPacketRxInfo (p, pktrxInfo, animUid);
948 }
949 
950 void
952 {
953  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
954  return;
955  if (!pb)
956  {
957  NS_LOG_WARN ("pb == 0. Not yet supported");
958  return;
959  }
960  context = "/" + context;
961  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
962  NS_ASSERT (ndev);
963  Ptr <Node> n = ndev->GetNode ();
964  NS_ASSERT (n);
965 
966  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
967  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
968  i != pbList.end ();
969  ++i)
970  {
971  Ptr <Packet> p = *i;
972  ++gAnimUid;
973  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
974  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
976  AddByteTag (gAnimUid, p);
978  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
979  }
980 }
981 
982 void
984 {
985  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
986  return;
987  if (!pb)
988  {
989  NS_LOG_WARN ("pb == 0. Not yet supported");
990  return;
991  }
992  context = "/" + context;
993  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
994  NS_ASSERT (ndev);
995  Ptr <Node> n = ndev->GetNode ();
996  NS_ASSERT (n);
997 
998  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
999  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1000  i != pbList.end ();
1001  ++i)
1002  {
1003  Ptr <Packet> p = *i;
1004  uint64_t animUid = GetAnimUidFromPacket (p);
1005  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1006  if (!IsPacketPending (animUid, AnimationInterface::LTE))
1007  {
1008  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1009  return;
1010  }
1011  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1012  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1013  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1015  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1016  OutputWirelessPacketRxInfo (p, pktrxInfo, animUid);
1017  }
1018 }
1019 
1020 void
1022 {
1023  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1024  return;
1025  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1026  NS_ASSERT (ndev);
1027  Ptr <Node> n = ndev->GetNode ();
1028  NS_ASSERT (n);
1029  ++gAnimUid;
1030  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1031  AddByteTag (gAnimUid, p);
1032  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1034 
1035 }
1036 
1037 void
1039 {
1040  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1041  return;
1042  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1043  NS_ASSERT (ndev);
1044  Ptr <Node> n = ndev->GetNode ();
1045  NS_ASSERT (n);
1046  uint64_t animUid = GetAnimUidFromPacket (p);
1047  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid);
1048  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1049  {
1050  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1051  NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid");
1052  AnimPacketInfo pktInfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1053  AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1054  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1055  }
1057  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1058  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1059 }
1060 
1061 void
1063 {
1064  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1065  return;
1066  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1067  NS_ASSERT (ndev);
1068  Ptr <Node> n = ndev->GetNode ();
1069  NS_ASSERT (n);
1070  uint64_t animUid = GetAnimUidFromPacket (p);
1071  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1072  {
1073  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1074  return;
1075  }
1077  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1078  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1079  pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1080  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid);
1081  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1082  if (pktrxInfo.IsPhyRxComplete ())
1083  {
1084  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1085  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1086  }
1087 }
1088 
1089 void
1092 {
1093  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1094  return;
1095  NS_LOG_FUNCTION (this);
1096  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1097  NS_ASSERT (ndev);
1098  Ptr <Node> n = ndev->GetNode ();
1099  NS_ASSERT (n);
1100  uint64_t animUid = GetAnimUidFromPacket (p);
1101  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1102  {
1103  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1104  return;
1105  }
1107  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1108  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1109  if (pktrxInfo.IsPhyRxComplete ())
1110  {
1111  NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete");
1112  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1113  }
1114 }
1115 
1116 void
1118 {
1120  uint32_t nodeId = 0;
1121  if (pktInfo.m_txnd)
1122  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1123  else
1124  nodeId = pktInfo.m_txNodeId;
1125  double lbTx = pktInfo.m_firstLastBitDelta + pktInfo.m_fbTx;
1126  WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, lbTx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1127 
1128 }
1129 
1130 void
1132 {
1134  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1135  WriteXmlP (animUid, "wpr", rxId, pktrxInfo.m_fbRx, pktrxInfo.m_lbRx);
1136 }
1137 
1138 void
1140 {
1142  NS_ASSERT (pktInfo.m_txnd);
1143  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1144  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1145 
1146  WriteXmlP ("p",
1147  nodeId,
1148  pktInfo.m_fbTx,
1149  pktInfo.m_lbTx,
1150  rxId,
1151  pktrxInfo.m_fbRx,
1152  pktrxInfo.m_lbRx,
1154 }
1155 
1156 void
1157 AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1158 {
1159  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1160  NS_ASSERT (pendingPackets);
1161  pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1162 }
1163 
1164 bool
1166 {
1167  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1168  NS_ASSERT (pendingPackets);
1169  return (pendingPackets->find (animUid) != pendingPackets->end ());
1170 }
1171 
1172 void
1174 {
1175  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1176  NS_ASSERT (pendingPackets);
1177  if (pendingPackets->empty ())
1178  return;
1179  std::vector <uint64_t> purgeList;
1180  for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1181  i != pendingPackets->end ();
1182  ++i)
1183  {
1184 
1185  AnimPacketInfo pktInfo = i->second;
1186  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1187  if (delta > PURGE_INTERVAL)
1188  {
1189  purgeList.push_back (i->first);
1190  }
1191  }
1192  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1193  i != purgeList.end ();
1194  ++i)
1195  {
1196  pendingPackets->erase (*i);
1197  }
1198 }
1199 
1202 {
1203  AnimUidPacketInfoMap * pendingPackets = 0;
1204  switch (protocolType)
1205  {
1207  {
1208  pendingPackets = &m_pendingWifiPackets;
1209  break;
1210  }
1212  {
1213  pendingPackets = &m_pendingUanPackets;
1214  break;
1215  }
1217  {
1218  pendingPackets = &m_pendingCsmaPackets;
1219  break;
1220  }
1222  {
1223  pendingPackets = &m_pendingWimaxPackets;
1224  break;
1225  }
1227  {
1228  pendingPackets = &m_pendingLtePackets;
1229  break;
1230  }
1231  }
1232  return pendingPackets;
1233 
1234 }
1235 
1236 // Counters
1237 
1238 std::string
1240 {
1241  std::string typeString = "unknown";
1242  switch (counterType)
1243  {
1244  case UINT32_COUNTER:
1245  {
1246  typeString = "UINT32";
1247  break;
1248  }
1249  case DOUBLE_COUNTER:
1250  {
1251  typeString = "DOUBLE";
1252  break;
1253  }
1254  }
1255  return typeString;
1256 }
1257 
1258 // General
1259 
1260 std::string
1262 {
1263  std::ostringstream oss;
1264  p->Print (oss);
1265  return oss.str ();
1266 }
1267 
1268 uint64_t
1270 {
1271  return m_currentPktCount;
1272 }
1273 
1274 void
1276 {
1277  m_started = false;
1278  NS_LOG_INFO ("Stopping Animation");
1280  if (m_f)
1281  {
1282  // Terminate the anim element
1283  WriteXmlClose ("anim");
1284  std::fclose (m_f);
1285  m_f = 0;
1286  }
1287  if (onlyAnimation)
1288  {
1289  return;
1290  }
1291  if (m_routingF)
1292  {
1293  WriteXmlClose ("anim", true);
1294  std::fclose (m_routingF);
1295  m_routingF = 0;
1296  }
1297 }
1298 
1299 void
1301 {
1302  m_currentPktCount = 0;
1303  m_started = true;
1305  WriteXmlAnim ();
1306  WriteNodes ();
1307  WriteNodeColors ();
1309  WriteNodeSizes ();
1310  WriteNodeEnergies ();
1311  if (!restart)
1312  {
1314  ConnectCallbacks ();
1315  }
1316 }
1317 
1318 void
1319 AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1320 {
1321  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1322 }
1323 
1324 
1325 // Callbacks
1326 void
1328 {
1329 
1330  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1331  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1332  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1333  std::ostringstream oss;
1334  //NodeList/*/DeviceList/*/
1335  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1336  if (dlPhy)
1337  {
1338  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1339  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1340  }
1341  if (ulPhy)
1342  {
1343  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1344  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1345  }
1346 }
1347 
1348 
1349 
1350 void
1352 {
1353 
1354  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1355  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1356  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1357  std::ostringstream oss;
1358  //NodeList/*/DeviceList/*/
1359  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1360  if (dlPhy)
1361  {
1362  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1363  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1364  }
1365  if (ulPhy)
1366  {
1367  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1368  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1369  }
1370 }
1371 
1372 void
1374 {
1375 
1376  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1377  {
1378  Ptr<Node> n = *i;
1379  NS_ASSERT (n);
1380  uint32_t nDevices = n->GetNDevices ();
1381  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1382  {
1383  Ptr <NetDevice> nd = n->GetDevice (devIndex);
1384  if (!nd)
1385  continue;
1386  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1387  if (lteUeNetDevice)
1388  {
1389  ConnectLteUe (n, lteUeNetDevice, devIndex);
1390  continue;
1391  }
1392  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1393  if (lteEnbNetDevice)
1394  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1395  }
1396 
1397  }
1398 }
1399 
1400 void
1402 {
1403  // Connect the callbacks
1404  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
1406  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
1408  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1410  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1412  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1414  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1416  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1418  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1420  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1422  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1424  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1426  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1428  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1430  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1432  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1434 
1435  ConnectLte ();
1436 
1437  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1439  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1441  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1443 
1444  // Queue Enqueues
1445 
1446  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1448  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1450  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1452 
1453  // Queue Dequeues
1454 
1455  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1457  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1459  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1461 
1462  // Queue Drops
1463 
1464  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1466  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1468  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1470 
1471 
1472  // Wifi Mac
1473  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1475  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1477  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1479  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1481 
1482  // Wifi Phy
1483  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1485  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1487 }
1488 
1489 Vector
1491 {
1493  if (loc)
1494  {
1495  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1496  }
1497  else
1498  {
1499  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1500  m_nodeLocation[n->GetId ()] = Vector (0, 0, 0);
1501  }
1502  return m_nodeLocation[n->GetId ()];
1503 }
1504 
1505 Vector
1507 {
1508  m_nodeLocation[n->GetId ()] = v;
1509  return v;
1510 }
1511 
1512 Vector
1514 {
1515  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1516  {
1517  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
1518  }
1519  return m_nodeLocation[n->GetId ()];
1520 }
1521 
1522 
1523 std::string
1525 {
1526  Address nodeAddr = nd->GetAddress ();
1527  std::ostringstream oss;
1528  oss << nodeAddr;
1529  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1530 }
1531 
1532 std::string
1534 {
1535  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1536  if (!ipv4)
1537  {
1538  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1539  return "0.0.0.0";
1540  }
1541  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1542  if (ifIndex == -1)
1543  {
1544  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1545  return "0.0.0.0";
1546  }
1547  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1548  std::ostringstream oss;
1549  oss << addr.GetLocal ();
1550  return oss.str ();
1551 }
1552 
1553 void
1555 {
1556  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1557  {
1558  Ptr<Node> n = *i;
1559  UpdatePosition (n);
1560  uint32_t n1Id = n->GetId ();
1561  uint32_t nDev = n->GetNDevices (); // Number of devices
1562  for (uint32_t i = 0; i < nDev; ++i)
1563  {
1564  Ptr<NetDevice> dev = n->GetDevice (i);
1565  NS_ASSERT (dev);
1566  Ptr<Channel> ch = dev->GetChannel ();
1567  if (!ch)
1568  {
1569  NS_LOG_DEBUG ("No channel can't be a p2p device");
1570  // Try to see if it is an LTE NetDevice, which does not return a channel
1571  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1572  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1573  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1574  {
1575  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
1577  }
1578  continue;
1579  }
1580  std::string channelType = ch->GetInstanceTypeId ().GetName ();
1581  NS_LOG_DEBUG ("Got ChannelType" << channelType);
1582  if (channelType == std::string ("ns3::PointToPointChannel"))
1583  { // Since these are duplex links, we only need to dump
1584  // if srcid < dstid
1585  uint32_t nChDev = ch->GetNDevices ();
1586  for (uint32_t j = 0; j < nChDev; ++j)
1587  {
1588  Ptr<NetDevice> chDev = ch->GetDevice (j);
1589  uint32_t n2Id = chDev->GetNode ()->GetId ();
1590  if (n1Id < n2Id)
1591  {
1592  // ouptut the p2p link
1593  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << ":" << GetMacAddress (dev) << "----" << GetIpv4Address (chDev) << ":" << GetMacAddress (chDev) );
1596  WriteXmlLink (n1Id, 0, n2Id);
1597  }
1598  }
1599  }
1600  else
1601  {
1602  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << " Channel Type:" << channelType << " Mac: " << GetMacAddress (dev));
1603  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1605  }
1606  }
1607  }
1608  m_linkProperties.clear ();
1609 }
1610 
1611 void
1613 {
1614  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1615  {
1616  Ptr<Node> n = *i;
1617  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
1618  Vector v = UpdatePosition (n);
1619  WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
1620  }
1621 }
1622 
1623 void
1625 {
1626  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1627  {
1628  Ptr<Node> n = *i;
1629  Rgb rgb = {255, 0, 0};
1630  if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
1631  {
1632  m_nodeColors[n->GetId ()] = rgb;
1633  }
1634  UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
1635  }
1636 }
1637 
1638 void
1640 {
1641  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1642  {
1643  Ptr<Node> n = *i;
1644  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
1645  AnimationInterface::NodeSize s = { 1, 1 };
1646  m_nodeSizes[n->GetId ()] = s;
1647  UpdateNodeSize (n->GetId (), s.width, s.height);
1648  }
1649 }
1650 
1651 void
1653 {
1655  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1656  {
1657  Ptr<Node> n = *i;
1658  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
1659  {
1661  }
1662  }
1663 }
1664 
1665 bool
1667 {
1668  if ((Simulator::Now () >= m_startTime) &&
1669  (Simulator::Now () <= m_stopTime))
1670  return true;
1671  else
1672  return false;
1673 }
1674 
1675 void
1676 AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
1677 {
1678  if (!routing && m_f)
1679  {
1680  return;
1681  }
1682  if (routing && m_routingF)
1683  {
1684  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
1685  return;
1686  }
1687 
1688  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
1689  FILE * f = 0;
1690  f = std::fopen (fn.c_str (), "w");
1691  if (!f)
1692  {
1693  NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ());
1694  return; // Can't open output file
1695  }
1696  if (routing)
1697  {
1698  m_routingF = f;
1699  m_routingFileName = fn;
1700  }
1701  else
1702  {
1703  m_f = f;
1704  m_outputFileName = fn;
1705  }
1706  return;
1707 }
1708 
1709 void
1711 {
1712  // Start a new trace file if the current packet count exceeded nax packets per file
1715  {
1716  return;
1717  }
1718  NS_LOG_UNCOND ("Max Packets per trace file exceeded");
1719  StopAnimation (true);
1720 }
1721 
1722 std::string
1724 {
1725  return NETANIM_VERSION;
1726 }
1727 
1728 
1729 // Routing
1730 
1731 void
1733 {
1734  if (m_ipv4RouteTrackElements.empty ())
1735  {
1736  return;
1737  }
1738  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
1739  i != m_ipv4RouteTrackElements.end ();
1740  ++i)
1741  {
1742  Ipv4RouteTrackElement trackElement = *i;
1743  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
1744  if (!fromNode)
1745  {
1746  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
1747  continue;
1748  }
1749  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1750  if (!ipv4)
1751  {
1752  NS_LOG_WARN ("ipv4 object not found");
1753  continue;
1754  }
1756  if (!rp)
1757  {
1758  NS_LOG_WARN ("Routing protocol object not found");
1759  continue;
1760  }
1761  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
1762  Ptr<Packet> pkt = Create<Packet> ();
1763  Ipv4Header header;
1764  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
1765  Socket::SocketErrno sockerr;
1766  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1767  Ipv4RoutePathElements rpElements;
1768  if (!rt)
1769  {
1770  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
1771  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1772  rpElements.push_back (elem);
1773  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1774  continue;
1775  }
1776  std::ostringstream oss;
1777  oss << rt->GetGateway ();
1778  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
1779  if (rt->GetGateway () == "0.0.0.0")
1780  {
1781  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
1782  rpElements.push_back (elem);
1783  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
1784  {
1785  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
1786  rpElements.push_back (elem2);
1787  }
1788  }
1789  else if (rt->GetGateway () == "127.0.0.1")
1790  {
1791  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1792  rpElements.push_back (elem);
1793  }
1794  else
1795  {
1796  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
1797  rpElements.push_back (elem);
1798  }
1799  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
1800  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1801  }
1802 
1803 }
1804 
1805 void
1807 {
1809  {
1810  NS_LOG_INFO ("TrackQueueCounters Completed");
1811  return;
1812  }
1813  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1814  {
1815  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1819  }
1821 }
1822 
1823 void
1825 {
1827  {
1828  NS_LOG_INFO ("TrackWifiMacCounters Completed");
1829  return;
1830  }
1831  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1832  {
1833  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1838  }
1840 }
1841 
1842 void
1844 {
1846  {
1847  NS_LOG_INFO ("TrackWifiPhyCounters Completed");
1848  return;
1849  }
1850  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1851  {
1852  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1855  }
1857 }
1858 
1859 void
1861 {
1863  {
1864  NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed");
1865  return;
1866  }
1867  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1868  {
1869  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1873  }
1875 }
1876 
1877 void
1879 {
1881  {
1882  NS_LOG_INFO ("TrackIpv4Route completed");
1883  return;
1884  }
1885  if (m_routingNc.GetN ())
1886  {
1887  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
1888  {
1889  Ptr <Node> n = *i;
1891  }
1892  }
1893  else
1894  {
1895  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1896  {
1897  Ptr <Node> n = *i;
1899  }
1900  }
1903 }
1904 
1905 std::string
1907 {
1908 
1909  NS_ASSERT (n);
1910  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
1911  if (!ipv4)
1912  {
1913  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
1914  return "";
1915  }
1916  std::stringstream stream;
1917  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
1918  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
1919  return stream.str ();
1920 
1921 }
1922 
1923 void
1924 AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
1925 {
1926  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
1927  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
1928  {
1929  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
1930  return;
1931  }
1932  Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
1934  if (fromNode->GetId () == toNode->GetId ())
1935  {
1936  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
1937  rpElements.push_back (elem);
1938  return;
1939  }
1940  if (!fromNode)
1941  {
1942  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
1943  return;
1944  }
1945  if (!toNode)
1946  {
1947  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
1948  return;
1949  }
1950  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1951  if (!ipv4)
1952  {
1953  NS_LOG_WARN ("ipv4 object not found");
1954  return;
1955  }
1957  if (!rp)
1958  {
1959  NS_LOG_WARN ("Routing protocol object not found");
1960  return;
1961  }
1962  Ptr<Packet> pkt = Create<Packet> ();
1963  Ipv4Header header;
1964  header.SetDestination (Ipv4Address (to.c_str ()));
1965  Socket::SocketErrno sockerr;
1966  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1967  if (!rt)
1968  {
1969  return;
1970  }
1971  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
1972  std::ostringstream oss;
1973  oss << rt->GetGateway ();
1974  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
1975  {
1976  NS_LOG_INFO ("Null gw");
1977  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
1978  rpElements.push_back (elem);
1979  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
1980  {
1981  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
1982  rpElements.push_back (elem2);
1983  }
1984  return;
1985  }
1986  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
1987  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
1988  rpElements.push_back (elem);
1989  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
1990 
1991 }
1992 
1993 
1994 // XML
1995 
1997  m_tagName (tagName)
1998 {
1999  m_elementString = "<" + tagName + " ";
2000 }
2001 
2002 template <typename T>
2003 void
2005 {
2006  std::ostringstream oss;
2007  oss << std::setprecision (10);
2008  oss << value;
2009  m_elementString += attribute.c_str ();
2010  m_elementString += "=\"" + oss.str () + "\" ";
2011 }
2012 
2013 void
2015 {
2016  m_elementString += ">\n";
2017 }
2018 
2019 void
2021 {
2022  m_elementString += ">";
2023 }
2024 
2025 void
2027 {
2028  m_elementString += "\n";
2029 }
2030 
2031 void
2033 {
2034  m_elementString += e.GetElementString ();
2035 }
2036 
2037 std::string
2039 {
2040  return m_elementString;
2041 }
2042 
2043 
2044 void
2046 {
2047  AnimXmlElement element ("anim");
2048  element.AddAttribute ("ver", GetNetAnimVersion ());
2049  element.Close ();
2050  if (!routing)
2051  {
2052  WriteN (element.GetElementString (), m_f);
2053  }
2054  else
2055  {
2056  WriteN (element.GetElementString (), m_routingF);
2057  }
2058 }
2059 
2060 void
2061 AnimationInterface::WriteXmlClose (std::string name, bool routing)
2062 {
2063  std::string closeString = "</" + name + ">\n";
2064  if (!routing)
2065  {
2066  WriteN (closeString, m_f);
2067  }
2068  else
2069  {
2070  WriteN (closeString, m_routingF);
2071  }
2072 }
2073 
2074 void
2075 AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2076 {
2077  AnimXmlElement element ("node");
2078  element.AddAttribute ("id", id);
2079  element.AddAttribute ("sysId", sysId);
2080  element.AddAttribute ("locX", locX);
2081  element.AddAttribute ("locY", locY);
2082  element.Close ();
2083  WriteN (element.GetElementString (), m_f);
2084 }
2085 
2086 void
2087 AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2088 {
2089  AnimXmlElement element ("linkupdate");
2090  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2091  element.AddAttribute ("fromId", fromId);
2092  element.AddAttribute ("toId", toId);
2093  element.AddAttribute ("ld", linkDescription);
2094  element.Close ();
2095  WriteN (element.GetElementString (), m_f);
2096 }
2097 
2098 void
2099 AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2100 {
2101  AnimXmlElement element ("link");
2102  element.AddAttribute ("fromId", fromId);
2103  element.AddAttribute ("toId", toId);
2104 
2105  LinkProperties lprop ;
2106  lprop.fromNodeDescription = "";
2107  lprop.toNodeDescription = "";
2108  lprop.linkDescription = "";
2109 
2110  P2pLinkNodeIdPair p1 = { fromId, toId };
2111  P2pLinkNodeIdPair p2 = { toId, fromId };
2112  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2113  {
2114  lprop = m_linkProperties[p1];
2115  }
2116  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2117  {
2118  lprop = m_linkProperties[p2];
2119  }
2120 
2121  element.AddAttribute ("fd", lprop.fromNodeDescription);
2122  element.AddAttribute ("td", lprop.toNodeDescription);
2123  element.AddAttribute ("ld", lprop.linkDescription);
2124  element.Close ();
2125  WriteN (element.GetElementString (), m_f);
2126 }
2127 
2128 void
2129 AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2130 {
2131  AnimXmlElement element ("rt");
2132  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2133  element.AddAttribute ("id", nodeId);
2134  element.AddAttribute ("info", routingInfo.c_str ());
2135  element.Close ();
2136  WriteN (element.GetElementString (), m_routingF);
2137 }
2138 
2139 void
2140 AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2141 {
2142  AnimXmlElement element ("rp");
2143  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2144  element.AddAttribute ("id", nodeId);
2145  element.AddAttribute ("d", destination.c_str ());
2146  element.AddAttribute ("c", rpElements.size ());
2147  element.CloseTag ();
2148  element.AddLineBreak ();
2149  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2150  i != rpElements.end ();
2151  ++i)
2152  {
2153  Ipv4RoutePathElement rpElement = *i;
2154  AnimXmlElement rpeElement ("rpe");
2155  rpeElement.AddAttribute ("n", rpElement.nodeId);
2156  rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2157  rpeElement.Close ();
2158  element.Add (rpeElement);
2159  }
2160  WriteN (element.GetElementString (), m_routingF);
2161 }
2162 
2163 
2164 void
2165 AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, double lbTx, std::string metaInfo)
2166 {
2167  AnimXmlElement element ("pr");
2168  element.AddAttribute ("uId", animUid);
2169  element.AddAttribute ("fId", fId);
2170  element.AddAttribute ("fbTx", fbTx);
2171  element.AddAttribute ("lbTx", lbTx);
2172  if (!metaInfo.empty ())
2173  {
2174  element.AddAttribute ("meta-info", metaInfo.c_str ());
2175  }
2176  element.Close ();
2177  WriteN (element.GetElementString (), m_f);
2178 }
2179 
2180 void
2181 AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2182 {
2183  AnimXmlElement element (pktType);
2184  element.AddAttribute ("uId", animUid);
2185  element.AddAttribute ("tId", tId);
2186  element.AddAttribute ("fbRx", fbRx);
2187  element.AddAttribute ("lbRx", lbRx);
2188  element.Close ();
2189  WriteN (element.GetElementString (), m_f);
2190 }
2191 
2192 void
2193 AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2194  uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2195 {
2196  AnimXmlElement element (pktType);
2197  element.AddAttribute ("fId", fId);
2198  element.AddAttribute ("fbTx", fbTx);
2199  element.AddAttribute ("lbTx", lbTx);
2200  if (!metaInfo.empty ())
2201  {
2202  element.AddAttribute ("meta-info", metaInfo.c_str ());
2203  }
2204  element.AddAttribute ("tId", tId);
2205  element.AddAttribute ("fbRx", fbRx);
2206  element.AddAttribute ("lbRx", lbRx);
2207  element.Close ();
2208  WriteN (element.GetElementString (), m_f);
2209 }
2210 
2211 void
2212 AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2213 {
2214  AnimXmlElement element ("ncs");
2215  element.AddAttribute ("ncId", nodeCounterId);
2216  element.AddAttribute ("n", counterName);
2217  element.AddAttribute ("t", CounterTypeToString (counterType));
2218  element.Close ();
2219  WriteN (element.GetElementString (), m_f);
2220 }
2221 
2222 void
2223 AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2224 {
2225  AnimXmlElement element ("res");
2226  element.AddAttribute ("rid", resourceId);
2227  element.AddAttribute ("p", resourcePath);
2228  element.Close ();
2229  WriteN (element.GetElementString (), m_f);
2230 }
2231 
2232 void
2233 AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2234 {
2235  AnimXmlElement element ("nu");
2236  element.AddAttribute ("p", "i");
2237  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2238  element.AddAttribute ("id", nodeId);
2239  element.AddAttribute ("rid", resourceId);
2240  element.Close ();
2241  WriteN (element.GetElementString (), m_f);
2242 }
2243 
2244 void
2245 AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2246 {
2247  AnimXmlElement element ("nu");
2248  element.AddAttribute ("p", "s");
2249  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2250  element.AddAttribute ("id", nodeId);
2251  element.AddAttribute ("w", width);
2252  element.AddAttribute ("h", height);
2253  element.Close ();
2254  WriteN (element.GetElementString (), m_f);
2255 }
2256 
2257 void
2258 AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2259 {
2260  AnimXmlElement element ("nu");
2261  element.AddAttribute ("p", "p");
2262  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2263  element.AddAttribute ("id", nodeId);
2264  element.AddAttribute ("x", x);
2265  element.AddAttribute ("y", y);
2266  element.Close ();
2267  WriteN (element.GetElementString (), m_f);
2268 }
2269 
2270 void
2271 AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2272 {
2273  AnimXmlElement element ("nu");
2274  element.AddAttribute ("p", "c");
2275  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2276  element.AddAttribute ("id", nodeId);
2277  element.AddAttribute ("r", (uint32_t) r);
2278  element.AddAttribute ("g", (uint32_t) g);
2279  element.AddAttribute ("b", (uint32_t) b);
2280  element.Close ();
2281  WriteN (element.GetElementString (), m_f);
2282 }
2283 
2284 void
2286 {
2287  AnimXmlElement element ("nu");
2288  element.AddAttribute ("p", "d");
2289  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2290  element.AddAttribute ("id", nodeId);
2291  if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2292  {
2293  element.AddAttribute ("descr", m_nodeDescriptions[nodeId]);
2294  }
2295  element.Close ();
2296  WriteN (element.GetElementString (), m_f);
2297 }
2298 
2299 
2300 void
2301 AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2302 {
2303  AnimXmlElement element ("nc");
2304  element.AddAttribute ("c", nodeCounterId);
2305  element.AddAttribute ("i", nodeId);
2306  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2307  element.AddAttribute ("v", counterValue);
2308  element.Close ();
2309  WriteN (element.GetElementString (), m_f);
2310 }
2311 
2312 void
2313 AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2314 {
2315  AnimXmlElement element ("bg");
2316  element.AddAttribute ("f", fileName);
2317  element.AddAttribute ("x", x);
2318  element.AddAttribute ("y", y);
2319  element.AddAttribute ("sx", scaleX);
2320  element.AddAttribute ("sy", scaleY);
2321  element.AddAttribute ("o", opacity);
2322  element.Close ();
2323  WriteN (element.GetElementString (), m_f);
2324 }
2325 
2326 void
2327 AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2328 {
2329  AnimXmlElement element ("nonp2plinkproperties");
2330  element.AddAttribute ("id", id);
2331  element.AddAttribute ("ipv4Address", ipv4Address);
2332  element.AddAttribute ("channelType", channelType);
2333  element.Close ();
2334  WriteN (element.GetElementString (), m_f);
2335 }
2336 
2337 TypeId
2339 {
2340  static TypeId tid = TypeId ("ns3::AnimByteTag")
2341  .SetParent<Tag> ()
2342  .AddConstructor<AnimByteTag> ()
2343  ;
2344  return tid;
2345 }
2346 
2347 TypeId
2349 {
2350  return GetTypeId ();
2351 }
2352 
2353 uint32_t
2355 {
2356  return sizeof (uint64_t);
2357 }
2358 
2359 void
2361 {
2362  i.WriteU64 (m_AnimUid);
2363 }
2364 
2365 void
2367 {
2368  m_AnimUid = i.ReadU64 ();
2369 }
2370 
2371 void
2372 AnimByteTag::Print (std::ostream &os) const
2373 {
2374  os << "AnimUid=" << m_AnimUid;
2375 }
2376 
2377 void
2378 AnimByteTag::Set (uint64_t AnimUid)
2379 {
2380  m_AnimUid = AnimUid;
2381 }
2382 
2383 uint64_t
2384 AnimByteTag::Get (void) const
2385 {
2386  return m_AnimUid;
2387 }
2388 
2390  : m_txnd (0),
2391  m_txNodeId (0),
2392  m_fbTx (0),
2393  m_lbTx (0),
2394  m_txLoc (Vector (0,0,0)),
2395  m_firstLastBitDelta (0)
2396 {
2397 }
2398 
2400 {
2401  m_txnd = pInfo.m_txnd;
2402  m_txNodeId = pInfo.m_txNodeId;
2403  m_fbTx = pInfo.m_fbTx;
2404  m_lbTx = pInfo.m_lbTx;
2405  m_txLoc = pInfo.m_txLoc;
2406  m_firstLastBitDelta = pInfo.m_firstLastBitDelta;
2407 }
2408 
2410  const Time fbTx,
2411  const Time lbTx,
2412  Vector txLoc,
2413  uint32_t txNodeId)
2414  : m_txnd (txnd),
2415  m_txNodeId (0),
2416  m_fbTx (fbTx.GetSeconds ()),
2417  m_lbTx (lbTx.GetSeconds ()),
2418  m_txLoc (txLoc),
2419  m_firstLastBitDelta (0)
2420 {
2421  if (!m_txnd)
2422  m_txNodeId = txNodeId;
2423 }
2424 
2425 void
2427 {
2428  m_rx[nd->GetNode ()->GetId ()] = AnimRxInfo (fbRx, nd, 0);
2429 }
2430 
2431 bool
2433 {
2434  uint32_t NodeId = nd->GetNode ()->GetId ();
2435  // Find the RxInfo
2436  if (m_rx.find (NodeId) == m_rx.end ())
2437  {
2438  return false;
2439  }
2440  AnimRxInfo& rxInfo = m_rx[NodeId];
2441  // Check if the NetDevice matches. A node may have several NetDevices
2442  if (rxInfo.m_rxnd != nd)
2443  {
2444  return false;
2445  }
2446  rxInfo.rxRange = CalculateDistance (m_txLoc, rxLoc);
2447  rxInfo.m_lbRx = lbRx.GetSeconds ();
2448  rxInfo.SetPhyRxComplete ();
2449  m_firstLastBitDelta = rxInfo.m_lbRx - rxInfo.m_fbRx;
2450  return true;
2451 }
2452 
2455 {
2456  uint32_t NodeId = nd->GetNode ()->GetId ();
2457  NS_ASSERT (m_rx.find (NodeId) != m_rx.end ());
2458  return m_rx[NodeId];
2459 }
2460 
2461 void
2463 {
2464  uint32_t NodeId = nd->GetNode ()->GetId ();
2465  m_rx.erase (m_rx.find (NodeId));
2466 }
2467 
2468 void
2470 {
2471 }
2472 
2473 bool
2475 {
2476  return m_PhyRxComplete;
2477 }
2478 
2479 void
2481 {
2482  m_PhyRxComplete = true;
2483 }
2484 
2485 } // namespace ns3
bool HasNext(void) const
Definition: packet.cc:65
uint64_t GetAnimUidFromPacket(Ptr< const Packet >)
void Set(uint64_t AnimUid)
Set global Uid in tag.
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing)
void AddToIpv4AddressNodeIdTable(std::string, uint32_t)
void UpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Helper function to update the image of a node.
void WriteXmlRp(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
double x
x coordinate of vector
Definition: vector.h:49
void AddPendingPacket(ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
void CsmaMacRxTrace(std::string context, Ptr< const Packet > p)
void WriteXmlNonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
NodeCounterMap64 m_nodeQueueDequeue
void WifiMacRxTrace(std::string context, Ptr< const Packet >)
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ipv4Address GetLocal(void) const
Get the local address.
std::string GetIpv4Address(Ptr< NetDevice > nd)
std::string CounterTypeToString(CounterType counterType)
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
AnimationInterface(const std::string filename)
Constructor.
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:240
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP.
void WriteXmlUpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
static TypeId GetTypeId(void)
Get Type Id.
Doxygen introspection did not find any typical Config paths.
Definition: energy-source.h:81
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
Ptr< LteEnbPhy > GetPhy(void) const
Mobility model for which the current position does not change once it has been set and until it is se...
AnimUidPacketInfoMap m_pendingWifiPackets
void WriteXmlUpdateNodePosition(uint32_t nodeId, double x, double y)
NodeDescriptionsMap m_nodeDescriptions
static bool IsInitialized(void)
Check if AnimationInterface is initialized.
void PurgePendingPackets(ProtocolType protocolType)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
void RemoveRxInfo(Ptr< const NetDevice > nd)
void QueueDropTrace(std::string context, Ptr< const Packet >)
#define NETANIM_VERSION
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, double lbTx, std::string metaInfo="")
void OutputCsmaPacket(Ptr< const Packet > p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
std::map< std::string, uint32_t > m_macToNodeIdMap
void LteSpectrumPhyRxStart(std::string context, Ptr< const PacketBurst > pb)
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Vector GetPosition(void) const
void WifiPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
void EnableWifiPhyCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Wifi Phy Counters such as TxDrop, RxDrop.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
void WriteXmlAnim(bool routing=false)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
NodeCounterMap64 m_nodeWifiPhyTxDrop
void LteTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void WimaxRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
std::map< std::string, uint32_t > m_ipv4ToNodeIdMap
void RecursiveIpv4RoutePathSearch(std::string fromIpv4, std::string toIpv4, Ipv4RoutePathElements &)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
void UpdateNodeSize(uint32_t nodeId, double width, double height)
Helper function to update the size of a node.
virtual void Deserialize(TagBuffer i)
Deserialize function.
void ProcessRxBegin(Ptr< const NetDevice > nd, const Time fbRx)
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
void WriteXmlAddNodeCounter(uint32_t counterId, std::string counterName, CounterType counterType)
AnimRxInfo GetRxInfo(Ptr< const NetDevice > nd)
void ConnectLteEnb(Ptr< Node > n, Ptr< LteEnbNetDevice > nd, uint32_t devIndex)
std::string GetIpv4RoutingTable(Ptr< Node > n)
void WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
void Print(std::ostream &os) const
Print the packet contents.
Definition: packet.cc:429
bool ProcessRxEnd(Ptr< const NetDevice > nd, const Time fbRx, Vector rxLoc)
void WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void SetStartTime(Time t)
Specify the time at which capture should start.
void SetStopTime(Time t)
Specify the time at which capture should stop.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
std::vector< Ptr< Node > > GetMovedNodes()
LinkPropertiesMap m_linkProperties
uint32_t GetSystemId(void) const
Definition: node.cc:113
a 3d vector
Definition: vector.h:31
void WifiPhyRxBeginTrace(std::string context, Ptr< const Packet > p)
void Ipv4TxTrace(std::string context, Ptr< const Packet >, Ptr< Ipv4 >, uint32_t)
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color.
double stopTime
void WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
void ResetAnimWriteCallback()
Reset the write callback function.
NodeCounterMap64 m_nodeWifiMacTx
AnimWriteCallback m_writeCallback
a polymophic address class
Definition: address.h:86
void AddAttribute(std::string attribute, T value)
void UanPhyGenTxTrace(std::string context, Ptr< const Packet >)
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
void WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string)
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
DropReason
Reason why a packet has been dropped.
void ConnectLteUe(Ptr< Node > n, Ptr< LteUeNetDevice > nd, uint32_t devIndex)
std::map< uint32_t, Vector > m_nodeLocation
virtual void Print(std::ostream &os) const
Print tag info.
Keep track of the current position and velocity of an object.
Packet header for IPv4.
Definition: ipv4-header.h:31
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:322
void SetBackgroundImage(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Helper function to set the background image.
void CsmaPhyRxEndTrace(std::string context, Ptr< const Packet > p)
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition: packet.h:57
void RemainingEnergyTrace(std::string context, double previousEnergy, double currentEnergy)
void WifiMacRxDropTrace(std::string context, Ptr< const Packet >)
void WriteXmlClose(std::string name, bool routing=false)
void OutputWirelessPacketTxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
void EnableWifiMacCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Wifi Mac Counters such as Tx, TxDrop, Rx, RxDrop.
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:552
void UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
Helper function to update a node's counter referenced by the nodeCounterId.
uint32_t AddNodeCounter(std::string counterName, CounterType counterType)
Setup a node counter.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:71
~AnimationInterface()
Destructor for the animator interface.
AnimUidPacketInfoMap m_pendingWimaxPackets
EnergyFractionMap m_nodeEnergyFraction
void SkipPacketTracing()
Do not trace packets.
double startTime
static Iterator End(void)
Definition: node-list.cc:234
uint8_t data[writeSize]
Ptr< SampleEmitter > s
double GetNodeEnergyFraction(Ptr< const Node > node) const
Get node's energy fraction (This used only for testing)
Ptr< Node > GetNodeFromContext(const std::string &context) const
Vector3D Vector
Definition: vector.h:118
void DequeueTrace(std::string context, Ptr< const Packet >)
NodeCounterMap64 m_nodeIpv4Drop
void UanPhyGenRxTrace(std::string context, Ptr< const Packet >)
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:134
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1283
ByteTagIterator GetByteTagIterator(void) const
Retiurns an iterator over the set of byte tags included in this packet.
Definition: packet.cc:818
void WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, uint32_t tId, double fbRx, double lbRx, std::string metaInfo="")
Item Next(void)
Definition: packet.cc:70
void WifiMacTxTrace(std::string context, Ptr< const Packet >)
void StartAnimation(bool restart=false)
void WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
std::vector< Ipv4RoutePathElement > Ipv4RoutePathElements
AnimationInterface & EnableIpv4RouteTracking(std::string fileName, Time startTime, Time stopTime, Time pollInterval=Seconds(5))
Enable tracking of the Ipv4 routing table for all Nodes.
std::map< uint32_t, NodeSize > m_nodeSizes
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
#define list
void CsmaPhyTxEndTrace(std::string context, Ptr< const Packet > p)
std::string GetPacketMetadata(Ptr< const Packet > p)
std::vector< std::string > m_resources
int WriteN(const char *, uint32_t, FILE *f)
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void DevTxTrace(std::string context, Ptr< const Packet > p, Ptr< NetDevice > tx, Ptr< NetDevice > rx, Time txTime, Time rxTime)
uint32_t GetNDevices(void) const
Definition: node.cc:142
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
tag a set of bytes in a packet
Definition: tag.h:36
void WriteXmlRouting(uint32_t id, std::string routingInfo)
void Ipv4RxTrace(std::string context, Ptr< const Packet >, Ptr< Ipv4 >, uint32_t)
keep track of a set of node pointers.
void UpdateLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription)
Helper function to update the description for a link.
uint64_t ReadU64(void)
Definition: tag-buffer.cc:134
uint32_t AddResource(std::string resourcePath)
Add a resource such as the path to an image file.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetMaxPktsPerTraceFile(uint64_t maxPktsPerFile)
Set Max packets per trace file.
bool NodeHasMoved(Ptr< Node > n, Vector newLocation)
Iterator over the set of byte tags in a packet.
Definition: packet.h:50
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
an EUI-48 address
Definition: mac48-address.h:41
NodeCounterMap64 m_nodeQueueDrop
double y
y coordinate of vector
Definition: vector.h:53
AnimUidPacketInfoMap m_pendingLtePackets
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
std::map< uint64_t, AnimPacketInfo > AnimUidPacketInfoMap
TypeId GetTypeId(void) const
Definition: packet.cc:34
virtual void Serialize(TagBuffer i) const
Serialize function.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
const std::vector< std::string > GetElementsFromContext(const std::string &context) const
void WriteXmlUpdateNodeDescription(uint32_t nodeId)
void EnqueueTrace(std::string context, Ptr< const Packet >)
Byte tag using by Anim to uniquely identify packets.
virtual TypeId GetInstanceTypeId(void) const
Get Instance Type Id.
void StopAnimation(bool onlyAnimation=false)
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:49
void WriteXmlUpdateNodeCounter(uint32_t counterId, uint32_t nodeId, double value)
Vector UpdatePosition(Ptr< Node > n)
uint64_t Get(void) const
Get Uid in tag.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
std::vector< Ipv4RouteTrackElement > m_ipv4RouteTrackElements
NodeCounterMap64 m_nodeWifiMacRxDrop
void WifiMacTxDropTrace(std::string context, Ptr< const Packet >)
void MobilityCourseChangeTrace(Ptr< const MobilityModel > mob)
read and write tag data
Definition: tag-buffer.h:51
NodeCounterMap64 m_nodeWifiPhyRxDrop
bool IsPacketPending(uint64_t animUid, ProtocolType protocolType)
uint32_t GetId(void) const
Definition: node.cc:106
a class to store IPv4 address information on an interface
static bool initialized
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
std::string GetMacAddress(Ptr< NetDevice > nd)
static Iterator Begin(void)
Definition: node-list.cc:228
NodeCounterMap64 m_nodeWifiMacRx
AnimUidPacketInfoMap m_pendingUanPackets
#define MAX_PKTS_PER_TRACE_FILE
void AddByteTag(uint64_t animUid, Ptr< const Packet > p)
A network Node.
Definition: node.h:55
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
void WriteXmlUpdateBackground(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
virtual uint32_t GetSerializedSize(void) const
Get Serialized Size.
Interface to network animator.
void WriteNonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
static bool IsFinished(void)
If there are no more events lefts to be scheduled, or if simulation time has already reached the "sto...
Definition: simulator.cc:150
void ProcessRxDrop(Ptr< const NetDevice > nd)
void SetAnimWriteCallback(AnimWriteCallback cb)
Set a callback function to listen to AnimationInterface write events.
void SetMobilityPollInterval(Time t)
Set mobility poll interval:WARNING: setting a low interval can cause slowness.
void Ipv4DropTrace(std::string context, const Ipv4Header &, Ptr< const Packet >, Ipv4L3Protocol::DropReason, Ptr< Ipv4 >, uint32_t)
NodeCounterMap64 m_nodeQueueEnqueue
void WriteRoutePath(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
bool IsStarted(void)
Is AnimationInterface started.
void EnableIpv4L3ProtocolCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Ipv4 L3 Protocol Counters such as Tx, Rx, Drop.
AnimUidPacketInfoMap * ProtocolTypeToPendingPackets(ProtocolType protocolType)
void OutputWirelessPacketRxInfo(Ptr< const Packet > p, AnimRxInfo pktrxInfo, uint64_t animUid)
void EnableQueueCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Queue Counters such as Enqueue, Dequeue, Queue Drops.
Ptr< T > GetObject(void) const
Definition: object.h:362
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet >)
Vector GetPosition(Ptr< Node > n)
a unique identifier for an interface.
Definition: type-id.h:49
NodeCounterMap64 m_nodeWifiMacTxDrop
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::vector< std::string > m_nodeCounters
void WifiPhyTxDropTrace(std::string context, Ptr< const Packet >)
void LteRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:727
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
#define PURGE_INTERVAL
void SetOutputFile(const std::string &fn, bool routing=false)
void LteSpectrumPhyTxStart(std::string context, Ptr< const PacketBurst > pb)
AnimUidPacketInfoMap m_pendingCsmaPackets
void WriteXmlLink(uint32_t fromId, uint32_t toLp, uint32_t toId)
void WimaxTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808