14#include "ns3/config.h"
15#include "ns3/ethernet-header.h"
17#include "ns3/node-list.h"
18#include "ns3/ppp-header.h"
19#include "ns3/simulator.h"
20#include "ns3/wifi-mac-header.h"
21#include "ns3/wifi-net-device.h"
28#define NUM_LAST_PACKETS 10
30static std::vector<std::string>
33 std::vector<std::string> results;
35 while ((cutAt = str.find_first_of(
'/')) != std::string::npos)
39 results.push_back(str.substr(0, cutAt));
41 str = str.substr(cutAt + 1);
45 results.push_back(str);
65 void Print(std::ostream& os)
const override;
80 .SetGroupName(
"Visualizer")
177 std::ostringstream sstream;
178 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/MacTx";
182 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
186 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/PromiscRx";
195 std::ostringstream sstream;
196 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Tx";
200 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
209 std::ostringstream sstream;
210 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/TxQueue/Dequeue";
214 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
222 << nodeId <<
" PacketCaptureOptions (headers size = " << options.
headers.size()
258std::vector<std::string>
263 <<
" pause messages");
292 if (iter->second.time < expirationTime)
305 if (iter->second < expirationTime)
334 visualImpl->RunRealSimulator();
376 std::vector<NetDeviceStatistics>* stats;
384 stats = &(nodeStatsIter->second);
400 *outOptions = &iter->second;
408 switch (options.
mode)
415 while (metadataIterator.
HasNext())
427 std::set<TypeId> missingHeaders(options.
headers);
429 while (metadataIterator.
HasNext())
432 auto missingIter = missingHeaders.find(item.
tid);
433 if (missingIter != missingHeaders.end())
435 missingHeaders.erase(missingIter);
438 return missingHeaders.empty();
451 std::vector<std::string> splitPath =
PathSplit(context);
452 int nodeIndex = std::stoi(splitPath[1]);
461 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
474 lastPacket.
packet = packet->Copy();
475 lastPacket.
device =
nullptr;
490 iter->second += packet->GetSize();
503 packetCopy->AddHeader(hdr);
516 std::vector<std::string> splitPath =
PathSplit(context);
517 int nodeIndex = std::stoi(splitPath[1]);
518 int devIndex = std::stoi(splitPath[3]);
535 lastPacket.
packet = packet->Copy();
536 lastPacket.
device = device;
537 lastPacket.
to = destinationAddress;
553 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
564 if (destinationAddress == device->GetBroadcast())
574 packet->AddByteTag(tag);
595 destinationAddress = hdr.
GetAddr3();
599 destinationAddress = hdr.
GetAddr1();
608 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
627 if (packet->FindFirstMatchingByteTag(tag))
634 NS_LOG_WARN(
"Packet has no byte tag; wimax link?");
635 uid = packet->GetUid();
639 std::vector<std::string> splitPath =
PathSplit(context);
640 int nodeIndex = std::stoi(splitPath[1]);
641 int devIndex = std::stoi(splitPath[3]);
659 lastPacket.
packet = packet->Copy();
660 lastPacket.
device = device;
661 lastPacket.
from = from;
672 NS_LOG_DEBUG(
"RX Packet " << uid <<
" is not of interest");
682 NS_LOG_DEBUG(
"RX Packet " << uid <<
" was not transmitted?!");
690 NS_LOG_WARN(
"Node " << node->GetId() <<
" receiving back the same packet (UID=" << uid
691 <<
") it had previously transmitted, on the same channel!");
704 <<
"/" << iter->first.transmitter->GetId() <<
", " << iter->first.receiver
705 <<
"/" << iter->first.receiver->GetId() <<
", " << iter->first.channel
706 <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
719 << channel <<
": " << packet->GetSize()
720 <<
" bytes more. => new sample with " << packet->GetSize()
729 << channel <<
": " << packet->GetSize()
730 <<
" bytes more. => sample " << &sample <<
" with bytes "
733 sample.
bytes += packet->GetSize();
773 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
787 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
842 sample.
receiver = iter->first.receiver;
843 sample.
channel = iter->first.channel;
844 sample.
bytes = iter->second.bytes;
846 <<
": " << sample.
bytes <<
" bytes.");
847 list.push_back(sample);
862 sample.
bytes = iter->second;
864 <<
" bytes dropped.");
865 list.push_back(sample);
877std::vector<PyViz::NodeStatistics>
880 std::vector<PyViz::NodeStatistics> retval;
884 retval.push_back(stats);
977 line.
end.
x += line.
dx * (m_clipMin.
y - line.
end.
y) / line.
dy;
978 line.
end.
y = m_clipMin.
y;
987 line.
end.
x += line.
dx * (m_clipMax.
y - line.
end.
y) / line.
dy;
988 line.
end.
y = m_clipMax.
y;
997 line.
end.
y += line.
dy * (m_clipMax.
x - line.
end.
x) / line.
dx;
998 line.
end.
x = m_clipMax.
x;
1007 line.
end.
y += line.
dy * (m_clipMin.
x - line.
end.
x) / line.
dx;
1008 line.
end.
x = m_clipMin.
x;
1019 : m_clipMin(clipMin),
1031 uint8_t lineCode = 0;
1033 if (line.
end.
y < m_clipMin.
y)
1037 else if (line.
end.
y > m_clipMax.
y)
1042 if (line.
end.
x > m_clipMax.
x)
1046 else if (line.
end.
x < m_clipMin.
x)
1051 if (line.
start.
y < m_clipMin.
y)
1055 else if (line.
start.
y > m_clipMax.
y)
1060 if (line.
start.
x > m_clipMax.
x)
1064 else if (line.
start.
x < m_clipMin.
x)
1089 ClipEndBottom(line);
1094 if (line.
end.
y > m_clipMax.
y)
1096 ClipEndBottom(line);
1102 if (line.
end.
y > m_clipMax.
y)
1104 ClipEndBottom(line);
1114 if (line.
end.
y < m_clipMin.
y)
1122 if (line.
end.
y < m_clipMin.
y)
1130 ClipStartLeft(line);
1134 ClipStartLeft(line);
1139 ClipStartLeft(line);
1140 if (line.
start.
y > m_clipMax.
y)
1144 ClipEndBottom(line);
1148 ClipStartLeft(line);
1149 if (line.
start.
y > m_clipMax.
y)
1153 ClipEndBottom(line);
1154 if (line.
end.
x > m_clipMax.
x)
1161 ClipStartLeft(line);
1162 if (line.
start.
y < m_clipMin.
y)
1170 ClipStartLeft(line);
1171 if (line.
start.
y < m_clipMin.
y)
1176 if (line.
end.
x > m_clipMax.
x)
1184 ClipStartRight(line);
1188 ClipStartRight(line);
1193 ClipStartRight(line);
1194 if (line.
start.
y > m_clipMax.
y)
1198 ClipEndBottom(line);
1202 ClipStartRight(line);
1203 if (line.
start.
y > m_clipMax.
y)
1207 ClipEndBottom(line);
1208 if (line.
end.
x < m_clipMin.
x)
1215 ClipStartRight(line);
1216 if (line.
start.
y < m_clipMin.
y)
1224 ClipStartRight(line);
1225 if (line.
start.
y < m_clipMin.
y)
1230 if (line.
end.
x < m_clipMin.
x)
1238 ClipStartBottom(line);
1242 ClipStartBottom(line);
1243 if (line.
start.
x < m_clipMin.
x)
1248 if (line.
end.
y > m_clipMax.
y)
1250 ClipEndBottom(line);
1255 ClipStartBottom(line);
1256 if (line.
start.
x > m_clipMax.
x)
1264 ClipStartBottom(line);
1269 ClipStartBottom(line);
1270 if (line.
start.
x < m_clipMin.
x)
1275 if (line.
end.
y < m_clipMin.
y)
1282 ClipStartBottom(line);
1283 if (line.
start.
x > m_clipMax.
x)
1288 if (line.
end.
y < m_clipMin.
y)
1296 ClipStartLeft(line);
1297 if (line.
start.
y > m_clipMax.
y)
1299 ClipStartBottom(line);
1305 if (line.
end.
y > m_clipMax.
y)
1309 ClipStartBottom(line);
1310 if (line.
start.
x < m_clipMin.
x)
1312 ClipStartLeft(line);
1318 if (line.
end.
x < m_clipMin.
x)
1322 ClipStartBottom(line);
1323 if (line.
start.
x < m_clipMin.
x)
1325 ClipStartLeft(line);
1330 ClipStartLeft(line);
1331 if (line.
start.
y < m_clipMin.
y)
1336 if (line.
end.
y > m_clipMax.
y)
1340 if (line.
start.
y > m_clipMax.
y)
1342 ClipStartBottom(line);
1344 if (line.
end.
y < m_clipMin.
y)
1352 ClipStartRight(line);
1353 if (line.
start.
y > m_clipMax.
y)
1355 ClipStartBottom(line);
1361 if (line.
end.
y > m_clipMax.
y)
1365 ClipStartBottom(line);
1366 if (line.
start.
x > m_clipMax.
x)
1368 ClipStartRight(line);
1374 if (line.
end.
x > m_clipMax.
x)
1378 ClipStartRight(line);
1379 if (line.
start.
y > m_clipMax.
y)
1381 ClipStartBottom(line);
1387 if (line.
end.
y > m_clipMax.
y)
1391 ClipStartRight(line);
1392 if (line.
start.
y < m_clipMin.
y)
1396 if (line.
end.
y < m_clipMin.
y)
1400 if (line.
start.
y > m_clipMax.
y)
1402 ClipStartBottom(line);
1413 if (line.
start.
x < m_clipMin.
x)
1422 if (line.
start.
x > m_clipMax.
x)
1431 ClipEndBottom(line);
1436 if (line.
start.
x < m_clipMin.
x)
1441 if (line.
end.
y > m_clipMax.
y)
1443 ClipEndBottom(line);
1449 if (line.
start.
x > m_clipMax.
x)
1454 if (line.
end.
y > m_clipMax.
y)
1456 ClipEndBottom(line);
1462 ClipStartLeft(line);
1463 if (line.
start.
y < m_clipMin.
y)
1471 if (line.
end.
y < m_clipMin.
y)
1476 if (line.
start.
x < m_clipMin.
x)
1478 ClipStartLeft(line);
1483 ClipEndBottom(line);
1484 if (line.
end.
x < m_clipMin.
x)
1488 ClipStartLeft(line);
1489 if (line.
start.
y < m_clipMin.
y)
1496 ClipStartLeft(line);
1497 if (line.
start.
y > m_clipMax.
y)
1502 if (line.
end.
y < m_clipMin.
y)
1506 if (line.
start.
y < m_clipMin.
y)
1510 if (line.
end.
y > m_clipMax.
y)
1512 ClipEndBottom(line);
1518 ClipStartRight(line);
1519 if (line.
start.
y < m_clipMin.
y)
1527 if (line.
end.
y < m_clipMin.
y)
1532 if (line.
start.
x > m_clipMax.
x)
1534 ClipStartRight(line);
1539 ClipEndBottom(line);
1540 if (line.
end.
x > m_clipMax.
x)
1544 ClipStartRight(line);
1545 if (line.
start.
y < m_clipMin.
y)
1553 if (line.
end.
y < m_clipMin.
y)
1557 ClipStartRight(line);
1558 if (line.
start.
y > m_clipMax.
y)
1562 if (line.
end.
y > m_clipMax.
y)
1564 ClipEndBottom(line);
1566 if (line.
start.
y < m_clipMin.
y)
1588 FastClipping::Vector2 clipMin = {boundsX1, boundsY1};
1589 FastClipping::Vector2 clipMax = {boundsX2, boundsY2};
1590 FastClipping::Line line = {{lineX1, lineY1},
1595 FastClipping clipper(clipMin, clipMax);
1596 clipper.ClipLine(line);
1597 lineX1 = line.start.x;
1598 lineX2 = line.end.x;
1599 lineY1 = line.start.y;
1600 lineY2 = line.end.y;
DropReason
Reason why a packet has been dropped.
PacketType
Packet types are used as they are in Linux.
@ PACKET_OTHERHOST
Packet addressed to someone else.
static Ptr< Node > GetNode(uint32_t n)
Smart pointer class similar to boost::intrusive_ptr.
helper class to be used by the visualizer
void RegisterCsmaLikeDevice(const std::string &deviceTypeName)
Register CSMA like device function.
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
CSMA receive trace callback function.
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
Set packet capture options function.
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point receive trace callback function.
void RegisterDropTracePath(const std::string &tracePath)
Register drop trace path function.
void RegisterWifiLikeDevice(const std::string &deviceTypeName)
Register WIFI like device function.
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
packet capture options
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &destination)
LTE transmit trace callback function.
std::map< uint32_t, LastPacketsSample > m_lastPackets
last packets
void SimulatorRunUntil(Time time)
Run simulation until a given (simulated, absolute) time is reached.
PacketDropSampleList GetPacketDropSamples() const
Get packet drop samples.
void SetNodesOfInterest(std::set< uint32_t > nodes)
Set nodes of interest function.
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
node statistics
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
CSMA transmit trace callback function.
void TraceNetDevTxCommon(const std::string &context, Ptr< const Packet > packet, const Mac48Address &destination)
Network transmit common trace callback function.
void DoPause(const std::string &message)
Do pause function.
std::vector< NodeStatistics > GetNodesStatistics() const
Get node statistics.
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, const Mac48Address &source)
WiMax transmit trace callback function.
std::set< uint32_t > m_nodesOfInterest
list of node IDs whose transmissions will be monitored
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
CSMA promiscuous receive function.
static void Pause(const std::string &message)
Pause function.
std::vector< std::string > m_pauseMessages
pause message
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &source)
LTE receive trace callback function.
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, const Mac48Address &destination)
WiMax transmit trace callback function.
void TraceIpv4Drop(std::string context, const ns3::Ipv4Header &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
Ipv4 drop trace callback function.
void TraceNetDevRxCommon(const std::string &context, Ptr< const Packet > packet, const Mac48Address &source)
Network receive common trace callback function.
TransmissionSampleList GetTransmissionSamples() const
Get transmission samples.
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
Utility function - clips a line to a bounding box.
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
transmission samples
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point transmit trace callback function.
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi receive trace callback function.
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
Find net device statistics function.
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
Queue drop trace callback function.
std::map< TxRecordKey, TxRecordValue > m_txRecords
transmit records
std::vector< std::string > GetPauseMessages() const
Get pause message function.
std::vector< PacketDropSample > PacketDropSampleList
PacketDropSampleList typedef.
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Filter packet function.
void CallbackStopSimulation()
Stop simulation callback function.
void RegisterPointToPointLikeDevice(const std::string &deviceTypeName)
Register point to point like device function.
std::map< Ptr< Node >, uint32_t > m_packetDrops
packet drops
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Get last packets function.
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi transmit trace callback function.
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Get packet capture options function.
Time m_runUntil
run until time
std::map< uint32_t, Time > m_packetsOfInterest
list of packet UIDs that will be monitored
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
TxRecordKey typedef.
std::vector< TransmissionSample > TransmissionSampleList
TransmissionSampleList typedef.
@ PACKET_CAPTURE_FILTER_HEADERS_OR
@ PACKET_CAPTURE_DISABLED
@ PACKET_CAPTURE_FILTER_HEADERS_AND
static Ptr< SimulatorImpl > GetImplementation()
Get the SimulatorImpl singleton.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
@ NO_CONTEXT
Flag for events not associated with any particular context.
static Time Now()
Return the current simulation virtual time.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
TAG_BUFFER_INLINE uint32_t ReadU32()
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
tag a set of bytes in a packet
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Adapted from http://en.wikipedia.org/w/index.php?title=Line_clipping&oldid=248609574.
bool ClipLine(Line &line)
Clip line function.
Vector2 m_clipMin
clip minimum
void ClipEndRight(Line &line) const
Clip end right function.
Vector2 m_clipMax
clip maximum
void ClipEndBottom(Line &line) const
Clip end bottom function.
void ClipStartLeft(Line &line) const
Clip start left function.
void ClipStartTop(Line &line) const
Clip start top function.
void ClipStartBottom(Line &line) const
Clip start bottom function.
void ClipStartRight(Line &line) const
Clip start right function.
FastClipping(Vector2 clipMin, Vector2 clipMax)
Constructor.
void ClipEndLeft(Line &line) const
Clip end left function.
void ClipEndTop(Line &line) const
Clip end top function.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void Connect(std::string path, const CallbackBase &cb)
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
@ LOG_DEBUG
Full voluminous logging to support debugging.
static PyViz * g_visualizer
the visualizer
static std::vector< std::string > PathSplit(std::string str)
LastPacketsSample structure.
std::vector< PacketSample > lastDroppedPackets
last dropped packets
std::vector< TxPacketSample > lastTransmittedPackets
last transmitted packets
std::vector< RxPacketSample > lastReceivedPackets
last received packets
NetDeviceStatistics structure.
uint64_t receivedBytes
received bytes
uint64_t transmittedBytes
transmitted bytes
uint32_t receivedPackets
received packets
uint32_t transmittedPackets
transmitted packets
NodeStatistics structure.
PacketCaptureOptions structure.
PacketCaptureMode mode
mode
uint32_t numLastPackets
num last packets
std::set< TypeId > headers
headers
PacketDropSample structure.
Ptr< Node > transmitter
transmitter
Ptr< Packet > packet
packet
Ptr< NetDevice > device
device
RxPacketSample structure.
TransmissionSample structure.
Ptr< Node > transmitter
transmitter
Ptr< Channel > channel
channel
Ptr< Node > receiver
NULL if broadcast.
TransmissionSampleKey structure.
Ptr< Channel > channel
channel
bool operator==(const TransmissionSampleKey &other) const
Equality operator.
bool operator<(const TransmissionSampleKey &other) const
Less than operator.
Ptr< Node > transmitter
transmitter
Ptr< Node > receiver
NULL if broadcast.
TransmissionSampleValue structure.
TxPacketSample structure.
Ptr< Node > srcNode
source node
bool isBroadcast
is broadcast?
PyVizPacketTag structure.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Deserialize(TagBuffer buf) override
void Serialize(TagBuffer buf) const override
static TypeId GetTypeId()
Get the type ID.
uint32_t m_packetId
packet id
void Print(std::ostream &os) const override
uint32_t GetSerializedSize() const override