Mahesh Poojary Huawei | aec251d | 2015-12-04 02:27:45 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary Huawei | aec251d | 2015-12-04 02:27:45 +0530 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.sfc.util; |
| 17 | |
| 18 | import java.util.concurrent.ConcurrentMap; |
| 19 | import java.util.concurrent.ConcurrentHashMap; |
| 20 | |
| 21 | import org.onosproject.vtnrsc.FlowClassifierId; |
| 22 | import org.onosproject.vtnrsc.FlowClassifier; |
| 23 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener; |
| 24 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
| 25 | |
| 26 | import com.google.common.collect.ImmutableList; |
| 27 | |
| 28 | /** |
| 29 | * Provides implementation of the Flow Classifier Service. |
| 30 | */ |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 31 | public class FlowClassifierAdapter implements FlowClassifierService { |
Mahesh Poojary Huawei | aec251d | 2015-12-04 02:27:45 +0530 | [diff] [blame] | 32 | |
| 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 | } |