blob: 724ec95a045e1955b2ff730f2a2d1ba0a465f855 [file] [log] [blame]
Mahesh Poojary Huaweiaec251d2015-12-04 02:27:45 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Mahesh Poojary Huaweiaec251d2015-12-04 02:27:45 +05303 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package org.onosproject.sfc.util;
17
18import java.util.concurrent.ConcurrentMap;
19import java.util.concurrent.ConcurrentHashMap;
20
21import org.onosproject.vtnrsc.FlowClassifierId;
22import org.onosproject.vtnrsc.FlowClassifier;
23import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
24import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
25
26import com.google.common.collect.ImmutableList;
27
28/**
29 * Provides implementation of the Flow Classifier Service.
30 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053031public class FlowClassifierAdapter implements FlowClassifierService {
Mahesh Poojary Huaweiaec251d2015-12-04 02:27:45 +053032
33 private final ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore = new ConcurrentHashMap<>();
34
35 @Override
36 public boolean exists(FlowClassifierId id) {
37 return flowClassifierStore.containsKey(id);
38 }
39
40 @Override
41 public int getFlowClassifierCount() {
42 return flowClassifierStore.size();
43 }
44
45 @Override
46 public Iterable<FlowClassifier> getFlowClassifiers() {
47 return ImmutableList.copyOf(flowClassifierStore.values());
48 }
49
50 @Override
51 public FlowClassifier getFlowClassifier(FlowClassifierId id) {
52 return flowClassifierStore.get(id);
53 }
54
55 @Override
56 public boolean createFlowClassifier(FlowClassifier flowClassifier) {
57 FlowClassifierId id = flowClassifier.flowClassifierId();
58
59 flowClassifierStore.put(id, flowClassifier);
60 if (!flowClassifierStore.containsKey(id)) {
61 return false;
62 }
63 return true;
64 }
65
66 @Override
67 public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
68
69 if (!flowClassifierStore.containsKey(flowClassifier.flowClassifierId())) {
70 return false;
71 }
72
73 flowClassifierStore.put(flowClassifier.flowClassifierId(), flowClassifier);
74
75 if (!flowClassifier.equals(flowClassifierStore.get(flowClassifier.flowClassifierId()))) {
76 return false;
77 }
78 return true;
79 }
80
81 @Override
82 public boolean removeFlowClassifier(FlowClassifierId id) {
83 return true;
84 }
85
86 @Override
87 public void addListener(FlowClassifierListener listener) {
88 }
89
90 @Override
91 public void removeListener(FlowClassifierListener listener) {
92 }
93}