Make Channel an argument to handleSerializedLispBuffer() 64/47664/4
authorLorand Jakab <lojakab@cisco.com>
Thu, 27 Oct 2016 11:26:14 +0000 (14:26 +0300)
committerLori Jakab <lorand.jakab@gmail.com>
Fri, 28 Oct 2016 11:51:32 +0000 (11:51 +0000)
In preparation for multi-threading, this patch allows the sender channel
to be passed as an argument to handleSerializedLispBuffer() which puts
the packet on the wire.  Since the ChannelHandlerContext passed to
channelRead() has the original channel where the packet was received, we
can use it to send out the packet on the same channel, instead of using
just one channel for sending in LispSouthboundPlugin.

Change-Id: I1cd6205f8dc2e5431f73910ed1563773a1b12a1c
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/MapRegisterCacheTestUtil.java

index d1cf0f1f89afc977189d8a1defbee4701a28b27f..246763348c49bd4af93ce50aa243999bb914ea98 100644 (file)
@@ -207,11 +207,14 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     public void handleSerializedLispBuffer(TransportAddress address, ByteBuffer outBuffer,
                                            final MessageType packetType) {
         InetAddress ip = getInetAddress(address);
-        handleSerializedLispBuffer(ip, outBuffer, packetType, address.getPort().getValue());
+        handleSerializedLispBuffer(ip, outBuffer, packetType, address.getPort().getValue(), null);
     }
 
     public void handleSerializedLispBuffer(InetAddress address, ByteBuffer outBuffer,
-            final MessageType packetType, final int portNumber) {
+            final MessageType packetType, final int portNumber, Channel senderChannel) {
+        if (senderChannel == null) {
+            senderChannel = this.channel;
+        }
         InetSocketAddress recipient = new InetSocketAddress(address, portNumber);
         outBuffer.position(0);
         ByteBuf data = wrappedBuffer(outBuffer);
@@ -220,7 +223,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
         if (LOG.isTraceEnabled()) {
             LOG.trace("Buffer:\n{}", ByteBufUtil.prettyHexDump(data));
         }
-        channel.write(packet).addListener(new ChannelFutureListener() {
+        senderChannel.write(packet).addListener(new ChannelFutureListener() {
             @Override
             public void operationComplete(ChannelFuture future) {
                 if (future.isSuccess()) {
@@ -232,7 +235,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
                 }
             }
         });
-        channel.flush();
+        senderChannel.flush();
     }
 
     private InetAddress getInetAddress(TransportAddress address) {
index 0ba084a8bb9bd463581ea69448079010d32752aa..3c42818a49154778d19519672790fe379d6012d7 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.lispflowmapping.southbound.lisp;
 
 import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
@@ -90,6 +91,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     private DataStoreBackEnd dsbe;
     private boolean isReadFromChannelEnabled = true;
 
+    private Channel channel;
+
     public LispSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
         this.lispSbPlugin = lispSbPlugin;
     }
@@ -340,7 +343,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
                 outBuffer = calculateAndSetNewMAC(outBuffer, mapRegisterValue.getMappingAuthkey().getKeyString());
             }
             outBuffer.position(0);
-            lispSbPlugin.handleSerializedLispBuffer(inetAddress, outBuffer, MessageType.MapNotify, portNumber);
+            lispSbPlugin.handleSerializedLispBuffer(inetAddress, outBuffer, MessageType.MapNotify, portNumber,
+                    this.channel);
         } else {
             LOG.error("Map-Register Cache: authentication succeeded, but can't find auth key for sending Map-Notify");
         }
@@ -493,6 +497,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
                 LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
                         msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
             }
+            this.channel = ctx.channel();
             handlePacket(msg);
         }
     }
index 4ed6f658af921d07916e408e1bf80672a9655636..4f31b7a4b1d9d272795fd02a06f241ec9ed9baee 100644 (file)
@@ -119,7 +119,8 @@ final class MapRegisterCacheTestUtil {
                 Mockito.eq(Inet4Address.getByAddress("0.0.0.0", new byte[]{0, 0, 0, 0})),
                 Mockito.eq(byteBuffer),
                 Mockito.eq(MessageType.MapNotify),
-                Mockito.eq(0));
+                Mockito.eq(0),
+                Mockito.eq(null));
     }
 
     static void afterMapRegisterInvocationValidation(final NotificationPublishService mockedNotificationProvider, final