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