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