blob: 80f62a58405adf41e603e4b7c76f41ce6527ea8a [file] [log] [blame]
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16package org.onosproject.pce.util;
17
18import com.google.common.collect.ImmutableSet;
19
20import java.util.concurrent.ConcurrentHashMap;
21import java.util.concurrent.ConcurrentMap;
Avantika-Huawei28b53752016-06-23 17:04:49 +053022
23import java.util.HashMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053024import java.util.HashSet;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053025import java.util.Map;
26import java.util.Set;
27import java.util.stream.Collectors;
28
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053029import org.onosproject.incubator.net.tunnel.TunnelId;
Priyankab-Huawei3946d732016-10-11 06:24:38 +000030import org.onosproject.net.DeviceId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053031import org.onosproject.net.resource.ResourceConsumer;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053032import org.onosproject.pce.pcestore.PcePathInfo;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053033import org.onosproject.pce.pcestore.api.PceStore;
34
35/**
36 * Provides test implementation of PceStore.
37 */
38public class PceStoreAdapter implements PceStore {
39
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053040 // Mapping tunnel with device local info with tunnel consumer id
Avantika-Huawei9e848e82016-09-01 12:12:42 +053041 private ConcurrentMap<TunnelId, ResourceConsumer> tunnelInfoMap = new ConcurrentHashMap<>();
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053042
43 // Set of Path info
44 private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
45
Priyankab-Huawei3946d732016-10-11 06:24:38 +000046 // Locally maintain LSRID to device id mapping for better performance.
47 private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
Avantika-Huawei28b53752016-06-23 17:04:49 +053048
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053049 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053050 public boolean existsTunnelInfo(TunnelId tunnelId) {
51 return tunnelInfoMap.containsKey(tunnelId);
52 }
53
54 @Override
55 public boolean existsFailedPathInfo(PcePathInfo pathInfo) {
56 return failedPathInfoSet.contains(pathInfo);
57 }
58
59 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053060 public int getTunnelInfoCount() {
61 return tunnelInfoMap.size();
62 }
63
64 @Override
65 public int getFailedPathInfoCount() {
66 return failedPathInfoSet.size();
67 }
68
69 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053070 public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053071 return tunnelInfoMap.entrySet().stream()
Avantika-Huawei9e848e82016-09-01 12:12:42 +053072 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053073 }
74
75 @Override
76 public Iterable<PcePathInfo> getFailedPathInfos() {
77 return ImmutableSet.copyOf(failedPathInfoSet);
78 }
79
80 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053081 public ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053082 return tunnelInfoMap.get(tunnelId);
83 }
84
85 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053086 public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
87 tunnelInfoMap.put(tunnelId, tunnelConsumerId);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053088 }
89
90 @Override
91 public void addFailedPathInfo(PcePathInfo pathInfo) {
92 failedPathInfoSet.add(pathInfo);
93 }
94
95 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053096 public boolean removeTunnelInfo(TunnelId tunnelId) {
97 tunnelInfoMap.remove(tunnelId);
98 if (tunnelInfoMap.containsKey(tunnelId)) {
99 return false;
100 }
101 return true;
102 }
103
104 @Override
105 public boolean removeFailedPathInfo(PcePathInfo pathInfo) {
106 if (failedPathInfoSet.remove(pathInfo)) {
107 return false;
108 }
109 return true;
110 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530111}