private static final byte OF10_VERSION_ID = EncodeConstants.OF10_VERSION_ID;
/** Version number of OpenFlow 1.3 protocol */
private static final byte OF13_VERSION_ID = EncodeConstants.OF13_VERSION_ID;
+ private static final short OF_PACKETIN = 10;
private static final Logger LOGGER = LoggerFactory.getLogger(OFVersionDetector.class);
+ private volatile boolean filterPacketIns;
/**
* Constructor of class.
LOGGER.trace("Creating OFVersionDetector");
}
+ public void setFilterPacketIns(final boolean enabled) {
+ filterPacketIns = enabled;
+ }
+
@Override
- protected void decode(final ChannelHandlerContext chc, final ByteBuf bb, final List<Object> list) throws Exception {
- if (bb.readableBytes() == 0) {
+ protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) {
+ if (!in.isReadable()) {
LOGGER.debug("not enough data");
- bb.release();
+ in.release();
return;
}
- byte version = bb.readByte();
- if ((version == OF13_VERSION_ID) || (version == OF10_VERSION_ID)) {
+
+ final byte version = in.readByte();
+ if (version == OF13_VERSION_ID || version == OF10_VERSION_ID) {
LOGGER.debug("detected version: {}", version);
- ByteBuf messageBuffer = bb.slice();
- list.add(new VersionMessageWrapper(version, messageBuffer));
- messageBuffer.retain();
+ if (!filterPacketIns || OF_PACKETIN != in.getUnsignedByte(in.readerIndex())) {
+ ByteBuf messageBuffer = in.slice();
+ out.add(new VersionMessageWrapper(version, messageBuffer));
+ messageBuffer.retain();
+ } else {
+ LOGGER.debug("dropped packetin");
+ }
} else {
LOGGER.warn("detected version: {} - currently not supported", version);
}
- bb.skipBytes(bb.readableBytes());
+ in.skipBytes(in.readableBytes());
}
-
}
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandler;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
+import org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector;
+import org.opendaylight.openflowjava.protocol.impl.core.PipelineHandlers;
import org.opendaylight.openflowjava.statistics.CounterEventTypes;
import org.opendaylight.openflowjava.statistics.StatisticsCounters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
private OutboundQueueManager<?> outputManager;
private boolean disconnectOccured = false;
private final StatisticsCounters statisticsCounters;
+ private OFVersionDetector versionDetector;
private final InetSocketAddress address;
/**
this.address = address;
channel.pipeline().addLast(output);
statisticsCounters = StatisticsCounters.getInstance();
+
LOG.debug("ConnectionAdapter created");
}
@Override
public void fireConnectionReadyNotification() {
+ versionDetector = (OFVersionDetector) channel.pipeline().get(PipelineHandlers.OF_VERSION_DETECTOR.name());
+ Preconditions.checkState(versionDetector != null);
+
new Thread(new Runnable() {
@Override
public void run() {
Channel getChannel() {
return channel;
}
+
+ @Override
+ public void setPacketInFiltering(final boolean enabled) {
+ versionDetector.setFilterPacketIns(enabled);
+ LOG.debug("PacketIn filtering {}abled", enabled ? "en" : "dis");
+ }
}