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