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