Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [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 | */ |
Marc De Leenheer | 40a544b | 2017-04-25 14:16:02 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.optical.flowrule; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 17 | |
| 18 | import org.apache.commons.lang3.tuple.Pair; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 19 | import org.onosproject.net.flow.FlowId; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 20 | import org.osgi.service.component.annotations.Component; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 21 | |
| 22 | import java.util.HashMap; |
| 23 | import java.util.Map; |
| 24 | |
Marc De Leenheer | 2898a7f | 2016-03-02 21:42:59 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Simple implementation of a local flow rule cache that stores the flow ID and priority. |
| 27 | * |
| 28 | * Use this if you have a device that does not allow you to store these fields. |
| 29 | * |
| 30 | * WARNING: Be aware that this implementation makes no attempt to use a distributed store |
| 31 | * for the cache, so do not rely on it to support fail-over in multi-instance deployments. |
| 32 | * If the instance which holds the cache goes down, you *will* be in trouble. |
| 33 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 34 | @Component(immediate = true, service = CrossConnectCache.class) |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 35 | public class DefaultCrossConnectCache implements CrossConnectCache { |
| 36 | private final Map<Integer, Pair<FlowId, Integer>> cache = new HashMap<>(); |
| 37 | |
| 38 | @Override |
| 39 | public Pair<FlowId, Integer> get(int hash) { |
| 40 | return cache.get(hash); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void set(int hash, FlowId flowId, int priority) { |
| 45 | cache.put(hash, Pair.of(flowId, priority)); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void remove(int hash) { |
| 50 | cache.remove(hash); |
| 51 | } |
| 52 | } |