return ((InetSocketAddress) this.channel.remoteAddress()).getAddress();
}
+ private synchronized void closeWithoutMessage(final TerminationReason reason) {
+ LOG.info("Closing PCEP session without sending msg: {}", reason);
+ this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
+ this.closed = true;
+ this.close();
+ }
+
private synchronized void terminate(final TerminationReason reason) {
LOG.info("Local PCEP session termination : {}", reason);
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
* exception is CLOSE message, which needs to be converted into a
* session DOWN event.
*/
- this.close();
+ this.closeWithoutMessage(TerminationReason.forValue(((CloseMessage) msg).getCCloseMessage().getCClose().getReason()));
} else {
// This message needs to be handled by the user
if (msg instanceof PcerrMessage) {
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Starttls;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.StarttlsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.start.tls.message.StartTlsMessageBuilder;
protected Open openMsg;
+ protected Close closeMsg;
+
protected Starttls startTlsMsg;
protected Keepalive kaMsg;
DEADTIMER).setKeepalive(KEEP_ALIVE).setSessionId((short) 0).build()).build()).build();
this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
this.startTlsMsg = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build();
+ this.closeMsg = new CloseBuilder().setCCloseMessage(
+ new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason((short) 6).build()).build()).build();
this.listener = new SimpleSessionListener();
Assert.assertTrue(this.listener.messages.get(0) instanceof Pcreq);
Assert.assertEquals(2, this.session.getMessages().getReceivedMsgCount().intValue());
- this.session.handleMessage(new CloseBuilder().build());
+ this.session.handleMessage(this.closeMsg);
Assert.assertEquals(3, this.session.getMessages().getReceivedMsgCount().intValue());
Assert.assertEquals(1, this.listener.messages.size());
Assert.assertTrue(this.channel.isActive());
Assert.assertEquals(PCEPErrors.ATTEMPT_2ND_SESSION, PCEPErrors.forValue(errorObj.getType(), errorObj.getValue()));
}
+ @Test
+ public void testClosedByNode() {
+ this.session.handleMessage(this.closeMsg);
+ Mockito.verify(this.channel).close();
+ }
+
@Test
public void testCapabilityNotSupported() {
this.session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);