@Override
void close();
-}
+}
\ No newline at end of file
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Maps;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
private static final String ALIEN_SYSTEM_FLOW_ID = "#UF$TABLE*";
private static final AtomicInteger UNACCOUNTED_FLOWS_COUNTER = new AtomicInteger(0);
- private final ConcurrentMap<FlowRegistryKey, FlowDescriptor> flowRegistry = new TrieMap<>();
+
+ private final BiMap<FlowRegistryKey, FlowDescriptor> flowRegistry = HashBiMap.create();
@GuardedBy("marks")
private final Collection<FlowRegistryKey> marks = new HashSet<>();
private final DataBroker dataBroker;
public FlowDescriptor retrieveIdForFlow(final FlowRegistryKey flowRegistryKey) {
LOG.trace("Retrieving flowDescriptor for flow hash: {}", flowRegistryKey.hashCode());
FlowDescriptor flowDescriptor = flowRegistry.get(flowRegistryKey);
+ // Get FlowDescriptor from flow registry
if(flowDescriptor == null){
for(Map.Entry<FlowRegistryKey, FlowDescriptor> fd : flowRegistry.entrySet()) {
if (fd.getKey().equals(flowRegistryKey)) {
}
}
}
- // Get FlowDescriptor from flow registry
return flowDescriptor;
}
+
@Override
public void store(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
- LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}", flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
- flowRegistry.put(flowRegistryKey, flowDescriptor);
+ LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
+ flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
+ try {
+ flowRegistry.put(flowRegistryKey, flowDescriptor);
+ } catch (IllegalArgumentException ex) {
+ LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
+ flowDescriptor.getTableKey().getId());
+ final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
+ final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
+ create(flowDescriptor.getTableKey().getId(), newFlowId);
+ flowRegistry.put(flowRegistryKey, newFlowDescriptor);
+ }
}
@Override
final String alienId = ALIEN_SYSTEM_FLOW_ID + tableId + '-' + UNACCOUNTED_FLOWS_COUNTER.incrementAndGet();
return new FlowId(alienId);
}
-}
+}
\ No newline at end of file
package org.opendaylight.openflowplugin.impl.registry.flow;
+import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
this.tableKey = tableKey;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ FlowDescriptorDto that = (FlowDescriptorDto) o;
+ return Objects.equal(flowId, that.flowId) &&
+ Objects.equal(tableKey, that.tableKey);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(flowId, tableKey);
+ }
+
@Override
public FlowId getFlowId() {
return flowId;
return tableKey;
}
}
-}
+}
\ No newline at end of file
@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
- final FlowId flowId;
- 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 = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
- flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
- }
-
- LOG.trace("Calling add flow for flow with ID ={}.", flowId);
final ListenableFuture<RpcResult<AddFlowOutput>> future =
flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
@Override
public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
if (rpcResult.isSuccessful()) {
+ final FlowId flowId;
+ 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 = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
+ flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
+ }
+
if(LOG.isDebugEnabled()) {
LOG.debug("flow add with id={},finished without error,", flowId.getValue());
}
}
} else {
deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
- LOG.error("flow add failed for id={}, errors={}", flowId.getValue(),
+ LOG.error("flow add failed for flow={}, errors={}", input.toString(),
errorsToString(rpcResult.getErrors()));
}
}
@Override
public void onFailure(final Throwable throwable) {
- deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
- LOG.error("Service call for adding flow with id={} failed, reason {} .", flowId.getValue(), throwable);
+ LOG.error("Service call for adding flow={} failed, reason {} .", input.toString(), throwable);
}
});
itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
}
}
-
-
}
}
.child(Table.class, flowDescriptor.getTableKey())
.child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
}
-}
+}
\ No newline at end of file
@Override
public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
- deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
final ListenableFuture<RpcResult<AddGroupOutput>> resultFuture = addGroup.handleServiceCall(input);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddGroupOutput>>() {
@Override
if(LOG.isDebugEnabled()) {
LOG.debug("group add with id={} finished without error", input.getGroupId().getValue());
}
+ deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
addIfNecessaryToDS(input.getGroupId(), input);
} else {
- deviceContext.getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
LOG.error("group add with id={} failed, errors={}", input.getGroupId().getValue(),
errorsToString(result.getErrors()));
}
@Override
public void onFailure(Throwable t) {
- deviceContext.getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
LOG.error("Service call for group add failed for id={}. Exception: {}", input.getGroupId().getValue(), t);
}
});
@Override
public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
- removeGroup.getDeviceRegistry().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
final ListenableFuture<RpcResult<RemoveGroupOutput>> resultFuture = removeGroup.handleServiceCall(input);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveGroupOutput>>() {
@Override
if(LOG.isDebugEnabled()) {
LOG.debug("Group remove for id {} succeded", input.getGroupId().getValue());
}
+ removeGroup.getDeviceRegistry().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
removeIfNecessaryFromDS(input.getGroupId());
}else{
LOG.error("group remove failed with id={}, errors={}", input.getGroupId().getValue(),
}
return errors.toString();
}
-}
+}
\ No newline at end of file
@Override
public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
- deviceContext.getDeviceMeterRegistry().store(input.getMeterId());
+
final ListenableFuture<RpcResult<AddMeterOutput>> resultFuture = addMeter.handleServiceCall(input);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddMeterOutput>>() {
@Override
public void onSuccess(@Nullable RpcResult<AddMeterOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
+ if(LOG.isDebugEnabled()) {
LOG.debug("Meter add finished without error, id={}", input.getMeterId());
}
+ deviceContext.getDeviceMeterRegistry().store(input.getMeterId());
addIfNecessaryToDS(input.getMeterId(),input);
} else {
- deviceContext.getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
LOG.error("Meter add with id {} failed with error {}", input.getMeterId(),
errorsToString(result.getErrors()));
}
@Override
public void onFailure(Throwable t) {
- deviceContext.getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
- LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
+ LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
}
});
@Override
public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
final ListenableFuture<RpcResult<UpdateMeterOutput>> resultFuture = updateMeter.handleServiceCall(input.getUpdatedMeter());
-
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<UpdateMeterOutput>>() {
@Override
}
return errors.toString();
}
-}
+}
\ No newline at end of file