Clustering - adding to LispSouthboundPlugin.
[lispflowmapping.git] / mappingservice / southbound / src / main / java / org / opendaylight / lispflowmapping / southbound / lisp / LispSouthboundHandler.java
index a4b7aab055fb1a4d6b274371fd9d9d9bfa94c0f4..2b4cef6af38fd0d26f9b5047fd585575544ca3c7 100644 (file)
@@ -100,6 +100,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     private SimpleMapCache smc;
     private AuthenticationKeyDataListener authenticationKeyDataListener;
     private DataStoreBackEnd dsbe;
+    private boolean isReadFromChannelEnabled = true;
 
     public LispSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
         this.lispSbPlugin = lispSbPlugin;
@@ -241,8 +242,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
                         final MapRegisterCacheValueBuilder cacheValueBldNew = new MapRegisterCacheValueBuilder();
                         cacheValueBldNew.setPacketData(artificialEntry.getValue());
-                        cacheValueBldNew.setAuthKeyValue(mappingAuthkey.getKeyString());
-                        cacheValueBldNew.setAuthKeyType(mappingAuthkey.getKeyType());
+                        cacheValueBldNew.setMappingAuthkey(mappingAuthkey);
                         cacheValueBldNew.setMapRegisterCacheMetadata(cacheMetadataBldNew.build());
 
                         mapRegisterCache.addEntry(cacheKey, cacheValueBldNew.build());
@@ -283,8 +283,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
                 final MapRegisterCacheMetadataBuilder newMapRegisterCacheMetadataBuilder =
                         new MapRegisterCacheMetadataBuilder(mapRegisterCacheValue.getMapRegisterCacheMetadata());
 
-                newMapRegisterCacheValueBuilder.setAuthKeyValue(mappingAuthkey.getKeyString());
-                newMapRegisterCacheValueBuilder.setAuthKeyType(mappingAuthkey.getKeyType());
+                newMapRegisterCacheValueBuilder.setMappingAuthkey(mappingAuthkey);
                 newMapRegisterCacheValueBuilder.setMapRegisterCacheMetadata(newMapRegisterCacheMetadataBuilder.build());
                 return newMapRegisterCacheValueBuilder.build();
             }
@@ -348,10 +347,10 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
     private void sendMapNotifyMsg(final ByteBuffer inBuffer, final InetAddress inetAddress, int portNumber,
                                   MapRegisterCacheValue mapRegisterValue) {
-        if (mapRegisterValue.getAuthKeyType() != null) {
+        if (mapRegisterValue.getMappingAuthkey().getKeyType() != null) {
             ByteBuffer outBuffer = transformMapRegisterToMapNotify(inBuffer);
-            if (mapRegisterValue.getAuthKeyType() != 0) {
-                outBuffer = calculateAndSetNewMAC(outBuffer, mapRegisterValue.getAuthKeyValue());
+            if (mapRegisterValue.getMappingAuthkey().getKeyType() != 0) {
+                outBuffer = calculateAndSetNewMAC(outBuffer, mapRegisterValue.getMappingAuthkey().getKeyString());
             }
             outBuffer.position(0);
             lispSbPlugin.handleSerializedLispBuffer(inetAddress, outBuffer, MessageType.MapNotify, portNumber);
@@ -506,11 +505,13 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
-                    msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+        if (isReadFromChannelEnabled) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
+                        msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+            }
+            handlePacket(msg);
         }
-        handlePacket(msg);
     }
 
     @Override
@@ -571,4 +572,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
         dsbe = new DataStoreBackEnd(dataBroker);
     }
+
+    public void setIsReadFromChannelEnabled(boolean isReadFromChannelEnabled) {
+        this.isReadFromChannelEnabled = isReadFromChannelEnabled;
+    }
 }