blob: f9740b5987846fc1302270955d5ddc505fe4ae41 [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;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530103import org.onosproject.pcepio.protocol.PcepNai;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530104import org.onosproject.pcepio.protocol.PcepReportMsg;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530105import org.onosproject.pcepio.protocol.PcepSrpObject;
106import org.onosproject.pcepio.protocol.PcepStateReport;
107import org.onosproject.pcepio.protocol.PcepUpdateMsg;
108import org.onosproject.pcepio.protocol.PcepUpdateRequest;
109import org.onosproject.pcepio.types.IPv4SubObject;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530110import org.onosproject.pcepio.types.PathSetupTypeTlv;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530111import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency;
112import org.onosproject.pcepio.types.PcepNaiIpv4NodeId;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530113import org.onosproject.pcepio.types.PcepValueType;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530114import org.onosproject.pcepio.types.SrEroSubObject;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530115import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530116import org.onosproject.pcepio.types.SymbolicPathNameTlv;
chengfan2fff70f2015-08-24 18:20:19 -0500117import org.osgi.service.component.ComponentContext;
Jonathan Hart51539b82015-10-29 09:53:04 -0700118import org.osgi.service.component.annotations.Modified;
119import org.slf4j.Logger;
120
121import java.util.ArrayList;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530122import java.util.Arrays;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530123import java.util.Collection;
Jonathan Hart51539b82015-10-29 09:53:04 -0700124import java.util.Collections;
125import java.util.Dictionary;
126import java.util.HashMap;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530127import java.util.Iterator;
Jonathan Hart51539b82015-10-29 09:53:04 -0700128import java.util.LinkedList;
129import java.util.List;
130import java.util.ListIterator;
131import java.util.Optional;
Priyanka B413fbe82016-05-26 11:44:45 +0530132import java.util.concurrent.Executors;
133import java.util.concurrent.ScheduledExecutorService;
134import java.util.concurrent.TimeUnit;
Jonathan Hart51539b82015-10-29 09:53:04 -0700135
136import static com.google.common.base.Preconditions.checkNotNull;
137import static com.google.common.base.Strings.isNullOrEmpty;
138import static org.onlab.util.Tools.get;
Priyanka B4c3cef02016-06-14 20:27:53 +0530139import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530140import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
Jonathan Hart51539b82015-10-29 09:53:04 -0700141import static org.onosproject.net.DefaultAnnotations.EMPTY;
142import static org.onosproject.net.DeviceId.deviceId;
143import static org.onosproject.net.PortNumber.portNumber;
144import static org.onosproject.pcep.api.PcepDpid.uri;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530145import static org.onosproject.pcep.controller.LspType.WITH_SIGNALLING;
146import static org.onosproject.pcep.controller.LspType.SR_WITHOUT_SIGNALLING;
147import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530148import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
149import static org.onosproject.pcep.controller.PcepAnnotationKeys.LOCAL_LSP_ID;
150import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
151import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCC_TUNNEL_ID;
Priyanka B4c3cef02016-06-14 20:27:53 +0530152import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530153import static org.onosproject.pcep.controller.PcepAnnotationKeys.PLSP_ID;
154import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
155import static org.onosproject.pcep.controller.PcepAnnotationKeys.COST_TYPE;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530156import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
157import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
158import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
159import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530160import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530161import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
162import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530163import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.IGP_METRIC;
164import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.TE_METRIC;
Jonathan Hart51539b82015-10-29 09:53:04 -0700165import static org.slf4j.LoggerFactory.getLogger;
cheng fan48e832c2015-05-29 01:54:47 +0800166
167/**
168 * Provider which uses an PCEP controller to detect, update, create network
169 * tunnels.
170 */
171@Component(immediate = true)
172@Service
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530173public class PcepTunnelProvider extends AbstractProvider implements TunnelProvider {
cheng fan48e832c2015-05-29 01:54:47 +0800174
175 private static final Logger log = getLogger(PcepTunnelProvider.class);
176 private static final long MAX_BANDWIDTH = 99999744;
177 private static final long MIN_BANDWIDTH = 64;
cheng fan7716ec92015-05-31 01:53:19 +0800178 private static final String BANDWIDTH_UINT = "kbps";
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530179 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka B413fbe82016-05-26 11:44:45 +0530180 public static final long IDENTIFIER_SET = 0x100000000L;
181 public static final long SET = 0xFFFFFFFFL;
182 private static final int DELAY = 2;
183 private static final int WAIT_TIME = 5;
184 public static final String LSRID = "lsrId";
cheng fan48e832c2015-05-29 01:54:47 +0800185
chengfan2fff70f2015-08-24 18:20:19 -0500186 static final int POLL_INTERVAL = 10;
187 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL,
188 label = "Frequency (in seconds) for polling tunnel statistics")
189 private int tunnelStatsPollFrequency = POLL_INTERVAL;
190
cheng fan48e832c2015-05-29 01:54:47 +0800191 private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied.";
192
193 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
194 protected TunnelProviderRegistry tunnelProviderRegistry;
195
196 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
197 protected PcepController controller;
198
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530199 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
200 protected PcepClientController pcepClientController;
chengfan2fff70f2015-08-24 18:20:19 -0500201
202 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
203 protected TunnelService tunnelService;
204
205 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
206 protected ComponentConfigService cfgService;
207
Priyanka B413fbe82016-05-26 11:44:45 +0530208 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
209 protected TunnelAdminService tunnelAdminService;
210
211 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
212 protected MastershipService mastershipService;
213
214 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
215 protected DeviceService deviceService;
216
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530217 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
218 protected LinkService linkService;
219
cheng fan48e832c2015-05-29 01:54:47 +0800220 TunnelProviderService service;
221
222 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
chengfan2fff70f2015-08-24 18:20:19 -0500223 HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>();
Brian Stanke9a108972016-04-11 15:25:17 -0400224 private HashMap<String, TunnelStatsCollector> collectors = Maps.newHashMap();
cheng fan48e832c2015-05-29 01:54:47 +0800225
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530226 private InnerTunnelProvider listener = new InnerTunnelProvider();
227
Jonathan Hart51539b82015-10-29 09:53:04 -0700228 protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper();
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530229 private static final int DEFAULT_BANDWIDTH_VALUE = 10;
cheng fan48e832c2015-05-29 01:54:47 +0800230
231 /**
232 * Creates a Tunnel provider.
233 */
234 public PcepTunnelProvider() {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530235 super(new ProviderId("pcep", PROVIDER_ID));
cheng fan48e832c2015-05-29 01:54:47 +0800236 }
237
238 @Activate
239 public void activate() {
chengfan2fff70f2015-08-24 18:20:19 -0500240 cfgService.registerProperties(getClass());
cheng fan48e832c2015-05-29 01:54:47 +0800241 service = tunnelProviderRegistry.register(this);
242 controller.addTunnelListener(listener);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530243 pcepClientController.addListener(listener);
244 pcepClientController.addEventListener(listener);
chengfan2fff70f2015-08-24 18:20:19 -0500245 tunnelService.queryAllTunnels().forEach(tunnel -> {
Jonathan Hart51539b82015-10-29 09:53:04 -0700246 String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
chengfan2fff70f2015-08-24 18:20:19 -0500247 TunnelStatsCollector tsc = new TunnelStatsCollector(pcepTunnelId, tunnelStatsPollFrequency);
248 tsc.start();
249 collectors.put(tunnel.tunnelId().id(), tsc);
250
251 });
252
cheng fan48e832c2015-05-29 01:54:47 +0800253 log.info("Started");
254 }
255
256 @Deactivate
257 public void deactivate() {
258 tunnelProviderRegistry.unregister(this);
259 controller.removeTunnelListener(listener);
chengfan2fff70f2015-08-24 18:20:19 -0500260 collectors.values().forEach(TunnelStatsCollector::stop);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530261 pcepClientController.removeListener(listener);
cheng fan48e832c2015-05-29 01:54:47 +0800262 log.info("Stopped");
263 }
264
chengfan2fff70f2015-08-24 18:20:19 -0500265 @Modified
266 public void modified(ComponentContext context) {
267 Dictionary<?, ?> properties = context.getProperties();
268 int newTunnelStatsPollFrequency;
269 try {
270 String s = get(properties, "tunnelStatsPollFrequency");
271 newTunnelStatsPollFrequency = isNullOrEmpty(s) ? tunnelStatsPollFrequency : Integer.parseInt(s.trim());
272
273 } catch (NumberFormatException | ClassCastException e) {
274 newTunnelStatsPollFrequency = tunnelStatsPollFrequency;
275 }
276
277 if (newTunnelStatsPollFrequency != tunnelStatsPollFrequency) {
278 tunnelStatsPollFrequency = newTunnelStatsPollFrequency;
279 collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency));
280 log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency);
281 }
282
283 }
284
cheng fan48e832c2015-05-29 01:54:47 +0800285 @Override
286 public void setupTunnel(Tunnel tunnel, Path path) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530287 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530288 log.error("Tunnel Type MPLS is only supported");
289 return;
290 }
cheng fan48e832c2015-05-29 01:54:47 +0800291
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530292 // check for tunnel end points
293 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
294 log.error("Tunnel source or destination is not valid");
295 return;
296 }
297
298 // Get the pcc client
299 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
300
301 if (!(pc instanceof PcepClient)) {
302 log.error("There is no PCC connected with ip addresss {}"
chengfan2fff70f2015-08-24 18:20:19 -0500303 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530304 return;
305 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530306
307 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
Priyanka B413fbe82016-05-26 11:44:45 +0530308 //Only master will initiate setup tunnel
309 if (pc.capability().pcInstantiationCapability() && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530310 pcepSetupTunnel(tunnel, path, pc);
311 }
cheng fan48e832c2015-05-29 01:54:47 +0800312 }
313
314 @Override
315 public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
cheng fan48e832c2015-05-29 01:54:47 +0800316
Priyanka B4c3cef02016-06-14 20:27:53 +0530317 //TODO: tunnel which is passed doesn't have tunnelID
Avantika-Huawei56c11842016-04-28 00:56:56 +0530318 if (tunnel.annotations().value(PLSP_ID) != null) {
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530319 if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
320 // For CR LSPs, BGP flow provider will send update message after pushing labels.
321 updateTunnel(tunnel, path);
322 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530323 return;
324 }
325
326 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530327 log.error("Tunnel Type MPLS is only supported");
328 return;
329 }
330
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530331 // check for tunnel end points
332 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
333 log.error("Tunnel source or destination is not valid");
334 return;
335 }
336
Priyanka Bcdf9b102016-06-07 20:01:38 +0530337 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530338
339 if (!(pc instanceof PcepClient)) {
Priyanka B4c3cef02016-06-14 20:27:53 +0530340 log.error("There is no PCC connected with this device {}"
341 + srcElement.toString());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530342 return;
343 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530344
Priyanka B413fbe82016-05-26 11:44:45 +0530345 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
346 //Only master will initiate setup tunnel
347 if (pc.capability().pcInstantiationCapability()
348 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530349 pcepSetupTunnel(tunnel, path, pc);
350 }
cheng fan48e832c2015-05-29 01:54:47 +0800351 }
352
353 @Override
354 public void releaseTunnel(Tunnel tunnel) {
cheng fan48e832c2015-05-29 01:54:47 +0800355
Avantika-Huawei56c11842016-04-28 00:56:56 +0530356 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530357 log.error("Tunnel Type MPLS is only supported");
358 return;
359 }
360
361 // check for tunnel end points
362 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
363 log.error("Tunnel source or destination is not valid");
364 return;
365 }
366
367 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
368
369 if (!(pc instanceof PcepClient)) {
370 log.error("There is no PCC connected with ip addresss {}"
371 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
372 return;
373 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530374
Priyanka B413fbe82016-05-26 11:44:45 +0530375 //Only master will release tunnel
376 if (pc.capability().pcInstantiationCapability()
377 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530378 pcepReleaseTunnel(tunnel, pc);
379 }
cheng fan48e832c2015-05-29 01:54:47 +0800380 }
381
382 @Override
383 public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530384 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530385 log.error("Tunnel Type MPLS is only supported");
386 return;
387 }
cheng fan48e832c2015-05-29 01:54:47 +0800388
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530389 if (!(srcElement instanceof IpElementId)) {
390 log.error("Element id is not valid");
391 return;
392 }
393
394 // check for tunnel end points
395 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
396 log.error("Tunnel source or destination is not valid");
397 return;
398 }
399
400 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress()));
401
402 if (!(pc instanceof PcepClient)) {
403 log.error("There is no PCC connected with ip addresss {}"
404 + ((IpElementId) srcElement).ipAddress().toString());
405 return;
406 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530407
Priyanka B413fbe82016-05-26 11:44:45 +0530408 //Only master will release tunnel
409 if (pc.capability().pcInstantiationCapability()
410 && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530411 pcepReleaseTunnel(tunnel, pc);
412 }
cheng fan48e832c2015-05-29 01:54:47 +0800413 }
414
415 @Override
416 public void updateTunnel(Tunnel tunnel, Path path) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530417 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530418 log.error("Tunnel Type MPLS is only supported");
419 return;
420 }
cheng fan48e832c2015-05-29 01:54:47 +0800421
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530422 // check for tunnel end points
423 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
424 log.error("Tunnel source or destination is not valid");
425 return;
426 }
427
Priyanka B4c3cef02016-06-14 20:27:53 +0530428 //To get new tunnel ID (modified tunnel ID)
429 Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
430 for (Tunnel t : tunnels) {
431 if (t.state().equals(INIT) && t.tunnelName().equals(tunnel.tunnelName())) {
432 tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
433 tunnel.dst(), tunnel.type(),
434 t.state(), tunnel.groupId(),
435 t.tunnelId(),
436 tunnel.tunnelName(),
437 tunnel.path(),
438 tunnel.resource(),
439 tunnel.annotations());
440 break;
441 }
442 }
443
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530444 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip()));
445
446 if (!(pc instanceof PcepClient)) {
447 log.error("There is no PCC connected with ip addresss {}"
448 + ((IpTunnelEndPoint) tunnel.src()).ip().toString());
449 return;
450 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530451
Priyanka B4c3cef02016-06-14 20:27:53 +0530452 //PCInitiate tunnels are always have D flag set, else check for tunnels who are delegated via LspKey
453 if (pc.capability().statefulPceCapability()) {
454 if (tunnel.annotations().value(PCE_INIT) != null && tunnel.annotations().value(PCE_INIT).equals("true")) {
455 pcepUpdateTunnel(tunnel, path, pc);
Priyanka B4c3b4512016-07-22 11:41:49 +0530456 } else {
457 // If delegation flag is set then only send update message[means delegated PCE can send update msg for
458 // that LSP. If annotation is null D flag is not set else it is set.
459 Short localLspId = 0;
460 for (Tunnel t : tunnels) {
461 if (!t.tunnelId().equals(tunnel.tunnelId()) && t.tunnelName().equals(tunnel.tunnelName())) {
462 localLspId = Short.valueOf(t.annotations().value(LOCAL_LSP_ID));
463 }
464 }
465
466 if (localLspId == 0) {
467 log.error("Local LSP ID for old tunnel not found");
468 return;
469 }
470
471 if (pc.delegationInfo(new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)),
472 localLspId.shortValue())) != null) {
473
474 pcepUpdateTunnel(tunnel, path, pc);
475 }
Priyanka B4c3cef02016-06-14 20:27:53 +0530476 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530477 }
cheng fan48e832c2015-05-29 01:54:47 +0800478 }
479
480 @Override
481 public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
cheng fan48e832c2015-05-29 01:54:47 +0800482
Avantika-Huawei56c11842016-04-28 00:56:56 +0530483 if (tunnel.type() != MPLS) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530484 log.error("Tunnel Type MPLS is only supported");
485 return;
486 }
487
488 if (!(srcElement instanceof IpElementId)) {
489 log.error("Element id is not valid");
490 return;
491 }
492
493 // check for tunnel end points
494 if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) {
495 log.error("Tunnel source or destination is not valid");
496 return;
497 }
498
499 PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress()));
500
501 if (!(pc instanceof PcepClient)) {
502 log.error("There is no PCC connected with ip addresss {}"
503 + ((IpElementId) srcElement).ipAddress().toString());
504 return;
505 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530506
Priyanka B413fbe82016-05-26 11:44:45 +0530507 // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
508 // LSP].If annotation is null D flag is not set else it is set.
509 if (pc.capability().statefulPceCapability()
510 && pc.delegationInfo(
511 new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
512 .annotations().value(LOCAL_LSP_ID)))) != null) {
Priyanka Bd2b28882016-04-04 16:57:04 +0530513 pcepUpdateTunnel(tunnel, path, pc);
514 }
cheng fan48e832c2015-05-29 01:54:47 +0800515 }
516
517 @Override
518 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530519 return handleTunnelAdded(tunnel, null);
520 }
521
522 public TunnelId tunnelAdded(TunnelDescription tunnel, State tunnelState) {
523 return handleTunnelAdded(tunnel, tunnelState);
524 }
525
526 private TunnelId handleTunnelAdded(TunnelDescription tunnel, State tunnelState) {
527
528 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700529 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Avantika-Huawei56c11842016-04-28 00:56:56 +0530530
531 if (tunnelState == null) {
532 return service.tunnelAdded(tunnel);
533 } else {
534 return service.tunnelAdded(tunnel, tunnelState);
535 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530536 }
cheng fan48e832c2015-05-29 01:54:47 +0800537
Avantika-Huawei56c11842016-04-28 00:56:56 +0530538 long bandwidth = Long.parseLong(tunnel.annotations().value(BANDWIDTH));
cheng fan48e832c2015-05-29 01:54:47 +0800539
540 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
cheng fan7716ec92015-05-31 01:53:19 +0800541 error("Update failed, invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800542 return null;
543 }
544
545 // endpoints
546 OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel
547 .src();
548 OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst();
549 // devices
550 DeviceId srcId = (DeviceId) src.elementId().get();
551 DeviceId dstId = (DeviceId) dst.elementId().get();
552
553 // ports
554 long srcPort = src.portNumber().get().toLong();
555 long dstPort = dst.portNumber().get().toLong();
556
557 // type
558 if (tunnel.type() != Tunnel.Type.VLAN) {
cheng fan7716ec92015-05-31 01:53:19 +0800559 error("Illegal tunnel type. Only support VLAN tunnel creation.");
cheng fan48e832c2015-05-29 01:54:47 +0800560 return null;
561 }
562
563 PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort,
564 dstPort, bandwidth,
565 tunnel.tunnelName()
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530566 .value());
cheng fan48e832c2015-05-29 01:54:47 +0800567
568 checkNotNull(pcepTunnel, TUNNLE_NOT_NULL);
569 TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null);
570 TunnelId tunnelId = service.tunnelAdded(tunnelAdded);
571
572 tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId);
573 return tunnelId;
574 }
575
Priyanka B4c3b4512016-07-22 11:41:49 +0530576 private void tunnelUpdated(Tunnel tunnel, Path path, State tunnelState) {
577 handleTunnelUpdate(tunnel, path, tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +0530578 }
579
580 //Handles tunnel updated using tunnel admin service[specially to update annotations].
Priyanka B4c3b4512016-07-22 11:41:49 +0530581 private void handleTunnelUpdate(Tunnel tunnel, Path path, State tunnelState) {
Priyanka B413fbe82016-05-26 11:44:45 +0530582
583 if (tunnel.type() == MPLS) {
584 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.tunnelId());
585
Priyanka B4c3b4512016-07-22 11:41:49 +0530586 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
587 tunnel.type(), tunnel.groupId(), tunnel.providerId(),
588 tunnel.tunnelName(), path, tunnel.resource(),
589 (SparseAnnotations) tunnel.annotations());
Priyanka B413fbe82016-05-26 11:44:45 +0530590
Priyanka B4c3b4512016-07-22 11:41:49 +0530591 service.tunnelUpdated(td, tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +0530592 return;
593 }
594
595 Tunnel tunnelOld = tunnelQueryById(tunnel.tunnelId());
596 if (tunnelOld.type() != Tunnel.Type.VLAN) {
597 error("Illegal tunnel type. Only support VLAN tunnel update.");
598 return;
599 }
600
601 long bandwidth = Long
602 .parseLong(tunnel.annotations().value("bandwidth"));
603 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
604 error("Update failed, invalid bandwidth.");
605 return;
606 }
607 String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
608
609 checkNotNull(pcepTunnelId, "Invalid tunnel id");
610 if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
611 error("Update failed,maybe invalid bandwidth.");
612 return;
613 }
614 tunnelAdminService.updateTunnel(tunnel, path);
615 }
616
cheng fan48e832c2015-05-29 01:54:47 +0800617 @Override
618 public void tunnelRemoved(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530619 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700620 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530621 service.tunnelRemoved(tunnel);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530622 return;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530623 }
624
cheng fan48e832c2015-05-29 01:54:47 +0800625 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
626 checkNotNull(tunnelOld, "The tunnel id is not exsited.");
627 if (tunnelOld.type() != Tunnel.Type.VLAN) {
cheng fan93258c72015-06-02 23:42:32 +0800628 error("Illegal tunnel type. Only support VLAN tunnel deletion.");
cheng fan48e832c2015-05-29 01:54:47 +0800629 return;
630 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700631 String pcepTunnelId = getPcepTunnelKey(tunnel.id());
cheng fan48e832c2015-05-29 01:54:47 +0800632 checkNotNull(pcepTunnelId, "The tunnel id is not exsited.");
cheng fan7716ec92015-05-31 01:53:19 +0800633 if (!controller.deleteTunnel(pcepTunnelId)) {
634 error("Delete tunnel failed, Maybe some devices have been disconnected.");
635 return;
cheng fan48e832c2015-05-29 01:54:47 +0800636 }
637 tunnelMap.remove(pcepTunnelId);
638 service.tunnelRemoved(tunnel);
cheng fan48e832c2015-05-29 01:54:47 +0800639 }
640
641 @Override
642 public void tunnelUpdated(TunnelDescription tunnel) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530643 handleTunnelUpdate(tunnel, null);
644 }
645
646 public void tunnelUpdated(TunnelDescription tunnel, State tunnelState) {
647 handleTunnelUpdate(tunnel, tunnelState);
648 }
649
650 private void handleTunnelUpdate(TunnelDescription tunnel, State tunnelState) {
651 if (tunnel.type() == MPLS) {
Jonathan Hart51539b82015-10-29 09:53:04 -0700652 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
Avantika-Huawei56c11842016-04-28 00:56:56 +0530653
654 if (tunnelState == null) {
655 service.tunnelUpdated(tunnel);
656 } else {
657 service.tunnelUpdated(tunnel, tunnelState);
658 }
659 return;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530660 }
cheng fan48e832c2015-05-29 01:54:47 +0800661
662 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
663 if (tunnelOld.type() != Tunnel.Type.VLAN) {
cheng fan93258c72015-06-02 23:42:32 +0800664 error("Illegal tunnel type. Only support VLAN tunnel update.");
cheng fan48e832c2015-05-29 01:54:47 +0800665 return;
666 }
cheng fan7716ec92015-05-31 01:53:19 +0800667 long bandwidth = Long
668 .parseLong(tunnel.annotations().value("bandwidth"));
cheng fan48e832c2015-05-29 01:54:47 +0800669 if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
cheng fan7716ec92015-05-31 01:53:19 +0800670 error("Update failed, invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800671 return;
672 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700673 String pcepTunnelId = getPcepTunnelKey(tunnel.id());
cheng fan48e832c2015-05-29 01:54:47 +0800674
675 checkNotNull(pcepTunnelId, "Invalid tunnel id");
676 if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
677
cheng fan7716ec92015-05-31 01:53:19 +0800678 error("Update failed,maybe invalid bandwidth.");
cheng fan48e832c2015-05-29 01:54:47 +0800679 return;
680
681 }
682 service.tunnelUpdated(tunnel);
683 }
684
cheng fan7716ec92015-05-31 01:53:19 +0800685 private void error(String info) {
686 System.err.println(info);
687 }
688
cheng fan48e832c2015-05-29 01:54:47 +0800689 // Short-hand for creating a connection point.
690 private ConnectPoint connectPoint(PcepDpid id, long port) {
691 return new ConnectPoint(deviceId(uri(id)), portNumber(port));
692 }
693
694 // Short-hand for creating a link.
695 private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
Ray Milkey2693bda2016-01-22 16:08:14 -0800696 return DefaultLink.builder()
697 .providerId(id())
698 .src(connectPoint(src, sp))
699 .dst(connectPoint(dst, dp))
700 .type(Link.Type.TUNNEL)
701 .build();
cheng fan48e832c2015-05-29 01:54:47 +0800702 }
703
704 // Creates a path that leads through the given devices.
705 private Path createPath(List<PcepHopNodeDescription> hopList,
Jonathan Hart51539b82015-10-29 09:53:04 -0700706 PathType pathtype, PathState pathState) {
cheng fan48e832c2015-05-29 01:54:47 +0800707 if (hopList == null || hopList.size() == 0) {
708 return null;
709 }
710 List<Link> links = new ArrayList<>();
711 for (int i = 1; i < hopList.size() - 1; i = i + 2) {
712 links.add(link(hopList.get(i).getDeviceId(), hopList.get(i)
713 .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList
714 .get(i + 1).getPortNum()));
715 }
716
717 int hopNum = hopList.size() - 2;
718 DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
719 .set("pathNum", String.valueOf(hopNum))
cheng fan93258c72015-06-02 23:42:32 +0800720 .set("pathState", String.valueOf(pathState))
cheng fan48e832c2015-05-29 01:54:47 +0800721 .set("pathType", String.valueOf(pathtype)).build();
722 return new DefaultPath(id(), links, hopNum, extendAnnotations);
723 }
724
725 // convert the path description to a string.
726 public String pathToString(List<Link> links) {
727 StringBuilder builder = new StringBuilder();
728 builder.append("{");
729 for (Link link : links) {
730 builder.append("(Device:" + link.src().deviceId() + " Port:"
731 + link.src().port().toLong());
732 builder.append(" Device:" + link.dst().deviceId() + " Port:"
733 + link.dst().port().toLong());
734 builder.append(")");
735 }
736 builder.append("}");
737 return builder.toString();
738 }
739
740 // build a TunnelDescription.
741 private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel,
742 TunnelId tunnelId) {
743 TunnelEndPoint srcPoint = null;
744 TunnelEndPoint dstPoint = null;
745 Tunnel.Type tunnelType = null;
746 TunnelName name = TunnelName.tunnelName(pcepTunnel.name());
747
748 // add path after codes of tunnel's path merged
749 Path path = createPath(pcepTunnel.getHopList(),
cheng fan93258c72015-06-02 23:42:32 +0800750 pcepTunnel.getPathType(),
751 pcepTunnel.getPathState());
cheng fan48e832c2015-05-29 01:54:47 +0800752
753 OpticalTunnelEndPoint.Type endPointType = null;
754 switch (pcepTunnel.type()) {
755 case OCH:
756 tunnelType = Tunnel.Type.OCH;
757 endPointType = OpticalTunnelEndPoint.Type.LAMBDA;
758 break;
759
760 case OTN:
761 tunnelType = Tunnel.Type.ODUK;
762 endPointType = OpticalTunnelEndPoint.Type.TIMESLOT;
763 break;
764
765 case UNI:
766 tunnelType = Tunnel.Type.VLAN;
767 endPointType = null;
768 break;
769
770 default:
771 break;
772 }
773 DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID()));
774 DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId()));
775 PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort());
776 PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort());
777
778 srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid),
779 Optional.of(srcPort), null,
780 endPointType,
781 OpticalLogicId.logicId(0),
782 true);
783 dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid),
784 Optional.of(dstPort), null,
785 endPointType,
786 OpticalLogicId.logicId(0),
787 true);
788
789 // basic annotations
cheng fan7716ec92015-05-31 01:53:19 +0800790 DefaultAnnotations annotations = DefaultAnnotations
791 .builder()
cheng fan48e832c2015-05-29 01:54:47 +0800792 .set("SLA", String.valueOf(pcepTunnel.getSla()))
cheng fan7716ec92015-05-31 01:53:19 +0800793 .set("bandwidth",
794 String.valueOf(pcepTunnel.bandWidth()) + BANDWIDTH_UINT)
cheng fan48e832c2015-05-29 01:54:47 +0800795 .set("index", String.valueOf(pcepTunnel.id())).build();
796
cheng fan48e832c2015-05-29 01:54:47 +0800797 // a VLAN tunnel always carry OCH tunnel, this annotation is the index
798 // of a OCH tunnel.
cheng fan93258c72015-06-02 23:42:32 +0800799 if (pcepTunnel.underlayTunnelId() != 0) {
cheng fan48e832c2015-05-29 01:54:47 +0800800 DefaultAnnotations extendAnnotations = DefaultAnnotations
801 .builder()
802 .set("underLayTunnelIndex",
cheng fan93258c72015-06-02 23:42:32 +0800803 String.valueOf(pcepTunnel.underlayTunnelId())).build();
cheng fan48e832c2015-05-29 01:54:47 +0800804 annotations = DefaultAnnotations.merge(annotations,
805 extendAnnotations);
806
807 }
808 TunnelDescription tunnel = new DefaultTunnelDescription(
809 tunnelId,
810 srcPoint,
811 dstPoint,
812 tunnelType,
813 new DefaultGroupId(
814 0),
815 id(), name,
816 path,
817 annotations);
818 return tunnel;
cheng fan48e832c2015-05-29 01:54:47 +0800819 }
820
821 /**
822 * Get the tunnelID according to the tunnel key.
823 *
824 * @param tunnelKey tunnel key
825 * @return corresponding tunnel id of the a tunnel key.
826 */
827 private TunnelId getTunnelId(String tunnelKey) {
cheng fan48e832c2015-05-29 01:54:47 +0800828 for (String key : tunnelMap.keySet()) {
829 if (key.equals(tunnelKey)) {
830 return tunnelMap.get(key);
831 }
832 }
833 return null;
834 }
835
836 /**
837 * Get the tunnel key according to the tunnelID.
838 *
839 * @param tunnelId tunnel id
840 * @return corresponding a tunnel key of the tunnel id.
841 */
Jonathan Hart51539b82015-10-29 09:53:04 -0700842 private String getPcepTunnelKey(TunnelId tunnelId) {
cheng fan48e832c2015-05-29 01:54:47 +0800843 for (String key : tunnelMap.keySet()) {
844 if (tunnelMap.get(key).id() == tunnelId.id()) {
845 return key;
846 }
847 }
848 return null;
849
850 }
851
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530852 /**
chengfan2fff70f2015-08-24 18:20:19 -0500853 * Build a DefaultTunnelStatistics from a PcepTunnelStatistics.
854 *
855 * @param statistics statistics data from a PCEP tunnel
856 * @return TunnelStatistics
857 */
858 private TunnelStatistics buildTunnelStatistics(PcepTunnelStatistics statistics) {
859 DefaultTunnelStatistics.Builder builder = new DefaultTunnelStatistics.Builder();
860 DefaultTunnelStatistics tunnelStatistics = builder.setBwUtilization(statistics.bandwidthUtilization())
861 .setPacketLossRatio(statistics.packetLossRate())
862 .setFlowDelay(statistics.flowDelay())
863 .setAlarms(statistics.alarms())
864 .build();
865 return tunnelStatistics;
866 }
867 /**
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530868 * Creates list of hops for ERO object from Path.
869 *
870 * @param path network path
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530871 * @return list of ERO subobjects
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530872 */
873 private LinkedList<PcepValueType> createPcepPath(Path path) {
874 LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
875 List<Link> listLink = path.links();
876 ConnectPoint source = null;
877 ConnectPoint destination = null;
878 IpAddress ipDstAddress = null;
879 IpAddress ipSrcAddress = null;
880 PcepValueType subObj = null;
Priyanka Bcdf9b102016-06-07 20:01:38 +0530881 long portNo;
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530882
883 for (Link link : listLink) {
884 source = link.src();
885 if (!(source.equals(destination))) {
886 //set IPv4SubObject for ERO object
Priyanka Bcdf9b102016-06-07 20:01:38 +0530887 portNo = source.port().toLong();
888 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
889 ipSrcAddress = Ip4Address.valueOf((int) portNo);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530890 subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
891 llSubObjects.add(subObj);
892 }
893
894 destination = link.dst();
Priyanka Bcdf9b102016-06-07 20:01:38 +0530895 portNo = destination.port().toLong();
896 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
897 ipDstAddress = Ip4Address.valueOf((int) portNo);
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530898 subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
899 llSubObjects.add(subObj);
900 }
Priyanka Bcdf9b102016-06-07 20:01:38 +0530901
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530902 return llSubObjects;
903 }
904
905 /**
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530906 * Creates label stack for ERO object from network resource.
907 *
908 * @param labelStack
909 * @param path (hop list)
910 * @return list of ERO subobjects
911 */
912 private LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
913 checkNotNull(labelStack);
914
915 LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
916 Iterator<Link> links = path.links().iterator();
917 LabelResourceId label = null;
918 Link link = null;
919 PcepValueType subObj = null;
920 PcepNai nai = null;
921 Device dstNode = null;
922 long srcPortNo, dstPortNo;
923
924 ListIterator<LabelResourceId> labelListIterator = labelStack.labelResources().listIterator();
925 while (labelListIterator.hasNext()) {
926 label = labelListIterator.next();
927 link = links.next();
928
929 srcPortNo = link.src().port().toLong();
930 srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo;
931
932 dstPortNo = link.dst().port().toLong();
933 dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo;
934
935 nai = new PcepNaiIpv4Adjacency((int) srcPortNo, (int) dstPortNo);
936 subObj = new SrEroSubObject(PcepNaiIpv4Adjacency.ST_TYPE, false, false, false, true, (int) label.labelId(),
937 nai);
938 llSubObjects.add(subObj);
939
940 dstNode = deviceService.getDevice(link.dst().deviceId());
941 nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt());
942
943 if (!labelListIterator.hasNext()) {
944 log.error("Malformed label stack.");
945 }
946 label = labelListIterator.next();
947 subObj = new SrEroSubObject(PcepNaiIpv4NodeId.ST_TYPE, false, false, false, true, (int) label.labelId(),
948 nai);
949 llSubObjects.add(subObj);
950 }
951 return llSubObjects;
952 }
953
954 /**
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530955 * Creates PcInitiated lsp request list for setup tunnel.
956 *
957 * @param tunnel mpls tunnel
958 * @param path network path
959 * @param pc pcep client
960 * @param srpId unique id for pcep message
961 * @return list of PcInitiatedLspRequest
962 * @throws PcepParseException while building pcep objects fails
963 */
964 LinkedList<PcInitiatedLspRequest> createPcInitiatedLspReqList(Tunnel tunnel, Path path,
965 PcepClient pc, int srpId)
966 throws PcepParseException {
967 PcepValueType tlv;
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530968 LinkedList<PcepValueType> llSubObjects = null;
969
970 NetworkResource labelStack = tunnel.resource();
971 if (labelStack != null && labelStack instanceof DefaultLabelStack) {
972 llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
973 } else {
974 llSubObjects = createPcepPath(path);
975 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530976
Sho SHIMIZUde09fa02015-09-03 09:39:52 -0700977 if (llSubObjects == null || llSubObjects.size() == 0) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530978 log.error("There is no link information to create tunnel");
979 return null;
980 }
981
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530982 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530983
984 // set PathSetupTypeTlv of SRP object
985 tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)).type());
986 llOptionalTlv.add(tlv);
987
988 // build SRP object
989 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
990 .setOptionalTlv(llOptionalTlv).build();
991
992 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530993 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530994
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530995 // set LSP identifiers TLV
Avantika-Huawei56c11842016-04-28 00:56:56 +0530996 short localLspId = 0;
997 if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITH_SIGNALLING) {
998 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
999 if (localLspIdString != null) {
1000 localLspId = Short.valueOf(localLspIdString);
1001 }
1002 }
1003
Priyanka B4c3cef02016-06-14 20:27:53 +05301004 tunnel.annotations().value(LSP_SIG_TYPE);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301005 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
1006 localLspId, (short) 0, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
1007 .getIp4Address().toInt()));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301008 llOptionalTlv.add(tlv);
1009 //set SymbolicPathNameTlv of LSP object
1010 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
1011 llOptionalTlv.add(tlv);
1012
1013 //build LSP object
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301014 PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setDFlag(true).setOFlag((byte) 0)
1015 .setPlspId(0).setOptionalTlv(llOptionalTlv).build();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301016
1017 //build ENDPOINTS object
1018 PcepEndPointsObject endpointsobj = pc.factory().buildEndPointsObject()
1019 .setSourceIpAddress(((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt())
1020 .setDestIpAddress(((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())
1021 .setPFlag(true).build();
1022
1023 //build ERO object
1024 PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
1025
Priyanka Bc1e4e4c2016-07-01 14:57:19 +05301026 float iBandwidth = DEFAULT_BANDWIDTH_VALUE;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301027 if (tunnel.annotations().value(BANDWIDTH) != null) {
Priyanka Bc1e4e4c2016-07-01 14:57:19 +05301028 iBandwidth = Float.valueOf(tunnel.annotations().value(BANDWIDTH));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301029 }
1030 // build bandwidth object
1031 PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
1032 // build pcep attribute
1033 PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build();
1034
1035 PcInitiatedLspRequest initiateLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj)
1036 .setLspObject(lspobj).setEndPointsObject(endpointsobj).setEroObject(eroobj)
1037 .setPcepAttribute(pcepAttribute).build();
1038 llPcInitiatedLspRequestList.add(initiateLspRequest);
1039 return llPcInitiatedLspRequestList;
1040 }
1041
1042 /**
1043 * To send initiate tunnel message to pcc.
1044 *
1045 * @param tunnel mpls tunnel info
1046 * @param path explicit route for the tunnel
1047 * @param pc pcep client to send message
1048 */
1049 private void pcepSetupTunnel(Tunnel tunnel, Path path, PcepClient pc) {
1050 try {
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +05301051 if (!(pc.lspDbSyncStatus().equals(PcepSyncStatus.SYNCED))) {
1052 log.error("Setup tunnel has failed as LSP DB sync is not finished");
1053 return;
1054 }
1055
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301056 int srpId = SrpIdGenerators.create();
Priyanka B4c3cef02016-06-14 20:27:53 +05301057 Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
1058 for (Tunnel t : tunnels) {
1059 if (t.tunnelName().equals(tunnel.tunnelName())) {
1060 tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
1061 tunnel.dst(), tunnel.type(),
1062 t.state(), tunnel.groupId(),
1063 t.tunnelId(),
1064 tunnel.tunnelName(),
1065 tunnel.path(),
1066 tunnel.resource(),
1067 tunnel.annotations());
Priyanka B4c3b4512016-07-22 11:41:49 +05301068 break;
Priyanka B4c3cef02016-06-14 20:27:53 +05301069 }
1070 }
1071
1072 if (tunnel.tunnelId() == null) {
1073 log.error("Tunnel ID not found");
1074 return;
1075 }
1076
Avantika-Huawei56c11842016-04-28 00:56:56 +05301077 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, CREATE);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301078
Jonathan Hart51539b82015-10-29 09:53:04 -07001079 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301080
1081 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = createPcInitiatedLspReqList(tunnel, path,
1082 pc, srpId);
Sho SHIMIZUde09fa02015-09-03 09:39:52 -07001083 if (llPcInitiatedLspRequestList == null || llPcInitiatedLspRequestList.size() == 0) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301084 log.error("Failed to create PcInitiatedLspRequestList");
1085 return;
1086 }
1087
1088 //build PCInitiate message
1089 PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
1090 .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList)
1091 .build();
1092
1093 pc.sendMessage(Collections.singletonList(pcInitiateMsg));
1094
Jonathan Hart51539b82015-10-29 09:53:04 -07001095 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301096 } catch (PcepParseException e) {
1097 log.error("PcepParseException occurred while processing setup tunnel {}", e.getMessage());
1098 }
1099 }
1100
1101 /**
1102 * To send Release tunnel message to pcc.
1103 *
1104 * @param tunnel mpls tunnel info
1105 * @param pc pcep client to send message
1106 */
1107 private void pcepReleaseTunnel(Tunnel tunnel, PcepClient pc) {
1108 try {
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +05301109 if (!(pc.lspDbSyncStatus().equals(PcepSyncStatus.SYNCED))) {
1110 log.error("Release tunnel has failed as LSP DB sync is not finished");
1111 return;
1112 }
1113
Avantika-Huawei56c11842016-04-28 00:56:56 +05301114 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE);
Jonathan Hart51539b82015-10-29 09:53:04 -07001115 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301116 int srpId = SrpIdGenerators.create();
1117 TunnelId tunnelId = tunnel.tunnelId();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301118
1119 PcepValueType tlv;
1120 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301121
1122 // set PathSetupTypeTlv of SRP object
1123 tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))
1124 .type());
1125 llOptionalTlv.add(tlv);
1126
1127 // build SRP object
1128 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true)
1129 .setOptionalTlv(llOptionalTlv).build();
1130
1131 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301132 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
1133
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301134 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
1135 llOptionalTlv.add(tlv);
Priyanka B4c3cef02016-06-14 20:27:53 +05301136
1137 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
1138 String pccTunnelIdString = tunnel.annotations().value(PCC_TUNNEL_ID);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301139 String pLspIdString = tunnel.annotations().value(PLSP_ID);
1140
Priyanka B4c3cef02016-06-14 20:27:53 +05301141 short localLspId = 0;
1142 short pccTunnelId = 0;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301143 int plspId = 0;
Priyanka B4c3cef02016-06-14 20:27:53 +05301144
1145 if (localLspIdString != null) {
1146 localLspId = Short.valueOf(localLspIdString);
1147 }
1148
1149 if (pccTunnelIdString != null) {
1150 pccTunnelId = Short.valueOf(pccTunnelIdString);
1151 }
1152
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301153 if (pLspIdString != null) {
1154 plspId = Integer.valueOf(pLspIdString);
1155 }
1156
Priyanka B4c3cef02016-06-14 20:27:53 +05301157 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src())
1158 .ip().getIp4Address().toInt()),
1159 localLspId, pccTunnelId, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
1160 .getIp4Address().toInt()));
1161 llOptionalTlv.add(tlv);
1162
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301163 // build lsp object, set r flag as false to delete the tunnel
1164 PcepLspObject lspobj = pc.factory().buildLspObject().setRFlag(false).setPlspId(plspId)
1165 .setOptionalTlv(llOptionalTlv).build();
1166
1167 PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj)
1168 .setLspObject(lspobj).build();
1169
1170 llPcInitiatedLspRequestList.add(releaseLspRequest);
1171
1172 PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
1173 .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
1174
1175 pc.sendMessage(Collections.singletonList(pcInitiateMsg));
1176
Jonathan Hart51539b82015-10-29 09:53:04 -07001177 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301178 } catch (PcepParseException e) {
1179 log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage());
1180 }
1181 }
1182
1183 /**
1184 * To send Update tunnel request message to pcc.
1185 *
1186 * @param tunnel mpls tunnel info
1187 * @param path explicit route for the tunnel
1188 * @param pc pcep client to send message
1189 */
1190 private void pcepUpdateTunnel(Tunnel tunnel, Path path, PcepClient pc) {
1191 try {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301192 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE);
Jonathan Hart51539b82015-10-29 09:53:04 -07001193 pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301194 int srpId = SrpIdGenerators.create();
1195 TunnelId tunnelId = tunnel.tunnelId();
1196 PcepValueType tlv;
1197 int plspId = 0;
1198
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301199 LinkedList<PcepValueType> llSubObjects = null;
1200 NetworkResource labelStack = tunnel.resource();
1201 if (labelStack != null && labelStack instanceof DefaultLabelStack) {
1202 llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
1203 } else {
1204 llSubObjects = createPcepPath(path);
1205 }
1206
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301207 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
1208 LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
1209
Avantika-Huawei56c11842016-04-28 00:56:56 +05301210 // set PathSetupTypeTlv of SRP object
1211 LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
1212 tlv = new PathSetupTypeTlv(lspSigType.type());
1213 llOptionalTlv.add(tlv);
1214
1215 // build SRP object
1216 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
1217 .setOptionalTlv(llOptionalTlv).build();
1218
1219 llOptionalTlv = new LinkedList<PcepValueType>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301220
Avantika-Huawei56c11842016-04-28 00:56:56 +05301221 if (lspSigType != WITH_SIGNALLING) {
1222 String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
1223 String pccTunnelIdString = tunnel.annotations().value(PCC_TUNNEL_ID);
1224 short localLspId = 0;
1225 short pccTunnelId = 0;
1226
1227 if (localLspIdString != null) {
1228 localLspId = Short.valueOf(localLspIdString);
1229 }
1230
1231 if (pccTunnelIdString != null) {
1232 pccTunnelId = Short.valueOf(pccTunnelIdString);
1233 }
1234
1235 tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src())
1236 .ip().getIp4Address().toInt()),
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301237 localLspId, pccTunnelId,
1238 ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(),
1239 (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()));
Avantika-Huawei56c11842016-04-28 00:56:56 +05301240 llOptionalTlv.add(tlv);
1241 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301242
1243 if (tunnel.tunnelName().value() != null) {
1244 tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
1245 llOptionalTlv.add(tlv);
1246 }
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301247 boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false
1248 : Boolean.valueOf(tunnel.annotations()
1249 .value(DELEGATE));
1250 boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false
1251 : Boolean.valueOf(tunnel.annotations()
1252 .value(PCE_INIT));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301253 // build lsp object
Priyanka B4c3cef02016-06-14 20:27:53 +05301254 PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true)
1255 .setPlspId(Integer.valueOf(tunnel.annotations().value(PLSP_ID)))
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +05301256 .setDFlag(delegated)
1257 .setCFlag(initiated)
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301258 .setOptionalTlv(llOptionalTlv).build();
1259 // build ero object
1260 PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
Priyanka B4c3cef02016-06-14 20:27:53 +05301261 float iBandwidth = DEFAULT_BANDWIDTH_VALUE;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301262 if (tunnel.annotations().value(BANDWIDTH) != null) {
Priyanka B4c3cef02016-06-14 20:27:53 +05301263 iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301264 }
1265 // build bandwidth object
1266 PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
1267 // build pcep attribute
1268 PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build();
1269 // build pcep msg path
1270 PcepMsgPath msgPath = pc.factory().buildPcepMsgPath().setEroObject(eroobj).setPcepAttribute(pcepAttribute)
1271 .build();
1272
1273 PcepUpdateRequest updateRequest = pc.factory().buildPcepUpdateRequest().setSrpObject(srpobj)
1274 .setLspObject(lspobj).setMsgPath(msgPath).build();
1275
1276 llUpdateRequestList.add(updateRequest);
1277
1278 PcepUpdateMsg pcUpdateMsg = pc.factory().buildUpdateMsg().setUpdateRequestList(llUpdateRequestList).build();
1279
1280 pc.sendMessage(Collections.singletonList(pcUpdateMsg));
Jonathan Hart51539b82015-10-29 09:53:04 -07001281 pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301282 } catch (PcepParseException e) {
1283 log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage());
1284 }
1285 }
1286
chengfan2fff70f2015-08-24 18:20:19 -05001287
1288
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301289 private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener {
cheng fan48e832c2015-05-29 01:54:47 +08001290
1291 @Override
Jonathan Hart51539b82015-10-29 09:53:04 -07001292 public void handlePcepTunnel(PcepTunnel pcepTunnel) {
cheng fan48e832c2015-05-29 01:54:47 +08001293 TunnelDescription tunnel = null;
1294 // instance and id identify a tunnel together
1295 String tunnelKey = String.valueOf(pcepTunnel.getInstance())
1296 + String.valueOf(pcepTunnel.id());
1297
1298 if (tunnelKey == null || "".equals(tunnelKey)) {
1299 log.error("Invalid PCEP tunnel");
1300 return;
1301 }
1302
1303 TunnelId tunnelId = getTunnelId(tunnelKey);
1304
1305 tunnel = buildOpticalTunnel(pcepTunnel, tunnelId);
1306
1307 OperationType operType = pcepTunnel.getOperationType();
1308 switch (operType) {
1309 case ADD:
1310 tunnelId = service.tunnelAdded(tunnel);
1311 tunnelMap.put(tunnelKey, tunnelId);
1312 break;
1313
1314 case UPDATE:
1315 service.tunnelUpdated(tunnel);
1316 break;
1317
1318 case DELETE:
1319 service.tunnelRemoved(tunnel);
1320 tunnelMap.remove(tunnelKey);
1321 break;
1322
1323 default:
1324 log.error("Invalid tunnel operation");
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301325 }
1326 }
cheng fan48e832c2015-05-29 01:54:47 +08001327
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301328 @Override
1329 public void handleMessage(PccId pccId, PcepMessage msg) {
1330 try {
1331 log.debug("tunnel provider handle message {}", msg.getType().toString());
1332 switch (msg.getType()) {
1333 case REPORT:
1334 int srpId = 0;
1335 LinkedList<PcepStateReport> llStateReportList = null;
1336 llStateReportList = ((PcepReportMsg) msg).getStateReportList();
1337 ListIterator<PcepStateReport> listIterator = llStateReportList.listIterator();
1338 PcepSrpObject srpObj = null;
1339 PcepLspObject lspObj = null;
1340 while (listIterator.hasNext()) {
1341 PcepStateReport stateRpt = listIterator.next();
1342 srpObj = stateRpt.getSrpObject();
1343 lspObj = stateRpt.getLspObject();
1344
1345 if (srpObj instanceof PcepSrpObject) {
1346 srpId = srpObj.getSrpID();
1347 }
1348
1349 log.debug("Plsp ID in handle message " + lspObj.getPlspId());
1350 log.debug("SRP ID in handle message " + srpId);
1351
Jonathan Hart51539b82015-10-29 09:53:04 -07001352 if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301353 // For PCRpt without matching SRP id.
1354 handleRptWithoutSrpId(stateRpt, pccId);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301355 continue;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301356 }
1357
Avantika-Huawei56c11842016-04-28 00:56:56 +05301358 handleReportMessage(srpId, lspObj, stateRpt);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301359 }
1360 break;
1361
1362 default:
1363 log.debug("Received unsupported message type {}", msg.getType().toString());
1364 }
1365 } catch (Exception e) {
1366 log.error("Exception occured while processing report message {}", e.getMessage());
1367 }
1368 }
1369
1370 /**
1371 * Handles report message for setup/update/delete tunnel request.
1372 *
Avantika-Huawei56c11842016-04-28 00:56:56 +05301373 * @param srpId unique identifier for PCEP message
1374 * @param lspObj LSP object
1375 * @param stateRpt parsed PCEP report msg.
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301376 */
Avantika-Huawei56c11842016-04-28 00:56:56 +05301377 private void handleReportMessage(int srpId, PcepLspObject lspObj, PcepStateReport stateRpt) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301378 ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
Jonathan Hart51539b82015-10-29 09:53:04 -07001379 PcepTunnelData pcepTunnelData = pcepTunnelApiMapper.getDataFromTunnelRequestQueue(srpId);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301380
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301381 // store the values required from report message
1382 pcepTunnelData.setPlspId(lspObj.getPlspId());
1383 pcepTunnelData.setLspAFlag(lspObj.getAFlag());
1384 pcepTunnelData.setLspOFlag(lspObj.getOFlag());
1385 pcepTunnelData.setLspDFlag(lspObj.getDFlag());
1386
Avantika-Huawei56c11842016-04-28 00:56:56 +05301387 StatefulIPv4LspIdentifiersTlv ipv4LspTlv = null;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301388 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
1389 while (listTlvIterator.hasNext()) {
1390 PcepValueType tlv = listTlvIterator.next();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301391 if (tlv.getType() == StatefulIPv4LspIdentifiersTlv.TYPE) {
1392 ipv4LspTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301393 break;
1394 }
1395 }
Sho SHIMIZUde09fa02015-09-03 09:39:52 -07001396 if (ipv4LspTlv != null) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301397 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspTlv);
cheng fan48e832c2015-05-29 01:54:47 +08001398 }
1399
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301400 Path path = pcepTunnelData.path();
1401 Tunnel tunnel = pcepTunnelData.tunnel();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301402 Builder annotationBuilder = DefaultAnnotations.builder();
1403 annotationBuilder.putAll(pcepTunnelData.tunnel().annotations());
1404
1405 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
1406 if (tunnel.annotations().value(PLSP_ID) == null) {
1407 annotationBuilder.set(PLSP_ID, String.valueOf(lspObj.getPlspId()));
1408 }
1409
1410 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
1411 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1412 annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(ipv4LspTlv.getLspId()));
1413 }
1414
Priyanka B4c3cef02016-06-14 20:27:53 +05301415 if (tunnel.annotations().value(PCC_TUNNEL_ID) == null) {
1416 annotationBuilder.set(PCC_TUNNEL_ID, String.valueOf(ipv4LspTlv.getTunnelId()));
1417 }
1418
Avantika-Huawei56c11842016-04-28 00:56:56 +05301419 SparseAnnotations annotations = annotationBuilder.build();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301420 DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(),
1421 tunnel.dst(), tunnel.type(), tunnel.groupId(),
1422 providerId, tunnel.tunnelName(), path,
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301423 tunnel.resource(), annotations);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301424
Avantika-Huawei56c11842016-04-28 00:56:56 +05301425 if (CREATE == pcepTunnelData.requestType()) {
Priyanka B4c3cef02016-06-14 20:27:53 +05301426 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Jonathan Hart51539b82015-10-29 09:53:04 -07001427 pcepTunnelApiMapper.handleCreateTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301428 } else if (DELETE == pcepTunnelData.requestType()) {
Jonathan Hart51539b82015-10-29 09:53:04 -07001429 pcepTunnelApiMapper.handleRemoveFromTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301430 } else if (UPDATE == pcepTunnelData.requestType()) {
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301431 pcepTunnelData.setRptFlag(true);
Jonathan Hart51539b82015-10-29 09:53:04 -07001432 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1433 pcepTunnelApiMapper.handleUpdateTunnelRequestQueue(srpId, pcepTunnelData);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301434 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301435
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301436 PcepLspStatus pcepLspStatus = PcepLspStatus.values()[lspObj.getOFlag()];
1437
Avantika-Huawei56c11842016-04-28 00:56:56 +05301438 if (lspObj.getRFlag()) {
1439 tunnelRemoved(td);
1440 } else {
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301441 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(pcepLspStatus);
Avantika-Huawei56c11842016-04-28 00:56:56 +05301442 tunnelUpdated(td, tunnelState);
1443 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301444
1445 // SR-TE also needs PCUpd msg after receiving PCRpt with status GOING-UP even
1446 // though there are no labels to download for SR-TE.
1447 if ((pcepLspStatus == PcepLspStatus.GOING_UP)
1448 && (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) == SR_WITHOUT_SIGNALLING)) {
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301449 // Query again to get latest tunnel updated with protocol values from PCRpt msg.
1450 updateTunnel(service.tunnelQueryById(tunnel.tunnelId()), tunnel.path());
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301451 }
Avantika-Huawei56c11842016-04-28 00:56:56 +05301452 }
1453
Priyanka B413fbe82016-05-26 11:44:45 +05301454 private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
Priyanka B4c3b4512016-07-22 11:41:49 +05301455 String bandwidth, LspType lspType, String costType, boolean isPceInit) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301456 Builder builder = DefaultAnnotations.builder();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301457 /*
1458 * [RFC 5440] The absence of the METRIC object MUST be interpreted by the PCE as a path computation request
1459 * for which no constraints need be applied to any of the metrics.
1460 */
1461 if (costType != null) {
1462 builder.set(COST_TYPE, costType);
1463 }
1464
Priyanka B4c3b4512016-07-22 11:41:49 +05301465 if (isPceInit) {
1466 builder.set(PCE_INIT, String.valueOf(isPceInit));
1467 }
1468
1469 if (bandwidth != null) {
1470 builder.set(BANDWIDTH, bandwidth);
1471 }
1472
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301473 SparseAnnotations annotations = builder
Priyanka B4c3b4512016-07-22 11:41:49 +05301474 .set(LSP_SIG_TYPE, lspType.name())
Priyanka B413fbe82016-05-26 11:44:45 +05301475 .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1476 .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1477 .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId()))
1478 .set(DELEGATE, String.valueOf(lspObj.getDFlag()))
1479 .build();
1480 return annotations;
1481 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301482
Priyanka B413fbe82016-05-26 11:44:45 +05301483 private LspType getLspType(PcepSrpObject srpObj) {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301484 LspType lspType = WITH_SIGNALLING;
1485
1486 if (null != srpObj) {
1487 LinkedList<PcepValueType> llOptionalTlv = srpObj.getOptionalTlv();
1488 ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
1489
1490 while (listIterator.hasNext()) {
1491 PcepValueType tlv = listIterator.next();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301492 switch (tlv.getType()) {
1493 case PathSetupTypeTlv.TYPE:
1494 lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())];
1495 break;
Avantika-Huawei56c11842016-04-28 00:56:56 +05301496 default:
1497 break;
1498 }
1499 }
1500 }
Priyanka B413fbe82016-05-26 11:44:45 +05301501 return lspType;
1502 }
1503
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301504 private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId) {
Priyanka B413fbe82016-05-26 11:44:45 +05301505 ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301506 String costType = null;
Priyanka B413fbe82016-05-26 11:44:45 +05301507 PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
1508 checkNotNull(msgPath);
1509 PcepEroObject eroObj = msgPath.getEroObject();
1510 if (eroObj == null) {
1511 log.error("ERO object is null in report message.");
1512 return;
1513 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301514 PcepAttribute attributes = msgPath.getPcepAttribute();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301515 float bandwidth = 0;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301516 int cost = 0;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301517 if (attributes != null) {
1518 if (attributes.getMetricObjectList() != null) {
1519 ListIterator<PcepMetricObject> iterator = attributes.getMetricObjectList().listIterator();
1520 PcepMetricObject metricObj = iterator.next();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301521
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301522 while (metricObj != null) {
1523 if (metricObj.getBType() == IGP_METRIC) {
1524 costType = "COST";
1525 } else if (metricObj.getBType() == TE_METRIC) {
1526 costType = "TE_COST";
1527 }
1528 if (costType != null) {
1529 cost = metricObj.getMetricVal();
1530 log.debug("Path cost {}", cost);
1531 break;
1532 }
1533 metricObj = iterator.next();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301534 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301535 }
1536 if (attributes.getBandwidthObject() != null) {
1537 bandwidth = attributes.getBandwidthObject().getBandwidth();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301538 }
1539 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301540 PcepLspObject lspObj = stateRpt.getLspObject();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301541 List<Object> eroSubObjList = buildPathFromEroObj(eroObj, providerId);
1542 List<Link> links = new ArrayList<>();
1543 List<LabelResourceId> labels = new ArrayList<>();
1544 for (Object linkOrLabel : eroSubObjList) {
1545 if (linkOrLabel instanceof Link) {
1546 links.add((Link) linkOrLabel);
1547 } else if (linkOrLabel instanceof Integer) {
1548 labels.add(LabelResourceId.labelResourceId(((Integer) linkOrLabel).longValue()));
1549 }
Priyanka B413fbe82016-05-26 11:44:45 +05301550 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301551 Path path = null;
1552 if (!links.isEmpty()) {
1553 path = new DefaultPath(providerId, links, cost, EMPTY);
1554 } else if (!lspObj.getRFlag()) {
1555 return;
1556 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301557 NetworkResource labelStack = new DefaultLabelStack(labels);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301558 // To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
1559 // from PCE.
Priyanka B413fbe82016-05-26 11:44:45 +05301560 PcepSrpObject srpObj = stateRpt.getSrpObject();
1561 LspType lspType = getLspType(srpObj);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301562 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
1563 StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
1564 SymbolicPathNameTlv pathNameTlv = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301565 while (listTlvIterator.hasNext()) {
1566 PcepValueType tlv = listTlvIterator.next();
1567 switch (tlv.getType()) {
1568 case StatefulIPv4LspIdentifiersTlv.TYPE:
1569 ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
1570 break;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301571 case SymbolicPathNameTlv.TYPE:
1572 pathNameTlv = (SymbolicPathNameTlv) tlv;
1573 break;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301574 default:
1575 break;
1576 }
1577 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301578 /*
1579 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for
1580 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory.
1581 */
1582 if (ipv4LspIdenTlv == null) {
1583 log.error("Stateful IPv4 identifier TLV is null in PCRpt msg.");
1584 return;
1585 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301586 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint
1587 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4IngressAddress()));
1588 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint
1589 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress()));
1590 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
Priyanka B413fbe82016-05-26 11:44:45 +05301591 // Store delegation flag info and that LSP info because only delegated PCE sends update message
1592 // Storing if D flag is set, if not dont store. while checking whether delegation if annotation for D flag
1593 // not present then non-delegated , if present it is delegated.
1594 if (lspObj.getDFlag()) {
1595 pcepClientController.getClient(pccId).setLspAndDelegationInfo(
1596 new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId()), lspObj.getDFlag());
1597 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301598 Tunnel tunnel = null;
Priyanka B4c3b4512016-07-22 11:41:49 +05301599 SparseAnnotations oldTunnelAnnotations = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301600 // Asynchronous status change message from PCC for LSP reported earlier.
1601 for (Tunnel tunnelObj : tunnelQueryResult) {
1602 if (tunnelObj.annotations().value(PLSP_ID) == null) {
1603 /*
1604 * PLSP_ID is null while Tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by
1605 * PCC and in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic
1606 * path name must be carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be
1607 * included in the LSP object in the LSP State Report (PCRpt) message when during a given PCEP
1608 * session an LSP is "first" reported to a PCE.
1609 */
1610 if ((pathNameTlv != null)
1611 && Arrays.equals(tunnelObj.tunnelName().value().getBytes(), pathNameTlv.getValue())) {
1612 tunnel = tunnelObj;
1613 break;
1614 }
1615 continue;
1616 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301617 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId())) {
1618 if ((Integer
1619 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) {
1620 tunnel = tunnelObj;
1621 }
1622 if ((Integer
1623 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) != ipv4LspIdenTlv.getLspId())) {
1624 oldTunnelAnnotations = (SparseAnnotations) tunnelObj.annotations();
1625 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301626 }
1627 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301628 DefaultTunnelDescription td;
Priyanka B413fbe82016-05-26 11:44:45 +05301629 SparseAnnotations annotations = null;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301630 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
1631 if (tunnel == null) {
1632 if (lspObj.getRFlag()) {
1633 /*
1634 * If PCC sends remove message and for any reason PCE does not have that entry, simply discard the
1635 * message. Or if PCRpt for initiated LSP received and PCE doesn't know, then too discard.
1636 */
1637 return;
1638 }
Priyanka B413fbe82016-05-26 11:44:45 +05301639 DeviceId deviceId = getDevice(pccId);
1640 if (deviceId == null) {
1641 log.error("Ingress deviceId not found");
1642 return;
1643 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301644 String tempBandwidth = null;
1645 String temoCostType = null;
1646 if (oldTunnelAnnotations != null) {
1647 tempBandwidth = oldTunnelAnnotations.value(BANDWIDTH);
1648 temoCostType = oldTunnelAnnotations.value(COST_TYPE);
1649 }
1650 annotations = getAnnotations(lspObj, ipv4LspIdenTlv, tempBandwidth, lspType,
1651 temoCostType, lspObj.getCFlag());
Priyanka B413fbe82016-05-26 11:44:45 +05301652 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301653 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
Priyanka B413fbe82016-05-26 11:44:45 +05301654 annotations);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301655 // Do not support PCC initiated LSP after LSP DB sync is completed.
1656 if (!lspObj.getSFlag() && !lspObj.getCFlag()) {
1657 log.error("Received PCC initiated LSP while not in sync.");
1658 return;
1659 }
Priyanka B413fbe82016-05-26 11:44:45 +05301660 /*
1661 * If ONOS instance is master for PCC then set delegated flag as annotation and add the tunnel to store.
1662 * Because all LSPs need not be delegated, hence mastership for the PCC is confirmed whereas not the
1663 * delegation set to all LSPs.If ONOS is not the master for that PCC then check if D flag is set, if yes
1664 * wait for 2 seconds [while master has added the tunnel to the store] then update the tunnel. Tunnel is
1665 * updated because in case of resilency only delegated LSPs are recomputed and only delegated PCE can
1666 * send update message to that client.
1667 *
1668 * 1)Master can 1st get the Rpt message
1669 * a)Master adds the tunnel into core.
1670 * b)If a non-master for ingress gets Rpt message with D flag set[as delegation owner]
1671 * after master, then runs timer then update the tunnel with D flag set.
1672 * 2)Non-Master can 1st get the Rpt message
1673 * a)Non-Master runs the timer check for the tunnel then updates the tunnel with D flag set
1674 * b)Master would have got the message while the non-master running timer, hence master adds
1675 * tunnel to core
1676 *
1677 * In general always master adds the tunnel to the core
1678 * while delegated owner [master or non-master with D flag set] always updates the tunnel running timer
1679 */
1680 if (mastershipService.isLocalMaster(deviceId)) {
1681 TunnelId tId = tunnelAdded(td, tunnelState);
1682 Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1683 tunnelState, new DefaultGroupId(0), tId, TunnelName.tunnelName(String.valueOf(pathNameTlv
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301684 .getValue())), path, labelStack, annotations);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301685
Priyanka B413fbe82016-05-26 11:44:45 +05301686 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT);
1687 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1688 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1689 } else if (!mastershipService.isLocalMaster(deviceId) && lspObj.getDFlag()) {
1690 //Start timer then update the tunnel with D flag
Priyanka B4c3b4512016-07-22 11:41:49 +05301691 tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId, tunnelState, ipv4LspIdenTlv);
Priyanka B413fbe82016-05-26 11:44:45 +05301692 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301693 return;
1694 }
Priyanka B413fbe82016-05-26 11:44:45 +05301695 //delegated owner will update can be a master or non-master
Priyanka B4c3b4512016-07-22 11:41:49 +05301696 if (lspObj.getDFlag() && !lspObj.getRFlag()) {
1697 tunnelUpdateForDelegatedLsp(tunnel, lspObj,
1698 lspType, tunnelState, pccId, labelStack, ipv4LspIdenTlv);
1699 return;
Priyanka B413fbe82016-05-26 11:44:45 +05301700 }
Priyanka B4c3b4512016-07-22 11:41:49 +05301701 removeOrUpdatetunnel(tunnel, lspObj, providerId, tunnelState, ipv4LspIdenTlv);
Priyanka B413fbe82016-05-26 11:44:45 +05301702 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301703
Priyanka B4c3b4512016-07-22 11:41:49 +05301704 private void tunnelUpdateForDelegatedLsp(Tunnel tunnel, PcepLspObject lspObj,
1705 LspType lspType, State tunnelState, PccId pccId,
1706 NetworkResource labelStack,
1707 StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
1708 SparseAnnotations annotations = null;
1709 DefaultTunnelDescription td;
1710 boolean isPceInit = tunnel.annotations().value(PCE_INIT) == null ? false :
1711 Boolean.valueOf((tunnel.annotations().value(PCE_INIT))).booleanValue();
1712 annotations = getAnnotations(lspObj, ipv4LspIdenTlv,
1713 tunnel.annotations().value(BANDWIDTH), lspType,
1714 tunnel.annotations().value(COST_TYPE), isPceInit);
1715 td = new DefaultTunnelDescription(null, tunnel.src(), tunnel.dst(), MPLS, new DefaultGroupId(
1716 0), tunnel.providerId(), tunnel.tunnelName(),
1717 tunnel.path(), labelStack, annotations);
1718 tunnelUpdateInDelegatedCase(pccId, annotations, td, tunnel.providerId(), tunnelState, ipv4LspIdenTlv);
1719 }
1720
1721 private void removeOrUpdatetunnel(Tunnel tunnel, PcepLspObject lspObj, ProviderId providerId,
1722 State tunnelState, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
Priyanka B413fbe82016-05-26 11:44:45 +05301723 DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
1724 tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
1725 (SparseAnnotations) tunnel.annotations());
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301726 if (lspObj.getRFlag()) {
1727 tunnelRemoved(td);
1728 } else {
Priyanka B4c3b4512016-07-22 11:41:49 +05301729 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
1730 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1731 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301732 tunnelUpdated(td, tunnelState);
1733 }
Priyanka B413fbe82016-05-26 11:44:45 +05301734 }
1735
1736 private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
Priyanka B4c3b4512016-07-22 11:41:49 +05301737 DefaultTunnelDescription td, ProviderId providerId, State tunnelState,
1738 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
Priyanka B413fbe82016-05-26 11:44:45 +05301739 //Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
1740
1741 /*
1742 * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while
1743 * master has added the tunnel to the store] then update the tunnel.
1744 */
1745 ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
1746
1747 // Thread is started after 2 seconds first time later periodically after 2 seconds to update the tunnel
1748 executor.scheduleAtFixedRate(new UpdateDelegation(td, providerId, annotations, pccId,
Priyanka B4c3b4512016-07-22 11:41:49 +05301749 executor, tunnelState, ipv4LspIdentifiersTlv), DELAY, DELAY, TimeUnit.SECONDS);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301750 }
1751
1752 /**
Avantika-Huawei56c11842016-04-28 00:56:56 +05301753 * To build Path in network from ERO object.
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301754 *
Avantika-Huawei56c11842016-04-28 00:56:56 +05301755 * @param eroObj ERO object
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301756 * @param providerId provider id
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301757 * @return list of links and labels
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301758 */
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301759 private List<Object> buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) {
Avantika-Huawei56c11842016-04-28 00:56:56 +05301760 checkNotNull(eroObj);
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301761 List<Object> subObjList = new ArrayList<>();
Avantika-Huawei56c11842016-04-28 00:56:56 +05301762 LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301763 if (0 == llSubObj.size()) {
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301764 log.error("ERO in report message does not have hop information");
Priyanka B4c3b4512016-07-22 11:41:49 +05301765 return new ArrayList<>();
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301766 }
1767 ListIterator<PcepValueType> tlvIterator = llSubObj.listIterator();
1768
1769 ConnectPoint src = null;
1770 ConnectPoint dst = null;
1771 boolean isSrcSet = false;
1772 while (tlvIterator.hasNext()) {
1773 PcepValueType subObj = tlvIterator.next();
1774 switch (subObj.getType()) {
1775
1776 case IPv4SubObject.TYPE:
1777
1778 IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj;
1779 if (!isSrcSet) {
Priyanka Bc1e4e4c2016-07-01 14:57:19 +05301780 Iterable<Link> links = linkService.getActiveLinks();
1781 for (Link l : links) {
1782 if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1783 src = l.src();
1784 isSrcSet = true;
1785 break;
1786 } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1787 src = l.dst();
1788 isSrcSet = true;
1789 break;
1790 }
1791 }
1792 } else {
1793 Iterable<Link> links = linkService.getActiveLinks();
1794 for (Link l : links) {
1795 if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1796 dst = l.src();
1797 break;
1798 } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1799 dst = l.dst();
1800 break;
1801 }
1802 }
Ray Milkey2693bda2016-01-22 16:08:14 -08001803 Link link = DefaultLink.builder()
1804 .providerId(providerId)
1805 .src(src)
1806 .dst(dst)
1807 .type(Link.Type.DIRECT)
1808 .build();
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301809 subObjList.add(link);
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301810 src = dst;
1811 }
1812 break;
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301813 case SrEroSubObject.TYPE:
1814 SrEroSubObject srEroSubObj = (SrEroSubObject) subObj;
1815 subObjList.add(srEroSubObj.getSid());
1816
1817 if (srEroSubObj.getSt() == PcepNaiIpv4Adjacency.ST_TYPE) {
1818 PcepNaiIpv4Adjacency nai = (PcepNaiIpv4Adjacency) (srEroSubObj.getNai());
Priyanka B4c3b4512016-07-22 11:41:49 +05301819 int srcIp = nai.getLocalIpv4Addr();
1820 int dstIp = nai.getRemoteIpv4Addr();
1821 Iterable<Link> links = linkService.getActiveLinks();
1822 for (Link l : links) {
1823 long lSrc = l.src().port().toLong();
1824 long lDst = l.dst().port().toLong();
1825 if (lSrc == srcIp) {
1826 src = l.src();
1827 } else if (lDst == srcIp) {
1828 src = l.dst();
1829 }
1830 if (lSrc == dstIp) {
1831 dst = l.src();
1832 } else if (lDst == dstIp) {
1833 dst = l.dst();
1834 }
1835 if (src != null && dst != null) {
1836 break;
1837 }
1838 }
1839 if (src == null || dst == null) {
1840 return new ArrayList<>();
1841 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301842 Link link = DefaultLink.builder()
1843 .providerId(providerId)
1844 .src(src)
1845 .dst(dst)
1846 .type(Link.Type.DIRECT)
1847 .build();
1848 subObjList.add(link);
1849 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301850 default:
1851 // the other sub objects are not required
1852 }
1853 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +05301854 return subObjList;
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301855 }
1856
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301857 @Override
1858 public void clientConnected(PccId pccId) {
1859 // TODO
1860 }
1861
1862 @Override
1863 public void clientDisconnected(PccId pccId) {
1864 // TODO
cheng fan48e832c2015-05-29 01:54:47 +08001865 }
chengfan2fff70f2015-08-24 18:20:19 -05001866
chengfan2fff70f2015-08-24 18:20:19 -05001867 @Override
1868 public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) {
1869 TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id()));
1870 TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics);
1871 tunnelStatisticsMap.put(id, tunnelStatistics);
1872 }
cheng fan48e832c2015-05-29 01:54:47 +08001873
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301874 @Override
1875 public void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction) {
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301876
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301877 if (endOfSyncAction == SEND_UPDATE) {
1878 updateTunnel(tunnel, tunnel.path());
1879 return;
1880 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301881
1882 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(),
1883 tunnel.src(), tunnel.dst(),
1884 tunnel.type(),
1885 tunnel.groupId(),
1886 tunnel.providerId(),
1887 tunnel.tunnelName(),
1888 tunnel.path(),
1889 (SparseAnnotations) tunnel.annotations());
1890
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301891
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301892 if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) {
1893
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301894 // Send PCInit msg again after global reoptimization.
1895 tunnelUpdated(td, UNSTABLE);
1896
1897 // To remove the old tunnel from store whose PLSPID is not
1898 // recognized by ingress PCC.
1899 tunnelRemoved(td);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301900
1901 } else if (endOfSyncAction == REMOVE) {
1902 tunnelRemoved(td);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301903 }
1904 }
Avantika-Huawei7f7376a2016-05-11 17:07:50 +05301905 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +05301906 @Override
1907 public Tunnel tunnelQueryById(TunnelId tunnelId) {
1908 return service.tunnelQueryById(tunnelId);
1909 }
1910
Priyanka B413fbe82016-05-26 11:44:45 +05301911 private DeviceId getDevice(PccId pccId) {
1912 // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
1913 IpAddress lsrId = pccId.ipAddress();
1914 String lsrIdentifier = String.valueOf(lsrId);
1915
1916 // Find PCC deviceID from lsrId stored as annotations
1917 Iterable<Device> devices = deviceService.getAvailableDevices();
1918 for (Device dev : devices) {
1919 if (dev.annotations().value(AnnotationKeys.TYPE).equals("L3")
1920 && dev.annotations().value(LSRID).equals(lsrIdentifier)) {
1921 return dev.id();
1922 }
1923 }
1924 return null;
1925 }
1926
1927 /**
1928 * Updates the tunnel with updated tunnel annotation after a delay of two seconds and checks it till
1929 * tunnel is found.
1930 */
1931 private class UpdateDelegation implements Runnable {
1932 DefaultTunnelDescription td;
1933 ProviderId providerId;
1934 SparseAnnotations annotations;
1935 PccId pccId;
1936 ScheduledExecutorService executor;
Priyanka B4c3b4512016-07-22 11:41:49 +05301937 State tunnelState;
1938 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv;
Priyanka B413fbe82016-05-26 11:44:45 +05301939
1940 /**
1941 * Creates an instance of UpdateDelegation.
1942 *
1943 * @param td tunnel description
1944 * @param providerId provider id
1945 * @param annotations tunnel annotations
1946 * @param pccId PCEP client id
1947 * @param executor service of delegated owner
1948 */
1949 public UpdateDelegation(DefaultTunnelDescription td, ProviderId providerId, SparseAnnotations annotations,
Priyanka B4c3b4512016-07-22 11:41:49 +05301950 PccId pccId, ScheduledExecutorService executor, State tunnelState,
1951 StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
Priyanka B413fbe82016-05-26 11:44:45 +05301952 this.td = td;
1953 this.providerId = providerId;
1954 this.annotations = annotations;
1955 this.pccId = pccId;
1956 this.executor = executor;
Priyanka B4c3b4512016-07-22 11:41:49 +05301957 this.tunnelState = tunnelState;
1958 this.ipv4LspIdentifiersTlv = ipv4LspIdentifiersTlv;
Priyanka B413fbe82016-05-26 11:44:45 +05301959 }
1960
1961 //Temporary using annotations later will use projection/network config service
1962 @Override
1963 public void run() {
1964 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(td.src(), td.dst());
1965 TunnelId tempTunnelId = null;
1966 for (Tunnel t : tunnelQueryResult) {
1967 if (t.annotations().value(LOCAL_LSP_ID) == null || t.annotations().value(PLSP_ID) == null) {
1968 continue;
1969 }
1970
1971 if (t.annotations().value(LOCAL_LSP_ID).equals(td.annotations().value(LOCAL_LSP_ID))
1972 && t.annotations().value(PLSP_ID).equals(td.annotations().value(PLSP_ID))
1973 && ((IpTunnelEndPoint) t.src()).ip().equals(pccId.id())) {
1974 tempTunnelId = t.tunnelId();
1975 break;
1976 }
1977 }
1978
1979 //If tunnel is found update the tunnel and shutdown the thread otherwise thread will be executing
1980 //periodically
1981 if (tempTunnelId != null) {
1982 Tunnel tunnel = new DefaultTunnel(providerId, td.src(), td.dst(), MPLS, new DefaultGroupId(0),
1983 tempTunnelId, td.tunnelName(), td.path(), annotations);
Priyanka B4c3b4512016-07-22 11:41:49 +05301984 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
1985 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdentifiersTlv);
1986 pcepTunnelData.setLspDFlag(Boolean.valueOf(tunnel.annotations().value(DELEGATE)));
1987 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1988 tunnelUpdated(tunnel, td.path(), tunnelState);
Priyanka B413fbe82016-05-26 11:44:45 +05301989 executor.shutdown();
1990 try {
1991 executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS);
1992 } catch (InterruptedException e) {
1993 log.error("updating delegation failed");
1994 }
1995 }
1996 }
1997 }
cheng fan48e832c2015-05-29 01:54:47 +08001998}