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