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  * Tommaso Pecorella <tommaso.pecorella@unifi.it>
20  * Pavel Vasilyev <pavel.vasilyev@sredasolutions.com>
21  */
22 
23 // Interface between ns-3 and the network animator
24 
25 
26 
27 #include <cstdio>
28 #ifndef WIN32
29 #include <unistd.h>
30 #endif
31 #include <sstream>
32 #include <fstream>
33 #include <string>
34 #include <iomanip>
35 #include <map>
36 
37 // ns3 includes
38 #include "ns3/animation-interface.h"
39 #include "ns3/channel.h"
40 #include "ns3/config.h"
41 #include "ns3/node.h"
42 #include "ns3/mobility-model.h"
43 #include "ns3/packet.h"
44 #include "ns3/simulator.h"
45 #include "ns3/wifi-mac-header.h"
46 #include "ns3/wimax-mac-header.h"
47 #include "ns3/wifi-net-device.h"
48 #include "ns3/wifi-mac.h"
49 #include "ns3/lr-wpan-mac-header.h"
50 #include "ns3/lr-wpan-net-device.h"
51 #include "ns3/constant-position-mobility-model.h"
52 #include "ns3/lte-ue-phy.h"
53 #include "ns3/lte-enb-phy.h"
54 #include "ns3/uan-net-device.h"
55 #include "ns3/uan-mac.h"
56 #include "ns3/double.h"
57 #include "ns3/ipv4.h"
58 #include "ns3/ipv6.h"
59 #include "ns3/ipv4-routing-protocol.h"
60 #include "ns3/energy-source-container.h"
61 #include "animation-interface.h"
62 
63 namespace ns3 {
64 
65 NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
66 
67 // Globals
68 
69 static bool initialized = false;
70 
71 
72 // Public methods
73 
75  : m_f (0),
76  m_routingF (0),
77  m_mobilityPollInterval (Seconds (0.25)),
78  m_outputFileName (fn),
79  gAnimUid (0),
80  m_writeCallback (0),
81  m_started (false),
82  m_enablePacketMetadata (false),
83  m_startTime (Seconds (0)),
84  m_stopTime (Seconds (3600 * 1000)),
85  m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE),
86  m_originalFileName (fn),
87  m_routingStopTime (Seconds (0)),
88  m_routingFileName (""),
89  m_routingPollInterval (Seconds (5)),
90  m_trackPackets (true)
91 {
92  initialized = true;
93  StartAnimation ();
94 }
95 
97 {
98  StopAnimation ();
99 }
100 
101 void
103 {
104  m_trackPackets = false;
105 }
106 
107 void
109 {
111  m_wifiPhyCountersPollInterval = pollInterval;
114  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
115  {
116  Ptr<Node> n = *i;
117  m_nodeWifiPhyTxDrop[n->GetId ()] = 0;
118  m_nodeWifiPhyRxDrop[n->GetId ()] = 0;
121  }
123 
124 }
125 
126 void
128 {
130  m_wifiMacCountersPollInterval = pollInterval;
135  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
136  {
137  Ptr<Node> n = *i;
138  m_nodeWifiMacTx[n->GetId ()] = 0;
139  m_nodeWifiMacTxDrop[n->GetId ()] = 0;
140  m_nodeWifiMacRx[n->GetId ()] = 0;
141  m_nodeWifiMacRxDrop[n->GetId ()] = 0;
142  UpdateNodeCounter (m_wifiMacTxCounterId, n->GetId (), 0);
144  UpdateNodeCounter (m_wifiMacRxCounterId, n->GetId (), 0);
146  }
148 }
149 
150 void
152 {
154  m_queueCountersPollInterval = pollInterval;
158  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
159  {
160  Ptr<Node> n = *i;
161  m_nodeQueueEnqueue[n->GetId ()] = 0;
162  m_nodeQueueDequeue[n->GetId ()] = 0;
163  m_nodeQueueDrop[n->GetId ()] = 0;
166  UpdateNodeCounter (m_queueDropCounterId, n->GetId (), 0);
167  }
169 }
170 
171 void
173 {
179  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
180  {
181  Ptr<Node> n = *i;
182  m_nodeIpv4Tx[n->GetId ()] = 0;
183  m_nodeIpv4Rx[n->GetId ()] = 0;
184  m_nodeIpv4Drop[n->GetId ()] = 0;
188  }
190 }
191 
194 {
195  SetOutputFile (fileName, true);
197  m_routingPollInterval = pollInterval;
198  WriteXmlAnim (true);
200  return *this;
201 }
202 
205 {
206  m_routingNc = nc;
207  return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
208 }
209 
211 AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
212 {
213  Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
214  m_ipv4RouteTrackElements.push_back (element);
215  return *this;
216 }
217 
218 void
220 {
221  m_startTime = t;
222 }
223 
224 void
226 {
227  m_stopTime = t;
228 }
229 
230 void
231 AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile)
232 {
233  m_maxPktsPerFile = maxPacketsPerFile;
234 }
235 
236 uint32_t
237 AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType)
238 {
239  m_nodeCounters.push_back (counterName);
240  uint32_t counterId = m_nodeCounters.size () - 1; // counter ID is zero-indexed
241  WriteXmlAddNodeCounter (counterId, counterName, counterType);
242  return counterId;
243 }
244 
245 uint32_t
246 AnimationInterface::AddResource (std::string resourcePath)
247 {
248  m_resources.push_back (resourcePath);
249  uint32_t resourceId = m_resources.size () - 1; // resource ID is zero-indexed
250  WriteXmlAddResource (resourceId, resourcePath);
251  return resourceId;
252 }
253 
254 void
256 {
257  m_enablePacketMetadata = enable;
258  if (enable)
259  {
261  }
262 }
263 
264 bool
266 {
267  return initialized;
268 }
269 
270 bool
272 {
273  return m_started;
274 }
275 
276 void
278 {
279  m_writeCallback = cb;
280 }
281 
282 void
284 {
285  m_writeCallback = 0;
286 }
287 
288 void
290 {
292 }
293 
294 
295 void
297 {
298  NS_ASSERT (n);
300  if (loc == 0)
301  {
302  loc = CreateObject<ConstantPositionMobilityModel> ();
303  n->AggregateObject (loc);
304  }
305  Vector hubVec (x, y, z);
306  loc->SetPosition (hubVec);
307  NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")");
308 
309 }
310 
311 void
312 AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
313 {
314  NS_LOG_INFO ("Setting node image for Node Id:" << nodeId);
315  if (resourceId > (m_resources.size ()-1))
316  {
317  NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?");
318  }
319  WriteXmlUpdateNodeImage (nodeId, resourceId);
320 }
321 
322 void
323 AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter)
324 {
325  if (nodeCounterId > (m_nodeCounters.size () - 1))
326  {
327  NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?");
328  }
329  WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter);
330 }
331 
332 void
333 AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
334 {
335  if ((opacity < 0) || (opacity > 1))
336  {
337  NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0");
338  }
339  WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
340 }
341 
342 void
343 AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height)
344 {
345  AnimationInterface::NodeSize s = { width, height };
346  m_nodeSizes[nodeId] = s;
347  WriteXmlUpdateNodeSize (nodeId, s.width, s.height);
348 }
349 
350 void
351 AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
352 {
353  UpdateNodeColor (n->GetId (), r, g, b);
354 }
355 
356 void
357 AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
358 {
359  NS_ASSERT (NodeList::GetNode (nodeId));
360  NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
361  Rgb rgb = {r, g, b};
362  m_nodeColors[nodeId] = rgb;
363  WriteXmlUpdateNodeColor (nodeId, r, g, b);
364 }
365 
366 void
367 AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
368  std::string linkDescription)
369 {
370  WriteXmlUpdateLink (fromNode, toNode, linkDescription);
371 }
372 
373 void
375  std::string linkDescription)
376 {
377  NS_ASSERT (fromNode);
378  NS_ASSERT (toNode);
379  WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription);
380 }
381 
382 void
384 {
385  UpdateNodeDescription (n->GetId (), descr);
386 }
387 
388 void
389 AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
390 {
391  NS_ASSERT (NodeList::GetNode (nodeId));
392  m_nodeDescriptions[nodeId] = descr;
394 }
395 
396 // Private methods
397 
398 
399 double
401 {
402  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
403  NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ());
404  return fractionIter->second;
405 }
406 
407 void
409 {
411  Ptr <Node> n = mobility->GetObject <Node> ();
412  NS_ASSERT (n);
413  Vector v ;
414  if (!mobility)
415  {
416  v = GetPosition (n);
417  }
418  else
419  {
420  v = mobility->GetPosition ();
421  }
422  UpdatePosition (n, v);
423  WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y);
424 }
425 
426 bool
428 {
429  Vector oldLocation = GetPosition (n);
430  bool moved = true;
431  if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
432  (ceil (oldLocation.y) == ceil (newLocation.y)))
433  {
434  moved = false;
435  }
436  else
437  {
438  moved = true;
439  }
440  return moved;
441 }
442 
443 void
445 {
447  std::vector <Ptr <Node> > MovedNodes = GetMovedNodes ();
448  for (uint32_t i = 0; i < MovedNodes.size (); i++)
449  {
450  Ptr <Node> n = MovedNodes [i];
451  NS_ASSERT (n);
452  Vector v = GetPosition (n);
453  WriteXmlUpdateNodePosition (n->GetId () , v.x, v.y);
454  }
455  if (!Simulator::IsFinished ())
456  {
464  }
465 }
466 
467 std::vector <Ptr <Node> >
469 {
470  std::vector < Ptr <Node> > movedNodes;
471  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
472  {
473  Ptr<Node> n = *i;
474  NS_ASSERT (n);
475  Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
476  Vector newLocation;
477  if (!mobility)
478  {
479  newLocation = GetPosition (n);
480  }
481  else
482  {
483  newLocation = mobility->GetPosition ();
484  }
485  if (!NodeHasMoved (n, newLocation))
486  {
487  continue; //Location has not changed
488  }
489  else
490  {
491  UpdatePosition (n, newLocation);
492  movedNodes.push_back (n);
493  }
494  }
495  return movedNodes;
496 }
497 
498 int
499 AnimationInterface::WriteN (const std::string& st, FILE * f)
500 {
501  if (!f)
502  {
503  return 0;
504  }
505  if (m_writeCallback)
506  {
507  m_writeCallback (st.c_str ());
508  }
509  return WriteN (st.c_str (), st.length (), f);
510 }
511 
512 int
513 AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
514 {
515  if (!f)
516  {
517  return 0;
518  }
519  // Write count bytes to h from data
520  uint32_t nLeft = count;
521  const char* p = data;
522  uint32_t written = 0;
523  while (nLeft)
524  {
525  int n = std::fwrite (p, 1, nLeft, f);
526  if (n <= 0)
527  {
528  return written;
529  }
530  written += n;
531  nLeft -= n;
532  p += n;
533  }
534  return written;
535 }
536 
537 void
538 AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
539 {
540  NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ());
541  WriteXmlRp (nodeId, destination, rpElements);
542  /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
543  i != rpElements.end ();
544  ++i)
545  {
546  Ipv4RoutePathElement rpElement = *i;
547  NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
548  WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
549 
550  }
551  */
552 }
553 
554 void
555 AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
556 {
557  WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType);
558 }
559 
560 const std::vector<std::string>
561 AnimationInterface::GetElementsFromContext (const std::string& context) const
562 {
563  std::vector <std::string> elements;
564  std::size_t pos1=0, pos2;
565  while (pos1 != context.npos)
566  {
567  pos1 = context.find ("/",pos1);
568  pos2 = context.find ("/",pos1+1);
569  elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
570  pos1 = pos2;
571  pos2 = context.npos;
572  }
573  return elements;
574 }
575 
577 AnimationInterface::GetNodeFromContext (const std::string& context) const
578 {
579  // Use "NodeList/*/ as reference
580  // where element [1] is the Node Id
581 
582  std::vector <std::string> elements = GetElementsFromContext (context);
583  Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
584  NS_ASSERT (n);
585 
586  return n;
587 }
588 
591 {
592  // Use "NodeList/*/DeviceList/*/ as reference
593  // where element [1] is the Node Id
594  // element [2] is the NetDevice Id
595 
596  std::vector <std::string> elements = GetElementsFromContext (context);
597  Ptr <Node> n = GetNodeFromContext (context);
598 
599  return n->GetDevice (atoi (elements.at (3).c_str ()));
600 }
601 
602 uint64_t
604 {
605  AnimByteTag tag;
606  TypeId tid = tag.GetInstanceTypeId ();
608  bool found = false;
609  while (i.HasNext ())
610  {
611  ByteTagIterator::Item item = i.Next ();
612  if (tid == item.GetTypeId ())
613  {
614  item.GetTag (tag);
615  found = true;
616  }
617  }
618  if (found)
619  {
620  return tag.Get ();
621  }
622  else
623  {
624  return 0;
625  }
626 }
627 
628 void
630 {
631  AnimByteTag tag;
632  tag.Set (animUid);
633  p->AddByteTag (tag);
634 }
635 
636 void
637 AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
638 {
640  const Ptr <const Node> node = GetNodeFromContext (context);
641  const uint32_t nodeId = node->GetId ();
642 
643  NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
644 
645  const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
646 
647  NS_ASSERT (energySource);
648  // Don't call GetEnergyFraction () because of recursion
649  const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
650 
651  NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction);
652 
653  m_nodeEnergyFraction[nodeId] = energyFraction;
654  UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction);
655 }
656 
657 void
659 {
660  const Ptr <const Node> node = GetNodeFromContext (context);
661  ++m_nodeWifiPhyTxDrop[node->GetId ()];
662 }
663 
664 void
666 {
667  const Ptr <const Node> node = GetNodeFromContext (context);
668  ++m_nodeWifiPhyRxDrop[node->GetId ()];
669 }
670 
671 void
673 {
674  const Ptr <const Node> node = GetNodeFromContext (context);
675  ++m_nodeWifiMacTx[node->GetId ()];
676 }
677 
678 void
680 {
681  const Ptr <const Node> node = GetNodeFromContext (context);
682  ++m_nodeWifiMacTxDrop[node->GetId ()];
683 }
684 
685 void
687 {
688  const Ptr <const Node> node = GetNodeFromContext (context);
689  ++m_nodeWifiMacRx[node->GetId ()];
690 }
691 
692 void
694 {
695  const Ptr <const Node> node = GetNodeFromContext (context);
696  ++m_nodeWifiMacRxDrop[node->GetId ()];
697 }
698 
699 void
701 {
702  const Ptr <const Node> node = GetNodeFromContext (context);
703  ++m_nodeLrWpanMacTx[node->GetId ()];
704 }
705 
706 void
708 {
709  const Ptr <const Node> node = GetNodeFromContext (context);
710  ++m_nodeLrWpanMacTxDrop[node->GetId ()];
711 }
712 
713 void
715 {
716  const Ptr <const Node> node = GetNodeFromContext (context);
717  ++m_nodeLrWpanMacRx[node->GetId ()];
718 }
719 
720 void
722 {
723  const Ptr <const Node> node = GetNodeFromContext (context);
724  ++m_nodeLrWpanMacRxDrop[node->GetId ()];
725 }
726 
727 void
728 AnimationInterface::Ipv4TxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
729 {
730  const Ptr <const Node> node = GetNodeFromContext (context);
731  ++m_nodeIpv4Tx[node->GetId ()];
732 }
733 
734 void
735 AnimationInterface::Ipv4RxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
736 {
737  const Ptr <const Node> node = GetNodeFromContext (context);
738  ++m_nodeIpv4Rx[node->GetId ()];
739 }
740 
741 void
742 AnimationInterface::Ipv4DropTrace (std::string context,
743  const Ipv4Header & ipv4Header,
745  Ipv4L3Protocol::DropReason dropReason,
746  Ptr<Ipv4> ipv4,
747  uint32_t)
748 {
749  const Ptr <const Node> node = GetNodeFromContext (context);
750  ++m_nodeIpv4Drop[node->GetId ()];
751 }
752 
753 void
754 AnimationInterface::EnqueueTrace (std::string context,
756 {
757  const Ptr <const Node> node = GetNodeFromContext (context);
758  ++m_nodeQueueEnqueue[node->GetId ()];
759 }
760 
761 void
762 AnimationInterface::DequeueTrace (std::string context,
764 {
765  const Ptr <const Node> node = GetNodeFromContext (context);
766  ++m_nodeQueueDequeue[node->GetId ()];
767 }
768 
769 void
772 {
773  const Ptr <const Node> node = GetNodeFromContext (context);
774  ++m_nodeQueueDrop[node->GetId ()];
775 }
776 
777 void
778 AnimationInterface::DevTxTrace (std::string context,
780  Ptr<NetDevice> tx,
781  Ptr<NetDevice> rx,
782  Time txTime,
783  Time rxTime)
784 {
785  NS_LOG_FUNCTION (this);
787  NS_ASSERT (tx);
788  NS_ASSERT (rx);
789  Time now = Simulator::Now ();
790  double fbTx = now.GetSeconds ();
791  double lbTx = (now + txTime).GetSeconds ();
792  double fbRx = (now + rxTime - txTime).GetSeconds ();
793  double lbRx = (now + rxTime).GetSeconds ();
795  WriteXmlP ("p",
796  tx->GetNode ()->GetId (),
797  fbTx,
798  lbTx,
799  rx->GetNode ()->GetId (),
800  fbRx,
801  lbRx,
803 }
804 
805 void
807 {
808  NS_LOG_FUNCTION (this);
810  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
811  NS_ASSERT (ndev);
812  UpdatePosition (ndev);
813 
814  ++gAnimUid;
815  NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessTxTrace for packet:" << gAnimUid);
816  AddByteTag (gAnimUid, p);
817  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
818  AddPendingPacket (protocolType, gAnimUid, pktInfo);
819 
820  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
821  if (netDevice)
822  {
823  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
824  std::ostringstream oss;
825  oss << nodeAddr;
826  Ptr <Node> n = netDevice->GetNode ();
827  NS_ASSERT (n);
828  m_macToNodeIdMap[oss.str ()] = n->GetId ();
829  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
830  }
831  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
832  OutputWirelessPacketTxInfo (p, pendingPackets->at (gAnimUid), gAnimUid);
833 }
834 
835 void
837 {
838  NS_LOG_FUNCTION (this);
840  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
841  NS_ASSERT (ndev);
842  UpdatePosition (ndev);
843  uint64_t animUid = GetAnimUidFromPacket (p);
844  NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " for packet:" << animUid);
845  if (!IsPacketPending (animUid, protocolType))
846  {
847  NS_LOG_WARN (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid");
848  return;
849  }
850  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
851  pendingPackets->at (animUid).ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
852  OutputWirelessPacketRxInfo (p, pendingPackets->at (animUid), animUid);
853 }
854 
855 void
857 {
858  NS_LOG_FUNCTION (this);
859  return GenericWirelessTxTrace (context, p, AnimationInterface::UAN);
860 }
861 
862 void
864 {
865  NS_LOG_FUNCTION (this);
866  return GenericWirelessRxTrace (context, p, AnimationInterface::UAN);
867 }
868 
869 void
871 {
872  NS_LOG_FUNCTION (this);
874 }
875 
876 void
878 {
879  NS_LOG_FUNCTION (this);
881  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
882  NS_ASSERT (ndev);
883  UpdatePosition (ndev);
884  uint64_t animUid = GetAnimUidFromPacket (p);
885  NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid);
887  {
888  NS_ASSERT (0);
889  NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
890  std::ostringstream oss;
891  WifiMacHeader hdr;
892  if (!p->PeekHeader (hdr))
893  {
894  NS_LOG_WARN ("WifiMacHeader not present");
895  return;
896  }
897  oss << hdr.GetAddr2 ();
898  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
899  {
900  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
901  return;
902  }
903  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
904  UpdatePosition (txNode);
905  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
906  AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
907  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
908  }
910  m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
911  OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid);
912 }
913 
914 void
917 {
918  NS_LOG_FUNCTION (this);
920 
921  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
922  NS_ASSERT (ndev);
923  Ptr<LrWpanNetDevice> netDevice = DynamicCast<LrWpanNetDevice> (ndev);
924 
925  Ptr <Node> n = ndev->GetNode ();
926  NS_ASSERT (n);
927 
928  UpdatePosition (n);
929 
930  LrWpanMacHeader hdr;
931  if (!p->PeekHeader (hdr))
932  {
933  NS_LOG_WARN ("LrWpanMacHeader not present");
934  return;
935  }
936 
937  std::ostringstream oss;
938  if (hdr.GetSrcAddrMode () == 2)
939  {
940  Mac16Address nodeAddr = netDevice->GetMac ()->GetShortAddress ();
941  oss << nodeAddr;
942  }
943  else if (hdr.GetSrcAddrMode () == 3)
944  {
945  Mac64Address nodeAddr = netDevice->GetMac ()->GetExtendedAddress ();
946  oss << nodeAddr;
947  }
948  else
949  {
950  NS_LOG_WARN ("LrWpanMacHeader without source address");
951  return;
952  }
953  m_macToNodeIdMap[oss.str ()] = n->GetId ();
954  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
955 
956  ++gAnimUid;
957  NS_LOG_INFO ("LrWpan TxBeginTrace for packet:" << gAnimUid);
958  AddByteTag (gAnimUid, p);
959 
960  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
962 
964 }
965 
966 void
969 {
970  NS_LOG_FUNCTION (this);
972  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
973  NS_ASSERT (ndev);
974  Ptr <Node> n = ndev->GetNode ();
975  NS_ASSERT (n);
976 
977  AnimByteTag tag;
978  if (!p->FindFirstMatchingByteTag (tag))
979  {
980  return;
981  }
982 
983  uint64_t animUid = GetAnimUidFromPacket (p);
984  NS_LOG_INFO ("LrWpan RxBeginTrace for packet:" << animUid);
986  {
987  NS_LOG_WARN ("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
988  }
989 
990  UpdatePosition (n);
991  m_pendingLrWpanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
992  OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid);
993 }
994 
995 void
997 {
998  NS_LOG_FUNCTION (this);
1000 }
1001 
1002 void
1004 {
1005  NS_LOG_FUNCTION (this);
1007  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1008  NS_ASSERT (ndev);
1009  UpdatePosition (ndev);
1010  uint64_t animUid = GetAnimUidFromPacket (p);
1011  NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid);
1012  if (!IsPacketPending (animUid, AnimationInterface::WAVE))
1013  {
1014  NS_ASSERT (0);
1015  NS_LOG_WARN ("WavePhyRxBeginTrace: unknown Uid");
1016  std::ostringstream oss;
1017  WifiMacHeader hdr;
1018  if (!p->PeekHeader (hdr))
1019  {
1020  NS_LOG_WARN ("WaveMacHeader not present");
1021  return;
1022  }
1023  oss << hdr.GetAddr2 ();
1024  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1025  {
1026  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
1027  return;
1028  }
1029  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
1030  UpdatePosition (txNode);
1031  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
1032  AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo);
1033  NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet");
1034  }
1036  m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1037  OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid);
1038 }
1039 
1040 
1041 void
1043 {
1044  NS_LOG_FUNCTION (this);
1046 }
1047 
1048 
1049 void
1051 {
1052  NS_LOG_FUNCTION (this);
1054 }
1055 
1056 void
1058 {
1059  NS_LOG_FUNCTION (this);
1060  return GenericWirelessTxTrace (context, p, AnimationInterface::LTE);
1061 }
1062 
1063 void
1065 {
1066  NS_LOG_FUNCTION (this);
1067  return GenericWirelessRxTrace (context, p, AnimationInterface::LTE);
1068 }
1069 
1070 void
1072 {
1073  NS_LOG_FUNCTION (this);
1075  if (!pb)
1076  {
1077  NS_LOG_WARN ("pb == 0. Not yet supported");
1078  return;
1079  }
1080  context = "/" + context;
1081  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1082  NS_ASSERT (ndev);
1083  UpdatePosition (ndev);
1084 
1085  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1086  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1087  i != pbList.end ();
1088  ++i)
1089  {
1090  Ptr <Packet> p = *i;
1091  ++gAnimUid;
1092  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1093  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1094  AddByteTag (gAnimUid, p);
1096  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
1097  }
1098 }
1099 
1100 void
1102 {
1103  NS_LOG_FUNCTION (this);
1105  if (!pb)
1106  {
1107  NS_LOG_WARN ("pb == 0. Not yet supported");
1108  return;
1109  }
1110  context = "/" + context;
1111  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1112  NS_ASSERT (ndev);
1113  UpdatePosition (ndev);
1114 
1115  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1116  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1117  i != pbList.end ();
1118  ++i)
1119  {
1120  Ptr <Packet> p = *i;
1121  uint64_t animUid = GetAnimUidFromPacket (p);
1122  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1123  if (!IsPacketPending (animUid, AnimationInterface::LTE))
1124  {
1125  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1126  return;
1127  }
1128  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1129  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1130  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
1131  }
1132 }
1133 
1134 void
1136 {
1137  NS_LOG_FUNCTION (this);
1139  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1140  NS_ASSERT (ndev);
1141  UpdatePosition (ndev);
1142  ++gAnimUid;
1143  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1144  AddByteTag (gAnimUid, p);
1145  UpdatePosition (ndev);
1146  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1148 
1149 
1150 }
1151 
1152 void
1154 {
1155  NS_LOG_FUNCTION (this);
1157  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1158  NS_ASSERT (ndev);
1159  UpdatePosition (ndev);
1160  uint64_t animUid = GetAnimUidFromPacket (p);
1161  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid);
1162  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1163  {
1164  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1165  NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid");
1166  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1167  AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1168  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1169  }
1171  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1172  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1173 }
1174 
1175 void
1177 {
1178  NS_LOG_FUNCTION (this);
1180  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1181  NS_ASSERT (ndev);
1182  UpdatePosition (ndev);
1183  uint64_t animUid = GetAnimUidFromPacket (p);
1184  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1185  {
1186  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1187  return;
1188  }
1190  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1191  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1192  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid);
1193  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1194  OutputCsmaPacket (p, pktInfo);
1195 }
1196 
1197 void
1200 {
1201  NS_LOG_FUNCTION (this);
1203  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1204  NS_ASSERT (ndev);
1205  uint64_t animUid = GetAnimUidFromPacket (p);
1206  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1207  {
1208  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1209  return;
1210  }
1212  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1213  NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete");
1214  OutputCsmaPacket (p, pktInfo);
1215 }
1216 
1217 void
1219 {
1221  uint32_t nodeId = 0;
1222  if (pktInfo.m_txnd)
1223  {
1224  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1225  }
1226  else
1227  {
1228  nodeId = pktInfo.m_txNodeId;
1229  }
1230  WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1231 }
1232 
1233 void
1235 {
1237  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1238  WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1239 }
1240 
1241 void
1243 {
1245  NS_ASSERT (pktInfo.m_txnd);
1246  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1247  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1248 
1249  WriteXmlP ("p",
1250  nodeId,
1251  pktInfo.m_fbTx,
1252  pktInfo.m_lbTx,
1253  rxId,
1254  pktInfo.m_fbRx,
1255  pktInfo.m_lbRx,
1257 }
1258 
1259 void
1260 AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1261 {
1262  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1263  NS_ASSERT (pendingPackets);
1264  pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1265 }
1266 
1267 bool
1269 {
1270  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1271  NS_ASSERT (pendingPackets);
1272  return (pendingPackets->find (animUid) != pendingPackets->end ());
1273 }
1274 
1275 void
1277 {
1278  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1279  NS_ASSERT (pendingPackets);
1280  if (pendingPackets->empty ())
1281  {
1282  return;
1283  }
1284  std::vector <uint64_t> purgeList;
1285  for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1286  i != pendingPackets->end ();
1287  ++i)
1288  {
1289 
1290  AnimPacketInfo pktInfo = i->second;
1291  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1292  if (delta > PURGE_INTERVAL)
1293  {
1294  purgeList.push_back (i->first);
1295  }
1296  }
1297  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1298  i != purgeList.end ();
1299  ++i)
1300  {
1301  pendingPackets->erase (*i);
1302  }
1303 }
1304 
1307 {
1308  AnimUidPacketInfoMap * pendingPackets = 0;
1309  switch (protocolType)
1310  {
1312  {
1313  pendingPackets = &m_pendingWifiPackets;
1314  break;
1315  }
1317  {
1318  pendingPackets = &m_pendingUanPackets;
1319  break;
1320  }
1322  {
1323  pendingPackets = &m_pendingCsmaPackets;
1324  break;
1325  }
1327  {
1328  pendingPackets = &m_pendingWimaxPackets;
1329  break;
1330  }
1332  {
1333  pendingPackets = &m_pendingLtePackets;
1334  break;
1335  }
1337  {
1338  pendingPackets = &m_pendingLrWpanPackets;
1339  break;
1340  }
1342  {
1343  pendingPackets = &m_pendingWavePackets;
1344  break;
1345  }
1346  }
1347  return pendingPackets;
1348 
1349 }
1350 
1351 std::string
1353 {
1354  std::string result = "Unknown";
1355  switch (protocolType)
1356  {
1358  {
1359  result = "WIFI";
1360  break;
1361  }
1363  {
1364  result = "UAN";
1365  break;
1366  }
1368  {
1369  result = "CSMA";
1370  break;
1371  }
1373  {
1374  result = "WIMAX";
1375  break;
1376  }
1378  {
1379  result = "LTE";
1380  break;
1381  }
1383  {
1384  result = "LRWPAN";
1385  break;
1386  }
1388  {
1389  result = "WAVE";
1390  break;
1391  }
1392  }
1393  return result;
1394 }
1395 
1396 // Counters
1397 
1398 std::string
1400 {
1401  std::string typeString = "unknown";
1402  switch (counterType)
1403  {
1404  case UINT32_COUNTER:
1405  {
1406  typeString = "UINT32";
1407  break;
1408  }
1409  case DOUBLE_COUNTER:
1410  {
1411  typeString = "DOUBLE";
1412  break;
1413  }
1414  }
1415  return typeString;
1416 }
1417 
1418 // General
1419 
1420 std::string
1422 {
1423  std::ostringstream oss;
1424  p->Print (oss);
1425  return oss.str ();
1426 }
1427 
1428 uint64_t
1430 {
1431  return m_currentPktCount;
1432 }
1433 
1434 void
1436 {
1437  m_started = false;
1438  NS_LOG_INFO ("Stopping Animation");
1440  if (m_f)
1441  {
1442  // Terminate the anim element
1443  WriteXmlClose ("anim");
1444  std::fclose (m_f);
1445  m_f = 0;
1446  }
1447  if (onlyAnimation)
1448  {
1449  return;
1450  }
1451  if (m_routingF)
1452  {
1453  WriteXmlClose ("anim", true);
1454  std::fclose (m_routingF);
1455  m_routingF = 0;
1456  }
1457 }
1458 
1459 void
1461 {
1462  m_currentPktCount = 0;
1463  m_started = true;
1465  WriteXmlAnim ();
1466  WriteNodes ();
1467  WriteNodeColors ();
1469  WriteIpv4Addresses ();
1470  WriteIpv6Addresses ();
1471  WriteNodeSizes ();
1472  WriteNodeEnergies ();
1473  if (!restart)
1474  {
1476  ConnectCallbacks ();
1477  }
1478 }
1479 
1480 void
1481 AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1482 {
1483  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1484  m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address));
1485 }
1486 
1487 void
1488 AnimationInterface::AddToIpv4AddressNodeIdTable (std::vector<std::string> ipv4Addresses, uint32_t nodeId)
1489 {
1490  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
1491  i != ipv4Addresses.end ();
1492  ++i)
1493  {
1494  AddToIpv4AddressNodeIdTable (*i, nodeId);
1495  }
1496 }
1497 
1498 void
1499 AnimationInterface::AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId)
1500 {
1501  m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1502  m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address));
1503 }
1504 
1505 void
1506 AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector<std::string> ipv6Addresses, uint32_t nodeId)
1507 {
1508  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin();
1509  i != ipv6Addresses.end();
1510  ++i)
1511  {
1512  AddToIpv6AddressNodeIdTable(*i, nodeId);
1513  }
1514 }
1515 
1516 // Callbacks
1517 void
1519 {
1520 
1521  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1522  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1523  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1524  std::ostringstream oss;
1525  //NodeList/*/DeviceList/*/
1526  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1527  if (dlPhy)
1528  {
1529  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1530  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1531  }
1532  if (ulPhy)
1533  {
1534  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1535  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1536  }
1537 }
1538 
1539 
1540 
1541 void
1543 {
1544 
1545  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1546  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1547  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1548  std::ostringstream oss;
1549  //NodeList/*/DeviceList/*/
1550  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1551  if (dlPhy)
1552  {
1553  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1554  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1555  }
1556  if (ulPhy)
1557  {
1558  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1559  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1560  }
1561 }
1562 
1563 void
1565 {
1566 
1567  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1568  {
1569  Ptr<Node> n = *i;
1570  NS_ASSERT (n);
1571  uint32_t nDevices = n->GetNDevices ();
1572  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1573  {
1574  Ptr <NetDevice> nd = n->GetDevice (devIndex);
1575  if (!nd)
1576  continue;
1577  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1578  if (lteUeNetDevice)
1579  {
1580  ConnectLteUe (n, lteUeNetDevice, devIndex);
1581  continue;
1582  }
1583  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1584  if (lteEnbNetDevice)
1585  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1586  }
1587 
1588  }
1589 }
1590 
1591 void
1593 {
1594  // Connect the callbacks
1595  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
1597  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
1599  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1601  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1603  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1605  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1607  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1609  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1611  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1613  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1615  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1617  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1619  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1621  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1623  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1625 
1626  ConnectLte ();
1627 
1628  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1630  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1632  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1634 
1635  // Queue Enqueues
1636 
1637  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1639  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1641  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1643 
1644  // Queue Dequeues
1645 
1646  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1648  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1650  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1652 
1653  // Queue Drops
1654 
1655  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1657  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1659  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1661 
1662 
1663  // Wifi Mac
1664  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1666  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1668  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1670  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1672 
1673  // Wifi Phy
1674  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1676  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1678 
1679  // LrWpan
1680  Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin",
1682  Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin",
1684  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx",
1686  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop",
1688  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx",
1690  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop",
1692 
1693  // Wave
1694  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin",
1696  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin",
1698 }
1699 
1700 Vector
1702 {
1703  Ptr<MobilityModel> loc = n->GetObject<MobilityModel> ();
1704  if (loc)
1705  {
1706  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1707  }
1708  else
1709  {
1710  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1711  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
1712  x->SetAttribute ("Min", DoubleValue (0));
1713  x->SetAttribute ("Max", DoubleValue (100));
1714  Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable> ();
1715  y->SetAttribute ("Min", DoubleValue (0));
1716  y->SetAttribute ("Max", DoubleValue (100));
1717  m_nodeLocation[n->GetId ()] = Vector (int (x->GetValue ()), int (y->GetValue ()), 0);
1718  }
1719  return m_nodeLocation[n->GetId ()];
1720 }
1721 
1722 Vector
1724 {
1725  m_nodeLocation[n->GetId ()] = v;
1726  return v;
1727 }
1728 
1729 Vector
1731 {
1732  Ptr <Node> n = ndev->GetNode ();
1733  NS_ASSERT (n);
1734  return UpdatePosition (n);
1735 }
1736 
1737 Vector
1739 {
1740  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1741  {
1742  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
1743  }
1744  return m_nodeLocation[n->GetId ()];
1745 }
1746 
1747 
1748 std::string
1750 {
1751  Address nodeAddr = nd->GetAddress ();
1752  std::ostringstream oss;
1753  oss << nodeAddr;
1754  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1755 }
1756 
1757 std::string
1759 {
1760  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1761  if (!ipv4)
1762  {
1763  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1764  return "0.0.0.0";
1765  }
1766  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1767  if (ifIndex == -1)
1768  {
1769  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1770  return "0.0.0.0";
1771  }
1772  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1773  std::ostringstream oss;
1774  oss << addr.GetLocal ();
1775  return oss.str ();
1776 }
1777 
1778 std::string
1780 {
1781  Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject <Ipv6>();
1782  if (!ipv6)
1783  {
1784  NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1785  return "::";
1786  }
1787  int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1788  if (ifIndex == -1)
1789  {
1790  NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1791  return "::";
1792  }
1793  bool nonLinkLocalFound = false;
1794  uint32_t nAddresses = ipv6->GetNAddresses(ifIndex);
1795  Ipv6InterfaceAddress addr;
1796  for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1797  {
1798  addr = ipv6->GetAddress(ifIndex, addressIndex);
1799  if (!addr.GetAddress().IsLinkLocal())
1800  {
1801  nonLinkLocalFound = true;
1802  break;
1803  }
1804  }
1805  if (!nonLinkLocalFound)
1806  addr = ipv6->GetAddress(ifIndex, 0);
1807  std::ostringstream oss;
1808  oss << addr.GetAddress();
1809  return oss.str();
1810 }
1811 
1812 
1813 
1814 std::vector<std::string>
1816 {
1817  std::vector<std::string> ipv4Addresses;
1818  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1819  if (!ipv4)
1820  {
1821  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1822  return ipv4Addresses;
1823  }
1824  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1825  if (ifIndex == -1)
1826  {
1827  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1828  return ipv4Addresses;
1829  }
1830  for (uint32_t index = 0; index < ipv4->GetNAddresses (ifIndex); ++index)
1831  {
1832  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, index);
1833  std::ostringstream oss;
1834  oss << addr.GetLocal ();
1835  ipv4Addresses.push_back(oss.str ());
1836  }
1837  return ipv4Addresses;
1838 }
1839 
1840 std::vector<std::string>
1842 {
1843  std::vector<std::string> ipv6Addresses;
1844  Ptr<Ipv6> ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv6> ();
1845  if (!ipv6)
1846  {
1847  NS_LOG_WARN("Node: " << nd->GetNode ()->GetId () << " No ipv6 object found");
1848  return ipv6Addresses;
1849  }
1850  int32_t ifIndex = ipv6->GetInterfaceForDevice (nd);
1851  if (ifIndex == -1)
1852  {
1853  NS_LOG_WARN("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1854  return ipv6Addresses;
1855  }
1856  for (uint32_t index = 0; index < ipv6->GetNAddresses (ifIndex); ++index)
1857  {
1858  Ipv6InterfaceAddress addr = ipv6->GetAddress (ifIndex, index);
1859  std::ostringstream oss;
1860  oss << addr.GetAddress ();
1861  ipv6Addresses.push_back (oss.str ());
1862  }
1863  return ipv6Addresses;
1864 }
1865 
1866 
1867 void
1869 {
1870  for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin ();
1871  i != m_nodeIdIpv4Map.end();
1872  ++i)
1873  {
1874  std::vector <std::string> ipv4Addresses;
1875  std::pair<NodeIdIpv4Map::const_iterator, NodeIdIpv4Map::const_iterator> iterPair = m_nodeIdIpv4Map.equal_range (i->first);
1876  for (NodeIdIpv4Map::const_iterator it = iterPair.first;
1877  it != iterPair.second;
1878  ++it)
1879  {
1880  ipv4Addresses.push_back (it->second);
1881  }
1882  WriteXmlIpv4Addresses (i->first, ipv4Addresses);
1883  }
1884 }
1885 
1886 void
1888 {
1889  for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin ();
1890  i != m_nodeIdIpv6Map.end ();
1891  i = m_nodeIdIpv6Map.upper_bound (i->first))
1892  {
1893  std::vector <std::string> ipv6Addresses;
1894  std::pair<NodeIdIpv6Map::const_iterator, NodeIdIpv6Map::const_iterator> iterPair = m_nodeIdIpv6Map.equal_range (i->first);
1895  for (NodeIdIpv6Map::const_iterator it = iterPair.first;
1896  it != iterPair.second;
1897  ++it)
1898  {
1899  ipv6Addresses.push_back (it->second);
1900  }
1901  WriteXmlIpv6Addresses (i->first, ipv6Addresses);
1902  }
1903 }
1904 
1905 void
1907 {
1908  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1909  {
1910  Ptr<Node> n = *i;
1911  UpdatePosition (n);
1912  uint32_t n1Id = n->GetId ();
1913  uint32_t nDev = n->GetNDevices (); // Number of devices
1914  for (uint32_t i = 0; i < nDev; ++i)
1915  {
1916  Ptr<NetDevice> dev = n->GetDevice (i);
1917  NS_ASSERT (dev);
1918  Ptr<Channel> ch = dev->GetChannel ();
1919  std::string channelType = "Unknown channel";
1920  if (ch)
1921  {
1922  channelType = ch->GetInstanceTypeId ().GetName ();
1923  }
1924  NS_LOG_DEBUG("Got ChannelType" << channelType);
1925 
1926  if (!ch || (channelType != std::string("ns3::PointToPointChannel")))
1927  {
1928  NS_LOG_DEBUG ("No channel can't be a p2p device");
1929  /*
1930  // Try to see if it is an LTE NetDevice, which does not return a channel
1931  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1932  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1933  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1934  {
1935  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1936  AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ());
1937  }
1938  */
1939  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
1940  AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId ());
1941  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
1942  AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId ());
1943  if (!ipv4Addresses.empty ())
1944  {
1945  NS_LOG_INFO ("Writing Ipv4 link");
1946  WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1947  }
1948  else if (!ipv6Addresses.empty ())
1949  {
1950  NS_LOG_INFO ("Writing Ipv6 link");
1951  WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType);
1952  }
1953  continue;
1954  }
1955 
1956  else if (channelType == std::string ("ns3::PointToPointChannel"))
1957  { // Since these are duplex links, we only need to dump
1958  // if srcid < dstid
1959  std::size_t nChDev = ch->GetNDevices ();
1960  for (std::size_t j = 0; j < nChDev; ++j)
1961  {
1962  Ptr<NetDevice> chDev = ch->GetDevice (j);
1963  uint32_t n2Id = chDev->GetNode ()->GetId ();
1964  if (n1Id < n2Id)
1965  {
1966 
1967  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
1968  AddToIpv4AddressNodeIdTable (ipv4Addresses, n1Id);
1969  ipv4Addresses = GetIpv4Addresses (chDev);
1970  AddToIpv4AddressNodeIdTable (ipv4Addresses, n2Id);
1971  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
1972  AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id);
1973  ipv6Addresses = GetIpv6Addresses (chDev);
1974  AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id);
1975 
1976  P2pLinkNodeIdPair p2pPair;
1977  p2pPair.fromNode = n1Id;
1978  p2pPair.toNode = n2Id;
1979  if (!ipv4Addresses.empty ())
1980  {
1981  LinkProperties lp = { GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), "" };
1982  m_linkProperties[p2pPair] = lp;
1983  }
1984  else if (!ipv6Addresses.empty ())
1985  {
1986  LinkProperties lp = { GetIpv6Address (dev) + "~" + GetMacAddress (dev), GetIpv6Address (chDev) + "~" + GetMacAddress (chDev), "" };
1987  m_linkProperties[p2pPair] = lp;
1988  }
1989  WriteXmlLink (n1Id, 0, n2Id);
1990  }
1991  }
1992  }
1993  }
1994  }
1995  m_linkProperties.clear ();
1996 }
1997 
1998 void
2000 {
2001  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2002  {
2003  Ptr<Node> n = *i;
2004  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
2005  Vector v = UpdatePosition (n);
2006  WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
2007  }
2008 }
2009 
2010 void
2012 {
2013  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2014  {
2015  Ptr<Node> n = *i;
2016  Rgb rgb = {255, 0, 0};
2017  if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
2018  {
2019  m_nodeColors[n->GetId ()] = rgb;
2020  }
2021  UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
2022  }
2023 }
2024 
2025 void
2027 {
2028  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2029  {
2030  Ptr<Node> n = *i;
2031  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
2032  AnimationInterface::NodeSize s = { 1, 1 };
2033  m_nodeSizes[n->GetId ()] = s;
2034  UpdateNodeSize (n->GetId (), s.width, s.height);
2035  }
2036 }
2037 
2038 void
2040 {
2042  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2043  {
2044  Ptr<Node> n = *i;
2045  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
2046  {
2048  }
2049  }
2050 }
2051 
2052 bool
2054 {
2055  if ((Simulator::Now () >= m_startTime) &&
2056  (Simulator::Now () <= m_stopTime))
2057  return true;
2058  else
2059  return false;
2060 }
2061 
2062 void
2063 AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
2064 {
2065  if (!routing && m_f)
2066  {
2067  return;
2068  }
2069  if (routing && m_routingF)
2070  {
2071  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
2072  return;
2073  }
2074 
2075  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
2076  FILE * f = 0;
2077  f = std::fopen (fn.c_str (), "w");
2078  if (!f)
2079  {
2080  NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ());
2081  return; // Can't open output file
2082  }
2083  if (routing)
2084  {
2085  m_routingF = f;
2086  m_routingFileName = fn;
2087  }
2088  else
2089  {
2090  m_f = f;
2091  m_outputFileName = fn;
2092  }
2093  return;
2094 }
2095 
2096 void
2098 {
2099  // Start a new trace file if the current packet count exceeded nax packets per file
2102  {
2103  return;
2104  }
2105  NS_LOG_UNCOND ("Max Packets per trace file exceeded");
2106  StopAnimation (true);
2107 }
2108 
2109 std::string
2111 {
2112  return NETANIM_VERSION;
2113 }
2114 
2115 
2116 void
2118 {
2120  {
2121  NS_LOG_INFO ("TrackQueueCounters Completed");
2122  return;
2123  }
2124  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2125  {
2126  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2130  }
2132 }
2133 
2134 void
2136 {
2138  {
2139  NS_LOG_INFO ("TrackWifiMacCounters Completed");
2140  return;
2141  }
2142  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2143  {
2144  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2149  }
2151 }
2152 
2153 void
2155 {
2157  {
2158  NS_LOG_INFO ("TrackWifiPhyCounters Completed");
2159  return;
2160  }
2161  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2162  {
2163  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2166  }
2168 }
2169 
2170 void
2172 {
2174  {
2175  NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed");
2176  return;
2177  }
2178  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2179  {
2180  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2184  }
2186 }
2187 
2188 
2189 
2190 
2191 
2192 /***** Routing-related *****/
2193 
2194 void
2196 {
2197  if (m_ipv4RouteTrackElements.empty ())
2198  {
2199  return;
2200  }
2201  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
2202  i != m_ipv4RouteTrackElements.end ();
2203  ++i)
2204  {
2205  Ipv4RouteTrackElement trackElement = *i;
2206  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
2207  if (!fromNode)
2208  {
2209  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
2210  continue;
2211  }
2212  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2213  if (!ipv4)
2214  {
2215  NS_LOG_WARN ("ipv4 object not found");
2216  continue;
2217  }
2219  if (!rp)
2220  {
2221  NS_LOG_WARN ("Routing protocol object not found");
2222  continue;
2223  }
2224  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
2225  Ptr<Packet> pkt = Create<Packet> ();
2226  Ipv4Header header;
2227  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
2228  Socket::SocketErrno sockerr;
2229  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2230  Ipv4RoutePathElements rpElements;
2231  if (!rt)
2232  {
2233  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
2234  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2235  rpElements.push_back (elem);
2236  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2237  continue;
2238  }
2239  std::ostringstream oss;
2240  oss << rt->GetGateway ();
2241  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
2242  if (rt->GetGateway () == "0.0.0.0")
2243  {
2244  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
2245  rpElements.push_back (elem);
2246  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
2247  {
2248  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
2249  rpElements.push_back (elem2);
2250  }
2251  }
2252  else if (rt->GetGateway () == "127.0.0.1")
2253  {
2254  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2255  rpElements.push_back (elem);
2256  }
2257  else
2258  {
2259  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
2260  rpElements.push_back (elem);
2261  }
2262  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
2263  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2264  }
2265 
2266 }
2267 
2268 void
2270 {
2272  {
2273  NS_LOG_INFO ("TrackIpv4Route completed");
2274  return;
2275  }
2276  if (m_routingNc.GetN ())
2277  {
2278  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
2279  {
2280  Ptr <Node> n = *i;
2281  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2282  }
2283  }
2284  else
2285  {
2286  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2287  {
2288  Ptr <Node> n = *i;
2289  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2290  }
2291  }
2294 }
2295 
2296 std::string
2298 {
2299 
2300  NS_ASSERT (n);
2301  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
2302  if (!ipv4)
2303  {
2304  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
2305  return "";
2306  }
2307  std::stringstream stream;
2308  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
2309  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
2310  return stream.str ();
2311 
2312 }
2313 
2314 void
2315 AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
2316 {
2317  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
2318  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
2319  {
2320  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
2321  return;
2322  }
2323  Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
2325  if (fromNode->GetId () == toNode->GetId ())
2326  {
2327  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
2328  rpElements.push_back (elem);
2329  return;
2330  }
2331  if (!fromNode)
2332  {
2333  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2334  return;
2335  }
2336  if (!toNode)
2337  {
2338  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2339  return;
2340  }
2341  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2342  if (!ipv4)
2343  {
2344  NS_LOG_WARN ("ipv4 object not found");
2345  return;
2346  }
2348  if (!rp)
2349  {
2350  NS_LOG_WARN ("Routing protocol object not found");
2351  return;
2352  }
2353  Ptr<Packet> pkt = Create<Packet> ();
2354  Ipv4Header header;
2355  header.SetDestination (Ipv4Address (to.c_str ()));
2356  Socket::SocketErrno sockerr;
2357  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2358  if (!rt)
2359  {
2360  return;
2361  }
2362  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
2363  std::ostringstream oss;
2364  oss << rt->GetGateway ();
2365  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2366  {
2367  NS_LOG_INFO ("Null gw");
2368  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
2369  rpElements.push_back (elem);
2370  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
2371  {
2372  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
2373  rpElements.push_back (elem2);
2374  }
2375  return;
2376  }
2377  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
2378  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
2379  rpElements.push_back (elem);
2380  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
2381 
2382 }
2383 
2384 
2385 
2386 /***** WriteXml *****/
2387 
2388 void
2390 {
2391  AnimXmlElement element ("anim");
2392  element.AddAttribute ("ver", GetNetAnimVersion ());
2393  FILE * f = m_f;
2394  if (!routing)
2395  {
2396  element.AddAttribute ("filetype", "animation");
2397  }
2398  else
2399  {
2400  element.AddAttribute ("filetype", "routing");
2401  f = m_routingF;
2402  }
2403  WriteN (element.ToString (false) + ">\n", f);
2404 }
2405 
2406 void
2407 AnimationInterface::WriteXmlClose (std::string name, bool routing)
2408 {
2409  std::string closeString = "</" + name + ">\n";
2410  if (!routing)
2411  {
2412  WriteN (closeString, m_f);
2413  }
2414  else
2415  {
2416  WriteN (closeString, m_routingF);
2417  }
2418 }
2419 
2420 void
2421 AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2422 {
2423  AnimXmlElement element ("node");
2424  element.AddAttribute ("id", id);
2425  element.AddAttribute ("sysId", sysId);
2426  element.AddAttribute ("locX", locX);
2427  element.AddAttribute ("locY", locY);
2428  WriteN (element.ToString (), m_f);
2429 }
2430 
2431 void
2432 AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2433 {
2434  AnimXmlElement element ("linkupdate");
2435  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2436  element.AddAttribute ("fromId", fromId);
2437  element.AddAttribute ("toId", toId);
2438  element.AddAttribute ("ld", linkDescription, true);
2439  WriteN (element.ToString (), m_f);
2440 }
2441 
2442 void
2443 AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2444 {
2445  AnimXmlElement element ("link");
2446  element.AddAttribute ("fromId", fromId);
2447  element.AddAttribute ("toId", toId);
2448 
2449  LinkProperties lprop ;
2450  lprop.fromNodeDescription = "";
2451  lprop.toNodeDescription = "";
2452  lprop.linkDescription = "";
2453 
2454  P2pLinkNodeIdPair p1 = { fromId, toId };
2455  P2pLinkNodeIdPair p2 = { toId, fromId };
2456  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2457  {
2458  lprop = m_linkProperties[p1];
2459  }
2460  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2461  {
2462  lprop = m_linkProperties[p2];
2463  }
2464 
2465  element.AddAttribute ("fd", lprop.fromNodeDescription, true);
2466  element.AddAttribute ("td", lprop.toNodeDescription, true);
2467  element.AddAttribute ("ld", lprop.linkDescription, true);
2468  WriteN (element.ToString (), m_f);
2469 }
2470 
2471 void
2472 AnimationInterface::WriteXmlIpv4Addresses (uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2473 {
2474  AnimXmlElement element ("ip");
2475  element.AddAttribute ("n", nodeId);
2476  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
2477  i != ipv4Addresses.end ();
2478  ++i)
2479  {
2480  AnimXmlElement valueElement ("address");
2481  valueElement.SetText (*i);
2482  element.AppendChild(valueElement);
2483  }
2484  WriteN (element.ToString (), m_f);
2485 }
2486 
2487 void
2488 AnimationInterface::WriteXmlIpv6Addresses (uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2489 {
2490  AnimXmlElement element ("ipv6");
2491  element.AddAttribute("n", nodeId);
2492  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin ();
2493  i != ipv6Addresses.end ();
2494  ++i)
2495  {
2496  AnimXmlElement valueElement ("address");
2497  valueElement.SetText (*i);
2498  element.AppendChild (valueElement);
2499  }
2500  WriteN(element.ToString (), m_f);
2501 }
2502 
2503 void
2504 AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2505 {
2506  AnimXmlElement element ("rt");
2507  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2508  element.AddAttribute ("id", nodeId);
2509  element.AddAttribute ("info", routingInfo.c_str (), true);
2510  WriteN (element.ToString (), m_routingF);
2511 }
2512 
2513 void
2514 AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2515 {
2516  std::string tagName = "rp";
2517  AnimXmlElement element (tagName, false);
2518  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2519  element.AddAttribute ("id", nodeId);
2520  element.AddAttribute ("d", destination.c_str ());
2521  element.AddAttribute ("c", rpElements.size ());
2522  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2523  i != rpElements.end ();
2524  ++i)
2525  {
2526  Ipv4RoutePathElement rpElement = *i;
2527  AnimXmlElement rpeElement ("rpe");
2528  rpeElement.AddAttribute ("n", rpElement.nodeId);
2529  rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2530  element.AppendChild (rpeElement);
2531  }
2532  WriteN (element.ToString (), m_routingF);
2533 }
2534 
2535 
2536 void
2537 AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2538 {
2539  AnimXmlElement element ("pr");
2540  element.AddAttribute ("uId", animUid);
2541  element.AddAttribute ("fId", fId);
2542  element.AddAttribute ("fbTx", fbTx);
2543  if (!metaInfo.empty ())
2544  {
2545  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2546  }
2547  WriteN (element.ToString (), m_f);
2548 }
2549 
2550 void
2551 AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2552 {
2553  AnimXmlElement element (pktType);
2554  element.AddAttribute ("uId", animUid);
2555  element.AddAttribute ("tId", tId);
2556  element.AddAttribute ("fbRx", fbRx);
2557  element.AddAttribute ("lbRx", lbRx);
2558  WriteN (element.ToString (), m_f);
2559 }
2560 
2561 void
2562 AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2563  uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2564 {
2565  AnimXmlElement element (pktType);
2566  element.AddAttribute ("fId", fId);
2567  element.AddAttribute ("fbTx", fbTx);
2568  element.AddAttribute ("lbTx", lbTx);
2569  if (!metaInfo.empty ())
2570  {
2571  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2572  }
2573  element.AddAttribute ("tId", tId);
2574  element.AddAttribute ("fbRx", fbRx);
2575  element.AddAttribute ("lbRx", lbRx);
2576  WriteN (element.ToString (), m_f);
2577 }
2578 
2579 void
2580 AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2581 {
2582  AnimXmlElement element ("ncs");
2583  element.AddAttribute ("ncId", nodeCounterId);
2584  element.AddAttribute ("n", counterName);
2585  element.AddAttribute ("t", CounterTypeToString (counterType));
2586  WriteN (element.ToString (), m_f);
2587 }
2588 
2589 void
2590 AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2591 {
2592  AnimXmlElement element ("res");
2593  element.AddAttribute ("rid", resourceId);
2594  element.AddAttribute ("p", resourcePath);
2595  WriteN (element.ToString (), m_f);
2596 }
2597 
2598 void
2599 AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2600 {
2601  AnimXmlElement element ("nu");
2602  element.AddAttribute ("p", "i");
2603  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2604  element.AddAttribute ("id", nodeId);
2605  element.AddAttribute ("rid", resourceId);
2606  WriteN (element.ToString (), m_f);
2607 }
2608 
2609 void
2610 AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2611 {
2612  AnimXmlElement element ("nu");
2613  element.AddAttribute ("p", "s");
2614  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2615  element.AddAttribute ("id", nodeId);
2616  element.AddAttribute ("w", width);
2617  element.AddAttribute ("h", height);
2618  WriteN (element.ToString (), m_f);
2619 }
2620 
2621 void
2622 AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2623 {
2624  AnimXmlElement element ("nu");
2625  element.AddAttribute ("p", "p");
2626  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2627  element.AddAttribute ("id", nodeId);
2628  element.AddAttribute ("x", x);
2629  element.AddAttribute ("y", y);
2630  WriteN (element.ToString (), m_f);
2631 }
2632 
2633 void
2634 AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2635 {
2636  AnimXmlElement element ("nu");
2637  element.AddAttribute ("p", "c");
2638  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2639  element.AddAttribute ("id", nodeId);
2640  element.AddAttribute ("r", (uint32_t) r);
2641  element.AddAttribute ("g", (uint32_t) g);
2642  element.AddAttribute ("b", (uint32_t) b);
2643  WriteN (element.ToString (), m_f);
2644 }
2645 
2646 void
2648 {
2649  AnimXmlElement element ("nu");
2650  element.AddAttribute ("p", "d");
2651  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2652  element.AddAttribute ("id", nodeId);
2653  if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2654  {
2655  element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
2656  }
2657  WriteN (element.ToString (), m_f);
2658 }
2659 
2660 
2661 void
2662 AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2663 {
2664  AnimXmlElement element ("nc");
2665  element.AddAttribute ("c", nodeCounterId);
2666  element.AddAttribute ("i", nodeId);
2667  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2668  element.AddAttribute ("v", counterValue);
2669  WriteN (element.ToString (), m_f);
2670 }
2671 
2672 void
2673 AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2674 {
2675  AnimXmlElement element ("bg");
2676  element.AddAttribute ("f", fileName);
2677  element.AddAttribute ("x", x);
2678  element.AddAttribute ("y", y);
2679  element.AddAttribute ("sx", scaleX);
2680  element.AddAttribute ("sy", scaleY);
2681  element.AddAttribute ("o", opacity);
2682  WriteN (element.ToString (), m_f);
2683 }
2684 
2685 void
2686 AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType)
2687 {
2688  AnimXmlElement element ("nonp2plinkproperties");
2689  element.AddAttribute ("id", id);
2690  element.AddAttribute ("ipAddress", ipAddress);
2691  element.AddAttribute ("channelType", channelType);
2692  WriteN (element.ToString (), m_f);
2693 }
2694 
2695 
2696 
2697 /***** AnimXmlElement *****/
2698 
2699 AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement) :
2700  m_tagName(tagName),
2701  m_text("")
2702 {
2703 }
2704 
2705 template <typename T>
2706 void
2707 AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape)
2708 {
2709  std::ostringstream oss;
2710  oss << std::setprecision(10);
2711  oss << value;
2712  std::string attributeString = attribute.c_str();
2713  if (xmlEscape)
2714  {
2715  attributeString += "=\"";
2716  std::string valueStr = oss.str();
2717  for (std::string::iterator it = valueStr.begin(); it != valueStr.end(); ++it)
2718  {
2719  switch (*it)
2720  {
2721  case '&':
2722  attributeString += "&amp;";
2723  break;
2724  case '\"':
2725  attributeString += "&quot;";
2726  break;
2727  case '\'':
2728  attributeString += "&apos;";
2729  break;
2730  case '<':
2731  attributeString += "&lt;";
2732  break;
2733  case '>':
2734  attributeString += "&gt;";
2735  break;
2736  default:
2737  attributeString += *it;
2738  break;
2739  }
2740  }
2741  attributeString += "\" ";
2742  }
2743  else
2744  {
2745  attributeString += "=\"" + oss.str() + "\" ";
2746  }
2747  m_attributes.push_back(attributeString);
2748 }
2749 
2750 void
2752 {
2753  m_children.push_back(e.ToString());
2754 }
2755 
2756 void
2758 {
2759  m_text = text;
2760 }
2761 
2762 std::string
2764 {
2765  std::string elementString = "<" + m_tagName + " ";
2766 
2767 
2768  for (std::vector<std::string>::const_iterator i = m_attributes.begin();
2769  i != m_attributes.end();
2770  ++i)
2771  {
2772  elementString += *i;
2773  }
2774  if (m_children.empty() && m_text.empty())
2775  {
2776  if (autoClose)
2777  {
2778  elementString += "/>";
2779  }
2780  }
2781  else
2782  {
2783  elementString += ">";
2784  if (!m_text.empty())
2785  {
2786  elementString += m_text;
2787  }
2788  if (!m_children.empty())
2789  {
2790  elementString += "\n";
2791  for (std::vector<std::string>::const_iterator i = m_children.begin();
2792  i != m_children.end();
2793  ++i)
2794  {
2795  elementString += *i + "\n";
2796  }
2797 
2798  }
2799  if (autoClose)
2800  {
2801  elementString += "</" + m_tagName + ">";
2802  }
2803  }
2804 
2805 
2806  return elementString + ((autoClose) ?"\n": "");
2807 }
2808 
2809 
2810 
2811 
2812 
2813 /***** AnimByteTag *****/
2814 
2815 TypeId
2817 {
2818  static TypeId tid = TypeId ("ns3::AnimByteTag")
2819  .SetParent<Tag> ()
2820  .SetGroupName ("NetAnim")
2821  .AddConstructor<AnimByteTag> ()
2822  ;
2823  return tid;
2824 }
2825 
2826 TypeId
2828 {
2829  return GetTypeId ();
2830 }
2831 
2832 uint32_t
2834 {
2835  return sizeof (uint64_t);
2836 }
2837 
2838 void
2840 {
2841  i.WriteU64 (m_AnimUid);
2842 }
2843 
2844 void
2846 {
2847  m_AnimUid = i.ReadU64 ();
2848 }
2849 
2850 void
2851 AnimByteTag::Print (std::ostream &os) const
2852 {
2853  os << "AnimUid=" << m_AnimUid;
2854 }
2855 
2856 void
2857 AnimByteTag::Set (uint64_t AnimUid)
2858 {
2859  m_AnimUid = AnimUid;
2860 }
2861 
2862 uint64_t
2863 AnimByteTag::Get (void) const
2864 {
2865  return m_AnimUid;
2866 }
2867 
2869  : m_txnd (0),
2870  m_txNodeId (0),
2871  m_fbTx (0),
2872  m_lbTx (0),
2873  m_lbRx (0)
2874 {
2875 }
2876 
2878 {
2879  m_txnd = pInfo.m_txnd;
2880  m_txNodeId = pInfo.m_txNodeId;
2881  m_fbTx = pInfo.m_fbTx;
2882  m_lbTx = pInfo.m_lbTx;
2883  m_lbRx = pInfo.m_lbRx;
2884 }
2885 
2887  const Time fbTx,
2888  uint32_t txNodeId)
2889  : m_txnd (txnd),
2890  m_txNodeId (0),
2891  m_fbTx (fbTx.GetSeconds ()),
2892  m_lbTx (0),
2893  m_lbRx (0)
2894 {
2895  if (!m_txnd)
2896  m_txNodeId = txNodeId;
2897 }
2898 
2899 void
2901 {
2902  Ptr <Node> n = nd->GetNode ();
2903  m_fbRx = fbRx;
2904  m_rxnd = nd;
2905 }
2906 
2907 } // namespace ns3
void GenericWirelessTxTrace(std::string context, Ptr< const Packet > p, ProtocolType protocolType)
Generic wireless transmit trace function.
uint64_t GetAnimUidFromPacket(Ptr< const Packet >)
Get anim UID from packet function.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:835
void Set(uint64_t AnimUid)
Set global Uid in tag.
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing)
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)
Write XMLRP function.
TypeId GetTypeId(void) const
Definition: packet.cc:34
void AddPendingPacket(ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
Add pending packet function.
void CsmaMacRxTrace(std::string context, Ptr< const Packet > p)
CSMA MAC receive trace function.
Ipv6Address GetAddress() const
Get the IPv6 address.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void MobilityAutoCheck()
Mobility auto check function.
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
void Print(std::ostream &os) const
Print the packet contents.
Definition: packet.cc:434
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string linkDescription)
Write XML update link counter function.
NodeCounterMap64 m_nodeQueueDequeue
node queue dequeue
uint64_t Get(void) const
Get Uid in tag.
void LteTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
LTE transmit trace function.
void LrWpanMacTxDropTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC transmit drop trace function.
uint32_t GetId(void) const
Definition: node.cc:107
FILE * m_routingF
File handle for routing table output (0 if None);.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
bool HasNext(void) const
Definition: packet.cc:65
std::string GetIpv4Address(Ptr< NetDevice > nd)
Get IPv4 address.
std::string CounterTypeToString(CounterType counterType)
Counter type to string function.
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)
Write XML update node image function.
std::string GetIpv6Address(Ptr< NetDevice > nd)
Get IPv6 address.
virtual void Serialize(TagBuffer i) const
Serialize function.
NodeCounterMap64 m_nodeLrWpanMacRxDrop
node LR-WPAN MAC receive drop
std::map< std::string, uint32_t > m_ipv6ToNodeIdMap
IPv6 to node ID map.
static TypeId GetTypeId(void)
Get Type Id.
void WriteXmlIpv6Addresses(uint32_t nodeId, std::vector< std::string > ipv6Addresses)
Write XML Ipv6 addresses function.
void WriteNodes()
Write nodes function.
void TrackIpv4L3ProtocolCounters()
Track IPv4 L3 protocol counters function.
Introspection did not find any typical Config paths.
Definition: energy-source.h:81
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
CSMA Phy transmit begin trace function.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
Mobility model for which the current position does not change once it has been set and until it is se...
AnimUidPacketInfoMap m_pendingWifiPackets
pending wifi packets
void WriteXmlUpdateNodePosition(uint32_t nodeId, double x, double y)
Write XML update node position function.
NodeDescriptionsMap m_nodeDescriptions
node description
std::string ToString(bool autoClose=true)
Get text for the element function.
static bool IsInitialized(void)
Check if AnimationInterface is initialized.
uint32_t m_ipv4L3ProtocolTxCounterId
IPv4 L3 protocol transmit counter ID.
void WifiMacTxDropTrace(std::string context, Ptr< const Packet > p)
wifi MAC transmit drop trace function
void PurgePendingPackets(ProtocolType protocolType)
Purge pending packets function.
#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
uint32_t m_queueEnqueueCounterId
queue enqueue counter ID
uint64_t m_maxPktsPerFile
maximum pakets per file
virtual Ptr< Node > GetNode(void) const =0
void QueueDropTrace(std::string context, Ptr< const Packet >)
Queue trace function.
#define NETANIM_VERSION
void WifiMacRxTrace(std::string context, Ptr< const Packet > p)
wifi MAC receive trace function
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
IPv6 address associated with an interface.
std::map< std::string, uint32_t > m_macToNodeIdMap
MAC to node ID map.
Time m_ipv4L3ProtocolCountersPollInterval
IPv4 L3 protocol counters poll interval.
void LteSpectrumPhyRxStart(std::string context, Ptr< const PacketBurst > pb)
LTE Spectrum Phy receive start function.
void TrackQueueCounters()
Track queue counters function.
void TrackWifiPhyCounters()
Track wifi phy counters function.
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Get net device from context.
void WifiPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
wifi Phy transmit begin trace function
void EnableWifiPhyCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Wifi Phy Counters such as TxDrop, RxDrop.
void TrackIpv4RoutePaths()
Track IPv4 route paths function.
NodeContainer m_routingNc
routing node container
Time m_ipv4L3ProtocolCountersStopTime
IPv4 L3 protocol counters stop time.
void WriteXmlAnim(bool routing=false)
Write XML anim function.
uint64_t m_currentPktCount
current packet count
std::pair< uint32_t, std::string > NodeIdIpv6Pair
NodeIdIpv6Pair typedef.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void WimaxRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
WIMax receive trace function.
NodeCounterMap64 m_nodeWifiPhyTxDrop
node wifi Phy transmit drop
void LrWpanMacRxDropTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC receive drop trace function.
#define CHECK_STARTED_INTIMEWINDOW
void Ipv4RxTrace(std::string context, Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 receive trace function.
Represent the Mac Header with the Frame Control and Sequence Number fields.
std::map< std::string, uint32_t > m_ipv4ToNodeIdMap
IPv4 to node ID map.
void WavePhyTxBeginTrace(std::string context, Ptr< const Packet > p)
WAVE Phy transmit begin trace function.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
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)
Write XML add node counter function.
void ProcessRxBegin(Ptr< const NetDevice > nd, const double fbRx)
Process receive begin.
void ConnectLteEnb(Ptr< Node > n, Ptr< LteEnbNetDevice > nd, uint32_t devIndex)
Connect LTE ENB function.
std::string GetIpv4RoutingTable(Ptr< Node > n)
Get IPv4 routing table function.
void WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
Write XML update node size function.
void WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
Write XML update node color function.
void WriteIpv6Addresses()
Write IPv6 Addresses function.
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()
Get moved nodes function.
LinkPropertiesMap m_linkProperties
link properties
Time m_queueCountersPollInterval
queue counters poll interval
void WifiPhyRxBeginTrace(std::string context, Ptr< const Packet > p)
wifi Phy receive begin trace function
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color.
#define CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS
double stopTime
void WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
Write XML add resource function.
void ResetAnimWriteCallback()
Reset the write callback function.
NodeCounterMap64 m_nodeWifiMacTx
node wifi MAC transmit
AnimWriteCallback m_writeCallback
write callback
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet > p)
wifi Phy receive drop trace function
a polymophic address class
Definition: address.h:90
void UanPhyGenTxTrace(std::string context, Ptr< const Packet >)
UAN Phy gen transmit trace function.
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
mobility
Definition: third.py:101
an EUI-64 address
Definition: mac64-address.h:43
void CheckMaxPktsPerTraceFile()
Check maximum packets per trace file function.
void AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId)
Add to IPv6 address node ID table function.
DropReason
Reason why a packet has been dropped.
void ConnectLteUe(Ptr< Node > n, Ptr< LteUeNetDevice > nd, uint32_t devIndex)
Connect LTE ue function.
void WriteNodeColors()
Write node colors function.
std::map< uint32_t, Vector > m_nodeLocation
node location
Keep track of the current position and velocity of an object.
Packet header for IPv4.
Definition: ipv4-header.h:33
void SetBackgroundImage(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Helper function to set the background image.
void LteRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
LTE receive trace function.
uint32_t m_ipv4L3ProtocolRxCounterId
IPv4 L3 protocol receive counter ID.
void CsmaPhyRxEndTrace(std::string context, Ptr< const Packet > p)
CSMA Phy receive end trace function.
NodeIdIpv6Map m_nodeIdIpv6Map
node ID to IPv6 map
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)
Remaining energy trace function.
uint32_t m_wifiPhyTxDropCounterId
wifi Phy transmit drop counter ID
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
void WriteXmlClose(std::string name, bool routing=false)
Write XML close function.
void OutputWirelessPacketTxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
Output wireless packet transmit info.
int WriteN(const char *data, uint32_t count, FILE *f)
WriteN function.
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:572
void UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
Helper function to update a node&#39;s counter referenced by the nodeCounterId.
virtual TypeId GetInstanceTypeId(void) const
Get Instance Type Id.
uint32_t m_queueDropCounterId
queue drop counter ID
uint32_t AddNodeCounter(std::string counterName, CounterType counterType)
Setup a node counter.
~AnimationInterface()
Destructor for the animator interface.
AnimUidPacketInfoMap m_pendingWimaxPackets
pending wimax packets
std::vector< std::string > GetIpv4Addresses(Ptr< NetDevice > nd)
Get IPv4 addresses.
EnergyFractionMap m_nodeEnergyFraction
node energy fraction
bool m_trackPackets
track packets
void SkipPacketTracing()
Do not trace packets.
double startTime
static Iterator End(void)
Definition: node-list.cc:235
uint8_t data[writeSize]
std::string GetNetAnimVersion()
Get netanim version function.
void RecursiveIpv4RoutePathSearch(std::string from, std::string to, Ipv4RoutePathElements &rpElements)
Recursive IPv4 route path search function.
void WriteXmlNonP2pLinkProperties(uint32_t id, std::string ipAddress, std::string channelType)
Write XML non P2P link properties function.
std::string m_outputFileName
output file name
FILE * m_f
File handle for output (0 if none)
void DequeueTrace(std::string context, Ptr< const Packet >)
Dequeue trace function.
NodeCounterMap64 m_nodeIpv4Drop
node IPv4 drop
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
void UanPhyGenRxTrace(std::string context, Ptr< const Packet >)
UAN Phy gen receive trace function.
std::pair< uint32_t, std::string > NodeIdIpv4Pair
NodeIdIpv4Pair typedef.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:832
void WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, uint32_t tId, double fbRx, double lbRx, std::string metaInfo="")
Write XMLP function.
Item Next(void)
Definition: packet.cc:70
void StartAnimation(bool restart=false)
Start animation function.
void WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
Write XML node function.
std::vector< Ipv4RoutePathElement > Ipv4RoutePathElements
Ipv4RoutePathElements typedef.
void Ipv4TxTrace(std::string context, Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 transmit trace function.
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)
Constructor.
AnimUidPacketInfoMap m_pendingLrWpanPackets
pending LR-WPAN packets
std::map< uint32_t, NodeSize > m_nodeSizes
node sizes
void WifiPhyTxDropTrace(std::string context, Ptr< const Packet > p)
wifi Phy transmit drop trace function
Ptr< LteEnbPhy > GetPhy(void) const
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
void WavePhyRxBeginTrace(std::string context, Ptr< const Packet > p)
WAVE Phy receive begin trace function.
#define list
void CsmaPhyTxEndTrace(std::string context, Ptr< const Packet > p)
CSMA Phy transmit end trace function.
std::string GetPacketMetadata(Ptr< const Packet > p)
Get packet metadata function.
Time m_wifiMacCountersPollInterval
wifi MAC counters poll interval
std::vector< std::string > m_resources
resources
void WriteXmlIpv4Addresses(uint32_t nodeId, std::vector< std::string > ipv4Addresses)
Write XML Ipv4 addresses function.
NodeIdIpv4Map m_nodeIdIpv4Map
node ID to IPv4 map
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
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)
Device transmit trace function.
Time m_wifiPhyCountersPollInterval
wifi Phy counters poll interval
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
double f(double x, void *params)
Definition: 80211b.c:70
tag a set of bytes in a packet
Definition: tag.h:36
NodeColorsMap m_nodeColors
node colors
void WriteXmlRouting(uint32_t id, std::string routingInfo)
Write XML routing function.
NodeCounterMap64 m_nodeLrWpanMacTxDrop
node LR-WPAN MAC transmit drop
void WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo="")
Write XMLP Ref function.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetSrcAddrMode(void) const
Get the Source Addressing Mode of Frame control field.
uint32_t m_wifiMacRxDropCounterId
wifi MAC receive drop counter ID
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.
ProtocolType
ProtocolType enumeration.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
NodeCounterMap64 m_nodeLrWpanMacTx
node LR-WPAN MAC transmit
void ConnectCallbacks()
Connect callbacks function.
void SetMaxPktsPerTraceFile(uint64_t maxPktsPerFile)
Set Max packets per trace file.
bool NodeHasMoved(Ptr< Node > n, Vector newLocation)
Node has moved function.
uint8_t g
green
void WriteNodeEnergies()
Write node energies function.
uint64_t gAnimUid
Packet unique identifier used by AnimationInterface.
std::vector< std::string > GetIpv6Addresses(Ptr< NetDevice > nd)
Get IPv6 addresses.
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
Iterator over the set of byte tags in a packet.
Definition: packet.h:54
void AddToIpv4AddressNodeIdTable(std::string ipv4Address, uint32_t nodeId)
Add to IPv4 address node ID table function.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
an EUI-48 address
Definition: mac48-address.h:43
Time m_routingPollInterval
routing poll interval
NodeCounterMap64 m_nodeQueueDrop
node queue drop
uint32_t m_wifiMacRxCounterId
wifi MAC receive counter ID
void LrWpanPhyRxBeginTrace(std::string context, Ptr< const Packet > p)
LR-WPAN Phy receive begin trace function.
AnimUidPacketInfoMap m_pendingLtePackets
pending LTE packets
void TrackWifiMacCounters()
Track wifi MAC counters function.
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
std::map< uint64_t, AnimPacketInfo > AnimUidPacketInfoMap
AnimUidPacketInfoMap typedef.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void WriteXmlUpdateNodeDescription(uint32_t nodeId)
Write XML update node description function.
void AppendChild(AnimXmlElement e)
Append child function.
void EnqueueTrace(std::string context, Ptr< const Packet >)
Enqueue trace function.
Byte tag using by Anim to uniquely identify packets.
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
uint32_t m_wifiMacTxCounterId
wifi MAC transmit counter ID
void StopAnimation(bool onlyAnimation=false)
Stop animation function.
const std::vector< std::string > GetElementsFromContext(const std::string &context) const
Get elements from context.
void WriteXmlUpdateNodeCounter(uint32_t counterId, uint32_t nodeId, double value)
Write XML update node counter function.
AnimUidPacketInfoMap m_pendingWavePackets
pending WAVE packets
Vector UpdatePosition(Ptr< Node > n)
Update position function.
void LrWpanMacRxTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC receive trace function.
Ptr< const NetDevice > m_rxnd
receive device
Vector GetPosition(void) const
virtual uint32_t GetSerializedSize(void) const
Get Serialized Size.
void WriteNodeSizes()
Write node sizes function.
double GetNodeEnergyFraction(Ptr< const Node > node) const
Get node&#39;s energy fraction (This used only for testing)
void GenericWirelessRxTrace(std::string context, Ptr< const Packet > p, ProtocolType protocolType)
Generic wireless receive trace function.
NodeCounterMap64 m_nodeIpv4Rx
node IPv4 receive
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
std::vector< Ipv4RouteTrackElement > m_ipv4RouteTrackElements
IPv route track elements.
NodeCounterMap64 m_nodeWifiMacRxDrop
node wifi MAC receive drop
void MobilityCourseChangeTrace(Ptr< const MobilityModel > mob)
Mobility course change trace function.
void WimaxTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
WIMax transmit trace function.
read and write tag data
Definition: tag-buffer.h:51
NodeCounterMap64 m_nodeWifiPhyRxDrop
node wifi Phy receive drop
std::string m_routingFileName
routing file name
bool IsPacketPending(uint64_t animUid, ProtocolType protocolType)
Is packet pending function.
void SetText(std::string text)
Set text function.
a class to store IPv4 address information on an interface
uint8_t b
blue
static bool initialized
Initialization flag.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
uint32_t m_queueDequeueCounterId
queue dequeue counter ID
std::string GetMacAddress(Ptr< NetDevice > nd)
Get MAC address function.
static Iterator Begin(void)
Definition: node-list.cc:229
NodeCounterMap64 m_nodeIpv4Tx
node IPv4 transmit
NodeCounterMap64 m_nodeWifiMacRx
node wifi MAC receive
AnimUidPacketInfoMap m_pendingUanPackets
pending UAN packets
#define MAX_PKTS_PER_TRACE_FILE
std::string ProtocolTypeToString(ProtocolType protocolType)
Protocol type to string function.
void AddByteTag(uint64_t animUid, Ptr< const Packet > p)
Add byte tag function.
A network Node.
Definition: node.h:56
void ConnectLte()
Connect LTE function.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
void WifiMacTxTrace(std::string context, Ptr< const Packet > p)
wifi MAC transmit trace function
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void WriteXmlUpdateBackground(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Write XML update background function.
Interface to network animator.
void WriteNonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
Write non P2P link properties function.
bool m_enablePacketMetadata
enable packet metadata
Ptr< const NetDevice > m_txnd
transmit device
uint32_t m_wifiMacTxDropCounterId
wifi MAC transmit drop counter ID
NodeCounterMap64 m_nodeLrWpanMacRx
node LR-WPAN MAC receive
Time m_wifiPhyCountersStopTime
wifi Phy counters stop time
void OutputWirelessPacketRxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
Output wireless packet receive info.
void LrWpanMacTxTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC transmit trace function.
void Ipv4DropTrace(std::string context, const Ipv4Header &ipv4Header, Ptr< const Packet > p, Ipv4L3Protocol::DropReason dropReason, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 drop trace function.
Ipv4Address GetLocal(void) const
Get the local address.
static bool IsFinished(void)
Check if the simulation should finish.
Definition: simulator.cc:219
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.
NodeCounterMap64 m_nodeQueueEnqueue
node queue enqueue
uint32_t m_wifiPhyRxDropCounterId
wifi Phy receive drop counter ID
Time m_wifiMacCountersStopTime
wifi MAC counters stop time
void LrWpanPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
LR-WPAN Phy receive begin trace function.
virtual void Print(std::ostream &os) const
Print tag info.
void WriteRoutePath(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
Write route path function.
void WriteLinkProperties()
Write link properties function.
Time m_mobilityPollInterval
mobility poll interval
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:49
bool IsStarted(void)
Is AnimationInterface started.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
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)
Protocol type to pending packets function.
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)
Add attribute function.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
uint32_t m_remainingEnergyCounterId
remaining energy counter ID
void WriteIpv4Addresses()
Write IPv4 Addresses function.
Vector GetPosition(Ptr< Node > n)
Get position function.
bool IsInTimeWindow()
Is in time window function.
a unique identifier for an interface.
Definition: type-id.h:58
NodeCounterMap64 m_nodeWifiMacTxDrop
node wifi MAC transmit drop
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:819
std::vector< std::string > m_nodeCounters
node counters
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)
Output CSMA packet function.
Time m_routingStopTime
routing stop time
uint32_t m_ipv4L3ProtocolDropCounterId
IPv4 protocol drop counter ID.
Ptr< Node > GetNodeFromContext(const std::string &context) const
Get node from context.
Implements the IEEE 802.11 MAC header.
#define PURGE_INTERVAL
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Time m_queueCountersStopTime
queue counters stop time
RGB structure.
void SetOutputFile(const std::string &fn, bool routing=false)
Set output file function.
ByteTagIterator GetByteTagIterator(void) const
Returns an iterator over the set of byte tags included in this packet.
Definition: packet.cc:829
void LteSpectrumPhyTxStart(std::string context, Ptr< const PacketBurst > pb)
LTE Spectrum Phy transmit start function.
AnimUidPacketInfoMap m_pendingCsmaPackets
pending CSMA packets
void WifiMacRxDropTrace(std::string context, Ptr< const Packet > p)
wifi MAC receive drop trace function
void WriteXmlLink(uint32_t fromId, uint32_t toLp, uint32_t toId)
Write XML link counter function.
uint8_t r
red
void TrackIpv4Route()
Track IPv4 router function.