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