Mahesh Poojary S
Committed by Mahesh Poojary Huawei

[ONOS-4164] PCE Store

Change-Id: I2caa918fae0bf635f98976b11ee8a717aba42aac
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import com.google.common.base.MoreObjects;
19 +
20 +import java.util.Objects;
21 +
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.PortNumber;
24 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
25 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
26 +
27 +/**
28 + * Local node details including IN and OUT labels as well as IN and OUT port details.
29 + */
30 +public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo {
31 +
32 + private final DeviceId deviceId;
33 +
34 + private final LabelResourceId inLabelId;
35 +
36 + private final LabelResourceId outLabelId;
37 +
38 + private final PortNumber inPort;
39 +
40 + private final PortNumber outPort;
41 +
42 + /**
43 + * Initialization of member variables.
44 + *
45 + * @param deviceId device id
46 + * @param inLabelId in label id of a node
47 + * @param outLabelId out label id of a node
48 + * @param inPort input port
49 + * @param outPort remote port
50 + */
51 + private DefaultLspLocalLabelInfo(DeviceId deviceId,
52 + LabelResourceId inLabelId,
53 + LabelResourceId outLabelId,
54 + PortNumber inPort,
55 + PortNumber outPort) {
56 + this.deviceId = deviceId;
57 + this.inLabelId = inLabelId;
58 + this.outLabelId = outLabelId;
59 + this.inPort = inPort;
60 + this.outPort = outPort;
61 + }
62 +
63 + /**
64 + * Initialization of member variables for serialization.
65 + */
66 + private DefaultLspLocalLabelInfo() {
67 + this.deviceId = null;
68 + this.inLabelId = null;
69 + this.outLabelId = null;
70 + this.inPort = null;
71 + this.outPort = null;
72 + }
73 +
74 + @Override
75 + public DeviceId deviceId() {
76 + return deviceId;
77 + }
78 +
79 + @Override
80 + public LabelResourceId inLabelId() {
81 + return inLabelId;
82 + }
83 +
84 + @Override
85 + public LabelResourceId outLabelId() {
86 + return outLabelId;
87 + }
88 +
89 + @Override
90 + public PortNumber inPort() {
91 + return inPort;
92 + }
93 +
94 + @Override
95 + public PortNumber outPort() {
96 + return outPort;
97 + }
98 +
99 + @Override
100 + public int hashCode() {
101 + return Objects.hash(deviceId, inLabelId, outLabelId, inPort, outPort);
102 + }
103 +
104 + @Override
105 + public boolean equals(Object obj) {
106 + if (this == obj) {
107 + return true;
108 + }
109 + if (obj instanceof LspLocalLabelInfo) {
110 + final DefaultLspLocalLabelInfo other = (DefaultLspLocalLabelInfo) obj;
111 + return Objects.equals(this.deviceId, other.deviceId) &&
112 + Objects.equals(this.inLabelId, other.inLabelId) &&
113 + Objects.equals(this.outLabelId, other.outLabelId) &&
114 + Objects.equals(this.inPort, other.inPort) &&
115 + Objects.equals(this.outPort, other.outPort);
116 + }
117 + return false;
118 + }
119 +
120 + @Override
121 + public String toString() {
122 + return MoreObjects.toStringHelper(getClass())
123 + .omitNullValues()
124 + .add("DeviceId", deviceId.toString())
125 + .add("InLabelId", inLabelId.toString())
126 + .add("OutLabelId", outLabelId.toString())
127 + .add("InPort", inPort.toString())
128 + .add("OutPort", outPort.toString())
129 + .toString();
130 + }
131 +
132 + /**
133 + * Creates and returns a new builder instance that clones an existing object.
134 + *
135 + * @param deviceLabelInfo device label information
136 + * @return new builder
137 + */
138 + public static Builder builder(LspLocalLabelInfo deviceLabelInfo) {
139 + return new Builder(deviceLabelInfo);
140 + }
141 +
142 + /**
143 + * Creates and returns a new builder instance.
144 + *
145 + * @return new builder
146 + */
147 + public static Builder builder() {
148 + return new Builder();
149 + }
150 +
151 + /**
152 + * Builder.
153 + */
154 + public static final class Builder implements LspLocalLabelInfo.Builder {
155 +
156 + private DeviceId deviceId;
157 +
158 + private LabelResourceId inLabelId;
159 +
160 + private LabelResourceId outLabelId;
161 +
162 + private PortNumber inPort;
163 +
164 + private PortNumber outPort;
165 +
166 + /**
167 + * Constructs default builder.
168 + */
169 + private Builder() {
170 + }
171 +
172 + /**
173 + * Initializes member variables with existing object.
174 + */
175 + private Builder(LspLocalLabelInfo deviceLabelInfo) {
176 + this.deviceId = deviceLabelInfo.deviceId();
177 + this.inLabelId = deviceLabelInfo.inLabelId();
178 + this.outLabelId = deviceLabelInfo.outLabelId();
179 + this.inPort = deviceLabelInfo.inPort();
180 + this.outPort = deviceLabelInfo.outPort();
181 + }
182 +
183 + @Override
184 + public Builder deviceId(DeviceId id) {
185 + this.deviceId = id;
186 + return this;
187 + }
188 +
189 + @Override
190 + public Builder inLabelId(LabelResourceId id) {
191 + this.inLabelId = id;
192 + return this;
193 + }
194 +
195 + @Override
196 + public Builder outLabelId(LabelResourceId id) {
197 + this.outLabelId = id;
198 + return this;
199 + }
200 +
201 + @Override
202 + public Builder inPort(PortNumber port) {
203 + this.inPort = port;
204 + return this;
205 + }
206 +
207 + @Override
208 + public Builder outPort(PortNumber port) {
209 + this.outPort = port;
210 + return this;
211 + }
212 +
213 + @Override
214 + public LspLocalLabelInfo build() {
215 + return new DefaultLspLocalLabelInfo(deviceId, inLabelId, outLabelId, inPort, outPort);
216 + }
217 + }
218 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +
20 +import java.util.List;
21 +import java.util.Map;
22 +import java.util.stream.Collectors;
23 +
24 +import org.apache.felix.scr.annotations.Activate;
25 +import org.apache.felix.scr.annotations.Component;
26 +import org.apache.felix.scr.annotations.Deactivate;
27 +import org.apache.felix.scr.annotations.Reference;
28 +import org.apache.felix.scr.annotations.ReferenceCardinality;
29 +import org.apache.felix.scr.annotations.Service;
30 +
31 +import org.onlab.util.KryoNamespace;
32 +import org.onosproject.incubator.net.tunnel.TunnelId;
33 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
34 +import org.onosproject.net.DeviceId;
35 +import org.onosproject.net.Link;
36 +import org.onosproject.net.resource.ResourceConsumer;
37 +import org.onosproject.pce.pceservice.TunnelConsumerId;
38 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
39 +import org.onosproject.pce.pcestore.api.PceStore;
40 +import org.onosproject.store.serializers.KryoNamespaces;
41 +import org.onosproject.store.service.ConsistentMap;
42 +import org.onosproject.store.service.Serializer;
43 +import org.onosproject.store.service.StorageService;
44 +
45 +import org.slf4j.Logger;
46 +import org.slf4j.LoggerFactory;
47 +
48 +/**
49 + * Manages the pool of available labels to devices, links and tunnels.
50 + */
51 +@Component(immediate = true)
52 +@Service
53 +public class DistributedPceStore implements PceStore {
54 +
55 + private static final String DEVICE_ID_NULL = "Device ID cannot be null";
56 + private static final String LINK_NULL = "LINK cannot be null";
57 + private static final String TUNNEL_ID_NULL = "Tunnel ID cannot be null";
58 + private static final String LABEL_RESOURCE_ID_NULL = "Label Resource ID cannot be null";
59 + private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
60 + private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label info cannot be null";
61 + private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
62 +
63 + private final Logger log = LoggerFactory.getLogger(getClass());
64 +
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected StorageService storageService;
67 +
68 + // Mapping device with global node label
69 + private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap;
70 +
71 + // Mapping link with adjacency label
72 + private ConsistentMap<Link, LabelResourceId> adjLabelMap;
73 +
74 + // Mapping tunnel with device local info with tunnel consumer id
75 + private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
76 +
77 + @Activate
78 + protected void activate() {
79 + globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
80 + .withName("onos-pce-globalnodelabelmap")
81 + .withSerializer(Serializer.using(
82 + new KryoNamespace.Builder()
83 + .register(KryoNamespaces.API)
84 + .register(LabelResourceId.class)
85 + .build()))
86 + .build();
87 +
88 + adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
89 + .withName("onos-pce-adjlabelmap")
90 + .withSerializer(Serializer.using(
91 + new KryoNamespace.Builder()
92 + .register(KryoNamespaces.API)
93 + .register(Link.class,
94 + LabelResourceId.class)
95 + .build()))
96 + .build();
97 +
98 + tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder()
99 + .withName("onos-pce-tunnelinfomap")
100 + .withSerializer(Serializer.using(
101 + new KryoNamespace.Builder()
102 + .register(KryoNamespaces.API)
103 + .register(TunnelId.class,
104 + PceccTunnelInfo.class,
105 + DefaultLspLocalLabelInfo.class,
106 + TunnelConsumerId.class,
107 + LabelResourceId.class)
108 + .build()))
109 + .build();
110 +
111 + log.info("Started");
112 + }
113 +
114 + @Deactivate
115 + protected void deactivate() {
116 + log.info("Stopped");
117 + }
118 +
119 + @Override
120 + public boolean existsGlobalNodeLabel(DeviceId id) {
121 + checkNotNull(id, DEVICE_ID_NULL);
122 + return globalNodeLabelMap.containsKey(id);
123 + }
124 +
125 + @Override
126 + public boolean existsAdjLabel(Link link) {
127 + checkNotNull(link, LINK_NULL);
128 + return adjLabelMap.containsKey(link);
129 + }
130 +
131 + @Override
132 + public boolean existsTunnelInfo(TunnelId tunnelId) {
133 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
134 + return tunnelInfoMap.containsKey(tunnelId);
135 + }
136 +
137 + @Override
138 + public int getGlobalNodeLabelCount() {
139 + return globalNodeLabelMap.size();
140 + }
141 +
142 + @Override
143 + public int getAdjLabelCount() {
144 + return adjLabelMap.size();
145 + }
146 +
147 + @Override
148 + public int getTunnelInfoCount() {
149 + return tunnelInfoMap.size();
150 + }
151 +
152 + @Override
153 + public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
154 + return globalNodeLabelMap.entrySet().stream()
155 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
156 + }
157 +
158 + @Override
159 + public Map<Link, LabelResourceId> getAdjLabels() {
160 + return adjLabelMap.entrySet().stream()
161 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
162 + }
163 +
164 + @Override
165 + public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
166 + return tunnelInfoMap.entrySet().stream()
167 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value()));
168 + }
169 +
170 + @Override
171 + public LabelResourceId getGlobalNodeLabel(DeviceId id) {
172 + checkNotNull(id, DEVICE_ID_NULL);
173 + return globalNodeLabelMap.get(id).value();
174 + }
175 +
176 + @Override
177 + public LabelResourceId getAdjLabel(Link link) {
178 + checkNotNull(link, LINK_NULL);
179 + return adjLabelMap.get(link).value();
180 + }
181 +
182 + @Override
183 + public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
184 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
185 + return tunnelInfoMap.get(tunnelId).value();
186 + }
187 +
188 + @Override
189 + public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
190 + checkNotNull(deviceId, DEVICE_ID_NULL);
191 + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
192 +
193 + globalNodeLabelMap.put(deviceId, labelId);
194 + }
195 +
196 + @Override
197 + public void addAdjLabel(Link link, LabelResourceId labelId) {
198 + checkNotNull(link, LINK_NULL);
199 + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
200 +
201 + adjLabelMap.put(link, labelId);
202 + }
203 +
204 + @Override
205 + public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
206 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
207 + checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL);
208 +
209 + tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
210 + }
211 +
212 + @Override
213 + public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
214 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
215 + checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
216 +
217 + if (!tunnelInfoMap.containsKey((tunnelId))) {
218 + log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
219 + return false;
220 + }
221 +
222 + PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
223 + tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
224 + tunnelInfoMap.put(tunnelId, tunnelInfo);
225 +
226 + return true;
227 + }
228 +
229 + @Override
230 + public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
231 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
232 + checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL);
233 +
234 + if (!tunnelInfoMap.containsKey((tunnelId))) {
235 + log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
236 + return false;
237 + }
238 +
239 + PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
240 + tunnelInfo.tunnelConsumerId(tunnelConsumerId);
241 + tunnelInfoMap.put(tunnelId, tunnelInfo);
242 +
243 + return true;
244 + }
245 +
246 + @Override
247 + public boolean removeGlobalNodeLabel(DeviceId id) {
248 + checkNotNull(id, DEVICE_ID_NULL);
249 +
250 + if (globalNodeLabelMap.remove(id) == null) {
251 + log.error("SR-TE node label deletion for device {} has failed.", id.toString());
252 + return false;
253 + }
254 + return true;
255 + }
256 +
257 + @Override
258 + public boolean removeAdjLabel(Link link) {
259 + checkNotNull(link, LINK_NULL);
260 +
261 + if (adjLabelMap.remove(link) == null) {
262 + log.error("Adjacency label deletion for link {} hash failed.", link.toString());
263 + return false;
264 + }
265 + return true;
266 + }
267 +
268 + @Override
269 + public boolean removeTunnelInfo(TunnelId tunnelId) {
270 + checkNotNull(tunnelId, TUNNEL_ID_NULL);
271 +
272 + if (tunnelInfoMap.remove(tunnelId) == null) {
273 + log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
274 + return false;
275 + }
276 + return true;
277 + }
278 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import java.util.List;
19 +import com.google.common.base.MoreObjects;
20 +
21 +import java.util.Objects;
22 +
23 +import org.onosproject.net.resource.ResourceConsumer;
24 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
25 +
26 +/**
27 + * PCECC tunnel information is used to store
28 + * list of links label information of a path containing IN, OUT label and destination port of a link
29 + * to release label allocation in devices.
30 + * Also storing resource consumer id to release bandwdith of a tunnel.
31 + * The first entry is created with TunnelId and resource consumer id,
32 + * later this entry may be updated to store label information on basic PCECC case.
33 + */
34 +public final class PceccTunnelInfo {
35 +
36 + private List<LspLocalLabelInfo> lspLocalLabelInfoList;
37 +
38 + private ResourceConsumer tunnelConsumerId;
39 +
40 + /**
41 + * Initialization of member variables.
42 + *
43 + * @param lspLocalLabelInfoList list of devices local label info
44 + * @param tunnelConsumerId tunnel consumer id
45 + */
46 + public PceccTunnelInfo(List<LspLocalLabelInfo> lspLocalLabelInfoList,
47 + ResourceConsumer tunnelConsumerId) {
48 + this.lspLocalLabelInfoList = lspLocalLabelInfoList;
49 + this.tunnelConsumerId = tunnelConsumerId;
50 + }
51 +
52 + /**
53 + * Initialization for serialization.
54 + */
55 + public PceccTunnelInfo() {
56 + this.lspLocalLabelInfoList = null;
57 + this.tunnelConsumerId = null;
58 + }
59 +
60 + /**
61 + * Retrieves list of devices local label info.
62 + *
63 + * @return list of devices local label info
64 + */
65 + public List<LspLocalLabelInfo> lspLocalLabelInfoList() {
66 + return this.lspLocalLabelInfoList;
67 + }
68 +
69 + /**
70 + * Retrieves tunnel consumer id.
71 + *
72 + * @return tunnel consumer id
73 + */
74 + public ResourceConsumer tunnelConsumerId() {
75 + return this.tunnelConsumerId;
76 + }
77 +
78 + /**
79 + * Sets list of local label info of a path.
80 + *
81 + * @param lspLocalLabelInfoList list of devices local label info
82 + */
83 + public void lspLocalLabelInfoList(List<LspLocalLabelInfo> lspLocalLabelInfoList) {
84 + this.lspLocalLabelInfoList = lspLocalLabelInfoList;
85 + }
86 +
87 + /**
88 + * Sets tunnel consumer id.
89 + *
90 + * @param id tunnel consumer id
91 + */
92 + public void tunnelConsumerId(ResourceConsumer id) {
93 + this.tunnelConsumerId = id;
94 + }
95 +
96 + @Override
97 + public int hashCode() {
98 + return Objects.hash(lspLocalLabelInfoList, tunnelConsumerId);
99 + }
100 +
101 + @Override
102 + public boolean equals(Object obj) {
103 + if (this == obj) {
104 + return true;
105 + }
106 + if (obj instanceof PceccTunnelInfo) {
107 + final PceccTunnelInfo other = (PceccTunnelInfo) obj;
108 + return Objects.equals(this.lspLocalLabelInfoList, other.lspLocalLabelInfoList) &&
109 + Objects.equals(this.tunnelConsumerId, other.tunnelConsumerId);
110 + }
111 + return false;
112 + }
113 +
114 + @Override
115 + public String toString() {
116 + return MoreObjects.toStringHelper(getClass())
117 + .omitNullValues()
118 + .add("DeviceLabelInfoList", lspLocalLabelInfoList.toString())
119 + .add("TunnelConsumerId", tunnelConsumerId.toString())
120 + .toString();
121 + }
122 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore.api;
17 +
18 +import org.onosproject.net.DeviceId;
19 +import org.onosproject.net.PortNumber;
20 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
21 +
22 +/**
23 + * Abstraction of an entity providing LSP local label information.
24 + */
25 +public interface LspLocalLabelInfo {
26 +
27 + /**
28 + * Returns device id.
29 + *
30 + * @return device id
31 + */
32 + DeviceId deviceId();
33 +
34 + /**
35 + * Returns in label id of a device.
36 + *
37 + * @return in label resource id
38 + */
39 + LabelResourceId inLabelId();
40 +
41 + /**
42 + * Returns out label id of a device.
43 + *
44 + * @return node out label resource id
45 + */
46 + LabelResourceId outLabelId();
47 +
48 + /**
49 + * Returns in port of an incoming label.
50 + *
51 + * @return in port
52 + */
53 + PortNumber inPort();
54 +
55 + /**
56 + * Returns next hop of an outgoing label.
57 + *
58 + * @return out port
59 + */
60 + PortNumber outPort();
61 +
62 + /**
63 + * LspLocalLabelInfo Builder.
64 + */
65 + interface Builder {
66 +
67 + /**
68 + * Returns builder object of a device id.
69 + *
70 + * @param id device id
71 + * @return builder object of device id
72 + */
73 + Builder deviceId(DeviceId id);
74 +
75 + /**
76 + * Returns builder object of in label.
77 + *
78 + * @param id in label id
79 + * @return builder object of in label id
80 + */
81 + Builder inLabelId(LabelResourceId id);
82 +
83 + /**
84 + * Returns builder object of out label.
85 + *
86 + * @param id out label id
87 + * @return builder object of out label id
88 + */
89 + Builder outLabelId(LabelResourceId id);
90 +
91 + /**
92 + * Returns builder object of in port of an incoming label.
93 + *
94 + * @param port in port
95 + * @return builder object of in port
96 + */
97 + Builder inPort(PortNumber port);
98 +
99 + /**
100 + * Returns builder object of next hop of an outgoing label.
101 + *
102 + * @param port out port
103 + * @return builder object of out port
104 + */
105 + Builder outPort(PortNumber port);
106 +
107 + /**
108 + * Builds object of device local label info.
109 + *
110 + * @return object of device local label info.
111 + */
112 + LspLocalLabelInfo build();
113 + }
114 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore.api;
17 +
18 +import java.util.List;
19 +
20 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
21 +import org.onosproject.incubator.net.tunnel.TunnelId;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.Link;
24 +import org.onosproject.net.resource.ResourceConsumer;
25 +import org.onosproject.pce.pcestore.PceccTunnelInfo;
26 +
27 +import java.util.Map;
28 +
29 +/**
30 + * Abstraction of an entity providing pool of available labels to devices, links and tunnels.
31 + */
32 +public interface PceStore {
33 + /**
34 + * Checks whether device id is present in global node label store.
35 + *
36 + * @param id device id
37 + * @return success of failure
38 + */
39 + boolean existsGlobalNodeLabel(DeviceId id);
40 +
41 + /**
42 + * Checks whether link is present in adjacency label store.
43 + *
44 + * @param link link between devices
45 + * @return success of failure
46 + */
47 + boolean existsAdjLabel(Link link);
48 +
49 + /**
50 + * Checks whether tunnel id is present in tunnel info store.
51 + *
52 + * @param tunnelId tunnel id
53 + * @return success of failure
54 + */
55 + boolean existsTunnelInfo(TunnelId tunnelId);
56 +
57 + /**
58 + * Retrieves the node label count.
59 + *
60 + * @return node label count
61 + */
62 + int getGlobalNodeLabelCount();
63 +
64 + /**
65 + * Retrieves the adjacency label count.
66 + *
67 + * @return adjacency label count
68 + */
69 + int getAdjLabelCount();
70 +
71 + /**
72 + * Retrieves the tunnel info count.
73 + *
74 + * @return tunnel info count
75 + */
76 + int getTunnelInfoCount();
77 +
78 + /**
79 + * Retrieves device id and label pairs collection from global node label store.
80 + *
81 + * @return collection of device id and label pairs
82 + */
83 + Map<DeviceId, LabelResourceId> getGlobalNodeLabels();
84 +
85 + /**
86 + * Retrieves link and label pairs collection from adjacency label store.
87 + *
88 + * @return collection of link and label pairs
89 + */
90 + Map<Link, LabelResourceId> getAdjLabels();
91 +
92 + /**
93 + * Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store.
94 + *
95 + * @return collection of tunnel id and pcecc tunnel info pairs
96 + */
97 + Map<TunnelId, PceccTunnelInfo> getTunnelInfos();
98 +
99 + /**
100 + * Retrieves node label for specified device id.
101 + *
102 + * @param id device id
103 + * @return node label
104 + */
105 + LabelResourceId getGlobalNodeLabel(DeviceId id);
106 +
107 + /**
108 + * Retrieves adjacency label for specified link.
109 + *
110 + * @param link between devices
111 + * @return adjacency label
112 + */
113 + LabelResourceId getAdjLabel(Link link);
114 +
115 + /**
116 + * Retrieves local label info with tunnel consumer id from tunnel info store.
117 + *
118 + * @param tunnelId tunnel id
119 + * @return pcecc tunnel info
120 + */
121 + PceccTunnelInfo getTunnelInfo(TunnelId tunnelId);
122 +
123 + /**
124 + * Stores node label into global node label store.
125 + *
126 + * @param deviceId device id
127 + * @param labelId node label id
128 + */
129 + void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId);
130 +
131 + /**
132 + * Stores adjacency label into adjacency label store.
133 + *
134 + * @param link link between nodes
135 + * @param labelId link label id
136 + */
137 + void addAdjLabel(Link link, LabelResourceId labelId);
138 +
139 + /**
140 + * Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id.
141 + *
142 + * @param tunnelId tunnel id
143 + * @param pceccTunnelInfo local label info
144 + */
145 + void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo);
146 +
147 + /**
148 + * Updates local label info. The first entry is created with TunnelId and TunnelConsumerId.
149 + * Later this entry may be updated to store label information if it is basic PCECC case.
150 + *
151 + * @param tunnelId tunnel id
152 + * @param lspLocalLabelInfoList list of local labels
153 + * @return success or failure
154 + */
155 + boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList);
156 +
157 + /**
158 + * Updates tunnel info map with tunnel consumer id.
159 + *
160 + * @param tunnelId tunnel id
161 + * @param tunnelConsumerId tunnel consumer id
162 + * @return success or failure
163 + */
164 + boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId);
165 +
166 + /**
167 + * Removes device label from global node label store for specified device id.
168 + *
169 + * @param id device id
170 + * @return success or failure
171 + */
172 + boolean removeGlobalNodeLabel(DeviceId id);
173 +
174 + /**
175 + * Removes adjacency label from adjacency label store for specified link information.
176 + *
177 + * @param link between nodes
178 + * @return success or failure
179 + */
180 + boolean removeAdjLabel(Link link);
181 +
182 + /**
183 + * Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id.
184 + *
185 + * @param tunnelId tunnel id
186 + * @return success or failure
187 + */
188 + boolean removeTunnelInfo(TunnelId tunnelId);
189 +}
1 +/*
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 + */
16 +
17 +/**
18 + * PCE store service API.
19 + */
20 +package org.onosproject.pce.pcestore.api;
1 +/*
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 + */
16 +
17 +/**
18 + * PCE store application.
19 + */
20 +package org.onosproject.pce.pcestore;
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +import org.junit.Test;
24 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
25 +import org.onosproject.net.DeviceId;
26 +import org.onosproject.net.PortNumber;
27 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
28 +
29 +/**
30 + * Unit tests for DefaultLspLocalLabelInfo class.
31 + */
32 +public class DefaultLspLocalLabelInfoTest {
33 +
34 + /**
35 + * Checks the operation of equals() methods.
36 + */
37 + @Test
38 + public void testEquals() {
39 + // create same two objects.
40 + DeviceId deviceId1 = DeviceId.deviceId("foo");
41 + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
42 + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
43 + PortNumber inPort1 = PortNumber.portNumber(5122);
44 + PortNumber outPort1 = PortNumber.portNumber(5123);
45 +
46 + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
47 + .deviceId(deviceId1)
48 + .inLabelId(inLabelId1)
49 + .outLabelId(outLabelId1)
50 + .inPort(inPort1)
51 + .outPort(outPort1)
52 + .build();
53 +
54 + // create same object as above object
55 + LspLocalLabelInfo sameLocalLabel1 = DefaultLspLocalLabelInfo.builder()
56 + .deviceId(deviceId1)
57 + .inLabelId(inLabelId1)
58 + .outLabelId(outLabelId1)
59 + .inPort(inPort1)
60 + .outPort(outPort1)
61 + .build();
62 +
63 + // Create different object.
64 + DeviceId deviceId2 = DeviceId.deviceId("goo");
65 + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
66 + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
67 + PortNumber inPort2 = PortNumber.portNumber(5124);
68 + PortNumber outPort2 = PortNumber.portNumber(5125);
69 +
70 + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
71 + .deviceId(deviceId2)
72 + .inLabelId(inLabelId2)
73 + .outLabelId(outLabelId2)
74 + .inPort(inPort2)
75 + .outPort(outPort2)
76 + .build();
77 +
78 + new EqualsTester().addEqualityGroup(lspLocalLabel1, sameLocalLabel1)
79 + .addEqualityGroup(lspLocalLabel2)
80 + .testEquals();
81 + }
82 +
83 + /**
84 + * Checks the construction of a DefaultLspLocalLabelInfo object.
85 + */
86 + @Test
87 + public void testConstruction() {
88 + DeviceId deviceId = DeviceId.deviceId("foo");
89 + LabelResourceId inLabelId = LabelResourceId.labelResourceId(1);
90 + LabelResourceId outLabelId = LabelResourceId.labelResourceId(2);
91 + PortNumber inPort = PortNumber.portNumber(5122);
92 + PortNumber outPort = PortNumber.portNumber(5123);
93 +
94 + LspLocalLabelInfo lspLocalLabel = DefaultLspLocalLabelInfo.builder()
95 + .deviceId(deviceId)
96 + .inLabelId(inLabelId)
97 + .outLabelId(outLabelId)
98 + .inPort(inPort)
99 + .outPort(outPort)
100 + .build();
101 +
102 + assertThat(deviceId, is(lspLocalLabel.deviceId()));
103 + assertThat(inLabelId, is(lspLocalLabel.inLabelId()));
104 + assertThat(outLabelId, is(lspLocalLabel.outLabelId()));
105 + assertThat(inPort, is(lspLocalLabel.inPort()));
106 + assertThat(outPort, is(lspLocalLabel.outPort()));
107 + }
108 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import java.util.LinkedList;
23 +import java.util.List;
24 +import java.util.Map;
25 +
26 +import org.junit.After;
27 +import org.junit.AfterClass;
28 +import org.junit.Before;
29 +import org.junit.BeforeClass;
30 +import org.junit.Test;
31 +
32 +import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
33 +import org.onosproject.incubator.net.resource.label.LabelResource;
34 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
35 +import org.onosproject.incubator.net.tunnel.TunnelId;
36 +import org.onosproject.net.ConnectPoint;
37 +import org.onosproject.net.DefaultAnnotations;
38 +import org.onosproject.net.DefaultLink;
39 +import org.onosproject.net.DeviceId;
40 +import org.onosproject.net.ElementId;
41 +import org.onosproject.net.Link;
42 +import org.onosproject.net.PortNumber;
43 +import org.onosproject.net.resource.ResourceConsumer;
44 +import org.onosproject.pce.pceservice.TunnelConsumerId;
45 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
46 +import org.onosproject.net.provider.ProviderId;
47 +import org.onosproject.store.service.TestStorageService;
48 +
49 +/**
50 + * Unit tests for DistributedPceStore class.
51 + */
52 +public class DistributedPceStoreTest {
53 +
54 + private DistributedPceStore distrPceStore;
55 + private DeviceId deviceId1 = DeviceId.deviceId("foo");
56 + private DeviceId deviceId2 = DeviceId.deviceId("goo");
57 + private DeviceId deviceId3 = DeviceId.deviceId("yaa");
58 + private DeviceId deviceId4 = DeviceId.deviceId("zoo");
59 + private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1);
60 + private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2);
61 + private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3);
62 + private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4);
63 + private PortNumber portNumber1 = PortNumber.portNumber(1);
64 + private PortNumber portNumber2 = PortNumber.portNumber(2);
65 + private PortNumber portNumber3 = PortNumber.portNumber(3);
66 + private PortNumber portNumber4 = PortNumber.portNumber(4);
67 + private ConnectPoint srcConnectionPoint1 = new ConnectPoint((ElementId) deviceId1, portNumber1);
68 + private ConnectPoint dstConnectionPoint2 = new ConnectPoint((ElementId) deviceId2, portNumber2);
69 + private ConnectPoint srcConnectionPoint3 = new ConnectPoint((ElementId) deviceId3, portNumber3);
70 + private ConnectPoint dstConnectionPoint4 = new ConnectPoint((ElementId) deviceId4, portNumber4);
71 + private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1);
72 + private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2);
73 + private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3);
74 + private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4);
75 + private Link link1;
76 + private Link link2;
77 + private List<LabelResource> labelList1 = new LinkedList<>();
78 + private List<LabelResource> labelList2 = new LinkedList<>();
79 + private TunnelId tunnelId1 = TunnelId.valueOf("1");
80 + private TunnelId tunnelId2 = TunnelId.valueOf("2");
81 + private TunnelId tunnelId3 = TunnelId.valueOf("3");
82 + private TunnelId tunnelId4 = TunnelId.valueOf("4");
83 + private PceccTunnelInfo pceccTunnelInfo1;
84 + private PceccTunnelInfo pceccTunnelInfo2;
85 +
86 + @BeforeClass
87 + public static void setUpBeforeClass() throws Exception {
88 + }
89 +
90 + @AfterClass
91 + public static void tearDownAfterClass() throws Exception {
92 + }
93 +
94 + @Before
95 + public void setUp() throws Exception {
96 + distrPceStore = new DistributedPceStore();
97 +
98 + // Initialization of member variables
99 + link1 = DefaultLink.builder()
100 + .providerId(new ProviderId("eth", "1"))
101 + .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
102 + .src(srcConnectionPoint1)
103 + .dst(dstConnectionPoint2)
104 + .type(Link.Type.DIRECT)
105 + .state(Link.State.ACTIVE)
106 + .build();
107 + link2 = DefaultLink.builder()
108 + .providerId(new ProviderId("mac", "2"))
109 + .annotations(DefaultAnnotations.builder().set("key2", "google").build())
110 + .src(srcConnectionPoint3)
111 + .dst(dstConnectionPoint4)
112 + .type(Link.Type.DIRECT)
113 + .state(Link.State.ACTIVE)
114 + .build();
115 + labelList1.add(labelResource1);
116 + labelList1.add(labelResource2);
117 + labelList2.add(labelResource3);
118 + labelList2.add(labelResource4);
119 +
120 + // Create pceccTunnelInfo1
121 + List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>();
122 + ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
123 +
124 + DeviceId deviceId1 = DeviceId.deviceId("foo");
125 + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
126 + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
127 +
128 + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
129 + .deviceId(deviceId1)
130 + .inLabelId(inLabelId1)
131 + .outLabelId(outLabelId1)
132 + .build();
133 + lspLocalLabelInfoList1.add(lspLocalLabel1);
134 +
135 + pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelInfoList1, tunnelConsumerId1);
136 +
137 + // Create pceccTunnelInfo2
138 + List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
139 + ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
140 +
141 + DeviceId deviceId2 = DeviceId.deviceId("foo");
142 + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
143 + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
144 +
145 + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
146 + .deviceId(deviceId2)
147 + .inLabelId(inLabelId2)
148 + .outLabelId(outLabelId2)
149 + .build();
150 + lspLocalLabelInfoList2.add(lspLocalLabel2);
151 +
152 + pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
153 + }
154 +
155 + @After
156 + public void tearDown() throws Exception {
157 + }
158 +
159 + /**
160 + * Checks the operation of addGlobalNodeLabel() method.
161 + */
162 + @Test
163 + public void testAddGlobalNodeLabel() {
164 + // initialization
165 + distrPceStore.storageService = new TestStorageService();
166 + distrPceStore.activate();
167 +
168 + // add device with label
169 + distrPceStore.addGlobalNodeLabel(deviceId1, labelId1);
170 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
171 + assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
172 + distrPceStore.addGlobalNodeLabel(deviceId2, labelId2);
173 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
174 + assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
175 + }
176 +
177 + /**
178 + * Checks the operation of addAdjLabel() method.
179 + */
180 + @Test
181 + public void testAddAdjLabel() {
182 + // initialization
183 + distrPceStore.storageService = new TestStorageService();
184 + distrPceStore.activate();
185 +
186 + // link with list of labels
187 + distrPceStore.addAdjLabel(link1, labelId1);
188 + assertThat(distrPceStore.existsAdjLabel(link1), is(true));
189 + assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
190 + distrPceStore.addAdjLabel(link2, labelId2);
191 + assertThat(distrPceStore.existsAdjLabel(link2), is(true));
192 + assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
193 + }
194 +
195 + /**
196 + * Checks the operation of addTunnelInfo() method.
197 + */
198 + @Test
199 + public void testAddTunnelInfo() {
200 + // initialization
201 + distrPceStore.storageService = new TestStorageService();
202 + distrPceStore.activate();
203 +
204 + // TunnelId with device label store information
205 + distrPceStore.addTunnelInfo(tunnelId1, pceccTunnelInfo1);
206 + assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
207 + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1));
208 + distrPceStore.addTunnelInfo(tunnelId2, pceccTunnelInfo2);
209 + assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
210 + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2));
211 + }
212 +
213 + /**
214 + * Checks the operation of existsGlobalNodeLabel() method.
215 + */
216 + @Test
217 + public void testExistsGlobalNodeLabel() {
218 + testAddGlobalNodeLabel();
219 +
220 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
221 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
222 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false));
223 + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false));
224 + }
225 +
226 + /**
227 + * Checks the operation of existsAdjLabel() method.
228 + */
229 + @Test
230 + public void testExistsAdjLabel() {
231 + testAddAdjLabel();
232 +
233 + assertThat(distrPceStore.existsAdjLabel(link1), is(true));
234 + assertThat(distrPceStore.existsAdjLabel(link2), is(true));
235 + }
236 +
237 + /**
238 + * Checks the operation of existsTunnelInfo() method.
239 + */
240 + @Test
241 + public void testExistsTunnelInfo() {
242 + testAddTunnelInfo();
243 +
244 + assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
245 + assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
246 + assertThat(distrPceStore.existsTunnelInfo(tunnelId3), is(false));
247 + assertThat(distrPceStore.existsTunnelInfo(tunnelId4), is(false));
248 + }
249 +
250 + /**
251 + * Checks the operation of getGlobalNodeLabelCount() method.
252 + */
253 + @Test
254 + public void testGetGlobalNodeLabelCount() {
255 + testAddGlobalNodeLabel();
256 +
257 + assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2));
258 + }
259 +
260 + /**
261 + * Checks the operation of getAdjLabelCount() method.
262 + */
263 + @Test
264 + public void testGetAdjLabelCount() {
265 + testAddAdjLabel();
266 +
267 + assertThat(distrPceStore.getAdjLabelCount(), is(2));
268 + }
269 +
270 + /**
271 + * Checks the operation of getTunnelInfoCount() method.
272 + */
273 + @Test
274 + public void testGetTunnelInfoCount() {
275 + testAddTunnelInfo();
276 +
277 + assertThat(distrPceStore.getTunnelInfoCount(), is(2));
278 + }
279 +
280 + /**
281 + * Checks the operation of getGlobalNodeLabels() method.
282 + */
283 + @Test
284 + public void testGetGlobalNodeLabels() {
285 + testAddGlobalNodeLabel();
286 +
287 + Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels();
288 + assertThat(nodeLabelMap, is(notNullValue()));
289 + assertThat(nodeLabelMap.isEmpty(), is(false));
290 + assertThat(nodeLabelMap.size(), is(2));
291 + }
292 +
293 + /**
294 + * Checks the operation of getAdjLabels() method.
295 + */
296 + @Test
297 + public void testGetAdjLabels() {
298 + testAddAdjLabel();
299 +
300 + Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels();
301 + assertThat(adjLabelMap, is(notNullValue()));
302 + assertThat(adjLabelMap.isEmpty(), is(false));
303 + assertThat(adjLabelMap.size(), is(2));
304 + }
305 +
306 + /**
307 + * Checks the operation of getTunnelInfos() method.
308 + */
309 + @Test
310 + public void testGetTunnelInfos() {
311 + testAddTunnelInfo();
312 +
313 + Map<TunnelId, PceccTunnelInfo> tunnelInfoMap = distrPceStore.getTunnelInfos();
314 + assertThat(tunnelInfoMap, is(notNullValue()));
315 + assertThat(tunnelInfoMap.isEmpty(), is(false));
316 + assertThat(tunnelInfoMap.size(), is(2));
317 + }
318 +
319 + /**
320 + * Checks the operation of getGlobalNodeLabel() method.
321 + */
322 + @Test
323 + public void testGetGlobalNodeLabel() {
324 + testAddGlobalNodeLabel();
325 +
326 + // deviceId1 with labelId1
327 + assertThat(deviceId1, is(notNullValue()));
328 + assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
329 +
330 + // deviceId2 with labelId2
331 + assertThat(deviceId2, is(notNullValue()));
332 + assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
333 + }
334 +
335 + /**
336 + * Checks the operation of getAdjLabel() method.
337 + */
338 + @Test
339 + public void testGetAdjLabel() {
340 + testAddAdjLabel();
341 +
342 + // link1 with labels
343 + assertThat(link1, is(notNullValue()));
344 + assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
345 +
346 + // link2 with labels
347 + assertThat(link2, is(notNullValue()));
348 + assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
349 + }
350 +
351 + /**
352 + * Checks the operation of getTunnelInfo() method.
353 + */
354 + @Test
355 + public void testGetTunnelInfo() {
356 + testAddTunnelInfo();
357 +
358 + // tunnelId1 with device label store info
359 + assertThat(tunnelId1, is(notNullValue()));
360 + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1));
361 +
362 + // tunnelId2 with device label store info
363 + assertThat(tunnelId2, is(notNullValue()));
364 + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2));
365 + }
366 +
367 + /**
368 + * Checks the operation of updateTunnelInfo() method.
369 + */
370 + @Test
371 + public void testUpdateTunnelInfo() {
372 + // add tunnel info
373 + testAddTunnelInfo();
374 +
375 + // new updates
376 + // Create pceccTunnelInfo3
377 + List<LspLocalLabelInfo> lspLocalLabelInfoList3 = new LinkedList<>();
378 + ResourceConsumer tunnelConsumerId3 = TunnelConsumerId.valueOf(30);
379 +
380 + DeviceId deviceId3 = DeviceId.deviceId("goo");
381 + LabelResourceId inLabelId3 = LabelResourceId.labelResourceId(3);
382 + LabelResourceId outLabelId3 = LabelResourceId.labelResourceId(4);
383 +
384 + LspLocalLabelInfo lspLocalLabel3 = DefaultLspLocalLabelInfo.builder()
385 + .deviceId(deviceId3)
386 + .inLabelId(inLabelId3)
387 + .outLabelId(outLabelId3)
388 + .build();
389 + lspLocalLabelInfoList3.add(lspLocalLabel3);
390 +
391 + PceccTunnelInfo pceccTunnelInfo3 = new PceccTunnelInfo(lspLocalLabelInfoList3, tunnelConsumerId3);
392 +
393 + // Create pceccTunnelInfo4
394 + List<LspLocalLabelInfo> lspLocalLabelInfoList4 = new LinkedList<>();
395 + ResourceConsumer tunnelConsumerId4 = TunnelConsumerId.valueOf(40);
396 +
397 + DeviceId deviceId4 = DeviceId.deviceId("goo");
398 + LabelResourceId inLabelId4 = LabelResourceId.labelResourceId(4);
399 + LabelResourceId outLabelId4 = LabelResourceId.labelResourceId(5);
400 +
401 + LspLocalLabelInfo lspLocalLabel4 = DefaultLspLocalLabelInfo.builder()
402 + .deviceId(deviceId4)
403 + .inLabelId(inLabelId4)
404 + .outLabelId(outLabelId4)
405 + .build();
406 + lspLocalLabelInfoList4.add(lspLocalLabel4);
407 +
408 + PceccTunnelInfo pceccTunnelInfo4 = new PceccTunnelInfo(lspLocalLabelInfoList4, tunnelConsumerId4);
409 +
410 + // update only lspLocalLabelInfoList
411 + assertThat(distrPceStore.updateTunnelInfo(tunnelId1, lspLocalLabelInfoList3), is(true));
412 + assertThat(distrPceStore.updateTunnelInfo(tunnelId2, lspLocalLabelInfoList4), is(true));
413 +
414 + // update only tunnelConsumerId
415 + assertThat(distrPceStore.updateTunnelInfo(tunnelId1, tunnelConsumerId3), is(true));
416 + assertThat(distrPceStore.updateTunnelInfo(tunnelId2, tunnelConsumerId4), is(true));
417 +
418 + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo3));
419 + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo4));
420 + }
421 +
422 + /**
423 + * Checks the operation of removeGlobalNodeLabel() method.
424 + */
425 + @Test
426 + public void testRemoveGlobalNodeLabel() {
427 + testAddGlobalNodeLabel();
428 +
429 + assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true));
430 + assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true));
431 + }
432 +
433 + /**
434 + * Checks the operation of removeAdjLabel() method.
435 + */
436 + @Test
437 + public void testRemoveAdjLabel() {
438 + testAddAdjLabel();
439 +
440 + assertThat(distrPceStore.removeAdjLabel(link1), is(true));
441 + assertThat(distrPceStore.removeAdjLabel(link2), is(true));
442 + }
443 +
444 + /**
445 + * Checks the operation of removeTunnelInfo() method.
446 + */
447 + @Test
448 + public void testRemoveTunnelInfo() {
449 + testAddTunnelInfo();
450 +
451 + assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true));
452 + assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true));
453 + }
454 +}
1 +/*
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 + */
16 +package org.onosproject.pce.pcestore;
17 +
18 +import java.util.LinkedList;
19 +import java.util.List;
20 +
21 +import static org.hamcrest.MatcherAssert.assertThat;
22 +import static org.hamcrest.Matchers.is;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +import org.junit.Test;
27 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.PortNumber;
30 +import org.onosproject.net.resource.ResourceConsumer;
31 +import org.onosproject.pce.pceservice.TunnelConsumerId;
32 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
33 +
34 +/**
35 + * Unit tests for PceccTunnelInfo class.
36 + */
37 +public class PceccTunnelInfoTest {
38 +
39 + /**
40 + * Checks the operation of equals() methods.
41 + */
42 + @Test
43 + public void testEquals() {
44 + // create same two objects.
45 + List<LspLocalLabelInfo> lspLocalLabelList1 = new LinkedList<>();
46 + ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
47 +
48 + // create object of DefaultLspLocalLabelInfo
49 + DeviceId deviceId1 = DeviceId.deviceId("foo");
50 + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
51 + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
52 + PortNumber inPort1 = PortNumber.portNumber(5122);
53 + PortNumber outPort1 = PortNumber.portNumber(5123);
54 +
55 + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
56 + .deviceId(deviceId1)
57 + .inLabelId(inLabelId1)
58 + .outLabelId(outLabelId1)
59 + .inPort(inPort1)
60 + .outPort(outPort1)
61 + .build();
62 + lspLocalLabelList1.add(lspLocalLabel1);
63 +
64 + PceccTunnelInfo pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
65 +
66 + // create same as above object
67 + PceccTunnelInfo samePceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
68 +
69 + // Create different object.
70 + List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
71 + ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
72 +
73 + // create object of DefaultLspLocalLabelInfo
74 + DeviceId deviceId2 = DeviceId.deviceId("goo");
75 + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
76 + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
77 + PortNumber inPort2 = PortNumber.portNumber(5124);
78 + PortNumber outPort2 = PortNumber.portNumber(5125);
79 +
80 + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
81 + .deviceId(deviceId2)
82 + .inLabelId(inLabelId2)
83 + .outLabelId(outLabelId2)
84 + .inPort(inPort2)
85 + .outPort(outPort2)
86 + .build();
87 + lspLocalLabelInfoList2.add(lspLocalLabel2);
88 +
89 + PceccTunnelInfo pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
90 +
91 + new EqualsTester().addEqualityGroup(pceccTunnelInfo1, samePceccTunnelInfo1)
92 + .addEqualityGroup(pceccTunnelInfo2)
93 + .testEquals();
94 + }
95 +
96 + /**
97 + * Checks the construction of a PceccTunnelInfo object.
98 + */
99 + @Test
100 + public void testConstruction() {
101 + List<LspLocalLabelInfo> lspLocalLabelInfoList = new LinkedList<>();
102 + ResourceConsumer tunnelConsumerId = TunnelConsumerId.valueOf(10);
103 +
104 + // create object of DefaultLspLocalLabelInfo
105 + DeviceId deviceId = DeviceId.deviceId("foo");
106 + LabelResourceId inLabelId = LabelResourceId.labelResourceId(1);
107 + LabelResourceId outLabelId = LabelResourceId.labelResourceId(2);
108 + PortNumber inPort = PortNumber.portNumber(5122);
109 + PortNumber outPort = PortNumber.portNumber(5123);
110 +
111 + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
112 + .deviceId(deviceId)
113 + .inLabelId(inLabelId)
114 + .outLabelId(outLabelId)
115 + .inPort(inPort)
116 + .outPort(outPort)
117 + .build();
118 + lspLocalLabelInfoList.add(lspLocalLabelInfo);
119 +
120 + PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(lspLocalLabelInfoList, tunnelConsumerId);
121 +
122 + assertThat(lspLocalLabelInfoList, is(pceccTunnelInfo.lspLocalLabelInfoList()));
123 + }
124 +}