From 88985a73cd3434bd9aa888cd9aab388d609130ea Mon Sep 17 00:00:00 2001 From: Dana Kutenicsova Date: Sun, 18 Aug 2013 12:04:27 +0200 Subject: [PATCH] PCEP sucessfull connection now implemented. Fixed minor bug in parsing. Change-Id: I17a3386a159795b149dc0a6ef42ff6e6853c2bd8 Signed-off-by: Dana Kutenicsova --- .../protocol/bgp/rib/impl/BGPSessionImpl.java | 2 +- framework/pom.xml | 2 +- .../protocol/framework/DispatcherImpl.java | 31 +++++++++++++---- .../framework/ProtocolHandlerFactory.java | 17 ++++++++-- .../framework/ProtocolMessageDecoder.java | 24 ++++++++----- .../framework/ProtocolMessageEncoder.java | 8 +++++ .../ProtocolSessionInboundHandler.java | 34 ++++++++++++++----- .../ProtocolSessionOutboundHandler.java | 19 +---------- .../protocol/framework/Session.java | 7 +--- .../protocol/pcep/PCEPSessionFactory.java | 23 ------------- .../pcep/impl/PCEPDispatcherImpl.java | 17 +++++++++- .../pcep/impl/PCEPMessageFactory.java | 6 ++-- .../pcep/impl/PCEPSessionFactoryImpl.java | 4 +-- .../protocol/pcep/impl/PCEPSessionImpl.java | 6 +--- .../protocol/pcep/impl/PCEPValidatorTest.java | 8 ++--- pcep/testtool/pom.xml | 5 +++ .../protocol/pcep/testtool/Main.java | 10 ++++-- .../pcep/testtool/TestingSessionListener.java | 17 +++------- .../protocol/pcep/testtool/PCCMock.java | 2 +- 19 files changed, 135 insertions(+), 107 deletions(-) delete mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionFactory.java diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java index d45f3f0bb2..a2bf6a5d5b 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java @@ -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 diff --git a/framework/pom.xml b/framework/pom.xml index d49792f0f5..aa05beae84 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -27,7 +27,7 @@ io.netty netty-all - 4.0.0.CR9 + 4.0.6.Final com.google.guava diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java b/framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java index e05c9e3783..d818bfafb8 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java @@ -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; } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolHandlerFactory.java b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolHandlerFactory.java index 1c3674daca..e5b7382ba2 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolHandlerFactory.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolHandlerFactory.java @@ -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(); } } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageDecoder.java b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageDecoder.java index f3be094a52..26e7a48720 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageDecoder.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageDecoder.java @@ -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 out) throws Exception { + protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List 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(); - } } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageEncoder.java b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageEncoder.java index 7b3173753b..919caa96d9 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageEncoder.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolMessageEncoder.java @@ -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 { + 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 @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)); } } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionInboundHandler.java b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionInboundHandler.java index 070aa4f651..2c761a2b1a 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionInboundHandler.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionInboundHandler.java @@ -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 { + + 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 msgs) { - final MessageList 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; } } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionOutboundHandler.java b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionOutboundHandler.java index c919f2f3a2..2671ec7fda 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionOutboundHandler.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionOutboundHandler.java @@ -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. newInstance(msg), ctx.newPromise()); + this.write(ctx, msg, ctx.newPromise()); } } diff --git a/framework/src/test/java/org/opendaylight/protocol/framework/Session.java b/framework/src/test/java/org/opendaylight/protocol/framework/Session.java index 94e4d06403..bca23c3160 100644 --- a/framework/src/test/java/org/opendaylight/protocol/framework/Session.java +++ b/framework/src/test/java/org/opendaylight/protocol/framework/Session.java @@ -21,16 +21,11 @@ public class Session implements ProtocolSession { public final List 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 index a3d9b16912..0000000000 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionFactory.java +++ /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); -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java index 7cc5ab9e5d..f8dc6ff920 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java @@ -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 diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java index 788e982fe6..b4f38ccd72 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java @@ -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: " diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionFactoryImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionFactoryImpl.java index 2e67494f49..984ef3a031 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionFactoryImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionFactoryImpl.java @@ -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; diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java index 3fa9dda68d..8b0e3bbd99 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java @@ -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); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java index 49d9f94f44..05a6ffecbb 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java @@ -126,7 +126,7 @@ public class PCEPValidatorTest { private static List 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(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)); diff --git a/pcep/testtool/pom.xml b/pcep/testtool/pom.xml index 3feddce7c9..e18589a3ec 100644 --- a/pcep/testtool/pom.xml +++ b/pcep/testtool/pom.xml @@ -54,6 +54,11 @@ groovy-all 2.0.2 + + ch.qos.logback + logback-classic + ${logback.version} + diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java index 2ec8987b5a..73760d15d5 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java @@ -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); diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java index 69e6334f1a..35cfe2160a 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java @@ -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 diff --git a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java index 6c33111c88..ac13117cdf 100644 --- a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java +++ b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java @@ -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 -- 2.36.6