A Discrete-Event Network Simulator
API
pyviz.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INESC Porto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Gustavo Carneiro <gjc@inescporto.pt>
19  */
20 
21 #include <cstdlib>
22 #include "pyviz.h"
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"
30 #include "ns3/log.h"
31 #include "ns3/abort.h"
32 
33 #include "visual-simulator-impl.h"
34 
35 #include <sstream>
36 
37 NS_LOG_COMPONENT_DEFINE ("PyViz");
38 
39 #define NUM_LAST_PACKETS 10
40 
41 static
42 std::vector<std::string>
43 PathSplit (std::string str)
44 {
45  std::vector<std::string> results;
46  size_t cutAt;
47  while ((cutAt = str.find_first_of ('/')) != str.npos)
48  {
49  if(cutAt > 0)
50  {
51  results.push_back (str.substr (0,cutAt));
52  }
53  str = str.substr (cutAt+1);
54  }
55  if (str.length () > 0)
56  {
57  results.push_back (str);
58  }
59  return results;
60 }
61 
62 
63 namespace ns3 {
64 
65 static PyViz* g_visualizer = NULL;
66 
67 
71 struct PyVizPacketTag : public Tag
72 {
73  static TypeId GetTypeId (void);
74  virtual TypeId GetInstanceTypeId (void) const;
75  virtual uint32_t GetSerializedSize (void) const;
76  virtual void Serialize (TagBuffer buf) const;
77  virtual void Deserialize (TagBuffer buf);
78  virtual void Print (std::ostream &os) const;
79  PyVizPacketTag ();
80 
81  uint32_t m_packetId;
82 };
83 
84 
89 TypeId
91 {
92  static TypeId tid = TypeId ("ns3::PyVizPacketTag")
93  .SetParent<Tag> ()
94  .SetGroupName ("Visualizer")
95  .AddConstructor<PyVizPacketTag> ()
96  ;
97  return tid;
98 }
99 TypeId
101 {
102  return GetTypeId ();
103 }
104 uint32_t
106 {
107  return 4;
108 }
109 void
111 {
112  buf.WriteU32 (m_packetId);
113 }
114 void
116 {
117  m_packetId = buf.ReadU32 ();
118 }
119 void
120 PyVizPacketTag::Print (std::ostream &os) const
121 {
122  os << "PacketId=" << m_packetId;
123 }
125  : Tag ()
126 {
127 }
128 
129 
130 
132 {
134  NS_ASSERT (g_visualizer == NULL);
135  g_visualizer = this;
136 
137  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
139 
140  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
142 
143  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacTx",
145 
146  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
148 
149  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacPromiscRx",
151 
152  Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Drop",
154 
155  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop",
157 
158  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
160 
161  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacRx",
163 
164  // WiMax
165  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
167 
168  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
170 
171  // LTE
172  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
174 
175  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
177 }
178 
179 void
180 PyViz::RegisterCsmaLikeDevice (std::string const &deviceTypeName)
181 {
182  TypeId::LookupByName (deviceTypeName); // this will assert if the type name is invalid
183 
184  std::ostringstream sstream;
185  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/MacTx";
186  Config::Connect (sstream.str (), MakeCallback (&PyViz::TraceNetDevTxCsma, this));
187 
188  sstream.str ("");
189  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/Rx";
190  Config::Connect (sstream.str (), MakeCallback (&PyViz::TraceNetDevRxCsma, this));
191 
192  sstream.str ("");
193  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/PromiscRx";
195 }
196 
197 void
198 PyViz::RegisterWifiLikeDevice (std::string const &deviceTypeName)
199 {
200  TypeId::LookupByName (deviceTypeName); // this will assert if the type name is invalid
201 
202  std::ostringstream sstream;
203  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/Tx";
204  Config::Connect (sstream.str (), MakeCallback (&PyViz::TraceNetDevTxWifi, this));
205 
206  sstream.str ("");
207  sstream <<"/NodeList/*/DeviceList/*/$" << deviceTypeName << "/Rx";
208  Config::Connect (sstream.str (), MakeCallback (&PyViz::TraceNetDevRxWifi, this));
209 }
210 
211 void
212 PyViz::RegisterPointToPointLikeDevice (std::string const &deviceTypeName)
213 {
214  TypeId::LookupByName (deviceTypeName); // this will assert if the type name is invalid
215 
216  std::ostringstream sstream;
217  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/TxQueue/Dequeue";
219 
220  sstream.str ("");
221  sstream << "/NodeList/*/DeviceList/*/$" << deviceTypeName << "/Rx";
223 }
224 
225 void
227 {
228  NS_LOG_DEBUG (" SetPacketCaptureOptions " << nodeId
229  << " PacketCaptureOptions (headers size = " << options.headers.size ()
230  << " mode = " << options.mode << " numLastPackets = " << options.numLastPackets
231  << ")");
232  m_packetCaptureOptions[nodeId] = options;
233 }
234 
235 void
236 PyViz::RegisterDropTracePath (std::string const &tracePath)
237 {
239 }
240 
242 {
244 
245  NS_ASSERT (g_visualizer == this);
246  g_visualizer = NULL;
247 }
248 
249 void PyViz::DoPause (std::string const &message)
250 {
251  m_pauseMessages.push_back (message);
252  m_stop = true;
253  NS_LOG_LOGIC (Simulator::Now ().GetSeconds () << ": Have "
254  << g_visualizer->m_pauseMessages.size () << " pause messages");
255 }
256 
257 void PyViz::Pause (std::string const &message)
258 {
260  g_visualizer->DoPause (message);
261 }
262 
263 std::vector<std::string>
265 {
266  NS_LOG_LOGIC (Simulator::Now ().GetSeconds () << ": GetPauseMessages: have "
267  << g_visualizer->m_pauseMessages.size () << " pause messages");
268  return m_pauseMessages;
269 }
270 
271 
272 void
274 {
276  if (m_runUntil <= Simulator::Now ())
277  {
278  Simulator::Stop (Seconds (0)); // Stop right now
279  m_stop = true;
280  }
281 }
282 
283 void
285 {
286  NS_LOG_LOGIC ("SimulatorRunUntil " << time << " (now is " << Simulator::Now () << ")");
287 
288  m_pauseMessages.clear ();
289  m_transmissionSamples.clear ();
290  m_packetDrops.clear ();
291 
292  Time expirationTime = Simulator::Now () - Seconds (10);
293 
294  // Clear very old transmission records
295  for (std::map<TxRecordKey, TxRecordValue>::iterator iter = m_txRecords.begin ();
296  iter != m_txRecords.end ();)
297  {
298  if (iter->second.time < expirationTime)
299  {
300  m_txRecords.erase (iter++);
301  }
302  else
303  {
304  iter++;
305  }
306  }
307 
308  // Clear very old packets of interest
309  for (std::map<uint32_t, Time>::iterator iter = m_packetsOfInterest.begin ();
310  iter != m_packetsOfInterest.end ();)
311  {
312  if (iter->second < expirationTime)
313  {
314  m_packetsOfInterest.erase (iter++);
315  }
316  else
317  {
318  iter++;
319  }
320  }
321 
322  if (Simulator::Now () >= time)
323  {
324  return;
325  }
326  // Schedule a dummy callback function for the target time, to make
327  // sure we stop at the right time. Otherwise, simulations with few
328  // events just appear to "jump" big chunks of time.
329  NS_LOG_LOGIC ("Schedule dummy callback to be called in " << (time - Simulator::Now ()));
330  m_runUntil = time;
331  m_stop = false;
333 
335  Ptr<VisualSimulatorImpl> visualImpl = DynamicCast<VisualSimulatorImpl> (impl);
336  if (visualImpl)
337  {
338  visualImpl->RunRealSimulator ();
339  }
340  else
341  {
342  impl->Run ();
343  }
344 }
345 
347 {
348  if (this->transmitter < other.transmitter)
349  {
350  return true;
351  }
352  if (this->transmitter != other.transmitter)
353  {
354  return false;
355  }
356  if (this->receiver < other.receiver)
357  {
358  return true;
359  }
360  if (this->receiver != other.receiver)
361  {
362  return false;
363  }
364  if (this->channel < other.channel)
365  {
366  return true;
367  }
368  else
369  {
370  return false;
371  }
372 }
373 
375 {
376  bool retval = (transmitter == other.transmitter) &&
377  (receiver == other.receiver) &&
378  (channel == other.channel);
379  return retval;
380 }
381 
382 
384 PyViz::FindNetDeviceStatistics (int node, int interface)
385 {
386  std::map<uint32_t, std::vector<NetDeviceStatistics> >::iterator nodeStatsIter = m_nodesStatistics.find (node);
387  std::vector<NetDeviceStatistics> *stats;
388  if (nodeStatsIter == m_nodesStatistics.end ())
389  {
390  stats = &m_nodesStatistics[node];
391  stats->resize (NodeList::GetNode (node)->GetNDevices ());
392  }
393  else
394  {
395  stats = &(nodeStatsIter->second);
396  }
397  NetDeviceStatistics &devStats = (*stats)[interface];
398  return devStats;
399 }
400 
401 bool PyViz::GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const
402 {
403  std::map<uint32_t, PacketCaptureOptions>::const_iterator iter = m_packetCaptureOptions.find (nodeId);
404  if (iter == m_packetCaptureOptions.end ())
405  {
406  return false;
407  }
408  else
409  {
410  *outOptions = &iter->second;
411  return true;
412  }
413 }
414 
416 {
417  switch (options.mode)
418  {
420  return false;
421 
423  {
424  PacketMetadata::ItemIterator metadataIterator = packet->BeginItem ();
425  while (metadataIterator.HasNext ())
426  {
427  PacketMetadata::Item item = metadataIterator.Next ();
428  if (options.headers.find (item.tid) != options.headers.end ())
429  {
430  return true;
431  }
432  }
433  return false;
434  }
435 
437  {
438  std::set<TypeId> missingHeaders (options.headers);
439  PacketMetadata::ItemIterator metadataIterator = packet->BeginItem ();
440  while (metadataIterator.HasNext ())
441  {
442  PacketMetadata::Item item = metadataIterator.Next ();
443  std::set<TypeId>::iterator missingIter = missingHeaders.find (item.tid);
444  if (missingIter != missingHeaders.end ())
445  {
446  missingHeaders.erase (missingIter);
447  }
448  }
449  if (missingHeaders.size () == 0)
450  {
451  return true;
452  }
453  else
454  {
455  return false;
456  }
457  }
458 
459  default:
460  NS_FATAL_ERROR ("should not be reached");
461  return false;
462  }
463 }
464 
465 void
466 PyViz::TraceDevQueueDrop (std::string context, Ptr<const Packet> packet)
467 {
468  NS_LOG_FUNCTION (context << packet->GetUid ());
469  std::vector<std::string> splitPath = PathSplit (context);
470  int nodeIndex = std::atoi (splitPath[1].c_str ());
471  Ptr<Node> node = NodeList::GetNode (nodeIndex);
472 
473  if (m_nodesOfInterest.find (nodeIndex) == m_nodesOfInterest.end ())
474  {
475  // if the transmitting node is not "of interest", we still
476  // record the transmission if it is a packet of interest.
477  if (m_packetsOfInterest.find (packet->GetUid ()) == m_packetsOfInterest.end ())
478  {
479  NS_LOG_DEBUG ("Packet " << packet->GetUid () << " is not of interest");
480  return;
481  }
482  }
483 
484  // ---- "last packets"
485  const PacketCaptureOptions *captureOptions;
486  if (GetPacketCaptureOptions (nodeIndex, &captureOptions) && FilterPacket (packet, *captureOptions))
487  {
488  LastPacketsSample &last = m_lastPackets[nodeIndex];
489  PacketSample lastPacket;
490  lastPacket.time = Simulator::Now ();
491  lastPacket.packet = packet->Copy ();
492  lastPacket.device = NULL;
493  last.lastDroppedPackets.push_back (lastPacket);
494  while (last.lastDroppedPackets.size () > captureOptions->numLastPackets)
495  {
496  last.lastDroppedPackets.erase (last.lastDroppedPackets.begin ());
497  }
498  }
499 
500  std::map<Ptr<Node>, uint32_t>::iterator iter = m_packetDrops.find (node);
501  if (iter == m_packetDrops.end ())
502  {
503  m_packetDrops[node] = packet->GetSize ();
504  }
505  else
506  {
507  iter->second += packet->GetSize ();
508  }
509 }
510 
511 void
512 PyViz::TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet,
513  ns3::Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> dummy_ipv4, uint32_t interface)
514 {
515  Ptr<Packet> packetCopy = packet->Copy ();
516  packetCopy->AddHeader (hdr);
517  TraceDevQueueDrop (context, packetCopy);
518 }
519 
520 
521 // --------- TX device tracing -------------------
522 
523 void
524 PyViz::TraceNetDevTxCommon (std::string const &context, Ptr<const Packet> packet,
525  Mac48Address const &destinationAddress)
526 {
527  NS_LOG_FUNCTION (context << packet->GetUid () << *packet);
528 
529  std::vector<std::string> splitPath = PathSplit (context);
530  int nodeIndex = std::atoi (splitPath[1].c_str ());
531  int devIndex = std::atoi (splitPath[3].c_str ());
532  Ptr<Node> node = NodeList::GetNode (nodeIndex);
533  Ptr<NetDevice> device = node->GetDevice (devIndex);
534 
535  // ---- statistics
536  NetDeviceStatistics &stats = FindNetDeviceStatistics (nodeIndex, devIndex);
537  ++stats.transmittedPackets;
538  stats.transmittedBytes += packet->GetSize ();
539 
540  // ---- "last packets"
541  const PacketCaptureOptions *captureOptions;
542  if (GetPacketCaptureOptions (nodeIndex, &captureOptions) && FilterPacket (packet, *captureOptions))
543  {
544  LastPacketsSample &last = m_lastPackets[nodeIndex];
545  TxPacketSample lastPacket;
546  lastPacket.time = Simulator::Now ();
547  lastPacket.packet = packet->Copy ();
548  lastPacket.device = device;
549  lastPacket.to = destinationAddress;
550  last.lastTransmittedPackets.push_back (lastPacket);
551  while (last.lastTransmittedPackets.size () > captureOptions->numLastPackets)
552  {
553  last.lastTransmittedPackets.erase (last.lastTransmittedPackets.begin ());
554  }
555  }
556 
557  // ---- transmissions records
558 
559  if (m_nodesOfInterest.find (nodeIndex) == m_nodesOfInterest.end ())
560  {
561  // if the transmitting node is not "of interest", we still
562  // record the transmission if it is a packet of interest.
563  if (m_packetsOfInterest.find (packet->GetUid ()) == m_packetsOfInterest.end ())
564  {
565  NS_LOG_DEBUG ("Packet " << packet->GetUid () << " is not of interest");
566  return;
567  }
568  }
569  else
570  {
571  // We will follow this packet throughout the network.
572  m_packetsOfInterest[packet->GetUid ()] = Simulator::Now ();
573  }
574 
575  TxRecordValue record = { Simulator::Now (), node, false };
576  if (destinationAddress == device->GetBroadcast ())
577  {
578  record.isBroadcast = true;
579  }
580 
581  m_txRecords[TxRecordKey (device->GetChannel (), packet->GetUid ())] = record;
582 
583  PyVizPacketTag tag;
584  //packet->RemovePacketTag (tag);
585  tag.m_packetId = packet->GetUid ();
586  packet->AddByteTag (tag);
587 }
588 
589 void
590 PyViz::TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet)
591 {
592  NS_LOG_FUNCTION (context << packet->GetUid () << *packet);
593 
594  /*
595  * To DS From DS Address 1 Address 2 Address 3 Address 4
596  *----------------------------------------------------------------------
597  * 0 0 Destination Source BSSID N/A
598  * 0 1 Destination BSSID Source N/A
599  * 1 0 BSSID Source Destination N/A
600  * 1 1 Receiver Transmitter Destination Source
601  */
602  WifiMacHeader hdr;
603  NS_ABORT_IF (packet->PeekHeader (hdr) == 0);
604  Mac48Address destinationAddress;
605  if (hdr.IsToDs () && !hdr.IsFromDs ())
606  {
607  destinationAddress = hdr.GetAddr3 ();
608  }
609  else if (!hdr.IsToDs () && hdr.IsFromDs ())
610  {
611  destinationAddress = hdr.GetAddr1 ();
612  }
613  else if (!hdr.IsToDs () && !hdr.IsFromDs ())
614  {
615  destinationAddress = hdr.GetAddr1 ();
616  }
617  else
618  {
619  destinationAddress = hdr.GetAddr3 ();
620  }
621  TraceNetDevTxCommon (context, packet, destinationAddress);
622 }
623 
624 
625 void
626 PyViz::TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet)
627 {
628  EthernetHeader ethernetHeader;
629  NS_ABORT_IF (packet->PeekHeader (ethernetHeader) == 0);
630  TraceNetDevTxCommon (context, packet, ethernetHeader.GetDestination ());
631 }
632 
633 void
635 {
636  TraceNetDevTxCommon (context, packet, Mac48Address ());
637 }
638 
639 
640 
641 
642 // --------- RX device tracing -------------------
643 
644 void
645 PyViz::TraceNetDevRxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &from)
646 {
647  uint32_t uid;
648  PyVizPacketTag tag;
649  if (packet->FindFirstMatchingByteTag (tag))
650  {
651  uid = tag.m_packetId;
652  }
653  else
654  {
655  //NS_ASSERT (0);
656  NS_LOG_WARN ("Packet has no byte tag; wimax link?");
657  uid = packet->GetUid ();
658  }
659 
660  NS_LOG_FUNCTION (context << uid);
661  std::vector<std::string> splitPath = PathSplit (context);
662  int nodeIndex = std::atoi (splitPath[1].c_str ());
663  int devIndex = std::atoi (splitPath[3].c_str ());
664 
665  // ---- statistics
666  NetDeviceStatistics &stats = FindNetDeviceStatistics (nodeIndex, devIndex);
667  ++stats.receivedPackets;
668  stats.receivedBytes += packet->GetSize ();
669 
670  Ptr<Node> node = NodeList::GetNode (nodeIndex);
671  Ptr<NetDevice> device = node->GetDevice (devIndex);
672 
673  // ---- "last packets"
674  const PacketCaptureOptions *captureOptions;
675  if (GetPacketCaptureOptions (nodeIndex, &captureOptions) && FilterPacket (packet, *captureOptions))
676  {
677  LastPacketsSample &last = m_lastPackets[nodeIndex];
678  RxPacketSample lastPacket;
679  lastPacket.time = Simulator::Now ();
680  lastPacket.packet = packet->Copy ();
681  lastPacket.device = device;
682  lastPacket.from = from;
683  last.lastReceivedPackets.push_back (lastPacket);
684  while (last.lastReceivedPackets.size () > captureOptions->numLastPackets)
685  {
686  last.lastReceivedPackets.erase (last.lastReceivedPackets.begin ());
687  }
688  }
689 
690  // ---- transmissions
691  if (m_packetsOfInterest.find (uid) == m_packetsOfInterest.end ())
692  {
693  NS_LOG_DEBUG ("RX Packet " << uid << " is not of interest");
694  return;
695  }
696 
697  Ptr<Channel> channel = device->GetChannel ();
698 
699  std::map<TxRecordKey, TxRecordValue>::iterator recordIter =
700  m_txRecords.find (TxRecordKey (channel, uid));
701 
702  if (recordIter == m_txRecords.end ())
703  {
704  NS_LOG_DEBUG ("RX Packet " << uid << " was not transmitted?!");
705  return;
706  }
707 
708  TxRecordValue &record = recordIter->second;
709 
710  if (record.srcNode == node)
711  {
712  NS_LOG_WARN ("Node " << node->GetId () << " receiving back the same packet (UID=" << uid
713  << ") it had previously transmitted, on the same channel!");
714  return;
715  }
716 
717  TransmissionSampleKey key = { record.srcNode, node, channel };
718 
719 #ifdef NS3_LOG_ENABLE
720  NS_LOG_DEBUG ("m_transmissionSamples begin:");
721  if (g_log.IsEnabled (ns3::LOG_DEBUG))
722  {
723  for (std::map<TransmissionSampleKey,TransmissionSampleValue>::const_iterator iter
724  = m_transmissionSamples.begin (); iter != m_transmissionSamples.end (); iter++)
725  {
726  NS_LOG_DEBUG (iter->first.transmitter<<"/"<<iter->first.transmitter->GetId () << ", "
727  << iter->first.receiver<<"/"<<iter->first.receiver->GetId ()
728  << ", " << iter->first.channel << " => " << iter->second.bytes << " (@ " << &iter->second << ")");
729  }
730  }
731  NS_LOG_DEBUG ("m_transmissionSamples end.");
732 #endif
733 
734  std::map<TransmissionSampleKey,TransmissionSampleValue>::iterator
735  iter = m_transmissionSamples.find (key);
736 
737  if (iter == m_transmissionSamples.end ())
738  {
739  TransmissionSampleValue sample = { packet->GetSize () };
740  NS_LOG_DEBUG ("RX: from " << key.transmitter<<"/"<<key.transmitter->GetId () << " to "
741  << key.receiver<<"/"<<key.receiver->GetId ()
742  << " channel " << channel << ": " << packet->GetSize ()
743  << " bytes more. => new sample with " << packet->GetSize () << " bytes.");
744  m_transmissionSamples[key] = sample;
745  }
746  else
747  {
748  TransmissionSampleValue &sample = iter->second;
749  NS_LOG_DEBUG ("RX: from " << key.transmitter<<"/"<<key.transmitter->GetId () << " to "
750  << key.receiver<<"/"<<key.receiver->GetId ()
751  << " channel " << channel << ": " << packet->GetSize ()
752  << " bytes more. => sample " << &sample << " with bytes " << sample.bytes);
753 
754  sample.bytes += packet->GetSize ();
755  }
756 }
757 
758 void
759 PyViz::TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet)
760 {
761  NS_LOG_FUNCTION (context << packet->GetUid ());
762 
763 
764  /*
765  * To DS From DS Address 1 Address 2 Address 3 Address 4
766  *----------------------------------------------------------------------
767  * 0 0 Destination Source BSSID N/A
768  * 0 1 Destination BSSID Source N/A
769  * 1 0 BSSID Source Destination N/A
770  * 1 1 Receiver Transmitter Destination Source
771  */
772  WifiMacHeader hdr;
773  NS_ABORT_IF (packet->PeekHeader (hdr) == 0);
774  Mac48Address sourceAddress;
775  if (hdr.IsToDs () && !hdr.IsFromDs ())
776  {
777  sourceAddress = hdr.GetAddr2 ();
778  }
779  else if (!hdr.IsToDs () && hdr.IsFromDs ())
780  {
781  sourceAddress = hdr.GetAddr3 ();
782  }
783  else if (!hdr.IsToDs () && !hdr.IsFromDs ())
784  {
785  sourceAddress = hdr.GetAddr2 ();
786  }
787  else
788  {
789  sourceAddress = hdr.GetAddr4 ();
790  }
791 
792  TraceNetDevRxCommon (context, packet, sourceAddress);
793 }
794 
795 
796 
797 void
798 PyViz::TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet)
799 {
800  EthernetHeader ethernetHeader;
801  NS_ABORT_IF (packet->PeekHeader (ethernetHeader) == 0);
802  TraceNetDevRxCommon (context, packet, ethernetHeader.GetSource ());
803 }
804 
805 void
807 {
808  TraceNetDevRxCommon (context, packet, Mac48Address ());
809 }
810 
811 void
813 {
814  EthernetHeader ethernetHeader;
815  NS_ABORT_IF (packet->PeekHeader (ethernetHeader) == 0);
816 
818 
819  // Other packet types are already being received by
820  // TraceNetDevRxCsma; we don't want to receive them twice.
821  if (packetType == NetDevice::PACKET_OTHERHOST)
822  {
823  TraceNetDevRxCommon (context, packet, ethernetHeader.GetDestination ());
824  }
825 }
826 
827 void
828 PyViz::TraceNetDevTxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &destination)
829 {
830  NS_LOG_FUNCTION (context);
831  TraceNetDevTxCommon (context, packet, destination);
832 }
833 
834 void
835 PyViz::TraceNetDevRxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &source)
836 {
837  NS_LOG_FUNCTION (context);
838  TraceNetDevRxCommon (context, packet, source);
839 }
840 
841 void
842 PyViz::TraceNetDevTxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &destination)
843 {
844  NS_LOG_FUNCTION (context);
845  TraceNetDevTxCommon (context, packet, destination);
846 }
847 
848 void
849 PyViz::TraceNetDevRxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &source)
850 {
851  NS_LOG_FUNCTION (context);
852  TraceNetDevRxCommon (context, packet, source);
853 }
854 
855 // ---------------------
856 
859 {
860  NS_LOG_DEBUG ("GetTransmissionSamples BEGIN");
862  for (std::map<TransmissionSampleKey, TransmissionSampleValue>::const_iterator
863  iter = m_transmissionSamples.begin ();
864  iter != m_transmissionSamples.end ();
865  iter++)
866  {
867  TransmissionSample sample;
868  sample.transmitter = iter->first.transmitter;
869  sample.receiver = iter->first.receiver;
870  sample.channel = iter->first.channel;
871  sample.bytes = iter->second.bytes;
872  NS_LOG_DEBUG ("from " << sample.transmitter->GetId () << " to " << sample.receiver->GetId ()
873  << ": " << sample.bytes << " bytes.");
874  list.push_back (sample);
875  }
876  NS_LOG_DEBUG ("GetTransmissionSamples END");
877  return list;
878 }
879 
882 {
883  NS_LOG_DEBUG ("GetPacketDropSamples BEGIN");
885  for (std::map<Ptr<Node>, uint32_t>::const_iterator
886  iter = m_packetDrops.begin ();
887  iter != m_packetDrops.end ();
888  iter++)
889  {
890  PacketDropSample sample;
891  sample.transmitter = iter->first;
892  sample.bytes = iter->second;
893  NS_LOG_DEBUG ("in " << sample.transmitter->GetId ()
894  << ": " << sample.bytes << " bytes dropped.");
895  list.push_back (sample);
896  }
897  NS_LOG_DEBUG ("GetPacketDropSamples END");
898  return list;
899 }
900 
901 void
902 PyViz::SetNodesOfInterest (std::set<uint32_t> nodes)
903 {
905 }
906 
907 std::vector<PyViz::NodeStatistics>
909 {
910  std::vector<PyViz::NodeStatistics> retval;
911  for (std::map<uint32_t, std::vector<NetDeviceStatistics> >::const_iterator iter = m_nodesStatistics.begin ();
912  iter != m_nodesStatistics.end (); iter++)
913  {
914  NodeStatistics stats = { iter->first, iter->second };
915  retval.push_back (stats);
916  }
917  return retval;
918 }
919 
920 
922 PyViz::GetLastPackets (uint32_t nodeId) const
923 {
924  NS_LOG_DEBUG ("GetLastPackets: " << nodeId);
925 
926  std::map<uint32_t, LastPacketsSample>::const_iterator
927  iter = m_lastPackets.find (nodeId);
928  if (iter != m_lastPackets.end ())
929  {
930  return iter->second;
931  }
932  else
933  {
934  return LastPacketsSample ();
935  }
936 }
937 
938 
939 
940 
941 
942 
943 namespace
944 {
947 {
948 public:
950  struct Vector2
951  {
952  double x;
953  double y;
954  };
955 
958 
960  struct Line
961  {
964  double dx;
965  double dy;
966  };
967 
968 private:
969 
974  void ClipStartTop (Line &line)
975  {
976  line.start.x += line.dx * (m_clipMin.y - line.start.y) / line.dy;
977  line.start.y = m_clipMin.y;
978  }
979 
984  void ClipStartBottom (Line &line)
985  {
986  line.start.x += line.dx * (m_clipMax.y - line.start.y) / line.dy;
987  line.start.y = m_clipMax.y;
988  }
989 
994  void ClipStartRight (Line &line)
995  {
996  line.start.y += line.dy * (m_clipMax.x - line.start.x) / line.dx;
997  line.start.x = m_clipMax.x;
998  }
999 
1004  void ClipStartLeft (Line &line)
1005  {
1006  line.start.y += line.dy * (m_clipMin.x - line.start.x) / line.dx;
1007  line.start.x = m_clipMin.x;
1008  }
1009 
1014  void ClipEndTop (Line &line)
1015  {
1016  line.end.x += line.dx * (m_clipMin.y - line.end.y) / line.dy;
1017  line.end.y = m_clipMin.y;
1018  }
1019 
1024  void ClipEndBottom (Line &line) {
1025  line.end.x += line.dx * (m_clipMax.y - line.end.y) / line.dy;
1026  line.end.y = m_clipMax.y;
1027  }
1028 
1033  void ClipEndRight (Line &line)
1034  {
1035  line.end.y += line.dy * (m_clipMax.x - line.end.x) / line.dx;
1036  line.end.x = m_clipMax.x;
1037  }
1038 
1043  void ClipEndLeft (Line &line)
1044  {
1045  line.end.y += line.dy * (m_clipMin.x - line.end.x) / line.dx;
1046  line.end.x = m_clipMin.x;
1047  }
1048 
1049 public:
1056  FastClipping (Vector2 clipMin, Vector2 clipMax)
1057  : m_clipMin (clipMin), m_clipMax (clipMax)
1058  {
1059  }
1060 
1061 
1067  bool ClipLine (Line &line)
1068  {
1069  uint8_t lineCode = 0;
1070 
1071  if (line.end.y < m_clipMin.y)
1072  lineCode |= 8;
1073  else if (line.end.y > m_clipMax.y)
1074  lineCode |= 4;
1075 
1076  if (line.end.x > m_clipMax.x)
1077  lineCode |= 2;
1078  else if (line.end.x < m_clipMin.x)
1079  lineCode |= 1;
1080 
1081  if (line.start.y < m_clipMin.y)
1082  lineCode |= 128;
1083  else if (line.start.y > m_clipMax.y)
1084  lineCode |= 64;
1085 
1086  if (line.start.x > m_clipMax.x)
1087  lineCode |= 32;
1088  else if (line.start.x < m_clipMin.x)
1089  lineCode |= 16;
1090 
1091  // 9 - 8 - A
1092  // | | |
1093  // 1 - 0 - 2
1094  // | | |
1095  // 5 - 4 - 6
1096  switch (lineCode)
1097  {
1098  // center
1099  case 0x00:
1100  return true;
1101 
1102  case 0x01:
1103  ClipEndLeft (line);
1104  return true;
1105 
1106  case 0x02:
1107  ClipEndRight (line);
1108  return true;
1109 
1110  case 0x04:
1111  ClipEndBottom (line);
1112  return true;
1113 
1114  case 0x05:
1115  ClipEndLeft (line);
1116  if (line.end.y > m_clipMax.y)
1117  ClipEndBottom (line);
1118  return true;
1119 
1120  case 0x06:
1121  ClipEndRight (line);
1122  if (line.end.y > m_clipMax.y)
1123  ClipEndBottom (line);
1124  return true;
1125 
1126  case 0x08:
1127  ClipEndTop (line);
1128  return true;
1129 
1130  case 0x09:
1131  ClipEndLeft (line);
1132  if (line.end.y < m_clipMin.y)
1133  ClipEndTop (line);
1134  return true;
1135 
1136  case 0x0A:
1137  ClipEndRight (line);
1138  if (line.end.y < m_clipMin.y)
1139  ClipEndTop (line);
1140  return true;
1141 
1142  // left
1143  case 0x10:
1144  ClipStartLeft (line);
1145  return true;
1146 
1147  case 0x12:
1148  ClipStartLeft (line);
1149  ClipEndRight (line);
1150  return true;
1151 
1152  case 0x14:
1153  ClipStartLeft (line);
1154  if (line.start.y > m_clipMax.y)
1155  return false;
1156  ClipEndBottom (line);
1157  return true;
1158 
1159  case 0x16:
1160  ClipStartLeft (line);
1161  if (line.start.y > m_clipMax.y)
1162  return false;
1163  ClipEndBottom (line);
1164  if (line.end.x > m_clipMax.x)
1165  ClipEndRight (line);
1166  return true;
1167 
1168  case 0x18:
1169  ClipStartLeft (line);
1170  if (line.start.y < m_clipMin.y)
1171  return false;
1172  ClipEndTop (line);
1173  return true;
1174 
1175  case 0x1A:
1176  ClipStartLeft (line);
1177  if (line.start.y < m_clipMin.y)
1178  return false;
1179  ClipEndTop (line);
1180  if (line.end.x > m_clipMax.x)
1181  ClipEndRight (line);
1182  return true;
1183 
1184  // right
1185  case 0x20:
1186  ClipStartRight (line);
1187  return true;
1188 
1189  case 0x21:
1190  ClipStartRight (line);
1191  ClipEndLeft (line);
1192  return true;
1193 
1194  case 0x24:
1195  ClipStartRight (line);
1196  if (line.start.y > m_clipMax.y)
1197  return false;
1198  ClipEndBottom (line);
1199  return true;
1200 
1201  case 0x25:
1202  ClipStartRight (line);
1203  if (line.start.y > m_clipMax.y)
1204  return false;
1205  ClipEndBottom (line);
1206  if (line.end.x < m_clipMin.x)
1207  ClipEndLeft (line);
1208  return true;
1209 
1210  case 0x28:
1211  ClipStartRight (line);
1212  if (line.start.y < m_clipMin.y)
1213  return false;
1214  ClipEndTop (line);
1215  return true;
1216 
1217  case 0x29:
1218  ClipStartRight (line);
1219  if (line.start.y < m_clipMin.y)
1220  return false;
1221  ClipEndTop (line);
1222  if (line.end.x < m_clipMin.x)
1223  ClipEndLeft (line);
1224  return true;
1225 
1226  // bottom
1227  case 0x40:
1228  ClipStartBottom (line);
1229  return true;
1230 
1231  case 0x41:
1232  ClipStartBottom (line);
1233  if (line.start.x < m_clipMin.x)
1234  return false;
1235  ClipEndLeft (line);
1236  if (line.end.y > m_clipMax.y)
1237  ClipEndBottom (line);
1238  return true;
1239 
1240  case 0x42:
1241  ClipStartBottom (line);
1242  if (line.start.x > m_clipMax.x)
1243  return false;
1244  ClipEndRight (line);
1245  return true;
1246 
1247  case 0x48:
1248  ClipStartBottom (line);
1249  ClipEndTop (line);
1250  return true;
1251 
1252  case 0x49:
1253  ClipStartBottom (line);
1254  if (line.start.x < m_clipMin.x)
1255  return false;
1256  ClipEndLeft (line);
1257  if (line.end.y < m_clipMin.y)
1258  ClipEndTop (line);
1259  return true;
1260 
1261  case 0x4A:
1262  ClipStartBottom (line);
1263  if (line.start.x > m_clipMax.x)
1264  return false;
1265  ClipEndRight (line);
1266  if (line.end.y < m_clipMin.y)
1267  ClipEndTop (line);
1268  return true;
1269 
1270  // bottom-left
1271  case 0x50:
1272  ClipStartLeft (line);
1273  if (line.start.y > m_clipMax.y)
1274  ClipStartBottom (line);
1275  return true;
1276 
1277  case 0x52:
1278  ClipEndRight (line);
1279  if (line.end.y > m_clipMax.y)
1280  return false;
1281  ClipStartBottom (line);
1282  if (line.start.x < m_clipMin.x)
1283  ClipStartLeft (line);
1284  return true;
1285 
1286  case 0x58:
1287  ClipEndTop (line);
1288  if (line.end.x < m_clipMin.x)
1289  return false;
1290  ClipStartBottom (line);
1291  if (line.start.x < m_clipMin.x)
1292  ClipStartLeft (line);
1293  return true;
1294 
1295  case 0x5A:
1296  ClipStartLeft (line);
1297  if (line.start.y < m_clipMin.y)
1298  return false;
1299  ClipEndRight (line);
1300  if (line.end.y > m_clipMax.y)
1301  return false;
1302  if (line.start.y > m_clipMax.y)
1303  ClipStartBottom (line);
1304  if (line.end.y < m_clipMin.y)
1305  ClipEndTop (line);
1306  return true;
1307 
1308  // bottom-right
1309  case 0x60:
1310  ClipStartRight (line);
1311  if (line.start.y > m_clipMax.y)
1312  ClipStartBottom (line);
1313  return true;
1314 
1315  case 0x61:
1316  ClipEndLeft (line);
1317  if (line.end.y > m_clipMax.y)
1318  return false;
1319  ClipStartBottom (line);
1320  if (line.start.x > m_clipMax.x)
1321  ClipStartRight (line);
1322  return true;
1323 
1324  case 0x68:
1325  ClipEndTop (line);
1326  if (line.end.x > m_clipMax.x)
1327  return false;
1328  ClipStartRight (line);
1329  if (line.start.y > m_clipMax.y)
1330  ClipStartBottom (line);
1331  return true;
1332 
1333  case 0x69:
1334  ClipEndLeft (line);
1335  if (line.end.y > m_clipMax.y)
1336  return false;
1337  ClipStartRight (line);
1338  if (line.start.y < m_clipMin.y)
1339  return false;
1340  if (line.end.y < m_clipMin.y)
1341  ClipEndTop (line);
1342  if (line.start.y > m_clipMax.y)
1343  ClipStartBottom (line);
1344  return true;
1345 
1346  // top
1347  case 0x80:
1348  ClipStartTop (line);
1349  return true;
1350 
1351  case 0x81:
1352  ClipStartTop (line);
1353  if (line.start.x < m_clipMin.x)
1354  return false;
1355  ClipEndLeft (line);
1356  return true;
1357 
1358  case 0x82:
1359  ClipStartTop (line);
1360  if (line.start.x > m_clipMax.x)
1361  return false;
1362  ClipEndRight (line);
1363  return true;
1364 
1365  case 0x84:
1366  ClipStartTop (line);
1367  ClipEndBottom (line);
1368  return true;
1369 
1370  case 0x85:
1371  ClipStartTop (line);
1372  if (line.start.x < m_clipMin.x)
1373  return false;
1374  ClipEndLeft (line);
1375  if (line.end.y > m_clipMax.y)
1376  ClipEndBottom (line);
1377  return true;
1378 
1379  case 0x86:
1380  ClipStartTop (line);
1381  if (line.start.x > m_clipMax.x)
1382  return false;
1383  ClipEndRight (line);
1384  if (line.end.y > m_clipMax.y)
1385  ClipEndBottom (line);
1386  return true;
1387 
1388  // top-left
1389  case 0x90:
1390  ClipStartLeft (line);
1391  if (line.start.y < m_clipMin.y)
1392  ClipStartTop (line);
1393  return true;
1394 
1395  case 0x92:
1396  ClipEndRight (line);
1397  if (line.end.y < m_clipMin.y)
1398  return false;
1399  ClipStartTop (line);
1400  if (line.start.x < m_clipMin.x)
1401  ClipStartLeft (line);
1402  return true;
1403 
1404  case 0x94:
1405  ClipEndBottom (line);
1406  if (line.end.x < m_clipMin.x)
1407  return false;
1408  ClipStartLeft (line);
1409  if (line.start.y < m_clipMin.y)
1410  ClipStartTop (line);
1411  return true;
1412 
1413  case 0x96:
1414  ClipStartLeft (line);
1415  if (line.start.y > m_clipMax.y)
1416  return false;
1417  ClipEndRight (line);
1418  if (line.end.y < m_clipMin.y)
1419  return false;
1420  if (line.start.y < m_clipMin.y)
1421  ClipStartTop (line);
1422  if (line.end.y > m_clipMax.y)
1423  ClipEndBottom (line);
1424  return true;
1425 
1426  // top-right
1427  case 0xA0:
1428  ClipStartRight (line);
1429  if (line.start.y < m_clipMin.y)
1430  ClipStartTop (line);
1431  return true;
1432 
1433  case 0xA1:
1434  ClipEndLeft (line);
1435  if (line.end.y < m_clipMin.y)
1436  return false;
1437  ClipStartTop (line);
1438  if (line.start.x > m_clipMax.x)
1439  ClipStartRight (line);
1440  return true;
1441 
1442  case 0xA4:
1443  ClipEndBottom (line);
1444  if (line.end.x > m_clipMax.x)
1445  return false;
1446  ClipStartRight (line);
1447  if (line.start.y < m_clipMin.y)
1448  ClipStartTop (line);
1449  return true;
1450 
1451  case 0xA5:
1452  ClipEndLeft (line);
1453  if (line.end.y < m_clipMin.y)
1454  return false;
1455  ClipStartRight (line);
1456  if (line.start.y > m_clipMax.y)
1457  return false;
1458  if (line.end.y > m_clipMax.y)
1459  ClipEndBottom (line);
1460  if (line.start.y < m_clipMin.y)
1461  ClipStartTop (line);
1462  return true;
1463  }
1464 
1465  return false;
1466  }
1467 };
1468 }
1469 
1470 void
1471 PyViz::LineClipping (double boundsX1, double boundsY1, double boundsX2, double boundsY2,
1472  double &lineX1, double &lineY1, double &lineX2, double &lineY2)
1473 {
1474  FastClipping::Vector2 clipMin = { boundsX1, boundsY1}, clipMax = { boundsX2, boundsY2};
1475  FastClipping::Line line = { { lineX1, lineY1 }, { lineX2, lineY2 }, (lineX2-lineX1), (lineY2-lineY1) };
1476 
1477  FastClipping clipper (clipMin, clipMax);
1478  clipper.ClipLine (line);
1479  lineX1 = line.start.x;
1480  lineX2 = line.end.x;
1481  lineY1 = line.start.y;
1482  lineY2 = line.end.y;
1483 }
1484 
1485 
1486 }
1487 
uint32_t bytes
bytes
Definition: pyviz.h:102
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:835
std::vector< TransmissionSample > TransmissionSampleList
TransmissionSampleList typedef.
Definition: pyviz.h:104
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
std::vector< std::string > m_pauseMessages
pause message
Definition: pyviz.h:276
Adapted from http://en.wikipedia.org/w/index.php?title=Line_clipping&oldid=248609574.
Definition: pyviz.cc:946
TransmissionSampleList GetTransmissionSamples() const
Get transmission samples.
Definition: pyviz.cc:858
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint64_t transmittedBytes
transmitted bytes
Definition: pyviz.h:170
void TraceNetDevTxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &destination)
network transmit common trace callback function
Definition: pyviz.cc:524
Packet addressed to someone else.
Definition: net-device.h:304
uint32_t GetId(void) const
Definition: node.cc:107
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
TxRecordKey typedef.
Definition: pyviz.h:236
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
node statsitics
Definition: pyviz.h:283
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
helper class to be used by the visualizer
Definition: pyviz.h:51
void ClipStartRight(Line &line)
Clip start right function.
Definition: pyviz.cc:994
static Ptr< SimulatorImpl > GetImplementation(void)
Get the SimulatorImpl singleton.
Definition: simulator.cc:425
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
bool isBroadcast
is broadcast?
Definition: pyviz.h:243
void TraceIpv4Drop(std::string context, ns3::Ipv4Header const &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
ipv4 drop trace callback function
Definition: pyviz.cc:512
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:142
Item Next(void)
Retrieve the next metadata item.
TxRecordValue structure.
Definition: pyviz.h:239
structure describing a packet metadata item
std::map< uint32_t, Time > m_packetsOfInterest
list of packet UIDs that will be monitored
Definition: pyviz.h:281
TypeId tid
TypeId of Header or Trailer.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
transmission samples
Definition: pyviz.h:278
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void ClipEndLeft(Line &line)
Clip end left function.
Definition: pyviz.cc:1043
void TraceNetDevRxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &source)
network receive common trace callback function
Definition: pyviz.cc:645
std::map< Ptr< Node >, uint32_t > m_packetDrops
packt drops
Definition: pyviz.h:279
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition: tag-buffer.h:215
void ClipEndTop(Line &line)
Clip end top function.
Definition: pyviz.cc:1014
std::map< uint32_t, LastPacketsSample > m_lastPackets
last packets
Definition: pyviz.h:282
PacketSample structure.
Definition: pyviz.h:126
uint32_t bytes
bytes
Definition: pyviz.h:115
PyVizPacketTag structure.
Definition: pyviz.cc:71
void ClipEndBottom(Line &line)
Clip end bottom function.
Definition: pyviz.cc:1024
Mac48Address GetSource(void) const
virtual void Serialize(TagBuffer buf) const
Definition: pyviz.cc:110
channel
Definition: third.py:85
void CallbackStopSimulation()
stop simulation callback function
Definition: pyviz.cc:273
Mac48Address from
from
Definition: pyviz.h:140
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Filter packet function.
Definition: pyviz.cc:415
DropReason
Reason why a packet has been dropped.
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
WIFI transmit trace callback function.
Definition: pyviz.cc:590
void RegisterDropTracePath(std::string const &tracePath)
Register drop trace path function.
Definition: pyviz.cc:236
std::vector< std::string > GetPauseMessages() const
Get pause message function.
Definition: pyviz.cc:264
uint32_t transmittedPackets
transmitted packets
Definition: pyviz.h:172
Packet header for IPv4.
Definition: ipv4-header.h:33
Ptr< Channel > channel
channel
Definition: pyviz.h:265
Ptr< Node > srcNode
source node
Definition: pyviz.h:242
nodes
Definition: first.py:25
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: pyviz.cc:100
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
Findnet device statistics function.
Definition: pyviz.cc:384
TransmissionSampleKey structure.
Definition: pyviz.h:247
std::vector< TxPacketSample > lastTransmittedPackets
last transmitted packets
Definition: pyviz.h:147
PacketDropSampleList GetPacketDropSamples() const
Get packet drop samples.
Definition: pyviz.cc:881
Ptr< Packet > packet
packet
Definition: pyviz.h:129
void ClipStartLeft(Line &line)
Clip start left function.
Definition: pyviz.cc:1004
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition: tag-buffer.h:186
void RegisterPointToPointLikeDevice(std::string const &deviceTypeName)
Register point to point like device function.
Definition: pyviz.cc:212
Ptr< Channel > channel
channel
Definition: pyviz.h:101
Iterator class for metadata items.
Mac48Address GetDestination(void) const
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
LTE receive trace callback function.
Definition: pyviz.cc:849
Ptr< Node > receiver
NULL if broadcast.
Definition: pyviz.h:264
std::set< TypeId > headers
headers
Definition: pyviz.h:199
std::vector< NodeStatistics > GetNodesStatistics() const
Get node statistics.
Definition: pyviz.cc:908
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
static PyViz * g_visualizer
the visualizer
Definition: pyviz.cc:65
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
CSMA promiscious receive function.
Definition: pyviz.cc:812
static std::vector< std::string > PathSplit(std::string str)
Definition: pyviz.cc:43
Ptr< NetDevice > device
device
Definition: pyviz.h:130
uint32_t receivedPackets
received packets
Definition: pyviz.h:173
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
bool HasNext(void) const
Checks if there is another metadata item.
#define list
FastClipping(Vector2 clipMin, Vector2 clipMax)
Constructor.
Definition: pyviz.cc:1056
void ClipEndRight(Line &line)
Clip end right function.
Definition: pyviz.cc:1033
void SimulatorRunUntil(Time time)
Run simulation until a given (simulated, absolute) time is reached.
Definition: pyviz.cc:284
bool operator==(TransmissionSampleKey const &other) const
equality operator
Definition: pyviz.cc:374
NodeStatistics structure.
Definition: pyviz.h:177
tag a set of bytes in a packet
Definition: tag.h:36
void SetNodesOfInterest(std::set< uint32_t > nodes)
Set nodes of interest function.
Definition: pyviz.cc:902
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:114
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NetDeviceStatistics structure.
Definition: pyviz.h:165
bool ClipLine(Line &line)
Clip line function.
Definition: pyviz.cc:1067
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
packet capture options
Definition: pyviz.h:275
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
an EUI-48 address
Definition: mac48-address.h:43
Packet header for Ethernet.
std::vector< RxPacketSample > lastReceivedPackets
last received packets
Definition: pyviz.h:146
virtual void Print(std::ostream &os) const
Definition: pyviz.cc:120
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
PacketMetadata::ItemIterator BeginItem(void) const
Returns an iterator which points to the first &#39;item&#39; stored in this buffer.
Definition: packet.cc:566
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point transmit trace calllback function.
Definition: pyviz.cc:634
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
WIFI receive trace callback function.
Definition: pyviz.cc:759
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
queue drop trace callback function
Definition: pyviz.cc:466
void RegisterCsmaLikeDevice(std::string const &deviceTypeName)
Register CSMA like device function.
Definition: pyviz.cc:180
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Get last packets function.
Definition: pyviz.cc:922
uint64_t receivedBytes
received bytes
Definition: pyviz.h:171
virtual void Deserialize(TagBuffer buf)
Definition: pyviz.cc:115
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
WIMax transmit trace callback function.
Definition: pyviz.cc:828
static TypeId GetTypeId(void)
Get the type ID.
Definition: pyviz.cc:90
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1475
read and write tag data
Definition: tag-buffer.h:51
TransmissionSample structure.
Definition: pyviz.h:97
std::set< uint32_t > m_nodesOfInterest
list of node IDs whose transmissions will be monitored
Definition: pyviz.h:280
bool m_stop
stop?
Definition: pyviz.h:408
~PyViz()
Definition: pyviz.cc:241
Time m_runUntil
run until time
Definition: pyviz.h:409
PacketDropSample structure.
Definition: pyviz.h:112
PacketCaptureOptions structure.
Definition: pyviz.h:197
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
don&#39;t break this line or pybindgen will not be able to pick up the above annotation :( ...
Definition: pyviz.cc:1471
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
void ClipStartBottom(Line &line)
Clip start bottom function.
Definition: pyviz.cc:984
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
TransmissionSampleValue structure.
Definition: pyviz.h:269
void RegisterWifiLikeDevice(std::string const &deviceTypeName)
Register WIFI like device function.
Definition: pyviz.cc:198
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:99
PacketCaptureMode mode
mode
Definition: pyviz.h:201
std::vector< PacketDropSample > PacketDropSampleList
PacketDropSampleList typedef.
Definition: pyviz.h:117
Flag for events not associated with any particular context.
Definition: simulator.h:198
TxPacketSample structure.
Definition: pyviz.h:133
Rare ad-hoc debug messages.
Definition: log.h:100
Mac48Address to
to
Definition: pyviz.h:135
uint32_t numLastPackets
num last packets
Definition: pyviz.h:200
RxPacketSample structure.
Definition: pyviz.h:138
void DoPause(std::string const &message)
Do pause function.
Definition: pyviz.cc:249
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
Set packet capture options function.
Definition: pyviz.cc:226
static void Pause(std::string const &message)
Pause function.
Definition: pyviz.cc:257
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
std::map< TxRecordKey, TxRecordValue > m_txRecords
transmit records
Definition: pyviz.h:277
virtual uint32_t GetSerializedSize(void) const
Definition: pyviz.cc:105
void ClipStartTop(Line &line)
Clip start top function.
Definition: pyviz.cc:974
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:263
std::vector< PacketSample > lastDroppedPackets
last dropped packets
Definition: pyviz.h:148
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_packetId
packet id
Definition: pyviz.cc:81
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:819
bool operator<(TransmissionSampleKey const &other) const
less than operator
Definition: pyviz.cc:346
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
LTE transmit trace callback function.
Definition: pyviz.cc:842
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
CSMA transmit trace callback function.
Definition: pyviz.cc:626
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point receive trace callback function.
Definition: pyviz.cc:806
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Implements the IEEE 802.11 MAC header.
LastPacketsSample structure.
Definition: pyviz.h:144
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
CSMA receive trace callback function.
Definition: pyviz.cc:798
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
WIMax transmit trace callback function.
Definition: pyviz.cc:835
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Get packet capture options function.
Definition: pyviz.cc:401
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824
Ptr< Node > receiver
NULL if broadcast.
Definition: pyviz.h:100