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