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