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