Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-4164] Failed path info store

Change-Id: I8e16493ce479d2489b16fc76b56f55455927cb56
...@@ -17,6 +17,8 @@ package org.onosproject.pce.pcestore; ...@@ -17,6 +17,8 @@ package org.onosproject.pce.pcestore;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 19
20 +import com.google.common.collect.ImmutableSet;
21 +
20 import java.util.List; 22 import java.util.List;
21 import java.util.Map; 23 import java.util.Map;
22 import java.util.stream.Collectors; 24 import java.util.stream.Collectors;
...@@ -30,15 +32,19 @@ import org.apache.felix.scr.annotations.Service; ...@@ -30,15 +32,19 @@ import org.apache.felix.scr.annotations.Service;
30 32
31 import org.onlab.util.KryoNamespace; 33 import org.onlab.util.KryoNamespace;
32 import org.onosproject.incubator.net.tunnel.TunnelId; 34 import org.onosproject.incubator.net.tunnel.TunnelId;
35 +import org.onosproject.incubator.net.resource.label.LabelResource;
33 import org.onosproject.incubator.net.resource.label.LabelResourceId; 36 import org.onosproject.incubator.net.resource.label.LabelResourceId;
34 import org.onosproject.net.DeviceId; 37 import org.onosproject.net.DeviceId;
38 +import org.onosproject.net.intent.Constraint;
35 import org.onosproject.net.Link; 39 import org.onosproject.net.Link;
36 import org.onosproject.net.resource.ResourceConsumer; 40 import org.onosproject.net.resource.ResourceConsumer;
37 import org.onosproject.pce.pceservice.TunnelConsumerId; 41 import org.onosproject.pce.pceservice.TunnelConsumerId;
42 +import org.onosproject.pce.pceservice.LspType;
38 import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; 43 import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
39 import org.onosproject.pce.pcestore.api.PceStore; 44 import org.onosproject.pce.pcestore.api.PceStore;
40 import org.onosproject.store.serializers.KryoNamespaces; 45 import org.onosproject.store.serializers.KryoNamespaces;
41 import org.onosproject.store.service.ConsistentMap; 46 import org.onosproject.store.service.ConsistentMap;
47 +import org.onosproject.store.service.DistributedSet;
42 import org.onosproject.store.service.Serializer; 48 import org.onosproject.store.service.Serializer;
43 import org.onosproject.store.service.StorageService; 49 import org.onosproject.store.service.StorageService;
44 50
...@@ -53,11 +59,15 @@ import org.slf4j.LoggerFactory; ...@@ -53,11 +59,15 @@ import org.slf4j.LoggerFactory;
53 public class DistributedPceStore implements PceStore { 59 public class DistributedPceStore implements PceStore {
54 60
55 private static final String DEVICE_ID_NULL = "Device ID cannot be null"; 61 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
62 + private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null";
63 + private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
64 + private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null";
65 + private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null";
56 private static final String LINK_NULL = "LINK cannot be null"; 66 private static final String LINK_NULL = "LINK cannot be null";
57 - private static final String TUNNEL_ID_NULL = "Tunnel ID cannot be null"; 67 + private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null";
58 - private static final String LABEL_RESOURCE_ID_NULL = "Label Resource ID cannot be null"; 68 + private static final String PATH_INFO_NULL = "Path Info cannot be null";
59 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; 69 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"; 70 + private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
61 private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null"; 71 private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
62 72
63 private final Logger log = LoggerFactory.getLogger(getClass()); 73 private final Logger log = LoggerFactory.getLogger(getClass());
...@@ -74,6 +84,9 @@ public class DistributedPceStore implements PceStore { ...@@ -74,6 +84,9 @@ public class DistributedPceStore implements PceStore {
74 // Mapping tunnel with device local info with tunnel consumer id 84 // Mapping tunnel with device local info with tunnel consumer id
75 private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap; 85 private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
76 86
87 + // List of Failed path info
88 + private DistributedSet<PcePathInfo> failedPathSet;
89 +
77 @Activate 90 @Activate
78 protected void activate() { 91 protected void activate() {
79 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder() 92 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
...@@ -91,6 +104,7 @@ public class DistributedPceStore implements PceStore { ...@@ -91,6 +104,7 @@ public class DistributedPceStore implements PceStore {
91 new KryoNamespace.Builder() 104 new KryoNamespace.Builder()
92 .register(KryoNamespaces.API) 105 .register(KryoNamespaces.API)
93 .register(Link.class, 106 .register(Link.class,
107 + LabelResource.class,
94 LabelResourceId.class) 108 LabelResourceId.class)
95 .build())) 109 .build()))
96 .build(); 110 .build();
...@@ -108,6 +122,22 @@ public class DistributedPceStore implements PceStore { ...@@ -108,6 +122,22 @@ public class DistributedPceStore implements PceStore {
108 .build())) 122 .build()))
109 .build(); 123 .build();
110 124
125 + failedPathSet = storageService.<PcePathInfo>setBuilder()
126 + .withName("failed-path-info")
127 + .withSerializer(Serializer.using(
128 + new KryoNamespace.Builder()
129 + .register(KryoNamespaces.API)
130 + .register(PcePathInfo.class,
131 + //TODO: Instead of Constraint.class need to add actual implemented class
132 + //TODO: on this interface like CostConstraint.class and
133 + //TODO: BandwidthConstraint.class. Will be added once it is confirmed.
134 + Constraint.class,
135 + LspType.class)
136 + .build()))
137 +
138 + .build()
139 + .asDistributedSet();
140 +
111 log.info("Started"); 141 log.info("Started");
112 } 142 }
113 143
...@@ -135,6 +165,12 @@ public class DistributedPceStore implements PceStore { ...@@ -135,6 +165,12 @@ public class DistributedPceStore implements PceStore {
135 } 165 }
136 166
137 @Override 167 @Override
168 + public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
169 + checkNotNull(failedPathInfo, PATH_INFO_NULL);
170 + return failedPathSet.contains(failedPathInfo);
171 + }
172 +
173 + @Override
138 public int getGlobalNodeLabelCount() { 174 public int getGlobalNodeLabelCount() {
139 return globalNodeLabelMap.size(); 175 return globalNodeLabelMap.size();
140 } 176 }
...@@ -150,6 +186,11 @@ public class DistributedPceStore implements PceStore { ...@@ -150,6 +186,11 @@ public class DistributedPceStore implements PceStore {
150 } 186 }
151 187
152 @Override 188 @Override
189 + public int getFailedPathInfoCount() {
190 + return failedPathSet.size();
191 + }
192 +
193 + @Override
153 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { 194 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
154 return globalNodeLabelMap.entrySet().stream() 195 return globalNodeLabelMap.entrySet().stream()
155 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value())); 196 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
...@@ -168,6 +209,11 @@ public class DistributedPceStore implements PceStore { ...@@ -168,6 +209,11 @@ public class DistributedPceStore implements PceStore {
168 } 209 }
169 210
170 @Override 211 @Override
212 + public Iterable<PcePathInfo> getFailedPathInfos() {
213 + return ImmutableSet.copyOf(failedPathSet);
214 + }
215 +
216 + @Override
171 public LabelResourceId getGlobalNodeLabel(DeviceId id) { 217 public LabelResourceId getGlobalNodeLabel(DeviceId id) {
172 checkNotNull(id, DEVICE_ID_NULL); 218 checkNotNull(id, DEVICE_ID_NULL);
173 return globalNodeLabelMap.get(id).value(); 219 return globalNodeLabelMap.get(id).value();
...@@ -210,6 +256,12 @@ public class DistributedPceStore implements PceStore { ...@@ -210,6 +256,12 @@ public class DistributedPceStore implements PceStore {
210 } 256 }
211 257
212 @Override 258 @Override
259 + public void addFailedPathInfo(PcePathInfo failedPathInfo) {
260 + checkNotNull(failedPathInfo, PATH_INFO_NULL);
261 + failedPathSet.add(failedPathInfo);
262 + }
263 +
264 + @Override
213 public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { 265 public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
214 checkNotNull(tunnelId, TUNNEL_ID_NULL); 266 checkNotNull(tunnelId, TUNNEL_ID_NULL);
215 checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL); 267 checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
...@@ -275,4 +327,15 @@ public class DistributedPceStore implements PceStore { ...@@ -275,4 +327,15 @@ public class DistributedPceStore implements PceStore {
275 } 327 }
276 return true; 328 return true;
277 } 329 }
330 +
331 + @Override
332 + public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
333 + checkNotNull(failedPathInfo, PATH_INFO_NULL);
334 +
335 + if (!failedPathSet.remove(failedPathInfo)) {
336 + log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
337 + return false;
338 + }
339 + return true;
340 + }
278 } 341 }
......
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.List;
21 +import java.util.Objects;
22 +
23 +import org.onosproject.net.DeviceId;
24 +import org.onosproject.net.intent.Constraint;
25 +import org.onosproject.pce.pceservice.LspType;
26 +
27 +/**
28 + * Input path information to compute CSPF path.
29 + * This path information will be stored in pce store and will be used later to recalculate the path.
30 + */
31 +public final class PcePathInfo {
32 +
33 + private DeviceId src; // source path
34 +
35 + private DeviceId dst; // destination path
36 +
37 + private String name; // tunnel name
38 +
39 + private List<Constraint> constraints; // list of constraints (cost, bandwidth, etc.)
40 +
41 + private LspType lspType; // lsp type
42 +
43 + /**
44 + * Initialization of member variables.
45 + *
46 + * @param src source device id
47 + * @param dst destination device id
48 + * @param name tunnel name
49 + * @param constraints list of constraints
50 + * @param lspType lsp type
51 + */
52 + public PcePathInfo(DeviceId src,
53 + DeviceId dst,
54 + String name,
55 + List<Constraint> constraints,
56 + LspType lspType) {
57 + this.src = src;
58 + this.dst = dst;
59 + this.name = name;
60 + this.constraints = constraints;
61 + this.lspType = lspType;
62 + }
63 +
64 + /**
65 + * Initialization for serialization.
66 + */
67 + public PcePathInfo() {
68 + this.src = null;
69 + this.dst = null;
70 + this.name = null;
71 + this.constraints = null;
72 + this.lspType = null;
73 + }
74 +
75 + /**
76 + * Returns source device id.
77 + *
78 + * @return source device id
79 + */
80 + public DeviceId src() {
81 + return src;
82 + }
83 +
84 + /**
85 + * Sets source device id.
86 + *
87 + * @param id source device id
88 + */
89 + public void src(DeviceId id) {
90 + this.src = id;
91 + }
92 +
93 + /**
94 + * Returns destination device id.
95 + *
96 + * @return destination device id
97 + */
98 + public DeviceId dst() {
99 + return dst;
100 + }
101 +
102 + /**
103 + * Sets destination device id.
104 + *
105 + * @param id destination device id
106 + */
107 + public void dst(DeviceId id) {
108 + this.dst = id;
109 + }
110 +
111 +
112 + /**
113 + * Returns tunnel name.
114 + *
115 + * @return name
116 + */
117 + public String name() {
118 + return name;
119 + }
120 +
121 + /**
122 + * Sets tunnel name.
123 + *
124 + * @param name tunnel name
125 + */
126 + public void name(String name) {
127 + this.name = name;
128 + }
129 +
130 + /**
131 + * Returns list of constraints including cost, bandwidth, etc.
132 + *
133 + * @return list of constraints
134 + */
135 + public List<Constraint> constraints() {
136 + return constraints;
137 + }
138 +
139 + /**
140 + * Sets list of constraints.
141 + * @param constraints list of constraints
142 + */
143 + public void constraints(List<Constraint> constraints) {
144 + this.constraints = constraints;
145 + }
146 +
147 + /**
148 + * Returns lsp type.
149 + *
150 + * @return lsp type
151 + */
152 + public LspType lspType() {
153 + return lspType;
154 + }
155 +
156 + /**
157 + * Sets lsp type.
158 + *
159 + * @param lspType lsp type
160 + */
161 + public void lspType(LspType lspType) {
162 + this.lspType = lspType;
163 + }
164 +
165 + @Override
166 + public int hashCode() {
167 + return Objects.hash(src, dst, name, constraints, lspType);
168 + }
169 +
170 + @Override
171 + public boolean equals(Object obj) {
172 + if (this == obj) {
173 + return true;
174 + }
175 + if (obj instanceof PcePathInfo) {
176 + final PcePathInfo other = (PcePathInfo) obj;
177 + return Objects.equals(this.src, other.src) &&
178 + Objects.equals(this.dst, other.dst) &&
179 + Objects.equals(this.name, other.name) &&
180 + Objects.equals(this.constraints, other.constraints) &&
181 + Objects.equals(this.lspType, other.lspType);
182 + }
183 + return false;
184 + }
185 +
186 + @Override
187 + public String toString() {
188 + return MoreObjects.toStringHelper(getClass())
189 + .omitNullValues()
190 + .add("Source", src.toString())
191 + .add("Destination", dst.toString())
192 + .add("Name", name.toString())
193 + .add("Constraints", constraints.toString())
194 + .add("LspType", lspType.toString())
195 + .toString();
196 + }
197 +}
...@@ -23,6 +23,7 @@ import org.onosproject.net.DeviceId; ...@@ -23,6 +23,7 @@ import org.onosproject.net.DeviceId;
23 import org.onosproject.net.Link; 23 import org.onosproject.net.Link;
24 import org.onosproject.net.resource.ResourceConsumer; 24 import org.onosproject.net.resource.ResourceConsumer;
25 import org.onosproject.pce.pcestore.PceccTunnelInfo; 25 import org.onosproject.pce.pcestore.PceccTunnelInfo;
26 +import org.onosproject.pce.pcestore.PcePathInfo;
26 27
27 import java.util.Map; 28 import java.util.Map;
28 29
...@@ -55,6 +56,14 @@ public interface PceStore { ...@@ -55,6 +56,14 @@ public interface PceStore {
55 boolean existsTunnelInfo(TunnelId tunnelId); 56 boolean existsTunnelInfo(TunnelId tunnelId);
56 57
57 /** 58 /**
59 + * Checks whether path info is present in failed path info list.
60 + *
61 + * @param failedPathInfo failed path information
62 + * @return success or failure
63 + */
64 + boolean existsFailedPathInfo(PcePathInfo failedPathInfo);
65 +
66 + /**
58 * Retrieves the node label count. 67 * Retrieves the node label count.
59 * 68 *
60 * @return node label count 69 * @return node label count
...@@ -76,6 +85,13 @@ public interface PceStore { ...@@ -76,6 +85,13 @@ public interface PceStore {
76 int getTunnelInfoCount(); 85 int getTunnelInfoCount();
77 86
78 /** 87 /**
88 + * Retrieves the failed path info count.
89 + *
90 + * @return failed path info count
91 + */
92 + int getFailedPathInfoCount();
93 +
94 + /**
79 * Retrieves device id and label pairs collection from global node label store. 95 * Retrieves device id and label pairs collection from global node label store.
80 * 96 *
81 * @return collection of device id and label pairs 97 * @return collection of device id and label pairs
...@@ -97,6 +113,13 @@ public interface PceStore { ...@@ -97,6 +113,13 @@ public interface PceStore {
97 Map<TunnelId, PceccTunnelInfo> getTunnelInfos(); 113 Map<TunnelId, PceccTunnelInfo> getTunnelInfos();
98 114
99 /** 115 /**
116 + * Retrieves path info collection from failed path info store.
117 + *
118 + * @return collection of failed path info
119 + */
120 + Iterable<PcePathInfo> getFailedPathInfos();
121 +
122 + /**
100 * Retrieves node label for specified device id. 123 * Retrieves node label for specified device id.
101 * 124 *
102 * @param id device id 125 * @param id device id
...@@ -145,6 +168,13 @@ public interface PceStore { ...@@ -145,6 +168,13 @@ public interface PceStore {
145 void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo); 168 void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo);
146 169
147 /** 170 /**
171 + * Stores path information into failed path info store.
172 + *
173 + * @param failedPathInfo failed path information
174 + */
175 + void addFailedPathInfo(PcePathInfo failedPathInfo);
176 +
177 + /**
148 * Updates local label info. The first entry is created with TunnelId and TunnelConsumerId. 178 * 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. 179 * Later this entry may be updated to store label information if it is basic PCECC case.
150 * 180 *
...@@ -186,4 +216,12 @@ public interface PceStore { ...@@ -186,4 +216,12 @@ public interface PceStore {
186 * @return success or failure 216 * @return success or failure
187 */ 217 */
188 boolean removeTunnelInfo(TunnelId tunnelId); 218 boolean removeTunnelInfo(TunnelId tunnelId);
219 +
220 + /**
221 + * Removes path info from failed path info store.
222 + *
223 + * @param failedPathInfo failed path information
224 + * @return success or failure
225 + */
226 + boolean removeFailedPathInfo(PcePathInfo failedPathInfo);
189 } 227 }
......
...@@ -29,6 +29,7 @@ import org.junit.Before; ...@@ -29,6 +29,7 @@ import org.junit.Before;
29 import org.junit.BeforeClass; 29 import org.junit.BeforeClass;
30 import org.junit.Test; 30 import org.junit.Test;
31 31
32 +import org.onlab.util.DataRateUnit;
32 import org.onosproject.incubator.net.resource.label.DefaultLabelResource; 33 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.LabelResource;
34 import org.onosproject.incubator.net.resource.label.LabelResourceId; 35 import org.onosproject.incubator.net.resource.label.LabelResourceId;
...@@ -38,9 +39,12 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -38,9 +39,12 @@ import org.onosproject.net.DefaultAnnotations;
38 import org.onosproject.net.DefaultLink; 39 import org.onosproject.net.DefaultLink;
39 import org.onosproject.net.DeviceId; 40 import org.onosproject.net.DeviceId;
40 import org.onosproject.net.ElementId; 41 import org.onosproject.net.ElementId;
42 +import org.onosproject.net.intent.Constraint;
43 +import org.onosproject.net.intent.constraint.BandwidthConstraint;
41 import org.onosproject.net.Link; 44 import org.onosproject.net.Link;
42 import org.onosproject.net.PortNumber; 45 import org.onosproject.net.PortNumber;
43 import org.onosproject.net.resource.ResourceConsumer; 46 import org.onosproject.net.resource.ResourceConsumer;
47 +import org.onosproject.pce.pceservice.LspType;
44 import org.onosproject.pce.pceservice.TunnelConsumerId; 48 import org.onosproject.pce.pceservice.TunnelConsumerId;
45 import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; 49 import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
46 import org.onosproject.net.provider.ProviderId; 50 import org.onosproject.net.provider.ProviderId;
...@@ -82,6 +86,10 @@ public class DistributedPceStoreTest { ...@@ -82,6 +86,10 @@ public class DistributedPceStoreTest {
82 private TunnelId tunnelId4 = TunnelId.valueOf("4"); 86 private TunnelId tunnelId4 = TunnelId.valueOf("4");
83 private PceccTunnelInfo pceccTunnelInfo1; 87 private PceccTunnelInfo pceccTunnelInfo1;
84 private PceccTunnelInfo pceccTunnelInfo2; 88 private PceccTunnelInfo pceccTunnelInfo2;
89 + private PcePathInfo failedPathInfo1;
90 + private PcePathInfo failedPathInfo2;
91 + private PcePathInfo failedPathInfo3;
92 + private PcePathInfo failedPathInfo4;
85 93
86 @BeforeClass 94 @BeforeClass
87 public static void setUpBeforeClass() throws Exception { 95 public static void setUpBeforeClass() throws Exception {
...@@ -150,6 +158,50 @@ public class DistributedPceStoreTest { ...@@ -150,6 +158,50 @@ public class DistributedPceStoreTest {
150 lspLocalLabelInfoList2.add(lspLocalLabel2); 158 lspLocalLabelInfoList2.add(lspLocalLabel2);
151 159
152 pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2); 160 pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
161 +
162 + // Creates failedPathInfo1
163 + DeviceId src1 = DeviceId.deviceId("foo1");
164 + DeviceId dst1 = DeviceId.deviceId("goo1");
165 + String name1 = "pcc1";
166 + LspType lspType1 = LspType.SR_WITHOUT_SIGNALLING;
167 + List<Constraint> constraints1 = new LinkedList<>();
168 + Constraint bandwidth1 = BandwidthConstraint.of(200, DataRateUnit.BPS);
169 + constraints1.add(bandwidth1);
170 +
171 + failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1);
172 +
173 + // Creates failedPathInfo2
174 + DeviceId src2 = DeviceId.deviceId("foo2");
175 + DeviceId dst2 = DeviceId.deviceId("goo2");
176 + String name2 = "pcc2";
177 + LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING;
178 + List<Constraint> constraints2 = new LinkedList<>();
179 + Constraint bandwidth2 = BandwidthConstraint.of(400, DataRateUnit.BPS);
180 + constraints2.add(bandwidth2);
181 +
182 + failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2);
183 +
184 + // Creates failedPathInfo3
185 + DeviceId src3 = DeviceId.deviceId("foo3");
186 + DeviceId dst3 = DeviceId.deviceId("goo3");
187 + String name3 = "pcc3";
188 + LspType lspType3 = LspType.SR_WITHOUT_SIGNALLING;
189 + List<Constraint> constraints3 = new LinkedList<>();
190 + Constraint bandwidth3 = BandwidthConstraint.of(500, DataRateUnit.BPS);
191 + constraints3.add(bandwidth3);
192 +
193 + failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3);
194 +
195 + // Creates failedPathInfo4
196 + DeviceId src4 = DeviceId.deviceId("foo4");
197 + DeviceId dst4 = DeviceId.deviceId("goo4");
198 + String name4 = "pcc4";
199 + LspType lspType4 = LspType.SR_WITHOUT_SIGNALLING;
200 + List<Constraint> constraints4 = new LinkedList<>();
201 + Constraint bandwidth4 = BandwidthConstraint.of(600, DataRateUnit.BPS);
202 + constraints4.add(bandwidth4);
203 +
204 + failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4);
153 } 205 }
154 206
155 @After 207 @After
...@@ -211,6 +263,22 @@ public class DistributedPceStoreTest { ...@@ -211,6 +263,22 @@ public class DistributedPceStoreTest {
211 } 263 }
212 264
213 /** 265 /**
266 + * Checks the operation of addFailedPathInfo() method.
267 + */
268 + @Test
269 + public void testAddFailedPathInfo() {
270 + // initialization
271 + distrPceStore.storageService = new TestStorageService();
272 + distrPceStore.activate();
273 +
274 + // PcePathInfo with pce path input information
275 + distrPceStore.addFailedPathInfo(failedPathInfo1);
276 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
277 + distrPceStore.addFailedPathInfo(failedPathInfo2);
278 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
279 + }
280 +
281 + /**
214 * Checks the operation of existsGlobalNodeLabel() method. 282 * Checks the operation of existsGlobalNodeLabel() method.
215 */ 283 */
216 @Test 284 @Test
...@@ -248,6 +316,19 @@ public class DistributedPceStoreTest { ...@@ -248,6 +316,19 @@ public class DistributedPceStoreTest {
248 } 316 }
249 317
250 /** 318 /**
319 + * Checks the operation of existsFailedPathInfo() method.
320 + */
321 + @Test
322 + public void testExistsFailedPathInfo() {
323 + testAddFailedPathInfo();
324 +
325 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
326 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
327 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo3), is(false));
328 + assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo4), is(false));
329 + }
330 +
331 + /**
251 * Checks the operation of getGlobalNodeLabelCount() method. 332 * Checks the operation of getGlobalNodeLabelCount() method.
252 */ 333 */
253 @Test 334 @Test
...@@ -278,6 +359,16 @@ public class DistributedPceStoreTest { ...@@ -278,6 +359,16 @@ public class DistributedPceStoreTest {
278 } 359 }
279 360
280 /** 361 /**
362 + * Checks the operation of getFailedPathInfoCount() method.
363 + */
364 + @Test
365 + public void testGetFailedPathInfoCount() {
366 + testAddFailedPathInfo();
367 +
368 + assertThat(distrPceStore.getFailedPathInfoCount(), is(2));
369 + }
370 +
371 + /**
281 * Checks the operation of getGlobalNodeLabels() method. 372 * Checks the operation of getGlobalNodeLabels() method.
282 */ 373 */
283 @Test 374 @Test
...@@ -317,6 +408,18 @@ public class DistributedPceStoreTest { ...@@ -317,6 +408,18 @@ public class DistributedPceStoreTest {
317 } 408 }
318 409
319 /** 410 /**
411 + * Checks the operation of getFailedPathInfos() method.
412 + */
413 + @Test
414 + public void testGetFailedPathInfos() {
415 + testAddFailedPathInfo();
416 +
417 + Iterable<PcePathInfo> failedPathInfoSet = distrPceStore.getFailedPathInfos();
418 + assertThat(failedPathInfoSet, is(notNullValue()));
419 + assertThat(failedPathInfoSet.iterator().hasNext(), is(true));
420 + }
421 +
422 + /**
320 * Checks the operation of getGlobalNodeLabel() method. 423 * Checks the operation of getGlobalNodeLabel() method.
321 */ 424 */
322 @Test 425 @Test
...@@ -451,4 +554,17 @@ public class DistributedPceStoreTest { ...@@ -451,4 +554,17 @@ public class DistributedPceStoreTest {
451 assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true)); 554 assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true));
452 assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true)); 555 assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true));
453 } 556 }
557 +
558 + /**
559 + * Checks the operation of removeFailedPathInfo() method.
560 + */
561 + @Test
562 + public void testRemoveFailedPathInfo() {
563 + testAddFailedPathInfo();
564 +
565 + assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo1), is(true));
566 + assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo2), is(true));
567 + assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo3), is(false));
568 + assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo4), is(false));
569 + }
454 } 570 }
......
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 java.util.List;
24 +import java.util.LinkedList;
25 +
26 +import org.junit.Test;
27 +import org.onlab.util.DataRateUnit;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.intent.Constraint;
30 +import org.onosproject.net.intent.constraint.BandwidthConstraint;
31 +import org.onosproject.pce.pceservice.LspType;
32 +
33 +/**
34 + * Unit tests for PcePathInfo class.
35 + */
36 +public class PcePathInfoTest {
37 +
38 + /**
39 + * Checks the operation of equals() methods.
40 + */
41 + @Test
42 + public void testEquals() {
43 + // create same two objects.
44 + DeviceId src1 = DeviceId.deviceId("foo1");
45 + DeviceId dst1 = DeviceId.deviceId("goo1");
46 + String name1 = "pcc1";
47 + LspType lspType1 = LspType.WITH_SIGNALLING;
48 + List<Constraint> constraints1 = new LinkedList<>();
49 + Constraint bandwidth11 = BandwidthConstraint.of(100, DataRateUnit.BPS);
50 + constraints1.add(bandwidth11);
51 + Constraint bandwidth12 = BandwidthConstraint.of(200, DataRateUnit.BPS);
52 + constraints1.add(bandwidth12);
53 + Constraint bandwidth13 = BandwidthConstraint.of(300, DataRateUnit.BPS);
54 + constraints1.add(bandwidth13);
55 +
56 + PcePathInfo pathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1);
57 +
58 + // create same object as above object
59 + PcePathInfo samePathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1);
60 +
61 + // Create different object.
62 + DeviceId src2 = DeviceId.deviceId("foo2");
63 + DeviceId dst2 = DeviceId.deviceId("goo2");
64 + String name2 = "pcc2";
65 + LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING;
66 + List<Constraint> constraints2 = new LinkedList<>();
67 + Constraint bandwidth21 = BandwidthConstraint.of(400, DataRateUnit.BPS);
68 + constraints2.add(bandwidth21);
69 + Constraint bandwidth22 = BandwidthConstraint.of(800, DataRateUnit.BPS);
70 + constraints2.add(bandwidth22);
71 +
72 + PcePathInfo pathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2);
73 +
74 + new EqualsTester().addEqualityGroup(pathInfo1, samePathInfo1)
75 + .addEqualityGroup(pathInfo2)
76 + .testEquals();
77 + }
78 +
79 + /**
80 + * Checks the construction of a PcePathInfo object.
81 + */
82 + @Test
83 + public void testConstruction() {
84 + DeviceId src = DeviceId.deviceId("foo2");
85 + DeviceId dst = DeviceId.deviceId("goo2");
86 + String name = "pcc2";
87 + LspType lspType = LspType.SR_WITHOUT_SIGNALLING;
88 + List<Constraint> constraints = new LinkedList<>();
89 + Constraint bandwidth1 = BandwidthConstraint.of(100, DataRateUnit.BPS);
90 + constraints.add(bandwidth1);
91 + Constraint bandwidth2 = BandwidthConstraint.of(200, DataRateUnit.BPS);
92 + constraints.add(bandwidth2);
93 + Constraint bandwidth3 = BandwidthConstraint.of(300, DataRateUnit.BPS);
94 + constraints.add(bandwidth3);
95 +
96 + PcePathInfo pathInfo = new PcePathInfo(src, dst, name, constraints, lspType);
97 +
98 + assertThat(src, is(pathInfo.src()));
99 + assertThat(dst, is(pathInfo.dst()));
100 + assertThat(name, is(pathInfo.name()));
101 + assertThat(constraints, is(pathInfo.constraints()));
102 + assertThat(lspType, is(pathInfo.lspType()));
103 + }
104 +}
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.util;
17 +
18 +import com.google.common.collect.ImmutableSet;
19 +
20 +import java.util.concurrent.ConcurrentHashMap;
21 +import java.util.concurrent.ConcurrentMap;
22 +import java.util.HashSet;
23 +import java.util.List;
24 +import java.util.Map;
25 +import java.util.Set;
26 +import java.util.stream.Collectors;
27 +
28 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
29 +import org.onosproject.incubator.net.tunnel.TunnelId;
30 +import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.Link;
32 +import org.onosproject.net.resource.ResourceConsumer;
33 +import org.onosproject.pce.pcestore.PceccTunnelInfo;
34 +import org.onosproject.pce.pcestore.PcePathInfo;
35 +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
36 +import org.onosproject.pce.pcestore.api.PceStore;
37 +
38 +/**
39 + * Provides test implementation of PceStore.
40 + */
41 +public class PceStoreAdapter implements PceStore {
42 +
43 + // Mapping device with global node label
44 + private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>();
45 +
46 + // Mapping link with adjacency label
47 + private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>();
48 +
49 + // Mapping tunnel with device local info with tunnel consumer id
50 + private ConcurrentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap = new ConcurrentHashMap<>();
51 +
52 + // Set of Path info
53 + private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
54 +
55 + @Override
56 + public boolean existsGlobalNodeLabel(DeviceId id) {
57 + return globalNodeLabelMap.containsKey(id);
58 + }
59 +
60 + @Override
61 + public boolean existsAdjLabel(Link link) {
62 + return adjLabelMap.containsKey(link);
63 + }
64 +
65 + @Override
66 + public boolean existsTunnelInfo(TunnelId tunnelId) {
67 + return tunnelInfoMap.containsKey(tunnelId);
68 + }
69 +
70 + @Override
71 + public boolean existsFailedPathInfo(PcePathInfo pathInfo) {
72 + return failedPathInfoSet.contains(pathInfo);
73 + }
74 +
75 + @Override
76 + public int getGlobalNodeLabelCount() {
77 + return globalNodeLabelMap.size();
78 + }
79 +
80 + @Override
81 + public int getAdjLabelCount() {
82 + return adjLabelMap.size();
83 + }
84 +
85 + @Override
86 + public int getTunnelInfoCount() {
87 + return tunnelInfoMap.size();
88 + }
89 +
90 + @Override
91 + public int getFailedPathInfoCount() {
92 + return failedPathInfoSet.size();
93 + }
94 +
95 + @Override
96 + public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
97 + return globalNodeLabelMap.entrySet().stream()
98 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue()));
99 + }
100 +
101 + @Override
102 + public Map<Link, LabelResourceId> getAdjLabels() {
103 + return adjLabelMap.entrySet().stream()
104 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue()));
105 + }
106 +
107 + @Override
108 + public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
109 + return tunnelInfoMap.entrySet().stream()
110 + .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue()));
111 + }
112 +
113 + @Override
114 + public Iterable<PcePathInfo> getFailedPathInfos() {
115 + return ImmutableSet.copyOf(failedPathInfoSet);
116 + }
117 +
118 + @Override
119 + public LabelResourceId getGlobalNodeLabel(DeviceId id) {
120 + return globalNodeLabelMap.get(id);
121 + }
122 +
123 + @Override
124 + public LabelResourceId getAdjLabel(Link link) {
125 + return adjLabelMap.get(link);
126 + }
127 +
128 + @Override
129 + public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
130 + return tunnelInfoMap.get(tunnelId);
131 + }
132 +
133 + @Override
134 + public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
135 + globalNodeLabelMap.put(deviceId, labelId);
136 + }
137 +
138 + @Override
139 + public void addAdjLabel(Link link, LabelResourceId labelId) {
140 + adjLabelMap.put(link, labelId);
141 + }
142 +
143 + @Override
144 + public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
145 + tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
146 + }
147 +
148 + @Override
149 + public void addFailedPathInfo(PcePathInfo pathInfo) {
150 + failedPathInfoSet.add(pathInfo);
151 + }
152 +
153 + @Override
154 + public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
155 + if (!tunnelInfoMap.containsKey((tunnelId))) {
156 + return false;
157 + }
158 +
159 + PceccTunnelInfo labelStoreInfo = tunnelInfoMap.get(tunnelId);
160 + labelStoreInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
161 + tunnelInfoMap.put(tunnelId, labelStoreInfo);
162 + return true;
163 + }
164 +
165 + @Override
166 + public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
167 + if (!tunnelInfoMap.containsKey((tunnelId))) {
168 + return false;
169 + }
170 +
171 + PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId);
172 + tunnelInfo.tunnelConsumerId(tunnelConsumerId);
173 + tunnelInfoMap.put(tunnelId, tunnelInfo);
174 + return true;
175 + }
176 +
177 + @Override
178 + public boolean removeGlobalNodeLabel(DeviceId id) {
179 + globalNodeLabelMap.remove(id);
180 + if (globalNodeLabelMap.containsKey(id)) {
181 + return false;
182 + }
183 + return true;
184 + }
185 +
186 + @Override
187 + public boolean removeAdjLabel(Link link) {
188 + adjLabelMap.remove(link);
189 + if (adjLabelMap.containsKey(link)) {
190 + return false;
191 + }
192 + return true;
193 + }
194 +
195 + @Override
196 + public boolean removeTunnelInfo(TunnelId tunnelId) {
197 + tunnelInfoMap.remove(tunnelId);
198 + if (tunnelInfoMap.containsKey(tunnelId)) {
199 + return false;
200 + }
201 + return true;
202 + }
203 +
204 + @Override
205 + public boolean removeFailedPathInfo(PcePathInfo pathInfo) {
206 + if (failedPathInfoSet.remove(pathInfo)) {
207 + return false;
208 + }
209 + return true;
210 + }
211 +}