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