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