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
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))
111 std::stringstream stream;
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");
131 rpElements.push_back (elem);
166 std::ostringstream oss;
172 rpElements.push_back (elem);
176 rpElements.push_back (elem2);
182 rpElements.push_back (elem);
226 std::ostringstream oss;
233 rpElements.push_back (elem);
237 rpElements.push_back (elem2);
243 rpElements.push_back (elem);
248 rpElements.push_back (elem);
293 std::ostringstream oss;
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");
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);
474 std::vector <uint64_t> purgeList;
484 purgeList.push_back (i->first);
488 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
489 i != purgeList.end ();
501 std::vector <uint64_t> purgeList;
511 purgeList.push_back (i->first);
515 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
516 i != purgeList.end ();
529 std::vector <uint64_t> purgeList;
539 purgeList.push_back (i->first);
543 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
544 i != purgeList.end ();
555 std::vector <uint64_t> purgeList;
565 purgeList.push_back (i->first);
569 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
570 i != purgeList.end ();
581 std::ostringstream oss;
583 return oss.str ().substr (6);
601 std::ostringstream oss;
626 struct Rgb rgb = {255, 0, 0};
634 std::ostringstream oss;
644 std::ostringstream oss;
655 uint32_t n1Id = n->
GetId ();
657 for (uint32_t i = 0; i < nDev; ++i)
677 if (channelType == std::string (
"ns3::PointToPointChannel"))
681 for (uint32_t j = 0; j < nChDev; ++j)
692 std::ostringstream oss;
699 oss <<
"0.0 L " << n1Id <<
" " << n2Id << std::endl;
714 if (
m_xml && !restart)
742 std::ostringstream oss;
744 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
765 std::ostringstream oss;
767 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
788 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
812 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
814 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
826 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
828 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
830 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
834 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
836 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
875 return WriteN (st.c_str (), st.length (), f);
880 std::vector < Ptr <Node> > MovedNodes;
903 MovedNodes.push_back (n);
921 uint32_t nLeft = count;
922 const char* p =
data;
923 uint32_t written = 0;
926 int n = std::fwrite (p, 1, nLeft, f);
941 std::ostringstream oss;
946 oss <<
GetXMLOpenClose_p (
"p", 0, fbTx, lbTx, 0, fbRx, lbRx,
"",
"DummyPktIgnoreThis");
954 NS_LOG_INFO (
"Writing Route Path From :" << nodeId <<
" To: " << destination.c_str ());
970 std::ostringstream oss;
984 std::ostringstream oss;
986 double lbTx = (now + txTime).GetSeconds ();
987 double fbRx = (now + rxTime - txTime).GetSeconds ();
988 double lbRx = (now + rxTime).GetSeconds ();
998 oss << std::setprecision (10);
1002 << (now + txTime).GetSeconds () <<
" "
1003 << (now + rxTime - txTime).GetSeconds () <<
" "
1004 << (now + rxTime).GetSeconds () << std::endl;
1020 return n->
GetDevice (atoi (elements[3].c_str ()));
1105 NS_LOG_INFO (
"UanPhyGenRxTrace for packet:" << AnimUid);
1108 NS_LOG_WARN (
"UanPhyGenRxBeginTrace: unknown Uid");
1136 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
1137 std::ostringstream oss;
1157 NS_LOG_INFO (
"TxDropTrace for packet:" << AnimUid);
1173 NS_LOG_INFO (
"Wifi RxBeginTrace for packet:" << AnimUid);
1177 std::ostringstream oss;
1193 NS_LOG_WARN (
"WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1224 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1249 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1287 NS_LOG_INFO (
"WimaxRxTrace for packet:" << AnimUid);
1348 context =
"/" + context;
1354 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1380 context =
"/" + context;
1386 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1396 NS_LOG_WARN (
"LteSpectrumPhyRxTrace: unknown Uid");
1435 NS_LOG_INFO (
"CsmaPhyTxEndTrace for packet:" << AnimUid);
1441 NS_LOG_WARN (
"Unknown Uid, but adding Csma Packet anyway");
1466 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid);
1491 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1515 std::ostringstream oss;
1526 if ((ceil (oldLocation.
x) == ceil (newLocation.
x)) &&
1527 (ceil (oldLocation.
y) == ceil (newLocation.
y)))
1543 std::ostringstream oss;
1545 for (uint32_t i = 0; i < MovedNodes.size (); i++)
1567 std::ostringstream oss;
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\
1650 std::ostringstream oss;
1651 uint32_t nodeId = 0;
1669 std::ostringstream oss;
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};
1707 NS_LOG_INFO (
"Setting node visibility for Node Id:" << nodeId);
1708 std::ostringstream oss;
1727 NS_LOG_INFO (
"Setting node color for Node Id:" << nodeId);
1728 struct Rgb rgb = {r, g, b};
1730 std::ostringstream oss;
1739 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1749 std::string linkDescription)
1751 std::ostringstream oss;
1757 std::string linkDescription)
1761 std::ostringstream oss;
1767 std::string linkDescription,
1768 std::string fromNodeDescription,
1769 std::string toNodeDescription)
1775 LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
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");
1818 std::ostringstream oss;
1828 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1829 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1842 std::ostringstream oss;
1848 std::ostringstream oss;
1849 oss <<
"<topology minX = \"" << minX <<
"\" minY = \"" << minY
1850 <<
"\" maxX = \"" << maxX <<
"\" maxY = \"" << maxY
1851 <<
"\">" << std::endl;
1862 std::ostringstream oss;
1863 oss <<
"<nodeupdate id=\"" <<
id <<
"\"";
1866 oss <<
" visible=\"" << 1 <<
"\"";
1868 oss <<
" visible=\"" << 0 <<
"\"";
1875 oss <<
" descr=\"\"";
1877 oss <<
" r=\"" << (uint32_t)r <<
"\" "
1878 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1885 std::ostringstream oss;
1886 oss <<
"<node id=\"" <<
id <<
"\"";
1893 oss <<
" descr=\"\"";
1895 oss <<
" locX = \"" << locX <<
"\" " <<
"locY = \"" << locY <<
"\" />\n";
1904 std::ostringstream oss;
1905 oss <<
"<node id = \"" <<
id <<
"\"";
1912 oss <<
" descr=\"\"";
1914 oss <<
" locX=\"" << locX <<
"\" " <<
"locY=\"" << locY <<
"\"" <<
" r=\"" << (uint32_t)r <<
"\" "
1915 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1921 std::ostringstream oss;
1923 <<
" fromId=\"" << fromId
1924 <<
"\" toId=\"" << toId
1927 oss <<
" ld=\"" << linkDescription <<
"\""
1935 std::ostringstream oss;
1936 oss <<
"<link fromId=\"" << fromId
1937 <<
"\" toId=\"" << toId
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 () <<
"\">";
1977 std::ostringstream oss;
1979 <<
" id=\"" << nodeId <<
"\""
1980 <<
" info=\"" << routingInfo.c_str () <<
"\""
1981 <<
"/>" << std::endl;
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 ();
1996 oss <<
"<rpe" <<
" n=\"" << rpElement.
nodeId <<
"\"" <<
" nH=\"" << rpElement.
nextHop.c_str () <<
"\"" <<
"/>" << std::endl;
1998 oss <<
"<rp/>" << std::endl;
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;
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;
2040 std::ostringstream oss;
2041 oss << std::setprecision (10);
2042 oss <<
"<rx toId=\"" << toId
2043 <<
"\" fbRx=\"" << fbRx
2044 <<
"\" lbRx=\"" << lbRx
2045 <<
"\"/>" << std::endl;
2051 std::ostringstream oss;
2052 oss <<
"<meta info=\""
2053 << metaInfo <<
"\" />" << std::endl;
2060 std::ostringstream oss;
2061 oss <<
"<nonp2plinkproperties id=\""
2063 <<
" ipv4Address=\"" << ipv4Address <<
"\""
2064 <<
" channelType=\"" << channelType <<
"\""
2065 <<
"/>" << std::endl;
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> ()
2103 return sizeof (uint64_t);