Bug 8667 - PCEP: When peer closes got IO exception 38/58638/12
authormatcauf <mcauffiez@inocybe.ca>
Fri, 9 Jun 2017 21:10:03 +0000 (17:10 -0400)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 7 Jul 2017 07:45:46 +0000 (07:45 +0000)
When peer closes the pcep session, it results on IO
Exception.
it is due to this close is not recognized as local pcep
PCEP session termination.
It was first implemented as a local pcep session
termination.
https://git.opendaylight.org/gerrit/#/c/906/1/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
Solution: Use the reason encapsulated in the close message to close the session.

Change-Id: Ia423f5c10b117ef21af5a3bddc28652ebb659e26
Signed-off-by: matcauf <mcauffiez@inocybe.ca>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java

index 04152c312257442f71c946b26ef88cd74cdb5c42..71469745c0ecc3d3a79807051a1d78cf281a37da 100644 (file)
@@ -239,6 +239,13 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler<Message> implem
         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));
@@ -316,7 +323,7 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler<Message> implem
              * 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) {
index 59ad5969e898cfc8fb1115bff593de881617efe5..d17f81d4e7ba9dd4ffb849d31ba7fba57d355f46 100644 (file)
@@ -30,12 +30,16 @@ import org.junit.Before;
 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;
@@ -70,6 +74,8 @@ public class AbstractPCEPSessionTest {
 
     protected Open openMsg;
 
+    protected Close closeMsg;
+
     protected Starttls startTlsMsg;
 
     protected Keepalive kaMsg;
@@ -106,6 +112,8 @@ public class AbstractPCEPSessionTest {
                                 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();
index 8eccb4b8e48389108253dd24b1bcbf7ae44a7bbb..1704c5264e497436dd3385c5da0600930e5f2f8b 100644 (file)
@@ -55,7 +55,7 @@ public class PCEPSessionImplTest extends AbstractPCEPSessionTest {
         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());
@@ -76,6 +76,12 @@ public class PCEPSessionImplTest extends AbstractPCEPSessionTest {
         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);