Add configuration parameter for single layer 19/50819/10
authorTomas Slusny <tomas.slusny@pantheon.tech>
Mon, 23 Jan 2017 12:32:51 +0000 (13:32 +0100)
committerTomas Slusny <tomas.slusny@pantheon.tech>
Wed, 15 Feb 2017 15:13:41 +0000 (16:13 +0100)
 - Add use-single-layer-serialization to openflow-provider-config.yang
 - Pass this new configuration parameter to DeviceContext

See also: bug 7139

Change-Id: I00557cd1c0c637fcf83c42e47808a5bf96a57a1b
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.tech>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/yang/openflow-provider-config.yang
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImplTest.java

index 219ef6919be9becf0353901b527e6d6be834e1ec..ae8be1e9839916599bbff10612d4d5f50787921a 100644 (file)
@@ -84,4 +84,6 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
 
     void setMaximumTimerDelay(long maximumTimerDelay);
 
+    void setIsUseSingleLayerSerialization(Boolean useSingleLayerSerialization);
+
 }
index b4e0b098fd496158c3774744a1bf70001d37e9a5..b26a7addb87910cff8cd3f944e1d0efcf44b4d89 100644 (file)
@@ -145,5 +145,7 @@ public interface DeviceContext extends
      * @return listenable future from sal role service
      */
     ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave();
+
+    boolean isUseSingleLayerSerialization();
 }
 
index d9497d7811b9e03f02af4b47263cec3f4f04b4de..acaacd32c8acd7b1fef5c45d4f0dbcc6c7ea831f 100644 (file)
@@ -108,5 +108,13 @@ module openflow-provider-config {
             type non-zero-uint32-type;
             default 900000;
         }
+
+        leaf use-single-layer-serialization {
+            description "When true, Yang models are serialized and deserialized directly to and from format supported
+            by device, so serialization and deserialization is faster. Otherwise, models are first serialized to
+            Openflow specification models and then to format supported by device, and reversed when deserializing.";
+            type boolean;
+            default "false";
+        }
     }
-}
\ No newline at end of file
+}
index bc770118636e9759ac67ec2a909aef052e702b41..c68bfe0bd54085551f6ce2dfd73c3f5e3867fab5 100644 (file)
@@ -64,6 +64,7 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider
         openflowPluginProvider.setSkipTableFeatures(providerConfig.isSkipTableFeatures());
         openflowPluginProvider.setBasicTimerDelay(providerConfig.getBasicTimerDelay().getValue());
         openflowPluginProvider.setMaximumTimerDelay(providerConfig.getMaximumTimerDelay().getValue());
+        openflowPluginProvider.setIsUseSingleLayerSerialization(providerConfig.isUseSingleLayerSerialization());
 
         openflowPluginProvider.initialize();
 
index 470cc0d4d718953646dc5c6c87dd1cf680dbc6bf..2b647610c993542039c474fe07fa9c252f26b9c5 100644 (file)
@@ -97,6 +97,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private boolean skipTableFeatures = true;
     private long basicTimerDelay;
     private long maximumTimerDelay;
+    private boolean useSingleLayerSerialization = false;
 
     private final ThreadPoolExecutor threadPool;
     private ClusterSingletonServiceProvider singletonServicesProvider;
@@ -134,8 +135,10 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private void startSwitchConnections() {
         Futures.addCallback(Futures.allAsList(switchConnectionProviders.stream().map(switchConnectionProvider -> {
             // Inject OpenflowPlugin custom serializers and deserializers into OpenflowJava
-            SerializerInjector.injectSerializers(switchConnectionProvider);
-            DeserializerInjector.injectDeserializers(switchConnectionProvider);
+            if (useSingleLayerSerialization) {
+                SerializerInjector.injectSerializers(switchConnectionProvider);
+                DeserializerInjector.injectDeserializers(switchConnectionProvider);
+            }
 
             // Set handler of incoming connections and start switch connection provider
             switchConnectionProvider.setSwitchConnectionHandler(connectionManager);
@@ -175,7 +178,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
 
     @Override
     public void setFlowRemovedNotification(boolean isFlowRemovedNotificationOn) {
-        this.isFlowRemovedNotificationOn = this.isFlowRemovedNotificationOn;
+        this.isFlowRemovedNotificationOn = isFlowRemovedNotificationOn;
     }
 
     @Override
@@ -249,7 +252,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 notificationPublishService,
                 hashedWheelTimer,
                 convertorManager,
-                skipTableFeatures);
+                skipTableFeatures,
+                useSingleLayerSerialization);
 
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
@@ -375,4 +379,9 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         // Manually shutdown all remaining running threads in pool
         threadPool.shutdown();
     }
-}
\ No newline at end of file
+
+    @Override
+    public void setIsUseSingleLayerSerialization(Boolean useSingleLayerSerialization) {
+        this.useSingleLayerSerialization = useSingleLayerSerialization;
+    }
+}
index 515d3ec041766d3ea7c4c23eec79c24803b6c76a..cb01c5cabe2e0dd7ed805ba548e6791c0d68a9c4 100644 (file)
@@ -159,6 +159,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     private volatile CONTEXT_STATE state;
     private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
     private final DeviceManager myManager;
+    private final boolean useSingleLayerSerialization;
 
     DeviceContextImpl(
             @Nonnull final ConnectionContext primaryConnectionContext,
@@ -169,7 +170,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             final ConvertorExecutor convertorExecutor,
             final boolean skipTableFeatures,
             final HashedWheelTimer hashedWheelTimer,
-            final DeviceManager myManager) {
+            final DeviceManager myManager,
+            final boolean useSingleLayerSerialization) {
         this.primaryConnectionContext = primaryConnectionContext;
         this.deviceInfo = primaryConnectionContext.getDeviceInfo();
         this.hashedWheelTimer = hashedWheelTimer;
@@ -197,6 +199,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         this.state = CONTEXT_STATE.INITIALIZATION;
         this.convertorExecutor = convertorExecutor;
         this.skipTableFeatures = skipTableFeatures;
+        this.useSingleLayerSerialization = useSingleLayerSerialization;
         this.initialized = false;
     }
 
@@ -644,6 +647,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         this.onPublished();
     }
 
+    @Override
+    public boolean isUseSingleLayerSerialization() {
+        return useSingleLayerSerialization;
+    }
+
     @Override
     public boolean isSkipTableFeatures() {
         return this.skipTableFeatures;
index d88cb1c359489f4ceb7f40a977c29bd5411f1c0f..9144f61d5e009c20c62c868e91082d213dcd5207 100644 (file)
@@ -95,6 +95,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private final NotificationPublishService notificationPublishService;
     private final MessageSpy messageSpy;
     private final HashedWheelTimer hashedWheelTimer;
+    private final boolean useSingleLayerSerialization;
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
                              final long globalNotificationQuota,
@@ -107,7 +108,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                              final NotificationPublishService notificationPublishService,
                              final HashedWheelTimer hashedWheelTimer,
                              final ConvertorExecutor convertorExecutor,
-                             final boolean skipTableFeatures) {
+                             final boolean skipTableFeatures,
+                             final boolean useSingleLayerSerialization) {
 
         this.dataBroker = dataBroker;
 
@@ -135,6 +137,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         this.singletonServiceProvider = singletonServiceProvider;
         this.notificationPublishService = notificationPublishService;
         this.messageSpy = messageSpy;
+        this.useSingleLayerSerialization = useSingleLayerSerialization;
     }
 
 
@@ -205,7 +208,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 convertorExecutor,
                 skipTableFeatures,
                 hashedWheelTimer,
-                this);
+                this,
+                useSingleLayerSerialization);
 
         deviceContext.setSalRoleService(new SalRoleServiceImpl(deviceContext, deviceContext));
         deviceContexts.put(deviceInfo, deviceContext);
index e5a3167bc5ab581e4ad722f752e958c669d2525c..ffba264ed470f4417bc61f729a3eef5f6b65627e 100644 (file)
@@ -230,7 +230,7 @@ public class DeviceContextImplTest {
                 translatorLibrary,
                 deviceManager,
                 convertorExecutor,
-                false, timer, deviceManager);
+                false, timer, deviceManager, false);
         deviceContextSpy = Mockito.spy(deviceContext);
 
         xid = new Xid(atomicLong.incrementAndGet());
@@ -243,12 +243,12 @@ public class DeviceContextImplTest {
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
-        new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor,false, timer, deviceManager).close();
+        new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor,false, timer, deviceManager, false).close();
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullTimer() throws Exception {
-        new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor,false, timer, deviceManager).close();
+        new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor,false, timer, deviceManager, false).close();
     }
 
     @Test
index 33e54b4d7c313e1bab26b678954fc151a8c95a3c..237839ad3d941f5b7dfdac467b55fe0bac7642e8 100644 (file)
@@ -156,6 +156,7 @@ public class DeviceManagerImplTest {
                 null,
                 new HashedWheelTimer(),
                 convertorExecutor,
+                false,
                 false);
 
         deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);