PCEP sucessfull connection now implemented. Fixed minor bug in parsing. 97/897/3
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 18 Aug 2013 10:04:27 +0000 (12:04 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Mon, 19 Aug 2013 06:58:35 +0000 (08:58 +0200)
Change-Id: I17a3386a159795b149dc0a6ef42ff6e6853c2bd8
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
19 files changed:
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
framework/pom.xml
framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java
framework/src/main/java/org/opendaylight/protocol/framework/ProtocolHandlerFactory.java
framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageDecoder.java
framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageEncoder.java
framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionInboundHandler.java
framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionOutboundHandler.java
framework/src/test/java/org/opendaylight/protocol/framework/Session.java
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionFactory.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionFactoryImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java
pcep/testtool/pom.xml
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java

index d45f3f0bb29f56eea386b71b41b2ab7fe85ab17a..a2bf6a5d5b224c8b0b3096a222535cb5896584b7 100644 (file)
@@ -150,7 +150,7 @@ class BGPSessionImpl implements BGPSession, ProtocolSession {
                this.ctx = ctx;
                this.checker = connection.getProposalChecker();
                this.sync = new BGPSynchronization(this.listener);
-               this.handler = new ProtocolSessionOutboundHandler(this);
+               this.handler = new ProtocolSessionOutboundHandler();
        }
 
        @Override
index d49792f0f5a30245973cdcd72707d73a2736ec04..aa05beae8499238ad484bd8fca19c42ae2c14b0d 100644 (file)
@@ -27,7 +27,7 @@
         <dependency>
                        <groupId>io.netty</groupId>
                        <artifactId>netty-all</artifactId>
-                       <version>4.0.0.CR9</version>
+                       <version>4.0.6.Final</version>
                </dependency>
                <dependency>
                        <groupId>com.google.guava</groupId>
index e05c9e378376340f9d950be3e7488e498397fef5..d818bfafb8a81756648c55d9a1187282320d3ebd 100644 (file)
@@ -11,6 +11,7 @@ import io.netty.bootstrap.Bootstrap;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
@@ -38,14 +39,26 @@ public final class DispatcherImpl implements Dispatcher, SessionParent {
 
                private final ProtocolServer server;
 
+               private ProtocolSession session;
+
                public ServerChannelInitializer(final ProtocolServer server) {
                        this.server = server;
                }
 
                @Override
                protected void initChannel(final SocketChannel ch) throws Exception {
-                       final ProtocolSession session = this.server.createSession(DispatcherImpl.this.stateTimer, ch);
-                       ch.pipeline().addLast(DispatcherImpl.this.handlerFactory.getHandlers(session));
+                       final ProtocolHandlerFactory factory = new ProtocolHandlerFactory(DispatcherImpl.this.messageFactory);
+                       final ChannelHandler handler = factory.getSessionOutboundHandler();
+                       ch.pipeline().addFirst("outbound", handler);
+                       ch.pipeline().addFirst("decoder", factory.getDecoder());
+                       this.session = this.server.createSession(DispatcherImpl.this.stateTimer, ch);
+
+                       ch.pipeline().addAfter("decoder", "inbound", factory.getSessionInboundHandler(this.session));
+                       ch.pipeline().addAfter("inbound", "encoder", factory.getEncoder());
+               }
+
+               public ProtocolSession getSession() {
+                       return this.session;
                }
 
        }
@@ -65,9 +78,14 @@ public final class DispatcherImpl implements Dispatcher, SessionParent {
 
                @Override
                protected void initChannel(final SocketChannel ch) throws Exception {
+                       final ProtocolHandlerFactory factory = new ProtocolHandlerFactory(DispatcherImpl.this.messageFactory);
+                       final ChannelHandler handler = factory.getSessionOutboundHandler();
+                       ch.pipeline().addFirst("outbound", handler);
+                       ch.pipeline().addFirst("decoder", factory.getDecoder());
                        this.session = this.sfactory.getProtocolSession(DispatcherImpl.this, DispatcherImpl.this.stateTimer, this.connection, 0,
                                        ch.pipeline().context(ProtocolSessionOutboundHandler.class));
-                       ch.pipeline().addLast(DispatcherImpl.this.handlerFactory.getHandlers(this.session));
+                       ch.pipeline().addAfter("decoder", "inbound", factory.getSessionInboundHandler(this.session));
+                       ch.pipeline().addAfter("inbound", "encoder", factory.getEncoder());
                }
 
                public ProtocolSession getSession() {
@@ -102,13 +120,13 @@ public final class DispatcherImpl implements Dispatcher, SessionParent {
         */
        private final Timer stateTimer;
 
-       private final ProtocolHandlerFactory handlerFactory;
+       private final ProtocolMessageFactory messageFactory;
 
        public DispatcherImpl(final ProtocolMessageFactory factory) {
                this.bossGroup = new NioEventLoopGroup();
                this.workerGroup = new NioEventLoopGroup();
                this.stateTimer = new Timer();
-               this.handlerFactory = new ProtocolHandlerFactory(factory);
+               this.messageFactory = factory;
        }
 
        @Override
@@ -123,8 +141,7 @@ public final class DispatcherImpl implements Dispatcher, SessionParent {
                b.childOption(ChannelOption.SO_KEEPALIVE, true);
 
                // Bind and start to accept incoming connections.
-               final ChannelFuture f = b.bind(address);
-               // b.localAddress(address);
+               b.bind(address);
                logger.debug("Server {} created.", server);
                return server;
        }
index 1c3674dacad9f1d704f85580cd9c8c530486653d..e5b7382ba2688ff99d48b769b543d0cf333b8d69 100644 (file)
@@ -21,8 +21,19 @@ public class ProtocolHandlerFactory {
                this.decoder = new ProtocolMessageDecoder(msgFactory);
        }
 
-       public ChannelHandler[] getHandlers(final ProtocolSession session) {
-               return new ChannelHandler[] { this.encoder, new ProtocolSessionInboundHandler(session),
-                               new ProtocolSessionOutboundHandler(session), this.decoder };
+       public ChannelHandler getEncoder() {
+               return this.encoder;
+       }
+
+       public ChannelHandler getDecoder() {
+               return this.decoder;
+       }
+
+       public ChannelHandler getSessionInboundHandler(final ProtocolSession session) {
+               return new ProtocolSessionInboundHandler(session);
+       }
+
+       public ChannelHandler getSessionOutboundHandler() {
+               return new ProtocolSessionOutboundHandler();
        }
 }
index f3be094a52421c474b331698eb1b9fe8883cab9a..26e7a48720a7f57b3064c1ac7206c6a33d33b742 100644 (file)
@@ -9,11 +9,18 @@ package org.opendaylight.protocol.framework;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.MessageList;
 import io.netty.handler.codec.ByteToMessageDecoder;
 
+import java.util.Arrays;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 final class ProtocolMessageDecoder extends ByteToMessageDecoder {
 
+       private final static Logger logger = LoggerFactory.getLogger(ProtocolMessageDecoder.class);
+
        private final ProtocolMessageFactory factory;
 
        public ProtocolMessageDecoder(final ProtocolMessageFactory factory) {
@@ -21,19 +28,18 @@ final class ProtocolMessageDecoder extends ByteToMessageDecoder {
        }
 
        @Override
-       public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final MessageList<Object> out) throws Exception {
+       protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {
+               in.markReaderIndex();
                ProtocolMessage msg = null;
                try {
-                       msg = this.factory.parse(in.array());
+                       final byte[] bytes = new byte[in.readableBytes()];
+                       logger.debug("Received to decode: {}", Arrays.toString(bytes));
+                       in.readBytes(bytes);
+                       msg = this.factory.parse(bytes);
                } catch (DeserializerException | DocumentedException e) {
                        this.exceptionCaught(ctx, e);
                }
+               in.discardReadBytes();
                out.add(msg);
        }
-
-       @Override
-       public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
-               // TODO:
-               ctx.close();
-       }
 }
index 7b3173753b17155045b5356855a4274588b701b4..919caa96d9e82c0be24def23af2ebdd0650a08f4 100644 (file)
@@ -12,9 +12,16 @@ import io.netty.channel.ChannelHandler.Sharable;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.MessageToByteEncoder;
 
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 @Sharable
 final class ProtocolMessageEncoder extends MessageToByteEncoder<ProtocolMessage> {
 
+       private final static Logger logger = LoggerFactory.getLogger(ProtocolMessageEncoder.class);
+
        private final ProtocolMessageFactory factory;
 
        public ProtocolMessageEncoder(final ProtocolMessageFactory factory) {
@@ -23,6 +30,7 @@ final class ProtocolMessageEncoder extends MessageToByteEncoder<ProtocolMessage>
 
        @Override
        protected void encode(final ChannelHandlerContext ctx, final ProtocolMessage msg, final ByteBuf out) throws Exception {
+               logger.debug("Sent to encode : {}", Arrays.toString(ctx.channel().pipeline().names().toArray()));
                out.writeBytes(this.factory.put(msg));
        }
 }
index 070aa4f651ca0ecefe5ed435c7b521f698feb849..2c761a2b1a16178e9c0724b81077f54b0a7ecd84 100644 (file)
@@ -8,10 +8,14 @@
 package org.opendaylight.protocol.framework;
 
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.channel.MessageList;
+import io.netty.channel.SimpleChannelInboundHandler;
 
-final class ProtocolSessionInboundHandler extends ChannelInboundHandlerAdapter {
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class ProtocolSessionInboundHandler extends SimpleChannelInboundHandler<ProtocolMessage> {
+
+       private final static Logger logger = LoggerFactory.getLogger(ProtocolSessionInboundHandler.class);
 
        private final ProtocolSession session;
 
@@ -20,10 +24,24 @@ final class ProtocolSessionInboundHandler extends ChannelInboundHandlerAdapter {
        }
 
        @Override
-       public void messageReceived(final ChannelHandlerContext ctx, final MessageList<Object> msgs) {
-               final MessageList<ProtocolMessage> pmsgs = msgs.cast();
-               for (final ProtocolMessage msg : pmsgs) {
-                       this.session.handleMessage(msg);
-               }
+       public void channelActive(final ChannelHandlerContext ctx) throws Exception {
+               logger.debug("Channel active.");
+               this.session.startSession();
+       }
+
+       @Override
+       public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
+               logger.debug("Channel inactive.");
+               this.session.endOfInput();
+       }
+
+       @Override
+       protected void channelRead0(final ChannelHandlerContext ctx, final ProtocolMessage msg) throws Exception {
+               logger.debug("Message was received: {}", msg);
+               this.session.handleMessage(msg);
+       }
+
+       public ProtocolSession getSession() {
+               return this.session;
        }
 }
index c919f2f3a265961947c42072d258dacd4c09ead5..2671ec7fdac16ac01792e22ecf2cb98761344184 100644 (file)
@@ -9,26 +9,9 @@ package org.opendaylight.protocol.framework;
 
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
-import io.netty.channel.MessageList;
 
 public final class ProtocolSessionOutboundHandler extends ChannelOutboundHandlerAdapter {
 
-       private final ProtocolSession session;
-
-       public ProtocolSessionOutboundHandler(final ProtocolSession session) {
-               this.session = session;
-       }
-
-       @Override
-       public void handlerAdded(final ChannelHandlerContext ctx) throws Exception {
-               this.session.startSession();
-       }
-
-       @Override
-       public void handlerRemoved(final ChannelHandlerContext ctx) throws Exception {
-               this.session.close();
-       }
-
        @Override
        public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
                // TODO:
@@ -37,6 +20,6 @@ public final class ProtocolSessionOutboundHandler extends ChannelOutboundHandler
        }
 
        public void writeDown(final ChannelHandlerContext ctx, final ProtocolMessage msg) throws Exception {
-               this.write(ctx, MessageList.<Object> newInstance(msg), ctx.newPromise());
+               this.write(ctx, msg, ctx.newPromise());
        }
 }
index 94e4d0640328b9259f801be32e91a8d329c2de90..bca23c31607e44097b1b3b91c4e132bcaed02c07 100644 (file)
@@ -21,16 +21,11 @@ public class Session implements ProtocolSession {
 
        public final List<ProtocolMessage> msgs = Lists.newArrayList();
 
-       private final ProtocolMessageFactory pmf = new MessageFactory();
-
-       private final SessionParent parent;
-
        public boolean up = false;
 
        private final int maxMsgSize;
 
-       public Session(final SessionParent parent, final int maxMsgSize) {
-               this.parent = parent;
+       public Session(final int maxMsgSize) {
                this.maxMsgSize = maxMsgSize;
        }
 
diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionFactory.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionFactory.java
deleted file mode 100644 (file)
index a3d9b16..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep;
-
-import io.netty.channel.ChannelHandlerContext;
-
-import java.util.Timer;
-
-import org.opendaylight.protocol.framework.ProtocolConnection;
-import org.opendaylight.protocol.framework.ProtocolSession;
-import org.opendaylight.protocol.framework.ProtocolSessionFactory;
-import org.opendaylight.protocol.framework.SessionParent;
-
-public interface PCEPSessionFactory extends ProtocolSessionFactory {
-       @Override
-       public ProtocolSession getProtocolSession(SessionParent parent, Timer timer, ProtocolConnection connection, int sessionId,
-                       ChannelHandlerContext ctx);
-}
index 7cc5ab9e5d295c02aca4117264cd928cd1ab435a..f8dc6ff92087bcbe55b8df4fdbfa47734dad6caf 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.protocol.framework.Dispatcher;
 import org.opendaylight.protocol.framework.ProtocolServer;
@@ -17,11 +18,16 @@ import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of PCEPDispatcher.
  */
 public class PCEPDispatcherImpl implements PCEPDispatcher {
+
+       private final static Logger logger = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
+
        public static final int DEFAULT_MAX_UNKNOWN_MSG = 5;
 
        private int maxUnknownMessages = DEFAULT_MAX_UNKNOWN_MSG;
@@ -48,10 +54,19 @@ public class PCEPDispatcherImpl implements PCEPDispatcher {
 
        /**
         * Create client is used for mock purposes only.
+        * 
+        * @throws ExecutionException
+        * @throws InterruptedException
         */
        @Override
        public PCEPSession createClient(final PCEPConnection connection) throws IOException {
-               return (PCEPSession) this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
+               PCEPSession session = null;
+               try {
+                       session = (PCEPSession) this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages)).get();
+               } catch (InterruptedException | ExecutionException e) {
+                       logger.warn("Client not created. Exception {}.", e.getMessage(), e);
+               }
+               return session;
        }
 
        @Override
index 788e982fe646305311eb5cdf6682d127e765a8fe..b4f38ccd72bf6505a406377a1ebc1cd86313d0a0 100644 (file)
@@ -137,11 +137,11 @@ public class PCEPMessageFactory implements ProtocolMessageFactory {
 
                logger.trace("Attempt to parse message from bytes: {}", ByteArray.bytesToHexString(bytes));
 
-               final int type = UnsignedBytes.toInt(bytes[0]);
+               final int type = UnsignedBytes.toInt(bytes[1]);
 
-               final int msgLength = ByteArray.bytesToInt(ByteArray.subByte(bytes, TYPE_SIZE, LENGTH_SIZE));
+               final int msgLength = ByteArray.bytesToInt(ByteArray.subByte(bytes, TYPE_SIZE + 1, LENGTH_SIZE));
 
-               final byte[] msgBody = ByteArray.cutBytes(bytes, TYPE_SIZE + LENGTH_SIZE);
+               final byte[] msgBody = ByteArray.cutBytes(bytes, TYPE_SIZE + 1 + LENGTH_SIZE);
 
                if (msgBody.length != (msgLength - COMMON_HEADER_LENGTH))
                        throw new DeserializerException("Size don't match size specified in header. Passed: " + msgBody.length + "; Expected: "
index 2e67494f4950e435317be89440d2a7eecb3eca7f..984ef3a03123b3847abe0cc50a7639ffb36d82d8 100644 (file)
@@ -13,11 +13,11 @@ import java.util.Timer;
 
 import org.opendaylight.protocol.framework.ProtocolConnection;
 import org.opendaylight.protocol.framework.ProtocolSession;
+import org.opendaylight.protocol.framework.ProtocolSessionFactory;
 import org.opendaylight.protocol.framework.SessionParent;
 import org.opendaylight.protocol.pcep.PCEPConnection;
-import org.opendaylight.protocol.pcep.PCEPSessionFactory;
 
-public class PCEPSessionFactoryImpl implements PCEPSessionFactory {
+public class PCEPSessionFactoryImpl implements ProtocolSessionFactory {
 
        private final int maxUnknownMessages;
 
index 3fa9dda68d2950382c8fc09c2be39fdc9ab5cc4b..8b0e3bbd99eeb4d1cf6e28e355e102f73dba4c43 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.framework.ProtocolMessage;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.opendaylight.protocol.framework.ProtocolSession;
-import org.opendaylight.protocol.framework.ProtocolSessionOutboundHandler;
 import org.opendaylight.protocol.framework.SessionParent;
 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
 import org.opendaylight.protocol.pcep.PCEPConnection;
@@ -205,8 +204,6 @@ class PCEPSessionImpl implements PCEPSession, ProtocolSession, PCEPSessionRuntim
 
        private final String peerAddress;
 
-       private final ProtocolSessionOutboundHandler handler;
-
        private final ChannelHandlerContext ctx;
 
        PCEPSessionImpl(final SessionParent parent, final Timer timer, final PCEPConnection connection, final PCEPMessageFactory factory,
@@ -223,7 +220,6 @@ class PCEPSessionImpl implements PCEPSession, ProtocolSession, PCEPSessionRuntim
                this.ctx = ctx;
                if (this.maxUnknownMessages != 0)
                        this.maxUnknownMessages = maxUnknownMessages;
-               this.handler = new ProtocolSessionOutboundHandler(this);
        }
 
        @Override
@@ -367,7 +363,7 @@ class PCEPSessionImpl implements PCEPSession, ProtocolSession, PCEPSessionRuntim
        @Override
        public void sendMessage(final PCEPMessage msg) {
                try {
-                       this.handler.writeDown(this.ctx, msg);
+                       this.ctx.writeAndFlush(msg);
                        this.lastMessageSentAt = System.nanoTime();
                        if (!(msg instanceof PCEPKeepAliveMessage))
                                logger.debug("Sent message: " + msg);
index 49d9f94f441a099fb459aaf8ec68e5a1f3391e9a..05a6ffecbbaa890b1b1a98d2b28607fee591cde1 100644 (file)
@@ -126,7 +126,7 @@ public class PCEPValidatorTest {
        private static List<PCEPMessage> deserMsg(final String srcFile) throws IOException, DeserializerException, DocumentedException,
                        PCEPDeserializerException {
                final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) new PCEPMessageFactory().parse(ByteArray.cutBytes(bytesFromFile, 1));
+               final PCEPRawMessage rawMessage = (PCEPRawMessage) new PCEPMessageFactory().parse(bytesFromFile);
 
                return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects());
        }
@@ -620,7 +620,7 @@ public class PCEPValidatorTest {
                final PCEPXRDeleteTunnelMessage dTunnel = new PCEPXRDeleteTunnelMessage(new PCEPLspObject(1, false, true, false, true));
                final byte[] bytes = this.msgFactory.put(dTunnel);
 
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(ByteArray.cutBytes(bytes, 1));
+               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(bytes);
 
                assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()),
                                asList((PCEPMessage) dTunnel));
@@ -633,7 +633,7 @@ public class PCEPValidatorTest {
                final PCEPXRAddTunnelMessage addTunnel = new PCEPXRAddTunnelMessage(new PCEPLspObject(1, false, false, false, false), new PCEPEndPointsObject<IPv4Address>(IPv4.FAMILY.addressForString("127.0.0.2"), IPv4.FAMILY.addressForString("127.0.0.1")), new PCEPExplicitRouteObject(subs, true));
                final byte[] bytes = this.msgFactory.put(addTunnel);
 
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(ByteArray.cutBytes(bytes, 1));
+               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(bytes);
                assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()),
                                asList((PCEPMessage) addTunnel));
        }
@@ -660,7 +660,7 @@ public class PCEPValidatorTest {
                final byte[] bytes = this.msgFactory.put(msg);
 
                // FIXME: need construct with invalid processed parameter
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(ByteArray.cutBytes(bytes, 1));
+               final PCEPRawMessage rawMessage = (PCEPRawMessage) this.msgFactory.parse(bytes);
 
                assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()),
                                asList((PCEPMessage) msg));
index 3feddce7c9668ad45ce75c412c309ce8daf8ca2b..e18589a3ecbc46f8cdaf3980bd6c52f2025069a9 100644 (file)
                        <artifactId>groovy-all</artifactId>
                        <version>2.0.2</version>
                </dependency>
+               <dependency>
+                       <groupId>ch.qos.logback</groupId>
+                       <artifactId>logback-classic</artifactId>
+                       <version>${logback.version}</version>
+               </dependency>
        </dependencies>
 
        <build>
index 2ec8987b5a4f2d2caf96a0c8de60fd648ab1849e..73760d15d599408f915ee8b70ca6ff0da5f755da 100644 (file)
@@ -12,6 +12,7 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.framework.DispatcherImpl;
+import org.opendaylight.protocol.framework.ProtocolServer;
 import org.opendaylight.protocol.pcep.PCEPConnection;
 import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
@@ -107,7 +108,9 @@ public class Main {
                        } else if (args[i].equalsIgnoreCase("--instant")) {
                                stateful = true;
                                instant = true;
-                               if (Integer.valueOf(args[i + 1]) > 0 && Integer.valueOf(args[i + 1]) < Integer.MAX_VALUE) {
+                               if (i == args.length - 1) {
+                                       timeout = 0;
+                               } else if (Integer.valueOf(args[i + 1]) > 0 && Integer.valueOf(args[i + 1]) < Integer.MAX_VALUE) {
                                        timeout = Integer.valueOf(args[i + 1]);
                                        i++;
                                }
@@ -143,8 +146,10 @@ public class Main {
                final DispatcherImpl d = new DispatcherImpl(new PCEPMessageFactory());
                final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(d, spf);
 
+               ProtocolServer s = null;
+
                try {
-                       dispatcher.createServer(address, new PCEPConnectionFactory() {
+                       s = dispatcher.createServer(address, new PCEPConnectionFactory() {
                                @Override
                                public PCEPConnection createProtocolConnection(final InetSocketAddress address) {
                                        final PCEPSessionProposalChecker checker = spcf.getPreferencesChecker(address);
@@ -157,7 +162,6 @@ public class Main {
                                public void setProposal(final PCEPSessionProposalFactory proposals, final InetSocketAddress address, final int sessionId) {
                                }
                        });
-                       // final ProtocolServer s = dispatcher.createServer(address, slf, spf, spcf);
 
                        // try {
                        // Thread.sleep(10000);
index 69e6334f1a7186d6c93c7e7097f665188efd668f..35cfe2160a99963544789308b1b23ded1c6f8d86 100644 (file)
@@ -11,7 +11,6 @@ import groovy.lang.GroovyClassLoader;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
@@ -21,13 +20,10 @@ import java.util.Queue;
 import java.util.Timer;
 import java.util.TimerTask;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.opendaylight.protocol.framework.TerminationReason;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.IPv4Prefix;
 import org.opendaylight.protocol.concepts.Prefix;
+import org.opendaylight.protocol.framework.TerminationReason;
 import org.opendaylight.protocol.pcep.PCEPMessage;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
@@ -39,6 +35,8 @@ import org.opendaylight.protocol.pcep.object.PCEPLspObject;
 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TestingSessionListener extends PCEPSessionListener {
 
@@ -126,7 +124,7 @@ public class TestingSessionListener extends PCEPSessionListener {
 
        @Override
        public void onMessage(final PCEPSession session, final PCEPMessage message) {
-               logger.debug("Received message: " + message);
+               logger.debug("Received message: {}", message);
                this.messages.add(message);
 
                // if (!this.replyMessages.isEmpty()) {
@@ -150,12 +148,7 @@ public class TestingSessionListener extends PCEPSessionListener {
 
        @Override
        public void onSessionDown(final PCEPSession session, final PCEPCloseObject reason, final Exception e) {
-               logger.debug("Session down because: " + reason);
-               try {
-                       session.close();
-               } catch (final IOException ex) {
-                       logger.warn("Session could not be closed.", e);
-               }
+               logger.debug("Session down because: {}", reason);
        }
 
        @Override
index 6c33111c8855b5721f2e46df45e37ae1fd383301..ac13117cdf1ada1eb3e6ff5bc54a1b88744361f7 100644 (file)
@@ -65,7 +65,7 @@ public class PCCMock {
                        d.createClient(new PCEPConnection() {
                                @Override
                                public InetSocketAddress getPeerAddress() {
-                                       return new InetSocketAddress("127.0.0.1", 4189);
+                                       return new InetSocketAddress("127.0.0.3", 12345);
                                }
 
                                @Override