cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.pcep.tunnel.impl; |
| 17 | |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Property; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 27 | import org.onosproject.cfg.ComponentConfigService; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 28 | import org.onosproject.core.DefaultGroupId; |
| 29 | import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 30 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 31 | import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 32 | import org.onosproject.incubator.net.tunnel.DefaultTunnelStatistics; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 33 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 34 | import org.onosproject.incubator.net.tunnel.OpticalLogicId; |
| 35 | import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; |
| 36 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 37 | import org.onosproject.incubator.net.tunnel.TunnelDescription; |
| 38 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| 39 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 40 | import org.onosproject.incubator.net.tunnel.TunnelName; |
| 41 | import org.onosproject.incubator.net.tunnel.TunnelProvider; |
| 42 | import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; |
| 43 | import org.onosproject.incubator.net.tunnel.TunnelProviderService; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 44 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 45 | import org.onosproject.incubator.net.tunnel.TunnelStatistics; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 46 | import org.onosproject.net.ConnectPoint; |
| 47 | import org.onosproject.net.DefaultAnnotations; |
| 48 | import org.onosproject.net.DefaultLink; |
| 49 | import org.onosproject.net.DefaultPath; |
| 50 | import org.onosproject.net.DeviceId; |
| 51 | import org.onosproject.net.ElementId; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 52 | import org.onosproject.net.IpElementId; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 53 | import org.onosproject.net.Link; |
| 54 | import org.onosproject.net.Path; |
| 55 | import org.onosproject.net.PortNumber; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 56 | import org.onosproject.net.SparseAnnotations; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 57 | import org.onosproject.net.provider.AbstractProvider; |
| 58 | import org.onosproject.net.provider.ProviderId; |
| 59 | import org.onosproject.pcep.api.PcepController; |
| 60 | import org.onosproject.pcep.api.PcepDpid; |
| 61 | import org.onosproject.pcep.api.PcepHopNodeDescription; |
| 62 | import org.onosproject.pcep.api.PcepOperator.OperationType; |
| 63 | import org.onosproject.pcep.api.PcepTunnel; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 64 | import org.onosproject.pcep.api.PcepTunnel.PathState; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 65 | import org.onosproject.pcep.api.PcepTunnel.PathType; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 66 | import org.onosproject.pcep.api.PcepTunnelListener; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 67 | import org.onosproject.pcep.api.PcepTunnelStatistics; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 68 | import org.onosproject.pcep.controller.PccId; |
| 69 | import org.onosproject.pcep.controller.PcepClient; |
| 70 | import org.onosproject.pcep.controller.PcepClientController; |
| 71 | import org.onosproject.pcep.controller.PcepClientListener; |
| 72 | import org.onosproject.pcep.controller.PcepEventListener; |
| 73 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 74 | import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; |
| 75 | import org.onosproject.pcepio.protocol.PcepAttribute; |
| 76 | import org.onosproject.pcepio.protocol.PcepBandwidthObject; |
| 77 | import org.onosproject.pcepio.protocol.PcepEndPointsObject; |
| 78 | import org.onosproject.pcepio.protocol.PcepEroObject; |
| 79 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; |
| 80 | import org.onosproject.pcepio.protocol.PcepLspObject; |
| 81 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 82 | import org.onosproject.pcepio.protocol.PcepMsgPath; |
| 83 | import org.onosproject.pcepio.protocol.PcepReportMsg; |
| 84 | import org.onosproject.pcepio.protocol.PcepRroObject; |
| 85 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
| 86 | import org.onosproject.pcepio.protocol.PcepStateReport; |
| 87 | import org.onosproject.pcepio.protocol.PcepUpdateMsg; |
| 88 | import org.onosproject.pcepio.protocol.PcepUpdateRequest; |
| 89 | import org.onosproject.pcepio.types.IPv4SubObject; |
| 90 | import org.onosproject.pcepio.types.PcepValueType; |
| 91 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; |
| 92 | import org.onosproject.pcepio.types.SymbolicPathNameTlv; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 93 | import org.osgi.service.component.ComponentContext; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 94 | import org.osgi.service.component.annotations.Modified; |
| 95 | import org.slf4j.Logger; |
| 96 | |
| 97 | import java.util.ArrayList; |
| 98 | import java.util.Collections; |
| 99 | import java.util.Dictionary; |
| 100 | import java.util.HashMap; |
| 101 | import java.util.LinkedList; |
| 102 | import java.util.List; |
| 103 | import java.util.ListIterator; |
| 104 | import java.util.Optional; |
| 105 | |
| 106 | import static com.google.common.base.Preconditions.checkNotNull; |
| 107 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 108 | import static org.onlab.util.Tools.get; |
| 109 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
| 110 | import static org.onosproject.net.DeviceId.deviceId; |
| 111 | import static org.onosproject.net.PortNumber.portNumber; |
| 112 | import static org.onosproject.pcep.api.PcepDpid.uri; |
| 113 | import static org.slf4j.LoggerFactory.getLogger; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Provider which uses an PCEP controller to detect, update, create network |
| 117 | * tunnels. |
| 118 | */ |
| 119 | @Component(immediate = true) |
| 120 | @Service |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 121 | public class PcepTunnelProvider extends AbstractProvider implements TunnelProvider { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 122 | |
| 123 | private static final Logger log = getLogger(PcepTunnelProvider.class); |
| 124 | private static final long MAX_BANDWIDTH = 99999744; |
| 125 | private static final long MIN_BANDWIDTH = 64; |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 126 | private static final String BANDWIDTH_UINT = "kbps"; |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 127 | static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 128 | |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 129 | static final int POLL_INTERVAL = 10; |
| 130 | @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL, |
| 131 | label = "Frequency (in seconds) for polling tunnel statistics") |
| 132 | private int tunnelStatsPollFrequency = POLL_INTERVAL; |
| 133 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 134 | private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied."; |
| 135 | |
| 136 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 137 | protected TunnelProviderRegistry tunnelProviderRegistry; |
| 138 | |
| 139 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 140 | protected PcepController controller; |
| 141 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 142 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 143 | protected PcepClientController pcepClientController; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 144 | |
| 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 146 | protected TunnelService tunnelService; |
| 147 | |
| 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 149 | protected ComponentConfigService cfgService; |
| 150 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 151 | TunnelProviderService service; |
| 152 | |
| 153 | HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 154 | HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>(); |
| 155 | private HashMap<Long, TunnelStatsCollector> collectors = Maps.newHashMap(); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 156 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 157 | private InnerTunnelProvider listener = new InnerTunnelProvider(); |
| 158 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 159 | protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper(); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 160 | private static final int DEFAULT_BANDWIDTH_VALUE = 10; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Creates a Tunnel provider. |
| 164 | */ |
| 165 | public PcepTunnelProvider() { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 166 | super(new ProviderId("pcep", PROVIDER_ID)); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Activate |
| 170 | public void activate() { |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 171 | cfgService.registerProperties(getClass()); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 172 | service = tunnelProviderRegistry.register(this); |
| 173 | controller.addTunnelListener(listener); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 174 | pcepClientController.addListener(listener); |
| 175 | pcepClientController.addEventListener(listener); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 176 | tunnelService.queryAllTunnels().forEach(tunnel -> { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 177 | String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId()); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 178 | TunnelStatsCollector tsc = new TunnelStatsCollector(pcepTunnelId, tunnelStatsPollFrequency); |
| 179 | tsc.start(); |
| 180 | collectors.put(tunnel.tunnelId().id(), tsc); |
| 181 | |
| 182 | }); |
| 183 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 184 | log.info("Started"); |
| 185 | } |
| 186 | |
| 187 | @Deactivate |
| 188 | public void deactivate() { |
| 189 | tunnelProviderRegistry.unregister(this); |
| 190 | controller.removeTunnelListener(listener); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 191 | collectors.values().forEach(TunnelStatsCollector::stop); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 192 | pcepClientController.removeListener(listener); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 193 | log.info("Stopped"); |
| 194 | } |
| 195 | |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 196 | @Modified |
| 197 | public void modified(ComponentContext context) { |
| 198 | Dictionary<?, ?> properties = context.getProperties(); |
| 199 | int newTunnelStatsPollFrequency; |
| 200 | try { |
| 201 | String s = get(properties, "tunnelStatsPollFrequency"); |
| 202 | newTunnelStatsPollFrequency = isNullOrEmpty(s) ? tunnelStatsPollFrequency : Integer.parseInt(s.trim()); |
| 203 | |
| 204 | } catch (NumberFormatException | ClassCastException e) { |
| 205 | newTunnelStatsPollFrequency = tunnelStatsPollFrequency; |
| 206 | } |
| 207 | |
| 208 | if (newTunnelStatsPollFrequency != tunnelStatsPollFrequency) { |
| 209 | tunnelStatsPollFrequency = newTunnelStatsPollFrequency; |
| 210 | collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency)); |
| 211 | log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency); |
| 212 | } |
| 213 | |
| 214 | } |
| 215 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 216 | @Override |
| 217 | public void setupTunnel(Tunnel tunnel, Path path) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 218 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 219 | log.error("Tunnel Type MPLS is only supported"); |
| 220 | return; |
| 221 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 222 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 223 | // check for tunnel end points |
| 224 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 225 | log.error("Tunnel source or destination is not valid"); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | // Get the pcc client |
| 230 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); |
| 231 | |
| 232 | if (!(pc instanceof PcepClient)) { |
| 233 | log.error("There is no PCC connected with ip addresss {}" |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 234 | + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 235 | return; |
| 236 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 237 | |
| 238 | //If stateful and PC Initiation capability is not supported by client not sending Initiate msg |
| 239 | if (pc.capability().pcInstantiationCapability()) { |
| 240 | pcepSetupTunnel(tunnel, path, pc); |
| 241 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 246 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 247 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 248 | log.error("Tunnel Type MPLS is only supported"); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | if (!(srcElement instanceof IpElementId)) { |
| 253 | log.error("Element id is not valid"); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | // check for tunnel end points |
| 258 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 259 | log.error("Tunnel source or destination is not valid"); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); |
| 264 | |
| 265 | if (!(pc instanceof PcepClient)) { |
| 266 | log.error("There is no PCC connected with ip addresss {}" |
| 267 | + ((IpElementId) srcElement).ipAddress().toString()); |
| 268 | return; |
| 269 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 270 | |
| 271 | if (pc.capability().pcInstantiationCapability()) { |
| 272 | pcepSetupTunnel(tunnel, path, pc); |
| 273 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void releaseTunnel(Tunnel tunnel) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 278 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 279 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 280 | log.error("Tunnel Type MPLS is only supported"); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | // check for tunnel end points |
| 285 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 286 | log.error("Tunnel source or destination is not valid"); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); |
| 291 | |
| 292 | if (!(pc instanceof PcepClient)) { |
| 293 | log.error("There is no PCC connected with ip addresss {}" |
| 294 | + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); |
| 295 | return; |
| 296 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 297 | |
| 298 | if (pc.capability().pcInstantiationCapability()) { |
| 299 | pcepReleaseTunnel(tunnel, pc); |
| 300 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 305 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 306 | log.error("Tunnel Type MPLS is only supported"); |
| 307 | return; |
| 308 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 309 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 310 | if (!(srcElement instanceof IpElementId)) { |
| 311 | log.error("Element id is not valid"); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | // check for tunnel end points |
| 316 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 317 | log.error("Tunnel source or destination is not valid"); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); |
| 322 | |
| 323 | if (!(pc instanceof PcepClient)) { |
| 324 | log.error("There is no PCC connected with ip addresss {}" |
| 325 | + ((IpElementId) srcElement).ipAddress().toString()); |
| 326 | return; |
| 327 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 328 | |
| 329 | if (pc.capability().pcInstantiationCapability()) { |
| 330 | pcepReleaseTunnel(tunnel, pc); |
| 331 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public void updateTunnel(Tunnel tunnel, Path path) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 336 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 337 | log.error("Tunnel Type MPLS is only supported"); |
| 338 | return; |
| 339 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 340 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 341 | // check for tunnel end points |
| 342 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 343 | log.error("Tunnel source or destination is not valid"); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); |
| 348 | |
| 349 | if (!(pc instanceof PcepClient)) { |
| 350 | log.error("There is no PCC connected with ip addresss {}" |
| 351 | + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); |
| 352 | return; |
| 353 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 354 | |
| 355 | if (pc.capability().statefulPceCapability()) { |
| 356 | pcepUpdateTunnel(tunnel, path, pc); |
| 357 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 362 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 363 | if (tunnel.type() != Tunnel.Type.MPLS) { |
| 364 | log.error("Tunnel Type MPLS is only supported"); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | if (!(srcElement instanceof IpElementId)) { |
| 369 | log.error("Element id is not valid"); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | // check for tunnel end points |
| 374 | if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { |
| 375 | log.error("Tunnel source or destination is not valid"); |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); |
| 380 | |
| 381 | if (!(pc instanceof PcepClient)) { |
| 382 | log.error("There is no PCC connected with ip addresss {}" |
| 383 | + ((IpElementId) srcElement).ipAddress().toString()); |
| 384 | return; |
| 385 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 386 | |
| 387 | if (pc.capability().statefulPceCapability()) { |
| 388 | pcepUpdateTunnel(tunnel, path, pc); |
| 389 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public TunnelId tunnelAdded(TunnelDescription tunnel) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 394 | if (tunnel.type() == Tunnel.Type.MPLS) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 395 | pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 396 | return service.tunnelAdded(tunnel); |
| 397 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 398 | |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 399 | long bandwidth = Long |
| 400 | .parseLong(tunnel.annotations().value("bandwidth")); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 401 | |
| 402 | if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) { |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 403 | error("Update failed, invalid bandwidth."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 404 | return null; |
| 405 | } |
| 406 | |
| 407 | // endpoints |
| 408 | OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel |
| 409 | .src(); |
| 410 | OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst(); |
| 411 | // devices |
| 412 | DeviceId srcId = (DeviceId) src.elementId().get(); |
| 413 | DeviceId dstId = (DeviceId) dst.elementId().get(); |
| 414 | |
| 415 | // ports |
| 416 | long srcPort = src.portNumber().get().toLong(); |
| 417 | long dstPort = dst.portNumber().get().toLong(); |
| 418 | |
| 419 | // type |
| 420 | if (tunnel.type() != Tunnel.Type.VLAN) { |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 421 | error("Illegal tunnel type. Only support VLAN tunnel creation."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 422 | return null; |
| 423 | } |
| 424 | |
| 425 | PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort, |
| 426 | dstPort, bandwidth, |
| 427 | tunnel.tunnelName() |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 428 | .value()); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 429 | |
| 430 | checkNotNull(pcepTunnel, TUNNLE_NOT_NULL); |
| 431 | TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null); |
| 432 | TunnelId tunnelId = service.tunnelAdded(tunnelAdded); |
| 433 | |
| 434 | tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId); |
| 435 | return tunnelId; |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public void tunnelRemoved(TunnelDescription tunnel) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 440 | if (tunnel.type() == Tunnel.Type.MPLS) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 441 | pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 442 | service.tunnelRemoved(tunnel); |
| 443 | } |
| 444 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 445 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); |
| 446 | checkNotNull(tunnelOld, "The tunnel id is not exsited."); |
| 447 | if (tunnelOld.type() != Tunnel.Type.VLAN) { |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 448 | error("Illegal tunnel type. Only support VLAN tunnel deletion."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 449 | return; |
| 450 | } |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 451 | String pcepTunnelId = getPcepTunnelKey(tunnel.id()); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 452 | checkNotNull(pcepTunnelId, "The tunnel id is not exsited."); |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 453 | if (!controller.deleteTunnel(pcepTunnelId)) { |
| 454 | error("Delete tunnel failed, Maybe some devices have been disconnected."); |
| 455 | return; |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 456 | } |
| 457 | tunnelMap.remove(pcepTunnelId); |
| 458 | service.tunnelRemoved(tunnel); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public void tunnelUpdated(TunnelDescription tunnel) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 463 | if (tunnel.type() == Tunnel.Type.MPLS) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 464 | pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 465 | service.tunnelUpdated(tunnel); |
| 466 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 467 | |
| 468 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); |
| 469 | if (tunnelOld.type() != Tunnel.Type.VLAN) { |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 470 | error("Illegal tunnel type. Only support VLAN tunnel update."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 471 | return; |
| 472 | } |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 473 | long bandwidth = Long |
| 474 | .parseLong(tunnel.annotations().value("bandwidth")); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 475 | if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) { |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 476 | error("Update failed, invalid bandwidth."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 477 | return; |
| 478 | } |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 479 | String pcepTunnelId = getPcepTunnelKey(tunnel.id()); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 480 | |
| 481 | checkNotNull(pcepTunnelId, "Invalid tunnel id"); |
| 482 | if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) { |
| 483 | |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 484 | error("Update failed,maybe invalid bandwidth."); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 485 | return; |
| 486 | |
| 487 | } |
| 488 | service.tunnelUpdated(tunnel); |
| 489 | } |
| 490 | |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 491 | private void error(String info) { |
| 492 | System.err.println(info); |
| 493 | } |
| 494 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 495 | // Short-hand for creating a connection point. |
| 496 | private ConnectPoint connectPoint(PcepDpid id, long port) { |
| 497 | return new ConnectPoint(deviceId(uri(id)), portNumber(port)); |
| 498 | } |
| 499 | |
| 500 | // Short-hand for creating a link. |
| 501 | private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) { |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 502 | return DefaultLink.builder() |
| 503 | .providerId(id()) |
| 504 | .src(connectPoint(src, sp)) |
| 505 | .dst(connectPoint(dst, dp)) |
| 506 | .type(Link.Type.TUNNEL) |
| 507 | .build(); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | // Creates a path that leads through the given devices. |
| 511 | private Path createPath(List<PcepHopNodeDescription> hopList, |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 512 | PathType pathtype, PathState pathState) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 513 | if (hopList == null || hopList.size() == 0) { |
| 514 | return null; |
| 515 | } |
| 516 | List<Link> links = new ArrayList<>(); |
| 517 | for (int i = 1; i < hopList.size() - 1; i = i + 2) { |
| 518 | links.add(link(hopList.get(i).getDeviceId(), hopList.get(i) |
| 519 | .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList |
| 520 | .get(i + 1).getPortNum())); |
| 521 | } |
| 522 | |
| 523 | int hopNum = hopList.size() - 2; |
| 524 | DefaultAnnotations extendAnnotations = DefaultAnnotations.builder() |
| 525 | .set("pathNum", String.valueOf(hopNum)) |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 526 | .set("pathState", String.valueOf(pathState)) |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 527 | .set("pathType", String.valueOf(pathtype)).build(); |
| 528 | return new DefaultPath(id(), links, hopNum, extendAnnotations); |
| 529 | } |
| 530 | |
| 531 | // convert the path description to a string. |
| 532 | public String pathToString(List<Link> links) { |
| 533 | StringBuilder builder = new StringBuilder(); |
| 534 | builder.append("{"); |
| 535 | for (Link link : links) { |
| 536 | builder.append("(Device:" + link.src().deviceId() + " Port:" |
| 537 | + link.src().port().toLong()); |
| 538 | builder.append(" Device:" + link.dst().deviceId() + " Port:" |
| 539 | + link.dst().port().toLong()); |
| 540 | builder.append(")"); |
| 541 | } |
| 542 | builder.append("}"); |
| 543 | return builder.toString(); |
| 544 | } |
| 545 | |
| 546 | // build a TunnelDescription. |
| 547 | private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel, |
| 548 | TunnelId tunnelId) { |
| 549 | TunnelEndPoint srcPoint = null; |
| 550 | TunnelEndPoint dstPoint = null; |
| 551 | Tunnel.Type tunnelType = null; |
| 552 | TunnelName name = TunnelName.tunnelName(pcepTunnel.name()); |
| 553 | |
| 554 | // add path after codes of tunnel's path merged |
| 555 | Path path = createPath(pcepTunnel.getHopList(), |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 556 | pcepTunnel.getPathType(), |
| 557 | pcepTunnel.getPathState()); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 558 | |
| 559 | OpticalTunnelEndPoint.Type endPointType = null; |
| 560 | switch (pcepTunnel.type()) { |
| 561 | case OCH: |
| 562 | tunnelType = Tunnel.Type.OCH; |
| 563 | endPointType = OpticalTunnelEndPoint.Type.LAMBDA; |
| 564 | break; |
| 565 | |
| 566 | case OTN: |
| 567 | tunnelType = Tunnel.Type.ODUK; |
| 568 | endPointType = OpticalTunnelEndPoint.Type.TIMESLOT; |
| 569 | break; |
| 570 | |
| 571 | case UNI: |
| 572 | tunnelType = Tunnel.Type.VLAN; |
| 573 | endPointType = null; |
| 574 | break; |
| 575 | |
| 576 | default: |
| 577 | break; |
| 578 | } |
| 579 | DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID())); |
| 580 | DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId())); |
| 581 | PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort()); |
| 582 | PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort()); |
| 583 | |
| 584 | srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid), |
| 585 | Optional.of(srcPort), null, |
| 586 | endPointType, |
| 587 | OpticalLogicId.logicId(0), |
| 588 | true); |
| 589 | dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid), |
| 590 | Optional.of(dstPort), null, |
| 591 | endPointType, |
| 592 | OpticalLogicId.logicId(0), |
| 593 | true); |
| 594 | |
| 595 | // basic annotations |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 596 | DefaultAnnotations annotations = DefaultAnnotations |
| 597 | .builder() |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 598 | .set("SLA", String.valueOf(pcepTunnel.getSla())) |
cheng fan | 7716ec9 | 2015-05-31 01:53:19 +0800 | [diff] [blame] | 599 | .set("bandwidth", |
| 600 | String.valueOf(pcepTunnel.bandWidth()) + BANDWIDTH_UINT) |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 601 | .set("index", String.valueOf(pcepTunnel.id())).build(); |
| 602 | |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 603 | // a VLAN tunnel always carry OCH tunnel, this annotation is the index |
| 604 | // of a OCH tunnel. |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 605 | if (pcepTunnel.underlayTunnelId() != 0) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 606 | DefaultAnnotations extendAnnotations = DefaultAnnotations |
| 607 | .builder() |
| 608 | .set("underLayTunnelIndex", |
cheng fan | 93258c7 | 2015-06-02 23:42:32 +0800 | [diff] [blame] | 609 | String.valueOf(pcepTunnel.underlayTunnelId())).build(); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 610 | annotations = DefaultAnnotations.merge(annotations, |
| 611 | extendAnnotations); |
| 612 | |
| 613 | } |
| 614 | TunnelDescription tunnel = new DefaultTunnelDescription( |
| 615 | tunnelId, |
| 616 | srcPoint, |
| 617 | dstPoint, |
| 618 | tunnelType, |
| 619 | new DefaultGroupId( |
| 620 | 0), |
| 621 | id(), name, |
| 622 | path, |
| 623 | annotations); |
| 624 | return tunnel; |
| 625 | |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Get the tunnelID according to the tunnel key. |
| 630 | * |
| 631 | * @param tunnelKey tunnel key |
| 632 | * @return corresponding tunnel id of the a tunnel key. |
| 633 | */ |
| 634 | private TunnelId getTunnelId(String tunnelKey) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 635 | for (String key : tunnelMap.keySet()) { |
| 636 | if (key.equals(tunnelKey)) { |
| 637 | return tunnelMap.get(key); |
| 638 | } |
| 639 | } |
| 640 | return null; |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Get the tunnel key according to the tunnelID. |
| 645 | * |
| 646 | * @param tunnelId tunnel id |
| 647 | * @return corresponding a tunnel key of the tunnel id. |
| 648 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 649 | private String getPcepTunnelKey(TunnelId tunnelId) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 650 | for (String key : tunnelMap.keySet()) { |
| 651 | if (tunnelMap.get(key).id() == tunnelId.id()) { |
| 652 | return key; |
| 653 | } |
| 654 | } |
| 655 | return null; |
| 656 | |
| 657 | } |
| 658 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 659 | /** |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 660 | * Build a DefaultTunnelStatistics from a PcepTunnelStatistics. |
| 661 | * |
| 662 | * @param statistics statistics data from a PCEP tunnel |
| 663 | * @return TunnelStatistics |
| 664 | */ |
| 665 | private TunnelStatistics buildTunnelStatistics(PcepTunnelStatistics statistics) { |
| 666 | DefaultTunnelStatistics.Builder builder = new DefaultTunnelStatistics.Builder(); |
| 667 | DefaultTunnelStatistics tunnelStatistics = builder.setBwUtilization(statistics.bandwidthUtilization()) |
| 668 | .setPacketLossRatio(statistics.packetLossRate()) |
| 669 | .setFlowDelay(statistics.flowDelay()) |
| 670 | .setAlarms(statistics.alarms()) |
| 671 | .build(); |
| 672 | return tunnelStatistics; |
| 673 | } |
| 674 | /** |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 675 | * Creates list of hops for ERO object from Path. |
| 676 | * |
| 677 | * @param path network path |
| 678 | * @return list of ipv4 subobjects |
| 679 | */ |
| 680 | private LinkedList<PcepValueType> createPcepPath(Path path) { |
| 681 | LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); |
| 682 | List<Link> listLink = path.links(); |
| 683 | ConnectPoint source = null; |
| 684 | ConnectPoint destination = null; |
| 685 | IpAddress ipDstAddress = null; |
| 686 | IpAddress ipSrcAddress = null; |
| 687 | PcepValueType subObj = null; |
| 688 | |
| 689 | for (Link link : listLink) { |
| 690 | source = link.src(); |
| 691 | if (!(source.equals(destination))) { |
| 692 | //set IPv4SubObject for ERO object |
| 693 | ipSrcAddress = source.ipElementId().ipAddress(); |
| 694 | subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); |
| 695 | llSubObjects.add(subObj); |
| 696 | } |
| 697 | |
| 698 | destination = link.dst(); |
| 699 | ipDstAddress = destination.ipElementId().ipAddress(); |
| 700 | subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); |
| 701 | llSubObjects.add(subObj); |
| 702 | } |
| 703 | return llSubObjects; |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Creates PcInitiated lsp request list for setup tunnel. |
| 708 | * |
| 709 | * @param tunnel mpls tunnel |
| 710 | * @param path network path |
| 711 | * @param pc pcep client |
| 712 | * @param srpId unique id for pcep message |
| 713 | * @return list of PcInitiatedLspRequest |
| 714 | * @throws PcepParseException while building pcep objects fails |
| 715 | */ |
| 716 | LinkedList<PcInitiatedLspRequest> createPcInitiatedLspReqList(Tunnel tunnel, Path path, |
| 717 | PcepClient pc, int srpId) |
| 718 | throws PcepParseException { |
| 719 | PcepValueType tlv; |
| 720 | LinkedList<PcepValueType> llSubObjects = createPcepPath(path); |
| 721 | |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 722 | if (llSubObjects == null || llSubObjects.size() == 0) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 723 | log.error("There is no link information to create tunnel"); |
| 724 | return null; |
| 725 | } |
| 726 | |
| 727 | //build SRP object |
| 728 | PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build(); |
| 729 | |
| 730 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); |
| 731 | LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>(); |
| 732 | // set LSP identifiers TLV |
| 733 | tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), |
| 734 | (short) 0, (short) 0, 0, |
| 735 | (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); |
| 736 | llOptionalTlv.add(tlv); |
| 737 | //set SymbolicPathNameTlv of LSP object |
| 738 | tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); |
| 739 | llOptionalTlv.add(tlv); |
| 740 | |
| 741 | //build LSP object |
| 742 | PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setOFlag((byte) 0).setPlspId(0) |
| 743 | .setOptionalTlv(llOptionalTlv).build(); |
| 744 | |
| 745 | //build ENDPOINTS object |
| 746 | PcepEndPointsObject endpointsobj = pc.factory().buildEndPointsObject() |
| 747 | .setSourceIpAddress(((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()) |
| 748 | .setDestIpAddress(((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()) |
| 749 | .setPFlag(true).build(); |
| 750 | |
| 751 | //build ERO object |
| 752 | PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build(); |
| 753 | |
| 754 | int iBandwidth = DEFAULT_BANDWIDTH_VALUE; |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 755 | if (tunnel.annotations().value("bandwidth") != null) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 756 | iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth")); |
| 757 | } |
| 758 | // build bandwidth object |
| 759 | PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build(); |
| 760 | // build pcep attribute |
| 761 | PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build(); |
| 762 | |
| 763 | PcInitiatedLspRequest initiateLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj) |
| 764 | .setLspObject(lspobj).setEndPointsObject(endpointsobj).setEroObject(eroobj) |
| 765 | .setPcepAttribute(pcepAttribute).build(); |
| 766 | llPcInitiatedLspRequestList.add(initiateLspRequest); |
| 767 | return llPcInitiatedLspRequestList; |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * To send initiate tunnel message to pcc. |
| 772 | * |
| 773 | * @param tunnel mpls tunnel info |
| 774 | * @param path explicit route for the tunnel |
| 775 | * @param pc pcep client to send message |
| 776 | */ |
| 777 | private void pcepSetupTunnel(Tunnel tunnel, Path path, PcepClient pc) { |
| 778 | try { |
| 779 | int srpId = SrpIdGenerators.create(); |
| 780 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.CREATE); |
| 781 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 782 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 783 | |
| 784 | LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = createPcInitiatedLspReqList(tunnel, path, |
| 785 | pc, srpId); |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 786 | if (llPcInitiatedLspRequestList == null || llPcInitiatedLspRequestList.size() == 0) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 787 | log.error("Failed to create PcInitiatedLspRequestList"); |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | //build PCInitiate message |
| 792 | PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg() |
| 793 | .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList) |
| 794 | .build(); |
| 795 | |
| 796 | pc.sendMessage(Collections.singletonList(pcInitiateMsg)); |
| 797 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 798 | pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 799 | } catch (PcepParseException e) { |
| 800 | log.error("PcepParseException occurred while processing setup tunnel {}", e.getMessage()); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * To send Release tunnel message to pcc. |
| 806 | * |
| 807 | * @param tunnel mpls tunnel info |
| 808 | * @param pc pcep client to send message |
| 809 | */ |
| 810 | private void pcepReleaseTunnel(Tunnel tunnel, PcepClient pc) { |
| 811 | try { |
| 812 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, RequestType.DELETE); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 813 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 814 | int srpId = SrpIdGenerators.create(); |
| 815 | TunnelId tunnelId = tunnel.tunnelId(); |
| 816 | int plspId = 0; |
| 817 | StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv = null; |
| 818 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 819 | if (!(pcepTunnelApiMapper.checkFromTunnelDBQueue(tunnelId))) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 820 | log.error("Tunnel doesnot exists. Tunnel id {}" + tunnelId.toString()); |
| 821 | return; |
| 822 | } else { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 823 | PcepTunnelData pcepTunnelDbData = pcepTunnelApiMapper.getDataFromTunnelDBQueue(tunnelId); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 824 | plspId = pcepTunnelDbData.plspId(); |
| 825 | statefulIpv4IndentifierTlv = pcepTunnelDbData.statefulIpv4IndentifierTlv(); |
| 826 | } |
| 827 | // build srp object |
| 828 | PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true).build(); |
| 829 | |
| 830 | PcepValueType tlv; |
| 831 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); |
| 832 | LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>(); |
| 833 | |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 834 | if (statefulIpv4IndentifierTlv != null) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 835 | tlv = statefulIpv4IndentifierTlv; |
| 836 | } else { |
| 837 | tlv = new StatefulIPv4LspIdentidiersTlv(( |
| 838 | ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), |
| 839 | (short) 0, (short) 0, 0, |
| 840 | (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); |
| 841 | } |
| 842 | llOptionalTlv.add(tlv); |
| 843 | tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); |
| 844 | llOptionalTlv.add(tlv); |
| 845 | // build lsp object, set r flag as false to delete the tunnel |
| 846 | PcepLspObject lspobj = pc.factory().buildLspObject().setRFlag(false).setPlspId(plspId) |
| 847 | .setOptionalTlv(llOptionalTlv).build(); |
| 848 | |
| 849 | PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj) |
| 850 | .setLspObject(lspobj).build(); |
| 851 | |
| 852 | llPcInitiatedLspRequestList.add(releaseLspRequest); |
| 853 | |
| 854 | PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg() |
| 855 | .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build(); |
| 856 | |
| 857 | pc.sendMessage(Collections.singletonList(pcInitiateMsg)); |
| 858 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 859 | pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 860 | } catch (PcepParseException e) { |
| 861 | log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage()); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * To send Update tunnel request message to pcc. |
| 867 | * |
| 868 | * @param tunnel mpls tunnel info |
| 869 | * @param path explicit route for the tunnel |
| 870 | * @param pc pcep client to send message |
| 871 | */ |
| 872 | private void pcepUpdateTunnel(Tunnel tunnel, Path path, PcepClient pc) { |
| 873 | try { |
| 874 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 875 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 876 | int srpId = SrpIdGenerators.create(); |
| 877 | TunnelId tunnelId = tunnel.tunnelId(); |
| 878 | PcepValueType tlv; |
| 879 | int plspId = 0; |
| 880 | |
| 881 | LinkedList<PcepValueType> llSubObjects = createPcepPath(path); |
| 882 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); |
| 883 | LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>(); |
| 884 | |
| 885 | //build SRP object |
| 886 | PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build(); |
| 887 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 888 | if (!(pcepTunnelApiMapper.checkFromTunnelDBQueue(tunnelId))) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 889 | log.error("Tunnel doesnot exists in DB"); |
| 890 | return; |
| 891 | } else { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 892 | PcepTunnelData pcepTunnelDBData = pcepTunnelApiMapper.getDataFromTunnelDBQueue(tunnelId); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 893 | plspId = pcepTunnelDBData.plspId(); |
| 894 | } |
| 895 | |
| 896 | tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), |
| 897 | (short) 0, (short) 0, 0, |
| 898 | (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); |
| 899 | llOptionalTlv.add(tlv); |
| 900 | |
| 901 | if (tunnel.tunnelName().value() != null) { |
| 902 | tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); |
| 903 | llOptionalTlv.add(tlv); |
| 904 | } |
| 905 | |
| 906 | // build lsp object |
| 907 | PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setPlspId(plspId) |
| 908 | .setOptionalTlv(llOptionalTlv).build(); |
| 909 | // build ero object |
| 910 | PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build(); |
| 911 | |
| 912 | int iBandwidth = DEFAULT_BANDWIDTH_VALUE; |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 913 | if (tunnel.annotations().value("bandwidth") != null) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 914 | iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth")); |
| 915 | } |
| 916 | // build bandwidth object |
| 917 | PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build(); |
| 918 | // build pcep attribute |
| 919 | PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build(); |
| 920 | // build pcep msg path |
| 921 | PcepMsgPath msgPath = pc.factory().buildPcepMsgPath().setEroObject(eroobj).setPcepAttribute(pcepAttribute) |
| 922 | .build(); |
| 923 | |
| 924 | PcepUpdateRequest updateRequest = pc.factory().buildPcepUpdateRequest().setSrpObject(srpobj) |
| 925 | .setLspObject(lspobj).setMsgPath(msgPath).build(); |
| 926 | |
| 927 | llUpdateRequestList.add(updateRequest); |
| 928 | |
| 929 | PcepUpdateMsg pcUpdateMsg = pc.factory().buildUpdateMsg().setUpdateRequestList(llUpdateRequestList).build(); |
| 930 | |
| 931 | pc.sendMessage(Collections.singletonList(pcUpdateMsg)); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 932 | pcepTunnelApiMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 933 | } catch (PcepParseException e) { |
| 934 | log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage()); |
| 935 | } |
| 936 | } |
| 937 | |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 938 | |
| 939 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 940 | private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 941 | |
| 942 | @Override |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 943 | public void handlePcepTunnel(PcepTunnel pcepTunnel) { |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 944 | TunnelDescription tunnel = null; |
| 945 | // instance and id identify a tunnel together |
| 946 | String tunnelKey = String.valueOf(pcepTunnel.getInstance()) |
| 947 | + String.valueOf(pcepTunnel.id()); |
| 948 | |
| 949 | if (tunnelKey == null || "".equals(tunnelKey)) { |
| 950 | log.error("Invalid PCEP tunnel"); |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | TunnelId tunnelId = getTunnelId(tunnelKey); |
| 955 | |
| 956 | tunnel = buildOpticalTunnel(pcepTunnel, tunnelId); |
| 957 | |
| 958 | OperationType operType = pcepTunnel.getOperationType(); |
| 959 | switch (operType) { |
| 960 | case ADD: |
| 961 | tunnelId = service.tunnelAdded(tunnel); |
| 962 | tunnelMap.put(tunnelKey, tunnelId); |
| 963 | break; |
| 964 | |
| 965 | case UPDATE: |
| 966 | service.tunnelUpdated(tunnel); |
| 967 | break; |
| 968 | |
| 969 | case DELETE: |
| 970 | service.tunnelRemoved(tunnel); |
| 971 | tunnelMap.remove(tunnelKey); |
| 972 | break; |
| 973 | |
| 974 | default: |
| 975 | log.error("Invalid tunnel operation"); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 976 | } |
| 977 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 978 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 979 | @Override |
| 980 | public void handleMessage(PccId pccId, PcepMessage msg) { |
| 981 | try { |
| 982 | log.debug("tunnel provider handle message {}", msg.getType().toString()); |
| 983 | switch (msg.getType()) { |
| 984 | case REPORT: |
| 985 | int srpId = 0; |
| 986 | LinkedList<PcepStateReport> llStateReportList = null; |
| 987 | llStateReportList = ((PcepReportMsg) msg).getStateReportList(); |
| 988 | ListIterator<PcepStateReport> listIterator = llStateReportList.listIterator(); |
| 989 | PcepSrpObject srpObj = null; |
| 990 | PcepLspObject lspObj = null; |
| 991 | while (listIterator.hasNext()) { |
| 992 | PcepStateReport stateRpt = listIterator.next(); |
| 993 | srpObj = stateRpt.getSrpObject(); |
| 994 | lspObj = stateRpt.getLspObject(); |
| 995 | |
| 996 | if (srpObj instanceof PcepSrpObject) { |
| 997 | srpId = srpObj.getSrpID(); |
| 998 | } |
| 999 | |
| 1000 | log.debug("Plsp ID in handle message " + lspObj.getPlspId()); |
| 1001 | log.debug("SRP ID in handle message " + srpId); |
| 1002 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1003 | if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1004 | |
| 1005 | // Check the sync status |
| 1006 | if (lspObj.getSFlag()) { |
| 1007 | handleSyncReport(stateRpt); |
| 1008 | } else if (!pcepClientController.getClient(pccId).isSyncComplete()) { |
| 1009 | // sync is done |
| 1010 | pcepClientController.getClient(pccId).setIsSyncComplete(true); |
| 1011 | } |
| 1012 | continue; |
| 1013 | } |
| 1014 | |
| 1015 | handleReportMessage(srpId, lspObj); |
| 1016 | } |
| 1017 | break; |
| 1018 | |
| 1019 | default: |
| 1020 | log.debug("Received unsupported message type {}", msg.getType().toString()); |
| 1021 | } |
| 1022 | } catch (Exception e) { |
| 1023 | log.error("Exception occured while processing report message {}", e.getMessage()); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * Handles report message for setup/update/delete tunnel request. |
| 1029 | * |
| 1030 | * @param srpId unique identifier for pcep message |
| 1031 | * @param lspObj lsp object |
| 1032 | */ |
| 1033 | private void handleReportMessage(int srpId, PcepLspObject lspObj) { |
| 1034 | ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1035 | PcepTunnelData pcepTunnelData = pcepTunnelApiMapper.getDataFromTunnelRequestQueue(srpId); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1036 | SparseAnnotations annotations = (SparseAnnotations) pcepTunnelData.tunnel().annotations(); |
| 1037 | |
| 1038 | // store the values required from report message |
| 1039 | pcepTunnelData.setPlspId(lspObj.getPlspId()); |
| 1040 | pcepTunnelData.setLspAFlag(lspObj.getAFlag()); |
| 1041 | pcepTunnelData.setLspOFlag(lspObj.getOFlag()); |
| 1042 | pcepTunnelData.setLspDFlag(lspObj.getDFlag()); |
| 1043 | |
| 1044 | StatefulIPv4LspIdentidiersTlv ipv4LspTlv = null; |
| 1045 | ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); |
| 1046 | while (listTlvIterator.hasNext()) { |
| 1047 | PcepValueType tlv = listTlvIterator.next(); |
| 1048 | if (tlv.getType() == StatefulIPv4LspIdentidiersTlv.TYPE) { |
| 1049 | ipv4LspTlv = (StatefulIPv4LspIdentidiersTlv) tlv; |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 1053 | if (ipv4LspTlv != null) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1054 | pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspTlv); |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 1055 | } |
| 1056 | |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1057 | Path path = pcepTunnelData.path(); |
| 1058 | Tunnel tunnel = pcepTunnelData.tunnel(); |
| 1059 | DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), |
| 1060 | tunnel.dst(), tunnel.type(), tunnel.groupId(), |
| 1061 | providerId, tunnel.tunnelName(), path, |
| 1062 | annotations); |
| 1063 | |
| 1064 | if (RequestType.CREATE == pcepTunnelData.requestType()) { |
| 1065 | log.debug("Report received for create request"); |
| 1066 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1067 | pcepTunnelApiMapper.handleCreateTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1068 | if (0 == lspObj.getOFlag()) { |
| 1069 | log.warn("The tunnel is in down state"); |
| 1070 | } |
| 1071 | tunnelAdded(td); |
| 1072 | } |
| 1073 | if (RequestType.DELETE == pcepTunnelData.requestType()) { |
| 1074 | log.debug("Report received for delete request"); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1075 | pcepTunnelApiMapper.handleRemoveFromTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1076 | tunnelRemoved(td); |
| 1077 | } |
| 1078 | |
| 1079 | if (RequestType.UPDATE == pcepTunnelData.requestType()) { |
| 1080 | log.debug("Report received for update request"); |
| 1081 | pcepTunnelData.setRptFlag(true); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1082 | pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
| 1083 | pcepTunnelApiMapper.handleUpdateTunnelRequestQueue(srpId, pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1084 | |
| 1085 | if (0 == lspObj.getOFlag()) { |
| 1086 | log.warn("The tunnel is in down state"); |
| 1087 | } |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1088 | if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1089 | tunnelUpdated(td); |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | /** |
| 1095 | * Handles sync report received from pcc. |
| 1096 | * |
| 1097 | * @param stateRpt pcep state report |
| 1098 | */ |
| 1099 | private void handleSyncReport(PcepStateReport stateRpt) { |
| 1100 | PcepLspObject lspObj = stateRpt.getLspObject(); |
| 1101 | PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); |
| 1102 | checkNotNull(msgPath); |
| 1103 | PcepRroObject rroObj = msgPath.getRroObject(); |
Mahesh Poojary S | 5eab857 | 2015-09-01 17:45:48 +0530 | [diff] [blame] | 1104 | if (rroObj == null) { |
| 1105 | log.debug("RRO object is null in sate report"); |
| 1106 | return; |
| 1107 | } |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1108 | int bandwidth = 0; |
| 1109 | |
| 1110 | log.debug("Handle Sync report received from PCC."); |
| 1111 | |
| 1112 | if (0 == lspObj.getOFlag()) { |
| 1113 | log.warn("The PCC reported tunnel is in down state"); |
| 1114 | } |
| 1115 | log.debug("Sync report received"); |
| 1116 | |
Sho SHIMIZU | de09fa0 | 2015-09-03 09:39:52 -0700 | [diff] [blame] | 1117 | if (msgPath.getBandwidthObject() != null) { |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1118 | bandwidth = msgPath.getBandwidthObject().getBandwidth(); |
| 1119 | } |
| 1120 | |
| 1121 | buildAndStorePcepTunnelData(lspObj, rroObj, bandwidth); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * To build Path in network from RRO object. |
| 1126 | * |
| 1127 | * @param rroObj rro object |
| 1128 | * @param providerId provider id |
| 1129 | * @return path object |
| 1130 | */ |
| 1131 | private Path buildPathFromRroObj(PcepRroObject rroObj, ProviderId providerId) { |
| 1132 | checkNotNull(rroObj); |
| 1133 | List<Link> links = new ArrayList<Link>(); |
| 1134 | LinkedList<PcepValueType> llSubObj = rroObj.getSubObjects(); |
| 1135 | if (0 == llSubObj.size()) { |
| 1136 | log.error("RRO in report message does not have hop information"); |
| 1137 | } |
| 1138 | ListIterator<PcepValueType> tlvIterator = llSubObj.listIterator(); |
| 1139 | |
| 1140 | ConnectPoint src = null; |
| 1141 | ConnectPoint dst = null; |
| 1142 | boolean isSrcSet = false; |
| 1143 | while (tlvIterator.hasNext()) { |
| 1144 | PcepValueType subObj = tlvIterator.next(); |
| 1145 | switch (subObj.getType()) { |
| 1146 | |
| 1147 | case IPv4SubObject.TYPE: |
| 1148 | |
| 1149 | IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj; |
| 1150 | if (!isSrcSet) { |
| 1151 | IpAddress srcIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); |
| 1152 | src = new ConnectPoint(IpElementId.ipElement(srcIp), PortNumber.portNumber(0)); |
| 1153 | isSrcSet = true; |
| 1154 | } else { |
| 1155 | IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); |
| 1156 | dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0)); |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 1157 | Link link = DefaultLink.builder() |
| 1158 | .providerId(providerId) |
| 1159 | .src(src) |
| 1160 | .dst(dst) |
| 1161 | .type(Link.Type.DIRECT) |
| 1162 | .build(); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1163 | links.add(link); |
| 1164 | src = dst; |
| 1165 | } |
| 1166 | break; |
| 1167 | default: |
| 1168 | // the other sub objects are not required |
| 1169 | } |
| 1170 | } |
| 1171 | return new DefaultPath(providerId, links, 0, EMPTY); |
| 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * To build pcepTunnelData and informs core about the pcc reported tunnel. |
| 1176 | * |
| 1177 | * @param lspObj pcep lsp object |
| 1178 | * @param rroObj pcep rro object |
| 1179 | * @param bandwidth bandwidth of tunnel |
| 1180 | */ |
| 1181 | private void buildAndStorePcepTunnelData(PcepLspObject lspObj, PcepRroObject rroObj, |
| 1182 | int bandwidth) { |
| 1183 | |
| 1184 | ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); |
| 1185 | |
| 1186 | // StatefulIPv4LspIdentidiersTlv in LSP object will have the source and destination address. |
| 1187 | StatefulIPv4LspIdentidiersTlv lspIdenTlv = null; |
| 1188 | SymbolicPathNameTlv pathNameTlv = null; |
| 1189 | LinkedList<PcepValueType> llOptionalTlv = lspObj.getOptionalTlv(); |
| 1190 | ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); |
| 1191 | while (listIterator.hasNext()) { |
| 1192 | PcepValueType tlv = listIterator.next(); |
| 1193 | switch (tlv.getType()) { |
| 1194 | case StatefulIPv4LspIdentidiersTlv.TYPE: |
| 1195 | lspIdenTlv = (StatefulIPv4LspIdentidiersTlv) tlv; |
| 1196 | break; |
| 1197 | case SymbolicPathNameTlv.TYPE: |
| 1198 | pathNameTlv = (SymbolicPathNameTlv) tlv; |
| 1199 | break; |
| 1200 | default: |
| 1201 | // currently this tlv is not required |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | IpTunnelEndPoint tunnelEndPointSrc; |
| 1206 | tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(lspIdenTlv.getIpv4IngressAddress())); |
| 1207 | IpTunnelEndPoint tunnelEndPointDst; |
| 1208 | tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(lspIdenTlv.getIpv4EgressAddress())); |
| 1209 | |
| 1210 | Path path = buildPathFromRroObj(rroObj, providerId); |
| 1211 | |
| 1212 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 1213 | .set("bandwidth", (new Integer(bandwidth)).toString()) |
| 1214 | .build(); |
| 1215 | |
| 1216 | DefaultTunnelDescription td = new DefaultTunnelDescription(null, tunnelEndPointSrc, |
| 1217 | tunnelEndPointDst, Tunnel.Type.MPLS, |
| 1218 | new DefaultGroupId(0), providerId, |
| 1219 | TunnelName.tunnelName(pathNameTlv.toString()), |
| 1220 | path, annotations); |
| 1221 | TunnelId tId = tunnelAdded(td); |
| 1222 | |
| 1223 | Tunnel tunnel = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, Tunnel.Type.MPLS, |
| 1224 | new DefaultGroupId(0), tId, |
| 1225 | TunnelName.tunnelName(pathNameTlv.toString()), path, annotations); |
| 1226 | |
| 1227 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.LSP_STATE_RPT); |
| 1228 | pcepTunnelData.setStatefulIpv4IndentifierTlv(lspIdenTlv); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1229 | pcepTunnelApiMapper.addPccTunnelDB(pcepTunnelData); |
| 1230 | pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | @Override |
| 1234 | public void clientConnected(PccId pccId) { |
| 1235 | // TODO |
| 1236 | } |
| 1237 | |
| 1238 | @Override |
| 1239 | public void clientDisconnected(PccId pccId) { |
| 1240 | // TODO |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 1241 | } |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 1242 | |
| 1243 | |
| 1244 | |
| 1245 | @Override |
| 1246 | public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) { |
| 1247 | TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id())); |
| 1248 | TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics); |
| 1249 | tunnelStatisticsMap.put(id, tunnelStatistics); |
| 1250 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | @Override |
| 1254 | public Tunnel tunnelQueryById(TunnelId tunnelId) { |
| 1255 | return service.tunnelQueryById(tunnelId); |
| 1256 | } |
cheng fan | 48e832c | 2015-05-29 01:54:47 +0800 | [diff] [blame] | 1257 | } |