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 java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import java.util.concurrent.ConcurrentHashMap;
16 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
17 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
18 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
19 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
25 * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
27 public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
29 private final Map<FlowHash, FlowDescriptor> flowRegistry = new HashMap<>();
30 private final List<FlowHash> marks = new ArrayList();
31 private static final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
34 public FlowDescriptor retrieveIdForFlow(final FlowHash flowHash) throws FlowRegistryException {
35 FlowDescriptor flowDescriptor = flowRegistry.get(flowHash);
36 if (null != flowDescriptor) {
37 return flowDescriptor;
39 throw new FlowRegistryException("Flow hash not registered.");
44 public void store(final FlowHash flowHash, final FlowDescriptor flowDescriptor) {
45 LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}", flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowHash.hashCode());
46 synchronized (flowRegistry) {
47 flowRegistry.put(flowHash, flowDescriptor);
52 public void markToBeremoved(final FlowHash flowHash) {
53 synchronized (marks) {
56 LOG.trace("Flow hash {} was marked for removal.", flowHash.hashCode());
61 public void removeMarked() {
62 synchronized (flowRegistry) {
63 for (FlowHash flowHash : marks) {
64 LOG.trace("Removing flowDescriptor for flow hash : {}", flowHash.hashCode());
65 flowRegistry.remove(flowHash);
68 synchronized (marks) {
75 public Map<FlowHash, FlowDescriptor> getAllFlowDescriptors() {
80 public void close() throws Exception {