This documentation is not the Latest Release.
A Discrete-Event Network Simulator
API
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 namespace ns3 {
55 
56 NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
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);
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  UpdatePosition (n);
777  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
780 }
781 
782 void
784 {
785  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
786  return;
787  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
788  NS_ASSERT (ndev);
789  Ptr <Node> n = ndev->GetNode ();
790  NS_ASSERT (n);
791  uint64_t animUid = GetAnimUidFromPacket (p);
792  NS_LOG_INFO ("UanPhyGenRxTrace for packet:" << animUid);
794  {
795  NS_LOG_WARN ("UanPhyGenRxBeginTrace: unknown Uid");
796  return;
797  }
798  UpdatePosition (n);
799  m_pendingUanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
800  OutputWirelessPacketRxInfo (p, m_pendingUanPackets[animUid], animUid);
801 }
802 
803 
804 void
807 {
808  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
809  return;
810  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
811  NS_ASSERT (ndev);
812  Ptr <Node> n = ndev->GetNode ();
813  NS_ASSERT (n);
814  ++gAnimUid;
815  NS_LOG_INFO ("Wifi TxBeginTrace for packet:" << gAnimUid);
816  AddByteTag (gAnimUid, p);
817  UpdatePosition (n);
818  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
820  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
821  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
822  std::ostringstream oss;
823  oss << nodeAddr;
824  m_macToNodeIdMap[oss.str ()] = n->GetId ();
825  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
827 }
828 
829 void
832 {
833  //NS_LOG_UNCOND ("Context:" << context.c_str ());
834  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
835  return;
836  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
837  NS_ASSERT (ndev);
838  Ptr <Node> n = ndev->GetNode ();
839  NS_ASSERT (n);
840  uint64_t animUid = GetAnimUidFromPacket (p);
841  NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid);
843  {
844  NS_ASSERT (0);
845  NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
846  std::ostringstream oss;
847  WifiMacHeader hdr;
848  if (!p->PeekHeader (hdr))
849  {
850  NS_LOG_WARN ("WifiMacHeader not present");
851  return;
852  }
853  oss << hdr.GetAddr2 ();
854  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
855  {
856  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
857  return;
858  }
859  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
860  UpdatePosition (txNode);
861  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
862  AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
863  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
864  }
866  UpdatePosition (n);
867  m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
868  OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid);
869 }
870 
871 void
873 {
874  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
875  return;
876  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
877  NS_ASSERT (ndev);
878  Ptr <Node> n = ndev->GetNode ();
879  NS_ASSERT (n);
880  ++gAnimUid;
881  NS_LOG_INFO ("WimaxTxTrace for packet:" << gAnimUid);
882  UpdatePosition (n);
883  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
884  AddByteTag (gAnimUid, p);
886  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
887 }
888 
889 
890 void
892 {
893  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
894  return;
895  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
896  NS_ASSERT (ndev);
897  Ptr <Node> n = ndev->GetNode ();
898  NS_ASSERT (n);
899  uint64_t animUid = GetAnimUidFromPacket (p);
900  NS_LOG_INFO ("WimaxRxTrace for packet:" << animUid);
902  AnimPacketInfo& pktInfo = m_pendingWimaxPackets[animUid];
903  UpdatePosition (n);
904  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
905  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
906 }
907 
908 void
910 {
911  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
912  return;
913  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
914  NS_ASSERT (ndev);
915  Ptr <Node> n = ndev->GetNode ();
916  NS_ASSERT (n);
917  ++gAnimUid;
918  NS_LOG_INFO ("LteTxTrace for packet:" << gAnimUid);
919  UpdatePosition (n);
920  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
921  AddByteTag (gAnimUid, p);
923  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
924 }
925 
926 
927 void
929 {
930  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
931  return;
932  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
933  NS_ASSERT (ndev);
934  Ptr <Node> n = ndev->GetNode ();
935  NS_ASSERT (n);
936  uint64_t animUid = GetAnimUidFromPacket (p);
937  NS_LOG_INFO ("LteRxTrace for packet:" << gAnimUid);
939  {
940  NS_LOG_WARN ("LteRxTrace: unknown Uid");
941  return;
942  }
943  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
944  UpdatePosition (n);
945  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
946  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
947 }
948 
949 void
951 {
952  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
953  return;
954  if (!pb)
955  {
956  NS_LOG_WARN ("pb == 0. Not yet supported");
957  return;
958  }
959  context = "/" + context;
960  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
961  NS_ASSERT (ndev);
962  Ptr <Node> n = ndev->GetNode ();
963  NS_ASSERT (n);
964 
965  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
966  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
967  i != pbList.end ();
968  ++i)
969  {
970  Ptr <Packet> p = *i;
971  ++gAnimUid;
972  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
973  UpdatePosition (n);
974  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
975  AddByteTag (gAnimUid, p);
977  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
978  }
979 }
980 
981 void
983 {
984  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
985  return;
986  if (!pb)
987  {
988  NS_LOG_WARN ("pb == 0. Not yet supported");
989  return;
990  }
991  context = "/" + context;
992  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
993  NS_ASSERT (ndev);
994  Ptr <Node> n = ndev->GetNode ();
995  NS_ASSERT (n);
996 
997  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
998  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
999  i != pbList.end ();
1000  ++i)
1001  {
1002  Ptr <Packet> p = *i;
1003  uint64_t animUid = GetAnimUidFromPacket (p);
1004  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1005  if (!IsPacketPending (animUid, AnimationInterface::LTE))
1006  {
1007  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1008  return;
1009  }
1010  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1011  UpdatePosition (n);
1012  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1013  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
1014  }
1015 }
1016 
1017 void
1019 {
1020  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1021  return;
1022  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1023  NS_ASSERT (ndev);
1024  Ptr <Node> n = ndev->GetNode ();
1025  NS_ASSERT (n);
1026  ++gAnimUid;
1027  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1028  AddByteTag (gAnimUid, p);
1029  UpdatePosition (n);
1030  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1032 
1033 }
1034 
1035 void
1037 {
1038  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1039  return;
1040  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1041  NS_ASSERT (ndev);
1042  Ptr <Node> n = ndev->GetNode ();
1043  NS_ASSERT (n);
1044  uint64_t animUid = GetAnimUidFromPacket (p);
1045  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid);
1046  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1047  {
1048  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1049  NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid");
1050  UpdatePosition (n);
1051  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1052  AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1053  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1054  }
1056  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1057  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1058 }
1059 
1060 void
1062 {
1063  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1064  return;
1065  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1066  NS_ASSERT (ndev);
1067  Ptr <Node> n = ndev->GetNode ();
1068  NS_ASSERT (n);
1069  uint64_t animUid = GetAnimUidFromPacket (p);
1070  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1071  {
1072  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1073  return;
1074  }
1076  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1077  UpdatePosition (n);
1078  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1079  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid);
1080  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1081  OutputCsmaPacket (p, pktInfo);
1082 }
1083 
1084 void
1087 {
1088  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1089  return;
1090  NS_LOG_FUNCTION (this);
1091  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1092  NS_ASSERT (ndev);
1093  Ptr <Node> n = ndev->GetNode ();
1094  NS_ASSERT (n);
1095  uint64_t animUid = GetAnimUidFromPacket (p);
1096  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1097  {
1098  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1099  return;
1100  }
1102  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1103  NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete");
1104  OutputCsmaPacket (p, pktInfo);
1105 }
1106 
1107 void
1109 {
1111  uint32_t nodeId = 0;
1112  if (pktInfo.m_txnd)
1113  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1114  else
1115  nodeId = pktInfo.m_txNodeId;
1116  WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1117 
1118 }
1119 
1120 void
1122 {
1124  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1125  WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1126 }
1127 
1128 void
1130 {
1132  NS_ASSERT (pktInfo.m_txnd);
1133  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1134  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1135 
1136  WriteXmlP ("p",
1137  nodeId,
1138  pktInfo.m_fbTx,
1139  pktInfo.m_lbTx,
1140  rxId,
1141  pktInfo.m_fbRx,
1142  pktInfo.m_lbRx,
1144 }
1145 
1146 void
1147 AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1148 {
1149  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1150  NS_ASSERT (pendingPackets);
1151  pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1152 }
1153 
1154 bool
1156 {
1157  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1158  NS_ASSERT (pendingPackets);
1159  return (pendingPackets->find (animUid) != pendingPackets->end ());
1160 }
1161 
1162 void
1164 {
1165  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1166  NS_ASSERT (pendingPackets);
1167  if (pendingPackets->empty ())
1168  return;
1169  std::vector <uint64_t> purgeList;
1170  for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1171  i != pendingPackets->end ();
1172  ++i)
1173  {
1174 
1175  AnimPacketInfo pktInfo = i->second;
1176  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1177  if (delta > PURGE_INTERVAL)
1178  {
1179  purgeList.push_back (i->first);
1180  }
1181  }
1182  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1183  i != purgeList.end ();
1184  ++i)
1185  {
1186  pendingPackets->erase (*i);
1187  }
1188 }
1189 
1192 {
1193  AnimUidPacketInfoMap * pendingPackets = 0;
1194  switch (protocolType)
1195  {
1197  {
1198  pendingPackets = &m_pendingWifiPackets;
1199  break;
1200  }
1202  {
1203  pendingPackets = &m_pendingUanPackets;
1204  break;
1205  }
1207  {
1208  pendingPackets = &m_pendingCsmaPackets;
1209  break;
1210  }
1212  {
1213  pendingPackets = &m_pendingWimaxPackets;
1214  break;
1215  }
1217  {
1218  pendingPackets = &m_pendingLtePackets;
1219  break;
1220  }
1221  }
1222  return pendingPackets;
1223 
1224 }
1225 
1226 // Counters
1227 
1228 std::string
1230 {
1231  std::string typeString = "unknown";
1232  switch (counterType)
1233  {
1234  case UINT32_COUNTER:
1235  {
1236  typeString = "UINT32";
1237  break;
1238  }
1239  case DOUBLE_COUNTER:
1240  {
1241  typeString = "DOUBLE";
1242  break;
1243  }
1244  }
1245  return typeString;
1246 }
1247 
1248 // General
1249 
1250 std::string
1252 {
1253  std::ostringstream oss;
1254  p->Print (oss);
1255  return oss.str ();
1256 }
1257 
1258 uint64_t
1260 {
1261  return m_currentPktCount;
1262 }
1263 
1264 void
1266 {
1267  m_started = false;
1268  NS_LOG_INFO ("Stopping Animation");
1270  if (m_f)
1271  {
1272  // Terminate the anim element
1273  WriteXmlClose ("anim");
1274  std::fclose (m_f);
1275  m_f = 0;
1276  }
1277  if (onlyAnimation)
1278  {
1279  return;
1280  }
1281  if (m_routingF)
1282  {
1283  WriteXmlClose ("anim", true);
1284  std::fclose (m_routingF);
1285  m_routingF = 0;
1286  }
1287 }
1288 
1289 void
1291 {
1292  m_currentPktCount = 0;
1293  m_started = true;
1295  WriteXmlAnim ();
1296  WriteNodes ();
1297  WriteNodeColors ();
1299  WriteNodeSizes ();
1300  WriteNodeEnergies ();
1301  if (!restart)
1302  {
1304  ConnectCallbacks ();
1305  }
1306 }
1307 
1308 void
1309 AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1310 {
1311  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1312 }
1313 
1314 
1315 // Callbacks
1316 void
1318 {
1319 
1320  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1321  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1322  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1323  std::ostringstream oss;
1324  //NodeList/*/DeviceList/*/
1325  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1326  if (dlPhy)
1327  {
1328  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1329  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1330  }
1331  if (ulPhy)
1332  {
1333  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1334  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1335  }
1336 }
1337 
1338 
1339 
1340 void
1342 {
1343 
1344  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1345  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1346  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1347  std::ostringstream oss;
1348  //NodeList/*/DeviceList/*/
1349  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1350  if (dlPhy)
1351  {
1352  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1353  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1354  }
1355  if (ulPhy)
1356  {
1357  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1358  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1359  }
1360 }
1361 
1362 void
1364 {
1365 
1366  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1367  {
1368  Ptr<Node> n = *i;
1369  NS_ASSERT (n);
1370  uint32_t nDevices = n->GetNDevices ();
1371  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1372  {
1373  Ptr <NetDevice> nd = n->GetDevice (devIndex);
1374  if (!nd)
1375  continue;
1376  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1377  if (lteUeNetDevice)
1378  {
1379  ConnectLteUe (n, lteUeNetDevice, devIndex);
1380  continue;
1381  }
1382  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1383  if (lteEnbNetDevice)
1384  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1385  }
1386 
1387  }
1388 }
1389 
1390 void
1392 {
1393  // Connect the callbacks
1394  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
1396  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
1398  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1400  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1402  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1404  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1406  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1408  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1410  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1412  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1414  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1416  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1418  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1420  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1422  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1424 
1425  ConnectLte ();
1426 
1427  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1429  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1431  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1433 
1434  // Queue Enqueues
1435 
1436  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1438  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1440  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1442 
1443  // Queue Dequeues
1444 
1445  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1447  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1449  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1451 
1452  // Queue Drops
1453 
1454  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1456  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1458  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1460 
1461 
1462  // Wifi Mac
1463  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1465  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1467  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1469  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1471 
1472  // Wifi Phy
1473  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1475  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1477 }
1478 
1479 Vector
1481 {
1483  if (loc)
1484  {
1485  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1486  }
1487  else
1488  {
1489  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1490  m_nodeLocation[n->GetId ()] = Vector (0, 0, 0);
1491  }
1492  return m_nodeLocation[n->GetId ()];
1493 }
1494 
1495 Vector
1497 {
1498  m_nodeLocation[n->GetId ()] = v;
1499  return v;
1500 }
1501 
1502 Vector
1504 {
1505  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1506  {
1507  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
1508  }
1509  return m_nodeLocation[n->GetId ()];
1510 }
1511 
1512 
1513 std::string
1515 {
1516  Address nodeAddr = nd->GetAddress ();
1517  std::ostringstream oss;
1518  oss << nodeAddr;
1519  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1520 }
1521 
1522 std::string
1524 {
1525  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1526  if (!ipv4)
1527  {
1528  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1529  return "0.0.0.0";
1530  }
1531  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1532  if (ifIndex == -1)
1533  {
1534  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1535  return "0.0.0.0";
1536  }
1537  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1538  std::ostringstream oss;
1539  oss << addr.GetLocal ();
1540  return oss.str ();
1541 }
1542 
1543 void
1545 {
1546  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1547  {
1548  Ptr<Node> n = *i;
1549  UpdatePosition (n);
1550  uint32_t n1Id = n->GetId ();
1551  uint32_t nDev = n->GetNDevices (); // Number of devices
1552  for (uint32_t i = 0; i < nDev; ++i)
1553  {
1554  Ptr<NetDevice> dev = n->GetDevice (i);
1555  NS_ASSERT (dev);
1556  Ptr<Channel> ch = dev->GetChannel ();
1557  if (!ch)
1558  {
1559  NS_LOG_DEBUG ("No channel can't be a p2p device");
1560  // Try to see if it is an LTE NetDevice, which does not return a channel
1561  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1562  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1563  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1564  {
1565  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
1567  }
1568  continue;
1569  }
1570  std::string channelType = ch->GetInstanceTypeId ().GetName ();
1571  NS_LOG_DEBUG ("Got ChannelType" << channelType);
1572  if (channelType == std::string ("ns3::PointToPointChannel"))
1573  { // Since these are duplex links, we only need to dump
1574  // if srcid < dstid
1575  uint32_t nChDev = ch->GetNDevices ();
1576  for (uint32_t j = 0; j < nChDev; ++j)
1577  {
1578  Ptr<NetDevice> chDev = ch->GetDevice (j);
1579  uint32_t n2Id = chDev->GetNode ()->GetId ();
1580  if (n1Id < n2Id)
1581  {
1582  // ouptut the p2p link
1583  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << ":" << GetMacAddress (dev) << "----" << GetIpv4Address (chDev) << ":" << GetMacAddress (chDev));
1586  P2pLinkNodeIdPair p2pPair;
1587  p2pPair.fromNode = n1Id;
1588  p2pPair.toNode = n2Id;
1589  LinkProperties lp = {GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), ""};
1590  m_linkProperties[p2pPair] = lp;
1591  WriteXmlLink (n1Id, 0, n2Id);
1592  }
1593  }
1594  }
1595  else
1596  {
1597  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << " Channel Type:" << channelType << " Mac: " << GetMacAddress (dev));
1598  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1600  }
1601  }
1602  }
1603  m_linkProperties.clear ();
1604 }
1605 
1606 void
1608 {
1609  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1610  {
1611  Ptr<Node> n = *i;
1612  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
1613  Vector v = UpdatePosition (n);
1614  WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
1615  }
1616 }
1617 
1618 void
1620 {
1621  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1622  {
1623  Ptr<Node> n = *i;
1624  Rgb rgb = {255, 0, 0};
1625  if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
1626  {
1627  m_nodeColors[n->GetId ()] = rgb;
1628  }
1629  UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
1630  }
1631 }
1632 
1633 void
1635 {
1636  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1637  {
1638  Ptr<Node> n = *i;
1639  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
1640  AnimationInterface::NodeSize s = { 1, 1 };
1641  m_nodeSizes[n->GetId ()] = s;
1642  UpdateNodeSize (n->GetId (), s.width, s.height);
1643  }
1644 }
1645 
1646 void
1648 {
1650  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1651  {
1652  Ptr<Node> n = *i;
1653  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
1654  {
1656  }
1657  }
1658 }
1659 
1660 bool
1662 {
1663  if ((Simulator::Now () >= m_startTime) &&
1664  (Simulator::Now () <= m_stopTime))
1665  return true;
1666  else
1667  return false;
1668 }
1669 
1670 void
1671 AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
1672 {
1673  if (!routing && m_f)
1674  {
1675  return;
1676  }
1677  if (routing && m_routingF)
1678  {
1679  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
1680  return;
1681  }
1682 
1683  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
1684  FILE * f = 0;
1685  f = std::fopen (fn.c_str (), "w");
1686  if (!f)
1687  {
1688  NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ());
1689  return; // Can't open output file
1690  }
1691  if (routing)
1692  {
1693  m_routingF = f;
1694  m_routingFileName = fn;
1695  }
1696  else
1697  {
1698  m_f = f;
1699  m_outputFileName = fn;
1700  }
1701  return;
1702 }
1703 
1704 void
1706 {
1707  // Start a new trace file if the current packet count exceeded nax packets per file
1710  {
1711  return;
1712  }
1713  NS_LOG_UNCOND ("Max Packets per trace file exceeded");
1714  StopAnimation (true);
1715 }
1716 
1717 std::string
1719 {
1720  return NETANIM_VERSION;
1721 }
1722 
1723 
1724 // Routing
1725 
1726 void
1728 {
1729  if (m_ipv4RouteTrackElements.empty ())
1730  {
1731  return;
1732  }
1733  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
1734  i != m_ipv4RouteTrackElements.end ();
1735  ++i)
1736  {
1737  Ipv4RouteTrackElement trackElement = *i;
1738  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
1739  if (!fromNode)
1740  {
1741  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
1742  continue;
1743  }
1744  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1745  if (!ipv4)
1746  {
1747  NS_LOG_WARN ("ipv4 object not found");
1748  continue;
1749  }
1751  if (!rp)
1752  {
1753  NS_LOG_WARN ("Routing protocol object not found");
1754  continue;
1755  }
1756  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
1757  Ptr<Packet> pkt = Create<Packet> ();
1758  Ipv4Header header;
1759  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
1760  Socket::SocketErrno sockerr;
1761  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1762  Ipv4RoutePathElements rpElements;
1763  if (!rt)
1764  {
1765  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
1766  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1767  rpElements.push_back (elem);
1768  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1769  continue;
1770  }
1771  std::ostringstream oss;
1772  oss << rt->GetGateway ();
1773  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
1774  if (rt->GetGateway () == "0.0.0.0")
1775  {
1776  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
1777  rpElements.push_back (elem);
1778  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
1779  {
1780  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
1781  rpElements.push_back (elem2);
1782  }
1783  }
1784  else if (rt->GetGateway () == "127.0.0.1")
1785  {
1786  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
1787  rpElements.push_back (elem);
1788  }
1789  else
1790  {
1791  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
1792  rpElements.push_back (elem);
1793  }
1794  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
1795  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
1796  }
1797 
1798 }
1799 
1800 void
1802 {
1804  {
1805  NS_LOG_INFO ("TrackQueueCounters Completed");
1806  return;
1807  }
1808  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1809  {
1810  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1814  }
1816 }
1817 
1818 void
1820 {
1822  {
1823  NS_LOG_INFO ("TrackWifiMacCounters Completed");
1824  return;
1825  }
1826  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1827  {
1828  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1833  }
1835 }
1836 
1837 void
1839 {
1841  {
1842  NS_LOG_INFO ("TrackWifiPhyCounters Completed");
1843  return;
1844  }
1845  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1846  {
1847  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1850  }
1852 }
1853 
1854 void
1856 {
1858  {
1859  NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed");
1860  return;
1861  }
1862  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1863  {
1864  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
1868  }
1870 }
1871 
1872 void
1874 {
1876  {
1877  NS_LOG_INFO ("TrackIpv4Route completed");
1878  return;
1879  }
1880  if (m_routingNc.GetN ())
1881  {
1882  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
1883  {
1884  Ptr <Node> n = *i;
1886  }
1887  }
1888  else
1889  {
1890  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1891  {
1892  Ptr <Node> n = *i;
1894  }
1895  }
1898 }
1899 
1900 std::string
1902 {
1903 
1904  NS_ASSERT (n);
1905  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
1906  if (!ipv4)
1907  {
1908  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
1909  return "";
1910  }
1911  std::stringstream stream;
1912  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
1913  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
1914  return stream.str ();
1915 
1916 }
1917 
1918 void
1919 AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
1920 {
1921  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
1922  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
1923  {
1924  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
1925  return;
1926  }
1927  Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
1929  if (fromNode->GetId () == toNode->GetId ())
1930  {
1931  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
1932  rpElements.push_back (elem);
1933  return;
1934  }
1935  if (!fromNode)
1936  {
1937  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
1938  return;
1939  }
1940  if (!toNode)
1941  {
1942  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
1943  return;
1944  }
1945  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
1946  if (!ipv4)
1947  {
1948  NS_LOG_WARN ("ipv4 object not found");
1949  return;
1950  }
1952  if (!rp)
1953  {
1954  NS_LOG_WARN ("Routing protocol object not found");
1955  return;
1956  }
1957  Ptr<Packet> pkt = Create<Packet> ();
1958  Ipv4Header header;
1959  header.SetDestination (Ipv4Address (to.c_str ()));
1960  Socket::SocketErrno sockerr;
1961  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
1962  if (!rt)
1963  {
1964  return;
1965  }
1966  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
1967  std::ostringstream oss;
1968  oss << rt->GetGateway ();
1969  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
1970  {
1971  NS_LOG_INFO ("Null gw");
1972  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
1973  rpElements.push_back (elem);
1974  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
1975  {
1976  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
1977  rpElements.push_back (elem2);
1978  }
1979  return;
1980  }
1981  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
1982  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
1983  rpElements.push_back (elem);
1984  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
1985 
1986 }
1987 
1988 
1989 // XML
1990 
1991 AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool emptyElement):
1992  m_tagName (tagName),
1993  m_emptyElement (emptyElement)
1994 {
1995  m_elementString = "<" + tagName + " ";
1996 }
1997 
1998 template <typename T>
1999 void
2000 AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape)
2001 {
2002  std::ostringstream oss;
2003  oss << std::setprecision (10);
2004  oss << value;
2005  m_elementString += attribute.c_str ();
2006  if (xmlEscape)
2007  {
2008  m_elementString += "=\"";
2009  std::string valueStr = oss.str ();
2010  for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it)
2011  {
2012  switch (*it)
2013  {
2014  case '&':
2015  m_elementString += "&amp;";
2016  break;
2017  case '\"':
2018  m_elementString += "&quot;";
2019  break;
2020  case '\'':
2021  m_elementString += "&apos;";
2022  break;
2023  case '<':
2024  m_elementString += "&lt;";
2025  break;
2026  case '>':
2027  m_elementString += "&gt;";
2028  break;
2029  default:
2030  m_elementString += *it;
2031  break;
2032  }
2033  }
2034  m_elementString += "\" ";
2035  }
2036  else
2037  {
2038  m_elementString += "=\"" + oss.str () + "\" ";
2039  }
2040 }
2041 
2042 void
2044 {
2045  m_elementString += ">\n";
2046 }
2047 
2048 void
2050 {
2051  if (m_emptyElement)
2052  {
2053  m_elementString += "/>\n";
2054  }
2055  else
2056  {
2057  m_elementString += "</" + m_tagName + ">\n";
2058  }
2059 }
2060 
2061 void
2063 {
2064  m_elementString += ">";
2065 }
2066 
2067 void
2069 {
2070  m_elementString += "\n";
2071 }
2072 
2073 void
2075 {
2076  m_elementString += e.GetElementString ();
2077 }
2078 
2079 std::string
2081 {
2082  return m_elementString;
2083 }
2084 
2085 
2086 void
2088 {
2089  AnimXmlElement element ("anim");
2090  element.AddAttribute ("ver", GetNetAnimVersion ());
2091  FILE * f = m_f;
2092  if (!routing)
2093  {
2094  element.AddAttribute ("filetype", "animation");
2095  }
2096  else
2097  {
2098  element.AddAttribute ("filetype", "routing");
2099  f = m_routingF;
2100  }
2101  element.Close ();
2102  WriteN (element.GetElementString (), f);
2103 }
2104 
2105 void
2106 AnimationInterface::WriteXmlClose (std::string name, bool routing)
2107 {
2108  std::string closeString = "</" + name + ">\n";
2109  if (!routing)
2110  {
2111  WriteN (closeString, m_f);
2112  }
2113  else
2114  {
2115  WriteN (closeString, m_routingF);
2116  }
2117 }
2118 
2119 void
2120 AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2121 {
2122  AnimXmlElement element ("node");
2123  element.AddAttribute ("id", id);
2124  element.AddAttribute ("sysId", sysId);
2125  element.AddAttribute ("locX", locX);
2126  element.AddAttribute ("locY", locY);
2127  element.CloseElement ();
2128  WriteN (element.GetElementString (), m_f);
2129 }
2130 
2131 void
2132 AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2133 {
2134  AnimXmlElement element ("linkupdate");
2135  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2136  element.AddAttribute ("fromId", fromId);
2137  element.AddAttribute ("toId", toId);
2138  element.AddAttribute ("ld", linkDescription, true);
2139  element.CloseElement ();
2140  WriteN (element.GetElementString (), m_f);
2141 }
2142 
2143 void
2144 AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2145 {
2146  AnimXmlElement element ("link");
2147  element.AddAttribute ("fromId", fromId);
2148  element.AddAttribute ("toId", toId);
2149 
2150  LinkProperties lprop ;
2151  lprop.fromNodeDescription = "";
2152  lprop.toNodeDescription = "";
2153  lprop.linkDescription = "";
2154 
2155  P2pLinkNodeIdPair p1 = { fromId, toId };
2156  P2pLinkNodeIdPair p2 = { toId, fromId };
2157  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2158  {
2159  lprop = m_linkProperties[p1];
2160  }
2161  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2162  {
2163  lprop = m_linkProperties[p2];
2164  }
2165 
2166  element.AddAttribute ("fd", lprop.fromNodeDescription, true);
2167  element.AddAttribute ("td", lprop.toNodeDescription, true);
2168  element.AddAttribute ("ld", lprop.linkDescription, true);
2169  element.CloseElement ();
2170  WriteN (element.GetElementString (), m_f);
2171 }
2172 
2173 void
2174 AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2175 {
2176  AnimXmlElement element ("rt");
2177  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2178  element.AddAttribute ("id", nodeId);
2179  element.AddAttribute ("info", routingInfo.c_str (), true);
2180  element.CloseElement ();
2181  WriteN (element.GetElementString (), m_routingF);
2182 }
2183 
2184 void
2185 AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2186 {
2187  std::string tagName = "rp";
2188  AnimXmlElement element (tagName, false);
2189  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2190  element.AddAttribute ("id", nodeId);
2191  element.AddAttribute ("d", destination.c_str ());
2192  element.AddAttribute ("c", rpElements.size ());
2193  element.CloseTag ();
2194  element.AddLineBreak ();
2195  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2196  i != rpElements.end ();
2197  ++i)
2198  {
2199  Ipv4RoutePathElement rpElement = *i;
2200  AnimXmlElement rpeElement ("rpe");
2201  rpeElement.AddAttribute ("n", rpElement.nodeId);
2202  rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2203  rpeElement.CloseElement ();
2204  element.Add (rpeElement);
2205  }
2206  element.CloseElement ();
2207  WriteN (element.GetElementString (), m_routingF);
2208 }
2209 
2210 
2211 void
2212 AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2213 {
2214  AnimXmlElement element ("pr");
2215  element.AddAttribute ("uId", animUid);
2216  element.AddAttribute ("fId", fId);
2217  element.AddAttribute ("fbTx", fbTx);
2218  if (!metaInfo.empty ())
2219  {
2220  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2221  }
2222  element.CloseElement ();
2223  WriteN (element.GetElementString (), m_f);
2224 }
2225 
2226 void
2227 AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2228 {
2229  AnimXmlElement element (pktType);
2230  element.AddAttribute ("uId", animUid);
2231  element.AddAttribute ("tId", tId);
2232  element.AddAttribute ("fbRx", fbRx);
2233  element.AddAttribute ("lbRx", lbRx);
2234  element.CloseElement ();
2235  WriteN (element.GetElementString (), m_f);
2236 }
2237 
2238 void
2239 AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2240  uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2241 {
2242  AnimXmlElement element (pktType);
2243  element.AddAttribute ("fId", fId);
2244  element.AddAttribute ("fbTx", fbTx);
2245  element.AddAttribute ("lbTx", lbTx);
2246  if (!metaInfo.empty ())
2247  {
2248  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2249  }
2250  element.AddAttribute ("tId", tId);
2251  element.AddAttribute ("fbRx", fbRx);
2252  element.AddAttribute ("lbRx", lbRx);
2253  element.CloseElement ();
2254  WriteN (element.GetElementString (), m_f);
2255 }
2256 
2257 void
2258 AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2259 {
2260  AnimXmlElement element ("ncs");
2261  element.AddAttribute ("ncId", nodeCounterId);
2262  element.AddAttribute ("n", counterName);
2263  element.AddAttribute ("t", CounterTypeToString (counterType));
2264  element.CloseElement ();
2265  WriteN (element.GetElementString (), m_f);
2266 }
2267 
2268 void
2269 AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2270 {
2271  AnimXmlElement element ("res");
2272  element.AddAttribute ("rid", resourceId);
2273  element.AddAttribute ("p", resourcePath);
2274  element.CloseElement ();
2275  WriteN (element.GetElementString (), m_f);
2276 }
2277 
2278 void
2279 AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2280 {
2281  AnimXmlElement element ("nu");
2282  element.AddAttribute ("p", "i");
2283  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2284  element.AddAttribute ("id", nodeId);
2285  element.AddAttribute ("rid", resourceId);
2286  element.CloseElement ();
2287  WriteN (element.GetElementString (), m_f);
2288 }
2289 
2290 void
2291 AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2292 {
2293  AnimXmlElement element ("nu");
2294  element.AddAttribute ("p", "s");
2295  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2296  element.AddAttribute ("id", nodeId);
2297  element.AddAttribute ("w", width);
2298  element.AddAttribute ("h", height);
2299  element.CloseElement ();
2300  WriteN (element.GetElementString (), m_f);
2301 }
2302 
2303 void
2304 AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2305 {
2306  AnimXmlElement element ("nu");
2307  element.AddAttribute ("p", "p");
2308  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2309  element.AddAttribute ("id", nodeId);
2310  element.AddAttribute ("x", x);
2311  element.AddAttribute ("y", y);
2312  element.CloseElement ();
2313  WriteN (element.GetElementString (), m_f);
2314 }
2315 
2316 void
2317 AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2318 {
2319  AnimXmlElement element ("nu");
2320  element.AddAttribute ("p", "c");
2321  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2322  element.AddAttribute ("id", nodeId);
2323  element.AddAttribute ("r", (uint32_t) r);
2324  element.AddAttribute ("g", (uint32_t) g);
2325  element.AddAttribute ("b", (uint32_t) b);
2326  element.CloseElement ();
2327  WriteN (element.GetElementString (), m_f);
2328 }
2329 
2330 void
2332 {
2333  AnimXmlElement element ("nu");
2334  element.AddAttribute ("p", "d");
2335  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2336  element.AddAttribute ("id", nodeId);
2337  if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2338  {
2339  element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
2340  }
2341  element.CloseElement ();
2342  WriteN (element.GetElementString (), m_f);
2343 }
2344 
2345 
2346 void
2347 AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2348 {
2349  AnimXmlElement element ("nc");
2350  element.AddAttribute ("c", nodeCounterId);
2351  element.AddAttribute ("i", nodeId);
2352  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2353  element.AddAttribute ("v", counterValue);
2354  element.CloseElement ();
2355  WriteN (element.GetElementString (), m_f);
2356 }
2357 
2358 void
2359 AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2360 {
2361  AnimXmlElement element ("bg");
2362  element.AddAttribute ("f", fileName);
2363  element.AddAttribute ("x", x);
2364  element.AddAttribute ("y", y);
2365  element.AddAttribute ("sx", scaleX);
2366  element.AddAttribute ("sy", scaleY);
2367  element.AddAttribute ("o", opacity);
2368  element.CloseElement ();
2369  WriteN (element.GetElementString (), m_f);
2370 }
2371 
2372 void
2373 AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2374 {
2375  AnimXmlElement element ("nonp2plinkproperties");
2376  element.AddAttribute ("id", id);
2377  element.AddAttribute ("ipv4Address", ipv4Address);
2378  element.AddAttribute ("channelType", channelType);
2379  element.CloseElement ();
2380  WriteN (element.GetElementString (), m_f);
2381 }
2382 
2383 TypeId
2385 {
2386  static TypeId tid = TypeId ("ns3::AnimByteTag")
2387  .SetParent<Tag> ()
2388  .SetGroupName ("NetAnim")
2389  .AddConstructor<AnimByteTag> ()
2390  ;
2391  return tid;
2392 }
2393 
2394 TypeId
2396 {
2397  return GetTypeId ();
2398 }
2399 
2400 uint32_t
2402 {
2403  return sizeof (uint64_t);
2404 }
2405 
2406 void
2408 {
2409  i.WriteU64 (m_AnimUid);
2410 }
2411 
2412 void
2414 {
2415  m_AnimUid = i.ReadU64 ();
2416 }
2417 
2418 void
2419 AnimByteTag::Print (std::ostream &os) const
2420 {
2421  os << "AnimUid=" << m_AnimUid;
2422 }
2423 
2424 void
2425 AnimByteTag::Set (uint64_t AnimUid)
2426 {
2427  m_AnimUid = AnimUid;
2428 }
2429 
2430 uint64_t
2431 AnimByteTag::Get (void) const
2432 {
2433  return m_AnimUid;
2434 }
2435 
2437  : m_txnd (0),
2438  m_txNodeId (0),
2439  m_fbTx (0),
2440  m_lbTx (0),
2441  m_lbRx (0)
2442 {
2443 }
2444 
2446 {
2447  m_txnd = pInfo.m_txnd;
2448  m_txNodeId = pInfo.m_txNodeId;
2449  m_fbTx = pInfo.m_fbTx;
2450  m_lbTx = pInfo.m_lbTx;
2451  m_lbRx = pInfo.m_lbRx;
2452 }
2453 
2455  const Time fbTx,
2456  uint32_t txNodeId)
2457  : m_txnd (txnd),
2458  m_txNodeId (0),
2459  m_fbTx (fbTx.GetSeconds ()),
2460  m_lbTx (0),
2461  m_lbRx (0)
2462 {
2463  if (!m_txnd)
2464  m_txNodeId = txNodeId;
2465 }
2466 
2467 void
2469 {
2470  Ptr <Node> n = nd->GetNode ();
2471  m_fbRx = fbRx;
2472  m_rxnd = nd;
2473 }
2474 
2475 } // 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)
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:102
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 "...
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
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)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
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:241
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.
Introspection did not find any typical Config paths.
Definition: energy-source.h:81
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:246
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:67
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:201
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:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
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 &)
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 WriteXmlAddNodeCounter(uint32_t counterId, std::string counterName, CounterType counterType)
void ProcessRxBegin(Ptr< const NetDevice > nd, const double fbRx)
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:410
void WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
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:121
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:90
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:341
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:61
void RemainingEnergyTrace(std::string context, double previousEnergy, double currentEnergy)
tuple mobility
Definition: third.py:101
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1216
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:533
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.
~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:235
uint8_t data[writeSize]
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
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:142
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
ByteTagIterator GetByteTagIterator(void) const
Retiurns an iterator over the set of byte tags included in this packet.
Definition: packet.cc:799
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:824
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.
AnimXmlElement(std::string tagName, bool emptyElement=true)
std::map< uint32_t, NodeSize > m_nodeSizes
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
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:150
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:276
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)
void WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo="")
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:54
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
an EUI-48 address
Definition: mac48-address.h:43
NodeCounterMap64 m_nodeQueueDrop
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 virtual time.
Definition: simulator.cc:223
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:40
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:107
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:228
std::string GetMacAddress(Ptr< NetDevice > nd)
static Iterator Begin(void)
Definition: node-list.cc:229
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:56
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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)
void OutputWirelessPacketRxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
static bool IsFinished(void)
Check if the simulation should finish.
Definition: simulator.cc:193
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 EnableQueueCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Queue Counters such as Enqueue, Dequeue, Queue Drops.
void AddAttribute(std::string attribute, T value, bool xmlEscape=false)
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet >)
Vector GetPosition(Ptr< Node > n)
a unique identifier for an interface.
Definition: type-id.h:58
NodeCounterMap64 m_nodeWifiMacTxDrop
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
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 OutputCsmaPacket(Ptr< const Packet > p, AnimPacketInfo &pktInfo)
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:789