return this.parser;
}
- @Override
- public void onConnectionFailed(final IOException e) {
- logger.info("Connection failed before finishing: {}", e.getMessage(), e);
- this.listener.onSessionDown(this, e);
- }
-
@Override
public int maximumMessageSize() {
return 4096;
*/
package org.opendaylight.protocol.framework;
-import io.netty.util.concurrent.Future;
-
import java.io.IOException;
import java.net.InetSocketAddress;
*
* @return session associated with this client
*/
- public Future<ProtocolSession> createClient(final ProtocolConnection connection, final ProtocolSessionFactory sfactory)
- throws IOException;
+ public ProtocolSession createClient(final ProtocolConnection connection, final ProtocolSessionFactory sfactory) throws IOException;
}
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.DefaultPromise;
-import io.netty.util.concurrent.Future;
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.Map;
import java.util.Timer;
+import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Maps;
+
/**
* Dispatcher class for creating servers and clients. The idea is to first create servers and clients and the run the
* start method that will handle sockets in different thread.
private final ProtocolMessageFactory messageFactory;
+ private final Map<ProtocolServer, Channel> serverSessions;
+
+ private final Map<ProtocolSession, Channel> clientSessions;
+
public DispatcherImpl(final ProtocolMessageFactory factory) {
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup();
this.stateTimer = new Timer();
this.messageFactory = factory;
+ this.clientSessions = Maps.newHashMap();
+ this.serverSessions = Maps.newHashMap();
}
@Override
public ProtocolServer createServer(final InetSocketAddress address, final ProtocolConnectionFactory connectionFactory,
final ProtocolSessionFactory sessionFactory) {
- final ProtocolServer server = new ProtocolServer(address, connectionFactory, sessionFactory);
+ final ProtocolServer server = new ProtocolServer(address, connectionFactory, sessionFactory, this);
final ServerBootstrap b = new ServerBootstrap();
b.group(this.bossGroup, this.workerGroup);
b.channel(NioServerSocketChannel.class);
b.childOption(ChannelOption.SO_KEEPALIVE, true);
// Bind and start to accept incoming connections.
- b.bind(address);
- logger.debug("Server {} created.", server);
+ final ChannelFuture f = b.bind(address);
+ this.serverSessions.put(server, f.channel());
+ logger.debug("Created server {}.", server);
return server;
}
@Override
- public Future<ProtocolSession> createClient(final ProtocolConnection connection, final ProtocolSessionFactory sfactory) {
+ public ProtocolSession createClient(final ProtocolConnection connection, final ProtocolSessionFactory sfactory) {
final Bootstrap b = new Bootstrap();
b.group(this.workerGroup);
b.channel(NioSocketChannel.class);
p.setFailure(cf.cause());
}
});
+ ProtocolSession s = null;
+ try {
+ s = p.get();
+ this.clientSessions.put(p.get(), f.channel());
+ } catch (InterruptedException | ExecutionException e) {
+ logger.warn("Client not created. Exception {}.", e.getMessage(), e);
+ }
logger.debug("Client created.");
- return p;
+ return s;
}
@Override
@Override
public void onSessionClosed(final ProtocolSession session) {
- // TODO Auto-generated method stub
+ logger.trace("Removing client session: {}", session);
+ final Channel ch = this.clientSessions.get(session);
+ ch.close();
+ this.clientSessions.remove(session);
+ logger.debug("Removed client session: {}", session.toString());
+ }
+
+ void onServerClosed(final ProtocolServer server) {
+ logger.trace("Removing server session: {}", server);
+ final Channel ch = this.serverSessions.get(server);
+ ch.close();
+ this.clientSessions.remove(server);
+ logger.debug("Removed server session: {}", server.toString());
}
}
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {
+ if (in.readableBytes() == 0) {
+ logger.debug("No more content in incoming buffer.");
+ return;
+ }
in.markReaderIndex();
ProtocolMessage msg = null;
try {
final byte[] bytes = new byte[in.readableBytes()];
- logger.debug("Received to decode: {}", Arrays.toString(bytes));
in.readBytes(bytes);
+ logger.debug("Received to decode: {}", Arrays.toString(bytes));
msg = this.factory.parse(bytes);
} catch (DeserializerException | DocumentedException e) {
this.exceptionCaught(ctx, e);
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
-import java.util.Arrays;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@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()));
+ logger.debug("Sent to encode : {}", msg);
out.writeBytes(this.factory.put(msg));
}
}
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Maps;
/**
* Representation of a server, created by {@link Dispatcher}. Should be extended by a protocol specific server
* implementation.
*/
-public class ProtocolServer implements SessionParent {
+public final class ProtocolServer implements SessionParent {
private static final Logger logger = LoggerFactory.getLogger(ProtocolServer.class);
private final Map<InetSocketAddress, Integer> sessionIds;
+ private final Dispatcher parent;
+
/**
* Creates a Protocol server.
*
- * @param dispatcher Dispatcher
* @param address address to which this server is bound
* @param connectionFactory factory for connection specific properties
- * @param channel server socket channel
+ * @param parent Dispatcher that created this server
* @param sessionFactory factory for sessions
- * @param inputStreamFactory factory for input streams
*/
public ProtocolServer(final InetSocketAddress address, final ProtocolConnectionFactory connectionFactory,
- final ProtocolSessionFactory sessionFactory) {
+ final ProtocolSessionFactory sessionFactory, final Dispatcher parent) {
this.serverAddress = address;
this.sessions = HashBiMap.create();
this.connectionFactory = connectionFactory;
this.sessionFactory = sessionFactory;
- this.sessionIds = new HashMap<InetSocketAddress, Integer>();
+ this.parent = parent;
+ this.sessionIds = Maps.newHashMap();
}
/**
try {
session.close();
} catch (final IOException e) {
- logger.error("Session {} could not be closed.", session);
+ logger.error("Could not close session: {}.", session);
}
}
} else {
return session;
}
- /**
- * Returns server address.
- *
- * @return server address
- */
- public InetSocketAddress getAddress() {
- return this.serverAddress;
- }
-
@Override
public synchronized void close() throws IOException {
- // TODO:
- logger.debug("Server {} closed.", this);
+ ((DispatcherImpl) this.parent).onServerClosed(this);
+ logger.debug("Closed server {}.", this);
}
@Override
public synchronized void onSessionClosed(final ProtocolSession session) {
this.sessions.inverse().remove(session); // when the session is closed, the key is the instance of the session
+ logger.debug("Closed session {}.", session);
}
private static int getNextId(Integer lastId, final int maxId) {
public String toString() {
return "ProtocolServer [serverAddress=" + this.serverAddress + ", hashCode()=" + hashCode() + "]";
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.serverAddress == null) ? 0 : this.serverAddress.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ProtocolServer other = (ProtocolServer) obj;
+ if (this.serverAddress == null) {
+ if (other.serverAddress != null)
+ return false;
+ } else if (!this.serverAddress.equals(other.serverAddress))
+ return false;
+ return true;
+ }
}
package org.opendaylight.protocol.framework;
import java.io.Closeable;
-import java.io.IOException;
/**
* Protocol Session represents the finite state machine in underlying protocol, including timers and its purpose is to
*/
public ProtocolMessageFactory getMessageFactory();
- /**
- * Session is notified about the connection not being established successfully.
- *
- * @param e IOException that was the cause of failed connection.
- */
- public void onConnectionFailed(final IOException e);
-
/**
* Returns the maximum message size (in bytes) for purposes of dispatcher buffering -- the dispatcher allocates a
* buffer this big, and if it gets full without making decoding progress, the dispatcher terminates the session.
package org.opendaylight.protocol.framework;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
-import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.junit.After;
import org.junit.Test;
ProtocolServer server = null;
+ public final InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.5", PORT);
+
@Test
public void testConnectionEstablished() throws Exception {
this.dispatcher = new DispatcherImpl(new MessageFactory());
- final InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.3", PORT);
-
- this.server = this.dispatcher.createServer(serverAddress, new ProtocolConnectionFactory() {
+ this.server = this.dispatcher.createServer(this.serverAddress, new ProtocolConnectionFactory() {
@Override
public ProtocolConnection createProtocolConnection(final InetSocketAddress address) {
@Override
public InetSocketAddress getPeerAddress() {
- return new InetSocketAddress("127.0.0.3", PORT);
+ return ServerTest.this.serverAddress;
}
@Override
public SessionListener getListener() {
return ServerTest.this.pce;
}
- }, new SimpleSessionFactory(MAX_MSGSIZE)).get();
+ }, new SimpleSessionFactory(MAX_MSGSIZE));
final int maxAttempts = 1000;
int attempts = 0;
this.clientDispatcher = new DispatcherImpl(new MessageFactory());
final SimpleSessionListener listener = new SimpleSessionListener();
- final Future<ProtocolSession> session = this.clientDispatcher.createClient(new ProtocolConnection() {
+ final ProtocolSession session = this.clientDispatcher.createClient(new ProtocolConnection() {
@Override
public SessionPreferencesChecker getProposalChecker() {
return new SimpleSessionProposalChecker();
@Override
public InetSocketAddress getPeerAddress() {
- return new InetSocketAddress("127.0.0.5", PORT);
+ return ServerTest.this.serverAddress;
}
@Override
return listener;
}
}, new SimpleSessionFactory(MAX_MSGSIZE));
- try {
- session.get();
- fail("Exception should have occurred.");
- } catch (final ExecutionException e) {
+ if (session == null)
listener.failed = true;
- assertTrue(e.getCause() instanceof ConnectException);
- }
final int maxAttempts = 100;
int attempts = 0;
synchronized (listener) {
@After
public void tearDown() throws IOException {
- this.dispatcher.onSessionClosed(this.session);
if (this.server != null)
this.server.close();
- // this.dispatcher.stop();
- // this.clientDispatcher.stop();
+ this.dispatcher.close();
+ this.clientDispatcher.close();
try {
Thread.sleep(100);
} catch (final InterruptedException e) {
return null;
}
- @Override
- public void onConnectionFailed(final IOException e) {
- logger.debug("Connection failed: {}", e.getMessage(), e);
- }
-
@Override
public int maximumMessageSize() {
return this.maxMsgSize;
return null;
}
- @Override
- public void onConnectionFailed(final IOException e) {
- ((SimpleSessionListener) this.listener).onConnectionFailed(this, e);
- }
-
@Override
public int maximumMessageSize() {
return this.maxMsgSize;
</encoder>
</appender>
- <root level="DEBUG">
+ <root level="TRACE">
<appender-ref ref="STDOUT" />
</root>
</configuration>
import java.io.Closeable;
+import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
+
/**
- * PCEP Session represents the finite state machine in PCEP,
- * including timers and its purpose is to create a PCEP connection
- * between PCE/PCC. Session is automatically started, when TCP
- * connection is created, but can be stopped manually.
- * If the session is up, it has to redirect messages to/from user.
- * Handles also malformed messages and unknown requests.
+ * PCEP Session represents the finite state machine in PCEP, including timers and its purpose is to create a PCEP
+ * connection between PCE/PCC. Session is automatically started, when TCP connection is created, but can be stopped
+ * manually. If the session is up, it has to redirect messages to/from user. Handles also malformed messages and unknown
+ * requests.
*/
public interface PCEPSession extends Closeable {
/**
- * Sends message from user to PCE/PCC. If the user sends an Open
- * Message, the session returns an error (open message is only
- * allowed, when a PCEP handshake is in progress). Close message
- * will close the session and free all the resources.
+ * Sends message from user to PCE/PCC. If the user sends an Open Message, the session returns an error (open message
+ * is only allowed, when a PCEP handshake is in progress). Close message will close the session and free all the
+ * resources.
+ *
* @param message message to be sent
*/
public void sendMessage(PCEPMessage message);
+
+ public void close(PCEPCloseObject.Reason reason);
}
import org.opendaylight.protocol.framework.SessionListener;
import org.opendaylight.protocol.framework.TerminationReason;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
/**
- * Listener that receives session informations from the session.
+ * Listener that receives session informations from the session.
*/
public abstract class PCEPSessionListener implements SessionListener {
/**
* Fired when a message is received.
+ *
* @param session session which received the message
* @param message PCEPMessage
*/
/**
* Fired when the session is in state UP.
- *
+ *
* @param session Session which went up
* @param local Local open proposal which the peer accepted
* @param remote Peer open proposal which we accepted
public abstract void onSessionUp(PCEPSession session, PCEPOpenObject local, PCEPOpenObject remote);
/**
- * Fired when the session went down as a result of peer's decision
- * to tear it down.
- * Implementation should take care of closing underlying session.
- *
+ * Fired when the session went down as a result of peer's decision to tear it down. Implementation should take care
+ * of closing underlying session.
+ *
* @param session Session which went down
- * @param reason Reason for termination, may be null when the underlying
- * channel was closed without a specific reason.
+ * @param cause Reason for termination
* @param e exception that caused session down
*/
- public abstract void onSessionDown(PCEPSession session, PCEPCloseObject reason, Exception e);
+ public abstract void onSessionDown(PCEPSession session, TerminationReason cause, Exception e);
/**
- * Fired when the session is terminated locally. The session has already
- * been closed and transitioned to IDLE state. Any outstanding queued
- * messages were not sent. The user should not attempt to make any use
- * of the session.
- *
+ * Fired when the session is terminated locally. The session has already been closed and transitioned to IDLE state.
+ * Any outstanding queued messages were not sent. The user should not attempt to make any use of the session.
+ *
* @param session Session which went down
* @param cause the cause why the session went down
*/
<artifactId>concepts</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>${guava.version}</version>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
*/
@Override
public PCEPSession createClient(final PCEPConnection connection) throws IOException {
- 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;
+ return (PCEPSession) this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
}
@Override
@Override
public ProtocolMessage parse(final byte[] bytes) throws DeserializerException, DocumentedException {
- if (bytes == null)
+ if (bytes == null || bytes.length == 0)
throw new IllegalArgumentException("Array of bytes is mandatory.");
logger.trace("Attempt to parse message from bytes: {}", ByteArray.bytesToHexString(bytes));
}
}
- private void commonClose() {
- this.changeState(State.IDLE);
- this.parent.onSessionClosed(this);
- }
-
/**
- * Closes PCEP session from the parent with given reason. A message needs to be sent, but parent doesn't have to be
- * modified, because he initiated the closing. (To prevent concurrent modification exception).
+ * Closes PCEP session without sending a Close message, as the channel is no longer active. Notify parent about
+ * this.
*
- * @param closeObject
+ * @param reason reason, why it was terminated
*/
- void closeWithoutMessage() {
- logger.debug("Closing session: {}", this);
- commonClose();
+ @Override
+ public void close() {
+ logger.trace("Closing session: {}", this);
+ this.changeState(State.IDLE);
+ this.parent.onSessionClosed(this);
}
/**
- * Closes PCEP session, cancels all timers, returns to state Idle WITHOUT sending the Close Message. KeepAlive and
- * DeadTimer are cancelled if the state of the session changes to IDLE. This method is used to close the PCEP
- * session from inside the session or from the listener, therefore the parent of this session should be informed.
- * The only closing reason is UNKNOWN.
+ * Closes PCEP session, cancels all timers, returns to state Idle, sends the Close Message. KeepAlive and DeadTimer
+ * are cancelled if the state of the session changes to IDLE. This method is used to close the PCEP session from
+ * inside the session or from the listener, therefore the parent of this session should be informed.
*/
@Override
- public synchronized void close() {
+ public synchronized void close(final PCEPCloseObject.Reason reason) {
logger.debug("Closing session: {}", this);
- this.sendMessage(new PCEPCloseMessage(new PCEPCloseObject(Reason.UNKNOWN)));
- commonClose();
+ this.sendMessage(new PCEPCloseMessage(new PCEPCloseObject(reason)));
+ this.changeState(State.IDLE);
+ this.parent.onSessionClosed(this);
}
private void terminate(final PCEPCloseObject.Reason reason) {
- this.sendMessage(new PCEPCloseMessage(new PCEPCloseObject(reason)));
- this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
+ this.sendMessage(new PCEPCloseMessage(new PCEPCloseObject(reason)));
+ this.close();
}
private void terminate(final PCEPErrors error) {
- this.sendErrorMessage(error);
- this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new PCEPErrorTermination(error));
+ this.sendErrorMessage(error);
+ this.close();
}
@Override
* session DOWN event.
*/
if (pcepMsg instanceof PCEPCloseMessage) {
- this.listener.onSessionTerminated(this, new PCEPCloseTermination(((PCEPCloseMessage) pcepMsg).getCloseObject().getReason()));
- this.closeWithoutMessage();
+ this.close();
return;
}
this.listener.onMessage(this, pcepMsg);
return this.factory;
}
- @Override
- public void onConnectionFailed(final IOException e) {
- logger.info("Connection failed before finishing: {}", e.getMessage(), e);
- this.listener.onSessionDown(this, new PCEPCloseObject(Reason.UNKNOWN), e);
- }
-
/**
* @return the sentMsgCount
*/
import java.util.ArrayList;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.opendaylight.protocol.framework.TerminationReason;
import org.opendaylight.protocol.pcep.PCEPErrors;
import org.opendaylight.protocol.pcep.PCEPMessage;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
public MockPCE() {
}
- public void sendMessage(PCEPMessage msg) {
+ public void sendMessage(final PCEPMessage msg) {
this.session.handleMessage(msg);
}
- public void sendErrorMessage(PCEPErrors value,
- PCEPOpenObject open) {
+ public void sendErrorMessage(final PCEPErrors value, final PCEPOpenObject open) {
final PCEPErrorObject error = new PCEPErrorObject(value);
final List<PCEPErrorObject> errors = new ArrayList<PCEPErrorObject>();
errors.add(error);
return this.listMsg;
}
- public void addSession(PCEPSessionImpl l) {
+ public void addSession(final PCEPSessionImpl l) {
this.session = l;
}
@Override
- public void onMessage(PCEPSession session, PCEPMessage message) {
+ public void onMessage(final PCEPSession session, final PCEPMessage message) {
this.listMsg.add(message);
- logger.debug("Message received:" + message);
+ logger.debug("Message received: {}", message);
}
@Override
- public void onSessionUp(PCEPSession session, PCEPOpenObject local,
- PCEPOpenObject remote) {
+ public void onSessionUp(final PCEPSession session, final PCEPOpenObject local, final PCEPOpenObject remote) {
logger.debug("Session Up");
this.up = true;
this.notifyAll();
}
@Override
- public void onSessionDown(PCEPSession session, PCEPCloseObject reason, Exception e) {
- logger.debug("Session Down");
+ public void onSessionDown(final PCEPSession session, final TerminationReason reason, final Exception e) {
+ logger.debug("Session Down. Cause {} or {}.", reason, e);
this.down = true;
- //this.notifyAll();
+ // this.notifyAll();
}
@Override
- public void onSessionTerminated(PCEPSession session,
- TerminationReason cause) {
- logger.debug("Session terminated. Cause : " + cause.toString());
+ public void onSessionTerminated(final PCEPSession session, final TerminationReason cause) {
+ logger.debug("Session terminated. Cause : {}", cause);
}
}
import java.util.ArrayList;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.opendaylight.protocol.framework.TerminationReason;
import org.opendaylight.protocol.pcep.PCEPMessage;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple Session Listener that is notified about messages and changes in the session.
}
@Override
- public void onMessage(PCEPSession session, PCEPMessage message) {
- logger.debug("Received message: " + message.getClass() + " " + message);
+ public void onMessage(final PCEPSession session, final PCEPMessage message) {
+ logger.debug("Received message: {} {}", message.getClass(), message);
this.messages.add(message);
}
@Override
- public synchronized void onSessionUp(PCEPSession session, PCEPOpenObject local,
- PCEPOpenObject remote) {
+ public synchronized void onSessionUp(final PCEPSession session, final PCEPOpenObject local, final PCEPOpenObject remote) {
logger.debug("Session up.");
this.up = true;
this.notifyAll();
}
@Override
- public void onSessionDown(PCEPSession session, PCEPCloseObject reason, Exception e) {
- logger.debug("Session down.");
+ public void onSessionDown(final PCEPSession session, final TerminationReason reason, final Exception e) {
+ logger.debug("Session down. Cause: {} or {}", reason, e);
this.up = false;
- //this.notifyAll();
+ // this.notifyAll();
}
@Override
- public void onSessionTerminated(PCEPSession session,
- TerminationReason cause) {
- logger.debug("Session terminated. Cause : " + cause.toString());
+ public void onSessionTerminated(final PCEPSession session, final TerminationReason cause) {
+ logger.debug("Session terminated. Cause : ", cause.toString());
}
}
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
- <version>2.0.2</version>
- </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
import java.util.ArrayList;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.opendaylight.protocol.framework.TerminationReason;
import org.opendaylight.protocol.pcep.PCEPMessage;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple Session Listener that is notified about messages and changes in the session.
}
@Override
- public void onMessage(PCEPSession session, PCEPMessage message) {
- logger.debug("Received message: " + message);
+ public void onMessage(final PCEPSession session, final PCEPMessage message) {
+ logger.debug("Received message: {}", message);
this.messages.add(message);
}
@Override
- public void onSessionUp(PCEPSession session, PCEPOpenObject local,
- PCEPOpenObject remote) {
+ public void onSessionUp(final PCEPSession session, final PCEPOpenObject local, final PCEPOpenObject remote) {
logger.debug("Session up.");
this.up = true;
- //this.notifyAll();
+ // this.notifyAll();
}
@Override
- public void onSessionDown(PCEPSession session, PCEPCloseObject reason, Exception e) {
- logger.debug("Session down.");
+ public void onSessionDown(final PCEPSession session, final TerminationReason reason, final Exception e) {
+ logger.debug("Session down. Cause : {} or {}", reason, e);
this.up = false;
- //this.notifyAll();
+ // this.notifyAll();
}
@Override
- public void onSessionTerminated(PCEPSession session,
- TerminationReason cause) {
- logger.debug("Session terminated. Cause : " + cause.toString());
+ public void onSessionTerminated(final PCEPSession session, final TerminationReason cause) {
+ logger.debug("Session terminated. Cause : {}", cause);
}
}
*/
package org.opendaylight.protocol.pcep.testtool;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.message.PCEPXRAddTunnelMessage;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
import org.opendaylight.protocol.pcep.object.PCEPLspObject;
}
@Override
- public void onSessionDown(final PCEPSession session, final PCEPCloseObject reason, final Exception e) {
- logger.debug("Session down because: {}", reason);
+ public void onSessionDown(final PCEPSession session, final TerminationReason cause, final Exception e) {
+ logger.debug("Session down with cause : {} or exception: {}", cause, e);
+ try {
+ session.close();
+ } catch (final IOException e1) {
+ logger.debug("Could not close session, because {}", e1.getMessage(), e1);
+ }
}
@Override