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))
110 std::stringstream stream;
153 std::ostringstream oss;
169 return "netanim-3.103";
188 NS_LOG_INFO (
"Creating new trace file:" << fn.c_str ());
189 m_f = std::fopen (fn.c_str (),
"w");
298 NS_LOG_UNCOND (
"AnimationInterface WARNING:Node:" << n->
GetId () <<
" Does not have a mobility model. Use SetConstantPosition if it is stationary");
299 Vector deterministicVector (100,100,0);
334 std::vector <uint64_t> purgeList;
344 purgeList.push_back (i->first);
348 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
349 i != purgeList.end ();
361 std::vector <uint64_t> purgeList;
371 purgeList.push_back (i->first);
375 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
376 i != purgeList.end ();
389 std::vector <uint64_t> purgeList;
399 purgeList.push_back (i->first);
403 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
404 i != purgeList.end ();
415 std::vector <uint64_t> purgeList;
425 purgeList.push_back (i->first);
429 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
430 i != purgeList.end ();
441 std::ostringstream oss;
443 return oss.str ().substr (6);
458 std::ostringstream oss;
483 struct Rgb rgb = {255, 0, 0};
491 std::ostringstream oss;
501 std::ostringstream oss;
512 uint32_t n1Id = n->
GetId ();
514 for (uint32_t i = 0; i < nDev; ++i)
525 if (channelType == std::string (
"ns3::PointToPointChannel"))
529 for (uint32_t j = 0; j < nChDev; ++j)
538 std::ostringstream oss;
545 oss <<
"0.0 L " << n1Id <<
" " << n2Id << std::endl;
559 if (
m_xml && !restart)
574 std::ostringstream oss;
576 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
597 std::ostringstream oss;
599 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
620 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
644 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
646 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
658 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
660 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
662 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
666 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
668 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
703 return WriteN (st.c_str (), st.length (), f);
708 std::vector < Ptr <Node> > MovedNodes;
731 MovedNodes.push_back (n);
749 uint32_t nLeft = count;
750 const char* p =
data;
751 uint32_t written = 0;
754 int n = std::fwrite (p, 1, nLeft, f);
769 std::ostringstream oss;
774 oss <<
GetXMLOpenClose_p (
"p", 0, fbTx, lbTx, 0, fbRx, lbRx,
"",
"DummyPktIgnoreThis");
783 std::ostringstream oss;
797 std::ostringstream oss;
799 double lbTx = (now + txTime).GetSeconds ();
800 double fbRx = (now + rxTime - txTime).GetSeconds ();
801 double lbRx = (now + rxTime).GetSeconds ();
811 oss << std::setprecision (10);
815 << (now + txTime).GetSeconds () <<
" "
816 << (now + rxTime - txTime).GetSeconds () <<
" "
817 << (now + rxTime).GetSeconds () << std::endl;
833 return n->
GetDevice (atoi (elements[3].c_str ()));
918 NS_LOG_INFO (
"UanPhyGenRxTrace for packet:" << AnimUid);
921 NS_LOG_WARN (
"UanPhyGenRxBeginTrace: unknown Uid");
949 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
950 std::ostringstream oss;
970 NS_LOG_INFO (
"TxDropTrace for packet:" << AnimUid);
986 NS_LOG_INFO (
"Wifi RxBeginTrace for packet:" << AnimUid);
990 std::ostringstream oss;
1006 NS_LOG_WARN (
"WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1037 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1062 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1100 NS_LOG_INFO (
"WimaxRxTrace for packet:" << AnimUid);
1161 context =
"/" + context;
1167 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1193 context =
"/" + context;
1199 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1209 NS_LOG_WARN (
"LteSpectrumPhyRxTrace: unknown Uid");
1248 NS_LOG_INFO (
"CsmaPhyTxEndTrace for packet:" << AnimUid);
1254 NS_LOG_WARN (
"Unknown Uid, but adding Csma Packet anyway");
1279 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid);
1304 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1328 std::ostringstream oss;
1339 if ((ceil (oldLocation.
x) == ceil (newLocation.
x)) &&
1340 (ceil (oldLocation.
y) == ceil (newLocation.
y)))
1356 std::ostringstream oss;
1358 for (uint32_t i = 0; i < MovedNodes.size (); i++)
1380 std::ostringstream oss;
1405 "<information><!-- \n\
1406 Description of attributes:\n\
1407 =========================\n\
1409 * ver = Current version\n\
1411 * minX = minimum X coordinate of the canvas\n\
1412 * minY = minimum Y coordinate of the canvas\n\
1413 * maxX = maximum X coordinate of the canvas\n\
1414 * maxY = maximum Y coordinate of the canvas\n\
1417 * locX = X coordinate\n\
1418 * locY = Y coordinate\n\
1419 * r = Red component\n\
1420 * g = Green component\n\
1421 * b = Blue component\n\
1423 * fromId = From Node Id\n\
1424 * toId = To Node Id\n\
1425 * fd = From Node description (for IP Address)\n\
1426 * td = To Node description (for IP Address)\n\
1427 * ld = Link description (for Bandwidth, delay etc)\n\
1429 * t = Simulation time\n\
1430 * ld = Link description (for Bandwidth, delay etc)\n\
1432 * t = Simulation time\n\
1433 * descr = Node description\n\
1434 * r = Red component\n\
1435 * g = Green component\n\
1436 * b = Blue component\n\
1437 * visible = Node visibility\n\
1439 * fId = From Node Id\n\
1440 * fbTx = First bit transmit time\n\
1441 * lbTx = Last bit transmit time\n\
1442 * tId = To Node Id\n\
1443 * fbRx = First bit Rx Time\n\
1444 * lbRx = Last bit Rx\n\
1445 * meta-info = Packet meta data\n\
1447 * fId = From Node Id\n\
1448 * fbTx = First bit transmit time\n\
1449 * lbTx = Last bit transmit time\n\
1450 * range = Reception range\n\
1451 * tId = To Node Id\n\
1452 * fbRx = First bit Rx time\n\
1453 * meta-info = Packet meta data\n\
1454 * lbRx = Last bit Rx time-->\n\
1463 std::ostringstream oss;
1464 uint32_t nodeId = 0;
1482 std::ostringstream oss;
1498 hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1502 hubLoc->SetPosition (hubVec);
1503 NS_LOG_INFO (
"Node:" << n->
GetId () <<
" Position set to:(" << x <<
"," << y <<
"," << z <<
")");
1510 NS_FATAL_ERROR (
"SetNodeColor must be used prior to creating the AnimationInterface object");
1513 struct Rgb rgb = {r, g, b};
1520 NS_LOG_INFO (
"Setting node visibility for Node Id:" << nodeId);
1521 std::ostringstream oss;
1540 NS_LOG_INFO (
"Setting node color for Node Id:" << nodeId);
1541 struct Rgb rgb = {r, g, b};
1543 std::ostringstream oss;
1552 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1562 std::string linkDescription)
1564 std::ostringstream oss;
1570 std::string linkDescription)
1574 std::ostringstream oss;
1580 std::string linkDescription,
1581 std::string fromNodeDescription,
1582 std::string toNodeDescription)
1588 LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1604 std::string linkDescription,
1605 std::string fromNodeDescription,
1606 std::string toNodeDescription)
1617 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1631 std::ostringstream oss;
1641 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1642 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1655 std::ostringstream oss;
1661 std::ostringstream oss;
1662 oss <<
"<topology minX = \"" << minX <<
"\" minY = \"" << minY
1663 <<
"\" maxX = \"" << maxX <<
"\" maxY = \"" << maxY
1664 <<
"\">" << std::endl;
1675 std::ostringstream oss;
1676 oss <<
"<nodeupdate id=\"" <<
id <<
"\"";
1679 oss <<
" visible=\"" << 1 <<
"\"";
1681 oss <<
" visible=\"" << 0 <<
"\"";
1688 oss <<
" descr=\"\"";
1690 oss <<
" r=\"" << (uint32_t)r <<
"\" "
1691 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1698 std::ostringstream oss;
1699 oss <<
"<node id=\"" <<
id <<
"\"";
1706 oss <<
" descr=\"\"";
1708 oss <<
" locX = \"" << locX <<
"\" " <<
"locY = \"" << locY <<
"\" />\n";
1717 std::ostringstream oss;
1718 oss <<
"<node id = \"" <<
id <<
"\"";
1725 oss <<
" descr=\"\"";
1727 oss <<
" locX=\"" << locX <<
"\" " <<
"locY=\"" << locY <<
"\"" <<
" r=\"" << (uint32_t)r <<
"\" "
1728 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1734 std::ostringstream oss;
1736 <<
" fromId=\"" << fromId
1737 <<
"\" toId=\"" << toId
1740 oss <<
" ld=\"" << linkDescription <<
"\""
1748 std::ostringstream oss;
1749 oss <<
"<link fromId=\"" << fromId
1750 <<
"\" toId=\"" << toId
1779 std::ostringstream oss;
1780 oss << std::setprecision (10);
1781 oss <<
"<p fId=\"" << fromId
1782 <<
"\" fbTx=\"" << fbTx
1783 <<
"\" lbTx=\"" << lbTx
1784 << (auxInfo.empty()?
"":
"\" aux=\"") << auxInfo.c_str () <<
"\">";
1790 std::ostringstream oss;
1792 <<
" id=\"" << nodeId <<
"\""
1793 <<
" info=\"" << routingInfo.c_str () <<
"\""
1794 <<
"/>" << std::endl;
1799 uint32_t tId,
double fbRx,
double lbRx, std::string metaInfo,
1800 std::string auxInfo)
1802 std::ostringstream oss;
1803 oss << std::setprecision (10);
1804 oss <<
"<" << pktType <<
" fId=\"" << fId
1805 <<
"\" fbTx=\"" << fbTx
1806 <<
"\" lbTx=\"" << lbTx <<
"\"";
1807 if (!auxInfo.empty ())
1809 oss <<
" aux=\"" << auxInfo.c_str () <<
"\"";
1811 if (!metaInfo.empty ())
1813 oss <<
" meta-info=\"" << metaInfo.c_str () <<
"\"";
1815 oss <<
" tId=\"" << tId <<
"\" fbRx=\"" << fbRx <<
"\" lbRx=\"" << lbRx <<
"\">" << std::endl;
1823 std::ostringstream oss;
1824 oss << std::setprecision (10);
1825 oss <<
"<wpacket fromId=\"" << fromId
1826 <<
"\" fbTx=\"" << fbTx
1827 <<
"\" lbTx=\"" << lbTx
1828 <<
"\" range=\"" << range <<
"\">" << std::endl;
1835 std::ostringstream oss;
1836 oss << std::setprecision (10);
1837 oss <<
"<rx toId=\"" << toId
1838 <<
"\" fbRx=\"" << fbRx
1839 <<
"\" lbRx=\"" << lbRx
1840 <<
"\"/>" << std::endl;
1846 std::ostringstream oss;
1847 oss <<
"<meta info=\""
1848 << metaInfo <<
"\" />" << std::endl;
1855 std::ostringstream oss;
1856 oss <<
"<nonp2plinkproperties id=\""
1858 <<
" ipv4Address=\"" << ipv4Address <<
"\""
1859 <<
" channelType=\"" << channelType <<
"\""
1860 <<
"/>" << std::endl;
1867 std::vector <std::string> elements;
1868 size_t pos1=0, pos2;
1869 while (pos1 != context.npos)
1871 pos1 = context.find (
"/",pos1);
1872 pos2 = context.find (
"/",pos1+1);
1873 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
1875 pos2 = context.npos;
1885 .AddConstructor<AnimByteTag> ()
1898 return sizeof (uint64_t);