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