Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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 | */ |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 17 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.DefaultPath; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.DisjointPath; |
| 28 | import org.onosproject.net.EdgeLink; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.Link; |
| 30 | import org.onosproject.net.Path; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 31 | import org.onosproject.net.Port; |
| 32 | import org.onosproject.net.PortNumber; |
| 33 | import org.onosproject.net.device.DeviceService; |
| 34 | import org.onosproject.net.flow.DefaultFlowRule; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.FlowRule; |
| 38 | import org.onosproject.net.flow.TrafficSelector; |
| 39 | import org.onosproject.net.flow.TrafficTreatment; |
| 40 | import org.onosproject.net.flow.instructions.Instruction; |
| 41 | import org.onosproject.net.flow.instructions.Instructions; |
| 42 | import org.onosproject.net.group.DefaultGroupBucket; |
| 43 | import org.onosproject.net.group.DefaultGroupDescription; |
| 44 | import org.onosproject.net.group.DefaultGroupKey; |
| 45 | import org.onosproject.net.group.Group; |
| 46 | import org.onosproject.net.group.GroupBucket; |
| 47 | import org.onosproject.net.group.GroupBuckets; |
| 48 | import org.onosproject.net.group.GroupDescription; |
| 49 | import org.onosproject.net.group.GroupKey; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 50 | import org.onosproject.net.group.GroupListener; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 51 | import org.onosproject.net.group.GroupService; |
| 52 | import org.onosproject.net.intent.FlowRuleIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 53 | import org.onosproject.net.intent.Intent; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 54 | import org.onosproject.net.intent.IntentCompilationException; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 55 | import org.onosproject.net.intent.IntentId; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 56 | import org.onosproject.net.intent.LinkCollectionIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.intent.PathIntent; |
| 58 | import org.onosproject.net.intent.PointToPointIntent; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 59 | import org.onosproject.net.intent.constraint.ProtectionConstraint; |
| 60 | import org.onosproject.net.intent.impl.PathNotFoundException; |
| 61 | import org.onosproject.net.link.LinkService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.provider.ProviderId; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 63 | import org.slf4j.Logger; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 64 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 65 | import java.nio.ByteBuffer; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 66 | import java.util.ArrayList; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 67 | import java.util.Collections; |
| 68 | import java.util.Iterator; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 69 | import java.util.List; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 70 | import java.util.ListIterator; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 71 | import java.util.Set; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 72 | import java.util.concurrent.CompletableFuture; |
| 73 | import java.util.concurrent.ExecutionException; |
| 74 | import java.util.concurrent.TimeUnit; |
| 75 | import java.util.concurrent.TimeoutException; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame^] | 76 | import java.util.stream.Collectors; |
| 77 | import java.util.stream.Stream; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 78 | |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 79 | import static java.util.Arrays.asList; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 80 | import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 81 | import static org.slf4j.LoggerFactory.getLogger; |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 82 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 83 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 84 | * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}. |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 85 | */ |
| 86 | @Component(immediate = true) |
| 87 | public class PointToPointIntentCompiler |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 88 | extends ConnectivityIntentCompiler<PointToPointIntent> { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 89 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 90 | // TODO: use off-the-shell core provider ID |
| 91 | private static final ProviderId PID = |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 92 | new ProviderId("core", "org.onosproject.core", true); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 93 | // TODO: consider whether the default cost is appropriate or not |
| 94 | public static final int DEFAULT_COST = 1; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 95 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 96 | protected static final int PRIORITY = Intent.DEFAULT_INTENT_PRIORITY; |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 97 | |
| 98 | private static final int GROUP_TIMEOUT = 5; |
| 99 | |
| 100 | private final Logger log = getLogger(getClass()); |
| 101 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 102 | protected boolean erasePrimary = false; |
| 103 | protected boolean eraseBackup = false; |
| 104 | |
| 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 106 | protected GroupService groupService; |
| 107 | |
| 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 109 | protected LinkService linkService; |
| 110 | |
| 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 112 | protected DeviceService deviceService; |
weibit | 50eb95b | 2014-10-25 21:47:54 -0700 | [diff] [blame] | 113 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 114 | @Activate |
| 115 | public void activate() { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 116 | intentManager.registerCompiler(PointToPointIntent.class, this); |
| 117 | } |
| 118 | |
| 119 | @Deactivate |
| 120 | public void deactivate() { |
| 121 | intentManager.unregisterCompiler(PointToPointIntent.class); |
| 122 | } |
| 123 | |
| 124 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 125 | public List<Intent> compile(PointToPointIntent intent, List<Intent> installable) { |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 126 | log.trace("compiling {} {}", intent, installable); |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame^] | 127 | ConnectPoint ingressPoint = intent.filteredIngressPoint().connectPoint(); |
| 128 | ConnectPoint egressPoint = intent.filteredEgressPoint().connectPoint(); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 129 | |
| 130 | if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 131 | return createZeroHopLinkCollectionIntent(intent); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 132 | } |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 133 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 134 | // proceed with no protected paths |
| 135 | if (!ProtectionConstraint.requireProtectedPath(intent)) { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 136 | return createUnprotectedLinkCollectionIntent(intent); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | try { |
| 140 | // attempt to compute and implement backup path |
| 141 | return createProtectedIntent(ingressPoint, egressPoint, intent, installable); |
| 142 | } catch (PathNotFoundException e) { |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 143 | log.warn("Could not find disjoint Path for {}", intent); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 144 | // no disjoint path extant -- maximum one path exists between devices |
| 145 | return createSinglePathIntent(ingressPoint, egressPoint, intent, installable); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | private List<Intent> createZeroHopIntent(ConnectPoint ingressPoint, |
| 150 | ConnectPoint egressPoint, |
| 151 | PointToPointIntent intent) { |
| 152 | List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); |
| 153 | return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), |
| 154 | intent, PathIntent.ProtectionType.PRIMARY)); |
| 155 | } |
| 156 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 157 | private List<Intent> createZeroHopLinkCollectionIntent(PointToPointIntent intent) { |
| 158 | return asList(createLinkCollectionIntent(ImmutableSet.of(), DEFAULT_COST, |
| 159 | intent)); |
| 160 | } |
| 161 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame^] | 162 | /** |
| 163 | * Creates an unprotected intent. |
| 164 | * @param ingressPoint the ingress connect point |
| 165 | * @param egressPoint the egress connect point |
| 166 | * @param intent the original intent |
| 167 | * @return the compilation result |
| 168 | * @deprecated 1.10.0 |
| 169 | */ |
| 170 | @Deprecated |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 171 | private List<Intent> createUnprotectedIntent(ConnectPoint ingressPoint, |
| 172 | ConnectPoint egressPoint, |
| 173 | PointToPointIntent intent) { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 174 | List<Link> links = new ArrayList<>(); |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 175 | Path path = getPathOrException(intent, ingressPoint.deviceId(), |
| 176 | egressPoint.deviceId()); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 177 | |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 178 | links.add(createEdgeLink(ingressPoint, true)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 179 | links.addAll(path.links()); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 180 | links.add(createEdgeLink(egressPoint, false)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 181 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 182 | return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 183 | path.annotations()), intent, |
| 184 | PathIntent.ProtectionType.PRIMARY)); |
| 185 | } |
| 186 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 187 | private List<Intent> createUnprotectedLinkCollectionIntent(PointToPointIntent intent) { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 188 | Path path = getPathOrException(intent, intent.filteredIngressPoint().connectPoint().deviceId(), |
| 189 | intent.filteredEgressPoint().connectPoint().deviceId()); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 190 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame^] | 191 | // Allocate bandwidth if a bandwidth constraint is set |
| 192 | ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint(); |
| 193 | ConnectPoint egressCP = intent.filteredEgressPoint().connectPoint(); |
| 194 | |
| 195 | List<ConnectPoint> pathCPs = |
| 196 | path.links().stream() |
| 197 | .flatMap(l -> Stream.of(l.src(), l.dst())) |
| 198 | .collect(Collectors.toList()); |
| 199 | |
| 200 | pathCPs.add(ingressCP); |
| 201 | pathCPs.add(egressCP); |
| 202 | |
| 203 | allocateBandwidth(intent, pathCPs); |
| 204 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 205 | return asList(createLinkCollectionIntent(ImmutableSet.copyOf(path.links()), |
| 206 | path.cost(), |
| 207 | intent)); |
| 208 | } |
| 209 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 210 | //FIXME: Compatibility with EncapsulationConstraint |
| 211 | private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, |
| 212 | ConnectPoint egressPoint, |
| 213 | PointToPointIntent intent, |
| 214 | List<Intent> installable) { |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 215 | log.trace("createProtectedIntent"); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 216 | DisjointPath path = getDisjointPath(intent, ingressPoint.deviceId(), |
| 217 | egressPoint.deviceId()); |
| 218 | |
| 219 | List<Intent> reusableIntents = null; |
| 220 | if (installable != null) { |
| 221 | reusableIntents = filterInvalidSubIntents(installable, intent); |
| 222 | if (reusableIntents.size() == installable.size()) { |
| 223 | // all old paths are still viable |
| 224 | return installable; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | List<Intent> intentList = new ArrayList<>(); |
| 229 | |
| 230 | // primary path intent |
| 231 | List<Link> links = new ArrayList<>(); |
| 232 | links.addAll(path.links()); |
| 233 | links.add(createEdgeLink(egressPoint, false)); |
| 234 | |
| 235 | // backup path intent |
| 236 | List<Link> backupLinks = new ArrayList<>(); |
| 237 | backupLinks.addAll(path.backup().links()); |
| 238 | backupLinks.add(createEdgeLink(egressPoint, false)); |
| 239 | |
| 240 | /* |
| 241 | * One of the old paths is still entirely intact. This old path has |
| 242 | * already been made primary, so we must add a backup path intent |
| 243 | * and modify the failover group treatment accordingly. |
| 244 | */ |
| 245 | if (reusableIntents != null && reusableIntents.size() > 1) { |
| 246 | /* |
| 247 | * Ensures that the egress port on source device is different than |
| 248 | * that of existing path so that failover group will be useful |
| 249 | * (would not be useful if both output ports in group bucket were |
| 250 | * the same). Does not necessarily ensure that the new backup path |
| 251 | * is entirely disjoint from the old path. |
| 252 | */ |
| 253 | PortNumber primaryPort = getPrimaryPort(intent); |
| 254 | if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) { |
| 255 | reusableIntents.add(createPathIntent(new DefaultPath(PID, links, |
| 256 | path.cost(), path.annotations()), |
| 257 | intent, PathIntent.ProtectionType.BACKUP)); |
| 258 | updateFailoverGroup(intent, links); |
| 259 | return reusableIntents; |
| 260 | |
| 261 | } else { |
| 262 | reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().cost(), |
| 263 | path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP)); |
| 264 | updateFailoverGroup(intent, backupLinks); |
| 265 | return reusableIntents; |
| 266 | } |
| 267 | } |
| 268 | |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 269 | intentList.add(createPathIntent(new DefaultPath(PID, links, path.cost(), |
| 270 | path.annotations()), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 271 | intent, PathIntent.ProtectionType.PRIMARY)); |
| 272 | intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().cost(), |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 273 | path.backup().annotations()), |
| 274 | intent, PathIntent.ProtectionType.BACKUP)); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 275 | |
| 276 | // Create fast failover flow rule intent or, if it already exists, |
| 277 | // add contents appropriately. |
| 278 | if (groupService.getGroup(ingressPoint.deviceId(), |
| 279 | makeGroupKey(intent.id())) == null) { |
| 280 | // manufactured fast failover flow rule intent |
| 281 | createFailoverTreatmentGroup(path.links(), path.backup().links(), intent); |
| 282 | |
| 283 | FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 284 | intent.key(), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 285 | createFailoverFlowRules(intent), |
| 286 | asList(ingressPoint.deviceId()), |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 287 | PathIntent.ProtectionType.FAILOVER, |
| 288 | intent.resourceGroup()); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 289 | intentList.add(frIntent); |
| 290 | } else { |
| 291 | updateFailoverGroup(intent, links); |
| 292 | updateFailoverGroup(intent, backupLinks); |
| 293 | } |
| 294 | |
| 295 | return intentList; |
| 296 | } |
| 297 | |
| 298 | private List<Intent> createSinglePathIntent(ConnectPoint ingressPoint, |
| 299 | ConnectPoint egressPoint, |
| 300 | PointToPointIntent intent, |
| 301 | List<Intent> installable) { |
| 302 | List<Link> links = new ArrayList<>(); |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 303 | Path onlyPath = getPathOrException(intent, ingressPoint.deviceId(), |
| 304 | egressPoint.deviceId()); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 305 | |
| 306 | List<Intent> reusableIntents = null; |
| 307 | if (installable != null) { |
| 308 | reusableIntents = filterInvalidSubIntents(installable, intent); |
| 309 | if (reusableIntents.size() == installable.size()) { |
| 310 | // all old paths are still viable |
| 311 | return installable; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | // If there exists a full path from old installable intents, |
| 316 | // return the intents that comprise it. |
| 317 | if (reusableIntents != null && reusableIntents.size() > 1) { |
| 318 | return reusableIntents; |
| 319 | } else { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame^] | 320 | // Allocate bandwidth if a bandwidth constraint is set |
| 321 | ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint(); |
| 322 | ConnectPoint egressCP = intent.filteredEgressPoint().connectPoint(); |
| 323 | |
| 324 | List<ConnectPoint> pathCPs = |
| 325 | onlyPath.links().stream() |
| 326 | .flatMap(l -> Stream.of(l.src(), l.dst())) |
| 327 | .collect(Collectors.toList()); |
| 328 | |
| 329 | pathCPs.add(ingressCP); |
| 330 | pathCPs.add(egressCP); |
| 331 | |
| 332 | // Allocate bandwidth if a bandwidth constraint is set |
| 333 | allocateBandwidth(intent, pathCPs); |
| 334 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 335 | links.add(createEdgeLink(ingressPoint, true)); |
| 336 | links.addAll(onlyPath.links()); |
| 337 | links.add(createEdgeLink(egressPoint, false)); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 338 | return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.cost(), |
| 339 | onlyPath.annotations()), |
| 340 | intent, PathIntent.ProtectionType.PRIMARY)); |
| 341 | } |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Creates a path intent from the specified path and original |
| 346 | * connectivity intent. |
| 347 | * |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 348 | * @param path path to create an intent for |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 349 | * @param intent original intent |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 350 | * @param type primary or backup |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 351 | */ |
| 352 | private Intent createPathIntent(Path path, |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 353 | PointToPointIntent intent, |
| 354 | PathIntent.ProtectionType type) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 355 | return PathIntent.builder() |
| 356 | .appId(intent.appId()) |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 357 | .key(intent.key()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 358 | .selector(intent.selector()) |
| 359 | .treatment(intent.treatment()) |
| 360 | .path(path) |
| 361 | .constraints(intent.constraints()) |
| 362 | .priority(intent.priority()) |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 363 | .setType(type) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 364 | .resourceGroup(intent.resourceGroup()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 365 | .build(); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 368 | |
| 369 | /** |
| 370 | * Creates a link collection intent from the specified path and original |
| 371 | * point to point intent. |
| 372 | * |
| 373 | * @param links the links of the packets |
| 374 | * @param cost the cost associated to the links |
| 375 | * @param intent the point to point intent we are compiling |
| 376 | * @return the link collection intent |
| 377 | */ |
| 378 | private Intent createLinkCollectionIntent(Set<Link> links, |
| 379 | double cost, |
| 380 | PointToPointIntent intent) { |
| 381 | |
| 382 | return LinkCollectionIntent.builder() |
| 383 | .key(intent.key()) |
| 384 | .appId(intent.appId()) |
| 385 | .selector(intent.selector()) |
| 386 | .treatment(intent.treatment()) |
| 387 | .links(ImmutableSet.copyOf(links)) |
| 388 | .filteredIngressPoints(ImmutableSet.of( |
| 389 | intent.filteredIngressPoint() |
| 390 | )) |
| 391 | .filteredEgressPoints(ImmutableSet.of( |
| 392 | intent.filteredEgressPoint() |
| 393 | )) |
| 394 | .applyTreatmentOnEgress(true) |
| 395 | .constraints(intent.constraints()) |
| 396 | .priority(intent.priority()) |
| 397 | .cost(cost) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 398 | .resourceGroup(intent.resourceGroup()) |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 399 | .build(); |
| 400 | } |
| 401 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 402 | /** |
| 403 | * Gets primary port number through failover group associated |
| 404 | * with this intent. |
| 405 | */ |
| 406 | private PortNumber getPrimaryPort(PointToPointIntent intent) { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 407 | Group group = groupService.getGroup(intent.filteredIngressPoint().connectPoint().deviceId(), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 408 | makeGroupKey(intent.id())); |
| 409 | PortNumber primaryPort = null; |
| 410 | if (group != null) { |
| 411 | List<GroupBucket> buckets = group.buckets().buckets(); |
| 412 | Iterator<GroupBucket> iterator = buckets.iterator(); |
| 413 | while (primaryPort == null && iterator.hasNext()) { |
| 414 | GroupBucket bucket = iterator.next(); |
| 415 | Instruction individualInstruction = bucket.treatment().allInstructions().get(0); |
| 416 | if (individualInstruction instanceof Instructions.OutputInstruction) { |
| 417 | Instructions.OutputInstruction outInstruction = |
| 418 | (Instructions.OutputInstruction) individualInstruction; |
| 419 | PortNumber tempPortNum = outInstruction.port(); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 420 | Port port = deviceService.getPort(intent.filteredIngressPoint().connectPoint().deviceId(), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 421 | tempPortNum); |
| 422 | if (port != null && port.isEnabled()) { |
| 423 | primaryPort = tempPortNum; |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | return primaryPort; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Creates group key unique to each intent. |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 433 | * |
| 434 | * @param intentId identifier of intent to get a key for |
| 435 | * @return unique group key for the intent identifier |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 436 | */ |
| 437 | public static GroupKey makeGroupKey(IntentId intentId) { |
| 438 | ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); |
| 439 | buffer.putLong(intentId.fingerprint()); |
| 440 | return new DefaultGroupKey(buffer.array()); |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Creates a new failover group with the initial ports of the links |
| 445 | * from the primary and backup path. |
| 446 | * |
| 447 | * @param links links from the primary path |
| 448 | * @param backupLinks links from the backup path |
| 449 | * @param intent intent from which this call originates |
| 450 | */ |
| 451 | private void createFailoverTreatmentGroup(List<Link> links, |
| 452 | List<Link> backupLinks, |
| 453 | PointToPointIntent intent) { |
| 454 | |
| 455 | List<GroupBucket> buckets = new ArrayList<>(); |
| 456 | |
| 457 | TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); |
| 458 | ConnectPoint src = links.get(0).src(); |
| 459 | tBuilderIn.setOutput(src.port()); |
| 460 | |
| 461 | TrafficTreatment.Builder tBuilderIn2 = DefaultTrafficTreatment.builder(); |
| 462 | ConnectPoint src2 = backupLinks.get(0).src(); |
| 463 | tBuilderIn2.setOutput(src2.port()); |
| 464 | |
| 465 | buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null)); |
| 466 | buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn2.build(), src2.port(), null)); |
| 467 | |
| 468 | GroupBuckets groupBuckets = new GroupBuckets(buckets); |
| 469 | |
| 470 | GroupDescription groupDesc = new DefaultGroupDescription(src.deviceId(), Group.Type.FAILOVER, |
| 471 | groupBuckets, makeGroupKey(intent.id()), null, intent.appId()); |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 472 | log.trace("adding failover group {}", groupDesc); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 473 | groupService.addGroup(groupDesc); |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Manufactures flow rule with treatment that is defined by failover |
| 478 | * group and traffic selector determined by ingress port of the intent. |
| 479 | * |
| 480 | * @param intent intent which is being compiled (for appId) |
| 481 | * @return a list of a singular flow rule with fast failover |
| 482 | * outport traffic treatment |
| 483 | */ |
| 484 | private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) { |
| 485 | List<FlowRule> flowRules = new ArrayList<>(); |
| 486 | |
| 487 | ConnectPoint ingress = intent.ingressPoint(); |
| 488 | DeviceId deviceId = ingress.deviceId(); |
| 489 | |
| 490 | // flow rule with failover traffic treatment |
| 491 | TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()) |
| 492 | .matchInPort(ingress.port()).build(); |
| 493 | |
| 494 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 495 | flowRules.add(flowRuleBuilder.withSelector(trafficSelector) |
| 496 | .withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))) |
| 497 | .fromApp(intent.appId()) |
| 498 | .makePermanent() |
| 499 | .forDevice(deviceId) |
| 500 | .withPriority(PRIORITY) |
| 501 | .build()); |
| 502 | |
| 503 | return flowRules; |
| 504 | } |
| 505 | |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 506 | |
| 507 | /** |
| 508 | * Waits for specified group to appear maximum of {@value #GROUP_TIMEOUT} seconds. |
| 509 | * |
| 510 | * @param deviceId {@link DeviceId} |
| 511 | * @param groupKey {@link GroupKey} to wait for. |
| 512 | * @return {@link Group} |
| 513 | * @throws IntentCompilationException on any error. |
| 514 | */ |
| 515 | private Group waitForGroup(DeviceId deviceId, GroupKey groupKey) { |
| 516 | return waitForGroup(deviceId, groupKey, GROUP_TIMEOUT, TimeUnit.SECONDS); |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Waits for specified group to appear until timeout. |
| 521 | * |
| 522 | * @param deviceId {@link DeviceId} |
| 523 | * @param groupKey {@link GroupKey} to wait for. |
| 524 | * @param timeout timeout |
| 525 | * @param unit unit of timeout |
| 526 | * @return {@link Group} |
| 527 | * @throws IntentCompilationException on any error. |
| 528 | */ |
| 529 | private Group waitForGroup(DeviceId deviceId, GroupKey groupKey, long timeout, TimeUnit unit) { |
| 530 | Group group = groupService.getGroup(deviceId, groupKey); |
| 531 | if (group != null) { |
| 532 | return group; |
| 533 | } |
| 534 | |
| 535 | final CompletableFuture<Group> future = new CompletableFuture<>(); |
| 536 | final GroupListener listener = event -> { |
| 537 | if (event.subject().deviceId() == deviceId && |
| 538 | event.subject().appCookie().equals(groupKey)) { |
| 539 | future.complete(event.subject()); |
| 540 | return; |
| 541 | } |
| 542 | }; |
| 543 | |
| 544 | groupService.addListener(listener); |
| 545 | try { |
| 546 | group = groupService.getGroup(deviceId, groupKey); |
| 547 | if (group != null) { |
| 548 | return group; |
| 549 | } |
| 550 | return future.get(timeout, unit); |
| 551 | } catch (InterruptedException e) { |
| 552 | log.debug("Interrupted", e); |
| 553 | Thread.currentThread().interrupt(); |
| 554 | throw new IntentCompilationException("Interrupted", e); |
| 555 | } catch (ExecutionException e) { |
| 556 | log.debug("ExecutionException", e); |
| 557 | throw new IntentCompilationException("ExecutionException caught", e); |
| 558 | } catch (TimeoutException e) { |
| 559 | // one last try |
| 560 | group = groupService.getGroup(deviceId, groupKey); |
| 561 | if (group != null) { |
| 562 | return group; |
| 563 | } else { |
| 564 | log.debug("Timeout", e); |
| 565 | throw new IntentCompilationException("Timeout", e); |
| 566 | } |
| 567 | } finally { |
| 568 | groupService.removeListener(listener); |
| 569 | } |
| 570 | } |
| 571 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 572 | private TrafficTreatment buildFailoverTreatment(DeviceId srcDevice, |
| 573 | GroupKey groupKey) { |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 574 | Group group = waitForGroup(srcDevice, groupKey); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 575 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 576 | TrafficTreatment trafficTreatment = tBuilder.group(group.id()).build(); |
| 577 | return trafficTreatment; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Deletes intents from the given list if the ports or links the intent |
| 582 | * relies on are no longer viable. The failover flow rule intent is never |
| 583 | * deleted -- only its contents are updated. |
| 584 | * |
| 585 | * @param oldInstallables list of intents to examine |
| 586 | * @return list of reusable installable intents |
| 587 | */ |
| 588 | private List<Intent> filterInvalidSubIntents(List<Intent> oldInstallables, |
| 589 | PointToPointIntent pointIntent) { |
| 590 | List<Intent> intentList = new ArrayList<>(); |
| 591 | intentList.addAll(oldInstallables); |
| 592 | erasePrimary = false; |
| 593 | eraseBackup = false; |
| 594 | if (intentList != null) { |
| 595 | Iterator<Intent> iterator = intentList.iterator(); |
| 596 | while (iterator.hasNext() && !(erasePrimary && eraseBackup)) { |
| 597 | Intent intent = iterator.next(); |
| 598 | intent.resources().forEach(resource -> { |
| 599 | if (resource instanceof Link) { |
| 600 | Link link = (Link) resource; |
| 601 | if (link.state() == Link.State.INACTIVE) { |
| 602 | setPathsToRemove(intent); |
| 603 | } else if (link instanceof EdgeLink) { |
| 604 | ConnectPoint connectPoint = (link.src().elementId() instanceof DeviceId) |
| 605 | ? link.src() : link.dst(); |
| 606 | Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); |
| 607 | if (port == null || !port.isEnabled()) { |
| 608 | setPathsToRemove(intent); |
| 609 | } |
| 610 | } else { |
| 611 | Port port1 = deviceService.getPort(link.src().deviceId(), link.src().port()); |
| 612 | Port port2 = deviceService.getPort(link.dst().deviceId(), link.dst().port()); |
| 613 | if (port1 == null || !port1.isEnabled() || port2 == null || !port2.isEnabled()) { |
| 614 | setPathsToRemove(intent); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | }); |
| 619 | } |
| 620 | removeAndUpdateIntents(intentList, pointIntent); |
| 621 | } |
| 622 | return intentList; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * Sets instance variables erasePrimary and eraseBackup. If erasePrimary, |
| 627 | * the primary path is no longer viable and related intents will be deleted. |
| 628 | * If eraseBackup, the backup path is no longer viable and related intents |
| 629 | * will be deleted. |
| 630 | * |
| 631 | * @param intent intent whose resources are found to be disabled/inactive: |
| 632 | * if intent is part of primary path, primary path set for removal; |
| 633 | * if intent is part of backup path, backup path set for removal; |
| 634 | * if bad intent is of type failover, the ingress point is down, |
| 635 | * and both paths are rendered inactive. |
| 636 | * @return true if both primary and backup paths are to be removed |
| 637 | */ |
| 638 | private boolean setPathsToRemove(Intent intent) { |
| 639 | if (intent instanceof FlowRuleIntent) { |
| 640 | FlowRuleIntent frIntent = (FlowRuleIntent) intent; |
| 641 | PathIntent.ProtectionType type = frIntent.type(); |
| 642 | if (type == PathIntent.ProtectionType.PRIMARY || type == PathIntent.ProtectionType.FAILOVER) { |
| 643 | erasePrimary = true; |
| 644 | } |
| 645 | if (type == PathIntent.ProtectionType.BACKUP || type == PathIntent.ProtectionType.FAILOVER) { |
| 646 | eraseBackup = true; |
| 647 | } |
| 648 | } |
| 649 | return erasePrimary && eraseBackup; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Removes intents from installables list, depending on the values |
| 654 | * of instance variables erasePrimary and eraseBackup. Flow rule intents |
| 655 | * that contain the manufactured fast failover flow rules are never deleted. |
| 656 | * The contents are simply modified as necessary. If cleanUpIntents size |
| 657 | * is greater than 1 (failover intent), then one whole path from previous |
| 658 | * installables must be still viable. |
| 659 | * |
| 660 | * @param cleanUpIntents list of installable intents |
| 661 | */ |
| 662 | private void removeAndUpdateIntents(List<Intent> cleanUpIntents, |
| 663 | PointToPointIntent pointIntent) { |
| 664 | ListIterator<Intent> iterator = cleanUpIntents.listIterator(); |
| 665 | while (iterator.hasNext()) { |
| 666 | Intent cIntent = iterator.next(); |
| 667 | if (cIntent instanceof FlowRuleIntent) { |
| 668 | FlowRuleIntent fIntent = (FlowRuleIntent) cIntent; |
| 669 | if (fIntent.type() == PathIntent.ProtectionType.PRIMARY && erasePrimary) { |
| 670 | // remove primary path's flow rule intents |
| 671 | iterator.remove(); |
| 672 | } else if (fIntent.type() == PathIntent.ProtectionType.BACKUP && eraseBackup) { |
| 673 | //remove backup path's flow rule intents |
| 674 | iterator.remove(); |
| 675 | } else if (fIntent.type() == PathIntent.ProtectionType.BACKUP && erasePrimary) { |
| 676 | // promote backup path's flow rule intents to primary |
| 677 | iterator.set(new FlowRuleIntent(fIntent, PathIntent.ProtectionType.PRIMARY)); |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | // remove buckets whose watchports are disabled if the failover group exists |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 682 | Group group = groupService.getGroup(pointIntent.filteredIngressPoint().connectPoint().deviceId(), |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 683 | makeGroupKey(pointIntent.id())); |
| 684 | if (group != null) { |
| 685 | updateFailoverGroup(pointIntent); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // Removes buckets whose treatments rely on disabled ports from the |
| 690 | // failover group. |
| 691 | private void updateFailoverGroup(PointToPointIntent pointIntent) { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 692 | DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId(); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 693 | GroupKey groupKey = makeGroupKey(pointIntent.id()); |
Yuta HIGUCHI | 625fb64 | 2016-09-01 16:10:24 -0700 | [diff] [blame] | 694 | Group group = waitForGroup(deviceId, groupKey); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 695 | Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator(); |
| 696 | while (groupIterator.hasNext()) { |
| 697 | GroupBucket bucket = groupIterator.next(); |
| 698 | Instruction individualInstruction = bucket.treatment().allInstructions().get(0); |
| 699 | if (individualInstruction instanceof Instructions.OutputInstruction) { |
| 700 | Instructions.OutputInstruction outInstruction = |
| 701 | (Instructions.OutputInstruction) individualInstruction; |
| 702 | Port port = deviceService.getPort(deviceId, outInstruction.port()); |
| 703 | if (port == null || !port.isEnabled()) { |
| 704 | GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket)); |
| 705 | groupService.removeBucketsFromGroup(deviceId, groupKey, |
| 706 | removeBuckets, groupKey, |
| 707 | pointIntent.appId()); |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // Adds failover group bucket with treatment outport determined by the |
| 714 | // ingress point of the links. |
| 715 | private void updateFailoverGroup(PointToPointIntent intent, List<Link> links) { |
| 716 | GroupKey groupKey = makeGroupKey(intent.id()); |
| 717 | |
| 718 | TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); |
| 719 | ConnectPoint src = links.get(0).src(); |
| 720 | tBuilderIn.setOutput(src.port()); |
| 721 | GroupBucket bucket = DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null); |
| 722 | GroupBuckets addBuckets = new GroupBuckets(Collections.singletonList(bucket)); |
| 723 | |
| 724 | groupService.addBucketsToGroup(src.deviceId(), groupKey, addBuckets, groupKey, intent.appId()); |
| 725 | } |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 726 | } |