org.openflow.gui
Class ConnectionHandler

java.lang.Object
  extended by org.openflow.gui.ConnectionHandler
All Implemented Interfaces:
MessageProcessor<OFGMessage>

public class ConnectionHandler
extends java.lang.Object
implements MessageProcessor<OFGMessage>

Processes messages from a connection and updates the associated topology accordingly. It also maintains the network topology data structure associated with it. This class should be extended to process new messages in extended OFG versions which add new message types.

Author:
David Underhill

Constructor Summary
ConnectionHandler(Topology topo, java.lang.String ip, int port, boolean subscribeSwitches, boolean subscribeLinks)
          Create a connection bound to the server at the specified address and port which will be used to populate the specified topology.
 
Method Summary
 void connectionStateChange()
          Called when the backend has been disconnected or reconnected
 OFGMessage decode(int len, java.io.DataInput in)
          Constructs the object representing the received message.
 BackendConnection<OFGMessage> getConnection()
           
 Topology getTopology()
           
protected  void handleNewSwitch(OpenFlowSwitch s)
          Handles a new switch by requesting its links and description if Options.AUTO_REQUEST_LINK_INFO_FOR_NEW_SWITCH is true.
 boolean isSubscribeToLinkChanges()
          Returns whether the connection is subscribed to link changes
 boolean isSubscribeToSwitchChanges()
          Returns whether the connection is subscribed to switch changes
protected  void logLinkMissing(java.lang.String msg, java.lang.String why, long dstDPID, short dstPort, long srcDPID, short srcPort)
          Prints an error message about a missing link.
protected  void logNodeMissing(java.lang.String msg, java.lang.String why, long id)
          Prints an error message about a missing node.
 void process(OFGMessage msg)
          Handles messages received from the backend
protected  void processAuthRequest(AuthRequest req)
          Query the user for login credentials and send them to the backend.
protected  void processAuthStatus(AuthStatus status)
          Let the user know about the authentication status contained in msg.
protected  void processDrawableNodeAdd(Node n)
          add new node to the topology
protected  void processEchoReply(int xid)
          Handles the echo reply by simply printing a message to stdout.
protected  void processEchoRequest(int xid)
          Handles the echo request by replying.
protected  Node processNodeAdd(Node n)
          Add a new node to the topology.
 void setSubscribeToLinkChanges(boolean b)
          Sets whether the connection is subscribed to link changes and sends the appropriate subscription request if this is different.
 void setSubscribeToSwitchChanges(boolean b)
          Sets whether the connection is subscribed to switch changes and sends the appropriate subscription request if this is different.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHandler

public ConnectionHandler(Topology topo,
                         java.lang.String ip,
                         int port,
                         boolean subscribeSwitches,
                         boolean subscribeLinks)
Create a connection bound to the server at the specified address and port which will be used to populate the specified topology.

Parameters:
topo - the topology this connection will interact with
ip - the IP where the server lives
port - the port the server listens on
subscribeSwitches - whether to subscribe to switch changes
subscribeLinks - whether to subscribe to link changes
Method Detail

getConnection

public BackendConnection<OFGMessage> getConnection()

getTopology

public Topology getTopology()

connectionStateChange

public void connectionStateChange()
Called when the backend has been disconnected or reconnected

Specified by:
connectionStateChange in interface MessageProcessor<OFGMessage>

decode

public OFGMessage decode(int len,
                         java.io.DataInput in)
                  throws java.io.IOException
Constructs the object representing the received message. The message is known to be of length len and len - 4 bytes representing the rest of the message should be extracted from buf.

Specified by:
decode in interface MessageProcessor<OFGMessage>
Throws:
java.io.IOException

process

public void process(OFGMessage msg)
Handles messages received from the backend

Specified by:
process in interface MessageProcessor<OFGMessage>

processAuthRequest

protected void processAuthRequest(AuthRequest req)
Query the user for login credentials and send them to the backend. If msg does not supply a salt of at least 20B then a message is instead printed to stderr and the request is ignored.


processAuthStatus

protected void processAuthStatus(AuthStatus status)
Let the user know about the authentication status contained in msg. A message is printed to stdout if authentication succeeded. Otherwise, a dialog box pops up to notify the user of the authentication failure.


processEchoRequest

protected void processEchoRequest(int xid)
Handles the echo request by replying.


processEchoReply

protected void processEchoReply(int xid)
Handles the echo reply by simply printing a message to stdout.


handleNewSwitch

protected void handleNewSwitch(OpenFlowSwitch s)
Handles a new switch by requesting its links and description if Options.AUTO_REQUEST_LINK_INFO_FOR_NEW_SWITCH is true.

Parameters:
s - the new switch

processDrawableNodeAdd

protected void processDrawableNodeAdd(Node n)
add new node to the topology


processNodeAdd

protected Node processNodeAdd(Node n)
Add a new node to the topology. The default implementation assumes the new node is a OpenFlowSwitch (unless its type is host). The caller will add the returned node to the topology if it is a subclass of NodeWithPorts. The default caller will also call handleNewSwitch() if an OpenFlowSwitch is returned.


logNodeMissing

protected void logNodeMissing(java.lang.String msg,
                              java.lang.String why,
                              long id)
Prints an error message about a missing node.


logLinkMissing

protected void logLinkMissing(java.lang.String msg,
                              java.lang.String why,
                              long dstDPID,
                              short dstPort,
                              long srcDPID,
                              short srcPort)
Prints an error message about a missing link.


shutdown

public void shutdown()

isSubscribeToSwitchChanges

public boolean isSubscribeToSwitchChanges()
Returns whether the connection is subscribed to switch changes


setSubscribeToSwitchChanges

public void setSubscribeToSwitchChanges(boolean b)
                                 throws java.io.IOException
Sets whether the connection is subscribed to switch changes and sends the appropriate subscription request if this is different.

Throws:
java.io.IOException

isSubscribeToLinkChanges

public boolean isSubscribeToLinkChanges()
Returns whether the connection is subscribed to link changes


setSubscribeToLinkChanges

public void setSubscribeToLinkChanges(boolean b)
                               throws java.io.IOException
Sets whether the connection is subscribed to link changes and sends the appropriate subscription request if this is different.

Throws:
java.io.IOException