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