[ONOS-4170] [ONOS-4163] PCE APP side changes : PceManager (code + UT)
Change-Id: I43db98b2fa3c5930b989d4fa3e2c00f7fa65c5ca
Showing
13 changed files
with
2247 additions
and
117 deletions
... | @@ -23,13 +23,24 @@ import java.util.List; | ... | @@ -23,13 +23,24 @@ import java.util.List; |
23 | import java.util.ListIterator; | 23 | import java.util.ListIterator; |
24 | import java.util.LinkedList; | 24 | import java.util.LinkedList; |
25 | 25 | ||
26 | +import org.onlab.packet.MplsLabel; | ||
27 | +import org.onosproject.core.ApplicationId; | ||
26 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | 28 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; |
27 | import org.onosproject.incubator.net.resource.label.LabelResource; | 29 | import org.onosproject.incubator.net.resource.label.LabelResource; |
28 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 30 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
29 | import org.onosproject.incubator.net.resource.label.LabelResourceService; | 31 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
30 | import org.onosproject.incubator.net.tunnel.Tunnel; | 32 | import org.onosproject.incubator.net.tunnel.Tunnel; |
33 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
31 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
32 | import org.onosproject.net.PortNumber; | 35 | import org.onosproject.net.PortNumber; |
36 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
37 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
38 | +import org.onosproject.net.flow.TrafficSelector; | ||
39 | +import org.onosproject.net.flow.TrafficTreatment; | ||
40 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
41 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
42 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
43 | +import org.onosproject.net.flowobjective.Objective; | ||
33 | import org.onosproject.pce.pcestore.api.PceStore; | 44 | import org.onosproject.pce.pcestore.api.PceStore; |
34 | import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | 45 | import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; |
35 | import org.onosproject.pce.pcestore.PceccTunnelInfo; | 46 | import org.onosproject.pce.pcestore.PceccTunnelInfo; |
... | @@ -58,6 +69,8 @@ public final class BasicPceccHandler { | ... | @@ -58,6 +69,8 @@ public final class BasicPceccHandler { |
58 | private static BasicPceccHandler crHandlerInstance = null; | 69 | private static BasicPceccHandler crHandlerInstance = null; |
59 | private LabelResourceService labelRsrcService; | 70 | private LabelResourceService labelRsrcService; |
60 | private PceStore pceStore; | 71 | private PceStore pceStore; |
72 | + private FlowObjectiveService flowObjectiveService; | ||
73 | + private ApplicationId appId; | ||
61 | 74 | ||
62 | /** | 75 | /** |
63 | * Initializes default values. | 76 | * Initializes default values. |
... | @@ -83,8 +96,11 @@ public final class BasicPceccHandler { | ... | @@ -83,8 +96,11 @@ public final class BasicPceccHandler { |
83 | * @param labelRsrcService label resource service | 96 | * @param labelRsrcService label resource service |
84 | * @param pceStore pce label store | 97 | * @param pceStore pce label store |
85 | */ | 98 | */ |
86 | - public void initialize(LabelResourceService labelRsrcService, PceStore pceStore) { | 99 | + public void initialize(LabelResourceService labelRsrcService, FlowObjectiveService flowObjectiveService, |
100 | + ApplicationId appId, PceStore pceStore) { | ||
87 | this.labelRsrcService = labelRsrcService; | 101 | this.labelRsrcService = labelRsrcService; |
102 | + this.flowObjectiveService = flowObjectiveService; | ||
103 | + this.appId = appId; | ||
88 | this.pceStore = pceStore; | 104 | this.pceStore = pceStore; |
89 | } | 105 | } |
90 | 106 | ||
... | @@ -106,8 +122,8 @@ public final class BasicPceccHandler { | ... | @@ -106,8 +122,8 @@ public final class BasicPceccHandler { |
106 | if ((linkList != null) && (linkList.size() > 0)) { | 122 | if ((linkList != null) && (linkList.size() > 0)) { |
107 | // Sequence through reverse order to push local labels into devices | 123 | // Sequence through reverse order to push local labels into devices |
108 | // Generation of labels from egress to ingress | 124 | // Generation of labels from egress to ingress |
109 | - for (ListIterator iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { | 125 | + for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { |
110 | - Link link = (Link) iterator.previous(); | 126 | + Link link = iterator.previous(); |
111 | DeviceId dstDeviceId = link.dst().deviceId(); | 127 | DeviceId dstDeviceId = link.dst().deviceId(); |
112 | DeviceId srcDeviceId = link.src().deviceId(); | 128 | DeviceId srcDeviceId = link.src().deviceId(); |
113 | labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); | 129 | labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); |
... | @@ -131,16 +147,14 @@ public final class BasicPceccHandler { | ... | @@ -131,16 +147,14 @@ public final class BasicPceccHandler { |
131 | } | 147 | } |
132 | 148 | ||
133 | // Push into destination device | 149 | // Push into destination device |
134 | - //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
135 | // Destination device IN port is link.dst().port() | 150 | // Destination device IN port is link.dst().port() |
136 | - //installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, | 151 | + installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, |
137 | - // LabelType.IN, Objective.Operation.ADD); | 152 | + Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); |
138 | 153 | ||
139 | // Push into source device | 154 | // Push into source device |
140 | - //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
141 | // Source device OUT port will be link.dst().port(). Means its remote port used to send packet. | 155 | // Source device OUT port will be link.dst().port(). Means its remote port used to send packet. |
142 | - //installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, | 156 | + installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, |
143 | - // LabelType.OUT, Objective.Operation.ADD); | 157 | + Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); |
144 | 158 | ||
145 | // Add or update pcecc tunnel info in pce store. | 159 | // Add or update pcecc tunnel info in pce store. |
146 | updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, | 160 | updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, |
... | @@ -183,7 +197,7 @@ public final class BasicPceccHandler { | ... | @@ -183,7 +197,7 @@ public final class BasicPceccHandler { |
183 | if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) { | 197 | if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) { |
184 | for (int i = 0; i < lspLabelInfoList.size(); ++i) { | 198 | for (int i = 0; i < lspLabelInfoList.size(); ++i) { |
185 | LspLocalLabelInfo lspLocalLabelInfo = | 199 | LspLocalLabelInfo lspLocalLabelInfo = |
186 | - (DefaultLspLocalLabelInfo) lspLabelInfoList.get(i); | 200 | + lspLabelInfoList.get(i); |
187 | LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null; | 201 | LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null; |
188 | if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) { | 202 | if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) { |
189 | lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | 203 | lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); |
... | @@ -264,7 +278,7 @@ public final class BasicPceccHandler { | ... | @@ -264,7 +278,7 @@ public final class BasicPceccHandler { |
264 | List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | 278 | List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); |
265 | if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) { | 279 | if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) { |
266 | for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) { | 280 | for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) { |
267 | - LspLocalLabelInfo lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 281 | + LspLocalLabelInfo lspLocalLabelInfo = iterator.next(); |
268 | DeviceId deviceId = lspLocalLabelInfo.deviceId(); | 282 | DeviceId deviceId = lspLocalLabelInfo.deviceId(); |
269 | LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId(); | 283 | LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId(); |
270 | LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId(); | 284 | LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId(); |
... | @@ -278,15 +292,13 @@ public final class BasicPceccHandler { | ... | @@ -278,15 +292,13 @@ public final class BasicPceccHandler { |
278 | 292 | ||
279 | // Push into device | 293 | // Push into device |
280 | if ((inLabelId != null) && (inPort != null)) { | 294 | if ((inLabelId != null) && (inPort != null)) { |
281 | - //TODO: uncomment below lines once installLocalLabelRule() method is ready | 295 | + installLocalLabelRule(deviceId, inLabelId, inPort, tunnel.tunnelId(), isLastLabelToPush, |
282 | - //installLocalLabelRule(deviceId, inLabelId, inPort, tunnelId, isLastLabelToPush, | 296 | + Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.REMOVE); |
283 | - // LabelType.IN, Objective.Operation.REMOVE); | ||
284 | } | 297 | } |
285 | 298 | ||
286 | if ((outLabelId != null) && (outPort != null)) { | 299 | if ((outLabelId != null) && (outPort != null)) { |
287 | - //TODO: uncomment below lines once installLocalLabelRule() method is ready | 300 | + installLocalLabelRule(deviceId, outLabelId, outPort, tunnel.tunnelId(), isLastLabelToPush, |
288 | - //installLocalLabelRule(deviceId, outLabelId, outPort, tunnelId, isLastLabelToPush, | 301 | + Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.REMOVE); |
289 | - // LabelType.OUT, Objective.Operation.REMOVE); | ||
290 | } | 302 | } |
291 | 303 | ||
292 | // List is stored from egress to ingress. So, using IN label id to release. | 304 | // List is stored from egress to ingress. So, using IN label id to release. |
... | @@ -315,4 +327,35 @@ public final class BasicPceccHandler { | ... | @@ -315,4 +327,35 @@ public final class BasicPceccHandler { |
315 | log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString()); | 327 | log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString()); |
316 | } | 328 | } |
317 | } | 329 | } |
330 | + | ||
331 | + // Install a rule for pushing local labels to the device which is specific to path. | ||
332 | + private void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId, | ||
333 | + PortNumber portNum, TunnelId tunnelId, | ||
334 | + Boolean isBos, Long labelType, | ||
335 | + Objective.Operation type) { | ||
336 | + checkNotNull(flowObjectiveService); | ||
337 | + checkNotNull(appId); | ||
338 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
339 | + | ||
340 | + selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
341 | + selectorBuilder.matchInPort(portNum); | ||
342 | + selectorBuilder.matchTunnelId(Long.parseLong(tunnelId.id())); | ||
343 | + selectorBuilder.matchMplsBos(isBos); | ||
344 | + selectorBuilder.matchMetadata(labelType); | ||
345 | + | ||
346 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
347 | + | ||
348 | + ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
349 | + .withSelector(selectorBuilder.build()) | ||
350 | + .withTreatment(treatment) | ||
351 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
352 | + .fromApp(appId) | ||
353 | + .makePermanent(); | ||
354 | + | ||
355 | + if (type.equals(Objective.Operation.ADD)) { | ||
356 | + flowObjectiveService.forward(deviceId, forwardingObjective.add()); | ||
357 | + } else { | ||
358 | + flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | ||
359 | + } | ||
360 | + } | ||
318 | } | 361 | } | ... | ... |
... | @@ -16,11 +16,15 @@ | ... | @@ -16,11 +16,15 @@ |
16 | package org.onosproject.pce.pceservice; | 16 | package org.onosproject.pce.pceservice; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | -import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; | ||
20 | 19 | ||
20 | +import java.util.Collection; | ||
21 | import java.util.Collections; | 21 | import java.util.Collections; |
22 | import java.util.Iterator; | 22 | import java.util.Iterator; |
23 | +import java.util.LinkedList; | ||
23 | import java.util.List; | 24 | import java.util.List; |
25 | +import java.util.Map; | ||
26 | +import java.util.Optional; | ||
27 | +import java.util.Map.Entry; | ||
24 | import java.util.Set; | 28 | import java.util.Set; |
25 | 29 | ||
26 | import org.apache.felix.scr.annotations.Activate; | 30 | import org.apache.felix.scr.annotations.Activate; |
... | @@ -29,22 +33,53 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -29,22 +33,53 @@ import org.apache.felix.scr.annotations.Deactivate; |
29 | import org.apache.felix.scr.annotations.Reference; | 33 | import org.apache.felix.scr.annotations.Reference; |
30 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 34 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
31 | import org.apache.felix.scr.annotations.Service; | 35 | import org.apache.felix.scr.annotations.Service; |
36 | +import org.onlab.packet.IpAddress; | ||
37 | +import org.onlab.packet.IpPrefix; | ||
38 | +import org.onlab.util.Bandwidth; | ||
32 | import org.onosproject.core.ApplicationId; | 39 | import org.onosproject.core.ApplicationId; |
33 | import org.onosproject.core.CoreService; | 40 | import org.onosproject.core.CoreService; |
41 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
42 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
43 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
34 | import org.onosproject.core.IdGenerator; | 44 | import org.onosproject.core.IdGenerator; |
45 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
46 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
47 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
35 | import org.onosproject.incubator.net.tunnel.Tunnel; | 48 | import org.onosproject.incubator.net.tunnel.Tunnel; |
49 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
50 | +import org.onosproject.incubator.net.tunnel.TunnelEvent; | ||
36 | import org.onosproject.incubator.net.tunnel.TunnelId; | 51 | import org.onosproject.incubator.net.tunnel.TunnelId; |
52 | +import org.onosproject.incubator.net.tunnel.TunnelListener; | ||
53 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
37 | import org.onosproject.incubator.net.tunnel.TunnelService; | 54 | import org.onosproject.incubator.net.tunnel.TunnelService; |
55 | +import org.onosproject.net.DefaultAnnotations; | ||
56 | +import org.onosproject.net.DefaultAnnotations.Builder; | ||
57 | +import org.onosproject.net.Device; | ||
38 | import org.onosproject.net.DeviceId; | 58 | import org.onosproject.net.DeviceId; |
59 | +import org.onosproject.net.Link; | ||
39 | import org.onosproject.net.Path; | 60 | import org.onosproject.net.Path; |
40 | -import org.onosproject.net.intent.Constraint; | ||
41 | import org.onosproject.net.device.DeviceService; | 61 | import org.onosproject.net.device.DeviceService; |
62 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
63 | +import org.onosproject.net.flowobjective.Objective; | ||
64 | +import org.onosproject.net.intent.Constraint; | ||
65 | +import org.onosproject.net.intent.constraint.BandwidthConstraint; | ||
66 | +import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; | ||
67 | +import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; | ||
68 | +import org.onosproject.pce.pceservice.constraint.CostConstraint; | ||
69 | +import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; | ||
70 | +import org.onosproject.net.resource.Resource; | ||
71 | +import org.onosproject.net.resource.ResourceAllocation; | ||
72 | +import org.onosproject.net.resource.ResourceConsumer; | ||
73 | +import org.onosproject.net.resource.ResourceQueryService; | ||
42 | import org.onosproject.net.resource.ResourceService; | 74 | import org.onosproject.net.resource.ResourceService; |
75 | +import org.onosproject.net.resource.Resources; | ||
43 | import org.onosproject.net.topology.LinkWeight; | 76 | import org.onosproject.net.topology.LinkWeight; |
44 | import org.onosproject.net.topology.PathService; | 77 | import org.onosproject.net.topology.PathService; |
45 | import org.onosproject.net.topology.TopologyEdge; | 78 | import org.onosproject.net.topology.TopologyEdge; |
46 | import org.onosproject.pce.pceservice.api.PceService; | 79 | import org.onosproject.pce.pceservice.api.PceService; |
47 | -import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; | 80 | +import org.onosproject.pce.pcestore.PcePathInfo; |
81 | +import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
82 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
48 | import org.onosproject.store.serializers.KryoNamespaces; | 83 | import org.onosproject.store.serializers.KryoNamespaces; |
49 | import org.onosproject.store.service.DistributedSet; | 84 | import org.onosproject.store.service.DistributedSet; |
50 | import org.onosproject.store.service.Serializer; | 85 | import org.onosproject.store.service.Serializer; |
... | @@ -53,6 +88,29 @@ import org.slf4j.Logger; | ... | @@ -53,6 +88,29 @@ import org.slf4j.Logger; |
53 | import org.slf4j.LoggerFactory; | 88 | import org.slf4j.LoggerFactory; |
54 | 89 | ||
55 | import com.google.common.collect.ImmutableList; | 90 | import com.google.common.collect.ImmutableList; |
91 | +import com.google.common.collect.ImmutableSet; | ||
92 | + | ||
93 | +import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; | ||
94 | +import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT; | ||
95 | +import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; | ||
96 | +import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; | ||
97 | +import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; | ||
98 | +import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; | ||
99 | +import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; | ||
100 | + | ||
101 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.BANDWIDTH; | ||
102 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; | ||
103 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LSP_SIG_TYPE; | ||
104 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PCE_INIT; | ||
105 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; | ||
106 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PCC_TUNNEL_ID; | ||
107 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.DELEGATE; | ||
108 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.COST_TYPE; | ||
109 | + | ||
110 | +import org.onosproject.net.packet.InboundPacket; | ||
111 | +import org.onosproject.net.packet.PacketContext; | ||
112 | +import org.onosproject.net.packet.PacketProcessor; | ||
113 | +import org.onosproject.net.packet.PacketService; | ||
56 | 114 | ||
57 | /** | 115 | /** |
58 | * Implementation of PCE service. | 116 | * Implementation of PCE service. |
... | @@ -63,8 +121,17 @@ public class PceManager implements PceService { | ... | @@ -63,8 +121,17 @@ public class PceManager implements PceService { |
63 | private static final Logger log = LoggerFactory.getLogger(PceManager.class); | 121 | private static final Logger log = LoggerFactory.getLogger(PceManager.class); |
64 | 122 | ||
65 | public static final String PCE_SERVICE_APP = "org.onosproject.pce"; | 123 | public static final String PCE_SERVICE_APP = "org.onosproject.pce"; |
66 | - | ||
67 | private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; | 124 | private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; |
125 | + private static final int PREFIX_LENGTH = 32; | ||
126 | + | ||
127 | + private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id"; | ||
128 | + private IdGenerator tunnelConsumerIdGen; | ||
129 | + | ||
130 | + private static final String LSRID = "lsrId"; | ||
131 | + private static final String TRUE = "true"; | ||
132 | + private static final String FALSE = "false"; | ||
133 | + private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32"; | ||
134 | + | ||
68 | private IdGenerator localLspIdIdGen; | 135 | private IdGenerator localLspIdIdGen; |
69 | protected DistributedSet<Short> localLspIdFreeList; | 136 | protected DistributedSet<Short> localLspIdFreeList; |
70 | 137 | ||
... | @@ -72,22 +139,45 @@ public class PceManager implements PceService { | ... | @@ -72,22 +139,45 @@ public class PceManager implements PceService { |
72 | protected CoreService coreService; | 139 | protected CoreService coreService; |
73 | 140 | ||
74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
75 | - protected TunnelService tunnelService; | 142 | + protected ResourceService resourceService; |
76 | 143 | ||
77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
78 | - protected StorageService storageService; | 145 | + protected ResourceQueryService resourceQueryService; |
79 | 146 | ||
80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
81 | protected PathService pathService; | 148 | protected PathService pathService; |
82 | 149 | ||
83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
84 | - protected ResourceService resourceService; | 151 | + protected PceStore pceStore; |
152 | + | ||
153 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
154 | + protected TunnelService tunnelService; | ||
155 | + | ||
156 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
157 | + protected StorageService storageService; | ||
158 | + | ||
159 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
160 | + protected PacketService packetService; | ||
85 | 161 | ||
86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 162 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
87 | protected DeviceService deviceService; | 163 | protected DeviceService deviceService; |
88 | 164 | ||
165 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
166 | + protected LabelResourceAdminService labelRsrcAdminService; | ||
167 | + | ||
168 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
169 | + protected LabelResourceService labelRsrcService; | ||
170 | + | ||
171 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
172 | + protected FlowObjectiveService flowObjectiveService; | ||
173 | + | ||
174 | + private TunnelListener listener = new InnerTunnelListener(); | ||
175 | + private BasicPceccHandler crHandler; | ||
176 | + private PceccSrTeBeHandler srTeHandler; | ||
89 | private ApplicationId appId; | 177 | private ApplicationId appId; |
90 | 178 | ||
179 | + private final PcepPacketProcessor processor = new PcepPacketProcessor(); | ||
180 | + | ||
91 | /** | 181 | /** |
92 | * Creates new instance of PceManager. | 182 | * Creates new instance of PceManager. |
93 | */ | 183 | */ |
... | @@ -97,18 +187,30 @@ public class PceManager implements PceService { | ... | @@ -97,18 +187,30 @@ public class PceManager implements PceService { |
97 | @Activate | 187 | @Activate |
98 | protected void activate() { | 188 | protected void activate() { |
99 | appId = coreService.registerApplication(PCE_SERVICE_APP); | 189 | appId = coreService.registerApplication(PCE_SERVICE_APP); |
100 | - log.info("Started"); | 190 | + crHandler = BasicPceccHandler.getInstance(); |
191 | + crHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore); | ||
101 | 192 | ||
193 | + srTeHandler = PceccSrTeBeHandler.getInstance(); | ||
194 | + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore); | ||
195 | + | ||
196 | + tunnelService.addListener(listener); | ||
197 | + | ||
198 | + tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC); | ||
102 | localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); | 199 | localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); |
103 | localLspIdFreeList = storageService.<Short>setBuilder() | 200 | localLspIdFreeList = storageService.<Short>setBuilder() |
104 | .withName("pcepLocalLspIdDeletedList") | 201 | .withName("pcepLocalLspIdDeletedList") |
105 | .withSerializer(Serializer.using(KryoNamespaces.API)) | 202 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
106 | .build() | 203 | .build() |
107 | .asDistributedSet(); | 204 | .asDistributedSet(); |
205 | + | ||
206 | + packetService.addProcessor(processor, PacketProcessor.director(4)); | ||
207 | + log.info("Started"); | ||
108 | } | 208 | } |
109 | 209 | ||
110 | @Deactivate | 210 | @Deactivate |
111 | protected void deactivate() { | 211 | protected void deactivate() { |
212 | + tunnelService.removeListener(listener); | ||
213 | + packetService.removeProcessor(processor); | ||
112 | log.info("Stopped"); | 214 | log.info("Stopped"); |
113 | } | 215 | } |
114 | 216 | ||
... | @@ -133,13 +235,13 @@ public class PceManager implements PceService { | ... | @@ -133,13 +235,13 @@ public class PceManager implements PceService { |
133 | */ | 235 | */ |
134 | protected Set<Path> computePath(DeviceId src, DeviceId dst, List<Constraint> constraints) { | 236 | protected Set<Path> computePath(DeviceId src, DeviceId dst, List<Constraint> constraints) { |
135 | if (pathService == null) { | 237 | if (pathService == null) { |
136 | - return null; | 238 | + return ImmutableSet.of(); |
137 | } | 239 | } |
138 | Set<Path> paths = pathService.getPaths(src, dst, weight(constraints)); | 240 | Set<Path> paths = pathService.getPaths(src, dst, weight(constraints)); |
139 | if (!paths.isEmpty()) { | 241 | if (!paths.isEmpty()) { |
140 | return paths; | 242 | return paths; |
141 | } | 243 | } |
142 | - return null; | 244 | + return ImmutableSet.of(); |
143 | } | 245 | } |
144 | 246 | ||
145 | //[TODO:] handle requests in queue | 247 | //[TODO:] handle requests in queue |
... | @@ -149,22 +251,264 @@ public class PceManager implements PceService { | ... | @@ -149,22 +251,264 @@ public class PceManager implements PceService { |
149 | checkNotNull(src); | 251 | checkNotNull(src); |
150 | checkNotNull(dst); | 252 | checkNotNull(dst); |
151 | checkNotNull(tunnelName); | 253 | checkNotNull(tunnelName); |
152 | - checkNotNull(constraints); | ||
153 | checkNotNull(lspType); | 254 | checkNotNull(lspType); |
154 | 255 | ||
155 | - // TODO: compute and setup path. | 256 | + // Convert from DeviceId to TunnelEndPoint |
156 | - //TODO: gets the path based on constraints and creates a tunnel in network via tunnel manager | 257 | + Device srcDevice = deviceService.getDevice(src); |
157 | - return computePath(src, dst, constraints) != null ? true : false; | 258 | + Device dstDevice = deviceService.getDevice(dst); |
259 | + | ||
260 | + if (srcDevice == null || dstDevice == null) { | ||
261 | + // Device is not known. | ||
262 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
263 | + return false; | ||
264 | + } | ||
265 | + | ||
266 | + // In future projections instead of annotations will be used to fetch LSR ID. | ||
267 | + String srcLsrId = srcDevice.annotations().value(LSRID); | ||
268 | + String dstLsrId = dstDevice.annotations().value(LSRID); | ||
269 | + | ||
270 | + if (srcLsrId == null || dstLsrId == null) { | ||
271 | + // LSR id is not known. | ||
272 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
273 | + return false; | ||
274 | + } | ||
275 | + | ||
276 | + TunnelEndPoint srcEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(srcLsrId)); | ||
277 | + TunnelEndPoint dstEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dstLsrId)); | ||
278 | + | ||
279 | + double bwConstraintValue = 0; | ||
280 | + CostConstraint costConstraint = null; | ||
281 | + if (constraints != null) { | ||
282 | + constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspType.name()))); | ||
283 | + Iterator<Constraint> iterator = constraints.iterator(); | ||
284 | + | ||
285 | + while (iterator.hasNext()) { | ||
286 | + Constraint constraint = iterator.next(); | ||
287 | + if (constraint instanceof BandwidthConstraint) { | ||
288 | + bwConstraintValue = ((BandwidthConstraint) constraint).bandwidth().bps(); | ||
289 | + } else if (constraint instanceof CostConstraint) { | ||
290 | + costConstraint = (CostConstraint) constraint; | ||
291 | + } | ||
292 | + } | ||
293 | + | ||
294 | + /* | ||
295 | + * Add cost at the end of the list of constraints. The path computation algorithm also computes cumulative | ||
296 | + * cost. The function which checks the limiting/capability constraints also returns per link cost. This | ||
297 | + * function can either return the result of limiting/capability constraint validation or the value of link | ||
298 | + * cost, depending upon what is the last constraint in the loop. | ||
299 | + */ | ||
300 | + if (costConstraint != null) { | ||
301 | + constraints.remove(costConstraint); | ||
302 | + constraints.add(costConstraint); | ||
303 | + } | ||
304 | + } else { | ||
305 | + constraints = new LinkedList<>(); | ||
306 | + constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspType.name()))); | ||
307 | + } | ||
308 | + | ||
309 | + Set<Path> computedPathSet = computePath(src, dst, constraints); | ||
310 | + | ||
311 | + // NO-PATH | ||
312 | + if (computedPathSet.isEmpty()) { | ||
313 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
314 | + return false; | ||
315 | + } | ||
316 | + | ||
317 | + Builder annotationBuilder = DefaultAnnotations.builder(); | ||
318 | + if (bwConstraintValue != 0) { | ||
319 | + annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue)); | ||
320 | + } | ||
321 | + if (costConstraint != null) { | ||
322 | + annotationBuilder.set(COST_TYPE, String.valueOf(costConstraint.type())); | ||
323 | + } | ||
324 | + annotationBuilder.set(LSP_SIG_TYPE, lspType.name()); | ||
325 | + annotationBuilder.set(PCE_INIT, TRUE); | ||
326 | + annotationBuilder.set(DELEGATE, TRUE); | ||
327 | + | ||
328 | + Path computedPath = computedPathSet.iterator().next(); | ||
329 | + LabelStack labelStack = null; | ||
330 | + | ||
331 | + if (lspType == SR_WITHOUT_SIGNALLING) { | ||
332 | + labelStack = srTeHandler.computeLabelStack(computedPath); | ||
333 | + // Failed to form a label stack. | ||
334 | + if (labelStack == null) { | ||
335 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
336 | + return false; | ||
337 | + } | ||
158 | } | 338 | } |
159 | 339 | ||
340 | + if (lspType != WITH_SIGNALLING) { | ||
341 | + /* | ||
342 | + * Local LSP id which is assigned by RSVP for RSVP signalled LSPs, will be assigned by | ||
343 | + * PCE for non-RSVP signalled LSPs. | ||
344 | + */ | ||
345 | + annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(getNextLocalLspId())); | ||
346 | + } | ||
347 | + | ||
348 | + // For SR-TE tunnels, call SR manager for label stack and put it inside tunnel. | ||
349 | + Tunnel tunnel = new DefaultTunnel(null, srcEndPoint, dstEndPoint, MPLS, INIT, null, null, | ||
350 | + TunnelName.tunnelName(tunnelName), computedPath, | ||
351 | + labelStack, annotationBuilder.build()); | ||
352 | + | ||
353 | + // Allocate bandwidth. | ||
354 | + TunnelConsumerId consumerId = null; | ||
355 | + if (bwConstraintValue != 0) { | ||
356 | + consumerId = reserveBandwidth(computedPath, bwConstraintValue, null); | ||
357 | + if (consumerId == null) { | ||
358 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
359 | + return false; | ||
360 | + } | ||
361 | + } | ||
362 | + | ||
363 | + TunnelId tunnelId = tunnelService.setupTunnel(appId, src, tunnel, computedPath); | ||
364 | + if (tunnelId == null) { | ||
365 | + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
366 | + if (consumerId != null) { | ||
367 | + resourceService.release(consumerId); | ||
368 | + } | ||
369 | + return false; | ||
370 | + } | ||
371 | + | ||
372 | + if (consumerId != null) { | ||
373 | + // Store tunnel consumer id in LSP-Label store. | ||
374 | + PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId); | ||
375 | + pceStore.addTunnelInfo(tunnelId, pceccTunnelInfo); | ||
376 | + } | ||
377 | + return true; | ||
378 | + } | ||
160 | 379 | ||
161 | @Override | 380 | @Override |
162 | public boolean updatePath(TunnelId tunnelId, List<Constraint> constraints) { | 381 | public boolean updatePath(TunnelId tunnelId, List<Constraint> constraints) { |
163 | checkNotNull(tunnelId); | 382 | checkNotNull(tunnelId); |
164 | - checkNotNull(constraints); | 383 | + Set<Path> computedPathSet = null; |
384 | + Tunnel tunnel = tunnelService.queryTunnel(tunnelId); | ||
385 | + | ||
386 | + if (tunnel == null) { | ||
387 | + return false; | ||
388 | + } | ||
389 | + | ||
390 | + if (tunnel.type() != MPLS || FALSE.equalsIgnoreCase(tunnel.annotations().value(DELEGATE))) { | ||
391 | + // Only delegated LSPs can be updated. | ||
392 | + return false; | ||
393 | + } | ||
394 | + | ||
395 | + List<Link> links = tunnel.path().links(); | ||
396 | + String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE); | ||
397 | + double bwConstraintValue = 0; | ||
398 | + SharedBandwidthConstraint shBwConstraint = null; | ||
399 | + BandwidthConstraint bwConstraint = null; | ||
400 | + CostConstraint costConstraint = null; | ||
401 | + | ||
402 | + if (constraints != null) { | ||
403 | + // Call path computation in shared bandwidth mode. | ||
404 | + Iterator<Constraint> iterator = constraints.iterator(); | ||
405 | + while (iterator.hasNext()) { | ||
406 | + Constraint constraint = iterator.next(); | ||
407 | + if (constraint instanceof BandwidthConstraint) { | ||
408 | + bwConstraint = (BandwidthConstraint) constraint; | ||
409 | + bwConstraintValue = bwConstraint.bandwidth().bps(); | ||
410 | + } else if (constraint instanceof CostConstraint) { | ||
411 | + costConstraint = (CostConstraint) constraint; | ||
412 | + } | ||
413 | + } | ||
414 | + | ||
415 | + // Remove and keep the cost constraint at the end of the list of constraints. | ||
416 | + if (costConstraint != null) { | ||
417 | + constraints.remove(costConstraint); | ||
418 | + } | ||
165 | 419 | ||
166 | - // TODO: compute and update path. | 420 | + Bandwidth existingBwValue = null; |
421 | + String existingBwAnnotation = tunnel.annotations().value(BANDWIDTH); | ||
422 | + if (existingBwAnnotation != null) { | ||
423 | + existingBwValue = Bandwidth.bps(Double.parseDouble(existingBwAnnotation)); | ||
167 | 424 | ||
425 | + /* | ||
426 | + * The computation is a shared bandwidth constraint based, so need to remove bandwidth constraint which | ||
427 | + * has been utilized to create shared bandwidth constraint. | ||
428 | + */ | ||
429 | + if (bwConstraint != null) { | ||
430 | + constraints.remove(bwConstraint); | ||
431 | + } | ||
432 | + } | ||
433 | + | ||
434 | + if (existingBwValue != null) { | ||
435 | + shBwConstraint = new SharedBandwidthConstraint(links, existingBwValue, bwConstraint.bandwidth()); | ||
436 | + constraints.add(shBwConstraint); | ||
437 | + } | ||
438 | + } else { | ||
439 | + constraints = new LinkedList<>(); | ||
440 | + } | ||
441 | + | ||
442 | + constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspSigType))); | ||
443 | + if (costConstraint != null) { | ||
444 | + constraints.add(costConstraint); | ||
445 | + } | ||
446 | + | ||
447 | + computedPathSet = computePath(links.get(0).src().deviceId(), links.get(links.size() - 1).dst().deviceId(), | ||
448 | + constraints); | ||
449 | + | ||
450 | + // NO-PATH | ||
451 | + if (computedPathSet.isEmpty()) { | ||
452 | + return false; | ||
453 | + } | ||
454 | + | ||
455 | + Builder annotationBuilder = DefaultAnnotations.builder(); | ||
456 | + annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue)); | ||
457 | + annotationBuilder.set(LSP_SIG_TYPE, lspSigType); | ||
458 | + annotationBuilder.set(PCE_INIT, TRUE); | ||
459 | + annotationBuilder.set(DELEGATE, TRUE); | ||
460 | + annotationBuilder.set(PLSP_ID, tunnel.annotations().value(PLSP_ID)); | ||
461 | + annotationBuilder.set(PCC_TUNNEL_ID, tunnel.annotations().value(PCC_TUNNEL_ID)); | ||
462 | + | ||
463 | + Path computedPath = computedPathSet.iterator().next(); | ||
464 | + LabelStack labelStack = null; | ||
465 | + TunnelConsumerId consumerId = null; | ||
466 | + LspType lspType = LspType.valueOf(lspSigType); | ||
467 | + long localLspId = 0; | ||
468 | + if (lspType != WITH_SIGNALLING) { | ||
469 | + /* | ||
470 | + * Local LSP id which is assigned by RSVP for RSVP signalled LSPs, will be assigned by | ||
471 | + * PCE for non-RSVP signalled LSPs. | ||
472 | + */ | ||
473 | + localLspId = getNextLocalLspId(); | ||
474 | + annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(localLspId)); | ||
475 | + | ||
476 | + if (lspType == SR_WITHOUT_SIGNALLING) { | ||
477 | + labelStack = srTeHandler.computeLabelStack(computedPath); | ||
478 | + // Failed to form a label stack. | ||
479 | + if (labelStack == null) { | ||
480 | + return false; | ||
481 | + } | ||
482 | + } | ||
483 | + } | ||
484 | + | ||
485 | + Tunnel updatedTunnel = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null, null, | ||
486 | + tunnel.tunnelName(), computedPath, | ||
487 | + labelStack, annotationBuilder.build()); | ||
488 | + | ||
489 | + // Allocate shared bandwidth. | ||
490 | + if (bwConstraintValue != 0) { | ||
491 | + consumerId = reserveBandwidth(computedPath, bwConstraintValue, shBwConstraint); | ||
492 | + if (consumerId == null) { | ||
493 | + return false; | ||
494 | + } | ||
495 | + } | ||
496 | + | ||
497 | + TunnelId updatedTunnelId = tunnelService.setupTunnel(appId, links.get(0).src().deviceId(), updatedTunnel, | ||
498 | + computedPath); | ||
499 | + | ||
500 | + if (updatedTunnelId == null) { | ||
501 | + if (consumerId != null) { | ||
502 | + resourceService.release(consumerId); | ||
503 | + } | ||
504 | + return false; | ||
505 | + } | ||
506 | + | ||
507 | + if (consumerId != null) { | ||
508 | + // Store tunnel consumer id in LSP-Label store. | ||
509 | + PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId); | ||
510 | + pceStore.addTunnelInfo(updatedTunnelId, pceccTunnelInfo); | ||
511 | + } | ||
168 | return true; | 512 | return true; |
169 | } | 513 | } |
170 | 514 | ||
... | @@ -249,4 +593,281 @@ public class PceManager implements PceService { | ... | @@ -249,4 +593,281 @@ public class PceManager implements PceService { |
249 | return cost; | 593 | return cost; |
250 | } | 594 | } |
251 | } | 595 | } |
596 | + | ||
597 | + | ||
598 | + // Allocates the bandwidth locally for PCECC tunnels. | ||
599 | + private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint, | ||
600 | + SharedBandwidthConstraint shBwConstraint) { | ||
601 | + checkNotNull(computedPath); | ||
602 | + checkNotNull(bandwidthConstraint); | ||
603 | + Resource resource = null; | ||
604 | + double bwToAllocate = 0; | ||
605 | + | ||
606 | + TunnelConsumerId consumer = TunnelConsumerId.valueOf(tunnelConsumerIdGen.getNewId()); | ||
607 | + | ||
608 | + /** | ||
609 | + * Shared bandwidth sub-case : Lesser bandwidth required than original - | ||
610 | + * No reservation required. | ||
611 | + */ | ||
612 | + Double additionalBwValue = null; | ||
613 | + if (shBwConstraint != null) { | ||
614 | + additionalBwValue = ((bandwidthConstraint - shBwConstraint.sharedBwValue().bps()) <= 0) ? null | ||
615 | + : (bandwidthConstraint - shBwConstraint.sharedBwValue().bps()); | ||
616 | + } | ||
617 | + | ||
618 | + Optional<ResourceAllocation> resAlloc = null; | ||
619 | + for (Link link : computedPath.links()) { | ||
620 | + bwToAllocate = 0; | ||
621 | + if ((shBwConstraint != null) && (shBwConstraint.links().contains(link))) { | ||
622 | + if (additionalBwValue != null) { | ||
623 | + bwToAllocate = bandwidthConstraint - additionalBwValue; | ||
624 | + } | ||
625 | + } else { | ||
626 | + bwToAllocate = bandwidthConstraint; | ||
627 | + } | ||
628 | + | ||
629 | + /** | ||
630 | + * In shared bandwidth cases, where new BW is lesser than old BW, it | ||
631 | + * is not required to allocate anything. | ||
632 | + */ | ||
633 | + if (bwToAllocate != 0) { | ||
634 | + resource = Resources.continuous(link.src().deviceId(), link.src().port(), Bandwidth.class) | ||
635 | + .resource(bwToAllocate); | ||
636 | + resAlloc = resourceService.allocate(consumer, resource); | ||
637 | + | ||
638 | + // If allocation for any link fails, then release the partially allocated bandwidth. | ||
639 | + if (!resAlloc.isPresent()) { | ||
640 | + resourceService.release(consumer); | ||
641 | + return null; | ||
642 | + } | ||
643 | + } | ||
644 | + } | ||
645 | + | ||
646 | + /* | ||
647 | + * Note: Storing of tunnel consumer id is done by caller of bandwidth reservation function. So deleting tunnel | ||
648 | + * consumer id should be done by caller of bandwidth releasing function. This will prevent ambiguities related | ||
649 | + * to who is supposed to store/delete. | ||
650 | + */ | ||
651 | + return consumer; | ||
652 | + } | ||
653 | + | ||
654 | + /* | ||
655 | + * Deallocates the bandwidth which is reserved locally for PCECC tunnels. | ||
656 | + */ | ||
657 | + private void releaseBandwidth(Tunnel tunnel) { | ||
658 | + // Between same source and destination, search the tunnel with same symbolic path name. | ||
659 | + Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnel.src(), tunnel.dst()); | ||
660 | + Tunnel newTunnel = null; | ||
661 | + for (Tunnel tunnelObj : tunnelQueryResult) { | ||
662 | + if (tunnel.tunnelName().value().equals(tunnelObj.tunnelName().value())) { | ||
663 | + newTunnel = tunnelObj; | ||
664 | + break; | ||
665 | + } | ||
666 | + } | ||
667 | + | ||
668 | + // Even if one link is shared, the bandwidth release should happen based on shared mechanism. | ||
669 | + boolean isLinkShared = false; | ||
670 | + if (newTunnel != null) { | ||
671 | + for (Link link : tunnel.path().links()) { | ||
672 | + if (newTunnel.path().links().contains(link)) { | ||
673 | + isLinkShared = true; | ||
674 | + break; | ||
675 | + } | ||
676 | + } | ||
677 | + } | ||
678 | + | ||
679 | + if (isLinkShared) { | ||
680 | + releaseSharedBandwidth(newTunnel, tunnel); | ||
681 | + return; | ||
682 | + } | ||
683 | + | ||
684 | + resourceService.release(pceStore.getTunnelInfo(tunnel.tunnelId()).tunnelConsumerId()); | ||
685 | + return; | ||
686 | + | ||
687 | + /* | ||
688 | + * Note: Storing of tunnel consumer id is done by caller of bandwidth reservation function. So deleting tunnel | ||
689 | + * consumer id should be done by caller of bandwidth releasing function. This will prevent ambiguities related | ||
690 | + * to who is supposed to store/delete. | ||
691 | + */ | ||
692 | + } | ||
693 | + | ||
694 | + /** | ||
695 | + * Re-allocates the bandwidth for the tunnel for which the bandwidth was | ||
696 | + * allocated in shared mode initially. | ||
697 | + */ | ||
698 | + private synchronized void releaseSharedBandwidth(Tunnel newTunnel, Tunnel oldTunnel) { | ||
699 | + // 1. Release old tunnel's bandwidth. | ||
700 | + resourceService.release(pceStore.getTunnelInfo(oldTunnel.tunnelId()).tunnelConsumerId()); | ||
701 | + | ||
702 | + // 2. Release new tunnel's bandwidth | ||
703 | + ResourceConsumer consumer = pceStore.getTunnelInfo(newTunnel.tunnelId()).tunnelConsumerId(); | ||
704 | + resourceService.release(consumer); | ||
705 | + | ||
706 | + // 3. Allocate new tunnel's complete bandwidth. | ||
707 | + double bandwidth = Double.parseDouble(newTunnel.annotations().value(BANDWIDTH)); | ||
708 | + Resource resource; | ||
709 | + | ||
710 | + for (Link link : newTunnel.path().links()) { | ||
711 | + resource = Resources.continuous(link.src().deviceId(), link.src().port(), Bandwidth.class) | ||
712 | + .resource(bandwidth); | ||
713 | + resourceService.allocate(consumer, resource); // Reusing new tunnel's TunnelConsumerId intentionally. | ||
714 | + } | ||
715 | + } | ||
716 | + | ||
717 | + // Listens on tunnel events. | ||
718 | + private class InnerTunnelListener implements TunnelListener { | ||
719 | + @Override | ||
720 | + public void event(TunnelEvent event) { | ||
721 | + // Event gets generated with old tunnel object. | ||
722 | + Tunnel tunnel = event.subject(); | ||
723 | + if (tunnel.type() != MPLS) { | ||
724 | + return; | ||
725 | + } | ||
726 | + | ||
727 | + LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
728 | + String tunnelBandwidth = tunnel.annotations().value(BANDWIDTH); | ||
729 | + double bwConstraintValue = 0; | ||
730 | + if (tunnelBandwidth != null) { | ||
731 | + bwConstraintValue = Double.parseDouble(tunnelBandwidth); | ||
732 | + } | ||
733 | + | ||
734 | + switch (event.type()) { | ||
735 | + case TUNNEL_ADDED: | ||
736 | + // Allocate bandwidth for non-initiated, delegated LSPs with non-zero bandwidth (learned LSPs). | ||
737 | + String pceInit = tunnel.annotations().value(PCE_INIT); | ||
738 | + if (FALSE.equalsIgnoreCase(pceInit) | ||
739 | + && bwConstraintValue != 0) { | ||
740 | + reserveBandwidth(tunnel.path(), bwConstraintValue, null); | ||
741 | + } | ||
742 | + break; | ||
743 | + | ||
744 | + case TUNNEL_UPDATED: | ||
745 | + // Allocate/send labels for basic PCECC tunnels. | ||
746 | + if ((tunnel.state() == ESTABLISHED) && (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR)) { | ||
747 | + crHandler.allocateLabel(tunnel); | ||
748 | + } | ||
749 | + | ||
750 | + if (tunnel.state() == UNSTABLE) { | ||
751 | + /* | ||
752 | + * During LSP DB sync if PCC doesn't report LSP which was PCE initiated, it's state is turned into | ||
753 | + * unstable so that it can be setup again. Add into failed path store so that it can be recomputed | ||
754 | + * and setup while global reoptimization. | ||
755 | + */ | ||
756 | + | ||
757 | + List<Constraint> constraints = new LinkedList<>(); | ||
758 | + String bandwidth = tunnel.annotations().value(BANDWIDTH); | ||
759 | + if (bandwidth != null) { | ||
760 | + constraints.add(new BandwidthConstraint(Bandwidth | ||
761 | + .bps(Double.parseDouble(bandwidth)))); | ||
762 | + } | ||
763 | + | ||
764 | + String costType = tunnel.annotations().value(COST_TYPE); | ||
765 | + if (costType != null) { | ||
766 | + CostConstraint costConstraint = new CostConstraint(CostConstraint.Type.valueOf(costType)); | ||
767 | + constraints.add(costConstraint); | ||
768 | + } | ||
769 | + | ||
770 | + constraints.add(CapabilityConstraint | ||
771 | + .of(CapabilityType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)))); | ||
772 | + | ||
773 | + List<Link> links = tunnel.path().links(); | ||
774 | + pceStore.addFailedPathInfo(new PcePathInfo(links.get(0).src().deviceId(), | ||
775 | + links.get(links.size() - 1).dst().deviceId(), | ||
776 | + tunnel.tunnelName().value(), constraints, lspType)); | ||
777 | + } | ||
778 | + break; | ||
779 | + | ||
780 | + case TUNNEL_REMOVED: | ||
781 | + if (lspType != WITH_SIGNALLING) { | ||
782 | + localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID))); | ||
783 | + } | ||
784 | + | ||
785 | + // If not zero bandwidth, and delegated (initiated LSPs will also be delegated). | ||
786 | + if (bwConstraintValue != 0) { | ||
787 | + releaseBandwidth(event.subject()); | ||
788 | + | ||
789 | + // Release basic PCECC labels. | ||
790 | + if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) { | ||
791 | + // Delete stored tunnel consumer id from PCE store (while still retaining label list.) | ||
792 | + PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
793 | + pceccTunnelInfo.tunnelConsumerId(null); | ||
794 | + crHandler.releaseLabel(tunnel); | ||
795 | + } else { | ||
796 | + pceStore.removeTunnelInfo(tunnel.tunnelId()); | ||
797 | + } | ||
798 | + } | ||
799 | + break; | ||
800 | + | ||
801 | + default: | ||
802 | + break; | ||
803 | + | ||
804 | + } | ||
805 | + return; | ||
806 | + } | ||
807 | + } | ||
808 | + | ||
809 | + private boolean syncLabelDb(DeviceId deviceId) { | ||
810 | + checkNotNull(deviceId); | ||
811 | + Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels(); | ||
812 | + | ||
813 | + for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) { | ||
814 | + | ||
815 | + // Convert from DeviceId to TunnelEndPoint | ||
816 | + Device srcDevice = deviceService.getDevice(entry.getKey()); | ||
817 | + | ||
818 | + /* | ||
819 | + * If there is a slight difference in timing such that if device subsystem has removed the device but PCE | ||
820 | + * store still has it, just ignore such devices. | ||
821 | + */ | ||
822 | + if (srcDevice == null) { | ||
823 | + continue; | ||
824 | + } | ||
825 | + | ||
826 | + String srcLsrId = srcDevice.annotations().value(LSRID); | ||
827 | + if (srcLsrId == null) { | ||
828 | + continue; | ||
829 | + } | ||
830 | + | ||
831 | + srTeHandler.advertiseNodeLabelRule(deviceId, | ||
832 | + entry.getValue(), | ||
833 | + IpPrefix.valueOf(IpAddress.valueOf(srcLsrId), PREFIX_LENGTH), | ||
834 | + Objective.Operation.ADD, false); | ||
835 | + } | ||
836 | + | ||
837 | + Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels(); | ||
838 | + for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) { | ||
839 | + if (entry.getKey().src().deviceId().equals(deviceId)) { | ||
840 | + srTeHandler.installAdjLabelRule(deviceId, | ||
841 | + entry.getValue(), | ||
842 | + entry.getKey().src().port(), | ||
843 | + entry.getKey().dst().port(), | ||
844 | + Objective.Operation.ADD); | ||
845 | + } | ||
846 | + } | ||
847 | + | ||
848 | + srTeHandler.advertiseNodeLabelRule(deviceId, | ||
849 | + LabelResourceId.labelResourceId(0), | ||
850 | + IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX), | ||
851 | + Objective.Operation.ADD, true); | ||
852 | + | ||
853 | + return true; | ||
854 | + } | ||
855 | + | ||
856 | + // Process the packet received. | ||
857 | + private class PcepPacketProcessor implements PacketProcessor { | ||
858 | + // Process the packet received and in our case initiates the label DB sync. | ||
859 | + @Override | ||
860 | + public void process(PacketContext context) { | ||
861 | + // Stop processing if the packet has been handled, since we | ||
862 | + // can't do any more to it. | ||
863 | + | ||
864 | + if (context.isHandled()) { | ||
865 | + return; | ||
866 | + } | ||
867 | + | ||
868 | + InboundPacket pkt = context.inPacket(); | ||
869 | + syncLabelDb(pkt.receivedFrom().deviceId()); | ||
870 | + } | ||
871 | + } | ||
872 | + | ||
252 | } | 873 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -25,6 +25,11 @@ import java.util.LinkedList; | ... | @@ -25,6 +25,11 @@ import java.util.LinkedList; |
25 | import java.util.Map; | 25 | import java.util.Map; |
26 | import java.util.Set; | 26 | import java.util.Set; |
27 | 27 | ||
28 | +import org.onlab.packet.IpAddress; | ||
29 | +import org.onlab.packet.IpPrefix; | ||
30 | +import org.onlab.packet.MplsLabel; | ||
31 | +import org.onlab.packet.TpPort; | ||
32 | +import org.onosproject.core.ApplicationId; | ||
28 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | 33 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; |
29 | import org.onosproject.incubator.net.resource.label.LabelResource; | 34 | import org.onosproject.incubator.net.resource.label.LabelResource; |
30 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
... | @@ -36,7 +41,15 @@ import org.onosproject.net.DeviceId; | ... | @@ -36,7 +41,15 @@ import org.onosproject.net.DeviceId; |
36 | import org.onosproject.pce.pcestore.api.PceStore; | 41 | import org.onosproject.pce.pcestore.api.PceStore; |
37 | import org.onosproject.net.Link; | 42 | import org.onosproject.net.Link; |
38 | import org.onosproject.net.Path; | 43 | import org.onosproject.net.Path; |
39 | - | 44 | +import org.onosproject.net.PortNumber; |
45 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
46 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
47 | +import org.onosproject.net.flow.TrafficSelector; | ||
48 | +import org.onosproject.net.flow.TrafficTreatment; | ||
49 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
50 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
51 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
52 | +import org.onosproject.net.flowobjective.Objective; | ||
40 | import org.slf4j.Logger; | 53 | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; | 54 | import org.slf4j.LoggerFactory; |
42 | 55 | ||
... | @@ -67,7 +80,9 @@ public final class PceccSrTeBeHandler { | ... | @@ -67,7 +80,9 @@ public final class PceccSrTeBeHandler { |
67 | private static PceccSrTeBeHandler srTeHandlerInstance = null; | 80 | private static PceccSrTeBeHandler srTeHandlerInstance = null; |
68 | private LabelResourceAdminService labelRsrcAdminService; | 81 | private LabelResourceAdminService labelRsrcAdminService; |
69 | private LabelResourceService labelRsrcService; | 82 | private LabelResourceService labelRsrcService; |
83 | + private FlowObjectiveService flowObjectiveService; | ||
70 | private PceStore pceStore; | 84 | private PceStore pceStore; |
85 | + private ApplicationId appId; | ||
71 | 86 | ||
72 | /** | 87 | /** |
73 | * Initializes default values. | 88 | * Initializes default values. |
... | @@ -95,10 +110,14 @@ public final class PceccSrTeBeHandler { | ... | @@ -95,10 +110,14 @@ public final class PceccSrTeBeHandler { |
95 | * @param pceStore PCE label store | 110 | * @param pceStore PCE label store |
96 | */ | 111 | */ |
97 | public void initialize(LabelResourceAdminService labelRsrcAdminService, | 112 | public void initialize(LabelResourceAdminService labelRsrcAdminService, |
98 | - LabelResourceService labelRsrcService, PceStore pceStore) { | 113 | + LabelResourceService labelRsrcService, |
114 | + FlowObjectiveService flowObjectiveService, | ||
115 | + ApplicationId appId, PceStore pceStore) { | ||
99 | this.labelRsrcAdminService = labelRsrcAdminService; | 116 | this.labelRsrcAdminService = labelRsrcAdminService; |
100 | this.labelRsrcService = labelRsrcService; | 117 | this.labelRsrcService = labelRsrcService; |
118 | + this.flowObjectiveService = flowObjectiveService; | ||
101 | this.pceStore = pceStore; | 119 | this.pceStore = pceStore; |
120 | + this.appId = appId; | ||
102 | } | 121 | } |
103 | 122 | ||
104 | /** | 123 | /** |
... | @@ -152,15 +171,15 @@ public final class PceccSrTeBeHandler { | ... | @@ -152,15 +171,15 @@ public final class PceccSrTeBeHandler { |
152 | } | 171 | } |
153 | 172 | ||
154 | pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); | 173 | pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); |
155 | - //TODO: uncomment below line once advertiseNodeLabelRule() is ready | ||
156 | // Push its label information into specificDeviceId | 174 | // Push its label information into specificDeviceId |
157 | - //advertiseNodeLabelRule(specificDeviceId, specificLabelId, | 175 | + advertiseNodeLabelRule(specificDeviceId, specificLabelId, |
158 | - // IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), | 176 | + IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), |
177 | + Objective.Operation.ADD, false); | ||
159 | 178 | ||
160 | // Configure (node-label, lsr-id) mapping of each devices in list to specific device and vice versa. | 179 | // Configure (node-label, lsr-id) mapping of each devices in list to specific device and vice versa. |
161 | - for (Map.Entry element:deviceIdLsrIdMap.entrySet()) { | 180 | + for (Map.Entry<DeviceId, String> element:deviceIdLsrIdMap.entrySet()) { |
162 | - DeviceId otherDevId = (DeviceId) element.getKey(); | 181 | + DeviceId otherDevId = element.getKey(); |
163 | - String otherLsrId = (String) element.getValue(); | 182 | + String otherLsrId = element.getValue(); |
164 | if (otherLsrId == null) { | 183 | if (otherLsrId == null) { |
165 | log.error("The lsr-id of device id {} is null.", otherDevId.toString()); | 184 | log.error("The lsr-id of device id {} is null.", otherDevId.toString()); |
166 | releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap); | 185 | releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap); |
... | @@ -176,12 +195,11 @@ public final class PceccSrTeBeHandler { | ... | @@ -176,12 +195,11 @@ public final class PceccSrTeBeHandler { |
176 | } | 195 | } |
177 | 196 | ||
178 | // Push to device | 197 | // Push to device |
179 | - // TODO: uncomment below line once advertiseNodeLabelRule() is ready | ||
180 | // Push label information of specificDeviceId to otherDevId in list and vice versa. | 198 | // Push label information of specificDeviceId to otherDevId in list and vice versa. |
181 | - //advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), | 199 | + advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), |
182 | - // PREFIX_LENGTH), Objective.Operation.ADD); | 200 | + PREFIX_LENGTH), Objective.Operation.ADD, false); |
183 | - //advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), | 201 | + advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), |
184 | - // PREFIX_LENGTH), Objective.Operation.ADD); | 202 | + PREFIX_LENGTH), Objective.Operation.ADD, false); |
185 | } | 203 | } |
186 | 204 | ||
187 | return true; | 205 | return true; |
... | @@ -214,15 +232,14 @@ public final class PceccSrTeBeHandler { | ... | @@ -214,15 +232,14 @@ public final class PceccSrTeBeHandler { |
214 | } | 232 | } |
215 | 233 | ||
216 | // Go through all devices in the map and remove label entry | 234 | // Go through all devices in the map and remove label entry |
217 | - for (Map.Entry element:deviceIdLsrIdMap.entrySet()) { | 235 | + for (Map.Entry<DeviceId, String> element:deviceIdLsrIdMap.entrySet()) { |
218 | - DeviceId otherDevId = (DeviceId) element.getKey(); | 236 | + DeviceId otherDevId = element.getKey(); |
219 | 237 | ||
220 | // Remove this specific device label information from all other nodes except | 238 | // Remove this specific device label information from all other nodes except |
221 | // this specific node where connection already lost. | 239 | // this specific node where connection already lost. |
222 | if (!specificDeviceId.equals(otherDevId)) { | 240 | if (!specificDeviceId.equals(otherDevId)) { |
223 | - //TODO: uncomment below lines once advertiseNodeLabelRule() is ready | 241 | + advertiseNodeLabelRule(otherDevId, labelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), |
224 | - //advertiseNodeLabelRule(otherDevId, labelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), | 242 | + PREFIX_LENGTH), Objective.Operation.REMOVE, false); |
225 | - // PREFIX_LENGTH), Objective.Operation.REMOVE); | ||
226 | } | 243 | } |
227 | } | 244 | } |
228 | 245 | ||
... | @@ -278,8 +295,7 @@ public final class PceccSrTeBeHandler { | ... | @@ -278,8 +295,7 @@ public final class PceccSrTeBeHandler { |
278 | link.toString()); | 295 | link.toString()); |
279 | 296 | ||
280 | // Push adjacency label to device | 297 | // Push adjacency label to device |
281 | - //TODO: uncomment below line once installAdjLabelRule() method is ready | 298 | + installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); |
282 | - //installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); | ||
283 | 299 | ||
284 | // Save in store | 300 | // Save in store |
285 | pceStore.addAdjLabel(link, labelId); | 301 | pceStore.addAdjLabel(link, labelId); |
... | @@ -309,8 +325,7 @@ public final class PceccSrTeBeHandler { | ... | @@ -309,8 +325,7 @@ public final class PceccSrTeBeHandler { |
309 | DeviceId srcDeviceId = link.src().deviceId(); | 325 | DeviceId srcDeviceId = link.src().deviceId(); |
310 | 326 | ||
311 | // Release adjacency label from device | 327 | // Release adjacency label from device |
312 | - //TODO: uncomment below line once installAdjLabelRule() method is ready | 328 | + installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE); |
313 | - //installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE); | ||
314 | 329 | ||
315 | // Release link label from label manager | 330 | // Release link label from label manager |
316 | Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | 331 | Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); |
... | @@ -350,7 +365,7 @@ public final class PceccSrTeBeHandler { | ... | @@ -350,7 +365,7 @@ public final class PceccSrTeBeHandler { |
350 | LabelResourceId adjLabelId = null; | 365 | LabelResourceId adjLabelId = null; |
351 | DeviceId deviceId = null; | 366 | DeviceId deviceId = null; |
352 | for (Iterator<Link> iterator = linkList.iterator(); iterator.hasNext();) { | 367 | for (Iterator<Link> iterator = linkList.iterator(); iterator.hasNext();) { |
353 | - link = (Link) iterator.next(); | 368 | + link = iterator.next(); |
354 | // Add source device label now | 369 | // Add source device label now |
355 | deviceId = link.src().deviceId(); | 370 | deviceId = link.src().deviceId(); |
356 | nodeLabelId = pceStore.getGlobalNodeLabel(deviceId); | 371 | nodeLabelId = pceStore.getGlobalNodeLabel(deviceId); |
... | @@ -386,4 +401,109 @@ public final class PceccSrTeBeHandler { | ... | @@ -386,4 +401,109 @@ public final class PceccSrTeBeHandler { |
386 | } | 401 | } |
387 | return new DefaultLabelStack(labelStack); | 402 | return new DefaultLabelStack(labelStack); |
388 | } | 403 | } |
404 | + | ||
405 | + /** | ||
406 | + * Install a rule for pushing unique global labels to the device. | ||
407 | + * @param deviceId device to which flow should be pushed | ||
408 | + * @param labelId label for the device | ||
409 | + * @param type type of operation | ||
410 | + */ | ||
411 | + private void installNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, Objective.Operation type) { | ||
412 | + checkNotNull(flowObjectiveService); | ||
413 | + checkNotNull(appId); | ||
414 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
415 | + | ||
416 | + selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
417 | + | ||
418 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
419 | + .build(); | ||
420 | + | ||
421 | + ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
422 | + .withSelector(selectorBuilder.build()) | ||
423 | + .withTreatment(treatment) | ||
424 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
425 | + .fromApp(appId) | ||
426 | + .makePermanent(); | ||
427 | + | ||
428 | + if (type.equals(Objective.Operation.ADD)) { | ||
429 | + | ||
430 | + flowObjectiveService.forward(deviceId, forwardingObjective.add()); | ||
431 | + } else { | ||
432 | + flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | ||
433 | + } | ||
434 | + } | ||
435 | + | ||
436 | + /** | ||
437 | + * Install a rule for pushing node labels to the device of other nodes. | ||
438 | + * @param deviceId device to which flow should be pushed | ||
439 | + * @param labelId label for the device | ||
440 | + * @param ipPrefix device for which label is pushed | ||
441 | + * @param type type of operation | ||
442 | + * @param bBos is this the end of sync push | ||
443 | + */ | ||
444 | + public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, | ||
445 | + IpPrefix ipPrefix, Objective.Operation type, boolean bBos) { | ||
446 | + checkNotNull(flowObjectiveService); | ||
447 | + checkNotNull(appId); | ||
448 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
449 | + | ||
450 | + selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
451 | + selectorBuilder.matchIPSrc(ipPrefix); | ||
452 | + | ||
453 | + if (bBos) { | ||
454 | + selectorBuilder.matchMplsBos(bBos); | ||
455 | + } | ||
456 | + | ||
457 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
458 | + .build(); | ||
459 | + | ||
460 | + ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
461 | + .withSelector(selectorBuilder.build()) | ||
462 | + .withTreatment(treatment) | ||
463 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
464 | + .fromApp(appId) | ||
465 | + .makePermanent(); | ||
466 | + | ||
467 | + if (type.equals(Objective.Operation.ADD)) { | ||
468 | + flowObjectiveService.forward(deviceId, forwardingObjective.add()); | ||
469 | + } else { | ||
470 | + flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | ||
471 | + } | ||
472 | + } | ||
473 | + | ||
474 | + /** | ||
475 | + * Install a rule for pushing Adjacency labels to the device. | ||
476 | + * @param deviceId device to which flow should be pushed | ||
477 | + * @param labelId label for the adjacency | ||
478 | + * @param srcPortNum local port of the adjacency | ||
479 | + * @param dstPortNum remote port of the adjacency | ||
480 | + * @param type type of operation | ||
481 | + */ | ||
482 | + public void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, | ||
483 | + PortNumber srcPortNum, PortNumber dstPortNum, | ||
484 | + Objective.Operation type) { | ||
485 | + checkNotNull(flowObjectiveService); | ||
486 | + checkNotNull(appId); | ||
487 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
488 | + | ||
489 | + selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
490 | + selectorBuilder.matchTcpSrc(TpPort.tpPort((int) srcPortNum.toLong())); | ||
491 | + selectorBuilder.matchTcpDst(TpPort.tpPort((int) dstPortNum.toLong())); | ||
492 | + | ||
493 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
494 | + .build(); | ||
495 | + | ||
496 | + ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
497 | + .withSelector(selectorBuilder.build()) | ||
498 | + .withTreatment(treatment) | ||
499 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
500 | + .fromApp(appId) | ||
501 | + .makePermanent(); | ||
502 | + | ||
503 | + if (type.equals(Objective.Operation.ADD)) { | ||
504 | + flowObjectiveService.forward(deviceId, forwardingObjective.add()); | ||
505 | + } else { | ||
506 | + flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | ||
507 | + } | ||
508 | + } | ||
389 | } | 509 | } | ... | ... |
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.pceservice; | ||
17 | + | ||
18 | +/** | ||
19 | + * Collection of keys for annotation for PCEP tunnels. | ||
20 | + */ | ||
21 | +public final class PcepAnnotationKeys { | ||
22 | + | ||
23 | + /** | ||
24 | + * Prohibits instantiation. | ||
25 | + */ | ||
26 | + private PcepAnnotationKeys() { | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * Annotation key for bandwidth. | ||
31 | + * The value for this key is interpreted as Mbps. | ||
32 | + */ | ||
33 | + public static final String BANDWIDTH = "bandwidth"; | ||
34 | + | ||
35 | + /** | ||
36 | + * Annotation key for the LSP signaling type. | ||
37 | + */ | ||
38 | + public static final String LSP_SIG_TYPE = "lspSigType"; | ||
39 | + | ||
40 | + /** | ||
41 | + * Annotation key for the PCC tunnel id. | ||
42 | + */ | ||
43 | + public static final String PCC_TUNNEL_ID = "PccTunnelId"; | ||
44 | + | ||
45 | + /** | ||
46 | + * Annotation key for the LSP id assigned per tunnel per session. | ||
47 | + */ | ||
48 | + public static final String PLSP_ID = "PLspId"; | ||
49 | + | ||
50 | + /** | ||
51 | + * Annotation key for the LSP id assigned per tunnel. | ||
52 | + */ | ||
53 | + public static final String LOCAL_LSP_ID = "localLspId"; | ||
54 | + | ||
55 | + /** | ||
56 | + * Annotation key for the identification of initiated LSP. | ||
57 | + */ | ||
58 | + public static final String PCE_INIT = "pceInit"; | ||
59 | + | ||
60 | + /** | ||
61 | + * Annotation key for the cost type. | ||
62 | + */ | ||
63 | + public static final String COST_TYPE = "costType"; | ||
64 | + | ||
65 | + /** | ||
66 | + * Annotation key for the Delegation. | ||
67 | + * Whether LSPs are delegated or not. | ||
68 | + */ | ||
69 | + public static final String DELEGATE = "delegate"; | ||
70 | +} |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.pce.pceservice; | 16 | package org.onosproject.pce.pceservice; |
17 | 17 | ||
18 | +import org.onlab.util.Identifier; | ||
18 | import org.onosproject.net.resource.ResourceConsumer; | 19 | import org.onosproject.net.resource.ResourceConsumer; |
19 | 20 | ||
20 | import com.google.common.annotations.Beta; | 21 | import com.google.common.annotations.Beta; |
... | @@ -25,9 +26,7 @@ import org.onosproject.net.resource.ResourceConsumerId; | ... | @@ -25,9 +26,7 @@ import org.onosproject.net.resource.ResourceConsumerId; |
25 | * resource allocations. | 26 | * resource allocations. |
26 | */ | 27 | */ |
27 | @Beta | 28 | @Beta |
28 | -public final class TunnelConsumerId implements ResourceConsumer { | 29 | +public final class TunnelConsumerId extends Identifier<Long> implements ResourceConsumer { |
29 | - | ||
30 | - private final long value; | ||
31 | 30 | ||
32 | /** | 31 | /** |
33 | * Creates a tunnel resource consumer identifier from the specified long value. | 32 | * Creates a tunnel resource consumer identifier from the specified long value. |
... | @@ -43,7 +42,7 @@ public final class TunnelConsumerId implements ResourceConsumer { | ... | @@ -43,7 +42,7 @@ public final class TunnelConsumerId implements ResourceConsumer { |
43 | * Initializes object for serializer. | 42 | * Initializes object for serializer. |
44 | */ | 43 | */ |
45 | public TunnelConsumerId() { | 44 | public TunnelConsumerId() { |
46 | - this.value = 0; | 45 | + super(0L); |
47 | } | 46 | } |
48 | 47 | ||
49 | /** | 48 | /** |
... | @@ -54,43 +53,25 @@ public final class TunnelConsumerId implements ResourceConsumer { | ... | @@ -54,43 +53,25 @@ public final class TunnelConsumerId implements ResourceConsumer { |
54 | * resource consumer id | 53 | * resource consumer id |
55 | */ | 54 | */ |
56 | public TunnelConsumerId(long value) { | 55 | public TunnelConsumerId(long value) { |
57 | - this.value = value; | 56 | + super(value); |
58 | } | 57 | } |
59 | 58 | ||
60 | /** | 59 | /** |
61 | - * Returns the tunnel resource consumer id value in long format. | 60 | + * Returns the backing identifier value. |
62 | * | 61 | * |
63 | - * @return value the tunnel resource consumer id's long value | 62 | + * @return value backing identifier value |
64 | */ | 63 | */ |
65 | public long value() { | 64 | public long value() { |
66 | - return value; | 65 | + return identifier; |
67 | - } | ||
68 | - | ||
69 | - @Override | ||
70 | - public int hashCode() { | ||
71 | - return Long.hashCode(value); | ||
72 | - } | ||
73 | - | ||
74 | - @Override | ||
75 | - public boolean equals(Object obj) { | ||
76 | - if (obj == this) { | ||
77 | - return true; | ||
78 | - } | ||
79 | - if (!(obj instanceof TunnelConsumerId)) { | ||
80 | - return false; | ||
81 | - } | ||
82 | - TunnelConsumerId that = (TunnelConsumerId) obj; | ||
83 | - return this.value == that.value; | ||
84 | } | 66 | } |
85 | 67 | ||
86 | @Override | 68 | @Override |
87 | public String toString() { | 69 | public String toString() { |
88 | - return "0x" + Long.toHexString(value); | 70 | + return "0x" + Long.toHexString(identifier); |
89 | } | 71 | } |
90 | 72 | ||
91 | @Override | 73 | @Override |
92 | public ResourceConsumerId consumerId() { | 74 | public ResourceConsumerId consumerId() { |
93 | - // TODO | 75 | + return ResourceConsumerId.of(this); |
94 | - return null; | ||
95 | } | 76 | } |
96 | } | 77 | } | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. | ... | ... |
... | @@ -31,6 +31,8 @@ import org.junit.Before; | ... | @@ -31,6 +31,8 @@ import org.junit.Before; |
31 | import org.junit.Test; | 31 | import org.junit.Test; |
32 | 32 | ||
33 | import org.onlab.packet.IpAddress; | 33 | import org.onlab.packet.IpAddress; |
34 | +import org.onosproject.core.ApplicationId; | ||
35 | +import org.onosproject.core.CoreService; | ||
34 | import org.onosproject.core.DefaultGroupId; | 36 | import org.onosproject.core.DefaultGroupId; |
35 | import org.onosproject.incubator.net.tunnel.Tunnel; | 37 | import org.onosproject.incubator.net.tunnel.Tunnel; |
36 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | 38 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
... | @@ -45,11 +47,11 @@ import org.onosproject.net.DefaultAnnotations; | ... | @@ -45,11 +47,11 @@ import org.onosproject.net.DefaultAnnotations; |
45 | import org.onosproject.net.DefaultPath; | 47 | import org.onosproject.net.DefaultPath; |
46 | import org.onosproject.net.DeviceId; | 48 | import org.onosproject.net.DeviceId; |
47 | import org.onosproject.net.PortNumber; | 49 | import org.onosproject.net.PortNumber; |
50 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
48 | import org.onosproject.net.Path; | 51 | import org.onosproject.net.Path; |
49 | import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | 52 | import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; |
50 | import org.onosproject.pce.pcestore.api.PceStore; | 53 | import org.onosproject.pce.pcestore.api.PceStore; |
51 | import org.onosproject.pce.pcestore.PceccTunnelInfo; | 54 | import org.onosproject.pce.pcestore.PceccTunnelInfo; |
52 | -import org.onosproject.pce.pcestore.DefaultLspLocalLabelInfo; | ||
53 | import org.onosproject.net.provider.ProviderId; | 55 | import org.onosproject.net.provider.ProviderId; |
54 | import org.onosproject.pce.util.LabelResourceAdapter; | 56 | import org.onosproject.pce.util.LabelResourceAdapter; |
55 | import org.onosproject.pce.util.PceStoreAdapter; | 57 | import org.onosproject.pce.util.PceStoreAdapter; |
... | @@ -67,6 +69,9 @@ public class BasicPceccHandlerTest { | ... | @@ -67,6 +69,9 @@ public class BasicPceccHandlerTest { |
67 | private BasicPceccHandler pceccHandler; | 69 | private BasicPceccHandler pceccHandler; |
68 | protected LabelResourceService labelRsrcService; | 70 | protected LabelResourceService labelRsrcService; |
69 | protected PceStore pceStore; | 71 | protected PceStore pceStore; |
72 | + private FlowObjectiveService flowObjectiveService; | ||
73 | + private CoreService coreService; | ||
74 | + private ApplicationId appId; | ||
70 | private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423)); | 75 | private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423)); |
71 | private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); | 76 | private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); |
72 | private DefaultGroupId groupId = new DefaultGroupId(92034); | 77 | private DefaultGroupId groupId = new DefaultGroupId(92034); |
... | @@ -92,7 +97,10 @@ public class BasicPceccHandlerTest { | ... | @@ -92,7 +97,10 @@ public class BasicPceccHandlerTest { |
92 | pceccHandler = BasicPceccHandler.getInstance(); | 97 | pceccHandler = BasicPceccHandler.getInstance(); |
93 | labelRsrcService = new LabelResourceAdapter(); | 98 | labelRsrcService = new LabelResourceAdapter(); |
94 | pceStore = new PceStoreAdapter(); | 99 | pceStore = new PceStoreAdapter(); |
95 | - pceccHandler.initialize(labelRsrcService, pceStore); | 100 | + flowObjectiveService = new PceManagerTest.MockFlowObjService(); |
101 | + coreService = new PceManagerTest.MockCoreService(); | ||
102 | + appId = coreService.registerApplication("org.onosproject.pce"); | ||
103 | + pceccHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore); | ||
96 | 104 | ||
97 | // Cretae tunnel test | 105 | // Cretae tunnel test |
98 | // Link | 106 | // Link |
... | @@ -190,7 +198,7 @@ public class BasicPceccHandlerTest { | ... | @@ -190,7 +198,7 @@ public class BasicPceccHandlerTest { |
190 | iterator = lspLocalLabelInfoList.iterator(); | 198 | iterator = lspLocalLabelInfoList.iterator(); |
191 | 199 | ||
192 | // Retrieve values and check device5 | 200 | // Retrieve values and check device5 |
193 | - lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 201 | + lspLocalLabelInfo = iterator.next(); |
194 | deviceId = lspLocalLabelInfo.deviceId(); | 202 | deviceId = lspLocalLabelInfo.deviceId(); |
195 | inLabelId = lspLocalLabelInfo.inLabelId(); | 203 | inLabelId = lspLocalLabelInfo.inLabelId(); |
196 | outLabelId = lspLocalLabelInfo.outLabelId(); | 204 | outLabelId = lspLocalLabelInfo.outLabelId(); |
... | @@ -205,7 +213,7 @@ public class BasicPceccHandlerTest { | ... | @@ -205,7 +213,7 @@ public class BasicPceccHandlerTest { |
205 | 213 | ||
206 | // Next element check | 214 | // Next element check |
207 | // Retrieve values and check device4 | 215 | // Retrieve values and check device4 |
208 | - lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 216 | + lspLocalLabelInfo = iterator.next(); |
209 | deviceId = lspLocalLabelInfo.deviceId(); | 217 | deviceId = lspLocalLabelInfo.deviceId(); |
210 | inLabelId = lspLocalLabelInfo.inLabelId(); | 218 | inLabelId = lspLocalLabelInfo.inLabelId(); |
211 | outLabelId = lspLocalLabelInfo.outLabelId(); | 219 | outLabelId = lspLocalLabelInfo.outLabelId(); |
... | @@ -220,7 +228,7 @@ public class BasicPceccHandlerTest { | ... | @@ -220,7 +228,7 @@ public class BasicPceccHandlerTest { |
220 | 228 | ||
221 | // Next element check | 229 | // Next element check |
222 | // Retrieve values and check device3 | 230 | // Retrieve values and check device3 |
223 | - lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 231 | + lspLocalLabelInfo = iterator.next(); |
224 | deviceId = lspLocalLabelInfo.deviceId(); | 232 | deviceId = lspLocalLabelInfo.deviceId(); |
225 | inLabelId = lspLocalLabelInfo.inLabelId(); | 233 | inLabelId = lspLocalLabelInfo.inLabelId(); |
226 | outLabelId = lspLocalLabelInfo.outLabelId(); | 234 | outLabelId = lspLocalLabelInfo.outLabelId(); |
... | @@ -235,7 +243,7 @@ public class BasicPceccHandlerTest { | ... | @@ -235,7 +243,7 @@ public class BasicPceccHandlerTest { |
235 | 243 | ||
236 | // Next element check | 244 | // Next element check |
237 | // Retrieve values and check device2 | 245 | // Retrieve values and check device2 |
238 | - lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 246 | + lspLocalLabelInfo = iterator.next(); |
239 | deviceId = lspLocalLabelInfo.deviceId(); | 247 | deviceId = lspLocalLabelInfo.deviceId(); |
240 | inLabelId = lspLocalLabelInfo.inLabelId(); | 248 | inLabelId = lspLocalLabelInfo.inLabelId(); |
241 | outLabelId = lspLocalLabelInfo.outLabelId(); | 249 | outLabelId = lspLocalLabelInfo.outLabelId(); |
... | @@ -250,7 +258,7 @@ public class BasicPceccHandlerTest { | ... | @@ -250,7 +258,7 @@ public class BasicPceccHandlerTest { |
250 | 258 | ||
251 | // Next element check | 259 | // Next element check |
252 | // Retrieve values and check device1 | 260 | // Retrieve values and check device1 |
253 | - lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | 261 | + lspLocalLabelInfo = iterator.next(); |
254 | deviceId = lspLocalLabelInfo.deviceId(); | 262 | deviceId = lspLocalLabelInfo.deviceId(); |
255 | inLabelId = lspLocalLabelInfo.inLabelId(); | 263 | inLabelId = lspLocalLabelInfo.inLabelId(); |
256 | outLabelId = lspLocalLabelInfo.outLabelId(); | 264 | outLabelId = lspLocalLabelInfo.outLabelId(); | ... | ... |
... | @@ -96,20 +96,20 @@ public class PathComputationTest { | ... | @@ -96,20 +96,20 @@ public class PathComputationTest { |
96 | private final MockDeviceService deviceService = new MockDeviceService(); | 96 | private final MockDeviceService deviceService = new MockDeviceService(); |
97 | private PceManager pceManager = new PceManager(); | 97 | private PceManager pceManager = new PceManager(); |
98 | public static ProviderId providerId = new ProviderId("pce", "foo"); | 98 | public static ProviderId providerId = new ProviderId("pce", "foo"); |
99 | - private static final String DEVICE1 = "D001"; | 99 | + public static final String DEVICE1 = "D001"; |
100 | - private static final String DEVICE2 = "D002"; | 100 | + public static final String DEVICE2 = "D002"; |
101 | - private static final String DEVICE3 = "D003"; | 101 | + public static final String DEVICE3 = "D003"; |
102 | - private static final String DEVICE4 = "D004"; | 102 | + public static final String DEVICE4 = "D004"; |
103 | - private static final String DEVICE5 = "D005"; | 103 | + public static final String DEVICE5 = "D005"; |
104 | public static final String PCEPDEVICE1 = "PD001"; | 104 | public static final String PCEPDEVICE1 = "PD001"; |
105 | public static final String PCEPDEVICE2 = "PD002"; | 105 | public static final String PCEPDEVICE2 = "PD002"; |
106 | public static final String PCEPDEVICE3 = "PD003"; | 106 | public static final String PCEPDEVICE3 = "PD003"; |
107 | public static final String PCEPDEVICE4 = "PD004"; | 107 | public static final String PCEPDEVICE4 = "PD004"; |
108 | - private static final TopologyVertex D1 = new DefaultTopologyVertex(DeviceId.deviceId("D001")); | 108 | + public static final TopologyVertex D1 = new DefaultTopologyVertex(DeviceId.deviceId("D001")); |
109 | - private static final TopologyVertex D2 = new DefaultTopologyVertex(DeviceId.deviceId("D002")); | 109 | + public static final TopologyVertex D2 = new DefaultTopologyVertex(DeviceId.deviceId("D002")); |
110 | - private static final TopologyVertex D3 = new DefaultTopologyVertex(DeviceId.deviceId("D003")); | 110 | + public static final TopologyVertex D3 = new DefaultTopologyVertex(DeviceId.deviceId("D003")); |
111 | - private static final TopologyVertex D4 = new DefaultTopologyVertex(DeviceId.deviceId("D004")); | 111 | + public static final TopologyVertex D4 = new DefaultTopologyVertex(DeviceId.deviceId("D004")); |
112 | - private static final TopologyVertex D5 = new DefaultTopologyVertex(DeviceId.deviceId("D005")); | 112 | + public static final TopologyVertex D5 = new DefaultTopologyVertex(DeviceId.deviceId("D005")); |
113 | private static final String ANNOTATION_COST = "cost"; | 113 | private static final String ANNOTATION_COST = "cost"; |
114 | private static final String ANNOTATION_TE_COST = "teCost"; | 114 | private static final String ANNOTATION_TE_COST = "teCost"; |
115 | private static final String UNKNOWN = "unknown"; | 115 | private static final String UNKNOWN = "unknown"; |
... | @@ -130,7 +130,7 @@ public class PathComputationTest { | ... | @@ -130,7 +130,7 @@ public class PathComputationTest { |
130 | * | 130 | * |
131 | * @return graph path search algorithm | 131 | * @return graph path search algorithm |
132 | */ | 132 | */ |
133 | - private AbstractGraphPathSearch<TopologyVertex, TopologyEdge> graphSearch() { | 133 | + public static AbstractGraphPathSearch<TopologyVertex, TopologyEdge> graphSearch() { |
134 | return new DijkstraGraphSearch<>(); | 134 | return new DijkstraGraphSearch<>(); |
135 | } | 135 | } |
136 | 136 | ||
... | @@ -143,7 +143,7 @@ public class PathComputationTest { | ... | @@ -143,7 +143,7 @@ public class PathComputationTest { |
143 | * @param port2 destination port | 143 | * @param port2 destination port |
144 | * @return link | 144 | * @return link |
145 | */ | 145 | */ |
146 | - private Link addLink(String device, long port, String device2, long port2, boolean setCost, int value) { | 146 | + public static Link addLink(String device, long port, String device2, long port2, boolean setCost, int value) { |
147 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(device), PortNumber.portNumber(port)); | 147 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(device), PortNumber.portNumber(port)); |
148 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(device2), PortNumber.portNumber(port2)); | 148 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(device2), PortNumber.portNumber(port2)); |
149 | Link curLink; | 149 | Link curLink; |
... | @@ -256,19 +256,37 @@ public class PathComputationTest { | ... | @@ -256,19 +256,37 @@ public class PathComputationTest { |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | - private Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { | 259 | + /** |
260 | + * Returns the path in Path object format. | ||
261 | + */ | ||
262 | + public static Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { | ||
260 | List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList()); | 263 | List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList()); |
261 | return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); | 264 | return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); |
262 | } | 265 | } |
263 | 266 | ||
264 | /** | 267 | /** |
265 | - * Test Resource service for path computation. | 268 | + * Tests Resource service for path computation. |
266 | */ | 269 | */ |
267 | - private class MockPathResourceService extends ResourceServiceAdapter { | 270 | + public class MockPathResourceService extends ResourceServiceAdapter { |
268 | private final Map<Resource, ResourceConsumer> assignment = new HashMap<>(); | 271 | private final Map<Resource, ResourceConsumer> assignment = new HashMap<>(); |
269 | private Map<ResourceId, List<ResourceAllocation>> resourcesAllocations = new HashMap<>(); | 272 | private Map<ResourceId, List<ResourceAllocation>> resourcesAllocations = new HashMap<>(); |
270 | 273 | ||
271 | @Override | 274 | @Override |
275 | + public Optional<ResourceAllocation> allocate(ResourceConsumer consumer, Resource resources) { | ||
276 | + List<ResourceAllocation> allocations = allocate(consumer, ImmutableList.of(resources)); | ||
277 | + if (allocations.isEmpty()) { | ||
278 | + return Optional.empty(); | ||
279 | + } | ||
280 | + | ||
281 | + assert allocations.size() == 1; | ||
282 | + ResourceAllocation allocation = allocations.get(0); | ||
283 | + assert allocation.resource().equals(resources); | ||
284 | + | ||
285 | + // cast is ensured by the assertions above | ||
286 | + return Optional.of(allocation); | ||
287 | + } | ||
288 | + | ||
289 | + @Override | ||
272 | public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) { | 290 | public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) { |
273 | for (Resource resource: resources) { | 291 | for (Resource resource: resources) { |
274 | if (resource instanceof ContinuousResource) { | 292 | if (resource instanceof ContinuousResource) { | ... | ... |
1 | +package org.onosproject.pce.pceservice; | ||
2 | + | ||
3 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
4 | +import static org.hamcrest.core.Is.is; | ||
5 | +import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | ||
6 | +import static org.onosproject.net.Link.State.ACTIVE; | ||
7 | +import static org.onosproject.net.Link.Type.DIRECT; | ||
8 | +import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; | ||
9 | +import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; | ||
10 | +import static org.onosproject.net.resource.Resources.continuous; | ||
11 | +import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; | ||
12 | +import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; | ||
13 | +import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; | ||
14 | +import static org.onosproject.pce.pceservice.PathComputationTest.D1; | ||
15 | +import static org.onosproject.pce.pceservice.PathComputationTest.D2; | ||
16 | +import static org.onosproject.pce.pceservice.PathComputationTest.D3; | ||
17 | +import static org.onosproject.pce.pceservice.PathComputationTest.D4; | ||
18 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; | ||
19 | +import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; | ||
20 | +import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; | ||
21 | +import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; | ||
22 | + | ||
23 | +import java.net.URISyntaxException; | ||
24 | +import java.nio.ByteBuffer; | ||
25 | +import java.util.Collection; | ||
26 | +import java.util.Collections; | ||
27 | +import java.util.HashMap; | ||
28 | +import java.util.HashSet; | ||
29 | +import java.util.LinkedList; | ||
30 | +import java.util.List; | ||
31 | +import java.util.Set; | ||
32 | +import java.util.concurrent.atomic.AtomicLong; | ||
33 | + | ||
34 | +import org.junit.After; | ||
35 | +import org.junit.Before; | ||
36 | +import org.junit.Test; | ||
37 | +import org.onlab.graph.GraphPathSearch; | ||
38 | +import org.onlab.packet.Ethernet; | ||
39 | +import org.onlab.packet.IPv4; | ||
40 | +import org.onlab.util.Bandwidth; | ||
41 | +import org.onosproject.common.DefaultTopologyGraph; | ||
42 | +import org.onosproject.core.ApplicationId; | ||
43 | +import org.onosproject.core.CoreServiceAdapter; | ||
44 | +import org.onosproject.core.DefaultApplicationId; | ||
45 | +import org.onosproject.core.IdGenerator; | ||
46 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
47 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
48 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
49 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
50 | +import org.onosproject.incubator.net.tunnel.Tunnel.State; | ||
51 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
52 | +import org.onosproject.incubator.net.tunnel.TunnelEvent; | ||
53 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
54 | +import org.onosproject.incubator.net.tunnel.TunnelListener; | ||
55 | +import org.onosproject.net.AnnotationKeys; | ||
56 | +import org.onosproject.net.Annotations; | ||
57 | +import org.onosproject.net.ConnectPoint; | ||
58 | +import org.onosproject.net.DefaultAnnotations; | ||
59 | +import org.onosproject.net.DefaultDevice; | ||
60 | +import org.onosproject.net.DefaultLink; | ||
61 | +import org.onosproject.net.Device; | ||
62 | +import org.onosproject.net.DefaultAnnotations.Builder; | ||
63 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
64 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
65 | +import org.onosproject.net.DeviceId; | ||
66 | +import org.onosproject.net.ElementId; | ||
67 | +import org.onosproject.net.Link; | ||
68 | +import org.onosproject.net.Path; | ||
69 | +import org.onosproject.net.PortNumber; | ||
70 | +import org.onosproject.net.SparseAnnotations; | ||
71 | +import org.onosproject.net.intent.Constraint; | ||
72 | +import org.onosproject.net.intent.IntentId; | ||
73 | +import org.onosproject.net.intent.constraint.BandwidthConstraint; | ||
74 | +import org.onosproject.net.packet.DefaultInboundPacket; | ||
75 | +import org.onosproject.net.packet.DefaultPacketContext; | ||
76 | +import org.onosproject.net.packet.InboundPacket; | ||
77 | +import org.onosproject.net.packet.OutboundPacket; | ||
78 | +import org.onosproject.net.packet.PacketProcessor; | ||
79 | +import org.onosproject.net.packet.PacketService; | ||
80 | +import org.onosproject.net.packet.PacketServiceAdapter; | ||
81 | +import org.onosproject.net.provider.ProviderId; | ||
82 | +import org.onosproject.net.resource.Resource; | ||
83 | +import org.onosproject.net.topology.DefaultTopologyEdge; | ||
84 | +import org.onosproject.net.topology.DefaultTopologyVertex; | ||
85 | +import org.onosproject.net.topology.LinkWeight; | ||
86 | +import org.onosproject.net.topology.PathServiceAdapter; | ||
87 | +import org.onosproject.net.topology.Topology; | ||
88 | +import org.onosproject.net.topology.TopologyEdge; | ||
89 | +import org.onosproject.net.topology.TopologyGraph; | ||
90 | +import org.onosproject.net.topology.TopologyServiceAdapter; | ||
91 | +import org.onosproject.net.topology.TopologyVertex; | ||
92 | +import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; | ||
93 | +import org.onosproject.pce.pceservice.constraint.CostConstraint; | ||
94 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
95 | +import org.onosproject.pce.util.LabelResourceAdapter; | ||
96 | +import org.onosproject.pce.util.PceStoreAdapter; | ||
97 | +import org.onosproject.pce.util.TunnelServiceAdapter; | ||
98 | +import org.onosproject.pce.util.FlowObjServiceAdapter; | ||
99 | +import org.onosproject.store.service.TestStorageService; | ||
100 | +import com.google.common.collect.ImmutableSet; | ||
101 | + | ||
102 | +/** | ||
103 | + * Tests the functions of PceManager. | ||
104 | + */ | ||
105 | +public class PceManagerTest { | ||
106 | + | ||
107 | + private PathComputationTest pathCompTest = new PathComputationTest(); | ||
108 | + private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService(); | ||
109 | + private MockTopologyService topologyService = new MockTopologyService(); | ||
110 | + private MockPathService pathService = new MockPathService(); | ||
111 | + private PceManager pceManager = new PceManager(); | ||
112 | + private MockCoreService coreService = new MockCoreService(); | ||
113 | + private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); | ||
114 | + private TestStorageService storageService = new TestStorageService(); | ||
115 | + private PacketService packetService = new MockPacketService(); | ||
116 | + private MockDeviceService deviceService = new MockDeviceService(); | ||
117 | + private MockFlowObjService flowObjectiveService = new MockFlowObjService(); | ||
118 | + private PceStore pceStore = new PceStoreAdapter(); | ||
119 | + private LabelResourceService labelResourceService = new LabelResourceAdapter(); | ||
120 | + | ||
121 | + public static ProviderId providerId = new ProviderId("pce", "foo"); | ||
122 | + private static final String L3 = "L3"; | ||
123 | + private static final String LSRID = "lsrId"; | ||
124 | + private static final String PCECC_CAPABILITY = "pceccCapability"; | ||
125 | + private static final String SR_CAPABILITY = "srCapability"; | ||
126 | + private static final String LABEL_STACK_CAPABILITY = "labelStackCapability"; | ||
127 | + | ||
128 | + private TopologyGraph graph = null; | ||
129 | + private Device deviceD1, deviceD2, deviceD3, deviceD4; | ||
130 | + private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4; | ||
131 | + private Link link1, link2, link3, link4; | ||
132 | + private static int flowsDownloaded; | ||
133 | + private TunnelListener tunnelListener; | ||
134 | + | ||
135 | + @Before | ||
136 | + public void startUp() { | ||
137 | + pceManager.pathService = pathService; | ||
138 | + pceManager.resourceService = resourceService; | ||
139 | + pceManager.tunnelService = tunnelService; | ||
140 | + pceManager.coreService = coreService; | ||
141 | + pceManager.storageService = storageService; | ||
142 | + pceManager.packetService = packetService; | ||
143 | + pceManager.deviceService = deviceService; | ||
144 | + pceManager.labelRsrcService = labelResourceService; | ||
145 | + pceManager.flowObjectiveService = flowObjectiveService; | ||
146 | + pceManager.pceStore = pceStore; | ||
147 | + pceManager.activate(); | ||
148 | + } | ||
149 | + | ||
150 | + private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap, | ||
151 | + boolean setLabelStackCap, int bandwidth) { | ||
152 | + Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>(); | ||
153 | + vertexes.add(D1); | ||
154 | + vertexes.add(D2); | ||
155 | + vertexes.add(D3); | ||
156 | + vertexes.add(D4); | ||
157 | + | ||
158 | + Set<TopologyEdge> edges = new HashSet<TopologyEdge>(); | ||
159 | + link1 = PathComputationTest.addLink(D1.deviceId().toString(), 10, D2.deviceId().toString(), 20, setCost, 50); | ||
160 | + TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1); | ||
161 | + edges.add(edge1); | ||
162 | + | ||
163 | + link2 = PathComputationTest.addLink(D2.deviceId().toString(), 30, D4.deviceId().toString(), 40, setCost, 20); | ||
164 | + TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2); | ||
165 | + edges.add(edge2); | ||
166 | + | ||
167 | + link3 = PathComputationTest.addLink(D1.deviceId().toString(), 80, D3.deviceId().toString(), 70, setCost, 100); | ||
168 | + TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3); | ||
169 | + edges.add(edge3); | ||
170 | + | ||
171 | + link4 = PathComputationTest.addLink(D3.deviceId().toString(), 60, D4.deviceId().toString(), 50, setCost, 80); | ||
172 | + TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4); | ||
173 | + edges.add(edge4); | ||
174 | + | ||
175 | + graph = new DefaultTopologyGraph(vertexes, edges); | ||
176 | + | ||
177 | + DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); | ||
178 | + DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); | ||
179 | + DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); | ||
180 | + DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); | ||
181 | + | ||
182 | + builderDev1.set(AnnotationKeys.TYPE, L3); | ||
183 | + builderDev1.set(LSRID, "1.1.1.1"); | ||
184 | + | ||
185 | + builderDev2.set(AnnotationKeys.TYPE, L3); | ||
186 | + builderDev2.set(LSRID, "2.2.2.2"); | ||
187 | + | ||
188 | + builderDev3.set(AnnotationKeys.TYPE, L3); | ||
189 | + builderDev3.set(LSRID, "3.3.3.3"); | ||
190 | + | ||
191 | + builderDev4.set(AnnotationKeys.TYPE, L3); | ||
192 | + builderDev4.set(LSRID, "4.4.4.4"); | ||
193 | + | ||
194 | + if (setSrCap) { | ||
195 | + builderDev1.set(SR_CAPABILITY, "true"); | ||
196 | + builderDev2.set(SR_CAPABILITY, "true"); | ||
197 | + builderDev3.set(SR_CAPABILITY, "true"); | ||
198 | + builderDev4.set(SR_CAPABILITY, "true"); | ||
199 | + } | ||
200 | + | ||
201 | + if (setPceccCap) { | ||
202 | + builderDev1.set(PCECC_CAPABILITY, "true"); | ||
203 | + builderDev2.set(PCECC_CAPABILITY, "true"); | ||
204 | + builderDev3.set(PCECC_CAPABILITY, "true"); | ||
205 | + builderDev4.set(PCECC_CAPABILITY, "true"); | ||
206 | + } | ||
207 | + | ||
208 | + if (setLabelStackCap) { | ||
209 | + builderDev1.set(LABEL_STACK_CAPABILITY, "true"); | ||
210 | + builderDev2.set(LABEL_STACK_CAPABILITY, "true"); | ||
211 | + builderDev3.set(LABEL_STACK_CAPABILITY, "true"); | ||
212 | + builderDev4.set(LABEL_STACK_CAPABILITY, "true"); | ||
213 | + } | ||
214 | + | ||
215 | + deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build()); | ||
216 | + deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build()); | ||
217 | + deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build()); | ||
218 | + deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build()); | ||
219 | + | ||
220 | + deviceService.addDevice(deviceD1); | ||
221 | + deviceService.addDevice(deviceD2); | ||
222 | + deviceService.addDevice(deviceD3); | ||
223 | + deviceService.addDevice(deviceD4); | ||
224 | + | ||
225 | + pcepDeviceD1 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE1), builderDev1.build()); | ||
226 | + deviceService.addDevice(pcepDeviceD1); | ||
227 | + | ||
228 | + pcepDeviceD2 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE2), builderDev1.build()); | ||
229 | + deviceService.addDevice(pcepDeviceD2); | ||
230 | + | ||
231 | + pcepDeviceD3 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE3), builderDev1.build()); | ||
232 | + deviceService.addDevice(pcepDeviceD3); | ||
233 | + | ||
234 | + pcepDeviceD4 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE4), builderDev1.build()); | ||
235 | + deviceService.addDevice(pcepDeviceD4); | ||
236 | + | ||
237 | + if (bandwidth != 0) { | ||
238 | + List<Resource> resources = new LinkedList<>(); | ||
239 | + resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(bandwidth)); | ||
240 | + resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(bandwidth)); | ||
241 | + resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(bandwidth)); | ||
242 | + resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(bandwidth)); | ||
243 | + | ||
244 | + resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(bandwidth)); | ||
245 | + resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(bandwidth)); | ||
246 | + resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(bandwidth)); | ||
247 | + resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(bandwidth)); | ||
248 | + | ||
249 | + resourceService.allocate(IntentId.valueOf(bandwidth), resources); | ||
250 | + } | ||
251 | + } | ||
252 | + | ||
253 | + /** | ||
254 | + * Tests path success with (IGP) cost constraint for signalled LSP. | ||
255 | + */ | ||
256 | + @Test | ||
257 | + public void setupPathTest1() { | ||
258 | + build4RouterTopo(true, false, false, false, 0); // IGP cost is set here. | ||
259 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
260 | + CostConstraint costConstraint = new CostConstraint(COST); | ||
261 | + constraints.add(costConstraint); | ||
262 | + | ||
263 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
264 | + assertThat(result, is(true)); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Tests path failure with (IGP) cost constraint for signalled LSP. | ||
269 | + */ | ||
270 | + @Test | ||
271 | + public void setupPathTest2() { | ||
272 | + build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP. | ||
273 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
274 | + CostConstraint costConstraint = new CostConstraint(COST); | ||
275 | + constraints.add(costConstraint); | ||
276 | + | ||
277 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
278 | + assertThat(result, is(false)); | ||
279 | + } | ||
280 | + | ||
281 | + /** | ||
282 | + * Tests path success with TE-cost constraint for signalled LSP. | ||
283 | + */ | ||
284 | + @Test | ||
285 | + public void setupPathTest3() { | ||
286 | + build4RouterTopo(false, false, false, false, 0); // TE cost is set here. | ||
287 | + | ||
288 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
289 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
290 | + constraints.add(costConstraint); | ||
291 | + | ||
292 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
293 | + assertThat(result, is(true)); | ||
294 | + } | ||
295 | + | ||
296 | + /** | ||
297 | + * Tests path failure with TE-cost constraint for signalled LSP. | ||
298 | + */ | ||
299 | + @Test | ||
300 | + public void setupPathTest4() { | ||
301 | + build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE. | ||
302 | + | ||
303 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
304 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
305 | + constraints.add(costConstraint); | ||
306 | + | ||
307 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
308 | + assertThat(result, is(false)); | ||
309 | + } | ||
310 | + | ||
311 | + /** | ||
312 | + * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP. | ||
313 | + */ | ||
314 | + @Test | ||
315 | + public void setupPathTest5() { | ||
316 | + build4RouterTopo(true, true, false, false, 0); | ||
317 | + | ||
318 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
319 | + CostConstraint costConstraint = new CostConstraint(COST); | ||
320 | + constraints.add(costConstraint); | ||
321 | + | ||
322 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, | ||
323 | + WITHOUT_SIGNALLING_AND_WITHOUT_SR); | ||
324 | + assertThat(result, is(true)); | ||
325 | + } | ||
326 | + | ||
327 | + /** | ||
328 | + * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP. | ||
329 | + */ | ||
330 | + @Test | ||
331 | + public void setupPathTest6() { | ||
332 | + build4RouterTopo(false, true, false, false, 0); | ||
333 | + | ||
334 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
335 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
336 | + constraints.add(costConstraint); | ||
337 | + | ||
338 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, | ||
339 | + WITHOUT_SIGNALLING_AND_WITHOUT_SR); | ||
340 | + assertThat(result, is(true)); | ||
341 | + } | ||
342 | + | ||
343 | + /** | ||
344 | + * Tests path failure with TE-cost constraint for non-SR non-signalled LSP(CR). Label capability not registered. | ||
345 | + */ | ||
346 | + @Test | ||
347 | + public void setupPathTest7() { | ||
348 | + build4RouterTopo(true, false, false, false, 0); | ||
349 | + | ||
350 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
351 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
352 | + constraints.add(costConstraint); | ||
353 | + | ||
354 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, | ||
355 | + WITHOUT_SIGNALLING_AND_WITHOUT_SR); | ||
356 | + assertThat(result, is(false)); | ||
357 | + } | ||
358 | + | ||
359 | + /** | ||
360 | + * Tests path failure as bandwidth is requested but is not registered. | ||
361 | + */ | ||
362 | + @Test | ||
363 | + public void setupPathTest8() { | ||
364 | + build4RouterTopo(true, false, false, false, 0); | ||
365 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
366 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
367 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
368 | + | ||
369 | + constraints.add(costConstraint); | ||
370 | + constraints.add(bwConstraint); | ||
371 | + | ||
372 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
373 | + assertThat(result, is(false)); | ||
374 | + } | ||
375 | + | ||
376 | + /** | ||
377 | + * Tests path failure as bandwidth requested is more than registered. | ||
378 | + */ | ||
379 | + @Test | ||
380 | + public void setupPathTest9() { | ||
381 | + build4RouterTopo(false, false, false, false, 5); | ||
382 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
383 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
384 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
385 | + | ||
386 | + constraints.add(costConstraint); | ||
387 | + constraints.add(bwConstraint); | ||
388 | + | ||
389 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
390 | + assertThat(result, is(false)); | ||
391 | + } | ||
392 | + | ||
393 | + /** | ||
394 | + * Tests path setup failure(without signalling). Label capability is not present. | ||
395 | + */ | ||
396 | + @Test | ||
397 | + public void setupPathTest10() { | ||
398 | + build4RouterTopo(false, false, false, false, 0); | ||
399 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
400 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
401 | + constraints.add(costConstraint); | ||
402 | + | ||
403 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | ||
404 | + assertThat(result, is(false)); | ||
405 | + } | ||
406 | + | ||
407 | + /** | ||
408 | + * Tests path setup without failure for LSP with signalling and with bandwidth reservation. | ||
409 | + */ | ||
410 | + @Test | ||
411 | + public void setupPathTest11() { | ||
412 | + build4RouterTopo(false, true, true, true, 15); | ||
413 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
414 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
415 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
416 | + | ||
417 | + constraints.add(costConstraint); | ||
418 | + constraints.add(bwConstraint); | ||
419 | + | ||
420 | + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
421 | + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
422 | + | ||
423 | + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
424 | + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
425 | + | ||
426 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | ||
427 | + assertThat(result, is(false)); | ||
428 | + } | ||
429 | + | ||
430 | + /** | ||
431 | + * Tests path setup without signalling and with bandwidth reservation. | ||
432 | + */ | ||
433 | + @Test | ||
434 | + public void setupPathTest12() { | ||
435 | + build4RouterTopo(false, true, true, true, 15); | ||
436 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
437 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
438 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
439 | + | ||
440 | + constraints.add(costConstraint); | ||
441 | + constraints.add(bwConstraint); | ||
442 | + | ||
443 | + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
444 | + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
445 | + | ||
446 | + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
447 | + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
448 | + | ||
449 | + LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
450 | + pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
451 | + | ||
452 | + LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
453 | + pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
454 | + | ||
455 | + LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
456 | + pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
457 | + | ||
458 | + LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
459 | + pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
460 | + | ||
461 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | ||
462 | + assertThat(result, is(true)); | ||
463 | + } | ||
464 | + | ||
465 | + /** | ||
466 | + * Tests path setup without cost/bandwidth constraints. | ||
467 | + */ | ||
468 | + @Test | ||
469 | + public void setupPathTest13() { | ||
470 | + build4RouterTopo(false, false, false, false, 0); | ||
471 | + | ||
472 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING); | ||
473 | + assertThat(result, is(true)); | ||
474 | + } | ||
475 | + | ||
476 | + /** | ||
477 | + * Tests path update with increase in bandwidth. | ||
478 | + */ | ||
479 | + @Test | ||
480 | + public void updatePathTest1() { | ||
481 | + build4RouterTopo(false, true, true, true, 100); | ||
482 | + | ||
483 | + // Setup tunnel. | ||
484 | + List<Constraint> constraints = new LinkedList<>(); | ||
485 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0)); | ||
486 | + constraints.add(bwConstraint); | ||
487 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
488 | + constraints.add(costConstraint); | ||
489 | + | ||
490 | + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
491 | + assertThat(result, is(true)); | ||
492 | + | ||
493 | + // Change constraint and update it. | ||
494 | + constraints = new LinkedList<>(); | ||
495 | + bwConstraint = new BandwidthConstraint(Bandwidth.bps(50.0)); | ||
496 | + constraints.add(bwConstraint); | ||
497 | + constraints.add(costConstraint); | ||
498 | + | ||
499 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
500 | + assertThat(tunnels.size(), is(1)); | ||
501 | + | ||
502 | + Tunnel tunnel = tunnels.iterator().next(); | ||
503 | + | ||
504 | + // Stimulate the effect of LSP ids from protocol msg. | ||
505 | + tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE); | ||
506 | + | ||
507 | + result = pceManager.updatePath(tunnel.tunnelId(), constraints); | ||
508 | + assertThat(result, is(true)); | ||
509 | + | ||
510 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
511 | + assertThat(tunnels.size(), is(2)); | ||
512 | + } | ||
513 | + | ||
514 | + /** | ||
515 | + * Tests path update with decrease in bandwidth. | ||
516 | + */ | ||
517 | + @Test | ||
518 | + public void updatePathTest2() { | ||
519 | + build4RouterTopo(false, true, true, true, 100); | ||
520 | + | ||
521 | + // Setup tunnel. | ||
522 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
523 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0)); | ||
524 | + constraints.add(bwConstraint); | ||
525 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
526 | + constraints.add(costConstraint); | ||
527 | + | ||
528 | + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
529 | + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
530 | + | ||
531 | + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
532 | + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
533 | + | ||
534 | + LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
535 | + pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
536 | + | ||
537 | + LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
538 | + pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
539 | + | ||
540 | + LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
541 | + pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
542 | + | ||
543 | + LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
544 | + pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
545 | + | ||
546 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | ||
547 | + assertThat(result, is(true)); | ||
548 | + | ||
549 | + // Change constraint and update it. | ||
550 | + constraints.remove(bwConstraint); | ||
551 | + bwConstraint = new BandwidthConstraint(Bandwidth.bps(70.0)); | ||
552 | + constraints.add(bwConstraint); | ||
553 | + | ||
554 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
555 | + assertThat(tunnels.size(), is(1)); | ||
556 | + | ||
557 | + for (Tunnel tunnel : tunnels) { | ||
558 | + result = pceManager.updatePath(tunnel.tunnelId(), constraints); | ||
559 | + assertThat(result, is(true)); | ||
560 | + } | ||
561 | + | ||
562 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
563 | + assertThat(tunnels.size(), is(2)); | ||
564 | + } | ||
565 | + | ||
566 | + /** | ||
567 | + * Tests path update without cost/bandwidth constraints. | ||
568 | + */ | ||
569 | + @Test | ||
570 | + public void updatePathTest3() { | ||
571 | + build4RouterTopo(false, true, true, true, 100); | ||
572 | + | ||
573 | + // Setup tunnel. | ||
574 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING); | ||
575 | + assertThat(result, is(true)); | ||
576 | + | ||
577 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
578 | + assertThat(tunnels.size(), is(1)); | ||
579 | + | ||
580 | + for (Tunnel tunnel : tunnels) { | ||
581 | + result = pceManager.updatePath(tunnel.tunnelId(), null); | ||
582 | + assertThat(result, is(true)); | ||
583 | + } | ||
584 | + | ||
585 | + Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath(); | ||
586 | + assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2)); | ||
587 | + } | ||
588 | + | ||
589 | + /** | ||
590 | + * Tests path release. | ||
591 | + */ | ||
592 | + @Test | ||
593 | + public void releasePathTest1() { | ||
594 | + build4RouterTopo(false, false, false, false, 5); | ||
595 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
596 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
597 | + constraints.add(costConstraint); | ||
598 | + | ||
599 | + pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
600 | + | ||
601 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
602 | + assertThat(tunnels.size(), is(1)); | ||
603 | + boolean result; | ||
604 | + for (Tunnel tunnel : tunnels) { | ||
605 | + result = pceManager.releasePath(tunnel.tunnelId()); | ||
606 | + assertThat(result, is(true)); | ||
607 | + } | ||
608 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
609 | + assertThat(tunnels.size(), is(0)); | ||
610 | + } | ||
611 | + | ||
612 | + /** | ||
613 | + * Tests path release failure. | ||
614 | + */ | ||
615 | + @Test | ||
616 | + public void releasePathTest2() { | ||
617 | + build4RouterTopo(false, false, false, false, 5); | ||
618 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
619 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
620 | + constraints.add(costConstraint); | ||
621 | + | ||
622 | + pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
623 | + | ||
624 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
625 | + assertThat(tunnels.size(), is(1)); | ||
626 | + | ||
627 | + // Random tunnel id. | ||
628 | + boolean result = pceManager.releasePath(TunnelId.valueOf("111")); | ||
629 | + assertThat(result, is(false)); | ||
630 | + | ||
631 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
632 | + assertThat(tunnels.size(), is(1)); | ||
633 | + } | ||
634 | + | ||
635 | + /** | ||
636 | + * Tests packet in to trigger label DB sync. | ||
637 | + */ | ||
638 | + @Test | ||
639 | + public void packetProcessingTest() throws URISyntaxException { | ||
640 | + | ||
641 | + build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc. | ||
642 | + | ||
643 | + final int srcHost = 2; | ||
644 | + final int dstHost = 5; | ||
645 | + | ||
646 | + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
647 | + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
648 | + | ||
649 | + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
650 | + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
651 | + | ||
652 | + ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)); | ||
653 | + ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(dstHost)); | ||
654 | + | ||
655 | + Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) | ||
656 | + .providerId(new ProviderId("eth", "1")).build(); | ||
657 | + | ||
658 | + LabelResourceId link1Label = LabelResourceId.labelResourceId(5204); | ||
659 | + pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
660 | + | ||
661 | + Ethernet eth; | ||
662 | + IPv4 ipv4; | ||
663 | + | ||
664 | + ipv4 = new IPv4(); | ||
665 | + eth = new Ethernet(); | ||
666 | + eth.setEtherType(Ethernet.TYPE_IPV4); | ||
667 | + eth.setPayload(ipv4); | ||
668 | + | ||
669 | + eth.setSourceMACAddress("00:00:00:10:00:0" + srcHost).setDestinationMACAddress("00:00:00:10:00:0" + dstHost); | ||
670 | + | ||
671 | + InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)), | ||
672 | + eth, ByteBuffer.wrap(eth.serialize())); | ||
673 | + | ||
674 | + pktProcessor.process(new MockPcepPacketContext(inPkt, null)); | ||
675 | + assertThat(flowsDownloaded, is(4)); | ||
676 | + } | ||
677 | + | ||
678 | + /** | ||
679 | + * Tests tunnel events added and removed. | ||
680 | + */ | ||
681 | + @Test | ||
682 | + public void tunnelEventTest1() { | ||
683 | + build4RouterTopo(false, true, true, true, 15); | ||
684 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
685 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
686 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
687 | + | ||
688 | + constraints.add(costConstraint); | ||
689 | + constraints.add(bwConstraint); | ||
690 | + | ||
691 | + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
692 | + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
693 | + | ||
694 | + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
695 | + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
696 | + | ||
697 | + LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
698 | + pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
699 | + | ||
700 | + LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
701 | + pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
702 | + | ||
703 | + LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
704 | + pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
705 | + | ||
706 | + LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
707 | + pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
708 | + | ||
709 | + pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING); | ||
710 | + assertThat(pceStore.getTunnelInfoCount(), is(1)); | ||
711 | + | ||
712 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
713 | + | ||
714 | + for (Tunnel tunnel : tunnels) { | ||
715 | + TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); | ||
716 | + tunnelListener.event(event); | ||
717 | + | ||
718 | + pceManager.releasePath(tunnel.tunnelId()); | ||
719 | + | ||
720 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel); | ||
721 | + tunnelListener.event(event); | ||
722 | + } | ||
723 | + | ||
724 | + assertThat(pceStore.getTunnelInfoCount(), is(0)); | ||
725 | + } | ||
726 | + | ||
727 | + /** | ||
728 | + * Tests label allocation/removal in CR case based on tunnel event. | ||
729 | + */ | ||
730 | + @Test | ||
731 | + public void tunnelEventTest2() { | ||
732 | + build4RouterTopo(false, true, true, true, 15); | ||
733 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
734 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
735 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
736 | + | ||
737 | + constraints.add(costConstraint); | ||
738 | + constraints.add(bwConstraint); | ||
739 | + | ||
740 | + pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR); | ||
741 | + assertThat(pceStore.getTunnelInfoCount(), is(1)); | ||
742 | + | ||
743 | + TunnelEvent event; | ||
744 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
745 | + for (Tunnel tunnel : tunnels) { | ||
746 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); | ||
747 | + tunnelListener.event(event); | ||
748 | + | ||
749 | + // Stimulate the effect of LSP ids from protocol msg. | ||
750 | + tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED); | ||
751 | + } | ||
752 | + | ||
753 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
754 | + for (Tunnel tunnel : tunnels) { | ||
755 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel); | ||
756 | + tunnelListener.event(event); | ||
757 | + | ||
758 | + pceManager.releasePath(tunnel.tunnelId()); | ||
759 | + | ||
760 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel); | ||
761 | + tunnelListener.event(event); | ||
762 | + } | ||
763 | + | ||
764 | + assertThat(pceStore.getTunnelInfoCount(), is(0)); | ||
765 | + } | ||
766 | + | ||
767 | + /** | ||
768 | + * Tests handling UNSTABLE state based on tunnel event. | ||
769 | + */ | ||
770 | + @Test | ||
771 | + public void tunnelEventTest3() { | ||
772 | + build4RouterTopo(false, true, true, true, 15); | ||
773 | + List<Constraint> constraints = new LinkedList<Constraint>(); | ||
774 | + BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
775 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
776 | + | ||
777 | + constraints.add(costConstraint); | ||
778 | + constraints.add(bwConstraint); | ||
779 | + | ||
780 | + pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR); | ||
781 | + assertThat(pceStore.getTunnelInfoCount(), is(1)); | ||
782 | + assertThat(pceStore.getFailedPathInfoCount(), is(0)); | ||
783 | + | ||
784 | + TunnelEvent event; | ||
785 | + Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
786 | + for (Tunnel tunnel : tunnels) { | ||
787 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); | ||
788 | + tunnelListener.event(event); | ||
789 | + | ||
790 | + // Stimulate the effect of LSP ids from protocol msg. | ||
791 | + tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE); | ||
792 | + } | ||
793 | + | ||
794 | + tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ||
795 | + for (Tunnel tunnel : tunnels) { | ||
796 | + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel); | ||
797 | + tunnelListener.event(event); | ||
798 | + } | ||
799 | + assertThat(pceStore.getTunnelInfoCount(), is(1)); | ||
800 | + assertThat(pceStore.getFailedPathInfoCount(), is(1)); | ||
801 | + } | ||
802 | + | ||
803 | + @After | ||
804 | + public void tearDown() { | ||
805 | + pceManager.deactivate(); | ||
806 | + pceManager.pathService = null; | ||
807 | + pceManager.resourceService = null; | ||
808 | + pceManager.tunnelService = null; | ||
809 | + pceManager.coreService = null; | ||
810 | + pceManager.storageService = null; | ||
811 | + pceManager.packetService = null; | ||
812 | + pceManager.deviceService = null; | ||
813 | + pceManager.labelRsrcService = null; | ||
814 | + pceManager.flowObjectiveService = null; | ||
815 | + pceManager.pceStore = null; | ||
816 | + flowsDownloaded = 0; | ||
817 | + } | ||
818 | + | ||
819 | + private class MockTopologyService extends TopologyServiceAdapter { | ||
820 | + @Override | ||
821 | + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { | ||
822 | + DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); | ||
823 | + DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); | ||
824 | + Set<TopologyVertex> vertices = graph.getVertexes(); | ||
825 | + if (!vertices.contains(srcV) || !vertices.contains(dstV)) { | ||
826 | + // src or dst not part of the current graph | ||
827 | + return ImmutableSet.of(); | ||
828 | + } | ||
829 | + | ||
830 | + GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch() | ||
831 | + .search(graph, srcV, dstV, weight, ALL_PATHS); | ||
832 | + ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); | ||
833 | + for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { | ||
834 | + builder.add(PathComputationTest.networkPath(path)); | ||
835 | + } | ||
836 | + return builder.build(); | ||
837 | + } | ||
838 | + } | ||
839 | + | ||
840 | + private class MockPathService extends PathServiceAdapter { | ||
841 | + | ||
842 | + @Override | ||
843 | + public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { | ||
844 | + // If either edge is null, bail with no paths. | ||
845 | + if (src == null || dst == null) { | ||
846 | + return ImmutableSet.of(); | ||
847 | + } | ||
848 | + | ||
849 | + // Otherwise get all paths between the source and destination edge | ||
850 | + // devices. | ||
851 | + return topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight); | ||
852 | + } | ||
853 | + } | ||
854 | + | ||
855 | + private class MockTunnelServiceAdapter extends TunnelServiceAdapter { | ||
856 | + private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>(); | ||
857 | + private int tunnelIdCounter = 0; | ||
858 | + | ||
859 | + @Override | ||
860 | + public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) { | ||
861 | + TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); | ||
862 | + Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(), | ||
863 | + tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(), | ||
864 | + path, tunnel.annotations()); | ||
865 | + tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert); | ||
866 | + return tunnelId; | ||
867 | + } | ||
868 | + | ||
869 | + @Override | ||
870 | + public void addListener(TunnelListener listener) { | ||
871 | + tunnelListener = listener; | ||
872 | + } | ||
873 | + | ||
874 | + /** | ||
875 | + * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg. | ||
876 | + */ | ||
877 | + public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) { | ||
878 | + TunnelId tunnelId = tunnel.tunnelId(); | ||
879 | + Builder annotationBuilder = DefaultAnnotations.builder(); | ||
880 | + annotationBuilder.putAll(tunnel.annotations()); | ||
881 | + | ||
882 | + // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC. | ||
883 | + if (tunnel.annotations().value(PLSP_ID) == null) { | ||
884 | + annotationBuilder.set(PLSP_ID, pLspId); | ||
885 | + } | ||
886 | + | ||
887 | + // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC). | ||
888 | + if (tunnel.annotations().value(LOCAL_LSP_ID) == null) { | ||
889 | + annotationBuilder.set(LOCAL_LSP_ID, localLspId); | ||
890 | + } | ||
891 | + SparseAnnotations annotations = annotationBuilder.build(); | ||
892 | + tunnelIdAsKeyStore.remove(tunnelId, tunnel); | ||
893 | + | ||
894 | + Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(), | ||
895 | + state, tunnel.groupId(), tunnelId, tunnel.tunnelName(), | ||
896 | + tunnel.path(), annotations); | ||
897 | + | ||
898 | + tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert); | ||
899 | + | ||
900 | + return tunnelId; | ||
901 | + } | ||
902 | + | ||
903 | + @Override | ||
904 | + public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) { | ||
905 | + for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) { | ||
906 | + if (tunnelIdKey.equals(tunnelId)) { | ||
907 | + tunnelIdAsKeyStore.remove(tunnelId); | ||
908 | + return true; | ||
909 | + } | ||
910 | + } | ||
911 | + return false; | ||
912 | + } | ||
913 | + | ||
914 | + @Override | ||
915 | + public Tunnel queryTunnel(TunnelId tunnelId) { | ||
916 | + for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) { | ||
917 | + if (tunnelIdKey.equals(tunnelId)) { | ||
918 | + return tunnelIdAsKeyStore.get(tunnelId); | ||
919 | + } | ||
920 | + } | ||
921 | + return null; | ||
922 | + } | ||
923 | + | ||
924 | + @Override | ||
925 | + public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { | ||
926 | + Collection<Tunnel> result = new HashSet<Tunnel>(); | ||
927 | + Tunnel tunnel = null; | ||
928 | + for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { | ||
929 | + tunnel = tunnelIdAsKeyStore.get(tunnelId); | ||
930 | + | ||
931 | + if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) { | ||
932 | + result.add(tunnel); | ||
933 | + } | ||
934 | + } | ||
935 | + | ||
936 | + return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); | ||
937 | + } | ||
938 | + | ||
939 | + @Override | ||
940 | + public Collection<Tunnel> queryTunnel(Tunnel.Type type) { | ||
941 | + Collection<Tunnel> result = new HashSet<Tunnel>(); | ||
942 | + | ||
943 | + for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { | ||
944 | + result.add(tunnelIdAsKeyStore.get(tunnelId)); | ||
945 | + } | ||
946 | + | ||
947 | + return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); | ||
948 | + } | ||
949 | + } | ||
950 | + | ||
951 | + public static class MockCoreService extends CoreServiceAdapter { | ||
952 | + | ||
953 | + @Override | ||
954 | + public ApplicationId registerApplication(String name) { | ||
955 | + return new DefaultApplicationId(1, name); | ||
956 | + } | ||
957 | + | ||
958 | + @Override | ||
959 | + public IdGenerator getIdGenerator(String topic) { | ||
960 | + return new IdGenerator() { | ||
961 | + private AtomicLong counter = new AtomicLong(0); | ||
962 | + | ||
963 | + @Override | ||
964 | + public long getNewId() { | ||
965 | + return counter.getAndIncrement(); | ||
966 | + } | ||
967 | + }; | ||
968 | + } | ||
969 | + } | ||
970 | + | ||
971 | + private class MockDevice extends DefaultDevice { | ||
972 | + MockDevice(DeviceId id, Annotations annotations) { | ||
973 | + super(null, id, null, null, null, null, null, null, annotations); | ||
974 | + } | ||
975 | + } | ||
976 | + | ||
977 | + private class MockDeviceService extends DeviceServiceAdapter { | ||
978 | + List<Device> devices = new LinkedList<>(); | ||
979 | + | ||
980 | + private void addDevice(Device dev) { | ||
981 | + devices.add(dev); | ||
982 | + } | ||
983 | + | ||
984 | + @Override | ||
985 | + public Device getDevice(DeviceId deviceId) { | ||
986 | + for (Device dev : devices) { | ||
987 | + if (dev.id().equals(deviceId)) { | ||
988 | + return dev; | ||
989 | + } | ||
990 | + } | ||
991 | + return null; | ||
992 | + } | ||
993 | + | ||
994 | + @Override | ||
995 | + public Iterable<Device> getAvailableDevices() { | ||
996 | + return devices; | ||
997 | + } | ||
998 | + } | ||
999 | + | ||
1000 | + private PacketProcessor pktProcessor = null; | ||
1001 | + | ||
1002 | + private class MockPacketService extends PacketServiceAdapter { | ||
1003 | + @Override | ||
1004 | + public void addProcessor(PacketProcessor processor, int priority) { | ||
1005 | + pktProcessor = processor; | ||
1006 | + } | ||
1007 | + } | ||
1008 | + | ||
1009 | + // Minimal PacketContext to make core and applications happy. | ||
1010 | + final class MockPcepPacketContext extends DefaultPacketContext { | ||
1011 | + private MockPcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) { | ||
1012 | + super(System.currentTimeMillis(), inPkt, outPkt, false); | ||
1013 | + } | ||
1014 | + | ||
1015 | + @Override | ||
1016 | + public void send() { | ||
1017 | + } | ||
1018 | + } | ||
1019 | + | ||
1020 | + public static class MockFlowObjService extends FlowObjServiceAdapter { | ||
1021 | + @Override | ||
1022 | + public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { | ||
1023 | + ++flowsDownloaded; | ||
1024 | + } | ||
1025 | + } | ||
1026 | +} |
... | @@ -33,6 +33,8 @@ import org.junit.Before; | ... | @@ -33,6 +33,8 @@ import org.junit.Before; |
33 | import org.junit.Test; | 33 | import org.junit.Test; |
34 | 34 | ||
35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
36 | +import org.onosproject.core.ApplicationId; | ||
37 | +import org.onosproject.core.CoreService; | ||
36 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | 38 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; |
37 | import org.onosproject.incubator.net.resource.label.LabelResourceService; | 39 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
38 | import org.onosproject.incubator.net.tunnel.LabelStack; | 40 | import org.onosproject.incubator.net.tunnel.LabelStack; |
... | @@ -41,6 +43,7 @@ import org.onosproject.net.DefaultAnnotations; | ... | @@ -41,6 +43,7 @@ import org.onosproject.net.DefaultAnnotations; |
41 | import org.onosproject.net.DefaultPath; | 43 | import org.onosproject.net.DefaultPath; |
42 | import org.onosproject.net.DeviceId; | 44 | import org.onosproject.net.DeviceId; |
43 | import org.onosproject.net.PortNumber; | 45 | import org.onosproject.net.PortNumber; |
46 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
44 | import org.onosproject.net.Path; | 47 | import org.onosproject.net.Path; |
45 | import org.onosproject.pce.pcestore.api.PceStore; | 48 | import org.onosproject.pce.pcestore.api.PceStore; |
46 | import org.onosproject.net.provider.ProviderId; | 49 | import org.onosproject.net.provider.ProviderId; |
... | @@ -61,6 +64,9 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -61,6 +64,9 @@ public class PceccSrTeBeHandlerTest { |
61 | protected LabelResourceAdminService labelRsrcAdminService; | 64 | protected LabelResourceAdminService labelRsrcAdminService; |
62 | protected LabelResourceService labelRsrcService; | 65 | protected LabelResourceService labelRsrcService; |
63 | protected PceStore pceStore; | 66 | protected PceStore pceStore; |
67 | + private FlowObjectiveService flowObjectiveService; | ||
68 | + private CoreService coreService; | ||
69 | + private ApplicationId appId; | ||
64 | private ProviderId providerId; | 70 | private ProviderId providerId; |
65 | private DeviceId deviceId1; | 71 | private DeviceId deviceId1; |
66 | private DeviceId deviceId2; | 72 | private DeviceId deviceId2; |
... | @@ -88,8 +94,11 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -88,8 +94,11 @@ public class PceccSrTeBeHandlerTest { |
88 | srTeHandler = PceccSrTeBeHandler.getInstance(); | 94 | srTeHandler = PceccSrTeBeHandler.getInstance(); |
89 | labelRsrcService = new LabelResourceAdapter(); | 95 | labelRsrcService = new LabelResourceAdapter(); |
90 | labelRsrcAdminService = new LabelResourceAdapter(); | 96 | labelRsrcAdminService = new LabelResourceAdapter(); |
97 | + flowObjectiveService = new PceManagerTest.MockFlowObjService(); | ||
98 | + coreService = new PceManagerTest.MockCoreService(); | ||
99 | + appId = coreService.registerApplication("org.onosproject.pce"); | ||
91 | pceStore = new PceStoreAdapter(); | 100 | pceStore = new PceStoreAdapter(); |
92 | - srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, pceStore); | 101 | + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore); |
93 | 102 | ||
94 | // Creates path | 103 | // Creates path |
95 | // Creates list of links | 104 | // Creates list of links |
... | @@ -446,39 +455,39 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -446,39 +455,39 @@ public class PceccSrTeBeHandlerTest { |
446 | // check node-label of deviceId1 | 455 | // check node-label of deviceId1 |
447 | List<LabelResourceId> labelList = labelStack.labelResources(); | 456 | List<LabelResourceId> labelList = labelStack.labelResources(); |
448 | Iterator<LabelResourceId> iterator = labelList.iterator(); | 457 | Iterator<LabelResourceId> iterator = labelList.iterator(); |
449 | - labelId = (LabelResourceId) iterator.next(); | 458 | + labelId = iterator.next(); |
450 | assertThat(labelId, is(LabelResourceId.labelResourceId(4097))); | 459 | assertThat(labelId, is(LabelResourceId.labelResourceId(4097))); |
451 | 460 | ||
452 | // check adjacency label of deviceId1 | 461 | // check adjacency label of deviceId1 |
453 | - labelId = (LabelResourceId) iterator.next(); | 462 | + labelId = iterator.next(); |
454 | assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); | 463 | assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); |
455 | 464 | ||
456 | // check node-label of deviceId2 | 465 | // check node-label of deviceId2 |
457 | - labelId = (LabelResourceId) iterator.next(); | 466 | + labelId = iterator.next(); |
458 | assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); | 467 | assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); |
459 | 468 | ||
460 | // check adjacency label of deviceId2 | 469 | // check adjacency label of deviceId2 |
461 | - labelId = (LabelResourceId) iterator.next(); | 470 | + labelId = iterator.next(); |
462 | assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); | 471 | assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); |
463 | 472 | ||
464 | // check node-label of deviceId3 | 473 | // check node-label of deviceId3 |
465 | - labelId = (LabelResourceId) iterator.next(); | 474 | + labelId = iterator.next(); |
466 | assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); | 475 | assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); |
467 | 476 | ||
468 | // check adjacency label of deviceId3 | 477 | // check adjacency label of deviceId3 |
469 | - labelId = (LabelResourceId) iterator.next(); | 478 | + labelId = iterator.next(); |
470 | assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); | 479 | assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); |
471 | 480 | ||
472 | // check node-label of deviceId4 | 481 | // check node-label of deviceId4 |
473 | - labelId = (LabelResourceId) iterator.next(); | 482 | + labelId = iterator.next(); |
474 | assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); | 483 | assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); |
475 | 484 | ||
476 | // check adjacency label of deviceId4 | 485 | // check adjacency label of deviceId4 |
477 | - labelId = (LabelResourceId) iterator.next(); | 486 | + labelId = iterator.next(); |
478 | assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); | 487 | assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); |
479 | 488 | ||
480 | // check node-label of deviceId5 | 489 | // check node-label of deviceId5 |
481 | - labelId = (LabelResourceId) iterator.next(); | 490 | + labelId = iterator.next(); |
482 | assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); | 491 | assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); |
483 | } | 492 | } |
484 | } | 493 | } | ... | ... |
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 java.util.List; | ||
19 | + | ||
20 | +import org.onosproject.net.DeviceId; | ||
21 | +import org.onosproject.net.flowobjective.FilteringObjective; | ||
22 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
23 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
24 | +import org.onosproject.net.flowobjective.NextObjective; | ||
25 | + | ||
26 | +/** | ||
27 | + * Test implementation of FlowObjectiveService. | ||
28 | + */ | ||
29 | +public class FlowObjServiceAdapter implements FlowObjectiveService { | ||
30 | + | ||
31 | + private ForwardingObjective forwardingObjective; | ||
32 | + @Override | ||
33 | + public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { | ||
34 | + | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { | ||
39 | + this.forwardingObjective = forwardingObjective; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public void next(DeviceId deviceId, NextObjective nextObjective) { | ||
44 | + | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public int allocateNextId() { | ||
49 | + return 0; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public void initPolicy(String policy) { | ||
54 | + | ||
55 | + } | ||
56 | + | ||
57 | + public ForwardingObjective forwardingObjective() { | ||
58 | + return forwardingObjective; | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public List<String> getNextMappings() { | ||
63 | + return null; | ||
64 | + } | ||
65 | +} |
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 java.util.Collection; | ||
19 | + | ||
20 | +import org.onosproject.core.ApplicationId; | ||
21 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
22 | +import org.onosproject.incubator.net.tunnel.Tunnel.Type; | ||
23 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
24 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
25 | +import org.onosproject.incubator.net.tunnel.TunnelListener; | ||
26 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
27 | +import org.onosproject.incubator.net.tunnel.TunnelService; | ||
28 | +import org.onosproject.incubator.net.tunnel.TunnelSubscription; | ||
29 | +import org.onosproject.net.Annotations; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.ElementId; | ||
32 | +import org.onosproject.net.Path; | ||
33 | + | ||
34 | +/** | ||
35 | + * Provides test implementation of class TunnelService. | ||
36 | + */ | ||
37 | +public class TunnelServiceAdapter implements TunnelService { | ||
38 | + | ||
39 | + @Override | ||
40 | + public void addListener(TunnelListener listener) { | ||
41 | + // TODO Auto-generated method stub | ||
42 | + | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public void removeListener(TunnelListener listener) { | ||
47 | + // TODO Auto-generated method stub | ||
48 | + | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) { | ||
53 | + // TODO Auto-generated method stub | ||
54 | + return null; | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelName tunnelName, | ||
59 | + Annotations... annotations) { | ||
60 | + // TODO Auto-generated method stub | ||
61 | + return null; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, | ||
66 | + Annotations... annotations) { | ||
67 | + // TODO Auto-generated method stub | ||
68 | + return null; | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, Type type, | ||
73 | + Annotations... annotations) { | ||
74 | + // TODO Auto-generated method stub | ||
75 | + return null; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) { | ||
80 | + // TODO Auto-generated method stub | ||
81 | + return null; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) { | ||
86 | + // TODO Auto-generated method stub | ||
87 | + return false; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) { | ||
92 | + // TODO Auto-generated method stub | ||
93 | + return false; | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public boolean returnTunnel(ApplicationId consumerId, TunnelName tunnelName, Annotations... annotations) { | ||
98 | + // TODO Auto-generated method stub | ||
99 | + return false; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, Type type, | ||
104 | + Annotations... annotations) { | ||
105 | + // TODO Auto-generated method stub | ||
106 | + return false; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, | ||
111 | + Annotations... annotations) { | ||
112 | + // TODO Auto-generated method stub | ||
113 | + return false; | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public Tunnel queryTunnel(TunnelId tunnelId) { | ||
118 | + // TODO Auto-generated method stub | ||
119 | + return null; | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) { | ||
124 | + // TODO Auto-generated method stub | ||
125 | + return null; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public Collection<Tunnel> queryTunnel(Type type) { | ||
130 | + // TODO Auto-generated method stub | ||
131 | + return null; | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { | ||
136 | + // TODO Auto-generated method stub | ||
137 | + return null; | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public Collection<Tunnel> queryAllTunnels() { | ||
142 | + // TODO Auto-generated method stub | ||
143 | + return null; | ||
144 | + } | ||
145 | + | ||
146 | + @Override | ||
147 | + public int tunnelCount() { | ||
148 | + // TODO Auto-generated method stub | ||
149 | + return 0; | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public Iterable<Tunnel> getTunnels(DeviceId deviceId) { | ||
154 | + // TODO Auto-generated method stub | ||
155 | + return null; | ||
156 | + } | ||
157 | + | ||
158 | +} |
... | @@ -56,4 +56,15 @@ public final class PcepAnnotationKeys { | ... | @@ -56,4 +56,15 @@ public final class PcepAnnotationKeys { |
56 | * Annotation key for the identification of initiated LSP. | 56 | * Annotation key for the identification of initiated LSP. |
57 | */ | 57 | */ |
58 | public static final String PCE_INIT = "pceInit"; | 58 | public static final String PCE_INIT = "pceInit"; |
59 | + | ||
60 | + /** | ||
61 | + * Annotation key for the cost type. | ||
62 | + */ | ||
63 | + public static final String COST_TYPE = "costType"; | ||
64 | + | ||
65 | + /** | ||
66 | + * Annotation key for the Delegation. | ||
67 | + * Whether LSPs are delegated or not | ||
68 | + */ | ||
69 | + public static final String DELEGATE = "delegate"; | ||
59 | } | 70 | } | ... | ... |
-
Please register or login to post a comment