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