A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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#endif
39#include "animation-interface.h"
40
41#include "ns3/animation-interface.h"
42#include "ns3/channel.h"
43#include "ns3/config.h"
44#include "ns3/constant-position-mobility-model.h"
45#include "ns3/double.h"
46#include "ns3/energy-source-container.h"
47#include "ns3/ipv4-routing-protocol.h"
48#include "ns3/ipv4.h"
49#include "ns3/ipv6.h"
50#include "ns3/lr-wpan-mac-header.h"
51#include "ns3/lr-wpan-net-device.h"
52#include "ns3/lte-enb-phy.h"
53#include "ns3/lte-ue-phy.h"
54#include "ns3/mobility-model.h"
55#include "ns3/node.h"
56#include "ns3/packet.h"
57#include "ns3/simulator.h"
58#include "ns3/uan-mac.h"
59#include "ns3/uan-net-device.h"
60#include "ns3/wifi-mac-header.h"
61#include "ns3/wifi-mac.h"
62#include "ns3/wifi-net-device.h"
63#include "ns3/wifi-psdu.h"
64#include "ns3/wimax-mac-header.h"
65
66namespace ns3
67{
68
69NS_LOG_COMPONENT_DEFINE("AnimationInterface");
70
71// Globals
72
73static bool initialized = false;
74
75// Public methods
76
78 : m_f(nullptr),
79 m_routingF(nullptr),
80 m_mobilityPollInterval(Seconds(0.25)),
81 m_outputFileName(fn),
82 gAnimUid(0),
83 m_writeCallback(nullptr),
84 m_started(false),
85 m_enablePacketMetadata(false),
86 m_startTime(Seconds(0)),
87 m_stopTime(Seconds(3600 * 1000)),
88 m_maxPktsPerFile(MAX_PKTS_PER_TRACE_FILE),
89 m_originalFileName(fn),
90 m_routingStopTime(Seconds(0)),
91 m_routingFileName(""),
92 m_routingPollInterval(Seconds(5)),
93 m_trackPackets(true)
94{
95 initialized = true;
97
98#ifdef __WIN32__
114 static BaseStationNetDevice b;
115 static CsmaNetDevice c;
116 static WifiNetDevice w;
117 static UanNetDevice u;
118#endif
119}
120
122{
124}
125
126void
128{
129 m_trackPackets = false;
130}
131
132void
134{
136 m_wifiPhyCountersPollInterval = pollInterval;
139 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
140 {
141 Ptr<Node> n = *i;
142 m_nodeWifiPhyTxDrop[n->GetId()] = 0;
143 m_nodeWifiPhyRxDrop[n->GetId()] = 0;
146 }
148}
149
150void
152{
154 m_wifiMacCountersPollInterval = pollInterval;
159 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
160 {
161 Ptr<Node> n = *i;
162 m_nodeWifiMacTx[n->GetId()] = 0;
163 m_nodeWifiMacTxDrop[n->GetId()] = 0;
164 m_nodeWifiMacRx[n->GetId()] = 0;
165 m_nodeWifiMacRxDrop[n->GetId()] = 0;
170 }
172}
173
174void
176{
178 m_queueCountersPollInterval = pollInterval;
182 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
183 {
184 Ptr<Node> n = *i;
185 m_nodeQueueEnqueue[n->GetId()] = 0;
186 m_nodeQueueDequeue[n->GetId()] = 0;
187 m_nodeQueueDrop[n->GetId()] = 0;
191 }
193}
194
195void
197{
203 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
204 {
205 Ptr<Node> n = *i;
206 m_nodeIpv4Tx[n->GetId()] = 0;
207 m_nodeIpv4Rx[n->GetId()] = 0;
208 m_nodeIpv4Drop[n->GetId()] = 0;
212 }
214}
215
218 Time startTime,
220 Time pollInterval)
221{
222 SetOutputFile(fileName, true);
224 m_routingPollInterval = pollInterval;
225 WriteXmlAnim(true);
227 return *this;
228}
229
232 Time startTime,
234 NodeContainer nc,
235 Time pollInterval)
236{
237 m_routingNc = nc;
238 return EnableIpv4RouteTracking(fileName, startTime, stopTime, pollInterval);
239}
240
242AnimationInterface::AddSourceDestination(uint32_t fromNodeId, std::string ipv4Address)
243{
244 Ipv4RouteTrackElement element = {ipv4Address, fromNodeId};
245 m_ipv4RouteTrackElements.push_back(element);
246 return *this;
247}
248
249void
251{
252 m_startTime = t;
253}
254
255void
257{
258 m_stopTime = t;
259}
260
261void
263{
264 m_maxPktsPerFile = maxPacketsPerFile;
265}
266
268AnimationInterface::AddNodeCounter(std::string counterName, CounterType counterType)
269{
270 m_nodeCounters.push_back(counterName);
271 uint32_t counterId = m_nodeCounters.size() - 1; // counter ID is zero-indexed
272 WriteXmlAddNodeCounter(counterId, counterName, counterType);
273 return counterId;
274}
275
277AnimationInterface::AddResource(std::string resourcePath)
278{
279 m_resources.push_back(resourcePath);
280 uint32_t resourceId = m_resources.size() - 1; // resource ID is zero-indexed
281 WriteXmlAddResource(resourceId, resourcePath);
282 return resourceId;
283}
284
285void
287{
288 m_enablePacketMetadata = enable;
289 if (enable)
290 {
292 }
293}
294
295bool
297{
298 return initialized;
299}
300
301bool
303{
304 return m_started;
305}
306
307void
309{
310 m_writeCallback = cb;
311}
312
313void
315{
316 m_writeCallback = nullptr;
317}
318
319void
321{
323}
324
325void
327{
328 NS_ASSERT(n);
330 if (!loc)
331 {
332 loc = CreateObject<ConstantPositionMobilityModel>();
333 n->AggregateObject(loc);
334 }
335 Vector hubVec(x, y, z);
336 loc->SetPosition(hubVec);
337 NS_LOG_INFO("Node:" << n->GetId() << " Position set to:(" << x << "," << y << "," << z << ")");
338}
339
340void
342{
343 NS_LOG_INFO("Setting node image for Node Id:" << nodeId);
344 if (resourceId > (m_resources.size() - 1))
345 {
346 NS_FATAL_ERROR("Resource Id:" << resourceId << " not found. Did you use AddResource?");
347 }
348 WriteXmlUpdateNodeImage(nodeId, resourceId);
349}
350
351void
352AnimationInterface::UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
353{
354 if (nodeCounterId > (m_nodeCounters.size() - 1))
355 {
356 NS_FATAL_ERROR("NodeCounter Id:" << nodeCounterId
357 << " not found. Did you use AddNodeCounter?");
358 }
359 WriteXmlUpdateNodeCounter(nodeCounterId, nodeId, counter);
360}
361
362void
364 double x,
365 double y,
366 double scaleX,
367 double scaleY,
368 double opacity)
369{
370 if ((opacity < 0) || (opacity > 1))
371 {
372 NS_FATAL_ERROR("Opacity must be between 0.0 and 1.0");
373 }
374 WriteXmlUpdateBackground(fileName, x, y, scaleX, scaleY, opacity);
375}
376
377void
378AnimationInterface::UpdateNodeSize(Ptr<Node> n, double width, double height)
379{
380 UpdateNodeSize(n->GetId(), width, height);
381}
382
383void
384AnimationInterface::UpdateNodeSize(uint32_t nodeId, double width, double height)
385{
386 AnimationInterface::NodeSize s = {width, height};
387 m_nodeSizes[nodeId] = s;
388 WriteXmlUpdateNodeSize(nodeId, s.width, s.height);
389}
390
391void
392AnimationInterface::UpdateNodeColor(Ptr<Node> n, uint8_t r, uint8_t g, uint8_t b)
393{
394 UpdateNodeColor(n->GetId(), r, g, b);
395}
396
397void
398AnimationInterface::UpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
399{
401 NS_LOG_INFO("Setting node color for Node Id:" << nodeId);
402 Rgb rgb = {r, g, b};
403 m_nodeColors[nodeId] = rgb;
404 WriteXmlUpdateNodeColor(nodeId, r, g, b);
405}
406
407void
409 uint32_t toNode,
410 std::string linkDescription)
411{
412 WriteXmlUpdateLink(fromNode, toNode, linkDescription);
413}
414
415void
417 Ptr<Node> toNode,
418 std::string linkDescription)
419{
420 NS_ASSERT(fromNode);
421 NS_ASSERT(toNode);
422 WriteXmlUpdateLink(fromNode->GetId(), toNode->GetId(), linkDescription);
423}
424
425void
427{
428 UpdateNodeDescription(n->GetId(), descr);
429}
430
431void
433{
435 m_nodeDescriptions[nodeId] = descr;
437}
438
439// Private methods
440
441double
443{
444 const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find(node->GetId());
445 NS_ASSERT(fractionIter != m_nodeEnergyFraction.end());
446 return fractionIter->second;
447}
448
449void
451{
453 Ptr<Node> n = mobility->GetObject<Node>();
454 NS_ASSERT(n);
455 Vector v;
456 if (!mobility)
457 {
458 v = GetPosition(n);
459 }
460 else
461 {
462 v = mobility->GetPosition();
463 }
464 UpdatePosition(n, v);
465 WriteXmlUpdateNodePosition(n->GetId(), v.x, v.y);
466}
467
468bool
470{
471 Vector oldLocation = GetPosition(n);
472 bool moved = !((ceil(oldLocation.x) == ceil(newLocation.x)) &&
473 (ceil(oldLocation.y) == ceil(newLocation.y)));
474 return moved;
475}
476
477void
479{
481 std::vector<Ptr<Node>> MovedNodes = GetMovedNodes();
482 for (uint32_t i = 0; i < MovedNodes.size(); i++)
483 {
484 Ptr<Node> n = MovedNodes[i];
485 NS_ASSERT(n);
486 Vector v = GetPosition(n);
487 WriteXmlUpdateNodePosition(n->GetId(), v.x, v.y);
488 }
490 {
497 }
498}
499
500std::vector<Ptr<Node>>
502{
503 std::vector<Ptr<Node>> movedNodes;
504 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
505 {
506 Ptr<Node> n = *i;
507 NS_ASSERT(n);
508 Ptr<MobilityModel> mobility = n->GetObject<MobilityModel>();
509 Vector newLocation;
510 if (!mobility)
511 {
512 newLocation = GetPosition(n);
513 }
514 else
515 {
516 newLocation = mobility->GetPosition();
517 }
518 if (!NodeHasMoved(n, newLocation))
519 {
520 continue; // Location has not changed
521 }
522 else
523 {
524 UpdatePosition(n, newLocation);
525 movedNodes.push_back(n);
526 }
527 }
528 return movedNodes;
529}
530
531int
532AnimationInterface::WriteN(const std::string& st, FILE* f)
533{
534 if (!f)
535 {
536 return 0;
537 }
538 if (m_writeCallback)
539 {
540 m_writeCallback(st.c_str());
541 }
542 return WriteN(st.c_str(), st.length(), f);
543}
544
545int
546AnimationInterface::WriteN(const char* data, uint32_t count, FILE* f)
547{
548 if (!f)
549 {
550 return 0;
551 }
552 // Write count bytes to h from data
553 uint32_t nLeft = count;
554 const char* p = data;
555 uint32_t written = 0;
556 while (nLeft)
557 {
558 int n = std::fwrite(p, 1, nLeft, f);
559 if (n <= 0)
560 {
561 return written;
562 }
563 written += n;
564 nLeft -= n;
565 p += n;
566 }
567 return written;
568}
569
570void
572 std::string destination,
573 Ipv4RoutePathElements rpElements)
574{
575 NS_LOG_INFO("Writing Route Path From :" << nodeId << " To: " << destination);
576 WriteXmlRp(nodeId, destination, rpElements);
577 /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
578 i != rpElements.end ();
579 ++i)
580 {
581 Ipv4RoutePathElement rpElement = *i;
582 NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
583 WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
584
585 }
586 */
587}
588
589void
591 std::string ipv4Address,
592 std::string channelType)
593{
594 WriteXmlNonP2pLinkProperties(id, ipv4Address, channelType);
595}
596
597const std::vector<std::string>
598AnimationInterface::GetElementsFromContext(const std::string& context) const
599{
600 std::vector<std::string> elements;
601 std::size_t pos1 = 0;
602 std::size_t pos2;
603 while (pos1 != std::string::npos)
604 {
605 pos1 = context.find('/', pos1);
606 pos2 = context.find('/', pos1 + 1);
607 elements.push_back(context.substr(pos1 + 1, pos2 - (pos1 + 1)));
608 pos1 = pos2;
609 pos2 = std::string::npos;
610 }
611 return elements;
612}
613
615AnimationInterface::GetNodeFromContext(const std::string& context) const
616{
617 // Use "NodeList/*/ as reference
618 // where element [1] is the Node Id
619
620 std::vector<std::string> elements = GetElementsFromContext(context);
621 Ptr<Node> n = NodeList::GetNode(std::stoi(elements.at(1)));
622 NS_ASSERT(n);
623
624 return n;
625}
626
629{
630 // Use "NodeList/*/DeviceList/*/ as reference
631 // where element [1] is the Node Id
632 // element [2] is the NetDevice Id
633
634 std::vector<std::string> elements = GetElementsFromContext(context);
635 Ptr<Node> n = GetNodeFromContext(context);
636
637 return n->GetDevice(std::stoi(elements.at(3)));
638}
639
640uint64_t
642{
643 AnimByteTag tag;
644 TypeId tid = tag.GetInstanceTypeId();
645 ByteTagIterator i = p->GetByteTagIterator();
646 bool found = false;
647 while (i.HasNext())
648 {
649 ByteTagIterator::Item item = i.Next();
650 if (tid == item.GetTypeId())
651 {
652 item.GetTag(tag);
653 found = true;
654 }
655 }
656 if (found)
657 {
658 return tag.Get();
659 }
660 else
661 {
662 return 0;
663 }
664}
665
666void
668{
669 AnimByteTag tag;
670 tag.Set(animUid);
671 p->AddByteTag(tag);
672}
673
674void
676 double previousEnergy,
677 double currentEnergy)
678{
680 const Ptr<const Node> node = GetNodeFromContext(context);
681 const uint32_t nodeId = node->GetId();
682
683 NS_LOG_INFO("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
684
685 const Ptr<EnergySource> energySource = node->GetObject<EnergySource>();
686
687 NS_ASSERT(energySource);
688 // Don't call GetEnergyFraction () because of recursion
689 const double energyFraction = currentEnergy / energySource->GetInitialEnergy();
690
691 NS_LOG_INFO("Total energy fraction on node " << nodeId << ": " << energyFraction);
692
693 m_nodeEnergyFraction[nodeId] = energyFraction;
694 UpdateNodeCounter(m_remainingEnergyCounterId, nodeId, energyFraction);
695}
696
697void
699{
700 const Ptr<const Node> node = GetNodeFromContext(context);
701 ++m_nodeWifiPhyTxDrop[node->GetId()];
702}
703
704void
708{
709 const Ptr<const Node> node = GetNodeFromContext(context);
710 ++m_nodeWifiPhyRxDrop[node->GetId()];
711}
712
713void
715{
716 const Ptr<const Node> node = GetNodeFromContext(context);
717 ++m_nodeWifiMacTx[node->GetId()];
718}
719
720void
722{
723 const Ptr<const Node> node = GetNodeFromContext(context);
724 ++m_nodeWifiMacTxDrop[node->GetId()];
725}
726
727void
729{
730 const Ptr<const Node> node = GetNodeFromContext(context);
731 ++m_nodeWifiMacRx[node->GetId()];
732}
733
734void
736{
737 const Ptr<const Node> node = GetNodeFromContext(context);
738 ++m_nodeWifiMacRxDrop[node->GetId()];
739}
740
741void
743{
744 const Ptr<const Node> node = GetNodeFromContext(context);
745 ++m_nodeLrWpanMacTx[node->GetId()];
746}
747
748void
750{
751 const Ptr<const Node> node = GetNodeFromContext(context);
752 ++m_nodeLrWpanMacTxDrop[node->GetId()];
753}
754
755void
757{
758 const Ptr<const Node> node = GetNodeFromContext(context);
759 ++m_nodeLrWpanMacRx[node->GetId()];
760}
761
762void
764{
765 const Ptr<const Node> node = GetNodeFromContext(context);
766 ++m_nodeLrWpanMacRxDrop[node->GetId()];
767}
768
769void
772 Ptr<Ipv4> ipv4,
773 uint32_t interfaceIndex)
774{
775 const Ptr<const Node> node = GetNodeFromContext(context);
776 ++m_nodeIpv4Tx[node->GetId()];
777}
778
779void
782 Ptr<Ipv4> ipv4,
783 uint32_t interfaceIndex)
784{
785 const Ptr<const Node> node = GetNodeFromContext(context);
786 ++m_nodeIpv4Rx[node->GetId()];
787}
788
789void
791 const Ipv4Header& ipv4Header,
794 Ptr<Ipv4> ipv4,
795 uint32_t)
796{
797 const Ptr<const Node> node = GetNodeFromContext(context);
798 ++m_nodeIpv4Drop[node->GetId()];
799}
800
801void
803{
804 const Ptr<const Node> node = GetNodeFromContext(context);
805 ++m_nodeQueueEnqueue[node->GetId()];
806}
807
808void
810{
811 const Ptr<const Node> node = GetNodeFromContext(context);
812 ++m_nodeQueueDequeue[node->GetId()];
813}
814
815void
817{
818 const Ptr<const Node> node = GetNodeFromContext(context);
819 ++m_nodeQueueDrop[node->GetId()];
820}
821
822void
827 Time txTime,
828 Time rxTime)
829{
830 NS_LOG_FUNCTION(this);
832 NS_ASSERT(tx);
833 NS_ASSERT(rx);
834 Time now = Simulator::Now();
835 double fbTx = now.GetSeconds();
836 double lbTx = (now + txTime).GetSeconds();
837 double fbRx = (now + rxTime - txTime).GetSeconds();
838 double lbRx = (now + rxTime).GetSeconds();
840 WriteXmlP("p",
841 tx->GetNode()->GetId(),
842 fbTx,
843 lbTx,
844 rx->GetNode()->GetId(),
845 fbRx,
846 lbRx,
848}
849
850void
853 ProtocolType protocolType)
854{
855 NS_LOG_FUNCTION(this);
858 NS_ASSERT(ndev);
859 UpdatePosition(ndev);
860
861 ++gAnimUid;
863 << " GenericWirelessTxTrace for packet:" << gAnimUid);
865 AnimPacketInfo pktInfo(ndev, Simulator::Now());
866 AddPendingPacket(protocolType, gAnimUid, pktInfo);
867
868 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice>(ndev);
869 if (netDevice)
870 {
871 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
872 std::ostringstream oss;
873 oss << nodeAddr;
874 Ptr<Node> n = netDevice->GetNode();
875 NS_ASSERT(n);
876 m_macToNodeIdMap[oss.str()] = n->GetId();
877 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
878 }
879 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
880 OutputWirelessPacketTxInfo(p, pendingPackets->at(gAnimUid), gAnimUid);
881}
882
883void
886 ProtocolType protocolType)
887{
888 NS_LOG_FUNCTION(this);
891 NS_ASSERT(ndev);
892 UpdatePosition(ndev);
893 uint64_t animUid = GetAnimUidFromPacket(p);
894 NS_LOG_INFO(ProtocolTypeToString(protocolType) << " for packet:" << animUid);
895 if (!IsPacketPending(animUid, protocolType))
896 {
897 NS_LOG_WARN(ProtocolTypeToString(protocolType) << " GenericWirelessRxTrace: unknown Uid");
898 return;
899 }
900 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
901 pendingPackets->at(animUid).ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
902 OutputWirelessPacketRxInfo(p, pendingPackets->at(animUid), animUid);
903}
904
905void
907{
908 NS_LOG_FUNCTION(this);
910}
911
912void
914{
915 NS_LOG_FUNCTION(this);
917}
918
919void
921 WifiConstPsduMap psduMap,
922 WifiTxVector /* txVector */,
923 double /* txPowerW */)
924{
925 NS_LOG_FUNCTION(this);
928 NS_ASSERT(ndev);
929 UpdatePosition(ndev);
930
931 AnimPacketInfo pktInfo(ndev, Simulator::Now());
933 for (auto& psdu : psduMap)
934 {
935 for (auto& mpdu : *PeekPointer(psdu.second))
936 {
937 ++gAnimUid;
938 NS_LOG_INFO("WifiPhyTxTrace for MPDU:" << gAnimUid);
940 mpdu->GetPacket()); // the underlying MSDU/A-MSDU should be handed off
941 AddPendingPacket(WIFI, gAnimUid, pktInfo);
943 mpdu->GetProtocolDataUnit(),
944 pendingPackets->at(gAnimUid),
945 gAnimUid); // PDU should be considered in order to have header
946 }
947 }
948
949 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice>(ndev);
950 if (netDevice)
951 {
952 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
953 std::ostringstream oss;
954 oss << nodeAddr;
955 Ptr<Node> n = netDevice->GetNode();
956 NS_ASSERT(n);
957 m_macToNodeIdMap[oss.str()] = n->GetId();
958 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
959 }
960 else
961 {
962 NS_ABORT_MSG("This NetDevice should be a Wi-Fi network device");
963 }
964}
965
966void
970{
971 NS_LOG_FUNCTION(this);
974 NS_ASSERT(ndev);
975 UpdatePosition(ndev);
976 uint64_t animUid = GetAnimUidFromPacket(p);
977 NS_LOG_INFO("Wifi RxBeginTrace for packet: " << animUid);
979 {
980 NS_ASSERT_MSG(false, "WifiPhyRxBeginTrace: unknown Uid");
981 std::ostringstream oss;
982 WifiMacHeader hdr;
983 if (!p->PeekHeader(hdr))
984 {
985 NS_LOG_WARN("WifiMacHeader not present");
986 return;
987 }
988 oss << hdr.GetAddr2();
989 if (m_macToNodeIdMap.find(oss.str()) == m_macToNodeIdMap.end())
990 {
991 NS_LOG_WARN("Transmitter Mac address " << oss.str() << " never seen before. Skipping");
992 return;
993 }
994 Ptr<Node> txNode = NodeList::GetNode(m_macToNodeIdMap[oss.str()]);
995 UpdatePosition(txNode);
996 AnimPacketInfo pktInfo(nullptr, Simulator::Now(), m_macToNodeIdMap[oss.str()]);
998 NS_LOG_WARN("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
999 }
1001 m_pendingWifiPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1003}
1004
1005void
1007{
1008 NS_LOG_FUNCTION(this);
1010
1012 NS_ASSERT(ndev);
1013 Ptr<LrWpanNetDevice> netDevice = DynamicCast<LrWpanNetDevice>(ndev);
1014
1015 Ptr<Node> n = ndev->GetNode();
1016 NS_ASSERT(n);
1017
1018 UpdatePosition(n);
1019
1020 LrWpanMacHeader hdr;
1021 if (!p->PeekHeader(hdr))
1022 {
1023 NS_LOG_WARN("LrWpanMacHeader not present");
1024 return;
1025 }
1026
1027 std::ostringstream oss;
1028 if (hdr.GetSrcAddrMode() == 2)
1029 {
1030 Mac16Address nodeAddr = netDevice->GetMac()->GetShortAddress();
1031 oss << nodeAddr;
1032 }
1033 else if (hdr.GetSrcAddrMode() == 3)
1034 {
1035 Mac64Address nodeAddr = netDevice->GetMac()->GetExtendedAddress();
1036 oss << nodeAddr;
1037 }
1038 else
1039 {
1040 NS_LOG_WARN("LrWpanMacHeader without source address");
1041 return;
1042 }
1043 m_macToNodeIdMap[oss.str()] = n->GetId();
1044 NS_LOG_INFO("Added Mac" << oss.str() << " node:" << m_macToNodeIdMap[oss.str()]);
1045
1046 ++gAnimUid;
1047 NS_LOG_INFO("LrWpan TxBeginTrace for packet:" << gAnimUid);
1048 AddByteTag(gAnimUid, p);
1049
1050 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1052
1054}
1055
1056void
1058{
1059 NS_LOG_FUNCTION(this);
1062 NS_ASSERT(ndev);
1063 Ptr<Node> n = ndev->GetNode();
1064 NS_ASSERT(n);
1065
1066 AnimByteTag tag;
1067 if (!p->FindFirstMatchingByteTag(tag))
1068 {
1069 return;
1070 }
1071
1072 uint64_t animUid = GetAnimUidFromPacket(p);
1073 NS_LOG_INFO("LrWpan RxBeginTrace for packet:" << animUid);
1075 {
1076 NS_LOG_WARN("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK.");
1077 }
1078
1079 UpdatePosition(n);
1080 m_pendingLrWpanPackets[animUid].ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1082}
1083
1084void
1086{
1087 NS_LOG_FUNCTION(this);
1089}
1090
1091void
1093{
1094 NS_LOG_FUNCTION(this);
1096}
1097
1098void
1100{
1101 NS_LOG_FUNCTION(this);
1103}
1104
1105void
1107{
1108 NS_LOG_FUNCTION(this);
1110}
1111
1112void
1114{
1115 NS_LOG_FUNCTION(this);
1117 if (!pb)
1118 {
1119 NS_LOG_WARN("pb == 0. Not yet supported");
1120 return;
1121 }
1122 context = "/" + context;
1124 NS_ASSERT(ndev);
1125 UpdatePosition(ndev);
1126
1127 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1128 for (std::list<Ptr<Packet>>::iterator i = pbList.begin(); i != pbList.end(); ++i)
1129 {
1130 Ptr<Packet> p = *i;
1131 ++gAnimUid;
1132 NS_LOG_INFO("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1133 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1134 AddByteTag(gAnimUid, p);
1137 }
1138}
1139
1140void
1142{
1143 NS_LOG_FUNCTION(this);
1145 if (!pb)
1146 {
1147 NS_LOG_WARN("pb == 0. Not yet supported");
1148 return;
1149 }
1150 context = "/" + context;
1152 NS_ASSERT(ndev);
1153 UpdatePosition(ndev);
1154
1155 std::list<Ptr<Packet>> pbList = pb->GetPackets();
1156 for (std::list<Ptr<Packet>>::iterator i = pbList.begin(); i != pbList.end(); ++i)
1157 {
1158 Ptr<Packet> p = *i;
1159 uint64_t animUid = GetAnimUidFromPacket(p);
1160 NS_LOG_INFO("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1162 {
1163 NS_LOG_WARN("LteSpectrumPhyRxTrace: unknown Uid");
1164 return;
1165 }
1166 AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid];
1167 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1168 OutputWirelessPacketRxInfo(p, pktInfo, animUid);
1169 }
1170}
1171
1172void
1174{
1175 NS_LOG_FUNCTION(this);
1178 NS_ASSERT(ndev);
1179 UpdatePosition(ndev);
1180 ++gAnimUid;
1181 NS_LOG_INFO("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1182 AddByteTag(gAnimUid, p);
1183 UpdatePosition(ndev);
1184 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1186}
1187
1188void
1190{
1191 NS_LOG_FUNCTION(this);
1194 NS_ASSERT(ndev);
1195 UpdatePosition(ndev);
1196 uint64_t animUid = GetAnimUidFromPacket(p);
1197 NS_LOG_INFO("CsmaPhyTxEndTrace for packet:" << animUid);
1199 {
1200 NS_LOG_WARN("CsmaPhyTxEndTrace: unknown Uid");
1201 NS_FATAL_ERROR("CsmaPhyTxEndTrace: unknown Uid");
1202 AnimPacketInfo pktInfo(ndev, Simulator::Now());
1203 AddPendingPacket(AnimationInterface::CSMA, animUid, pktInfo);
1204 NS_LOG_WARN("Unknown Uid, but adding Csma Packet anyway");
1205 }
1207 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1208 pktInfo.m_lbTx = Simulator::Now().GetSeconds();
1209}
1210
1211void
1213{
1214 NS_LOG_FUNCTION(this);
1217 NS_ASSERT(ndev);
1218 UpdatePosition(ndev);
1219 uint64_t animUid = GetAnimUidFromPacket(p);
1221 {
1222 NS_LOG_WARN("CsmaPhyRxEndTrace: unknown Uid");
1223 return;
1224 }
1226 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1227 pktInfo.ProcessRxBegin(ndev, Simulator::Now().GetSeconds());
1228 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid);
1229 NS_LOG_INFO("CsmaPhyRxEndTrace for packet:" << animUid << " complete");
1230 OutputCsmaPacket(p, pktInfo);
1231}
1232
1233void
1235{
1236 NS_LOG_FUNCTION(this);
1239 NS_ASSERT(ndev);
1240 uint64_t animUid = GetAnimUidFromPacket(p);
1242 {
1243 NS_LOG_WARN("CsmaMacRxTrace: unknown Uid");
1244 return;
1245 }
1247 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid];
1248 NS_LOG_INFO("MacRxTrace for packet:" << animUid << " complete");
1249 OutputCsmaPacket(p, pktInfo);
1250}
1251
1252void
1254 AnimPacketInfo& pktInfo,
1255 uint64_t animUid)
1256{
1258 uint32_t nodeId = 0;
1259 if (pktInfo.m_txnd)
1260 {
1261 nodeId = pktInfo.m_txnd->GetNode()->GetId();
1262 }
1263 else
1264 {
1265 nodeId = pktInfo.m_txNodeId;
1266 }
1267 WriteXmlPRef(animUid,
1268 nodeId,
1269 pktInfo.m_fbTx,
1271}
1272
1273void
1275 AnimPacketInfo& pktInfo,
1276 uint64_t animUid)
1277{
1279 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1280 WriteXmlP(animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx);
1281}
1282
1283void
1285{
1287 NS_ASSERT(pktInfo.m_txnd);
1288 uint32_t nodeId = pktInfo.m_txnd->GetNode()->GetId();
1289 uint32_t rxId = pktInfo.m_rxnd->GetNode()->GetId();
1290
1291 WriteXmlP("p",
1292 nodeId,
1293 pktInfo.m_fbTx,
1294 pktInfo.m_lbTx,
1295 rxId,
1296 pktInfo.m_fbRx,
1297 pktInfo.m_lbRx,
1299}
1300
1301void
1303 uint64_t animUid,
1304 AnimPacketInfo pktInfo)
1305{
1306 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1307 NS_ASSERT(pendingPackets);
1308 pendingPackets->insert(AnimUidPacketInfoMap::value_type(animUid, pktInfo));
1309}
1310
1311bool
1313{
1314 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1315 NS_ASSERT(pendingPackets);
1316 return (pendingPackets->find(animUid) != pendingPackets->end());
1317}
1318
1319void
1321{
1322 AnimUidPacketInfoMap* pendingPackets = ProtocolTypeToPendingPackets(protocolType);
1323 NS_ASSERT(pendingPackets);
1324 if (pendingPackets->empty())
1325 {
1326 return;
1327 }
1328 std::vector<uint64_t> purgeList;
1329 for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin(); i != pendingPackets->end();
1330 ++i)
1331 {
1332 AnimPacketInfo pktInfo = i->second;
1333 double delta = (Simulator::Now().GetSeconds() - pktInfo.m_fbTx);
1334 if (delta > PURGE_INTERVAL)
1335 {
1336 purgeList.push_back(i->first);
1337 }
1338 }
1339 for (std::vector<uint64_t>::iterator i = purgeList.begin(); i != purgeList.end(); ++i)
1340 {
1341 pendingPackets->erase(*i);
1342 }
1343}
1344
1347{
1348 AnimUidPacketInfoMap* pendingPackets = nullptr;
1349 switch (protocolType)
1350 {
1352 pendingPackets = &m_pendingWifiPackets;
1353 break;
1354 }
1356 pendingPackets = &m_pendingUanPackets;
1357 break;
1358 }
1360 pendingPackets = &m_pendingCsmaPackets;
1361 break;
1362 }
1364 pendingPackets = &m_pendingWimaxPackets;
1365 break;
1366 }
1368 pendingPackets = &m_pendingLtePackets;
1369 break;
1370 }
1372 pendingPackets = &m_pendingLrWpanPackets;
1373 break;
1374 }
1375 }
1376 return pendingPackets;
1377}
1378
1379std::string
1381{
1382 std::string result = "Unknown";
1383 switch (protocolType)
1384 {
1386 result = "WIFI";
1387 break;
1388 }
1390 result = "UAN";
1391 break;
1392 }
1394 result = "CSMA";
1395 break;
1396 }
1398 result = "WIMAX";
1399 break;
1400 }
1402 result = "LTE";
1403 break;
1404 }
1406 result = "LRWPAN";
1407 break;
1408 }
1409 }
1410 return result;
1411}
1412
1413// Counters
1414
1415std::string
1417{
1418 std::string typeString = "unknown";
1419 switch (counterType)
1420 {
1421 case UINT32_COUNTER: {
1422 typeString = "UINT32";
1423 break;
1424 }
1425 case DOUBLE_COUNTER: {
1426 typeString = "DOUBLE";
1427 break;
1428 }
1429 }
1430 return typeString;
1431}
1432
1433// General
1434
1435std::string
1437{
1438 std::ostringstream oss;
1439 p->Print(oss);
1440 return oss.str();
1441}
1442
1443uint64_t
1445{
1446 return m_currentPktCount;
1447}
1448
1449void
1451{
1452 m_started = false;
1453 NS_LOG_INFO("Stopping Animation");
1455 if (m_f)
1456 {
1457 // Terminate the anim element
1458 WriteXmlClose("anim");
1459 std::fclose(m_f);
1460 m_f = nullptr;
1461 }
1462 if (onlyAnimation)
1463 {
1464 return;
1465 }
1466 if (m_routingF)
1467 {
1468 WriteXmlClose("anim", true);
1469 std::fclose(m_routingF);
1470 m_routingF = nullptr;
1471 }
1472}
1473
1474void
1476{
1478 m_started = true;
1480 WriteXmlAnim();
1481 WriteNodes();
1488 if (!restart)
1489 {
1492 }
1493}
1494
1495void
1497{
1498 m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
1499 m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address));
1500}
1501
1502void
1503AnimationInterface::AddToIpv4AddressNodeIdTable(std::vector<std::string> ipv4Addresses,
1504 uint32_t nodeId)
1505{
1506 for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin();
1507 i != ipv4Addresses.end();
1508 ++i)
1509 {
1510 AddToIpv4AddressNodeIdTable(*i, nodeId);
1511 }
1512}
1513
1514void
1516{
1517 m_ipv6ToNodeIdMap[ipv6Address] = nodeId;
1518 m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address));
1519}
1520
1521void
1522AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector<std::string> ipv6Addresses,
1523 uint32_t nodeId)
1524{
1525 for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin();
1526 i != ipv6Addresses.end();
1527 ++i)
1528 {
1529 AddToIpv6AddressNodeIdTable(*i, nodeId);
1530 }
1531}
1532
1533// Callbacks
1534void
1536{
1537 Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy();
1538 Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy();
1539 Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy();
1540 std::ostringstream oss;
1541 // NodeList/*/DeviceList/*/
1542 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1543 if (dlPhy)
1544 {
1545 dlPhy->TraceConnect("TxStart",
1546 oss.str(),
1548 dlPhy->TraceConnect("RxStart",
1549 oss.str(),
1551 }
1552 if (ulPhy)
1553 {
1554 ulPhy->TraceConnect("TxStart",
1555 oss.str(),
1557 ulPhy->TraceConnect("RxStart",
1558 oss.str(),
1560 }
1561}
1562
1563void
1565{
1566 Ptr<LteUePhy> lteUePhy = nd->GetPhy();
1567 Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy();
1568 Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy();
1569 std::ostringstream oss;
1570 // NodeList/*/DeviceList/*/
1571 oss << "NodeList/" << n->GetId() << "/DeviceList/" << devIndex << "/";
1572 if (dlPhy)
1573 {
1574 dlPhy->TraceConnect("TxStart",
1575 oss.str(),
1577 dlPhy->TraceConnect("RxStart",
1578 oss.str(),
1580 }
1581 if (ulPhy)
1582 {
1583 ulPhy->TraceConnect("TxStart",
1584 oss.str(),
1586 ulPhy->TraceConnect("RxStart",
1587 oss.str(),
1589 }
1590}
1591
1592void
1594{
1595 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
1596 {
1597 Ptr<Node> n = *i;
1598 NS_ASSERT(n);
1599 uint32_t nDevices = n->GetNDevices();
1600 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
1601 {
1602 Ptr<NetDevice> nd = n->GetDevice(devIndex);
1603 if (!nd)
1604 {
1605 continue;
1606 }
1607 Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice>(nd);
1608 if (lteUeNetDevice)
1609 {
1610 ConnectLteUe(n, lteUeNetDevice, devIndex);
1611 continue;
1612 }
1613 Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice>(nd);
1614 if (lteEnbNetDevice)
1615 {
1616 ConnectLteEnb(n, lteEnbNetDevice, devIndex);
1617 }
1618 }
1619 }
1620}
1621
1622void
1624{
1625 // Connect the callbacks
1626 Config::ConnectFailSafe("/ChannelList/*/TxRxPointToPoint",
1628 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
1630 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
1633 "/NodeList/*/$ns3::MobilityModel/CourseChange",
1635 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
1637 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
1639 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
1641 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
1643 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
1645 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
1647 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
1649 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
1651 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
1653 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
1655 Config::ConnectFailSafe("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
1657
1658 ConnectLte();
1659
1660 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
1662 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
1664 Config::ConnectFailSafe("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
1666
1667 // Queue Enqueues
1668
1669 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue",
1671 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue",
1673 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue",
1675
1676 // Queue Dequeues
1677
1678 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue",
1680 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue",
1682 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue",
1684
1685 // Queue Drops
1686
1687 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop",
1689 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop",
1691 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop",
1693
1694 // Wifi Mac
1695 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
1697 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
1699 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
1701 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
1703
1704 // Wifi Phy
1705 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop",
1707 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
1709
1710 // LrWpan
1711 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin",
1713 Config::ConnectFailSafe("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin",
1715 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx",
1717 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop",
1719 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx",
1721 Config::ConnectFailSafe("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop",
1723}
1724
1725Vector
1727{
1728 Ptr<MobilityModel> loc = n->GetObject<MobilityModel>();
1729 if (loc)
1730 {
1731 m_nodeLocation[n->GetId()] = loc->GetPosition();
1732 }
1733 else
1734 {
1736 "AnimationInterface WARNING:Node:"
1737 << n->GetId()
1738 << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
1739 Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable>();
1740 x->SetAttribute("Min", DoubleValue(0));
1741 x->SetAttribute("Max", DoubleValue(100));
1742 Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable>();
1743 y->SetAttribute("Min", DoubleValue(0));
1744 y->SetAttribute("Max", DoubleValue(100));
1745 m_nodeLocation[n->GetId()] = Vector(int(x->GetValue()), int(y->GetValue()), 0);
1746 }
1747 return m_nodeLocation[n->GetId()];
1748}
1749
1750Vector
1752{
1753 m_nodeLocation[n->GetId()] = v;
1754 return v;
1755}
1756
1757Vector
1759{
1760 Ptr<Node> n = ndev->GetNode();
1761 NS_ASSERT(n);
1762 return UpdatePosition(n);
1763}
1764
1765Vector
1767{
1768 if (m_nodeLocation.find(n->GetId()) == m_nodeLocation.end())
1769 {
1770 NS_FATAL_ERROR("Node:" << n->GetId() << " not found in Location table");
1771 }
1772 return m_nodeLocation[n->GetId()];
1773}
1774
1775std::string
1777{
1778 Address nodeAddr = nd->GetAddress();
1779 std::ostringstream oss;
1780 oss << nodeAddr;
1781 return oss.str().substr(6); // Skip the first 6 chars to get the Mac
1782}
1783
1784std::string
1786{
1787 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1788 if (!ipv4)
1789 {
1790 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1791 return "0.0.0.0";
1792 }
1793 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1794 if (ifIndex == -1)
1795 {
1796 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1797 return "0.0.0.0";
1798 }
1799 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, 0);
1800 std::ostringstream oss;
1801 oss << addr.GetLocal();
1802 return oss.str();
1803}
1804
1805std::string
1807{
1808 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1809 if (!ipv6)
1810 {
1811 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1812 return "::";
1813 }
1814 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1815 if (ifIndex == -1)
1816 {
1817 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1818 return "::";
1819 }
1820 bool nonLinkLocalFound = false;
1821 uint32_t nAddresses = ipv6->GetNAddresses(ifIndex);
1823 for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex)
1824 {
1825 addr = ipv6->GetAddress(ifIndex, addressIndex);
1826 if (!addr.GetAddress().IsLinkLocal())
1827 {
1828 nonLinkLocalFound = true;
1829 break;
1830 }
1831 }
1832 if (!nonLinkLocalFound)
1833 {
1834 addr = ipv6->GetAddress(ifIndex, 0);
1835 }
1836 std::ostringstream oss;
1837 oss << addr.GetAddress();
1838 return oss.str();
1839}
1840
1841std::vector<std::string>
1843{
1844 std::vector<std::string> ipv4Addresses;
1845 Ptr<Ipv4> ipv4 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv4>();
1846 if (!ipv4)
1847 {
1848 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found");
1849 return ipv4Addresses;
1850 }
1851 int32_t ifIndex = ipv4->GetInterfaceForDevice(nd);
1852 if (ifIndex == -1)
1853 {
1854 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1855 return ipv4Addresses;
1856 }
1857 for (uint32_t index = 0; index < ipv4->GetNAddresses(ifIndex); ++index)
1858 {
1859 Ipv4InterfaceAddress addr = ipv4->GetAddress(ifIndex, index);
1860 std::ostringstream oss;
1861 oss << addr.GetLocal();
1862 ipv4Addresses.push_back(oss.str());
1863 }
1864 return ipv4Addresses;
1865}
1866
1867std::vector<std::string>
1869{
1870 std::vector<std::string> ipv6Addresses;
1871 Ptr<Ipv6> ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject<Ipv6>();
1872 if (!ipv6)
1873 {
1874 NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv6 object found");
1875 return ipv6Addresses;
1876 }
1877 int32_t ifIndex = ipv6->GetInterfaceForDevice(nd);
1878 if (ifIndex == -1)
1879 {
1880 NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice");
1881 return ipv6Addresses;
1882 }
1883 for (uint32_t index = 0; index < ipv6->GetNAddresses(ifIndex); ++index)
1884 {
1885 Ipv6InterfaceAddress addr = ipv6->GetAddress(ifIndex, index);
1886 std::ostringstream oss;
1887 oss << addr.GetAddress();
1888 ipv6Addresses.push_back(oss.str());
1889 }
1890 return ipv6Addresses;
1891}
1892
1893void
1895{
1896 for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin(); i != m_nodeIdIpv4Map.end(); ++i)
1897 {
1898 std::vector<std::string> ipv4Addresses;
1899 std::pair<NodeIdIpv4Map::const_iterator, NodeIdIpv4Map::const_iterator> iterPair =
1900 m_nodeIdIpv4Map.equal_range(i->first);
1901 for (NodeIdIpv4Map::const_iterator it = iterPair.first; it != iterPair.second; ++it)
1902 {
1903 ipv4Addresses.push_back(it->second);
1904 }
1905 WriteXmlIpv4Addresses(i->first, ipv4Addresses);
1906 }
1907}
1908
1909void
1911{
1912 for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin(); i != m_nodeIdIpv6Map.end();
1913 i = m_nodeIdIpv6Map.upper_bound(i->first))
1914 {
1915 std::vector<std::string> ipv6Addresses;
1916 std::pair<NodeIdIpv6Map::const_iterator, NodeIdIpv6Map::const_iterator> iterPair =
1917 m_nodeIdIpv6Map.equal_range(i->first);
1918 for (NodeIdIpv6Map::const_iterator it = iterPair.first; it != iterPair.second; ++it)
1919 {
1920 ipv6Addresses.push_back(it->second);
1921 }
1922 WriteXmlIpv6Addresses(i->first, ipv6Addresses);
1923 }
1924}
1925
1926void
1928{
1929 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
1930 {
1931 Ptr<Node> n = *i;
1932 UpdatePosition(n);
1933 uint32_t n1Id = n->GetId();
1934 uint32_t nDev = n->GetNDevices(); // Number of devices
1935 for (uint32_t i = 0; i < nDev; ++i)
1936 {
1937 Ptr<NetDevice> dev = n->GetDevice(i);
1938 NS_ASSERT(dev);
1939 Ptr<Channel> ch = dev->GetChannel();
1940 std::string channelType = "Unknown channel";
1941 if (ch)
1942 {
1943 channelType = ch->GetInstanceTypeId().GetName();
1944 }
1945 NS_LOG_DEBUG("Got ChannelType" << channelType);
1946
1947 if (!ch || (channelType != "ns3::PointToPointChannel"))
1948 {
1949 NS_LOG_DEBUG("No channel can't be a p2p device");
1950 /*
1951 // Try to see if it is an LTE NetDevice, which does not return a channel
1952 if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
1953 (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
1954 (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
1955 {
1956 WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" +
1957 GetMacAddress (dev), channelType); AddToIpv4AddressNodeIdTable (GetIpv4Address
1958 (dev), n->GetId ());
1959 }
1960 */
1961 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1962 AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId());
1963 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1964 AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId());
1965 if (!ipv4Addresses.empty())
1966 {
1967 NS_LOG_INFO("Writing Ipv4 link");
1968 WriteNonP2pLinkProperties(n->GetId(),
1969 GetIpv4Address(dev) + "~" + GetMacAddress(dev),
1970 channelType);
1971 }
1972 else if (!ipv6Addresses.empty())
1973 {
1974 NS_LOG_INFO("Writing Ipv6 link");
1975 WriteNonP2pLinkProperties(n->GetId(),
1976 GetIpv6Address(dev) + "~" + GetMacAddress(dev),
1977 channelType);
1978 }
1979 continue;
1980 }
1981
1982 else if (channelType == "ns3::PointToPointChannel")
1983 { // Since these are duplex links, we only need to dump
1984 // if srcid < dstid
1985 std::size_t nChDev = ch->GetNDevices();
1986 for (std::size_t j = 0; j < nChDev; ++j)
1987 {
1988 Ptr<NetDevice> chDev = ch->GetDevice(j);
1989 uint32_t n2Id = chDev->GetNode()->GetId();
1990 if (n1Id < n2Id)
1991 {
1992 std::vector<std::string> ipv4Addresses = GetIpv4Addresses(dev);
1993 AddToIpv4AddressNodeIdTable(ipv4Addresses, n1Id);
1994 ipv4Addresses = GetIpv4Addresses(chDev);
1995 AddToIpv4AddressNodeIdTable(ipv4Addresses, n2Id);
1996 std::vector<std::string> ipv6Addresses = GetIpv6Addresses(dev);
1997 AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id);
1998 ipv6Addresses = GetIpv6Addresses(chDev);
1999 AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id);
2000
2001 P2pLinkNodeIdPair p2pPair;
2002 p2pPair.fromNode = n1Id;
2003 p2pPair.toNode = n2Id;
2004 if (!ipv4Addresses.empty())
2005 {
2006 LinkProperties lp = {GetIpv4Address(dev) + "~" + GetMacAddress(dev),
2007 GetIpv4Address(chDev) + "~" + GetMacAddress(chDev),
2008 ""};
2009 m_linkProperties[p2pPair] = lp;
2010 }
2011 else if (!ipv6Addresses.empty())
2012 {
2013 LinkProperties lp = {GetIpv6Address(dev) + "~" + GetMacAddress(dev),
2014 GetIpv6Address(chDev) + "~" + GetMacAddress(chDev),
2015 ""};
2016 m_linkProperties[p2pPair] = lp;
2017 }
2018 WriteXmlLink(n1Id, 0, n2Id);
2019 }
2020 }
2021 }
2022 }
2023 }
2024 m_linkProperties.clear();
2025}
2026
2027void
2029{
2030 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2031 {
2032 Ptr<Node> n = *i;
2033 NS_LOG_INFO("Update Position for Node: " << n->GetId());
2034 Vector v = UpdatePosition(n);
2035 WriteXmlNode(n->GetId(), n->GetSystemId(), v.x, v.y);
2036 }
2037}
2038
2039void
2041{
2042 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2043 {
2044 Ptr<Node> n = *i;
2045 Rgb rgb = {255, 0, 0};
2046 if (m_nodeColors.find(n->GetId()) == m_nodeColors.end())
2047 {
2048 m_nodeColors[n->GetId()] = rgb;
2049 }
2050 UpdateNodeColor(n, rgb.r, rgb.g, rgb.b);
2051 }
2052}
2053
2054void
2056{
2057 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2058 {
2059 Ptr<Node> n = *i;
2060 NS_LOG_INFO("Update Size for Node: " << n->GetId());
2062 m_nodeSizes[n->GetId()] = s;
2063 UpdateNodeSize(n->GetId(), s.width, s.height);
2064 }
2065}
2066
2067void
2069{
2072 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2073 {
2074 Ptr<Node> n = *i;
2075 if (NodeList::GetNode(n->GetId())->GetObject<EnergySource>())
2076 {
2078 }
2079 }
2080}
2081
2082bool
2084{
2086}
2087
2088void
2089AnimationInterface::SetOutputFile(const std::string& fn, bool routing)
2090{
2091 if (!routing && m_f)
2092 {
2093 return;
2094 }
2095 if (routing && m_routingF)
2096 {
2097 NS_FATAL_ERROR("SetRoutingOutputFile already used once");
2098 return;
2099 }
2100
2101 NS_LOG_INFO("Creating new trace file:" << fn);
2102 FILE* f = nullptr;
2103 f = std::fopen(fn.c_str(), "w");
2104 if (!f)
2105 {
2106 NS_FATAL_ERROR("Unable to open output file:" << fn);
2107 return; // Can't open output file
2108 }
2109 if (routing)
2110 {
2111 m_routingF = f;
2112 m_routingFileName = fn;
2113 }
2114 else
2115 {
2116 m_f = f;
2117 m_outputFileName = fn;
2118 }
2119}
2120
2121void
2123{
2124 // Start a new trace file if the current packet count exceeded max packets per file
2127 {
2128 return;
2129 }
2130 NS_LOG_UNCOND("Max Packets per trace file exceeded");
2131 StopAnimation(true);
2132}
2133
2134std::string
2136{
2137 return NETANIM_VERSION;
2138}
2139
2140void
2142{
2144 {
2145 NS_LOG_INFO("TrackQueueCounters Completed");
2146 return;
2147 }
2148 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2149 {
2150 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2154 }
2156}
2157
2158void
2160{
2162 {
2163 NS_LOG_INFO("TrackWifiMacCounters Completed");
2164 return;
2165 }
2166 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2167 {
2168 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2173 }
2176 this);
2177}
2178
2179void
2181{
2183 {
2184 NS_LOG_INFO("TrackWifiPhyCounters Completed");
2185 return;
2186 }
2187 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2188 {
2189 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2192 }
2195 this);
2196}
2197
2198void
2200{
2202 {
2203 NS_LOG_INFO("TrackIpv4L3ProtocolCounters Completed");
2204 return;
2205 }
2206 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2207 {
2208 uint32_t nodeId = Ptr<Node>(*i)->GetId();
2212 }
2215 this);
2216}
2217
2218/***** Routing-related *****/
2219
2220void
2222{
2223 if (m_ipv4RouteTrackElements.empty())
2224 {
2225 return;
2226 }
2227 for (std::vector<Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin();
2228 i != m_ipv4RouteTrackElements.end();
2229 ++i)
2230 {
2231 Ipv4RouteTrackElement trackElement = *i;
2232 Ptr<Node> fromNode = NodeList::GetNode(trackElement.fromNodeId);
2233 if (!fromNode)
2234 {
2235 NS_FATAL_ERROR("Node: " << trackElement.fromNodeId << " Not found");
2236 continue;
2237 }
2238 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2239 if (!ipv4)
2240 {
2241 NS_LOG_WARN("ipv4 object not found");
2242 continue;
2243 }
2244 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2245 if (!rp)
2246 {
2247 NS_LOG_WARN("Routing protocol object not found");
2248 continue;
2249 }
2250 NS_LOG_INFO("Begin Track Route for: " << trackElement.destination
2251 << " From:" << trackElement.fromNodeId);
2252 Ptr<Packet> pkt = Create<Packet>();
2253 Ipv4Header header;
2254 header.SetDestination(Ipv4Address(trackElement.destination.c_str()));
2255 Socket::SocketErrno sockerr;
2256 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2257 Ipv4RoutePathElements rpElements;
2258 if (!rt)
2259 {
2260 NS_LOG_INFO("No route to :" << trackElement.destination);
2261 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2262 rpElements.push_back(elem);
2263 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2264 continue;
2265 }
2266 std::ostringstream oss;
2267 oss << rt->GetGateway();
2268 NS_LOG_INFO("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway());
2269 if (rt->GetGateway() == "0.0.0.0")
2270 {
2271 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "C"};
2272 rpElements.push_back(elem);
2273 if (m_ipv4ToNodeIdMap.find(trackElement.destination) != m_ipv4ToNodeIdMap.end())
2274 {
2275 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[trackElement.destination], "L"};
2276 rpElements.push_back(elem2);
2277 }
2278 }
2279 else if (rt->GetGateway() == "127.0.0.1")
2280 {
2281 Ipv4RoutePathElement elem = {trackElement.fromNodeId, "-1"};
2282 rpElements.push_back(elem);
2283 }
2284 else
2285 {
2286 Ipv4RoutePathElement elem = {trackElement.fromNodeId, oss.str()};
2287 rpElements.push_back(elem);
2288 }
2289 RecursiveIpv4RoutePathSearch(oss.str(), trackElement.destination, rpElements);
2290 WriteRoutePath(trackElement.fromNodeId, trackElement.destination, rpElements);
2291 }
2292}
2293
2294void
2296{
2298 {
2299 NS_LOG_INFO("TrackIpv4Route completed");
2300 return;
2301 }
2302 if (m_routingNc.GetN())
2303 {
2305 {
2306 Ptr<Node> n = *i;
2307 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2308 }
2309 }
2310 else
2311 {
2312 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
2313 {
2314 Ptr<Node> n = *i;
2315 WriteXmlRouting(n->GetId(), GetIpv4RoutingTable(n));
2316 }
2317 }
2320}
2321
2322std::string
2324{
2325 NS_ASSERT(n);
2326 Ptr<ns3::Ipv4> ipv4 = n->GetObject<ns3::Ipv4>();
2327 if (!ipv4)
2328 {
2329 NS_LOG_WARN("Node " << n->GetId() << " Does not have an Ipv4 object");
2330 return "";
2331 }
2332 std::stringstream stream;
2333 Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper>(&stream);
2334 ipv4->GetRoutingProtocol()->PrintRoutingTable(routingstream);
2335 return stream.str();
2336}
2337
2338void
2340 std::string to,
2341 Ipv4RoutePathElements& rpElements)
2342{
2343 NS_LOG_INFO("RecursiveIpv4RoutePathSearch from:" << from << " to:" << to);
2344 if (from == "0.0.0.0" || from == "127.0.0.1")
2345 {
2346 NS_LOG_INFO("Got " << from << " End recursion");
2347 return;
2348 }
2351 if (fromNode->GetId() == toNode->GetId())
2352 {
2353 Ipv4RoutePathElement elem = {fromNode->GetId(), "L"};
2354 rpElements.push_back(elem);
2355 return;
2356 }
2357 if (!fromNode)
2358 {
2359 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
2360 return;
2361 }
2362 if (!toNode)
2363 {
2364 NS_FATAL_ERROR("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
2365 return;
2366 }
2367 Ptr<ns3::Ipv4> ipv4 = fromNode->GetObject<ns3::Ipv4>();
2368 if (!ipv4)
2369 {
2370 NS_LOG_WARN("ipv4 object not found");
2371 return;
2372 }
2373 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
2374 if (!rp)
2375 {
2376 NS_LOG_WARN("Routing protocol object not found");
2377 return;
2378 }
2379 Ptr<Packet> pkt = Create<Packet>();
2380 Ipv4Header header;
2381 header.SetDestination(Ipv4Address(to.c_str()));
2382 Socket::SocketErrno sockerr;
2383 Ptr<Ipv4Route> rt = rp->RouteOutput(pkt, header, nullptr, sockerr);
2384 if (!rt)
2385 {
2386 return;
2387 }
2388 NS_LOG_DEBUG("Node: " << fromNode->GetId() << " G:" << rt->GetGateway());
2389 std::ostringstream oss;
2390 oss << rt->GetGateway();
2391 if (oss.str() == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
2392 {
2393 NS_LOG_INFO("Null gw");
2394 Ipv4RoutePathElement elem = {fromNode->GetId(), "C"};
2395 rpElements.push_back(elem);
2396 if (m_ipv4ToNodeIdMap.find(to) != m_ipv4ToNodeIdMap.end())
2397 {
2398 Ipv4RoutePathElement elem2 = {m_ipv4ToNodeIdMap[to], "L"};
2399 rpElements.push_back(elem2);
2400 }
2401 return;
2402 }
2403 NS_LOG_INFO("Node:" << fromNode->GetId() << "-->" << rt->GetGateway());
2404 Ipv4RoutePathElement elem = {fromNode->GetId(), oss.str()};
2405 rpElements.push_back(elem);
2406 RecursiveIpv4RoutePathSearch(oss.str(), to, rpElements);
2407}
2408
2409/***** WriteXml *****/
2410
2411void
2413{
2414 AnimXmlElement element("anim");
2415 element.AddAttribute("ver", GetNetAnimVersion());
2416 FILE* f = m_f;
2417 if (!routing)
2418 {
2419 element.AddAttribute("filetype", "animation");
2420 }
2421 else
2422 {
2423 element.AddAttribute("filetype", "routing");
2424 f = m_routingF;
2425 }
2426 WriteN(element.ToString(false) + ">\n", f);
2427}
2428
2429void
2430AnimationInterface::WriteXmlClose(std::string name, bool routing)
2431{
2432 std::string closeString = "</" + name + ">\n";
2433 if (!routing)
2434 {
2435 WriteN(closeString, m_f);
2436 }
2437 else
2438 {
2439 WriteN(closeString, m_routingF);
2440 }
2441}
2442
2443void
2444AnimationInterface::WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
2445{
2446 AnimXmlElement element("node");
2447 element.AddAttribute("id", id);
2448 element.AddAttribute("sysId", sysId);
2449 element.AddAttribute("locX", locX);
2450 element.AddAttribute("locY", locY);
2451 WriteN(element.ToString(), m_f);
2452}
2453
2454void
2455AnimationInterface::WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string linkDescription)
2456{
2457 AnimXmlElement element("linkupdate");
2458 element.AddAttribute("t", Simulator::Now().GetSeconds());
2459 element.AddAttribute("fromId", fromId);
2460 element.AddAttribute("toId", toId);
2461 element.AddAttribute("ld", linkDescription, true);
2462 WriteN(element.ToString(), m_f);
2463}
2464
2465void
2467{
2468 AnimXmlElement element("link");
2469 element.AddAttribute("fromId", fromId);
2470 element.AddAttribute("toId", toId);
2471
2472 LinkProperties lprop;
2473 lprop.fromNodeDescription = "";
2474 lprop.toNodeDescription = "";
2475 lprop.linkDescription = "";
2476
2477 P2pLinkNodeIdPair p1 = {fromId, toId};
2478 P2pLinkNodeIdPair p2 = {toId, fromId};
2479 if (m_linkProperties.find(p1) != m_linkProperties.end())
2480 {
2481 lprop = m_linkProperties[p1];
2482 }
2483 else if (m_linkProperties.find(p2) != m_linkProperties.end())
2484 {
2485 lprop = m_linkProperties[p2];
2486 }
2487
2488 element.AddAttribute("fd", lprop.fromNodeDescription, true);
2489 element.AddAttribute("td", lprop.toNodeDescription, true);
2490 element.AddAttribute("ld", lprop.linkDescription, true);
2491 WriteN(element.ToString(), m_f);
2492}
2493
2494void
2495AnimationInterface::WriteXmlIpv4Addresses(uint32_t nodeId, std::vector<std::string> ipv4Addresses)
2496{
2497 AnimXmlElement element("ip");
2498 element.AddAttribute("n", nodeId);
2499 for (std::vector<std::string>::const_iterator i = ipv4Addresses.begin();
2500 i != ipv4Addresses.end();
2501 ++i)
2502 {
2503 AnimXmlElement valueElement("address");
2504 valueElement.SetText(*i);
2505 element.AppendChild(valueElement);
2506 }
2507 WriteN(element.ToString(), m_f);
2508}
2509
2510void
2511AnimationInterface::WriteXmlIpv6Addresses(uint32_t nodeId, std::vector<std::string> ipv6Addresses)
2512{
2513 AnimXmlElement element("ipv6");
2514 element.AddAttribute("n", nodeId);
2515 for (std::vector<std::string>::const_iterator i = ipv6Addresses.begin();
2516 i != ipv6Addresses.end();
2517 ++i)
2518 {
2519 AnimXmlElement valueElement("address");
2520 valueElement.SetText(*i);
2521 element.AppendChild(valueElement);
2522 }
2523 WriteN(element.ToString(), m_f);
2524}
2525
2526void
2527AnimationInterface::WriteXmlRouting(uint32_t nodeId, std::string routingInfo)
2528{
2529 AnimXmlElement element("rt");
2530 element.AddAttribute("t", Simulator::Now().GetSeconds());
2531 element.AddAttribute("id", nodeId);
2532 element.AddAttribute("info", routingInfo.c_str(), true);
2533 WriteN(element.ToString(), m_routingF);
2534}
2535
2536void
2538 std::string destination,
2539 Ipv4RoutePathElements rpElements)
2540{
2541 std::string tagName = "rp";
2542 AnimXmlElement element(tagName, false);
2543 element.AddAttribute("t", Simulator::Now().GetSeconds());
2544 element.AddAttribute("id", nodeId);
2545 element.AddAttribute("d", destination.c_str());
2546 element.AddAttribute("c", rpElements.size());
2547 for (Ipv4RoutePathElements::const_iterator i = rpElements.begin(); i != rpElements.end(); ++i)
2548 {
2549 Ipv4RoutePathElement rpElement = *i;
2550 AnimXmlElement rpeElement("rpe");
2551 rpeElement.AddAttribute("n", rpElement.nodeId);
2552 rpeElement.AddAttribute("nH", rpElement.nextHop.c_str());
2553 element.AppendChild(rpeElement);
2554 }
2555 WriteN(element.ToString(), m_routingF);
2556}
2557
2558void
2559AnimationInterface::WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo)
2560{
2561 AnimXmlElement element("pr");
2562 element.AddAttribute("uId", animUid);
2563 element.AddAttribute("fId", fId);
2564 element.AddAttribute("fbTx", fbTx);
2565 if (!metaInfo.empty())
2566 {
2567 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2568 }
2569 WriteN(element.ToString(), m_f);
2570}
2571
2572void
2574 std::string pktType,
2575 uint32_t tId,
2576 double fbRx,
2577 double lbRx)
2578{
2579 AnimXmlElement element(pktType);
2580 element.AddAttribute("uId", animUid);
2581 element.AddAttribute("tId", tId);
2582 element.AddAttribute("fbRx", fbRx);
2583 element.AddAttribute("lbRx", lbRx);
2584 WriteN(element.ToString(), m_f);
2585}
2586
2587void
2589 uint32_t fId,
2590 double fbTx,
2591 double lbTx,
2592 uint32_t tId,
2593 double fbRx,
2594 double lbRx,
2595 std::string metaInfo)
2596{
2597 AnimXmlElement element(pktType);
2598 element.AddAttribute("fId", fId);
2599 element.AddAttribute("fbTx", fbTx);
2600 element.AddAttribute("lbTx", lbTx);
2601 if (!metaInfo.empty())
2602 {
2603 element.AddAttribute("meta-info", metaInfo.c_str(), true);
2604 }
2605 element.AddAttribute("tId", tId);
2606 element.AddAttribute("fbRx", fbRx);
2607 element.AddAttribute("lbRx", lbRx);
2608 WriteN(element.ToString(), m_f);
2609}
2610
2611void
2613 std::string counterName,
2614 CounterType counterType)
2615{
2616 AnimXmlElement element("ncs");
2617 element.AddAttribute("ncId", nodeCounterId);
2618 element.AddAttribute("n", counterName);
2619 element.AddAttribute("t", CounterTypeToString(counterType));
2620 WriteN(element.ToString(), m_f);
2621}
2622
2623void
2624AnimationInterface::WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
2625{
2626 AnimXmlElement element("res");
2627 element.AddAttribute("rid", resourceId);
2628 element.AddAttribute("p", resourcePath);
2629 WriteN(element.ToString(), m_f);
2630}
2631
2632void
2634{
2635 AnimXmlElement element("nu");
2636 element.AddAttribute("p", "i");
2637 element.AddAttribute("t", Simulator::Now().GetSeconds());
2638 element.AddAttribute("id", nodeId);
2639 element.AddAttribute("rid", resourceId);
2640 WriteN(element.ToString(), m_f);
2641}
2642
2643void
2644AnimationInterface::WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
2645{
2646 AnimXmlElement element("nu");
2647 element.AddAttribute("p", "s");
2648 element.AddAttribute("t", Simulator::Now().GetSeconds());
2649 element.AddAttribute("id", nodeId);
2650 element.AddAttribute("w", width);
2651 element.AddAttribute("h", height);
2652 WriteN(element.ToString(), m_f);
2653}
2654
2655void
2657{
2658 AnimXmlElement element("nu");
2659 element.AddAttribute("p", "p");
2660 element.AddAttribute("t", Simulator::Now().GetSeconds());
2661 element.AddAttribute("id", nodeId);
2662 element.AddAttribute("x", x);
2663 element.AddAttribute("y", y);
2664 WriteN(element.ToString(), m_f);
2665}
2666
2667void
2668AnimationInterface::WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2669{
2670 AnimXmlElement element("nu");
2671 element.AddAttribute("p", "c");
2672 element.AddAttribute("t", Simulator::Now().GetSeconds());
2673 element.AddAttribute("id", nodeId);
2674 element.AddAttribute("r", (uint32_t)r);
2675 element.AddAttribute("g", (uint32_t)g);
2676 element.AddAttribute("b", (uint32_t)b);
2677 WriteN(element.ToString(), m_f);
2678}
2679
2680void
2682{
2683 AnimXmlElement element("nu");
2684 element.AddAttribute("p", "d");
2685 element.AddAttribute("t", Simulator::Now().GetSeconds());
2686 element.AddAttribute("id", nodeId);
2687 if (m_nodeDescriptions.find(nodeId) != m_nodeDescriptions.end())
2688 {
2689 element.AddAttribute("descr", m_nodeDescriptions[nodeId], true);
2690 }
2691 WriteN(element.ToString(), m_f);
2692}
2693
2694void
2696 uint32_t nodeId,
2697 double counterValue)
2698{
2699 AnimXmlElement element("nc");
2700 element.AddAttribute("c", nodeCounterId);
2701 element.AddAttribute("i", nodeId);
2702 element.AddAttribute("t", Simulator::Now().GetSeconds());
2703 element.AddAttribute("v", counterValue);
2704 WriteN(element.ToString(), m_f);
2705}
2706
2707void
2709 double x,
2710 double y,
2711 double scaleX,
2712 double scaleY,
2713 double opacity)
2714{
2715 AnimXmlElement element("bg");
2716 element.AddAttribute("f", fileName);
2717 element.AddAttribute("x", x);
2718 element.AddAttribute("y", y);
2719 element.AddAttribute("sx", scaleX);
2720 element.AddAttribute("sy", scaleY);
2721 element.AddAttribute("o", opacity);
2722 WriteN(element.ToString(), m_f);
2723}
2724
2725void
2727 std::string ipAddress,
2728 std::string channelType)
2729{
2730 AnimXmlElement element("nonp2plinkproperties");
2731 element.AddAttribute("id", id);
2732 element.AddAttribute("ipAddress", ipAddress);
2733 element.AddAttribute("channelType", channelType);
2734 WriteN(element.ToString(), m_f);
2735}
2736
2737/***** AnimXmlElement *****/
2738
2739AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement)
2740 : m_tagName(tagName),
2741 m_text("")
2742{
2743}
2744
2745template <typename T>
2746void
2747AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape)
2748{
2749 std::ostringstream oss;
2750 oss << std::setprecision(10);
2751 oss << value;
2752 std::string attributeString = attribute;
2753 if (xmlEscape)
2754 {
2755 attributeString += "=\"";
2756 std::string valueStr = oss.str();
2757 for (std::string::iterator it = valueStr.begin(); it != valueStr.end(); ++it)
2758 {
2759 switch (*it)
2760 {
2761 case '&':
2762 attributeString += "&amp;";
2763 break;
2764 case '\"':
2765 attributeString += "&quot;";
2766 break;
2767 case '\'':
2768 attributeString += "&apos;";
2769 break;
2770 case '<':
2771 attributeString += "&lt;";
2772 break;
2773 case '>':
2774 attributeString += "&gt;";
2775 break;
2776 default:
2777 attributeString += *it;
2778 break;
2779 }
2780 }
2781 attributeString += "\" ";
2782 }
2783 else
2784 {
2785 attributeString += "=\"" + oss.str() + "\" ";
2786 }
2787 m_attributes.push_back(attributeString);
2788}
2789
2790void
2792{
2793 m_children.push_back(e.ToString());
2794}
2795
2796void
2798{
2799 m_text = text;
2800}
2801
2802std::string
2804{
2805 std::string elementString = "<" + m_tagName + " ";
2806
2807 for (std::vector<std::string>::const_iterator i = m_attributes.begin(); i != m_attributes.end();
2808 ++i)
2809 {
2810 elementString += *i;
2811 }
2812 if (m_children.empty() && m_text.empty())
2813 {
2814 if (autoClose)
2815 {
2816 elementString += "/>";
2817 }
2818 }
2819 else
2820 {
2821 elementString += ">";
2822 if (!m_text.empty())
2823 {
2824 elementString += m_text;
2825 }
2826 if (!m_children.empty())
2827 {
2828 elementString += "\n";
2829 for (std::vector<std::string>::const_iterator i = m_children.begin();
2830 i != m_children.end();
2831 ++i)
2832 {
2833 elementString += *i + "\n";
2834 }
2835 }
2836 if (autoClose)
2837 {
2838 elementString += "</" + m_tagName + ">";
2839 }
2840 }
2841
2842 return elementString + ((autoClose) ? "\n" : "");
2843}
2844
2845/***** AnimByteTag *****/
2846
2847TypeId
2849{
2850 static TypeId tid = TypeId("ns3::AnimByteTag")
2851 .SetParent<Tag>()
2852 .SetGroupName("NetAnim")
2853 .AddConstructor<AnimByteTag>();
2854 return tid;
2855}
2856
2857TypeId
2859{
2860 return GetTypeId();
2861}
2862
2865{
2866 return sizeof(uint64_t);
2867}
2868
2869void
2871{
2872 i.WriteU64(m_AnimUid);
2873}
2874
2875void
2877{
2878 m_AnimUid = i.ReadU64();
2879}
2880
2881void
2882AnimByteTag::Print(std::ostream& os) const
2883{
2884 os << "AnimUid=" << m_AnimUid;
2885}
2886
2887void
2888AnimByteTag::Set(uint64_t AnimUid)
2889{
2890 m_AnimUid = AnimUid;
2891}
2892
2893uint64_t
2895{
2896 return m_AnimUid;
2897}
2898
2900 : m_txnd(nullptr),
2901 m_txNodeId(0),
2902 m_fbTx(0),
2903 m_lbTx(0),
2904 m_lbRx(0)
2905{
2906}
2907
2909{
2910 m_txnd = pInfo.m_txnd;
2911 m_txNodeId = pInfo.m_txNodeId;
2912 m_fbTx = pInfo.m_fbTx;
2913 m_lbTx = pInfo.m_lbTx;
2914 m_lbRx = pInfo.m_lbRx;
2915}
2916
2918 const Time fbTx,
2919 uint32_t txNodeId)
2920 : m_txnd(txnd),
2921 m_txNodeId(0),
2922 m_fbTx(fbTx.GetSeconds()),
2923 m_lbTx(0),
2924 m_lbRx(0)
2925{
2926 if (!m_txnd)
2927 {
2928 m_txNodeId = txNodeId;
2929 }
2930}
2931
2932void
2934{
2935 Ptr<Node> n = nd->GetNode();
2936 m_fbRx = fbRx;
2937 m_rxnd = nd;
2938}
2939
2940} // namespace ns3
double f(double x, void *params)
Definition: 80211b.c:70
#define NETANIM_VERSION
#define MAX_PKTS_PER_TRACE_FILE
#define CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS
#define CHECK_STARTED_INTIMEWINDOW
#define PURGE_INTERVAL
a polymophic address class
Definition: address.h:100
Byte tag using by Anim to uniquely identify packets.
TypeId GetInstanceTypeId() const override
Get Instance Type Id.
void Serialize(TagBuffer i) const override
Serialize function.
void Print(std::ostream &os) const override
Print tag info.
uint32_t GetSerializedSize() const override
Get Serialized Size.
uint64_t Get() const
Get Uid in tag.
static TypeId GetTypeId()
Get Type Id.
void Deserialize(TagBuffer i) override
Deserialize function.
void Set(uint64_t AnimUid)
Set global Uid in tag.
Ptr< const NetDevice > m_txnd
transmit device
void ProcessRxBegin(Ptr< const NetDevice > nd, const double fbRx)
Process receive begin.
Ptr< const NetDevice > m_rxnd
receive device
void AppendChild(AnimXmlElement e)
Append child function.
void SetText(std::string text)
Set text function.
std::string ToString(bool autoClose=true)
Get text for the element function.
AnimXmlElement(std::string tagName, bool emptyElement=true)
Constructor.
void AddAttribute(std::string attribute, T value, bool xmlEscape=false)
Add attribute function.
Interface to network animator.
FILE * m_f
File handle for output (0 if none)
Time m_wifiMacCountersPollInterval
wifi MAC counters poll interval
void CsmaPhyRxEndTrace(std::string context, Ptr< const Packet > p)
CSMA Phy receive end trace function.
void WriteNodeSizes()
Write node sizes function.
uint32_t AddNodeCounter(std::string counterName, CounterType counterType)
Setup a node counter.
void TrackQueueCounters()
Track queue counters function.
void SetMobilityPollInterval(Time t)
Set mobility poll interval:WARNING: setting a low interval can cause slowness.
uint32_t m_wifiMacRxCounterId
wifi MAC receive counter ID
bool IsPacketPending(uint64_t animUid, ProtocolType protocolType)
Is packet pending function.
bool NodeHasMoved(Ptr< Node > n, Vector newLocation)
Node has moved function.
void LrWpanPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
LR-WPAN Phy receive begin trace function.
uint32_t m_queueDropCounterId
queue drop counter ID
void WimaxTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
WIMax transmit trace function.
void LrWpanPhyRxBeginTrace(std::string context, Ptr< const Packet > p)
LR-WPAN Phy receive begin trace function.
Time m_routingPollInterval
routing poll interval
void OutputCsmaPacket(Ptr< const Packet > p, AnimPacketInfo &pktInfo)
Output CSMA packet function.
uint64_t GetAnimUidFromPacket(Ptr< const Packet >)
Get anim UID from packet function.
EnergyFractionMap m_nodeEnergyFraction
node energy fraction
void GenericWirelessTxTrace(std::string context, Ptr< const Packet > p, ProtocolType protocolType)
Generic wireless transmit trace function.
void LteRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
LTE receive trace function.
std::string ProtocolTypeToString(ProtocolType protocolType)
Protocol type to string function.
NodeCounterMap64 m_nodeLrWpanMacRx
node LR-WPAN MAC receive
std::string m_routingFileName
routing file name
NodeCounterMap64 m_nodeIpv4Tx
node IPv4 transmit
std::map< std::string, uint32_t > m_ipv6ToNodeIdMap
IPv6 to node ID map.
void MobilityAutoCheck()
Mobility auto check function.
void WriteXmlRouting(uint32_t id, std::string routingInfo)
Write XML routing function.
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet > p, WifiPhyRxfailureReason reason)
wifi Phy receive drop trace function
void WifiMacRxDropTrace(std::string context, Ptr< const Packet > p)
wifi MAC receive drop trace function
NodeCounterMap64 m_nodeQueueDrop
node queue drop
void ConnectLteUe(Ptr< Node > n, Ptr< LteUeNetDevice > nd, uint32_t devIndex)
Connect LTE ue function.
void DequeueTrace(std::string context, Ptr< const Packet >)
Dequeue trace function.
void ConnectCallbacks()
Connect callbacks function.
void WriteRoutePath(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
Write route path function.
AnimUidPacketInfoMap * ProtocolTypeToPendingPackets(ProtocolType protocolType)
Protocol type to pending packets function.
void RemainingEnergyTrace(std::string context, double previousEnergy, double currentEnergy)
Remaining energy trace function.
void Ipv4DropTrace(std::string context, const Ipv4Header &ipv4Header, Ptr< const Packet > p, Ipv4L3Protocol::DropReason dropReason, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 drop trace function.
NodeColorsMap m_nodeColors
node colors
void UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
Helper function to update a node's counter referenced by the nodeCounterId.
void WifiPhyRxBeginTrace(std::string context, Ptr< const Packet > p, RxPowerWattPerChannelBand rxPowersW)
wifi Phy receive begin trace function
void LrWpanMacRxDropTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC receive drop trace function.
void LteSpectrumPhyTxStart(std::string context, Ptr< const PacketBurst > pb)
LTE Spectrum Phy transmit start function.
NodeCounterMap64 m_nodeLrWpanMacTx
node LR-WPAN MAC transmit
void WriteXmlAddNodeCounter(uint32_t counterId, std::string counterName, CounterType counterType)
Write XML add node counter function.
void WriteXmlPRef(uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo="")
Write XMLP Ref function.
NodeCounterMap64 m_nodeWifiPhyTxDrop
node wifi Phy transmit drop
void WriteLinkProperties()
Write link properties function.
void WriteIpv4Addresses()
Write IPv4 Addresses function.
const std::vector< std::string > GetElementsFromContext(const std::string &context) const
Get elements from context.
void WriteXmlAddResource(uint32_t resourceId, std::string resourcePath)
Write XML add resource function.
void OutputWirelessPacketTxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
Output wireless packet transmit info.
void LteSpectrumPhyRxStart(std::string context, Ptr< const PacketBurst > pb)
LTE Spectrum Phy receive start function.
void SetOutputFile(const std::string &fn, bool routing=false)
Set output file function.
NodeCounterMap64 m_nodeWifiMacTx
node wifi MAC transmit
AnimUidPacketInfoMap m_pendingWimaxPackets
pending wimax packets
void LteTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
LTE transmit trace function.
void EnableIpv4L3ProtocolCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Ipv4 L3 Protocol Counters such as Tx, Rx, Drop.
int WriteN(const char *data, uint32_t count, FILE *f)
WriteN function.
std::map< std::string, uint32_t > m_macToNodeIdMap
MAC to node ID map.
Ptr< Node > GetNodeFromContext(const std::string &context) const
Get node from context.
std::map< uint32_t, Vector > m_nodeLocation
node location
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Get net device from context.
FILE * m_routingF
File handle for routing table output (0 if None);.
void UpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Helper function to update the image of a node.
void TrackWifiPhyCounters()
Track wifi phy counters function.
AnimUidPacketInfoMap m_pendingUanPackets
pending UAN packets
void TrackIpv4RoutePaths()
Track IPv4 route paths function.
double GetNodeEnergyFraction(Ptr< const Node > node) const
Get node's energy fraction (This used only for testing)
bool IsInTimeWindow()
Is in time window function.
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
CSMA Phy transmit begin trace function.
bool m_enablePacketMetadata
enable packet metadata
void PurgePendingPackets(ProtocolType protocolType)
Purge pending packets function.
void SetMaxPktsPerTraceFile(uint64_t maxPktsPerFile)
Set Max packets per trace file.
uint64_t m_maxPktsPerFile
maximum packets per file
uint32_t m_ipv4L3ProtocolRxCounterId
IPv4 L3 protocol receive counter ID.
NodeCounterMap64 m_nodeIpv4Rx
node IPv4 receive
~AnimationInterface()
Destructor for the animator interface.
void AddToIpv4AddressNodeIdTable(std::string ipv4Address, uint32_t nodeId)
Add to IPv4 address node ID table function.
NodeIdIpv4Map m_nodeIdIpv4Map
node ID to IPv4 map
Time m_queueCountersPollInterval
queue counters poll interval
std::vector< std::string > GetIpv6Addresses(Ptr< NetDevice > nd)
Get IPv6 addresses.
void UpdateLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription)
Helper function to update the description for a link.
void Ipv4RxTrace(std::string context, Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 receive trace function.
NodeCounterMap64 m_nodeQueueEnqueue
node queue enqueue
void WriteXmlUpdateNodeCounter(uint32_t counterId, uint32_t nodeId, double value)
Write XML update node counter function.
std::vector< std::string > GetIpv4Addresses(Ptr< NetDevice > nd)
Get IPv4 addresses.
Time m_wifiPhyCountersPollInterval
wifi Phy counters poll interval
uint32_t m_queueDequeueCounterId
queue dequeue counter ID
NodeCounterMap64 m_nodeWifiMacRx
node wifi MAC receive
void AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId)
Add to IPv6 address node ID table function.
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP.
NodeCounterMap64 m_nodeIpv4Drop
node IPv4 drop
Time m_ipv4L3ProtocolCountersStopTime
IPv4 L3 protocol counters stop time.
uint32_t m_queueEnqueueCounterId
queue enqueue counter ID
void AddByteTag(uint64_t animUid, Ptr< const Packet > p)
Add byte tag function.
Time m_ipv4L3ProtocolCountersPollInterval
IPv4 L3 protocol counters poll interval.
void WriteNonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
Write non P2P link properties function.
void StopAnimation(bool onlyAnimation=false)
Stop animation function.
std::vector< Ipv4RoutePathElement > Ipv4RoutePathElements
Ipv4RoutePathElements typedef.
void UanPhyGenTxTrace(std::string context, Ptr< const Packet >)
UAN Phy gen transmit trace function.
void WifiMacTxDropTrace(std::string context, Ptr< const Packet > p)
wifi MAC transmit drop trace function
uint32_t m_ipv4L3ProtocolTxCounterId
IPv4 L3 protocol transmit counter ID.
Time m_queueCountersStopTime
queue counters stop time
std::string CounterTypeToString(CounterType counterType)
Counter type to string function.
ProtocolType
ProtocolType enumeration.
std::string GetMacAddress(Ptr< NetDevice > nd)
Get MAC address function.
std::vector< Ptr< Node > > GetMovedNodes()
Get moved nodes function.
uint32_t m_wifiMacTxCounterId
wifi MAC transmit counter ID
void SkipPacketTracing()
Do not trace packets.
NodeCounterMap64 m_nodeWifiMacRxDrop
node wifi MAC receive drop
NodeDescriptionsMap m_nodeDescriptions
node description
void WriteXmlAnim(bool routing=false)
Write XML anim function.
void SetStartTime(Time t)
Specify the time at which capture should start.
uint32_t AddResource(std::string resourcePath)
Add a resource such as the path to an image file.
AnimationInterface(const std::string filename)
Constructor.
std::string GetIpv6Address(Ptr< NetDevice > nd)
Get IPv6 address.
void WriteNodeEnergies()
Write node energies function.
void CsmaMacRxTrace(std::string context, Ptr< const Packet > p)
CSMA MAC receive trace function.
void WifiPhyTxBeginTrace(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
wifi Phy transmit PSDU begin trace function
void UanPhyGenRxTrace(std::string context, Ptr< const Packet >)
UAN Phy gen receive trace function.
LinkPropertiesMap m_linkProperties
link properties
void WriteXmlUpdateNodeDescription(uint32_t nodeId)
Write XML update node description function.
void UpdateNodeSize(Ptr< Node > n, double width, double height)
Helper function to update the size of a node.
std::map< uint32_t, NodeSize > m_nodeSizes
node sizes
std::pair< uint32_t, std::string > NodeIdIpv6Pair
NodeIdIpv6Pair typedef.
void ConnectLte()
Connect LTE function.
bool m_trackPackets
track packets
std::string GetNetAnimVersion()
Get netanim version function.
void WriteXmlNonP2pLinkProperties(uint32_t id, std::string ipAddress, std::string channelType)
Write XML non P2P link properties function.
AnimationInterface & EnableIpv4RouteTracking(std::string fileName, Time startTime, Time stopTime, Time pollInterval=Seconds(5))
Enable tracking of the Ipv4 routing table for all Nodes.
void WriteXmlClose(std::string name, bool routing=false)
Write XML close function.
uint64_t gAnimUid
Packet unique identifier used by AnimationInterface.
void CheckMaxPktsPerTraceFile()
Check maximum packets per trace file function.
NodeCounterMap64 m_nodeLrWpanMacTxDrop
node LR-WPAN MAC transmit drop
NodeIdIpv6Map m_nodeIdIpv6Map
node ID to IPv6 map
void TrackIpv4Route()
Track IPv4 router function.
void EnableWifiPhyCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Wifi Phy Counters such as TxDrop, RxDrop.
AnimUidPacketInfoMap m_pendingWifiPackets
pending wifi packets
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
Time m_routingStopTime
routing stop time
void SetStopTime(Time t)
Specify the time at which capture should stop.
void MobilityCourseChangeTrace(Ptr< const MobilityModel > mob)
Mobility course change trace function.
void EnableWifiMacCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Wifi Mac Counters such as Tx, TxDrop, Rx, RxDrop.
void WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, uint32_t tId, double fbRx, double lbRx, std::string metaInfo="")
Write XMLP function.
uint32_t m_wifiMacTxDropCounterId
wifi MAC transmit drop counter ID
void WriteXmlRp(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
Write XMLRP function.
AnimUidPacketInfoMap m_pendingLrWpanPackets
pending LR-WPAN packets
void WifiMacTxTrace(std::string context, Ptr< const Packet > p)
wifi MAC transmit trace function
void ResetAnimWriteCallback()
Reset the write callback function.
void WimaxRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &m)
WIMax receive trace function.
void LrWpanMacTxDropTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC transmit drop trace function.
void LrWpanMacRxTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC receive trace function.
std::vector< std::string > m_nodeCounters
node counters
void WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY)
Write XML node function.
AnimWriteCallback m_writeCallback
write callback
NodeCounterMap64 m_nodeWifiMacTxDrop
node wifi MAC transmit drop
uint64_t m_currentPktCount
current packet count
std::string GetIpv4RoutingTable(Ptr< Node > n)
Get IPv4 routing table function.
void Ipv4TxTrace(std::string context, Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interfaceIndex)
IPv4 transmit trace function.
std::pair< uint32_t, std::string > NodeIdIpv4Pair
NodeIdIpv4Pair typedef.
void EnqueueTrace(std::string context, Ptr< const Packet >)
Enqueue trace function.
uint64_t GetTracePktCount() const
Get trace file packet count (This used only for testing)
void WriteXmlUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
Write XML update node color function.
Vector UpdatePosition(Ptr< Node > n)
Update position function.
std::string m_outputFileName
output file name
void WriteIpv6Addresses()
Write IPv6 Addresses function.
void AddPendingPacket(ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo)
Add pending packet function.
NodeCounterMap64 m_nodeWifiPhyRxDrop
node wifi Phy receive drop
void WriteXmlIpv4Addresses(uint32_t nodeId, std::vector< std::string > ipv4Addresses)
Write XML Ipv4 addresses function.
Vector GetPosition(Ptr< Node > n)
Get position function.
AnimUidPacketInfoMap m_pendingLtePackets
pending LTE packets
void SetBackgroundImage(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Helper function to set the background image.
void WriteNodes()
Write nodes function.
NodeCounterMap64 m_nodeLrWpanMacRxDrop
node LR-WPAN MAC receive drop
Time m_wifiMacCountersStopTime
wifi MAC counters stop time
void WriteNodeColors()
Write node colors function.
void RecursiveIpv4RoutePathSearch(std::string from, std::string to, Ipv4RoutePathElements &rpElements)
Recursive IPv4 route path search function.
static bool IsInitialized()
Check if AnimationInterface is initialized.
void LrWpanMacTxTrace(std::string context, Ptr< const Packet > p)
LR-WPAN MAC transmit trace function.
void WriteXmlUpdateBackground(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Write XML update background function.
void CsmaPhyTxEndTrace(std::string context, Ptr< const Packet > p)
CSMA Phy transmit end trace function.
void WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height)
Write XML update node size function.
uint32_t m_remainingEnergyCounterId
remaining energy counter ID
void WriteXmlUpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Write XML update node image function.
uint32_t m_wifiMacRxDropCounterId
wifi MAC receive drop counter ID
void TrackWifiMacCounters()
Track wifi MAC counters function.
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node.
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color.
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
NodeCounterMap64 m_nodeQueueDequeue
node queue dequeue
void WifiPhyTxDropTrace(std::string context, Ptr< const Packet > p)
wifi Phy transmit drop trace function
uint32_t m_wifiPhyRxDropCounterId
wifi Phy receive drop counter ID
void WriteXmlUpdateLink(uint32_t fromId, uint32_t toId, std::string linkDescription)
Write XML update link counter function.
void ConnectLteEnb(Ptr< Node > n, Ptr< LteEnbNetDevice > nd, uint32_t devIndex)
Connect LTE ENB function.
void GenericWirelessRxTrace(std::string context, Ptr< const Packet > p, ProtocolType protocolType)
Generic wireless receive trace function.
std::string GetPacketMetadata(Ptr< const Packet > p)
Get packet metadata function.
uint32_t m_wifiPhyTxDropCounterId
wifi Phy transmit drop counter ID
std::vector< Ipv4RouteTrackElement > m_ipv4RouteTrackElements
IPv route track elements.
void EnableQueueCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Queue Counters such as Enqueue, Dequeue, Queue Drops.
uint32_t m_ipv4L3ProtocolDropCounterId
IPv4 protocol drop counter ID.
Time m_wifiPhyCountersStopTime
wifi Phy counters stop time
Time m_mobilityPollInterval
mobility poll interval
void OutputWirelessPacketRxInfo(Ptr< const Packet > p, AnimPacketInfo &pktInfo, uint64_t animUid)
Output wireless packet receive info.
std::map< std::string, uint32_t > m_ipv4ToNodeIdMap
IPv4 to node ID map.
AnimUidPacketInfoMap m_pendingCsmaPackets
pending CSMA packets
std::vector< std::string > m_resources
resources
void TrackIpv4L3ProtocolCounters()
Track IPv4 L3 protocol counters function.
void WriteXmlUpdateNodePosition(uint32_t nodeId, double x, double y)
Write XML update node position function.
void StartAnimation(bool restart=false)
Start animation function.
void DevTxTrace(std::string context, Ptr< const Packet > p, Ptr< NetDevice > tx, Ptr< NetDevice > rx, Time txTime, Time rxTime)
Device transmit trace function.
std::string GetIpv4Address(Ptr< NetDevice > nd)
Get IPv4 address.
void WifiMacRxTrace(std::string context, Ptr< const Packet > p)
wifi MAC receive trace function
bool IsStarted() const
Is AnimationInterface started.
void WriteXmlIpv6Addresses(uint32_t nodeId, std::vector< std::string > ipv6Addresses)
Write XML Ipv6 addresses function.
NodeContainer m_routingNc
routing node container
void SetAnimWriteCallback(AnimWriteCallback cb)
Set a callback function to listen to AnimationInterface write events.
void QueueDropTrace(std::string context, Ptr< const Packet >)
Queue trace function.
void WriteXmlLink(uint32_t fromId, uint32_t toLp, uint32_t toId)
Write XML link counter function.
std::map< uint64_t, AnimPacketInfo > AnimUidPacketInfoMap
AnimUidPacketInfoMap typedef.
BaseStation NetDevice.
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:63
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:56
bool HasNext() const
Definition: packet.cc:72
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:42
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
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.
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.
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 GetId() const
Definition: node.cc:117
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
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
static void EnablePrinting()
Enable printing packets metadata.
Definition: packet.cc:596
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
Net device for UAN models.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
Hold together all Wifi-related objects.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time stopTime
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:985
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:961
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:702
static bool initialized
Initialization flag.
std::map< WifiSpectrumBandInfo, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:78
uint8_t data[writeSize]
Ipv4RoutePathElement structure IPv4 route path element.
Ipv4RouteTrackElement structure IPv4 route track element.
NodeSize structure node size.
RGB structure RGB structure.