Skip to content

Instantly share code, notes, and snippets.

@oshothebig
Created September 3, 2011 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshothebig/1190953 to your computer and use it in GitHub Desktop.
Save oshothebig/1190953 to your computer and use it in GitHub Desktop.
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof OFMessage) {
OFMessage in = (OFMessage)e.getMessage();
log.debug("Message received: message({}), switch({})", in.getType(), ctx.getChannel().getRemoteAddress());
switch (in.getType()) {
case HELLO:
ctx.getChannel().write(factory.getMessage(OFType.FEATURES_REQUEST));
case ECHO_REQUEST:
int xid = in.getXid();
OFMessage out = factory.getMessage(OFType.ECHO_REPLY);
out.setXid(xid);
// replies an ECHO_REPLY message
ctx.getChannel().write(out);
break;
case FEATURES_REPLY:
log.info("Handshake completed: switch({})", ctx.getChannel().getRemoteAddress());
break;
case ERROR:
OFError error = (OFError)in;
log.warn("Error occurred: type({}), switch({})", error.getErrorType(), ctx.getChannel().getRemoteAddress());
break;
default:
controller.invokeMessageListeners(ctx.getChannel(), in);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment