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"
39 #define NUM_LAST_PACKETS 10
42 std::vector<std::string>
45 std::vector<std::string> results;
47 while ((cutAt = str.find_first_of (
'/')) != str.npos)
51 results.push_back (str.substr (0,cutAt));
53 str = str.substr (cutAt+1);
55 if (str.length () > 0)
57 results.push_back (str);
76 virtual void Print (std::ostream &os)
const;
88 .SetGroupName (
"Visualizer")
131 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
134 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
143 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacPromiscRx",
152 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
155 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacRx",
178 std::ostringstream sstream;
179 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/MacTx";
183 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
187 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/PromiscRx";
196 std::ostringstream sstream;
197 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Tx";
201 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
210 std::ostringstream sstream;
211 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/TxQueue/Dequeue";
215 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
223 <<
" PacketCaptureOptions (headers size = " << options.
headers.size ()
254 g_visualizer->
DoPause (message);
257 std::vector<std::string>
289 for (std::map<TxRecordKey, TxRecordValue>::iterator iter =
m_txRecords.begin ();
292 if (iter->second.time < expirationTime)
306 if (iter->second < expirationTime)
332 visualImpl->RunRealSimulator ();
370 bool retval = (transmitter == other.
transmitter) &&
380 std::map<uint32_t, std::vector<NetDeviceStatistics> >::iterator nodeStatsIter =
m_nodesStatistics.find (node);
381 std::vector<NetDeviceStatistics> *stats;
389 stats = &(nodeStatsIter->second);
404 *outOptions = &iter->second;
411 switch (options.
mode)
419 while (metadataIterator.
HasNext ())
432 std::set<TypeId> missingHeaders (options.
headers);
434 while (metadataIterator.
HasNext ())
437 std::set<TypeId>::iterator missingIter = missingHeaders.find (item.
tid);
438 if (missingIter != missingHeaders.end ())
440 missingHeaders.erase (missingIter);
443 if (missingHeaders.size () == 0)
463 std::vector<std::string> splitPath =
PathSplit (context);
464 int nodeIndex = std::atoi (splitPath[1].c_str ());
494 std::map<Ptr<Node>, uint32_t>::iterator iter =
m_packetDrops.find (node);
501 iter->second += packet->
GetSize ();
523 std::vector<std::string> splitPath =
PathSplit (context);
524 int nodeIndex = std::atoi (splitPath[1].c_str ());
525 int devIndex = std::atoi (splitPath[3].c_str ());
542 lastPacket.
device = device;
543 lastPacket.
to = destinationAddress;
570 if (destinationAddress == device->GetBroadcast ())
599 if (hdr.IsToDs () && !hdr.IsFromDs ())
601 destinationAddress = hdr.GetAddr3 ();
603 else if (!hdr.IsToDs () && hdr.IsFromDs ())
605 destinationAddress = hdr.GetAddr1 ();
607 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
609 destinationAddress = hdr.GetAddr1 ();
613 destinationAddress = hdr.GetAddr3 ();
650 NS_LOG_WARN (
"Packet has no byte tag; wimax link?");
655 std::vector<std::string> splitPath =
PathSplit (context);
656 int nodeIndex = std::atoi (splitPath[1].c_str ());
657 int devIndex = std::atoi (splitPath[3].c_str ());
675 lastPacket.
device = device;
676 lastPacket.
from = from;
687 NS_LOG_DEBUG (
"RX Packet " << uid <<
" is not of interest");
693 std::map<TxRecordKey, TxRecordValue>::iterator recordIter =
698 NS_LOG_DEBUG (
"RX Packet " << uid <<
" was not transmitted?!");
706 NS_LOG_WARN (
"Node " << node->
GetId () <<
" receiving back the same packet (UID=" << uid
707 <<
") it had previously transmitted, on the same channel!");
713 #ifdef NS3_LOG_ENABLE
717 for (std::map<TransmissionSampleKey,TransmissionSampleValue>::const_iterator iter
720 NS_LOG_DEBUG (iter->first.transmitter<<
"/"<<iter->first.transmitter->GetId () <<
", "
721 << iter->first.receiver<<
"/"<<iter->first.receiver->GetId ()
722 <<
", " << iter->first.channel <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
728 std::map<TransmissionSampleKey,TransmissionSampleValue>::iterator
736 <<
" channel " << channel <<
": " << packet->
GetSize ()
737 <<
" bytes more. => new sample with " << packet->
GetSize () <<
" bytes.");
745 <<
" channel " << channel <<
": " << packet->
GetSize ()
746 <<
" bytes more. => sample " << &sample <<
" with bytes " << sample.
bytes);
769 if (hdr.IsToDs () && !hdr.IsFromDs ())
771 sourceAddress = hdr.GetAddr2 ();
773 else if (!hdr.IsToDs () && hdr.IsFromDs ())
775 sourceAddress = hdr.GetAddr3 ();
777 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
779 sourceAddress = hdr.GetAddr2 ();
783 sourceAddress = hdr.GetAddr4 ();
856 for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator
863 sample.
receiver = iter->first.receiver;
864 sample.
channel = iter->first.channel;
865 sample.
bytes = iter->second.bytes;
867 <<
": " << sample.
bytes <<
" bytes.");
868 list.push_back (sample);
879 for (std::map<
Ptr<Node>, uint32_t>::const_iterator
886 sample.
bytes = iter->second;
888 <<
": " << sample.
bytes <<
" bytes dropped.");
889 list.push_back (sample);
901 std::vector<PyViz::NodeStatistics>
904 std::vector<PyViz::NodeStatistics> retval;
905 for (std::map<uint32_t, std::vector<NetDeviceStatistics> >::const_iterator iter =
m_nodesStatistics.begin ();
909 retval.push_back (stats);
920 std::map<uint32_t, LastPacketsSample>::const_iterator
985 line.
end.
x += line.
dx * (m_clipMin.
y - line.
end.
y) / line.
dy;
986 line.
end.
y = m_clipMin.
y;
990 line.
end.
x += line.
dx * (m_clipMax.
y - line.
end.
y) / line.
dy;
991 line.
end.
y = m_clipMax.
y;
996 line.
end.
y += line.
dy * (m_clipMax.
x - line.
end.
x) / line.
dx;
997 line.
end.
x = m_clipMax.
x;
1002 line.
end.
y += line.
dy * (m_clipMin.
x - line.
end.
x) / line.
dx;
1003 line.
end.
x = m_clipMin.
x;
1008 : m_clipMin (clipMin), m_clipMax (clipMax)
1015 uint8_t lineCode = 0;
1017 if (line.
end.
y < m_clipMin.
y)
1019 else if (line.
end.
y > m_clipMax.
y)
1022 if (line.
end.
x > m_clipMax.
x)
1024 else if (line.
end.
x < m_clipMin.
x)
1027 if (line.
start.
y < m_clipMin.
y)
1029 else if (line.
start.
y > m_clipMax.
y)
1032 if (line.
start.
x > m_clipMax.
x)
1034 else if (line.
start.
x < m_clipMin.
x)
1053 ClipEndRight (line);
1057 ClipEndBottom (line);
1062 if (line.
end.
y > m_clipMax.
y)
1063 ClipEndBottom (line);
1067 ClipEndRight (line);
1068 if (line.
end.
y > m_clipMax.
y)
1069 ClipEndBottom (line);
1078 if (line.
end.
y < m_clipMin.
y)
1083 ClipEndRight (line);
1084 if (line.
end.
y < m_clipMin.
y)
1090 ClipStartLeft (line);
1094 ClipStartLeft (line);
1095 ClipEndRight (line);
1099 ClipStartLeft (line);
1100 if (line.
start.
y > m_clipMax.
y)
1102 ClipEndBottom (line);
1106 ClipStartLeft (line);
1107 if (line.
start.
y > m_clipMax.
y)
1109 ClipEndBottom (line);
1110 if (line.
end.
x > m_clipMax.
x)
1111 ClipEndRight (line);
1115 ClipStartLeft (line);
1116 if (line.
start.
y < m_clipMin.
y)
1122 ClipStartLeft (line);
1123 if (line.
start.
y < m_clipMin.
y)
1126 if (line.
end.
x > m_clipMax.
x)
1127 ClipEndRight (line);
1132 ClipStartRight (line);
1136 ClipStartRight (line);
1141 ClipStartRight (line);
1142 if (line.
start.
y > m_clipMax.
y)
1144 ClipEndBottom (line);
1148 ClipStartRight (line);
1149 if (line.
start.
y > m_clipMax.
y)
1151 ClipEndBottom (line);
1152 if (line.
end.
x < m_clipMin.
x)
1157 ClipStartRight (line);
1158 if (line.
start.
y < m_clipMin.
y)
1164 ClipStartRight (line);
1165 if (line.
start.
y < m_clipMin.
y)
1168 if (line.
end.
x < m_clipMin.
x)
1174 ClipStartBottom (line);
1178 ClipStartBottom (line);
1179 if (line.
start.
x < m_clipMin.
x)
1182 if (line.
end.
y > m_clipMax.
y)
1183 ClipEndBottom (line);
1187 ClipStartBottom (line);
1188 if (line.
start.
x > m_clipMax.
x)
1190 ClipEndRight (line);
1194 ClipStartBottom (line);
1199 ClipStartBottom (line);
1200 if (line.
start.
x < m_clipMin.
x)
1203 if (line.
end.
y < m_clipMin.
y)
1208 ClipStartBottom (line);
1209 if (line.
start.
x > m_clipMax.
x)
1211 ClipEndRight (line);
1212 if (line.
end.
y < m_clipMin.
y)
1218 ClipStartLeft (line);
1219 if (line.
start.
y > m_clipMax.
y)
1220 ClipStartBottom (line);
1224 ClipEndRight (line);
1225 if (line.
end.
y > m_clipMax.
y)
1227 ClipStartBottom (line);
1228 if (line.
start.
x < m_clipMin.
x)
1229 ClipStartLeft (line);
1234 if (line.
end.
x < m_clipMin.
x)
1236 ClipStartBottom (line);
1237 if (line.
start.
x < m_clipMin.
x)
1238 ClipStartLeft (line);
1242 ClipStartLeft (line);
1243 if (line.
start.
y < m_clipMin.
y)
1245 ClipEndRight (line);
1246 if (line.
end.
y > m_clipMax.
y)
1248 if (line.
start.
y > m_clipMax.
y)
1249 ClipStartBottom (line);
1250 if (line.
end.
y < m_clipMin.
y)
1256 ClipStartRight (line);
1257 if (line.
start.
y > m_clipMax.
y)
1258 ClipStartBottom (line);
1263 if (line.
end.
y > m_clipMax.
y)
1265 ClipStartBottom (line);
1266 if (line.
start.
x > m_clipMax.
x)
1267 ClipStartRight (line);
1272 if (line.
end.
x > m_clipMax.
x)
1274 ClipStartRight (line);
1275 if (line.
start.
y > m_clipMax.
y)
1276 ClipStartBottom (line);
1281 if (line.
end.
y > m_clipMax.
y)
1283 ClipStartRight (line);
1284 if (line.
start.
y < m_clipMin.
y)
1286 if (line.
end.
y < m_clipMin.
y)
1288 if (line.
start.
y > m_clipMax.
y)
1289 ClipStartBottom (line);
1294 ClipStartTop (line);
1298 ClipStartTop (line);
1299 if (line.
start.
x < m_clipMin.
x)
1305 ClipStartTop (line);
1306 if (line.
start.
x > m_clipMax.
x)
1308 ClipEndRight (line);
1312 ClipStartTop (line);
1313 ClipEndBottom (line);
1317 ClipStartTop (line);
1318 if (line.
start.
x < m_clipMin.
x)
1321 if (line.
end.
y > m_clipMax.
y)
1322 ClipEndBottom (line);
1326 ClipStartTop (line);
1327 if (line.
start.
x > m_clipMax.
x)
1329 ClipEndRight (line);
1330 if (line.
end.
y > m_clipMax.
y)
1331 ClipEndBottom (line);
1336 ClipStartLeft (line);
1337 if (line.
start.
y < m_clipMin.
y)
1338 ClipStartTop (line);
1342 ClipEndRight (line);
1343 if (line.
end.
y < m_clipMin.
y)
1345 ClipStartTop (line);
1346 if (line.
start.
x < m_clipMin.
x)
1347 ClipStartLeft (line);
1351 ClipEndBottom (line);
1352 if (line.
end.
x < m_clipMin.
x)
1354 ClipStartLeft (line);
1355 if (line.
start.
y < m_clipMin.
y)
1356 ClipStartTop (line);
1360 ClipStartLeft (line);
1361 if (line.
start.
y > m_clipMax.
y)
1363 ClipEndRight (line);
1364 if (line.
end.
y < m_clipMin.
y)
1366 if (line.
start.
y < m_clipMin.
y)
1367 ClipStartTop (line);
1368 if (line.
end.
y > m_clipMax.
y)
1369 ClipEndBottom (line);
1374 ClipStartRight (line);
1375 if (line.
start.
y < m_clipMin.
y)
1376 ClipStartTop (line);
1381 if (line.
end.
y < m_clipMin.
y)
1383 ClipStartTop (line);
1384 if (line.
start.
x > m_clipMax.
x)
1385 ClipStartRight (line);
1389 ClipEndBottom (line);
1390 if (line.
end.
x > m_clipMax.
x)
1392 ClipStartRight (line);
1393 if (line.
start.
y < m_clipMin.
y)
1394 ClipStartTop (line);
1399 if (line.
end.
y < m_clipMin.
y)
1401 ClipStartRight (line);
1402 if (line.
start.
y > m_clipMax.
y)
1404 if (line.
end.
y > m_clipMax.
y)
1405 ClipEndBottom (line);
1406 if (line.
start.
y < m_clipMin.
y)
1407 ClipStartTop (line);
1418 double &lineX1,
double &lineY1,
double &lineX2,
double &lineY2)
1420 FastClipping::Vector2 clipMin = { boundsX1, boundsY1}, clipMax = { boundsX2, boundsY2};
1421 FastClipping::Line line = { { lineX1, lineY1 }, { lineX2, lineY2 }, (lineX2-lineX1), (lineY2-lineY1) };
1423 FastClipping clipper (clipMin, clipMax);
1424 clipper.ClipLine (line);
1425 lineX1 = line.start.x;
1426 lineX2 = line.end.x;
1427 lineY1 = line.start.y;
1428 lineY2 = line.end.y;
std::vector< TransmissionSample > TransmissionSampleList
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Simulation virtual time values and global simulation resolution.
std::vector< std::string > m_pauseMessages
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint64_t transmittedBytes
void TraceNetDevTxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &destination)
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)
Get the SimulatorImpl singleton.
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
Returns the packet's Uid.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
PacketType
Packet types are used as they are in Linux.
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
TAG_BUFFER_INLINE uint32_t ReadU32(void)
void ClipEndTop(Line &line)
std::map< uint32_t, LastPacketsSample > m_lastPackets
Rare ad-hoc debug messages.
void ClipEndBottom(Line &line)
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
Retrieve the index-th NetDevice associated to this node.
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)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void Connect(std::string path, const CallbackBase &cb)
FastClipping(Vector2 clipMin, Vector2 clipMax)
void ClipEndRight(Line &line)
void SimulatorRunUntil(Time time)
PacketDropSampleList GetPacketDropSamples() const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
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)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool ClipLine(Line &line)
PacketMetadata::ItemIterator BeginItem(void) const
Returns an iterator which points to the first 'item' stored in this buffer.
Packet addressed to someone else.
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
std::vector< RxPacketSample > lastReceivedPackets
static Time Now(void)
Return the current simulation virtual 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)
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
std::set< uint32_t > m_nodesOfInterest
uint32_t GetId(void) const
std::vector< NodeStatistics > GetNodesStatistics() const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
void ClipStartBottom(Line &line)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
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)
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)
Set the parent TypeId.
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)
Get a TypeId by name.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.