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