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"
55 #define PURGE_INTERVAL 5
64 : m_xml (usingXML), m_mobilityPollInterval (
Seconds(0.25)),
65 m_outputFileName (fn),
66 m_outputFileSet (false), gAnimUid (0), m_randomPosition (true),
67 m_writeCallback (0), m_started (false),
68 m_enablePacketMetadata (false), m_startTime (
Seconds(0)), m_stopTime (
Seconds(3600 * 1000)),
69 m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn)
92 std::ostringstream oss;
108 return "netanim-3.101";
127 NS_LOG_INFO (
"Creating new trace file:" << fn.c_str ());
128 m_f = fopen (fn.c_str (),
"w");
221 NS_LOG_UNCOND (
"AnimationInterface WARNING:Node:" << n->
GetId () <<
" Does not have a mobility model. Use SetConstantPosition if it is stationary");
222 Vector deterministicVector (100,100,0);
257 std::vector <uint64_t> purgeList;
267 purgeList.push_back (i->first);
271 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
272 i != purgeList.end ();
284 std::vector <uint64_t> purgeList;
294 purgeList.push_back (i->first);
298 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
299 i != purgeList.end ();
312 std::vector <uint64_t> purgeList;
322 purgeList.push_back (i->first);
326 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
327 i != purgeList.end ();
338 std::vector <uint64_t> purgeList;
348 purgeList.push_back (i->first);
352 for (std::vector <uint64_t>::iterator i = purgeList.begin ();
353 i != purgeList.end ();
368 std::ostringstream oss;
393 struct Rgb rgb = {255, 0, 0};
403 std::ostringstream oss;
414 std::ostringstream oss;
426 oss <<
"0.0 N " << n->
GetId ()
427 <<
" " << v.
x <<
" " << v.
y << std::endl;
428 WriteN (oss.str ().c_str (), oss.str ().length ());
436 uint32_t n1Id = n->
GetId ();
438 for (uint32_t i = 0; i < nDev; ++i)
449 if (channelType == std::string (
"ns3::PointToPointChannel"))
453 for (uint32_t j = 0; j < nChDev; ++j)
462 std::ostringstream oss;
469 oss <<
"0.0 L " << n1Id <<
" " << n2Id << std::endl;
482 if (
m_xml && !restart)
497 std::ostringstream oss;
499 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
520 std::ostringstream oss;
522 oss <<
"NodeList/" << n->
GetId () <<
"/DeviceList/" << devIndex <<
"/";
543 for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
567 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
569 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
581 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
583 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
585 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
589 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
591 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
621 return WriteN (st.c_str (), st.length ());
630 m_topoMinX -= w * 0.05;
631 m_topoMinY -= h * 0.05;
634 NS_LOG_INFO (
"Added Canvas Margin:" << m_topoMinX <<
"," <<
640 std::vector < Ptr <Node> > MovedNodes;
663 MovedNodes.push_back (n);
690 uint32_t nLeft = count;
691 const char* p =
data;
692 uint32_t written = 0;
695 int n = fwrite (p, 1, nLeft,
m_f);
710 std::ostringstream oss;
734 std::ostringstream oss;
736 double lbTx = (now + txTime).GetSeconds ();
737 double fbRx = (now + rxTime - txTime).GetSeconds ();
738 double lbRx = (now + rxTime).GetSeconds ();
751 oss << std::setprecision (10);
755 << (now + txTime).GetSeconds () <<
" "
756 << (now + rxTime - txTime).GetSeconds () <<
" "
757 << (now + rxTime).GetSeconds () << std::endl;
773 return n->
GetDevice (atoi (elements[3].c_str ()));
858 NS_LOG_INFO (
"UanPhyGenRxTrace for packet:" << AnimUid);
861 NS_LOG_WARN (
"UanPhyGenRxBeginTrace: unknown Uid");
889 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
890 std::ostringstream oss;
910 NS_LOG_INFO (
"TxDropTrace for packet:" << AnimUid);
926 NS_LOG_INFO (
"Wifi RxBeginTrace for packet:" << AnimUid);
930 std::ostringstream oss;
946 NS_LOG_WARN (
"WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
977 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1002 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1040 NS_LOG_INFO (
"WimaxRxTrace for packet:" << AnimUid);
1101 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1127 std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1137 NS_LOG_WARN (
"LteSpectrumPhyRxTrace: unknown Uid");
1176 NS_LOG_INFO (
"CsmaPhyTxEndTrace for packet:" << AnimUid);
1182 NS_LOG_WARN (
"Unknown Uid, but adding Csma Packet anyway");
1207 NS_LOG_INFO (
"CsmaPhyRxEndTrace for packet:" << AnimUid);
1232 NS_LOG_INFO (
"MacRxTrace for packet:" << AnimUid <<
" complete");
1256 std::ostringstream oss;
1267 if ((ceil (oldLocation.
x) == ceil (newLocation.
x)) &&
1268 (ceil (oldLocation.
y) == ceil (newLocation.
y)))
1284 std::ostringstream oss;
1286 for (uint32_t i = 0; i < MovedNodes.size (); i++)
1308 std::ostringstream oss;
1333 "<information><!-- \n\
1334 Description of attributes:\n\
1335 =========================\n\
1337 * ver = Current version\n\
1339 * minX = minimum X coordinate of the canvas\n\
1340 * minY = minimum Y coordinate of the canvas\n\
1341 * maxX = maximum X coordinate of the canvas\n\
1342 * maxY = maximum Y coordinate of the canvas\n\
1345 * locX = X coordinate\n\
1346 * locY = Y coordinate\n\
1347 * r = Red component\n\
1348 * g = Green component\n\
1349 * b = Blue component\n\
1351 * fromId = From Node Id\n\
1352 * toId = To Node Id\n\
1353 * fd = From Node description (for IP Address)\n\
1354 * td = To Node description (for IP Address)\n\
1355 * ld = Link description (for Bandwidth, delay etc)\n\
1357 * t = Simulation time\n\
1358 * ld = Link description (for Bandwidth, delay etc)\n\
1360 * t = Simulation time\n\
1361 * descr = Node description\n\
1362 * r = Red component\n\
1363 * g = Green component\n\
1364 * b = Blue component\n\
1365 * visible = Node visibility\n\
1367 * fbTx = First bit transmit time\n\
1368 * lbTx = Last bit transmit time\n\
1370 * toId = To Node Id\n\
1371 * fbRx = First bit Rx Time\n\
1372 * lbRx = Last bit Rx\n\
1374 * fromId = From Node Id\n\
1375 * fbTx = First bit transmit time\n\
1376 * lbTx = Last bit transmit time\n\
1377 * range = Reception range\n\
1379 * toId = To Node Id\n\
1380 * fbRx = First bit Rx time\n\
1381 * lbRx = Last bit Rx time-->\n\
1390 std::ostringstream oss;
1391 uint32_t nodeId = 0;
1413 std::ostringstream oss;
1432 hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1436 hubLoc->SetPosition (hubVec);
1437 NS_LOG_INFO (
"Node:" << n->
GetId () <<
" Position set to:(" << x <<
"," << y <<
"," << z <<
")");
1444 NS_FATAL_ERROR (
"SetNodeColor must be used prior to creating the AnimationInterface object");
1447 struct Rgb rgb = {r, g, b};
1454 NS_LOG_INFO (
"Setting node visibility for Node Id:" << nodeId);
1455 std::ostringstream oss;
1474 NS_LOG_INFO (
"Setting node color for Node Id:" << nodeId);
1475 struct Rgb rgb = {r, g, b};
1477 std::ostringstream oss;
1486 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1496 std::string linkDescription)
1498 std::ostringstream oss;
1504 std::string linkDescription)
1508 std::ostringstream oss;
1514 std::string linkDescription,
1515 std::string fromNodeDescription,
1516 std::string toNodeDescription)
1522 LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1538 std::string linkDescription,
1539 std::string fromNodeDescription,
1540 std::string toNodeDescription)
1551 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1565 std::ostringstream oss;
1575 NS_FATAL_ERROR (
"SetNodeDescription must be used prior to creating the AnimationInterface object");
1576 for (uint32_t i = 0; i < nc.
GetN (); ++i)
1589 std::ostringstream oss;
1595 std::ostringstream oss;
1596 oss <<
"<topology minX = \"" << minX <<
"\" minY = \"" << minY
1597 <<
"\" maxX = \"" << maxX <<
"\" maxY = \"" << maxY
1598 <<
"\">" << std::endl;
1609 std::ostringstream oss;
1610 oss <<
"<nodeupdate id=\"" <<
id <<
"\"";
1613 oss <<
" visible=\"" << 1 <<
"\"";
1615 oss <<
" visible=\"" << 0 <<
"\"";
1622 oss <<
" descr=\"\"";
1624 oss <<
" r=\"" << (uint32_t)r <<
"\" "
1625 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1632 std::ostringstream oss;
1633 oss <<
"<node id=\"" <<
id <<
"\"";
1640 oss <<
" descr=\"\"";
1642 oss <<
" locX = \"" << locX <<
"\" " <<
"locY = \"" << locY <<
"\" />\n";
1651 std::ostringstream oss;
1652 oss <<
"<node id = \"" <<
id <<
"\"";
1659 oss <<
" descr=\"\"";
1661 oss <<
" locX=\"" << locX <<
"\" " <<
"locY=\"" << locY <<
"\"" <<
" r=\"" << (uint32_t)r <<
"\" "
1662 <<
" g=\"" << (uint32_t)g <<
"\" b=\"" << (uint32_t)b <<
"\"/>\n";
1668 std::ostringstream oss;
1670 <<
" fromId=\"" << fromId
1671 <<
"\" toId=\"" << toId
1674 oss <<
" ld=\"" << linkDescription <<
"\""
1682 std::ostringstream oss;
1683 oss <<
"<link fromId=\"" << fromId
1684 <<
"\" toId=\"" << toId
1713 std::ostringstream oss;
1714 oss << std::setprecision (10);
1715 oss <<
"<packet fromId=\"" << fromId
1716 <<
"\" fbTx=\"" << fbTx
1717 <<
"\" lbTx=\"" << lbTx
1718 << (auxInfo.empty()?
"":
"\" aux=\"") << auxInfo.c_str ()
1725 std::ostringstream oss;
1726 oss << std::setprecision (10);
1727 oss <<
"<wpacket fromId=\"" << fromId
1728 <<
"\" fbTx=\"" << fbTx
1729 <<
"\" lbTx=\"" << lbTx
1730 <<
"\" range=\"" << range <<
"\">" << std::endl;
1737 std::ostringstream oss;
1738 oss << std::setprecision (10);
1739 oss <<
"<rx toId=\"" << toId
1740 <<
"\" fbRx=\"" << fbRx
1741 <<
"\" lbRx=\"" << lbRx
1742 <<
"\"/>" << std::endl;
1748 std::ostringstream oss;
1749 oss <<
"<meta info=\""
1750 << metaInfo <<
"\" />" << std::endl;
1756 std::vector <std::string> elements;
1757 size_t pos1=0, pos2;
1758 while (pos1 != context.npos)
1760 pos1 = context.find (
"/",pos1);
1761 pos2 = context.find (
"/",pos1+1);
1762 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
1764 pos2 = context.npos;
1774 .AddConstructor<AnimByteTag> ()
1787 return sizeof (uint64_t);