blob: cba8801510d6f4d11bd5f6ccec1d9e9658a4e6e5 [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;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053025import java.util.List;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053026import java.util.Map;
27import java.util.Set;
28import java.util.stream.Collectors;
29
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053030import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053031import org.onosproject.net.resource.ResourceConsumer;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053032import org.onosproject.pce.pceservice.ExplicitPathInfo;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053033import org.onosproject.pce.pcestore.PcePathInfo;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053034import org.onosproject.pce.pcestore.api.PceStore;
35
36/**
37 * Provides test implementation of PceStore.
38 */
39public class PceStoreAdapter implements PceStore {
40
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053041 // Mapping tunnel with device local info with tunnel consumer id
Avantika-Huawei9e848e82016-09-01 12:12:42 +053042 private ConcurrentMap<TunnelId, ResourceConsumer> tunnelInfoMap = new ConcurrentHashMap<>();
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053043
44 // Set of Path info
45 private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
46
Priyanka Bbae0eeb12016-11-30 11:59:48 +053047 // Locally maintain with tunnel name as key and corresponding list of explicit path object
48 private Map<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap = new HashMap<>();
Avantika-Huawei28b53752016-06-23 17:04:49 +053049
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053050 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053051 public boolean existsTunnelInfo(TunnelId tunnelId) {
52 return tunnelInfoMap.containsKey(tunnelId);
53 }
54
55 @Override
56 public boolean existsFailedPathInfo(PcePathInfo pathInfo) {
57 return failedPathInfoSet.contains(pathInfo);
58 }
59
60 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053061 public int getTunnelInfoCount() {
62 return tunnelInfoMap.size();
63 }
64
65 @Override
66 public int getFailedPathInfoCount() {
67 return failedPathInfoSet.size();
68 }
69
70 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053071 public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053072 return tunnelInfoMap.entrySet().stream()
Avantika-Huawei9e848e82016-09-01 12:12:42 +053073 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053074 }
75
76 @Override
77 public Iterable<PcePathInfo> getFailedPathInfos() {
78 return ImmutableSet.copyOf(failedPathInfoSet);
79 }
80
81 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053082 public ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053083 return tunnelInfoMap.get(tunnelId);
84 }
85
86 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +053087 public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
88 tunnelInfoMap.put(tunnelId, tunnelConsumerId);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053089 }
90
91 @Override
92 public void addFailedPathInfo(PcePathInfo pathInfo) {
93 failedPathInfoSet.add(pathInfo);
94 }
95
96 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053097 public boolean removeTunnelInfo(TunnelId tunnelId) {
98 tunnelInfoMap.remove(tunnelId);
99 if (tunnelInfoMap.containsKey(tunnelId)) {
100 return false;
101 }
102 return true;
103 }
104
105 @Override
106 public boolean removeFailedPathInfo(PcePathInfo pathInfo) {
107 if (failedPathInfoSet.remove(pathInfo)) {
108 return false;
109 }
110 return true;
111 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530112
113 @Override
114 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
115 tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo);
116 return false;
117 }
118
119 @Override
120 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
121 return tunnelNameExplicitPathInfoMap.get(tunnelName);
122 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530123}