A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
animation-interface.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: George F. Riley<riley@ece.gatech.edu>
5 * Modified by: John Abraham <john.abraham@gatech.edu>
6 * Contributions: Eugene Kalishenko <ydginster@gmail.com> (Open Source and Linux Laboratory
7 * http://wiki.osll.ru/doku.php/start) Tommaso Pecorella <tommaso.pecorella@unifi.it> Pavel Vasilyev
8 * <pavel.vasilyev@sredasolutions.com>
9 */
10
11// Interface between ns-3 and the network animator
12
13#include <cstdio>
14#ifndef WIN32
15#include <unistd.h>
16#endif
17#include <fstream>
18#include <iomanip>
19#include <map>
20#include <sstream>
21#include <string>
22
23// ns3 includes
24#ifdef __WIN32__
25#include "ns3/bs-net-device.h"
26#include "ns3/csma-net-device.h"
27#endif
28#include "animation-interface.h"
29
30#include "ns3/channel.h"
31#include "ns3/config.h"
32#include "ns3/constant-position-mobility-model.h"
33#include "ns3/double.h"
34#include "ns3/energy-source-container.h"
35#include "ns3/ipv4-routing-protocol.h"
36#include "ns3/ipv4.h"
37#include "ns3/ipv6.h"
38#include "ns3/lr-wpan-mac-header.h"
39#include "ns3/lr-wpan-net-device.h"
40#include "ns3/lte-enb-phy.h"
41#include "ns3/lte-ue-phy.h"
42#include "ns3/mobility-model.h"
43#include "ns3/node.h"
44#include "ns3/packet.h"
45#include "ns3/simulator.h"
46#include "ns3/uan-mac.h"
47#include "ns3/uan-net-device.h"
48#include "ns3/wifi-mac-header.h"
49#include "ns3/wifi-mac.h"
50#include "ns3/wifi-net-device.h"
51#include "ns3/wifi-psdu.h"
52#include "ns3/wimax-mac-header.h"
53
54namespace ns3
55{
56
57NS_LOG_COMPONENT_DEFINE("AnimationInterface");
58
59// Globals
60
61static bool initialized = false; //!< Initialization flag
62
63// Public methods
64
66 : m_f(nullptr),
67 m_routingF(nullptr),
68 m_mobilityPollInterval(Seconds(0.25)),
69 m_outputFileName(fn),
70 gAnimUid(0),
71 m_writeCallback(nullptr),
72 m_started(false),
73 m_enablePacketMetadata(false),
74 m_startTime(Seconds(0)),
75 m_stopTime(Seconds(3600 * 1000)),
76 m_maxPktsPerFile(MAX_PKTS_PER_TRACE_FILE),
77 m_originalFileName(fn),
78 m_routingStopTime(Seconds(0)),
79 m_routingFileName(""),
80 m_routingPollInterval(Seconds(5)),
81 m_trackPackets(true)
82{
83 initialized = true;
85
86#ifdef __WIN32__
87 /**
88 * Shared libraries are handled differently on Windows and
89 * need to be explicitly loaded via LoadLibrary("library.dll").
90 *
91 * Otherwise, static import libraries .dll.a/.lib (MinGW/MSVC)
92 * can be linked to the executables to perform the loading of
93 * their respective .dll implicitly during static initialization.
94 *
95 * The .dll.a/.lib however, only gets linked if we instantiate at
96 * least one symbol exported by the .dll.
97 *
98 * To ensure TypeIds from the Csma, Uan, Wifi and Wimax
99 * modules are registered during runtime, we need to instantiate
100 * at least one symbol exported by each of these module libraries.
101 */
102 static BaseStationNetDevice b;
103 static CsmaNetDevice c;
104 static WifiNetDevice w;
105 static UanNetDevice u;
106#endif
107}
108
113
114void
119
120void
137
138void
161
162void
182
183void
203
206 Time startTime,
208 Time pollInterval)
209{
210 SetOutputFile(fileName, true);
212 m_routingPollInterval = pollInterval;
213 WriteXmlAnim(true);
215 return *this;
216}
217
220 Time startTime,
222 NodeContainer nc,
223 Time pollInterval)
224{
225 m_routingNc = nc;
226 return EnableIpv4RouteTracking(fileName, startTime, stopTime, pollInterval);
227}
228
230AnimationInterface::AddSourceDestination(uint32_t fromNodeId, std::string ipv4Address)
231{
232 Ipv4RouteTrackElement element = {ipv4Address, fromNodeId};
233 m_ipv4RouteTrackElements.push_back(element);
234 return *this;
235}
236
237void
242
243void
248
249void
251{
252 m_maxPktsPerFile = maxPacketsPerFile;
253}
254
256AnimationInterface::AddNodeCounter(std::string counterName, CounterType counterType)
257{
258 m_nodeCounters.push_back(counterName);
259 uint32_t counterId = m_nodeCounters.size() - 1; // counter ID is zero-indexed
260 WriteXmlAddNodeCounter(counterId, counterName, counterType);
261 return counterId;
262}
263
265AnimationInterface::AddResource(std::string resourcePath)
266{
267 m_resources.push_back(resourcePath);
268 uint32_t resourceId = m_resources.size() - 1; // resource ID is zero-indexed
269 WriteXmlAddResource(resourceId, resourcePath);
270 return resourceId;
271}
272
273void
275{
276 m_enablePacketMetadata = enable;
277 if (enable)
278 {
280 }
281}
282
283bool
288
289bool
291{
292 return m_started;
293}
294
295void
297{
298 m_writeCallback = cb;
299}
300
301void
306
307void
312
313void
315{
316 NS_ASSERT(n);
318 if (!loc)
319 {
321 n->AggregateObject(loc);
322 }
323 Vector hubVec(x, y, z);
324 loc->SetPosition(hubVec);
325 NS_LOG_INFO("Node:" << n->GetId() << " Position set to:(" << x << "," << y << "," << z << ")");
326}
327
328void
330{
331 NS_LOG_INFO("Setting node image for Node Id:" << nodeId);
332 if (resourceId > (m_resources.size() - 1))
333 {
334 NS_FATAL_ERROR("Resource Id:" << resourceId << " not found. Did you use AddResource?");
335 }
336 WriteXmlUpdateNodeImage(nodeId, resourceId);
337}
338
339void
340AnimationInterface::UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
341{
342 if (nodeCounterId > (m_nodeCounters.size() - 1))
343 {
344 NS_FATAL_ERROR("NodeCounter Id:" << nodeCounterId
345 << " not found. Did you use AddNodeCounter?");
346 }
347 WriteXmlUpdateNodeCounter(nodeCounterId, nodeId, counter);
348}
349
350void
352 double x,
353 double y,
354 double scaleX,
355 double scaleY,
356 double opacity)
357{
358 if ((opacity < 0) || (opacity > 1))
359 {
360 NS_FATAL_ERROR("Opacity must be between 0.0 and 1.0");
361 }
362 WriteXmlUpdateBackground(fileName, x, y, scaleX, scaleY, opacity);
363}
364
365void
366AnimationInterface::UpdateNodeSize(Ptr<Node> n, double width, double height)
367{
368 UpdateNodeSize(n->GetId(), width, height);
369}
370
371void
372AnimationInterface::UpdateNodeSize(uint32_t nodeId, double width, double height)
373{
374 AnimationInterface::NodeSize s = {width, height};
375 m_nodeSizes[nodeId] = s;
376 WriteXmlUpdateNodeSize(nodeId, s.width, s.height);
377}
378
379void
380AnimationInterface::UpdateNodeColor(Ptr<Node> n, uint8_t r, uint8_t g, uint8_t b)
381{
382 UpdateNodeColor(n->GetId(), r, g, b);
383}
384
385void
386AnimationInterface::UpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
387{
389 NS_LOG_INFO("Setting node color for Node Id:" << nodeId);
390 Rgb rgb = {r, g, b};
391 m_nodeColors[nodeId] = rgb;
392 WriteXmlUpdateNodeColor(nodeId, r, g, b);
393}
394
395void
397 uint32_t toNode,
398 std::string linkDescription)
399{
400 WriteXmlUpdateLink(fromNode, toNode, linkDescription);
401}
402
403void
405 Ptr<Node> toNode,
406 std::string linkDescription)
407{
408 NS_ASSERT(fromNode);
409 NS_ASSERT(toNode);
410 WriteXmlUpdateLink(fromNode->GetId(), toNode->GetId(), linkDescription);
411}
412
413void
415{
416 UpdateNodeDescription(n->GetId(), descr);
417}
418
419void
421{
423 m_nodeDescriptions[nodeId] = descr;
425}
426
427// Private methods
428
429double
431{
432 const auto fractionIter = m_nodeEnergyFraction.find(node->GetId());
433 NS_ASSERT(fractionIter != m_nodeEnergyFraction.end());
434 return fractionIter->second;
435}
436
437void
439{
441 Ptr<Node> n = mobility->GetObject<Node>();
442 NS_ASSERT(n);
443 Vector v;
444 if (!mobility)
445 {
446 v = GetPosition(n);
447 }
448 else
449 {
450 v = mobility->GetPosition();
451 }
452 UpdatePosition(n, v);
453 WriteXmlUpdateNodePosition(n->GetId(), v.x, v.y);
454}
455
456bool
458{
459 Vector oldLocation = GetPosition(n);
460 bool moved = !((ceil(oldLocation.x) == ceil(newLocation.x)) &&
461 (ceil(oldLocation.y) == ceil(newLocation.y)));
462 return moved;
463}
464
465void
487
488std::vector<Ptr<Node>>
490{
491 std::vector<Ptr<Node>> movedNodes;
492 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
493 {
494 Ptr<Node> n = *i;
495 NS_ASSERT(n);
496 Ptr<MobilityModel> mobility = n->GetObject<MobilityModel>();
497 Vector newLocation;
498 if (!mobility)
499 {
500 newLocation = GetPosition(n);
501 }
502 else
503 {
504 newLocation = mobility->GetPosition();
505 }
506 if (!NodeHasMoved(n, newLocation))
507 {
508 continue; // Location has not changed
509 }
510 else
511 {
512 UpdatePosition(n, newLocation);
513 movedNodes.push_back(n);
514 }
515 }
516 return movedNodes;
517}
518
519int
520AnimationInterface::WriteN(const std::string& st, FILE* f)
521{
522 if (!f)
523 {
524 return 0;
525 }
526 if (m_writeCallback)
527 {
528 m_writeCallback(st.c_str());
529 }
530 return WriteN(st.c_str(), st.length(), f);
531}
532
533int
534AnimationInterface::WriteN(const char* data, uint32_t count, FILE* f)
535{
536 if (!f)
537 {
538 return 0;
539 }
540 // Write count bytes to h from data
541 uint32_t nLeft = count;
542 const char* p = data;
543 uint32_t written = 0;
544 while (nLeft)
545 {
546 int n = std::fwrite(p, 1, nLeft, f);
547 if (n <= 0)
548 {
549 return written;
550 }
551 written += n;
552 nLeft -= n;
553 p += n;
554 }
555 return written;
556}
557
558void
560 std::string destination,
561 Ipv4RoutePathElements rpElements)
562{
563 NS_LOG_INFO("Writing Route Path From :" << nodeId << " To: " << destination);
564 WriteXmlRp(nodeId, destination, rpElements);
565 /*
566 for (auto i = rpElements.begin (); i != rpElements.end (); ++i)
567 {
568 Ipv4RoutePathElement rpElement = *i;
569 NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
570 WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
571
572 }
573 */
574}
575
576void
578 std::string ipv4Address,
579 std::string channelType)
580{
581 WriteXmlNonP2pLinkProperties(id, ipv4Address, channelType);
582}
583
584const std::vector<std::string>
585AnimationInterface::GetElementsFromContext(const std::string& context) const
586{
587 std::vector<std::string> elements;
588 std::size_t pos1 = 0;
589 std::size_t pos2;
590 while (pos1 != std::string::npos)
591 {
592 pos1 = context.find('/', pos1);
593 pos2 = context.find('/', pos1 + 1);
594 elements.push_back(context.substr(pos1 + 1, pos2 - (pos1 + 1)));
595 pos1 = pos2;
596 pos2 = std::string::npos;
597 }
598 return elements;
599}
600
602AnimationInterface::GetNodeFromContext(const std::string& context) const
603{
604 // Use "NodeList/*/ as reference
605 // where element [1] is the Node Id
606
607 std::vector<std::string> elements = GetElementsFromContext(context);
608 Ptr<Node> n = NodeList::GetNode(std::stoi(elements.at(1)));
609 NS_ASSERT(n);
610
611 return n;
612}
613
616{
617 // Use "NodeList/*/DeviceList/*/ as reference
618 // where element [1] is the Node Id
619 // element [2] is the NetDevice Id
620
621 std::vector<std::string> elements = GetElementsFromContext(context);
622 Ptr<Node> n = GetNodeFromContext(context);
623
624 return n->GetDevice(std::stoi(elements.at(3)));
625}
626
627uint64_t
629{
630 AnimByteTag tag;
631 TypeId tid = tag.GetInstanceTypeId();
632 ByteTagIterator i = p->GetByteTagIterator();
633 bool found = false;
634 while (i.HasNext())
635 {
636 ByteTagIterator::Item item = i.Next();
637 if (tid == item.GetTypeId())
638 {
639 item.GetTag(tag);
640 found = true;
641 }
642 }
643 if (found)
644 {
645 return tag.Get();
646 }
647 else
648 {
649 return 0;
650 }
651}
652
653void
655{
656 AnimByteTag tag;
657 tag.Set(animUid);
658 p->AddByteTag(tag);
659}
660
661void
663 double previousEnergy,
664 double currentEnergy)
665{
667 const Ptr<const Node> node = GetNodeFromContext(context);
668 const uint32_t nodeId = node->GetId();
669
670 NS_LOG_INFO("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
671
672 const Ptr<energy::EnergySource> energySource = node->GetObject<energy::EnergySource>();
673
674 NS_ASSERT(energySource);
675 // Don't call GetEnergyFraction () because of recursion
676 const double energyFraction = currentEnergy / energySource->GetInitialEnergy();
677
678 NS_LOG_INFO("Total energy fraction on node " << nodeId << ": " << energyFraction);
679
680 m_nodeEnergyFraction[nodeId] = energyFraction;
681 UpdateNodeCounter(m_remainingEnergyCounterId, nodeId, energyFraction);
682}
683
684void
686{
687 const Ptr<const Node> node = GetNodeFromContext(context);
688 ++m_nodeWifiPhyTxDrop[node->GetId()];
689}
690
691void
695{
696 const Ptr<const Node> node = GetNodeFromContext(context);
697 ++m_nodeWifiPhyRxDrop[node->GetId()];
698}
699
700void
702{
703 const Ptr<const Node> node = GetNodeFromContext(context);
704 ++m_nodeWifiMacTx[node->GetId()];
705}
706
707void
709{
710 const Ptr<const Node> node = GetNodeFromContext(context);
711 ++m_nodeWifiMacTxDrop[node->GetId()];
712}
713
714void
716{
717 const Ptr<const Node> node = GetNodeFromContext(context);
718 ++m_nodeWifiMacRx[node->GetId()];
719}
720
721void
723{
724 const Ptr<const Node> node = GetNodeFromContext(context);
725 ++m_nodeWifiMacRxDrop[node->GetId()];
726}
727
728void
730{
731 const Ptr<const Node> node = GetNodeFromContext(context);
732 ++m_nodeLrWpanMacTx[node->GetId()];
733}
734
735void
737{
738 const Ptr<const Node> node = GetNodeFromContext(context);
739 ++m_nodeLrWpanMacTxDrop[node->GetId()];
740}
741
742void
744{
745 const Ptr<const Node> node = GetNodeFromContext(context);
746 ++m_nodeLrWpanMacRx[node->GetId()];
747}
748
749void
751{
752 const Ptr<const Node> node = GetNodeFromContext(context);
753 ++m_nodeLrWpanMacRxDrop[node->GetId()];
754}
755
756void
759 Ptr<Ipv4> ipv4,
760 uint32_t interfaceIndex)
761{
762 const Ptr<const Node> node = GetNodeFromContext(context);
763 ++m_nodeIpv4Tx[node->GetId()];
764}
765
766void
769 Ptr<Ipv4> ipv4,
770 uint32_t interfaceIndex)
771{
772 const Ptr<const Node> node = GetNodeFromContext(context);
773 ++m_nodeIpv4Rx[node->GetId()];
774}
775
776void
778 const Ipv4Header& ipv4Header,
781 Ptr<Ipv4> ipv4,
782 uint32_t)
783{
784 const Ptr<const Node> node = GetNodeFromContext(context);
785 ++m_nodeIpv4Drop[node->GetId()];
786}
787
788void
790{
791 const Ptr<const Node> node = GetNodeFromContext(context);
792 ++m_nodeQueueEnqueue[node->GetId()];
793}
794
795void
797{
798 const Ptr<const Node> node = GetNodeFromContext(context);
799 ++m_nodeQueueDequeue[node->GetId()];
800}
801
802void
804{
805 const Ptr<const Node> node = GetNodeFromContext(context);
806 ++m_nodeQueueDrop[node->GetId()];
807}
808
809void
814 Time txTime,
815 Time rxTime)
816{
817 NS_LOG_FUNCTION(this);
819 NS_ASSERT(tx);
820 NS_ASSERT(rx);
821 Time now = Simulator::Now();
822 double fbTx = now.GetSeconds();
823 double lbTx = (now + txTime).GetSeconds();
824 double fbRx = (now + rxTime - txTime).GetSeconds();
825 double lbRx = (now + rxTime).GetSeconds();
827 WriteXmlP("p",
828 tx->GetNode()->GetId(),
829 fbTx,
830 lbTx,
831 rx->GetNode()->GetId(),
832 fbRx,
833 lbRx,
835}
836
837void
840 ProtocolType protocolType)
841{
842 NS_LOG_FUNCTION(this);
845 NS_ASSERT(ndev);
846 UpdatePosition(ndev);
847
848 ++gAnimUid;
850 << " GenericWirelessTxTrace for packet:" << gAnimUid);
852 AnimPacketInfo pktInfo(ndev, Simulator::Now());
853 AddPendingPacket(protocolType, gAnimUid, pktInfo);
854
856 if (netDevice)
857 {
858 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
859 std::ostringstream oss;
860 oss << nodeAddr;
861 Ptr<Node> n = netDevice->GetNode();
862 NS_ASSERT(n);
863 m_macToNodeIdMap[oss.str()] = n->GetId();
864 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
865 }
866 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
867 OutputWirelessPacketTxInfo(p, pendingPackets->at(gAnimUid), gAnimUid);
868}
869
870void
873 ProtocolType protocolType)
874{
875 NS_LOG_FUNCTION(this);
878 NS_ASSERT(ndev);
879 UpdatePosition(ndev);
880 uint64_t animUid = GetAnimUidFromPacket(p);
881 NS_LOG_INFO(ProtocolTypeToString(protocolType) << " for packet:" << animUid);
882 if (!IsPacketPending(animUid, protocolType))
883 {
884 NS_LOG_WARN(ProtocolTypeToString(protocolType) << " GenericWirelessRxTrace: unknown Uid");
885 return;
886 }
887 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
888 pendingPackets->at(animUid).ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
889 OutputWirelessPacketRxInfo(p, pendingPackets->at(animUid), animUid);
890}
891
892void
898
899void
905
906void
908 WifiConstPsduMap psduMap,
909 WifiTxVector /* txVector */,
910 double /* txPowerW */)
911{
912 NS_LOG_FUNCTION(this);
915 NS_ASSERT(ndev);
916 UpdatePosition(ndev);
917
918 AnimPacketInfo pktInfo(ndev, Simulator::Now());
920 for (auto& psdu : psduMap)
921 {
922 for (auto& mpdu : *PeekPointer(psdu.second))
923 {
924 ++gAnimUid;
925 NS_LOG_INFO("WifiPhyTxTrace for MPDU:" << gAnimUid);
927 mpdu->GetPacket()); // the underlying MSDU/A-MSDU should be handed off
928 AddPendingPacket(WIFI, gAnimUid, pktInfo);
930 mpdu->GetProtocolDataUnit(),
931 pendingPackets->at(gAnimUid),
932 gAnimUid); // PDU should be considered in order to have header
933 }
934 }
935
937 if (netDevice)
938 {
939 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
940 std::ostringstream oss;
941 oss << nodeAddr;
942 Ptr<Node> n = netDevice->GetNode();
943 NS_ASSERT(n);
944 m_macToNodeIdMap[oss.str()] = n->GetId();
945 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
946 }
947 else
948 {
949 NS_ABORT_MSG("This NetDevice should be a Wi-Fi network device");
950 }
951}
952
953void
957{
958 NS_LOG_FUNCTION(this);
961 NS_ASSERT(ndev);
962 UpdatePosition(ndev);
963 uint64_t animUid = GetAnimUidFromPacket(p);
964 NS_LOG_INFO("Wifi RxBeginTrace for packet: " << animUid);
966 {
967 NS_ASSERT_MSG(false, "WifiPhyRxBeginTrace: unknown Uid");
968 std::ostringstream oss;
969 WifiMacHeader hdr;
970 if (!p->PeekHeader(hdr))
971 {
972 NS_LOG_WARN("WifiMacHeader not present");
973 return;
974 }
975 oss << hdr.GetAddr2();
976 if (m_macToNodeIdMap.find(oss.str()) == m_macToNodeIdMap.end())
977 {
978 NS_LOG_WARN("Transmitter Mac address " << oss.str() << " never seen before. Skipping");
979 return;
980 }
981 Ptr<Node> txNode = NodeList::GetNode(m_macToNodeIdMap[oss.str()]);
982 UpdatePosition(txNode);
983 AnimPacketInfo pktInfo(nullptr, Simulator::Now(), m_macToNodeIdMap[oss.str()]);
985 NS_LOG_WARN("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
986 }
987 /// \todo NS_ASSERT (WifiPacketIsPending (animUid) == true);
988 m_pendingWifiPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
990}
991
992void
994{
995 NS_LOG_FUNCTION(this);
997
999 NS_ASSERT(ndev);
1001
1002 Ptr<Node> n = ndev->GetNode();
1003 NS_ASSERT(n);
1004
1005 UpdatePosition(n);
1006
1008 if (!p->PeekHeader(hdr))
1009 {
1010 NS_LOG_WARN("LrWpanMacHeader not present");
1011 return;
1012 }
1013
1014 std::ostringstream oss;
1015 if (hdr.GetSrcAddrMode() == 2)
1016 {
1017 Mac16Address nodeAddr = netDevice->GetMac()->GetShortAddress();
1018 oss << nodeAddr;
1019 }
1020 else if (hdr.GetSrcAddrMode() == 3)
1021 {
1022 Mac64Address nodeAddr = netDevice->GetMac()->GetExtendedAddress();
1023 oss << nodeAddr;
1024 }
1025 else
1026 {
1027 NS_LOG_WARN("LrWpanMacHeader without source address");
1028 return;
1029 }
1030 m_macToNodeIdMap[oss.str()] = n->GetId();
1031 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
1032
1033 ++gAnimUid;
1034 NS_LOG_INFO("LrWpan TxBeginTrace for packet:" << gAnimUid);
1035 AddByteTag(gAnimUid, p);
1036
1037 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1039
1041}
1042
1043void
1045{
1046 NS_LOG_FUNCTION(this);
1049 NS_ASSERT(ndev);
1050 Ptr<Node> n = ndev->GetNode();
1051 NS_ASSERT(n);
1052
1053 AnimByteTag tag;
1054 if (!p->FindFirstMatchingByteTag(tag))
1055 {
1056 return;
1057 }
1058
1059 uint64_t animUid = GetAnimUidFromPacket(p);
1060 NS_LOG_INFO("LrWpan RxBeginTrace for packet:" << animUid);
1062 {
1063 NS_LOG_WARN("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
1064 }
1065
1066 UpdatePosition(n);
1067 m_pendingLrWpanPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1069}
1070
1071void
1073{
1074 NS_LOG_FUNCTION(this);
1076}
1077
1078void
1080{
1081 NS_LOG_FUNCTION(this);
1083}
1084
1085void
1087{
1088 NS_LOG_FUNCTION(this);
1090}
1091
1092void
1094{
1095 NS_LOG_FUNCTION(this);
1097}
1098
1099void
1101{
1102 NS_LOG_FUNCTION(this);
1104 if (!pb)
1105 {
1106 NS_LOG_WARN("pb == 0. Not yet supported");
1107 return;
1108 }
1109 context = "/" + context;
1111 NS_ASSERT(ndev);
1112 UpdatePosition(ndev);
1113
1114 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1115 for (auto i = pbList.begin(); i != pbList.end(); ++i)
1116 {
1117 Ptr<Packet> p = *i;
1118 ++gAnimUid;
1119 NS_LOG_INFO("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1120 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1121 AddByteTag(gAnimUid, p);
1124 }
1125}
1126
1127void
1129{
1130 NS_LOG_FUNCTION(this);
1132 if (!pb)
1133 {
1134 NS_LOG_WARN("pb == 0. Not yet supported");
1135 return;
1136 }
1137 context = "/" + context;
1139 NS_ASSERT(ndev);
1140 UpdatePosition(ndev);
1141
1142 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1143 for (auto i = pbList.begin(); i != pbList.end(); ++i)
1144 {
1145 Ptr<Packet> p = *i;
1146 uint64_t animUid = GetAnimUidFromPacket(p);
1147 NS_LOG_INFO("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1149 {
1150 NS_LOG_WARN("LteSpectrumPhyRxTrace: unknown Uid");
1151 return;
1152 }
1153 AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1154 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1155 OutputWirelessPacketRxInfo(p, pktInfo, animUid);
1156 }
1157}
1158
1159void
1161{
1162 NS_LOG_FUNCTION(this);
1165 NS_ASSERT(ndev);
1166 UpdatePosition(ndev);
1167 ++gAnimUid;
1168 NS_LOG_INFO("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1169 AddByteTag(gAnimUid, p);
1170 UpdatePosition(ndev);
1171 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1173}
1174
1175void
1177{
1178 NS_LOG_FUNCTION(this);
1181 NS_ASSERT(ndev);
1182 UpdatePosition(ndev);
1183 uint64_t animUid = GetAnimUidFromPacket(p);
1184 NS_LOG_INFO("CsmaPhyTxEndTrace for packet:" << animUid);
1186 {
1187 NS_LOG_WARN("CsmaPhyTxEndTrace: unknown Uid");
1188 NS_FATAL_ERROR("CsmaPhyTxEndTrace: unknown Uid");
1189 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1190 AddPendingPacket(AnimationInterface::CSMA, animUid, pktInfo);
1191 NS_LOG_WARN("Unknown Uid, but adding Csma Packet anyway");
1192 }
1193 /// \todo NS_ASSERT (IsPacketPending (AnimUid) == true);
1194 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1195 pktInfo.m_lbTx = Simulator::Now().GetSeconds();
1196}
1197
1198void
1200{
1201 NS_LOG_FUNCTION(this);
1204 NS_ASSERT(ndev);
1205 UpdatePosition(ndev);
1206 uint64_t animUid = GetAnimUidFromPacket(p);
1208 {
1209 NS_LOG_WARN("CsmaPhyRxEndTrace: unknown Uid");
1210 return;
1211 }
1212 /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1213 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1214 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1215 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid);
1216 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1217 OutputCsmaPacket(p, pktInfo);
1218}
1219
1220void
1222{
1223 NS_LOG_FUNCTION(this);
1226 NS_ASSERT(ndev);
1227 uint64_t animUid = GetAnimUidFromPacket(p);
1229 {
1230 NS_LOG_WARN("CsmaMacRxTrace: unknown Uid");
1231 return;
1232 }
1233 /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1234 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1235 NS_LOG_INFO("MacRxTrace for packet:" << animUid << " complete");
1236 OutputCsmaPacket(p, pktInfo);
1237}
1238
1239void
1241 AnimPacketInfo& pktInfo,
1242 uint64_t animUid)
1243{
1245 uint32_t nodeId = 0;
1246 if (pktInfo.m_txnd)
1247 {
1248 nodeId = pktInfo.m_txnd->GetNode()->GetId();
1249 }
1250 else
1251 {
1252 nodeId = pktInfo.m_txNodeId;
1253 }
1254 WriteXmlPRef(animUid,
1255 nodeId,
1256 pktInfo.m_fbTx,
1258}
1259
1260void
1262 AnimPacketInfo& pktInfo,
1263 uint64_t animUid)
1264{
1266 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1267 WriteXmlP(animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1268}
1269
1270void
1272{
1274 NS_ASSERT(pktInfo.m_txnd);
1275 uint32_t nodeId = pktInfo.m_txnd->GetNode()->GetId();
1276 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1277
1278 WriteXmlP("p",
1279 nodeId,
1280 pktInfo.m_fbTx,
1281 pktInfo.m_lbTx,
1282 rxId,
1283 pktInfo.m_fbRx,
1284 pktInfo.m_lbRx,
1286}
1287
1288void
1290 uint64_t animUid,
1291 AnimPacketInfo pktInfo)
1292{
1293 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1294 NS_ASSERT(pendingPackets);
1295 pendingPackets->insert(AnimUidPacketInfoMap::value_type(animUid, pktInfo));
1296}
1297
1298bool
1300{
1301 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1302 NS_ASSERT(pendingPackets);
1303 return (pendingPackets->find(animUid) != pendingPackets->end());
1304}
1305
1306void
1308{
1309 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1310 NS_ASSERT(pendingPackets);
1311 if (pendingPackets->empty())
1312 {
1313 return;
1314 }
1315 std::vector<uint64_t> purgeList;
1316 for (auto i = pendingPackets->begin(); i != pendingPackets->end(); ++i)
1317 {
1318 AnimPacketInfo pktInfo = i->second;
1319 double delta = (Simulator::Now().GetSeconds() - pktInfo.m_fbTx);
1320 if (delta > PURGE_INTERVAL)
1321 {
1322 purgeList.push_back(i->first);
1323 }
1324 }
1325 for (auto i = purgeList.begin(); i != purgeList.end(); ++i)
1326 {
1327 pendingPackets->erase(*i);
1328 }
1329}
1330
1333{
1334 AnimUidPacketInfoMap* pendingPackets = nullptr;
1335 switch (protocolType)
1336 {
1338 pendingPackets = &m_pendingWifiPackets;
1339 break;
1340 }
1342 pendingPackets = &m_pendingUanPackets;
1343 break;
1344 }
1346 pendingPackets = &m_pendingCsmaPackets;
1347 break;
1348 }
1350 pendingPackets = &m_pendingWimaxPackets;
1351 break;
1352 }
1354 pendingPackets = &m_pendingLtePackets;
1355 break;
1356 }
1358 pendingPackets = &m_pendingLrWpanPackets;
1359 break;
1360 }
1361 }
1362 return pendingPackets;
1363}
1364
1365std::string
1367{
1368 std::string result = "Unknown";
1369 switch (protocolType)
1370 {
1372 result = "WIFI";
1373 break;
1374 }
1376 result = "UAN";
1377 break;
1378 }
1380 result = "CSMA";
1381 break;
1382 }
1384 result = "WIMAX";
1385 break;
1386 }
1388 result = "LTE";
1389 break;
1390 }
1392 result = "LRWPAN";
1393 break;
1394 }
1395 }
1396 return result;
1397}
1398
1399// Counters
1400
1401std::string
1403{
1404 std::string typeString = "unknown";
1405 switch (counterType)
1406 {
1407 case UINT32_COUNTER: {
1408 typeString = "UINT32";
1409 break;
1410 }
1411 case DOUBLE_COUNTER: {
1412 typeString = "DOUBLE";
1413 break;
1414 }
1415 }
1416 return typeString;
1417}
1418
1419// General
1420
1421std::string
1423{
1424 std::ostringstream oss;
1425 p->Print(oss);
1426 return oss.str();
1427}
1428
1429uint64_t
1434
1435void
1437{
1438 m_started = false;
1439 NS_LOG_INFO("Stopping Animation");
1441 if (m_f)
1442 {
1443 // Terminate the anim element
1444 WriteXmlClose("anim");
1445 std::fclose(m_f);
1446 m_f = nullptr;
1447 }
1448 if (onlyAnimation)
1449 {
1450 return;
1451 }
1452 if (m_routingF)
1453 {
1454 WriteXmlClose("anim", true);
1455 std::fclose(m_routingF);
1456 m_routingF = nullptr;
1457 }
1458}
1459
1460void
1480
1481void
1483{
1484 m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1485 m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address));
1486}
1487
1488void
1489AnimationInterface::AddToIpv4AddressNodeIdTable(std::vector<std::string> ipv4Addresses,
1490 uint32_t nodeId)
1491{
1492 for (auto i = ipv4Addresses.begin(); i != ipv4Addresses.end(); ++i)
1493 {
1494 AddToIpv4AddressNodeIdTable(*i, nodeId);
1495 }
1496}
1497
1498void
1500{
1501 m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1502 m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address));
1503}
1504
1505void
1506AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector<std::string> ipv6Addresses,
1507 uint32_t nodeId)
1508{
1509 for (auto i = ipv6Addresses.begin(); i != ipv6Addresses.end(); ++i)
1510 {
1511 AddToIpv6AddressNodeIdTable(*i, nodeId);
1512 }
1513}
1514
1515// Callbacks
1516void
1518{
1519 Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy();
1520 Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy();
1521 Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy();
1522 std::ostringstream oss;
1523 // NodeList/*/DeviceList/*/
1524 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1525 if (dlPhy)
1526 {
1527 dlPhy->TraceConnect("TxStart",
1528 oss.str(),
1530 dlPhy->TraceConnect("RxStart",
1531 oss.str(),
1533 }
1534 if (ulPhy)
1535 {
1536 ulPhy->TraceConnect("TxStart",
1537 oss.str(),
1539 ulPhy->TraceConnect("RxStart",
1540 oss.str(),
1542 }
1543}
1544
1545void
1547{
1548 Ptr<LteUePhy> lteUePhy = nd->GetPhy();
1549 Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy();
1550 Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy();
1551 std::ostringstream oss;
1552 // NodeList/*/DeviceList/*/
1553 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1554 if (dlPhy)
1555 {
1556 dlPhy->TraceConnect("TxStart",
1557 oss.str(),
1559 dlPhy->TraceConnect("RxStart",
1560 oss.str(),
1562 }
1563 if (ulPhy)
1564 {
1565 ulPhy->TraceConnect("TxStart",
1566 oss.str(),
1568 ulPhy->TraceConnect("RxStart",
1569 oss.str(),
1571 }
1572}
1573
1574void
1576{
1577 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1578 {
1579 Ptr<Node> n = *i;
1580 NS_ASSERT(n);
1581 uint32_t nDevices = n->GetNDevices();
1582 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1583 {
1584 Ptr<NetDevice> nd = n->GetDevice(devIndex);
1585 if (!nd)
1586 {
1587 continue;
1588 }
1590 if (lteUeNetDevice)
1591 {
1592 ConnectLteUe(n, lteUeNetDevice, devIndex);
1593 continue;
1594 }
1596 if (lteEnbNetDevice)
1597 {
1598 ConnectLteEnb(n, lteEnbNetDevice, devIndex);
1599 }
1600 }
1601 }
1602}
1603
1604void
1606{
1607 // Connect the callbacks
1608 Config::ConnectFailSafe("/ChannelList/*/TxRxPointToPoint",
1610 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
1612 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1615 "/NodeList/*/$ns3::MobilityModel/CourseChange",
1617 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1619 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1621 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1623 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1625 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1627 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1629 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1631 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1633 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1635 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1637 Config::ConnectFailSafe("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1639
1640 ConnectLte();
1641
1642 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1644 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1646 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1648
1649 // Queue Enqueues
1650
1651 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1653 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1655 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1657
1658 // Queue Dequeues
1659
1660 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1662 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1664 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1666
1667 // Queue Drops
1668
1669 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1671 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1673 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1675
1676 // Wifi Mac
1677 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1679 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1681 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1683 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1685
1686 // Wifi Phy
1687 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1689 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1691
1692 // LrWpan
1693 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin",
1695 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin",
1697 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx",
1699 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop",
1701 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx",
1703 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop",
1705}
1706
1707Vector
1709{
1710 Ptr<MobilityModel> loc = n->GetObject<MobilityModel>();
1711 if (loc)
1712 {
1713 m_nodeLocation[n->GetId()] = loc->GetPosition();
1714 }
1715 else
1716 {
1718 "AnimationInterface WARNING:Node:"
1719 << n->GetId()
1720 << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1722 x->SetAttribute("Min", DoubleValue(0));
1723 x->SetAttribute("Max", DoubleValue(100));
1725 y->SetAttribute("Min", DoubleValue(0));
1726 y->SetAttribute("Max", DoubleValue(100));
1727 m_nodeLocation[n->GetId()] = Vector(int(x->GetValue()), int(y->GetValue()), 0);
1728 }
1729 return m_nodeLocation[n->GetId()];
1730}
1731
1732Vector
1734{
1735 m_nodeLocation[n->GetId()] = v;
1736 return v;
1737}
1738
1739Vector
1741{
1742 Ptr<Node> n = ndev->GetNode();
1743 NS_ASSERT(n);
1744 return UpdatePosition(n);
1745}
1746
1747Vector
1749{
1750 if (m_nodeLocation.find(n->GetId()) == m_nodeLocation.end())
1751 {
1752 NS_FATAL_ERROR("Node:" << n->GetId() << " not found in Location table");
1753 }
1754 return m_nodeLocation[n->GetId()];
1755}
1756
1757std::string
1759{
1760 Address nodeAddr = nd->GetAddress();
1761 std::ostringstream oss;
1762 oss << nodeAddr;
1763 return oss.str().substr(6); // Skip the first 6 chars to get the Mac
1764}
1765
1766std::string
1768{
1769 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1770 if (!ipv4)
1771 {
1772 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1773 return "0.0.0.0";
1774 }
1775 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1776 if (ifIndex == -1)
1777 {
1778 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1779 return "0.0.0.0";
1780 }
1781 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, 0);
1782 std::ostringstream oss;
1783 oss << addr.GetLocal();
1784 return oss.str();
1785}
1786
1787std::string
1789{
1790 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1791 if (!ipv6)
1792 {
1793 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1794 return "::";
1795 }
1796 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1797 if (ifIndex == -1)
1798 {
1799 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1800 return "::";
1801 }
1802 bool nonLinkLocalFound = false;
1803 uint32_t nAddresses = ipv6->GetNAddresses(ifIndex);
1805 for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1806 {
1807 addr = ipv6->GetAddress(ifIndex, addressIndex);
1808 if (!addr.GetAddress().IsLinkLocal())
1809 {
1810 nonLinkLocalFound = true;
1811 break;
1812 }
1813 }
1814 if (!nonLinkLocalFound)
1815 {
1816 addr = ipv6->GetAddress(ifIndex, 0);
1817 }
1818 std::ostringstream oss;
1819 oss << addr.GetAddress();
1820 return oss.str();
1821}
1822
1823std::vector<std::string>
1825{
1826 std::vector<std::string> ipv4Addresses;
1827 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1828 if (!ipv4)
1829 {
1830 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1831 return ipv4Addresses;
1832 }
1833 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1834 if (ifIndex == -1)
1835 {
1836 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1837 return ipv4Addresses;
1838 }
1839 for (uint32_t index = 0; index < ipv4->GetNAddresses(ifIndex); ++index)
1840 {
1841 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, index);
1842 std::ostringstream oss;
1843 oss << addr.GetLocal();
1844 ipv4Addresses.push_back(oss.str());
1845 }
1846 return ipv4Addresses;
1847}
1848
1849std::vector<std::string>
1851{
1852 std::vector<std::string> ipv6Addresses;
1853 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1854 if (!ipv6)
1855 {
1856 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv6 object found");
1857 return ipv6Addresses;
1858 }
1859 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1860 if (ifIndex == -1)
1861 {
1862 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1863 return ipv6Addresses;
1864 }
1865 for (uint32_t index = 0; index < ipv6->GetNAddresses(ifIndex); ++index)
1866 {
1867 Ipv6InterfaceAddress addr = ipv6->GetAddress(ifIndex, index);
1868 std::ostringstream oss;
1869 oss << addr.GetAddress();
1870 ipv6Addresses.push_back(oss.str());
1871 }
1872 return ipv6Addresses;
1873}
1874
1875void
1877{
1878 for (auto i = m_nodeIdIpv4Map.begin(); i != m_nodeIdIpv4Map.end(); ++i)
1879 {
1880 std::vector<std::string> ipv4Addresses;
1881 auto iterPair = m_nodeIdIpv4Map.equal_range(i->first);
1882 for (auto it = iterPair.first; it != iterPair.second; ++it)
1883 {
1884 ipv4Addresses.push_back(it->second);
1885 }
1886 WriteXmlIpv4Addresses(i->first, ipv4Addresses);
1887 }
1888}
1889
1890void
1892{
1893 for (auto i = m_nodeIdIpv6Map.begin(); i != m_nodeIdIpv6Map.end();
1894 i = m_nodeIdIpv6Map.upper_bound(i->first))
1895 {
1896 std::vector<std::string> ipv6Addresses;
1897 auto iterPair = m_nodeIdIpv6Map.equal_range(i->first);
1898 for (auto it = iterPair.first; it != iterPair.second; ++it)
1899 {
1900 ipv6Addresses.push_back(it->second);
1901 }
1902 WriteXmlIpv6Addresses(i->first, ipv6Addresses);
1903 }
1904}
1905
1906void
1908{
1909 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1910 {
1911 Ptr<Node> n = *i;
1912 UpdatePosition(n);
1913 uint32_t n1Id = n->GetId();
1914 uint32_t nDev = n->GetNDevices(); // Number of devices
1915 for (uint32_t i = 0; i < nDev; ++i)
1916 {
1917 Ptr<NetDevice> dev = n->GetDevice(i);
1918 NS_ASSERT(dev);
1919 Ptr<Channel> ch = dev->GetChannel();
1920 std::string channelType = "Unknown channel";
1921 if (ch)
1922 {
1923 channelType = ch->GetInstanceTypeId().GetName();
1924 }
1925 NS_LOG_DEBUG("Got ChannelType" << channelType);
1926
1927 if (!ch || (channelType != "ns3::PointToPointChannel"))
1928 {
1929 NS_LOG_DEBUG("No channel can't be a p2p device");
1930 /*
1931 // Try to see if it is an LTE NetDevice, which does not return a channel
1932 if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1933 (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1934 (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1935 {
1936 WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" +
1937 GetMacAddress (dev), channelType); AddToIpv4AddressNodeIdTable (GetIpv4Address
1938 (dev), n->GetId ());
1939 }
1940 */
1941 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1942 AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId());
1943 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1944 AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId());
1945 if (!ipv4Addresses.empty())
1946 {
1947 NS_LOG_INFO("Writing Ipv4 link");
1948 WriteNonP2pLinkProperties(n->GetId(),
1949 GetIpv4Address(dev) + "~" + GetMacAddress(dev),
1950 channelType);
1951 }
1952 else if (!ipv6Addresses.empty())
1953 {
1954 NS_LOG_INFO("Writing Ipv6 link");
1955 WriteNonP2pLinkProperties(n->GetId(),
1956 GetIpv6Address(dev) + "~" + GetMacAddress(dev),
1957 channelType);
1958 }
1959 continue;
1960 }
1961
1962 else if (channelType == "ns3::PointToPointChannel")
1963 { // Since these are duplex links, we only need to dump
1964 // if srcid < dstid
1965 std::size_t nChDev = ch->GetNDevices();
1966 for (std::size_t j = 0; j < nChDev; ++j)
1967 {
1968 Ptr<NetDevice> chDev = ch->GetDevice(j);
1969 uint32_t n2Id = chDev->GetNode()->GetId();
1970 if (n1Id < n2Id)
1971 {
1972 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1973 AddToIpv4AddressNodeIdTable(ipv4Addresses, n1Id);
1974 ipv4Addresses = GetIpv4Addresses(chDev);
1975 AddToIpv4AddressNodeIdTable(ipv4Addresses, n2Id);
1976 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1977 AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id);
1978 ipv6Addresses = GetIpv6Addresses(chDev);
1979 AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id);
1980
1981 P2pLinkNodeIdPair p2pPair;
1982 p2pPair.fromNode = n1Id;
1983 p2pPair.toNode = n2Id;
1984 if (!ipv4Addresses.empty())
1985 {
1986 LinkProperties lp = {GetIpv4Address(dev) + "~" + GetMacAddress(dev),
1987 GetIpv4Address(chDev) + "~" + GetMacAddress(chDev),
1988 ""};
1989 m_linkProperties[p2pPair] = lp;
1990 }
1991 else if (!ipv6Addresses.empty())
1992 {
1993 LinkProperties lp = {GetIpv6Address(dev) + "~" + GetMacAddress(dev),
1994 GetIpv6Address(chDev) + "~" + GetMacAddress(chDev),
1995 ""};
1996 m_linkProperties[p2pPair] = lp;
1997 }
1998 WriteXmlLink(n1Id, 0, n2Id);
1999 }
2000 }
2001 }
2002 }
2003 }
2004 m_linkProperties.clear();
2005}
2006
2007void
2009{
2010 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2011 {
2012 Ptr<Node> n = *i;
2013 NS_LOG_INFO("Update Position for Node: " << n->GetId());
2014 Vector v = UpdatePosition(n);
2015 WriteXmlNode(n->GetId(), n->GetSystemId(), v.x, v.y);
2016 }
2017}
2018
2019void
2021{
2022 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2023 {
2024 Ptr<Node> n = *i;
2025 Rgb rgb = {255, 0, 0};
2026 if (m_nodeColors.find(n->GetId()) == m_nodeColors.end())
2027 {
2028 m_nodeColors[n->GetId()] = rgb;
2029 }
2030 UpdateNodeColor(n, rgb.r, rgb.g, rgb.b);
2031 }
2032}
2033
2034void
2036{
2037 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2038 {
2039 Ptr<Node> n = *i;
2040 NS_LOG_INFO("Update Size for Node: " << n->GetId());
2042 m_nodeSizes[n->GetId()] = s;
2043 UpdateNodeSize(n->GetId(), s.width, s.height);
2044 }
2045}
2046
2047void
2049{
2052 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2053 {
2054 Ptr<Node> n = *i;
2056 {
2058 }
2059 }
2060}
2061
2062bool
2067
2068void
2069AnimationInterface::SetOutputFile(const std::string& fn, bool routing)
2070{
2071 if (!routing && m_f)
2072 {
2073 return;
2074 }
2075 if (routing && m_routingF)
2076 {
2077 NS_FATAL_ERROR("SetRoutingOutputFile already used once");
2078 return;
2079 }
2080
2081 NS_LOG_INFO("Creating new trace file:" << fn);
2082 FILE* f = nullptr;
2083 f = std::fopen(fn.c_str(), "w");
2084 if (!f)
2085 {
2086 NS_FATAL_ERROR("Unable to open output file:" << fn);
2087 return; // Can't open output file
2088 }
2089 if (routing)
2090 {
2091 m_routingF = f;
2092 m_routingFileName = fn;
2093 }
2094 else
2095 {
2096 m_f = f;
2097 m_outputFileName = fn;
2098 }
2099}
2100
2101void
2103{
2104 // Start a new trace file if the current packet count exceeded max packets per file
2107 {
2108 return;
2109 }
2110 NS_LOG_UNCOND("Max Packets per trace file exceeded");
2111 StopAnimation(true);
2112}
2113
2114std::string
2119
2120void
2122{
2124 {
2125 NS_LOG_INFO("TrackQueueCounters Completed");
2126 return;
2127 }
2128 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2129 {
2130 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2134 }
2136}
2137
2138void
2140{
2142 {
2143 NS_LOG_INFO("TrackWifiMacCounters Completed");
2144 return;
2145 }
2146 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2147 {
2148 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2153 }
2156 this);
2157}
2158
2159void
2161{
2163 {
2164 NS_LOG_INFO("TrackWifiPhyCounters Completed");
2165 return;
2166 }
2167 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2168 {
2169 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2172 }
2175 this);
2176}
2177
2178void
2180{
2182 {
2183 NS_LOG_INFO("TrackIpv4L3ProtocolCounters Completed");
2184 return;
2185 }
2186 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2187 {
2188 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2192 }
2195 this);
2196}
2197
2198/***** Routing-related *****/
2199
2200void
2202{
2203 if (m_ipv4RouteTrackElements.empty())
2204 {
2205 return;
2206 }
2207 for (auto i = m_ipv4RouteTrackElements.begin(); i != m_ipv4RouteTrackElements.end(); ++i)
2208 {
2209 Ipv4RouteTrackElement trackElement = *i;
2210 Ptr<Node> fromNode = NodeList::GetNode(trackElement.fromNodeId);
2211 if (!fromNode)
2212 {
2213 NS_FATAL_ERROR("Node: " << trackElement.fromNodeId << " Not found");
2214 continue;
2215 }
2216 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2217 if (!ipv4)
2218 {
2219 NS_LOG_WARN("ipv4 object not found");
2220 continue;
2221 }
2222 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2223 if (!rp)
2224 {
2225 NS_LOG_WARN("Routing protocol object not found");
2226 continue;
2227 }
2228 NS_LOG_INFO("Begin Track Route for: " << trackElement.destination
2229 << " From:" << trackElement.fromNodeId);
2231 Ipv4Header header;
2232 header.SetDestination(Ipv4Address(trackElement.destination.c_str()));
2233 Socket::SocketErrno sockerr;
2234 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2235 Ipv4RoutePathElements rpElements;
2236 if (!rt)
2237 {
2238 NS_LOG_INFO("No route to :" << trackElement.destination);
2239 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2240 rpElements.push_back(elem);
2241 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2242 continue;
2243 }
2244 std::ostringstream oss;
2245 oss << rt->GetGateway();
2246 NS_LOG_INFO("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway());
2247 if (rt->GetGateway() == "0.0.0.0")
2248 {
2249 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "C"};
2250 rpElements.push_back(elem);
2251 if (m_ipv4ToNodeIdMap.find(trackElement.destination) != m_ipv4ToNodeIdMap.end())
2252 {
2253 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[trackElement.destination], "L"};
2254 rpElements.push_back(elem2);
2255 }
2256 }
2257 else if (rt->GetGateway() == "127.0.0.1")
2258 {
2259 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2260 rpElements.push_back(elem);
2261 }
2262 else
2263 {
2264 Ipv4RoutePathElement elem = {trackElement.fromNodeId, oss.str()};
2265 rpElements.push_back(elem);
2266 }
2267 RecursiveIpv4RoutePathSearch(oss.str(), trackElement.destination, rpElements);
2268 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2269 }
2270}
2271
2272void
2274{
2276 {
2277 NS_LOG_INFO("TrackIpv4Route completed");
2278 return;
2279 }
2280 if (m_routingNc.GetN())
2281 {
2282 for (auto i = m_routingNc.Begin(); i != m_routingNc.End(); ++i)
2283 {
2284 Ptr<Node> n = *i;
2285 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2286 }
2287 }
2288 else
2289 {
2290 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2291 {
2292 Ptr<Node> n = *i;
2293 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2294 }
2295 }
2298}
2299
2300std::string
2302{
2303 NS_ASSERT(n);
2304 Ptr<ns3::Ipv4> ipv4 = n->GetObject<ns3::Ipv4>();
2305 if (!ipv4)
2306 {
2307 NS_LOG_WARN("Node " << n->GetId() << " Does not have an Ipv4 object");
2308 return "";
2309 }
2310 std::stringstream stream;
2312 ipv4->GetRoutingProtocol()->PrintRoutingTable(routingstream);
2313 return stream.str();
2314}
2315
2316void
2318 std::string to,
2319 Ipv4RoutePathElements& rpElements)
2320{
2321 NS_LOG_INFO("RecursiveIpv4RoutePathSearch from:" << from << " to:" << to);
2322 if (from == "0.0.0.0" || from == "127.0.0.1")
2323 {
2324 NS_LOG_INFO("Got " << from << " End recursion");
2325 return;
2326 }
2329 if (fromNode->GetId() == toNode->GetId())
2330 {
2331 Ipv4RoutePathElement elem = {fromNode->GetId(), "L"};
2332 rpElements.push_back(elem);
2333 return;
2334 }
2335 if (!fromNode)
2336 {
2337 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2338 return;
2339 }
2340 if (!toNode)
2341 {
2342 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2343 return;
2344 }
2345 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2346 if (!ipv4)
2347 {
2348 NS_LOG_WARN("ipv4 object not found");
2349 return;
2350 }
2351 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2352 if (!rp)
2353 {
2354 NS_LOG_WARN("Routing protocol object not found");
2355 return;
2356 }
2358 Ipv4Header header;
2359 header.SetDestination(Ipv4Address(to.c_str()));
2360 Socket::SocketErrno sockerr;
2361 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2362 if (!rt)
2363 {
2364 return;
2365 }
2366 NS_LOG_DEBUG("Node: " << fromNode->GetId() << " G:" << rt->GetGateway());
2367 std::ostringstream oss;
2368 oss << rt->GetGateway();
2369 if (oss.str() == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2370 {
2371 NS_LOG_INFO("Null gw");
2372 Ipv4RoutePathElement elem = {fromNode->GetId(), "C"};
2373 rpElements.push_back(elem);
2374 if (m_ipv4ToNodeIdMap.find(to) != m_ipv4ToNodeIdMap.end())
2375 {
2376 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[to], "L"};
2377 rpElements.push_back(elem2);
2378 }
2379 return;
2380 }
2381 NS_LOG_INFO("Node:" << fromNode->GetId() << "-->" << rt->GetGateway());
2382 Ipv4RoutePathElement elem = {fromNode->GetId(), oss.str()};
2383 rpElements.push_back(elem);
2384 RecursiveIpv4RoutePathSearch(oss.str(), to, rpElements);
2385}
2386
2387/***** WriteXml *****/
2388
2389void
2391{
2392 AnimXmlElement element("anim");
2393 element.AddAttribute("ver", GetNetAnimVersion());
2394 FILE* f = m_f;
2395 if (!routing)
2396 {
2397 element.AddAttribute("filetype", "animation");
2398 }
2399 else
2400 {
2401 element.AddAttribute("filetype", "routing");
2402 f = m_routingF;
2403 }
2404 WriteN(element.ToString(false) + ">\n", f);
2405}
2406
2407void
2408AnimationInterface::WriteXmlClose(std::string name, bool routing)
2409{
2410 std::string closeString = "</" + name + ">\n";
2411 if (!routing)
2412 {
2413 WriteN(closeString, m_f);
2414 }
2415 else
2416 {
2417 WriteN(closeString, m_routingF);
2418 }
2419}
2420
2421void
2422AnimationInterface::WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
2423{
2424 AnimXmlElement element("node");
2425 element.AddAttribute("id", id);
2426 element.AddAttribute("sysId", sysId);
2427 element.AddAttribute("locX", locX);
2428 element.AddAttribute("locY", locY);
2429 WriteN(element.ToString(), m_f);
2430}
2431
2432void
2433AnimationInterface::WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string linkDescription)
2434{
2435 AnimXmlElement element("linkupdate");
2436 element.AddAttribute("t", Simulator::Now().GetSeconds());
2437 element.AddAttribute("fromId", fromId);
2438 element.AddAttribute("toId", toId);
2439 element.AddAttribute("ld", linkDescription, true);
2440 WriteN(element.ToString(), m_f);
2441}
2442
2443void
2445{
2446 AnimXmlElement element("link");
2447 element.AddAttribute("fromId", fromId);
2448 element.AddAttribute("toId", toId);
2449
2450 LinkProperties lprop;
2451 lprop.fromNodeDescription = "";
2452 lprop.toNodeDescription = "";
2453 lprop.linkDescription = "";
2454
2455 P2pLinkNodeIdPair p1 = {fromId, toId};
2456 P2pLinkNodeIdPair p2 = {toId, fromId};
2457 if (m_linkProperties.find(p1) != m_linkProperties.end())
2458 {
2459 lprop = m_linkProperties[p1];
2460 }
2461 else if (m_linkProperties.find(p2) != m_linkProperties.end())
2462 {
2463 lprop = m_linkProperties[p2];
2464 }
2465
2466 element.AddAttribute("fd", lprop.fromNodeDescription, true);
2467 element.AddAttribute("td", lprop.toNodeDescription, true);
2468 element.AddAttribute("ld", lprop.linkDescription, true);
2469 WriteN(element.ToString(), m_f);
2470}
2471
2472void
2473AnimationInterface::WriteXmlIpv4Addresses(uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2474{
2475 AnimXmlElement element("ip");
2476 element.AddAttribute("n", nodeId);
2477 for (auto i = ipv4Addresses.begin(); i != ipv4Addresses.end(); ++i)
2478 {
2479 AnimXmlElement valueElement("address");
2480 valueElement.SetText(*i);
2481 element.AppendChild(valueElement);
2482 }
2483 WriteN(element.ToString(), m_f);
2484}
2485
2486void
2487AnimationInterface::WriteXmlIpv6Addresses(uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2488{
2489 AnimXmlElement element("ipv6");
2490 element.AddAttribute("n", nodeId);
2491 for (auto i = ipv6Addresses.begin(); i != ipv6Addresses.end(); ++i)
2492 {
2493 AnimXmlElement valueElement("address");
2494 valueElement.SetText(*i);
2495 element.AppendChild(valueElement);
2496 }
2497 WriteN(element.ToString(), m_f);
2498}
2499
2500void
2501AnimationInterface::WriteXmlRouting(uint32_t nodeId, std::string routingInfo)
2502{
2503 AnimXmlElement element("rt");
2504 element.AddAttribute("t", Simulator::Now().GetSeconds());
2505 element.AddAttribute("id", nodeId);
2506 element.AddAttribute("info", routingInfo.c_str(), true);
2507 WriteN(element.ToString(), m_routingF);
2508}
2509
2510void
2512 std::string destination,
2513 Ipv4RoutePathElements rpElements)
2514{
2515 std::string tagName = "rp";
2516 AnimXmlElement element(tagName, false);
2517 element.AddAttribute("t", Simulator::Now().GetSeconds());
2518 element.AddAttribute("id", nodeId);
2519 element.AddAttribute("d", destination.c_str());
2520 element.AddAttribute("c", rpElements.size());
2521 for (auto i = rpElements.begin(); i != rpElements.end(); ++i)
2522 {
2523 Ipv4RoutePathElement rpElement = *i;
2524 AnimXmlElement rpeElement("rpe");
2525 rpeElement.AddAttribute("n", rpElement.nodeId);
2526 rpeElement.AddAttribute("nH", rpElement.nextHop.c_str());
2527 element.AppendChild(rpeElement);
2528 }
2529 WriteN(element.ToString(), m_routingF);
2530}
2531
2532void
2533AnimationInterface::WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2534{
2535 AnimXmlElement element("pr");
2536 element.AddAttribute("uId", animUid);
2537 element.AddAttribute("fId", fId);
2538 element.AddAttribute("fbTx", fbTx);
2539 if (!metaInfo.empty())
2540 {
2541 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2542 }
2543 WriteN(element.ToString(), m_f);
2544}
2545
2546void
2548 std::string pktType,
2549 uint32_t tId,
2550 double fbRx,
2551 double lbRx)
2552{
2553 AnimXmlElement element(pktType);
2554 element.AddAttribute("uId", animUid);
2555 element.AddAttribute("tId", tId);
2556 element.AddAttribute("fbRx", fbRx);
2557 element.AddAttribute("lbRx", lbRx);
2558 WriteN(element.ToString(), m_f);
2559}
2560
2561void
2563 uint32_t fId,
2564 double fbTx,
2565 double lbTx,
2566 uint32_t tId,
2567 double fbRx,
2568 double lbRx,
2569 std::string metaInfo)
2570{
2571 AnimXmlElement element(pktType);
2572 element.AddAttribute("fId", fId);
2573 element.AddAttribute("fbTx", fbTx);
2574 element.AddAttribute("lbTx", lbTx);
2575 if (!metaInfo.empty())
2576 {
2577 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2578 }
2579 element.AddAttribute("tId", tId);
2580 element.AddAttribute("fbRx", fbRx);
2581 element.AddAttribute("lbRx", lbRx);
2582 WriteN(element.ToString(), m_f);
2583}
2584
2585void
2587 std::string counterName,
2588 CounterType counterType)
2589{
2590 AnimXmlElement element("ncs");
2591 element.AddAttribute("ncId", nodeCounterId);
2592 element.AddAttribute("n", counterName);
2593 element.AddAttribute("t", CounterTypeToString(counterType));
2594 WriteN(element.ToString(), m_f);
2595}
2596
2597void
2598AnimationInterface::WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
2599{
2600 AnimXmlElement element("res");
2601 element.AddAttribute("rid", resourceId);
2602 element.AddAttribute("p", resourcePath);
2603 WriteN(element.ToString(), m_f);
2604}
2605
2606void
2608{
2609 AnimXmlElement element("nu");
2610 element.AddAttribute("p", "i");
2611 element.AddAttribute("t", Simulator::Now().GetSeconds());
2612 element.AddAttribute("id", nodeId);
2613 element.AddAttribute("rid", resourceId);
2614 WriteN(element.ToString(), m_f);
2615}
2616
2617void
2618AnimationInterface::WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
2619{
2620 AnimXmlElement element("nu");
2621 element.AddAttribute("p", "s");
2622 element.AddAttribute("t", Simulator::Now().GetSeconds());
2623 element.AddAttribute("id", nodeId);
2624 element.AddAttribute("w", width);
2625 element.AddAttribute("h", height);
2626 WriteN(element.ToString(), m_f);
2627}
2628
2629void
2631{
2632 AnimXmlElement element("nu");
2633 element.AddAttribute("p", "p");
2634 element.AddAttribute("t", Simulator::Now().GetSeconds());
2635 element.AddAttribute("id", nodeId);
2636 element.AddAttribute("x", x);
2637 element.AddAttribute("y", y);
2638 WriteN(element.ToString(), m_f);
2639}
2640
2641void
2642AnimationInterface::WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2643{
2644 AnimXmlElement element("nu");
2645 element.AddAttribute("p", "c");
2646 element.AddAttribute("t", Simulator::Now().GetSeconds());
2647 element.AddAttribute("id", nodeId);
2648 element.AddAttribute("r", (uint32_t)r);
2649 element.AddAttribute("g", (uint32_t)g);
2650 element.AddAttribute("b", (uint32_t)b);
2651 WriteN(element.ToString(), m_f);
2652}
2653
2654void
2656{
2657 AnimXmlElement element("nu");
2658 element.AddAttribute("p", "d");
2659 element.AddAttribute("t", Simulator::Now().GetSeconds());
2660 element.AddAttribute("id", nodeId);
2661 if (m_nodeDescriptions.find(nodeId) != m_nodeDescriptions.end())
2662 {
2663 element.AddAttribute("descr", m_nodeDescriptions[nodeId], true);
2664 }
2665 WriteN(element.ToString(), m_f);
2666}
2667
2668void
2670 uint32_t nodeId,
2671 double counterValue)
2672{
2673 AnimXmlElement element("nc");
2674 element.AddAttribute("c", nodeCounterId);
2675 element.AddAttribute("i", nodeId);
2676 element.AddAttribute("t", Simulator::Now().GetSeconds());
2677 element.AddAttribute("v", counterValue);
2678 WriteN(element.ToString(), m_f);
2679}
2680
2681void
2683 double x,
2684 double y,
2685 double scaleX,
2686 double scaleY,
2687 double opacity)
2688{
2689 AnimXmlElement element("bg");
2690 element.AddAttribute("f", fileName);
2691 element.AddAttribute("x", x);
2692 element.AddAttribute("y", y);
2693 element.AddAttribute("sx", scaleX);
2694 element.AddAttribute("sy", scaleY);
2695 element.AddAttribute("o", opacity);
2696 WriteN(element.ToString(), m_f);
2697}
2698
2699void
2701 std::string ipAddress,
2702 std::string channelType)
2703{
2704 AnimXmlElement element("nonp2plinkproperties");
2705 element.AddAttribute("id", id);
2706 element.AddAttribute("ipAddress", ipAddress);
2707 element.AddAttribute("channelType", channelType);
2708 WriteN(element.ToString(), m_f);
2709}
2710
2711/***** AnimXmlElement *****/
2712
2713AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement)
2714 : m_tagName(tagName),
2715 m_text("")
2716{
2717}
2718
2719template <typename T>
2720void
2721AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape)
2722{
2723 std::ostringstream oss;
2724 oss << std::setprecision(10);
2725 oss << value;
2726 std::string attributeString = attribute;
2727 if (xmlEscape)
2728 {
2729 attributeString += "=\"";
2730 std::string valueStr = oss.str();
2731 for (auto it = valueStr.begin(); it != valueStr.end(); ++it)
2732 {
2733 switch (*it)
2734 {
2735 case '&':
2736 attributeString += "&amp;";
2737 break;
2738 case '\"':
2739 attributeString += "&quot;";
2740 break;
2741 case '\'':
2742 attributeString += "&apos;";
2743 break;
2744 case '<':
2745 attributeString += "&lt;";
2746 break;
2747 case '>':
2748 attributeString += "&gt;";
2749 break;
2750 default:
2751 attributeString += *it;
2752 break;
2753 }
2754 }
2755 attributeString += "\" ";
2756 }
2757 else
2758 {
2759 attributeString += "=\"" + oss.str() + "\" ";
2760 }
2761 m_attributes.push_back(attributeString);
2762}
2763
2764void
2766{
2767 m_children.push_back(e.ToString());
2768}
2769
2770void
2772{
2773 m_text = text;
2774}
2775
2776std::string
2778{
2779 std::string elementString = "<" + m_tagName + " ";
2780
2781 for (auto i = m_attributes.begin(); i != m_attributes.end(); ++i)
2782 {
2783 elementString += *i;
2784 }
2785 if (m_children.empty() && m_text.empty())
2786 {
2787 if (autoClose)
2788 {
2789 elementString += "/>";
2790 }
2791 }
2792 else
2793 {
2794 elementString += ">";
2795 if (!m_text.empty())
2796 {
2797 elementString += m_text;
2798 }
2799 if (!m_children.empty())
2800 {
2801 elementString += "\n";
2802 for (auto i = m_children.begin(); i != m_children.end(); ++i)
2803 {
2804 elementString += *i + "\n";
2805 }
2806 }
2807 if (autoClose)
2808 {
2809 elementString += "</" + m_tagName + ">";
2810 }
2811 }
2812
2813 return elementString + ((autoClose) ? "\n" : "");
2814}
2815
2816/***** AnimByteTag *****/
2817
2818TypeId
2820{
2821 static TypeId tid = TypeId("ns3::AnimByteTag")
2822 .SetParent<Tag>()
2823 .SetGroupName("NetAnim")
2824 .AddConstructor<AnimByteTag>();
2825 return tid;
2826}
2827
2828TypeId
2830{
2831 return GetTypeId();
2832}
2833
2836{
2837 return sizeof(uint64_t);
2838}
2839
2840void
2842{
2843 i.WriteU64(m_AnimUid);
2844}
2845
2846void
2848{
2849 m_AnimUid = i.ReadU64();
2850}
2851
2852void
2853AnimByteTag::Print(std::ostream& os) const
2854{
2855 os << "AnimUid=" << m_AnimUid;
2856}
2857
2858void
2859AnimByteTag::Set(uint64_t AnimUid)
2860{
2861 m_AnimUid = AnimUid;
2862}
2863
2864uint64_t
2866{
2867 return m_AnimUid;
2868}
2869
2871 : m_txnd(nullptr),
2872 m_txNodeId(0),
2873 m_fbTx(0),
2874 m_lbTx(0),
2875 m_lbRx(0)
2876{
2877}
2878
2880{
2881 m_txnd = pInfo.m_txnd;
2882 m_txNodeId = pInfo.m_txNodeId;
2883 m_fbTx = pInfo.m_fbTx;
2884 m_lbTx = pInfo.m_lbTx;
2885 m_lbRx = pInfo.m_lbRx;
2886}
2887
2889 const Time fbTx,
2890 uint32_t txNodeId)
2891 : m_txnd(txnd),
2892 m_txNodeId(0),
2893 m_fbTx(fbTx.GetSeconds()),
2894 m_lbTx(0),
2895 m_lbRx(0)
2896{
2897 if (!m_txnd)
2898 {
2899 m_txNodeId = txNodeId;
2900 }
2901}
2902
2903void
2905{
2906 Ptr<Node> n = nd->GetNode();
2907 m_fbRx = fbRx;
2908 m_rxnd = nd;
2909}
2910
2911} // namespace ns3
#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:90
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
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.
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 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.
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition packet.h:52
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition packet.cc:43
TypeId GetTypeId() const
Definition packet.cc:25
Iterator over the set of byte tags in a packet.
Definition packet.h:45
bool HasNext() const
Definition packet.cc:61
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:31
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
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:71
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
This class can contain 16 bit addresses.
an EUI-48 address
an EUI-64 address
Keep track of the current position and velocity of an object.
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.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
A network Node.
Definition node.h:46
uint32_t GetId() const
Definition node.cc:106
static Iterator Begin()
Definition node-list.cc:226
static Ptr< Node > GetNode(uint32_t n)
Definition node-list.cc:240
static Iterator End()
Definition node-list.cc:233
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
static void EnablePrinting()
Enable printing packets metadata.
Definition packet.cc:585
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static bool IsFinished()
Check if the simulation should finish.
Definition simulator.cc:160
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
@ ERROR_NOROUTETOHOST
Definition socket.h:84
read and write tag data
Definition tag-buffer.h:41
void WriteU64(uint64_t v)
Definition tag-buffer.cc:93
uint64_t ReadU64()
tag a set of bytes in a packet
Definition tag.h:28
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Net device for UAN models.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
Hold together all Wifi-related objects.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Energy source base class.
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.
int nDevices
Number of end device nodes to create.
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:55
#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:75
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
Definition config.cc:977
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition config.cc:953
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:443
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:684
static bool initialized
Initialization flag.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
std::map< WifiSpectrumBandInfo, Watt_u > RxPowerWattPerChannelBand
A map of the received power for each band.
Definition phy-entity.h:45
uint8_t data[writeSize]
Ipv4RoutePathElement structure IPv4 route path element.
Ipv4RouteTrackElement structure IPv4 route track element.
NodeSize structure node size.
RGB structure RGB structure.