import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
-import org.opendaylight.openflowplugin.impl.util.FlowUtil;
import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
+ final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
final FlowId flowId;
- if (null != input.getFlowRef()) {
+ final FlowDescriptor flowDescriptor;
+
+ if (Objects.nonNull(input.getFlowRef())) {
flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+ flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
+ deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
} else {
- flowId = FlowUtil.createAlienFlowId(input.getTableId());
+ flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
+ flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
}
+
LOG.trace("Calling add flow for flow with ID ={}.", flowId);
- final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
- final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
- deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
final ListenableFuture<RpcResult<AddFlowOutput>> future =
flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
final FlowRef flowRef = input.getFlowRef();
final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
- deviceFlowRegistry.markToBeremoved(flowRegistryKey);
- if (itemLifecycleListener != null) {
- final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
- if (flowDescriptor != null) {
+ if (flowRef == null) { //then this is equivalent to a delete
+ deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+
+ if (itemLifecycleListener != null) {
+ final FlowDescriptor flowDescriptor =
+ deviceContext.getDeviceFlowRegistry().retrieveIdForFlow( flowRegistryKey);
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(flowPath);
}
- }
- //if provided, store flow id to flow registry
- if (flowRef != null) {
+ } else { //this is either an add or an update
final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- final FlowBuilder flowBuilder = new FlowBuilder(input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
- itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+ final FlowBuilder flowBuilder = new FlowBuilder(
+ input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
+
+ boolean isUpdate = null !=
+ deviceFlowRegistry.retrieveIdForFlow(flowRegistryKey);
+ if (isUpdate) {
+ itemLifecycleListener.onUpdated(flowPath, flowBuilder.build());
+ } else {
+ itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+ }
}
+
+
}
}