15#include "ns3/config.h"
16#include "ns3/ethernet-header.h"
18#include "ns3/lr-wpan-mac-header.h"
19#include "ns3/lr-wpan-net-device.h"
20#include "ns3/node-list.h"
21#include "ns3/ppp-header.h"
22#include "ns3/simulator.h"
23#include "ns3/wifi-mac-header.h"
24#include "ns3/wifi-net-device.h"
33static std::vector<std::string>
36 std::vector<std::string> results;
38 while ((cutAt = str.find_first_of(
'/')) != std::string::npos)
42 results.push_back(str.substr(0, cutAt));
44 str = str.substr(cutAt + 1);
48 results.push_back(str);
71 void Print(std::ostream& os)
const override;
84 static TypeId tid =
TypeId(
"ns3::visualizer::PyVizPacketTag")
87 .SetGroupName(
"Visualizer")
183 std::ostringstream sstream;
184 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/MacTx";
188 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
192 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/PromiscRx";
201 std::ostringstream sstream;
202 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Tx";
206 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
215 std::ostringstream sstream;
216 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/TxQueue/Dequeue";
220 sstream <<
"/NodeList/*/DeviceList/*/$" << deviceTypeName <<
"/Rx";
228 << nodeId <<
" PacketCaptureOptions (headers size = " << options.
headers.size()
254 <<
": Have " <<
g_visualizer->m_pauseMessages.size() <<
" pause messages");
264std::vector<std::string>
268 <<
": GetPauseMessages: have " <<
g_visualizer->m_pauseMessages.size()
269 <<
" pause messages");
298 if (iter->second.time < expirationTime)
311 if (iter->second < expirationTime)
341 visualImpl->RunRealSimulator();
354 return visualImpl->GetStopTime();
391 std::vector<NetDeviceStatistics>* stats;
399 stats = &(nodeStatsIter->second);
415 *outOptions = &iter->second;
423 switch (options.
mode)
430 while (metadataIterator.
HasNext())
442 std::set<TypeId> missingHeaders(options.
headers);
444 while (metadataIterator.
HasNext())
447 auto missingIter = missingHeaders.find(item.
tid);
448 if (missingIter != missingHeaders.end())
450 missingHeaders.erase(missingIter);
453 return missingHeaders.empty();
466 std::vector<std::string> splitPath =
PathSplit(context);
467 int nodeIndex = std::stoi(splitPath[1]);
476 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
489 lastPacket.
packet = packet->Copy();
490 lastPacket.
device =
nullptr;
505 iter->second += packet->GetSize();
518 packetCopy->AddHeader(hdr);
526 const std::string& context,
528 const std::variant<Mac16Address, Mac48Address, Mac64Address>& destination)
532 std::vector<std::string> splitPath =
PathSplit(context);
533 int nodeIndex = std::stoi(splitPath[1]);
534 int devIndex = std::stoi(splitPath[3]);
551 lastPacket.
packet = packet->Copy();
552 lastPacket.
device = device;
553 lastPacket.
to = destination;
570 NS_LOG_DEBUG(
"Packet " << packet->GetUid() <<
" is not of interest");
582 if (std::holds_alternative<Mac16Address>(destination))
584 if (std::get<Mac16Address>(destination) ==
Mac16Address(
"FF:FF"))
589 else if (std::holds_alternative<Mac48Address>(destination))
591 if (std::get<Mac48Address>(destination) == device->GetBroadcast())
596 else if (std::holds_alternative<Mac64Address>(destination))
598 if (std::get<Mac64Address>(destination) ==
Mac64Address(
"FF:FF:FF:FF:FF:FF:FF:FF"))
611 packet->AddByteTag(tag);
630 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
633 destinationAddress = hdr.
GetAddr3();
637 destinationAddress = hdr.
GetAddr1();
647 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
666 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
667 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
675 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
685 const std::variant<Mac16Address, Mac48Address, Mac64Address>& source)
689 if (packet->FindFirstMatchingByteTag(tag))
697 uid = packet->GetUid();
701 std::vector<std::string> splitPath =
PathSplit(context);
702 int nodeIndex = std::stoi(splitPath[1]);
703 int devIndex = std::stoi(splitPath[3]);
721 lastPacket.
packet = packet->Copy();
722 lastPacket.
device = device;
723 lastPacket.
from = source;
735 NS_LOG_DEBUG(
"RX Packet " << uid <<
" is not of interest");
745 NS_LOG_DEBUG(
"RX Packet " << uid <<
" was not transmitted?!");
753 NS_LOG_WARN(
"Node " << node->GetId() <<
" receiving back the same packet (UID=" << uid
754 <<
") it had previously transmitted, on the same channel!");
767 <<
"/" << iter->first.transmitter->GetId() <<
", " << iter->first.receiver
768 <<
"/" << iter->first.receiver->GetId() <<
", " << iter->first.channel
769 <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
782 << channel <<
": " << packet->GetSize()
783 <<
" bytes more. => new sample with " << packet->GetSize()
792 << channel <<
": " << packet->GetSize()
793 <<
" bytes more. => sample " << &sample <<
" with bytes "
796 sample.
bytes += packet->GetSize();
815 std::variant<Mac16Address, Mac48Address, Mac64Address> sourceAddress;
837 std::variant<Mac16Address, Mac48Address, Mac64Address> sourceAddress;
855 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
856 std::variant<Mac16Address, Mac48Address, Mac64Address> sourceAddress;
857 sourceAddress = ethernetHeader.
GetSource();
864 std::variant<Mac16Address, Mac48Address, Mac64Address> sourceAddress;
873 NS_ABORT_IF(packet->PeekHeader(ethernetHeader) == 0);
881 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
893 std::variant<Mac16Address, Mac48Address, Mac64Address> destinationAddress;
894 destinationAddress = destination;
902 std::variant<Mac16Address, Mac48Address, Mac64Address> sourceAddress;
903 sourceAddress = source;
918 sample.
receiver = iter->first.receiver;
919 sample.
channel = iter->first.channel;
920 sample.
bytes = iter->second.bytes;
922 <<
": " << sample.
bytes <<
" bytes.");
923 list.push_back(sample);
938 sample.
bytes = iter->second;
940 <<
" bytes dropped.");
941 list.push_back(sample);
953std::vector<NodeStatistics>
956 std::vector<NodeStatistics> retval;
960 retval.push_back(stats);
1001 lineX2 = line.
end.
x;
1003 lineY2 = line.
end.
y;
DropReason
Reason why a packet has been dropped.
This class can contain 16 bit addresses.
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.
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.
static Time Now()
Return the current simulation virtual time.
@ NO_CONTEXT
Flag for events not associated with any particular context.
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 AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class is used by the visualizer for the process of removing lines or portions of lines outside o...
bool ClipLine(Line &line)
Clip line function.
helper class to be used by the visualizer
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
TxRecordKey type definition.
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &destination)
LTE transmit trace callback function.
void SetNodesOfInterest(std::set< uint32_t > nodes)
Set nodes of interest 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 TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi receive trace callback function.
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point 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::vector< NodeStatistics > GetNodesStatistics() const
Get node statistics.
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Filter packet function.
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
Transmission samples.
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
CSMA promiscuous receive function.
Time GetSimulatorStopTime()
Get the stop time of the underlying visual simulator implementation.
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
Packet capture options.
std::vector< std::string > GetPauseMessages() const
Get pause message function.
void TraceNetDevTxCommon(const std::string &context, Ptr< const Packet > packet, const std::variant< Mac16Address, Mac48Address, Mac64Address > &destination)
Network transmit common trace callback function.
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point transmit trace callback function.
std::map< uint32_t, Time > m_packetsOfInterest
List of packet UIDs that will be monitored.
void RegisterCsmaLikeDevice(const std::string &deviceTypeName)
Register CSMA like device function.
void TraceNetDevRxCommon(const std::string &context, Ptr< const Packet > packet, const std::variant< Mac16Address, Mac48Address, Mac64Address > &source)
Network receive common trace callback function.
std::set< uint32_t > m_nodesOfInterest
List of node IDs whose transmissions will be monitored.
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi transmit trace callback function.
std::map< Ptr< Node >, uint32_t > m_packetDrops
Packet drops.
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.
TransmissionSampleList GetTransmissionSamples() const
Get transmission samples.
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Get last packets function.
std::map< uint32_t, LastPacketsSample > m_lastPackets
Last packets.
static void Pause(const std::string &message)
Pause function.
bool m_stop
Stop simulation flag.
void RegisterPointToPointLikeDevice(const std::string &deviceTypeName)
Register point to point like device function.
void TraceNetDevTxLrWpan(std::string context, Ptr< const Packet > packet)
Lr-Wpan transmit trace callback function.
void RegisterWifiLikeDevice(const std::string &deviceTypeName)
Register WIFI like device function.
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< TxRecordKey, TxRecordValue > m_txRecords
Transmit records.
void DoPause(const std::string &message)
Do pause function.
void TraceNetDevRxLrWpan(std::string context, Ptr< const Packet > packet)
Lr-Wpan receive trace callback function.
void SimulatorRunUntil(Time time)
Run simulation until a given (simulated, absolute) time is reached.
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &source)
LTE receive trace callback function.
PacketDropSampleList GetPacketDropSamples() const
Get packet drop samples.
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
Node statistics.
Time m_runUntil
Indicates until when the simulation should run for its next step.
void RegisterDropTracePath(const std::string &tracePath)
Register drop trace path function.
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
CSMA transmit trace callback function.
void CallbackStopSimulation()
Stop simulation callback function.
std::vector< std::string > m_pauseMessages
Pause message.
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Get packet capture options function.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
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...
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.
@ PACKET_CAPTURE_DISABLED
Packet capture is disabled.
@ PACKET_CAPTURE_FILTER_HEADERS_AND
Packet capture if all of the indicated headers are present.
@ PACKET_CAPTURE_FILTER_HEADERS_OR
Packet capture if any of the indicated headers is present.
std::vector< TransmissionSample > TransmissionSampleList
The transmission sample list.
static PyViz * g_visualizer
the visualizer
std::vector< PacketDropSample > PacketDropSampleList
The packet drop list.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
@ LOG_DEBUG
Full voluminous logging to support debugging.
static std::vector< std::string > PathSplit(std::string str)
Vector2 start
The start point of the line.
Vector2 end
The end point of the line.
Structure to handle a sample of the last received, transmitted or drop packets in a node.
std::vector< PacketSample > lastDroppedPackets
Last dropped packets.
std::vector< TxPacketSample > lastTransmittedPackets
Last transmitted packets.
std::vector< RxPacketSample > lastReceivedPackets
Last received packets.
The NetDeviceStatistics structure.
uint32_t transmittedPackets
Transmitted packets.
uint64_t receivedBytes
Received bytes.
uint64_t transmittedBytes
Transmitted bytes.
uint32_t receivedPackets
Received packets.
The NodeStatistics structure.
The PacketCaptureOptions structure.
uint32_t numLastPackets
Number of last packets.
std::set< TypeId > headers
The headers.
PacketCaptureMode mode
The packet capture node.
PacketDropSample structure.
uint32_t bytes
The number of bytes dropped.
Ptr< Node > transmitter
The transmitter node where the drop was registered.
Ptr< Packet > packet
The packet reference.
Ptr< NetDevice > device
The NetDevice reference.
Time time
The received or transmitted time of the sample.
The TransmissionSampleKey structure.
Ptr< Node > transmitter
transmitter
Ptr< Channel > channel
channel
bool operator==(const TransmissionSampleKey &other) const
Equality operator.
bool operator<(const TransmissionSampleKey &other) const
Less than operator.
Ptr< Node > receiver
NULL if broadcast.
The TransmissionSampleValue structure.
uint32_t bytes
The nuumber of bytes of the transmission sample.
The TxRecordValue structure.
Ptr< Node > srcNode
The source node of the transmission.
bool isBroadcast
Broadcast flag.
PyVizPacketTag structure.
void Deserialize(TagBuffer buf) override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
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
void Serialize(TagBuffer buf) const override
RxPacketSample structure.
std::variant< Mac16Address, Mac48Address, Mac64Address > from
The source MAC address.
TransmissionSample structure.
Ptr< Channel > channel
The channel reference used for the transmission.
Ptr< Node > receiver
The destination node of the transmission (Null if broadcast).
Ptr< Node > transmitter
The source node of the transmission.
uint32_t bytes
The number of bytes transmitted.
TxPacketSample structure.
std::variant< Mac16Address, Mac48Address, Mac64Address > to
The destination MAC address.