This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static class OpenFlowDecoder extends OneToOneDecoder { | |
@Override | |
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { | |
if (!(msg instanceof ChannelBuffer)) { | |
return msg; | |
} | |
ChannelBuffer channelBuffer = (ChannelBuffer)msg; | |
ByteBuffer byteBuffer = channelBuffer.toByteBuffer(); | |
List<OFMessage> messages = factory.parseMessages(byteBuffer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static class OpenFlowEncoder extends OneToOneEncoder { | |
@Override | |
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { | |
if (msg instanceof OFMessage) { | |
OFMessage response = (OFMessage) msg; | |
// may have an bad effect on performance | |
ByteBuffer buffer = ByteBuffer.allocate(response.getLength()); | |
response.writeTo(buffer); | |
buffer.flip(); | |
return ChannelBuffers.wrappedBuffer(buffer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ChannelPipeline getPipeline() throws Exception { | |
ChannelPipeline pipeline = Channels.pipeline(); | |
// add the binary codec combination first | |
pipeline.addLast("framer", new LengthFieldBasedFrameDecoder( | |
MAXIMUM_PACKET_LENGTH, LENGTH_FIELD_OFFSET, LENGTH_FIELD_LENGTH, LENGTH_FIELD_MODIFICATION, 0)); | |
pipeline.addLast("decoder", new OpenFlowDecoder()); | |
pipeline.addLast("encoder", new OpenFlowEncoder()); | |
// add then the business logic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | |
OFMessage out = factory.getMessage(OFType.HELLO); | |
ctx.getChannel().write(out); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// リピータハブとして動作 | |
MessageListener hub = new MessageListener() { | |
public void messageReceived(Channel channel, OFMessage msg) { | |
if (msg.getType() == OFType.PACKET_IN) { | |
OFPacketIn in = (OFPacketIn)msg; | |
OFPacketOut out = (OFPacketOut)factory.getMessage(OFType.PACKET_OUT); | |
out.setBufferId(in.getBufferId()); | |
out.setInPort(in.getInPort()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ofp_header { | |
uint8_t version; /* OFP_VERSION. */ | |
uint8_t type; /* One of the OFPT_ constants. */ | |
uint16_t length; /* Length including this ofp_header. */ | |
uint32_t xid; /* Transaction id associated with this packet. | |
Replies use the same id as was in the request | |
to facilitate pairing. */ | |
} | |
OFP_ASSERT(sizeof(struct ofp_header) == 8); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2011, Sho SHIMIZU | |
* | |
* Permission is hereby granted, free of charge, to any person | |
* obtaining a copy of this software and associated documentation | |
* files (the "Software"), to deal in the Software without | |
* restriction, including without limitation the rights to use, | |
* copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the | |
* Software is furnished to do so, subject to the following |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { | |
OFMessage in = (OFMessage) e.getMessage(); | |
OFMessage out; | |
switch (in.getType()) { | |
case HELLO: | |
break; | |
case ECHO_REQUEST: | |
out = fakeSwitch.echoReplyData((OFEchoRequest)in); | |
ctx.getChannel().write(out); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
486 ./datapath/actions.c | |
578 ./datapath/brcompat_main.c | |
271 ./datapath/checksum.c | |
149 ./datapath/checksum.h | |
84 ./datapath/compat.h | |
2241 ./datapath/datapath.c | |
195 ./datapath/datapath.h | |
74 ./datapath/dp_notify.c | |
38 ./datapath/dp_sysfs.h | |
419 ./datapath/dp_sysfs_dp.c |
OlderNewer