Fixed PCE's remote and local address 06/10006/5
authorMilos Fabian <milfabia@cisco.com>
Fri, 15 Aug 2014 12:15:03 +0000 (14:15 +0200)
committerMilos Fabian <milfabia@cisco.com>
Mon, 18 Aug 2014 09:10:59 +0000 (09:10 +0000)
-server's channel remote and local address are reversed
if channel has parent channel - return proper values,
since remote address is used to build pcc's node-id

-hit the issue while testing PCC Mock with ODL's PCE on localhost

Change-Id: I0f764a606fde2336c51e085184cf0feb08cb748a
Signed-off-by: Milos Fabian <milfabia@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java

index 5739ad1767c4b3248b595179d03b5174b681b966..07bb6386afddf6a49866b8b33cae2492e43b6f99 100644 (file)
@@ -119,7 +119,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
             }, getKeepAliveTimerValue(), TimeUnit.SECONDS);
         }
 
-        LOG.info("Session {}[{}] <-> {}[{}] started", channel.localAddress(), localOpen.getSessionId(), channel.remoteAddress(),
+        LOG.info("Session {}[{}] <-> {}[{}] started", getLocalAddress(), localOpen.getSessionId(), getRemoteAddress(),
             remoteOpen.getSessionId());
     }
 
@@ -233,9 +233,19 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
     @Override
     public InetAddress getRemoteAddress() {
+        if (this.channel.parent() != null) {
+            return ((InetSocketAddress) this.channel.localAddress()).getAddress();
+        }
         return ((InetSocketAddress) this.channel.remoteAddress()).getAddress();
     }
 
+    private InetAddress getLocalAddress() {
+        if (this.channel.parent() != null) {
+            return ((InetSocketAddress) this.channel.remoteAddress()).getAddress();
+        }
+        return ((InetSocketAddress) this.channel.localAddress()).getAddress();
+    }
+
     private synchronized void terminate(final TerminationReason reason) {
         LOG.info("Local PCEP session termination : {}", reason);
         this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
index e8b8966419538e0c3c5aae6d411567e3590cedca..4f5a1e9ef3d0010e0b2401a52440ddbc65f9a328 100644 (file)
@@ -88,6 +88,7 @@ public class FiniteStateMachineTest {
                 return future;
             }
         }).when(this.clientListener).writeAndFlush(any(Notification.class));
+        doReturn(null).when(this.clientListener).parent();
         doReturn("TestingChannel").when(this.clientListener).toString();
         doReturn(this.pipeline).when(this.clientListener).pipeline();
         doReturn(this.address).when(this.clientListener).localAddress();
index c3d819f72bf790d5ac2e0e68b60da5cefb016fd3..013ab9a52ca41d01a2376a9eb871d5be2a87e1bc 100644 (file)
@@ -111,6 +111,7 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         doReturn(ra).when(this.clientListener).remoteAddress();
         final SocketAddress la = new InetSocketAddress("127.0.0.1", 30000);
         doReturn(la).when(this.clientListener).localAddress();
+        doReturn(null).when(this.clientListener).parent();
 
         doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();