blob: 4c561d3327d4be75d4738348ddcf34a2646cc78d [file] [log] [blame]
Marc De Leenheerc662d322016-02-18 16:05:10 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Marc De Leenheerc662d322016-02-18 16:05:10 -08003 *
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 Leenheer40a544b2017-04-25 14:16:02 -070016package org.onosproject.driver.optical.flowrule;
Marc De Leenheerc662d322016-02-18 16:05:10 -080017
18import org.apache.commons.lang3.tuple.Pair;
Marc De Leenheerc662d322016-02-18 16:05:10 -080019import org.onosproject.net.flow.FlowId;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.osgi.service.component.annotations.Component;
Marc De Leenheerc662d322016-02-18 16:05:10 -080021
22import java.util.HashMap;
23import java.util.Map;
24
Marc De Leenheer2898a7f2016-03-02 21:42:59 -080025/**
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 Milkeyd84f89b2018-08-17 14:54:17 -070034@Component(immediate = true, service = CrossConnectCache.class)
Marc De Leenheerc662d322016-02-18 16:05:10 -080035public 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}