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/csma-net-device.h"
26#endif
27#include "animation-interface.h"
28
29#include "ns3/channel.h"
30#include "ns3/config.h"
31#include "ns3/constant-position-mobility-model.h"
32#include "ns3/double.h"
33#include "ns3/energy-source-container.h"
34#include "ns3/ipv4-routing-protocol.h"
35#include "ns3/ipv4.h"
36#include "ns3/ipv6.h"
37#include "ns3/lr-wpan-mac-header.h"
38#include "ns3/lr-wpan-net-device.h"
39#include "ns3/lte-enb-phy.h"
40#include "ns3/lte-ue-phy.h"
41#include "ns3/mobility-model.h"
42#include "ns3/node.h"
43#include "ns3/packet.h"
44#include "ns3/simulator.h"
45#include "ns3/uan-mac.h"
46#include "ns3/uan-net-device.h"
47#include "ns3/wifi-mac-header.h"
48#include "ns3/wifi-mac.h"
49#include "ns3/wifi-net-device.h"
50#include "ns3/wifi-psdu.h"
51
52namespace ns3
53{
54
55NS_LOG_COMPONENT_DEFINE("AnimationInterface");
56
57// Globals
58
59static bool initialized = false; //!< Initialization flag
60
61// Public methods
62
64 : m_f(nullptr),
65 m_routingF(nullptr),
68 gAnimUid(0),
69 m_writeCallback(nullptr),
70 m_started(false),
73 m_stopTime(Seconds(3600 * 1000)),
79 m_trackPackets(true)
80{
81 initialized = true;
83
84#ifdef __WIN32__
85 /**
86 * Shared libraries are handled differently on Windows and
87 * need to be explicitly loaded via LoadLibrary("library.dll").
88 *
89 * Otherwise, static import libraries .dll.a/.lib (MinGW/MSVC)
90 * can be linked to the executables to perform the loading of
91 * their respective .dll implicitly during static initialization.
92 *
93 * The .dll.a/.lib however, only gets linked if we instantiate at
94 * least one symbol exported by the .dll.
95 *
96 * To ensure TypeIds from the Csma, Uan, and Wifi
97 * modules are registered during runtime, we need to instantiate
98 * at least one symbol exported by each of these module libraries.
99 */
100 static CsmaNetDevice c;
101 static WifiNetDevice w;
102 static UanNetDevice u;
103#endif
104}
105
110
111void
116
117void
134
135void
158
159void
179
180void
200
203 Time startTime,
205 Time pollInterval)
206{
207 SetOutputFile(fileName, true);
209 m_routingPollInterval = pollInterval;
210 WriteXmlAnim(true);
212 return *this;
213}
214
217 Time startTime,
219 NodeContainer nc,
220 Time pollInterval)
221{
222 m_routingNc = nc;
223 return EnableIpv4RouteTracking(fileName, startTime, stopTime, pollInterval);
224}
225
227AnimationInterface::AddSourceDestination(uint32_t fromNodeId, std::string ipv4Address)
228{
229 Ipv4RouteTrackElement element = {ipv4Address, fromNodeId};
230 m_ipv4RouteTrackElements.push_back(element);
231 return *this;
232}
233
234void
239
240void
245
246void
248{
249 m_maxPktsPerFile = maxPacketsPerFile;
250}
251
253AnimationInterface::AddNodeCounter(std::string counterName, CounterType counterType)
254{
255 m_nodeCounters.push_back(counterName);
256 uint32_t counterId = m_nodeCounters.size() - 1; // counter ID is zero-indexed
257 WriteXmlAddNodeCounter(counterId, counterName, counterType);
258 return counterId;
259}
260
262AnimationInterface::AddResource(std::string resourcePath)
263{
264 m_resources.push_back(resourcePath);
265 uint32_t resourceId = m_resources.size() - 1; // resource ID is zero-indexed
266 WriteXmlAddResource(resourceId, resourcePath);
267 return resourceId;
268}
269
270void
272{
273 m_enablePacketMetadata = enable;
274 if (enable)
275 {
277 }
278}
279
280bool
285
286bool
288{
289 return m_started;
290}
291
292void
297
298void
303
304void
309
310void
312{
313 NS_ASSERT(n);
315 if (!loc)
316 {
318 n->AggregateObject(loc);
319 }
320 Vector hubVec(x, y, z);
321 loc->SetPosition(hubVec);
322 NS_LOG_INFO("Node:" << n->GetId() << " Position set to:(" << x << "," << y << "," << z << ")");
323}
324
325void
327{
328 NS_LOG_INFO("Setting node image for Node Id:" << nodeId);
329 if (resourceId > (m_resources.size() - 1))
330 {
331 NS_FATAL_ERROR("Resource Id:" << resourceId << " not found. Did you use AddResource?");
332 }
333 WriteXmlUpdateNodeImage(nodeId, resourceId);
334}
335
336void
337AnimationInterface::UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
338{
339 if (nodeCounterId > (m_nodeCounters.size() - 1))
340 {
341 NS_FATAL_ERROR("NodeCounter Id:" << nodeCounterId
342 << " not found. Did you use AddNodeCounter?");
343 }
344 WriteXmlUpdateNodeCounter(nodeCounterId, nodeId, counter);
345}
346
347void
349 double x,
350 double y,
351 double scaleX,
352 double scaleY,
353 double opacity)
354{
355 if ((opacity < 0) || (opacity > 1))
356 {
357 NS_FATAL_ERROR("Opacity must be between 0.0 and 1.0");
358 }
359 WriteXmlUpdateBackground(fileName, x, y, scaleX, scaleY, opacity);
360}
361
362void
363AnimationInterface::UpdateNodeSize(Ptr<Node> n, double width, double height)
364{
365 UpdateNodeSize(n->GetId(), width, height);
366}
367
368void
369AnimationInterface::UpdateNodeSize(uint32_t nodeId, double width, double height)
370{
371 AnimationInterface::NodeSize s = {width, height};
372 m_nodeSizes[nodeId] = s;
373 WriteXmlUpdateNodeSize(nodeId, s.width, s.height);
374}
375
376void
377AnimationInterface::UpdateNodeColor(Ptr<Node> n, uint8_t r, uint8_t g, uint8_t b)
378{
379 UpdateNodeColor(n->GetId(), r, g, b);
380}
381
382void
383AnimationInterface::UpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
384{
386 NS_LOG_INFO("Setting node color for Node Id:" << nodeId);
387 Rgb rgb = {r, g, b};
388 m_nodeColors[nodeId] = rgb;
389 WriteXmlUpdateNodeColor(nodeId, r, g, b);
390}
391
392void
394 uint32_t toNode,
395 std::string linkDescription)
396{
397 WriteXmlUpdateLink(fromNode, toNode, linkDescription);
398}
399
400void
402 Ptr<Node> toNode,
403 std::string linkDescription)
404{
405 NS_ASSERT(fromNode);
406 NS_ASSERT(toNode);
407 WriteXmlUpdateLink(fromNode->GetId(), toNode->GetId(), linkDescription);
408}
409
410void
412{
413 UpdateNodeDescription(n->GetId(), descr);
414}
415
416void
418{
420 m_nodeDescriptions[nodeId] = descr;
422}
423
424// Private methods
425
426double
428{
429 const auto fractionIter = m_nodeEnergyFraction.find(node->GetId());
430 NS_ASSERT(fractionIter != m_nodeEnergyFraction.end());
431 return fractionIter->second;
432}
433
434void
436{
438 Ptr<Node> n = mobility->GetObject<Node>();
439 NS_ASSERT(n);
440 Vector v;
441 if (!mobility)
442 {
443 v = GetPosition(n);
444 }
445 else
446 {
447 v = mobility->GetPosition();
448 }
449 UpdatePosition(n, v);
450 WriteXmlUpdateNodePosition(n->GetId(), v.x, v.y);
451}
452
453bool
455{
456 Vector oldLocation = GetPosition(n);
457 bool moved = !((ceil(oldLocation.x) == ceil(newLocation.x)) &&
458 (ceil(oldLocation.y) == ceil(newLocation.y)));
459 return moved;
460}
461
462void
483
484std::vector<Ptr<Node>>
486{
487 std::vector<Ptr<Node>> movedNodes;
488 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
489 {
490 Ptr<Node> n = *i;
491 NS_ASSERT(n);
492 Ptr<MobilityModel> mobility = n->GetObject<MobilityModel>();
493 Vector newLocation;
494 if (!mobility)
495 {
496 newLocation = GetPosition(n);
497 }
498 else
499 {
500 newLocation = mobility->GetPosition();
501 }
502 if (!NodeHasMoved(n, newLocation))
503 {
504 continue; // Location has not changed
505 }
506 else
507 {
508 UpdatePosition(n, newLocation);
509 movedNodes.push_back(n);
510 }
511 }
512 return movedNodes;
513}
514
515int
516AnimationInterface::WriteN(const std::string& st, FILE* f)
517{
518 if (!f)
519 {
520 return 0;
521 }
522 if (m_writeCallback)
523 {
524 m_writeCallback(st.c_str());
525 }
526 return WriteN(st.c_str(), st.length(), f);
527}
528
529int
530AnimationInterface::WriteN(const char* data, uint32_t count, FILE* f)
531{
532 if (!f)
533 {
534 return 0;
535 }
536 // Write count bytes to h from data
537 uint32_t nLeft = count;
538 const char* p = data;
539 uint32_t written = 0;
540 while (nLeft)
541 {
542 int n = std::fwrite(p, 1, nLeft, f);
543 if (n <= 0)
544 {
545 return written;
546 }
547 written += n;
548 nLeft -= n;
549 p += n;
550 }
551 return written;
552}
553
554void
556 std::string destination,
557 Ipv4RoutePathElements rpElements)
558{
559 NS_LOG_INFO("Writing Route Path From :" << nodeId << " To: " << destination);
560 WriteXmlRp(nodeId, destination, rpElements);
561 /*
562 for (auto i = rpElements.begin (); i != rpElements.end (); ++i)
563 {
564 Ipv4RoutePathElement rpElement = *i;
565 NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
566 WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
567
568 }
569 */
570}
571
572void
574 std::string ipv4Address,
575 std::string channelType)
576{
577 WriteXmlNonP2pLinkProperties(id, ipv4Address, channelType);
578}
579
580const std::vector<std::string>
581AnimationInterface::GetElementsFromContext(const std::string& context) const
582{
583 std::vector<std::string> elements;
584 std::size_t pos1 = 0;
585 std::size_t pos2;
586 while (pos1 != std::string::npos)
587 {
588 pos1 = context.find('/', pos1);
589 pos2 = context.find('/', pos1 + 1);
590 elements.push_back(context.substr(pos1 + 1, pos2 - (pos1 + 1)));
591 pos1 = pos2;
592 pos2 = std::string::npos;
593 }
594 return elements;
595}
596
598AnimationInterface::GetNodeFromContext(const std::string& context) const
599{
600 // Use "NodeList/*/ as reference
601 // where element [1] is the Node Id
602
603 std::vector<std::string> elements = GetElementsFromContext(context);
604 Ptr<Node> n = NodeList::GetNode(std::stoi(elements.at(1)));
605 NS_ASSERT(n);
606
607 return n;
608}
609
612{
613 // Use "NodeList/*/DeviceList/*/ as reference
614 // where element [1] is the Node Id
615 // element [2] is the NetDevice Id
616
617 std::vector<std::string> elements = GetElementsFromContext(context);
618 Ptr<Node> n = GetNodeFromContext(context);
619
620 return n->GetDevice(std::stoi(elements.at(3)));
621}
622
623uint64_t
625{
626 AnimByteTag tag;
627 TypeId tid = tag.GetInstanceTypeId();
628 ByteTagIterator i = p->GetByteTagIterator();
629 bool found = false;
630 while (i.HasNext())
631 {
632 ByteTagIterator::Item item = i.Next();
633 if (tid == item.GetTypeId())
634 {
635 item.GetTag(tag);
636 found = true;
637 }
638 }
639 if (found)
640 {
641 return tag.Get();
642 }
643 else
644 {
645 return 0;
646 }
647}
648
649void
651{
652 AnimByteTag tag;
653 tag.Set(animUid);
654 p->AddByteTag(tag);
655}
656
657void
659 double previousEnergy,
660 double currentEnergy)
661{
663 const Ptr<const Node> node = GetNodeFromContext(context);
664 const uint32_t nodeId = node->GetId();
665
666 NS_LOG_INFO("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
667
668 const Ptr<energy::EnergySource> energySource = node->GetObject<energy::EnergySource>();
669
670 NS_ASSERT(energySource);
671 // Don't call GetEnergyFraction () because of recursion
672 const double energyFraction = currentEnergy / energySource->GetInitialEnergy();
673
674 NS_LOG_INFO("Total energy fraction on node " << nodeId << ": " << energyFraction);
675
676 m_nodeEnergyFraction[nodeId] = energyFraction;
677 UpdateNodeCounter(m_remainingEnergyCounterId, nodeId, energyFraction);
678}
679
680void
682{
683 const Ptr<const Node> node = GetNodeFromContext(context);
684 ++m_nodeWifiPhyTxDrop[node->GetId()];
685}
686
687void
691{
692 const Ptr<const Node> node = GetNodeFromContext(context);
693 ++m_nodeWifiPhyRxDrop[node->GetId()];
694}
695
696void
698{
699 const Ptr<const Node> node = GetNodeFromContext(context);
700 ++m_nodeWifiMacTx[node->GetId()];
701}
702
703void
705{
706 const Ptr<const Node> node = GetNodeFromContext(context);
707 ++m_nodeWifiMacTxDrop[node->GetId()];
708}
709
710void
712{
713 const Ptr<const Node> node = GetNodeFromContext(context);
714 ++m_nodeWifiMacRx[node->GetId()];
715}
716
717void
719{
720 const Ptr<const Node> node = GetNodeFromContext(context);
721 ++m_nodeWifiMacRxDrop[node->GetId()];
722}
723
724void
726{
727 const Ptr<const Node> node = GetNodeFromContext(context);
728 ++m_nodeLrWpanMacTx[node->GetId()];
729}
730
731void
733{
734 const Ptr<const Node> node = GetNodeFromContext(context);
735 ++m_nodeLrWpanMacTxDrop[node->GetId()];
736}
737
738void
740{
741 const Ptr<const Node> node = GetNodeFromContext(context);
742 ++m_nodeLrWpanMacRx[node->GetId()];
743}
744
745void
747{
748 const Ptr<const Node> node = GetNodeFromContext(context);
749 ++m_nodeLrWpanMacRxDrop[node->GetId()];
750}
751
752void
755 Ptr<Ipv4> ipv4,
756 uint32_t interfaceIndex)
757{
758 const Ptr<const Node> node = GetNodeFromContext(context);
759 ++m_nodeIpv4Tx[node->GetId()];
760}
761
762void
765 Ptr<Ipv4> ipv4,
766 uint32_t interfaceIndex)
767{
768 const Ptr<const Node> node = GetNodeFromContext(context);
769 ++m_nodeIpv4Rx[node->GetId()];
770}
771
772void
774 const Ipv4Header& ipv4Header,
777 Ptr<Ipv4> ipv4,
778 uint32_t)
779{
780 const Ptr<const Node> node = GetNodeFromContext(context);
781 ++m_nodeIpv4Drop[node->GetId()];
782}
783
784void
786{
787 const Ptr<const Node> node = GetNodeFromContext(context);
788 ++m_nodeQueueEnqueue[node->GetId()];
789}
790
791void
793{
794 const Ptr<const Node> node = GetNodeFromContext(context);
795 ++m_nodeQueueDequeue[node->GetId()];
796}
797
798void
800{
801 const Ptr<const Node> node = GetNodeFromContext(context);
802 ++m_nodeQueueDrop[node->GetId()];
803}
804
805void
810 Time txTime,
811 Time rxTime)
812{
813 NS_LOG_FUNCTION(this);
815 NS_ASSERT(tx);
816 NS_ASSERT(rx);
817 Time now = Simulator::Now();
818 double fbTx = now.GetSeconds();
819 double lbTx = (now + txTime).GetSeconds();
820 double fbRx = (now + rxTime - txTime).GetSeconds();
821 double lbRx = (now + rxTime).GetSeconds();
823 WriteXmlP("p",
824 tx->GetNode()->GetId(),
825 fbTx,
826 lbTx,
827 rx->GetNode()->GetId(),
828 fbRx,
829 lbRx,
831}
832
833void
836 ProtocolType protocolType)
837{
838 NS_LOG_FUNCTION(this);
841 NS_ASSERT(ndev);
842 UpdatePosition(ndev);
843
844 ++gAnimUid;
846 << " GenericWirelessTxTrace for packet:" << gAnimUid);
848 AnimPacketInfo pktInfo(ndev, Simulator::Now());
849 AddPendingPacket(protocolType, gAnimUid, pktInfo);
850
852 if (netDevice)
853 {
854 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
855 std::ostringstream oss;
856 oss << nodeAddr;
857 Ptr<Node> n = netDevice->GetNode();
858 NS_ASSERT(n);
859 m_macToNodeIdMap[oss.str()] = n->GetId();
860 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
861 }
862 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
863 OutputWirelessPacketTxInfo(p, pendingPackets->at(gAnimUid), gAnimUid);
864}
865
866void
869 ProtocolType protocolType)
870{
871 NS_LOG_FUNCTION(this);
874 NS_ASSERT(ndev);
875 UpdatePosition(ndev);
876 uint64_t animUid = GetAnimUidFromPacket(p);
877 NS_LOG_INFO(ProtocolTypeToString(protocolType) << " for packet:" << animUid);
878 if (!IsPacketPending(animUid, protocolType))
879 {
880 NS_LOG_WARN(ProtocolTypeToString(protocolType) << " GenericWirelessRxTrace: unknown Uid");
881 return;
882 }
883 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
884 pendingPackets->at(animUid).ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
885 OutputWirelessPacketRxInfo(p, pendingPackets->at(animUid), animUid);
886}
887
888void
894
895void
901
902void
904 WifiConstPsduMap psduMap,
905 WifiTxVector /* txVector */,
906 double /* txPowerW */)
907{
908 NS_LOG_FUNCTION(this);
911 NS_ASSERT(ndev);
912 UpdatePosition(ndev);
913
914 AnimPacketInfo pktInfo(ndev, Simulator::Now());
916 for (auto& psdu : psduMap)
917 {
918 for (auto& mpdu : *PeekPointer(psdu.second))
919 {
920 ++gAnimUid;
921 NS_LOG_INFO("WifiPhyTxTrace for MPDU:" << gAnimUid);
923 mpdu->GetPacket()); // the underlying MSDU/A-MSDU should be handed off
924 AddPendingPacket(WIFI, gAnimUid, pktInfo);
926 mpdu->GetProtocolDataUnit(),
927 pendingPackets->at(gAnimUid),
928 gAnimUid); // PDU should be considered in order to have header
929 }
930 }
931
933 if (netDevice)
934 {
935 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
936 std::ostringstream oss;
937 oss << nodeAddr;
938 Ptr<Node> n = netDevice->GetNode();
939 NS_ASSERT(n);
940 m_macToNodeIdMap[oss.str()] = n->GetId();
941 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
942 }
943 else
944 {
945 NS_ABORT_MSG("This NetDevice should be a Wi-Fi network device");
946 }
947}
948
949void
953{
954 NS_LOG_FUNCTION(this);
957 NS_ASSERT(ndev);
958 UpdatePosition(ndev);
959 uint64_t animUid = GetAnimUidFromPacket(p);
960 NS_LOG_INFO("Wifi RxBeginTrace for packet: " << animUid);
962 {
963 NS_ASSERT_MSG(false, "WifiPhyRxBeginTrace: unknown Uid");
964 std::ostringstream oss;
965 WifiMacHeader hdr;
966 if (!p->PeekHeader(hdr))
967 {
968 NS_LOG_WARN("WifiMacHeader not present");
969 return;
970 }
971 oss << hdr.GetAddr2();
972 if (m_macToNodeIdMap.find(oss.str()) == m_macToNodeIdMap.end())
973 {
974 NS_LOG_WARN("Transmitter Mac address " << oss.str() << " never seen before. Skipping");
975 return;
976 }
977 Ptr<Node> txNode = NodeList::GetNode(m_macToNodeIdMap[oss.str()]);
978 UpdatePosition(txNode);
979 AnimPacketInfo pktInfo(nullptr, Simulator::Now(), m_macToNodeIdMap[oss.str()]);
981 NS_LOG_WARN("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
982 }
983 /// @todo NS_ASSERT (WifiPacketIsPending (animUid) == true);
984 m_pendingWifiPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
986}
987
988void
990{
991 NS_LOG_FUNCTION(this);
993
995 NS_ASSERT(ndev);
997
998 Ptr<Node> n = ndev->GetNode();
999 NS_ASSERT(n);
1000
1001 UpdatePosition(n);
1002
1004 if (!p->PeekHeader(hdr))
1005 {
1006 NS_LOG_WARN("LrWpanMacHeader not present");
1007 return;
1008 }
1009
1010 std::ostringstream oss;
1011 if (hdr.GetSrcAddrMode() == 2)
1012 {
1013 Mac16Address nodeAddr = netDevice->GetMac()->GetShortAddress();
1014 oss << nodeAddr;
1015 }
1016 else if (hdr.GetSrcAddrMode() == 3)
1017 {
1018 Mac64Address nodeAddr = netDevice->GetMac()->GetExtendedAddress();
1019 oss << nodeAddr;
1020 }
1021 else
1022 {
1023 NS_LOG_WARN("LrWpanMacHeader without source address");
1024 return;
1025 }
1026 m_macToNodeIdMap[oss.str()] = n->GetId();
1027 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
1028
1029 ++gAnimUid;
1030 NS_LOG_INFO("LrWpan TxBeginTrace for packet:" << gAnimUid);
1031 AddByteTag(gAnimUid, p);
1032
1033 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1035
1037}
1038
1039void
1041{
1042 NS_LOG_FUNCTION(this);
1045 NS_ASSERT(ndev);
1046 Ptr<Node> n = ndev->GetNode();
1047 NS_ASSERT(n);
1048
1049 AnimByteTag tag;
1050 if (!p->FindFirstMatchingByteTag(tag))
1051 {
1052 return;
1053 }
1054
1055 uint64_t animUid = GetAnimUidFromPacket(p);
1056 NS_LOG_INFO("LrWpan RxBeginTrace for packet:" << animUid);
1058 {
1059 NS_LOG_WARN("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
1060 }
1061
1062 UpdatePosition(n);
1063 m_pendingLrWpanPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1065}
1066
1067void
1069{
1070 NS_LOG_FUNCTION(this);
1072}
1073
1074void
1076{
1077 NS_LOG_FUNCTION(this);
1079}
1080
1081void
1083{
1084 NS_LOG_FUNCTION(this);
1086 if (!pb)
1087 {
1088 NS_LOG_WARN("pb == 0. Not yet supported");
1089 return;
1090 }
1091 context = "/" + context;
1093 NS_ASSERT(ndev);
1094 UpdatePosition(ndev);
1095
1096 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1097 for (auto i = pbList.begin(); i != pbList.end(); ++i)
1098 {
1099 Ptr<Packet> p = *i;
1100 ++gAnimUid;
1101 NS_LOG_INFO("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1102 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1103 AddByteTag(gAnimUid, p);
1106 }
1107}
1108
1109void
1111{
1112 NS_LOG_FUNCTION(this);
1114 if (!pb)
1115 {
1116 NS_LOG_WARN("pb == 0. Not yet supported");
1117 return;
1118 }
1119 context = "/" + context;
1121 NS_ASSERT(ndev);
1122 UpdatePosition(ndev);
1123
1124 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1125 for (auto i = pbList.begin(); i != pbList.end(); ++i)
1126 {
1127 Ptr<Packet> p = *i;
1128 uint64_t animUid = GetAnimUidFromPacket(p);
1129 NS_LOG_INFO("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1131 {
1132 NS_LOG_WARN("LteSpectrumPhyRxTrace: unknown Uid");
1133 return;
1134 }
1135 AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1136 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1137 OutputWirelessPacketRxInfo(p, pktInfo, animUid);
1138 }
1139}
1140
1141void
1143{
1144 NS_LOG_FUNCTION(this);
1147 NS_ASSERT(ndev);
1148 UpdatePosition(ndev);
1149 ++gAnimUid;
1150 NS_LOG_INFO("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1151 AddByteTag(gAnimUid, p);
1152 UpdatePosition(ndev);
1153 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1155}
1156
1157void
1159{
1160 NS_LOG_FUNCTION(this);
1163 NS_ASSERT(ndev);
1164 UpdatePosition(ndev);
1165 uint64_t animUid = GetAnimUidFromPacket(p);
1166 NS_LOG_INFO("CsmaPhyTxEndTrace for packet:" << animUid);
1168 {
1169 NS_LOG_WARN("CsmaPhyTxEndTrace: unknown Uid");
1170 NS_FATAL_ERROR("CsmaPhyTxEndTrace: unknown Uid");
1171 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1172 AddPendingPacket(AnimationInterface::CSMA, animUid, pktInfo);
1173 NS_LOG_WARN("Unknown Uid, but adding Csma Packet anyway");
1174 }
1175 /// @todo NS_ASSERT (IsPacketPending (AnimUid) == true);
1176 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1177 pktInfo.m_lbTx = Simulator::Now().GetSeconds();
1178}
1179
1180void
1182{
1183 NS_LOG_FUNCTION(this);
1186 NS_ASSERT(ndev);
1187 UpdatePosition(ndev);
1188 uint64_t animUid = GetAnimUidFromPacket(p);
1190 {
1191 NS_LOG_WARN("CsmaPhyRxEndTrace: unknown Uid");
1192 return;
1193 }
1194 /// @todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1195 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1196 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1197 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid);
1198 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1199 OutputCsmaPacket(p, pktInfo);
1200}
1201
1202void
1204{
1205 NS_LOG_FUNCTION(this);
1208 NS_ASSERT(ndev);
1209 uint64_t animUid = GetAnimUidFromPacket(p);
1211 {
1212 NS_LOG_WARN("CsmaMacRxTrace: unknown Uid");
1213 return;
1214 }
1215 /// @todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
1216 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1217 NS_LOG_INFO("MacRxTrace for packet:" << animUid << " complete");
1218 OutputCsmaPacket(p, pktInfo);
1219}
1220
1221void
1223 AnimPacketInfo& pktInfo,
1224 uint64_t animUid)
1225{
1227 uint32_t nodeId = 0;
1228 if (pktInfo.m_txnd)
1229 {
1230 nodeId = pktInfo.m_txnd->GetNode()->GetId();
1231 }
1232 else
1233 {
1234 nodeId = pktInfo.m_txNodeId;
1235 }
1236 WriteXmlPRef(animUid,
1237 nodeId,
1238 pktInfo.m_fbTx,
1240}
1241
1242void
1244 AnimPacketInfo& pktInfo,
1245 uint64_t animUid)
1246{
1248 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1249 WriteXmlP(animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1250}
1251
1252void
1254{
1256 NS_ASSERT(pktInfo.m_txnd);
1257 uint32_t nodeId = pktInfo.m_txnd->GetNode()->GetId();
1258 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1259
1260 WriteXmlP("p",
1261 nodeId,
1262 pktInfo.m_fbTx,
1263 pktInfo.m_lbTx,
1264 rxId,
1265 pktInfo.m_fbRx,
1266 pktInfo.m_lbRx,
1268}
1269
1270void
1272 uint64_t animUid,
1273 AnimPacketInfo pktInfo)
1274{
1275 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1276 NS_ASSERT(pendingPackets);
1277 pendingPackets->insert(AnimUidPacketInfoMap::value_type(animUid, pktInfo));
1278}
1279
1280bool
1282{
1283 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1284 NS_ASSERT(pendingPackets);
1285 return (pendingPackets->find(animUid) != pendingPackets->end());
1286}
1287
1288void
1290{
1291 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1292 NS_ASSERT(pendingPackets);
1293 if (pendingPackets->empty())
1294 {
1295 return;
1296 }
1297 std::vector<uint64_t> purgeList;
1298 for (auto i = pendingPackets->begin(); i != pendingPackets->end(); ++i)
1299 {
1300 AnimPacketInfo pktInfo = i->second;
1301 double delta = (Simulator::Now().GetSeconds() - pktInfo.m_fbTx);
1302 if (delta > PURGE_INTERVAL)
1303 {
1304 purgeList.push_back(i->first);
1305 }
1306 }
1307 for (auto i = purgeList.begin(); i != purgeList.end(); ++i)
1308 {
1309 pendingPackets->erase(*i);
1310 }
1311}
1312
1315{
1316 AnimUidPacketInfoMap* pendingPackets = nullptr;
1317 switch (protocolType)
1318 {
1320 pendingPackets = &m_pendingWifiPackets;
1321 break;
1322 }
1324 pendingPackets = &m_pendingUanPackets;
1325 break;
1326 }
1328 pendingPackets = &m_pendingCsmaPackets;
1329 break;
1330 }
1332 pendingPackets = &m_pendingLtePackets;
1333 break;
1334 }
1336 pendingPackets = &m_pendingLrWpanPackets;
1337 break;
1338 }
1339 }
1340 return pendingPackets;
1341}
1342
1343std::string
1345{
1346 std::string result = "Unknown";
1347 switch (protocolType)
1348 {
1350 result = "WIFI";
1351 break;
1352 }
1354 result = "UAN";
1355 break;
1356 }
1358 result = "CSMA";
1359 break;
1360 }
1362 result = "LTE";
1363 break;
1364 }
1366 result = "LRWPAN";
1367 break;
1368 }
1369 }
1370 return result;
1371}
1372
1373// Counters
1374
1375std::string
1377{
1378 std::string typeString = "unknown";
1379 switch (counterType)
1380 {
1381 case UINT32_COUNTER: {
1382 typeString = "UINT32";
1383 break;
1384 }
1385 case DOUBLE_COUNTER: {
1386 typeString = "DOUBLE";
1387 break;
1388 }
1389 }
1390 return typeString;
1391}
1392
1393// General
1394
1395std::string
1397{
1398 std::ostringstream oss;
1399 p->Print(oss);
1400 return oss.str();
1401}
1402
1403uint64_t
1408
1409void
1411{
1412 m_started = false;
1413 NS_LOG_INFO("Stopping Animation");
1415 if (m_f)
1416 {
1417 // Terminate the anim element
1418 WriteXmlClose("anim");
1419 std::fclose(m_f);
1420 m_f = nullptr;
1421 }
1422 if (onlyAnimation)
1423 {
1424 return;
1425 }
1426 if (m_routingF)
1427 {
1428 WriteXmlClose("anim", true);
1429 std::fclose(m_routingF);
1430 m_routingF = nullptr;
1431 }
1432}
1433
1434void
1454
1455void
1457{
1458 m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1459 m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address));
1460}
1461
1462void
1463AnimationInterface::AddToIpv4AddressNodeIdTable(std::vector<std::string> ipv4Addresses,
1464 uint32_t nodeId)
1465{
1466 for (auto i = ipv4Addresses.begin(); i != ipv4Addresses.end(); ++i)
1467 {
1468 AddToIpv4AddressNodeIdTable(*i, nodeId);
1469 }
1470}
1471
1472void
1474{
1475 m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1476 m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address));
1477}
1478
1479void
1480AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector<std::string> ipv6Addresses,
1481 uint32_t nodeId)
1482{
1483 for (auto i = ipv6Addresses.begin(); i != ipv6Addresses.end(); ++i)
1484 {
1485 AddToIpv6AddressNodeIdTable(*i, nodeId);
1486 }
1487}
1488
1489// Callbacks
1490void
1492{
1493 Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy();
1494 Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy();
1495 Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy();
1496 std::ostringstream oss;
1497 // NodeList/*/DeviceList/*/
1498 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1499 if (dlPhy)
1500 {
1501 dlPhy->TraceConnect("TxStart",
1502 oss.str(),
1504 dlPhy->TraceConnect("RxStart",
1505 oss.str(),
1507 }
1508 if (ulPhy)
1509 {
1510 ulPhy->TraceConnect("TxStart",
1511 oss.str(),
1513 ulPhy->TraceConnect("RxStart",
1514 oss.str(),
1516 }
1517}
1518
1519void
1521{
1522 Ptr<LteUePhy> lteUePhy = nd->GetPhy();
1523 Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy();
1524 Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy();
1525 std::ostringstream oss;
1526 // NodeList/*/DeviceList/*/
1527 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1528 if (dlPhy)
1529 {
1530 dlPhy->TraceConnect("TxStart",
1531 oss.str(),
1533 dlPhy->TraceConnect("RxStart",
1534 oss.str(),
1536 }
1537 if (ulPhy)
1538 {
1539 ulPhy->TraceConnect("TxStart",
1540 oss.str(),
1542 ulPhy->TraceConnect("RxStart",
1543 oss.str(),
1545 }
1546}
1547
1548void
1550{
1551 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1552 {
1553 Ptr<Node> n = *i;
1554 NS_ASSERT(n);
1555 uint32_t nDevices = n->GetNDevices();
1556 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1557 {
1558 Ptr<NetDevice> nd = n->GetDevice(devIndex);
1559 if (!nd)
1560 {
1561 continue;
1562 }
1564 if (lteUeNetDevice)
1565 {
1566 ConnectLteUe(n, lteUeNetDevice, devIndex);
1567 continue;
1568 }
1570 if (lteEnbNetDevice)
1571 {
1572 ConnectLteEnb(n, lteEnbNetDevice, devIndex);
1573 }
1574 }
1575 }
1576}
1577
1578void
1580{
1581 // Connect the callbacks
1582 Config::ConnectFailSafe("/ChannelList/*/TxRxPointToPoint",
1584 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
1586 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1589 "/NodeList/*/$ns3::MobilityModel/CourseChange",
1591 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1593 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1595 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1597 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1599 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1601 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1603 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1605 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1607 Config::ConnectFailSafe("/NodeList/*/$ns3::energy::BasicEnergySource/RemainingEnergy",
1609
1610 ConnectLte();
1611
1612 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1614 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1616 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1618
1619 // Queue Enqueues
1620
1621 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1623 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1625 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1627
1628 // Queue Dequeues
1629
1630 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1632 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1634 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1636
1637 // Queue Drops
1638
1639 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1641 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1643 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1645
1646 // Wifi Mac
1647 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1649 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1651 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1653 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1655
1656 // Wifi Phy
1657 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1659 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1661
1662 // LrWpan
1663 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Phy/PhyTxBegin",
1665 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Phy/PhyRxBegin",
1667 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTx",
1669 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTxDrop",
1671 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Mac/MacRx",
1673 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::lrwpan::LrWpanNetDevice/Mac/MacRxDrop",
1675}
1676
1677Vector
1679{
1680 Ptr<MobilityModel> loc = n->GetObject<MobilityModel>();
1681 if (loc)
1682 {
1683 m_nodeLocation[n->GetId()] = loc->GetPosition();
1684 }
1685 else
1686 {
1688 "AnimationInterface WARNING:Node:"
1689 << n->GetId()
1690 << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1692 x->SetAttribute("Min", DoubleValue(0));
1693 x->SetAttribute("Max", DoubleValue(100));
1695 y->SetAttribute("Min", DoubleValue(0));
1696 y->SetAttribute("Max", DoubleValue(100));
1697 m_nodeLocation[n->GetId()] = Vector(int(x->GetValue()), int(y->GetValue()), 0);
1698 }
1699 return m_nodeLocation[n->GetId()];
1700}
1701
1702Vector
1704{
1705 m_nodeLocation[n->GetId()] = v;
1706 return v;
1707}
1708
1709Vector
1711{
1712 Ptr<Node> n = ndev->GetNode();
1713 NS_ASSERT(n);
1714 return UpdatePosition(n);
1715}
1716
1717Vector
1719{
1720 if (m_nodeLocation.find(n->GetId()) == m_nodeLocation.end())
1721 {
1722 NS_FATAL_ERROR("Node:" << n->GetId() << " not found in Location table");
1723 }
1724 return m_nodeLocation[n->GetId()];
1725}
1726
1727std::string
1729{
1730 Address nodeAddr = nd->GetAddress();
1731 std::ostringstream oss;
1732 oss << nodeAddr;
1733 return oss.str().substr(6); // Skip the first 6 chars to get the Mac
1734}
1735
1736std::string
1738{
1739 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1740 if (!ipv4)
1741 {
1742 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1743 return "0.0.0.0";
1744 }
1745 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1746 if (ifIndex == -1)
1747 {
1748 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1749 return "0.0.0.0";
1750 }
1751 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, 0);
1752 std::ostringstream oss;
1753 oss << addr.GetLocal();
1754 return oss.str();
1755}
1756
1757std::string
1759{
1760 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1761 if (!ipv6)
1762 {
1763 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1764 return "::";
1765 }
1766 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1767 if (ifIndex == -1)
1768 {
1769 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1770 return "::";
1771 }
1772 bool nonLinkLocalFound = false;
1773 uint32_t nAddresses = ipv6->GetNAddresses(ifIndex);
1775 for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1776 {
1777 addr = ipv6->GetAddress(ifIndex, addressIndex);
1778 if (!addr.GetAddress().IsLinkLocal())
1779 {
1780 nonLinkLocalFound = true;
1781 break;
1782 }
1783 }
1784 if (!nonLinkLocalFound)
1785 {
1786 addr = ipv6->GetAddress(ifIndex, 0);
1787 }
1788 std::ostringstream oss;
1789 oss << addr.GetAddress();
1790 return oss.str();
1791}
1792
1793std::vector<std::string>
1795{
1796 std::vector<std::string> ipv4Addresses;
1797 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1798 if (!ipv4)
1799 {
1800 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1801 return ipv4Addresses;
1802 }
1803 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1804 if (ifIndex == -1)
1805 {
1806 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1807 return ipv4Addresses;
1808 }
1809 for (uint32_t index = 0; index < ipv4->GetNAddresses(ifIndex); ++index)
1810 {
1811 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, index);
1812 std::ostringstream oss;
1813 oss << addr.GetLocal();
1814 ipv4Addresses.push_back(oss.str());
1815 }
1816 return ipv4Addresses;
1817}
1818
1819std::vector<std::string>
1821{
1822 std::vector<std::string> ipv6Addresses;
1823 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1824 if (!ipv6)
1825 {
1826 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv6 object found");
1827 return ipv6Addresses;
1828 }
1829 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1830 if (ifIndex == -1)
1831 {
1832 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1833 return ipv6Addresses;
1834 }
1835 for (uint32_t index = 0; index < ipv6->GetNAddresses(ifIndex); ++index)
1836 {
1837 Ipv6InterfaceAddress addr = ipv6->GetAddress(ifIndex, index);
1838 std::ostringstream oss;
1839 oss << addr.GetAddress();
1840 ipv6Addresses.push_back(oss.str());
1841 }
1842 return ipv6Addresses;
1843}
1844
1845void
1847{
1848 for (auto i = m_nodeIdIpv4Map.begin(); i != m_nodeIdIpv4Map.end(); ++i)
1849 {
1850 std::vector<std::string> ipv4Addresses;
1851 auto iterPair = m_nodeIdIpv4Map.equal_range(i->first);
1852 for (auto it = iterPair.first; it != iterPair.second; ++it)
1853 {
1854 ipv4Addresses.push_back(it->second);
1855 }
1856 WriteXmlIpv4Addresses(i->first, ipv4Addresses);
1857 }
1858}
1859
1860void
1862{
1863 for (auto i = m_nodeIdIpv6Map.begin(); i != m_nodeIdIpv6Map.end();
1864 i = m_nodeIdIpv6Map.upper_bound(i->first))
1865 {
1866 std::vector<std::string> ipv6Addresses;
1867 auto iterPair = m_nodeIdIpv6Map.equal_range(i->first);
1868 for (auto it = iterPair.first; it != iterPair.second; ++it)
1869 {
1870 ipv6Addresses.push_back(it->second);
1871 }
1872 WriteXmlIpv6Addresses(i->first, ipv6Addresses);
1873 }
1874}
1875
1876void
1878{
1879 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1880 {
1881 Ptr<Node> n = *i;
1882 UpdatePosition(n);
1883 uint32_t n1Id = n->GetId();
1884 uint32_t nDev = n->GetNDevices(); // Number of devices
1885 for (uint32_t i = 0; i < nDev; ++i)
1886 {
1887 Ptr<NetDevice> dev = n->GetDevice(i);
1888 NS_ASSERT(dev);
1889 Ptr<Channel> ch = dev->GetChannel();
1890 std::string channelType = "Unknown channel";
1891 if (ch)
1892 {
1893 channelType = ch->GetInstanceTypeId().GetName();
1894 }
1895 NS_LOG_DEBUG("Got ChannelType" << channelType);
1896
1897 if (!ch || (channelType != "ns3::PointToPointChannel"))
1898 {
1899 NS_LOG_DEBUG("No channel can't be a p2p device");
1900 /*
1901 // Try to see if it is an LTE NetDevice, which does not return a channel
1902 if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1903 (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1904 (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1905 {
1906 WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" +
1907 GetMacAddress (dev), channelType); AddToIpv4AddressNodeIdTable (GetIpv4Address
1908 (dev), n->GetId ());
1909 }
1910 */
1911 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1912 AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId());
1913 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1914 AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId());
1915 if (!ipv4Addresses.empty())
1916 {
1917 NS_LOG_INFO("Writing Ipv4 link");
1918 WriteNonP2pLinkProperties(n->GetId(),
1919 GetIpv4Address(dev) + "~" + GetMacAddress(dev),
1920 channelType);
1921 }
1922 else if (!ipv6Addresses.empty())
1923 {
1924 NS_LOG_INFO("Writing Ipv6 link");
1925 WriteNonP2pLinkProperties(n->GetId(),
1926 GetIpv6Address(dev) + "~" + GetMacAddress(dev),
1927 channelType);
1928 }
1929 continue;
1930 }
1931
1932 else if (channelType == "ns3::PointToPointChannel")
1933 { // Since these are duplex links, we only need to dump
1934 // if srcid < dstid
1935 std::size_t nChDev = ch->GetNDevices();
1936 for (std::size_t j = 0; j < nChDev; ++j)
1937 {
1938 Ptr<NetDevice> chDev = ch->GetDevice(j);
1939 uint32_t n2Id = chDev->GetNode()->GetId();
1940 if (n1Id < n2Id)
1941 {
1942 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1943 AddToIpv4AddressNodeIdTable(ipv4Addresses, n1Id);
1944 ipv4Addresses = GetIpv4Addresses(chDev);
1945 AddToIpv4AddressNodeIdTable(ipv4Addresses, n2Id);
1946 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1947 AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id);
1948 ipv6Addresses = GetIpv6Addresses(chDev);
1949 AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id);
1950
1951 P2pLinkNodeIdPair p2pPair;
1952 p2pPair.fromNode = n1Id;
1953 p2pPair.toNode = n2Id;
1954 if (!ipv4Addresses.empty())
1955 {
1956 LinkProperties lp = {GetIpv4Address(dev) + "~" + GetMacAddress(dev),
1957 GetIpv4Address(chDev) + "~" + GetMacAddress(chDev),
1958 ""};
1959 m_linkProperties[p2pPair] = lp;
1960 }
1961 else if (!ipv6Addresses.empty())
1962 {
1963 LinkProperties lp = {GetIpv6Address(dev) + "~" + GetMacAddress(dev),
1964 GetIpv6Address(chDev) + "~" + GetMacAddress(chDev),
1965 ""};
1966 m_linkProperties[p2pPair] = lp;
1967 }
1968 WriteXmlLink(n1Id, 0, n2Id);
1969 }
1970 }
1971 }
1972 }
1973 }
1974 m_linkProperties.clear();
1975}
1976
1977void
1979{
1980 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1981 {
1982 Ptr<Node> n = *i;
1983 NS_LOG_INFO("Update Position for Node: " << n->GetId());
1984 Vector v = UpdatePosition(n);
1985 WriteXmlNode(n->GetId(), n->GetSystemId(), v.x, v.y);
1986 }
1987}
1988
1989void
1991{
1992 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
1993 {
1994 Ptr<Node> n = *i;
1995 Rgb rgb = {255, 0, 0};
1996 if (m_nodeColors.find(n->GetId()) == m_nodeColors.end())
1997 {
1998 m_nodeColors[n->GetId()] = rgb;
1999 }
2000 UpdateNodeColor(n, rgb.r, rgb.g, rgb.b);
2001 }
2002}
2003
2004void
2006{
2007 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2008 {
2009 Ptr<Node> n = *i;
2010 NS_LOG_INFO("Update Size for Node: " << n->GetId());
2012 m_nodeSizes[n->GetId()] = s;
2013 UpdateNodeSize(n->GetId(), s.width, s.height);
2014 }
2015}
2016
2017void
2019{
2022 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2023 {
2024 Ptr<Node> n = *i;
2025 if (NodeList::GetNode(n->GetId())->GetObject<energy::EnergySource>())
2026 {
2028 }
2029 }
2030}
2031
2032bool
2037
2038void
2039AnimationInterface::SetOutputFile(const std::string& fn, bool routing)
2040{
2041 if (!routing && m_f)
2042 {
2043 return;
2044 }
2045 if (routing && m_routingF)
2046 {
2047 NS_FATAL_ERROR("SetRoutingOutputFile already used once");
2048 return;
2049 }
2050
2051 NS_LOG_INFO("Creating new trace file:" << fn);
2052 FILE* f = nullptr;
2053 f = std::fopen(fn.c_str(), "w");
2054 if (!f)
2055 {
2056 NS_FATAL_ERROR("Unable to open output file:" << fn);
2057 return; // Can't open output file
2058 }
2059 if (routing)
2060 {
2061 m_routingF = f;
2062 m_routingFileName = fn;
2063 }
2064 else
2065 {
2066 m_f = f;
2067 m_outputFileName = fn;
2068 }
2069}
2070
2071void
2073{
2074 // Start a new trace file if the current packet count exceeded max packets per file
2077 {
2078 return;
2079 }
2080 NS_LOG_UNCOND("Max Packets per trace file exceeded");
2081 StopAnimation(true);
2082}
2083
2084std::string
2089
2090void
2092{
2094 {
2095 NS_LOG_INFO("TrackQueueCounters Completed");
2096 return;
2097 }
2098 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2099 {
2100 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2104 }
2106}
2107
2108void
2110{
2112 {
2113 NS_LOG_INFO("TrackWifiMacCounters Completed");
2114 return;
2115 }
2116 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2117 {
2118 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2123 }
2126 this);
2127}
2128
2129void
2131{
2133 {
2134 NS_LOG_INFO("TrackWifiPhyCounters Completed");
2135 return;
2136 }
2137 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2138 {
2139 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2142 }
2145 this);
2146}
2147
2148void
2150{
2152 {
2153 NS_LOG_INFO("TrackIpv4L3ProtocolCounters Completed");
2154 return;
2155 }
2156 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2157 {
2158 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2162 }
2165 this);
2166}
2167
2168/***** Routing-related *****/
2169
2170void
2172{
2173 if (m_ipv4RouteTrackElements.empty())
2174 {
2175 return;
2176 }
2177 for (auto i = m_ipv4RouteTrackElements.begin(); i != m_ipv4RouteTrackElements.end(); ++i)
2178 {
2179 Ipv4RouteTrackElement trackElement = *i;
2180 Ptr<Node> fromNode = NodeList::GetNode(trackElement.fromNodeId);
2181 if (!fromNode)
2182 {
2183 NS_FATAL_ERROR("Node: " << trackElement.fromNodeId << " Not found");
2184 continue;
2185 }
2186 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2187 if (!ipv4)
2188 {
2189 NS_LOG_WARN("ipv4 object not found");
2190 continue;
2191 }
2192 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2193 if (!rp)
2194 {
2195 NS_LOG_WARN("Routing protocol object not found");
2196 continue;
2197 }
2198 NS_LOG_INFO("Begin Track Route for: " << trackElement.destination
2199 << " From:" << trackElement.fromNodeId);
2201 Ipv4Header header;
2202 header.SetDestination(Ipv4Address(trackElement.destination.c_str()));
2203 Socket::SocketErrno sockerr;
2204 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2205 Ipv4RoutePathElements rpElements;
2206 if (!rt)
2207 {
2208 NS_LOG_INFO("No route to :" << trackElement.destination);
2209 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2210 rpElements.push_back(elem);
2211 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2212 continue;
2213 }
2214 std::ostringstream oss;
2215 oss << rt->GetGateway();
2216 NS_LOG_INFO("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway());
2217 if (rt->GetGateway() == "0.0.0.0")
2218 {
2219 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "C"};
2220 rpElements.push_back(elem);
2221 if (m_ipv4ToNodeIdMap.find(trackElement.destination) != m_ipv4ToNodeIdMap.end())
2222 {
2223 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[trackElement.destination], "L"};
2224 rpElements.push_back(elem2);
2225 }
2226 }
2227 else if (rt->GetGateway() == "127.0.0.1")
2228 {
2229 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2230 rpElements.push_back(elem);
2231 }
2232 else
2233 {
2234 Ipv4RoutePathElement elem = {trackElement.fromNodeId, oss.str()};
2235 rpElements.push_back(elem);
2236 }
2237 RecursiveIpv4RoutePathSearch(oss.str(), trackElement.destination, rpElements);
2238 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2239 }
2240}
2241
2242void
2244{
2246 {
2247 NS_LOG_INFO("TrackIpv4Route completed");
2248 return;
2249 }
2250 if (m_routingNc.GetN())
2251 {
2252 for (auto i = m_routingNc.Begin(); i != m_routingNc.End(); ++i)
2253 {
2254 Ptr<Node> n = *i;
2255 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2256 }
2257 }
2258 else
2259 {
2260 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
2261 {
2262 Ptr<Node> n = *i;
2263 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2264 }
2265 }
2268}
2269
2270std::string
2272{
2273 NS_ASSERT(n);
2274 Ptr<ns3::Ipv4> ipv4 = n->GetObject<ns3::Ipv4>();
2275 if (!ipv4)
2276 {
2277 NS_LOG_WARN("Node " << n->GetId() << " Does not have an Ipv4 object");
2278 return "";
2279 }
2280 std::stringstream stream;
2282 ipv4->GetRoutingProtocol()->PrintRoutingTable(routingstream);
2283 return stream.str();
2284}
2285
2286void
2288 std::string to,
2289 Ipv4RoutePathElements& rpElements)
2290{
2291 NS_LOG_INFO("RecursiveIpv4RoutePathSearch from:" << from << " to:" << to);
2292 if (from == "0.0.0.0" || from == "127.0.0.1")
2293 {
2294 NS_LOG_INFO("Got " << from << " End recursion");
2295 return;
2296 }
2299 if (fromNode->GetId() == toNode->GetId())
2300 {
2301 Ipv4RoutePathElement elem = {fromNode->GetId(), "L"};
2302 rpElements.push_back(elem);
2303 return;
2304 }
2305 if (!fromNode)
2306 {
2307 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2308 return;
2309 }
2310 if (!toNode)
2311 {
2312 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2313 return;
2314 }
2315 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2316 if (!ipv4)
2317 {
2318 NS_LOG_WARN("ipv4 object not found");
2319 return;
2320 }
2321 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2322 if (!rp)
2323 {
2324 NS_LOG_WARN("Routing protocol object not found");
2325 return;
2326 }
2328 Ipv4Header header;
2329 header.SetDestination(Ipv4Address(to.c_str()));
2330 Socket::SocketErrno sockerr;
2331 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2332 if (!rt)
2333 {
2334 return;
2335 }
2336 NS_LOG_DEBUG("Node: " << fromNode->GetId() << " G:" << rt->GetGateway());
2337 std::ostringstream oss;
2338 oss << rt->GetGateway();
2339 if (oss.str() == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2340 {
2341 NS_LOG_INFO("Null gw");
2342 Ipv4RoutePathElement elem = {fromNode->GetId(), "C"};
2343 rpElements.push_back(elem);
2344 if (m_ipv4ToNodeIdMap.find(to) != m_ipv4ToNodeIdMap.end())
2345 {
2346 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[to], "L"};
2347 rpElements.push_back(elem2);
2348 }
2349 return;
2350 }
2351 NS_LOG_INFO("Node:" << fromNode->GetId() << "-->" << rt->GetGateway());
2352 Ipv4RoutePathElement elem = {fromNode->GetId(), oss.str()};
2353 rpElements.push_back(elem);
2354 RecursiveIpv4RoutePathSearch(oss.str(), to, rpElements);
2355}
2356
2357/***** WriteXml *****/
2358
2359void
2361{
2362 AnimXmlElement element("anim");
2363 element.AddAttribute("ver", GetNetAnimVersion());
2364 FILE* f = m_f;
2365 if (!routing)
2366 {
2367 element.AddAttribute("filetype", "animation");
2368 }
2369 else
2370 {
2371 element.AddAttribute("filetype", "routing");
2372 f = m_routingF;
2373 }
2374 WriteN(element.ToString(false) + ">\n", f);
2375}
2376
2377void
2378AnimationInterface::WriteXmlClose(std::string name, bool routing)
2379{
2380 std::string closeString = "</" + name + ">\n";
2381 if (!routing)
2382 {
2383 WriteN(closeString, m_f);
2384 }
2385 else
2386 {
2387 WriteN(closeString, m_routingF);
2388 }
2389}
2390
2391void
2392AnimationInterface::WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
2393{
2394 AnimXmlElement element("node");
2395 element.AddAttribute("id", id);
2396 element.AddAttribute("sysId", sysId);
2397 element.AddAttribute("locX", locX);
2398 element.AddAttribute("locY", locY);
2399 WriteN(element.ToString(), m_f);
2400}
2401
2402void
2403AnimationInterface::WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string linkDescription)
2404{
2405 AnimXmlElement element("linkupdate");
2406 element.AddAttribute("t", Simulator::Now().GetSeconds());
2407 element.AddAttribute("fromId", fromId);
2408 element.AddAttribute("toId", toId);
2409 element.AddAttribute("ld", linkDescription, true);
2410 WriteN(element.ToString(), m_f);
2411}
2412
2413void
2415{
2416 AnimXmlElement element("link");
2417 element.AddAttribute("fromId", fromId);
2418 element.AddAttribute("toId", toId);
2419
2420 LinkProperties lprop;
2421 lprop.fromNodeDescription = "";
2422 lprop.toNodeDescription = "";
2423 lprop.linkDescription = "";
2424
2425 P2pLinkNodeIdPair p1 = {fromId, toId};
2426 P2pLinkNodeIdPair p2 = {toId, fromId};
2427 if (m_linkProperties.find(p1) != m_linkProperties.end())
2428 {
2429 lprop = m_linkProperties[p1];
2430 }
2431 else if (m_linkProperties.find(p2) != m_linkProperties.end())
2432 {
2433 lprop = m_linkProperties[p2];
2434 }
2435
2436 element.AddAttribute("fd", lprop.fromNodeDescription, true);
2437 element.AddAttribute("td", lprop.toNodeDescription, true);
2438 element.AddAttribute("ld", lprop.linkDescription, true);
2439 WriteN(element.ToString(), m_f);
2440}
2441
2442void
2443AnimationInterface::WriteXmlIpv4Addresses(uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2444{
2445 AnimXmlElement element("ip");
2446 element.AddAttribute("n", nodeId);
2447 for (auto i = ipv4Addresses.begin(); i != ipv4Addresses.end(); ++i)
2448 {
2449 AnimXmlElement valueElement("address");
2450 valueElement.SetText(*i);
2451 element.AppendChild(valueElement);
2452 }
2453 WriteN(element.ToString(), m_f);
2454}
2455
2456void
2457AnimationInterface::WriteXmlIpv6Addresses(uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2458{
2459 AnimXmlElement element("ipv6");
2460 element.AddAttribute("n", nodeId);
2461 for (auto i = ipv6Addresses.begin(); i != ipv6Addresses.end(); ++i)
2462 {
2463 AnimXmlElement valueElement("address");
2464 valueElement.SetText(*i);
2465 element.AppendChild(valueElement);
2466 }
2467 WriteN(element.ToString(), m_f);
2468}
2469
2470void
2471AnimationInterface::WriteXmlRouting(uint32_t nodeId, std::string routingInfo)
2472{
2473 AnimXmlElement element("rt");
2474 element.AddAttribute("t", Simulator::Now().GetSeconds());
2475 element.AddAttribute("id", nodeId);
2476 element.AddAttribute("info", routingInfo.c_str(), true);
2477 WriteN(element.ToString(), m_routingF);
2478}
2479
2480void
2482 std::string destination,
2483 Ipv4RoutePathElements rpElements)
2484{
2485 std::string tagName = "rp";
2486 AnimXmlElement element(tagName, false);
2487 element.AddAttribute("t", Simulator::Now().GetSeconds());
2488 element.AddAttribute("id", nodeId);
2489 element.AddAttribute("d", destination.c_str());
2490 element.AddAttribute("c", rpElements.size());
2491 for (const auto& rpElement : rpElements)
2492 {
2493 AnimXmlElement rpeElement("rpe");
2494 rpeElement.AddAttribute("n", rpElement.nodeId);
2495 rpeElement.AddAttribute("nH", rpElement.nextHop.c_str());
2496 element.AppendChild(rpeElement);
2497 }
2498 WriteN(element.ToString(), m_routingF);
2499}
2500
2501void
2502AnimationInterface::WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2503{
2504 AnimXmlElement element("pr");
2505 element.AddAttribute("uId", animUid);
2506 element.AddAttribute("fId", fId);
2507 element.AddAttribute("fbTx", fbTx);
2508 if (!metaInfo.empty())
2509 {
2510 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2511 }
2512 WriteN(element.ToString(), m_f);
2513}
2514
2515void
2517 std::string pktType,
2518 uint32_t tId,
2519 double fbRx,
2520 double lbRx)
2521{
2522 AnimXmlElement element(pktType);
2523 element.AddAttribute("uId", animUid);
2524 element.AddAttribute("tId", tId);
2525 element.AddAttribute("fbRx", fbRx);
2526 element.AddAttribute("lbRx", lbRx);
2527 WriteN(element.ToString(), m_f);
2528}
2529
2530void
2532 uint32_t fId,
2533 double fbTx,
2534 double lbTx,
2535 uint32_t tId,
2536 double fbRx,
2537 double lbRx,
2538 std::string metaInfo)
2539{
2540 AnimXmlElement element(pktType);
2541 element.AddAttribute("fId", fId);
2542 element.AddAttribute("fbTx", fbTx);
2543 element.AddAttribute("lbTx", lbTx);
2544 if (!metaInfo.empty())
2545 {
2546 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2547 }
2548 element.AddAttribute("tId", tId);
2549 element.AddAttribute("fbRx", fbRx);
2550 element.AddAttribute("lbRx", lbRx);
2551 WriteN(element.ToString(), m_f);
2552}
2553
2554void
2556 std::string counterName,
2557 CounterType counterType)
2558{
2559 AnimXmlElement element("ncs");
2560 element.AddAttribute("ncId", nodeCounterId);
2561 element.AddAttribute("n", counterName);
2562 element.AddAttribute("t", CounterTypeToString(counterType));
2563 WriteN(element.ToString(), m_f);
2564}
2565
2566void
2567AnimationInterface::WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
2568{
2569 AnimXmlElement element("res");
2570 element.AddAttribute("rid", resourceId);
2571 element.AddAttribute("p", resourcePath);
2572 WriteN(element.ToString(), m_f);
2573}
2574
2575void
2577{
2578 AnimXmlElement element("nu");
2579 element.AddAttribute("p", "i");
2580 element.AddAttribute("t", Simulator::Now().GetSeconds());
2581 element.AddAttribute("id", nodeId);
2582 element.AddAttribute("rid", resourceId);
2583 WriteN(element.ToString(), m_f);
2584}
2585
2586void
2587AnimationInterface::WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
2588{
2589 AnimXmlElement element("nu");
2590 element.AddAttribute("p", "s");
2591 element.AddAttribute("t", Simulator::Now().GetSeconds());
2592 element.AddAttribute("id", nodeId);
2593 element.AddAttribute("w", width);
2594 element.AddAttribute("h", height);
2595 WriteN(element.ToString(), m_f);
2596}
2597
2598void
2600{
2601 AnimXmlElement element("nu");
2602 element.AddAttribute("p", "p");
2603 element.AddAttribute("t", Simulator::Now().GetSeconds());
2604 element.AddAttribute("id", nodeId);
2605 element.AddAttribute("x", x);
2606 element.AddAttribute("y", y);
2607 WriteN(element.ToString(), m_f);
2608}
2609
2610void
2611AnimationInterface::WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2612{
2613 AnimXmlElement element("nu");
2614 element.AddAttribute("p", "c");
2615 element.AddAttribute("t", Simulator::Now().GetSeconds());
2616 element.AddAttribute("id", nodeId);
2617 element.AddAttribute("r", (uint32_t)r);
2618 element.AddAttribute("g", (uint32_t)g);
2619 element.AddAttribute("b", (uint32_t)b);
2620 WriteN(element.ToString(), m_f);
2621}
2622
2623void
2625{
2626 AnimXmlElement element("nu");
2627 element.AddAttribute("p", "d");
2628 element.AddAttribute("t", Simulator::Now().GetSeconds());
2629 element.AddAttribute("id", nodeId);
2630 if (m_nodeDescriptions.find(nodeId) != m_nodeDescriptions.end())
2631 {
2632 element.AddAttribute("descr", m_nodeDescriptions[nodeId], true);
2633 }
2634 WriteN(element.ToString(), m_f);
2635}
2636
2637void
2639 uint32_t nodeId,
2640 double counterValue)
2641{
2642 AnimXmlElement element("nc");
2643 element.AddAttribute("c", nodeCounterId);
2644 element.AddAttribute("i", nodeId);
2645 element.AddAttribute("t", Simulator::Now().GetSeconds());
2646 element.AddAttribute("v", counterValue);
2647 WriteN(element.ToString(), m_f);
2648}
2649
2650void
2652 double x,
2653 double y,
2654 double scaleX,
2655 double scaleY,
2656 double opacity)
2657{
2658 AnimXmlElement element("bg");
2659 element.AddAttribute("f", fileName);
2660 element.AddAttribute("x", x);
2661 element.AddAttribute("y", y);
2662 element.AddAttribute("sx", scaleX);
2663 element.AddAttribute("sy", scaleY);
2664 element.AddAttribute("o", opacity);
2665 WriteN(element.ToString(), m_f);
2666}
2667
2668void
2670 std::string ipAddress,
2671 std::string channelType)
2672{
2673 AnimXmlElement element("nonp2plinkproperties");
2674 element.AddAttribute("id", id);
2675 element.AddAttribute("ipAddress", ipAddress);
2676 element.AddAttribute("channelType", channelType);
2677 WriteN(element.ToString(), m_f);
2678}
2679
2680/***** AnimXmlElement *****/
2681
2682AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement)
2683 : m_tagName(tagName),
2684 m_text("")
2685{
2686}
2687
2688template <typename T>
2689void
2690AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape)
2691{
2692 std::ostringstream oss;
2693 oss << std::setprecision(10);
2694 oss << value;
2695 std::string attributeString = attribute;
2696 if (xmlEscape)
2697 {
2698 attributeString += "=\"";
2699 std::string valueStr = oss.str();
2700 for (auto it = valueStr.begin(); it != valueStr.end(); ++it)
2701 {
2702 switch (*it)
2703 {
2704 case '&':
2705 attributeString += "&amp;";
2706 break;
2707 case '\"':
2708 attributeString += "&quot;";
2709 break;
2710 case '\'':
2711 attributeString += "&apos;";
2712 break;
2713 case '<':
2714 attributeString += "&lt;";
2715 break;
2716 case '>':
2717 attributeString += "&gt;";
2718 break;
2719 default:
2720 attributeString += *it;
2721 break;
2722 }
2723 }
2724 attributeString += "\" ";
2725 }
2726 else
2727 {
2728 attributeString += "=\"" + oss.str() + "\" ";
2729 }
2730 m_attributes.push_back(attributeString);
2731}
2732
2733void
2738
2739void
2741{
2742 m_text = text;
2743}
2744
2745std::string
2747{
2748 std::string elementString = "<" + m_tagName + " ";
2749
2750 for (auto i = m_attributes.begin(); i != m_attributes.end(); ++i)
2751 {
2752 elementString += *i;
2753 }
2754 if (m_children.empty() && m_text.empty())
2755 {
2756 if (autoClose)
2757 {
2758 elementString += "/>";
2759 }
2760 }
2761 else
2762 {
2763 elementString += ">";
2764 if (!m_text.empty())
2765 {
2766 elementString += m_text;
2767 }
2768 if (!m_children.empty())
2769 {
2770 elementString += "\n";
2771 for (auto i = m_children.begin(); i != m_children.end(); ++i)
2772 {
2773 elementString += *i + "\n";
2774 }
2775 }
2776 if (autoClose)
2777 {
2778 elementString += "</" + m_tagName + ">";
2779 }
2780 }
2781
2782 return elementString + ((autoClose) ? "\n" : "");
2783}
2784
2785/***** AnimByteTag *****/
2786
2787TypeId
2789{
2790 static TypeId tid = TypeId("ns3::AnimByteTag")
2791 .SetParent<Tag>()
2792 .SetGroupName("NetAnim")
2793 .AddConstructor<AnimByteTag>();
2794 return tid;
2795}
2796
2797TypeId
2799{
2800 return GetTypeId();
2801}
2802
2805{
2806 return sizeof(uint64_t);
2807}
2808
2809void
2814
2815void
2820
2821void
2822AnimByteTag::Print(std::ostream& os) const
2823{
2824 os << "AnimUid=" << m_AnimUid;
2825}
2826
2827void
2828AnimByteTag::Set(uint64_t AnimUid)
2829{
2830 m_AnimUid = AnimUid;
2831}
2832
2833uint64_t
2835{
2836 return m_AnimUid;
2837}
2838
2840 : m_txnd(nullptr),
2841 m_txNodeId(0),
2842 m_fbTx(0),
2843 m_lbTx(0),
2844 m_lbRx(0)
2845{
2846}
2847
2849{
2850 m_txnd = pInfo.m_txnd;
2851 m_txNodeId = pInfo.m_txNodeId;
2852 m_fbTx = pInfo.m_fbTx;
2853 m_lbTx = pInfo.m_lbTx;
2854 m_lbRx = pInfo.m_lbRx;
2855}
2856
2858 const Time fbTx,
2859 uint32_t txNodeId)
2860 : m_txnd(txnd),
2861 m_txNodeId(0),
2862 m_fbTx(fbTx.GetSeconds()),
2863 m_lbTx(0),
2864 m_lbRx(0)
2865{
2866 if (!m_txnd)
2867 {
2868 m_txNodeId = txNodeId;
2869 }
2870}
2871
2872void
2874{
2875 Ptr<Node> n = nd->GetNode();
2876 m_fbRx = fbRx;
2877 m_rxnd = nd;
2878}
2879
2880} // 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.
uint64_t m_AnimUid
the UID
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.
std::vector< std::string > m_children
list of children
void SetText(std::string text)
Set text function.
std::vector< std::string > m_attributes
list of attributes
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 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
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(* AnimWriteCallback)(const char *str)
typedef for WriteCallBack used for listening to AnimationInterface write messages
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 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.
std::string m_originalFileName
original file name
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.
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.
keep track of a set of node pointers.
A network Node.
Definition node.h:46
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.
Definition ptr.h:67
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
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:96
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:394
a unique identifier for an interface.
Definition type-id.h:49
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.
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:980
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition config.cc:956
#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:439
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
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:448
std::map< WifiSpectrumBandInfo, Watt_u > RxPowerWattPerChannelBand
A map of the received power for each band.
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:585
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:38
uint8_t data[writeSize]