Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [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.pce.util; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 19 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 20 | import org.onosproject.pce.pceservice.ExplicitPathInfo; |
| 21 | import org.onosproject.pce.pcestore.PcePathInfo; |
| 22 | import org.onosproject.pce.pcestore.api.PceStore; |
Avantika-Huawei | 28b5375 | 2016-06-23 17:04:49 +0530 | [diff] [blame] | 23 | |
| 24 | import java.util.HashMap; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 25 | import java.util.HashSet; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 26 | import java.util.Arrays; |
| 27 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 28 | import java.util.List; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 29 | import java.util.Map; |
| 30 | import java.util.Set; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Provides test implementation of PceStore. |
| 34 | */ |
| 35 | public class PceStoreAdapter implements PceStore { |
| 36 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 37 | // Mapping tunnel with device local info with tunnel consumer id |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 38 | |
| 39 | // Set of Path info |
| 40 | private Set<PcePathInfo> failedPathInfoSet = new HashSet<>(); |
| 41 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 42 | // Locally maintain with tunnel name as key and corresponding list of explicit path object |
| 43 | private Map<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap = new HashMap<>(); |
Avantika-Huawei | 28b5375 | 2016-06-23 17:04:49 +0530 | [diff] [blame] | 44 | |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 45 | //Mapping tunnel name with Disjoint paths |
| 46 | private Map<String, List<TunnelId>> loadBalancingPathNameTunnelIdInfo = new HashMap<>(); |
| 47 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 48 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 49 | public boolean existsFailedPathInfo(PcePathInfo pathInfo) { |
| 50 | return failedPathInfoSet.contains(pathInfo); |
| 51 | } |
| 52 | |
| 53 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 54 | public int getFailedPathInfoCount() { |
| 55 | return failedPathInfoSet.size(); |
| 56 | } |
| 57 | |
| 58 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 59 | public Iterable<PcePathInfo> getFailedPathInfos() { |
| 60 | return ImmutableSet.copyOf(failedPathInfoSet); |
| 61 | } |
| 62 | |
| 63 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 64 | public void addFailedPathInfo(PcePathInfo pathInfo) { |
| 65 | failedPathInfoSet.add(pathInfo); |
| 66 | } |
| 67 | |
| 68 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 69 | public boolean removeFailedPathInfo(PcePathInfo pathInfo) { |
| 70 | if (failedPathInfoSet.remove(pathInfo)) { |
| 71 | return false; |
| 72 | } |
| 73 | return true; |
| 74 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 75 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 86 | |
| 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 129 | } |