Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.bgpcep.flow.impl; |
| 17 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
| 20 | |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 26 | import org.onlab.packet.Ip4Address; |
| 27 | import org.onlab.packet.IpAddress; |
| 28 | import org.onlab.packet.IpPrefix; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 29 | import org.onlab.packet.MplsLabel; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 30 | import org.onosproject.bgp.controller.BgpController; |
| 31 | import org.onosproject.cfg.ComponentConfigService; |
| 32 | import org.onosproject.core.ApplicationId; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 33 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 34 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 35 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 37 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 38 | import org.onosproject.net.ConnectPoint; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 39 | import org.onosproject.net.Device; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 40 | import org.onosproject.net.DeviceId; |
| 41 | import org.onosproject.net.Link; |
| 42 | import org.onosproject.net.Path; |
| 43 | import org.onosproject.net.PortNumber; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 44 | import org.onosproject.net.device.DeviceService; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 45 | import org.onosproject.net.flow.FlowRule; |
| 46 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 47 | import org.onosproject.net.flow.FlowRuleProvider; |
| 48 | import org.onosproject.net.flow.FlowRuleProviderRegistry; |
| 49 | import org.onosproject.net.flow.FlowRuleProviderService; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 50 | import org.onosproject.net.flow.TrafficSelector; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 51 | import org.onosproject.net.flow.criteria.Criterion; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 52 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 53 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
| 54 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 55 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 56 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 57 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
| 58 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 59 | import org.onosproject.net.flowobjective.Objective; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 60 | import org.onosproject.net.provider.AbstractProvider; |
| 61 | import org.onosproject.net.provider.ProviderId; |
| 62 | import org.onosproject.net.resource.ResourceService; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 63 | import org.onosproject.pcep.controller.PccId; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 64 | import org.onosproject.pcep.controller.PcepClient; |
| 65 | import org.onosproject.pcep.controller.PcepClientController; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 66 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 67 | import org.onosproject.pcepio.protocol.PcepEroObject; |
| 68 | import org.onosproject.pcepio.protocol.PcepFecObjectIPv4; |
| 69 | import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; |
| 70 | import org.onosproject.pcepio.protocol.PcepLabelObject; |
| 71 | import org.onosproject.pcepio.protocol.PcepLabelUpdate; |
| 72 | import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; |
| 73 | import org.onosproject.pcepio.protocol.PcepLspObject; |
| 74 | import org.onosproject.pcepio.protocol.PcepMsgPath; |
| 75 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
| 76 | import org.onosproject.pcepio.protocol.PcepUpdateMsg; |
| 77 | import org.onosproject.pcepio.protocol.PcepUpdateRequest; |
| 78 | import org.onosproject.pcepio.types.IPv4SubObject; |
| 79 | import org.onosproject.pcepio.types.NexthopIPv4addressTlv; |
| 80 | import org.onosproject.pcepio.types.PcepLabelDownload; |
| 81 | import org.onosproject.pcepio.types.PcepLabelMap; |
| 82 | import org.onosproject.pcepio.types.PcepValueType; |
| 83 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; |
| 84 | import org.onosproject.provider.pcep.tunnel.impl.SrpIdGenerators; |
| 85 | import org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 86 | import org.osgi.service.component.ComponentContext; |
| 87 | import org.slf4j.Logger; |
| 88 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 89 | import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; |
| 90 | import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; |
| 91 | import static com.google.common.base.Preconditions.checkNotNull; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 92 | import static org.slf4j.LoggerFactory.getLogger; |
| 93 | |
| 94 | /** |
| 95 | * Implementation of BGP-PCEP flow provider. |
| 96 | */ |
| 97 | @Component(immediate = true) |
| 98 | public class BgpcepFlowRuleProvider extends AbstractProvider |
| 99 | implements FlowRuleProvider { |
| 100 | |
| 101 | private final Logger log = getLogger(getClass()); |
| 102 | |
| 103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 104 | protected FlowRuleProviderRegistry providerRegistry; |
| 105 | |
| 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 107 | protected ComponentConfigService cfgService; |
| 108 | |
| 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 110 | protected BgpController bgpController; |
| 111 | |
| 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 113 | protected PcepClientController pcepController; |
| 114 | |
| 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 116 | protected ResourceService resourceService; |
| 117 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 119 | protected TunnelService tunnelService; |
| 120 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 121 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 122 | protected DeviceService deviceService; |
| 123 | |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 124 | private FlowRuleProviderService providerService; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 125 | private PcepLabelObject labelObj; |
| 126 | public static final int OUT_LABEL_TYPE = 0; |
| 127 | public static final int IN_LABEL_TYPE = 1; |
| 128 | public static final long IDENTIFIER_SET = 0x100000000L; |
| 129 | public static final long SET = 0xFFFFFFFFL; |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 130 | private static final String LSRID = "lsrId"; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Creates a BgpFlow host provider. |
| 134 | */ |
| 135 | public BgpcepFlowRuleProvider() { |
| 136 | super(new ProviderId("l3", "org.onosproject.provider.bgpcep")); |
| 137 | } |
| 138 | |
| 139 | @Activate |
| 140 | public void activate(ComponentContext context) { |
| 141 | cfgService.registerProperties(getClass()); |
| 142 | providerService = providerRegistry.register(this); |
| 143 | log.info("Started"); |
| 144 | } |
| 145 | |
| 146 | @Deactivate |
| 147 | public void deactivate(ComponentContext context) { |
| 148 | cfgService.unregisterProperties(getClass(), false); |
| 149 | providerRegistry.unregister(this); |
| 150 | providerService = null; |
| 151 | log.info("Stopped"); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void applyFlowRule(FlowRule... flowRules) { |
| 156 | for (FlowRule flowRule : flowRules) { |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 157 | processRule(flowRule, Objective.Operation.ADD); |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 161 | @Override |
| 162 | public void removeFlowRule(FlowRule... flowRules) { |
| 163 | for (FlowRule flowRule : flowRules) { |
| 164 | processRule(flowRule, Objective.Operation.REMOVE); |
| 165 | } |
| 166 | } |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 167 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 168 | private void processRule(FlowRule flowRule, Objective.Operation type) { |
| 169 | MplsLabel mplsLabel = null; |
| 170 | IpPrefix ip4Prefix = null; |
| 171 | PortNumber port = null; |
| 172 | TunnelId tunnelId = null; |
| 173 | long labelType = 0; |
| 174 | boolean bottomOfStack = false; |
| 175 | int srcPort = 0; |
| 176 | int dstPort = 0; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 177 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 178 | TrafficSelector selector = flowRule.selector(); |
| 179 | for (Criterion c : selector.criteria()) { |
| 180 | switch (c.type()) { |
| 181 | case MPLS_LABEL: |
| 182 | MplsCriterion lc = (MplsCriterion) c; |
| 183 | mplsLabel = lc.label(); |
| 184 | break; |
| 185 | case IPV4_SRC: |
| 186 | IPCriterion ipCriterion = (IPCriterion) c; |
| 187 | ip4Prefix = ipCriterion.ip().getIp4Prefix(); |
| 188 | break; |
| 189 | case IN_PORT: |
| 190 | PortCriterion inPort = (PortCriterion) c; |
| 191 | port = inPort.port(); |
| 192 | break; |
| 193 | case TCP_SRC: |
| 194 | TcpPortCriterion srcTcpPort = (TcpPortCriterion) c; |
| 195 | srcPort = srcTcpPort.tcpPort().toInt(); |
| 196 | break; |
| 197 | case TCP_DST: |
| 198 | TcpPortCriterion dstTcpPort = (TcpPortCriterion) c; |
| 199 | dstPort = dstTcpPort.tcpPort().toInt(); |
| 200 | break; |
| 201 | case TUNNEL_ID: |
| 202 | TunnelIdCriterion tc = (TunnelIdCriterion) c; |
| 203 | tunnelId = TunnelId.valueOf(String.valueOf(tc.tunnelId())); |
| 204 | break; |
| 205 | case METADATA: |
| 206 | MetadataCriterion metadata = (MetadataCriterion) c; |
| 207 | labelType = metadata.metadata(); |
| 208 | break; |
| 209 | case MPLS_BOS: |
| 210 | MplsBosCriterion mplsBos = (MplsBosCriterion) c; |
| 211 | bottomOfStack = mplsBos.mplsBos(); |
| 212 | break; |
| 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | checkNotNull(mplsLabel); |
| 219 | LabelResourceId label = LabelResourceId.labelResourceId(mplsLabel.toInt()); |
| 220 | |
| 221 | try { |
| 222 | if (tunnelId != null) { |
| 223 | pushLocalLabels(flowRule.deviceId(), label, port, tunnelId, bottomOfStack, labelType, type); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | if (srcPort != 0 && dstPort != 0) { |
| 228 | pushAdjacencyLabel(flowRule.deviceId(), label, PortNumber.portNumber(srcPort), |
| 229 | PortNumber.portNumber(dstPort), type); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | pushGlobalNodeLabel(flowRule.deviceId(), label, ip4Prefix, type, bottomOfStack); |
| 234 | |
| 235 | } catch (PcepParseException e) { |
| 236 | log.error("Exception occured while sending label message to PCC {}", e.getMessage()); |
| 237 | } |
| 238 | |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 239 | } |
| 240 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 241 | /** |
| 242 | * Returns PCEP client. |
| 243 | * |
| 244 | * @return PCEP client |
| 245 | */ |
| 246 | private PcepClient getPcepClient(DeviceId deviceId) { |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 247 | Device device = deviceService.getDevice(deviceId); |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 248 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 249 | // In future projections instead of annotations will be used to fetch LSR ID. |
| 250 | String lsrId = device.annotations().value(LSRID); |
| 251 | |
| 252 | PcepClient pcc = pcepController.getClient(PccId.pccId(IpAddress.valueOf(lsrId))); |
| 253 | return pcc; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | //Pushes node labels to the specified device. |
| 257 | private void pushGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId, |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 258 | IpPrefix ipPrefix, Objective.Operation type, boolean isBos) throws PcepParseException { |
| 259 | |
| 260 | checkNotNull(deviceId); |
| 261 | checkNotNull(labelId); |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 262 | checkNotNull(type); |
| 263 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 264 | PcepClient pc = getPcepClient(deviceId); |
| 265 | if (pc == null) { |
| 266 | log.error("PCEP client not found"); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); |
| 271 | |
Avantika-Huawei | a4f66f6 | 2016-05-25 16:52:08 +0530 | [diff] [blame^] | 272 | if (ipPrefix == null) { |
| 273 | // Pushing self node label to device. |
| 274 | IpPrefix.valueOf(pc.getPccId().ipAddress(), 32); |
| 275 | } |
| 276 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 277 | PcepFecObjectIPv4 fecObject = pc.factory().buildFecObjectIpv4() |
| 278 | .setNodeID(ipPrefix.address().getIp4Address().toInt()) |
| 279 | .build(); |
| 280 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 281 | boolean bSFlag = false; |
| 282 | if (pc.labelDbSyncStatus() == IN_SYNC) { |
| 283 | if (isBos) { |
| 284 | /* |
| 285 | * Now the sync is completed. |
| 286 | * Need to send label DB end-of-sync msg, i.e. S flag in SRP id is reset. |
| 287 | */ |
| 288 | pc.setLabelDbSyncStatus(SYNCED); |
| 289 | } else { |
| 290 | bSFlag = true; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag); |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 295 | |
| 296 | //Global NODE-SID as label object |
| 297 | PcepLabelObject labelObject = pc.factory().buildLabelObject() |
| 298 | .setLabel((int) labelId.labelId()) |
| 299 | .build(); |
| 300 | |
| 301 | PcepLabelMap labelMap = new PcepLabelMap(); |
| 302 | labelMap.setFecObject(fecObject); |
| 303 | labelMap.setLabelObject(labelObject); |
| 304 | labelMap.setSrpObject(srpObj); |
| 305 | |
| 306 | labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() |
| 307 | .setLabelMap(labelMap) |
| 308 | .build()); |
| 309 | |
| 310 | PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() |
| 311 | .setPcLabelUpdateList(labelUpdateList) |
| 312 | .build(); |
| 313 | |
| 314 | pc.sendMessage(labelMsg); |
| 315 | } |
| 316 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 317 | private PcepSrpObject getSrpObject(PcepClient pc, Objective.Operation type, boolean bSFlag) |
| 318 | throws PcepParseException { |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 319 | PcepSrpObject srpObj; |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 320 | boolean bRFlag = false; |
| 321 | |
| 322 | if (!type.equals(Objective.Operation.ADD)) { |
| 323 | // To cleanup labels, R bit is set |
| 324 | bRFlag = true; |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 325 | } |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 326 | |
| 327 | srpObj = pc.factory().buildSrpObject() |
| 328 | .setRFlag(bRFlag) |
| 329 | .setSFlag(bSFlag) |
| 330 | .setSrpID(SrpIdGenerators.create()) |
| 331 | .build(); |
| 332 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 333 | return srpObj; |
| 334 | } |
| 335 | |
| 336 | //Pushes adjacency labels to the specified device. |
| 337 | private void pushAdjacencyLabel(DeviceId deviceId, LabelResourceId labelId, |
| 338 | PortNumber srcPortNum, PortNumber dstPortNum, Objective.Operation type) throws PcepParseException { |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 339 | |
| 340 | checkNotNull(deviceId); |
| 341 | checkNotNull(labelId); |
| 342 | checkNotNull(srcPortNum); |
| 343 | checkNotNull(dstPortNum); |
| 344 | checkNotNull(type); |
| 345 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 346 | PcepClient pc = getPcepClient(deviceId); |
| 347 | if (pc == null) { |
| 348 | log.error("PCEP client not found"); |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); |
| 353 | |
| 354 | long srcPortNo = srcPortNum.toLong(); |
| 355 | long dstPortNo = dstPortNum.toLong(); |
| 356 | srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo; |
| 357 | dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo; |
| 358 | |
| 359 | PcepFecObjectIPv4Adjacency fecAdjObject = pc.factory().buildFecIpv4Adjacency() |
| 360 | .seRemoteIPv4Address((int) dstPortNo) |
| 361 | .seLocalIPv4Address((int) srcPortNo) |
| 362 | .build(); |
| 363 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 364 | PcepSrpObject srpObj = getSrpObject(pc, type, false); |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 365 | |
| 366 | //Adjacency label object |
| 367 | PcepLabelObject labelObject = pc.factory().buildLabelObject() |
| 368 | .setLabel((int) labelId.labelId()) |
| 369 | .build(); |
| 370 | |
| 371 | PcepLabelMap labelMap = new PcepLabelMap(); |
| 372 | labelMap.setFecObject(fecAdjObject); |
| 373 | labelMap.setLabelObject(labelObject); |
| 374 | labelMap.setSrpObject(srpObj); |
| 375 | |
| 376 | labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() |
| 377 | .setLabelMap(labelMap) |
| 378 | .build()); |
| 379 | |
| 380 | PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() |
| 381 | .setPcLabelUpdateList(labelUpdateList) |
| 382 | .build(); |
| 383 | |
| 384 | pc.sendMessage(labelMsg); |
| 385 | } |
| 386 | |
| 387 | //Pushes local labels to the device which is specific to path [CR-case]. |
| 388 | private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId, |
| 389 | PortNumber portNum, TunnelId tunnelId, |
| 390 | Boolean isBos, Long labelType, Objective.Operation type) throws PcepParseException { |
| 391 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 392 | checkNotNull(deviceId); |
| 393 | checkNotNull(labelId); |
| 394 | checkNotNull(portNum); |
| 395 | checkNotNull(tunnelId); |
| 396 | checkNotNull(labelType); |
| 397 | checkNotNull(type); |
| 398 | |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 399 | PcepClient pc = getPcepClient(deviceId); |
| 400 | if (pc == null) { |
| 401 | log.error("PCEP client not found"); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | PcepLspObject lspObj; |
| 406 | LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); |
| 407 | LinkedList<PcepLabelObject> labelObjects = new LinkedList<>(); |
| 408 | PcepSrpObject srpObj; |
| 409 | PcepLabelDownload labelDownload = new PcepLabelDownload(); |
| 410 | LinkedList<PcepValueType> optionalTlv = new LinkedList<>(); |
| 411 | |
| 412 | long portNo = portNum.toLong(); |
| 413 | portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; |
| 414 | |
| 415 | optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo)); |
| 416 | |
| 417 | Tunnel tunnel = tunnelService.queryTunnel(tunnelId); |
| 418 | |
| 419 | PcepLabelObject labelObj = pc.factory().buildLabelObject() |
| 420 | .setOFlag(labelType == OUT_LABEL_TYPE ? true : false) |
| 421 | .setOptionalTlv(optionalTlv) |
| 422 | .setLabel((int) labelId.labelId()) |
| 423 | .build(); |
| 424 | |
| 425 | /** |
| 426 | * Check whether transit node or not. For transit node, label update message should include IN and OUT labels. |
| 427 | * Hence store IN label object and next when out label comes add IN and OUT label objects and encode label |
| 428 | * update message and send to specified client. |
| 429 | */ |
| 430 | if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) { |
| 431 | //Device is transit node |
| 432 | if (labelType == IN_LABEL_TYPE) { |
| 433 | //Store label object having IN label value |
| 434 | this.labelObj = labelObj; |
| 435 | return; |
| 436 | } |
| 437 | //Add IN label object |
| 438 | labelObjects.add(this.labelObj); |
| 439 | } |
| 440 | |
| 441 | //Add OUT label object in case of transit node |
| 442 | labelObjects.add(labelObj); |
| 443 | |
Avantika-Huawei | 7c14e66 | 2016-05-16 19:13:34 +0530 | [diff] [blame] | 444 | srpObj = getSrpObject(pc, type, false); |
Priyanka B | bd455ca | 2016-05-05 22:13:25 +0530 | [diff] [blame] | 445 | |
| 446 | String lspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID); |
| 447 | String plspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID); |
| 448 | String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID); |
| 449 | |
| 450 | LinkedList<PcepValueType> tlvs = new LinkedList<>(); |
| 451 | StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src()) |
| 452 | .ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier), 0, |
| 453 | ((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()); |
| 454 | tlvs.add(lspIdTlv); |
| 455 | |
| 456 | lspObj = pc.factory().buildLspObject() |
| 457 | .setRFlag(false) |
| 458 | .setAFlag(true) |
| 459 | .setDFlag(true) |
| 460 | .setPlspId(Integer.valueOf(plspId)) |
| 461 | .setOptionalTlv(tlvs) |
| 462 | .build(); |
| 463 | |
| 464 | labelDownload.setLabelList(labelObjects); |
| 465 | labelDownload.setLspObject(lspObj); |
| 466 | labelDownload.setSrpObject(srpObj); |
| 467 | |
| 468 | labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() |
| 469 | .setLabelDownload(labelDownload) |
| 470 | .build()); |
| 471 | |
| 472 | PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() |
| 473 | .setPcLabelUpdateList(labelUpdateList) |
| 474 | .build(); |
| 475 | |
| 476 | pc.sendMessage(labelMsg); |
| 477 | |
| 478 | //If isBos is true, label download is done along the LSP, send PCEP update message. |
| 479 | if (isBos) { |
| 480 | sendPcepUpdateMsg(pc, lspObj, tunnel); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | //Sends PCEP update message. |
| 485 | private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException { |
| 486 | LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>(); |
| 487 | LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path()); |
| 488 | |
| 489 | if (subObjects == null) { |
| 490 | log.error("ERO subjects not present"); |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | PcepSrpObject srpObj = pc.factory().buildSrpObject() |
| 495 | .setRFlag(false) |
| 496 | .setSrpID(SrpIdGenerators.create()) |
| 497 | .build(); |
| 498 | |
| 499 | PcepEroObject eroObj = pc.factory().buildEroObject() |
| 500 | .setSubObjects(subObjects) |
| 501 | .build(); |
| 502 | |
| 503 | PcepMsgPath msgPath = pc.factory().buildPcepMsgPath() |
| 504 | .setEroObject(eroObj) |
| 505 | .build(); |
| 506 | |
| 507 | PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest() |
| 508 | .setSrpObject(srpObj) |
| 509 | .setMsgPath(msgPath) |
| 510 | .setLspObject(lspObj) |
| 511 | .build(); |
| 512 | |
| 513 | updateRequestList.add(updateReq); |
| 514 | |
| 515 | //TODO: P = 1 is it P flag in PCEP obj header |
| 516 | PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg() |
| 517 | .setUpdateRequestList(updateRequestList) |
| 518 | .build(); |
| 519 | |
| 520 | pc.sendMessage(updateMsg); |
| 521 | } |
| 522 | |
| 523 | private LinkedList<PcepValueType> createEroSubObj(Path path) { |
| 524 | LinkedList<PcepValueType> subObjects = new LinkedList<>(); |
| 525 | List<Link> links = path.links(); |
| 526 | ConnectPoint source = null; |
| 527 | ConnectPoint destination = null; |
| 528 | IpAddress ipDstAddress = null; |
| 529 | IpAddress ipSrcAddress = null; |
| 530 | PcepValueType subObj = null; |
| 531 | long portNo; |
| 532 | |
| 533 | for (Link link : links) { |
| 534 | source = link.src(); |
| 535 | if (!(source.equals(destination))) { |
| 536 | //set IPv4SubObject for ERO object |
| 537 | portNo = source.port().toLong(); |
| 538 | portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; |
| 539 | ipSrcAddress = Ip4Address.valueOf((int) portNo); |
| 540 | subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); |
| 541 | subObjects.add(subObj); |
| 542 | } |
| 543 | |
| 544 | destination = link.dst(); |
| 545 | portNo = destination.port().toLong(); |
| 546 | portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; |
| 547 | ipDstAddress = Ip4Address.valueOf((int) portNo); |
| 548 | subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); |
| 549 | subObjects.add(subObj); |
| 550 | } |
| 551 | return subObjects; |
| 552 | } |
| 553 | |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 554 | @Override |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 555 | public void removeRulesById(ApplicationId id, FlowRule... flowRules) { |
| 556 | // TODO |
| 557 | removeFlowRule(flowRules); |
| 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public void executeBatch(FlowRuleBatchOperation batch) { |
| 562 | //TODO |
| 563 | } |
| 564 | } |