24 #include "ns3/abort.h"
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
41 static 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()
269 std::vector<std::string>
274 <<
" pause messages");
301 for (std::map<TxRecordKey, TxRecordValue>::iterator iter =
m_txRecords.begin();
304 if (iter->second.time < expirationTime)
318 if (iter->second < expirationTime)
347 visualImpl->RunRealSimulator();
395 std::map<uint32_t, std::vector<NetDeviceStatistics>>::iterator nodeStatsIter =
397 std::vector<NetDeviceStatistics>* stats;
405 stats = &(nodeStatsIter->second);
414 std::map<uint32_t, PacketCaptureOptions>::const_iterator iter =
422 *outOptions = &iter->second;
430 switch (options.
mode)
437 while (metadataIterator.
HasNext())
449 std::set<TypeId> missingHeaders(options.
headers);
451 while (metadataIterator.
HasNext())
454 std::set<TypeId>::iterator missingIter = missingHeaders.find(item.
tid);
455 if (missingIter != missingHeaders.end())
457 missingHeaders.erase(missingIter);
460 if (missingHeaders.empty())
480 std::vector<std::string> splitPath =
PathSplit(context);
481 int nodeIndex = std::stoi(splitPath[1]);
504 lastPacket.
device =
nullptr;
512 std::map<Ptr<Node>, uint32_t>::iterator iter =
m_packetDrops.find(node);
519 iter->second += packet->
GetSize();
545 std::vector<std::string> splitPath =
PathSplit(context);
546 int nodeIndex = std::stoi(splitPath[1]);
547 int devIndex = std::stoi(splitPath[3]);
565 lastPacket.
device = device;
566 lastPacket.
to = destinationAddress;
593 if (destinationAddress == device->GetBroadcast())
624 destinationAddress = hdr.
GetAddr3();
628 destinationAddress = hdr.
GetAddr1();
632 destinationAddress = hdr.
GetAddr1();
636 destinationAddress = hdr.
GetAddr3();
671 NS_LOG_WARN(
"Packet has no byte tag; wimax link?");
676 std::vector<std::string> splitPath =
PathSplit(context);
677 int nodeIndex = std::stoi(splitPath[1]);
678 int devIndex = std::stoi(splitPath[3]);
697 lastPacket.
device = device;
698 lastPacket.
from = from;
709 NS_LOG_DEBUG(
"RX Packet " << uid <<
" is not of interest");
715 std::map<TxRecordKey, TxRecordValue>::iterator recordIter =
720 NS_LOG_DEBUG(
"RX Packet " << uid <<
" was not transmitted?!");
728 NS_LOG_WARN(
"Node " << node->
GetId() <<
" receiving back the same packet (UID=" << uid
729 <<
") it had previously transmitted, on the same channel!");
735 #ifdef NS3_LOG_ENABLE
739 for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator iter =
745 <<
"/" << iter->first.transmitter->GetId() <<
", " << iter->first.receiver
746 <<
"/" << iter->first.receiver->GetId() <<
", " << iter->first.channel
747 <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
753 std::map<TransmissionSampleKey, TransmissionSampleValue>::iterator iter =
762 <<
" bytes more. => new sample with " << packet->
GetSize()
772 <<
" bytes more. => sample " << &sample <<
" with bytes "
884 for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator iter =
891 sample.
receiver = iter->first.receiver;
892 sample.
channel = iter->first.channel;
893 sample.
bytes = iter->second.bytes;
895 <<
": " << sample.
bytes <<
" bytes.");
896 list.push_back(sample);
913 sample.
bytes = iter->second;
915 <<
" bytes dropped.");
916 list.push_back(sample);
928 std::vector<PyViz::NodeStatistics>
931 std::vector<PyViz::NodeStatistics> retval;
932 for (std::map<uint32_t, std::vector<NetDeviceStatistics>>::const_iterator iter =
938 retval.push_back(stats);
948 std::map<uint32_t, LastPacketsSample>::const_iterator iter =
m_lastPackets.find(nodeId);
1031 line.
end.
x += line.
dx * (m_clipMin.
y - line.
end.
y) / line.
dy;
1032 line.
end.
y = m_clipMin.
y;
1041 line.
end.
x += line.
dx * (m_clipMax.
y - line.
end.
y) / line.
dy;
1042 line.
end.
y = m_clipMax.
y;
1051 line.
end.
y += line.
dy * (m_clipMax.
x - line.
end.
x) / line.
dx;
1052 line.
end.
x = m_clipMax.
x;
1061 line.
end.
y += line.
dy * (m_clipMin.
x - line.
end.
x) / line.
dx;
1062 line.
end.
x = m_clipMin.
x;
1073 : m_clipMin(clipMin),
1085 uint8_t lineCode = 0;
1087 if (line.
end.
y < m_clipMin.
y)
1091 else if (line.
end.
y > m_clipMax.
y)
1096 if (line.
end.
x > m_clipMax.
x)
1100 else if (line.
end.
x < m_clipMin.
x)
1105 if (line.
start.
y < m_clipMin.
y)
1109 else if (line.
start.
y > m_clipMax.
y)
1114 if (line.
start.
x > m_clipMax.
x)
1118 else if (line.
start.
x < m_clipMin.
x)
1143 ClipEndBottom(line);
1148 if (line.
end.
y > m_clipMax.
y)
1150 ClipEndBottom(line);
1156 if (line.
end.
y > m_clipMax.
y)
1158 ClipEndBottom(line);
1168 if (line.
end.
y < m_clipMin.
y)
1176 if (line.
end.
y < m_clipMin.
y)
1184 ClipStartLeft(line);
1188 ClipStartLeft(line);
1193 ClipStartLeft(line);
1194 if (line.
start.
y > m_clipMax.
y)
1198 ClipEndBottom(line);
1202 ClipStartLeft(line);
1203 if (line.
start.
y > m_clipMax.
y)
1207 ClipEndBottom(line);
1208 if (line.
end.
x > m_clipMax.
x)
1215 ClipStartLeft(line);
1216 if (line.
start.
y < m_clipMin.
y)
1224 ClipStartLeft(line);
1225 if (line.
start.
y < m_clipMin.
y)
1230 if (line.
end.
x > m_clipMax.
x)
1238 ClipStartRight(line);
1242 ClipStartRight(line);
1247 ClipStartRight(line);
1248 if (line.
start.
y > m_clipMax.
y)
1252 ClipEndBottom(line);
1256 ClipStartRight(line);
1257 if (line.
start.
y > m_clipMax.
y)
1261 ClipEndBottom(line);
1262 if (line.
end.
x < m_clipMin.
x)
1269 ClipStartRight(line);
1270 if (line.
start.
y < m_clipMin.
y)
1278 ClipStartRight(line);
1279 if (line.
start.
y < m_clipMin.
y)
1284 if (line.
end.
x < m_clipMin.
x)
1292 ClipStartBottom(line);
1296 ClipStartBottom(line);
1297 if (line.
start.
x < m_clipMin.
x)
1302 if (line.
end.
y > m_clipMax.
y)
1304 ClipEndBottom(line);
1309 ClipStartBottom(line);
1310 if (line.
start.
x > m_clipMax.
x)
1318 ClipStartBottom(line);
1323 ClipStartBottom(line);
1324 if (line.
start.
x < m_clipMin.
x)
1329 if (line.
end.
y < m_clipMin.
y)
1336 ClipStartBottom(line);
1337 if (line.
start.
x > m_clipMax.
x)
1342 if (line.
end.
y < m_clipMin.
y)
1350 ClipStartLeft(line);
1351 if (line.
start.
y > m_clipMax.
y)
1353 ClipStartBottom(line);
1359 if (line.
end.
y > m_clipMax.
y)
1363 ClipStartBottom(line);
1364 if (line.
start.
x < m_clipMin.
x)
1366 ClipStartLeft(line);
1372 if (line.
end.
x < m_clipMin.
x)
1376 ClipStartBottom(line);
1377 if (line.
start.
x < m_clipMin.
x)
1379 ClipStartLeft(line);
1384 ClipStartLeft(line);
1385 if (line.
start.
y < m_clipMin.
y)
1390 if (line.
end.
y > m_clipMax.
y)
1394 if (line.
start.
y > m_clipMax.
y)
1396 ClipStartBottom(line);
1398 if (line.
end.
y < m_clipMin.
y)
1406 ClipStartRight(line);
1407 if (line.
start.
y > m_clipMax.
y)
1409 ClipStartBottom(line);
1415 if (line.
end.
y > m_clipMax.
y)
1419 ClipStartBottom(line);
1420 if (line.
start.
x > m_clipMax.
x)
1422 ClipStartRight(line);
1428 if (line.
end.
x > m_clipMax.
x)
1432 ClipStartRight(line);
1433 if (line.
start.
y > m_clipMax.
y)
1435 ClipStartBottom(line);
1441 if (line.
end.
y > m_clipMax.
y)
1445 ClipStartRight(line);
1446 if (line.
start.
y < m_clipMin.
y)
1450 if (line.
end.
y < m_clipMin.
y)
1454 if (line.
start.
y > m_clipMax.
y)
1456 ClipStartBottom(line);
1467 if (line.
start.
x < m_clipMin.
x)
1476 if (line.
start.
x > m_clipMax.
x)
1485 ClipEndBottom(line);
1490 if (line.
start.
x < m_clipMin.
x)
1495 if (line.
end.
y > m_clipMax.
y)
1497 ClipEndBottom(line);
1503 if (line.
start.
x > m_clipMax.
x)
1508 if (line.
end.
y > m_clipMax.
y)
1510 ClipEndBottom(line);
1516 ClipStartLeft(line);
1517 if (line.
start.
y < m_clipMin.
y)
1525 if (line.
end.
y < m_clipMin.
y)
1530 if (line.
start.
x < m_clipMin.
x)
1532 ClipStartLeft(line);
1537 ClipEndBottom(line);
1538 if (line.
end.
x < m_clipMin.
x)
1542 ClipStartLeft(line);
1543 if (line.
start.
y < m_clipMin.
y)
1550 ClipStartLeft(line);
1551 if (line.
start.
y > m_clipMax.
y)
1556 if (line.
end.
y < m_clipMin.
y)
1560 if (line.
start.
y < m_clipMin.
y)
1564 if (line.
end.
y > m_clipMax.
y)
1566 ClipEndBottom(line);
1572 ClipStartRight(line);
1573 if (line.
start.
y < m_clipMin.
y)
1581 if (line.
end.
y < m_clipMin.
y)
1586 if (line.
start.
x > m_clipMax.
x)
1588 ClipStartRight(line);
1593 ClipEndBottom(line);
1594 if (line.
end.
x > m_clipMax.
x)
1598 ClipStartRight(line);
1599 if (line.
start.
y < m_clipMin.
y)
1607 if (line.
end.
y < m_clipMin.
y)
1611 ClipStartRight(line);
1612 if (line.
start.
y > m_clipMax.
y)
1616 if (line.
end.
y > m_clipMax.
y)
1618 ClipEndBottom(line);
1620 if (line.
start.
y < m_clipMin.
y)
1642 FastClipping::Vector2 clipMin = {boundsX1, boundsY1};
1643 FastClipping::Vector2 clipMax = {boundsX2, boundsY2};
1644 FastClipping::Line line = {{lineX1, lineY1},
1649 FastClipping clipper(clipMin, clipMax);
1650 clipper.ClipLine(line);
1651 lineX1 = line.start.x;
1652 lineX2 = line.end.x;
1653 lineY1 = line.start.y;
1654 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.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
static Ptr< Node > GetNode(uint32_t n)
PacketMetadata::ItemIterator BeginItem() const
Returns an iterator which points to the first 'item' stored in this buffer.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > Copy() const
performs a COW copy of the packet.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
uint64_t GetUid() const
Returns the packet's Uid.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
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
Rare ad-hoc debug messages.
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