25#include "ns3/config.h"
26#include "ns3/ethernet-header.h"
28#include "ns3/node-list.h"
29#include "ns3/ppp-header.h"
30#include "ns3/simulator.h"
31#include "ns3/wifi-mac-header.h"
32#include "ns3/wifi-net-device.h"
39#define NUM_LAST_PACKETS 10
41static std::vector<std::string>
44 std::vector<std::string> results;
46 while ((cutAt = str.find_first_of(
'/')) != std::string::npos)
50 results.push_back(str.substr(0, cutAt));
52 str = str.substr(cutAt + 1);
56 results.push_back(str);
76 void Print(std::ostream& os)
const override;
91 .SetGroupName(
"Visualizer")
188 std::ostringstream sstream;
189 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/MacTx";
193 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
197 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/PromiscRx";
206 std::ostringstream sstream;
207 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Tx";
211 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
220 std::ostringstream sstream;
221 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/TxQueue/Dequeue";
225 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
233 << nodeId <<
" PacketCaptureOptions (headers size = " << options.
headers.size()
269std::vector<std::string>
274 <<
" pause messages");
303 if (iter->second.time < expirationTime)
316 if (iter->second < expirationTime)
345 visualImpl->RunRealSimulator();
387 std::vector<NetDeviceStatistics>* stats;
395 stats = &(nodeStatsIter->second);
411 *outOptions = &iter->second;
419 switch (options.
mode)
426 while (metadataIterator.
HasNext())
438 std::set<TypeId> missingHeaders(options.
headers);
440 while (metadataIterator.
HasNext())
443 auto missingIter = missingHeaders.find(item.
tid);
444 if (missingIter != missingHeaders.end())
446 missingHeaders.erase(missingIter);
449 return missingHeaders.empty();
462 std::vector<std::string> splitPath =
PathSplit(context);
463 int nodeIndex = std::stoi(splitPath[1]);
472 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
485 lastPacket.
packet = packet->Copy();
486 lastPacket.
device =
nullptr;
501 iter->second += packet->GetSize();
514 packetCopy->AddHeader(hdr);
527 std::vector<std::string> splitPath =
PathSplit(context);
528 int nodeIndex = std::stoi(splitPath[1]);
529 int devIndex = std::stoi(splitPath[3]);
546 lastPacket.
packet = packet->Copy();
547 lastPacket.
device = device;
548 lastPacket.
to = destinationAddress;
564 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
575 if (destinationAddress == device->GetBroadcast())
585 packet->AddByteTag(tag);
606 destinationAddress = hdr.
GetAddr3();
610 destinationAddress = hdr.
GetAddr1();
619 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
638 if (packet->FindFirstMatchingByteTag(tag))
645 NS_LOG_WARN(
"Packet has no byte tag; wimax link?");
646 uid = packet->GetUid();
650 std::vector<std::string> splitPath =
PathSplit(context);
651 int nodeIndex = std::stoi(splitPath[1]);
652 int devIndex = std::stoi(splitPath[3]);
670 lastPacket.
packet = packet->Copy();
671 lastPacket.
device = device;
672 lastPacket.
from = from;
683 NS_LOG_DEBUG(
"RX Packet " << uid <<
" is not of interest");
693 NS_LOG_DEBUG(
"RX Packet " << uid <<
" was not transmitted?!");
701 NS_LOG_WARN(
"Node " << node->GetId() <<
" receiving back the same packet (UID=" << uid
702 <<
") it had previously transmitted, on the same channel!");
715 <<
"/" << iter->first.transmitter->GetId() <<
", " << iter->first.receiver
716 <<
"/" << iter->first.receiver->GetId() <<
", " << iter->first.channel
717 <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
730 << channel <<
": " << packet->GetSize()
731 <<
" bytes more. => new sample with " << packet->GetSize()
740 << channel <<
": " << packet->GetSize()
741 <<
" bytes more. => sample " << &sample <<
" with bytes "
744 sample.
bytes += packet->GetSize();
784 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
798 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
853 sample.
receiver = iter->first.receiver;
854 sample.
channel = iter->first.channel;
855 sample.
bytes = iter->second.bytes;
857 <<
": " << sample.
bytes <<
" bytes.");
858 list.push_back(sample);
873 sample.
bytes = iter->second;
875 <<
" bytes dropped.");
876 list.push_back(sample);
888std::vector<PyViz::NodeStatistics>
891 std::vector<PyViz::NodeStatistics> retval;
895 retval.push_back(stats);
988 line.
end.
x += line.
dx * (m_clipMin.
y - line.
end.
y) / line.
dy;
989 line.
end.
y = m_clipMin.
y;
998 line.
end.
x += line.
dx * (m_clipMax.
y - line.
end.
y) / line.
dy;
999 line.
end.
y = m_clipMax.
y;
1008 line.
end.
y += line.
dy * (m_clipMax.
x - line.
end.
x) / line.
dx;
1009 line.
end.
x = m_clipMax.
x;
1018 line.
end.
y += line.
dy * (m_clipMin.
x - line.
end.
x) / line.
dx;
1019 line.
end.
x = m_clipMin.
x;
1030 : m_clipMin(clipMin),
1042 uint8_t lineCode = 0;
1044 if (line.
end.
y < m_clipMin.
y)
1048 else if (line.
end.
y > m_clipMax.
y)
1053 if (line.
end.
x > m_clipMax.
x)
1057 else if (line.
end.
x < m_clipMin.
x)
1062 if (line.
start.
y < m_clipMin.
y)
1066 else if (line.
start.
y > m_clipMax.
y)
1071 if (line.
start.
x > m_clipMax.
x)
1075 else if (line.
start.
x < m_clipMin.
x)
1100 ClipEndBottom(line);
1105 if (line.
end.
y > m_clipMax.
y)
1107 ClipEndBottom(line);
1113 if (line.
end.
y > m_clipMax.
y)
1115 ClipEndBottom(line);
1125 if (line.
end.
y < m_clipMin.
y)
1133 if (line.
end.
y < m_clipMin.
y)
1141 ClipStartLeft(line);
1145 ClipStartLeft(line);
1150 ClipStartLeft(line);
1151 if (line.
start.
y > m_clipMax.
y)
1155 ClipEndBottom(line);
1159 ClipStartLeft(line);
1160 if (line.
start.
y > m_clipMax.
y)
1164 ClipEndBottom(line);
1165 if (line.
end.
x > m_clipMax.
x)
1172 ClipStartLeft(line);
1173 if (line.
start.
y < m_clipMin.
y)
1181 ClipStartLeft(line);
1182 if (line.
start.
y < m_clipMin.
y)
1187 if (line.
end.
x > m_clipMax.
x)
1195 ClipStartRight(line);
1199 ClipStartRight(line);
1204 ClipStartRight(line);
1205 if (line.
start.
y > m_clipMax.
y)
1209 ClipEndBottom(line);
1213 ClipStartRight(line);
1214 if (line.
start.
y > m_clipMax.
y)
1218 ClipEndBottom(line);
1219 if (line.
end.
x < m_clipMin.
x)
1226 ClipStartRight(line);
1227 if (line.
start.
y < m_clipMin.
y)
1235 ClipStartRight(line);
1236 if (line.
start.
y < m_clipMin.
y)
1241 if (line.
end.
x < m_clipMin.
x)
1249 ClipStartBottom(line);
1253 ClipStartBottom(line);
1254 if (line.
start.
x < m_clipMin.
x)
1259 if (line.
end.
y > m_clipMax.
y)
1261 ClipEndBottom(line);
1266 ClipStartBottom(line);
1267 if (line.
start.
x > m_clipMax.
x)
1275 ClipStartBottom(line);
1280 ClipStartBottom(line);
1281 if (line.
start.
x < m_clipMin.
x)
1286 if (line.
end.
y < m_clipMin.
y)
1293 ClipStartBottom(line);
1294 if (line.
start.
x > m_clipMax.
x)
1299 if (line.
end.
y < m_clipMin.
y)
1307 ClipStartLeft(line);
1308 if (line.
start.
y > m_clipMax.
y)
1310 ClipStartBottom(line);
1316 if (line.
end.
y > m_clipMax.
y)
1320 ClipStartBottom(line);
1321 if (line.
start.
x < m_clipMin.
x)
1323 ClipStartLeft(line);
1329 if (line.
end.
x < m_clipMin.
x)
1333 ClipStartBottom(line);
1334 if (line.
start.
x < m_clipMin.
x)
1336 ClipStartLeft(line);
1341 ClipStartLeft(line);
1342 if (line.
start.
y < m_clipMin.
y)
1347 if (line.
end.
y > m_clipMax.
y)
1351 if (line.
start.
y > m_clipMax.
y)
1353 ClipStartBottom(line);
1355 if (line.
end.
y < m_clipMin.
y)
1363 ClipStartRight(line);
1364 if (line.
start.
y > m_clipMax.
y)
1366 ClipStartBottom(line);
1372 if (line.
end.
y > m_clipMax.
y)
1376 ClipStartBottom(line);
1377 if (line.
start.
x > m_clipMax.
x)
1379 ClipStartRight(line);
1385 if (line.
end.
x > m_clipMax.
x)
1389 ClipStartRight(line);
1390 if (line.
start.
y > m_clipMax.
y)
1392 ClipStartBottom(line);
1398 if (line.
end.
y > m_clipMax.
y)
1402 ClipStartRight(line);
1403 if (line.
start.
y < m_clipMin.
y)
1407 if (line.
end.
y < m_clipMin.
y)
1411 if (line.
start.
y > m_clipMax.
y)
1413 ClipStartBottom(line);
1424 if (line.
start.
x < m_clipMin.
x)
1433 if (line.
start.
x > m_clipMax.
x)
1442 ClipEndBottom(line);
1447 if (line.
start.
x < m_clipMin.
x)
1452 if (line.
end.
y > m_clipMax.
y)
1454 ClipEndBottom(line);
1460 if (line.
start.
x > m_clipMax.
x)
1465 if (line.
end.
y > m_clipMax.
y)
1467 ClipEndBottom(line);
1473 ClipStartLeft(line);
1474 if (line.
start.
y < m_clipMin.
y)
1482 if (line.
end.
y < m_clipMin.
y)
1487 if (line.
start.
x < m_clipMin.
x)
1489 ClipStartLeft(line);
1494 ClipEndBottom(line);
1495 if (line.
end.
x < m_clipMin.
x)
1499 ClipStartLeft(line);
1500 if (line.
start.
y < m_clipMin.
y)
1507 ClipStartLeft(line);
1508 if (line.
start.
y > m_clipMax.
y)
1513 if (line.
end.
y < m_clipMin.
y)
1517 if (line.
start.
y < m_clipMin.
y)
1521 if (line.
end.
y > m_clipMax.
y)
1523 ClipEndBottom(line);
1529 ClipStartRight(line);
1530 if (line.
start.
y < m_clipMin.
y)
1538 if (line.
end.
y < m_clipMin.
y)
1543 if (line.
start.
x > m_clipMax.
x)
1545 ClipStartRight(line);
1550 ClipEndBottom(line);
1551 if (line.
end.
x > m_clipMax.
x)
1555 ClipStartRight(line);
1556 if (line.
start.
y < m_clipMin.
y)
1564 if (line.
end.
y < m_clipMin.
y)
1568 ClipStartRight(line);
1569 if (line.
start.
y > m_clipMax.
y)
1573 if (line.
end.
y > m_clipMax.
y)
1575 ClipEndBottom(line);
1577 if (line.
start.
y < m_clipMin.
y)
1599 FastClipping::Vector2 clipMin = {boundsX1, boundsY1};
1600 FastClipping::Vector2 clipMax = {boundsX2, boundsY2};
1601 FastClipping::Line line = {{lineX1, lineY1},
1606 FastClipping clipper(clipMin, clipMax);
1607 clipper.ClipLine(line);
1608 lineX1 = line.start.x;
1609 lineX2 = line.end.x;
1610 lineY1 = line.start.y;
1611 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...
@ 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