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);
227 rpElements.push_back (elem);
231 std::ostringstream oss;
237 rpElements.push_back (elem);
241 rpElements.push_back (elem2);
247 rpElements.push_back (elem);
252 rpElements.push_back (elem);
297 std::ostringstream oss;
313 return "netanim-3.103";
332 NS_LOG_INFO (
"Creating new trace file:" << fn.c_str ());
333 m_f = std::fopen (fn.c_str (),
"w");
442 NS_LOG_UNCOND (
"AnimationInterface WARNING:Node:" << n->
GetId () <<
" Does not have a mobility model. Use SetConstantPosition if it is stationary");
443 Vector deterministicVector (100,100,0);
478 std::vector <uint64_t> purgeList;
488 purgeList.push_back (i->first);
492 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
493 i != purgeList.end ();
505 std::vector <uint64_t> purgeList;
515 purgeList.push_back (i->first);
519 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
520 i != purgeList.end ();
533 std::vector <uint64_t> purgeList;
543 purgeList.push_back (i->first);
547 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
548 i != purgeList.end ();
559 std::vector <uint64_t> purgeList;
569 purgeList.push_back (i->first);
573 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
574 i != purgeList.end ();
585 std::ostringstream oss;
587 return oss.str ().substr (6);
605 std::ostringstream oss;
630 struct Rgb rgb = {255, 0, 0};
638 std::ostringstream oss;
648 std::ostringstream oss;
659 uint32_t n1Id = n->
GetId ();
661 for (uint32_t i = 0; i < nDev; ++i)
681 if (channelType == std::string (
"ns3::PointToPointChannel"))
685 for (uint32_t j = 0; j < nChDev; ++j)
696 std::ostringstream oss;
703 oss <<
"0.0 L " << n1Id <<
" " << n2Id << std::endl;
718 if (
m_xml && !restart)
746 std::ostringstream oss;
748 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
769 std::ostringstream oss;
771 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
792 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
816 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
818 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
830 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
832 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
834 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
838 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
840 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
879 return WriteN (st.c_str (), st.length (), f);
884 std::vector < Ptr <Node> > MovedNodes;
907 MovedNodes.push_back (n);
925 uint32_t nLeft = count;
926 const char* p =
data;
927 uint32_t written = 0;
930 int n = std::fwrite (p, 1, nLeft, f);
945 std::ostringstream oss;
950 oss <<
GetXMLOpenClose_p (
"p", 0, fbTx, lbTx, 0, fbRx, lbRx,
"",
"DummyPktIgnoreThis");
958 NS_LOG_INFO (
"Writing Route Path From :" << nodeId <<
" To: " << destination.c_str ());
974 std::ostringstream oss;
988 std::ostringstream oss;
990 double lbTx = (now + txTime).GetSeconds ();
991 double fbRx = (now + rxTime - txTime).GetSeconds ();
992 double lbRx = (now + rxTime).GetSeconds ();
1002 oss << std::setprecision (10);
1006 << (now + txTime).GetSeconds () <<
" "
1007 << (now + rxTime - txTime).GetSeconds () <<
" "
1008 << (now + rxTime).GetSeconds () << std::endl;
1024 return n->
GetDevice (atoi (elements[3].c_str ()));
1109 NS_LOG_INFO (
"UanPhyGenRxTrace for packet:" << AnimUid);
1112 NS_LOG_WARN (
"UanPhyGenRxBeginTrace: unknown Uid");
1140 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
1141 std::ostringstream oss;
1161 NS_LOG_INFO (
"TxDropTrace for packet:" << AnimUid);
1177 NS_LOG_INFO (
"Wifi RxBeginTrace for packet:" << AnimUid);
1181 std::ostringstream oss;
1197 NS_LOG_WARN (
"WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1228 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1253 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1291 NS_LOG_INFO (
"WimaxRxTrace for packet:" << AnimUid);
1352 context =
"/" + context;
1358 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1384 context =
"/" + context;
1390 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1400 NS_LOG_WARN (
"LteSpectrumPhyRxTrace: unknown Uid");
1439 NS_LOG_INFO (
"CsmaPhyTxEndTrace for packet:" << AnimUid);
1445 NS_LOG_WARN (
"Unknown Uid, but adding Csma Packet anyway");
1470 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid);
1474 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid <<
" complete");
1501 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1525 std::ostringstream oss;
1536 if ((ceil (oldLocation.
x) == ceil (newLocation.
x)) &&
1537 (ceil (oldLocation.
y) == ceil (newLocation.
y)))
1553 std::ostringstream oss;
1555 for (uint32_t i = 0; i < MovedNodes.size (); i++)
1577 std::ostringstream oss;
1602 "<information><!-- \n\
1603 Description of attributes:\n\
1604 =========================\n\
1606 * ver = Current version\n\
1608 * minX = minimum X coordinate of the canvas\n\
1609 * minY = minimum Y coordinate of the canvas\n\
1610 * maxX = maximum X coordinate of the canvas\n\
1611 * maxY = maximum Y coordinate of the canvas\n\
1614 * locX = X coordinate\n\
1615 * locY = Y coordinate\n\
1616 * r = Red component\n\
1617 * g = Green component\n\
1618 * b = Blue component\n\
1620 * fromId = From Node Id\n\
1621 * toId = To Node Id\n\
1622 * fd = From Node description (for IP Address)\n\
1623 * td = To Node description (for IP Address)\n\
1624 * ld = Link description (for Bandwidth, delay etc)\n\
1626 * t = Simulation time\n\
1627 * ld = Link description (for Bandwidth, delay etc)\n\
1629 * t = Simulation time\n\
1630 * descr = Node description\n\
1631 * r = Red component\n\
1632 * g = Green component\n\
1633 * b = Blue component\n\
1634 * visible = Node visibility\n\
1636 * fId = From Node Id\n\
1637 * fbTx = First bit transmit time\n\
1638 * lbTx = Last bit transmit time\n\
1639 * tId = To Node Id\n\
1640 * fbRx = First bit Rx Time\n\
1641 * lbRx = Last bit Rx\n\
1642 * meta-info = Packet meta data\n\
1644 * fId = From Node Id\n\
1645 * fbTx = First bit transmit time\n\
1646 * lbTx = Last bit transmit time\n\
1647 * range = Reception range\n\
1648 * tId = To Node Id\n\
1649 * fbRx = First bit Rx time\n\
1650 * meta-info = Packet meta data\n\
1651 * lbRx = Last bit Rx time-->\n\
1660 std::ostringstream oss;
1661 uint32_t nodeId = 0;
1679 std::ostringstream oss;
1695 hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1699 hubLoc->SetPosition (hubVec);
1700 NS_LOG_INFO (
"Node:" << n->
GetId () <<
" Position set to:(" << x <<
"," << y <<
"," << z <<
")");
1707 NS_FATAL_ERROR (
"SetNodeColor must be used prior to creating the AnimationInterface object");
1710 struct Rgb rgb = {r, g, b};
1717 NS_LOG_INFO (
"Setting node visibility for Node Id:" << nodeId);
1718 std::ostringstream oss;
1737 NS_LOG_INFO (
"Setting node color for Node Id:" << nodeId);
1738 struct Rgb rgb = {r, g, b};
1740 std::ostringstream oss;
1749 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1759 std::string linkDescription)
1761 std::ostringstream oss;
1767 std::string linkDescription)
1771 std::ostringstream oss;
1777 std::string linkDescription,
1778 std::string fromNodeDescription,
1779 std::string toNodeDescription)
1785 LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1801 std::string linkDescription,
1802 std::string fromNodeDescription,
1803 std::string toNodeDescription)
1814 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1828 std::ostringstream oss;
1838 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1839 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1852 std::ostringstream oss;
1858 std::ostringstream oss;
1859 oss <<
"<topology minX = \"" << minX <<
"\" minY = \"" << minY
1860 <<
"\" maxX = \"" << maxX <<
"\" maxY = \"" << maxY
1861 <<
"\">" << std::endl;
1872 std::ostringstream oss;
1873 oss <<
"<nodeupdate id=\"" <<
id <<
"\"";
1876 oss <<
" visible=\"" << 1 <<
"\"";
1878 oss <<
" visible=\"" << 0 <<
"\"";
1885 oss <<
" descr=\"\"";
1887 oss <<
" r=\"" << (uint32_t)r <<
"\" "
1888 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1895 std::ostringstream oss;
1896 oss <<
"<node id=\"" <<
id <<
"\"";
1903 oss <<
" descr=\"\"";
1905 oss <<
" locX = \"" << locX <<
"\" " <<
"locY = \"" << locY <<
"\" />\n";
1914 std::ostringstream oss;
1915 oss <<
"<node id = \"" <<
id <<
"\"";
1922 oss <<
" descr=\"\"";
1924 oss <<
" locX=\"" << locX <<
"\" " <<
"locY=\"" << locY <<
"\"" <<
" r=\"" << (uint32_t)r <<
"\" "
1925 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1931 std::ostringstream oss;
1933 <<
" fromId=\"" << fromId
1934 <<
"\" toId=\"" << toId
1937 oss <<
" ld=\"" << linkDescription <<
"\""
1945 std::ostringstream oss;
1946 oss <<
"<link fromId=\"" << fromId
1947 <<
"\" toId=\"" << toId
1976 std::ostringstream oss;
1977 oss << std::setprecision (10);
1978 oss <<
"<p fId=\"" << fromId
1979 <<
"\" fbTx=\"" << fbTx
1980 <<
"\" lbTx=\"" << lbTx
1981 << (auxInfo.empty()?
"":
"\" aux=\"") << auxInfo.c_str () <<
"\">";
1987 std::ostringstream oss;
1989 <<
" id=\"" << nodeId <<
"\""
1990 <<
" info=\"" << routingInfo.c_str () <<
"\""
1991 <<
"/>" << std::endl;
1997 std::ostringstream oss;
1999 <<
" id=\"" << nodeId <<
"\"" <<
" d=\"" << destination.c_str () <<
"\""
2000 <<
" c=\"" << rpElements.size () <<
"\"" <<
">" << std::endl;
2001 for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2002 i != rpElements.end ();
2006 oss <<
"<rpe" <<
" n=\"" << rpElement.
nodeId <<
"\"" <<
" nH=\"" << rpElement.
nextHop.c_str () <<
"\"" <<
"/>" << std::endl;
2008 oss <<
"</rp>" << std::endl;
2014 uint32_t tId,
double fbRx,
double lbRx, std::string metaInfo,
2015 std::string auxInfo)
2017 std::ostringstream oss;
2018 oss << std::setprecision (10);
2019 oss <<
"<" << pktType <<
" fId=\"" << fId
2020 <<
"\" fbTx=\"" << fbTx
2021 <<
"\" lbTx=\"" << lbTx <<
"\"";
2022 if (!auxInfo.empty ())
2024 oss <<
" aux=\"" << auxInfo.c_str () <<
"\"";
2026 if (!metaInfo.empty ())
2028 oss <<
" meta-info=\"" << metaInfo.c_str () <<
"\"";
2030 oss <<
" tId=\"" << tId <<
"\" fbRx=\"" << fbRx <<
"\" lbRx=\"" << lbRx <<
"\">" << std::endl;
2038 std::ostringstream oss;
2039 oss << std::setprecision (10);
2040 oss <<
"<wpacket fromId=\"" << fromId
2041 <<
"\" fbTx=\"" << fbTx
2042 <<
"\" lbTx=\"" << lbTx
2043 <<
"\" range=\"" << range <<
"\">" << std::endl;
2050 std::ostringstream oss;
2051 oss << std::setprecision (10);
2052 oss <<
"<rx toId=\"" << toId
2053 <<
"\" fbRx=\"" << fbRx
2054 <<
"\" lbRx=\"" << lbRx
2055 <<
"\"/>" << std::endl;
2061 std::ostringstream oss;
2062 oss <<
"<meta info=\""
2063 << metaInfo <<
"\" />" << std::endl;
2070 std::ostringstream oss;
2071 oss <<
"<nonp2plinkproperties id=\""
2073 <<
" ipv4Address=\"" << ipv4Address <<
"\""
2074 <<
" channelType=\"" << channelType <<
"\""
2075 <<
"/>" << std::endl;
2082 std::vector <std::string> elements;
2083 size_t pos1=0, pos2;
2084 while (pos1 != context.npos)
2086 pos1 = context.find (
"/",pos1);
2087 pos2 = context.find (
"/",pos1+1);
2088 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
2090 pos2 = context.npos;
2100 .AddConstructor<AnimByteTag> ()
2113 return sizeof (uint64_t);