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.HashMap;
14 import java.util.List;
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 final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
34 public FlowDescriptor retrieveIdForFlow(final FlowHash flowHash) throws FlowRegistryException {
35 if (flowRegistry.containsKey(flowHash)) {
36 return flowRegistry.get(flowHash);
38 throw new FlowRegistryException("Flow hash not registered.");
43 public void store(final FlowHash flowHash, final FlowDescriptor flowDescriptor) {
44 LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}", flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowHash.hashCode());
45 flowRegistry.put(flowHash, flowDescriptor);
49 public void markToBeremoved(final FlowHash flowHash) {
51 LOG.trace("Flow hash {} was marked for removal.", flowHash.hashCode());
56 public void removeMarked() {
57 for (FlowHash flowHash : marks) {
58 LOG.trace("Removing flowDescriptor for flow hash : {}", flowHash.hashCode());
59 flowRegistry.remove(flowHash);
66 public Map<FlowHash, FlowDescriptor> getAllFlowDescriptors() {
67 return ImmutableMap.copyOf(flowRegistry);