Bug 4827: Extend ByteToMessage decoder to support peer constraints 71/35771/15
authorMilos Fabian <milfabia@cisco.com>
Fri, 4 Mar 2016 09:53:36 +0000 (10:53 +0100)
committerMilos Fabian <milfabia@cisco.com>
Thu, 5 May 2016 10:41:36 +0000 (12:41 +0200)
Optionally support MultiPathSupport in ByteToMessageDecoder.

Change-Id: I3296e73900dbe6b292f7cdaa57bcea8f0ca6e3d7
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java

index b83de5d0cebb2f31d32bec2a9bc969e652905599..afb01154ce9b13e595604fee769e076d321561de 100644 (file)
@@ -16,6 +16,9 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.PeerConstraint;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraintProvider;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.PeerSpecificParserConstraintImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -25,11 +28,17 @@ import org.slf4j.LoggerFactory;
 final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
     private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
     private final MessageRegistry registry;
+    private final PeerSpecificParserConstraintProvider constraints;
 
     public BGPByteToMessageDecoder(final MessageRegistry registry) {
+        this.constraints = new PeerSpecificParserConstraintImpl();
         this.registry = Preconditions.checkNotNull(registry);
     }
 
+    public <T extends PeerConstraint> boolean addDecoderConstraint(final Class<T> classType, final T peerConstraint) {
+        return this.constraints.addPeerConstraint(classType, peerConstraint);
+    }
+
     @Override
     protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws BGPDocumentedException,
             BGPParsingException {
@@ -37,7 +46,7 @@ final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
             }
-            out.add(this.registry.parseMessage(in));
+            out.add(this.registry.parseMessage(in, this.constraints));
         } else {
             LOG.trace("No more content in incoming buffer.");
         }
index ce8f658cf1d3991241aee1cf61166e2acbde5d43..31ba665d1b75ecd1a7df21a58a675a8c29230869 100644 (file)
@@ -18,6 +18,7 @@ import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPipeline;
 import io.netty.channel.SimpleChannelInboundHandler;
 import java.io.IOException;
 import java.util.Date;
@@ -30,6 +31,8 @@ import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BgpExtendedMessageUtil;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.MultiPathSupportImpl;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionStatistics;
@@ -174,6 +177,13 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
         this.tableTypes = tats;
         this.addPathTypes = addPathCapabilitiesList;
 
+        if (! this.addPathTypes.isEmpty()) {
+            final ChannelPipeline pipeline = this.channel.pipeline();
+            final BGPByteToMessageDecoder decoder = pipeline.get(BGPByteToMessageDecoder.class);
+            decoder.addDecoderConstraint(MultiPathSupport.class,
+                    MultiPathSupportImpl.createParserMultiPathSupport(this.addPathTypes));
+        }
+
         if (this.holdTimerValue != 0) {
             channel.eventLoop().schedule(new Runnable() {
                 @Override