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