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 .AddConstructor<PyVizPacketTag> ()
130 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
133 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
142 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacPromiscRx",
151 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
154 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacRx",
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 <<
" PacketCaptureOptions (headers size = " << options.
headers.size ()
253 g_visualizer->
DoPause (message);
256 std::vector<std::string>
288 for (std::map<TxRecordKey, TxRecordValue>::iterator iter =
m_txRecords.begin ();
291 if (iter->second.time < expirationTime)
305 if (iter->second < expirationTime)
331 visualImpl->RunRealSimulator ();
369 bool retval = (transmitter == other.
transmitter) &&
379 std::map<uint32_t, std::vector<NetDeviceStatistics> >::iterator nodeStatsIter =
m_nodesStatistics.find (node);
380 std::vector<NetDeviceStatistics> *stats;
388 stats = &(nodeStatsIter->second);
403 *outOptions = &iter->second;
410 switch (options.
mode)
418 while (metadataIterator.
HasNext ())
431 std::set<TypeId> missingHeaders (options.
headers);
433 while (metadataIterator.
HasNext ())
436 std::set<TypeId>::iterator missingIter = missingHeaders.find (item.
tid);
437 if (missingIter != missingHeaders.end ())
439 missingHeaders.erase (missingIter);
442 if (missingHeaders.size () == 0)
462 std::vector<std::string> splitPath =
PathSplit (context);
463 int nodeIndex = std::atoi (splitPath[1].c_str ());
493 std::map<Ptr<Node>, uint32_t>::iterator iter =
m_packetDrops.find (node);
500 iter->second += packet->
GetSize ();
522 std::vector<std::string> splitPath =
PathSplit (context);
523 int nodeIndex = std::atoi (splitPath[1].c_str ());
524 int devIndex = std::atoi (splitPath[3].c_str ());
541 lastPacket.
device = device;
542 lastPacket.
to = destinationAddress;
569 if (destinationAddress == device->GetBroadcast ())
598 if (hdr.IsToDs () && !hdr.IsFromDs ())
600 destinationAddress = hdr.GetAddr3 ();
602 else if (!hdr.IsToDs () && hdr.IsFromDs ())
604 destinationAddress = hdr.GetAddr1 ();
606 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
608 destinationAddress = hdr.GetAddr1 ();
612 destinationAddress = hdr.GetAddr3 ();
649 NS_LOG_WARN (
"Packet has no byte tag; wimax link?");
654 std::vector<std::string> splitPath =
PathSplit (context);
655 int nodeIndex = std::atoi (splitPath[1].c_str ());
656 int devIndex = std::atoi (splitPath[3].c_str ());
674 lastPacket.
device = device;
675 lastPacket.
from = from;
686 NS_LOG_DEBUG (
"RX Packet " << uid <<
" is not of interest");
692 std::map<TxRecordKey, TxRecordValue>::iterator recordIter =
697 NS_LOG_DEBUG (
"RX Packet " << uid <<
" was not transmitted?!");
705 NS_LOG_WARN (
"Node " << node->
GetId () <<
" receiving back the same packet (UID=" << uid
706 <<
") it had previously transmitted, on the same channel!");
712 #ifdef NS3_LOG_ENABLE
716 for (std::map<TransmissionSampleKey,TransmissionSampleValue>::const_iterator iter
719 NS_LOG_DEBUG (iter->first.transmitter<<
"/"<<iter->first.transmitter->GetId () <<
", "
720 << iter->first.receiver<<
"/"<<iter->first.receiver->GetId ()
721 <<
", " << iter->first.channel <<
" => " << iter->second.bytes <<
" (@ " << &iter->second <<
")");
727 std::map<TransmissionSampleKey,TransmissionSampleValue>::iterator
735 <<
" channel " << channel <<
": " << packet->
GetSize ()
736 <<
" bytes more. => new sample with " << packet->
GetSize () <<
" bytes.");
744 <<
" channel " << channel <<
": " << packet->
GetSize ()
745 <<
" bytes more. => sample " << &sample <<
" with bytes " << sample.
bytes);
768 if (hdr.IsToDs () && !hdr.IsFromDs ())
770 sourceAddress = hdr.GetAddr2 ();
772 else if (!hdr.IsToDs () && hdr.IsFromDs ())
774 sourceAddress = hdr.GetAddr3 ();
776 else if (!hdr.IsToDs () && !hdr.IsFromDs ())
778 sourceAddress = hdr.GetAddr2 ();
782 sourceAddress = hdr.GetAddr4 ();
855 for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator
862 sample.
receiver = iter->first.receiver;
863 sample.
channel = iter->first.channel;
864 sample.
bytes = iter->second.bytes;
866 <<
": " << sample.
bytes <<
" bytes.");
867 list.push_back (sample);
878 for (std::map<
Ptr<Node>, uint32_t>::const_iterator
885 sample.
bytes = iter->second;
887 <<
": " << sample.
bytes <<
" bytes dropped.");
888 list.push_back (sample);
900 std::vector<PyViz::NodeStatistics>
903 std::vector<PyViz::NodeStatistics> retval;
904 for (std::map<uint32_t, std::vector<NetDeviceStatistics> >::const_iterator iter =
m_nodesStatistics.begin ();
908 retval.push_back (stats);
919 std::map<uint32_t, LastPacketsSample>::const_iterator
984 line.
end.
x += line.
dx * (m_clipMin.
y - line.
end.
y) / line.
dy;
985 line.
end.
y = m_clipMin.
y;
989 line.
end.
x += line.
dx * (m_clipMax.
y - line.
end.
y) / line.
dy;
990 line.
end.
y = m_clipMax.
y;
995 line.
end.
y += line.
dy * (m_clipMax.
x - line.
end.
x) / line.
dx;
996 line.
end.
x = m_clipMax.
x;
1001 line.
end.
y += line.
dy * (m_clipMin.
x - line.
end.
x) / line.
dx;
1002 line.
end.
x = m_clipMin.
x;
1007 : m_clipMin (clipMin), m_clipMax (clipMax)
1014 uint8_t lineCode = 0;
1016 if (line.
end.
y < m_clipMin.
y)
1018 else if (line.
end.
y > m_clipMax.
y)
1021 if (line.
end.
x > m_clipMax.
x)
1023 else if (line.
end.
x < m_clipMin.
x)
1026 if (line.
start.
y < m_clipMin.
y)
1028 else if (line.
start.
y > m_clipMax.
y)
1031 if (line.
start.
x > m_clipMax.
x)
1033 else if (line.
start.
x < m_clipMin.
x)
1052 ClipEndRight (line);
1056 ClipEndBottom (line);
1061 if (line.
end.
y > m_clipMax.
y)
1062 ClipEndBottom (line);
1066 ClipEndRight (line);
1067 if (line.
end.
y > m_clipMax.
y)
1068 ClipEndBottom (line);
1077 if (line.
end.
y < m_clipMin.
y)
1082 ClipEndRight (line);
1083 if (line.
end.
y < m_clipMin.
y)
1089 ClipStartLeft (line);
1093 ClipStartLeft (line);
1094 ClipEndRight (line);
1098 ClipStartLeft (line);
1099 if (line.
start.
y > m_clipMax.
y)
1101 ClipEndBottom (line);
1105 ClipStartLeft (line);
1106 if (line.
start.
y > m_clipMax.
y)
1108 ClipEndBottom (line);
1109 if (line.
end.
x > m_clipMax.
x)
1110 ClipEndRight (line);
1114 ClipStartLeft (line);
1115 if (line.
start.
y < m_clipMin.
y)
1121 ClipStartLeft (line);
1122 if (line.
start.
y < m_clipMin.
y)
1125 if (line.
end.
x > m_clipMax.
x)
1126 ClipEndRight (line);
1131 ClipStartRight (line);
1135 ClipStartRight (line);
1140 ClipStartRight (line);
1141 if (line.
start.
y > m_clipMax.
y)
1143 ClipEndBottom (line);
1147 ClipStartRight (line);
1148 if (line.
start.
y > m_clipMax.
y)
1150 ClipEndBottom (line);
1151 if (line.
end.
x < m_clipMin.
x)
1156 ClipStartRight (line);
1157 if (line.
start.
y < m_clipMin.
y)
1163 ClipStartRight (line);
1164 if (line.
start.
y < m_clipMin.
y)
1167 if (line.
end.
x < m_clipMin.
x)
1173 ClipStartBottom (line);
1177 ClipStartBottom (line);
1178 if (line.
start.
x < m_clipMin.
x)
1181 if (line.
end.
y > m_clipMax.
y)
1182 ClipEndBottom (line);
1186 ClipStartBottom (line);
1187 if (line.
start.
x > m_clipMax.
x)
1189 ClipEndRight (line);
1193 ClipStartBottom (line);
1198 ClipStartBottom (line);
1199 if (line.
start.
x < m_clipMin.
x)
1202 if (line.
end.
y < m_clipMin.
y)
1207 ClipStartBottom (line);
1208 if (line.
start.
x > m_clipMax.
x)
1210 ClipEndRight (line);
1211 if (line.
end.
y < m_clipMin.
y)
1217 ClipStartLeft (line);
1218 if (line.
start.
y > m_clipMax.
y)
1219 ClipStartBottom (line);
1223 ClipEndRight (line);
1224 if (line.
end.
y > m_clipMax.
y)
1226 ClipStartBottom (line);
1227 if (line.
start.
x < m_clipMin.
x)
1228 ClipStartLeft (line);
1233 if (line.
end.
x < m_clipMin.
x)
1235 ClipStartBottom (line);
1236 if (line.
start.
x < m_clipMin.
x)
1237 ClipStartLeft (line);
1241 ClipStartLeft (line);
1242 if (line.
start.
y < m_clipMin.
y)
1244 ClipEndRight (line);
1245 if (line.
end.
y > m_clipMax.
y)
1247 if (line.
start.
y > m_clipMax.
y)
1248 ClipStartBottom (line);
1249 if (line.
end.
y < m_clipMin.
y)
1255 ClipStartRight (line);
1256 if (line.
start.
y > m_clipMax.
y)
1257 ClipStartBottom (line);
1262 if (line.
end.
y > m_clipMax.
y)
1264 ClipStartBottom (line);
1265 if (line.
start.
x > m_clipMax.
x)
1266 ClipStartRight (line);
1271 if (line.
end.
x > m_clipMax.
x)
1273 ClipStartRight (line);
1274 if (line.
start.
y > m_clipMax.
y)
1275 ClipStartBottom (line);
1280 if (line.
end.
y > m_clipMax.
y)
1282 ClipStartRight (line);
1283 if (line.
start.
y < m_clipMin.
y)
1285 if (line.
end.
y < m_clipMin.
y)
1287 if (line.
start.
y > m_clipMax.
y)
1288 ClipStartBottom (line);
1293 ClipStartTop (line);
1297 ClipStartTop (line);
1298 if (line.
start.
x < m_clipMin.
x)
1304 ClipStartTop (line);
1305 if (line.
start.
x > m_clipMax.
x)
1307 ClipEndRight (line);
1311 ClipStartTop (line);
1312 ClipEndBottom (line);
1316 ClipStartTop (line);
1317 if (line.
start.
x < m_clipMin.
x)
1320 if (line.
end.
y > m_clipMax.
y)
1321 ClipEndBottom (line);
1325 ClipStartTop (line);
1326 if (line.
start.
x > m_clipMax.
x)
1328 ClipEndRight (line);
1329 if (line.
end.
y > m_clipMax.
y)
1330 ClipEndBottom (line);
1335 ClipStartLeft (line);
1336 if (line.
start.
y < m_clipMin.
y)
1337 ClipStartTop (line);
1341 ClipEndRight (line);
1342 if (line.
end.
y < m_clipMin.
y)
1344 ClipStartTop (line);
1345 if (line.
start.
x < m_clipMin.
x)
1346 ClipStartLeft (line);
1350 ClipEndBottom (line);
1351 if (line.
end.
x < m_clipMin.
x)
1353 ClipStartLeft (line);
1354 if (line.
start.
y < m_clipMin.
y)
1355 ClipStartTop (line);
1359 ClipStartLeft (line);
1360 if (line.
start.
y > m_clipMax.
y)
1362 ClipEndRight (line);
1363 if (line.
end.
y < m_clipMin.
y)
1365 if (line.
start.
y < m_clipMin.
y)
1366 ClipStartTop (line);
1367 if (line.
end.
y > m_clipMax.
y)
1368 ClipEndBottom (line);
1373 ClipStartRight (line);
1374 if (line.
start.
y < m_clipMin.
y)
1375 ClipStartTop (line);
1380 if (line.
end.
y < m_clipMin.
y)
1382 ClipStartTop (line);
1383 if (line.
start.
x > m_clipMax.
x)
1384 ClipStartRight (line);
1388 ClipEndBottom (line);
1389 if (line.
end.
x > m_clipMax.
x)
1391 ClipStartRight (line);
1392 if (line.
start.
y < m_clipMin.
y)
1393 ClipStartTop (line);
1398 if (line.
end.
y < m_clipMin.
y)
1400 ClipStartRight (line);
1401 if (line.
start.
y > m_clipMax.
y)
1403 if (line.
end.
y > m_clipMax.
y)
1404 ClipEndBottom (line);
1405 if (line.
start.
y < m_clipMin.
y)
1406 ClipStartTop (line);
1417 double &lineX1,
double &lineY1,
double &lineX2,
double &lineY2)
1419 FastClipping::Vector2 clipMin = { boundsX1, boundsY1}, clipMax = { boundsX2, boundsY2};
1420 FastClipping::Line line = { { lineX1, lineY1 }, { lineX2, lineY2 }, (lineX2-lineX1), (lineY2-lineY1) };
1422 FastClipping clipper (clipMin, clipMax);
1423 clipper.ClipLine (line);
1424 lineX1 = line.start.x;
1425 lineX2 = line.end.x;
1426 lineY1 = line.start.y;
1427 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)
Fatal error handling.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
TAG_BUFFER_INLINE uint32_t ReadU32(void)
void ClipEndTop(Line &line)
void Connect(std::string path, const CallbackBase &cb)
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)
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
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.
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)
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)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.