visualizer: Correct doxygen warnings

This commit is contained in:
Robert Ammon
2017-04-26 06:51:40 -07:00
parent 250faaa547
commit 850e4cc02e
15 changed files with 1262 additions and 189 deletions

View File

@@ -62,10 +62,12 @@ PathSplit (std::string str)
namespace ns3 {
static PyViz* g_visualizer = NULL;
static PyViz* g_visualizer = NULL; ///< the visualizer
/**
* PyVizPacketTag structure
*/
struct PyVizPacketTag : public Tag
{
static TypeId GetTypeId (void);
@@ -76,10 +78,14 @@ struct PyVizPacketTag : public Tag
virtual void Print (std::ostream &os) const;
PyVizPacketTag ();
uint32_t m_packetId;
uint32_t m_packetId; ///< packet id
};
/**
* \brief Get the type ID.
* \return the object TypeId
*/
TypeId
PyVizPacketTag::GetTypeId (void)
{
@@ -936,67 +942,104 @@ PyViz::GetLastPackets (uint32_t nodeId) const
namespace
{
// Adapted from http://en.wikipedia.org/w/index.php?title=Line_clipping&oldid=248609574
/// Adapted from http://en.wikipedia.org/w/index.php?title=Line_clipping&oldid=248609574
class FastClipping
{
public:
/// Vector2 structure
struct Vector2
{
double x;
double y;
double x; ///< X
double y; ///< Y
};
Vector2 m_clipMin, m_clipMax;
Vector2 m_clipMin; ///< clip minimum
Vector2 m_clipMax; ///< clip maximum
/// Line structure
struct Line
{
Vector2 start, end;
double dx, dy;
Vector2 start; ///< start
Vector2 end; ///< end
double dx; ///< dX
double dy; ///< dY
};
private:
/**
* Clip start top function
* \param line the clip line
*/
void ClipStartTop (Line &line)
{
line.start.x += line.dx * (m_clipMin.y - line.start.y) / line.dy;
line.start.y = m_clipMin.y;
}
/**
* Clip start bottom function
* \param line the clip line
*/
void ClipStartBottom (Line &line)
{
line.start.x += line.dx * (m_clipMax.y - line.start.y) / line.dy;
line.start.y = m_clipMax.y;
}
/**
* Clip start right function
* \param line the clip line
*/
void ClipStartRight (Line &line)
{
line.start.y += line.dy * (m_clipMax.x - line.start.x) / line.dx;
line.start.x = m_clipMax.x;
}
/**
* Clip start left function
* \param line the clip line
*/
void ClipStartLeft (Line &line)
{
line.start.y += line.dy * (m_clipMin.x - line.start.x) / line.dx;
line.start.x = m_clipMin.x;
}
/**
* Clip end top function
* \param line the clip line
*/
void ClipEndTop (Line &line)
{
line.end.x += line.dx * (m_clipMin.y - line.end.y) / line.dy;
line.end.y = m_clipMin.y;
}
/**
* Clip end bottom function
* \param line the clip line
*/
void ClipEndBottom (Line &line) {
line.end.x += line.dx * (m_clipMax.y - line.end.y) / line.dy;
line.end.y = m_clipMax.y;
}
/**
* Clip end right function
* \param line the clip line
*/
void ClipEndRight (Line &line)
{
line.end.y += line.dy * (m_clipMax.x - line.end.x) / line.dx;
line.end.x = m_clipMax.x;
}
/**
* Clip end left function
* \param line the clip line
*/
void ClipEndLeft (Line &line)
{
line.end.y += line.dy * (m_clipMin.x - line.end.x) / line.dx;
@@ -1004,12 +1047,23 @@ private:
}
public:
/**
* Constructor
*
* \param clipMin minimum clipping vector
* \param clipMax maximum clipping vector
*/
FastClipping (Vector2 clipMin, Vector2 clipMax)
: m_clipMin (clipMin), m_clipMax (clipMax)
{
}
/**
* Clip line function
* \param line the clip line
* \returns true if clipped
*/
bool ClipLine (Line &line)
{
uint8_t lineCode = 0;

View File

@@ -54,173 +54,360 @@ public:
PyViz ();
~PyViz ();
/**
* Register drop trace path function
* \param tracePath the path to trace
*/
void RegisterDropTracePath (std::string const &tracePath);
/**
* Register CSMA like device function
* \param deviceTypeName the device type name
*/
void RegisterCsmaLikeDevice (std::string const &deviceTypeName);
/**
* Register WIFI like device function
* \param deviceTypeName the device type name
*/
void RegisterWifiLikeDevice (std::string const &deviceTypeName);
/**
* Register point to point like device function
* \param deviceTypeName the device type name
*/
void RegisterPointToPointLikeDevice (std::string const &deviceTypeName);
// Run simulation until a given (simulated, absolute) time is reached
/**
* Run simulation until a given (simulated, absolute) time is reached
* \param time the run time
*/
void SimulatorRunUntil (Time time);
/**
* Pause function
* \param message the pause message
*/
static void Pause (std::string const &message);
/**
* Get pause message function
* \returns the pause message
*/
std::vector<std::string> GetPauseMessages () const;
/// TransmissionSample structure
struct TransmissionSample
{
Ptr<Node> transmitter;
Ptr<Node> receiver; // NULL if broadcast
Ptr<Channel> channel;
uint32_t bytes;
Ptr<Node> transmitter; ///< transmitter
Ptr<Node> receiver; ///< NULL if broadcast
Ptr<Channel> channel; ///< channel
uint32_t bytes; ///< bytes
};
typedef std::vector<TransmissionSample> TransmissionSampleList;
typedef std::vector<TransmissionSample> TransmissionSampleList; ///< TransmissionSampleList typedef
/**
* Get transmission samples
* \returns the transmission sample list
*/
TransmissionSampleList GetTransmissionSamples () const;
/// PacketDropSample structure
struct PacketDropSample
{
Ptr<Node> transmitter;
uint32_t bytes;
Ptr<Node> transmitter; ///< transmitter
uint32_t bytes; ///< bytes
};
typedef std::vector<PacketDropSample> PacketDropSampleList;
typedef std::vector<PacketDropSample> PacketDropSampleList; ///< PacketDropSampleList typedef
/**
* Get packet drop samples
* \returns the packet drop sample list
*/
PacketDropSampleList GetPacketDropSamples () const;
/// PacketSample structure
struct PacketSample
{
Time time;
Ptr<Packet> packet;
Ptr<NetDevice> device;
Time time; ///< time
Ptr<Packet> packet; ///< packet
Ptr<NetDevice> device; ///< device
};
/// TxPacketSample structure
struct TxPacketSample : PacketSample
{
Mac48Address to;
Mac48Address to; ///< to
};
/// RxPacketSample structure
struct RxPacketSample : PacketSample
{
Mac48Address from;
Mac48Address from; ///< from
};
/// LastPacketsSample structure
struct LastPacketsSample
{
std::vector<RxPacketSample> lastReceivedPackets;
std::vector<TxPacketSample> lastTransmittedPackets;
std::vector<PacketSample> lastDroppedPackets;
std::vector<RxPacketSample> lastReceivedPackets; ///< last received packets
std::vector<TxPacketSample> lastTransmittedPackets; ///< last transmitted packets
std::vector<PacketSample> lastDroppedPackets; ///< last dropped packets
};
/**
* Get last packets function
* \param nodeId the node ID
* \returns the last packets
*/
LastPacketsSample GetLastPackets (uint32_t nodeId) const;
/**
* Set nodes of interest function
* \param nodes the collection of nodes
*/
void SetNodesOfInterest (std::set<uint32_t> nodes);
/// NetDeviceStatistics structure
struct NetDeviceStatistics
{
/// constructor
NetDeviceStatistics () : transmittedBytes (0), receivedBytes (0),
transmittedPackets (0), receivedPackets (0) {}
uint64_t transmittedBytes;
uint64_t receivedBytes;
uint32_t transmittedPackets;
uint32_t receivedPackets;
uint64_t transmittedBytes; ///< transmitted bytes
uint64_t receivedBytes; ///< received bytes
uint32_t transmittedPackets; ///< transmitted packets
uint32_t receivedPackets; ///< received packets
};
/// NodeStatistics structure
struct NodeStatistics
{
uint32_t nodeId;
std::vector<NetDeviceStatistics> statistics;
uint32_t nodeId; ///< node ID
std::vector<NetDeviceStatistics> statistics; ///< statistics
};
/**
* Get node statistics
* \returns the node statistics
*/
std::vector<NodeStatistics> GetNodesStatistics () const;
/// PacketCaptureMode enumeration
enum PacketCaptureMode {
PACKET_CAPTURE_DISABLED=1, // packet capture is disabled
PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present
PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present
};
/// PacketCaptureOptions structure
struct PacketCaptureOptions
{
std::set<TypeId> headers;
uint32_t numLastPackets;
PacketCaptureMode mode;
std::set<TypeId> headers; ///< headers
uint32_t numLastPackets; ///< num last packets
PacketCaptureMode mode; ///< mode
};
/**
* Set packet capture options function
* \param nodeId the node ID
* \param options the capture options
*/
void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options);
// Yes, I know, this is just a utility function, not really related to the class in any way.
// -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#-
static void LineClipping (double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2); // don't break this line or pybindgen will not be able to pick up the above annotation :(
static void LineClipping (double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2); ///< don't break this line or pybindgen will not be able to pick up the above annotation :(
private:
/**
* Get packet capture options function
* \param nodeId the node ID
* \param outOptions the packet capture options
* \returns true if successful
*/
bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
/**
* Filter packet function
* \param packet the packet
* \param options the capture options
* \returns true if successful
*/
static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey; ///< TxRecordKey typedef
/// TxRecordValue structure
struct TxRecordValue
{
Time time;
Ptr<Node> srcNode;
bool isBroadcast;
Time time; ///< time
Ptr<Node> srcNode; ///< source node
bool isBroadcast; ///< is broadcast?
};
/// TransmissionSampleKey structure
struct TransmissionSampleKey
{
/**
* less than operator
*
* \param other object to compare
* \return true if less than
*/
bool operator < (TransmissionSampleKey const &other) const;
/**
* equality operator
*
* \param other object to compare
* \return true if equal
*/
bool operator == (TransmissionSampleKey const &other) const;
Ptr<Node> transmitter;
Ptr<Node> receiver; // NULL if broadcast
Ptr<Channel> channel;
Ptr<Node> transmitter; ///< transmitter
Ptr<Node> receiver; ///< NULL if broadcast
Ptr<Channel> channel; ///< channel
};
/// TransmissionSampleValue structure
struct TransmissionSampleValue
{
uint32_t bytes;
uint32_t bytes; ///< bytes
};
// data
std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
std::vector<std::string> m_pauseMessages;
std::map<TxRecordKey, TxRecordValue> m_txRecords;
std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
std::map<Ptr<Node>, uint32_t> m_packetDrops;
std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored
std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored
std::map<uint32_t, LastPacketsSample> m_lastPackets;
std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions; ///< packet capture options
std::vector<std::string> m_pauseMessages; ///< pause message
std::map<TxRecordKey, TxRecordValue> m_txRecords; ///< transmit records
std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples; ///< transmission samples
std::map<Ptr<Node>, uint32_t> m_packetDrops; ///< packt drops
std::set<uint32_t> m_nodesOfInterest; ///< list of node IDs whose transmissions will be monitored
std::map<uint32_t, Time> m_packetsOfInterest; ///< list of packet UIDs that will be monitored
std::map<uint32_t, LastPacketsSample> m_lastPackets; ///< last packets
std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics; ///< node statsitics
// Trace callbacks
/**
* network transmit common trace callback function
* \param context the context
* \param packet the packet
* \param destination the destination MAC address
*/
void TraceNetDevTxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &destination);
/**
* network receive common trace callback function
* \param context the context
* \param packet the packet
* \param source the source MAC address
*/
void TraceNetDevRxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &source);
/**
* WIFI transmit trace callback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet);
/**
* WIFI receive trace callback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet);
/**
* queue drop trace callback function
* \param context the context
* \param packet the packet
*/
void TraceDevQueueDrop (std::string context, Ptr<const Packet> packet);
void TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet,
/**
* ipv4 drop trace callback function
* \param context the context
* \param hdr the header
* \param packet the packet
* \param reason the drop reason
* \param dummy_ipv4
* \param interface the interface
*/
void TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet,
ns3::Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> dummy_ipv4, uint32_t interface);
/**
* CSMA transmit trace callback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
/**
* CSMA receive trace callback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
/**
* CSMA promiscious receive function
* \param context the context
* \param packet the packet
*/
void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet);
/**
* Point to point transmit trace calllback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
/**
* Point to point receive trace callback function
* \param context the context
* \param packet the packet
*/
void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
/**
* WIMax transmit trace callback function
* \param context the context
* \param packet the packet
* \param destination the destination MAC address
*/
void TraceNetDevTxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
/**
* WIMax transmit trace callback function
* \param context the context
* \param packet the packet
* \param source the source MAC address
*/
void TraceNetDevRxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
/**
* LTE transmit trace callback function
* \param context the context
* \param packet the packet
* \param destination the destination MAC address
*/
void TraceNetDevTxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
/**
* LTE receive trace callback function
* \param context the context
* \param packet the packet
* \param source the MAC address of the source
*/
void TraceNetDevRxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
/**
* Findnet device statistics function
* \param node the node
* \param interface the interface number
* \returns the device statistics
*/
inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
/**
* Do pause function
* \param message the pause message
*/
void DoPause (std::string const &message);
bool m_stop;
Time m_runUntil;
bool m_stop; ///< stop?
Time m_runUntil; ///< run until time
/// stop simulation callback function
void CallbackStopSimulation ();
};

View File

@@ -30,6 +30,7 @@ NS_OBJECT_ENSURE_REGISTERED (VisualSimulatorImpl);
namespace
{
/// Get an object factory configured to the default simulator implementation
ObjectFactory
GetDefaultSimulatorImplFactory ()
{

View File

@@ -44,6 +44,10 @@ namespace ns3 {
class VisualSimulatorImpl : public SimulatorImpl
{
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);
VisualSimulatorImpl ();
@@ -76,9 +80,9 @@ protected:
void NotifyConstructionCompleted (void);
private:
Ptr<SimulatorImpl> GetSim ();
Ptr<SimulatorImpl> m_simulator;
ObjectFactory m_simulatorImplFactory;
Ptr<SimulatorImpl> GetSim (); ///< get the simulator implementation
Ptr<SimulatorImpl> m_simulator; ///< the simulator implementation
ObjectFactory m_simulatorImplFactory; ///< simulator implementation factory
};

View File

@@ -14,22 +14,44 @@ import sys
PIXELS_PER_METER = 3.0 # pixels-per-meter, at 100% zoom level
## PyVizObject class
class PyVizObject(gobject.GObject):
__gtype_name__ = "PyVizObject"
## @var __gtype_name__
# global type name
__gtype_name__ = "PyVizObject"
## Returns tooltip text string.
#
## @param tooltip: tooltip object.
## @return: Tooltip text.
def tooltip_query(self, tooltip):
tooltip.set_text("TODO: tooltip for %r" % self)
## Link class
class Link(PyVizObject):
pass
## InformationWindow class
class InformationWindow(object):
## update function
#
## @return: NotImplementedError exception
def update(self):
raise NotImplementedError
## NetDeviceTraits class
class NetDeviceTraits(object):
## class variables
## @var is_wireless
# is wireless
## @var is_virtual
# is virtual
def __init__(self, is_wireless=None, is_virtual=False):
''' Initialize function.
@param is_wireless is wireless flag
@param is_virtual is virtual flag
'''
assert is_virtual or is_wireless is not None
self.is_wireless = is_wireless
self.is_virtual = is_virtual

View File

@@ -66,17 +66,55 @@ from base import load_plugins, register_plugin, plugins
PI_OVER_2 = math.pi/2
PI_TIMES_2 = math.pi*2
## Node class
class Node(PyVizObject):
## @var visualizer
# visualier object
## @var node_index
# node index
## @var canvas_item
# canvas item
## @var links
# links
## @var _has_mobility
# has mobility model
## @var _selected
# is selected
## @var _highlighted
# is highlighted
## @var _color
# color
## @var _size
# size
## @var menu
# menu
## @var svg_item
# svg item
## @var svg_align_x
# svg align X
## @var svg_align_y
# svg align Y
## @var _label
# label
## @var _label_canvas_item
# label canvas
## @var selected
# selected property
## @var highlighted
# highlighted property
## @var __gsignals__
# signal emitted whenever a tooltip is about to be shown for the node
# the first signal parameter is a python list of strings, to which information can be appended
__gsignals__ = {
# signal emitted whenever a tooltip is about to be shown for the node
# the first signal parameter is a python list of strings, to which information can be appended
'query-extra-tooltip-info': (gobject.SIGNAL_RUN_LAST, None, (object,)),
}
def __init__(self, visualizer, node_index):
""" Initialize function.
@param self The object pointer.
@param visualizer: visualizer object
@param node_index: node index
"""
super(Node, self).__init__()
self.visualizer = visualizer
@@ -101,7 +139,7 @@ class Node(PyVizObject):
self._update_appearance() # call this last
def set_svg_icon(self, file_base_name, width=None, height=None, align_x=0.5, align_y=0.5):
"""
"""!
Set a background SVG icon for the node.
@param file_base_name: base file name, including .svg
@@ -109,7 +147,7 @@ class Node(PyVizObject):
src/contrib/visualizer/resource.
@param width: scale to the specified width, in meters
@param width: scale to the specified height, in meters
@param height: scale to the specified height, in meters
@param align_x: horizontal alignment of the icon relative to
the node position, from 0 (icon fully to the left of the node)
@@ -119,6 +157,8 @@ class Node(PyVizObject):
node position, from 0 (icon fully to the top of the node) to
1.0 (icon fully to the bottom of the node)
@return a ValueError exception if invalid dimensions.
"""
if width is None and height is None:
raise ValueError("either width or height must be given")
@@ -145,11 +185,27 @@ class Node(PyVizObject):
self._update_appearance()
def set_label(self, label):
"""!
Set a label for the node.
@param self: class object.
@param label: label to set
@return: an exception if invalid parameter.
"""
assert isinstance(label, basestring)
self._label = label
self._update_appearance()
def _update_svg_position(self, x, y):
"""!
Update svg position.
@param self: class object.
@param x: x position
@param y: y position
@return none
"""
w = self.svg_item.width
h = self.svg_item.height
self.svg_item.set_properties(x=(x - (1-self.svg_align_x)*w),
@@ -157,6 +213,13 @@ class Node(PyVizObject):
def tooltip_query(self, tooltip):
"""!
Query tooltip.
@param self: class object.
@param tooltip: tooltip
@return none
"""
self.visualizer.simulation.lock.acquire()
try:
ns3_node = ns.network.NodeList.GetNode(self.node_index)
@@ -212,30 +275,88 @@ class Node(PyVizObject):
self.visualizer.simulation.lock.release()
def on_enter_notify_event(self, view, target, event):
"""!
On Enter event handle.
@param self: class object.
@param view: view
@param target: target
@param event: event
@return none
"""
self.highlighted = True
def on_leave_notify_event(self, view, target, event):
"""!
On Leave event handle.
@param self: class object.
@param view: view
@param target: target
@param event: event
@return none
"""
self.highlighted = False
def _set_selected(self, value):
"""!
Set selected function.
@param self: class object.
@param value: selected value
@return none
"""
self._selected = value
self._update_appearance()
def _get_selected(self):
"""!
Get selected function.
@param self: class object.
@return selected status
"""
return self._selected
selected = property(_get_selected, _set_selected)
def _set_highlighted(self, value):
"""!
Set highlighted function.
@param self: class object.
@param value: selected value
@return none
"""
self._highlighted = value
self._update_appearance()
def _get_highlighted(self):
"""!
Get highlighted function.
@param self: class object.
@return highlighted status
"""
return self._highlighted
highlighted = property(_get_highlighted, _set_highlighted)
def set_size(self, size):
"""!
Set size function.
@param self: class object.
@param size: selected size
@return none
"""
self._size = size
self._update_appearance()
def _update_appearance(self):
"""Update the node aspect to reflect the selected/highlighted state"""
"""!
Update the node aspect to reflect the selected/highlighted state
@param self: class object.
@return none
"""
size = transform_distance_simulation_to_canvas(self._size)
if self.svg_item is not None:
@@ -271,6 +392,14 @@ class Node(PyVizObject):
self._update_position()
def set_position(self, x, y):
"""!
Set position function.
@param self: class object.
@param x: x position
@param y: y position
@return none
"""
self.canvas_item.set_property("center_x", x)
self.canvas_item.set_property("center_y", y)
if self.svg_item is not None:
@@ -283,13 +412,32 @@ class Node(PyVizObject):
self._label_canvas_item.set_properties(x=x, y=(y+self._size*3))
def get_position(self):
"""!
Get position function.
@param self: class object.
@return x and y position
"""
return (self.canvas_item.get_property("center_x"), self.canvas_item.get_property("center_y"))
def _update_position(self):
"""!
Update position function.
@param self: class object.
@return none
"""
x, y = self.get_position()
self.set_position(x, y)
def set_color(self, color):
"""!
Set color function.
@param self: class object.
@param color: color to set.
@return none
"""
if isinstance(color, str):
color = gtk.gdk.color_parse(color)
color = ((color.red>>8) << 24) | ((color.green>>8) << 16) | ((color.blue>>8) << 8) | 0xff
@@ -297,15 +445,35 @@ class Node(PyVizObject):
self._update_appearance()
def add_link(self, link):
"""!
Add link function.
@param self: class object.
@param link: link to add.
@return none
"""
assert isinstance(link, Link)
self.links.append(link)
def remove_link(self, link):
"""!
Remove link function.
@param self: class object.
@param link: link to add.
@return none
"""
assert isinstance(link, Link)
self.links.remove(link)
@property
def has_mobility(self):
"""!
Has mobility function.
@param self: class object.
@return modility option
"""
if self._has_mobility is None:
node = ns.network.NodeList.GetNode(self.node_index)
mobility = node.GetObject(ns.mobility.MobilityModel.GetTypeId())
@@ -313,8 +481,23 @@ class Node(PyVizObject):
return self._has_mobility
## Channel
class Channel(PyVizObject):
## @var channel
# channel
## @var canvas_item
# canvas
## @var links
# list of links
#
def __init__(self, channel):
"""!
Initializer function.
@param self: class object.
@param channel: channel.
@return none
"""
self.channel = channel
self.canvas_item = goocanvas.Ellipse(radius_x=30, radius_y=30,
fill_color="white",
@@ -325,6 +508,14 @@ class Channel(PyVizObject):
self.links = []
def set_position(self, x, y):
"""!
Initializer function.
@param self: class object.
@param x: x position.
@param y: y position.
@return
"""
self.canvas_item.set_property("center_x", x)
self.canvas_item.set_property("center_y", y)
@@ -332,11 +523,33 @@ class Channel(PyVizObject):
link.update_points()
def get_position(self):
"""!
Initializer function.
@param self: class object.
@return x / y position.
"""
return (self.canvas_item.get_property("center_x"), self.canvas_item.get_property("center_y"))
## WiredLink
class WiredLink(Link):
## @var node1
# first node
## @var node2
# second node
## @var canvas_item
# canvas
#
def __init__(self, node1, node2):
"""!
Initializer function.
@param self: class object.
@param node1: class object.
@param node2: class object.
@return none
"""
assert isinstance(node1, Node)
assert isinstance(node2, (Node, Channel))
self.node1 = node1
@@ -347,14 +560,41 @@ class WiredLink(Link):
self.node2.links.append(self)
def update_points(self):
"""!
Update points function.
@param self: class object.
@return none
"""
pos1_x, pos1_y = self.node1.get_position()
pos2_x, pos2_y = self.node2.get_position()
self.canvas_item.set_property("data", "M %r %r L %r %r" % (pos1_x, pos1_y, pos2_x, pos2_y))
## SimulationThread
class SimulationThread(threading.Thread):
## @var viz
# Visualizer object
## @var lock
# thread lock
## @var go
# thread event
## @var target_time
# in seconds
## @var quit
# quit indicator
## @var sim_helper
# helper function
## @var pause_messages
# pause messages
def __init__(self, viz):
"""!
Initializer function.
@param self: class object.
@param viz: class object.
@return none
"""
super(SimulationThread, self).__init__()
assert isinstance(viz, Visualizer)
self.viz = viz # Visualizer object
@@ -367,6 +607,13 @@ class SimulationThread(threading.Thread):
self.pause_messages = []
def set_nodes_of_interest(self, nodes):
"""!
Set nodes of interest function.
@param self: class object.
@param nodes: class object.
@return
"""
self.lock.acquire()
try:
self.sim_helper.SetNodesOfInterest(nodes)
@@ -374,6 +621,12 @@ class SimulationThread(threading.Thread):
self.lock.release()
def run(self):
"""!
Initializer function.
@param self: class object.
@return none
"""
while not self.quit:
#print "sim: Wait for go"
self.go.wait() # wait until the main (view) thread gives us the go signal
@@ -400,14 +653,25 @@ class SimulationThread(threading.Thread):
self.lock.release()
#print "sim: Release lock, loop."
# enumeration
## ShowTransmissionsMode
class ShowTransmissionsMode(object):
## @var ALL
# all
## @var NONE
# none
## @var SELECTED
# seleced
## @var __slots__
# enumeration
__slots__ = []
ShowTransmissionsMode.ALL = ShowTransmissionsMode()
ShowTransmissionsMode.NONE = ShowTransmissionsMode()
ShowTransmissionsMode.SELECTED = ShowTransmissionsMode()
ShowTransmissionsMode.ALL = ShowTransmissionsMode()
ShowTransmissionsMode.NONE = ShowTransmissionsMode()
ShowTransmissionsMode.SELECTED = ShowTransmissionsMode()
## Visualizer
class Visualizer(gobject.GObject):
## @var INSTANCE
# all
INSTANCE = None
if _import_error is None:
@@ -429,6 +693,12 @@ class Visualizer(gobject.GObject):
}
def __init__(self):
"""!
Initializer function.
@param self: class object.
@return none
"""
assert Visualizer.INSTANCE is None
Visualizer.INSTANCE = self
super(Visualizer, self).__init__()
@@ -470,6 +740,13 @@ class Visualizer(gobject.GObject):
plugin(self)
def set_show_transmissions_mode(self, mode):
"""!
Set show transmission mode.
@param self: class object.
@param mode: mode to set.
@return none
"""
assert isinstance(mode, ShowTransmissionsMode)
self._show_transmissions_mode = mode
if self._show_transmissions_mode == ShowTransmissionsMode.ALL:
@@ -483,6 +760,12 @@ class Visualizer(gobject.GObject):
self.simulation.set_nodes_of_interest([self.selected_node.node_index])
def _create_advanced_controls(self):
"""!
Create advanced controls.
@param self: class object.
@return expander
"""
expander = gtk.Expander("Advanced")
expander.show()
@@ -565,10 +848,20 @@ class Visualizer(gobject.GObject):
return expander
## PanningState class
class _PanningState(object):
## @var __slots__
# internal variables
__slots__ = ['initial_mouse_pos', 'initial_canvas_pos', 'motion_signal']
def _begin_panning(self, widget, event):
"""!
Set show trnamission mode.
@param self: class object.
@param mode: mode to set.
@return none
"""
self.canvas.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
self._panning_state = self._PanningState()
x, y, dummy = widget.window.get_pointer()
@@ -579,6 +872,13 @@ class Visualizer(gobject.GObject):
self._panning_state.motion_signal = self.canvas.connect("motion-notify-event", self._panning_motion)
def _end_panning(self, event):
"""!
End panning function.
@param self: class object.
@param event: active event.
@return none
"""
if self._panning_state is None:
return
self.canvas.window.set_cursor(None)
@@ -586,6 +886,14 @@ class Visualizer(gobject.GObject):
self._panning_state = None
def _panning_motion(self, widget, event):
"""!
Panning motion function.
@param self: class object.
@param widget: widget.
@param event: event.
@return true if successful
"""
assert self._panning_state is not None
if event.is_hint:
x, y, dummy = widget.window.get_pointer()

View File

@@ -7,15 +7,54 @@ except ImportError:
#root_library = 'hig'
## HIGContainer class
class HIGContainer(gtk.Bin):
## @var __title_text
# title
## @var __title
# title
## @var __indent
# indent
## @var title_req
# title request
## @var indent_req
# indent request
## @var child
# child
## @var child_req
# child request
## @var requisition
# reqisition
## @var allocation
# allocation
## @var title_alloc
# title allocation
## @var child_alloc
# child allocation
## @var title_alloc.x
# allocation x
## @var title_alloc.y
# allocation y
## @var title_alloc.width
# allocation width
## @var title_alloc.height
# allocation height
## @var __gtype_name__
# global type name
__gtype_name__ = 'HIGContainer'
## @var __gproperties__
# global properties
__gproperties__ = {
'title': (str, 'Group Title', 'the group title',
'', gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
}
def __init__(self, title=None):
""" Initializer
@param self: this object
@param title: title
"""
self.__title_text = None
gtk.widget_push_composite_child()
self.__title = gobject.new(gtk.Label, visible=True, xalign=0, yalign=0.5)
@@ -28,6 +67,13 @@ class HIGContainer(gtk.Bin):
self.props.title = title
def do_size_request(self, requisition):
"""!
Size request function
@param self: this object
@param requisition: requisition
@return none
"""
title_req = gtk.gdk.Rectangle(0, 0, *self.__title.size_request())
indent_req = gtk.gdk.Rectangle(0, 0, *self.__indent.size_request())
if self.child is None:
@@ -39,6 +85,13 @@ class HIGContainer(gtk.Bin):
requisition.width = max(title_req.width, indent_req.width + child_req.width)
def do_size_allocate(self, allocation):
"""!
Allocate size function
@param self: this object
@param allocation: allocation
@return none
"""
self.allocation = allocation
## title
@@ -63,6 +116,15 @@ class HIGContainer(gtk.Bin):
self.child.size_allocate(child_alloc)
def do_forall(self, internal, callback, data):
"""!
For all function
@param self: this object
@param internal: internal
@param callback: callback
@param data: data
@return none
"""
if internal:
callback(self.__title, data)
callback(self.__indent, data)
@@ -70,6 +132,14 @@ class HIGContainer(gtk.Bin):
callback(self.child, data)
def do_set_property(self, pspec, value):
"""!
Set property function
@param self: this object
@param pspec: internal
@param value: callback
@return AttributeError if unknown property
"""
if pspec.name == 'title':
self.__title.set_markup('<span weight="bold">%s</span>' %
gobject.markup_escape_text(value))
@@ -78,6 +148,13 @@ class HIGContainer(gtk.Bin):
raise AttributeError, 'unknown property %s' % pspec.name
def do_get_property(self, pspec):
"""!
Set property function
@param self: this object
@param pspec: internal
@return title text
"""
if pspec.name == 'title':
return self.__title_text
else:

View File

@@ -5,8 +5,28 @@ import pango
import gtk
## Axes class
class Axes(object):
## @var viz
# visualizer
## @var color
# color
## @var hlines
# horizontal lines
## @var vlines
# vertical lines
## @var labels
# list of labels
## @var visible
# visible
def __init__(self, viz):
"""!
Initializer function
@param self: this object
@param viz: visualization object
@return none
"""
self.viz = viz
self.color = 0x8080C0FF
self.hlines = goocanvas.Path(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.color)
@@ -27,6 +47,13 @@ class Axes(object):
self.update_view()
def set_visible(self, visible):
"""!
Set visible function
@param self: this object
@param visible: visible indicator
@return none
"""
self.visible = visible
if self.visible:
self.hlines.props.visibility = goocanvas.ITEM_VISIBLE
@@ -38,6 +65,14 @@ class Axes(object):
label.props.visibility = goocanvas.ITEM_HIDDEN
def _compute_divisions(self, xi, xf):
"""!
Compute divisions function
@param self: this object
@param xi: xi
@param xf: xf
@return x0 and div
"""
assert xf > xi
dx = xf - xi
size = dx
@@ -45,6 +80,12 @@ class Axes(object):
text_width = dx/ndiv/2
def rint(x):
"""!
Compute divisions function
@param x: x
@return x rounded up
"""
return math.floor(x+0.5)
dx_over_ndiv = dx / ndiv
@@ -63,6 +104,12 @@ class Axes(object):
def update_view(self):
"""!
Update view function
@param self: this object
@return none
"""
if self.viz.zoom is None:
return
@@ -71,6 +118,12 @@ class Axes(object):
for label in unused_labels:
label.set_property("visibility", goocanvas.ITEM_HIDDEN)
def get_label():
"""!
Get label function
@param self: this object
@return label
"""
try:
label = unused_labels.pop(0)
except IndexError:

View File

@@ -26,29 +26,65 @@ from pkg_resources import parse_version
try:
import IPython
except ImportError:
##@ var IPython
#
IPython = None
## IterableIPShell class
class IterableIPShell:
def __init__(self,argv=None,user_ns=None,user_global_ns=None,
## @var IP
# IP
## @var iter_more
# iterate more
## @var history_level
# history level
## @var complete_sep
# separators
## @var prompt
# prompt
## @var header
# header
## @var config
# config
## @var user_ns
# user_ns
## @var old_stdout
# saved stdout
## @var old_stderr
# saved stderr
## @var system
# system
## @var cfg
# configuration
## @var colors
# colors
## @var raw_input_original
# original raw input
## @var stdin
# cin
## @var stdout
# cout
## @var stderr
# cerr
## @var raw_input
# raw input
## @var excepthook
# exception hook
## Constructor
def __init__(self,argv=None,user_ns=None,user_global_ns=None,
cin=None, cout=None,cerr=None, input_func=None):
'''
"""! Initializer
@param self: this object
@param argv: Command line options for IPython
@type argv: list
@param user_ns: User namespace.
@type user_ns: dictionary
@param user_global_ns: User global namespace.
@type user_global_ns: dictionary.
@param cin: Console standard input.
@type cin: IO stream
@param cout: Console standard output.
@type cout: IO stream
@param cerr: Console standard error.
@type cerr: IO stream
@param input_func: Replacement for builtin raw_input()
@type input_func: function
'''
@return none
"""
io = IPython.utils.io
if input_func:
if parse_version(IPython.release.version) >= parse_version("1.2.1"):
@@ -110,17 +146,17 @@ class IterableIPShell:
self.__update_namespace()
def __update_namespace(self):
'''
"""!
Update self.IP namespace for autocompletion with sys.modules
'''
"""
for k, v in list(sys.modules.items()):
if not '.' in k:
self.IP.user_ns.update({k:v})
def execute(self):
'''
"""!
Executes the current line provided by the shell object.
'''
"""
self.history_level = 0
orig_stdout = sys.stdout
sys.stdout = IPython.utils.io.stdout
@@ -169,16 +205,13 @@ class IterableIPShell:
sys.stdin = orig_stdin
def generatePrompt(self, is_continuation):
'''
"""!
Generate prompt depending on is_continuation value
@param is_continuation
@type is_continuation: boolean
@return: The prompt string representation
@rtype: string
'''
"""
# Backwards compatibility with ipyton-0.11
#
@@ -195,35 +228,35 @@ class IterableIPShell:
def historyBack(self):
'''
"""!
Provides one history command back.
@param self this object
@return: The command string.
@rtype: string
'''
"""
self.history_level -= 1
if not self._getHistory():
self.history_level +=1
return self._getHistory()
def historyForward(self):
'''
"""!
Provides one history command forward.
@param self this object
@return: The command string.
@rtype: string
'''
"""
if self.history_level < 0:
self.history_level += 1
return self._getHistory()
def _getHistory(self):
'''
"""!
Get's the command string of the current history level.
@param self this object
@return: Historic command string.
@rtype: string
'''
"""
try:
rv = self.IP.user_ns['In'][self.history_level].strip('\n')
except IndexError:
@@ -231,25 +264,21 @@ class IterableIPShell:
return rv
def updateNamespace(self, ns_dict):
'''
"""!
Add the current dictionary to the shell namespace.
@param ns_dict: A dictionary of symbol-values.
@type ns_dict: dictionary
'''
@return none
"""
self.IP.user_ns.update(ns_dict)
def complete(self, line):
'''
"""!
Returns an auto completed line and/or posibilities for completion.
@param line: Given line so far.
@type line: string
@return: Line completed as for as possible,
and possible further completions.
@rtype: tuple
'''
@return: Line completed as for as possible, and possible further completions.
"""
split_line = self.complete_sep.split(line)
if split_line[-1]:
possibilities = self.IP.complete(split_line[-1])
@@ -258,17 +287,13 @@ class IterableIPShell:
possibilities = ['', []]
if possibilities:
def _commonPrefix(str1, str2):
'''
"""!
Reduction function. returns common prefix of two given strings.
@param str1: First string.
@type str1: string
@param str2: Second string
@type str2: string
@return: Common prefix to both strings.
@rtype: string
'''
"""
for i in range(len(str1)):
if not str2.startswith(str1[:i+1]):
return str1[:i]
@@ -284,18 +309,15 @@ class IterableIPShell:
def shell(self, cmd,verbose=0,debug=0,header=''):
'''
"""!
Replacement method to allow shell commands without them blocking.
@param cmd: Shell command to execute.
@type cmd: string
@param verbose: Verbosity
@type verbose: integer
@param debug: Debug level
@type debug: integer
@param header: Header to be printed before output
@type header: string
'''
@return none
"""
stat = 0
if verbose or debug: print header+cmd
# flush stdout so we don't mangle python's buffering
@@ -305,8 +327,19 @@ class IterableIPShell:
output.close()
input.close()
## ConsoleView class
class ConsoleView(gtk.TextView):
'''
## @var ANSI_COLORS
# color list
## @var text_buffer
# text buffer
## @var mark
# scroll mark
## @var color_pat
# color pattern
## @var line_start
# line start
"""
Specialized text view for console-like workflow.
@cvar ANSI_COLORS: Mapping of terminal colors to X11 names.
@@ -320,7 +353,7 @@ class ConsoleView(gtk.TextView):
@type mark: gtk.TextMark
@ivar line_start: Start of command line mark.
@type line_start: gtk.TextMark
'''
"""
ANSI_COLORS = {'0;30': 'Black', '0;31': 'Red',
'0;32': 'Green', '0;33': 'Brown',
'0;34': 'Blue', '0;35': 'Purple',
@@ -331,9 +364,9 @@ class ConsoleView(gtk.TextView):
'1;36': 'LightCyan', '1;37': 'White'}
def __init__(self):
'''
"""
Initialize console view.
'''
"""
gtk.TextView.__init__(self)
self.modify_font(pango.FontDescription('Mono'))
self.set_cursor_visible(True)
@@ -354,17 +387,23 @@ class ConsoleView(gtk.TextView):
self.connect('key-press-event', self.onKeyPress)
def write(self, text, editable=False):
gobject.idle_add(self._write, text, editable)
def _write(self, text, editable=False):
'''
"""!
Write given text to buffer.
@param text: Text to append.
@type text: string
@param editable: If true, added text is editable.
@type editable: boolean
'''
@return none
"""
gobject.idle_add(self._write, text, editable)
def _write(self, text, editable=False):
"""!
Write given text to buffer.
@param text: Text to append.
@param editable: If true, added text is editable.
@return none
"""
segments = self.color_pat.split(text)
segment = segments.pop(0)
start_mark = self.text_buffer.create_mark(None,
@@ -387,56 +426,73 @@ class ConsoleView(gtk.TextView):
self.scroll_mark_onscreen(self.mark)
def showPrompt(self, prompt):
gobject.idle_add(self._showPrompt, prompt)
def _showPrompt(self, prompt):
'''
"""!
Prints prompt at start of line.
@param prompt: Prompt to print.
@type prompt: string
'''
@return none
"""
gobject.idle_add(self._showPrompt, prompt)
def _showPrompt(self, prompt):
"""!
Prints prompt at start of line.
@param prompt: Prompt to print.
@return none
"""
self._write(prompt)
self.text_buffer.move_mark(self.line_start,
self.text_buffer.get_end_iter())
def changeLine(self, text):
gobject.idle_add(self._changeLine, text)
def _changeLine(self, text):
'''
"""!
Replace currently entered command line with given text.
@param text: Text to use as replacement.
@type text: string
'''
@return none
"""
gobject.idle_add(self._changeLine, text)
def _changeLine(self, text):
"""!
Replace currently entered command line with given text.
@param text: Text to use as replacement.
@return none
"""
iter = self.text_buffer.get_iter_at_mark(self.line_start)
iter.forward_to_line_end()
self.text_buffer.delete(self.text_buffer.get_iter_at_mark(self.line_start), iter)
self._write(text, True)
def getCurrentLine(self):
'''
"""!
Get text in current command line.
@return: Text of current command line.
@rtype: string
'''
@return Text of current command line.
"""
rv = self.text_buffer.get_slice(
self.text_buffer.get_iter_at_mark(self.line_start),
self.text_buffer.get_end_iter(), False)
return rv
def showReturned(self, text):
gobject.idle_add(self._showReturned, text)
def _showReturned(self, text):
'''
"""!
Show returned text from last command and print new prompt.
@param text: Text to show.
@type text: string
'''
@return none
"""
gobject.idle_add(self._showReturned, text)
def _showReturned(self, text):
"""!
Show returned text from last command and print new prompt.
@param text: Text to show.
@return none
"""
iter = self.text_buffer.get_iter_at_mark(self.line_start)
iter.forward_to_line_end()
self.text_buffer.apply_tag_by_name(
@@ -455,19 +511,15 @@ class ConsoleView(gtk.TextView):
self.text_buffer.insert_at_cursor(indentation)
def onKeyPress(self, widget, event):
'''
"""!
Key press callback used for correcting behavior for console-like
interfaces. For example 'home' should go to prompt, not to begining of
line.
@param widget: Widget that key press accored in.
@type widget: gtk.Widget
@param event: Event object
@type event: gtk.gdk.Event
@return: Return True if event should not trickle.
@rtype: boolean
'''
@return Return True if event should not trickle.
"""
insert_mark = self.text_buffer.get_insert()
insert_iter = self.text_buffer.get_iter_at_mark(insert_mark)
selection_mark = self.text_buffer.get_selection_bound()
@@ -502,20 +554,37 @@ class ConsoleView(gtk.TextView):
return self.onKeyPressExtend(event)
def onKeyPressExtend(self, event):
'''
"""!
For some reason we can't extend onKeyPress directly (bug #500900).
'''
@param event key press
@return none
"""
pass
## IPythonView class
class IPythonView(ConsoleView, IterableIPShell):
'''
## @var cout
# cout
## @var interrupt
# interrupt
## @var execute
# execute
## @var prompt
# prompt
## @var showPrompt
# show prompt
## @var history_pos
# history list
## @var window
# GTK Window
"""
Sub-class of both modified IPython shell and L{ConsoleView} this makes
a GTK+ IPython console.
'''
"""
def __init__(self):
'''
"""
Initialize. Redirect I/O to console.
'''
"""
ConsoleView.__init__(self)
self.cout = StringIO()
IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout,
@@ -527,33 +596,25 @@ class IPythonView(ConsoleView, IterableIPShell):
self.showPrompt(self.prompt)
def raw_input(self, prompt=''):
'''
"""!
Custom raw_input() replacement. Get's current line from console buffer.
@param prompt: Prompt to print. Here for compatability as replacement.
@type prompt: string
@return: The current command line text.
@rtype: string
'''
@return The current command line text.
"""
if self.interrupt:
self.interrupt = False
raise KeyboardInterrupt
return self.getCurrentLine()
def onKeyPressExtend(self, event):
'''
"""!
Key press callback with plenty of shell goodness, like history,
autocompletions, etc.
@param widget: Widget that key press occured in.
@type widget: gtk.Widget
@param event: Event object.
@type event: gtk.gdk.Event
@return: True if event should not trickle.
@rtype: boolean
'''
@return True if event should not trickle.
"""
if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99:
self.interrupt = True
@@ -582,9 +643,10 @@ class IPythonView(ConsoleView, IterableIPShell):
return True
def _processLine(self):
'''
"""!
Process current command line.
'''
@return none
"""
self.history_pos = 0
self.execute()
rv = self.cout.getvalue()

View File

@@ -6,20 +6,39 @@ from visualizer.base import InformationWindow
NODE_STATISTICS_MEMORY = 10
## StatisticsCollector class
class StatisticsCollector(object):
"""
Collects interface statistics for all nodes.
"""
## @var node_statistics
# node statistics
## @var visualizer
# visualizer
## NetDevStats class
class NetDevStats(object):
## @var __slots__
# class members
__slots__ = ['rxPackets', 'rxBytes', 'txPackets', 'txBytes',
'rxPacketRate', 'rxBitRate', 'txPacketRate', 'txBitRate']
def __init__(self, visualizer):
"""
Collects interface statistics for all nodes.
@param self this object
@param visualizer visualizer object
"""
self.node_statistics = {} # nodeid -> list(raw statistics)
self.visualizer = visualizer
def simulation_periodic_update(self, viz):
"""!
Simulation Periodic Update function.
@param self this object
@param viz visualizer object
@return none
"""
nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
for stats in nodes_statistics:
try:
@@ -32,6 +51,12 @@ class StatisticsCollector(object):
raw_stats_list.pop(0)
def get_interface_statistics(self, nodeId):
"""!
Get interface statistics function.
@param self this object
@param nodeId node ID
@return the statistics
"""
try:
raw_stats_list = self.node_statistics[nodeId]
except KeyError:
@@ -68,7 +93,20 @@ class StatisticsCollector(object):
return retval
## ShowInterfaceStatistics class
class ShowInterfaceStatistics(InformationWindow):
## @var win
# window
## @var visualizer
# visualizer
## @var statistics_collector
# statistics collector
## @var node_index
# node index
## @var viz_node
# visualizer node
## @var table_model
# table model
(
COLUMN_INTERFACE,
@@ -85,6 +123,13 @@ class ShowInterfaceStatistics(InformationWindow):
) = range(9)
def __init__(self, visualizer, node_index, statistics_collector):
"""
Initializer.
@param self this object
@param visualizer the visualizer object
@param node_index the node index
@param statistics_collector statistics collector class
"""
InformationWindow.__init__(self)
self.win = gtk.Dialog(parent=visualizer.window,
flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
@@ -122,10 +167,22 @@ class ShowInterfaceStatistics(InformationWindow):
self.win.show()
def _response_cb(self, win, response):
"""!
Response callback function.
@param self this object
@param win the window
@param response the response
@return none
"""
self.win.destroy()
self.visualizer.remove_information_window(self)
def update(self):
"""!
Update function.
@param self this object
@return none
"""
node = ns.network.NodeList.GetNode(self.node_index)
stats_list = self.statistics_collector.get_interface_statistics(self.node_index)
self.table_model.clear()

View File

@@ -6,7 +6,16 @@ import ns.internet
from visualizer.base import InformationWindow
## ShowIpv4RoutingTable class
class ShowIpv4RoutingTable(InformationWindow):
## @var win
# window
## @var visualizer
# visualizer
## @var node_index
# node index
## @var table_model
# table model
(
COLUMN_DESTINATION,
COLUMN_NEXT_HOP,
@@ -16,6 +25,13 @@ class ShowIpv4RoutingTable(InformationWindow):
) = range(5)
def __init__(self, visualizer, node_index):
"""
Initializer
@param self this object
@param visualizer visualizer object
@param node_index the node index
@return the statistics
"""
InformationWindow.__init__(self)
self.win = gtk.Dialog(parent=visualizer.window,
flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
@@ -66,10 +82,22 @@ class ShowIpv4RoutingTable(InformationWindow):
self.win.show()
def _response_cb(self, win, response):
"""!
Response callback function
@param self this object
@param win the window
@param response the response
@return none
"""
self.win.destroy()
self.visualizer.remove_information_window(self)
def update(self):
"""!
Update function
@param self this object
@return none
"""
node = ns.network.NodeList.GetNode(self.node_index)
ipv4 = node.GetObject(ns.internet.Ipv4.GetTypeId())
routing = ipv4.GetRoutingProtocol()

View File

@@ -7,7 +7,16 @@ import ns.olsr
from visualizer.base import InformationWindow
## ShowOlsrRoutingTable class
class ShowOlsrRoutingTable(InformationWindow):
## @var win
# window
## @var visualizer
# visualizer
## @var node_index
# node index
## @var table_model
# table model
(
COLUMN_DESTINATION,
COLUMN_NEXT_HOP,
@@ -16,6 +25,13 @@ class ShowOlsrRoutingTable(InformationWindow):
) = range(4)
def __init__(self, visualizer, node_index):
"""!
Initializer
@param self this object
@param visualizer visualizer object
@param node_index the node index
@return none
"""
InformationWindow.__init__(self)
self.win = gtk.Dialog(parent=visualizer.window,
flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
@@ -61,10 +77,22 @@ class ShowOlsrRoutingTable(InformationWindow):
self.win.show()
def _response_cb(self, win, response):
"""!
Initializer
@param self this object
@param win the window
@param response the response
@return none
"""
self.win.destroy()
self.visualizer.remove_information_window(self)
def update(self):
"""!
Update function
@param self this object
@return none
"""
node = ns.network.NodeList.GetNode(self.node_index)
olsr = node.GetObject(ns.olsr.olsr.RoutingProtocol.GetTypeId())
ipv4 = node.GetObject(ns.internet.Ipv4.GetTypeId())

View File

@@ -9,8 +9,38 @@ from visualizer.base import InformationWindow
from visualizer.higcontainer import HIGContainer
from kiwi.ui.objectlist import ObjectList, Column
## ShowLastPackets class
class ShowLastPackets(InformationWindow):
## @var win
# window
## @var visualizer
# visualizer
## @var viz_node
# visualizer node
## @var node
# the node
## @var tx_list
# packet transmit list
## @var rx_list
# packet receive list
## @var drop_list
# packet drop list
## @var packet_capture_options
# packet capture options
## @var packet_filter_widget
# packet filter widget
## @var packet_filter_list
# list of TypeIdConfig instances
## @var op_AND_button
# AND button
## @var op_OR_button
# OR button
class PacketList(gtk.ScrolledWindow):
"""
PacketList class
"""
## @var table_model
# table model
(
COLUMN_TIME,
COLUMN_INTERFACE,
@@ -19,6 +49,10 @@ class ShowLastPackets(InformationWindow):
) = range(4)
def __init__(self):
"""
Initializer
@param self this object
"""
super(ShowLastPackets.PacketList, self).__init__()
self.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
@@ -37,6 +71,13 @@ class ShowLastPackets(InformationWindow):
add_column("Contents", self.COLUMN_CONTENTS)
def update(self, node, packet_list):
"""!
Update function
@param self this object
@param node the node
@param packet_list packet list
@return none
"""
self.table_model.clear()
for sample in packet_list:
tree_iter = self.table_model.append()
@@ -55,6 +96,12 @@ class ShowLastPackets(InformationWindow):
def __init__(self, visualizer, node_index):
"""
Initializer
@param self this object
@param visualizer the visualizer object
@param node_index the node index
"""
InformationWindow.__init__(self)
self.win = gtk.Dialog(parent=visualizer.window,
flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
@@ -210,10 +257,22 @@ class ShowLastPackets(InformationWindow):
self.win.show()
def _response_cb(self, win, response):
"""!
Response callback function
@param self this object
@param win the window
@param response the response
@return none
"""
self.win.destroy()
self.visualizer.remove_information_window(self)
def update(self):
"""!
Update function
@param self this object
@return none
"""
last_packets = self.visualizer.simulation.sim_helper.GetLastPackets(self.node.GetId())
self.tx_list.update(self.node, last_packets.lastTransmittedPackets)

View File

@@ -4,8 +4,27 @@ import ns.network
import goocanvas
from visualizer.base import Link, transform_distance_canvas_to_simulation
## WifiLink class
class WifiLink(Link):
## @var node1
# sta
## @var dev
# dev
## @var node2
# ap
## @var canvas_item
# parent_canvas_item
## @var invisible_line
# invisible line
## @var visible_line
# visible line
def __init__(self, parent_canvas_item, sta, dev):
"""! Initialize function.
@param self The object pointer.
@param parent_canvas_item: parent canvas
@param sta The STA node
@param dev The dev
"""
self.node1 = sta
self.dev = dev
self.node2 = None # ap
@@ -25,6 +44,11 @@ class WifiLink(Link):
self.set_ap(None)
def set_ap(self, ap):
"""! Set AP.
@param self The object pointer.
@param ap The AP node
@return none
"""
if ap is self.node2:
return
if self.node2 is not None:
@@ -38,6 +62,10 @@ class WifiLink(Link):
self.update_points()
def update_points(self):
"""! Update points function.
@param self The object pointer.
@return none
"""
if self.node2 is None:
return
pos1_x, pos1_y = self.node1.get_position()
@@ -47,11 +75,20 @@ class WifiLink(Link):
self.invisible_line.set_property("points", points)
def destroy(self):
"""! Destroy function.
@param self The object pointer.
@return none
"""
self.canvas_item.destroy()
self.node1 = None
self.node2 = None
def tooltip_query(self, tooltip):
"""! Destroy function.
@param self The object pointer.
@param tooltip The tooltip.
@return tooltip
"""
pos1_x, pos1_y = self.node1.get_position()
pos2_x, pos2_y = self.node2.get_position()
dx = pos2_x - pos1_x
@@ -64,13 +101,27 @@ class WifiLink(Link):
% (self.node1.node_index, self.node2.node_index, d,
mac.GetSsid(), mac.GetBssid()))
## WifiLinkMonitor class
class WifiLinkMonitor(object):
## @var access_points
# bssid -> node
## @var stations
# list of (sta_netdevice, viz_node, wifi_link)
def __init__(self, dummy_viz):
"""! Initialize function.
@param self The object pointer.
@param dummy_viz A dummy visualizer
@return none
"""
self.access_points = {} # bssid -> node
self.stations = [] # list of (sta_netdevice, viz_node, wifi_link)
def scan_nodes(self, viz):
"""! Scan nodes function.
@param self The object pointer.
@param viz The visualizer object
@return none
"""
for (sta_netdevice, viz_node, wifi_link) in self.stations:
wifi_link.destroy()
@@ -94,6 +145,11 @@ class WifiLinkMonitor(object):
#print "STAs: ", self.stations
def simulation_periodic_update(self, viz):
"""! Simulation Periodic Update function.
@param self The object pointer.
@param viz The visualizer object
@return none
"""
for (sta_netdevice, viz_node, wifi_link) in self.stations:
if not sta_netdevice.IsLinkUp():
wifi_link.set_ap(None)
@@ -106,6 +162,11 @@ class WifiLinkMonitor(object):
wifi_link.set_ap(ap)
def update_view(self, viz):
"""! Update View function.
@param self The object pointer.
@param viz The visualizer object
@return none
"""
for (dummy_sta_netdevice, dummy_viz_node, wifi_link) in self.stations:
if wifi_link is not None:
wifi_link.update_points()

View File

@@ -5,7 +5,35 @@ import goocanvas
import os.path
## SvgItem class
class SvgItem(goocanvas.ItemSimple):
## @var x
# x
## @var y
# y
## @var sx
# x step
## @var sy
# y step
## @var handle
# handle
## @var width
# width
## @var height
# height
## @var custom_width
# custom width
## @var custom_height
# custom height
## @var bounds_x1
# minimum x
## @var bounds_y1
# minimum y
## @var bounds_x2
# maximum x
## @var bounds_y2
# maximum y
## @var __gproperties__
# setup our custom properties
__gproperties__ = {
'x': (float, # property type
@@ -42,6 +70,10 @@ class SvgItem(goocanvas.ItemSimple):
}
def __init__(self, x, y, rsvg_handle, **kwargs):
"""
Initializer
@param self this object
"""
super(SvgItem, self).__init__(**kwargs)
assert isinstance(rsvg_handle, rsvg.Handle)
self.x = x
@@ -55,6 +87,13 @@ class SvgItem(goocanvas.ItemSimple):
self.custom_height = None
def do_set_property(self, pspec, value):
"""!
Set Property
@param self this object
@param pspec property name
@param value property value
@return exception if unknown property
"""
if pspec.name == 'x':
self.x = value
@@ -85,6 +124,11 @@ class SvgItem(goocanvas.ItemSimple):
raise AttributeError, 'unknown property %s' % pspec.name
def _size_changed(self):
"""!
Size Changed function
@param self this object
@return exception if unknown property
"""
if self.custom_width is None and self.custom_height is None:
self.width = self.handle.props.width
self.height = self.handle.props.height
@@ -107,6 +151,12 @@ class SvgItem(goocanvas.ItemSimple):
self.sy = self.custom_height / self.handle.props.height
def do_get_property(self, pspec):
"""!
Get Property
@param self this object
@param pspec property name
@return property value or exception if unknown property
"""
if pspec.name == 'x':
return self.x
@@ -126,17 +176,39 @@ class SvgItem(goocanvas.ItemSimple):
raise AttributeError, 'unknown property %s' % pspec.name
def do_simple_paint(self, cr, bounds):
"""!
Simple Paint function
@param self this object
@param cr rendered
@param bounds bounds
@return none
"""
cr.translate(self.x, self.y)
cr.scale(self.sx, self.sy)
self.handle.render_cairo(cr)
def do_simple_update(self, cr):
"""!
Simple Update function
@param self this object
@param cr rendered
@return none
"""
self.bounds_x1 = float(self.x)
self.bounds_y1 = float(self.y)
self.bounds_x2 = float(self.x + self.width)
self.bounds_y2 = float(self.y + self.height)
def do_simple_is_item_at(self, x, y, cr, is_pointer_event):
"""!
Simple Is Item At function
@param self this object
@param x the X position
@param y the Y position
@param cr rendered
@param is_pointer_event is the event a pointer event
@return true if at or false if not
"""
if ((x < self.x) or (x > self.x + self.width)) or ((y < self.y) or (y > self.y + self.height)):
return False
else: