24 #include "ns3/animation-interface.h"
25 #include "ns3/channel.h"
26 #include "ns3/config.h"
28 #include "ns3/mobility-model.h"
29 #include "ns3/packet.h"
30 #include "ns3/simulator.h"
31 #include "ns3/animation-interface-helper.h"
32 #include "ns3/wifi-mac-header.h"
33 #include "ns3/wimax-mac-header.h"
34 #include "ns3/wifi-net-device.h"
35 #include "ns3/wifi-mac.h"
36 #include "ns3/constant-position-mobility-model.h"
37 #include "ns3/lte-ue-phy.h"
38 #include "ns3/lte-enb-phy.h"
39 #include "ns3/uan-net-device.h"
40 #include "ns3/uan-mac.h"
42 #include "ns3/ipv4-routing-protocol.h"
56 #define PURGE_INTERVAL 5
58 static bool initialized =
false;
59 std::map <uint32_t, std::string> AnimationInterface::nodeDescriptions;
60 std::map <uint32_t, Rgb> AnimationInterface::nodeColors;
61 std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> AnimationInterface::linkProperties;
65 : m_routingF (0), m_xml (usingXML), m_mobilityPollInterval (
Seconds(0.25)),
66 m_outputFileName (fn),
67 m_outputFileSet (false), gAnimUid (0), m_randomPosition (true),
68 m_writeCallback (0), m_started (false),
69 m_enablePacketMetadata (false), m_startTime (
Seconds(0)), m_stopTime (
Seconds(3600 * 1000)),
70 m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn),
71 m_routingStopTime (
Seconds (0)), m_routingFileName (
""),
72 m_routingPollInterval (
Seconds (5))
86 m_routingFileName = fileName;
87 SetRoutingOutputFile (m_routingFileName);
88 m_routingStopTime = stopTime;
89 m_routingPollInterval = pollInterval;
90 WriteN (GetXMLOpen_anim (0), m_routingF);
101 std::string AnimationInterface::GetIpv4RoutingTable (
Ptr <Node> n)
111 std::stringstream stream;
112 Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
118 void AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
120 NS_LOG_INFO (
"RecursiveIpv4RoutePathSearch from:" << from.c_str () <<
" to:" << to.c_str ());
121 if ((from ==
"0.0.0.0") || (from ==
"127.0.0.1"))
123 NS_LOG_INFO (
"Got " << from.c_str () <<
" End recursion");
128 if (fromNode->GetId () == toNode->GetId ())
130 Ipv4RoutePathElement elem = { fromNode->GetId (),
"L" };
131 rpElements.push_back (elem);
136 NS_FATAL_ERROR (
"Node: " << m_ipv4ToNodeIdMap[from] <<
" Not found");
141 NS_FATAL_ERROR (
"Node: " << m_ipv4ToNodeIdMap[to] <<
" Not found");
150 Ptr <Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
158 header.SetDestination (Ipv4Address (to.c_str ()));
159 Socket::SocketErrno sockerr;
160 Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
165 NS_LOG_UNCOND (
"Node: " << fromNode->GetId () <<
" G:" << rt->GetGateway ());
166 std::ostringstream oss;
167 oss << rt->GetGateway ();
168 if (oss.str () ==
"0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
171 Ipv4RoutePathElement elem = { fromNode->GetId (),
"C" };
172 rpElements.push_back (elem);
173 if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
175 Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to],
"L" };
176 rpElements.push_back (elem2);
180 NS_LOG_INFO (
"Node:" << fromNode->GetId () <<
"-->" << rt->GetGateway ());
181 Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
182 rpElements.push_back (elem);
183 RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
187 void AnimationInterface::TrackIpv4RoutePaths ()
189 if (m_ipv4RouteTrackElements.empty ())
193 for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
194 i != m_ipv4RouteTrackElements.end ();
197 Ipv4RouteTrackElement trackElement = *i;
201 NS_FATAL_ERROR (
"Node: " << trackElement.fromNodeId <<
" Not found");
204 Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <
ns3::Ipv4> ();
210 Ptr <Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
216 NS_LOG_INFO (
"Begin Track Route for: " << trackElement.destination.c_str () <<
" From:" << trackElement.fromNodeId);
219 header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
220 Socket::SocketErrno sockerr;
221 Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
224 NS_LOG_INFO (
"No route to :" << trackElement.destination.c_str ());
226 std::ostringstream oss;
227 oss << rt->GetGateway ();
228 NS_LOG_INFO (
"Node:" << trackElement.fromNodeId <<
"-->" << rt->GetGateway ());
229 Ipv4RoutePathElements rpElements;
230 if (rt->GetGateway () ==
"0.0.0.0")
232 Ipv4RoutePathElement elem = { trackElement.fromNodeId,
"C" };
233 rpElements.push_back (elem);
234 if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
236 Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination],
"L" };
237 rpElements.push_back (elem2);
240 else if (rt->GetGateway () ==
"127.0.0.1")
242 Ipv4RoutePathElement elem = { trackElement.fromNodeId,
"-1" };
243 rpElements.push_back (elem);
247 Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
248 rpElements.push_back (elem);
250 RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
251 WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
256 void AnimationInterface::TrackIpv4Route ()
263 if (m_routingNc.
GetN ())
265 for (NodeContainer::Iterator i = m_routingNc.
Begin (); i != m_routingNc.
End (); ++i)
268 WriteN (GetXMLOpenClose_routing (n->GetId (), GetIpv4RoutingTable (n)), m_routingF);
276 WriteN (GetXMLOpenClose_routing (n->GetId (), GetIpv4RoutingTable (n)), m_routingF);
279 TrackIpv4RoutePaths ();
290 void AnimationInterface::StartNewTraceFile ()
293 std::ostringstream oss;
296 if (m_currentPktCount <= m_maxPktsPerFile)
301 m_outputFileName = m_originalFileName +
"-" + oss.str ();
307 std::string AnimationInterface::GetNetAnimVersion ()
309 return "netanim-3.103";
328 NS_LOG_INFO (
"Creating new trace file:" << fn.c_str ());
329 m_f = std::fopen (fn.c_str (),
"w");
335 m_outputFileName = fn;
336 m_outputFileSet =
true;
340 bool AnimationInterface::SetRoutingOutputFile (
const std::string& fn)
347 m_routingF = std::fopen (fn.c_str (),
"w");
358 m_enablePacketMetadata = enable;
376 m_writeCallback = cb;
384 bool AnimationInterface::IsInTimeWindow ()
393 bool AnimationInterface::UanPacketIsPending (uint64_t AnimUid)
395 return (m_pendingUanPackets.find (AnimUid) != m_pendingUanPackets.end ());
398 bool AnimationInterface::WifiPacketIsPending (uint64_t AnimUid)
400 return (m_pendingWifiPackets.find (AnimUid) != m_pendingWifiPackets.end ());
403 bool AnimationInterface::CsmaPacketIsPending (uint64_t AnimUid)
405 return (m_pendingCsmaPackets.find (AnimUid) != m_pendingCsmaPackets.end ());
409 bool AnimationInterface::WimaxPacketIsPending (uint64_t AnimUid)
411 return (m_pendingWimaxPackets.find (AnimUid) != m_pendingWimaxPackets.end ());
414 bool AnimationInterface::LtePacketIsPending (uint64_t AnimUid)
416 return (m_pendingLtePackets.find (AnimUid) != m_pendingLtePackets.end ());
421 m_mobilityPollInterval = t;
426 m_randomPosition = setRandPos;
438 NS_LOG_UNCOND (
"AnimationInterface WARNING:Node:" << n->
GetId () <<
" Does not have a mobility model. Use SetConstantPosition if it is stationary");
439 Vector deterministicVector (100,100,0);
441 if (m_randomPosition)
443 m_nodeLocation[n->
GetId ()] = randomVector;
447 m_nodeLocation[n->
GetId ()] = deterministicVector;
450 return m_nodeLocation[n->
GetId ()];
453 Vector AnimationInterface::UpdatePosition (Ptr <Node> n, Vector v)
455 m_nodeLocation[n->GetId ()] = v;
459 Vector AnimationInterface::GetPosition (Ptr <Node> n)
462 if (m_nodeLocation.find (n->GetId()) == m_nodeLocation.end ())
464 NS_FATAL_ERROR (
"Node:" <<n->GetId() <<
" not found in Location table");
467 return m_nodeLocation[n->GetId ()];
470 void AnimationInterface::PurgePendingWifi ()
472 if (m_pendingWifiPackets.empty ())
474 std::vector <uint64_t> purgeList;
475 for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWifiPackets.begin ();
476 i != m_pendingWifiPackets.end ();
480 AnimPacketInfo pktInfo = i->second;
482 if (delta > PURGE_INTERVAL)
484 purgeList.push_back (i->first);
488 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
489 i != purgeList.end ();
492 m_pendingWifiPackets.erase (*i);
497 void AnimationInterface::PurgePendingWimax ()
499 if (m_pendingWimaxPackets.empty ())
501 std::vector <uint64_t> purgeList;
502 for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWimaxPackets.begin ();
503 i != m_pendingWimaxPackets.end ();
507 AnimPacketInfo pktInfo = i->second;
509 if (delta > PURGE_INTERVAL)
511 purgeList.push_back (i->first);
515 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
516 i != purgeList.end ();
519 m_pendingWimaxPackets.erase (*i);
525 void AnimationInterface::PurgePendingLte ()
527 if (m_pendingLtePackets.empty ())
529 std::vector <uint64_t> purgeList;
530 for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingLtePackets.begin ();
531 i != m_pendingLtePackets.end ();
535 AnimPacketInfo pktInfo = i->second;
537 if (delta > PURGE_INTERVAL)
539 purgeList.push_back (i->first);
543 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
544 i != purgeList.end ();
547 m_pendingLtePackets.erase (*i);
551 void AnimationInterface::PurgePendingCsma ()
553 if (m_pendingCsmaPackets.empty ())
555 std::vector <uint64_t> purgeList;
556 for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingCsmaPackets.begin ();
557 i != m_pendingCsmaPackets.end ();
561 AnimPacketInfo pktInfo = i->second;
563 if (delta > PURGE_INTERVAL)
565 purgeList.push_back (i->first);
569 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
570 i != purgeList.end ();
573 m_pendingCsmaPackets.erase (*i);
578 std::string AnimationInterface::GetMacAddress (Ptr <NetDevice> nd)
580 Address nodeAddr = nd->GetAddress();
581 std::ostringstream oss;
583 return oss.str ().substr (6);
586 std::string AnimationInterface::GetIpv4Address (Ptr <NetDevice> nd)
588 Ptr<Ipv4> ipv4 =
NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
591 NS_LOG_WARN (
"Node: " << nd->GetNode ()->GetId () <<
" No ipv4 object found");
594 int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
597 NS_LOG_WARN (
"Node :" << nd->GetNode ()->GetId () <<
" Could not find index of NetDevice");
600 Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
601 std::ostringstream oss;
602 oss << addr.GetLocal ();
608 m_currentPktCount = 0;
621 Vector v = UpdatePosition (n);
622 m_topoMinX = std::min (m_topoMinX, v.x);
623 m_topoMinY = std::min (m_topoMinY, v.y);
624 m_topoMaxX = std::max (m_topoMaxX, v.x);
625 m_topoMaxY = std::max (m_topoMaxY, v.y);
626 struct Rgb rgb = {255, 0, 0};
627 if (nodeColors.find (n->
GetId ()) == nodeColors.end ())
629 nodeColors[n->
GetId ()] = rgb;
634 std::ostringstream oss;
635 oss << GetXMLOpen_anim (0);
636 oss << GetPreamble ();
637 oss << GetXMLOpen_topology (m_topoMinX, m_topoMinY, m_topoMaxX, m_topoMaxY);
638 WriteN (oss.str (), m_f);
644 std::ostringstream oss;
645 Vector v = GetPosition (n);
646 struct Rgb rgb = nodeColors[n->
GetId ()];
647 oss << GetXMLOpenClose_node (0, n->
GetId (), v.
x, v.
y, rgb);
648 WriteN (oss.str (), m_f);
655 uint32_t n1Id = n->
GetId ();
657 for (uint32_t i = 0; i < nDev; ++i)
666 if ((dev->GetInstanceTypeId ().GetName () ==
"ns3::LteUeNetDevice") ||
667 (dev->GetInstanceTypeId ().GetName () ==
"ns3::LteEnbNetDevice")||
668 (dev->GetInstanceTypeId ().GetName () ==
"ns3::VirtualNetDevice"))
670 WriteNonP2pLinkProperties (n->
GetId (), GetIpv4Address (dev) +
"~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
671 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->
GetId ());
675 std::string channelType = ch->GetInstanceTypeId ().GetName ();
677 if (channelType == std::string (
"ns3::PointToPointChannel"))
680 uint32_t nChDev = ch->GetNDevices ();
681 for (uint32_t j = 0; j < nChDev; ++j)
684 uint32_t n2Id = chDev->GetNode ()->GetId ();
688 NS_LOG_INFO (
"Link:" << GetIpv4Address (dev) <<
":" << GetMacAddress (dev) <<
"----" << GetIpv4Address (chDev) <<
":" << GetMacAddress (chDev) );
689 SetLinkDescription (n1Id, n2Id,
"", GetIpv4Address (dev) +
"~" + GetMacAddress (dev), GetIpv4Address (chDev) +
"~" + GetMacAddress (chDev));
690 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n1Id);
691 AddToIpv4AddressNodeIdTable (GetIpv4Address (chDev), n2Id);
692 std::ostringstream oss;
695 oss << GetXMLOpenClose_link (0, n1Id, 0, n2Id);
699 oss <<
"0.0 L " << n1Id <<
" " << n2Id << std::endl;
701 WriteN (oss.str (), m_f);
707 NS_LOG_INFO (
"Link:" << GetIpv4Address (dev) <<
" Channel Type:" << channelType <<
" Mac: " << GetMacAddress (dev));
708 WriteNonP2pLinkProperties (n->
GetId (), GetIpv4Address (dev) +
"~" + GetMacAddress (dev), channelType);
709 AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->
GetId ());
713 linkProperties.clear ();
714 if (m_xml && !restart)
716 WriteN (GetXMLClose (
"topology"), m_f);
717 Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck,
this);
723 void AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
725 m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
731 m_ipv4RouteTrackElements.push_back (element);
742 std::ostringstream oss;
744 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
747 dlPhy->TraceConnect (
"TxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart,
this));
748 dlPhy->TraceConnect (
"RxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart,
this));
752 ulPhy->TraceConnect (
"TxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart,
this));
753 ulPhy->TraceConnect (
"RxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart,
this));
759 void AnimationInterface::ConnectLteUe (Ptr <Node> n, Ptr <LteUeNetDevice> nd, uint32_t devIndex)
762 Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
763 Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
764 Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
765 std::ostringstream oss;
767 oss <<
"NodeList/" << n->GetId () <<
"/DeviceList/" << devIndex <<
"/";
770 dlPhy->TraceConnect (
"TxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart,
this));
771 dlPhy->TraceConnect (
"RxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart,
this));
775 ulPhy->TraceConnect (
"TxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart,
this));
776 ulPhy->TraceConnect (
"RxStart",oss.str (),
MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart,
this));
780 void AnimationInterface::ConnectLte ()
787 uint32_t nDevices = n->GetNDevices ();
788 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
790 Ptr <NetDevice> nd = n->GetDevice(devIndex);
793 Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
796 ConnectLteUe (n, lteUeNetDevice, devIndex);
799 Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
801 ConnectLteEnb (n, lteEnbNetDevice, devIndex);
807 void AnimationInterface::ConnectCallbacks ()
812 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
813 MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace,
this));
814 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
815 MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace,
this));
817 MakeCallback (&AnimationInterface::MobilityCourseChangeTrace,
this));
819 MakeCallback (&AnimationInterface::WimaxTxTrace,
this));
821 MakeCallback (&AnimationInterface::WimaxRxTrace,
this));
826 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
827 MakeCallback (&AnimationInterface::CsmaPhyTxBeginTrace,
this));
828 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
829 MakeCallback (&AnimationInterface::CsmaPhyTxEndTrace,
this));
830 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
831 MakeCallback (&AnimationInterface::CsmaPhyRxEndTrace,
this));
833 MakeCallback (&AnimationInterface::CsmaMacRxTrace,
this));
834 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
835 MakeCallback (&AnimationInterface::UanPhyGenTxTrace,
this));
836 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
837 MakeCallback (&AnimationInterface::UanPhyGenRxTrace,
this));
853 WriteN (GetXMLClose (
"anim"), m_f);
857 m_outputFileSet =
false;
864 WriteN (GetXMLClose (
"anim"), m_routingF);
865 std::fclose (m_routingF);
869 int AnimationInterface::WriteN (
const std::string& st, FILE * f)
873 m_writeCallback (st.c_str ());
875 return WriteN (st.c_str (), st.length (), f);
878 std::vector <Ptr <Node> > AnimationInterface::RecalcTopoBounds ()
880 std::vector < Ptr <Node> > MovedNodes;
885 Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
889 newLocation = GetPosition (n);
893 newLocation = mobility->GetPosition ();
895 if (!NodeHasMoved (n, newLocation))
901 UpdatePosition (n, newLocation);
902 RecalcTopoBounds (newLocation);
903 MovedNodes.push_back (n);
909 void AnimationInterface::RecalcTopoBounds (Vector v)
911 m_topoMinX = std::min (m_topoMinX, v.x);
912 m_topoMinY = std::min (m_topoMinY, v.y);
913 m_topoMaxX = std::max (m_topoMaxX, v.x);
914 m_topoMaxY = std::max (m_topoMaxY, v.y);
918 int AnimationInterface::WriteN (
const char* data, uint32_t count, FILE * f)
921 uint32_t nLeft = count;
922 const char* p = data;
923 uint32_t written = 0;
926 int n = std::fwrite (p, 1, nLeft, f);
938 void AnimationInterface::WriteDummyPacket ()
941 std::ostringstream oss;
942 double fbTx = now.GetSeconds ();
943 double lbTx = now.GetSeconds ();
944 double fbRx = now.GetSeconds ();
945 double lbRx = now.GetSeconds ();
946 oss << GetXMLOpenClose_p (
"p", 0, fbTx, lbTx, 0, fbRx, lbRx,
"",
"DummyPktIgnoreThis");
947 WriteN (oss.str (), m_f);
952 void AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
954 NS_LOG_INFO (
"Writing Route Path From :" << nodeId <<
" To: " << destination.c_str ());
955 WriteN (GetXMLOpenClose_rp (nodeId, destination, rpElements), m_routingF);
968 void AnimationInterface::WriteNonP2pLinkProperties (uint32_t
id, std::string ipv4Address, std::string channelType)
970 std::ostringstream oss;
971 oss << GetXMLOpenClose_NonP2pLinkProperties (
id, ipv4Address, channelType);
972 WriteN (oss.str (), m_f);
975 void AnimationInterface::DevTxTrace (std::string context, Ptr<const Packet> p,
976 Ptr<NetDevice> tx, Ptr<NetDevice> rx,
977 Time txTime, Time rxTime)
979 if (!m_started || !IsInTimeWindow ())
984 std::ostringstream oss;
985 double fbTx = now.GetSeconds ();
986 double lbTx = (now + txTime).GetSeconds ();
987 double fbRx = (now + rxTime - txTime).GetSeconds ();
988 double lbRx = (now + rxTime).GetSeconds ();
991 oss << GetXMLOpenClose_p (
"p", tx->GetNode ()->GetId (), fbTx, lbTx, rx->GetNode ()->GetId (),
992 fbRx, lbRx, m_enablePacketMetadata? GetPacketMetadata (p):
"");
993 StartNewTraceFile ();
998 oss << std::setprecision (10);
999 oss << now.GetSeconds () <<
" P "
1000 << tx->GetNode ()->GetId () <<
" "
1001 << rx->GetNode ()->GetId () <<
" "
1002 << (now + txTime).GetSeconds () <<
" "
1003 << (now + rxTime - txTime).GetSeconds () <<
" "
1004 << (now + rxTime).GetSeconds () << std::endl;
1006 WriteN (oss.str (), m_f);
1011 AnimationInterface::GetNetDeviceFromContext (std::string context)
1017 std::vector <std::string> elements = GetElementsFromContext (context);
1020 return n->GetDevice (atoi (elements[3].c_str ()));
1023 void AnimationInterface::AddPendingUanPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
1025 m_pendingUanPackets[AnimUid] = pktinfo;
1029 void AnimationInterface::AddPendingWifiPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
1031 m_pendingWifiPackets[AnimUid] = pktinfo;
1034 void AnimationInterface::AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
1037 m_pendingWimaxPackets[AnimUid] = pktinfo;
1040 void AnimationInterface::AddPendingLtePacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
1043 m_pendingLtePackets[AnimUid] = pktinfo;
1046 void AnimationInterface::AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
1049 m_pendingCsmaPackets[AnimUid] = pktinfo;
1052 uint64_t AnimationInterface::GetAnimUidFromPacket (Ptr <const Packet> p)
1055 TypeId tid = tag.GetInstanceTypeId ();
1056 ByteTagIterator i = p->GetByteTagIterator ();
1058 while (i.HasNext ())
1060 ByteTagIterator::Item item = i.Next ();
1061 if (tid == item.GetTypeId ())
1077 void AnimationInterface::UanPhyGenTxTrace (std::string context, Ptr<const Packet> p)
1079 if (!m_started || !IsInTimeWindow ())
1081 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1083 Ptr <Node> n = ndev->GetNode ();
1086 NS_LOG_INFO (
"Uan TxBeginTrace for packet:" << gAnimUid);
1089 p->AddByteTag (tag);
1091 AddPendingUanPacket (gAnimUid, pktinfo);
1096 void AnimationInterface::UanPhyGenRxTrace (std::string context, Ptr<const Packet> p)
1098 if (!m_started || !IsInTimeWindow ())
1100 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1102 Ptr <Node> n = ndev->GetNode ();
1104 uint64_t AnimUid = GetAnimUidFromPacket (p);
1105 NS_LOG_INFO (
"UanPhyGenRxTrace for packet:" << AnimUid);
1106 if (!UanPacketIsPending (AnimUid))
1108 NS_LOG_WARN (
"UanPhyGenRxBeginTrace: unknown Uid");
1111 m_pendingUanPackets[AnimUid].ProcessRxBegin (ndev,
Simulator::Now ());
1112 m_pendingUanPackets[AnimUid].ProcessRxEnd (ndev,
Simulator::Now (), UpdatePosition (n));
1113 OutputWirelessPacket (p, m_pendingUanPackets[AnimUid], m_pendingUanPackets[AnimUid].GetRxInfo (ndev));
1118 void AnimationInterface::WifiPhyTxBeginTrace (std::string context,
1119 Ptr<const Packet> p)
1121 if (!m_started || !IsInTimeWindow ())
1123 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1125 Ptr <Node> n = ndev->GetNode ();
1129 NS_LOG_INFO (
"Wifi TxBeginTrace for packet:" << gAnimUid);
1132 p->AddByteTag (tag);
1134 AddPendingWifiPacket (gAnimUid, pktinfo);
1135 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
1136 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
1137 std::ostringstream oss;
1139 m_macToNodeIdMap[oss.str ()] = n->GetId ();
1140 NS_LOG_INFO (
"Added Mac" << oss.str () <<
" node:" <<m_macToNodeIdMap[oss.str ()]);
1143 void AnimationInterface::WifiPhyTxEndTrace (std::string context,
1144 Ptr<const Packet> p)
1148 void AnimationInterface::WifiPhyTxDropTrace (std::string context,
1149 Ptr<const Packet> p)
1151 if (!m_started || !IsInTimeWindow ())
1153 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1156 uint64_t AnimUid = GetAnimUidFromPacket (p);
1157 NS_LOG_INFO (
"TxDropTrace for packet:" << AnimUid);
1158 NS_ASSERT (WifiPacketIsPending (AnimUid) ==
true);
1159 m_pendingWifiPackets.erase (m_pendingWifiPackets.find (AnimUid));
1163 void AnimationInterface::WifiPhyRxBeginTrace (std::string context,
1164 Ptr<const Packet> p)
1166 if (!m_started || !IsInTimeWindow ())
1168 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1170 Ptr <Node> n = ndev->GetNode ();
1172 uint64_t AnimUid = GetAnimUidFromPacket (p);
1173 NS_LOG_INFO (
"Wifi RxBeginTrace for packet:" << AnimUid);
1174 if (!WifiPacketIsPending (AnimUid))
1177 std::ostringstream oss;
1179 if(!p->PeekHeader (hdr))
1184 oss << hdr.GetAddr2 ();
1185 if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1192 AddPendingWifiPacket (AnimUid, pktinfo);
1193 NS_LOG_WARN (
"WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1196 m_pendingWifiPackets[AnimUid].ProcessRxBegin (ndev,
Simulator::Now ());
1197 m_pendingWifiPackets[AnimUid].ProcessRxEnd (ndev,
Simulator::Now (), UpdatePosition (n));
1198 OutputWirelessPacket (p, m_pendingWifiPackets[AnimUid], m_pendingWifiPackets[AnimUid].GetRxInfo (ndev));
1202 void AnimationInterface::WifiPhyRxEndTrace (std::string context,
1203 Ptr<const Packet> p)
1205 if (!m_started || !IsInTimeWindow ())
1207 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1209 Ptr <Node> n = ndev->GetNode ();
1211 uint64_t AnimUid = GetAnimUidFromPacket (p);
1212 if (!WifiPacketIsPending (AnimUid))
1216 AddPendingWifiPacket (AnimUid, pktinfo);
1219 AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1220 pktInfo.ProcessRxEnd (ndev,
Simulator::Now (), UpdatePosition (n));
1221 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1222 if (pktrxInfo.IsPhyRxComplete ())
1224 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1225 OutputWirelessPacket (p, pktInfo, pktrxInfo);
1229 void AnimationInterface::WifiMacRxTrace (std::string context,
1230 Ptr<const Packet> p)
1232 if (!m_started || !IsInTimeWindow ())
1234 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1236 Ptr <Node> n = ndev->GetNode ();
1238 uint64_t AnimUid = GetAnimUidFromPacket (p);
1239 if (!WifiPacketIsPending (AnimUid))
1245 AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1246 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1247 if (pktrxInfo.IsPhyRxComplete ())
1249 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1250 OutputWirelessPacket (p, pktInfo, pktrxInfo);
1254 void AnimationInterface::WifiPhyRxDropTrace (std::string context,
1255 Ptr<const Packet> p)
1259 void AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p,
const Mac48Address & m)
1261 if (!m_started || !IsInTimeWindow ())
1263 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1265 Ptr <Node> n = ndev->GetNode ();
1268 NS_LOG_INFO (
"WimaxTxTrace for packet:" << gAnimUid);
1273 p->AddByteTag (tag);
1274 AddPendingWimaxPacket (gAnimUid, pktinfo);
1278 void AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p,
const Mac48Address & m)
1280 if (!m_started || !IsInTimeWindow ())
1282 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1284 Ptr <Node> n = ndev->GetNode ();
1286 uint64_t AnimUid = GetAnimUidFromPacket (p);
1287 NS_LOG_INFO (
"WimaxRxTrace for packet:" << AnimUid);
1288 NS_ASSERT (WimaxPacketIsPending (AnimUid) ==
true);
1289 AnimPacketInfo& pktInfo = m_pendingWimaxPackets[AnimUid];
1293 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1294 OutputWirelessPacket (p, pktInfo, pktrxInfo);
1297 void AnimationInterface::LteTxTrace (std::string context, Ptr<const Packet> p,
const Mac48Address & m)
1299 if (!m_started || !IsInTimeWindow ())
1301 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1303 Ptr <Node> n = ndev->GetNode ();
1306 NS_LOG_INFO (
"LteTxTrace for packet:" << gAnimUid);
1311 p->AddByteTag (tag);
1312 AddPendingLtePacket (gAnimUid, pktinfo);
1316 void AnimationInterface::LteRxTrace (std::string context, Ptr<const Packet> p,
const Mac48Address & m)
1318 if (!m_started || !IsInTimeWindow ())
1320 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1322 Ptr <Node> n = ndev->GetNode ();
1324 uint64_t AnimUid = GetAnimUidFromPacket (p);
1325 NS_LOG_INFO (
"LteRxTrace for packet:" << gAnimUid);
1326 if (!LtePacketIsPending (AnimUid))
1331 AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1335 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1336 OutputWirelessPacket (p, pktInfo, pktrxInfo);
1339 void AnimationInterface::LteSpectrumPhyTxStart (std::string context, Ptr<const PacketBurst> pb)
1341 if (!m_started || !IsInTimeWindow ())
1348 context =
"/" + context;
1349 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1351 Ptr <Node> n = ndev->GetNode ();
1354 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1355 for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1359 Ptr <Packet> p = *i;
1361 NS_LOG_INFO (
"LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1366 p->AddByteTag (tag);
1367 AddPendingLtePacket (gAnimUid, pktinfo);
1371 void AnimationInterface::LteSpectrumPhyRxStart (std::string context, Ptr<const PacketBurst> pb)
1373 if (!m_started || !IsInTimeWindow ())
1380 context =
"/" + context;
1381 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1383 Ptr <Node> n = ndev->GetNode ();
1386 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1387 for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1391 Ptr <Packet> p = *i;
1392 uint64_t AnimUid = GetAnimUidFromPacket (p);
1393 NS_LOG_INFO (
"LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1394 if (!LtePacketIsPending (AnimUid))
1396 NS_LOG_WARN (
"LteSpectrumPhyRxTrace: unknown Uid");
1399 AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1403 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1404 OutputWirelessPacket (p, pktInfo, pktrxInfo);
1408 void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr<const Packet> p)
1410 if (!m_started || !IsInTimeWindow ())
1412 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1414 Ptr <Node> n = ndev->GetNode ();
1417 NS_LOG_INFO (
"CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1420 p->AddByteTag (tag);
1422 AddPendingCsmaPacket (gAnimUid, pktinfo);
1426 void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr<const Packet> p)
1428 if (!m_started || !IsInTimeWindow ())
1430 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1432 Ptr <Node> n = ndev->GetNode ();
1434 uint64_t AnimUid = GetAnimUidFromPacket (p);
1435 NS_LOG_INFO (
"CsmaPhyTxEndTrace for packet:" << AnimUid);
1436 if (!CsmaPacketIsPending (AnimUid))
1440 AddPendingCsmaPacket (AnimUid, pktinfo);
1441 NS_LOG_WARN (
"Unknown Uid, but adding Csma Packet anyway");
1444 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1448 void AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr<const Packet> p)
1450 if (!m_started || !IsInTimeWindow ())
1452 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1454 Ptr <Node> n = ndev->GetNode ();
1456 uint64_t AnimUid = GetAnimUidFromPacket (p);
1457 if (!CsmaPacketIsPending (AnimUid))
1463 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1464 m_pendingCsmaPackets[AnimUid].ProcessRxBegin (ndev,
Simulator::Now ());
1465 pktInfo.ProcessRxEnd (ndev,
Simulator::Now (), UpdatePosition (n));
1466 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid);
1470 void AnimationInterface::CsmaMacRxTrace (std::string context,
1471 Ptr<const Packet> p)
1473 if (!m_started || !IsInTimeWindow ())
1476 Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1478 Ptr <Node> n = ndev->GetNode ();
1480 uint64_t AnimUid = GetAnimUidFromPacket (p);
1481 if (!CsmaPacketIsPending (AnimUid))
1487 AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1488 AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1489 if (pktrxInfo.IsPhyRxComplete ())
1491 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1492 OutputCsmaPacket (p, pktInfo, pktrxInfo);
1497 void AnimationInterface::MobilityCourseChangeTrace (Ptr <const MobilityModel> mobility)
1500 if (!m_started || !IsInTimeWindow ())
1502 Ptr <Node> n = mobility->GetObject <Node> ();
1507 v = GetPosition (n);
1511 v = mobility->GetPosition ();
1513 UpdatePosition (n,v);
1514 RecalcTopoBounds (v);
1515 std::ostringstream oss;
1516 oss << GetXMLOpen_topology (m_topoMinX, m_topoMinY, m_topoMaxX, m_topoMaxY);
1517 oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y, nodeColors[n->GetId ()]);
1518 oss << GetXMLClose (
"topology");
1519 WriteN (oss.str (), m_f);
1520 WriteDummyPacket ();
1523 bool AnimationInterface::NodeHasMoved (Ptr <Node> n, Vector newLocation)
1525 Vector oldLocation = GetPosition (n);
1526 if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
1527 (ceil (oldLocation.y) == ceil (newLocation.y)))
1538 void AnimationInterface::MobilityAutoCheck ()
1540 if (!m_started || !IsInTimeWindow ())
1542 std::vector <Ptr <Node> > MovedNodes = RecalcTopoBounds ();
1543 std::ostringstream oss;
1544 oss << GetXMLOpen_topology (m_topoMinX, m_topoMinY, m_topoMaxX, m_topoMaxY);
1545 for (uint32_t i = 0; i < MovedNodes.size (); i++)
1547 Ptr <Node> n = MovedNodes [i];
1549 Vector v = GetPosition (n);
1550 oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y);
1552 oss << GetXMLClose (
"topology");
1553 WriteN (oss.str (), m_f);
1554 WriteDummyPacket ();
1557 PurgePendingWifi ();
1558 PurgePendingWimax ();
1560 PurgePendingCsma ();
1561 Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck,
this);
1565 std::string AnimationInterface::GetPacketMetadata (Ptr<const Packet> p)
1567 std::ostringstream oss;
1574 return m_currentPktCount;
1589 std::string AnimationInterface::GetPreamble ()
1592 "<information><!-- \n\
1593 Description of attributes:\n\
1594 =========================\n\
1596 * ver = Current version\n\
1598 * minX = minimum X coordinate of the canvas\n\
1599 * minY = minimum Y coordinate of the canvas\n\
1600 * maxX = maximum X coordinate of the canvas\n\
1601 * maxY = maximum Y coordinate of the canvas\n\
1604 * locX = X coordinate\n\
1605 * locY = Y coordinate\n\
1606 * r = Red component\n\
1607 * g = Green component\n\
1608 * b = Blue component\n\
1610 * fromId = From Node Id\n\
1611 * toId = To Node Id\n\
1612 * fd = From Node description (for IP Address)\n\
1613 * td = To Node description (for IP Address)\n\
1614 * ld = Link description (for Bandwidth, delay etc)\n\
1616 * t = Simulation time\n\
1617 * ld = Link description (for Bandwidth, delay etc)\n\
1619 * t = Simulation time\n\
1620 * descr = Node description\n\
1621 * r = Red component\n\
1622 * g = Green component\n\
1623 * b = Blue component\n\
1624 * visible = Node visibility\n\
1626 * fId = From Node Id\n\
1627 * fbTx = First bit transmit time\n\
1628 * lbTx = Last bit transmit time\n\
1629 * tId = To Node Id\n\
1630 * fbRx = First bit Rx Time\n\
1631 * lbRx = Last bit Rx\n\
1632 * meta-info = Packet meta data\n\
1634 * fId = From Node Id\n\
1635 * fbTx = First bit transmit time\n\
1636 * lbTx = Last bit transmit time\n\
1637 * range = Reception range\n\
1638 * tId = To Node Id\n\
1639 * fbRx = First bit Rx time\n\
1640 * meta-info = Packet meta data\n\
1641 * lbRx = Last bit Rx time-->\n\
1646 void AnimationInterface::OutputWirelessPacket (Ptr<const Packet> p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
1648 StartNewTraceFile ();
1650 std::ostringstream oss;
1651 uint32_t nodeId = 0;
1653 nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1655 nodeId = pktInfo.m_txNodeId;
1657 double lbTx = pktInfo.firstlastbitDelta + pktInfo.m_fbTx;
1658 uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1660 oss << GetXMLOpenClose_p (
"wp", nodeId, pktInfo.m_fbTx, lbTx, rxId,
1661 pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):
"");
1662 WriteN (oss.str (), m_f);
1665 void AnimationInterface::OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
1667 StartNewTraceFile ();
1669 std::ostringstream oss;
1671 uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1672 uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1674 oss << GetXMLOpenClose_p (
"p", nodeId, pktInfo.m_fbTx, pktInfo.m_lbTx, rxId,
1675 pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):
"");
1676 WriteN (oss.str (), m_f);
1685 hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1689 hubLoc->SetPosition (hubVec);
1690 NS_LOG_INFO (
"Node:" << n->
GetId () <<
" Position set to:(" << x <<
"," << y <<
"," << z <<
")");
1697 NS_FATAL_ERROR (
"SetNodeColor must be used prior to creating the AnimationInterface object");
1700 struct Rgb rgb = {r, g, b};
1701 nodeColors[n->
GetId ()] = rgb;
1707 NS_LOG_INFO (
"Setting node visibility for Node Id:" << nodeId);
1708 std::ostringstream oss;
1709 oss << GetXMLOpenClose_nodeupdate (nodeId, show);
1710 WriteN (oss.str (), m_f);
1727 NS_LOG_INFO (
"Setting node color for Node Id:" << nodeId);
1728 struct Rgb rgb = {r, g, b};
1729 nodeColors[nodeId] = rgb;
1730 std::ostringstream oss;
1731 oss << GetXMLOpenClose_nodeupdate (nodeId);
1732 WriteN (oss.str (), m_f);
1739 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1749 std::string linkDescription)
1751 std::ostringstream oss;
1752 oss << GetXMLOpenClose_linkupdate (fromNode, toNode, linkDescription);
1753 WriteN (oss.str (), m_f);
1757 std::string linkDescription)
1761 std::ostringstream oss;
1762 oss << GetXMLOpenClose_linkupdate (fromNode->
GetId (), toNode->
GetId (), linkDescription);
1763 WriteN (oss.str (), m_f);
1767 std::string linkDescription,
1768 std::string fromNodeDescription,
1769 std::string toNodeDescription)
1773 p2pPair.fromNode = fromNode;
1774 p2pPair.toNode = toNode;
1775 LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1776 linkProperties[p2pPair] = lp;
1791 std::string linkDescription,
1792 std::string fromNodeDescription,
1793 std::string toNodeDescription)
1804 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1806 nodeDescriptions[n->
GetId ()] = descr;
1817 nodeDescriptions[nodeId] = descr;
1818 std::ostringstream oss;
1819 oss << GetXMLOpenClose_nodeupdate (nodeId);
1820 WriteN (oss.str (), m_f);
1828 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1829 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1833 nodeDescriptions[n->
GetId ()] = descr;
1840 std::string AnimationInterface::GetXMLOpen_anim (uint32_t lp)
1842 std::ostringstream oss;
1843 oss <<
"<anim ver=\"" << GetNetAnimVersion () <<
"\">\n";
1846 std::string AnimationInterface::GetXMLOpen_topology (
double minX,
double minY,
double maxX,
double maxY)
1848 std::ostringstream oss;
1849 oss <<
"<topology minX = \"" << minX <<
"\" minY = \"" << minY
1850 <<
"\" maxX = \"" << maxX <<
"\" maxY = \"" << maxY
1851 <<
"\">" << std::endl;
1856 std::string AnimationInterface::GetXMLOpenClose_nodeupdate (uint32_t
id,
bool visible)
1858 struct Rgb
rgb = nodeColors[id];
1862 std::ostringstream oss;
1863 oss <<
"<nodeupdate id=\"" <<
id <<
"\"";
1866 oss <<
" visible=\"" << 1 <<
"\"";
1868 oss <<
" visible=\"" << 0 <<
"\"";
1869 if (nodeDescriptions.find (
id) != nodeDescriptions.end ())
1871 oss <<
" descr=\""<< nodeDescriptions[id] <<
"\"";
1875 oss <<
" descr=\"\"";
1877 oss <<
" r=\"" << (uint32_t)r <<
"\" "
1878 <<
" g=\"" << (uint32_t)g << "\" b=\"" << (uint32_t)b <<"\"/>\n";
1883 std::
string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t
id,
double locX,
double locY)
1885 std::ostringstream oss;
1886 oss <<
"<node id=\"" <<
id <<
"\"";
1887 if (nodeDescriptions.find (
id) != nodeDescriptions.end ())
1889 oss <<
" descr=\""<< nodeDescriptions[id] <<
"\"";
1893 oss <<
" descr=\"\"";
1895 oss <<
" locX = \"" << locX <<
"\" " <<
"locY = \"" << locY <<
"\" />\n";
1899 std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t
id,
double locX,
double locY,
struct Rgb rgb)
1904 std::ostringstream oss;
1905 oss <<
"<node id = \"" <<
id <<
"\"";
1906 if (nodeDescriptions.find (
id) != nodeDescriptions.end ())
1908 oss <<
" descr=\""<< nodeDescriptions[id] <<
"\"";
1912 oss <<
" descr=\"\"";
1914 oss <<
" locX=\"" << locX <<
"\" " <<
"locY=\"" << locY <<
"\"" <<
" r=\"" << (uint32_t)r <<
"\" "
1915 <<
" g=\"" << (uint32_t)g << "\" b=\"" << (uint32_t)b <<"\"/>\n";
1919 std::
string AnimationInterface::GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::
string linkDescription)
1921 std::ostringstream oss;
1923 <<
" fromId=\"" << fromId
1924 <<
"\" toId=\"" << toId
1927 oss <<
" ld=\"" << linkDescription <<
"\""
1933 std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
1935 std::ostringstream oss;
1936 oss <<
"<link fromId=\"" << fromId
1937 <<
"\" toId=\"" << toId
1940 LinkProperties lprop ;
1941 lprop.fromNodeDescription =
"";
1942 lprop.toNodeDescription =
"";
1943 lprop.linkDescription =
"";
1945 P2pLinkNodeIdPair p1 = { fromId, toId };
1946 P2pLinkNodeIdPair p2 = { toId, fromId };
1947 if (linkProperties.find (p1) != linkProperties.end())
1949 lprop = linkProperties[p1];
1951 else if (linkProperties.find (p2) != linkProperties.end())
1953 lprop = linkProperties[p2];
1956 oss <<
" fd=\"" << lprop.fromNodeDescription <<
"\""
1957 <<
" td=\"" << lprop.toNodeDescription <<
"\""
1958 <<
" ld=\"" << lprop.linkDescription <<
"\""
1964 std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId,
double fbTx,
double lbTx, std::string auxInfo)
1966 std::ostringstream oss;
1967 oss << std::setprecision (10);
1968 oss <<
"<p fId=\"" << fromId
1969 <<
"\" fbTx=\"" << fbTx
1970 <<
"\" lbTx=\"" << lbTx
1971 << (auxInfo.empty()?
"":
"\" aux=\"") << auxInfo.c_str () <<
"\">";
1975 std::string AnimationInterface::GetXMLOpenClose_routing (uint32_t nodeId, std::string routingInfo)
1977 std::ostringstream oss;
1979 <<
" id=\"" << nodeId <<
"\""
1980 <<
" info=\"" << routingInfo.c_str () <<
"\""
1981 <<
"/>" << std::endl;
1985 std::string AnimationInterface::GetXMLOpenClose_rp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
1987 std::ostringstream oss;
1989 <<
" id=\"" << nodeId <<
"\"" <<
" d=\"" << destination.c_str () <<
"\""
1990 <<
" c=\"" << rpElements.size () <<
"\"" <<
">" << std::endl;
1991 for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
1992 i != rpElements.end ();
1995 Ipv4RoutePathElement rpElement = *i;
1996 oss <<
"<rpe" <<
" n=\"" << rpElement.nodeId <<
"\"" <<
" nH=\"" << rpElement.nextHop.c_str () <<
"\"" <<
"/>" << std::endl;
1998 oss <<
"<rp/>" << std::endl;
2003 std::string AnimationInterface::GetXMLOpenClose_p (std::string pktType, uint32_t fId,
double fbTx,
double lbTx,
2004 uint32_t tId,
double fbRx,
double lbRx, std::string metaInfo,
2005 std::string auxInfo)
2007 std::ostringstream oss;
2008 oss << std::setprecision (10);
2009 oss <<
"<" << pktType <<
" fId=\"" << fId
2010 <<
"\" fbTx=\"" << fbTx
2011 <<
"\" lbTx=\"" << lbTx <<
"\"";
2012 if (!auxInfo.empty ())
2014 oss <<
" aux=\"" << auxInfo.c_str () <<
"\"";
2016 if (!metaInfo.empty ())
2018 oss <<
" meta-info=\"" << metaInfo.c_str () <<
"\"";
2020 oss <<
" tId=\"" << tId <<
"\" fbRx=\"" << fbRx <<
"\" lbRx=\"" << lbRx <<
"\">" << std::endl;
2026 std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp, uint32_t fromId,
double fbTx,
double lbTx,
double range)
2028 std::ostringstream oss;
2029 oss << std::setprecision (10);
2030 oss <<
"<wpacket fromId=\"" << fromId
2031 <<
"\" fbTx=\"" << fbTx
2032 <<
"\" lbTx=\"" << lbTx
2033 <<
"\" range=\"" << range <<
"\">" << std::endl;
2038 std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId,
double fbRx,
double lbRx)
2040 std::ostringstream oss;
2041 oss << std::setprecision (10);
2042 oss <<
"<rx toId=\"" << toId
2043 <<
"\" fbRx=\"" << fbRx
2044 <<
"\" lbRx=\"" << lbRx
2045 <<
"\"/>" << std::endl;
2049 std::string AnimationInterface::GetXMLOpenClose_meta (std::string metaInfo)
2051 std::ostringstream oss;
2052 oss <<
"<meta info=\""
2053 << metaInfo <<
"\" />" << std::endl;
2058 std::string AnimationInterface::GetXMLOpenClose_NonP2pLinkProperties (uint32_t
id, std::string ipv4Address, std::string channelType)
2060 std::ostringstream oss;
2061 oss <<
"<nonp2plinkproperties id=\""
2063 <<
" ipv4Address=\"" << ipv4Address <<
"\""
2064 <<
" channelType=\"" << channelType <<
"\""
2065 <<
"/>" << std::endl;
2070 std::vector<std::string> AnimationInterface::GetElementsFromContext (std::string context)
2072 std::vector <std::string> elements;
2073 size_t pos1=0, pos2;
2074 while (pos1 != context.npos)
2076 pos1 = context.find (
"/",pos1);
2077 pos2 = context.find (
"/",pos1+1);
2078 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
2080 pos2 = context.npos;
2090 .AddConstructor<AnimByteTag> ()
2097 return GetTypeId ();
2103 return sizeof (uint64_t);
2118 os <<
"AnimUid=" << m_AnimUid;
2123 m_AnimUid = AnimUid;
void Set(uint64_t AnimUid)
Set global Uid in tag.
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing)
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
static uint32_t GetNNodes(void)
void WriteU64(uint64_t v)
static Ptr< Node > GetNode(uint32_t n)
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP.
void EnablePacketMetadata(bool enable)
Enable Packet metadata.
static TypeId GetTypeId(void)
Get Type Id.
static void SetNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to set the node color.
Mobility model for which the current position does not change once it has been set and until it is se...
static bool IsInitialized(void)
Check if AnimationInterface is initialized.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
Vector GetPosition(void) const
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void Deserialize(TagBuffer i)
Deserialize function.
void Connect(std::string path, const CallbackBase &cb)
void SetStartTime(Time t)
Specify the time at which capture should start.
void SetStopTime(Time t)
Specify the time at which capture should stop.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color.
void ResetAnimWriteCallback()
Reset the write callback function.
#define NS_FATAL_ERROR(msg)
fatal error handling
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
virtual void Print(std::ostream &os) const
Print tag info.
Keep track of the current position and velocity of an object.
static void SetLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription, std::string fromNodeDescription="", std::string toNodeDescription="")
Helper function to set the description for a link.
void SetXMLOutput()
Specify that animation commands are to be written in XML format.
double GetSeconds(void) const
static void EnablePrinting(void)
void SetRandomPosition(bool setRandPos)
Set random position if a Mobility Model does not exists for the node.
~AnimationInterface()
Destructor for the animator interface.
static Iterator End(void)
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
static void SetNodeDescription(Ptr< Node > n, std::string descr)
Helper function to set a brief description for a given node.
Ptr< NetDevice > GetDevice(uint32_t index) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void StartAnimation(bool restart=false)
Writes the topology information and sets up the appropriate animation packet tx callback.
int64_t AssignStreams(int64_t stream)
AnimationInterface & EnableIpv4RouteTracking(std::string fileName, Time startTime, Time stopTime, Time pollInterval=Seconds(5))
Enable tracking of the Ipv4 routing table for all Nodes.
void AggregateObject(Ptr< Object > other)
Access to the Ipv4 forwarding table, interfaces, and configuration.
uint32_t GetNDevices(void) const
tag a set of bytes in a packet
keep track of a set of node pointers.
void UpdateLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription)
Helper function to update the description for a link.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
#define NS_LOG_UNCOND(msg)
virtual void Serialize(TagBuffer i) const
Serialize function.
bool SetOutputFile(const std::string &fn)
Specify that animation commands are to be written to the specified output file.
virtual TypeId GetInstanceTypeId(void) const
Get Instance Type Id.
void StopAnimation(bool onlyAnimation=false)
Closes the interface to the animator.
uint64_t Get(void) const
Get Uid in tag.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t GetId(void) const
static Iterator Begin(void)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
#define NS_LOG_DEBUG(msg)
AnimationInterface(const std::string filename, uint64_t maxPktsPerFile=MAX_PKTS_PER_TRACE_FILE, bool usingXML=true)
Constructor.
virtual uint32_t GetSerializedSize(void) const
Get Serialized Size.
Interface to network animator.
static bool IsFinished(void)
void SetAnimWriteCallback(AnimWriteCallback cb)
Set a callback function to listen to AnimationInterface write events.
void SetMobilityPollInterval(Time t)
Set mobility poll interval:WARNING: setting a low interval can cause slowness.
A structure to store red, blue and green components for entities such as nodes.
void ShowNode(uint32_t nodeId, bool show=true)
Helper function to show/hide a node.
bool IsStarted(void)
Is AnimationInterface started.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)