23 #include "ns3/simulator.h"
24 #include "ns3/config.h"
25 #include "ns3/node-list.h"
26 #include "ns3/wifi-net-device.h"
27 #include "ns3/ppp-header.h"
28 #include "ns3/wifi-mac-header.h"
29 #include "ns3/ethernet-header.h"
31 #include "ns3/abort.h"
38 #define NUM_LAST_PACKETS 10
41 std::vector<std::string>
44 std::vector<std::string> results;
46 while ((cutAt = str.find_first_of (
'/')) != str.npos)
50 results.push_back (str.substr (0,cutAt));
52 str = str.substr (cutAt+1);
54 if (str.length () > 0)
56 results.push_back (str);
75 virtual void Print (std::ostream &os)
const;
87 .AddConstructor<PyVizPacketTag> ()
129 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
132 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
141 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacPromiscRx",
150 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
153 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacRx",
176 std::ostringstream sstream;
177 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/MacTx";
181 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
185 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/PromiscRx";
194 std::ostringstream sstream;
195 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Tx";
199 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
208 std::ostringstream sstream;
209 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/TxQueue/Dequeue";
213 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
221 <<
" PacketCaptureOptions (headers size = " << options.
headers.size ()
255 std::vector<std::string>
287 for (std::map<TxRecordKey, TxRecordValue>::iterator iter =
m_txRecords.begin ();
290 if (iter->second.time < expirationTime)
304 if (iter->second < expirationTime)
330 visualImpl->RunRealSimulator ();
368 bool retval = (transmitter == other.
transmitter) &&
378 std::map<uint32_t, std::vector<NetDeviceStatistics> >::iterator nodeStatsIter =
m_nodesStatistics.find (node);
379 std::vector<NetDeviceStatistics> *stats;
387 stats = &(nodeStatsIter->second);
402 *outOptions = &iter->second;
409 switch (options.
mode)
417 while (metadataIterator.
HasNext ())
430 std::set<TypeId> missingHeaders (options.
headers);
432 while (metadataIterator.
HasNext ())
435 std::set<TypeId>::iterator missingIter = missingHeaders.find (item.
tid);
436 if (missingIter != missingHeaders.end ())
438 missingHeaders.erase (missingIter);
441 if (missingHeaders.size () == 0)
461 std::vector<std::string> splitPath =
PathSplit (context);
462 int nodeIndex = atoi (splitPath[1].c_str ());
492 std::map<Ptr<Node>, uint32_t>::iterator iter =
m_packetDrops.find (node);
499 iter->second += packet->
GetSize ();
521 std::vector<std::string> splitPath =
PathSplit (context);
522 int nodeIndex = atoi (splitPath[1].c_str ());
523 int devIndex = atoi (splitPath[3].c_str ());
540 lastPacket.
device = device;
541 lastPacket.
to = destinationAddress;
597 if (hdr.IsToDs () && !hdr.IsFromDs ())
599 destinationAddress = hdr.GetAddr3 ();
601 else if (!hdr.IsToDs () && hdr.IsFromDs ())
603 destinationAddress = hdr.GetAddr1 ();
605 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
607 destinationAddress = hdr.GetAddr1 ();
611 destinationAddress = hdr.GetAddr3 ();
648 NS_LOG_WARN (
"Packet has no byte tag; wimax link?");
653 std::vector<std::string> splitPath =
PathSplit (context);
654 int nodeIndex = atoi (splitPath[1].c_str ());
655 int devIndex = atoi (splitPath[3].c_str ());
673 lastPacket.
device = device;
674 lastPacket.
from = from;
685 NS_LOG_DEBUG (
"RX Packet " << uid <<
" is not of interest");
691 std::map<TxRecordKey, TxRecordValue>::iterator recordIter =
696 NS_LOG_DEBUG (
"RX Packet " << uid <<
" was not transmitted?!");
704 NS_LOG_WARN (
"Node " << node->
GetId () <<
" receiving back the same packet (UID=" << uid
705 <<
") it had previously transmitted, on the same channel!");
711 #ifdef NS3_LOG_ENABLE
715 for (std::map<TransmissionSampleKey,TransmissionSampleValue>::const_iterator iter
718 NS_LOG_DEBUG (iter->first.transmitter<<
"/"<<iter->first.transmitter->GetId () <<
", "
719 << iter->first.receiver<<
"/"<<iter->first.receiver->GetId ()
720 <<
", " << iter->first.channel <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
726 std::map<TransmissionSampleKey,TransmissionSampleValue>::iterator
734 <<
" channel " << channel <<
": " << packet->
GetSize ()
735 <<
" bytes more. => new sample with " << packet->
GetSize () <<
" bytes.");
743 <<
" channel " << channel <<
": " << packet->
GetSize ()
744 <<
" bytes more. => sample " << &sample <<
" with bytes " << sample.
bytes);
767 if (hdr.IsToDs () && !hdr.IsFromDs ())
769 sourceAddress = hdr.GetAddr2 ();
771 else if (!hdr.IsToDs () && hdr.IsFromDs ())
773 sourceAddress = hdr.GetAddr3 ();
775 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
777 sourceAddress = hdr.GetAddr2 ();
781 sourceAddress = hdr.GetAddr4 ();
854 for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator
861 sample.
receiver = iter->first.receiver;
862 sample.
channel = iter->first.channel;
863 sample.
bytes = iter->second.bytes;
865 <<
": " << sample.
bytes <<
" bytes.");
866 list.push_back (sample);
877 for (std::map<
Ptr<Node>, uint32_t>::const_iterator
884 sample.
bytes = iter->second;
886 <<
": " << sample.
bytes <<
" bytes dropped.");
887 list.push_back (sample);
899 std::vector<PyViz::NodeStatistics>
902 std::vector<PyViz::NodeStatistics> retval;
903 for (std::map<uint32_t, std::vector<NetDeviceStatistics> >::const_iterator iter =
m_nodesStatistics.begin ();
907 retval.push_back (stats);
918 std::map<uint32_t, LastPacketsSample>::const_iterator
960 line.
start.
y = m_clipMin.y;
963 void ClipStartBottom (
Line &line)
966 line.
start.
y = m_clipMax.y;
969 void ClipStartRight (
Line &line)
972 line.
start.
x = m_clipMax.x;
975 void ClipStartLeft (
Line &line)
978 line.
start.
x = m_clipMin.x;
983 line.
end.
x += line.
dx * (m_clipMin.y - line.
end.
y) / line.
dy;
984 line.
end.
y = m_clipMin.y;
988 line.
end.
x += line.
dx * (m_clipMax.y - line.
end.
y) / line.
dy;
989 line.
end.
y = m_clipMax.y;
994 line.
end.
y += line.
dy * (m_clipMax.x - line.
end.
x) / line.
dx;
995 line.
end.
x = m_clipMax.x;
1000 line.
end.
y += line.
dy * (m_clipMin.x - line.
end.
x) / line.
dx;
1001 line.
end.
x = m_clipMin.x;
1006 : m_clipMin (clipMin), m_clipMax (clipMax)
1013 uint8_t lineCode = 0;
1015 if (line.
end.
y < m_clipMin.y)
1017 else if (line.
end.
y > m_clipMax.y)
1020 if (line.
end.
x > m_clipMax.x)
1022 else if (line.
end.
x < m_clipMin.x)
1025 if (line.
start.
y < m_clipMin.y)
1027 else if (line.
start.
y > m_clipMax.y)
1030 if (line.
start.
x > m_clipMax.x)
1032 else if (line.
start.
x < m_clipMin.x)
1051 ClipEndRight (line);
1055 ClipEndBottom (line);
1060 if (line.
end.
y > m_clipMax.y)
1061 ClipEndBottom (line);
1065 ClipEndRight (line);
1066 if (line.
end.
y > m_clipMax.y)
1067 ClipEndBottom (line);
1076 if (line.
end.
y < m_clipMin.y)
1081 ClipEndRight (line);
1082 if (line.
end.
y < m_clipMin.y)
1088 ClipStartLeft (line);
1092 ClipStartLeft (line);
1093 ClipEndRight (line);
1097 ClipStartLeft (line);
1098 if (line.
start.
y > m_clipMax.y)
1100 ClipEndBottom (line);
1104 ClipStartLeft (line);
1105 if (line.
start.
y > m_clipMax.y)
1107 ClipEndBottom (line);
1108 if (line.
end.
x > m_clipMax.x)
1109 ClipEndRight (line);
1113 ClipStartLeft (line);
1114 if (line.
start.
y < m_clipMin.y)
1120 ClipStartLeft (line);
1121 if (line.
start.
y < m_clipMin.y)
1124 if (line.
end.
x > m_clipMax.x)
1125 ClipEndRight (line);
1130 ClipStartRight (line);
1134 ClipStartRight (line);
1139 ClipStartRight (line);
1140 if (line.
start.
y > m_clipMax.y)
1142 ClipEndBottom (line);
1146 ClipStartRight (line);
1147 if (line.
start.
y > m_clipMax.y)
1149 ClipEndBottom (line);
1150 if (line.
end.
x < m_clipMin.x)
1155 ClipStartRight (line);
1156 if (line.
start.
y < m_clipMin.y)
1162 ClipStartRight (line);
1163 if (line.
start.
y < m_clipMin.y)
1166 if (line.
end.
x < m_clipMin.x)
1172 ClipStartBottom (line);
1176 ClipStartBottom (line);
1177 if (line.
start.
x < m_clipMin.x)
1180 if (line.
end.
y > m_clipMax.y)
1181 ClipEndBottom (line);
1185 ClipStartBottom (line);
1186 if (line.
start.
x > m_clipMax.x)
1188 ClipEndRight (line);
1192 ClipStartBottom (line);
1197 ClipStartBottom (line);
1198 if (line.
start.
x < m_clipMin.x)
1201 if (line.
end.
y < m_clipMin.y)
1206 ClipStartBottom (line);
1207 if (line.
start.
x > m_clipMax.x)
1209 ClipEndRight (line);
1210 if (line.
end.
y < m_clipMin.y)
1216 ClipStartLeft (line);
1217 if (line.
start.
y > m_clipMax.y)
1218 ClipStartBottom (line);
1222 ClipEndRight (line);
1223 if (line.
end.
y > m_clipMax.y)
1225 ClipStartBottom (line);
1226 if (line.
start.
x < m_clipMin.x)
1227 ClipStartLeft (line);
1232 if (line.
end.
x < m_clipMin.x)
1234 ClipStartBottom (line);
1235 if (line.
start.
x < m_clipMin.x)
1236 ClipStartLeft (line);
1240 ClipStartLeft (line);
1241 if (line.
start.
y < m_clipMin.y)
1243 ClipEndRight (line);
1244 if (line.
end.
y > m_clipMax.y)
1246 if (line.
start.
y > m_clipMax.y)
1247 ClipStartBottom (line);
1248 if (line.
end.
y < m_clipMin.y)
1254 ClipStartRight (line);
1255 if (line.
start.
y > m_clipMax.y)
1256 ClipStartBottom (line);
1261 if (line.
end.
y > m_clipMax.y)
1263 ClipStartBottom (line);
1264 if (line.
start.
x > m_clipMax.x)
1265 ClipStartRight (line);
1270 if (line.
end.
x > m_clipMax.x)
1272 ClipStartRight (line);
1273 if (line.
start.
y > m_clipMax.y)
1274 ClipStartBottom (line);
1279 if (line.
end.
y > m_clipMax.y)
1281 ClipStartRight (line);
1282 if (line.
start.
y < m_clipMin.y)
1284 if (line.
end.
y < m_clipMin.y)
1286 if (line.
start.
y > m_clipMax.y)
1287 ClipStartBottom (line);
1292 ClipStartTop (line);
1296 ClipStartTop (line);
1297 if (line.
start.
x < m_clipMin.x)
1303 ClipStartTop (line);
1304 if (line.
start.
x > m_clipMax.x)
1306 ClipEndRight (line);
1310 ClipStartTop (line);
1311 ClipEndBottom (line);
1315 ClipStartTop (line);
1316 if (line.
start.
x < m_clipMin.x)
1319 if (line.
end.
y > m_clipMax.y)
1320 ClipEndBottom (line);
1324 ClipStartTop (line);
1325 if (line.
start.
x > m_clipMax.x)
1327 ClipEndRight (line);
1328 if (line.
end.
y > m_clipMax.y)
1329 ClipEndBottom (line);
1334 ClipStartLeft (line);
1335 if (line.
start.
y < m_clipMin.y)
1336 ClipStartTop (line);
1340 ClipEndRight (line);
1341 if (line.
end.
y < m_clipMin.y)
1343 ClipStartTop (line);
1344 if (line.
start.
x < m_clipMin.x)
1345 ClipStartLeft (line);
1349 ClipEndBottom (line);
1350 if (line.
end.
x < m_clipMin.x)
1352 ClipStartLeft (line);
1353 if (line.
start.
y < m_clipMin.y)
1354 ClipStartTop (line);
1358 ClipStartLeft (line);
1359 if (line.
start.
y > m_clipMax.y)
1361 ClipEndRight (line);
1362 if (line.
end.
y < m_clipMin.y)
1364 if (line.
start.
y < m_clipMin.y)
1365 ClipStartTop (line);
1366 if (line.
end.
y > m_clipMax.y)
1367 ClipEndBottom (line);
1372 ClipStartRight (line);
1373 if (line.
start.
y < m_clipMin.y)
1374 ClipStartTop (line);
1379 if (line.
end.
y < m_clipMin.y)
1381 ClipStartTop (line);
1382 if (line.
start.
x > m_clipMax.x)
1383 ClipStartRight (line);
1387 ClipEndBottom (line);
1388 if (line.
end.
x > m_clipMax.x)
1390 ClipStartRight (line);
1391 if (line.
start.
y < m_clipMin.y)
1392 ClipStartTop (line);
1397 if (line.
end.
y < m_clipMin.y)
1399 ClipStartRight (line);
1400 if (line.
start.
y > m_clipMax.y)
1402 if (line.
end.
y > m_clipMax.y)
1403 ClipEndBottom (line);
1404 if (line.
start.
y < m_clipMin.y)
1405 ClipStartTop (line);
1416 double &lineX1,
double &lineY1,
double &lineX2,
double &lineY2)
1418 FastClipping::Vector2 clipMin = { boundsX1, boundsY1}, clipMax = { boundsX2, boundsY2};
1419 FastClipping::Line line = { { lineX1, lineY1 }, { lineX2, lineY2 }, (lineX2-lineX1), (lineY2-lineY1) };
1421 FastClipping clipper (clipMin, clipMax);
1422 clipper.ClipLine (line);
1423 lineX1 = line.start.x;
1424 lineX2 = line.end.x;
1425 lineY1 = line.start.y;
1426 lineY2 = line.end.y;