blob: 79bb214b300ed5c1ad3b9bf5850a30426b2a8154 [file] [log] [blame]
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +05303 *
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;
Satish Kba1c9122017-04-05 15:27:23 +053019import org.onosproject.incubator.net.tunnel.TunnelId;
Satish K2eb5d842017-04-04 16:28:37 +053020import org.onosproject.pce.pceservice.ExplicitPathInfo;
21import org.onosproject.pce.pcestore.PcePathInfo;
22import org.onosproject.pce.pcestore.api.PceStore;
Avantika-Huawei28b53752016-06-23 17:04:49 +053023
24import java.util.HashMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053025import java.util.HashSet;
Satish Kba1c9122017-04-05 15:27:23 +053026import java.util.Arrays;
27
Priyanka Bbae0eeb12016-11-30 11:59:48 +053028import java.util.List;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053029import java.util.Map;
30import java.util.Set;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053031
32/**
33 * Provides test implementation of PceStore.
34 */
35public class PceStoreAdapter implements PceStore {
36
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053037 // Mapping tunnel with device local info with tunnel consumer id
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053038
39 // Set of Path info
40 private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
41
Priyanka Bbae0eeb12016-11-30 11:59:48 +053042 // Locally maintain with tunnel name as key and corresponding list of explicit path object
43 private Map<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap = new HashMap<>();
Avantika-Huawei28b53752016-06-23 17:04:49 +053044
Satish Kba1c9122017-04-05 15:27:23 +053045 //Mapping tunnel name with Disjoint paths
46 private Map<String, List<TunnelId>> loadBalancingPathNameTunnelIdInfo = new HashMap<>();
47
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053048 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053049 public boolean existsFailedPathInfo(PcePathInfo pathInfo) {
50 return failedPathInfoSet.contains(pathInfo);
51 }
52
53 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053054 public int getFailedPathInfoCount() {
55 return failedPathInfoSet.size();
56 }
57
58 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053059 public Iterable<PcePathInfo> getFailedPathInfos() {
60 return ImmutableSet.copyOf(failedPathInfoSet);
61 }
62
63 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053064 public void addFailedPathInfo(PcePathInfo pathInfo) {
65 failedPathInfoSet.add(pathInfo);
66 }
67
68 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053069 public boolean removeFailedPathInfo(PcePathInfo pathInfo) {
70 if (failedPathInfoSet.remove(pathInfo)) {
71 return false;
72 }
73 return true;
74 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +053075
76 @Override
77 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
78 tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo);
79 return false;
80 }
81
82 @Override
83 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
84 return tunnelNameExplicitPathInfoMap.get(tunnelName);
85 }
Satish Kba1c9122017-04-05 15:27:23 +053086
87/* @Override
88 public DisjointPath getDisjointPaths(String tunnelName) {
89 if (tunnelNameDisjointPathInfo.get(tunnelName) != null) {
90 return tunnelNameDisjointPathInfo.get(tunnelName);
91 }
92 return null;
93 }
94
95 @Override
96 public boolean addDisjointPathInfo(String tunnelName, DisjointPath path) {
97 return tunnelNameDisjointPathInfo.put(tunnelName, path) != null ? true : false;
98 }*/
99
100 @Override
101 public boolean addLoadBalancingTunnelIdsInfo(String loadBalancingPathName, TunnelId... tunnelIds) {
102 return loadBalancingPathNameTunnelIdInfo.put(loadBalancingPathName,
103 Arrays.asList(tunnelIds)) != null ? true : false;
104 }
105
106 @Override
107 public List<TunnelId> getLoadBalancingTunnelIds(String loadBalancingPathName) {
108 if (loadBalancingPathNameTunnelIdInfo.get(loadBalancingPathName) != null) {
109 return loadBalancingPathNameTunnelIdInfo.get(loadBalancingPathName);
110 }
111 return null;
112 }
113
114 @Override
115 public boolean removeLoadBalancingTunnelIdsInfo(String loadBalancingPathName) {
116 if (loadBalancingPathNameTunnelIdInfo.remove(loadBalancingPathName) == null) {
117 return false;
118 }
119 return true;
120 }
121
122/* @Override
123 public boolean removeDisjointPathInfo(String tunnelName) {
124 if (tunnelNameDisjointPathInfo.remove(tunnelName) == null) {
125 return false;
126 }
127 return true;
128 }*/
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530129}