2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.registry.flow;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
16 import java.util.concurrent.ConcurrentHashMap;
17 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
18 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
19 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
20 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryException;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
26 * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
28 public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
30 private final Map<FlowHash, FlowDescriptor> flowRegistry = new ConcurrentHashMap<>();
31 private final List<FlowHash> marks = Collections.synchronizedList(new ArrayList());
32 private final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
35 public FlowDescriptor retrieveIdForFlow(final FlowHash flowHash) throws FlowRegistryException {
36 FlowDescriptor flowDescriptor = flowRegistry.get(flowHash);
37 if (null != flowDescriptor) {
38 return flowDescriptor;
40 throw new FlowRegistryException("Flow hash not registered.");
45 public void store(final FlowHash flowHash, final FlowDescriptor flowDescriptor) {
46 LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}", flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowHash.hashCode());
47 flowRegistry.put(flowHash, flowDescriptor);
51 public void markToBeremoved(final FlowHash flowHash) {
53 LOG.trace("Flow hash {} was marked for removal.", flowHash.hashCode());
58 public void removeMarked() {
59 for (FlowHash flowHash : marks) {
60 LOG.trace("Removing flowDescriptor for flow hash : {}", flowHash.hashCode());
61 flowRegistry.remove(flowHash);
68 public Map<FlowHash, FlowDescriptor> getAllFlowDescriptors() {
69 return ImmutableMap.copyOf(flowRegistry);
73 public void close() throws Exception {