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 = std::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 = std::atoi (splitPath[1].c_str ());
523 int devIndex = std::atoi (splitPath[3].c_str ());
540 lastPacket.
device = device;
541 lastPacket.
to = destinationAddress;
568 if (destinationAddress == device->GetBroadcast ())
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 = std::atoi (splitPath[1].c_str ());
655 int devIndex = std::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;
966 line.
start.
y = m_clipMax.y;
972 line.
start.
x = m_clipMax.x;
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;
std::vector< TransmissionSample > TransmissionSampleList
bool FindFirstMatchingByteTag(Tag &tag) const
keep track of time values and allow control of global simulation resolution
std::vector< std::string > m_pauseMessages
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
uint64_t transmittedBytes
void TraceNetDevTxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &destination)
Packet addressed to someone else.
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
helper class to be used by the visualizer
void ClipStartRight(Line &line)
static Ptr< SimulatorImpl > GetImplementation(void)
static Ptr< Node > GetNode(uint32_t n)
void TraceIpv4Drop(std::string context, ns3::Ipv4Header const &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
bool operator<(TransmissionSampleKey const &other) const
std::map< uint32_t, Time > m_packetsOfInterest
uint64_t GetUid(void) const
A packet is allocated a new uid when it is created empty or with zero-filled payload.
#define NS_ASSERT(condition)
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
uint32_t GetSize(void) const
void ClipEndLeft(Line &line)
void TraceNetDevRxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &source)
std::map< Ptr< Node >, uint32_t > m_packetDrops
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
TAG_BUFFER_INLINE uint32_t ReadU32(void)
void ClipEndTop(Line &line)
void Connect(std::string path, const CallbackBase &cb)
std::map< uint32_t, LastPacketsSample > m_lastPackets
void ClipEndBottom(Line &line)
#define NS_FATAL_ERROR(msg)
fatal error handling
void CallbackStopSimulation()
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
DropReason
Reason why a packet has been dropped.
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
void RegisterDropTracePath(std::string const &tracePath)
uint32_t transmittedPackets
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
std::vector< TxPacketSample > lastTransmittedPackets
void ClipStartLeft(Line &line)
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
void RegisterPointToPointLikeDevice(std::string const &deviceTypeName)
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
std::set< TypeId > headers
Ptr< NetDevice > GetDevice(uint32_t index) const
virtual uint32_t GetSerializedSize(void) const
static PyViz * g_visualizer
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
static std::vector< std::string > PathSplit(std::string str)
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
#define NS_LOG_LOGIC(msg)
FastClipping(Vector2 clipMin, Vector2 clipMax)
void ClipEndRight(Line &line)
void SimulatorRunUntil(Time time)
#define NS_ABORT_IF(cond)
Abnormal program termination if cond is true.
PacketDropSampleList GetPacketDropSamples() const
Ptr< Packet > Copy(void) const
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
tag a set of bytes in a packet
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
void SetNodesOfInterest(std::set< uint32_t > nodes)
bool ClipLine(Line &line)
PacketMetadata::ItemIterator BeginItem(void) const
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
std::vector< RxPacketSample > lastReceivedPackets
static Time Now(void)
Return the "current simulation time".
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
void RegisterCsmaLikeDevice(std::string const &deviceTypeName)
virtual void Deserialize(TagBuffer buf)
bool operator==(TransmissionSampleKey const &other) const
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
static TypeId GetTypeId(void)
NS_LOG_COMPONENT_DEFINE("PyViz")
std::set< uint32_t > m_nodesOfInterest
uint32_t GetId(void) const
std::vector< NodeStatistics > GetNodesStatistics() const
virtual TypeId GetInstanceTypeId(void) const
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
void ClipStartBottom(Line &line)
#define NS_LOG_DEBUG(msg)
TransmissionSampleList GetTransmissionSamples() const
void RegisterWifiLikeDevice(std::string const &deviceTypeName)
std::vector< PacketDropSample > PacketDropSampleList
virtual void Serialize(TagBuffer buf) const
void DoPause(std::string const &message)
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
static void Pause(std::string const &message)
PacketType
Packet types are used as they are in Linux.
std::map< TxRecordKey, TxRecordValue > m_txRecords
void ClipStartTop(Line &line)
virtual void Print(std::ostream &os) const
std::vector< PacketSample > lastDroppedPackets
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
void AddHeader(const Header &header)
Add header to this packet.
std::vector< std::string > GetPauseMessages() const
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
LastPacketsSample GetLastPackets(uint32_t nodeId) const
static TypeId LookupByName(std::string name)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.