org.openflow.gui.drawables
Class Link

java.lang.Object
  extended by org.pzgui.AbstractDrawable
      extended by org.openflow.gui.drawables.Link
All Implemented Interfaces:
Drawable, Edge<NodeWithPorts>

public class Link
extends AbstractDrawable
implements Edge<NodeWithPorts>

Information about a link.

Author:
David Underhill

Nested Class Summary
static class Link.LinkExistsException
          This exception is thrown if a link which already exists is tried to be re-created.
 
Field Summary
static int ARROW_HEAD_SIZE
          size of the arrow head
static float DEFAULT_PORT_NUM_ALPHA
          alpha channel of port numbers
static boolean DRAW_PORT_NUMBERS
          whether to draw port numbers each link is attached to
protected  NodeWithPorts dst
          the destination of this link
protected  short dstPort
          the port to which this link connects on the destination node
static java.awt.BasicStroke LINE_DEFAULT_STROKE
          how the draw a link
static int LINE_WIDTH
          thickness of a link
static int NUM_USAGE_COLORS
          how finely to precompute usage colors (larger => more memory and more preceise)
static java.awt.Font PORT_NUMBERS_FONT
          port number font
static int PORT_NUMBERS_OFFSET
          distance from the edge of an object to draw port numbers, if enabled
protected  NodeWithPorts src
          the source of this link
protected  short srcPort
          the port to which this link connects on the source node
static java.awt.Color TUNNEL_PAINT_DARK
          dark tunnel color
static java.awt.Color TUNNEL_PAINT_LIGHT
          light tunnel color
protected  LinkType type
          the type of this link
static java.awt.Color USAGE_COLOR_0
          how to color the link when it is completely unutilized
static java.awt.Color USAGE_COLOR_NEG
          how to color the link when it is negatively utilized (probably a special signal or error)
static java.awt.Color[] USAGE_COLORS
          array of precomputed usage colors
static java.awt.image.BufferedImage USAGE_LEGEND
          image containing the legend of usage colors from low to high utilization
static int WIRELESS_ARC_DEGREES
          how many degrees the arc covers
static int WIRELESS_ARC_SIZE
          bounding square around the arc
static int WIRELESS_ARCS_SPACE_BETWEEN
          amount of space between arcs
static java.awt.BasicStroke WIRELESS_LINE_DEFAULT_STROKE
          how to draw the line for wireless links
 
Constructor Summary
Link(LinkType linkType, NodeWithPorts dst, short dstPort, NodeWithPorts src, short srcPort)
          Constructs a new link between src and dst.
 
Method Summary
 boolean contains(int x, int y)
          Whether these x, y coordinates fall are contained by the object
 void disconnect(BackendConnection conn)
          Disconnects this link from its attached ports and stops tracking all statistics associated with this link.
protected  void drawFailed(java.awt.Graphics2D gfx)
          draw an "X" over the node to indicate failure
 void drawObject(java.awt.Graphics2D gfx)
          Draws the link
 void drawOutline(java.awt.Graphics2D gfx, java.awt.Paint outlineColor, double ratio)
          Draw an outline around the link.
 void drawPortNumbers(java.awt.Graphics2D gfx, float alpha)
          draws port numbers by the link drawing's endpoints with the specified alpha
 void drawTunnel(java.awt.Graphics2D gfx, int linkWidth)
          draws a tunnel in the area used by the middle of the link
 void drawWiredLink(java.awt.Graphics2D gfx)
          draws the link as a wired link between endpoints
 void drawWirelessLink(java.awt.Graphics2D gfx)
          draws the link as a wireless link between endpoints
 boolean equals(java.lang.Object o)
           
static java.awt.geom.GeneralPath getArrowHead(int sz, int x1, int y1, int x2, int y2)
          Gets a path for an arrow head on an arrow drawn from x1,y1 to x2,y2.
 double getCurrentDataRate()
          Returns the current bandwidth being sent through the link in ps or a value <0 if those stats are not currently being tracked.
 double getCurrentUtilization()
          Returns the current utilization of the link in the range [0, 1] or -1 if stats are not currently being tracked for this.
 NodeWithPorts getDestination()
          get the destination of this link
 double getMaximumDataRate()
          returns the maximum bandwidth which can be sent through the link in bps
 short getMyPort(NodeWithPorts p)
          Gets the port number associated with the specified endpoint.
 NodeWithPorts getOther(NodeWithPorts p)
          Given one endpoint of the link, return the other endpoint.
 short getOtherPort(NodeWithPorts p)
          Gets the port number associated with the endpoint which is not p.
 NodeWithPorts getSource()
          get the souce of this link
 LinkStats getStats(Match m)
          Gets the LinkStats associated with the specified Match, if any
static java.awt.Color getUsageColor(float usage)
          Gets the color associated with a particular usage value.
 int hashCode()
           
 boolean isFailed()
          Returns true if the link has failed.
 boolean isWired()
          returns true if the link is a wired link
 boolean isWireless()
          returns true if the link is a wireless link
 void setColorBasedOnCurrentUtilization()
          sets the color this link will be drawn based on the current utilization
 void setFailed(boolean b)
          Sets whether the link has failed.
 LinkType setLinkLink()
          gets the type of this link
 void setLinkLink(LinkType type)
          sets the type of this link
 void setMaximumDataRate(double bps)
          sets the maximum bandwidth which can be sent through the link in bps
 void stopTrackingAllStats(BackendConnection conn)
          Stop tracking and clear all statistics associated with this link.
 void stopTrackingStats(Match m, BackendConnection conn)
          Tells the link to stop tracking stats for the specified Match m.
 java.lang.String toString()
           
 void trackStats(int pollInterval_msec, Match m, BackendConnection conn)
          Tells the link to acquire the specified stats.
 LinkStats trackStats(Match m)
          Tells the link to setup stats for specified Match but do not acquire them automatically.
 void trackStats(Match m, BackendConnection conn)
          Tells the link to acquire the specified stats (once).
 LinkStats trackStats(Match m, int xid, boolean isPolling)
          Tells the link to setup stats for specified Match but do not acquire them automatically.
 void updateStats(Match m, AggregateStatsReply reply)
          update this links with the latest stats reply about this link
 
Methods inherited from class org.pzgui.AbstractDrawable
drag, drawBeforeObject, isDrawn, isHovered, isSelected, setHovered, setSelected, unsetDrawn
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

USAGE_COLOR_NEG

public static java.awt.Color USAGE_COLOR_NEG
how to color the link when it is negatively utilized (probably a special signal or error)


USAGE_COLOR_0

public static java.awt.Color USAGE_COLOR_0
how to color the link when it is completely unutilized


type

protected LinkType type
the type of this link


src

protected NodeWithPorts src
the source of this link


srcPort

protected short srcPort
the port to which this link connects on the source node


dst

protected NodeWithPorts dst
the destination of this link


dstPort

protected short dstPort
the port to which this link connects on the destination node


LINE_WIDTH

public static final int LINE_WIDTH
thickness of a link

See Also:
Constant Field Values

LINE_DEFAULT_STROKE

public static final java.awt.BasicStroke LINE_DEFAULT_STROKE
how the draw a link


ARROW_HEAD_SIZE

public static final int ARROW_HEAD_SIZE
size of the arrow head

See Also:
Constant Field Values

WIRELESS_ARC_SIZE

public static final int WIRELESS_ARC_SIZE
bounding square around the arc

See Also:
Constant Field Values

WIRELESS_ARCS_SPACE_BETWEEN

public static final int WIRELESS_ARCS_SPACE_BETWEEN
amount of space between arcs

See Also:
Constant Field Values

WIRELESS_ARC_DEGREES

public static final int WIRELESS_ARC_DEGREES
how many degrees the arc covers

See Also:
Constant Field Values

WIRELESS_LINE_DEFAULT_STROKE

public static final java.awt.BasicStroke WIRELESS_LINE_DEFAULT_STROKE
how to draw the line for wireless links


DRAW_PORT_NUMBERS

public static boolean DRAW_PORT_NUMBERS
whether to draw port numbers each link is attached to


PORT_NUMBERS_OFFSET

public static final int PORT_NUMBERS_OFFSET
distance from the edge of an object to draw port numbers, if enabled

See Also:
Constant Field Values

DEFAULT_PORT_NUM_ALPHA

public static float DEFAULT_PORT_NUM_ALPHA
alpha channel of port numbers


PORT_NUMBERS_FONT

public static final java.awt.Font PORT_NUMBERS_FONT
port number font


TUNNEL_PAINT_DARK

public static final java.awt.Color TUNNEL_PAINT_DARK
dark tunnel color


TUNNEL_PAINT_LIGHT

public static final java.awt.Color TUNNEL_PAINT_LIGHT
light tunnel color


NUM_USAGE_COLORS

public static final int NUM_USAGE_COLORS
how finely to precompute usage colors (larger => more memory and more preceise)

See Also:
Constant Field Values

USAGE_COLORS

public static final java.awt.Color[] USAGE_COLORS
array of precomputed usage colors


USAGE_LEGEND

public static final java.awt.image.BufferedImage USAGE_LEGEND
image containing the legend of usage colors from low to high utilization

Constructor Detail

Link

public Link(LinkType linkType,
            NodeWithPorts dst,
            short dstPort,
            NodeWithPorts src,
            short srcPort)
     throws Link.LinkExistsException
Constructs a new link between src and dst.

Parameters:
linkType - the type of this link
dst - the destination of this link
dstPort - the destination port of the link (on dst)
src - the source node of data on this link
srcPort - the source port of the link (on src)
Throws:
Link.LinkExistsException - thrown if the link already exists
Method Detail

disconnect

public void disconnect(BackendConnection conn)
                throws java.io.IOException
Disconnects this link from its attached ports and stops tracking all statistics associated with this link. stopTrackingAllStats() is called by this method.

Throws:
java.io.IOException

getSource

public NodeWithPorts getSource()
get the souce of this link

Specified by:
getSource in interface Edge<NodeWithPorts>

getDestination

public NodeWithPorts getDestination()
get the destination of this link

Specified by:
getDestination in interface Edge<NodeWithPorts>

getOther

public NodeWithPorts getOther(NodeWithPorts p)
Given one endpoint of the link, return the other endpoint. Throws an error if p is neither the source or destination of this link.

Specified by:
getOther in interface Edge<NodeWithPorts>

getMyPort

public short getMyPort(NodeWithPorts p)
Gets the port number associated with the specified endpoint.


getOtherPort

public short getOtherPort(NodeWithPorts p)
Gets the port number associated with the endpoint which is not p.


isWired

public boolean isWired()
returns true if the link is a wired link


isWireless

public boolean isWireless()
returns true if the link is a wireless link


setLinkLink

public LinkType setLinkLink()
gets the type of this link


setLinkLink

public void setLinkLink(LinkType type)
sets the type of this link


getMaximumDataRate

public double getMaximumDataRate()
returns the maximum bandwidth which can be sent through the link in bps


setMaximumDataRate

public void setMaximumDataRate(double bps)
sets the maximum bandwidth which can be sent through the link in bps


isFailed

public boolean isFailed()
Returns true if the link has failed.


setFailed

public void setFailed(boolean b)
Sets whether the link has failed.


drawObject

public void drawObject(java.awt.Graphics2D gfx)
Draws the link

Specified by:
drawObject in interface Drawable
Specified by:
drawObject in class AbstractDrawable

drawFailed

protected void drawFailed(java.awt.Graphics2D gfx)
draw an "X" over the node to indicate failure


drawOutline

public void drawOutline(java.awt.Graphics2D gfx,
                        java.awt.Paint outlineColor,
                        double ratio)
Draw an outline around the link.

Parameters:
gfx - where to draw
outlineColor - color of the outline
ratio - how big to make the outline (relative to the bounding box of this link)

drawPortNumbers

public void drawPortNumbers(java.awt.Graphics2D gfx,
                            float alpha)
draws port numbers by the link drawing's endpoints with the specified alpha


drawWiredLink

public void drawWiredLink(java.awt.Graphics2D gfx)
draws the link as a wired link between endpoints


getArrowHead

public static java.awt.geom.GeneralPath getArrowHead(int sz,
                                                     int x1,
                                                     int y1,
                                                     int x2,
                                                     int y2)
Gets a path for an arrow head on an arrow drawn from x1,y1 to x2,y2.

Parameters:
sz - Size of the arrow head
x1 - initial x coordinate
y1 - initial y coordinate
x2 - final x coordinate
y2 - final y coordinate
Returns:
path describing an arrow head

drawWirelessLink

public void drawWirelessLink(java.awt.Graphics2D gfx)
draws the link as a wireless link between endpoints


drawTunnel

public void drawTunnel(java.awt.Graphics2D gfx,
                       int linkWidth)
draws a tunnel in the area used by the middle of the link


getStats

public LinkStats getStats(Match m)
Gets the LinkStats associated with the specified Match, if any


trackStats

public void trackStats(Match m,
                       BackendConnection conn)
                throws java.io.IOException
Tells the link to acquire the specified stats (once).

Parameters:
m - what statistics to get
conn - connection to talk to the backend over
Throws:
java.io.IOException - thrown if the connection fails

trackStats

public void trackStats(int pollInterval_msec,
                       Match m,
                       BackendConnection conn)
                throws java.io.IOException
Tells the link to acquire the specified stats.

Parameters:
pollInterval_msec - how often to refresh the stats (0 = only once)
m - what statistics to get
conn - connection to talk to the backend over
Throws:
java.io.IOException - thrown if the connection fails

trackStats

public LinkStats trackStats(Match m)
Tells the link to setup stats for specified Match but do not acquire them automatically.

Parameters:
m - the match to setup stats for

trackStats

public LinkStats trackStats(Match m,
                            int xid,
                            boolean isPolling)
Tells the link to setup stats for specified Match but do not acquire them automatically.

Parameters:
m - the match to setup stats for
xid - the xid of the request which is acquiring stats for m
isPolling - whether the stats are being polled with xid

stopTrackingStats

public void stopTrackingStats(Match m,
                              BackendConnection conn)
                       throws java.io.IOException
Tells the link to stop tracking stats for the specified Match m. If m was being polled, then a message will be sent to the backend to terminate the polling of the message.

Parameters:
m - the match to stop collecting statistics for
conn - the connection over which to tell the backend to stop polling
Throws:
java.io.IOException - thrown if the connection fails

stopTrackingAllStats

public void stopTrackingAllStats(BackendConnection conn)
                          throws java.io.IOException
Stop tracking and clear all statistics associated with this link.

Parameters:
conn - the connection to send POLL_STOP messages over
Throws:
java.io.IOException - thrown if the connection fails

updateStats

public void updateStats(Match m,
                        AggregateStatsReply reply)
update this links with the latest stats reply about this link


getCurrentDataRate

public double getCurrentDataRate()
Returns the current bandwidth being sent through the link in ps or a value <0 if those stats are not currently being tracked.


getCurrentUtilization

public double getCurrentUtilization()
Returns the current utilization of the link in the range [0, 1] or -1 if stats are not currently being tracked for this.


setColorBasedOnCurrentUtilization

public void setColorBasedOnCurrentUtilization()
sets the color this link will be drawn based on the current utilization


getUsageColor

public static java.awt.Color getUsageColor(float usage)
Gets the color associated with a particular usage value.


contains

public boolean contains(int x,
                        int y)
Description copied from interface: Drawable
Whether these x, y coordinates fall are contained by the object

Specified by:
contains in interface Drawable
Specified by:
contains in class AbstractDrawable

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object