Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -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 | |
| 17 | package org.onosproject.segmentrouting.pwaas; |
| 18 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Iterables; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import org.apache.commons.lang3.RandomUtils; |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ethernet; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.MplsLabel; |
| 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onlab.util.KryoNamespace; |
| 27 | import org.onosproject.net.ConnectPoint; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 28 | import org.onosproject.net.DefaultLink; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.DisjointPath; |
| 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.PortNumber; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 33 | import org.onosproject.net.config.NetworkConfigEvent; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 36 | import org.onosproject.net.flow.TrafficSelector; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; |
| 38 | import org.onosproject.net.flow.criteria.Criteria; |
| 39 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 40 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 41 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
| 42 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
| 43 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 44 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 45 | import org.onosproject.net.flowobjective.NextObjective; |
| 46 | import org.onosproject.net.flowobjective.Objective; |
| 47 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 48 | import org.onosproject.net.flowobjective.ObjectiveError; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 49 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 50 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 51 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 52 | import org.onosproject.segmentrouting.config.PwaasConfig; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 53 | import org.onosproject.store.serializers.KryoNamespaces; |
| 54 | import org.onosproject.store.service.ConsistentMap; |
| 55 | import org.onosproject.store.service.Serializer; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 56 | import org.onosproject.store.service.Versioned; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | import org.slf4j.LoggerFactory; |
| 59 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 60 | import java.util.List; |
| 61 | import java.util.Set; |
| 62 | import java.util.concurrent.CompletableFuture; |
| 63 | import java.util.stream.Collectors; |
| 64 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 65 | import static com.google.common.base.Preconditions.checkArgument; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 66 | import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 67 | import static org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.INITIATION; |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 68 | import static org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.TERMINATION; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 69 | import static org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result.*; |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 70 | import static org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.FWD; |
| 71 | import static org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.REV; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 72 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 73 | /** |
| 74 | * Handles pwaas related events. |
| 75 | */ |
| 76 | public class L2TunnelHandler { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 77 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 78 | private static final Logger log = LoggerFactory.getLogger(L2TunnelHandler.class); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 79 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 80 | private final SegmentRoutingManager srManager; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 81 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 82 | * To store the next objectives related to the initiation. |
| 83 | */ |
| 84 | private final ConsistentMap<String, NextObjective> l2InitiationNextObjStore; |
| 85 | /** |
| 86 | * To store the next objectives related to the termination. |
| 87 | */ |
| 88 | private final ConsistentMap<String, NextObjective> l2TerminationNextObjStore; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 89 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 90 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 91 | * To store policies. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 92 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 93 | private final ConsistentMap<String, DefaultL2TunnelPolicy> l2PolicyStore; |
| 94 | |
| 95 | /** |
| 96 | * To store tunnels. |
| 97 | */ |
| 98 | private final ConsistentMap<String, DefaultL2Tunnel> l2TunnelStore; |
| 99 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 100 | private final KryoNamespace.Builder l2TunnelKryo; |
| 101 | |
| 102 | /** |
| 103 | * Create a l2 tunnel handler for the deploy and |
| 104 | * for the tear down of pseudo wires. |
| 105 | * |
| 106 | * @param segmentRoutingManager the segment routing manager |
| 107 | */ |
| 108 | public L2TunnelHandler(SegmentRoutingManager segmentRoutingManager) { |
| 109 | srManager = segmentRoutingManager; |
| 110 | l2TunnelKryo = new KryoNamespace.Builder() |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 111 | .register(KryoNamespaces.API) |
| 112 | .register(DefaultL2Tunnel.class, |
| 113 | DefaultL2TunnelPolicy.class, |
| 114 | L2Mode.class, |
| 115 | MplsLabel.class, |
| 116 | VlanId.class, |
| 117 | ConnectPoint.class); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 118 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 119 | l2InitiationNextObjStore = srManager. |
| 120 | storageService. |
| 121 | <String, NextObjective>consistentMapBuilder(). |
| 122 | withName("onos-l2initiation-nextobj-store"). |
| 123 | withSerializer(Serializer.using(l2TunnelKryo.build())). |
| 124 | build(); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 125 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 126 | l2TerminationNextObjStore = srManager.storageService. |
| 127 | <String, NextObjective>consistentMapBuilder() |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 128 | .withName("onos-l2termination-nextobj-store") |
| 129 | .withSerializer(Serializer.using(l2TunnelKryo.build())) |
| 130 | .build(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 131 | |
| 132 | l2PolicyStore = srManager.storageService |
| 133 | .<String, DefaultL2TunnelPolicy>consistentMapBuilder() |
| 134 | .withName("onos-l2-policy-store") |
| 135 | .withSerializer(Serializer.using(l2TunnelKryo.build())) |
| 136 | .build(); |
| 137 | |
| 138 | l2TunnelStore = srManager.storageService |
| 139 | .<String, DefaultL2Tunnel>consistentMapBuilder() |
| 140 | .withName("onos-l2-tunnel-store") |
| 141 | .withSerializer(Serializer.using(l2TunnelKryo.build())) |
| 142 | .build(); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns all L2 Policies. |
| 147 | * |
| 148 | * @return List of policies |
| 149 | */ |
| 150 | public List<DefaultL2TunnelPolicy> getL2Policies() { |
| 151 | |
| 152 | return l2PolicyStore |
| 153 | .values() |
| 154 | .stream() |
| 155 | .map(Versioned::value) |
| 156 | .map(DefaultL2TunnelPolicy::new) |
| 157 | .collect(Collectors.toList()); |
| 158 | |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Returns all L2 Tunnels. |
| 163 | * |
| 164 | * @return List of tunnels. |
| 165 | */ |
| 166 | public List<DefaultL2Tunnel> getL2Tunnels() { |
| 167 | |
| 168 | return l2TunnelStore |
| 169 | .values() |
| 170 | .stream() |
| 171 | .map(Versioned::value) |
| 172 | .map(DefaultL2Tunnel::new) |
| 173 | .collect(Collectors.toList()); |
| 174 | |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Processes a link removal. Finds affected pseudowires and rewires them. |
| 179 | * TODO: Make it also take into account failures of links that are used for pw |
| 180 | * traffic in the spine. |
| 181 | * @param link The link that failed |
| 182 | */ |
| 183 | public void processLinkDown(Link link) { |
| 184 | |
| 185 | List<DefaultL2Tunnel> tunnels = getL2Tunnels(); |
| 186 | List<DefaultL2TunnelPolicy> policies = getL2Policies(); |
| 187 | |
| 188 | // determine affected pseudowires and update them at once |
| 189 | Set<DefaultL2TunnelDescription> pwToUpdate = tunnels |
| 190 | .stream() |
| 191 | .filter(tun -> tun.pathUsed().contains(link)) |
| 192 | .map(l2Tunnel -> { |
| 193 | DefaultL2TunnelPolicy policy = null; |
| 194 | for (DefaultL2TunnelPolicy l2Policy : policies) { |
| 195 | if (l2Policy.tunnelId() == l2Tunnel.tunnelId()) { |
| 196 | policy = l2Policy; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return new DefaultL2TunnelDescription(l2Tunnel, policy); |
| 202 | }) |
| 203 | .collect(Collectors.toSet()); |
| 204 | |
| 205 | |
| 206 | log.info("Pseudowires affected by link failure : {}, rerouting them...", pwToUpdate); |
| 207 | |
| 208 | // update all pseudowires |
| 209 | pwToUpdate.forEach(tun -> updatePw(tun, tun)); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Processes Pwaas Config added event. |
| 214 | * |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 215 | * @param event network config add event |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 216 | */ |
| 217 | public void processPwaasConfigAdded(NetworkConfigEvent event) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 218 | checkArgument(event.config().isPresent(), |
| 219 | "Config is not presented in PwaasConfigAdded event {}", event); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 220 | |
| 221 | log.info("Network event : Pseudowire configuration added!"); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 222 | PwaasConfig config = (PwaasConfig) event.config().get(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 223 | |
| 224 | // gather pseudowires |
| 225 | Set<DefaultL2TunnelDescription> pwToAdd = config |
| 226 | .getPwIds() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 227 | .stream() |
| 228 | .map(config::getPwDescription) |
| 229 | .collect(Collectors.toSet()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 230 | |
| 231 | // deploy pseudowires |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 232 | deploy(pwToAdd); |
| 233 | } |
| 234 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 235 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 236 | * Returns the new vlan id for an ingress point of a |
| 237 | * pseudowire. For double tagged, it is the outer, |
| 238 | * For single tagged it is the single tag, and for |
| 239 | * inner it is None. |
| 240 | * |
| 241 | * @param ingressOuter vlanid of ingress outer |
| 242 | * @param ingressInner vlanid of ingress inner |
| 243 | * @param egressOuter vlanid of egress outer |
| 244 | * @param egressInner vlanid of egress inner |
| 245 | * @return returns the vlan id which will be installed at vlan table 1. |
| 246 | */ |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 247 | private VlanId determineEgressVlan(VlanId ingressOuter, VlanId ingressInner, |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 248 | VlanId egressOuter, VlanId egressInner) { |
| 249 | |
| 250 | // validity of vlan combinations was checked at verifyPseudowire |
| 251 | if (!(ingressOuter.equals(VlanId.NONE))) { |
| 252 | return egressOuter; |
| 253 | } else if (!(ingressInner.equals(VlanId.NONE))) { |
| 254 | return egressInner; |
| 255 | } else { |
| 256 | return VlanId.vlanId("None"); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 261 | * Adds a single pseudowire from leaf to a leaf. |
| 262 | * This method can be called from cli commands |
Charles Chan | e5a3255 | 2018-01-06 17:57:27 -0800 | [diff] [blame^] | 263 | * without configuration updates, thus it does not check for mastership |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 264 | * of the ingress pseudowire device. |
| 265 | * |
| 266 | * @param pw The pseudowire |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 267 | * @param spinePw True if pseudowire is from leaf to spine |
| 268 | * @return result of pseudowire deployment |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 269 | */ |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 270 | private Result deployPseudowire(DefaultL2TunnelDescription pw, boolean spinePw) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 271 | |
| 272 | Result result; |
| 273 | long l2TunnelId; |
| 274 | |
| 275 | l2TunnelId = pw.l2Tunnel().tunnelId(); |
| 276 | |
| 277 | // The tunnel id cannot be 0. |
| 278 | if (l2TunnelId == 0) { |
| 279 | log.warn("Tunnel id id must be > 0"); |
| 280 | return Result.ADDITION_ERROR; |
| 281 | } |
| 282 | |
| 283 | // get path here, need to use the same for fwd and rev direction |
| 284 | List<Link> path = getPath(pw.l2TunnelPolicy().cP1(), |
| 285 | pw.l2TunnelPolicy().cP2()); |
| 286 | if (path == null) { |
| 287 | log.info("Deploying process : No path between the connection points for pseudowire {}", l2TunnelId); |
| 288 | return WRONG_PARAMETERS; |
| 289 | } |
| 290 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 291 | Link fwdNextHop; |
| 292 | Link revNextHop; |
| 293 | if (!spinePw) { |
| 294 | if (path.size() != 2) { |
| 295 | log.info("Deploying process : Path between two leafs should have size of 2, for pseudowire {}", |
| 296 | l2TunnelId); |
| 297 | return INTERNAL_ERROR; |
| 298 | } |
| 299 | |
| 300 | fwdNextHop = path.get(0); |
| 301 | revNextHop = reverseLink(path.get(1)); |
| 302 | } else { |
| 303 | if (path.size() != 1) { |
Charles Chan | e5a3255 | 2018-01-06 17:57:27 -0800 | [diff] [blame^] | 304 | log.info("Deploying process : Path between leaf spine should equal to 1, for pseudowire {}", |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 305 | l2TunnelId); |
| 306 | return INTERNAL_ERROR; |
| 307 | } |
| 308 | |
| 309 | fwdNextHop = path.get(0); |
| 310 | revNextHop = reverseLink(path.get(0)); |
| 311 | } |
| 312 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 313 | pw.l2Tunnel().setPath(path); |
| 314 | |
| 315 | // next hops for next objectives |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 316 | |
| 317 | log.info("Deploying process : Establishing forward direction for pseudowire {}", l2TunnelId); |
| 318 | |
| 319 | // We establish the tunnel. |
| 320 | // result.nextId will be used in fwd |
| 321 | result = deployPseudoWireInit(pw.l2Tunnel(), |
| 322 | pw.l2TunnelPolicy().cP1(), |
| 323 | pw.l2TunnelPolicy().cP2(), |
| 324 | FWD, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 325 | fwdNextHop, |
| 326 | spinePw); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 327 | if (result != SUCCESS) { |
| 328 | log.info("Deploying process : Error in deploying pseudowire initiation for CP1"); |
| 329 | return Result.ADDITION_ERROR; |
| 330 | } |
| 331 | |
| 332 | VlanId egressVlan = determineEgressVlan(pw.l2TunnelPolicy().cP1OuterTag(), |
| 333 | pw.l2TunnelPolicy().cP1InnerTag(), |
| 334 | pw.l2TunnelPolicy().cP2OuterTag(), |
| 335 | pw.l2TunnelPolicy().cP2InnerTag()); |
| 336 | |
| 337 | // We create the policy. |
| 338 | result = deployPolicy(l2TunnelId, |
| 339 | pw.l2TunnelPolicy().cP1(), |
| 340 | pw.l2TunnelPolicy().cP1InnerTag(), |
| 341 | pw.l2TunnelPolicy().cP1OuterTag(), |
| 342 | egressVlan, |
| 343 | result.nextId); |
| 344 | if (result != SUCCESS) { |
| 345 | log.info("Deploying process : Error in deploying pseudowire policy for CP1"); |
| 346 | return Result.ADDITION_ERROR; |
| 347 | } |
| 348 | |
| 349 | // We terminate the tunnel |
| 350 | result = deployPseudoWireTerm(pw.l2Tunnel(), |
| 351 | pw.l2TunnelPolicy().cP2(), |
| 352 | pw.l2TunnelPolicy().cP2OuterTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 353 | FWD, |
| 354 | spinePw); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 355 | |
| 356 | if (result != SUCCESS) { |
| 357 | log.info("Deploying process : Error in deploying pseudowire termination for CP1"); |
| 358 | return Result.ADDITION_ERROR; |
| 359 | |
| 360 | } |
| 361 | |
| 362 | log.info("Deploying process : Establishing reverse direction for pseudowire {}", l2TunnelId); |
| 363 | |
| 364 | // We establish the reverse tunnel. |
| 365 | result = deployPseudoWireInit(pw.l2Tunnel(), |
| 366 | pw.l2TunnelPolicy().cP2(), |
| 367 | pw.l2TunnelPolicy().cP1(), |
| 368 | REV, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 369 | revNextHop, |
| 370 | spinePw); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 371 | if (result != SUCCESS) { |
| 372 | log.info("Deploying process : Error in deploying pseudowire initiation for CP2"); |
| 373 | return Result.ADDITION_ERROR; |
| 374 | } |
| 375 | |
| 376 | egressVlan = determineEgressVlan(pw.l2TunnelPolicy().cP2OuterTag(), |
| 377 | pw.l2TunnelPolicy().cP2InnerTag(), |
| 378 | pw.l2TunnelPolicy().cP1OuterTag(), |
| 379 | pw.l2TunnelPolicy().cP1InnerTag()); |
| 380 | result = deployPolicy(l2TunnelId, |
| 381 | pw.l2TunnelPolicy().cP2(), |
| 382 | pw.l2TunnelPolicy().cP2InnerTag(), |
| 383 | pw.l2TunnelPolicy().cP2OuterTag(), |
| 384 | egressVlan, |
| 385 | result.nextId); |
| 386 | if (result != SUCCESS) { |
| 387 | log.info("Deploying process : Error in deploying policy for CP2"); |
| 388 | return Result.ADDITION_ERROR; |
| 389 | } |
| 390 | |
| 391 | result = deployPseudoWireTerm(pw.l2Tunnel(), |
| 392 | pw.l2TunnelPolicy().cP1(), |
| 393 | pw.l2TunnelPolicy().cP1OuterTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 394 | REV, |
| 395 | spinePw); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 396 | |
| 397 | if (result != SUCCESS) { |
| 398 | log.info("Deploying process : Error in deploying pseudowire termination for CP2"); |
| 399 | return Result.ADDITION_ERROR; |
| 400 | } |
| 401 | |
| 402 | log.info("Deploying process : Updating relevant information for pseudowire {}", l2TunnelId); |
| 403 | |
| 404 | // Populate stores |
| 405 | l2TunnelStore.put(Long.toString(l2TunnelId), pw.l2Tunnel()); |
| 406 | l2PolicyStore.put(Long.toString(l2TunnelId), pw.l2TunnelPolicy()); |
| 407 | |
| 408 | return Result.SUCCESS; |
| 409 | } |
| 410 | |
| 411 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 412 | * To deploy a number of pseudo wires. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 413 | * <p> |
| 414 | * Called ONLY when configuration changes, thus the check |
| 415 | * for the mastership of the device. |
| 416 | * <p> |
| 417 | * Only the master of CP1 will deploy this pseudowire. |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 418 | * |
| 419 | * @param pwToAdd the set of pseudo wires to add |
| 420 | */ |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 421 | private void deploy(Set<DefaultL2TunnelDescription> pwToAdd) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 422 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 423 | Result result; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 424 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 425 | for (DefaultL2TunnelDescription currentL2Tunnel : pwToAdd) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 426 | ConnectPoint cp1 = currentL2Tunnel.l2TunnelPolicy().cP1(); |
| 427 | ConnectPoint cp2 = currentL2Tunnel.l2TunnelPolicy().cP2(); |
| 428 | long tunnelId = currentL2Tunnel.l2TunnelPolicy().tunnelId(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 429 | |
| 430 | // only the master of CP1 will program this pseudowire |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 431 | if (!srManager.isMasterOf(cp1)) { |
| 432 | log.debug("Not the master of {}. Ignore pseudo wire deployment id={}", cp1, tunnelId); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 433 | continue; |
| 434 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 435 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 436 | try { |
| 437 | // differentiate between leaf-leaf pseudowires and leaf-spine |
| 438 | // and pass the appropriate flag in them. |
| 439 | if (!srManager.deviceConfiguration().isEdgeDevice(cp1.deviceId()) && |
| 440 | !srManager.deviceConfiguration().isEdgeDevice(cp2.deviceId())) { |
| 441 | log.warn("Can not deploy pseudowire from spine to spine!"); |
| 442 | result = Result.INTERNAL_ERROR; |
| 443 | } else if (srManager.deviceConfiguration().isEdgeDevice(cp1.deviceId()) && |
| 444 | srManager.deviceConfiguration().isEdgeDevice(cp2.deviceId())) { |
| 445 | log.info("Deploying a leaf-leaf pseudowire {}", tunnelId); |
| 446 | result = deployPseudowire(currentL2Tunnel, false); |
| 447 | } else { |
| 448 | log.info("Deploying a leaf-spine pseudowire {}", tunnelId); |
| 449 | result = deployPseudowire(currentL2Tunnel, true); |
| 450 | } |
| 451 | } catch (DeviceConfigNotFoundException e) { |
| 452 | log.error("Exception caught when deploying pseudowire", e.toString()); |
| 453 | result = Result.INTERNAL_ERROR; |
| 454 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 455 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 456 | switch (result) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 457 | case INTERNAL_ERROR: |
| 458 | log.warn("Could not deploy pseudowire {}, internal error!", tunnelId); |
| 459 | break; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 460 | case WRONG_PARAMETERS: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 461 | log.warn("Could not deploy pseudowire {}, wrong parameters!", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 462 | break; |
| 463 | case ADDITION_ERROR: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 464 | log.warn("Could not deploy pseudowire {}, error in populating rules!", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 465 | break; |
| 466 | default: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 467 | log.info("Pseudowire with {} succesfully deployed!", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 468 | break; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 469 | } |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 470 | } |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 474 | * Processes PWaaS Config updated event. |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 475 | * |
| 476 | * @param event network config updated event |
| 477 | */ |
| 478 | public void processPwaasConfigUpdated(NetworkConfigEvent event) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 479 | checkArgument(event.config().isPresent(), |
| 480 | "Config is not presented in PwaasConfigUpdated event {}", event); |
| 481 | checkArgument(event.prevConfig().isPresent(), |
| 482 | "PrevConfig is not presented in PwaasConfigUpdated event {}", event); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 483 | |
| 484 | log.info("Pseudowire configuration updated."); |
| 485 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 486 | // We retrieve the old pseudo wires. |
| 487 | PwaasConfig prevConfig = (PwaasConfig) event.prevConfig().get(); |
| 488 | Set<Long> prevPws = prevConfig.getPwIds(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 489 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 490 | // We retrieve the new pseudo wires. |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 491 | PwaasConfig config = (PwaasConfig) event.config().get(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 492 | Set<Long> newPws = config.getPwIds(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 493 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 494 | // We compute the pseudo wires to update. |
| 495 | Set<Long> updPws = newPws.stream() |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 496 | .filter(tunnelId -> prevPws.contains(tunnelId) |
| 497 | && !config.getPwDescription(tunnelId).equals(prevConfig.getPwDescription(tunnelId))) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 498 | .collect(Collectors.toSet()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 499 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 500 | // The pseudo wires to remove. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 501 | Set<Long> rmvPWs = prevPws.stream() |
| 502 | .filter(tunnelId -> !newPws.contains(tunnelId)).collect(Collectors.toSet()); |
| 503 | |
| 504 | Set<DefaultL2TunnelDescription> pwToRemove = rmvPWs.stream() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 505 | .map(prevConfig::getPwDescription) |
| 506 | .collect(Collectors.toSet()); |
| 507 | tearDown(pwToRemove); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 508 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 509 | // The pseudo wires to add. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 510 | Set<Long> addedPWs = newPws.stream() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 511 | .filter(tunnelId -> !prevPws.contains(tunnelId)) |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 512 | .collect(Collectors.toSet()); |
| 513 | Set<DefaultL2TunnelDescription> pwToAdd = addedPWs.stream() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 514 | .map(config::getPwDescription) |
| 515 | .collect(Collectors.toSet()); |
| 516 | deploy(pwToAdd); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 517 | |
| 518 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 519 | // The pseudo wires to update. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 520 | updPws.forEach(tunnelId -> updatePw(prevConfig.getPwDescription(tunnelId), |
| 521 | config.getPwDescription(tunnelId))); |
| 522 | |
| 523 | log.info("Pseudowires removed : {}, Pseudowires updated : {}, Pseudowires added : {}", rmvPWs, |
| 524 | updPws, addedPWs); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Helper function to update a pw. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 529 | * <p> |
| 530 | * Called upon configuration changes that update existing pseudowires and |
| 531 | * when links fail. Checking of mastership for CP1 is mandatory because it is |
| 532 | * called in multiple instances for both cases. |
| 533 | * <p> |
| 534 | * Meant to call asynchronously for various events, thus this call can not block and need |
| 535 | * to perform asynchronous operations. |
| 536 | * <p> |
| 537 | * For this reason error checking is omitted. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 538 | * |
| 539 | * @param oldPw the pseudo wire to remove |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 540 | * @param newPw the pseudo wire to add |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 541 | */ |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 542 | private void updatePw(DefaultL2TunnelDescription oldPw, |
| 543 | DefaultL2TunnelDescription newPw) { |
| 544 | ConnectPoint oldCp1 = oldPw.l2TunnelPolicy().cP1(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 545 | long tunnelId = oldPw.l2Tunnel().tunnelId(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 546 | |
| 547 | // only the master of CP1 will update this pseudowire |
| 548 | if (!srManager.isMasterOf(oldPw.l2TunnelPolicy().cP1())) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 549 | log.debug("Not the master of {}. Ignore pseudo wire update id={}", oldCp1, tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 550 | return; |
| 551 | } |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 552 | // only determine if the new pseudowire is leaf-spine, because |
| 553 | // removal process is the same for both leaf-leaf and leaf-spine |
| 554 | // pws. |
| 555 | boolean newPwSpine; |
| 556 | try { |
| 557 | newPwSpine = !srManager.deviceConfiguration().isEdgeDevice(newPw.l2TunnelPolicy().cP1().deviceId()) || |
| 558 | !srManager.deviceConfiguration().isEdgeDevice(newPw.l2TunnelPolicy().cP2().deviceId()); |
| 559 | } catch (DeviceConfigNotFoundException e) { |
| 560 | // if exception is caught treat the newpw as leaf-leaf |
| 561 | newPwSpine = false; |
| 562 | } |
| 563 | |
| 564 | // copy the variable here because we need to |
| 565 | // use it in lambda thus it needs to be final |
| 566 | boolean finalNewPwSpine = newPwSpine; |
| 567 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 568 | |
| 569 | log.info("Updating pseudowire {}", oldPw.l2Tunnel().tunnelId()); |
| 570 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 571 | // The async tasks to orchestrate the next and |
| 572 | // forwarding update. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 573 | CompletableFuture<ObjectiveError> fwdInitNextFuture = new CompletableFuture<>(); |
| 574 | CompletableFuture<ObjectiveError> revInitNextFuture = new CompletableFuture<>(); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 575 | CompletableFuture<ObjectiveError> fwdTermNextFuture = new CompletableFuture<>(); |
| 576 | CompletableFuture<ObjectiveError> revTermNextFuture = new CompletableFuture<>(); |
| 577 | CompletableFuture<ObjectiveError> fwdPwFuture = new CompletableFuture<>(); |
| 578 | CompletableFuture<ObjectiveError> revPwFuture = new CompletableFuture<>(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 579 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 580 | // First we remove both policy. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 581 | log.debug("Start deleting fwd policy for {}", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 582 | |
| 583 | // first delete all information from our stores |
| 584 | // we can not do it asynchronously |
| 585 | l2PolicyStore.remove(Long.toString(tunnelId)); |
| 586 | l2TunnelStore.remove(Long.toString(tunnelId)); |
| 587 | |
| 588 | VlanId egressVlan = determineEgressVlan(oldPw.l2TunnelPolicy().cP1OuterTag(), |
| 589 | oldPw.l2TunnelPolicy().cP1InnerTag(), |
| 590 | oldPw.l2TunnelPolicy().cP2OuterTag(), |
| 591 | oldPw.l2TunnelPolicy().cP2InnerTag()); |
| 592 | deletePolicy(tunnelId, |
| 593 | oldPw.l2TunnelPolicy().cP1(), |
| 594 | oldPw.l2TunnelPolicy().cP1InnerTag(), |
| 595 | oldPw.l2TunnelPolicy().cP1OuterTag(), |
| 596 | egressVlan, |
| 597 | fwdInitNextFuture, |
| 598 | FWD); |
| 599 | |
| 600 | log.debug("Update process : Start deleting rev policy for {}", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 601 | egressVlan = determineEgressVlan(oldPw.l2TunnelPolicy().cP2OuterTag(), |
| 602 | oldPw.l2TunnelPolicy().cP2InnerTag(), |
| 603 | oldPw.l2TunnelPolicy().cP1OuterTag(), |
| 604 | oldPw.l2TunnelPolicy().cP1InnerTag()); |
| 605 | deletePolicy(tunnelId, |
| 606 | oldPw.l2TunnelPolicy().cP2(), |
| 607 | oldPw.l2TunnelPolicy().cP2InnerTag(), |
| 608 | oldPw.l2TunnelPolicy().cP2OuterTag(), |
| 609 | egressVlan, revInitNextFuture, |
| 610 | REV); |
| 611 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 612 | // Finally we remove both the tunnels. |
| 613 | fwdInitNextFuture.thenAcceptAsync(status -> { |
| 614 | if (status == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 615 | log.debug("Update process : Fwd policy removed. " + |
| 616 | "Now remove fwd {} for {}", INITIATION, tunnelId); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 617 | tearDownPseudoWireInit(tunnelId, oldPw.l2TunnelPolicy().cP1(), fwdTermNextFuture, FWD); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 618 | } |
| 619 | }); |
| 620 | revInitNextFuture.thenAcceptAsync(status -> { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 621 | if (status == null) { |
| 622 | log.debug("Update process : Rev policy removed. " + |
| 623 | "Now remove rev {} for {}", INITIATION, tunnelId); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 624 | tearDownPseudoWireInit(tunnelId, oldPw.l2TunnelPolicy().cP2(), revTermNextFuture, REV); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 625 | } |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 626 | }); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 627 | fwdTermNextFuture.thenAcceptAsync(status -> { |
| 628 | if (status == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 629 | log.debug("Update process : Fwd {} removed. " + |
| 630 | "Now remove fwd {} for {}", INITIATION, TERMINATION, tunnelId); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 631 | tearDownPseudoWireTerm(oldPw.l2Tunnel(), oldPw.l2TunnelPolicy().cP2(), fwdPwFuture, FWD); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 632 | } |
| 633 | }); |
| 634 | revTermNextFuture.thenAcceptAsync(status -> { |
| 635 | if (status == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 636 | log.debug("Update process : Rev {} removed. " + |
| 637 | "Now remove rev {} for {}", INITIATION, TERMINATION, tunnelId); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 638 | tearDownPseudoWireTerm(oldPw.l2Tunnel(), oldPw.l2TunnelPolicy().cP1(), revPwFuture, REV); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 639 | } |
| 640 | }); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 641 | |
| 642 | // get path here, need to use the same for fwd and rev direction |
| 643 | List<Link> path = getPath(newPw.l2TunnelPolicy().cP1(), |
| 644 | newPw.l2TunnelPolicy().cP2()); |
| 645 | if (path == null) { |
| 646 | log.info("Deploying process : " + |
| 647 | "No path between the connection points for pseudowire {}", newPw.l2Tunnel().tunnelId()); |
| 648 | return; |
| 649 | } |
| 650 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 651 | Link fwdNextHop, revNextHop; |
| 652 | if (!finalNewPwSpine) { |
| 653 | if (path.size() != 2) { |
| 654 | log.info("Update process : Error, path between two leafs should have size of 2, for pseudowire {}", |
| 655 | newPw.l2Tunnel().tunnelId()); |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | fwdNextHop = path.get(0); |
| 660 | revNextHop = reverseLink(path.get(1)); |
| 661 | } else { |
| 662 | if (path.size() != 1) { |
Charles Chan | e5a3255 | 2018-01-06 17:57:27 -0800 | [diff] [blame^] | 663 | log.info("Update process : Error, path between leaf spine should equal to 1, for pseudowire {}", |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 664 | newPw.l2Tunnel().tunnelId()); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | fwdNextHop = path.get(0); |
| 669 | revNextHop = reverseLink(path.get(0)); |
| 670 | } |
| 671 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 672 | newPw.l2Tunnel().setPath(path); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 673 | |
| 674 | // At the end we install the updated PW. |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 675 | fwdPwFuture.thenAcceptAsync(status -> { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 676 | if (status == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 677 | |
| 678 | // Upgrade stores and book keeping information, need to move this here |
| 679 | // cause this call is asynchronous. |
| 680 | l2PolicyStore.put(Long.toString(tunnelId), newPw.l2TunnelPolicy()); |
| 681 | l2TunnelStore.put(Long.toString(tunnelId), newPw.l2Tunnel()); |
| 682 | |
| 683 | log.debug("Update process : Deploying new fwd pw for {}", tunnelId); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 684 | Result lamdaResult = deployPseudoWireInit(newPw.l2Tunnel(), newPw.l2TunnelPolicy().cP1(), |
| 685 | newPw.l2TunnelPolicy().cP2(), FWD, |
| 686 | fwdNextHop, finalNewPwSpine); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 687 | if (lamdaResult != SUCCESS) { |
| 688 | return; |
| 689 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 690 | |
| 691 | VlanId egressVlanId = determineEgressVlan(newPw.l2TunnelPolicy().cP1OuterTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 692 | newPw.l2TunnelPolicy().cP1InnerTag(), |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 693 | newPw.l2TunnelPolicy().cP2OuterTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 694 | newPw.l2TunnelPolicy().cP2InnerTag()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 695 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 696 | lamdaResult = deployPolicy(tunnelId, newPw.l2TunnelPolicy().cP1(), |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 697 | newPw.l2TunnelPolicy().cP1InnerTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 698 | newPw.l2TunnelPolicy().cP1OuterTag(), |
| 699 | egressVlanId, lamdaResult.nextId); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 700 | if (lamdaResult != SUCCESS) { |
| 701 | return; |
| 702 | } |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 703 | deployPseudoWireTerm(newPw.l2Tunnel(), newPw.l2TunnelPolicy().cP2(), |
| 704 | newPw.l2TunnelPolicy().cP2OuterTag(), FWD, finalNewPwSpine); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 705 | |
| 706 | } |
| 707 | }); |
| 708 | revPwFuture.thenAcceptAsync(status -> { |
| 709 | if (status == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 710 | log.debug("Update process : Deploying new rev pw for {}", tunnelId); |
| 711 | Result lamdaResult = deployPseudoWireInit(newPw.l2Tunnel(), |
| 712 | newPw.l2TunnelPolicy().cP2(), |
| 713 | newPw.l2TunnelPolicy().cP1(), |
| 714 | REV, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 715 | revNextHop, finalNewPwSpine); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 716 | if (lamdaResult != SUCCESS) { |
| 717 | return; |
| 718 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 719 | |
| 720 | VlanId egressVlanId = determineEgressVlan(newPw.l2TunnelPolicy().cP2OuterTag(), |
| 721 | newPw.l2TunnelPolicy().cP2InnerTag(), |
| 722 | newPw.l2TunnelPolicy().cP1OuterTag(), |
| 723 | newPw.l2TunnelPolicy().cP1InnerTag()); |
| 724 | lamdaResult = deployPolicy(tunnelId, |
| 725 | newPw.l2TunnelPolicy().cP2(), |
| 726 | newPw.l2TunnelPolicy().cP2InnerTag(), |
| 727 | newPw.l2TunnelPolicy().cP2OuterTag(), |
| 728 | egressVlanId, |
| 729 | lamdaResult.nextId); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 730 | if (lamdaResult != SUCCESS) { |
| 731 | return; |
| 732 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 733 | deployPseudoWireTerm(newPw.l2Tunnel(), |
| 734 | newPw.l2TunnelPolicy().cP1(), |
| 735 | newPw.l2TunnelPolicy().cP1OuterTag(), |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 736 | REV, finalNewPwSpine); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 737 | } |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 738 | }); |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Processes Pwaas Config removed event. |
| 743 | * |
| 744 | * @param event network config removed event |
| 745 | */ |
| 746 | public void processPwaasConfigRemoved(NetworkConfigEvent event) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 747 | checkArgument(event.prevConfig().isPresent(), |
| 748 | "PrevConfig is not presented in PwaasConfigRemoved event {}", event); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 749 | |
| 750 | log.info("Network event : Pseudowire configuration removed!"); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 751 | PwaasConfig config = (PwaasConfig) event.prevConfig().get(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 752 | |
| 753 | Set<DefaultL2TunnelDescription> pwToRemove = config |
| 754 | .getPwIds() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 755 | .stream() |
| 756 | .map(config::getPwDescription) |
| 757 | .collect(Collectors.toSet()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 758 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 759 | // We teardown all the pseudo wire deployed |
| 760 | tearDown(pwToRemove); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 761 | } |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 762 | |
| 763 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 764 | * Helper function for removing a single pseudowire. |
| 765 | * <p> |
| 766 | * No mastership of CP1 is checked, because it can be called from |
| 767 | * the CLI for removal of pseudowires. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 768 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 769 | * @param l2TunnelId the id of the pseudowire to tear down |
| 770 | * @return Returns SUCCESS if no error is obeserved or an appropriate |
| 771 | * error on a failure |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 772 | */ |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 773 | private Result tearDownPseudowire(long l2TunnelId) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 774 | |
| 775 | CompletableFuture<ObjectiveError> fwdInitNextFuture = new CompletableFuture<>(); |
| 776 | CompletableFuture<ObjectiveError> fwdTermNextFuture = new CompletableFuture<>(); |
| 777 | |
| 778 | CompletableFuture<ObjectiveError> revInitNextFuture = new CompletableFuture<>(); |
| 779 | CompletableFuture<ObjectiveError> revTermNextFuture = new CompletableFuture<>(); |
| 780 | |
| 781 | if (l2TunnelId == 0) { |
| 782 | log.warn("Removal process : Tunnel id cannot be 0"); |
| 783 | return Result.WRONG_PARAMETERS; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 786 | // check existence of tunnels/policy in the store, if one is missing abort! |
| 787 | Versioned<DefaultL2Tunnel> l2TunnelVersioned = l2TunnelStore.get(Long.toString(l2TunnelId)); |
| 788 | Versioned<DefaultL2TunnelPolicy> l2TunnelPolicyVersioned = l2PolicyStore.get(Long.toString(l2TunnelId)); |
| 789 | if ((l2TunnelVersioned == null) || (l2TunnelPolicyVersioned == null)) { |
| 790 | log.warn("Removal process : Policy and/or tunnel missing for tunnel id {}", l2TunnelId); |
| 791 | return Result.REMOVAL_ERROR; |
| 792 | } |
| 793 | |
| 794 | DefaultL2TunnelDescription pwToRemove = new DefaultL2TunnelDescription(l2TunnelVersioned.value(), |
| 795 | l2TunnelPolicyVersioned.value()); |
| 796 | |
| 797 | // remove the tunnels and the policies from the store |
| 798 | l2PolicyStore.remove(Long.toString(l2TunnelId)); |
| 799 | l2TunnelStore.remove(Long.toString(l2TunnelId)); |
| 800 | |
| 801 | log.info("Removal process : Tearing down forward direction of pseudowire {}", l2TunnelId); |
| 802 | |
| 803 | VlanId egressVlan = determineEgressVlan(pwToRemove.l2TunnelPolicy().cP1OuterTag(), |
| 804 | pwToRemove.l2TunnelPolicy().cP1InnerTag(), |
| 805 | pwToRemove.l2TunnelPolicy().cP2OuterTag(), |
| 806 | pwToRemove.l2TunnelPolicy().cP2InnerTag()); |
| 807 | deletePolicy(l2TunnelId, |
| 808 | pwToRemove.l2TunnelPolicy().cP1(), |
| 809 | pwToRemove.l2TunnelPolicy().cP1InnerTag(), |
| 810 | pwToRemove.l2TunnelPolicy().cP1OuterTag(), |
| 811 | egressVlan, |
| 812 | fwdInitNextFuture, |
| 813 | FWD); |
| 814 | |
| 815 | fwdInitNextFuture.thenAcceptAsync(status -> { |
| 816 | if (status == null) { |
| 817 | // Finally we will tear down the pseudo wire. |
| 818 | tearDownPseudoWireInit(l2TunnelId, |
| 819 | pwToRemove.l2TunnelPolicy().cP1(), |
| 820 | fwdTermNextFuture, |
| 821 | FWD); |
| 822 | } |
| 823 | }); |
| 824 | |
| 825 | fwdTermNextFuture.thenAcceptAsync(status -> { |
| 826 | if (status == null) { |
| 827 | tearDownPseudoWireTerm(pwToRemove.l2Tunnel(), |
| 828 | pwToRemove.l2TunnelPolicy().cP2(), |
| 829 | null, |
| 830 | FWD); |
| 831 | } |
| 832 | }); |
| 833 | |
| 834 | log.info("Removal process : Tearing down reverse direction of pseudowire {}", l2TunnelId); |
| 835 | |
| 836 | egressVlan = determineEgressVlan(pwToRemove.l2TunnelPolicy().cP2OuterTag(), |
| 837 | pwToRemove.l2TunnelPolicy().cP2InnerTag(), |
| 838 | pwToRemove.l2TunnelPolicy().cP1OuterTag(), |
| 839 | pwToRemove.l2TunnelPolicy().cP1InnerTag()); |
| 840 | |
| 841 | // We do the same operations on the reverse side. |
| 842 | deletePolicy(l2TunnelId, |
| 843 | pwToRemove.l2TunnelPolicy().cP2(), |
| 844 | pwToRemove.l2TunnelPolicy().cP2InnerTag(), |
| 845 | pwToRemove.l2TunnelPolicy().cP2OuterTag(), |
| 846 | egressVlan, |
| 847 | revInitNextFuture, |
| 848 | REV); |
| 849 | |
| 850 | revInitNextFuture.thenAcceptAsync(status -> { |
| 851 | if (status == null) { |
| 852 | tearDownPseudoWireInit(l2TunnelId, |
| 853 | pwToRemove.l2TunnelPolicy().cP2(), |
| 854 | revTermNextFuture, |
| 855 | REV); |
| 856 | } |
| 857 | }); |
| 858 | |
| 859 | revTermNextFuture.thenAcceptAsync(status -> { |
| 860 | if (status == null) { |
| 861 | tearDownPseudoWireTerm(pwToRemove.l2Tunnel(), |
| 862 | pwToRemove.l2TunnelPolicy().cP1(), |
| 863 | null, |
| 864 | REV); |
| 865 | } |
| 866 | }); |
| 867 | |
| 868 | return Result.SUCCESS; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 872 | * Helper function to handle the pw removal. |
| 873 | * <p> |
| 874 | * This method checks for the mastership of the device because it is |
| 875 | * used only from network configuration updates, thus we only want |
| 876 | * one instance only to program each pseudowire. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 877 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 878 | * @param pwToRemove the pseudo wires to remove |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 879 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 880 | public void tearDown(Set<DefaultL2TunnelDescription> pwToRemove) { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 881 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 882 | Result result; |
| 883 | |
| 884 | // We remove all the pw in the configuration file. |
| 885 | for (DefaultL2TunnelDescription currentL2Tunnel : pwToRemove) { |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 886 | ConnectPoint cp1 = currentL2Tunnel.l2TunnelPolicy().cP1(); |
| 887 | ConnectPoint cp2 = currentL2Tunnel.l2TunnelPolicy().cP2(); |
| 888 | long tunnelId = currentL2Tunnel.l2TunnelPolicy().tunnelId(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 889 | |
| 890 | // only the master of CP1 will program this pseudowire |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 891 | if (!srManager.isMasterOf(cp1)) { |
| 892 | log.debug("Not the master of {}. Ignore pseudo wire removal id={}", cp1, tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 893 | continue; |
| 894 | } |
| 895 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 896 | // no need to differentiate here between leaf-leaf and leaf-spine, because |
| 897 | // the only change is in the groups, which we do not remove either way |
| 898 | log.info("Removing pseudowire {}", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 899 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 900 | result = tearDownPseudowire(tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 901 | switch (result) { |
| 902 | case WRONG_PARAMETERS: |
| 903 | log.warn("Error in supplied parameters for the pseudowire removal with tunnel id {}!", |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 904 | tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 905 | break; |
| 906 | case REMOVAL_ERROR: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 907 | log.warn("Error in pseudowire removal with tunnel id {}!", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 908 | break; |
| 909 | default: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 910 | log.warn("Pseudowire with tunnel id {} was removed successfully", tunnelId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 911 | } |
| 912 | } |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /** |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 916 | * Handles the policy establishment which consists in |
| 917 | * create the filtering and forwarding objectives related |
| 918 | * to the initiation and termination. |
| 919 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 920 | * @param tunnelId the tunnel id |
| 921 | * @param ingress the ingress point |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 922 | * @param ingressInner the ingress inner tag |
| 923 | * @param ingressOuter the ingress outer tag |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 924 | * @param nextId the next objective id |
| 925 | * @param egressVlan Vlan-id to set, depends on ingress vlan |
| 926 | * combinations. For example, if pw is double tagged |
| 927 | * then this is the value of the outer vlan, if single |
| 928 | * tagged then it is the new value of the single tag. |
| 929 | * Should be None for untagged traffic. |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 930 | * @return the result of the operation |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 931 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 932 | private Result deployPolicy(long tunnelId, ConnectPoint ingress, VlanId ingressInner, |
| 933 | VlanId ingressOuter, VlanId egressVlan, int nextId) { |
| 934 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 935 | List<Objective> objectives = Lists.newArrayList(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 936 | // We create the forwarding objective for supporting |
| 937 | // the l2 tunnel. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 938 | ForwardingObjective.Builder fwdBuilder = createInitFwdObjective(tunnelId, ingress.port(), nextId); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 939 | // We create and add objective context. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 940 | ObjectiveContext context = new DefaultObjectiveContext((objective) -> |
| 941 | log.debug("FwdObj for tunnel {} populated", tunnelId), |
| 942 | (objective, error) -> |
| 943 | log.warn("Failed to populate fwdrObj " + |
| 944 | "for tunnel {}", tunnelId, error)); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 945 | objectives.add(fwdBuilder.add(context)); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 946 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 947 | // We create the filtering objective to define the |
| 948 | // permit traffic in the switch |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 949 | FilteringObjective.Builder filtBuilder = createFiltObjective(ingress.port(), ingressInner, ingressOuter); |
| 950 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 951 | // We add the metadata. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 952 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 953 | .builder() |
| 954 | .setTunnelId(tunnelId) |
| 955 | .setVlanId(egressVlan); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 956 | filtBuilder.withMeta(treatment.build()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 957 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 958 | // We create and add objective context. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 959 | context = new DefaultObjectiveContext((objective) -> log.debug("FilterObj for tunnel {} populated", tunnelId), |
| 960 | (objective, error) -> log.warn("Failed to populate filterObj for " + |
| 961 | "tunnel {}", tunnelId, error)); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 962 | objectives.add(filtBuilder.add(context)); |
| 963 | |
| 964 | for (Objective objective : objectives) { |
| 965 | if (objective instanceof ForwardingObjective) { |
| 966 | srManager.flowObjectiveService.forward(ingress.deviceId(), (ForwardingObjective) objective); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 967 | log.debug("Creating new FwdObj for initiation NextObj with id={} for tunnel {}", nextId, tunnelId); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 968 | } else { |
| 969 | srManager.flowObjectiveService.filter(ingress.deviceId(), (FilteringObjective) objective); |
| 970 | log.debug("Creating new FiltObj for tunnel {}", tunnelId); |
| 971 | } |
| 972 | } |
| 973 | return SUCCESS; |
| 974 | } |
| 975 | |
| 976 | /** |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 977 | * Handles the tunnel establishment which consists in |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 978 | * create the next objectives related to the initiation. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 979 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 980 | * @param l2Tunnel the tunnel to deploy |
| 981 | * @param ingress the ingress connect point |
| 982 | * @param egress the egress connect point |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 983 | * @param direction the direction of the pw |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 984 | * @param spinePw if the pseudowire involves a spine switch |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 985 | * @return the result of the operation |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 986 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 987 | private Result deployPseudoWireInit(DefaultL2Tunnel l2Tunnel, ConnectPoint ingress, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 988 | ConnectPoint egress, Direction direction, Link nextHop, boolean spinePw) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 989 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 990 | if (nextHop == null) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 991 | log.warn("No path between ingress and egress cps for tunnel {}", l2Tunnel.tunnelId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 992 | return WRONG_PARAMETERS; |
| 993 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 994 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 995 | // We create the next objective without the metadata |
| 996 | // context and id. We check if it already exists in the |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 997 | // store. If not we store as it is in the store. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 998 | NextObjective.Builder nextObjectiveBuilder = createNextObjective(INITIATION, |
| 999 | nextHop.src(), |
| 1000 | nextHop.dst(), |
| 1001 | l2Tunnel, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1002 | egress.deviceId(), |
| 1003 | spinePw); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1004 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1005 | if (nextObjectiveBuilder == null) { |
| 1006 | return INTERNAL_ERROR; |
| 1007 | } |
| 1008 | // We set the metadata. We will use this metadata |
| 1009 | // to inform the driver we are doing a l2 tunnel. |
| 1010 | TrafficSelector metadata = DefaultTrafficSelector |
| 1011 | .builder() |
| 1012 | .matchTunnelId(l2Tunnel.tunnelId()) |
| 1013 | .build(); |
| 1014 | nextObjectiveBuilder.withMeta(metadata); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1015 | int nextId = srManager.flowObjectiveService.allocateNextId(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1016 | if (nextId < 0) { |
| 1017 | log.warn("Not able to allocate a next id for initiation"); |
| 1018 | return INTERNAL_ERROR; |
| 1019 | } |
| 1020 | nextObjectiveBuilder.withId(nextId); |
| 1021 | String key = generateKey(l2Tunnel.tunnelId(), direction); |
| 1022 | l2InitiationNextObjStore.put(key, nextObjectiveBuilder.add()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1023 | ObjectiveContext context = new DefaultObjectiveContext((objective) -> |
| 1024 | log.debug("Initiation l2 tunnel rule " + |
| 1025 | "for {} populated", |
| 1026 | l2Tunnel.tunnelId()), |
| 1027 | (objective, error) -> |
| 1028 | log.warn("Failed to populate Initiation " + |
| 1029 | "l2 tunnel rule for {}: {}", |
| 1030 | l2Tunnel.tunnelId(), error)); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1031 | NextObjective nextObjective = nextObjectiveBuilder.add(context); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1032 | srManager.flowObjectiveService.next(ingress.deviceId(), nextObjective); |
| 1033 | log.debug("Initiation next objective for {} not found. Creating new NextObj with id={}", |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1034 | l2Tunnel.tunnelId(), nextObjective.id()); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1035 | Result result = SUCCESS; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1036 | result.nextId = nextObjective.id(); |
| 1037 | return result; |
| 1038 | } |
| 1039 | |
| 1040 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1041 | * Handles the tunnel termination, which consists in the creation |
| 1042 | * of a forwarding objective and a next objective. |
| 1043 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1044 | * @param l2Tunnel the tunnel to terminate |
| 1045 | * @param egress the egress point |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1046 | * @param egressVlan the expected vlan at egress |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1047 | * @param direction the direction |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1048 | * @param spinePw if the pseudowire involves a spine switch |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1049 | * @return the result of the operation |
| 1050 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1051 | private Result deployPseudoWireTerm(DefaultL2Tunnel l2Tunnel, ConnectPoint egress, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1052 | VlanId egressVlan, Direction direction, boolean spinePw) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1053 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1054 | // We create the group relative to the termination. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1055 | NextObjective.Builder nextObjectiveBuilder = createNextObjective(TERMINATION, egress, null, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1056 | null, egress.deviceId(), |
| 1057 | spinePw); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1058 | if (nextObjectiveBuilder == null) { |
| 1059 | return INTERNAL_ERROR; |
| 1060 | } |
| 1061 | TrafficSelector metadata = DefaultTrafficSelector |
| 1062 | .builder() |
| 1063 | .matchVlanId(egressVlan) |
| 1064 | .build(); |
| 1065 | nextObjectiveBuilder.withMeta(metadata); |
| 1066 | int nextId = srManager.flowObjectiveService.allocateNextId(); |
| 1067 | if (nextId < 0) { |
| 1068 | log.warn("Not able to allocate a next id for initiation"); |
| 1069 | return INTERNAL_ERROR; |
| 1070 | } |
| 1071 | nextObjectiveBuilder.withId(nextId); |
| 1072 | String key = generateKey(l2Tunnel.tunnelId(), direction); |
| 1073 | l2TerminationNextObjStore.put(key, nextObjectiveBuilder.add()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1074 | ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Termination l2 tunnel rule " + |
| 1075 | "for {} populated", |
| 1076 | l2Tunnel.tunnelId()), |
| 1077 | (objective, error) -> log.warn("Failed to populate " + |
| 1078 | "termination l2 tunnel " + |
| 1079 | "rule for {}: {}", |
| 1080 | l2Tunnel.tunnelId(), |
| 1081 | error)); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1082 | NextObjective nextObjective = nextObjectiveBuilder.add(context); |
| 1083 | srManager.flowObjectiveService.next(egress.deviceId(), nextObjective); |
| 1084 | log.debug("Termination next objective for {} not found. Creating new NextObj with id={}", |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1085 | l2Tunnel.tunnelId(), nextObjective.id()); |
| 1086 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1087 | // We create the flow relative to the termination. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1088 | ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), l2Tunnel.tunnelId(), |
| 1089 | egress.port(), nextObjective.id()); |
| 1090 | context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel termination {} populated", |
| 1091 | l2Tunnel.tunnelId()), |
| 1092 | (objective, error) -> log.warn("Failed to populate fwdrObj" + |
| 1093 | " for tunnel termination {}", |
| 1094 | l2Tunnel.tunnelId(), error)); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1095 | srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.add(context)); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1096 | log.debug("Creating new FwdObj for termination NextObj with id={} for tunnel {}", |
| 1097 | nextId, l2Tunnel.tunnelId()); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1098 | return SUCCESS; |
| 1099 | |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1103 | * Creates the filtering objective according to a given policy. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1104 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1105 | * @param inPort the in port |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1106 | * @param innerTag the inner vlan tag |
| 1107 | * @param outerTag the outer vlan tag |
| 1108 | * @return the filtering objective |
| 1109 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1110 | private FilteringObjective.Builder createFiltObjective(PortNumber inPort, VlanId innerTag, VlanId outerTag) { |
| 1111 | |
| 1112 | log.info("Creating filtering objective for vlans {} / {}", outerTag, innerTag); |
| 1113 | return DefaultFilteringObjective |
| 1114 | .builder() |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1115 | .withKey(Criteria.matchInPort(inPort)) |
| 1116 | .addCondition(Criteria.matchInnerVlanId(innerTag)) |
| 1117 | .addCondition(Criteria.matchVlanId(outerTag)) |
| 1118 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY) |
| 1119 | .permit() |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1120 | .fromApp(srManager.appId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1124 | * Creates the forwarding objective for the termination. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1125 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1126 | * @param pwLabel the pseudo wire label |
| 1127 | * @param tunnelId the tunnel id |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1128 | * @param egressPort the egress port |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1129 | * @param nextId the next step |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1130 | * @return the forwarding objective to support the termination |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1131 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1132 | private ForwardingObjective.Builder createTermFwdObjective(MplsLabel pwLabel, long tunnelId, |
| 1133 | PortNumber egressPort, int nextId) { |
| 1134 | |
| 1135 | TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder(); |
| 1136 | TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder(); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1137 | // The flow has to match on the pw label and bos |
| 1138 | trafficSelector.matchEthType(Ethernet.MPLS_UNICAST); |
| 1139 | trafficSelector.matchMplsLabel(pwLabel); |
| 1140 | trafficSelector.matchMplsBos(true); |
| 1141 | // The flow has to decrement ttl, restore ttl in |
| 1142 | // pop mpls, set tunnel id and port. |
| 1143 | trafficTreatment.decMplsTtl(); |
| 1144 | trafficTreatment.copyTtlIn(); |
| 1145 | trafficTreatment.popMpls(); |
| 1146 | trafficTreatment.setTunnelId(tunnelId); |
| 1147 | trafficTreatment.setOutput(egressPort); |
| 1148 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1149 | return DefaultForwardingObjective |
| 1150 | .builder() |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1151 | .fromApp(srManager.appId()) |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1152 | .makePermanent() |
| 1153 | .nextStep(nextId) |
| 1154 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY) |
| 1155 | .withSelector(trafficSelector.build()) |
| 1156 | .withTreatment(trafficTreatment.build()) |
| 1157 | .withFlag(VERSATILE); |
| 1158 | } |
| 1159 | |
| 1160 | /** |
| 1161 | * Creates the forwarding objective for the initiation. |
| 1162 | * |
| 1163 | * @param tunnelId the tunnel id |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1164 | * @param inPort the input port |
| 1165 | * @param nextId the next step |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1166 | * @return the forwarding objective to support the initiation. |
| 1167 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1168 | private ForwardingObjective.Builder createInitFwdObjective(long tunnelId, PortNumber inPort, int nextId) { |
| 1169 | |
| 1170 | TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder(); |
| 1171 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1172 | // The flow has to match on the mpls logical |
| 1173 | // port and the tunnel id. |
| 1174 | trafficSelector.matchTunnelId(tunnelId); |
| 1175 | trafficSelector.matchInPort(inPort); |
| 1176 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1177 | return DefaultForwardingObjective |
| 1178 | .builder() |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1179 | .fromApp(srManager.appId()) |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1180 | .makePermanent() |
| 1181 | .nextStep(nextId) |
| 1182 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY) |
| 1183 | .withSelector(trafficSelector.build()) |
| 1184 | .withFlag(VERSATILE); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1185 | |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * Creates the next objective according to a given |
| 1190 | * pipeline. We don't set the next id and we don't |
| 1191 | * create the final meta to check if we are re-using |
| 1192 | * the same next objective for different tunnels. |
| 1193 | * |
| 1194 | * @param pipeline the pipeline to support |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1195 | * @param srcCp the source port |
| 1196 | * @param dstCp the destination port |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1197 | * @param l2Tunnel the tunnel to support |
| 1198 | * @param egressId the egress device id |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1199 | * @param spinePw if the pw involves a spine switch |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1200 | * @return the next objective to support the pipeline |
| 1201 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1202 | private NextObjective.Builder createNextObjective(Pipeline pipeline, ConnectPoint srcCp, |
| 1203 | ConnectPoint dstCp, DefaultL2Tunnel l2Tunnel, |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1204 | DeviceId egressId, boolean spinePw) { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1205 | NextObjective.Builder nextObjBuilder; |
| 1206 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1207 | if (pipeline == INITIATION) { |
| 1208 | nextObjBuilder = DefaultNextObjective |
| 1209 | .builder() |
| 1210 | .withType(NextObjective.Type.SIMPLE) |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1211 | .fromApp(srManager.appId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1212 | // The pw label is the bottom of stack. It has to |
| 1213 | // be different -1. |
| 1214 | if (l2Tunnel.pwLabel().toInt() == MplsLabel.MAX_MPLS) { |
| 1215 | log.warn("Pw label not configured"); |
| 1216 | return null; |
| 1217 | } |
| 1218 | treatmentBuilder.pushMpls(); |
| 1219 | treatmentBuilder.setMpls(l2Tunnel.pwLabel()); |
| 1220 | treatmentBuilder.setMplsBos(true); |
| 1221 | treatmentBuilder.copyTtlOut(); |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1222 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1223 | // If the inter-co label is present we have to set the label. |
| 1224 | if (l2Tunnel.interCoLabel().toInt() != MplsLabel.MAX_MPLS) { |
| 1225 | treatmentBuilder.pushMpls(); |
| 1226 | treatmentBuilder.setMpls(l2Tunnel.interCoLabel()); |
| 1227 | treatmentBuilder.setMplsBos(false); |
| 1228 | treatmentBuilder.copyTtlOut(); |
| 1229 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1230 | |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1231 | // if pw is leaf-to-leaf we need to |
| 1232 | // add the routing label also |
| 1233 | if (!spinePw) { |
| 1234 | // We retrieve the sr label from the config |
| 1235 | // specific for pseudowire traffic |
| 1236 | // using the egress leaf device id. |
| 1237 | MplsLabel srLabel; |
| 1238 | try { |
| 1239 | srLabel = MplsLabel.mplsLabel(srManager.deviceConfiguration().getPWRoutingLabel(egressId)); |
| 1240 | |
| 1241 | } catch (DeviceConfigNotFoundException e) { |
| 1242 | log.warn("Sr label for pw traffic not configured"); |
| 1243 | return null; |
| 1244 | } |
| 1245 | |
| 1246 | treatmentBuilder.pushMpls(); |
| 1247 | treatmentBuilder.setMpls(srLabel); |
| 1248 | treatmentBuilder.setMplsBos(false); |
| 1249 | treatmentBuilder.copyTtlOut(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1250 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1251 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1252 | // We have to rewrite the src and dst mac address. |
| 1253 | MacAddress ingressMac; |
| 1254 | try { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1255 | ingressMac = srManager.deviceConfiguration().getDeviceMac(srcCp.deviceId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1256 | } catch (DeviceConfigNotFoundException e) { |
| 1257 | log.warn("Was not able to find the ingress mac"); |
| 1258 | return null; |
| 1259 | } |
| 1260 | treatmentBuilder.setEthSrc(ingressMac); |
| 1261 | MacAddress neighborMac; |
| 1262 | try { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1263 | neighborMac = srManager.deviceConfiguration().getDeviceMac(dstCp.deviceId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1264 | } catch (DeviceConfigNotFoundException e) { |
| 1265 | log.warn("Was not able to find the neighbor mac"); |
| 1266 | return null; |
| 1267 | } |
| 1268 | treatmentBuilder.setEthDst(neighborMac); |
| 1269 | } else { |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1270 | // We create the next objective which |
| 1271 | // will be a simple l2 group. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1272 | nextObjBuilder = DefaultNextObjective |
| 1273 | .builder() |
| 1274 | .withType(NextObjective.Type.SIMPLE) |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1275 | .fromApp(srManager.appId()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1276 | } |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1277 | treatmentBuilder.setOutput(srcCp.port()); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1278 | nextObjBuilder.addTreatment(treatmentBuilder.build()); |
| 1279 | return nextObjBuilder; |
| 1280 | } |
| 1281 | |
| 1282 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1283 | * Reverses a link. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1284 | * |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1285 | * @param link link to be reversed |
| 1286 | * @return the reversed link |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1287 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1288 | private Link reverseLink(Link link) { |
| 1289 | |
| 1290 | DefaultLink.Builder linkBuilder = DefaultLink.builder(); |
| 1291 | |
| 1292 | linkBuilder.src(link.dst()); |
| 1293 | linkBuilder.dst(link.src()); |
| 1294 | linkBuilder.type(link.type()); |
| 1295 | linkBuilder.providerId(link.providerId()); |
| 1296 | |
| 1297 | return linkBuilder.build(); |
| 1298 | } |
| 1299 | |
| 1300 | /** |
| 1301 | * Returns the path betwwen two connect points. |
| 1302 | * |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 1303 | * @param srcCp source connect point |
| 1304 | * @param dstCp destination connect point |
| 1305 | * @return the path |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1306 | */ |
| 1307 | private List<Link> getPath(ConnectPoint srcCp, ConnectPoint dstCp) { |
| 1308 | |
| 1309 | /* We retrieve a set of disjoint paths. |
| 1310 | * We perform that in case of a link failure, what happens |
| 1311 | * if the PathService gets the link notification AFTER us and |
| 1312 | * has not updated the paths? |
| 1313 | */ |
| 1314 | Set<DisjointPath> paths = srManager |
| 1315 | .pathService |
| 1316 | .getDisjointPaths(srcCp.elementId(), dstCp.elementId()); |
| 1317 | |
| 1318 | // We randomly pick a path. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1319 | if (paths.isEmpty()) { |
| 1320 | return null; |
| 1321 | } |
| 1322 | int size = paths.size(); |
| 1323 | int index = RandomUtils.nextInt(0, size); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1324 | |
| 1325 | return Iterables.get(paths, index).links(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /** |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1329 | * Deletes a given policy using the parameter supplied. |
| 1330 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1331 | * @param tunnelId the tunnel id |
| 1332 | * @param ingress the ingress point |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1333 | * @param ingressInner the ingress inner vlan id |
| 1334 | * @param ingressOuter the ingress outer vlan id |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1335 | * @param future to perform the async operation |
| 1336 | * @param direction the direction: forward or reverse |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1337 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1338 | private void deletePolicy(long tunnelId, ConnectPoint ingress, VlanId ingressInner, VlanId ingressOuter, |
| 1339 | VlanId egressVlan, CompletableFuture<ObjectiveError> future, Direction direction) { |
| 1340 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1341 | String key = generateKey(tunnelId, direction); |
| 1342 | if (!l2InitiationNextObjStore.containsKey(key)) { |
| 1343 | log.warn("Abort delete of policy for tunnel {}: next does not exist in the store", tunnelId); |
| 1344 | if (future != null) { |
| 1345 | future.complete(null); |
| 1346 | } |
| 1347 | return; |
| 1348 | } |
| 1349 | NextObjective nextObjective = l2InitiationNextObjStore.get(key).value(); |
| 1350 | int nextId = nextObjective.id(); |
| 1351 | List<Objective> objectives = Lists.newArrayList(); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1352 | // We create the forwarding objective. |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1353 | ForwardingObjective.Builder fwdBuilder = createInitFwdObjective(tunnelId, ingress.port(), nextId); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1354 | ObjectiveContext context = new ObjectiveContext() { |
| 1355 | @Override |
| 1356 | public void onSuccess(Objective objective) { |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1357 | log.debug("Previous fwdObj for policy {} removed", tunnelId); |
| 1358 | if (future != null) { |
| 1359 | future.complete(null); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | @Override |
| 1364 | public void onError(Objective objective, ObjectiveError error) { |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1365 | log.warn("Failed to remove previous fwdObj for policy {}: {}", tunnelId, error); |
| 1366 | if (future != null) { |
| 1367 | future.complete(error); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | }; |
| 1371 | objectives.add(fwdBuilder.remove(context)); |
| 1372 | // We create the filtering objective to define the |
| 1373 | // permit traffic in the switch |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1374 | FilteringObjective.Builder filtBuilder = createFiltObjective(ingress.port(), ingressInner, ingressOuter); |
| 1375 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 1376 | .builder() |
| 1377 | .setTunnelId(tunnelId) |
| 1378 | .setVlanId(egressVlan); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1379 | filtBuilder.withMeta(treatment.build()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1380 | context = new DefaultObjectiveContext((objective) -> log.debug("FilterObj for policy {} revoked", tunnelId), |
| 1381 | (objective, error) -> |
| 1382 | log.warn("Failed to revoke filterObj for policy {}", |
| 1383 | tunnelId, error)); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1384 | objectives.add(filtBuilder.remove(context)); |
| 1385 | |
| 1386 | for (Objective objective : objectives) { |
| 1387 | if (objective instanceof ForwardingObjective) { |
| 1388 | srManager.flowObjectiveService.forward(ingress.deviceId(), (ForwardingObjective) objective); |
| 1389 | } else { |
| 1390 | srManager.flowObjectiveService.filter(ingress.deviceId(), (FilteringObjective) objective); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1396 | * Deletes the pseudo wire initiation. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1397 | * |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1398 | * @param l2TunnelId the tunnel id |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1399 | * @param ingress the ingress connect point |
| 1400 | * @param future to perform an async operation |
| 1401 | * @param direction the direction: reverse of forward |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1402 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1403 | private void tearDownPseudoWireInit(long l2TunnelId, ConnectPoint ingress, |
| 1404 | CompletableFuture<ObjectiveError> future, Direction direction) { |
| 1405 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1406 | String key = generateKey(l2TunnelId, direction); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1407 | if (!l2InitiationNextObjStore.containsKey(key)) { |
| 1408 | log.info("Abort delete of {} for {}: next does not exist in the store", INITIATION, key); |
| 1409 | if (future != null) { |
| 1410 | future.complete(null); |
| 1411 | } |
| 1412 | return; |
| 1413 | } |
| 1414 | NextObjective nextObjective = l2InitiationNextObjStore.get(key).value(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1415 | // un-comment in case you want to delete groups used by the pw |
| 1416 | // however, this will break the update of pseudowires cause the L2 interface group can |
| 1417 | // not be deleted (it is referenced by other groups) |
| 1418 | /* |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1419 | ObjectiveContext context = new ObjectiveContext() { |
| 1420 | @Override |
| 1421 | public void onSuccess(Objective objective) { |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1422 | log.debug("Previous {} next for {} removed", INITIATION, key); |
| 1423 | if (future != null) { |
| 1424 | future.complete(null); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | @Override |
| 1429 | public void onError(Objective objective, ObjectiveError error) { |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1430 | log.warn("Failed to remove previous {} next for {}: {}", INITIATION, key, error); |
| 1431 | if (future != null) { |
| 1432 | future.complete(error); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | }; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1436 | srManager.flowObjectiveService.next(ingress.deviceId(), (NextObjective) nextObjective.copy().remove(context)); |
| 1437 | */ |
| 1438 | |
| 1439 | future.complete(null); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1440 | l2InitiationNextObjStore.remove(key); |
| 1441 | } |
| 1442 | |
| 1443 | /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1444 | * Deletes the pseudo wire termination. |
| 1445 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1446 | * @param l2Tunnel the tunnel |
| 1447 | * @param egress the egress connect point |
| 1448 | * @param future the async task |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1449 | * @param direction the direction of the tunnel |
| 1450 | */ |
| 1451 | private void tearDownPseudoWireTerm(DefaultL2Tunnel l2Tunnel, |
| 1452 | ConnectPoint egress, |
| 1453 | CompletableFuture<ObjectiveError> future, |
| 1454 | Direction direction) { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1455 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1456 | String key = generateKey(l2Tunnel.tunnelId(), direction); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1457 | if (!l2TerminationNextObjStore.containsKey(key)) { |
| 1458 | log.info("Abort delete of {} for {}: next does not exist in the store", TERMINATION, key); |
| 1459 | if (future != null) { |
| 1460 | future.complete(null); |
| 1461 | } |
| 1462 | return; |
| 1463 | } |
| 1464 | NextObjective nextObjective = l2TerminationNextObjStore.get(key).value(); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1465 | ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), |
| 1466 | l2Tunnel.tunnelId(), |
| 1467 | egress.port(), |
| 1468 | nextObjective.id()); |
| 1469 | ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for {} {} removed", |
| 1470 | TERMINATION, |
| 1471 | l2Tunnel.tunnelId()), |
| 1472 | (objective, error) -> |
| 1473 | log.warn("Failed to remove fwdObj for {} {}", |
| 1474 | TERMINATION, |
| 1475 | l2Tunnel.tunnelId(), |
| 1476 | error)); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1477 | srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.remove(context)); |
| 1478 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1479 | // un-comment in case you want to delete groups used by the pw |
| 1480 | // however, this will break the update of pseudowires cause the L2 interface group can |
| 1481 | // not be deleted (it is referenced by other groups) |
| 1482 | /* |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1483 | context = new ObjectiveContext() { |
| 1484 | @Override |
| 1485 | public void onSuccess(Objective objective) { |
| 1486 | log.debug("Previous {} next for {} removed", TERMINATION, key); |
| 1487 | if (future != null) { |
| 1488 | future.complete(null); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | @Override |
| 1493 | public void onError(Objective objective, ObjectiveError error) { |
| 1494 | log.warn("Failed to remove previous {} next for {}: {}", TERMINATION, key, error); |
| 1495 | if (future != null) { |
| 1496 | future.complete(error); |
| 1497 | } |
| 1498 | } |
| 1499 | }; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1500 | srManager.flowObjectiveService.next(egress.deviceId(), (NextObjective) nextObjective.copy().remove(context)); |
| 1501 | */ |
| 1502 | |
| 1503 | future.complete(null); |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1504 | l2TerminationNextObjStore.remove(key); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1508 | * Utilities to generate pw key. |
| 1509 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1510 | * @param tunnelId the tunnel id |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1511 | * @param direction the direction of the pw |
| 1512 | * @return the key of the store |
| 1513 | */ |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1514 | private String generateKey(long tunnelId, Direction direction) { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1515 | return String.format("%s-%s", tunnelId, direction); |
| 1516 | } |
| 1517 | |
| 1518 | /** |
Pier Luigi | 0be3f0f | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1519 | * Pwaas pipelines. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1520 | */ |
| 1521 | protected enum Pipeline { |
| 1522 | /** |
| 1523 | * The initiation pipeline. |
| 1524 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1525 | INITIATION, /** |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1526 | * The termination pipeline. |
| 1527 | */ |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1528 | TERMINATION |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1532 | * Enum helper to carry results of various operations. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1533 | */ |
| 1534 | public enum Result { |
| 1535 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1536 | * Happy ending scenario. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1537 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1538 | SUCCESS(0, "No error occurred"), |
| 1539 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1540 | /** |
| 1541 | * We have problems with the supplied parameters. |
| 1542 | */ |
| 1543 | WRONG_PARAMETERS(1, "Wrong parameters"), |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1544 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1545 | /** |
| 1546 | * We have an internal error during the deployment |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1547 | * or removal phase. |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1548 | */ |
| 1549 | INTERNAL_ERROR(3, "Internal error"), |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1550 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1551 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1552 | * |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1553 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1554 | REMOVAL_ERROR(5, "Can not remove pseudowire from network configuration"), |
| 1555 | |
| 1556 | /** |
| 1557 | * |
| 1558 | */ |
| 1559 | ADDITION_ERROR(6, "Can not add pseudowire in network configuration"), |
| 1560 | |
| 1561 | /** |
| 1562 | * |
| 1563 | */ |
| 1564 | CONFIG_NOT_FOUND(7, "Can not find configuration class for pseudowires"); |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1565 | |
| 1566 | private final int code; |
| 1567 | private final String description; |
| 1568 | private int nextId; |
| 1569 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1570 | Result(int code, String description) { |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1571 | this.code = code; |
| 1572 | this.description = description; |
| 1573 | } |
| 1574 | |
| 1575 | public String getDescription() { |
| 1576 | return description; |
| 1577 | } |
| 1578 | |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 1579 | @Override |
| 1580 | public String toString() { |
| 1581 | return code + ": " + description; |
| 1582 | } |
| 1583 | } |
| 1584 | |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1585 | /** |
| 1586 | * Enum helper for handling the direction of the pw. |
| 1587 | */ |
| 1588 | public enum Direction { |
| 1589 | /** |
| 1590 | * The forward direction of the pseudo wire. |
| 1591 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1592 | FWD, /** |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1593 | * The reverse direction of the pseudo wire. |
| 1594 | */ |
Jon Hall | 8f867f4 | 2017-02-22 13:37:33 -0800 | [diff] [blame] | 1595 | REV |
Pier Ventre | ac3e1d9 | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 1596 | } |
| 1597 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1598 | } |