blob: caa317def508b4c4f6cf276c066c0941b0f500a1 [file] [log] [blame]
cheng fan48e832c2015-05-29 01:54:47 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
cheng fan48e832c2015-05-29 01:54:47 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.provider.pcep.tunnel.impl;
17
chengfan2fff70f2015-08-24 18:20:19 -050018import com.google.common.collect.Maps;
Avantika-Huawei56c11842016-04-28 00:56:56 +053019
cheng fan48e832c2015-05-29 01:54:47 +080020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
chengfan2fff70f2015-08-24 18:20:19 -050023import org.apache.felix.scr.annotations.Property;
cheng fan48e832c2015-05-29 01:54:47 +080024import org.apache.felix.scr.annotations.Reference;
25import org.apache.felix.scr.annotations.ReferenceCardinality;
26import org.apache.felix.scr.annotations.Service;
Priyanka Bcdf9b102016-06-07 20:01:38 +053027import org.onlab.packet.Ip4Address;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053028import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050029import org.onosproject.cfg.ComponentConfigService;
cheng fan48e832c2015-05-29 01:54:47 +080030import org.onosproject.core.DefaultGroupId;
Avantika-Huaweif849aab2016-06-21 22:29:15 +053031import org.onosproject.incubator.net.resource.label.LabelResourceId;
32import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
cheng fan48e832c2015-05-29 01:54:47 +080033import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053034import org.onosproject.incubator.net.tunnel.DefaultTunnel;
cheng fan48e832c2015-05-29 01:54:47 +080035import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
chengfan2fff70f2015-08-24 18:20:19 -050036import org.onosproject.incubator.net.tunnel.DefaultTunnelStatistics;
Jonathan Hart51539b82015-10-29 09:53:04 -070037import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
cheng fan48e832c2015-05-29 01:54:47 +080038import org.onosproject.incubator.net.tunnel.OpticalLogicId;
39import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
40import org.onosproject.incubator.net.tunnel.Tunnel;
Avantika-Huawei56c11842016-04-28 00:56:56 +053041import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B413fbe82016-05-26 11:44:45 +053042import org.onosproject.incubator.net.tunnel.TunnelAdminService;
cheng fan48e832c2015-05-29 01:54:47 +080043import org.onosproject.incubator.net.tunnel.TunnelDescription;
44import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
45import org.onosproject.incubator.net.tunnel.TunnelId;
46import org.onosproject.incubator.net.tunnel.TunnelName;
47import org.onosproject.incubator.net.tunnel.TunnelProvider;
48import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
49import org.onosproject.incubator.net.tunnel.TunnelProviderService;
chengfan2fff70f2015-08-24 18:20:19 -050050import org.onosproject.incubator.net.tunnel.TunnelService;
51import org.onosproject.incubator.net.tunnel.TunnelStatistics;
Priyanka B413fbe82016-05-26 11:44:45 +053052import org.onosproject.mastership.MastershipService;
53import org.onosproject.net.AnnotationKeys;
cheng fan48e832c2015-05-29 01:54:47 +080054import org.onosproject.net.ConnectPoint;
55import org.onosproject.net.DefaultAnnotations;
Avantika-Huawei56c11842016-04-28 00:56:56 +053056import org.onosproject.net.DefaultAnnotations.Builder;
cheng fan48e832c2015-05-29 01:54:47 +080057import org.onosproject.net.DefaultLink;
58import org.onosproject.net.DefaultPath;
Priyanka B413fbe82016-05-26 11:44:45 +053059import org.onosproject.net.Device;
cheng fan48e832c2015-05-29 01:54:47 +080060import org.onosproject.net.DeviceId;
61import org.onosproject.net.ElementId;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053062import org.onosproject.net.IpElementId;
cheng fan48e832c2015-05-29 01:54:47 +080063import org.onosproject.net.Link;
Avantika-Huaweif849aab2016-06-21 22:29:15 +053064import org.onosproject.net.NetworkResource;
cheng fan48e832c2015-05-29 01:54:47 +080065import org.onosproject.net.Path;
66import org.onosproject.net.PortNumber;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053067import org.onosproject.net.SparseAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053068import org.onosproject.net.device.DeviceService;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053069import org.onosproject.net.link.LinkService;
cheng fan48e832c2015-05-29 01:54:47 +080070import org.onosproject.net.provider.AbstractProvider;
71import org.onosproject.net.provider.ProviderId;
72import org.onosproject.pcep.api.PcepController;
73import org.onosproject.pcep.api.PcepDpid;
74import org.onosproject.pcep.api.PcepHopNodeDescription;
75import org.onosproject.pcep.api.PcepOperator.OperationType;
76import org.onosproject.pcep.api.PcepTunnel;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053077import org.onosproject.pcep.api.PcepTunnel.PathState;
Jonathan Hart51539b82015-10-29 09:53:04 -070078import org.onosproject.pcep.api.PcepTunnel.PathType;
cheng fan48e832c2015-05-29 01:54:47 +080079import org.onosproject.pcep.api.PcepTunnelListener;
chengfan2fff70f2015-08-24 18:20:19 -050080import org.onosproject.pcep.api.PcepTunnelStatistics;
Priyanka B413fbe82016-05-26 11:44:45 +053081import org.onosproject.pcep.controller.LspKey;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +053082import org.onosproject.pcep.controller.LspType;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053083import org.onosproject.pcep.controller.PccId;
84import org.onosproject.pcep.controller.PcepClient;
85import org.onosproject.pcep.controller.PcepClientController;
86import org.onosproject.pcep.controller.PcepClientListener;
87import org.onosproject.pcep.controller.PcepEventListener;
Priyanka B259847d2016-06-03 21:28:35 +053088import org.onosproject.pcep.controller.PcepLspStatus;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053089import org.onosproject.pcep.controller.PcepLspSyncAction;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +053090import org.onosproject.pcep.controller.SrpIdGenerators;
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +053091import org.onosproject.pcep.controller.PcepSyncStatus;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053092import org.onosproject.pcepio.exceptions.PcepParseException;
93import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
94import org.onosproject.pcepio.protocol.PcepAttribute;
95import org.onosproject.pcepio.protocol.PcepBandwidthObject;
96import org.onosproject.pcepio.protocol.PcepEndPointsObject;
97import org.onosproject.pcepio.protocol.PcepEroObject;
98import org.onosproject.pcepio.protocol.PcepInitiateMsg;
99import org.onosproject.pcepio.protocol.PcepLspObject;
100import org.onosproject.pcepio.protocol.PcepMessage;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530101import org.onosproject.pcepio.protocol.PcepMetricObject;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530102import org.onosproject.pcepio.protocol.PcepMsgPath;
103import org.onosproject.pcepio.protocol.PcepReportMsg;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530104import org.onosproject.pcepio.protocol.PcepSrpObject;
105import org.onosproject.pcepio.protocol.PcepStateReport;
106import org.onosproject.pcepio.protocol.PcepUpdateMsg;
107import org.onosproject.pcepio.protocol.PcepUpdateRequest;
108import org.onosproject.pcepio.types.IPv4SubObject;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530109import org.onosproject.pcepio.types.PathSetupTypeTlv;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530110import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530111import org.onosproject.pcepio.types.PcepValueType;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530112import org.onosproject.pcepio.types.SrEroSubObject;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530113import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530114import org.onosproject.pcepio.types.SymbolicPathNameTlv;
chengfan2fff70f2015-08-24 18:20:19 -0500115import org.osgi.service.component.ComponentContext;
Jonathan Hart51539b82015-10-29 09:53:04 -0700116import org.osgi.service.component.annotations.Modified;
117import org.slf4j.Logger;
118
119import java.util.ArrayList;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530120import java.util.Arrays;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530121import java.util.Collection;
Jonathan Hart51539b82015-10-29 09:53:04 -0700122import java.util.Collections;
123import java.util.Dictionary;
124import java.util.HashMap;
125import java.util.LinkedList;
126import java.util.List;
127import java.util.ListIterator;
Sho SHIMIZUc218bfa2016-08-18 14:22:50 -0700128import java.util.Objects;
Jonathan Hart51539b82015-10-29 09:53:04 -0700129import java.util.Optional;
Priyanka B413fbe82016-05-26 11:44:45 +0530130import java.util.concurrent.Executors;
131import java.util.concurrent.ScheduledExecutorService;
132import java.util.concurrent.TimeUnit;
Jonathan Hart51539b82015-10-29 09:53:04 -0700133
134import static com.google.common.base.Preconditions.checkNotNull;
135import static com.google.common.base.Strings.isNullOrEmpty;
136import static org.onlab.util.Tools.get;
Priyanka B4c3cef02016-06-14 20:27:53 +0530137import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530138import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
Jonathan Hart51539b82015-10-29 09:53:04 -0700139import static org.onosproject.net.DefaultAnnotations.EMPTY;
140import static org.onosproject.net.DeviceId.deviceId;
141import static org.onosproject.net.PortNumber.portNumber;
142import static org.onosproject.pcep.api.PcepDpid.uri;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530143import static org.onosproject.pcep.controller.LspType.WITH_SIGNALLING;
144import static org.onosproject.pcep.controller.LspType.SR_WITHOUT_SIGNALLING;
145import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530146import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
147import static org.onosproject.pcep.controller.PcepAnnotationKeys.LOCAL_LSP_ID;
148import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
149import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCC_TUNNEL_ID;
Priyanka B4c3cef02016-06-14 20:27:53 +0530150import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530151import static org.onosproject.pcep.controller.PcepAnnotationKeys.PLSP_ID;
152import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
153import static org.onosproject.pcep.controller.PcepAnnotationKeys.COST_TYPE;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530154import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
155import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
156import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
157import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530158import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530159import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
160import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530161import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.IGP_METRIC;
162import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.TE_METRIC;
Jonathan Hart51539b82015-10-29 09:53:04 -0700163import static org.slf4j.LoggerFactory.getLogger;
cheng fan48e832c2015-05-29 01:54:47 +0800164
165/**
166 * Provider which uses an PCEP controller to detect, update, create network
167 * tunnels.
168 */
169@Component(immediate = true)
170@Service
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530171public class PcepTunnelProvider extends AbstractProvider implements TunnelProvider {
cheng fan48e832c2015-05-29 01:54:47 +0800172
173 private static final Logger log = getLogger(PcepTunnelProvider.class);
174 private static final long MAX_BANDWIDTH = 99999744;
175 private static final long MIN_BANDWIDTH = 64;
cheng fan7716ec92015-05-31 01:53:19 +0800176 private static final String BANDWIDTH_UINT = "kbps";
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530177 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka B413fbe82016-05-26 11:44:45 +0530178 public static final long IDENTIFIER_SET = 0x100000000L;
179 public static final long SET = 0xFFFFFFFFL;
180 private static final int DELAY = 2;
181 private static final int WAIT_TIME = 5;
182 public static final String LSRID = "lsrId";
cheng fan48e832c2015-05-29 01:54:47 +0800183
chengfan2fff70f2015-08-24 18:20:19 -0500184 static final int POLL_INTERVAL = 10;
185 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL,
186 label = "Frequency (in seconds) for polling tunnel statistics")
187 private int tunnelStatsPollFrequency = POLL_INTERVAL;
188
cheng fan48e832c2015-05-29 01:54:47 +0800189 private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied.";
190
191 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
192 protected TunnelProviderRegistry tunnelProviderRegistry;
193
194 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
195 protected PcepController controller;
196
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530197 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
198 protected PcepClientController pcepClientController;
chengfan2fff70f2015-08-24 18:20:19 -0500199
200 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
201 protected TunnelService tunnelService;
202
203 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
204 protected ComponentConfigService cfgService;
205
Priyanka B413fbe82016-05-26 11:44:45 +0530206 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
207 protected TunnelAdminService tunnelAdminService;
208
209 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
210 protected MastershipService mastershipService;
211
212 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
213 protected DeviceService deviceService;
214
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530215 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
216 protected LinkService linkService;
217
cheng fan48e832c2015-05-29 01:54:47 +0800218 TunnelProviderService service;
219
220 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
chengfan2fff70f2015-08-24 18:20:19 -0500221 HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>();
Brian Stanke9a108972016-04-11 15:25:17 -0400222 private HashMap<String, TunnelStatsCollector> collectors = Maps.newHashMap();
cheng fan48e832c2015-05-29 01:54:47 +0800223
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530224 private InnerTunnelProvider listener = new InnerTunnelProvider();
225
Jonathan Hart51539b82015-10-29 09:53:04 -0700226 protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper();
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530227 private static final int DEFAULT_BANDWIDTH_VALUE = 10;
cheng fan48e832c2015-05-29 01:54:47 +0800228
229 /**
230 * Creates a Tunnel provider.
231 */
232 public PcepTunnelProvider() {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530233 super(new ProviderId("pcep", PROVIDER_ID));
cheng fan48e832c2015-05-29 01:54:47 +0800234 }
235
236 @Activate
237 public void activate() {
chengfan2fff70f2015-08-24 18:20:19 -0500238 cfgService.registerProperties(getClass());
cheng fan48e832c2015-05-29 01:54:47 +0800239 service = tunnelProviderRegistry.register(this);
240 controller.addTunnelListener(listener);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530241 pcepClientController.addListener(listener);
242 pcepClientController.addEventListener(listener);
chengfan2fff70f2015-08-24 18:20:19 -0500243 tunnelService.queryAllTunnels().forEach(tunnel -> {
Jonathan Hart51539b82015-10-29 09:53:04 -0700244 String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
chengfan2fff70f2015-08-24 18:20:19 -0500245 TunnelStatsCollector tsc = new TunnelStatsCollector(pcepTunnelId, tunnelStatsPollFrequency);
246 tsc.start();
247 collectors.put(tunnel.tunnelId().id(), tsc);
248
249 });
250
cheng fan48e832c2015-05-29 01:54:47 +0800251 log.info("Started");
252 }
253
254 @Deactivate
255 public void deactivate() {
256 tunnelProviderRegistry.unregister(this);
257 controller.removeTunnelListener(listener);
chengfan2fff70f2015-08-24 18:20:19 -0500258 collectors.values().forEach(TunnelStatsCollector::stop);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530259 pcepClientController.removeListener(listener);
cheng fan48e832c2015-05-29 01:54:47 +0800260 log.info("Stopped");
261 }
262
chengfan2fff70f2015-08-24 18:20:19 -0500263 @Modified
264 public void modified(ComponentContext context) {
265 Dictionary<?, ?> properties = context.getProperties();
266 int newTunnelStatsPollFrequency;
267 try {
268 String s = get(properties, "tunnelStatsPollFrequency");
269 newTunnelStatsPollFrequency = isNullOrEmpty(s) ? tunnelStatsPollFrequency : Integer.parseInt(s.trim());
270
271 } catch (NumberFormatException | ClassCastException e) {
272 newTunnelStatsPollFrequency = tunnelStatsPollFrequency;
273 }
274
275 if (newTunnelStatsPollFrequency != tunnelStatsPollFrequency) {
276 tunnelStatsPollFrequency = newTunnelStatsPollFrequency;
277 collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency));
278 log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency);
279 }
chengfan2fff70f2015-08-24 18:20:19 -0500280 }
281
cheng fan48e832c2015-05-29 01:54:47 +0800282 @Override
283 public void setupTunnel(Tunnel tunnel, Path path) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530284 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530285 log.error("Tunnel Type MPLS is only supported");
286 return;
287 }
cheng fan48e832c2015-05-29 01:54:47 +0800288
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530289 // check for tunnel end points
290 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
291 log.error("Tunnel source or destination is not valid");
292 return;
293 }
294
295 // Get the pcc client
296 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
297
298 if (!(pc instanceof PcepClient)) {
299 log.error("There is no PCC connected with ip addresss {}"
chengfan2fff70f2015-08-24 18:20:19 -0500300 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530301 return;
302 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530303
304 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
Priyanka B413fbe82016-05-26 11:44:45 +0530305 //Only master will initiate setup tunnel
306 if (pc.capability().pcInstantiationCapability() && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530307 pcepSetupTunnel(tunnel, path, pc);
308 }
cheng fan48e832c2015-05-29 01:54:47 +0800309 }
310
311 @Override
312 public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
cheng fan48e832c2015-05-29 01:54:47 +0800313
Priyanka B4c3cef02016-06-14 20:27:53 +0530314 //TODO: tunnel which is passed doesn't have tunnelID
Avantika-Huawei56c11842016-04-28 00:56:56 +0530315 if (tunnel.annotations().value(PLSP_ID) != null) {
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530316 if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530317 updateTunnel(tunnel, path);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530318 } else {
319 // Download labels and send update message.
320 // To get new tunnel ID (modified tunnel ID)
321 Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
322 for (Tunnel t : tunnels) {
323 if (t.state().equals(INIT) && t.tunnelName().equals(tunnel.tunnelName())) {
324 tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
325 tunnel.dst(), tunnel.type(),
326 t.state(), tunnel.groupId(),
327 t.tunnelId(),
328 tunnel.tunnelName(),
329 tunnel.path(),
330 tunnel.resource(),
331 tunnel.annotations());
332 break;
333 }
334 }
335 if (!pcepClientController.allocateLocalLabel(tunnel)) {
336 log.error("Unable to allocate labels for the tunnel {}.", tunnel.toString());
337 }
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530338 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530339 return;
340 }
341
342 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530343 log.error("Tunnel Type MPLS is only supported");
344 return;
345 }
346
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530347 // check for tunnel end points
348 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
349 log.error("Tunnel source or destination is not valid");
350 return;
351 }
352
Priyanka Bcdf9b102016-06-07 20:01:38 +0530353 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530354
355 if (!(pc instanceof PcepClient)) {
Priyanka B4c3cef02016-06-14 20:27:53 +0530356 log.error("There is no PCC connected with this device {}"
357 + srcElement.toString());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530358 return;
359 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530360
Priyanka B413fbe82016-05-26 11:44:45 +0530361 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
362 //Only master will initiate setup tunnel
363 if (pc.capability().pcInstantiationCapability()
364 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530365 pcepSetupTunnel(tunnel, path, pc);
366 }
cheng fan48e832c2015-05-29 01:54:47 +0800367 }
368
369 @Override
370 public void releaseTunnel(Tunnel tunnel) {
cheng fan48e832c2015-05-29 01:54:47 +0800371
Avantika-Huawei56c11842016-04-28 00:56:56 +0530372 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530373 log.error("Tunnel Type MPLS is only supported");
374 return;
375 }
376
377 // check for tunnel end points
378 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
379 log.error("Tunnel source or destination is not valid");
380 return;
381 }
382
383 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
384
385 if (!(pc instanceof PcepClient)) {
386 log.error("There is no PCC connected with ip addresss {}"
387 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
388 return;
389 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530390
Priyanka B413fbe82016-05-26 11:44:45 +0530391 //Only master will release tunnel
392 if (pc.capability().pcInstantiationCapability()
393 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530394 pcepReleaseTunnel(tunnel, pc);
395 }
cheng fan48e832c2015-05-29 01:54:47 +0800396 }
397
398 @Override
399 public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530400 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530401 log.error("Tunnel Type MPLS is only supported");
402 return;
403 }
cheng fan48e832c2015-05-29 01:54:47 +0800404
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530405 if (!(srcElement instanceof IpElementId)) {
406 log.error("Element id is not valid");
407 return;
408 }
409
410 // check for tunnel end points
411 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
412 log.error("Tunnel source or destination is not valid");
413 return;
414 }
415
416 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress()));
417
418 if (!(pc instanceof PcepClient)) {
419 log.error("There is no PCC connected with ip addresss {}"
420 + ((IpElementId) srcElement).ipAddress().toString());
421 return;
422 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530423
Priyanka B413fbe82016-05-26 11:44:45 +0530424 //Only master will release tunnel
425 if (pc.capability().pcInstantiationCapability()
426 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530427 pcepReleaseTunnel(tunnel, pc);
428 }
cheng fan48e832c2015-05-29 01:54:47 +0800429 }
430
431 @Override
432 public void updateTunnel(Tunnel tunnel, Path path) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530433 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530434 log.error("Tunnel Type MPLS is only supported");
435 return;
436 }
cheng fan48e832c2015-05-29 01:54:47 +0800437
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530438 // check for tunnel end points
439 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
440 log.error("Tunnel source or destination is not valid");
441 return;
442 }
443
Priyanka B4c3cef02016-06-14 20:27:53 +0530444 //To get new tunnel ID (modified tunnel ID)
445 Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
446 for (Tunnel t : tunnels) {
447 if (t.state().equals(INIT) && t.tunnelName().equals(tunnel.tunnelName())) {
448 tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
449 tunnel.dst(), tunnel.type(),
450 t.state(), tunnel.groupId(),
451 t.tunnelId(),
452 tunnel.tunnelName(),
453 tunnel.path(),
454 tunnel.resource(),
455 tunnel.annotations());
456 break;
457 }
458 }
459
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530460 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
461
462 if (!(pc instanceof PcepClient)) {
463 log.error("There is no PCC connected with ip addresss {}"
464 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
465 return;
466 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530467
Priyanka B4c3cef02016-06-14 20:27:53 +0530468 //PCInitiate tunnels are always have D flag set, else check for tunnels who are delegated via LspKey
469 if (pc.capability().statefulPceCapability()) {
470 if (tunnel.annotations().value(PCE_INIT) != null && tunnel.annotations().value(PCE_INIT).equals("true")) {
471 pcepUpdateTunnel(tunnel, path, pc);
Priyanka B4c3b4512016-07-22 11:41:49 +0530472 } else {
473 // If delegation flag is set then only send update message[means delegated PCE can send update msg for
474 // that LSP. If annotation is null D flag is not set else it is set.
475 Short localLspId = 0;
476 for (Tunnel t : tunnels) {
477 if (!t.tunnelId().equals(tunnel.tunnelId()) && t.tunnelName().equals(tunnel.tunnelName())) {
478 localLspId = Short.valueOf(t.annotations().value(LOCAL_LSP_ID));
479 }
480 }
481
482 if (localLspId == 0) {
483 log.error("Local LSP ID for old tunnel not found");
484 return;
485 }
486
487 if (pc.delegationInfo(new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)),
488 localLspId.shortValue())) != null) {
489
490 pcepUpdateTunnel(tunnel, path, pc);
491 }
Priyanka B4c3cef02016-06-14 20:27:53 +0530492 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530493 }
cheng fan48e832c2015-05-29 01:54:47 +0800494 }
495
496 @Override
497 public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
cheng fan48e832c2015-05-29 01:54:47 +0800498
Avantika-Huawei56c11842016-04-28 00:56:56 +0530499 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530500 log.error("Tunnel Type MPLS is only supported");
501 return;
502 }
503
504 if (!(srcElement instanceof IpElementId)) {
505 log.error("Element id is not valid");
506 return;
507 }
508
509 // check for tunnel end points
510 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
511 log.error("Tunnel source or destination is not valid");
512 return;
513 }
514
515 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress()));
516
517 if (!(pc instanceof PcepClient)) {
518 log.error("There is no PCC connected with ip addresss {}"
519 + ((IpElementId) srcElement).ipAddress().toString());
520 return;
521 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530522
Priyanka B413fbe82016-05-26 11:44:45 +0530523 // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
524 // LSP].If annotation is null D flag is not set else it is set.
525 if (pc.capability().statefulPceCapability()
526 && pc.delegationInfo(
527 new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
528 .annotations().value(LOCAL_LSP_ID)))) != null) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530529 pcepUpdateTunnel(tunnel, path, pc);
530 }
cheng fan48e832c2015-05-29 01:54:47 +0800531 }
532
533 @Override
534 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530535 return handleTunnelAdded(tunnel, null);
536 }
537
538 public TunnelId tunnelAdded(TunnelDescription tunnel, State tunnelState) {
539 return handleTunnelAdded(tunnel, tunnelState);
540 }
541
542 private TunnelId handleTunnelAdded(TunnelDescription tunnel, State tunnelState) {
543
544 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700545 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Avantika-Huawei56c11842016-04-28 00:56:56 +0530546
547 if (tunnelState == null) {
548 return service.tunnelAdded(tunnel);
549 } else {
550 return service.tunnelAdded(tunnel, tunnelState);
551 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530552 }
cheng fan48e832c2015-05-29 01:54:47 +0800553
Avantika-Huawei56c11842016-04-28 00:56:56 +0530554 long bandwidth = Long.parseLong(tunnel.annotations().value(BANDWIDTH));
cheng fan48e832c2015-05-29 01:54:47 +0800555
556 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
cheng fan7716ec92015-05-31 01:53:19 +0800557 error("Update failed, invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800558 return null;
559 }
560
561 // endpoints
562 OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel
563 .src();
564 OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst();
565 // devices
566 DeviceId srcId = (DeviceId) src.elementId().get();
567 DeviceId dstId = (DeviceId) dst.elementId().get();
568
569 // ports
570 long srcPort = src.portNumber().get().toLong();
571 long dstPort = dst.portNumber().get().toLong();
572
573 // type
574 if (tunnel.type() != Tunnel.Type.VLAN) {
cheng fan7716ec92015-05-31 01:53:19 +0800575 error("Illegal tunnel type. Only support VLAN tunnel creation.");
cheng fan48e832c2015-05-29 01:54:47 +0800576 return null;
577 }
578
579 PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort,
580 dstPort, bandwidth,
581 tunnel.tunnelName()
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530582 .value());
cheng fan48e832c2015-05-29 01:54:47 +0800583
584 checkNotNull(pcepTunnel, TUNNLE_NOT_NULL);
585 TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null);
586 TunnelId tunnelId = service.tunnelAdded(tunnelAdded);
587
588 tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId);
589 return tunnelId;
590 }
591
Priyanka B4c3b4512016-07-22 11:41:49 +0530592 private void tunnelUpdated(Tunnel tunnel, Path path, State tunnelState) {
593 handleTunnelUpdate(tunnel, path, tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +0530594 }
595
596 //Handles tunnel updated using tunnel admin service[specially to update annotations].
Priyanka B4c3b4512016-07-22 11:41:49 +0530597 private void handleTunnelUpdate(Tunnel tunnel, Path path, State tunnelState) {
Priyanka B413fbe82016-05-26 11:44:45 +0530598
599 if (tunnel.type() == MPLS) {
600 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.tunnelId());
601
Priyanka B4c3b4512016-07-22 11:41:49 +0530602 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
603 tunnel.type(), tunnel.groupId(), tunnel.providerId(),
604 tunnel.tunnelName(), path, tunnel.resource(),
605 (SparseAnnotations) tunnel.annotations());
Priyanka B413fbe82016-05-26 11:44:45 +0530606
Priyanka B4c3b4512016-07-22 11:41:49 +0530607 service.tunnelUpdated(td, tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +0530608 return;
609 }
610
611 Tunnel tunnelOld = tunnelQueryById(tunnel.tunnelId());
612 if (tunnelOld.type() != Tunnel.Type.VLAN) {
613 error("Illegal tunnel type. Only support VLAN tunnel update.");
614 return;
615 }
616
617 long bandwidth = Long
618 .parseLong(tunnel.annotations().value("bandwidth"));
619 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
620 error("Update failed, invalid bandwidth.");
621 return;
622 }
623 String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
624
625 checkNotNull(pcepTunnelId, "Invalid tunnel id");
626 if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
627 error("Update failed,maybe invalid bandwidth.");
628 return;
629 }
630 tunnelAdminService.updateTunnel(tunnel, path);
631 }
632
cheng fan48e832c2015-05-29 01:54:47 +0800633 @Override
634 public void tunnelRemoved(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530635 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700636 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530637 service.tunnelRemoved(tunnel);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530638 return;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530639 }
640
cheng fan48e832c2015-05-29 01:54:47 +0800641 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
642 checkNotNull(tunnelOld, "The tunnel id is not exsited.");
643 if (tunnelOld.type() != Tunnel.Type.VLAN) {
cheng fan93258c72015-06-02 23:42:32 +0800644 error("Illegal tunnel type. Only support VLAN tunnel deletion.");
cheng fan48e832c2015-05-29 01:54:47 +0800645 return;
646 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700647 String pcepTunnelId = getPcepTunnelKey(tunnel.id());
cheng fan48e832c2015-05-29 01:54:47 +0800648 checkNotNull(pcepTunnelId, "The tunnel id is not exsited.");
cheng fan7716ec92015-05-31 01:53:19 +0800649 if (!controller.deleteTunnel(pcepTunnelId)) {
650 error("Delete tunnel failed, Maybe some devices have been disconnected.");
651 return;
cheng fan48e832c2015-05-29 01:54:47 +0800652 }
653 tunnelMap.remove(pcepTunnelId);
654 service.tunnelRemoved(tunnel);
cheng fan48e832c2015-05-29 01:54:47 +0800655 }
656
657 @Override
658 public void tunnelUpdated(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530659 handleTunnelUpdate(tunnel, null);
660 }
661
662 public void tunnelUpdated(TunnelDescription tunnel, State tunnelState) {
663 handleTunnelUpdate(tunnel, tunnelState);
664 }
665
666 private void handleTunnelUpdate(TunnelDescription tunnel, State tunnelState) {
667 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700668 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Avantika-Huawei56c11842016-04-28 00:56:56 +0530669
670 if (tunnelState == null) {
671 service.tunnelUpdated(tunnel);
672 } else {
673 service.tunnelUpdated(tunnel, tunnelState);
674 }
675 return;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530676 }
cheng fan48e832c2015-05-29 01:54:47 +0800677
678 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
679 if (tunnelOld.type() != Tunnel.Type.VLAN) {
cheng fan93258c72015-06-02 23:42:32 +0800680 error("Illegal tunnel type. Only support VLAN tunnel update.");
cheng fan48e832c2015-05-29 01:54:47 +0800681 return;
682 }
cheng fan7716ec92015-05-31 01:53:19 +0800683 long bandwidth = Long
684 .parseLong(tunnel.annotations().value("bandwidth"));
cheng fan48e832c2015-05-29 01:54:47 +0800685 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
cheng fan7716ec92015-05-31 01:53:19 +0800686 error("Update failed, invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800687 return;
688 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700689 String pcepTunnelId = getPcepTunnelKey(tunnel.id());
cheng fan48e832c2015-05-29 01:54:47 +0800690
691 checkNotNull(pcepTunnelId, "Invalid tunnel id");
692 if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
693
cheng fan7716ec92015-05-31 01:53:19 +0800694 error("Update failed,maybe invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800695 return;
696
697 }
698 service.tunnelUpdated(tunnel);
699 }
700
cheng fan7716ec92015-05-31 01:53:19 +0800701 private void error(String info) {
702 System.err.println(info);
703 }
704
cheng fan48e832c2015-05-29 01:54:47 +0800705 // Short-hand for creating a connection point.
706 private ConnectPoint connectPoint(PcepDpid id, long port) {
707 return new ConnectPoint(deviceId(uri(id)), portNumber(port));
708 }
709
710 // Short-hand for creating a link.
711 private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
Ray Milkey2693bda2016-01-22 16:08:14 -0800712 return DefaultLink.builder()
713 .providerId(id())
714 .src(connectPoint(src, sp))
715 .dst(connectPoint(dst, dp))
716 .type(Link.Type.TUNNEL)
717 .build();
cheng fan48e832c2015-05-29 01:54:47 +0800718 }
719
720 // Creates a path that leads through the given devices.
721 private Path createPath(List<PcepHopNodeDescription> hopList,
Jonathan Hart51539b82015-10-29 09:53:04 -0700722 PathType pathtype, PathState pathState) {
Jon Hallcbd1b392017-01-18 20:15:44 -0800723 if (hopList == null || hopList.isEmpty()) {
cheng fan48e832c2015-05-29 01:54:47 +0800724 return null;
725 }
726 List<Link> links = new ArrayList<>();
727 for (int i = 1; i < hopList.size() - 1; i = i + 2) {
728 links.add(link(hopList.get(i).getDeviceId(), hopList.get(i)
729 .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList
730 .get(i + 1).getPortNum()));
731 }
732
733 int hopNum = hopList.size() - 2;
734 DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
735 .set("pathNum", String.valueOf(hopNum))
cheng fan93258c72015-06-02 23:42:32 +0800736 .set("pathState", String.valueOf(pathState))
cheng fan48e832c2015-05-29 01:54:47 +0800737 .set("pathType", String.valueOf(pathtype)).build();
738 return new DefaultPath(id(), links, hopNum, extendAnnotations);
739 }
740
741 // convert the path description to a string.
742 public String pathToString(List<Link> links) {
743 StringBuilder builder = new StringBuilder();
744 builder.append("{");
745 for (Link link : links) {
746 builder.append("(Device:" + link.src().deviceId() + " Port:"
747 + link.src().port().toLong());
748 builder.append(" Device:" + link.dst().deviceId() + " Port:"
749 + link.dst().port().toLong());
750 builder.append(")");
751 }
752 builder.append("}");
753 return builder.toString();
754 }
755
756 // build a TunnelDescription.
757 private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel,
758 TunnelId tunnelId) {
759 TunnelEndPoint srcPoint = null;
760 TunnelEndPoint dstPoint = null;
761 Tunnel.Type tunnelType = null;
762 TunnelName name = TunnelName.tunnelName(pcepTunnel.name());
763
764 // add path after codes of tunnel's path merged
765 Path path = createPath(pcepTunnel.getHopList(),
cheng fan93258c72015-06-02 23:42:32 +0800766 pcepTunnel.getPathType(),
767 pcepTunnel.getPathState());
cheng fan48e832c2015-05-29 01:54:47 +0800768
769 OpticalTunnelEndPoint.Type endPointType = null;
770 switch (pcepTunnel.type()) {
771 case OCH:
772 tunnelType = Tunnel.Type.OCH;
773 endPointType = OpticalTunnelEndPoint.Type.LAMBDA;
774 break;
775
776 case OTN:
777 tunnelType = Tunnel.Type.ODUK;
778 endPointType = OpticalTunnelEndPoint.Type.TIMESLOT;
779 break;
780
781 case UNI:
782 tunnelType = Tunnel.Type.VLAN;
783 endPointType = null;
784 break;
785
786 default:
787 break;
788 }
789 DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID()));
790 DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId()));
791 PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort());
792 PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort());
793
794 srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid),
795 Optional.of(srcPort), null,
796 endPointType,
797 OpticalLogicId.logicId(0),
798 true);
799 dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid),
800 Optional.of(dstPort), null,
801 endPointType,
802 OpticalLogicId.logicId(0),
803 true);
804
805 // basic annotations
cheng fan7716ec92015-05-31 01:53:19 +0800806 DefaultAnnotations annotations = DefaultAnnotations
807 .builder()
cheng fan48e832c2015-05-29 01:54:47 +0800808 .set("SLA", String.valueOf(pcepTunnel.getSla()))
cheng fan7716ec92015-05-31 01:53:19 +0800809 .set("bandwidth",
810 String.valueOf(pcepTunnel.bandWidth()) + BANDWIDTH_UINT)
cheng fan48e832c2015-05-29 01:54:47 +0800811 .set("index", String.valueOf(pcepTunnel.id())).build();
812
cheng fan48e832c2015-05-29 01:54:47 +0800813 // a VLAN tunnel always carry OCH tunnel, this annotation is the index
814 // of a OCH tunnel.
cheng fan93258c72015-06-02 23:42:32 +0800815 if (pcepTunnel.underlayTunnelId() != 0) {
cheng fan48e832c2015-05-29 01:54:47 +0800816 DefaultAnnotations extendAnnotations = DefaultAnnotations
817 .builder()
818 .set("underLayTunnelIndex",
cheng fan93258c72015-06-02 23:42:32 +0800819 String.valueOf(pcepTunnel.underlayTunnelId())).build();
cheng fan48e832c2015-05-29 01:54:47 +0800820 annotations = DefaultAnnotations.merge(annotations,
821 extendAnnotations);
822
823 }
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530824 TunnelDescription tunnel = new DefaultTunnelDescription(tunnelId,
cheng fan48e832c2015-05-29 01:54:47 +0800825 srcPoint,
826 dstPoint,
827 tunnelType,
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530828 new DefaultGroupId(0),
cheng fan48e832c2015-05-29 01:54:47 +0800829 id(), name,
830 path,
831 annotations);
832 return tunnel;
cheng fan48e832c2015-05-29 01:54:47 +0800833 }
834
835 /**
836 * Get the tunnelID according to the tunnel key.
837 *
838 * @param tunnelKey tunnel key
839 * @return corresponding tunnel id of the a tunnel key.
840 */
841 private TunnelId getTunnelId(String tunnelKey) {
cheng fan48e832c2015-05-29 01:54:47 +0800842 for (String key : tunnelMap.keySet()) {
843 if (key.equals(tunnelKey)) {
844 return tunnelMap.get(key);
845 }
846 }
847 return null;
848 }
849
850 /**
851 * Get the tunnel key according to the tunnelID.
852 *
853 * @param tunnelId tunnel id
854 * @return corresponding a tunnel key of the tunnel id.
855 */
Jonathan Hart51539b82015-10-29 09:53:04 -0700856 private String getPcepTunnelKey(TunnelId tunnelId) {
cheng fan48e832c2015-05-29 01:54:47 +0800857 for (String key : tunnelMap.keySet()) {
Sho SHIMIZUc218bfa2016-08-18 14:22:50 -0700858 if (Objects.equals(tunnelMap.get(key).id(), tunnelId.id())) {
cheng fan48e832c2015-05-29 01:54:47 +0800859 return key;
860 }
861 }
862 return null;
863
864 }
865
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530866 /**
chengfan2fff70f2015-08-24 18:20:19 -0500867 * Build a DefaultTunnelStatistics from a PcepTunnelStatistics.
868 *
869 * @param statistics statistics data from a PCEP tunnel
870 * @return TunnelStatistics
871 */
872 private TunnelStatistics buildTunnelStatistics(PcepTunnelStatistics statistics) {
873 DefaultTunnelStatistics.Builder builder = new DefaultTunnelStatistics.Builder();
874 DefaultTunnelStatistics tunnelStatistics = builder.setBwUtilization(statistics.bandwidthUtilization())
875 .setPacketLossRatio(statistics.packetLossRate())
876 .setFlowDelay(statistics.flowDelay())
877 .setAlarms(statistics.alarms())
878 .build();
879 return tunnelStatistics;
880 }
881 /**
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530882 * Creates list of hops for ERO object from Path.
883 *
884 * @param path network path
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530885 * @return list of ERO subobjects
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530886 */
887 private LinkedList<PcepValueType> createPcepPath(Path path) {
888 LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
889 List<Link> listLink = path.links();
890 ConnectPoint source = null;
891 ConnectPoint destination = null;
892 IpAddress ipDstAddress = null;
893 IpAddress ipSrcAddress = null;
894 PcepValueType subObj = null;
Priyanka Bcdf9b102016-06-07 20:01:38 +0530895 long portNo;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530896
897 for (Link link : listLink) {
898 source = link.src();
899 if (!(source.equals(destination))) {
900 //set IPv4SubObject for ERO object
Priyanka Bcdf9b102016-06-07 20:01:38 +0530901 portNo = source.port().toLong();
902 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
903 ipSrcAddress = Ip4Address.valueOf((int) portNo);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530904 subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
905 llSubObjects.add(subObj);
906 }
907
908 destination = link.dst();
Priyanka Bcdf9b102016-06-07 20:01:38 +0530909 portNo = destination.port().toLong();
910 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
911 ipDstAddress = Ip4Address.valueOf((int) portNo);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530912 subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
913 llSubObjects.add(subObj);
914 }
Priyanka Bcdf9b102016-06-07 20:01:38 +0530915
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530916 return llSubObjects;
917 }
918
919 /**
920 * Creates PcInitiated lsp request list for setup tunnel.
921 *
922 * @param tunnel mpls tunnel
923 * @param path network path
924 * @param pc pcep client
925 * @param srpId unique id for pcep message
926 * @return list of PcInitiatedLspRequest
927 * @throws PcepParseException while building pcep objects fails
928 */
929 LinkedList<PcInitiatedLspRequest> createPcInitiatedLspReqList(Tunnel tunnel, Path path,
930 PcepClient pc, int srpId)
931 throws PcepParseException {
932 PcepValueType tlv;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530933 LinkedList<PcepValueType> llSubObjects = null;
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530934 LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530935
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530936 if (lspType == SR_WITHOUT_SIGNALLING) {
937 NetworkResource labelStack = tunnel.resource();
938 if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) {
939 labelStack = pcepClientController.computeLabelStack(tunnel.path());
940 if (labelStack == null) {
941 log.error("Unable to create label stack.");
942 return null;
943 }
944 }
945 llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path);
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530946 } else {
947 llSubObjects = createPcepPath(path);
948 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530949
Jon Hallcbd1b392017-01-18 20:15:44 -0800950 if (llSubObjects == null || llSubObjects.isEmpty()) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530951 log.error("There is no link information to create tunnel");
952 return null;
953 }
954
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530955 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530956
957 // set PathSetupTypeTlv of SRP object
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530958 tlv = new PathSetupTypeTlv(lspType.type());
Avantika-Huawei56c11842016-04-28 00:56:56 +0530959 llOptionalTlv.add(tlv);
960
961 // build SRP object
962 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
963 .setOptionalTlv(llOptionalTlv).build();
964
965 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530966 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530967
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530968 // set LSP identifiers TLV
Avantika-Huawei56c11842016-04-28 00:56:56 +0530969 short localLspId = 0;
970 if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITH_SIGNALLING) {
971 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
972 if (localLspIdString != null) {
973 localLspId = Short.valueOf(localLspIdString);
974 }
975 }
976
Priyanka B4c3cef02016-06-14 20:27:53 +0530977 tunnel.annotations().value(LSP_SIG_TYPE);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530978 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
979 localLspId, (short) 0, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
980 .getIp4Address().toInt()));
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530981 llOptionalTlv.add(tlv);
982 //set SymbolicPathNameTlv of LSP object
983 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
984 llOptionalTlv.add(tlv);
985
986 //build LSP object
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530987 PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setDFlag(true).setOFlag((byte) 0)
988 .setPlspId(0).setOptionalTlv(llOptionalTlv).build();
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530989
990 //build ENDPOINTS object
991 PcepEndPointsObject endpointsobj = pc.factory().buildEndPointsObject()
992 .setSourceIpAddress(((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt())
993 .setDestIpAddress(((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())
994 .setPFlag(true).build();
995
996 //build ERO object
997 PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
998
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530999 float iBandwidth = DEFAULT_BANDWIDTH_VALUE;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301000 if (tunnel.annotations().value(BANDWIDTH) != null) {
Priyanka Bc1e4e4c2016-07-01 14:57:19 +05301001 iBandwidth = Float.valueOf(tunnel.annotations().value(BANDWIDTH));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301002 }
1003 // build bandwidth object
1004 PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
1005 // build pcep attribute
1006 PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build();
1007
1008 PcInitiatedLspRequest initiateLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj)
1009 .setLspObject(lspobj).setEndPointsObject(endpointsobj).setEroObject(eroobj)
1010 .setPcepAttribute(pcepAttribute).build();
1011 llPcInitiatedLspRequestList.add(initiateLspRequest);
1012 return llPcInitiatedLspRequestList;
1013 }
1014
1015 /**
1016 * To send initiate tunnel message to pcc.
1017 *
1018 * @param tunnel mpls tunnel info
1019 * @param path explicit route for the tunnel
1020 * @param pc pcep client to send message
1021 */
1022 private void pcepSetupTunnel(Tunnel tunnel, Path path, PcepClient pc) {
1023 try {
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +05301024 if (!(pc.lspDbSyncStatus().equals(PcepSyncStatus.SYNCED))) {
1025 log.error("Setup tunnel has failed as LSP DB sync is not finished");
1026 return;
1027 }
1028
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301029 int srpId = SrpIdGenerators.create();
Priyanka B4c3cef02016-06-14 20:27:53 +05301030 Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
1031 for (Tunnel t : tunnels) {
1032 if (t.tunnelName().equals(tunnel.tunnelName())) {
1033 tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
1034 tunnel.dst(), tunnel.type(),
1035 t.state(), tunnel.groupId(),
1036 t.tunnelId(),
1037 tunnel.tunnelName(),
1038 tunnel.path(),
1039 tunnel.resource(),
1040 tunnel.annotations());
Priyanka B4c3b4512016-07-22 11:41:49 +05301041 break;
Priyanka B4c3cef02016-06-14 20:27:53 +05301042 }
1043 }
1044
1045 if (tunnel.tunnelId() == null) {
1046 log.error("Tunnel ID not found");
1047 return;
1048 }
1049
Avantika-Huawei56c11842016-04-28 00:56:56 +05301050 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, CREATE);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301051
Jonathan Hart51539b82015-10-29 09:53:04 -07001052 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301053
1054 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = createPcInitiatedLspReqList(tunnel, path,
1055 pc, srpId);
Jon Hallcbd1b392017-01-18 20:15:44 -08001056 if (llPcInitiatedLspRequestList == null || llPcInitiatedLspRequestList.isEmpty()) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301057 log.error("Failed to create PcInitiatedLspRequestList");
1058 return;
1059 }
1060
1061 //build PCInitiate message
1062 PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
1063 .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList)
1064 .build();
1065
1066 pc.sendMessage(Collections.singletonList(pcInitiateMsg));
1067
Jonathan Hart51539b82015-10-29 09:53:04 -07001068 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301069 } catch (PcepParseException e) {
1070 log.error("PcepParseException occurred while processing setup tunnel {}", e.getMessage());
1071 }
1072 }
1073
1074 /**
1075 * To send Release tunnel message to pcc.
1076 *
1077 * @param tunnel mpls tunnel info
1078 * @param pc pcep client to send message
1079 */
1080 private void pcepReleaseTunnel(Tunnel tunnel, PcepClient pc) {
1081 try {
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +05301082 if (!(pc.lspDbSyncStatus().equals(PcepSyncStatus.SYNCED))) {
1083 log.error("Release tunnel has failed as LSP DB sync is not finished");
1084 return;
1085 }
1086
Avantika-Huawei56c11842016-04-28 00:56:56 +05301087 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE);
Jonathan Hart51539b82015-10-29 09:53:04 -07001088 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301089 int srpId = SrpIdGenerators.create();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301090
1091 PcepValueType tlv;
1092 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301093
1094 // set PathSetupTypeTlv of SRP object
1095 tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))
1096 .type());
1097 llOptionalTlv.add(tlv);
1098
1099 // build SRP object
1100 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true)
1101 .setOptionalTlv(llOptionalTlv).build();
1102
1103 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301104 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
1105
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301106 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
1107 llOptionalTlv.add(tlv);
Priyanka B4c3cef02016-06-14 20:27:53 +05301108
1109 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
1110 String pccTunnelIdString = tunnel.annotations().value(PCC_TUNNEL_ID);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301111 String pLspIdString = tunnel.annotations().value(PLSP_ID);
1112
Priyanka B4c3cef02016-06-14 20:27:53 +05301113 short localLspId = 0;
1114 short pccTunnelId = 0;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301115 int plspId = 0;
Priyanka B4c3cef02016-06-14 20:27:53 +05301116
1117 if (localLspIdString != null) {
1118 localLspId = Short.valueOf(localLspIdString);
1119 }
1120
1121 if (pccTunnelIdString != null) {
1122 pccTunnelId = Short.valueOf(pccTunnelIdString);
1123 }
1124
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301125 if (pLspIdString != null) {
1126 plspId = Integer.valueOf(pLspIdString);
1127 }
1128
Priyanka B4c3cef02016-06-14 20:27:53 +05301129 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src())
1130 .ip().getIp4Address().toInt()),
1131 localLspId, pccTunnelId, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
1132 .getIp4Address().toInt()));
1133 llOptionalTlv.add(tlv);
1134
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301135 // build lsp object, set r flag as false to delete the tunnel
1136 PcepLspObject lspobj = pc.factory().buildLspObject().setRFlag(false).setPlspId(plspId)
1137 .setOptionalTlv(llOptionalTlv).build();
1138
1139 PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj)
1140 .setLspObject(lspobj).build();
1141
1142 llPcInitiatedLspRequestList.add(releaseLspRequest);
1143
1144 PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
1145 .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
1146
1147 pc.sendMessage(Collections.singletonList(pcInitiateMsg));
1148
Jonathan Hart51539b82015-10-29 09:53:04 -07001149 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301150 } catch (PcepParseException e) {
1151 log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage());
1152 }
1153 }
1154
1155 /**
1156 * To send Update tunnel request message to pcc.
1157 *
1158 * @param tunnel mpls tunnel info
1159 * @param path explicit route for the tunnel
1160 * @param pc pcep client to send message
1161 */
1162 private void pcepUpdateTunnel(Tunnel tunnel, Path path, PcepClient pc) {
1163 try {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301164 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE);
Jonathan Hart51539b82015-10-29 09:53:04 -07001165 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301166 int srpId = SrpIdGenerators.create();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301167 PcepValueType tlv;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301168
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301169 LinkedList<PcepValueType> llSubObjects = null;
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301170 LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
1171
1172 if (lspSigType == SR_WITHOUT_SIGNALLING) {
1173 NetworkResource labelStack = tunnel.resource();
1174 if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) {
1175 labelStack = pcepClientController.computeLabelStack(tunnel.path());
1176 if (labelStack == null) {
1177 log.error("Unable to create label stack.");
1178 return;
1179 }
1180 }
1181 llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301182 } else {
1183 llSubObjects = createPcepPath(path);
1184 }
1185
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301186 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
1187 LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
1188
Avantika-Huawei56c11842016-04-28 00:56:56 +05301189 // set PathSetupTypeTlv of SRP object
Avantika-Huawei56c11842016-04-28 00:56:56 +05301190 tlv = new PathSetupTypeTlv(lspSigType.type());
1191 llOptionalTlv.add(tlv);
1192
1193 // build SRP object
1194 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
1195 .setOptionalTlv(llOptionalTlv).build();
1196
1197 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301198
Avantika-Huawei56c11842016-04-28 00:56:56 +05301199 if (lspSigType != WITH_SIGNALLING) {
1200 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
1201 String pccTunnelIdString = tunnel.annotations().value(PCC_TUNNEL_ID);
1202 short localLspId = 0;
1203 short pccTunnelId = 0;
1204
1205 if (localLspIdString != null) {
1206 localLspId = Short.valueOf(localLspIdString);
1207 }
1208
1209 if (pccTunnelIdString != null) {
1210 pccTunnelId = Short.valueOf(pccTunnelIdString);
1211 }
1212
1213 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src())
1214 .ip().getIp4Address().toInt()),
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301215 localLspId, pccTunnelId,
1216 ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(),
1217 (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()));
Avantika-Huawei56c11842016-04-28 00:56:56 +05301218 llOptionalTlv.add(tlv);
1219 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301220
1221 if (tunnel.tunnelName().value() != null) {
1222 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
1223 llOptionalTlv.add(tlv);
1224 }
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301225 boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false
1226 : Boolean.valueOf(tunnel.annotations()
1227 .value(DELEGATE));
1228 boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false
1229 : Boolean.valueOf(tunnel.annotations()
1230 .value(PCE_INIT));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301231 // build lsp object
Priyanka B4c3cef02016-06-14 20:27:53 +05301232 PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true)
1233 .setPlspId(Integer.valueOf(tunnel.annotations().value(PLSP_ID)))
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301234 .setDFlag(delegated)
1235 .setCFlag(initiated)
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301236 .setOptionalTlv(llOptionalTlv).build();
1237 // build ero object
1238 PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
Priyanka B4c3cef02016-06-14 20:27:53 +05301239 float iBandwidth = DEFAULT_BANDWIDTH_VALUE;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301240 if (tunnel.annotations().value(BANDWIDTH) != null) {
Priyanka B4c3cef02016-06-14 20:27:53 +05301241 iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301242 }
1243 // build bandwidth object
1244 PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
1245 // build pcep attribute
1246 PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build();
1247 // build pcep msg path
1248 PcepMsgPath msgPath = pc.factory().buildPcepMsgPath().setEroObject(eroobj).setPcepAttribute(pcepAttribute)
1249 .build();
1250
1251 PcepUpdateRequest updateRequest = pc.factory().buildPcepUpdateRequest().setSrpObject(srpobj)
1252 .setLspObject(lspobj).setMsgPath(msgPath).build();
1253
1254 llUpdateRequestList.add(updateRequest);
1255
1256 PcepUpdateMsg pcUpdateMsg = pc.factory().buildUpdateMsg().setUpdateRequestList(llUpdateRequestList).build();
1257
1258 pc.sendMessage(Collections.singletonList(pcUpdateMsg));
Jonathan Hart51539b82015-10-29 09:53:04 -07001259 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301260 } catch (PcepParseException e) {
1261 log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage());
1262 }
1263 }
1264
1265 private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener {
cheng fan48e832c2015-05-29 01:54:47 +08001266
1267 @Override
Jonathan Hart51539b82015-10-29 09:53:04 -07001268 public void handlePcepTunnel(PcepTunnel pcepTunnel) {
cheng fan48e832c2015-05-29 01:54:47 +08001269 TunnelDescription tunnel = null;
1270 // instance and id identify a tunnel together
1271 String tunnelKey = String.valueOf(pcepTunnel.getInstance())
1272 + String.valueOf(pcepTunnel.id());
1273
1274 if (tunnelKey == null || "".equals(tunnelKey)) {
1275 log.error("Invalid PCEP tunnel");
1276 return;
1277 }
1278
1279 TunnelId tunnelId = getTunnelId(tunnelKey);
cheng fan48e832c2015-05-29 01:54:47 +08001280 tunnel = buildOpticalTunnel(pcepTunnel, tunnelId);
1281
1282 OperationType operType = pcepTunnel.getOperationType();
1283 switch (operType) {
1284 case ADD:
1285 tunnelId = service.tunnelAdded(tunnel);
1286 tunnelMap.put(tunnelKey, tunnelId);
1287 break;
1288
1289 case UPDATE:
1290 service.tunnelUpdated(tunnel);
1291 break;
1292
1293 case DELETE:
1294 service.tunnelRemoved(tunnel);
1295 tunnelMap.remove(tunnelKey);
1296 break;
1297
1298 default:
1299 log.error("Invalid tunnel operation");
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301300 }
1301 }
cheng fan48e832c2015-05-29 01:54:47 +08001302
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301303 @Override
1304 public void handleMessage(PccId pccId, PcepMessage msg) {
1305 try {
1306 log.debug("tunnel provider handle message {}", msg.getType().toString());
1307 switch (msg.getType()) {
1308 case REPORT:
1309 int srpId = 0;
1310 LinkedList<PcepStateReport> llStateReportList = null;
1311 llStateReportList = ((PcepReportMsg) msg).getStateReportList();
1312 ListIterator<PcepStateReport> listIterator = llStateReportList.listIterator();
1313 PcepSrpObject srpObj = null;
1314 PcepLspObject lspObj = null;
1315 while (listIterator.hasNext()) {
1316 PcepStateReport stateRpt = listIterator.next();
1317 srpObj = stateRpt.getSrpObject();
1318 lspObj = stateRpt.getLspObject();
1319
1320 if (srpObj instanceof PcepSrpObject) {
1321 srpId = srpObj.getSrpID();
1322 }
1323
1324 log.debug("Plsp ID in handle message " + lspObj.getPlspId());
1325 log.debug("SRP ID in handle message " + srpId);
1326
Jonathan Hart51539b82015-10-29 09:53:04 -07001327 if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301328 // For PCRpt without matching SRP id.
1329 handleRptWithoutSrpId(stateRpt, pccId);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301330 continue;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301331 }
1332
Avantika-Huawei56c11842016-04-28 00:56:56 +05301333 handleReportMessage(srpId, lspObj, stateRpt);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301334 }
1335 break;
1336
1337 default:
1338 log.debug("Received unsupported message type {}", msg.getType().toString());
1339 }
1340 } catch (Exception e) {
1341 log.error("Exception occured while processing report message {}", e.getMessage());
1342 }
1343 }
1344
1345 /**
1346 * Handles report message for setup/update/delete tunnel request.
1347 *
Avantika-Huawei56c11842016-04-28 00:56:56 +05301348 * @param srpId unique identifier for PCEP message
1349 * @param lspObj LSP object
1350 * @param stateRpt parsed PCEP report msg.
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301351 */
Avantika-Huawei56c11842016-04-28 00:56:56 +05301352 private void handleReportMessage(int srpId, PcepLspObject lspObj, PcepStateReport stateRpt) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301353 ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
Jonathan Hart51539b82015-10-29 09:53:04 -07001354 PcepTunnelData pcepTunnelData = pcepTunnelApiMapper.getDataFromTunnelRequestQueue(srpId);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301355
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301356 // store the values required from report message
1357 pcepTunnelData.setPlspId(lspObj.getPlspId());
1358 pcepTunnelData.setLspAFlag(lspObj.getAFlag());
1359 pcepTunnelData.setLspOFlag(lspObj.getOFlag());
1360 pcepTunnelData.setLspDFlag(lspObj.getDFlag());
1361
Avantika-Huawei56c11842016-04-28 00:56:56 +05301362 StatefulIPv4LspIdentifiersTlv ipv4LspTlv = null;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301363 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
1364 while (listTlvIterator.hasNext()) {
1365 PcepValueType tlv = listTlvIterator.next();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301366 if (tlv.getType() == StatefulIPv4LspIdentifiersTlv.TYPE) {
1367 ipv4LspTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301368 break;
1369 }
1370 }
Sho SHIMIZUde09fa02015-09-03 09:39:52 -07001371 if (ipv4LspTlv != null) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301372 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspTlv);
cheng fan48e832c2015-05-29 01:54:47 +08001373 }
1374
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301375 Path path = pcepTunnelData.path();
1376 Tunnel tunnel = pcepTunnelData.tunnel();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301377 Builder annotationBuilder = DefaultAnnotations.builder();
1378 annotationBuilder.putAll(pcepTunnelData.tunnel().annotations());
1379
1380 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
1381 if (tunnel.annotations().value(PLSP_ID) == null) {
1382 annotationBuilder.set(PLSP_ID, String.valueOf(lspObj.getPlspId()));
1383 }
1384
1385 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
1386 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1387 annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(ipv4LspTlv.getLspId()));
1388 }
1389
Priyanka B4c3cef02016-06-14 20:27:53 +05301390 if (tunnel.annotations().value(PCC_TUNNEL_ID) == null) {
1391 annotationBuilder.set(PCC_TUNNEL_ID, String.valueOf(ipv4LspTlv.getTunnelId()));
1392 }
1393
Avantika-Huawei56c11842016-04-28 00:56:56 +05301394 SparseAnnotations annotations = annotationBuilder.build();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301395 DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(),
1396 tunnel.dst(), tunnel.type(), tunnel.groupId(),
1397 providerId, tunnel.tunnelName(), path,
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301398 tunnel.resource(), annotations);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301399
Avantika-Huawei56c11842016-04-28 00:56:56 +05301400 if (CREATE == pcepTunnelData.requestType()) {
Priyanka B4c3cef02016-06-14 20:27:53 +05301401 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Jonathan Hart51539b82015-10-29 09:53:04 -07001402 pcepTunnelApiMapper.handleCreateTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301403 } else if (DELETE == pcepTunnelData.requestType()) {
Jonathan Hart51539b82015-10-29 09:53:04 -07001404 pcepTunnelApiMapper.handleRemoveFromTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301405 } else if (UPDATE == pcepTunnelData.requestType()) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301406 pcepTunnelData.setRptFlag(true);
Jonathan Hart51539b82015-10-29 09:53:04 -07001407 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1408 pcepTunnelApiMapper.handleUpdateTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301409 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301410
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301411 PcepLspStatus pcepLspStatus = PcepLspStatus.values()[lspObj.getOFlag()];
1412
Avantika-Huawei56c11842016-04-28 00:56:56 +05301413 if (lspObj.getRFlag()) {
1414 tunnelRemoved(td);
1415 } else {
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301416 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(pcepLspStatus);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301417 tunnelUpdated(td, tunnelState);
1418 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301419
1420 // SR-TE also needs PCUpd msg after receiving PCRpt with status GOING-UP even
1421 // though there are no labels to download for SR-TE.
1422 if ((pcepLspStatus == PcepLspStatus.GOING_UP)
1423 && (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) == SR_WITHOUT_SIGNALLING)) {
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301424 // Query again to get latest tunnel updated with protocol values from PCRpt msg.
1425 updateTunnel(service.tunnelQueryById(tunnel.tunnelId()), tunnel.path());
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301426 }
Avantika-Huawei56c11842016-04-28 00:56:56 +05301427 }
1428
Priyanka B413fbe82016-05-26 11:44:45 +05301429 private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
Priyanka B4c3b4512016-07-22 11:41:49 +05301430 String bandwidth, LspType lspType, String costType, boolean isPceInit) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301431 Builder builder = DefaultAnnotations.builder();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301432 /*
1433 * [RFC 5440] The absence of the METRIC object MUST be interpreted by the PCE as a path computation request
1434 * for which no constraints need be applied to any of the metrics.
1435 */
1436 if (costType != null) {
1437 builder.set(COST_TYPE, costType);
1438 }
1439
Priyanka B4c3b4512016-07-22 11:41:49 +05301440 if (isPceInit) {
1441 builder.set(PCE_INIT, String.valueOf(isPceInit));
1442 }
1443
1444 if (bandwidth != null) {
1445 builder.set(BANDWIDTH, bandwidth);
1446 }
1447
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301448 SparseAnnotations annotations = builder
Priyanka B4c3b4512016-07-22 11:41:49 +05301449 .set(LSP_SIG_TYPE, lspType.name())
Priyanka B413fbe82016-05-26 11:44:45 +05301450 .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1451 .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1452 .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId()))
1453 .set(DELEGATE, String.valueOf(lspObj.getDFlag()))
1454 .build();
1455 return annotations;
1456 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301457
Priyanka B413fbe82016-05-26 11:44:45 +05301458 private LspType getLspType(PcepSrpObject srpObj) {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301459 LspType lspType = WITH_SIGNALLING;
1460
1461 if (null != srpObj) {
1462 LinkedList<PcepValueType> llOptionalTlv = srpObj.getOptionalTlv();
1463 ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
1464
1465 while (listIterator.hasNext()) {
1466 PcepValueType tlv = listIterator.next();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301467 switch (tlv.getType()) {
1468 case PathSetupTypeTlv.TYPE:
1469 lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())];
1470 break;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301471 default:
1472 break;
1473 }
1474 }
1475 }
Priyanka B413fbe82016-05-26 11:44:45 +05301476 return lspType;
1477 }
1478
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301479 private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId) {
Priyanka B413fbe82016-05-26 11:44:45 +05301480 ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301481 String costType = null;
Priyanka B413fbe82016-05-26 11:44:45 +05301482 PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
1483 checkNotNull(msgPath);
1484 PcepEroObject eroObj = msgPath.getEroObject();
1485 if (eroObj == null) {
1486 log.error("ERO object is null in report message.");
1487 return;
1488 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301489 PcepAttribute attributes = msgPath.getPcepAttribute();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301490 float bandwidth = 0;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301491 int cost = 0;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301492 if (attributes != null) {
1493 if (attributes.getMetricObjectList() != null) {
1494 ListIterator<PcepMetricObject> iterator = attributes.getMetricObjectList().listIterator();
1495 PcepMetricObject metricObj = iterator.next();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301496
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301497 while (metricObj != null) {
1498 if (metricObj.getBType() == IGP_METRIC) {
1499 costType = "COST";
1500 } else if (metricObj.getBType() == TE_METRIC) {
1501 costType = "TE_COST";
1502 }
1503 if (costType != null) {
1504 cost = metricObj.getMetricVal();
1505 log.debug("Path cost {}", cost);
1506 break;
1507 }
1508 metricObj = iterator.next();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301509 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301510 }
1511 if (attributes.getBandwidthObject() != null) {
1512 bandwidth = attributes.getBandwidthObject().getBandwidth();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301513 }
1514 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301515 PcepLspObject lspObj = stateRpt.getLspObject();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301516 List<Object> eroSubObjList = buildPathFromEroObj(eroObj, providerId);
1517 List<Link> links = new ArrayList<>();
1518 List<LabelResourceId> labels = new ArrayList<>();
1519 for (Object linkOrLabel : eroSubObjList) {
1520 if (linkOrLabel instanceof Link) {
1521 links.add((Link) linkOrLabel);
1522 } else if (linkOrLabel instanceof Integer) {
1523 labels.add(LabelResourceId.labelResourceId(((Integer) linkOrLabel).longValue()));
1524 }
Priyanka B413fbe82016-05-26 11:44:45 +05301525 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301526 Path path = null;
1527 if (!links.isEmpty()) {
1528 path = new DefaultPath(providerId, links, cost, EMPTY);
1529 } else if (!lspObj.getRFlag()) {
1530 return;
1531 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301532 NetworkResource labelStack = new DefaultLabelStack(labels);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301533 // To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
1534 // from PCE.
Priyanka B413fbe82016-05-26 11:44:45 +05301535 PcepSrpObject srpObj = stateRpt.getSrpObject();
1536 LspType lspType = getLspType(srpObj);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301537 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
1538 StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
1539 SymbolicPathNameTlv pathNameTlv = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301540 while (listTlvIterator.hasNext()) {
1541 PcepValueType tlv = listTlvIterator.next();
1542 switch (tlv.getType()) {
1543 case StatefulIPv4LspIdentifiersTlv.TYPE:
1544 ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
1545 break;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301546 case SymbolicPathNameTlv.TYPE:
1547 pathNameTlv = (SymbolicPathNameTlv) tlv;
1548 break;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301549 default:
1550 break;
1551 }
1552 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301553 /*
1554 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for
1555 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory.
1556 */
1557 if (ipv4LspIdenTlv == null) {
1558 log.error("Stateful IPv4 identifier TLV is null in PCRpt msg.");
1559 return;
1560 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301561 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint
1562 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4IngressAddress()));
1563 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint
1564 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress()));
1565 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
Priyanka B413fbe82016-05-26 11:44:45 +05301566 // Store delegation flag info and that LSP info because only delegated PCE sends update message
1567 // Storing if D flag is set, if not dont store. while checking whether delegation if annotation for D flag
1568 // not present then non-delegated , if present it is delegated.
1569 if (lspObj.getDFlag()) {
1570 pcepClientController.getClient(pccId).setLspAndDelegationInfo(
1571 new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId()), lspObj.getDFlag());
1572 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301573 Tunnel tunnel = null;
Priyanka B4c3b4512016-07-22 11:41:49 +05301574 SparseAnnotations oldTunnelAnnotations = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301575 // Asynchronous status change message from PCC for LSP reported earlier.
1576 for (Tunnel tunnelObj : tunnelQueryResult) {
1577 if (tunnelObj.annotations().value(PLSP_ID) == null) {
1578 /*
1579 * PLSP_ID is null while Tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by
1580 * PCC and in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic
1581 * path name must be carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be
1582 * included in the LSP object in the LSP State Report (PCRpt) message when during a given PCEP
1583 * session an LSP is "first" reported to a PCE.
1584 */
1585 if ((pathNameTlv != null)
1586 && Arrays.equals(tunnelObj.tunnelName().value().getBytes(), pathNameTlv.getValue())) {
1587 tunnel = tunnelObj;
1588 break;
1589 }
1590 continue;
1591 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301592 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId())) {
1593 if ((Integer
1594 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) {
1595 tunnel = tunnelObj;
1596 }
1597 if ((Integer
1598 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) != ipv4LspIdenTlv.getLspId())) {
1599 oldTunnelAnnotations = (SparseAnnotations) tunnelObj.annotations();
1600 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301601 }
1602 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301603 DefaultTunnelDescription td;
Priyanka B413fbe82016-05-26 11:44:45 +05301604 SparseAnnotations annotations = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301605 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
1606 if (tunnel == null) {
1607 if (lspObj.getRFlag()) {
1608 /*
1609 * If PCC sends remove message and for any reason PCE does not have that entry, simply discard the
1610 * message. Or if PCRpt for initiated LSP received and PCE doesn't know, then too discard.
1611 */
1612 return;
1613 }
Priyanka B413fbe82016-05-26 11:44:45 +05301614 DeviceId deviceId = getDevice(pccId);
1615 if (deviceId == null) {
1616 log.error("Ingress deviceId not found");
1617 return;
1618 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301619 String tempBandwidth = null;
1620 String temoCostType = null;
1621 if (oldTunnelAnnotations != null) {
1622 tempBandwidth = oldTunnelAnnotations.value(BANDWIDTH);
1623 temoCostType = oldTunnelAnnotations.value(COST_TYPE);
1624 }
1625 annotations = getAnnotations(lspObj, ipv4LspIdenTlv, tempBandwidth, lspType,
1626 temoCostType, lspObj.getCFlag());
Priyanka B413fbe82016-05-26 11:44:45 +05301627 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301628 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
Priyanka B413fbe82016-05-26 11:44:45 +05301629 annotations);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301630 // Do not support PCC initiated LSP after LSP DB sync is completed.
1631 if (!lspObj.getSFlag() && !lspObj.getCFlag()) {
1632 log.error("Received PCC initiated LSP while not in sync.");
1633 return;
1634 }
Priyanka B413fbe82016-05-26 11:44:45 +05301635 /*
1636 * If ONOS instance is master for PCC then set delegated flag as annotation and add the tunnel to store.
1637 * Because all LSPs need not be delegated, hence mastership for the PCC is confirmed whereas not the
1638 * delegation set to all LSPs.If ONOS is not the master for that PCC then check if D flag is set, if yes
1639 * wait for 2 seconds [while master has added the tunnel to the store] then update the tunnel. Tunnel is
1640 * updated because in case of resilency only delegated LSPs are recomputed and only delegated PCE can
1641 * send update message to that client.
1642 *
1643 * 1)Master can 1st get the Rpt message
1644 * a)Master adds the tunnel into core.
1645 * b)If a non-master for ingress gets Rpt message with D flag set[as delegation owner]
1646 * after master, then runs timer then update the tunnel with D flag set.
1647 * 2)Non-Master can 1st get the Rpt message
1648 * a)Non-Master runs the timer check for the tunnel then updates the tunnel with D flag set
1649 * b)Master would have got the message while the non-master running timer, hence master adds
1650 * tunnel to core
1651 *
1652 * In general always master adds the tunnel to the core
1653 * while delegated owner [master or non-master with D flag set] always updates the tunnel running timer
1654 */
1655 if (mastershipService.isLocalMaster(deviceId)) {
1656 TunnelId tId = tunnelAdded(td, tunnelState);
1657 Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1658 tunnelState, new DefaultGroupId(0), tId, TunnelName.tunnelName(String.valueOf(pathNameTlv
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301659 .getValue())), path, labelStack, annotations);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301660
Priyanka B413fbe82016-05-26 11:44:45 +05301661 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT);
1662 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1663 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1664 } else if (!mastershipService.isLocalMaster(deviceId) && lspObj.getDFlag()) {
1665 //Start timer then update the tunnel with D flag
Priyanka B4c3b4512016-07-22 11:41:49 +05301666 tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId, tunnelState, ipv4LspIdenTlv);
Priyanka B413fbe82016-05-26 11:44:45 +05301667 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301668 return;
1669 }
Priyanka B413fbe82016-05-26 11:44:45 +05301670 //delegated owner will update can be a master or non-master
Priyanka B4c3b4512016-07-22 11:41:49 +05301671 if (lspObj.getDFlag() && !lspObj.getRFlag()) {
1672 tunnelUpdateForDelegatedLsp(tunnel, lspObj,
1673 lspType, tunnelState, pccId, labelStack, ipv4LspIdenTlv);
1674 return;
Priyanka B413fbe82016-05-26 11:44:45 +05301675 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301676 removeOrUpdatetunnel(tunnel, lspObj, providerId, tunnelState, ipv4LspIdenTlv);
Priyanka B413fbe82016-05-26 11:44:45 +05301677 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301678
Priyanka B4c3b4512016-07-22 11:41:49 +05301679 private void tunnelUpdateForDelegatedLsp(Tunnel tunnel, PcepLspObject lspObj,
1680 LspType lspType, State tunnelState, PccId pccId,
1681 NetworkResource labelStack,
1682 StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
1683 SparseAnnotations annotations = null;
1684 DefaultTunnelDescription td;
1685 boolean isPceInit = tunnel.annotations().value(PCE_INIT) == null ? false :
1686 Boolean.valueOf((tunnel.annotations().value(PCE_INIT))).booleanValue();
1687 annotations = getAnnotations(lspObj, ipv4LspIdenTlv,
1688 tunnel.annotations().value(BANDWIDTH), lspType,
1689 tunnel.annotations().value(COST_TYPE), isPceInit);
1690 td = new DefaultTunnelDescription(null, tunnel.src(), tunnel.dst(), MPLS, new DefaultGroupId(
1691 0), tunnel.providerId(), tunnel.tunnelName(),
1692 tunnel.path(), labelStack, annotations);
1693 tunnelUpdateInDelegatedCase(pccId, annotations, td, tunnel.providerId(), tunnelState, ipv4LspIdenTlv);
1694 }
1695
1696 private void removeOrUpdatetunnel(Tunnel tunnel, PcepLspObject lspObj, ProviderId providerId,
1697 State tunnelState, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
Priyanka B413fbe82016-05-26 11:44:45 +05301698 DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
1699 tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
1700 (SparseAnnotations) tunnel.annotations());
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301701 if (lspObj.getRFlag()) {
1702 tunnelRemoved(td);
1703 } else {
Priyanka B4c3b4512016-07-22 11:41:49 +05301704 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
1705 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1706 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301707 tunnelUpdated(td, tunnelState);
1708 }
Priyanka B413fbe82016-05-26 11:44:45 +05301709 }
1710
1711 private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
Priyanka B4c3b4512016-07-22 11:41:49 +05301712 DefaultTunnelDescription td, ProviderId providerId, State tunnelState,
1713 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301714 // Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
Priyanka B413fbe82016-05-26 11:44:45 +05301715
1716 /*
1717 * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while
1718 * master has added the tunnel to the store] then update the tunnel.
1719 */
1720 ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
1721
1722 // Thread is started after 2 seconds first time later periodically after 2 seconds to update the tunnel
1723 executor.scheduleAtFixedRate(new UpdateDelegation(td, providerId, annotations, pccId,
Priyanka B4c3b4512016-07-22 11:41:49 +05301724 executor, tunnelState, ipv4LspIdentifiersTlv), DELAY, DELAY, TimeUnit.SECONDS);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301725 }
1726
1727 /**
Avantika-Huawei56c11842016-04-28 00:56:56 +05301728 * To build Path in network from ERO object.
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301729 *
Avantika-Huawei56c11842016-04-28 00:56:56 +05301730 * @param eroObj ERO object
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301731 * @param providerId provider id
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301732 * @return list of links and labels
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301733 */
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301734 private List<Object> buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301735 checkNotNull(eroObj);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301736 List<Object> subObjList = new ArrayList<>();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301737 LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
Jon Hallcbd1b392017-01-18 20:15:44 -08001738 if (llSubObj.isEmpty()) {
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301739 log.error("ERO in report message does not have hop information");
Priyanka B4c3b4512016-07-22 11:41:49 +05301740 return new ArrayList<>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301741 }
1742 ListIterator<PcepValueType> tlvIterator = llSubObj.listIterator();
1743
1744 ConnectPoint src = null;
1745 ConnectPoint dst = null;
1746 boolean isSrcSet = false;
1747 while (tlvIterator.hasNext()) {
1748 PcepValueType subObj = tlvIterator.next();
1749 switch (subObj.getType()) {
1750
1751 case IPv4SubObject.TYPE:
1752
1753 IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj;
1754 if (!isSrcSet) {
Priyanka Bc1e4e4c2016-07-01 14:57:19 +05301755 Iterable<Link> links = linkService.getActiveLinks();
1756 for (Link l : links) {
1757 if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1758 src = l.src();
1759 isSrcSet = true;
1760 break;
1761 } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1762 src = l.dst();
1763 isSrcSet = true;
1764 break;
1765 }
1766 }
1767 } else {
1768 Iterable<Link> links = linkService.getActiveLinks();
1769 for (Link l : links) {
1770 if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1771 dst = l.src();
1772 break;
1773 } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1774 dst = l.dst();
1775 break;
1776 }
1777 }
Ray Milkey2693bda2016-01-22 16:08:14 -08001778 Link link = DefaultLink.builder()
1779 .providerId(providerId)
1780 .src(src)
1781 .dst(dst)
1782 .type(Link.Type.DIRECT)
1783 .build();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301784 subObjList.add(link);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301785 src = dst;
1786 }
1787 break;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301788 case SrEroSubObject.TYPE:
1789 SrEroSubObject srEroSubObj = (SrEroSubObject) subObj;
1790 subObjList.add(srEroSubObj.getSid());
1791
1792 if (srEroSubObj.getSt() == PcepNaiIpv4Adjacency.ST_TYPE) {
1793 PcepNaiIpv4Adjacency nai = (PcepNaiIpv4Adjacency) (srEroSubObj.getNai());
Priyanka B4c3b4512016-07-22 11:41:49 +05301794 int srcIp = nai.getLocalIpv4Addr();
1795 int dstIp = nai.getRemoteIpv4Addr();
1796 Iterable<Link> links = linkService.getActiveLinks();
1797 for (Link l : links) {
1798 long lSrc = l.src().port().toLong();
1799 long lDst = l.dst().port().toLong();
1800 if (lSrc == srcIp) {
1801 src = l.src();
1802 } else if (lDst == srcIp) {
1803 src = l.dst();
1804 }
1805 if (lSrc == dstIp) {
1806 dst = l.src();
1807 } else if (lDst == dstIp) {
1808 dst = l.dst();
1809 }
1810 if (src != null && dst != null) {
1811 break;
1812 }
1813 }
1814 if (src == null || dst == null) {
1815 return new ArrayList<>();
1816 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301817 Link link = DefaultLink.builder()
1818 .providerId(providerId)
1819 .src(src)
1820 .dst(dst)
1821 .type(Link.Type.DIRECT)
1822 .build();
1823 subObjList.add(link);
1824 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301825 default:
1826 // the other sub objects are not required
1827 }
1828 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301829 return subObjList;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301830 }
1831
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301832 @Override
1833 public void clientConnected(PccId pccId) {
1834 // TODO
1835 }
1836
1837 @Override
1838 public void clientDisconnected(PccId pccId) {
1839 // TODO
cheng fan48e832c2015-05-29 01:54:47 +08001840 }
chengfan2fff70f2015-08-24 18:20:19 -05001841
chengfan2fff70f2015-08-24 18:20:19 -05001842 @Override
1843 public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) {
1844 TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id()));
1845 TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics);
1846 tunnelStatisticsMap.put(id, tunnelStatistics);
1847 }
cheng fan48e832c2015-05-29 01:54:47 +08001848
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301849 @Override
1850 public void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction) {
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301851
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301852 if (endOfSyncAction == SEND_UPDATE) {
1853 updateTunnel(tunnel, tunnel.path());
1854 return;
1855 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301856
1857 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(),
1858 tunnel.src(), tunnel.dst(),
1859 tunnel.type(),
1860 tunnel.groupId(),
1861 tunnel.providerId(),
1862 tunnel.tunnelName(),
1863 tunnel.path(),
1864 (SparseAnnotations) tunnel.annotations());
1865
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301866
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301867 if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) {
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301868 // Send PCInit msg again after global reoptimization.
1869 tunnelUpdated(td, UNSTABLE);
1870
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301871 // To remove the old tunnel from store whose PLSPID is not recognized by ingress PCC.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301872 tunnelRemoved(td);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301873 } else if (endOfSyncAction == REMOVE) {
1874 tunnelRemoved(td);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301875 }
1876 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301877 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301878 @Override
1879 public Tunnel tunnelQueryById(TunnelId tunnelId) {
1880 return service.tunnelQueryById(tunnelId);
1881 }
1882
Priyanka B413fbe82016-05-26 11:44:45 +05301883 private DeviceId getDevice(PccId pccId) {
1884 // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
1885 IpAddress lsrId = pccId.ipAddress();
1886 String lsrIdentifier = String.valueOf(lsrId);
1887
1888 // Find PCC deviceID from lsrId stored as annotations
1889 Iterable<Device> devices = deviceService.getAvailableDevices();
1890 for (Device dev : devices) {
1891 if (dev.annotations().value(AnnotationKeys.TYPE).equals("L3")
1892 && dev.annotations().value(LSRID).equals(lsrIdentifier)) {
1893 return dev.id();
1894 }
1895 }
1896 return null;
1897 }
1898
1899 /**
1900 * Updates the tunnel with updated tunnel annotation after a delay of two seconds and checks it till
1901 * tunnel is found.
1902 */
1903 private class UpdateDelegation implements Runnable {
1904 DefaultTunnelDescription td;
1905 ProviderId providerId;
1906 SparseAnnotations annotations;
1907 PccId pccId;
1908 ScheduledExecutorService executor;
Priyanka B4c3b4512016-07-22 11:41:49 +05301909 State tunnelState;
1910 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv;
Priyanka B413fbe82016-05-26 11:44:45 +05301911
1912 /**
1913 * Creates an instance of UpdateDelegation.
1914 *
1915 * @param td tunnel description
1916 * @param providerId provider id
1917 * @param annotations tunnel annotations
1918 * @param pccId PCEP client id
1919 * @param executor service of delegated owner
1920 */
1921 public UpdateDelegation(DefaultTunnelDescription td, ProviderId providerId, SparseAnnotations annotations,
Priyanka B4c3b4512016-07-22 11:41:49 +05301922 PccId pccId, ScheduledExecutorService executor, State tunnelState,
1923 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
Priyanka B413fbe82016-05-26 11:44:45 +05301924 this.td = td;
1925 this.providerId = providerId;
1926 this.annotations = annotations;
1927 this.pccId = pccId;
1928 this.executor = executor;
Priyanka B4c3b4512016-07-22 11:41:49 +05301929 this.tunnelState = tunnelState;
1930 this.ipv4LspIdentifiersTlv = ipv4LspIdentifiersTlv;
Priyanka B413fbe82016-05-26 11:44:45 +05301931 }
1932
1933 //Temporary using annotations later will use projection/network config service
1934 @Override
1935 public void run() {
1936 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(td.src(), td.dst());
1937 TunnelId tempTunnelId = null;
1938 for (Tunnel t : tunnelQueryResult) {
1939 if (t.annotations().value(LOCAL_LSP_ID) == null || t.annotations().value(PLSP_ID) == null) {
1940 continue;
1941 }
1942
1943 if (t.annotations().value(LOCAL_LSP_ID).equals(td.annotations().value(LOCAL_LSP_ID))
1944 && t.annotations().value(PLSP_ID).equals(td.annotations().value(PLSP_ID))
1945 && ((IpTunnelEndPoint) t.src()).ip().equals(pccId.id())) {
1946 tempTunnelId = t.tunnelId();
1947 break;
1948 }
1949 }
1950
1951 //If tunnel is found update the tunnel and shutdown the thread otherwise thread will be executing
1952 //periodically
1953 if (tempTunnelId != null) {
1954 Tunnel tunnel = new DefaultTunnel(providerId, td.src(), td.dst(), MPLS, new DefaultGroupId(0),
1955 tempTunnelId, td.tunnelName(), td.path(), annotations);
Priyanka B4c3b4512016-07-22 11:41:49 +05301956 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
1957 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdentifiersTlv);
1958 pcepTunnelData.setLspDFlag(Boolean.valueOf(tunnel.annotations().value(DELEGATE)));
1959 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1960 tunnelUpdated(tunnel, td.path(), tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +05301961 executor.shutdown();
1962 try {
1963 executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS);
1964 } catch (InterruptedException e) {
1965 log.error("updating delegation failed");
1966 }
1967 }
1968 }
1969 }
cheng fan48e832c2015-05-29 01:54:47 +08001970}