Skip to content

Commit

Permalink
added auto-icon guessing for interop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Sherwood committed Apr 9, 2011
1 parent bb173d5 commit b0199d1
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 25 deletions.
Binary file added gui/images/bcm_k49_ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/images/indigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/images/procurve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/images/switch-nec-ip8800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/images/unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gui/src/org/openflow/gui/ConnectionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected Node processNodeAdd(org.openflow.gui.net.protocol.Node n) {
if(n.nodeType == NodeType.HOST)
return new Host(n.id);
else
return new OpenFlowSwitch(n.id, n.nodeType);
return new OpenFlowSwitch(this.getConnection(), n.id, n.nodeType);
}

/** remove nodes from the topology */
Expand Down
3 changes: 2 additions & 1 deletion gui/src/org/openflow/gui/OpenFlowGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private OpenFlowGUI() { /* this class may not be instantiated */ }
* Run a simple version of the GUI by starting a single connection which
* will populate a single topology drawn by a PZLayoutManager.
*/
public static void main(String args[]) {
@SuppressWarnings("unchecked")
public static void main(String args[]) {
Pair<String, Short> serverPort = getServer(args);
String server = serverPort.a;
short port = serverPort.b;
Expand Down
9 changes: 6 additions & 3 deletions gui/src/org/openflow/gui/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public final class Options {
/** default server IP, if any */
public static final String DEFAULT_SERVER_IP = "127.0.0.1";
public static final String DEFAULT_SERVER_IP = "lavi-controller.openflow.interop.net";

/** default port to connect to the server on */
public static final short DEFAULT_PORT = 2503;
Expand All @@ -21,17 +21,20 @@ public final class Options {
public static final boolean AUTO_TRACK_STATS_FOR_NEW_LINK = true;

/** how often to refresh basic port statistics */
public static final int STATS_REFRESH_RATE_MSEC = 2000;
public static final int STATS_REFRESH_RATE_MSEC = 1000;

/**
* Whether links between nodes should be represented using one undirected
* or two directed links.
*/
public static final boolean USE_DIRECTED_LINKS = true;
public static final boolean USE_DIRECTED_LINKS = false;

/** whether to use a light or dark color scheme */
public static final boolean USE_LIGHT_COLOR_SCHEME = true;

/** ImageDirectory **/
public static String ImageDir = "images";

/* prevents this class from being instantiated */
private Options() {}
}
58 changes: 41 additions & 17 deletions gui/src/org/openflow/gui/drawables/OpenFlowSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,71 @@
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

import org.openflow.gui.Options;
import org.openflow.gui.net.BackendConnection;
import org.openflow.gui.net.protocol.NodeType;
import org.openflow.gui.net.protocol.OFGMessage;
import org.openflow.protocol.SwitchDescriptionStats;
import org.openflow.util.string.DPIDUtil;
import org.pzgui.icon.Icon;
import org.pzgui.icon.ImageIcon;
import org.pzgui.icon.ShapeIcon;


/**
* Describes an OpenFlow switch.
*
* @author David Underhill
*/
public class OpenFlowSwitch extends NodeWithPorts {
public OpenFlowSwitch(long dpid) {
this(dpid, NodeType.OPENFLOW_SWITCH);
public OpenFlowSwitch(BackendConnection<OFGMessage> conn, long dpid) {
this(conn, dpid, NodeType.OPENFLOW_SWITCH);
}

public OpenFlowSwitch(long dpid, NodeType nt) {
this("", 0, 0, dpid, nt);
public OpenFlowSwitch(BackendConnection<OFGMessage> conn, long dpid, NodeType nt) {
this(conn, "", 0, 0, dpid, nt);
}

public OpenFlowSwitch(String name, int x, int y, long dpid) {
this(name, x, y, dpid, NodeType.OPENFLOW_SWITCH);
public OpenFlowSwitch(BackendConnection<OFGMessage> conn, String name, int x, int y, long dpid) {
this(conn, name, x, y, dpid, NodeType.OPENFLOW_SWITCH);
}

public OpenFlowSwitch(String name, int x, int y, long dpid, NodeType nt) {
public OpenFlowSwitch(BackendConnection<OFGMessage> conn, String name, int x, int y, long dpid, NodeType nt) {
super(NodeType.OPENFLOW_SWITCH, name, x, y, newDefaultOpenFlowSwitchShape(nt));
this.datapathID = dpid;
this.conn = conn;
}

/** creates a new OpenFlowSwitch icon */
public static final ShapeIcon newDefaultOpenFlowSwitchShape(NodeType nt) {
Paint fill;
public static final Icon newDefaultOpenFlowSwitchShape(NodeType nt) {
if(nt == NodeType.OPENFLOW_WIRELESS_ACCESS_POINT)
fill = DEFAULT_FILL_WIFI;
return new ShapeIcon(DEFAULT_SHAPE, DEFAULT_FILL_WIFI);
else
fill = DEFAULT_FILL;

return new ShapeIcon(DEFAULT_SHAPE, fill);
}

return new ImageIcon(Options.ImageDir + "/unknown.png", (float) 0.3);
}

private void updateIcon() {
if (! isStringSet(manufacturer))
return;
if (this.manufacturer.startsWith("HP-Labs")) {
setIcon(new ImageIcon(Options.ImageDir + "/procurve.png",(float)0.05));
} else if (this.manufacturer.startsWith("Stanford")) {
setIcon(new ImageIcon(Options.ImageDir + "/switch-nec-ip8800.png",(float)0.05));
} else if (this.manufacturer.startsWith("Big")) {
setIcon(new ImageIcon(Options.ImageDir + "/indigo.png", (float)0.05));
}
// else leave as blue dot
}

// ------------------- Drawing ------------------ //

BackendConnection<OFGMessage> conn;

/** default size of the DEFAULT_SHAPE */
public static final int DEFAULT_SIZE = 40;

Expand All @@ -72,7 +94,7 @@ public void drawObject(Graphics2D gfx) {

// display switch description stats on mouse over
if(this.isHovered() || this.isSelected()) {
if(isStringSet(desc)) {
if(isStringSet(desc)) {
gfx.drawString(desc, x, y);
y += gfx.getFontMetrics().getHeight();
}
Expand Down Expand Up @@ -168,12 +190,14 @@ public void setSwitchDescription(SwitchDescriptionStats stats) {
serial_num = stats.serial_num;
desc = stats.desc;
descUpdateTime = System.currentTimeMillis();
updateIcon();
}


// -------------------- Other ------------------- //

public String toString() {

public String toString() {
return getName() + "; dpid=" + DPIDUtil.dpidToHex(getID());
}
}
4 changes: 2 additions & 2 deletions gui/src/org/openflow/gui/drawables/VirtualOpenFlowSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class VirtualOpenFlowSwitch extends OpenFlowSwitch {
private final int virtualSwitchIndex;

public VirtualOpenFlowSwitch(long parentDPID, int virtualSwitchIndex) {
super(parentDPID);
super(null, parentDPID);
this.virtualSwitchIndex = virtualSwitchIndex;
}

public VirtualOpenFlowSwitch(String name, int x, int y, long parentDPID, int virtualSwitchIndex) {
super(name, x, y, parentDPID);
super(null, name, x, y, parentDPID);
this.virtualSwitchIndex = virtualSwitchIndex;
}

Expand Down
6 changes: 5 additions & 1 deletion gui/src/org/openflow/gui/net/BackendConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void connect() {
System.out.println("Now connected to server");
stats.connected();
msgProcessor.connectionStateChange(true);
}
}

/** tells the connection to disconnect and then connect again */
public void reconnect() {
Expand Down Expand Up @@ -397,4 +397,8 @@ public String getServerAddr() {
public int getServerPort() {
return serverPort;
}

public SocketConnection getSocketConnection() {
return conn;
}
}

3 comments on commit b0199d1

@yapkke
Copy link
Collaborator

@yapkke yapkke commented on b0199d1 Apr 10, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good to push features into this repository but interop specific stuff should be left out! Please clean those out. E.g.
public static final String DEFAULT_SERVER_IP = "lavi-controller.openflow.interop.net";

@capveg
Copy link
Collaborator

@capveg capveg commented on b0199d1 Apr 11, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yapkke
Copy link
Collaborator

@yapkke yapkke commented on b0199d1 Apr 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The power of social coding... your mistake has been spotted!!! :P

Please sign in to comment.