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/wifi-psdu.h"
50 #include "ns3/lr-wpan-mac-header.h"
51 #include "ns3/lr-wpan-net-device.h"
52 #include "ns3/constant-position-mobility-model.h"
53 #include "ns3/lte-ue-phy.h"
54 #include "ns3/lte-enb-phy.h"
55 #include "ns3/uan-net-device.h"
56 #include "ns3/uan-mac.h"
57 #include "ns3/double.h"
58 #include "ns3/ipv4.h"
59 #include "ns3/ipv6.h"
60 #include "ns3/ipv4-routing-protocol.h"
61 #include "ns3/energy-source-container.h"
62 #include "animation-interface.h"
63 
64 namespace ns3 {
65 
66 NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
67 
68 // Globals
69 
70 static bool initialized = false;
71 
72 
73 // Public methods
74 
76  : m_f (0),
77  m_routingF (0),
78  m_mobilityPollInterval (Seconds (0.25)),
79  m_outputFileName (fn),
80  gAnimUid (0),
81  m_writeCallback (0),
82  m_started (false),
83  m_enablePacketMetadata (false),
84  m_startTime (Seconds (0)),
85  m_stopTime (Seconds (3600 * 1000)),
86  m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE),
87  m_originalFileName (fn),
88  m_routingStopTime (Seconds (0)),
89  m_routingFileName (""),
90  m_routingPollInterval (Seconds (5)),
91  m_trackPackets (true)
92 {
93  initialized = true;
94  StartAnimation ();
95 }
96 
98 {
99  StopAnimation ();
100 }
101 
102 void
104 {
105  m_trackPackets = false;
106 }
107 
108 void
110 {
112  m_wifiPhyCountersPollInterval = pollInterval;
115  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
116  {
117  Ptr<Node> n = *i;
118  m_nodeWifiPhyTxDrop[n->GetId ()] = 0;
119  m_nodeWifiPhyRxDrop[n->GetId ()] = 0;
122  }
124 
125 }
126 
127 void
129 {
131  m_wifiMacCountersPollInterval = pollInterval;
136  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
137  {
138  Ptr<Node> n = *i;
139  m_nodeWifiMacTx[n->GetId ()] = 0;
140  m_nodeWifiMacTxDrop[n->GetId ()] = 0;
141  m_nodeWifiMacRx[n->GetId ()] = 0;
142  m_nodeWifiMacRxDrop[n->GetId ()] = 0;
143  UpdateNodeCounter (m_wifiMacTxCounterId, n->GetId (), 0);
145  UpdateNodeCounter (m_wifiMacRxCounterId, n->GetId (), 0);
147  }
149 }
150 
151 void
153 {
155  m_queueCountersPollInterval = pollInterval;
159  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
160  {
161  Ptr<Node> n = *i;
162  m_nodeQueueEnqueue[n->GetId ()] = 0;
163  m_nodeQueueDequeue[n->GetId ()] = 0;
164  m_nodeQueueDrop[n->GetId ()] = 0;
167  UpdateNodeCounter (m_queueDropCounterId, n->GetId (), 0);
168  }
170 }
171 
172 void
174 {
180  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
181  {
182  Ptr<Node> n = *i;
183  m_nodeIpv4Tx[n->GetId ()] = 0;
184  m_nodeIpv4Rx[n->GetId ()] = 0;
185  m_nodeIpv4Drop[n->GetId ()] = 0;
189  }
191 }
192 
195 {
196  SetOutputFile (fileName, true);
198  m_routingPollInterval = pollInterval;
199  WriteXmlAnim (true);
201  return *this;
202 }
203 
206 {
207  m_routingNc = nc;
208  return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
209 }
210 
212 AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
213 {
214  Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
215  m_ipv4RouteTrackElements.push_back (element);
216  return *this;
217 }
218 
219 void
221 {
222  m_startTime = t;
223 }
224 
225 void
227 {
228  m_stopTime = t;
229 }
230 
231 void
232 AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile)
233 {
234  m_maxPktsPerFile = maxPacketsPerFile;
235 }
236 
237 uint32_t
238 AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType)
239 {
240  m_nodeCounters.push_back (counterName);
241  uint32_t counterId = m_nodeCounters.size () - 1; // counter ID is zero-indexed
242  WriteXmlAddNodeCounter (counterId, counterName, counterType);
243  return counterId;
244 }
245 
246 uint32_t
247 AnimationInterface::AddResource (std::string resourcePath)
248 {
249  m_resources.push_back (resourcePath);
250  uint32_t resourceId = m_resources.size () - 1; // resource ID is zero-indexed
251  WriteXmlAddResource (resourceId, resourcePath);
252  return resourceId;
253 }
254 
255 void
257 {
258  m_enablePacketMetadata = enable;
259  if (enable)
260  {
262  }
263 }
264 
265 bool
267 {
268  return initialized;
269 }
270 
271 bool
273 {
274  return m_started;
275 }
276 
277 void
279 {
280  m_writeCallback = cb;
281 }
282 
283 void
285 {
286  m_writeCallback = 0;
287 }
288 
289 void
291 {
293 }
294 
295 
296 void
298 {
299  NS_ASSERT (n);
301  if (loc == 0)
302  {
303  loc = CreateObject<ConstantPositionMobilityModel> ();
304  n->AggregateObject (loc);
305  }
306  Vector hubVec (x, y, z);
307  loc->SetPosition (hubVec);
308  NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")");
309 
310 }
311 
312 void
313 AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
314 {
315  NS_LOG_INFO ("Setting node image for Node Id:" << nodeId);
316  if (resourceId > (m_resources.size () - 1))
317  {
318  NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?");
319  }
320  WriteXmlUpdateNodeImage (nodeId, resourceId);
321 }
322 
323 void
324 AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter)
325 {
326  if (nodeCounterId > (m_nodeCounters.size () - 1))
327  {
328  NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?");
329  }
330  WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter);
331 }
332 
333 void
334 AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
335 {
336  if ((opacity < 0) || (opacity > 1))
337  {
338  NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0");
339  }
340  WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
341 }
342 
343 void
344 AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height)
345 {
346  AnimationInterface::NodeSize s = { width, height };
347  m_nodeSizes[nodeId] = s;
348  WriteXmlUpdateNodeSize (nodeId, s.width, s.height);
349 }
350 
351 void
352 AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
353 {
354  UpdateNodeColor (n->GetId (), r, g, b);
355 }
356 
357 void
358 AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
359 {
360  NS_ASSERT (NodeList::GetNode (nodeId));
361  NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
362  Rgb rgb = {r, g, b};
363  m_nodeColors[nodeId] = rgb;
364  WriteXmlUpdateNodeColor (nodeId, r, g, b);
365 }
366 
367 void
368 AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
369  std::string linkDescription)
370 {
371  WriteXmlUpdateLink (fromNode, toNode, linkDescription);
372 }
373 
374 void
376  std::string linkDescription)
377 {
378  NS_ASSERT (fromNode);
379  NS_ASSERT (toNode);
380  WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription);
381 }
382 
383 void
385 {
386  UpdateNodeDescription (n->GetId (), descr);
387 }
388 
389 void
390 AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
391 {
392  NS_ASSERT (NodeList::GetNode (nodeId));
393  m_nodeDescriptions[nodeId] = descr;
395 }
396 
397 // Private methods
398 
399 
400 double
402 {
403  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
404  NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ());
405  return fractionIter->second;
406 }
407 
408 void
410 {
412  Ptr <Node> n = mobility->GetObject <Node> ();
413  NS_ASSERT (n);
414  Vector v;
415  if (!mobility)
416  {
417  v = GetPosition (n);
418  }
419  else
420  {
421  v = mobility->GetPosition ();
422  }
423  UpdatePosition (n, v);
424  WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y);
425 }
426 
427 bool
429 {
430  Vector oldLocation = GetPosition (n);
431  bool moved = true;
432  if ((ceil (oldLocation.x) == ceil (newLocation.x))
433  && (ceil (oldLocation.y) == ceil (newLocation.y)))
434  {
435  moved = false;
436  }
437  else
438  {
439  moved = true;
440  }
441  return moved;
442 }
443 
444 void
446 {
448  std::vector <Ptr <Node> > MovedNodes = GetMovedNodes ();
449  for (uint32_t i = 0; i < MovedNodes.size (); i++)
450  {
451  Ptr <Node> n = MovedNodes [i];
452  NS_ASSERT (n);
453  Vector v = GetPosition (n);
454  WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y);
455  }
456  if (!Simulator::IsFinished ())
457  {
465  }
466 }
467 
468 std::vector <Ptr <Node> >
470 {
471  std::vector < Ptr <Node> > movedNodes;
472  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
473  {
474  Ptr<Node> n = *i;
475  NS_ASSERT (n);
476  Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
477  Vector newLocation;
478  if (!mobility)
479  {
480  newLocation = GetPosition (n);
481  }
482  else
483  {
484  newLocation = mobility->GetPosition ();
485  }
486  if (!NodeHasMoved (n, newLocation))
487  {
488  continue; //Location has not changed
489  }
490  else
491  {
492  UpdatePosition (n, newLocation);
493  movedNodes.push_back (n);
494  }
495  }
496  return movedNodes;
497 }
498 
499 int
500 AnimationInterface::WriteN (const std::string& st, FILE * f)
501 {
502  if (!f)
503  {
504  return 0;
505  }
506  if (m_writeCallback)
507  {
508  m_writeCallback (st.c_str ());
509  }
510  return WriteN (st.c_str (), st.length (), f);
511 }
512 
513 int
514 AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
515 {
516  if (!f)
517  {
518  return 0;
519  }
520  // Write count bytes to h from data
521  uint32_t nLeft = count;
522  const char* p = data;
523  uint32_t written = 0;
524  while (nLeft)
525  {
526  int n = std::fwrite (p, 1, nLeft, f);
527  if (n <= 0)
528  {
529  return written;
530  }
531  written += n;
532  nLeft -= n;
533  p += n;
534  }
535  return written;
536 }
537 
538 void
539 AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
540 {
541  NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ());
542  WriteXmlRp (nodeId, destination, rpElements);
543  /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
544  i != rpElements.end ();
545  ++i)
546  {
547  Ipv4RoutePathElement rpElement = *i;
548  NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
549  WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
550 
551  }
552  */
553 }
554 
555 void
556 AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
557 {
558  WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType);
559 }
560 
561 const std::vector<std::string>
562 AnimationInterface::GetElementsFromContext (const std::string& context) const
563 {
564  std::vector <std::string> elements;
565  std::size_t pos1 = 0, pos2;
566  while (pos1 != context.npos)
567  {
568  pos1 = context.find ("/",pos1);
569  pos2 = context.find ("/",pos1 + 1);
570  elements.push_back (context.substr (pos1 + 1,pos2 - (pos1 + 1)));
571  pos1 = pos2;
572  pos2 = context.npos;
573  }
574  return elements;
575 }
576 
578 AnimationInterface::GetNodeFromContext (const std::string& context) const
579 {
580  // Use "NodeList/*/ as reference
581  // where element [1] is the Node Id
582 
583  std::vector <std::string> elements = GetElementsFromContext (context);
584  Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
585  NS_ASSERT (n);
586 
587  return n;
588 }
589 
592 {
593  // Use "NodeList/*/DeviceList/*/ as reference
594  // where element [1] is the Node Id
595  // element [2] is the NetDevice Id
596 
597  std::vector <std::string> elements = GetElementsFromContext (context);
598  Ptr <Node> n = GetNodeFromContext (context);
599 
600  return n->GetDevice (atoi (elements.at (3).c_str ()));
601 }
602 
603 uint64_t
605 {
606  AnimByteTag tag;
607  TypeId tid = tag.GetInstanceTypeId ();
609  bool found = false;
610  while (i.HasNext ())
611  {
612  ByteTagIterator::Item item = i.Next ();
613  if (tid == item.GetTypeId ())
614  {
615  item.GetTag (tag);
616  found = true;
617  }
618  }
619  if (found)
620  {
621  return tag.Get ();
622  }
623  else
624  {
625  return 0;
626  }
627 }
628 
629 void
631 {
632  AnimByteTag tag;
633  tag.Set (animUid);
634  p->AddByteTag (tag);
635 }
636 
637 void
638 AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
639 {
641  const Ptr <const Node> node = GetNodeFromContext (context);
642  const uint32_t nodeId = node->GetId ();
643 
644  NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
645 
646  const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
647 
648  NS_ASSERT (energySource);
649  // Don't call GetEnergyFraction () because of recursion
650  const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
651 
652  NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction);
653 
654  m_nodeEnergyFraction[nodeId] = energyFraction;
655  UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction);
656 }
657 
658 void
660 {
661  const Ptr <const Node> node = GetNodeFromContext (context);
662  ++m_nodeWifiPhyTxDrop[node->GetId ()];
663 }
664 
665 void
667 {
668  const Ptr <const Node> node = GetNodeFromContext (context);
669  ++m_nodeWifiPhyRxDrop[node->GetId ()];
670 }
671 
672 void
674 {
675  const Ptr <const Node> node = GetNodeFromContext (context);
676  ++m_nodeWifiMacTx[node->GetId ()];
677 }
678 
679 void
681 {
682  const Ptr <const Node> node = GetNodeFromContext (context);
683  ++m_nodeWifiMacTxDrop[node->GetId ()];
684 }
685 
686 void
688 {
689  const Ptr <const Node> node = GetNodeFromContext (context);
690  ++m_nodeWifiMacRx[node->GetId ()];
691 }
692 
693 void
695 {
696  const Ptr <const Node> node = GetNodeFromContext (context);
697  ++m_nodeWifiMacRxDrop[node->GetId ()];
698 }
699 
700 void
702 {
703  const Ptr <const Node> node = GetNodeFromContext (context);
704  ++m_nodeLrWpanMacTx[node->GetId ()];
705 }
706 
707 void
709 {
710  const Ptr <const Node> node = GetNodeFromContext (context);
711  ++m_nodeLrWpanMacTxDrop[node->GetId ()];
712 }
713 
714 void
716 {
717  const Ptr <const Node> node = GetNodeFromContext (context);
718  ++m_nodeLrWpanMacRx[node->GetId ()];
719 }
720 
721 void
723 {
724  const Ptr <const Node> node = GetNodeFromContext (context);
725  ++m_nodeLrWpanMacRxDrop[node->GetId ()];
726 }
727 
728 void
729 AnimationInterface::Ipv4TxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
730 {
731  const Ptr <const Node> node = GetNodeFromContext (context);
732  ++m_nodeIpv4Tx[node->GetId ()];
733 }
734 
735 void
736 AnimationInterface::Ipv4RxTrace (std::string context, Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interfaceIndex)
737 {
738  const Ptr <const Node> node = GetNodeFromContext (context);
739  ++m_nodeIpv4Rx[node->GetId ()];
740 }
741 
742 void
744  const Ipv4Header & ipv4Header,
746  Ipv4L3Protocol::DropReason dropReason,
747  Ptr<Ipv4> ipv4,
748  uint32_t)
749 {
750  const Ptr <const Node> node = GetNodeFromContext (context);
751  ++m_nodeIpv4Drop[node->GetId ()];
752 }
753 
754 void
755 AnimationInterface::EnqueueTrace (std::string context,
757 {
758  const Ptr <const Node> node = GetNodeFromContext (context);
759  ++m_nodeQueueEnqueue[node->GetId ()];
760 }
761 
762 void
763 AnimationInterface::DequeueTrace (std::string context,
765 {
766  const Ptr <const Node> node = GetNodeFromContext (context);
767  ++m_nodeQueueDequeue[node->GetId ()];
768 }
769 
770 void
773 {
774  const Ptr <const Node> node = GetNodeFromContext (context);
775  ++m_nodeQueueDrop[node->GetId ()];
776 }
777 
778 void
779 AnimationInterface::DevTxTrace (std::string context,
781  Ptr<NetDevice> tx,
782  Ptr<NetDevice> rx,
783  Time txTime,
784  Time rxTime)
785 {
786  NS_LOG_FUNCTION (this);
788  NS_ASSERT (tx);
789  NS_ASSERT (rx);
790  Time now = Simulator::Now ();
791  double fbTx = now.GetSeconds ();
792  double lbTx = (now + txTime).GetSeconds ();
793  double fbRx = (now + rxTime - txTime).GetSeconds ();
794  double lbRx = (now + rxTime).GetSeconds ();
796  WriteXmlP ("p",
797  tx->GetNode ()->GetId (),
798  fbTx,
799  lbTx,
800  rx->GetNode ()->GetId (),
801  fbRx,
802  lbRx,
804 }
805 
806 void
808 {
809  NS_LOG_FUNCTION (this);
811  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
812  NS_ASSERT (ndev);
813  UpdatePosition (ndev);
814 
815  ++gAnimUid;
816  NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessTxTrace for packet:" << gAnimUid);
817  AddByteTag (gAnimUid, p);
818  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
819  AddPendingPacket (protocolType, gAnimUid, pktInfo);
820 
821  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
822  if (netDevice)
823  {
824  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
825  std::ostringstream oss;
826  oss << nodeAddr;
827  Ptr <Node> n = netDevice->GetNode ();
828  NS_ASSERT (n);
829  m_macToNodeIdMap[oss.str ()] = n->GetId ();
830  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" << m_macToNodeIdMap[oss.str ()]);
831  }
832  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
833  OutputWirelessPacketTxInfo (p, pendingPackets->at (gAnimUid), gAnimUid);
834 }
835 
836 void
838 {
839  NS_LOG_FUNCTION (this);
841  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
842  NS_ASSERT (ndev);
843  UpdatePosition (ndev);
844  uint64_t animUid = GetAnimUidFromPacket (p);
845  NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " for packet:" << animUid);
846  if (!IsPacketPending (animUid, protocolType))
847  {
848  NS_LOG_WARN (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid");
849  return;
850  }
851  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
852  pendingPackets->at (animUid).ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
853  OutputWirelessPacketRxInfo (p, pendingPackets->at (animUid), animUid);
854 }
855 
856 void
858 {
859  NS_LOG_FUNCTION (this);
860  return GenericWirelessTxTrace (context, p, AnimationInterface::UAN);
861 }
862 
863 void
865 {
866  NS_LOG_FUNCTION (this);
867  return GenericWirelessRxTrace (context, p, AnimationInterface::UAN);
868 }
869 
870 void
871 AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr<const WifiPsdu> psdu, WifiTxVector txVector, double txPowerW)
872 {
873  NS_LOG_FUNCTION (this);
874  NS_UNUSED (txVector);
876  Ptr<NetDevice> ndev = GetNetDeviceFromContext (context);
877  NS_ASSERT (ndev);
878  UpdatePosition (ndev);
879 
880  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
882  for (auto mpdu = psdu->begin (); mpdu != psdu->end (); ++mpdu)
883  {
884  ++gAnimUid;
885  NS_LOG_INFO ("WifiPhyTxTrace for MPDU:" << gAnimUid);
886  AddByteTag (gAnimUid, (*mpdu)->GetPacket ()); //the underlying MSDU/A-MSDU should be handed off
887  AddPendingPacket (WIFI, gAnimUid, pktInfo);
888  OutputWirelessPacketTxInfo ((*mpdu)->GetProtocolDataUnit (), pendingPackets->at (gAnimUid), gAnimUid); //PDU should be considered in order to have header
889  }
890 
891  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
892  if (netDevice)
893  {
894  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
895  std::ostringstream oss;
896  oss << nodeAddr;
897  Ptr<Node> n = netDevice->GetNode ();
898  NS_ASSERT (n);
899  m_macToNodeIdMap[oss.str ()] = n->GetId ();
900  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" << m_macToNodeIdMap[oss.str ()]);
901  }
902  else
903  {
904  NS_ABORT_MSG ("This NetDevice should be a Wi-Fi network device");
905  }
906 }
907 
908 void
910 {
911  NS_LOG_FUNCTION (this);
913  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
914  NS_ASSERT (ndev);
915  UpdatePosition (ndev);
916  uint64_t animUid = GetAnimUidFromPacket (p);
917  NS_LOG_INFO ("Wifi RxBeginTrace for packet: " << animUid);
919  {
920  NS_ASSERT_MSG (false, "WifiPhyRxBeginTrace: unknown Uid");
921  std::ostringstream oss;
922  WifiMacHeader hdr;
923  if (!p->PeekHeader (hdr))
924  {
925  NS_LOG_WARN ("WifiMacHeader not present");
926  return;
927  }
928  oss << hdr.GetAddr2 ();
929  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
930  {
931  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
932  return;
933  }
934  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
935  UpdatePosition (txNode);
936  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
937  AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo);
938  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
939  }
941  m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
942  OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid);
943 }
944 
945 void
948 {
949  NS_LOG_FUNCTION (this);
951 
952  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
953  NS_ASSERT (ndev);
954  Ptr<LrWpanNetDevice> netDevice = DynamicCast<LrWpanNetDevice> (ndev);
955 
956  Ptr <Node> n = ndev->GetNode ();
957  NS_ASSERT (n);
958 
959  UpdatePosition (n);
960 
961  LrWpanMacHeader hdr;
962  if (!p->PeekHeader (hdr))
963  {
964  NS_LOG_WARN ("LrWpanMacHeader not present");
965  return;
966  }
967 
968  std::ostringstream oss;
969  if (hdr.GetSrcAddrMode () == 2)
970  {
971  Mac16Address nodeAddr = netDevice->GetMac ()->GetShortAddress ();
972  oss << nodeAddr;
973  }
974  else if (hdr.GetSrcAddrMode () == 3)
975  {
976  Mac64Address nodeAddr = netDevice->GetMac ()->GetExtendedAddress ();
977  oss << nodeAddr;
978  }
979  else
980  {
981  NS_LOG_WARN ("LrWpanMacHeader without source address");
982  return;
983  }
984  m_macToNodeIdMap[oss.str ()] = n->GetId ();
985  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" << m_macToNodeIdMap[oss.str ()]);
986 
987  ++gAnimUid;
988  NS_LOG_INFO ("LrWpan TxBeginTrace for packet:" << gAnimUid);
989  AddByteTag (gAnimUid, p);
990 
991  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
993 
995 }
996 
997 void
1000 {
1001  NS_LOG_FUNCTION (this);
1003  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1004  NS_ASSERT (ndev);
1005  Ptr <Node> n = ndev->GetNode ();
1006  NS_ASSERT (n);
1007 
1008  AnimByteTag tag;
1009  if (!p->FindFirstMatchingByteTag (tag))
1010  {
1011  return;
1012  }
1013 
1014  uint64_t animUid = GetAnimUidFromPacket (p);
1015  NS_LOG_INFO ("LrWpan RxBeginTrace for packet:" << animUid);
1017  {
1018  NS_LOG_WARN ("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
1019  }
1020 
1021  UpdatePosition (n);
1022  m_pendingLrWpanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1023  OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid);
1024 }
1025 
1026 void
1028 {
1029  NS_LOG_FUNCTION (this);
1030  return GenericWirelessTxTrace (context, p, AnimationInterface::WAVE);
1031 }
1032 
1033 void
1035 {
1036  NS_LOG_FUNCTION (this);
1038  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1039  NS_ASSERT (ndev);
1040  UpdatePosition (ndev);
1041  uint64_t animUid = GetAnimUidFromPacket (p);
1042  NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid);
1043  if (!IsPacketPending (animUid, AnimationInterface::WAVE))
1044  {
1045  NS_ASSERT_MSG (false, "WavePhyRxBeginTrace: unknown Uid");
1046  std::ostringstream oss;
1047  WifiMacHeader hdr;
1048  if (!p->PeekHeader (hdr))
1049  {
1050  NS_LOG_WARN ("WaveMacHeader not present");
1051  return;
1052  }
1053  oss << hdr.GetAddr2 ();
1054  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1055  {
1056  NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping");
1057  return;
1058  }
1059  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
1060  UpdatePosition (txNode);
1061  AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]);
1062  AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo);
1063  NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet");
1064  }
1066  m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1067  OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid);
1068 }
1069 
1070 
1071 void
1073 {
1074  NS_LOG_FUNCTION (this);
1076 }
1077 
1078 
1079 void
1081 {
1082  NS_LOG_FUNCTION (this);
1084 }
1085 
1086 void
1088 {
1089  NS_LOG_FUNCTION (this);
1090  return GenericWirelessTxTrace (context, p, AnimationInterface::LTE);
1091 }
1092 
1093 void
1095 {
1096  NS_LOG_FUNCTION (this);
1097  return GenericWirelessRxTrace (context, p, AnimationInterface::LTE);
1098 }
1099 
1100 void
1102 {
1103  NS_LOG_FUNCTION (this);
1105  if (!pb)
1106  {
1107  NS_LOG_WARN ("pb == 0. Not yet supported");
1108  return;
1109  }
1110  context = "/" + context;
1111  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1112  NS_ASSERT (ndev);
1113  UpdatePosition (ndev);
1114 
1115  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1116  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1117  i != pbList.end ();
1118  ++i)
1119  {
1120  Ptr <Packet> p = *i;
1121  ++gAnimUid;
1122  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1123  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1124  AddByteTag (gAnimUid, p);
1126  OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid);
1127  }
1128 }
1129 
1130 void
1132 {
1133  NS_LOG_FUNCTION (this);
1135  if (!pb)
1136  {
1137  NS_LOG_WARN ("pb == 0. Not yet supported");
1138  return;
1139  }
1140  context = "/" + context;
1141  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1142  NS_ASSERT (ndev);
1143  UpdatePosition (ndev);
1144 
1145  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1146  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1147  i != pbList.end ();
1148  ++i)
1149  {
1150  Ptr <Packet> p = *i;
1151  uint64_t animUid = GetAnimUidFromPacket (p);
1152  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1153  if (!IsPacketPending (animUid, AnimationInterface::LTE))
1154  {
1155  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1156  return;
1157  }
1158  AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1159  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1160  OutputWirelessPacketRxInfo (p, pktInfo, animUid);
1161  }
1162 }
1163 
1164 void
1166 {
1167  NS_LOG_FUNCTION (this);
1169  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1170  NS_ASSERT (ndev);
1171  UpdatePosition (ndev);
1172  ++gAnimUid;
1173  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1174  AddByteTag (gAnimUid, p);
1175  UpdatePosition (ndev);
1176  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1178 
1179 
1180 }
1181 
1182 void
1184 {
1185  NS_LOG_FUNCTION (this);
1187  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1188  NS_ASSERT (ndev);
1189  UpdatePosition (ndev);
1190  uint64_t animUid = GetAnimUidFromPacket (p);
1191  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid);
1192  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1193  {
1194  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1195  NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid");
1196  AnimPacketInfo pktInfo (ndev, Simulator::Now ());
1197  AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo);
1198  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1199  }
1201  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1202  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1203 }
1204 
1205 void
1207 {
1208  NS_LOG_FUNCTION (this);
1210  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1211  NS_ASSERT (ndev);
1212  UpdatePosition (ndev);
1213  uint64_t animUid = GetAnimUidFromPacket (p);
1214  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1215  {
1216  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1217  return;
1218  }
1220  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1221  pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ());
1222  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid);
1223  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1224  OutputCsmaPacket (p, pktInfo);
1225 }
1226 
1227 void
1230 {
1231  NS_LOG_FUNCTION (this);
1233  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1234  NS_ASSERT (ndev);
1235  uint64_t animUid = GetAnimUidFromPacket (p);
1236  if (!IsPacketPending (animUid, AnimationInterface::CSMA))
1237  {
1238  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1239  return;
1240  }
1242  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1243  NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete");
1244  OutputCsmaPacket (p, pktInfo);
1245 }
1246 
1247 void
1249 {
1251  uint32_t nodeId = 0;
1252  if (pktInfo.m_txnd)
1253  {
1254  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1255  }
1256  else
1257  {
1258  nodeId = pktInfo.m_txNodeId;
1259  }
1260  WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata ? GetPacketMetadata (p) : "");
1261 }
1262 
1263 void
1265 {
1267  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1268  WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1269 }
1270 
1271 void
1273 {
1275  NS_ASSERT (pktInfo.m_txnd);
1276  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1277  uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId ();
1278 
1279  WriteXmlP ("p",
1280  nodeId,
1281  pktInfo.m_fbTx,
1282  pktInfo.m_lbTx,
1283  rxId,
1284  pktInfo.m_fbRx,
1285  pktInfo.m_lbRx,
1287 }
1288 
1289 void
1290 AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
1291 {
1292  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1293  NS_ASSERT (pendingPackets);
1294  pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo));
1295 }
1296 
1297 bool
1299 {
1300  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1301  NS_ASSERT (pendingPackets);
1302  return (pendingPackets->find (animUid) != pendingPackets->end ());
1303 }
1304 
1305 void
1307 {
1308  AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType);
1309  NS_ASSERT (pendingPackets);
1310  if (pendingPackets->empty ())
1311  {
1312  return;
1313  }
1314  std::vector <uint64_t> purgeList;
1315  for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin ();
1316  i != pendingPackets->end ();
1317  ++i)
1318  {
1319 
1320  AnimPacketInfo pktInfo = i->second;
1321  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
1322  if (delta > PURGE_INTERVAL)
1323  {
1324  purgeList.push_back (i->first);
1325  }
1326  }
1327  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
1328  i != purgeList.end ();
1329  ++i)
1330  {
1331  pendingPackets->erase (*i);
1332  }
1333 }
1334 
1337 {
1338  AnimUidPacketInfoMap * pendingPackets = 0;
1339  switch (protocolType)
1340  {
1342  {
1343  pendingPackets = &m_pendingWifiPackets;
1344  break;
1345  }
1347  {
1348  pendingPackets = &m_pendingUanPackets;
1349  break;
1350  }
1352  {
1353  pendingPackets = &m_pendingCsmaPackets;
1354  break;
1355  }
1357  {
1358  pendingPackets = &m_pendingWimaxPackets;
1359  break;
1360  }
1362  {
1363  pendingPackets = &m_pendingLtePackets;
1364  break;
1365  }
1367  {
1368  pendingPackets = &m_pendingLrWpanPackets;
1369  break;
1370  }
1372  {
1373  pendingPackets = &m_pendingWavePackets;
1374  break;
1375  }
1376  }
1377  return pendingPackets;
1378 
1379 }
1380 
1381 std::string
1383 {
1384  std::string result = "Unknown";
1385  switch (protocolType)
1386  {
1388  {
1389  result = "WIFI";
1390  break;
1391  }
1393  {
1394  result = "UAN";
1395  break;
1396  }
1398  {
1399  result = "CSMA";
1400  break;
1401  }
1403  {
1404  result = "WIMAX";
1405  break;
1406  }
1408  {
1409  result = "LTE";
1410  break;
1411  }
1413  {
1414  result = "LRWPAN";
1415  break;
1416  }
1418  {
1419  result = "WAVE";
1420  break;
1421  }
1422  }
1423  return result;
1424 }
1425 
1426 // Counters
1427 
1428 std::string
1430 {
1431  std::string typeString = "unknown";
1432  switch (counterType)
1433  {
1434  case UINT32_COUNTER:
1435  {
1436  typeString = "UINT32";
1437  break;
1438  }
1439  case DOUBLE_COUNTER:
1440  {
1441  typeString = "DOUBLE";
1442  break;
1443  }
1444  }
1445  return typeString;
1446 }
1447 
1448 // General
1449 
1450 std::string
1452 {
1453  std::ostringstream oss;
1454  p->Print (oss);
1455  return oss.str ();
1456 }
1457 
1458 uint64_t
1460 {
1461  return m_currentPktCount;
1462 }
1463 
1464 void
1466 {
1467  m_started = false;
1468  NS_LOG_INFO ("Stopping Animation");
1470  if (m_f)
1471  {
1472  // Terminate the anim element
1473  WriteXmlClose ("anim");
1474  std::fclose (m_f);
1475  m_f = 0;
1476  }
1477  if (onlyAnimation)
1478  {
1479  return;
1480  }
1481  if (m_routingF)
1482  {
1483  WriteXmlClose ("anim", true);
1484  std::fclose (m_routingF);
1485  m_routingF = 0;
1486  }
1487 }
1488 
1489 void
1491 {
1492  m_currentPktCount = 0;
1493  m_started = true;
1495  WriteXmlAnim ();
1496  WriteNodes ();
1497  WriteNodeColors ();
1499  WriteIpv4Addresses ();
1500  WriteIpv6Addresses ();
1501  WriteNodeSizes ();
1502  WriteNodeEnergies ();
1503  if (!restart)
1504  {
1506  ConnectCallbacks ();
1507  }
1508 }
1509 
1510 void
1511 AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
1512 {
1513  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1514  m_nodeIdIpv4Map.insert (NodeIdIpv4Pair (nodeId, ipv4Address));
1515 }
1516 
1517 void
1518 AnimationInterface::AddToIpv4AddressNodeIdTable (std::vector<std::string> ipv4Addresses, uint32_t nodeId)
1519 {
1520  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
1521  i != ipv4Addresses.end ();
1522  ++i)
1523  {
1524  AddToIpv4AddressNodeIdTable (*i, nodeId);
1525  }
1526 }
1527 
1528 void
1529 AnimationInterface::AddToIpv6AddressNodeIdTable (std::string ipv6Address, uint32_t nodeId)
1530 {
1531  m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1532  m_nodeIdIpv6Map.insert (NodeIdIpv6Pair (nodeId, ipv6Address));
1533 }
1534 
1535 void
1536 AnimationInterface::AddToIpv6AddressNodeIdTable (std::vector<std::string> ipv6Addresses, uint32_t nodeId)
1537 {
1538  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin ();
1539  i != ipv6Addresses.end ();
1540  ++i)
1541  {
1542  AddToIpv6AddressNodeIdTable (*i, nodeId);
1543  }
1544 }
1545 
1546 // Callbacks
1547 void
1549 {
1550 
1551  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
1552  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
1553  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
1554  std::ostringstream oss;
1555  //NodeList/*/DeviceList/*/
1556  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1557  if (dlPhy)
1558  {
1559  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1560  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1561  }
1562  if (ulPhy)
1563  {
1564  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1565  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1566  }
1567 }
1568 
1569 
1570 
1571 void
1573 {
1574 
1575  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
1576  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
1577  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
1578  std::ostringstream oss;
1579  //NodeList/*/DeviceList/*/
1580  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
1581  if (dlPhy)
1582  {
1583  dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1584  dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1585  }
1586  if (ulPhy)
1587  {
1588  ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
1589  ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
1590  }
1591 }
1592 
1593 void
1595 {
1596 
1597  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1598  {
1599  Ptr<Node> n = *i;
1600  NS_ASSERT (n);
1601  uint32_t nDevices = n->GetNDevices ();
1602  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1603  {
1604  Ptr <NetDevice> nd = n->GetDevice (devIndex);
1605  if (!nd)
1606  {
1607  continue;
1608  }
1609  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
1610  if (lteUeNetDevice)
1611  {
1612  ConnectLteUe (n, lteUeNetDevice, devIndex);
1613  continue;
1614  }
1615  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
1616  if (lteEnbNetDevice)
1617  {
1618  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
1619  }
1620  }
1621 
1622  }
1623 }
1624 
1625 void
1627 {
1628  // Connect the callbacks
1629  Config::ConnectFailSafe ("/ChannelList/*/TxRxPointToPoint",
1631  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
1633  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1635  Config::ConnectWithoutContextFailSafe ("/NodeList/*/$ns3::MobilityModel/CourseChange",
1637  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1639  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1641  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1643  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1645  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1647  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1649  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1651  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1653  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1655  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1657  Config::ConnectFailSafe ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1659 
1660  ConnectLte ();
1661 
1662  Config::ConnectFailSafe ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1664  Config::ConnectFailSafe ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1666  Config::ConnectFailSafe ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1668 
1669  // Queue Enqueues
1670 
1671  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1673  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1675  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1677 
1678  // Queue Dequeues
1679 
1680  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1682  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1684  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1686 
1687  // Queue Drops
1688 
1689  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1691  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1693  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1695 
1696 
1697  // Wifi Mac
1698  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1700  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1702  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1704  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1706 
1707  // Wifi Phy
1708  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1710  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1712 
1713  // LrWpan
1714  Config::ConnectFailSafe ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin",
1716  Config::ConnectFailSafe ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin",
1718  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx",
1720  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop",
1722  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx",
1724  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop",
1726 
1727  // Wave
1728  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin",
1730  Config::ConnectFailSafe ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin",
1732 }
1733 
1734 Vector
1736 {
1737  Ptr<MobilityModel> loc = n->GetObject<MobilityModel> ();
1738  if (loc)
1739  {
1740  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
1741  }
1742  else
1743  {
1744  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1745  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
1746  x->SetAttribute ("Min", DoubleValue (0));
1747  x->SetAttribute ("Max", DoubleValue (100));
1748  Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable> ();
1749  y->SetAttribute ("Min", DoubleValue (0));
1750  y->SetAttribute ("Max", DoubleValue (100));
1751  m_nodeLocation[n->GetId ()] = Vector (int (x->GetValue ()), int (y->GetValue ()), 0);
1752  }
1753  return m_nodeLocation[n->GetId ()];
1754 }
1755 
1756 Vector
1758 {
1759  m_nodeLocation[n->GetId ()] = v;
1760  return v;
1761 }
1762 
1763 Vector
1765 {
1766  Ptr <Node> n = ndev->GetNode ();
1767  NS_ASSERT (n);
1768  return UpdatePosition (n);
1769 }
1770 
1771 Vector
1773 {
1774  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
1775  {
1776  NS_FATAL_ERROR ("Node:" << n->GetId () << " not found in Location table");
1777  }
1778  return m_nodeLocation[n->GetId ()];
1779 }
1780 
1781 
1782 std::string
1784 {
1785  Address nodeAddr = nd->GetAddress ();
1786  std::ostringstream oss;
1787  oss << nodeAddr;
1788  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
1789 }
1790 
1791 std::string
1793 {
1794  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1795  if (!ipv4)
1796  {
1797  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1798  return "0.0.0.0";
1799  }
1800  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1801  if (ifIndex == -1)
1802  {
1803  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1804  return "0.0.0.0";
1805  }
1806  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
1807  std::ostringstream oss;
1808  oss << addr.GetLocal ();
1809  return oss.str ();
1810 }
1811 
1812 std::string
1814 {
1815  Ptr<Ipv6> ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv6> ();
1816  if (!ipv6)
1817  {
1818  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1819  return "::";
1820  }
1821  int32_t ifIndex = ipv6->GetInterfaceForDevice (nd);
1822  if (ifIndex == -1)
1823  {
1824  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1825  return "::";
1826  }
1827  bool nonLinkLocalFound = false;
1828  uint32_t nAddresses = ipv6->GetNAddresses (ifIndex);
1829  Ipv6InterfaceAddress addr;
1830  for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1831  {
1832  addr = ipv6->GetAddress (ifIndex, addressIndex);
1833  if (!addr.GetAddress ().IsLinkLocal ())
1834  {
1835  nonLinkLocalFound = true;
1836  break;
1837  }
1838  }
1839  if (!nonLinkLocalFound)
1840  {
1841  addr = ipv6->GetAddress (ifIndex, 0);
1842  }
1843  std::ostringstream oss;
1844  oss << addr.GetAddress ();
1845  return oss.str ();
1846 }
1847 
1848 
1849 
1850 std::vector<std::string>
1852 {
1853  std::vector<std::string> ipv4Addresses;
1854  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
1855  if (!ipv4)
1856  {
1857  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
1858  return ipv4Addresses;
1859  }
1860  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
1861  if (ifIndex == -1)
1862  {
1863  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1864  return ipv4Addresses;
1865  }
1866  for (uint32_t index = 0; index < ipv4->GetNAddresses (ifIndex); ++index)
1867  {
1868  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, index);
1869  std::ostringstream oss;
1870  oss << addr.GetLocal ();
1871  ipv4Addresses.push_back (oss.str ());
1872  }
1873  return ipv4Addresses;
1874 }
1875 
1876 std::vector<std::string>
1878 {
1879  std::vector<std::string> ipv6Addresses;
1880  Ptr<Ipv6> ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv6> ();
1881  if (!ipv6)
1882  {
1883  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv6 object found");
1884  return ipv6Addresses;
1885  }
1886  int32_t ifIndex = ipv6->GetInterfaceForDevice (nd);
1887  if (ifIndex == -1)
1888  {
1889  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
1890  return ipv6Addresses;
1891  }
1892  for (uint32_t index = 0; index < ipv6->GetNAddresses (ifIndex); ++index)
1893  {
1894  Ipv6InterfaceAddress addr = ipv6->GetAddress (ifIndex, index);
1895  std::ostringstream oss;
1896  oss << addr.GetAddress ();
1897  ipv6Addresses.push_back (oss.str ());
1898  }
1899  return ipv6Addresses;
1900 }
1901 
1902 
1903 void
1905 {
1906  for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin ();
1907  i != m_nodeIdIpv4Map.end ();
1908  ++i)
1909  {
1910  std::vector <std::string> ipv4Addresses;
1911  std::pair<NodeIdIpv4Map::const_iterator, NodeIdIpv4Map::const_iterator> iterPair = m_nodeIdIpv4Map.equal_range (i->first);
1912  for (NodeIdIpv4Map::const_iterator it = iterPair.first;
1913  it != iterPair.second;
1914  ++it)
1915  {
1916  ipv4Addresses.push_back (it->second);
1917  }
1918  WriteXmlIpv4Addresses (i->first, ipv4Addresses);
1919  }
1920 }
1921 
1922 void
1924 {
1925  for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin ();
1926  i != m_nodeIdIpv6Map.end ();
1927  i = m_nodeIdIpv6Map.upper_bound (i->first))
1928  {
1929  std::vector <std::string> ipv6Addresses;
1930  std::pair<NodeIdIpv6Map::const_iterator, NodeIdIpv6Map::const_iterator> iterPair = m_nodeIdIpv6Map.equal_range (i->first);
1931  for (NodeIdIpv6Map::const_iterator it = iterPair.first;
1932  it != iterPair.second;
1933  ++it)
1934  {
1935  ipv6Addresses.push_back (it->second);
1936  }
1937  WriteXmlIpv6Addresses (i->first, ipv6Addresses);
1938  }
1939 }
1940 
1941 void
1943 {
1944  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
1945  {
1946  Ptr<Node> n = *i;
1947  UpdatePosition (n);
1948  uint32_t n1Id = n->GetId ();
1949  uint32_t nDev = n->GetNDevices (); // Number of devices
1950  for (uint32_t i = 0; i < nDev; ++i)
1951  {
1952  Ptr<NetDevice> dev = n->GetDevice (i);
1953  NS_ASSERT (dev);
1954  Ptr<Channel> ch = dev->GetChannel ();
1955  std::string channelType = "Unknown channel";
1956  if (ch)
1957  {
1958  channelType = ch->GetInstanceTypeId ().GetName ();
1959  }
1960  NS_LOG_DEBUG ("Got ChannelType" << channelType);
1961 
1962  if (!ch || (channelType != std::string ("ns3::PointToPointChannel")))
1963  {
1964  NS_LOG_DEBUG ("No channel can't be a p2p device");
1965  /*
1966  // Try to see if it is an LTE NetDevice, which does not return a channel
1967  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1968  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1969  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1970  {
1971  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1972  AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ());
1973  }
1974  */
1975  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
1976  AddToIpv4AddressNodeIdTable (ipv4Addresses, n->GetId ());
1977  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
1978  AddToIpv6AddressNodeIdTable (ipv6Addresses, n->GetId ());
1979  if (!ipv4Addresses.empty ())
1980  {
1981  NS_LOG_INFO ("Writing Ipv4 link");
1982  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
1983  }
1984  else if (!ipv6Addresses.empty ())
1985  {
1986  NS_LOG_INFO ("Writing Ipv6 link");
1987  WriteNonP2pLinkProperties (n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType);
1988  }
1989  continue;
1990  }
1991 
1992  else if (channelType == std::string ("ns3::PointToPointChannel"))
1993  { // Since these are duplex links, we only need to dump
1994  // if srcid < dstid
1995  std::size_t nChDev = ch->GetNDevices ();
1996  for (std::size_t j = 0; j < nChDev; ++j)
1997  {
1998  Ptr<NetDevice> chDev = ch->GetDevice (j);
1999  uint32_t n2Id = chDev->GetNode ()->GetId ();
2000  if (n1Id < n2Id)
2001  {
2002 
2003  std::vector<std::string> ipv4Addresses = GetIpv4Addresses (dev);
2004  AddToIpv4AddressNodeIdTable (ipv4Addresses, n1Id);
2005  ipv4Addresses = GetIpv4Addresses (chDev);
2006  AddToIpv4AddressNodeIdTable (ipv4Addresses, n2Id);
2007  std::vector<std::string> ipv6Addresses = GetIpv6Addresses (dev);
2008  AddToIpv6AddressNodeIdTable (ipv6Addresses, n1Id);
2009  ipv6Addresses = GetIpv6Addresses (chDev);
2010  AddToIpv6AddressNodeIdTable (ipv6Addresses, n2Id);
2011 
2012  P2pLinkNodeIdPair p2pPair;
2013  p2pPair.fromNode = n1Id;
2014  p2pPair.toNode = n2Id;
2015  if (!ipv4Addresses.empty ())
2016  {
2017  LinkProperties lp = { GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), "" };
2018  m_linkProperties[p2pPair] = lp;
2019  }
2020  else if (!ipv6Addresses.empty ())
2021  {
2022  LinkProperties lp = { GetIpv6Address (dev) + "~" + GetMacAddress (dev), GetIpv6Address (chDev) + "~" + GetMacAddress (chDev), "" };
2023  m_linkProperties[p2pPair] = lp;
2024  }
2025  WriteXmlLink (n1Id, 0, n2Id);
2026  }
2027  }
2028  }
2029  }
2030  }
2031  m_linkProperties.clear ();
2032 }
2033 
2034 void
2036 {
2037  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2038  {
2039  Ptr<Node> n = *i;
2040  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
2041  Vector v = UpdatePosition (n);
2042  WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y);
2043  }
2044 }
2045 
2046 void
2048 {
2049  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2050  {
2051  Ptr<Node> n = *i;
2052  Rgb rgb = {255, 0, 0};
2053  if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ())
2054  {
2055  m_nodeColors[n->GetId ()] = rgb;
2056  }
2057  UpdateNodeColor (n, rgb.r, rgb.g, rgb.b);
2058  }
2059 }
2060 
2061 void
2063 {
2064  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2065  {
2066  Ptr<Node> n = *i;
2067  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
2068  AnimationInterface::NodeSize s = { 1, 1 };
2069  m_nodeSizes[n->GetId ()] = s;
2070  UpdateNodeSize (n->GetId (), s.width, s.height);
2071  }
2072 }
2073 
2074 void
2076 {
2078  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2079  {
2080  Ptr<Node> n = *i;
2081  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
2082  {
2084  }
2085  }
2086 }
2087 
2088 bool
2090 {
2091  if ((Simulator::Now () >= m_startTime)
2092  && (Simulator::Now () <= m_stopTime))
2093  {
2094  return true;
2095  }
2096  else
2097  {
2098  return false;
2099  }
2100 }
2101 
2102 void
2103 AnimationInterface::SetOutputFile (const std::string& fn, bool routing)
2104 {
2105  if (!routing && m_f)
2106  {
2107  return;
2108  }
2109  if (routing && m_routingF)
2110  {
2111  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
2112  return;
2113  }
2114 
2115  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
2116  FILE * f = 0;
2117  f = std::fopen (fn.c_str (), "w");
2118  if (!f)
2119  {
2120  NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ());
2121  return; // Can't open output file
2122  }
2123  if (routing)
2124  {
2125  m_routingF = f;
2126  m_routingFileName = fn;
2127  }
2128  else
2129  {
2130  m_f = f;
2131  m_outputFileName = fn;
2132  }
2133  return;
2134 }
2135 
2136 void
2138 {
2139  // Start a new trace file if the current packet count exceeded nax packets per file
2142  {
2143  return;
2144  }
2145  NS_LOG_UNCOND ("Max Packets per trace file exceeded");
2146  StopAnimation (true);
2147 }
2148 
2149 std::string
2151 {
2152  return NETANIM_VERSION;
2153 }
2154 
2155 
2156 void
2158 {
2160  {
2161  NS_LOG_INFO ("TrackQueueCounters Completed");
2162  return;
2163  }
2164  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2165  {
2166  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2170  }
2172 }
2173 
2174 void
2176 {
2178  {
2179  NS_LOG_INFO ("TrackWifiMacCounters Completed");
2180  return;
2181  }
2182  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2183  {
2184  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2189  }
2191 }
2192 
2193 void
2195 {
2197  {
2198  NS_LOG_INFO ("TrackWifiPhyCounters Completed");
2199  return;
2200  }
2201  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2202  {
2203  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2206  }
2208 }
2209 
2210 void
2212 {
2214  {
2215  NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed");
2216  return;
2217  }
2218  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2219  {
2220  uint32_t nodeId = Ptr <Node> (*i)->GetId ();
2224  }
2226 }
2227 
2228 
2229 
2230 
2231 
2232 /***** Routing-related *****/
2233 
2234 void
2236 {
2237  if (m_ipv4RouteTrackElements.empty ())
2238  {
2239  return;
2240  }
2241  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
2242  i != m_ipv4RouteTrackElements.end ();
2243  ++i)
2244  {
2245  Ipv4RouteTrackElement trackElement = *i;
2246  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
2247  if (!fromNode)
2248  {
2249  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
2250  continue;
2251  }
2252  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2253  if (!ipv4)
2254  {
2255  NS_LOG_WARN ("ipv4 object not found");
2256  continue;
2257  }
2259  if (!rp)
2260  {
2261  NS_LOG_WARN ("Routing protocol object not found");
2262  continue;
2263  }
2264  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
2265  Ptr<Packet> pkt = Create<Packet> ();
2266  Ipv4Header header;
2267  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
2268  Socket::SocketErrno sockerr;
2269  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2270  Ipv4RoutePathElements rpElements;
2271  if (!rt)
2272  {
2273  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
2274  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2275  rpElements.push_back (elem);
2276  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2277  continue;
2278  }
2279  std::ostringstream oss;
2280  oss << rt->GetGateway ();
2281  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
2282  if (rt->GetGateway () == "0.0.0.0")
2283  {
2284  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
2285  rpElements.push_back (elem);
2286  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
2287  {
2288  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
2289  rpElements.push_back (elem2);
2290  }
2291  }
2292  else if (rt->GetGateway () == "127.0.0.1")
2293  {
2294  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
2295  rpElements.push_back (elem);
2296  }
2297  else
2298  {
2299  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
2300  rpElements.push_back (elem);
2301  }
2302  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
2303  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
2304  }
2305 
2306 }
2307 
2308 void
2310 {
2312  {
2313  NS_LOG_INFO ("TrackIpv4Route completed");
2314  return;
2315  }
2316  if (m_routingNc.GetN ())
2317  {
2318  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
2319  {
2320  Ptr <Node> n = *i;
2321  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2322  }
2323  }
2324  else
2325  {
2326  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
2327  {
2328  Ptr <Node> n = *i;
2329  WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n));
2330  }
2331  }
2334 }
2335 
2336 std::string
2338 {
2339 
2340  NS_ASSERT (n);
2341  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
2342  if (!ipv4)
2343  {
2344  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
2345  return "";
2346  }
2347  std::stringstream stream;
2348  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
2349  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
2350  return stream.str ();
2351 
2352 }
2353 
2354 void
2355 AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
2356 {
2357  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
2358  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
2359  {
2360  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
2361  return;
2362  }
2363  Ptr <Node> fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]);
2365  if (fromNode->GetId () == toNode->GetId ())
2366  {
2367  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
2368  rpElements.push_back (elem);
2369  return;
2370  }
2371  if (!fromNode)
2372  {
2373  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2374  return;
2375  }
2376  if (!toNode)
2377  {
2378  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2379  return;
2380  }
2381  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
2382  if (!ipv4)
2383  {
2384  NS_LOG_WARN ("ipv4 object not found");
2385  return;
2386  }
2388  if (!rp)
2389  {
2390  NS_LOG_WARN ("Routing protocol object not found");
2391  return;
2392  }
2393  Ptr<Packet> pkt = Create<Packet> ();
2394  Ipv4Header header;
2395  header.SetDestination (Ipv4Address (to.c_str ()));
2396  Socket::SocketErrno sockerr;
2397  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
2398  if (!rt)
2399  {
2400  return;
2401  }
2402  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
2403  std::ostringstream oss;
2404  oss << rt->GetGateway ();
2405  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2406  {
2407  NS_LOG_INFO ("Null gw");
2408  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
2409  rpElements.push_back (elem);
2410  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
2411  {
2412  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
2413  rpElements.push_back (elem2);
2414  }
2415  return;
2416  }
2417  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
2418  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
2419  rpElements.push_back (elem);
2420  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
2421 
2422 }
2423 
2424 
2425 
2426 /***** WriteXml *****/
2427 
2428 void
2430 {
2431  AnimXmlElement element ("anim");
2432  element.AddAttribute ("ver", GetNetAnimVersion ());
2433  FILE * f = m_f;
2434  if (!routing)
2435  {
2436  element.AddAttribute ("filetype", "animation");
2437  }
2438  else
2439  {
2440  element.AddAttribute ("filetype", "routing");
2441  f = m_routingF;
2442  }
2443  WriteN (element.ToString (false) + ">\n", f);
2444 }
2445 
2446 void
2447 AnimationInterface::WriteXmlClose (std::string name, bool routing)
2448 {
2449  std::string closeString = "</" + name + ">\n";
2450  if (!routing)
2451  {
2452  WriteN (closeString, m_f);
2453  }
2454  else
2455  {
2456  WriteN (closeString, m_routingF);
2457  }
2458 }
2459 
2460 void
2461 AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY)
2462 {
2463  AnimXmlElement element ("node");
2464  element.AddAttribute ("id", id);
2465  element.AddAttribute ("sysId", sysId);
2466  element.AddAttribute ("locX", locX);
2467  element.AddAttribute ("locY", locY);
2468  WriteN (element.ToString (), m_f);
2469 }
2470 
2471 void
2472 AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription)
2473 {
2474  AnimXmlElement element ("linkupdate");
2475  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2476  element.AddAttribute ("fromId", fromId);
2477  element.AddAttribute ("toId", toId);
2478  element.AddAttribute ("ld", linkDescription, true);
2479  WriteN (element.ToString (), m_f);
2480 }
2481 
2482 void
2483 AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
2484 {
2485  AnimXmlElement element ("link");
2486  element.AddAttribute ("fromId", fromId);
2487  element.AddAttribute ("toId", toId);
2488 
2489  LinkProperties lprop;
2490  lprop.fromNodeDescription = "";
2491  lprop.toNodeDescription = "";
2492  lprop.linkDescription = "";
2493 
2494  P2pLinkNodeIdPair p1 = { fromId, toId };
2495  P2pLinkNodeIdPair p2 = { toId, fromId };
2496  if (m_linkProperties.find (p1) != m_linkProperties.end ())
2497  {
2498  lprop = m_linkProperties[p1];
2499  }
2500  else if (m_linkProperties.find (p2) != m_linkProperties.end ())
2501  {
2502  lprop = m_linkProperties[p2];
2503  }
2504 
2505  element.AddAttribute ("fd", lprop.fromNodeDescription, true);
2506  element.AddAttribute ("td", lprop.toNodeDescription, true);
2507  element.AddAttribute ("ld", lprop.linkDescription, true);
2508  WriteN (element.ToString (), m_f);
2509 }
2510 
2511 void
2512 AnimationInterface::WriteXmlIpv4Addresses (uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2513 {
2514  AnimXmlElement element ("ip");
2515  element.AddAttribute ("n", nodeId);
2516  for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin ();
2517  i != ipv4Addresses.end ();
2518  ++i)
2519  {
2520  AnimXmlElement valueElement ("address");
2521  valueElement.SetText (*i);
2522  element.AppendChild (valueElement);
2523  }
2524  WriteN (element.ToString (), m_f);
2525 }
2526 
2527 void
2528 AnimationInterface::WriteXmlIpv6Addresses (uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2529 {
2530  AnimXmlElement element ("ipv6");
2531  element.AddAttribute ("n", nodeId);
2532  for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin ();
2533  i != ipv6Addresses.end ();
2534  ++i)
2535  {
2536  AnimXmlElement valueElement ("address");
2537  valueElement.SetText (*i);
2538  element.AppendChild (valueElement);
2539  }
2540  WriteN (element.ToString (), m_f);
2541 }
2542 
2543 void
2544 AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
2545 {
2546  AnimXmlElement element ("rt");
2547  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2548  element.AddAttribute ("id", nodeId);
2549  element.AddAttribute ("info", routingInfo.c_str (), true);
2550  WriteN (element.ToString (), m_routingF);
2551 }
2552 
2553 void
2554 AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2555 {
2556  std::string tagName = "rp";
2557  AnimXmlElement element (tagName, false);
2558  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2559  element.AddAttribute ("id", nodeId);
2560  element.AddAttribute ("d", destination.c_str ());
2561  element.AddAttribute ("c", rpElements.size ());
2562  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2563  i != rpElements.end ();
2564  ++i)
2565  {
2566  Ipv4RoutePathElement rpElement = *i;
2567  AnimXmlElement rpeElement ("rpe");
2568  rpeElement.AddAttribute ("n", rpElement.nodeId);
2569  rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ());
2570  element.AppendChild (rpeElement);
2571  }
2572  WriteN (element.ToString (), m_routingF);
2573 }
2574 
2575 
2576 void
2577 AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2578 {
2579  AnimXmlElement element ("pr");
2580  element.AddAttribute ("uId", animUid);
2581  element.AddAttribute ("fId", fId);
2582  element.AddAttribute ("fbTx", fbTx);
2583  if (!metaInfo.empty ())
2584  {
2585  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2586  }
2587  WriteN (element.ToString (), m_f);
2588 }
2589 
2590 void
2591 AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx)
2592 {
2593  AnimXmlElement element (pktType);
2594  element.AddAttribute ("uId", animUid);
2595  element.AddAttribute ("tId", tId);
2596  element.AddAttribute ("fbRx", fbRx);
2597  element.AddAttribute ("lbRx", lbRx);
2598  WriteN (element.ToString (), m_f);
2599 }
2600 
2601 void
2602 AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2603  uint32_t tId, double fbRx, double lbRx, std::string metaInfo)
2604 {
2605  AnimXmlElement element (pktType);
2606  element.AddAttribute ("fId", fId);
2607  element.AddAttribute ("fbTx", fbTx);
2608  element.AddAttribute ("lbTx", lbTx);
2609  if (!metaInfo.empty ())
2610  {
2611  element.AddAttribute ("meta-info", metaInfo.c_str (), true);
2612  }
2613  element.AddAttribute ("tId", tId);
2614  element.AddAttribute ("fbRx", fbRx);
2615  element.AddAttribute ("lbRx", lbRx);
2616  WriteN (element.ToString (), m_f);
2617 }
2618 
2619 void
2620 AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2621 {
2622  AnimXmlElement element ("ncs");
2623  element.AddAttribute ("ncId", nodeCounterId);
2624  element.AddAttribute ("n", counterName);
2625  element.AddAttribute ("t", CounterTypeToString (counterType));
2626  WriteN (element.ToString (), m_f);
2627 }
2628 
2629 void
2630 AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath)
2631 {
2632  AnimXmlElement element ("res");
2633  element.AddAttribute ("rid", resourceId);
2634  element.AddAttribute ("p", resourcePath);
2635  WriteN (element.ToString (), m_f);
2636 }
2637 
2638 void
2639 AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2640 {
2641  AnimXmlElement element ("nu");
2642  element.AddAttribute ("p", "i");
2643  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2644  element.AddAttribute ("id", nodeId);
2645  element.AddAttribute ("rid", resourceId);
2646  WriteN (element.ToString (), m_f);
2647 }
2648 
2649 void
2650 AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height)
2651 {
2652  AnimXmlElement element ("nu");
2653  element.AddAttribute ("p", "s");
2654  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2655  element.AddAttribute ("id", nodeId);
2656  element.AddAttribute ("w", width);
2657  element.AddAttribute ("h", height);
2658  WriteN (element.ToString (), m_f);
2659 }
2660 
2661 void
2662 AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y)
2663 {
2664  AnimXmlElement element ("nu");
2665  element.AddAttribute ("p", "p");
2666  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2667  element.AddAttribute ("id", nodeId);
2668  element.AddAttribute ("x", x);
2669  element.AddAttribute ("y", y);
2670  WriteN (element.ToString (), m_f);
2671 }
2672 
2673 void
2674 AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2675 {
2676  AnimXmlElement element ("nu");
2677  element.AddAttribute ("p", "c");
2678  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2679  element.AddAttribute ("id", nodeId);
2680  element.AddAttribute ("r", (uint32_t) r);
2681  element.AddAttribute ("g", (uint32_t) g);
2682  element.AddAttribute ("b", (uint32_t) b);
2683  WriteN (element.ToString (), m_f);
2684 }
2685 
2686 void
2688 {
2689  AnimXmlElement element ("nu");
2690  element.AddAttribute ("p", "d");
2691  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2692  element.AddAttribute ("id", nodeId);
2693  if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
2694  {
2695  element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
2696  }
2697  WriteN (element.ToString (), m_f);
2698 }
2699 
2700 
2701 void
2702 AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2703 {
2704  AnimXmlElement element ("nc");
2705  element.AddAttribute ("c", nodeCounterId);
2706  element.AddAttribute ("i", nodeId);
2707  element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
2708  element.AddAttribute ("v", counterValue);
2709  WriteN (element.ToString (), m_f);
2710 }
2711 
2712 void
2713 AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2714 {
2715  AnimXmlElement element ("bg");
2716  element.AddAttribute ("f", fileName);
2717  element.AddAttribute ("x", x);
2718  element.AddAttribute ("y", y);
2719  element.AddAttribute ("sx", scaleX);
2720  element.AddAttribute ("sy", scaleY);
2721  element.AddAttribute ("o", opacity);
2722  WriteN (element.ToString (), m_f);
2723 }
2724 
2725 void
2726 AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType)
2727 {
2728  AnimXmlElement element ("nonp2plinkproperties");
2729  element.AddAttribute ("id", id);
2730  element.AddAttribute ("ipAddress", ipAddress);
2731  element.AddAttribute ("channelType", channelType);
2732  WriteN (element.ToString (), m_f);
2733 }
2734 
2735 
2736 
2737 /***** AnimXmlElement *****/
2738 
2739 AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool emptyElement)
2740  : m_tagName (tagName),
2741  m_text ("")
2742 {
2743 }
2744 
2745 template <typename T>
2746 void
2747 AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape)
2748 {
2749  std::ostringstream oss;
2750  oss << std::setprecision (10);
2751  oss << value;
2752  std::string attributeString = attribute.c_str ();
2753  if (xmlEscape)
2754  {
2755  attributeString += "=\"";
2756  std::string valueStr = oss.str ();
2757  for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it)
2758  {
2759  switch (*it)
2760  {
2761  case '&':
2762  attributeString += "&amp;";
2763  break;
2764  case '\"':
2765  attributeString += "&quot;";
2766  break;
2767  case '\'':
2768  attributeString += "&apos;";
2769  break;
2770  case '<':
2771  attributeString += "&lt;";
2772  break;
2773  case '>':
2774  attributeString += "&gt;";
2775  break;
2776  default:
2777  attributeString += *it;
2778  break;
2779  }
2780  }
2781  attributeString += "\" ";
2782  }
2783  else
2784  {
2785  attributeString += "=\"" + oss.str () + "\" ";
2786  }
2787  m_attributes.push_back (attributeString);
2788 }
2789 
2790 void
2792 {
2793  m_children.push_back (e.ToString ());
2794 }
2795 
2796 void
2798 {
2799  m_text = text;
2800 }
2801 
2802 std::string
2804 {
2805  std::string elementString = "<" + m_tagName + " ";
2806 
2807 
2808  for (std::vector<std::string>::const_iterator i = m_attributes.begin ();
2809  i != m_attributes.end ();
2810  ++i)
2811  {
2812  elementString += *i;
2813  }
2814  if (m_children.empty () && m_text.empty ())
2815  {
2816  if (autoClose)
2817  {
2818  elementString += "/>";
2819  }
2820  }
2821  else
2822  {
2823  elementString += ">";
2824  if (!m_text.empty ())
2825  {
2826  elementString += m_text;
2827  }
2828  if (!m_children.empty ())
2829  {
2830  elementString += "\n";
2831  for (std::vector<std::string>::const_iterator i = m_children.begin ();
2832  i != m_children.end ();
2833  ++i)
2834  {
2835  elementString += *i + "\n";
2836  }
2837 
2838  }
2839  if (autoClose)
2840  {
2841  elementString += "</" + m_tagName + ">";
2842  }
2843  }
2844 
2845 
2846  return elementString + ((autoClose) ? "\n" : "");
2847 }
2848 
2849 
2850 
2851 
2852 
2853 /***** AnimByteTag *****/
2854 
2855 TypeId
2857 {
2858  static TypeId tid = TypeId ("ns3::AnimByteTag")
2859  .SetParent<Tag> ()
2860  .SetGroupName ("NetAnim")
2861  .AddConstructor<AnimByteTag> ()
2862  ;
2863  return tid;
2864 }
2865 
2866 TypeId
2868 {
2869  return GetTypeId ();
2870 }
2871 
2872 uint32_t
2874 {
2875  return sizeof (uint64_t);
2876 }
2877 
2878 void
2880 {
2881  i.WriteU64 (m_AnimUid);
2882 }
2883 
2884 void
2886 {
2887  m_AnimUid = i.ReadU64 ();
2888 }
2889 
2890 void
2891 AnimByteTag::Print (std::ostream &os) const
2892 {
2893  os << "AnimUid=" << m_AnimUid;
2894 }
2895 
2896 void
2897 AnimByteTag::Set (uint64_t AnimUid)
2898 {
2899  m_AnimUid = AnimUid;
2900 }
2901 
2902 uint64_t
2903 AnimByteTag::Get (void) const
2904 {
2905  return m_AnimUid;
2906 }
2907 
2909  : m_txnd (0),
2910  m_txNodeId (0),
2911  m_fbTx (0),
2912  m_lbTx (0),
2913  m_lbRx (0)
2914 {
2915 }
2916 
2918 {
2919  m_txnd = pInfo.m_txnd;
2920  m_txNodeId = pInfo.m_txNodeId;
2921  m_fbTx = pInfo.m_fbTx;
2922  m_lbTx = pInfo.m_lbTx;
2923  m_lbRx = pInfo.m_lbRx;
2924 }
2925 
2927  const Time fbTx,
2928  uint32_t txNodeId)
2929  : m_txnd (txnd),
2930  m_txNodeId (0),
2931  m_fbTx (fbTx.GetSeconds ()),
2932  m_lbTx (0),
2933  m_lbRx (0)
2934 {
2935  if (!m_txnd)
2936  {
2937  m_txNodeId = txNodeId;
2938  }
2939 }
2940 
2941 void
2943 {
2944  Ptr <Node> n = nd->GetNode ();
2945  m_fbRx = fbRx;
2946  m_rxnd = nd;
2947 }
2948 
2949 } // 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:939
void Set(uint64_t AnimUid)
Set global Uid in tag.
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing)
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
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:103
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.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint32_t GetId(void) const
Definition: node.cc:109
FILE * m_routingF
File handle for routing table output (0 if None);.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
bool HasNext(void) const
Definition: packet.cc:65
std::string GetIpv4Address(Ptr< NetDevice > nd)
Get IPv4 address.
std::string CounterTypeToString(CounterType counterType)
Counter type to string function.
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
AnimationInterface(const std::string filename)
Constructor.
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP.
void WriteXmlUpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Write XML update node image function.
std::string GetIpv6Address(Ptr< NetDevice > nd)
Get IPv6 address.
virtual void Serialize(TagBuffer i) const
Serialize function.
NodeCounterMap64 m_nodeLrWpanMacRxDrop
node LR-WPAN MAC receive drop
std::map< std::string, uint32_t > m_ipv6ToNodeIdMap
IPv6 to node ID map.
static TypeId GetTypeId(void)
Get Type Id.
void WriteXmlIpv6Addresses(uint32_t nodeId, std::vector< std::string > ipv6Addresses)
Write XML Ipv6 addresses function.
void WriteNodes()
Write nodes function.
void TrackIpv4L3ProtocolCounters()
Track IPv4 L3 protocol counters function.
Introspection did not find any typical Config paths.
Definition: energy-source.h:81
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
CSMA Phy transmit begin trace function.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
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:205
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.
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
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:281
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
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
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
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
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.
Time stopTime
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 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:470
double f(double x, void *params)
Definition: 80211b.c:70
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:907
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.
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:927
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:195
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
void WriteXmlUpdateNodeCounter(uint32_t counterId, uint32_t nodeId, double value)
Write XML update node counter function.
AnimUidPacketInfoMap m_pendingWavePackets
pending WAVE packets
Vector UpdatePosition(Ptr< Node > n)
Update position function.
void LrWpanMacRxTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC receive trace function.
Ptr< const NetDevice > m_rxnd
receive device
Vector GetPosition(void) const
virtual uint32_t GetSerializedSize(void) const
Get Serialized Size.
void WriteNodeSizes()
Write node sizes function.
double GetNodeEnergyFraction(Ptr< const Node > node) const
Get node&#39;s energy fraction (This used only for testing)
void GenericWirelessRxTrace(std::string context, Ptr< const Packet > p, ProtocolType protocolType)
Generic wireless receive trace function.
NodeCounterMap64 m_nodeIpv4Rx
node IPv4 receive
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
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.
void WifiPhyTxBeginTrace(std::string context, Ptr< const WifiPsdu > psdu, WifiTxVector txVector, double txPowerW)
wifi Phy transmit PSDU begin trace function
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
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:273
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:1278
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
Definition: wifi-phy.h:52
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:165
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:923
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:912
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.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
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:933
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