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