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
870 AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr<const Packet> p, double txPowerW)
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_MSG (false, "WifiPhyRxBeginTrace: unknown Uid");
889  std::ostringstream oss;
890  WifiMacHeader hdr;
891  if (!p->PeekHeader (hdr))
892  {
893  NS_LOG_WARN ("WifiMacHeader not present");
894  return;
895  }
896  oss << hdr.GetAddr2 ();
897  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
898  {
899  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
900  return;
901  }
902  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
903  UpdatePosition (txNode);
904  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
905  AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
906  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
907  }
909  m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
910  OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid);
911 }
912 
913 void
916 {
917  NS_LOG_FUNCTION (this);
919 
920  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
921  NS_ASSERT (ndev);
922  Ptr<LrWpanNetDevice> netDevice = DynamicCast<LrWpanNetDevice> (ndev);
923 
924  Ptr <Node> n = ndev->GetNode ();
925  NS_ASSERT (n);
926 
927  UpdatePosition (n);
928 
929  LrWpanMacHeader hdr;
930  if (!p->PeekHeader (hdr))
931  {
932  NS_LOG_WARN ("LrWpanMacHeader not present");
933  return;
934  }
935 
936  std::ostringstream oss;
937  if (hdr.GetSrcAddrMode () == 2)
938  {
939  Mac16Address nodeAddr = netDevice->GetMac ()->GetShortAddress ();
940  oss << nodeAddr;
941  }
942  else if (hdr.GetSrcAddrMode () == 3)
943  {
944  Mac64Address nodeAddr = netDevice->GetMac ()->GetExtendedAddress ();
945  oss << nodeAddr;
946  }
947  else
948  {
949  NS_LOG_WARN ("LrWpanMacHeader without source address");
950  return;
951  }
952  m_macToNodeIdMap[oss.str ()] = n->GetId ();
953  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
954 
955  ++gAnimUid;
956  NS_LOG_INFO ("LrWpan TxBeginTrace for packet:" << gAnimUid);
957  AddByteTag (gAnimUid, p);
958 
959  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
961 
963 }
964 
965 void
968 {
969  NS_LOG_FUNCTION (this);
971  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
972  NS_ASSERT (ndev);
973  Ptr <Node> n = ndev->GetNode ();
974  NS_ASSERT (n);
975 
976  AnimByteTag tag;
977  if (!p->FindFirstMatchingByteTag (tag))
978  {
979  return;
980  }
981 
982  uint64_t animUid = GetAnimUidFromPacket (p);
983  NS_LOG_INFO ("LrWpan RxBeginTrace for packet:" << animUid);
985  {
986  NS_LOG_WARN ("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
987  }
988 
989  UpdatePosition (n);
990  m_pendingLrWpanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
991  OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid);
992 }
993 
994 void
996 {
997  NS_LOG_FUNCTION (this);
999 }
1000 
1001 void
1003 {
1004  NS_LOG_FUNCTION (this);
1006  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1007  NS_ASSERT (ndev);
1008  UpdatePosition (ndev);
1009  uint64_t animUid = GetAnimUidFromPacket (p);
1010  NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid);
1011  if (!IsPacketPending (animUid, AnimationInterface::WAVE))
1012  {
1013  NS_ASSERT_MSG (false, "WavePhyRxBeginTrace: unknown Uid");
1014  std::ostringstream oss;
1015  WifiMacHeader hdr;
1016  if (!p->PeekHeader (hdr))
1017  {
1018  NS_LOG_WARN ("WaveMacHeader not present");
1019  return;
1020  }
1021  oss << hdr.GetAddr2 ();
1022  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1023  {
1024  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
1025  return;
1026  }
1027  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
1028  UpdatePosition (txNode);
1029  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
1030  AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo);
1031  NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet");
1032  }
1034  m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1035  OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid);
1036 }
1037 
1038 
1039 void
1041 {
1042  NS_LOG_FUNCTION (this);
1044 }
1045 
1046 
1047 void
1049 {
1050  NS_LOG_FUNCTION (this);
1052 }
1053 
1054 void
1056 {
1057  NS_LOG_FUNCTION (this);
1058  return GenericWirelessTxTrace (context, p, AnimationInterface::LTE);
1059 }
1060 
1061 void
1063 {
1064  NS_LOG_FUNCTION (this);
1065  return GenericWirelessRxTrace (context, p, AnimationInterface::LTE);
1066 }
1067 
1068 void
1070 {
1071  NS_LOG_FUNCTION (this);
1073  if (!pb)
1074  {
1075  NS_LOG_WARN ("pb == 0. Not yet supported");
1076  return;
1077  }
1078  context = "/" + context;
1079  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1080  NS_ASSERT (ndev);
1081  UpdatePosition (ndev);
1082 
1083  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1084  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1085  i != pbList.end ();
1086  ++i)
1087  {
1088  Ptr <Packet> p = *i;
1089  ++gAnimUid;
1090  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1091  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1092  AddByteTag (gAnimUid, p);
1094  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
1095  }
1096 }
1097 
1098 void
1100 {
1101  NS_LOG_FUNCTION (this);
1103  if (!pb)
1104  {
1105  NS_LOG_WARN ("pb == 0. Not yet supported");
1106  return;
1107  }
1108  context = "/" + context;
1109  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1110  NS_ASSERT (ndev);
1111  UpdatePosition (ndev);
1112 
1113  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1114  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1115  i != pbList.end ();
1116  ++i)
1117  {
1118  Ptr <Packet> p = *i;
1119  uint64_t animUid = GetAnimUidFromPacket (p);
1120  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1121  if (!IsPacketPending (animUid, AnimationInterface::LTE))
1122  {
1123  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1124  return;
1125  }
1126  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1127  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1128  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
1129  }
1130 }
1131 
1132 void
1134 {
1135  NS_LOG_FUNCTION (this);
1137  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1138  NS_ASSERT (ndev);
1139  UpdatePosition (ndev);
1140  ++gAnimUid;
1141  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1142  AddByteTag (gAnimUid, p);
1143  UpdatePosition (ndev);
1144  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1146 
1147 
1148 }
1149 
1150 void
1152 {
1153  NS_LOG_FUNCTION (this);
1155  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1156  NS_ASSERT (ndev);
1157  UpdatePosition (ndev);
1158  uint64_t animUid = GetAnimUidFromPacket (p);
1159  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid);
1160  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1161  {
1162  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1163  NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid");
1164  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1165  AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1166  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1167  }
1169  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1170  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1171 }
1172 
1173 void
1175 {
1176  NS_LOG_FUNCTION (this);
1178  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1179  NS_ASSERT (ndev);
1180  UpdatePosition (ndev);
1181  uint64_t animUid = GetAnimUidFromPacket (p);
1182  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1183  {
1184  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1185  return;
1186  }
1188  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1189  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1190  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid);
1191  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1192  OutputCsmaPacket (p, pktInfo);
1193 }
1194 
1195 void
1198 {
1199  NS_LOG_FUNCTION (this);
1201  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1202  NS_ASSERT (ndev);
1203  uint64_t animUid = GetAnimUidFromPacket (p);
1204  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1205  {
1206  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1207  return;
1208  }
1210  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1211  NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete");
1212  OutputCsmaPacket (p, pktInfo);
1213 }
1214 
1215 void
1217 {
1219  uint32_t nodeId = 0;
1220  if (pktInfo.m_txnd)
1221  {
1222  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1223  }
1224  else
1225  {
1226  nodeId = pktInfo.m_txNodeId;
1227  }
1228  WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1229 }
1230 
1231 void
1233 {
1235  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1236  WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1237 }
1238 
1239 void
1241 {
1243  NS_ASSERT (pktInfo.m_txnd);
1244  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1245  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1246 
1247  WriteXmlP ("p",
1248  nodeId,
1249  pktInfo.m_fbTx,
1250  pktInfo.m_lbTx,
1251  rxId,
1252  pktInfo.m_fbRx,
1253  pktInfo.m_lbRx,
1255 }
1256 
1257 void
1258 AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1259 {
1260  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1261  NS_ASSERT (pendingPackets);
1262  pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1263 }
1264 
1265 bool
1267 {
1268  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1269  NS_ASSERT (pendingPackets);
1270  return (pendingPackets->find (animUid) != pendingPackets->end ());
1271 }
1272 
1273 void
1275 {
1276  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1277  NS_ASSERT (pendingPackets);
1278  if (pendingPackets->empty ())
1279  {
1280  return;
1281  }
1282  std::vector <uint64_t> purgeList;
1283  for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1284  i != pendingPackets->end ();
1285  ++i)
1286  {
1287 
1288  AnimPacketInfo pktInfo = i->second;
1289  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1290  if (delta > PURGE_INTERVAL)
1291  {
1292  purgeList.push_back (i->first);
1293  }
1294  }
1295  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1296  i != purgeList.end ();
1297  ++i)
1298  {
1299  pendingPackets->erase (*i);
1300  }
1301 }
1302 
1305 {
1306  AnimUidPacketInfoMap * pendingPackets = 0;
1307  switch (protocolType)
1308  {
1310  {
1311  pendingPackets = &m_pendingWifiPackets;
1312  break;
1313  }
1315  {
1316  pendingPackets = &m_pendingUanPackets;
1317  break;
1318  }
1320  {
1321  pendingPackets = &m_pendingCsmaPackets;
1322  break;
1323  }
1325  {
1326  pendingPackets = &m_pendingWimaxPackets;
1327  break;
1328  }
1330  {
1331  pendingPackets = &m_pendingLtePackets;
1332  break;
1333  }
1335  {
1336  pendingPackets = &m_pendingLrWpanPackets;
1337  break;
1338  }
1340  {
1341  pendingPackets = &m_pendingWavePackets;
1342  break;
1343  }
1344  }
1345  return pendingPackets;
1346 
1347 }
1348 
1349 std::string
1351 {
1352  std::string result = "Unknown";
1353  switch (protocolType)
1354  {
1356  {
1357  result = "WIFI";
1358  break;
1359  }
1361  {
1362  result = "UAN";
1363  break;
1364  }
1366  {
1367  result = "CSMA";
1368  break;
1369  }
1371  {
1372  result = "WIMAX";
1373  break;
1374  }
1376  {
1377  result = "LTE";
1378  break;
1379  }
1381  {
1382  result = "LRWPAN";
1383  break;
1384  }
1386  {
1387  result = "WAVE";
1388  break;
1389  }
1390  }
1391  return result;
1392 }
1393 
1394 // Counters
1395 
1396 std::string
1398 {
1399  std::string typeString = "unknown";
1400  switch (counterType)
1401  {
1402  case UINT32_COUNTER:
1403  {
1404  typeString = "UINT32";
1405  break;
1406  }
1407  case DOUBLE_COUNTER:
1408  {
1409  typeString = "DOUBLE";
1410  break;
1411  }
1412  }
1413  return typeString;
1414 }
1415 
1416 // General
1417 
1418 std::string
1420 {
1421  std::ostringstream oss;
1422  p->Print (oss);
1423  return oss.str ();
1424 }
1425 
1426 uint64_t
1428 {
1429  return m_currentPktCount;
1430 }
1431 
1432 void
1434 {
1435  m_started = false;
1436  NS_LOG_INFO ("Stopping Animation");
1438  if (m_f)
1439  {
1440  // Terminate the anim element
1441  WriteXmlClose ("anim");
1442  std::fclose (m_f);
1443  m_f = 0;
1444  }
1445  if (onlyAnimation)
1446  {
1447  return;
1448  }
1449  if (m_routingF)
1450  {
1451  WriteXmlClose ("anim", true);
1452  std::fclose (m_routingF);
1453  m_routingF = 0;
1454  }
1455 }
1456 
1457 void
1459 {
1460  m_currentPktCount = 0;
1461  m_started = true;
1463  WriteXmlAnim ();
1464  WriteNodes ();
1465  WriteNodeColors ();
1467  WriteIpv4Addresses ();
1468  WriteIpv6Addresses ();
1469  WriteNodeSizes ();
1470  WriteNodeEnergies ();
1471  if (!restart)
1472  {
1474  ConnectCallbacks ();
1475  }
1476 }
1477 
1478 void
1479 AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1480 {
1481  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1482  m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address));
1483 }
1484 
1485 void
1486 AnimationInterface::AddToIpv4AddressNodeIdTable (std::vector<std::string> ipv4Addresses, uint32_t nodeId)
1487 {
1488  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
1489  i != ipv4Addresses.end ();
1490  ++i)
1491  {
1492  AddToIpv4AddressNodeIdTable (*i, nodeId);
1493  }
1494 }
1495 
1496 void
1497 AnimationInterface::AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId)
1498 {
1499  m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1500  m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address));
1501 }
1502 
1503 void
1504 AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector<std::string> ipv6Addresses, uint32_t nodeId)
1505 {
1506  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin();
1507  i != ipv6Addresses.end();
1508  ++i)
1509  {
1510  AddToIpv6AddressNodeIdTable(*i, nodeId);
1511  }
1512 }
1513 
1514 // Callbacks
1515 void
1517 {
1518 
1519  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1520  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1521  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1522  std::ostringstream oss;
1523  //NodeList/*/DeviceList/*/
1524  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1525  if (dlPhy)
1526  {
1527  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1528  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1529  }
1530  if (ulPhy)
1531  {
1532  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1533  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1534  }
1535 }
1536 
1537 
1538 
1539 void
1541 {
1542 
1543  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1544  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1545  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1546  std::ostringstream oss;
1547  //NodeList/*/DeviceList/*/
1548  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1549  if (dlPhy)
1550  {
1551  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1552  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1553  }
1554  if (ulPhy)
1555  {
1556  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1557  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1558  }
1559 }
1560 
1561 void
1563 {
1564 
1565  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1566  {
1567  Ptr<Node> n = *i;
1568  NS_ASSERT (n);
1569  uint32_t nDevices = n->GetNDevices ();
1570  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1571  {
1572  Ptr <NetDevice> nd = n->GetDevice (devIndex);
1573  if (!nd)
1574  continue;
1575  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1576  if (lteUeNetDevice)
1577  {
1578  ConnectLteUe (n, lteUeNetDevice, devIndex);
1579  continue;
1580  }
1581  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1582  if (lteEnbNetDevice)
1583  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1584  }
1585 
1586  }
1587 }
1588 
1589 void
1591 {
1592  // Connect the callbacks
1593  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
1595  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
1597  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1599  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1601  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1603  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1605  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1607  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1609  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1611  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1613  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1615  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1617  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1619  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1621  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1623 
1624  ConnectLte ();
1625 
1626  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1628  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1630  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1632 
1633  // Queue Enqueues
1634 
1635  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1637  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1639  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1641 
1642  // Queue Dequeues
1643 
1644  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1646  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1648  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1650 
1651  // Queue Drops
1652 
1653  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1655  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1657  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1659 
1660 
1661  // Wifi Mac
1662  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1664  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1666  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1668  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1670 
1671  // Wifi Phy
1672  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1674  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1676 
1677  // LrWpan
1678  Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin",
1680  Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin",
1682  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx",
1684  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop",
1686  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx",
1688  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop",
1690 
1691  // Wave
1692  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin",
1694  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin",
1696 }
1697 
1698 Vector
1700 {
1701  Ptr<MobilityModel> loc = n->GetObject<MobilityModel> ();
1702  if (loc)
1703  {
1704  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1705  }
1706  else
1707  {
1708  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1709  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
1710  x->SetAttribute ("Min", DoubleValue (0));
1711  x->SetAttribute ("Max", DoubleValue (100));
1712  Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable> ();
1713  y->SetAttribute ("Min", DoubleValue (0));
1714  y->SetAttribute ("Max", DoubleValue (100));
1715  m_nodeLocation[n->GetId ()] = Vector (int (x->GetValue ()), int (y->GetValue ()), 0);
1716  }
1717  return m_nodeLocation[n->GetId ()];
1718 }
1719 
1720 Vector
1722 {
1723  m_nodeLocation[n->GetId ()] = v;
1724  return v;
1725 }
1726 
1727 Vector
1729 {
1730  Ptr <Node> n = ndev->GetNode ();
1731  NS_ASSERT (n);
1732  return UpdatePosition (n);
1733 }
1734 
1735 Vector
1737 {
1738  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1739  {
1740  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
1741  }
1742  return m_nodeLocation[n->GetId ()];
1743 }
1744 
1745 
1746 std::string
1748 {
1749  Address nodeAddr = nd->GetAddress ();
1750  std::ostringstream oss;
1751  oss << nodeAddr;
1752  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1753 }
1754 
1755 std::string
1757 {
1758  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1759  if (!ipv4)
1760  {
1761  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1762  return "0.0.0.0";
1763  }
1764  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1765  if (ifIndex == -1)
1766  {
1767  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1768  return "0.0.0.0";
1769  }
1770  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1771  std::ostringstream oss;
1772  oss << addr.GetLocal ();
1773  return oss.str ();
1774 }
1775 
1776 std::string
1778 {
1779  Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject <Ipv6>();
1780  if (!ipv6)
1781  {
1782  NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1783  return "::";
1784  }
1785  int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1786  if (ifIndex == -1)
1787  {
1788  NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1789  return "::";
1790  }
1791  bool nonLinkLocalFound = false;
1792  uint32_t nAddresses = ipv6->GetNAddresses(ifIndex);
1793  Ipv6InterfaceAddress addr;
1794  for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1795  {
1796  addr = ipv6->GetAddress(ifIndex, addressIndex);
1797  if (!addr.GetAddress().IsLinkLocal())
1798  {
1799  nonLinkLocalFound = true;
1800  break;
1801  }
1802  }
1803  if (!nonLinkLocalFound)
1804  addr = ipv6->GetAddress(ifIndex, 0);
1805  std::ostringstream oss;
1806  oss << addr.GetAddress();
1807  return oss.str();
1808 }
1809 
1810 
1811 
1812 std::vector<std::string>
1814 {
1815  std::vector<std::string> ipv4Addresses;
1816  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1817  if (!ipv4)
1818  {
1819  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1820  return ipv4Addresses;
1821  }
1822  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1823  if (ifIndex == -1)
1824  {
1825  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1826  return ipv4Addresses;
1827  }
1828  for (uint32_t index = 0; index < ipv4->GetNAddresses (ifIndex); ++index)
1829  {
1830  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, index);
1831  std::ostringstream oss;
1832  oss << addr.GetLocal ();
1833  ipv4Addresses.push_back(oss.str ());
1834  }
1835  return ipv4Addresses;
1836 }
1837 
1838 std::vector<std::string>
1840 {
1841  std::vector<std::string> ipv6Addresses;
1842  Ptr<Ipv6> ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv6> ();
1843  if (!ipv6)
1844  {
1845  NS_LOG_WARN("Node: " << nd->GetNode ()->GetId () << " No ipv6 object found");
1846  return ipv6Addresses;
1847  }
1848  int32_t ifIndex = ipv6->GetInterfaceForDevice (nd);
1849  if (ifIndex == -1)
1850  {
1851  NS_LOG_WARN("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1852  return ipv6Addresses;
1853  }
1854  for (uint32_t index = 0; index < ipv6->GetNAddresses (ifIndex); ++index)
1855  {
1856  Ipv6InterfaceAddress addr = ipv6->GetAddress (ifIndex, index);
1857  std::ostringstream oss;
1858  oss << addr.GetAddress ();
1859  ipv6Addresses.push_back (oss.str ());
1860  }
1861  return ipv6Addresses;
1862 }
1863 
1864 
1865 void
1867 {
1868  for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin ();
1869  i != m_nodeIdIpv4Map.end();
1870  ++i)
1871  {
1872  std::vector <std::string> ipv4Addresses;
1873  std::pair<NodeIdIpv4Map::const_iterator, NodeIdIpv4Map::const_iterator> iterPair = m_nodeIdIpv4Map.equal_range (i->first);
1874  for (NodeIdIpv4Map::const_iterator it = iterPair.first;
1875  it != iterPair.second;
1876  ++it)
1877  {
1878  ipv4Addresses.push_back (it->second);
1879  }
1880  WriteXmlIpv4Addresses (i->first, ipv4Addresses);
1881  }
1882 }
1883 
1884 void
1886 {
1887  for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin ();
1888  i != m_nodeIdIpv6Map.end ();
1889  i = m_nodeIdIpv6Map.upper_bound (i->first))
1890  {
1891  std::vector <std::string> ipv6Addresses;
1892  std::pair<NodeIdIpv6Map::const_iterator, NodeIdIpv6Map::const_iterator> iterPair = m_nodeIdIpv6Map.equal_range (i->first);
1893  for (NodeIdIpv6Map::const_iterator it = iterPair.first;
1894  it != iterPair.second;
1895  ++it)
1896  {
1897  ipv6Addresses.push_back (it->second);
1898  }
1899  WriteXmlIpv6Addresses (i->first, ipv6Addresses);
1900  }
1901 }
1902 
1903 void
1905 {
1906  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1907  {
1908  Ptr<Node> n = *i;
1909  UpdatePosition (n);
1910  uint32_t n1Id = n->GetId ();
1911  uint32_t nDev = n->GetNDevices (); // Number of devices
1912  for (uint32_t i = 0; i < nDev; ++i)
1913  {
1914  Ptr<NetDevice> dev = n->GetDevice (i);
1915  NS_ASSERT (dev);
1916  Ptr<Channel> ch = dev->GetChannel ();
1917  std::string channelType = "Unknown channel";
1918  if (ch)
1919  {
1920  channelType = ch->GetInstanceTypeId ().GetName ();
1921  }
1922  NS_LOG_DEBUG("Got ChannelType" << channelType);
1923 
1924  if (!ch || (channelType != std::string("ns3::PointToPointChannel")))
1925  {
1926  NS_LOG_DEBUG ("No channel can't be a p2p device");
1927  /*
1928  // Try to see if it is an LTE NetDevice, which does not return a channel
1929  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1930  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1931  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1932  {
1933  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1934  AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ());
1935  }
1936  */
1937  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
1938  AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId ());
1939  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
1940  AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId ());
1941  if (!ipv4Addresses.empty ())
1942  {
1943  NS_LOG_INFO ("Writing Ipv4 link");
1944  WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1945  }
1946  else if (!ipv6Addresses.empty ())
1947  {
1948  NS_LOG_INFO ("Writing Ipv6 link");
1949  WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType);
1950  }
1951  continue;
1952  }
1953 
1954  else if (channelType == std::string ("ns3::PointToPointChannel"))
1955  { // Since these are duplex links, we only need to dump
1956  // if srcid < dstid
1957  std::size_t nChDev = ch->GetNDevices ();
1958  for (std::size_t j = 0; j < nChDev; ++j)
1959  {
1960  Ptr<NetDevice> chDev = ch->GetDevice (j);
1961  uint32_t n2Id = chDev->GetNode ()->GetId ();
1962  if (n1Id < n2Id)
1963  {
1964 
1965  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
1966  AddToIpv4AddressNodeIdTable (ipv4Addresses, n1Id);
1967  ipv4Addresses = GetIpv4Addresses (chDev);
1968  AddToIpv4AddressNodeIdTable (ipv4Addresses, n2Id);
1969  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
1970  AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id);
1971  ipv6Addresses = GetIpv6Addresses (chDev);
1972  AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id);
1973 
1974  P2pLinkNodeIdPair p2pPair;
1975  p2pPair.fromNode = n1Id;
1976  p2pPair.toNode = n2Id;
1977  if (!ipv4Addresses.empty ())
1978  {
1979  LinkProperties lp = { GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), "" };
1980  m_linkProperties[p2pPair] = lp;
1981  }
1982  else if (!ipv6Addresses.empty ())
1983  {
1984  LinkProperties lp = { GetIpv6Address (dev) + "~" + GetMacAddress (dev), GetIpv6Address (chDev) + "~" + GetMacAddress (chDev), "" };
1985  m_linkProperties[p2pPair] = lp;
1986  }
1987  WriteXmlLink (n1Id, 0, n2Id);
1988  }
1989  }
1990  }
1991  }
1992  }
1993  m_linkProperties.clear ();
1994 }
1995 
1996 void
1998 {
1999  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2000  {
2001  Ptr<Node> n = *i;
2002  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
2003  Vector v = UpdatePosition (n);
2004  WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
2005  }
2006 }
2007 
2008 void
2010 {
2011  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2012  {
2013  Ptr<Node> n = *i;
2014  Rgb rgb = {255, 0, 0};
2015  if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
2016  {
2017  m_nodeColors[n->GetId ()] = rgb;
2018  }
2019  UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
2020  }
2021 }
2022 
2023 void
2025 {
2026  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2027  {
2028  Ptr<Node> n = *i;
2029  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
2030  AnimationInterface::NodeSize s = { 1, 1 };
2031  m_nodeSizes[n->GetId ()] = s;
2032  UpdateNodeSize (n->GetId (), s.width, s.height);
2033  }
2034 }
2035 
2036 void
2038 {
2040  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2041  {
2042  Ptr<Node> n = *i;
2043  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
2044  {
2046  }
2047  }
2048 }
2049 
2050 bool
2052 {
2053  if ((Simulator::Now () >= m_startTime) &&
2054  (Simulator::Now () <= m_stopTime))
2055  return true;
2056  else
2057  return false;
2058 }
2059 
2060 void
2061 AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
2062 {
2063  if (!routing && m_f)
2064  {
2065  return;
2066  }
2067  if (routing && m_routingF)
2068  {
2069  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
2070  return;
2071  }
2072 
2073  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
2074  FILE * f = 0;
2075  f = std::fopen (fn.c_str (), "w");
2076  if (!f)
2077  {
2078  NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ());
2079  return; // Can't open output file
2080  }
2081  if (routing)
2082  {
2083  m_routingF = f;
2084  m_routingFileName = fn;
2085  }
2086  else
2087  {
2088  m_f = f;
2089  m_outputFileName = fn;
2090  }
2091  return;
2092 }
2093 
2094 void
2096 {
2097  // Start a new trace file if the current packet count exceeded nax packets per file
2100  {
2101  return;
2102  }
2103  NS_LOG_UNCOND ("Max Packets per trace file exceeded");
2104  StopAnimation (true);
2105 }
2106 
2107 std::string
2109 {
2110  return NETANIM_VERSION;
2111 }
2112 
2113 
2114 void
2116 {
2118  {
2119  NS_LOG_INFO ("TrackQueueCounters Completed");
2120  return;
2121  }
2122  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2123  {
2124  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2128  }
2130 }
2131 
2132 void
2134 {
2136  {
2137  NS_LOG_INFO ("TrackWifiMacCounters Completed");
2138  return;
2139  }
2140  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2141  {
2142  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2147  }
2149 }
2150 
2151 void
2153 {
2155  {
2156  NS_LOG_INFO ("TrackWifiPhyCounters Completed");
2157  return;
2158  }
2159  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2160  {
2161  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2164  }
2166 }
2167 
2168 void
2170 {
2172  {
2173  NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed");
2174  return;
2175  }
2176  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2177  {
2178  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2182  }
2184 }
2185 
2186 
2187 
2188 
2189 
2190 /***** Routing-related *****/
2191 
2192 void
2194 {
2195  if (m_ipv4RouteTrackElements.empty ())
2196  {
2197  return;
2198  }
2199  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
2200  i != m_ipv4RouteTrackElements.end ();
2201  ++i)
2202  {
2203  Ipv4RouteTrackElement trackElement = *i;
2204  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
2205  if (!fromNode)
2206  {
2207  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
2208  continue;
2209  }
2210  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2211  if (!ipv4)
2212  {
2213  NS_LOG_WARN ("ipv4 object not found");
2214  continue;
2215  }
2217  if (!rp)
2218  {
2219  NS_LOG_WARN ("Routing protocol object not found");
2220  continue;
2221  }
2222  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
2223  Ptr<Packet> pkt = Create<Packet> ();
2224  Ipv4Header header;
2225  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
2226  Socket::SocketErrno sockerr;
2227  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2228  Ipv4RoutePathElements rpElements;
2229  if (!rt)
2230  {
2231  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
2232  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2233  rpElements.push_back (elem);
2234  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2235  continue;
2236  }
2237  std::ostringstream oss;
2238  oss << rt->GetGateway ();
2239  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
2240  if (rt->GetGateway () == "0.0.0.0")
2241  {
2242  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
2243  rpElements.push_back (elem);
2244  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
2245  {
2246  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
2247  rpElements.push_back (elem2);
2248  }
2249  }
2250  else if (rt->GetGateway () == "127.0.0.1")
2251  {
2252  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2253  rpElements.push_back (elem);
2254  }
2255  else
2256  {
2257  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
2258  rpElements.push_back (elem);
2259  }
2260  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
2261  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2262  }
2263 
2264 }
2265 
2266 void
2268 {
2270  {
2271  NS_LOG_INFO ("TrackIpv4Route completed");
2272  return;
2273  }
2274  if (m_routingNc.GetN ())
2275  {
2276  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
2277  {
2278  Ptr <Node> n = *i;
2279  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2280  }
2281  }
2282  else
2283  {
2284  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2285  {
2286  Ptr <Node> n = *i;
2287  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2288  }
2289  }
2292 }
2293 
2294 std::string
2296 {
2297 
2298  NS_ASSERT (n);
2299  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
2300  if (!ipv4)
2301  {
2302  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
2303  return "";
2304  }
2305  std::stringstream stream;
2306  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
2307  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
2308  return stream.str ();
2309 
2310 }
2311 
2312 void
2313 AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
2314 {
2315  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
2316  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
2317  {
2318  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
2319  return;
2320  }
2321  Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
2323  if (fromNode->GetId () == toNode->GetId ())
2324  {
2325  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
2326  rpElements.push_back (elem);
2327  return;
2328  }
2329  if (!fromNode)
2330  {
2331  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2332  return;
2333  }
2334  if (!toNode)
2335  {
2336  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2337  return;
2338  }
2339  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2340  if (!ipv4)
2341  {
2342  NS_LOG_WARN ("ipv4 object not found");
2343  return;
2344  }
2346  if (!rp)
2347  {
2348  NS_LOG_WARN ("Routing protocol object not found");
2349  return;
2350  }
2351  Ptr<Packet> pkt = Create<Packet> ();
2352  Ipv4Header header;
2353  header.SetDestination (Ipv4Address (to.c_str ()));
2354  Socket::SocketErrno sockerr;
2355  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2356  if (!rt)
2357  {
2358  return;
2359  }
2360  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
2361  std::ostringstream oss;
2362  oss << rt->GetGateway ();
2363  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2364  {
2365  NS_LOG_INFO ("Null gw");
2366  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
2367  rpElements.push_back (elem);
2368  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
2369  {
2370  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
2371  rpElements.push_back (elem2);
2372  }
2373  return;
2374  }
2375  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
2376  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
2377  rpElements.push_back (elem);
2378  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
2379 
2380 }
2381 
2382 
2383 
2384 /***** WriteXml *****/
2385 
2386 void
2388 {
2389  AnimXmlElement element ("anim");
2390  element.AddAttribute ("ver", GetNetAnimVersion ());
2391  FILE * f = m_f;
2392  if (!routing)
2393  {
2394  element.AddAttribute ("filetype", "animation");
2395  }
2396  else
2397  {
2398  element.AddAttribute ("filetype", "routing");
2399  f = m_routingF;
2400  }
2401  WriteN (element.ToString (false) + ">\n", f);
2402 }
2403 
2404 void
2405 AnimationInterface::WriteXmlClose (std::string name, bool routing)
2406 {
2407  std::string closeString = "</" + name + ">\n";
2408  if (!routing)
2409  {
2410  WriteN (closeString, m_f);
2411  }
2412  else
2413  {
2414  WriteN (closeString, m_routingF);
2415  }
2416 }
2417 
2418 void
2419 AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2420 {
2421  AnimXmlElement element ("node");
2422  element.AddAttribute ("id", id);
2423  element.AddAttribute ("sysId", sysId);
2424  element.AddAttribute ("locX", locX);
2425  element.AddAttribute ("locY", locY);
2426  WriteN (element.ToString (), m_f);
2427 }
2428 
2429 void
2430 AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2431 {
2432  AnimXmlElement element ("linkupdate");
2433  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2434  element.AddAttribute ("fromId", fromId);
2435  element.AddAttribute ("toId", toId);
2436  element.AddAttribute ("ld", linkDescription, true);
2437  WriteN (element.ToString (), m_f);
2438 }
2439 
2440 void
2441 AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2442 {
2443  AnimXmlElement element ("link");
2444  element.AddAttribute ("fromId", fromId);
2445  element.AddAttribute ("toId", toId);
2446 
2447  LinkProperties lprop ;
2448  lprop.fromNodeDescription = "";
2449  lprop.toNodeDescription = "";
2450  lprop.linkDescription = "";
2451 
2452  P2pLinkNodeIdPair p1 = { fromId, toId };
2453  P2pLinkNodeIdPair p2 = { toId, fromId };
2454  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2455  {
2456  lprop = m_linkProperties[p1];
2457  }
2458  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2459  {
2460  lprop = m_linkProperties[p2];
2461  }
2462 
2463  element.AddAttribute ("fd", lprop.fromNodeDescription, true);
2464  element.AddAttribute ("td", lprop.toNodeDescription, true);
2465  element.AddAttribute ("ld", lprop.linkDescription, true);
2466  WriteN (element.ToString (), m_f);
2467 }
2468 
2469 void
2470 AnimationInterface::WriteXmlIpv4Addresses (uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2471 {
2472  AnimXmlElement element ("ip");
2473  element.AddAttribute ("n", nodeId);
2474  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
2475  i != ipv4Addresses.end ();
2476  ++i)
2477  {
2478  AnimXmlElement valueElement ("address");
2479  valueElement.SetText (*i);
2480  element.AppendChild(valueElement);
2481  }
2482  WriteN (element.ToString (), m_f);
2483 }
2484 
2485 void
2486 AnimationInterface::WriteXmlIpv6Addresses (uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2487 {
2488  AnimXmlElement element ("ipv6");
2489  element.AddAttribute("n", nodeId);
2490  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin ();
2491  i != ipv6Addresses.end ();
2492  ++i)
2493  {
2494  AnimXmlElement valueElement ("address");
2495  valueElement.SetText (*i);
2496  element.AppendChild (valueElement);
2497  }
2498  WriteN(element.ToString (), m_f);
2499 }
2500 
2501 void
2502 AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2503 {
2504  AnimXmlElement element ("rt");
2505  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2506  element.AddAttribute ("id", nodeId);
2507  element.AddAttribute ("info", routingInfo.c_str (), true);
2508  WriteN (element.ToString (), m_routingF);
2509 }
2510 
2511 void
2512 AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2513 {
2514  std::string tagName = "rp";
2515  AnimXmlElement element (tagName, false);
2516  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2517  element.AddAttribute ("id", nodeId);
2518  element.AddAttribute ("d", destination.c_str ());
2519  element.AddAttribute ("c", rpElements.size ());
2520  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2521  i != rpElements.end ();
2522  ++i)
2523  {
2524  Ipv4RoutePathElement rpElement = *i;
2525  AnimXmlElement rpeElement ("rpe");
2526  rpeElement.AddAttribute ("n", rpElement.nodeId);
2527  rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2528  element.AppendChild (rpeElement);
2529  }
2530  WriteN (element.ToString (), m_routingF);
2531 }
2532 
2533 
2534 void
2535 AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2536 {
2537  AnimXmlElement element ("pr");
2538  element.AddAttribute ("uId", animUid);
2539  element.AddAttribute ("fId", fId);
2540  element.AddAttribute ("fbTx", fbTx);
2541  if (!metaInfo.empty ())
2542  {
2543  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2544  }
2545  WriteN (element.ToString (), m_f);
2546 }
2547 
2548 void
2549 AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2550 {
2551  AnimXmlElement element (pktType);
2552  element.AddAttribute ("uId", animUid);
2553  element.AddAttribute ("tId", tId);
2554  element.AddAttribute ("fbRx", fbRx);
2555  element.AddAttribute ("lbRx", lbRx);
2556  WriteN (element.ToString (), m_f);
2557 }
2558 
2559 void
2560 AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2561  uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2562 {
2563  AnimXmlElement element (pktType);
2564  element.AddAttribute ("fId", fId);
2565  element.AddAttribute ("fbTx", fbTx);
2566  element.AddAttribute ("lbTx", lbTx);
2567  if (!metaInfo.empty ())
2568  {
2569  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2570  }
2571  element.AddAttribute ("tId", tId);
2572  element.AddAttribute ("fbRx", fbRx);
2573  element.AddAttribute ("lbRx", lbRx);
2574  WriteN (element.ToString (), m_f);
2575 }
2576 
2577 void
2578 AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2579 {
2580  AnimXmlElement element ("ncs");
2581  element.AddAttribute ("ncId", nodeCounterId);
2582  element.AddAttribute ("n", counterName);
2583  element.AddAttribute ("t", CounterTypeToString (counterType));
2584  WriteN (element.ToString (), m_f);
2585 }
2586 
2587 void
2588 AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2589 {
2590  AnimXmlElement element ("res");
2591  element.AddAttribute ("rid", resourceId);
2592  element.AddAttribute ("p", resourcePath);
2593  WriteN (element.ToString (), m_f);
2594 }
2595 
2596 void
2597 AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2598 {
2599  AnimXmlElement element ("nu");
2600  element.AddAttribute ("p", "i");
2601  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2602  element.AddAttribute ("id", nodeId);
2603  element.AddAttribute ("rid", resourceId);
2604  WriteN (element.ToString (), m_f);
2605 }
2606 
2607 void
2608 AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2609 {
2610  AnimXmlElement element ("nu");
2611  element.AddAttribute ("p", "s");
2612  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2613  element.AddAttribute ("id", nodeId);
2614  element.AddAttribute ("w", width);
2615  element.AddAttribute ("h", height);
2616  WriteN (element.ToString (), m_f);
2617 }
2618 
2619 void
2620 AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2621 {
2622  AnimXmlElement element ("nu");
2623  element.AddAttribute ("p", "p");
2624  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2625  element.AddAttribute ("id", nodeId);
2626  element.AddAttribute ("x", x);
2627  element.AddAttribute ("y", y);
2628  WriteN (element.ToString (), m_f);
2629 }
2630 
2631 void
2632 AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2633 {
2634  AnimXmlElement element ("nu");
2635  element.AddAttribute ("p", "c");
2636  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2637  element.AddAttribute ("id", nodeId);
2638  element.AddAttribute ("r", (uint32_t) r);
2639  element.AddAttribute ("g", (uint32_t) g);
2640  element.AddAttribute ("b", (uint32_t) b);
2641  WriteN (element.ToString (), m_f);
2642 }
2643 
2644 void
2646 {
2647  AnimXmlElement element ("nu");
2648  element.AddAttribute ("p", "d");
2649  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2650  element.AddAttribute ("id", nodeId);
2651  if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2652  {
2653  element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
2654  }
2655  WriteN (element.ToString (), m_f);
2656 }
2657 
2658 
2659 void
2660 AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2661 {
2662  AnimXmlElement element ("nc");
2663  element.AddAttribute ("c", nodeCounterId);
2664  element.AddAttribute ("i", nodeId);
2665  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2666  element.AddAttribute ("v", counterValue);
2667  WriteN (element.ToString (), m_f);
2668 }
2669 
2670 void
2671 AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2672 {
2673  AnimXmlElement element ("bg");
2674  element.AddAttribute ("f", fileName);
2675  element.AddAttribute ("x", x);
2676  element.AddAttribute ("y", y);
2677  element.AddAttribute ("sx", scaleX);
2678  element.AddAttribute ("sy", scaleY);
2679  element.AddAttribute ("o", opacity);
2680  WriteN (element.ToString (), m_f);
2681 }
2682 
2683 void
2684 AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType)
2685 {
2686  AnimXmlElement element ("nonp2plinkproperties");
2687  element.AddAttribute ("id", id);
2688  element.AddAttribute ("ipAddress", ipAddress);
2689  element.AddAttribute ("channelType", channelType);
2690  WriteN (element.ToString (), m_f);
2691 }
2692 
2693 
2694 
2695 /***** AnimXmlElement *****/
2696 
2697 AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement) :
2698  m_tagName(tagName),
2699  m_text("")
2700 {
2701 }
2702 
2703 template <typename T>
2704 void
2705 AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape)
2706 {
2707  std::ostringstream oss;
2708  oss << std::setprecision(10);
2709  oss << value;
2710  std::string attributeString = attribute.c_str();
2711  if (xmlEscape)
2712  {
2713  attributeString += "=\"";
2714  std::string valueStr = oss.str();
2715  for (std::string::iterator it = valueStr.begin(); it != valueStr.end(); ++it)
2716  {
2717  switch (*it)
2718  {
2719  case '&':
2720  attributeString += "&amp;";
2721  break;
2722  case '\"':
2723  attributeString += "&quot;";
2724  break;
2725  case '\'':
2726  attributeString += "&apos;";
2727  break;
2728  case '<':
2729  attributeString += "&lt;";
2730  break;
2731  case '>':
2732  attributeString += "&gt;";
2733  break;
2734  default:
2735  attributeString += *it;
2736  break;
2737  }
2738  }
2739  attributeString += "\" ";
2740  }
2741  else
2742  {
2743  attributeString += "=\"" + oss.str() + "\" ";
2744  }
2745  m_attributes.push_back(attributeString);
2746 }
2747 
2748 void
2750 {
2751  m_children.push_back(e.ToString());
2752 }
2753 
2754 void
2756 {
2757  m_text = text;
2758 }
2759 
2760 std::string
2762 {
2763  std::string elementString = "<" + m_tagName + " ";
2764 
2765 
2766  for (std::vector<std::string>::const_iterator i = m_attributes.begin();
2767  i != m_attributes.end();
2768  ++i)
2769  {
2770  elementString += *i;
2771  }
2772  if (m_children.empty() && m_text.empty())
2773  {
2774  if (autoClose)
2775  {
2776  elementString += "/>";
2777  }
2778  }
2779  else
2780  {
2781  elementString += ">";
2782  if (!m_text.empty())
2783  {
2784  elementString += m_text;
2785  }
2786  if (!m_children.empty())
2787  {
2788  elementString += "\n";
2789  for (std::vector<std::string>::const_iterator i = m_children.begin();
2790  i != m_children.end();
2791  ++i)
2792  {
2793  elementString += *i + "\n";
2794  }
2795 
2796  }
2797  if (autoClose)
2798  {
2799  elementString += "</" + m_tagName + ">";
2800  }
2801  }
2802 
2803 
2804  return elementString + ((autoClose) ?"\n": "");
2805 }
2806 
2807 
2808 
2809 
2810 
2811 /***** AnimByteTag *****/
2812 
2813 TypeId
2815 {
2816  static TypeId tid = TypeId ("ns3::AnimByteTag")
2817  .SetParent<Tag> ()
2818  .SetGroupName ("NetAnim")
2819  .AddConstructor<AnimByteTag> ()
2820  ;
2821  return tid;
2822 }
2823 
2824 TypeId
2826 {
2827  return GetTypeId ();
2828 }
2829 
2830 uint32_t
2832 {
2833  return sizeof (uint64_t);
2834 }
2835 
2836 void
2838 {
2839  i.WriteU64 (m_AnimUid);
2840 }
2841 
2842 void
2844 {
2845  m_AnimUid = i.ReadU64 ();
2846 }
2847 
2848 void
2849 AnimByteTag::Print (std::ostream &os) const
2850 {
2851  os << "AnimUid=" << m_AnimUid;
2852 }
2853 
2854 void
2855 AnimByteTag::Set (uint64_t AnimUid)
2856 {
2857  m_AnimUid = AnimUid;
2858 }
2859 
2860 uint64_t
2861 AnimByteTag::Get (void) const
2862 {
2863  return m_AnimUid;
2864 }
2865 
2867  : m_txnd (0),
2868  m_txNodeId (0),
2869  m_fbTx (0),
2870  m_lbTx (0),
2871  m_lbRx (0)
2872 {
2873 }
2874 
2876 {
2877  m_txnd = pInfo.m_txnd;
2878  m_txNodeId = pInfo.m_txNodeId;
2879  m_fbTx = pInfo.m_fbTx;
2880  m_lbTx = pInfo.m_lbTx;
2881  m_lbRx = pInfo.m_lbRx;
2882 }
2883 
2885  const Time fbTx,
2886  uint32_t txNodeId)
2887  : m_txnd (txnd),
2888  m_txNodeId (0),
2889  m_fbTx (fbTx.GetSeconds ()),
2890  m_lbTx (0),
2891  m_lbRx (0)
2892 {
2893  if (!m_txnd)
2894  m_txNodeId = txNodeId;
2895 }
2896 
2897 void
2899 {
2900  Ptr <Node> n = nd->GetNode ();
2901  m_fbRx = fbRx;
2902  m_rxnd = nd;
2903 }
2904 
2905 } // 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:846
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.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
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:204
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 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.
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet > p, WifiPhyRxfailureReason reason)
wifi Phy receive drop trace 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:280
#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
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:108
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:1389
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:860
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:871
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:193
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
void WifiPhyTxBeginTrace(std::string context, Ptr< const Packet > p, double txPowerW)
wifi Phy transmit begin trace function
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
Ptr< WifiMac > GetMac(void) const
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:264
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:272
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:1062
WifiPhyRxfailureReason
Definition: wifi-phy.h:48
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:163
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:840
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.
Ptr< Node > GetNode(void) const