Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -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 | */ |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline.ofdpa; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 17 | |
| 18 | import com.google.common.cache.Cache; |
| 19 | import com.google.common.cache.CacheBuilder; |
| 20 | import com.google.common.cache.RemovalCause; |
| 21 | import com.google.common.cache.RemovalNotification; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
| 23 | import com.google.common.collect.Lists; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 24 | import com.google.common.collect.Sets; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 25 | import org.onlab.osgi.ServiceDirectory; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IpPrefix; |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 27 | import org.onlab.packet.MacAddress; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 28 | import org.onlab.packet.MplsLabel; |
| 29 | import org.onlab.packet.VlanId; |
| 30 | import org.onosproject.core.ApplicationId; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 31 | import org.onosproject.core.GroupId; |
Charles Chan | 3256252 | 2016-04-07 14:37:14 -0700 | [diff] [blame] | 32 | import org.onosproject.driver.extensions.OfdpaSetVlanVid; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 33 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.behaviour.NextGroup; |
| 36 | import org.onosproject.net.behaviour.PipelinerContext; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | import org.onosproject.net.flow.TrafficSelector; |
| 39 | import org.onosproject.net.flow.TrafficTreatment; |
| 40 | import org.onosproject.net.flow.criteria.Criterion; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 41 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 43 | import org.onosproject.net.flow.instructions.Instruction; |
| 44 | import org.onosproject.net.flow.instructions.Instructions; |
| 45 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 46 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 48 | import org.onosproject.net.flowobjective.NextObjective; |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flowobjective.Objective.Operation; |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 52 | import org.onosproject.net.group.DefaultGroupBucket; |
| 53 | import org.onosproject.net.group.DefaultGroupDescription; |
| 54 | import org.onosproject.net.group.DefaultGroupKey; |
| 55 | import org.onosproject.net.group.Group; |
| 56 | import org.onosproject.net.group.GroupBucket; |
| 57 | import org.onosproject.net.group.GroupBuckets; |
| 58 | import org.onosproject.net.group.GroupDescription; |
| 59 | import org.onosproject.net.group.GroupEvent; |
| 60 | import org.onosproject.net.group.GroupKey; |
| 61 | import org.onosproject.net.group.GroupListener; |
| 62 | import org.onosproject.net.group.GroupService; |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 63 | import org.onosproject.store.service.AtomicCounter; |
| 64 | import org.onosproject.store.service.StorageService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 65 | import org.slf4j.Logger; |
| 66 | |
| 67 | import java.util.ArrayDeque; |
| 68 | import java.util.ArrayList; |
| 69 | import java.util.Collection; |
| 70 | import java.util.Collections; |
| 71 | import java.util.Deque; |
| 72 | import java.util.List; |
Charles Chan | d0fd5dc | 2016-02-16 23:14:49 -0800 | [diff] [blame] | 73 | import java.util.Objects; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 74 | import java.util.Set; |
| 75 | import java.util.concurrent.ConcurrentHashMap; |
| 76 | import java.util.concurrent.CopyOnWriteArrayList; |
| 77 | import java.util.concurrent.Executors; |
| 78 | import java.util.concurrent.ScheduledExecutorService; |
| 79 | import java.util.concurrent.TimeUnit; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 80 | import java.util.stream.Collectors; |
| 81 | |
| 82 | import static org.onlab.util.Tools.groupedThreads; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 83 | import static org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline.*; |
| 84 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 85 | import static org.onosproject.net.flow.criteria.Criterion.Type.TUNNEL_ID; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 86 | import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 87 | import static org.onosproject.net.group.GroupDescription.Type.ALL; |
| 88 | import static org.onosproject.net.group.GroupDescription.Type.SELECT; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 89 | import static org.slf4j.LoggerFactory.getLogger; |
| 90 | |
| 91 | /** |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 92 | * Group handler that emulates Broadcom OF-DPA TTP. |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 93 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 94 | public class Ofdpa2GroupHandler { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 95 | protected final Logger log = getLogger(getClass()); |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 96 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 97 | // Services, Stores |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 98 | protected GroupService groupService; |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 99 | protected StorageService storageService; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 100 | protected FlowObjectiveStore flowObjectiveStore; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 101 | |
| 102 | // index number for group creation |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 103 | private AtomicCounter nextIndex; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 104 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 105 | protected DeviceId deviceId; |
| 106 | private Cache<GroupKey, List<OfdpaGroupHandlerUtility.OfdpaNextGroup>> pendingAddNextObjectives; |
| 107 | private Cache<NextObjective, List<GroupKey>> pendingRemoveNextObjectives; |
| 108 | private Cache<GroupKey, Set<OfdpaGroupHandlerUtility.GroupChainElem>> pendingGroups; |
| 109 | private ConcurrentHashMap<GroupKey, Set<NextObjective>> pendingUpdateNextObjectives; |
| 110 | |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 111 | // local store for pending bucketAdds - by design there can be multiple |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 112 | // pending bucket for a group |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 113 | protected ConcurrentHashMap<Integer, Set<NextObjective>> pendingBuckets = |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 114 | new ConcurrentHashMap<>(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 115 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 116 | private ScheduledExecutorService groupCheckerExecutor = |
| 117 | Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner", "ofdpa-%d", log)); |
| 118 | |
| 119 | public Cache<GroupKey, List<OfdpaNextGroup>> pendingAddNextObjectives() { |
| 120 | return pendingAddNextObjectives; |
| 121 | } |
| 122 | |
| 123 | public Cache<GroupKey, Set<GroupChainElem>> pendingGroups() { |
| 124 | return pendingGroups; |
| 125 | } |
| 126 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 127 | /** |
| 128 | * Determines whether this pipeline support copy ttl instructions or not. |
| 129 | * |
| 130 | * @return true if copy ttl instructions are supported |
| 131 | */ |
| 132 | protected boolean supportCopyTtl() { |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Determines whether this pipeline support set mpls bos instruction or not. |
| 138 | * |
| 139 | * @return true if set mpls bos instruction is supported |
| 140 | */ |
| 141 | protected boolean supportSetMplsBos() { |
| 142 | return true; |
| 143 | } |
| 144 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Determines whether this pipeline requires popping VLAN before pushing MPLS. |
| 147 | * <p> |
| 148 | * If required, pop vlan before push mpls and add an arbitrary vlan back afterward. |
| 149 | * MPLS interface group will substitute the arbitrary VLAN with expected VLAN later on. |
| 150 | * |
| 151 | * @return true if this pipeline requires popping VLAN before pushing MPLS |
| 152 | */ |
| 153 | protected boolean requireVlanPopBeforeMplsPush() { |
| 154 | return false; |
| 155 | } |
| 156 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 157 | protected void init(DeviceId deviceId, PipelinerContext context) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 158 | ServiceDirectory serviceDirectory = context.directory(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 159 | this.deviceId = deviceId; |
| 160 | this.flowObjectiveStore = context.store(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 161 | this.groupService = serviceDirectory.get(GroupService.class); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 162 | this.storageService = serviceDirectory.get(StorageService.class); |
Madan Jampani | d5714e0 | 2016-04-19 14:15:20 -0700 | [diff] [blame] | 163 | this.nextIndex = storageService.getAtomicCounter("group-id-index-counter"); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 164 | |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 165 | pendingAddNextObjectives = CacheBuilder.newBuilder() |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 166 | .expireAfterWrite(20, TimeUnit.SECONDS) |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 167 | .removalListener((RemovalNotification<GroupKey, List<OfdpaNextGroup>> notification) -> { |
| 168 | if (notification.getCause() == RemovalCause.EXPIRED && |
| 169 | Objects.nonNull(notification.getValue())) { |
| 170 | notification.getValue() |
| 171 | .forEach(ofdpaNextGrp -> |
| 172 | fail(ofdpaNextGrp.nextObjective(), |
| 173 | ObjectiveError.GROUPINSTALLATIONFAILED)); |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 174 | } |
| 175 | }).build(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 176 | |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 177 | pendingRemoveNextObjectives = CacheBuilder.newBuilder() |
| 178 | .expireAfterWrite(20, TimeUnit.SECONDS) |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 179 | .removalListener((RemovalNotification<NextObjective, List<GroupKey>> notification) -> { |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 180 | if (notification.getCause() == RemovalCause.EXPIRED) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 181 | fail(notification.getKey(), |
| 182 | ObjectiveError.GROUPREMOVALFAILED); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 183 | } |
| 184 | }).build(); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 185 | pendingGroups = CacheBuilder.newBuilder() |
| 186 | .expireAfterWrite(20, TimeUnit.SECONDS) |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 187 | .removalListener((RemovalNotification<GroupKey, Set<GroupChainElem>> notification) -> { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 188 | if (notification.getCause() == RemovalCause.EXPIRED) { |
| 189 | log.error("Unable to install group with key {} and pending GCEs: {}", |
| 190 | notification.getKey(), notification.getValue()); |
| 191 | } |
| 192 | }).build(); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 193 | pendingUpdateNextObjectives = new ConcurrentHashMap<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 194 | GroupChecker groupChecker = new GroupChecker(this); |
| 195 | groupCheckerExecutor.scheduleAtFixedRate(groupChecker, 0, 500, TimeUnit.MILLISECONDS); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 196 | groupService.addListener(new InnerGroupListener()); |
| 197 | } |
| 198 | |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 199 | ////////////////////////////////////// |
| 200 | // Group Creation |
| 201 | ////////////////////////////////////// |
| 202 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Adds a list of group chain by given NextObjective. |
| 205 | * |
| 206 | * @param nextObjective the NextObjective |
| 207 | */ |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 208 | protected void addGroup(NextObjective nextObjective) { |
| 209 | switch (nextObjective.type()) { |
| 210 | case SIMPLE: |
| 211 | Collection<TrafficTreatment> treatments = nextObjective.next(); |
| 212 | if (treatments.size() != 1) { |
| 213 | log.error("Next Objectives of type Simple should only have a " |
| 214 | + "single Traffic Treatment. Next Objective Id:{}", |
| 215 | nextObjective.id()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 216 | fail(nextObjective, ObjectiveError.BADPARAMS); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 217 | return; |
| 218 | } |
| 219 | processSimpleNextObjective(nextObjective); |
| 220 | break; |
| 221 | case BROADCAST: |
| 222 | processBroadcastNextObjective(nextObjective); |
| 223 | break; |
| 224 | case HASHED: |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 225 | if (!verifyHashedNextObjective(nextObjective)) { |
| 226 | log.error("Next Objectives of type hashed not supported. Next Objective Id:{}", |
| 227 | nextObjective.id()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 228 | fail(nextObjective, ObjectiveError.BADPARAMS); |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 229 | return; |
| 230 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 231 | processHashedNextObjective(nextObjective); |
| 232 | break; |
| 233 | case FAILOVER: |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 234 | fail(nextObjective, ObjectiveError.UNSUPPORTED); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 235 | log.warn("Unsupported next objective type {}", nextObjective.type()); |
| 236 | break; |
| 237 | default: |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 238 | fail(nextObjective, ObjectiveError.UNKNOWN); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 239 | log.warn("Unknown next objective type {}", nextObjective.type()); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * As per the OFDPA 2.0 TTP, packets are sent out of ports by using |
| 245 | * a chain of groups. The simple Next Objective passed |
| 246 | * in by the application has to be broken up into a group chain |
| 247 | * comprising of an L3 Unicast Group that points to an L2 Interface |
| 248 | * Group which in-turn points to an output port. In some cases, the simple |
| 249 | * next Objective can just be an L2 interface without the need for chaining. |
| 250 | * |
| 251 | * @param nextObj the nextObjective of type SIMPLE |
| 252 | */ |
| 253 | private void processSimpleNextObjective(NextObjective nextObj) { |
| 254 | TrafficTreatment treatment = nextObj.next().iterator().next(); |
| 255 | // determine if plain L2 or L3->L2 |
| 256 | boolean plainL2 = true; |
| 257 | for (Instruction ins : treatment.allInstructions()) { |
| 258 | if (ins.type() == Instruction.Type.L2MODIFICATION) { |
| 259 | L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; |
| 260 | if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST || |
| 261 | l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC) { |
| 262 | plainL2 = false; |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if (plainL2) { |
| 269 | createL2InterfaceGroup(nextObj); |
| 270 | return; |
| 271 | } |
| 272 | |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 273 | boolean isMpls = false; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 274 | // In order to understand if it is a pseudo wire related |
| 275 | // next objective we look for the tunnel id in the meta. |
| 276 | boolean isPw = false; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 277 | if (nextObj.meta() != null) { |
| 278 | isMpls = isNotMplsBos(nextObj.meta()); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 279 | |
| 280 | TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) nextObj |
| 281 | .meta() |
| 282 | .getCriterion(TUNNEL_ID); |
| 283 | if (tunnelIdCriterion != null) { |
| 284 | isPw = true; |
| 285 | } |
| 286 | |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 289 | if (!isPw) { |
| 290 | // break up simple next objective to GroupChain objects |
| 291 | GroupInfo groupInfo = createL2L3Chain(treatment, nextObj.id(), |
| 292 | nextObj.appId(), isMpls, |
| 293 | nextObj.meta()); |
| 294 | if (groupInfo == null) { |
| 295 | log.error("Could not process nextObj={} in dev:{}", nextObj.id(), deviceId); |
| 296 | return; |
| 297 | } |
| 298 | // create object for local and distributed storage |
| 299 | Deque<GroupKey> gkeyChain = new ArrayDeque<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 300 | gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie()); |
| 301 | gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie()); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 302 | OfdpaNextGroup ofdpaGrp = |
| 303 | new OfdpaNextGroup(Collections.singletonList(gkeyChain), nextObj); |
| 304 | |
| 305 | // store l3groupkey with the ofdpaNextGroup for the nextObjective that depends on it |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 306 | updatePendingNextObjective(groupInfo.nextGroupDesc().appCookie(), ofdpaGrp); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 307 | |
| 308 | // now we are ready to send the l2 groupDescription (inner), as all the stores |
| 309 | // that will get async replies have been updated. By waiting to update |
| 310 | // the stores, we prevent nasty race conditions. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 311 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 312 | } else { |
| 313 | // We handle the pseudo wire with a different a procedure. |
| 314 | // This procedure is meant to handle both initiation and |
| 315 | // termination of the pseudo wire. |
| 316 | processPwNextObjective(nextObj); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 317 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 320 | /** |
| 321 | * Creates a simple L2 Interface Group. |
| 322 | * |
| 323 | * @param nextObj the next Objective |
| 324 | */ |
| 325 | private void createL2InterfaceGroup(NextObjective nextObj) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 326 | VlanId assignedVlan = readVlanFromSelector(nextObj.meta()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 327 | if (assignedVlan == null) { |
| 328 | log.warn("VLAN ID required by simple next obj is missing. Abort."); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 329 | fail(nextObj, ObjectiveError.BADPARAMS); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 330 | return; |
| 331 | } |
| 332 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 333 | List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 334 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 335 | // There is only one L2 interface group in this case |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 336 | GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 337 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 338 | // Put all dependency information into allGroupKeys |
| 339 | List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList(); |
| 340 | Deque<GroupKey> gkeyChain = new ArrayDeque<>(); |
| 341 | gkeyChain.addFirst(l2InterfaceGroupDesc.appCookie()); |
| 342 | allGroupKeys.add(gkeyChain); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 343 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 344 | // Point the next objective to this group |
| 345 | OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj); |
| 346 | updatePendingNextObjective(l2InterfaceGroupDesc.appCookie(), ofdpaGrp); |
| 347 | |
| 348 | // Start installing the inner-most group |
| 349 | groupService.addGroup(l2InterfaceGroupDesc); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Creates one of two possible group-chains from the treatment |
| 354 | * passed in. Depending on the MPLS boolean, this method either creates |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 355 | * an L3Unicast Group --> L2Interface Group, if mpls is false; |
| 356 | * or MPLSInterface Group --> L2Interface Group, if mpls is true; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 357 | * The returned 'inner' group description is always the L2 Interface group. |
| 358 | * |
| 359 | * @param treatment that needs to be broken up to create the group chain |
| 360 | * @param nextId of the next objective that needs this group chain |
| 361 | * @param appId of the application that sent this next objective |
| 362 | * @param mpls determines if L3Unicast or MPLSInterface group is created |
| 363 | * @param meta metadata passed in by the application as part of the nextObjective |
| 364 | * @return GroupInfo containing the GroupDescription of the |
| 365 | * L2Interface group(inner) and the GroupDescription of the (outer) |
| 366 | * L3Unicast/MPLSInterface group. May return null if there is an |
| 367 | * error in processing the chain |
| 368 | */ |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 369 | protected GroupInfo createL2L3Chain(TrafficTreatment treatment, int nextId, |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 370 | ApplicationId appId, boolean mpls, |
| 371 | TrafficSelector meta) { |
| 372 | return createL2L3ChainInternal(treatment, nextId, appId, mpls, meta, true); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Internal implementation of createL2L3Chain. |
| 377 | * <p> |
| 378 | * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12. |
| 379 | * Since it is non-OF spec, we need an extension treatment for that. |
| 380 | * The useSetVlanExtension must be set to false for OFDPA i12. |
| 381 | * </p> |
| 382 | * |
| 383 | * @param treatment that needs to be broken up to create the group chain |
| 384 | * @param nextId of the next objective that needs this group chain |
| 385 | * @param appId of the application that sent this next objective |
| 386 | * @param mpls determines if L3Unicast or MPLSInterface group is created |
| 387 | * @param meta metadata passed in by the application as part of the nextObjective |
| 388 | * @param useSetVlanExtension use the setVlanVid extension that has is_present bit set to 0. |
| 389 | * @return GroupInfo containing the GroupDescription of the |
| 390 | * L2Interface group(inner) and the GroupDescription of the (outer) |
| 391 | * L3Unicast/MPLSInterface group. May return null if there is an |
| 392 | * error in processing the chain |
| 393 | */ |
| 394 | protected GroupInfo createL2L3ChainInternal(TrafficTreatment treatment, int nextId, |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 395 | ApplicationId appId, boolean mpls, |
| 396 | TrafficSelector meta, boolean useSetVlanExtension) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 397 | // for the l2interface group, get vlan and port info |
| 398 | // for the outer group, get the src/dst mac, and vlan info |
| 399 | TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder(); |
| 400 | TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder(); |
| 401 | VlanId vlanid = null; |
| 402 | long portNum = 0; |
| 403 | boolean setVlan = false, popVlan = false; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 404 | MacAddress srcMac; |
| 405 | MacAddress dstMac; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 406 | for (Instruction ins : treatment.allInstructions()) { |
| 407 | if (ins.type() == Instruction.Type.L2MODIFICATION) { |
| 408 | L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; |
| 409 | switch (l2ins.subtype()) { |
| 410 | case ETH_DST: |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 411 | dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac(); |
| 412 | outerTtb.setEthDst(dstMac); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 413 | break; |
| 414 | case ETH_SRC: |
Charles Chan | d0fd5dc | 2016-02-16 23:14:49 -0800 | [diff] [blame] | 415 | srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac(); |
| 416 | outerTtb.setEthSrc(srcMac); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 417 | break; |
| 418 | case VLAN_ID: |
| 419 | vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId(); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 420 | if (useSetVlanExtension) { |
| 421 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid); |
| 422 | outerTtb.extension(ofdpaSetVlanVid, deviceId); |
| 423 | } else { |
| 424 | outerTtb.setVlanId(vlanid); |
| 425 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 426 | setVlan = true; |
| 427 | break; |
| 428 | case VLAN_POP: |
| 429 | innerTtb.popVlan(); |
| 430 | popVlan = true; |
| 431 | break; |
| 432 | case DEC_MPLS_TTL: |
| 433 | case MPLS_LABEL: |
| 434 | case MPLS_POP: |
| 435 | case MPLS_PUSH: |
| 436 | case VLAN_PCP: |
| 437 | case VLAN_PUSH: |
| 438 | default: |
| 439 | break; |
| 440 | } |
| 441 | } else if (ins.type() == Instruction.Type.OUTPUT) { |
| 442 | portNum = ((Instructions.OutputInstruction) ins).port().toLong(); |
| 443 | innerTtb.add(ins); |
| 444 | } else { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 445 | log.debug("Driver does not handle this type of TrafficTreatment" |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 446 | + " instruction in nextObjectives: {}", ins.type()); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (vlanid == null && meta != null) { |
| 451 | // use metadata if available |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 452 | Criterion vidCriterion = meta.getCriterion(VLAN_VID); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 453 | if (vidCriterion != null) { |
| 454 | vlanid = ((VlanIdCriterion) vidCriterion).vlanId(); |
| 455 | } |
| 456 | // if vlan is not set, use the vlan in metadata for outerTtb |
| 457 | if (vlanid != null && !setVlan) { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 458 | if (useSetVlanExtension) { |
| 459 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid); |
| 460 | outerTtb.extension(ofdpaSetVlanVid, deviceId); |
| 461 | } else { |
| 462 | outerTtb.setVlanId(vlanid); |
| 463 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | if (vlanid == null) { |
| 468 | log.error("Driver cannot process an L2/L3 group chain without " |
| 469 | + "egress vlan information for dev: {} port:{}", |
| 470 | deviceId, portNum); |
| 471 | return null; |
| 472 | } |
| 473 | |
| 474 | if (!setVlan && !popVlan) { |
| 475 | // untagged outgoing port |
| 476 | TrafficTreatment.Builder temp = DefaultTrafficTreatment.builder(); |
| 477 | temp.popVlan(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 478 | innerTtb.build().allInstructions().forEach(temp::add); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 479 | innerTtb = temp; |
| 480 | } |
| 481 | |
| 482 | // assemble information for ofdpa l2interface group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 483 | int l2groupId = l2GroupId(vlanid, portNum); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 484 | // a globally unique groupkey that is different for ports in the same device, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 485 | // but different for the same portnumber on different devices. Also different |
| 486 | // for the various group-types created out of the same next objective. |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 487 | int l2gk = l2InterfaceGroupKey(deviceId, vlanid, portNum); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 488 | final GroupKey l2groupkey = new DefaultGroupKey(appKryo.serialize(l2gk)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 489 | |
| 490 | // assemble information for outer group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 491 | GroupDescription outerGrpDesc; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 492 | if (mpls) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 493 | // outer group is MPLS Interface |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 494 | int mplsInterfaceIndex = getNextAvailableIndex(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 495 | int mplsGroupId = MPLS_INTERFACE_TYPE | (SUBTYPE_MASK & mplsInterfaceIndex); |
| 496 | final GroupKey mplsGroupKey = new DefaultGroupKey( |
| 497 | appKryo.serialize(mplsInterfaceIndex)); |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 498 | outerTtb.group(new GroupId(l2groupId)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 499 | // create the mpls-interface group description to wait for the |
| 500 | // l2 interface group to be processed |
| 501 | GroupBucket mplsinterfaceGroupBucket = |
| 502 | DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build()); |
| 503 | outerGrpDesc = new DefaultGroupDescription( |
| 504 | deviceId, |
| 505 | GroupDescription.Type.INDIRECT, |
| 506 | new GroupBuckets(Collections.singletonList( |
| 507 | mplsinterfaceGroupBucket)), |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 508 | mplsGroupKey, |
| 509 | mplsGroupId, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 510 | appId); |
| 511 | log.debug("Trying MPLS-Interface: device:{} gid:{} gkey:{} nextid:{}", |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 512 | deviceId, Integer.toHexString(mplsGroupId), |
| 513 | mplsGroupKey, nextId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 514 | } else { |
| 515 | // outer group is L3Unicast |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 516 | int l3unicastIndex = getNextAvailableIndex(); |
| 517 | int l3groupId = L3_UNICAST_TYPE | (TYPE_MASK & l3unicastIndex); |
| 518 | final GroupKey l3groupkey = new DefaultGroupKey( |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 519 | appKryo.serialize(l3unicastIndex)); |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 520 | outerTtb.group(new GroupId(l2groupId)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 521 | // create the l3unicast group description to wait for the |
| 522 | // l2 interface group to be processed |
| 523 | GroupBucket l3unicastGroupBucket = |
| 524 | DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build()); |
| 525 | outerGrpDesc = new DefaultGroupDescription( |
| 526 | deviceId, |
| 527 | GroupDescription.Type.INDIRECT, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 528 | new GroupBuckets(Collections.singletonList(l3unicastGroupBucket)), |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 529 | l3groupkey, |
| 530 | l3groupId, |
| 531 | appId); |
| 532 | log.debug("Trying L3Unicast: device:{} gid:{} gkey:{} nextid:{}", |
| 533 | deviceId, Integer.toHexString(l3groupId), |
| 534 | l3groupkey, nextId); |
| 535 | } |
| 536 | |
| 537 | // store l2groupkey with the groupChainElem for the outer-group that depends on it |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 538 | GroupChainElem gce = new GroupChainElem(outerGrpDesc, 1, false, deviceId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 539 | updatePendingGroups(l2groupkey, gce); |
| 540 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 541 | // create group description for the inner l2 interface group |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 542 | GroupBucket l2InterfaceGroupBucket = |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 543 | DefaultGroupBucket.createIndirectGroupBucket(innerTtb.build()); |
| 544 | GroupDescription l2groupDescription = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 545 | new DefaultGroupDescription(deviceId, |
| 546 | GroupDescription.Type.INDIRECT, |
| 547 | new GroupBuckets(Collections.singletonList(l2InterfaceGroupBucket)), |
| 548 | l2groupkey, |
| 549 | l2groupId, |
| 550 | appId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 551 | log.debug("Trying L2Interface: device:{} gid:{} gkey:{} nextId:{}", |
| 552 | deviceId, Integer.toHexString(l2groupId), |
| 553 | l2groupkey, nextId); |
| 554 | return new GroupInfo(l2groupDescription, outerGrpDesc); |
| 555 | |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * As per the OFDPA 2.0 TTP, packets are sent out of ports by using |
| 560 | * a chain of groups. The broadcast Next Objective passed in by the application |
| 561 | * has to be broken up into a group chain comprising of an |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 562 | * L2 Flood group or L3 Multicast group, whose buckets point to L2 Interface groups. |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 563 | * |
| 564 | * @param nextObj the nextObjective of type BROADCAST |
| 565 | */ |
| 566 | private void processBroadcastNextObjective(NextObjective nextObj) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 567 | VlanId assignedVlan = readVlanFromSelector(nextObj.meta()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 568 | if (assignedVlan == null) { |
| 569 | log.warn("VLAN ID required by broadcast next obj is missing. Abort."); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 570 | fail(nextObj, ObjectiveError.BADPARAMS); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 571 | return; |
| 572 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 573 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 574 | List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan); |
| 575 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 576 | IpPrefix ipDst = readIpDstFromSelector(nextObj.meta()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 577 | if (ipDst != null) { |
| 578 | if (ipDst.isMulticast()) { |
| 579 | createL3MulticastGroup(nextObj, assignedVlan, groupInfos); |
| 580 | } else { |
| 581 | log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 582 | fail(nextObj, ObjectiveError.BADPARAMS); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 583 | } |
| 584 | } else { |
| 585 | createL2FloodGroup(nextObj, assignedVlan, groupInfos); |
| 586 | } |
| 587 | } |
| 588 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 589 | private List<GroupInfo> prepareL2InterfaceGroup(NextObjective nextObj, |
| 590 | VlanId assignedVlan) { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 591 | ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder(); |
| 592 | |
| 593 | // break up broadcast next objective to multiple groups |
| 594 | Collection<TrafficTreatment> buckets = nextObj.next(); |
| 595 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 596 | // each treatment is converted to an L2 interface group |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 597 | for (TrafficTreatment treatment : buckets) { |
| 598 | TrafficTreatment.Builder newTreatment = DefaultTrafficTreatment.builder(); |
| 599 | PortNumber portNum = null; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 600 | VlanId egressVlan = null; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 601 | // ensure that the only allowed treatments are pop-vlan and output |
| 602 | for (Instruction ins : treatment.allInstructions()) { |
| 603 | if (ins.type() == Instruction.Type.L2MODIFICATION) { |
| 604 | L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; |
| 605 | switch (l2ins.subtype()) { |
| 606 | case VLAN_POP: |
| 607 | newTreatment.add(l2ins); |
| 608 | break; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 609 | case VLAN_ID: |
| 610 | egressVlan = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId(); |
| 611 | break; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 612 | default: |
| 613 | log.debug("action {} not permitted for broadcast nextObj", |
| 614 | l2ins.subtype()); |
| 615 | break; |
| 616 | } |
| 617 | } else if (ins.type() == Instruction.Type.OUTPUT) { |
| 618 | portNum = ((Instructions.OutputInstruction) ins).port(); |
| 619 | newTreatment.add(ins); |
| 620 | } else { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 621 | log.debug("TrafficTreatment of type {} not permitted in " + |
| 622 | " broadcast nextObjective", ins.type()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 626 | if (portNum == null) { |
| 627 | log.warn("Can't find output port for the bucket {}.", treatment); |
| 628 | continue; |
| 629 | } |
| 630 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 631 | // assemble info for l2 interface group |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 632 | VlanId l2InterfaceGroupVlan = |
| 633 | (egressVlan != null && !assignedVlan.equals(egressVlan)) ? |
| 634 | egressVlan : assignedVlan; |
| 635 | int l2gk = l2InterfaceGroupKey(deviceId, l2InterfaceGroupVlan, portNum.toLong()); |
| 636 | final GroupKey l2InterfaceGroupKey = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 637 | new DefaultGroupKey(appKryo.serialize(l2gk)); |
Charles Chan | 372b63e | 2017-02-07 12:10:53 -0800 | [diff] [blame] | 638 | int l2InterfaceGroupId = L2_INTERFACE_TYPE | |
| 639 | ((l2InterfaceGroupVlan.toShort() & THREE_BIT_MASK) << PORT_LEN) | |
| 640 | ((int) portNum.toLong() & FOUR_BIT_MASK); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 641 | GroupBucket l2InterfaceGroupBucket = |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 642 | DefaultGroupBucket.createIndirectGroupBucket(newTreatment.build()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 643 | GroupDescription l2InterfaceGroupDescription = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 644 | new DefaultGroupDescription(deviceId, |
| 645 | GroupDescription.Type.INDIRECT, |
| 646 | new GroupBuckets(Collections.singletonList( |
| 647 | l2InterfaceGroupBucket)), |
| 648 | l2InterfaceGroupKey, |
| 649 | l2InterfaceGroupId, |
| 650 | nextObj.appId()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 651 | log.debug("Trying L2-Interface: device:{} gid:{} gkey:{} nextid:{}", |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 652 | deviceId, Integer.toHexString(l2InterfaceGroupId), |
| 653 | l2InterfaceGroupKey, nextObj.id()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 654 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 655 | groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDescription, |
| 656 | l2InterfaceGroupDescription)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 657 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 658 | return groupInfoBuilder.build(); |
| 659 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 660 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 661 | private void createL2FloodGroup(NextObjective nextObj, VlanId vlanId, |
| 662 | List<GroupInfo> groupInfos) { |
| 663 | // assemble info for l2 flood group. Since there can be only one flood |
| 664 | // group for a vlan, its index is always the same - 0 |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 665 | Integer l2FloodGroupId = L2_FLOOD_TYPE | (vlanId.toShort() << 16); |
| 666 | final GroupKey l2FloodGroupKey = l2FloodGroupKey(vlanId, deviceId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 667 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 668 | // collection of group buckets pointing to all the l2 interface groups |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 669 | List<GroupBucket> l2floodBuckets = generateNextGroupBuckets(groupInfos, ALL); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 670 | // create the l2flood group-description to wait for all the |
| 671 | // l2interface groups to be processed |
| 672 | GroupDescription l2floodGroupDescription = |
| 673 | new DefaultGroupDescription( |
| 674 | deviceId, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 675 | ALL, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 676 | new GroupBuckets(l2floodBuckets), |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 677 | l2FloodGroupKey, |
| 678 | l2FloodGroupId, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 679 | nextObj.appId()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 680 | log.debug("Trying L2-Flood: device:{} gid:{} gkey:{} nextid:{}", |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 681 | deviceId, Integer.toHexString(l2FloodGroupId), |
| 682 | l2FloodGroupKey, nextObj.id()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 683 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 684 | // Put all dependency information into allGroupKeys |
| 685 | List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList(); |
| 686 | groupInfos.forEach(groupInfo -> { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 687 | Deque<GroupKey> groupKeyChain = new ArrayDeque<>(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 688 | // In this case we should have L2 interface group only |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 689 | groupKeyChain.addFirst(groupInfo.nextGroupDesc().appCookie()); |
| 690 | groupKeyChain.addFirst(l2FloodGroupKey); |
| 691 | allGroupKeys.add(groupKeyChain); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 692 | }); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 693 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 694 | // Point the next objective to this group |
| 695 | OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 696 | updatePendingNextObjective(l2FloodGroupKey, ofdpaGrp); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 697 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 698 | GroupChainElem gce = new GroupChainElem(l2floodGroupDescription, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 699 | groupInfos.size(), false, deviceId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 700 | groupInfos.forEach(groupInfo -> { |
| 701 | // Point this group to the next group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 702 | updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), gce); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 703 | // Start installing the inner-most group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 704 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 705 | }); |
| 706 | } |
| 707 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 708 | private void createL3MulticastGroup(NextObjective nextObj, VlanId vlanId, |
| 709 | List<GroupInfo> groupInfos) { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 710 | List<GroupBucket> l3McastBuckets = new ArrayList<>(); |
| 711 | groupInfos.forEach(groupInfo -> { |
| 712 | // Points to L3 interface group if there is one. |
| 713 | // Otherwise points to L2 interface group directly. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 714 | GroupDescription nextGroupDesc = (groupInfo.nextGroupDesc() != null) ? |
| 715 | groupInfo.nextGroupDesc() : groupInfo.innerMostGroupDesc(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 716 | TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder(); |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 717 | ttb.group(new GroupId(nextGroupDesc.givenGroupId())); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 718 | GroupBucket abucket = DefaultGroupBucket.createAllGroupBucket(ttb.build()); |
| 719 | l3McastBuckets.add(abucket); |
| 720 | }); |
| 721 | |
| 722 | int l3MulticastIndex = getNextAvailableIndex(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 723 | int l3MulticastGroupId = L3_MULTICAST_TYPE | |
| 724 | vlanId.toShort() << 16 | (TYPE_VLAN_MASK & l3MulticastIndex); |
| 725 | final GroupKey l3MulticastGroupKey = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 726 | new DefaultGroupKey(appKryo.serialize(l3MulticastIndex)); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 727 | |
| 728 | GroupDescription l3MulticastGroupDesc = new DefaultGroupDescription(deviceId, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 729 | ALL, |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 730 | new GroupBuckets(l3McastBuckets), |
| 731 | l3MulticastGroupKey, |
| 732 | l3MulticastGroupId, |
| 733 | nextObj.appId()); |
| 734 | |
| 735 | // Put all dependency information into allGroupKeys |
| 736 | List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList(); |
| 737 | groupInfos.forEach(groupInfo -> { |
| 738 | Deque<GroupKey> gkeyChain = new ArrayDeque<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 739 | gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 740 | // Add L3 interface group to the chain if there is one. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 741 | if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) { |
| 742 | gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 743 | } |
| 744 | gkeyChain.addFirst(l3MulticastGroupKey); |
| 745 | allGroupKeys.add(gkeyChain); |
| 746 | }); |
| 747 | |
| 748 | // Point the next objective to this group |
| 749 | OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj); |
| 750 | updatePendingNextObjective(l3MulticastGroupKey, ofdpaGrp); |
| 751 | |
| 752 | GroupChainElem outerGce = new GroupChainElem(l3MulticastGroupDesc, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 753 | groupInfos.size(), false, deviceId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 754 | groupInfos.forEach(groupInfo -> { |
| 755 | // Point this group (L3 multicast) to the next group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 756 | updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), outerGce); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 757 | |
| 758 | // Point next group to inner-most group, if any |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 759 | if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) { |
| 760 | GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(), |
| 761 | 1, false, deviceId); |
| 762 | updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Start installing the inner-most group |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 766 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 767 | }); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 770 | /** |
| 771 | * As per the OFDPA 2.0 TTP, packets are sent out of ports by using |
| 772 | * a chain of groups. The hashed Next Objective passed in by the application |
| 773 | * has to be broken up into a group chain comprising of an |
| 774 | * L3 ECMP group as the top level group. Buckets of this group can point |
| 775 | * to a variety of groups in a group chain, depending on the whether |
| 776 | * MPLS labels are being pushed or not. |
| 777 | * <p> |
| 778 | * NOTE: We do not create MPLS ECMP groups as they are unimplemented in |
| 779 | * OF-DPA 2.0 (even though it is in the spec). Therefore we do not |
| 780 | * check the nextObjective meta to see what is matching before being |
| 781 | * sent to this nextObjective. |
| 782 | * |
| 783 | * @param nextObj the nextObjective of type HASHED |
| 784 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 785 | protected void processHashedNextObjective(NextObjective nextObj) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 786 | // storage for all group keys in the chain of groups created |
| 787 | List<Deque<GroupKey>> allGroupKeys = new ArrayList<>(); |
| 788 | List<GroupInfo> unsentGroups = new ArrayList<>(); |
| 789 | createHashBucketChains(nextObj, allGroupKeys, unsentGroups); |
| 790 | |
| 791 | // now we can create the outermost L3 ECMP group |
| 792 | List<GroupBucket> l3ecmpGroupBuckets = new ArrayList<>(); |
| 793 | for (GroupInfo gi : unsentGroups) { |
| 794 | // create ECMP bucket to point to the outer group |
| 795 | TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 796 | ttb.group(new GroupId(gi.nextGroupDesc().givenGroupId())); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 797 | GroupBucket sbucket = DefaultGroupBucket |
| 798 | .createSelectGroupBucket(ttb.build()); |
| 799 | l3ecmpGroupBuckets.add(sbucket); |
| 800 | } |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 801 | int l3ecmpIndex = getNextAvailableIndex(); |
| 802 | int l3ecmpGroupId = L3_ECMP_TYPE | (TYPE_MASK & l3ecmpIndex); |
| 803 | GroupKey l3ecmpGroupKey = new DefaultGroupKey( |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 804 | appKryo.serialize(l3ecmpIndex)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 805 | GroupDescription l3ecmpGroupDesc = |
| 806 | new DefaultGroupDescription( |
| 807 | deviceId, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 808 | SELECT, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 809 | new GroupBuckets(l3ecmpGroupBuckets), |
| 810 | l3ecmpGroupKey, |
| 811 | l3ecmpGroupId, |
| 812 | nextObj.appId()); |
| 813 | GroupChainElem l3ecmpGce = new GroupChainElem(l3ecmpGroupDesc, |
| 814 | l3ecmpGroupBuckets.size(), |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 815 | false, deviceId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 816 | |
| 817 | // create objects for local and distributed storage |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 818 | allGroupKeys.forEach(gKeyChain -> gKeyChain.addFirst(l3ecmpGroupKey)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 819 | OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj); |
| 820 | |
| 821 | // store l3ecmpGroupKey with the ofdpaGroupChain for the nextObjective |
| 822 | // that depends on it |
| 823 | updatePendingNextObjective(l3ecmpGroupKey, ofdpaGrp); |
| 824 | |
| 825 | log.debug("Trying L3ECMP: device:{} gid:{} gkey:{} nextId:{}", |
| 826 | deviceId, Integer.toHexString(l3ecmpGroupId), |
| 827 | l3ecmpGroupKey, nextObj.id()); |
| 828 | // finally we are ready to send the innermost groups |
| 829 | for (GroupInfo gi : unsentGroups) { |
| 830 | log.debug("Sending innermost group {} in group chain on device {} ", |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 831 | Integer.toHexString(gi.innerMostGroupDesc().givenGroupId()), deviceId); |
| 832 | updatePendingGroups(gi.nextGroupDesc().appCookie(), l3ecmpGce); |
| 833 | groupService.addGroup(gi.innerMostGroupDesc()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 834 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Creates group chains for all buckets in a hashed group, and stores the |
| 839 | * GroupInfos and GroupKeys for all the groups in the lists passed in, which |
| 840 | * should be empty. |
| 841 | * <p> |
| 842 | * Does not create the top level ECMP group. Does not actually send the |
| 843 | * groups to the groupService. |
| 844 | * |
| 845 | * @param nextObj the Next Objective with buckets that need to be converted |
| 846 | * to group chains |
| 847 | * @param allGroupKeys a list to store groupKey for each bucket-group-chain |
| 848 | * @param unsentGroups a list to store GroupInfo for each bucket-group-chain |
| 849 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 850 | protected void createHashBucketChains(NextObjective nextObj, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 851 | List<Deque<GroupKey>> allGroupKeys, |
| 852 | List<GroupInfo> unsentGroups) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 853 | // break up hashed next objective to multiple groups |
| 854 | Collection<TrafficTreatment> buckets = nextObj.next(); |
| 855 | |
| 856 | for (TrafficTreatment bucket : buckets) { |
| 857 | //figure out how many labels are pushed in each bucket |
| 858 | int labelsPushed = 0; |
| 859 | MplsLabel innermostLabel = null; |
| 860 | for (Instruction ins : bucket.allInstructions()) { |
| 861 | if (ins.type() == Instruction.Type.L2MODIFICATION) { |
| 862 | L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; |
| 863 | if (l2ins.subtype() == L2ModificationInstruction.L2SubType.MPLS_PUSH) { |
| 864 | labelsPushed++; |
| 865 | } |
| 866 | if (l2ins.subtype() == L2ModificationInstruction.L2SubType.MPLS_LABEL) { |
| 867 | if (innermostLabel == null) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 868 | innermostLabel = |
| 869 | ((L2ModificationInstruction.ModMplsLabelInstruction) l2ins).label(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 875 | Deque<GroupKey> gKeyChain = new ArrayDeque<>(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 876 | // XXX we only deal with 0 and 1 label push right now |
| 877 | if (labelsPushed == 0) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 878 | GroupInfo noLabelGroupInfo; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 879 | TrafficSelector metaSelector = nextObj.meta(); |
| 880 | if (metaSelector != null) { |
| 881 | if (isNotMplsBos(metaSelector)) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 882 | noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(), |
| 883 | nextObj.appId(), true, |
| 884 | nextObj.meta()); |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 885 | } else { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 886 | noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(), |
| 887 | nextObj.appId(), false, |
| 888 | nextObj.meta()); |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 889 | } |
| 890 | } else { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 891 | noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(), |
| 892 | nextObj.appId(), false, |
| 893 | nextObj.meta()); |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 894 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 895 | if (noLabelGroupInfo == null) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 896 | log.error("Could not process nextObj={} in dev:{}", |
| 897 | nextObj.id(), deviceId); |
| 898 | return; |
| 899 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 900 | gKeyChain.addFirst(noLabelGroupInfo.innerMostGroupDesc().appCookie()); |
| 901 | gKeyChain.addFirst(noLabelGroupInfo.nextGroupDesc().appCookie()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 902 | |
| 903 | // we can't send the inner group description yet, as we have to |
| 904 | // create the dependent ECMP group first. So we store.. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 905 | unsentGroups.add(noLabelGroupInfo); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 906 | |
| 907 | } else if (labelsPushed == 1) { |
| 908 | GroupInfo onelabelGroupInfo = createL2L3Chain(bucket, nextObj.id(), |
| 909 | nextObj.appId(), true, |
| 910 | nextObj.meta()); |
| 911 | if (onelabelGroupInfo == null) { |
| 912 | log.error("Could not process nextObj={} in dev:{}", |
| 913 | nextObj.id(), deviceId); |
| 914 | return; |
| 915 | } |
| 916 | // we need to add another group to this chain - the L3VPN group |
| 917 | TrafficTreatment.Builder l3vpnTtb = DefaultTrafficTreatment.builder(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 918 | if (requireVlanPopBeforeMplsPush()) { |
| 919 | l3vpnTtb.popVlan(); |
| 920 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 921 | l3vpnTtb.pushMpls() |
| 922 | .setMpls(innermostLabel) |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 923 | .group(new GroupId(onelabelGroupInfo.nextGroupDesc().givenGroupId())); |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 924 | if (supportCopyTtl()) { |
| 925 | l3vpnTtb.copyTtlOut(); |
| 926 | } |
| 927 | if (supportSetMplsBos()) { |
| 928 | l3vpnTtb.setMplsBos(true); |
| 929 | } |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 930 | if (requireVlanPopBeforeMplsPush()) { |
| 931 | l3vpnTtb.pushVlan().setVlanId(VlanId.vlanId(VlanId.RESERVED)); |
| 932 | } |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 933 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 934 | GroupBucket l3vpnGrpBkt = |
| 935 | DefaultGroupBucket.createIndirectGroupBucket(l3vpnTtb.build()); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 936 | int l3vpnIndex = getNextAvailableIndex(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 937 | int l3vpnGroupId = MPLS_L3VPN_SUBTYPE | (SUBTYPE_MASK & l3vpnIndex); |
| 938 | GroupKey l3vpnGroupKey = new DefaultGroupKey( |
| 939 | appKryo.serialize(l3vpnIndex)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 940 | GroupDescription l3vpnGroupDesc = |
| 941 | new DefaultGroupDescription( |
| 942 | deviceId, |
| 943 | GroupDescription.Type.INDIRECT, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 944 | new GroupBuckets(Collections.singletonList(l3vpnGrpBkt)), |
| 945 | l3vpnGroupKey, |
| 946 | l3vpnGroupId, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 947 | nextObj.appId()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 948 | GroupChainElem l3vpnGce = new GroupChainElem(l3vpnGroupDesc, |
| 949 | 1, |
| 950 | false, |
| 951 | deviceId); |
| 952 | updatePendingGroups(onelabelGroupInfo.nextGroupDesc().appCookie(), l3vpnGce); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 953 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 954 | gKeyChain.addFirst(onelabelGroupInfo.innerMostGroupDesc().appCookie()); |
| 955 | gKeyChain.addFirst(onelabelGroupInfo.nextGroupDesc().appCookie()); |
| 956 | gKeyChain.addFirst(l3vpnGroupKey); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 957 | |
| 958 | //now we can replace the outerGrpDesc with the one we just created |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 959 | onelabelGroupInfo.nextGroupDesc(l3vpnGroupDesc); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 960 | |
| 961 | // we can't send the innermost group yet, as we have to create |
| 962 | // the dependent ECMP group first. So we store ... |
| 963 | unsentGroups.add(onelabelGroupInfo); |
| 964 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 965 | log.debug("Trying L3VPN: device:{} gid:{} group key:{} nextId:{}", |
| 966 | deviceId, Integer.toHexString(l3vpnGroupId), |
| 967 | l3vpnGroupKey, nextObj.id()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 968 | |
| 969 | } else { |
| 970 | log.warn("Driver currently does not handle more than 1 MPLS " |
| 971 | + "labels. Not processing nextObjective {}", nextObj.id()); |
| 972 | return; |
| 973 | } |
| 974 | |
| 975 | // all groups in this chain |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 976 | allGroupKeys.add(gKeyChain); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 980 | /** |
| 981 | * Processes the pseudo wire related next objective. |
| 982 | * This procedure try to reuse the mpls label groups, |
| 983 | * the mpls interface group and the l2 interface group. |
| 984 | * |
| 985 | * @param nextObjective the objective to process. |
| 986 | */ |
| 987 | protected void processPwNextObjective(NextObjective nextObjective) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 988 | log.warn("Pseudo wire extensions are not supported in OFDPA 2.0 {}", |
| 989 | nextObjective.id()); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 990 | } |
| 991 | |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 992 | ////////////////////////////////////// |
| 993 | // Group Editing |
| 994 | ////////////////////////////////////// |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 995 | /** |
| 996 | * Adds a bucket to the top level group of a group-chain, and creates the chain. |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 997 | * Ensures that bucket being added is not a duplicate, by checking existing |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 998 | * buckets for the same output port. |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 999 | * |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1000 | * @param nextObjective the bucket information for a next group |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1001 | * @param next the representation of the existing group-chain for this next objective |
| 1002 | */ |
| 1003 | protected void addBucketToGroup(NextObjective nextObjective, NextGroup next) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1004 | if (nextObjective.type() != NextObjective.Type.HASHED && |
| 1005 | nextObjective.type() != NextObjective.Type.BROADCAST) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1006 | log.warn("AddBuckets not applied to nextType:{} in dev:{} for next:{}", |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1007 | nextObjective.type(), deviceId, nextObjective.id()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1008 | fail(nextObjective, ObjectiveError.UNSUPPORTED); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1009 | return; |
| 1010 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1011 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1012 | // first check to see if bucket being added is not a duplicate of an |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1013 | // existing bucket. If it is for an existing output port, then its a |
| 1014 | // duplicate. |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1015 | Set<TrafficTreatment> duplicateBuckets = Sets.newHashSet(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1016 | List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); |
| 1017 | Set<PortNumber> existingPorts = getExistingOutputPorts(allActiveKeys, |
| 1018 | groupService, |
| 1019 | deviceId); |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 1020 | Set<TrafficTreatment> nonDuplicateBuckets = Sets.newHashSet(); |
| 1021 | NextObjective objectiveToAdd; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1022 | |
| 1023 | nextObjective.next().forEach(trafficTreatment -> { |
| 1024 | PortNumber portNumber = readOutPortFromTreatment(trafficTreatment); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1025 | if (portNumber == null) { |
| 1026 | return; |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1027 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1028 | if (existingPorts.contains(portNumber)) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1029 | // its possible that portnumbers are same but labels are different |
| 1030 | int label = readLabelFromTreatment(trafficTreatment); |
| 1031 | if (label == -1) { |
| 1032 | duplicateBuckets.add(trafficTreatment); |
| 1033 | } else { |
| 1034 | boolean exists = existingPortAndLabel(allActiveKeys, groupService, |
| 1035 | deviceId, portNumber, label); |
| 1036 | if (exists) { |
| 1037 | duplicateBuckets.add(trafficTreatment); |
| 1038 | } else { |
| 1039 | nonDuplicateBuckets.add(trafficTreatment); |
| 1040 | } |
| 1041 | } |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 1042 | } else { |
| 1043 | nonDuplicateBuckets.add(trafficTreatment); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1044 | } |
| 1045 | }); |
| 1046 | |
Saurav Das | b28d5dd | 2017-03-24 19:03:58 -0700 | [diff] [blame] | 1047 | if (duplicateBuckets.isEmpty()) { |
| 1048 | // use the original objective |
| 1049 | objectiveToAdd = nextObjective; |
| 1050 | } else if (!nonDuplicateBuckets.isEmpty()) { |
| 1051 | // only use the non-duplicate buckets if there are any |
| 1052 | log.debug("Some buckets {} already exist in next id {}, duplicate " |
| 1053 | + "buckets will be ignored.", duplicateBuckets, nextObjective.id()); |
| 1054 | // new next objective with non duplicate treatments |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 1055 | NextObjective.Builder builder = DefaultNextObjective.builder() |
| 1056 | .withType(nextObjective.type()) |
| 1057 | .withId(nextObjective.id()) |
| 1058 | .withMeta(nextObjective.meta()) |
| 1059 | .fromApp(nextObjective.appId()); |
| 1060 | nonDuplicateBuckets.forEach(builder::addTreatment); |
| 1061 | |
| 1062 | ObjectiveContext context = nextObjective.context().orElse(null); |
| 1063 | objectiveToAdd = builder.addToExisting(context); |
| 1064 | } else { |
Saurav Das | b28d5dd | 2017-03-24 19:03:58 -0700 | [diff] [blame] | 1065 | // buckets to add are already there - nothing to do |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1066 | log.debug("buckets already exist {} in next: {} ..ignoring bucket add", |
| 1067 | duplicateBuckets, nextObjective.id()); |
| 1068 | pass(nextObjective); |
Saurav Das | b28d5dd | 2017-03-24 19:03:58 -0700 | [diff] [blame] | 1069 | return; |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1070 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1071 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1072 | if (nextObjective.type() == NextObjective.Type.HASHED) { |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 1073 | addBucketToHashGroup(objectiveToAdd, allActiveKeys); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1074 | } else if (nextObjective.type() == NextObjective.Type.BROADCAST) { |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 1075 | addBucketToBroadcastGroup(objectiveToAdd, allActiveKeys); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1078 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1079 | private void addBucketToHashGroup(NextObjective nextObjective, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1080 | List<Deque<GroupKey>> allActiveKeys) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1081 | // storage for all group keys in the chain of groups created |
| 1082 | List<Deque<GroupKey>> allGroupKeys = new ArrayList<>(); |
| 1083 | List<GroupInfo> unsentGroups = new ArrayList<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1084 | List<GroupBucket> newBuckets; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1085 | createHashBucketChains(nextObjective, allGroupKeys, unsentGroups); |
| 1086 | |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1087 | // now we can create the buckets to add to the outermost L3 ECMP group |
| 1088 | newBuckets = generateNextGroupBuckets(unsentGroups, SELECT); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1089 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1090 | // retrieve the original L3 ECMP group |
| 1091 | Group l3ecmpGroup = retrieveTopLevelGroup(allActiveKeys, nextObjective.id()); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1092 | if (l3ecmpGroup == null) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1093 | fail(nextObjective, ObjectiveError.GROUPMISSING); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1094 | return; |
| 1095 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1096 | GroupKey l3ecmpGroupKey = l3ecmpGroup.appCookie(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1097 | int l3ecmpGroupId = l3ecmpGroup.id().id(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1098 | |
| 1099 | // Although GroupDescriptions are not necessary for adding buckets to |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1100 | // existing groups, we still use one in the GroupChainElem. When the latter is |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1101 | // processed, the info will be extracted for the bucketAdd call to groupService |
| 1102 | GroupDescription l3ecmpGroupDesc = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1103 | new DefaultGroupDescription(deviceId, |
| 1104 | SELECT, |
| 1105 | new GroupBuckets(newBuckets), |
| 1106 | l3ecmpGroupKey, |
| 1107 | l3ecmpGroupId, |
| 1108 | nextObjective.appId()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1109 | GroupChainElem l3ecmpGce = new GroupChainElem(l3ecmpGroupDesc, |
| 1110 | unsentGroups.size(), |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1111 | true, |
| 1112 | deviceId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1113 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1114 | // update new bucket-chains |
| 1115 | List<Deque<GroupKey>> addedKeys = new ArrayList<>(); |
| 1116 | for (Deque<GroupKey> newBucketChain : allGroupKeys) { |
| 1117 | newBucketChain.addFirst(l3ecmpGroupKey); |
| 1118 | addedKeys.add(newBucketChain); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1119 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1120 | updatePendingNextObjective(l3ecmpGroupKey, |
| 1121 | new OfdpaNextGroup(addedKeys, nextObjective)); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1122 | log.debug("Adding to L3ECMP: device:{} gid:{} group key:{} nextId:{}", |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1123 | deviceId, Integer.toHexString(l3ecmpGroupId), |
| 1124 | l3ecmpGroupKey, nextObjective.id()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1125 | |
| 1126 | unsentGroups.forEach(groupInfo -> { |
| 1127 | // send the innermost group |
| 1128 | log.debug("Sending innermost group {} in group chain on device {} ", |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1129 | Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()), |
| 1130 | deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1131 | updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3ecmpGce); |
| 1132 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1133 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1134 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1135 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1136 | private void addBucketToBroadcastGroup(NextObjective nextObj, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1137 | List<Deque<GroupKey>> allActiveKeys) { |
| 1138 | VlanId assignedVlan = readVlanFromSelector(nextObj.meta()); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1139 | if (assignedVlan == null) { |
| 1140 | log.warn("VLAN ID required by broadcast next obj is missing. " |
| 1141 | + "Aborting add bucket to broadcast group for next:{} in dev:{}", |
| 1142 | nextObj.id(), deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1143 | fail(nextObj, ObjectiveError.BADPARAMS); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1144 | return; |
| 1145 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1146 | List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1147 | IpPrefix ipDst = readIpDstFromSelector(nextObj.meta()); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1148 | if (ipDst != null) { |
| 1149 | if (ipDst.isMulticast()) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1150 | addBucketToL3MulticastGroup(nextObj, allActiveKeys, groupInfos, assignedVlan); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1151 | } else { |
| 1152 | log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1153 | fail(nextObj, ObjectiveError.BADPARAMS); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } else { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1156 | addBucketToL2FloodGroup(nextObj, allActiveKeys, groupInfos, assignedVlan); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | private void addBucketToL2FloodGroup(NextObjective nextObj, |
| 1161 | List<Deque<GroupKey>> allActiveKeys, |
| 1162 | List<GroupInfo> groupInfos, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1163 | VlanId assignedVlan) { |
| 1164 | Group l2FloodGroup = retrieveTopLevelGroup(allActiveKeys, nextObj.id()); |
| 1165 | |
| 1166 | if (l2FloodGroup == null) { |
| 1167 | log.warn("Can't find L2 flood group while adding bucket to it. NextObj = {}", |
| 1168 | nextObj); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1169 | fail(nextObj, ObjectiveError.GROUPMISSING); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1170 | return; |
| 1171 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1172 | |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1173 | GroupKey l2floodGroupKey = l2FloodGroup.appCookie(); |
| 1174 | int l2floodGroupId = l2FloodGroup.id().id(); |
| 1175 | List<GroupBucket> newBuckets = generateNextGroupBuckets(groupInfos, ALL); |
| 1176 | |
| 1177 | GroupDescription l2FloodGroupDescription = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1178 | new DefaultGroupDescription(deviceId, |
| 1179 | ALL, |
| 1180 | new GroupBuckets(newBuckets), |
| 1181 | l2floodGroupKey, |
| 1182 | l2floodGroupId, |
| 1183 | nextObj.appId()); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1184 | |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1185 | GroupChainElem l2FloodGroupChainElement = |
| 1186 | new GroupChainElem(l2FloodGroupDescription, |
| 1187 | groupInfos.size(), |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1188 | true, |
| 1189 | deviceId); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1190 | |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1191 | |
| 1192 | //ensure assignedVlan applies to the chosen group |
| 1193 | VlanId floodGroupVlan = extractVlanIdFromGroupId(l2floodGroupId); |
| 1194 | |
| 1195 | if (!floodGroupVlan.equals(assignedVlan)) { |
| 1196 | log.warn("VLAN ID {} does not match Flood group {} to which bucket is " |
| 1197 | + "being added, for next:{} in dev:{}. Abort.", assignedVlan, |
| 1198 | Integer.toHexString(l2floodGroupId), nextObj.id(), deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1199 | fail(nextObj, ObjectiveError.BADPARAMS); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1200 | return; |
| 1201 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1202 | List<Deque<GroupKey>> addedKeys = new ArrayList<>(); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1203 | groupInfos.forEach(groupInfo -> { |
| 1204 | // update original NextGroup with new bucket-chain |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1205 | Deque<GroupKey> newBucketChain = new ArrayDeque<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1206 | newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1207 | newBucketChain.addFirst(l2floodGroupKey); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1208 | addedKeys.add(newBucketChain); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1209 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1210 | log.debug("Adding to L2FLOOD: device:{} gid:{} group key:{} nextId:{}", |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1211 | deviceId, Integer.toHexString(l2floodGroupId), |
| 1212 | l2floodGroupKey, nextObj.id()); |
| 1213 | // send the innermost group |
| 1214 | log.debug("Sending innermost group {} in group chain on device {} ", |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1215 | Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()), |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1216 | deviceId); |
| 1217 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1218 | updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l2FloodGroupChainElement); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1219 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1220 | DeviceId innerMostGroupDevice = groupInfo.innerMostGroupDesc().deviceId(); |
| 1221 | GroupKey innerMostGroupKey = groupInfo.innerMostGroupDesc().appCookie(); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1222 | Group existsL2IGroup = groupService.getGroup(innerMostGroupDevice, innerMostGroupKey); |
| 1223 | |
| 1224 | if (existsL2IGroup != null) { |
| 1225 | // group already exist |
| 1226 | processPendingAddGroupsOrNextObjs(innerMostGroupKey, true); |
| 1227 | } else { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1228 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1229 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1230 | }); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1231 | |
| 1232 | updatePendingNextObjective(l2floodGroupKey, |
| 1233 | new OfdpaNextGroup(addedKeys, nextObj)); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1236 | private void addBucketToL3MulticastGroup(NextObjective nextObj, |
| 1237 | List<Deque<GroupKey>> allActiveKeys, |
| 1238 | List<GroupInfo> groupInfos, |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1239 | VlanId assignedVlan) { |
| 1240 | // create the buckets to add to the outermost L3 Multicast group |
| 1241 | List<GroupBucket> newBuckets = Lists.newArrayList(); |
| 1242 | groupInfos.forEach(groupInfo -> { |
| 1243 | // Points to L3 interface group if there is one. |
| 1244 | // Otherwise points to L2 interface group directly. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1245 | GroupDescription nextGroupDesc = (groupInfo.nextGroupDesc() != null) ? |
| 1246 | groupInfo.nextGroupDesc() : groupInfo.innerMostGroupDesc(); |
| 1247 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1248 | treatmentBuilder.group(new GroupId(nextGroupDesc.givenGroupId())); |
| 1249 | GroupBucket newBucket = DefaultGroupBucket.createAllGroupBucket(treatmentBuilder.build()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1250 | newBuckets.add(newBucket); |
| 1251 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1252 | |
| 1253 | // get the group being edited |
| 1254 | Group l3mcastGroup = retrieveTopLevelGroup(allActiveKeys, nextObj.id()); |
| 1255 | if (l3mcastGroup == null) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1256 | fail(nextObj, ObjectiveError.GROUPMISSING); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1257 | return; |
| 1258 | } |
| 1259 | GroupKey l3mcastGroupKey = l3mcastGroup.appCookie(); |
| 1260 | int l3mcastGroupId = l3mcastGroup.id().id(); |
| 1261 | |
| 1262 | //ensure assignedVlan applies to the chosen group |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1263 | VlanId expectedVlan = extractVlanIdFromGroupId(l3mcastGroupId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1264 | if (!expectedVlan.equals(assignedVlan)) { |
| 1265 | log.warn("VLAN ID {} does not match L3 Mcast group {} to which bucket is " |
| 1266 | + "being added, for next:{} in dev:{}. Abort.", assignedVlan, |
| 1267 | Integer.toHexString(l3mcastGroupId), nextObj.id(), deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1268 | fail(nextObj, ObjectiveError.BADPARAMS); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1269 | } |
| 1270 | GroupDescription l3mcastGroupDescription = |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1271 | new DefaultGroupDescription(deviceId, |
| 1272 | ALL, |
| 1273 | new GroupBuckets(newBuckets), |
| 1274 | l3mcastGroupKey, |
| 1275 | l3mcastGroupId, |
| 1276 | nextObj.appId()); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1277 | GroupChainElem l3mcastGce = new GroupChainElem(l3mcastGroupDescription, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1278 | groupInfos.size(), |
| 1279 | true, |
| 1280 | deviceId); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1281 | |
| 1282 | List<Deque<GroupKey>> addedKeys = new ArrayList<>(); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1283 | groupInfos.forEach(groupInfo -> { |
| 1284 | // update original NextGroup with new bucket-chain |
| 1285 | Deque<GroupKey> newBucketChain = new ArrayDeque<>(); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1286 | newBucketChain.addFirst(groupInfo.innerMostGroupDesc().appCookie()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1287 | // Add L3 interface group to the chain if there is one. |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1288 | if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) { |
| 1289 | newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1290 | } |
| 1291 | newBucketChain.addFirst(l3mcastGroupKey); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1292 | addedKeys.add(newBucketChain); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1293 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1294 | updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3mcastGce); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1295 | // Point next group to inner-most group, if any |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1296 | if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) { |
| 1297 | GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(), |
| 1298 | 1, |
| 1299 | false, |
| 1300 | deviceId); |
| 1301 | updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1302 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1303 | log.debug("Adding to L3MCAST: device:{} gid:{} group key:{} nextId:{}", |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1304 | deviceId, Integer.toHexString(l3mcastGroupId), |
| 1305 | l3mcastGroupKey, nextObj.id()); |
| 1306 | // send the innermost group |
| 1307 | log.debug("Sending innermost group {} in group chain on device {} ", |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1308 | Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()), |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1309 | deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1310 | groupService.addGroup(groupInfo.innerMostGroupDesc()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1311 | |
| 1312 | }); |
| 1313 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1314 | updatePendingNextObjective(l3mcastGroupKey, |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1315 | new OfdpaNextGroup(addedKeys, nextObj)); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * Removes the bucket in the top level group of a possible group-chain. Does |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1320 | * not remove the groups in the group-chain pointed to by this bucket, as they |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1321 | * may be in use (referenced by other groups) elsewhere. |
| 1322 | * |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1323 | * @param nextObjective the bucket information for a next group |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1324 | * @param next the representation of the existing group-chain for this next objective |
| 1325 | */ |
| 1326 | protected void removeBucketFromGroup(NextObjective nextObjective, NextGroup next) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1327 | if (nextObjective.type() != NextObjective.Type.HASHED && |
| 1328 | nextObjective.type() != NextObjective.Type.BROADCAST) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1329 | log.warn("RemoveBuckets not applied to nextType:{} in dev:{} for next:{}", |
| 1330 | nextObjective.type(), deviceId, nextObjective.id()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1331 | fail(nextObjective, ObjectiveError.UNSUPPORTED); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1332 | return; |
| 1333 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1334 | Set<PortNumber> portsToRemove = Sets.newHashSet(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1335 | Collection<TrafficTreatment> treatments = nextObjective.next(); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1336 | for (TrafficTreatment treatment : treatments) { |
| 1337 | // find the bucket to remove by noting the outport, and figuring out the |
| 1338 | // top-level group in the group-chain that indirectly references the port |
| 1339 | PortNumber portToRemove = readOutPortFromTreatment(treatment); |
| 1340 | if (portToRemove == null) { |
| 1341 | log.warn("treatment {} of next objective {} has no outport.. cannot remove bucket" |
| 1342 | + "from group in dev: {}", treatment, nextObjective.id(), deviceId); |
| 1343 | } else { |
| 1344 | portsToRemove.add(portToRemove); |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (portsToRemove.isEmpty()) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1349 | log.warn("next objective {} has no outport.. cannot remove bucket" |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1350 | + "from group in dev: {}", nextObjective.id(), deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1351 | fail(nextObjective, ObjectiveError.BADPARAMS); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1354 | List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1355 | List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1356 | for (Deque<GroupKey> gkeys : allActiveKeys) { |
| 1357 | // last group in group chain should have a single bucket pointing to port |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1358 | GroupKey groupWithPort = gkeys.peekLast(); |
| 1359 | Group group = groupService.getGroup(deviceId, groupWithPort); |
| 1360 | if (group == null) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1361 | log.warn("Inconsistent group chain found when removing bucket" |
| 1362 | + "for next:{} in dev:{}", nextObjective.id(), deviceId); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1363 | continue; |
| 1364 | } |
Yi Tseng | 91cf2d4 | 2017-04-10 17:05:37 -0700 | [diff] [blame] | 1365 | if (group.buckets().buckets().isEmpty()) { |
| 1366 | log.warn("Can't get output port information from group {} " + |
| 1367 | "because there is no bucket in the group.", |
| 1368 | group.id().toString()); |
| 1369 | continue; |
| 1370 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1371 | PortNumber pout = readOutPortFromTreatment( |
| 1372 | group.buckets().buckets().get(0).treatment()); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1373 | if (portsToRemove.contains(pout)) { |
| 1374 | chainsToRemove.add(gkeys); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1375 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1376 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1377 | if (chainsToRemove.isEmpty()) { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1378 | log.warn("Could not find appropriate group-chain for removing bucket" |
| 1379 | + " for next id {} in dev:{}", nextObjective.id(), deviceId); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1380 | fail(nextObjective, ObjectiveError.BADPARAMS); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1381 | return; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1382 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1383 | List<GroupBucket> bucketsToRemove = Lists.newArrayList(); |
| 1384 | //first group key is the one we want to modify |
| 1385 | GroupKey modGroupKey = chainsToRemove.get(0).peekFirst(); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1386 | Group modGroup = groupService.getGroup(deviceId, modGroupKey); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1387 | for (Deque<GroupKey> foundChain : chainsToRemove) { |
| 1388 | //second group key is the one we wish to remove the reference to |
| 1389 | if (foundChain.size() < 2) { |
| 1390 | // additional check to make sure second group key exist in |
| 1391 | // the chain. |
| 1392 | log.warn("Can't find second group key from chain {}", |
| 1393 | foundChain); |
| 1394 | continue; |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1395 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1396 | GroupKey pointedGroupKey = foundChain.stream().collect(Collectors.toList()).get(1); |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1397 | Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey); |
| 1398 | |
| 1399 | if (pointedGroup == null) { |
| 1400 | continue; |
| 1401 | } |
| 1402 | |
| 1403 | GroupBucket bucket; |
| 1404 | if (nextObjective.type() == NextObjective.Type.HASHED) { |
| 1405 | bucket = DefaultGroupBucket.createSelectGroupBucket( |
| 1406 | DefaultTrafficTreatment.builder() |
| 1407 | .group(pointedGroup.id()) |
| 1408 | .build()); |
| 1409 | } else { |
| 1410 | bucket = DefaultGroupBucket.createAllGroupBucket( |
| 1411 | DefaultTrafficTreatment.builder() |
| 1412 | .group(pointedGroup.id()) |
| 1413 | .build()); |
| 1414 | } |
| 1415 | |
| 1416 | bucketsToRemove.add(bucket); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1417 | } |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1418 | |
| 1419 | GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove); |
| 1420 | List<String> pointedGroupIds; // for debug log |
| 1421 | pointedGroupIds = bucketsToRemove.stream() |
| 1422 | .map(GroupBucket::treatment) |
| 1423 | .map(TrafficTreatment::allInstructions) |
| 1424 | .flatMap(List::stream) |
| 1425 | .filter(inst -> inst instanceof Instructions.GroupInstruction) |
| 1426 | .map(inst -> (Instructions.GroupInstruction) inst) |
| 1427 | .map(Instructions.GroupInstruction::groupId) |
| 1428 | .map(GroupId::id) |
| 1429 | .map(Integer::toHexString) |
| 1430 | .map(id -> HEX_PREFIX + id) |
| 1431 | .collect(Collectors.toList()); |
| 1432 | |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1433 | log.debug("Removing buckets from group id 0x{} pointing to group id(s) {} " |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1434 | + "for next id {} in device {}", Integer.toHexString(modGroup.id().id()), |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1435 | pointedGroupIds, nextObjective.id(), deviceId); |
| 1436 | addPendingUpdateNextObjective(modGroupKey, nextObjective); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1437 | groupService.removeBucketsFromGroup(deviceId, modGroupKey, |
| 1438 | removeBuckets, modGroupKey, |
| 1439 | nextObjective.appId()); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1440 | // update store - synchronize access |
| 1441 | synchronized (flowObjectiveStore) { |
| 1442 | // get fresh copy of what the store holds |
| 1443 | next = flowObjectiveStore.getNextGroup(nextObjective.id()); |
| 1444 | allActiveKeys = appKryo.deserialize(next.data()); |
| 1445 | // Note that since we got a new object, and ArrayDeque does not implement |
| 1446 | // Object.equals(), we have to check the deque last elems one by one |
| 1447 | allActiveKeys.removeIf(active -> chainsToRemove.stream().anyMatch(remove -> |
| 1448 | remove.peekLast().equals(active.peekLast()))); |
| 1449 | // If no buckets in the group, then retain an entry for the |
| 1450 | // top level group which still exists. |
| 1451 | if (allActiveKeys.isEmpty()) { |
| 1452 | ArrayDeque<GroupKey> top = new ArrayDeque<>(); |
| 1453 | top.add(modGroupKey); |
| 1454 | allActiveKeys.add(top); |
| 1455 | } |
| 1456 | flowObjectiveStore.putNextGroup(nextObjective.id(), |
| 1457 | new OfdpaNextGroup(allActiveKeys, nextObjective)); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1458 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /** |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1462 | * Removes all groups in multiple possible group-chains that represent the next-obj. |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1463 | * |
| 1464 | * @param nextObjective the next objective to remove |
| 1465 | * @param next the NextGroup that represents the existing group-chain for |
| 1466 | * this next objective |
| 1467 | */ |
| 1468 | protected void removeGroup(NextObjective nextObjective, NextGroup next) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1469 | List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1470 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1471 | List<GroupKey> groupKeys = allActiveKeys.stream() |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1472 | .map(Deque::getFirst).collect(Collectors.toList()); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1473 | addPendingRemoveNextObjective(nextObjective, groupKeys); |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1474 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1475 | allActiveKeys.forEach(groupChain -> groupChain.forEach(groupKey -> |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1476 | groupService.removeGroup(deviceId, groupKey, nextObjective.appId()))); |
| 1477 | flowObjectiveStore.removeNextGroup(nextObjective.id()); |
| 1478 | } |
| 1479 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1480 | protected void updatePendingNextObjective(GroupKey groupKey, OfdpaNextGroup nextGrp) { |
| 1481 | pendingAddNextObjectives.asMap().compute(groupKey, (k, val) -> { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1482 | if (val == null) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1483 | val = new CopyOnWriteArrayList<>(); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1484 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1485 | val.add(nextGrp); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1486 | return val; |
| 1487 | }); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1488 | } |
| 1489 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1490 | protected void updatePendingGroups(GroupKey groupKey, GroupChainElem gce) { |
| 1491 | pendingGroups.asMap().compute(groupKey, (k, val) -> { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1492 | if (val == null) { |
| 1493 | val = Sets.newConcurrentHashSet(); |
| 1494 | } |
| 1495 | val.add(gce); |
| 1496 | return val; |
| 1497 | }); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1500 | protected void addPendingUpdateNextObjective(GroupKey groupKey, |
| 1501 | NextObjective nextObjective) { |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1502 | pendingUpdateNextObjectives.compute(groupKey, (gKey, nextObjs) -> { |
| 1503 | if (nextObjs != null) { |
| 1504 | nextObjs.add(nextObjective); |
| 1505 | } else { |
| 1506 | nextObjs = Sets.newHashSet(nextObjective); |
| 1507 | } |
| 1508 | return nextObjs; |
| 1509 | }); |
| 1510 | } |
| 1511 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1512 | private void processPendingUpdateNextObjs(GroupKey groupKey) { |
| 1513 | pendingUpdateNextObjectives.compute(groupKey, (gKey, nextObjs) -> { |
| 1514 | if (nextObjs != null) { |
| 1515 | |
| 1516 | nextObjs.forEach(nextObj -> { |
| 1517 | log.debug("Group {} updated, update pending next objective {}.", |
| 1518 | groupKey, nextObj); |
| 1519 | |
| 1520 | pass(nextObj); |
| 1521 | }); |
| 1522 | } |
| 1523 | return Sets.newHashSet(); |
| 1524 | }); |
| 1525 | } |
| 1526 | |
| 1527 | private void processPendingRemoveNextObjs(GroupKey key) { |
| 1528 | pendingRemoveNextObjectives.asMap().forEach((nextObjective, groupKeys) -> { |
| 1529 | if (groupKeys.isEmpty()) { |
| 1530 | pendingRemoveNextObjectives.invalidate(nextObjective); |
| 1531 | pass(nextObjective); |
| 1532 | } else { |
| 1533 | groupKeys.remove(key); |
| 1534 | } |
| 1535 | }); |
| 1536 | } |
| 1537 | |
| 1538 | protected int getNextAvailableIndex() { |
| 1539 | return (int) nextIndex.incrementAndGet(); |
| 1540 | } |
| 1541 | |
| 1542 | protected Group retrieveTopLevelGroup(List<Deque<GroupKey>> allActiveKeys, |
| 1543 | int nextid) { |
| 1544 | GroupKey topLevelGroupKey; |
| 1545 | if (!allActiveKeys.isEmpty()) { |
| 1546 | topLevelGroupKey = allActiveKeys.get(0).peekFirst(); |
| 1547 | } else { |
| 1548 | log.warn("Could not determine top level group while processing" |
| 1549 | + "next:{} in dev:{}", nextid, deviceId); |
| 1550 | return null; |
| 1551 | } |
| 1552 | Group topGroup = groupService.getGroup(deviceId, topLevelGroupKey); |
| 1553 | if (topGroup == null) { |
| 1554 | log.warn("Could not find top level group while processing " |
| 1555 | + "next:{} in dev:{}", nextid, deviceId); |
| 1556 | } |
| 1557 | return topGroup; |
| 1558 | } |
| 1559 | |
| 1560 | protected void processPendingAddGroupsOrNextObjs(GroupKey key, boolean added) { |
| 1561 | //first check for group chain |
| 1562 | Set<OfdpaGroupHandlerUtility.GroupChainElem> gceSet = pendingGroups.asMap().remove(key); |
| 1563 | if (gceSet != null) { |
| 1564 | for (GroupChainElem gce : gceSet) { |
| 1565 | log.debug("Group service {} group key {} in device {}. " |
| 1566 | + "Processing next group in group chain with group id 0x{}", |
| 1567 | (added) ? "ADDED" : "processed", |
| 1568 | key, deviceId, |
| 1569 | Integer.toHexString(gce.groupDescription().givenGroupId())); |
| 1570 | processGroupChain(gce); |
| 1571 | } |
| 1572 | } else { |
| 1573 | // otherwise chain complete - check for waiting nextObjectives |
| 1574 | List<OfdpaGroupHandlerUtility.OfdpaNextGroup> nextGrpList = |
| 1575 | pendingAddNextObjectives.getIfPresent(key); |
| 1576 | if (nextGrpList != null) { |
| 1577 | pendingAddNextObjectives.invalidate(key); |
| 1578 | nextGrpList.forEach(nextGrp -> { |
| 1579 | log.debug("Group service {} group key {} in device:{}. " |
| 1580 | + "Done implementing next objective: {} <<-->> gid:0x{}", |
| 1581 | (added) ? "ADDED" : "processed", |
| 1582 | key, deviceId, nextGrp.nextObjective().id(), |
| 1583 | Integer.toHexString(groupService.getGroup(deviceId, key) |
| 1584 | .givenGroupId())); |
| 1585 | pass(nextGrp.nextObjective()); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1586 | updateFlowObjectiveStore(nextGrp.nextObjective().id(), nextGrp); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1587 | |
| 1588 | // check if addBuckets waiting for this completion |
| 1589 | pendingBuckets.compute(nextGrp.nextObjective().id(), (nextId, pendBkts) -> { |
| 1590 | if (pendBkts != null) { |
| 1591 | pendBkts.forEach(pendBkt -> addBucketToGroup(pendBkt, nextGrp)); |
| 1592 | } |
| 1593 | return null; |
| 1594 | }); |
| 1595 | }); |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1600 | /** |
| 1601 | * Processes next element of a group chain. Assumption is that if this |
| 1602 | * group points to another group, the latter has already been created |
| 1603 | * and this driver has received notification for it. A second assumption is |
| 1604 | * that if there is another group waiting for this group then the appropriate |
| 1605 | * stores already have the information to act upon the notification for the |
| 1606 | * creation of this group. |
| 1607 | * <p> |
| 1608 | * The processing of the GroupChainElement depends on the number of groups |
| 1609 | * this element is waiting on. For all group types other than SIMPLE, a |
| 1610 | * GroupChainElement could be waiting on multiple groups. |
| 1611 | * |
| 1612 | * @param gce the group chain element to be processed next |
| 1613 | */ |
| 1614 | private void processGroupChain(GroupChainElem gce) { |
| 1615 | int waitOnGroups = gce.decrementAndGetGroupsWaitedOn(); |
| 1616 | if (waitOnGroups != 0) { |
| 1617 | log.debug("GCE: {} not ready to be processed", gce); |
| 1618 | return; |
| 1619 | } |
| 1620 | log.debug("GCE: {} ready to be processed", gce); |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1621 | if (gce.addBucketToGroup()) { |
| 1622 | groupService.addBucketsToGroup(gce.groupDescription().deviceId(), |
| 1623 | gce.groupDescription().appCookie(), |
| 1624 | gce.groupDescription().buckets(), |
| 1625 | gce.groupDescription().appCookie(), |
| 1626 | gce.groupDescription().appId()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1627 | } else { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1628 | groupService.addGroup(gce.groupDescription()); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1632 | protected void addPendingRemoveNextObjective(NextObjective nextObjective, |
| 1633 | List<GroupKey> groupKeys) { |
| 1634 | pendingRemoveNextObjectives.put(nextObjective, groupKeys); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1635 | } |
| 1636 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1637 | private void updateFlowObjectiveStore(Integer nextId, OfdpaNextGroup nextGrp) { |
| 1638 | synchronized (flowObjectiveStore) { |
| 1639 | // get fresh copy of what the store holds |
| 1640 | NextGroup next = flowObjectiveStore.getNextGroup(nextId); |
| 1641 | if (next == null || nextGrp.nextObjective().op() == Operation.ADD) { |
| 1642 | flowObjectiveStore.putNextGroup(nextId, nextGrp); |
| 1643 | return; |
| 1644 | } |
| 1645 | if (nextGrp.nextObjective().op() == Operation.ADD_TO_EXISTING) { |
| 1646 | List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); |
| 1647 | // If active keys shows only the top-level group without a chain of groups, |
| 1648 | // then it represents an empty group. Update by replacing empty chain. |
| 1649 | if (allActiveKeys.size() == 1 && allActiveKeys.get(0).size() == 1) { |
| 1650 | allActiveKeys.clear(); |
| 1651 | } |
| 1652 | allActiveKeys.addAll(nextGrp.allKeys()); |
| 1653 | flowObjectiveStore.putNextGroup(nextId, |
| 1654 | new OfdpaNextGroup(allActiveKeys, nextGrp.nextObjective())); |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1659 | private class InnerGroupListener implements GroupListener { |
| 1660 | @Override |
| 1661 | public void event(GroupEvent event) { |
| 1662 | log.trace("received group event of type {}", event.type()); |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1663 | switch (event.type()) { |
| 1664 | case GROUP_ADDED: |
| 1665 | processPendingAddGroupsOrNextObjs(event.subject().appCookie(), true); |
| 1666 | break; |
| 1667 | case GROUP_REMOVED: |
| 1668 | processPendingRemoveNextObjs(event.subject().appCookie()); |
| 1669 | break; |
Yi Tseng | 78f51f4 | 2017-02-02 13:54:58 -0800 | [diff] [blame] | 1670 | case GROUP_UPDATED: |
| 1671 | processPendingUpdateNextObjs(event.subject().appCookie()); |
| 1672 | break; |
Charles Chan | fc5c780 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1673 | default: |
| 1674 | break; |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1678 | } |