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