fixe NPE when logging in add flow's future callback 57/20557/1
authorMartin Bobak <mbobak@cisco.com>
Fri, 15 May 2015 19:13:09 +0000 (21:13 +0200)
committerMartin Bobak <mbobak@cisco.com>
Fri, 15 May 2015 19:13:09 +0000 (21:13 +0200)
Change-Id: Iaf53511e8b1f09676ddb7284b3c5b239d778c1d4
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java

index b9d66c341576e3157a875df915172efa05e34979..6089fee21486f5512b44f258464db3dd3a8644b3 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
+import org.opendaylight.openflowplugin.impl.util.FlowUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
@@ -65,12 +66,18 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
 
         final List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(input, getVersion(), getDatapathId());
         final ListenableFuture<RpcResult<AddFlowOutput>> future = processFlowModInputBuilders(ofFlowModInputs);
+        final FlowId flowId;
+        if (null != input.getFlowRef()) {
+            flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+        } else {
+            flowId = FlowUtil.createAlienFlowId(input.getTableId());
+        }
 
         Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
 
             final DeviceContext deviceContext = getDeviceContext();
             final FlowHash flowHash = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
-            FlowId flowId = null;
+
             @Override
             public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
                 if (rpcResult.isSuccessful()) {