2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onosproject.vtnrsc.flowClassifier.impl;
18 import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.ConcurrentMap;
21 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Service;
25 import org.onosproject.vtnrsc.FlowClassifierId;
26 import org.onosproject.vtnrsc.FlowClassifier;
27 import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService;
29 import org.slf4j.Logger;
30 import static org.slf4j.LoggerFactory.getLogger;
32 import static com.google.common.base.Preconditions.checkNotNull;
33 import com.google.common.collect.ImmutableList;
36 * Provides implementation of the Flow Classifier Service.
38 @Component(immediate = true)
40 public class FlowClassifierManager implements FlowClassifierService {
42 private final Logger log = getLogger(FlowClassifierManager.class);
44 private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null";
45 private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null";
47 private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore
48 = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>();
51 private void activate() {
52 log.info("Flow Classifier service activated");
56 private void deactivate() {
57 log.info("Flow Classifier service deactivated");
61 public boolean createFlowClassifier(FlowClassifier flowClassifier) {
62 log.debug("createFlowClassifier");
63 checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
64 FlowClassifierId id = flowClassifier.flowClassifierId();
66 flowClassifierStore.put(id, flowClassifier);
67 if (!flowClassifierStore.containsKey(id)) {
68 log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString());
75 public Iterable<FlowClassifier> getFlowClassifiers() {
76 return ImmutableList.copyOf(flowClassifierStore.values());
80 public boolean hasFlowClassifier(FlowClassifierId id) {
81 checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
82 return flowClassifierStore.containsKey(id);
86 public FlowClassifier getFlowClassifier(FlowClassifierId id) {
87 checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
88 return flowClassifierStore.get(id);
92 public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
93 checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
94 FlowClassifierId id = flowClassifier.flowClassifierId();
95 return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier);
99 public boolean removeFlowClassifier(FlowClassifierId id) {
100 checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
101 flowClassifierStore.remove(id);
102 if (flowClassifierStore.containsKey(id)) {
103 log.debug("The Flow Classifier removal is failed whose identifier is {}", id.toString());