blob: 23ed95feae456c4f2d68a485aa08e1b60d566713 [file] [log] [blame]
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Avantika-Huawei9e848e82016-09-01 12:12:42 +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.pcelabelstore.util;
17
18import java.util.concurrent.ConcurrentHashMap;
19import java.util.concurrent.ConcurrentMap;
20
21import java.util.HashMap;
22import java.util.List;
23import java.util.Map;
24import java.util.stream.Collectors;
25
26import org.onosproject.incubator.net.resource.label.LabelResourceId;
27import org.onosproject.incubator.net.tunnel.TunnelId;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.Link;
30import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
31import org.onosproject.pcelabelstore.api.PceLabelStore;
32
33/**
34 * Provides test implementation of PceStore.
35 */
36public class PceLabelStoreAdapter implements PceLabelStore {
37
38 // Mapping device with global node label
39 private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>();
40
41 // Mapping link with adjacency label
42 private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>();
43
44 // Mapping tunnel with device local info with tunnel consumer id
45 private ConcurrentMap<TunnelId, List<LspLocalLabelInfo>> tunnelInfoMap = new ConcurrentHashMap<>();
46
47
48 // Locally maintain LSRID to device id mapping for better performance.
49 private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
50
51 @Override
52 public boolean existsGlobalNodeLabel(DeviceId id) {
53 return globalNodeLabelMap.containsKey(id);
54 }
55
56 @Override
57 public boolean existsAdjLabel(Link link) {
58 return adjLabelMap.containsKey(link);
59 }
60
61 @Override
62 public boolean existsTunnelInfo(TunnelId tunnelId) {
63 return tunnelInfoMap.containsKey(tunnelId);
64 }
65
66 @Override
67 public int getGlobalNodeLabelCount() {
68 return globalNodeLabelMap.size();
69 }
70
71 @Override
72 public int getAdjLabelCount() {
73 return adjLabelMap.size();
74 }
75
76 @Override
77 public int getTunnelInfoCount() {
78 return tunnelInfoMap.size();
79 }
80
81 @Override
82 public boolean removeTunnelInfo(TunnelId tunnelId) {
83 tunnelInfoMap.remove(tunnelId);
84 if (tunnelInfoMap.containsKey(tunnelId)) {
85 return false;
86 }
87 return true;
88 }
89
90 @Override
91 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
92 return globalNodeLabelMap.entrySet().stream()
93 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
94 }
95
96 @Override
97 public Map<Link, LabelResourceId> getAdjLabels() {
98 return adjLabelMap.entrySet().stream()
99 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
100 }
101
102 @Override
103 public LabelResourceId getGlobalNodeLabel(DeviceId id) {
104 return globalNodeLabelMap.get(id);
105 }
106
107 @Override
108 public LabelResourceId getAdjLabel(Link link) {
109 return adjLabelMap.get(link);
110 }
111
112 @Override
113 public List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId) {
114 return tunnelInfoMap.get(tunnelId);
115 }
116
117 @Override
118 public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
119 globalNodeLabelMap.put(deviceId, labelId);
120 }
121
122 @Override
123 public void addAdjLabel(Link link, LabelResourceId labelId) {
124 adjLabelMap.put(link, labelId);
125 }
126
127 @Override
128 public void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
129 tunnelInfoMap.put(tunnelId, lspLocalLabelInfoList);
130 }
131
132 @Override
133 public boolean removeGlobalNodeLabel(DeviceId id) {
134 globalNodeLabelMap.remove(id);
135 if (globalNodeLabelMap.containsKey(id)) {
136 return false;
137 }
138 return true;
139 }
140
141 @Override
142 public boolean removeAdjLabel(Link link) {
143 adjLabelMap.remove(link);
144 if (adjLabelMap.containsKey(link)) {
145 return false;
146 }
147 return true;
148 }
149
150 @Override
151 public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
152 // TODO Auto-generated method stub
153 return false;
154 }
155
156 @Override
157 public boolean removeLsrIdDevice(String lsrId) {
158 // TODO Auto-generated method stub
159 return false;
160 }
161
162 @Override
163 public DeviceId getLsrIdDevice(String lsrId) {
164 // TODO Auto-generated method stub
165 return null;
166 }
167
168 @Override
169 public boolean addPccLsr(DeviceId lsrId) {
170 // TODO Auto-generated method stub
171 return false;
172 }
173
174 @Override
175 public boolean removePccLsr(DeviceId lsrId) {
176 // TODO Auto-generated method stub
177 return false;
178 }
179
180 @Override
181 public boolean hasPccLsr(DeviceId lsrId) {
182 // TODO Auto-generated method stub
183 return false;
184 }
185
186 @Override
187 public Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos() {
188 return tunnelInfoMap.entrySet().stream()
189 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
190 }
191}