blob: 2fa93343c3c691e3626ee3135da1c6ca81079f60 [file] [log] [blame]
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07003 *
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 Tsengef19de12017-04-24 11:33:05 -070016package org.onosproject.driver.pipeline.ofdpa;
Charles Chan188ebf52015-12-23 00:15:11 -080017
18import com.google.common.cache.Cache;
19import com.google.common.cache.CacheBuilder;
20import com.google.common.cache.RemovalCause;
21import com.google.common.cache.RemovalNotification;
Charles Chan5b9df8d2016-03-28 22:21:40 -070022import com.google.common.collect.ImmutableList;
23import com.google.common.collect.Lists;
Yi Tseng78f51f42017-02-02 13:54:58 -080024import com.google.common.collect.Sets;
Charles Chan188ebf52015-12-23 00:15:11 -080025import org.onlab.osgi.ServiceDirectory;
Charles Chan5b9df8d2016-03-28 22:21:40 -070026import org.onlab.packet.IpPrefix;
Charles Chan5270ed02016-01-30 23:22:37 -080027import org.onlab.packet.MacAddress;
Charles Chan188ebf52015-12-23 00:15:11 -080028import org.onlab.packet.MplsLabel;
29import org.onlab.packet.VlanId;
30import org.onosproject.core.ApplicationId;
Yi Tseng78f51f42017-02-02 13:54:58 -080031import org.onosproject.core.GroupId;
Charles Chan32562522016-04-07 14:37:14 -070032import org.onosproject.driver.extensions.OfdpaSetVlanVid;
Charles Chan188ebf52015-12-23 00:15:11 -080033import org.onosproject.net.DeviceId;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.behaviour.NextGroup;
36import org.onosproject.net.behaviour.PipelinerContext;
37import org.onosproject.net.flow.DefaultTrafficTreatment;
38import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
40import org.onosproject.net.flow.criteria.Criterion;
Pier Ventre42287df2016-11-09 14:17:26 -080041import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Charles Chan188ebf52015-12-23 00:15:11 -080042import org.onosproject.net.flow.criteria.VlanIdCriterion;
43import org.onosproject.net.flow.instructions.Instruction;
44import org.onosproject.net.flow.instructions.Instructions;
Saurav Das9df5b7c2017-08-14 16:44:43 -070045import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
Charles Chan188ebf52015-12-23 00:15:11 -080046import org.onosproject.net.flow.instructions.L2ModificationInstruction;
Yi Tseng47f82dc2017-03-05 22:48:39 -080047import org.onosproject.net.flowobjective.DefaultNextObjective;
Charles Chan188ebf52015-12-23 00:15:11 -080048import org.onosproject.net.flowobjective.FlowObjectiveStore;
49import org.onosproject.net.flowobjective.NextObjective;
Saurav Dasc88d4662017-05-15 15:34:25 -070050import org.onosproject.net.flowobjective.Objective.Operation;
Yi Tseng47f82dc2017-03-05 22:48:39 -080051import org.onosproject.net.flowobjective.ObjectiveContext;
Charles Chan188ebf52015-12-23 00:15:11 -080052import org.onosproject.net.flowobjective.ObjectiveError;
53import org.onosproject.net.group.DefaultGroupBucket;
54import org.onosproject.net.group.DefaultGroupDescription;
55import org.onosproject.net.group.DefaultGroupKey;
56import org.onosproject.net.group.Group;
57import org.onosproject.net.group.GroupBucket;
58import org.onosproject.net.group.GroupBuckets;
59import org.onosproject.net.group.GroupDescription;
60import org.onosproject.net.group.GroupEvent;
61import org.onosproject.net.group.GroupKey;
62import org.onosproject.net.group.GroupListener;
63import org.onosproject.net.group.GroupService;
Saurav Das8be4e3a2016-03-11 17:19:07 -080064import org.onosproject.store.service.AtomicCounter;
65import org.onosproject.store.service.StorageService;
Charles Chan188ebf52015-12-23 00:15:11 -080066import org.slf4j.Logger;
67
68import java.util.ArrayDeque;
69import java.util.ArrayList;
Saurav Dasceccf242017-08-03 18:30:35 -070070import java.util.Arrays;
Charles Chan188ebf52015-12-23 00:15:11 -080071import java.util.Collection;
72import java.util.Collections;
73import java.util.Deque;
74import java.util.List;
Charles Chand0fd5dc2016-02-16 23:14:49 -080075import java.util.Objects;
Charles Chan188ebf52015-12-23 00:15:11 -080076import java.util.Set;
77import java.util.concurrent.ConcurrentHashMap;
78import java.util.concurrent.CopyOnWriteArrayList;
79import java.util.concurrent.Executors;
80import java.util.concurrent.ScheduledExecutorService;
81import java.util.concurrent.TimeUnit;
Charles Chan188ebf52015-12-23 00:15:11 -080082import java.util.stream.Collectors;
83
84import static org.onlab.util.Tools.groupedThreads;
Yi Tsengef19de12017-04-24 11:33:05 -070085import static org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline.*;
pier5c817582019-04-17 17:05:08 +020086import static org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.*;
Yi Tsengef19de12017-04-24 11:33:05 -070087import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*;
jayakumarthazhathad3636a2018-10-01 00:51:54 +053088import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE;
89import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey;
Pier Ventre42287df2016-11-09 14:17:26 -080090import static org.onosproject.net.flow.criteria.Criterion.Type.TUNNEL_ID;
Pier Ventre140a8942016-11-02 07:26:38 -070091import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
Yi Tseng78f51f42017-02-02 13:54:58 -080092import static org.onosproject.net.group.GroupDescription.Type.ALL;
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -080093import static org.onosproject.net.group.GroupDescription.Type.INDIRECT;
Yi Tseng78f51f42017-02-02 13:54:58 -080094import static org.onosproject.net.group.GroupDescription.Type.SELECT;
Charles Chan188ebf52015-12-23 00:15:11 -080095import static org.slf4j.LoggerFactory.getLogger;
96
97/**
Saurav Das961beb22017-03-29 19:09:17 -070098 * Group handler that emulates Broadcom OF-DPA TTP.
Charles Chan188ebf52015-12-23 00:15:11 -080099 */
Charles Chan361154b2016-03-24 10:23:39 -0700100public class Ofdpa2GroupHandler {
Yi Tsengef19de12017-04-24 11:33:05 -0700101 protected final Logger log = getLogger(getClass());
Yi Tsengef19de12017-04-24 11:33:05 -0700102 // Services, Stores
Charles Chan188ebf52015-12-23 00:15:11 -0800103 protected GroupService groupService;
Saurav Das8be4e3a2016-03-11 17:19:07 -0800104 protected StorageService storageService;
Yi Tsengef19de12017-04-24 11:33:05 -0700105 protected FlowObjectiveStore flowObjectiveStore;
Charles Chan188ebf52015-12-23 00:15:11 -0800106 // index number for group creation
Saurav Das8be4e3a2016-03-11 17:19:07 -0800107 private AtomicCounter nextIndex;
Yi Tsengef19de12017-04-24 11:33:05 -0700108 protected DeviceId deviceId;
Saurav Das2c57bc82018-04-07 16:51:09 -0700109 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 Tseng47f82dc2017-03-05 22:48:39 -0800113 // local store for pending bucketAdds - by design there can be multiple
Charles Chan188ebf52015-12-23 00:15:11 -0800114 // pending bucket for a group
Yi Tseng47f82dc2017-03-05 22:48:39 -0800115 protected ConcurrentHashMap<Integer, Set<NextObjective>> pendingBuckets =
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700116 new ConcurrentHashMap<>();
Yi Tsengef19de12017-04-24 11:33:05 -0700117 private ScheduledExecutorService groupCheckerExecutor =
118 Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner", "ofdpa-%d", log));
pier95e62512020-03-20 11:00:38 +0100119 private InnerGroupListener innerGroupListener = new InnerGroupListener();
Charles Chan40132b32017-01-22 00:19:37 -0800120 /**
121 * Determines whether this pipeline support copy ttl instructions or not.
122 *
123 * @return true if copy ttl instructions are supported
124 */
125 protected boolean supportCopyTtl() {
126 return true;
127 }
128
129 /**
130 * Determines whether this pipeline support set mpls bos instruction or not.
131 *
132 * @return true if set mpls bos instruction is supported
133 */
134 protected boolean supportSetMplsBos() {
135 return true;
136 }
137
Charles Chan0f43e472017-02-14 14:00:16 -0800138 /**
139 * Determines whether this pipeline requires popping VLAN before pushing MPLS.
140 * <p>
141 * If required, pop vlan before push mpls and add an arbitrary vlan back afterward.
142 * MPLS interface group will substitute the arbitrary VLAN with expected VLAN later on.
143 *
144 * @return true if this pipeline requires popping VLAN before pushing MPLS
145 */
146 protected boolean requireVlanPopBeforeMplsPush() {
147 return false;
148 }
149
Alex Yashchuka3679532017-12-08 17:40:05 +0200150 public void init(DeviceId deviceId, PipelinerContext context) {
Yi Tsengef19de12017-04-24 11:33:05 -0700151 ServiceDirectory serviceDirectory = context.directory();
Charles Chan188ebf52015-12-23 00:15:11 -0800152 this.deviceId = deviceId;
153 this.flowObjectiveStore = context.store();
Charles Chan188ebf52015-12-23 00:15:11 -0800154 this.groupService = serviceDirectory.get(GroupService.class);
Saurav Das8be4e3a2016-03-11 17:19:07 -0800155 this.storageService = serviceDirectory.get(StorageService.class);
Madan Jampanid5714e02016-04-19 14:15:20 -0700156 this.nextIndex = storageService.getAtomicCounter("group-id-index-counter");
Charles Chan188ebf52015-12-23 00:15:11 -0800157
Charles Chanfc5c7802016-05-17 13:13:55 -0700158 pendingAddNextObjectives = CacheBuilder.newBuilder()
Charles Chan188ebf52015-12-23 00:15:11 -0800159 .expireAfterWrite(20, TimeUnit.SECONDS)
Yi Tsengef19de12017-04-24 11:33:05 -0700160 .removalListener((RemovalNotification<GroupKey, List<OfdpaNextGroup>> notification) -> {
161 if (notification.getCause() == RemovalCause.EXPIRED &&
162 Objects.nonNull(notification.getValue())) {
163 notification.getValue()
164 .forEach(ofdpaNextGrp ->
165 fail(ofdpaNextGrp.nextObjective(),
166 ObjectiveError.GROUPINSTALLATIONFAILED));
Charles Chanfc5c7802016-05-17 13:13:55 -0700167 }
168 }).build();
Charles Chan188ebf52015-12-23 00:15:11 -0800169
Charles Chanfc5c7802016-05-17 13:13:55 -0700170 pendingRemoveNextObjectives = CacheBuilder.newBuilder()
171 .expireAfterWrite(20, TimeUnit.SECONDS)
Yi Tsengef19de12017-04-24 11:33:05 -0700172 .removalListener((RemovalNotification<NextObjective, List<GroupKey>> notification) -> {
Charles Chanfc5c7802016-05-17 13:13:55 -0700173 if (notification.getCause() == RemovalCause.EXPIRED) {
Yi Tsengef19de12017-04-24 11:33:05 -0700174 fail(notification.getKey(),
175 ObjectiveError.GROUPREMOVALFAILED);
Charles Chan188ebf52015-12-23 00:15:11 -0800176 }
177 }).build();
Saurav Das961beb22017-03-29 19:09:17 -0700178 pendingGroups = CacheBuilder.newBuilder()
179 .expireAfterWrite(20, TimeUnit.SECONDS)
Yi Tsengef19de12017-04-24 11:33:05 -0700180 .removalListener((RemovalNotification<GroupKey, Set<GroupChainElem>> notification) -> {
Saurav Das961beb22017-03-29 19:09:17 -0700181 if (notification.getCause() == RemovalCause.EXPIRED) {
182 log.error("Unable to install group with key {} and pending GCEs: {}",
183 notification.getKey(), notification.getValue());
184 }
185 }).build();
Yi Tseng78f51f42017-02-02 13:54:58 -0800186 pendingUpdateNextObjectives = new ConcurrentHashMap<>();
Yi Tsengef19de12017-04-24 11:33:05 -0700187 GroupChecker groupChecker = new GroupChecker(this);
188 groupCheckerExecutor.scheduleAtFixedRate(groupChecker, 0, 500, TimeUnit.MILLISECONDS);
pier95e62512020-03-20 11:00:38 +0100189 groupService.addListener(innerGroupListener);
190 }
191
192 // Terminate internal references
193 public void terminate() {
194 if (nextIndex != null) {
195 nextIndex.destroy();
196 }
197 nextIndex = null;
198 if (pendingAddNextObjectives != null) {
199 pendingAddNextObjectives.cleanUp();
200 }
201 pendingAddNextObjectives = null;
202 if (pendingRemoveNextObjectives != null) {
203 pendingRemoveNextObjectives.cleanUp();
204 }
205 pendingRemoveNextObjectives = null;
206 if (pendingGroups != null) {
207 pendingGroups.cleanUp();
208 }
209 pendingGroups = null;
210 if (groupCheckerExecutor != null) {
211 groupCheckerExecutor.shutdown();
212 }
213 groupCheckerExecutor = null;
214 if (groupService != null) {
215 groupService.removeListener(innerGroupListener);
216 }
Charles Chan188ebf52015-12-23 00:15:11 -0800217 }
218
Saurav Das8be4e3a2016-03-11 17:19:07 -0800219 //////////////////////////////////////
220 // Group Creation
221 //////////////////////////////////////
222
Yi Tsengef19de12017-04-24 11:33:05 -0700223 /**
224 * Adds a list of group chain by given NextObjective.
225 *
226 * @param nextObjective the NextObjective
227 */
Charles Chan188ebf52015-12-23 00:15:11 -0800228 protected void addGroup(NextObjective nextObjective) {
229 switch (nextObjective.type()) {
230 case SIMPLE:
231 Collection<TrafficTreatment> treatments = nextObjective.next();
232 if (treatments.size() != 1) {
233 log.error("Next Objectives of type Simple should only have a "
234 + "single Traffic Treatment. Next Objective Id:{}",
235 nextObjective.id());
Yi Tsengef19de12017-04-24 11:33:05 -0700236 fail(nextObjective, ObjectiveError.BADPARAMS);
Charles Chan188ebf52015-12-23 00:15:11 -0800237 return;
238 }
239 processSimpleNextObjective(nextObjective);
240 break;
241 case BROADCAST:
242 processBroadcastNextObjective(nextObjective);
243 break;
244 case HASHED:
Pier Ventre140a8942016-11-02 07:26:38 -0700245 if (!verifyHashedNextObjective(nextObjective)) {
246 log.error("Next Objectives of type hashed not supported. Next Objective Id:{}",
247 nextObjective.id());
Yi Tsengef19de12017-04-24 11:33:05 -0700248 fail(nextObjective, ObjectiveError.BADPARAMS);
Pier Ventre140a8942016-11-02 07:26:38 -0700249 return;
250 }
Charles Chan188ebf52015-12-23 00:15:11 -0800251 processHashedNextObjective(nextObjective);
252 break;
253 case FAILOVER:
Yi Tsengef19de12017-04-24 11:33:05 -0700254 fail(nextObjective, ObjectiveError.UNSUPPORTED);
Charles Chan188ebf52015-12-23 00:15:11 -0800255 log.warn("Unsupported next objective type {}", nextObjective.type());
256 break;
257 default:
Yi Tsengef19de12017-04-24 11:33:05 -0700258 fail(nextObjective, ObjectiveError.UNKNOWN);
Charles Chan188ebf52015-12-23 00:15:11 -0800259 log.warn("Unknown next objective type {}", nextObjective.type());
260 }
261 }
262
263 /**
jayakumarthazhathad3636a2018-10-01 00:51:54 +0530264 * Similar to processBroadcastNextObjective but handles L2 Multicast Next Objectives.
265 *
266 * @param nextObj NextObjective of L2_MULTICAST with chained NextObjectives for single homed access ports
267 */
268 private void processL2MulticastNextObjective(NextObjective nextObj) {
269
270 VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
271 if (assignedVlan == null) {
272 log.warn("VLAN ID required by L2 multicast next objective is missing. Aborting group creation.");
273 fail(nextObj, ObjectiveError.BADPARAMS);
274 return;
275 }
276
277 // Group info should contain only single homed hosts for a given vlanId
278 List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
279 createL2MulticastGroup(nextObj, assignedVlan, groupInfos);
280 }
281
282 private void createL2MulticastGroup(NextObjective nextObj, VlanId vlanId, List<GroupInfo> groupInfos) {
283 // Realize & represent L2 multicast group in OFDPA driver layer
284 // TODO : Need to identify significance of OfdpaNextGroup.
285 Integer l2MulticastGroupId = L2_MULTICAST_TYPE | (vlanId.toShort() << 16);
286 final GroupKey l2MulticastGroupKey = l2MulticastGroupKey(vlanId, deviceId);
287 List<Deque<GroupKey>> l2MulticastAllGroup = Lists.newArrayList();
288 groupInfos.forEach(groupInfo -> {
289 Deque<GroupKey> groupKeyChain = new ArrayDeque<>();
290 groupKeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
291 groupKeyChain.addFirst(l2MulticastGroupKey);
292 l2MulticastAllGroup.add(groupKeyChain);
293 });
294 OfdpaNextGroup ofdpaL2MulticastGroup = new OfdpaNextGroup(l2MulticastAllGroup, nextObj);
295 updatePendingNextObjective(l2MulticastGroupKey, ofdpaL2MulticastGroup);
296 // Group Chain Hierarchy creation using group service and thus in device level
297 List<GroupBucket> l2McastBuckets = new ArrayList<>();
298 groupInfos.forEach(groupInfo -> {
299 // Points to L2 interface group directly.
300 TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder();
301 trafficTreatment.group(new GroupId(groupInfo.innerMostGroupDesc().givenGroupId()));
302 GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment.build());
303 l2McastBuckets.add(bucket);
304 });
305 GroupDescription l2MulticastGroupDescription =
306 new DefaultGroupDescription(
307 deviceId,
308 ALL,
309 new GroupBuckets(l2McastBuckets),
310 l2MulticastGroupKey,
311 l2MulticastGroupId,
312 nextObj.appId());
313 GroupChainElem l2MulticastGce = new GroupChainElem(l2MulticastGroupDescription,
314 groupInfos.size(), false, deviceId);
315 groupInfos.forEach(groupInfo -> {
316 updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), l2MulticastGce);
317 groupService.addGroup(groupInfo.innerMostGroupDesc());
318 });
319 }
320
321 /**
Charles Chan188ebf52015-12-23 00:15:11 -0800322 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
Saurav Dasa89b95a2018-02-14 14:14:54 -0800323 * a chain of groups. The simple Next Objective passed in by the application
324 * is broken up into a group chain. The following chains can be created
325 * depending on the parameters in the Next Objective.
326 * 1. L2 Interface group (no chaining)
327 * 2. L3 Unicast group -> L2 Interface group
328 * 3. MPLS Interface group -> L2 Interface group
329 * 4. MPLS Swap group -> MPLS Interface group -> L2 Interface group
330 * 5. PW initiation group chain
Charles Chan188ebf52015-12-23 00:15:11 -0800331 *
332 * @param nextObj the nextObjective of type SIMPLE
333 */
334 private void processSimpleNextObjective(NextObjective nextObj) {
335 TrafficTreatment treatment = nextObj.next().iterator().next();
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800336 // determine if plain L2 or L3->L2 or MPLS Swap -> MPLS Interface -> L2
Charles Chan188ebf52015-12-23 00:15:11 -0800337 boolean plainL2 = true;
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800338 boolean mplsSwap = false;
339 MplsLabel mplsLabel = null;
Charles Chan188ebf52015-12-23 00:15:11 -0800340 for (Instruction ins : treatment.allInstructions()) {
341 if (ins.type() == Instruction.Type.L2MODIFICATION) {
342 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
343 if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST ||
344 l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC) {
345 plainL2 = false;
Charles Chan188ebf52015-12-23 00:15:11 -0800346 }
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800347 // mpls label in simple next objectives is used only to indicate
348 // a MPLS Swap group before the MPLS Interface Group
349 if (l2ins.subtype() == L2ModificationInstruction.L2SubType.MPLS_LABEL) {
350 mplsSwap = true;
351 mplsLabel = ((L2ModificationInstruction.ModMplsLabelInstruction) l2ins).label();
352 }
Charles Chan188ebf52015-12-23 00:15:11 -0800353 }
354 }
Charles Chan188ebf52015-12-23 00:15:11 -0800355 if (plainL2) {
356 createL2InterfaceGroup(nextObj);
357 return;
358 }
Saurav Dasa89b95a2018-02-14 14:14:54 -0800359 // In order to understand if it is a pseudowire related
Pier Ventre42287df2016-11-09 14:17:26 -0800360 // next objective we look for the tunnel id in the meta.
361 boolean isPw = false;
Pier Ventre140a8942016-11-02 07:26:38 -0700362 if (nextObj.meta() != null) {
Pier Ventre42287df2016-11-09 14:17:26 -0800363 TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) nextObj
364 .meta()
365 .getCriterion(TUNNEL_ID);
366 if (tunnelIdCriterion != null) {
367 isPw = true;
368 }
Pier Ventre140a8942016-11-02 07:26:38 -0700369 }
Andreas Pantelopoulosb524fff2018-02-08 12:42:06 -0800370 if (mplsSwap && !isPw) {
Saurav Dasa89b95a2018-02-14 14:14:54 -0800371 log.debug("Creating a MPLS Swap -> MPLS Interface -> L2 Interface group chain.");
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800372 // break up simple next objective to GroupChain objects
373 GroupInfo groupInfo = createL2L3Chain(treatment, nextObj.id(),
374 nextObj.appId(), true,
375 nextObj.meta());
376 if (groupInfo == null) {
377 log.error("Could not process nextObj={} in dev:{}", nextObj.id(), deviceId);
378 fail(nextObj, ObjectiveError.BADPARAMS);
379 return;
380 }
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800381 Deque<GroupKey> gkeyChain = new ArrayDeque<>();
Saurav Dasa89b95a2018-02-14 14:14:54 -0800382 gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie()); // l2 interface
383 gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie()); // mpls interface
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800384 // creating the mpls swap group and adding it to the chain
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800385 int nextGid = groupInfo.nextGroupDesc().givenGroupId();
386 int index = getNextAvailableIndex();
Saurav Dasa89b95a2018-02-14 14:14:54 -0800387 GroupDescription swapGroupDescription = createMplsSwap(
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800388 nextGid,
389 OfdpaMplsGroupSubType.MPLS_SWAP_LABEL,
390 index,
391 mplsLabel,
392 nextObj.appId()
393 );
Saurav Dasa89b95a2018-02-14 14:14:54 -0800394 // ensure swap group is added after L2L3 chain
395 GroupKey swapGroupKey = swapGroupDescription.appCookie();
396 GroupChainElem swapChainElem = new GroupChainElem(swapGroupDescription,
397 1, false, deviceId);
398 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), swapChainElem);
399 gkeyChain.addFirst(swapGroupKey);
Saurav Dasa89b95a2018-02-14 14:14:54 -0800400 // ensure nextObjective waits on the outermost groupKey
401 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
402 allGroupKeys.add(gkeyChain);
403 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
404 updatePendingNextObjective(swapGroupKey, ofdpaGrp);
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800405 // now we are ready to send the l2 groupDescription (inner), as all the stores
406 // that will get async replies have been updated. By waiting to update
407 // the stores, we prevent nasty race conditions.
408 groupService.addGroup(groupInfo.innerMostGroupDesc());
409 } else if (!isPw) {
Saurav Dasa89b95a2018-02-14 14:14:54 -0800410 boolean isMpls = false;
411 if (nextObj.meta() != null) {
412 isMpls = isNotMplsBos(nextObj.meta());
413 }
414 log.debug("Creating a {} -> L2 Interface group chain.",
415 (isMpls) ? "MPLS Interface" : "L3 Unicast");
Pier Ventre42287df2016-11-09 14:17:26 -0800416 // break up simple next objective to GroupChain objects
417 GroupInfo groupInfo = createL2L3Chain(treatment, nextObj.id(),
418 nextObj.appId(), isMpls,
419 nextObj.meta());
420 if (groupInfo == null) {
421 log.error("Could not process nextObj={} in dev:{}", nextObj.id(), deviceId);
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800422 fail(nextObj, ObjectiveError.BADPARAMS);
Pier Ventre42287df2016-11-09 14:17:26 -0800423 return;
424 }
425 // create object for local and distributed storage
426 Deque<GroupKey> gkeyChain = new ArrayDeque<>();
Yi Tsengef19de12017-04-24 11:33:05 -0700427 gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
428 gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie());
Saurav Dasa89b95a2018-02-14 14:14:54 -0800429 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
430 allGroupKeys.add(gkeyChain);
431 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
Pier Ventre42287df2016-11-09 14:17:26 -0800432 // store l3groupkey with the ofdpaNextGroup for the nextObjective that depends on it
Yi Tsengef19de12017-04-24 11:33:05 -0700433 updatePendingNextObjective(groupInfo.nextGroupDesc().appCookie(), ofdpaGrp);
Pier Ventre42287df2016-11-09 14:17:26 -0800434 // now we are ready to send the l2 groupDescription (inner), as all the stores
435 // that will get async replies have been updated. By waiting to update
436 // the stores, we prevent nasty race conditions.
Yi Tsengef19de12017-04-24 11:33:05 -0700437 groupService.addGroup(groupInfo.innerMostGroupDesc());
Pier Ventre42287df2016-11-09 14:17:26 -0800438 } else {
439 // We handle the pseudo wire with a different a procedure.
440 // This procedure is meant to handle both initiation and
441 // termination of the pseudo wire.
442 processPwNextObjective(nextObj);
Charles Chan188ebf52015-12-23 00:15:11 -0800443 }
Charles Chan188ebf52015-12-23 00:15:11 -0800444 }
445
Charles Chan188ebf52015-12-23 00:15:11 -0800446 /**
447 * Creates a simple L2 Interface Group.
Charles Chan188ebf52015-12-23 00:15:11 -0800448 * @param nextObj the next Objective
449 */
450 private void createL2InterfaceGroup(NextObjective nextObj) {
Yi Tsengef19de12017-04-24 11:33:05 -0700451 VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700452 if (assignedVlan == null) {
453 log.warn("VLAN ID required by simple next obj is missing. Abort.");
Yi Tsengef19de12017-04-24 11:33:05 -0700454 fail(nextObj, ObjectiveError.BADPARAMS);
Charles Chan188ebf52015-12-23 00:15:11 -0800455 return;
456 }
Charles Chan5b9df8d2016-03-28 22:21:40 -0700457 List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700458 // There is only one L2 interface group in this case
Yi Tsengef19de12017-04-24 11:33:05 -0700459 GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700460 // Put all dependency information into allGroupKeys
461 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
462 Deque<GroupKey> gkeyChain = new ArrayDeque<>();
463 gkeyChain.addFirst(l2InterfaceGroupDesc.appCookie());
464 allGroupKeys.add(gkeyChain);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700465 // Point the next objective to this group
466 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
467 updatePendingNextObjective(l2InterfaceGroupDesc.appCookie(), ofdpaGrp);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700468 // Start installing the inner-most group
jayakumarthazhathad3636a2018-10-01 00:51:54 +0530469 groupService.addGroup(l2InterfaceGroupDesc); }
Charles Chan188ebf52015-12-23 00:15:11 -0800470
471 /**
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800472 * Creates an Mpls group of type swap.
473 *
474 * @param nextGroupId the next group in the chain
475 * @param subtype the mpls swap label group subtype
476 * @param index the index of the group
477 * @param mplsLabel the mpls label to swap
478 * @param applicationId the application id
479 * @return the group description
480 */
481 protected GroupDescription createMplsSwap(int nextGroupId,
482 OfdpaMplsGroupSubType subtype,
483 int index,
484 MplsLabel mplsLabel,
485 ApplicationId applicationId) {
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800486 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800487 treatment.setMpls(mplsLabel);
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800488 // We point the group to the next group.
489 treatment.group(new GroupId(nextGroupId));
490 GroupBucket groupBucket = DefaultGroupBucket
491 .createIndirectGroupBucket(treatment.build());
492 // Finally we build the group description.
493 int groupId = makeMplsLabelGroupId(subtype, index);
494 GroupKey groupKey = new DefaultGroupKey(
Saurav Dasa89b95a2018-02-14 14:14:54 -0800495 Ofdpa2Pipeline.appKryo.serialize(index));
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800496 return new DefaultGroupDescription(
497 deviceId,
498 INDIRECT,
499 new GroupBuckets(Collections.singletonList(groupBucket)),
500 groupKey,
501 groupId,
Saurav Dasa89b95a2018-02-14 14:14:54 -0800502 applicationId);
Andreas Pantelopoulos671d7462018-01-22 16:00:28 -0800503 }
504
505 /**
Charles Chan188ebf52015-12-23 00:15:11 -0800506 * Creates one of two possible group-chains from the treatment
507 * passed in. Depending on the MPLS boolean, this method either creates
Charles Chan425854b2016-04-11 15:32:12 -0700508 * an L3Unicast Group --&gt; L2Interface Group, if mpls is false;
509 * or MPLSInterface Group --&gt; L2Interface Group, if mpls is true;
Charles Chan188ebf52015-12-23 00:15:11 -0800510 * The returned 'inner' group description is always the L2 Interface group.
511 *
512 * @param treatment that needs to be broken up to create the group chain
513 * @param nextId of the next objective that needs this group chain
514 * @param appId of the application that sent this next objective
515 * @param mpls determines if L3Unicast or MPLSInterface group is created
516 * @param meta metadata passed in by the application as part of the nextObjective
517 * @return GroupInfo containing the GroupDescription of the
518 * L2Interface group(inner) and the GroupDescription of the (outer)
519 * L3Unicast/MPLSInterface group. May return null if there is an
520 * error in processing the chain
521 */
Charles Chan425854b2016-04-11 15:32:12 -0700522 protected GroupInfo createL2L3Chain(TrafficTreatment treatment, int nextId,
Charles Chanf9e98652016-09-07 16:54:23 -0700523 ApplicationId appId, boolean mpls,
524 TrafficSelector meta) {
525 return createL2L3ChainInternal(treatment, nextId, appId, mpls, meta, true);
526 }
527
528 /**
529 * Internal implementation of createL2L3Chain.
530 * <p>
531 * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12.
532 * Since it is non-OF spec, we need an extension treatment for that.
533 * The useSetVlanExtension must be set to false for OFDPA i12.
534 * </p>
535 *
536 * @param treatment that needs to be broken up to create the group chain
537 * @param nextId of the next objective that needs this group chain
538 * @param appId of the application that sent this next objective
539 * @param mpls determines if L3Unicast or MPLSInterface group is created
540 * @param meta metadata passed in by the application as part of the nextObjective
541 * @param useSetVlanExtension use the setVlanVid extension that has is_present bit set to 0.
542 * @return GroupInfo containing the GroupDescription of the
543 * L2Interface group(inner) and the GroupDescription of the (outer)
544 * L3Unicast/MPLSInterface group. May return null if there is an
545 * error in processing the chain
546 */
547 protected GroupInfo createL2L3ChainInternal(TrafficTreatment treatment, int nextId,
Pier Ventre42287df2016-11-09 14:17:26 -0800548 ApplicationId appId, boolean mpls,
549 TrafficSelector meta, boolean useSetVlanExtension) {
Charles Chan188ebf52015-12-23 00:15:11 -0800550 // for the l2interface group, get vlan and port info
551 // for the outer group, get the src/dst mac, and vlan info
552 TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
553 TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
554 VlanId vlanid = null;
555 long portNum = 0;
556 boolean setVlan = false, popVlan = false;
Yi Tseng78f51f42017-02-02 13:54:58 -0800557 MacAddress srcMac;
558 MacAddress dstMac;
Charles Chan188ebf52015-12-23 00:15:11 -0800559 for (Instruction ins : treatment.allInstructions()) {
560 if (ins.type() == Instruction.Type.L2MODIFICATION) {
561 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
562 switch (l2ins.subtype()) {
563 case ETH_DST:
Charles Chan5270ed02016-01-30 23:22:37 -0800564 dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
565 outerTtb.setEthDst(dstMac);
Charles Chan188ebf52015-12-23 00:15:11 -0800566 break;
567 case ETH_SRC:
Charles Chand0fd5dc2016-02-16 23:14:49 -0800568 srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
569 outerTtb.setEthSrc(srcMac);
Charles Chan188ebf52015-12-23 00:15:11 -0800570 break;
571 case VLAN_ID:
572 vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
Charles Chanf9e98652016-09-07 16:54:23 -0700573 if (useSetVlanExtension) {
574 OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid);
575 outerTtb.extension(ofdpaSetVlanVid, deviceId);
576 } else {
577 outerTtb.setVlanId(vlanid);
578 }
Charles Chan188ebf52015-12-23 00:15:11 -0800579 setVlan = true;
580 break;
581 case VLAN_POP:
582 innerTtb.popVlan();
583 popVlan = true;
584 break;
585 case DEC_MPLS_TTL:
586 case MPLS_LABEL:
587 case MPLS_POP:
588 case MPLS_PUSH:
589 case VLAN_PCP:
590 case VLAN_PUSH:
591 default:
592 break;
593 }
594 } else if (ins.type() == Instruction.Type.OUTPUT) {
595 portNum = ((Instructions.OutputInstruction) ins).port().toLong();
596 innerTtb.add(ins);
597 } else {
Saurav Das7bcbe702017-06-13 15:35:54 -0700598 log.debug("Driver does not handle this type of TrafficTreatment"
Saurav Dasa89b95a2018-02-14 14:14:54 -0800599 + " instruction in l2l3chain: {} - {}", ins.type(),
600 ins);
Charles Chan188ebf52015-12-23 00:15:11 -0800601 }
602 }
Charles Chan188ebf52015-12-23 00:15:11 -0800603 if (vlanid == null && meta != null) {
604 // use metadata if available
Pier Ventre140a8942016-11-02 07:26:38 -0700605 Criterion vidCriterion = meta.getCriterion(VLAN_VID);
Charles Chan188ebf52015-12-23 00:15:11 -0800606 if (vidCriterion != null) {
607 vlanid = ((VlanIdCriterion) vidCriterion).vlanId();
608 }
609 // if vlan is not set, use the vlan in metadata for outerTtb
610 if (vlanid != null && !setVlan) {
Charles Chanf9e98652016-09-07 16:54:23 -0700611 if (useSetVlanExtension) {
612 OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid);
613 outerTtb.extension(ofdpaSetVlanVid, deviceId);
614 } else {
615 outerTtb.setVlanId(vlanid);
616 }
Charles Chan188ebf52015-12-23 00:15:11 -0800617 }
618 }
Charles Chan188ebf52015-12-23 00:15:11 -0800619 if (vlanid == null) {
620 log.error("Driver cannot process an L2/L3 group chain without "
621 + "egress vlan information for dev: {} port:{}",
622 deviceId, portNum);
623 return null;
624 }
Charles Chan188ebf52015-12-23 00:15:11 -0800625 if (!setVlan && !popVlan) {
626 // untagged outgoing port
627 TrafficTreatment.Builder temp = DefaultTrafficTreatment.builder();
628 temp.popVlan();
Yi Tsengef19de12017-04-24 11:33:05 -0700629 innerTtb.build().allInstructions().forEach(temp::add);
Charles Chan188ebf52015-12-23 00:15:11 -0800630 innerTtb = temp;
631 }
Charles Chan188ebf52015-12-23 00:15:11 -0800632 // assemble information for ofdpa l2interface group
Yi Tsengef19de12017-04-24 11:33:05 -0700633 int l2groupId = l2GroupId(vlanid, portNum);
Saurav Das8be4e3a2016-03-11 17:19:07 -0800634 // a globally unique groupkey that is different for ports in the same device,
Charles Chan188ebf52015-12-23 00:15:11 -0800635 // but different for the same portnumber on different devices. Also different
636 // for the various group-types created out of the same next objective.
Charles Chane849c192016-01-11 18:28:54 -0800637 int l2gk = l2InterfaceGroupKey(deviceId, vlanid, portNum);
Yi Tsengef19de12017-04-24 11:33:05 -0700638 final GroupKey l2groupkey = new DefaultGroupKey(appKryo.serialize(l2gk));
Charles Chan188ebf52015-12-23 00:15:11 -0800639 // assemble information for outer group
Yi Tsengef19de12017-04-24 11:33:05 -0700640 GroupDescription outerGrpDesc;
Charles Chan188ebf52015-12-23 00:15:11 -0800641 if (mpls) {
Yi Tsengef19de12017-04-24 11:33:05 -0700642 // outer group is MPLS Interface
Saurav Das8be4e3a2016-03-11 17:19:07 -0800643 int mplsInterfaceIndex = getNextAvailableIndex();
Yi Tsengef19de12017-04-24 11:33:05 -0700644 int mplsGroupId = MPLS_INTERFACE_TYPE | (SUBTYPE_MASK & mplsInterfaceIndex);
645 final GroupKey mplsGroupKey = new DefaultGroupKey(
646 appKryo.serialize(mplsInterfaceIndex));
Yi Tsengfa394de2017-02-01 11:26:40 -0800647 outerTtb.group(new GroupId(l2groupId));
Charles Chan188ebf52015-12-23 00:15:11 -0800648 // create the mpls-interface group description to wait for the
649 // l2 interface group to be processed
650 GroupBucket mplsinterfaceGroupBucket =
651 DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
652 outerGrpDesc = new DefaultGroupDescription(
653 deviceId,
654 GroupDescription.Type.INDIRECT,
655 new GroupBuckets(Collections.singletonList(
656 mplsinterfaceGroupBucket)),
Yi Tsengef19de12017-04-24 11:33:05 -0700657 mplsGroupKey,
658 mplsGroupId,
Charles Chan188ebf52015-12-23 00:15:11 -0800659 appId);
660 log.debug("Trying MPLS-Interface: device:{} gid:{} gkey:{} nextid:{}",
Yi Tsengef19de12017-04-24 11:33:05 -0700661 deviceId, Integer.toHexString(mplsGroupId),
662 mplsGroupKey, nextId);
Charles Chan188ebf52015-12-23 00:15:11 -0800663 } else {
664 // outer group is L3Unicast
Saurav Das8be4e3a2016-03-11 17:19:07 -0800665 int l3unicastIndex = getNextAvailableIndex();
666 int l3groupId = L3_UNICAST_TYPE | (TYPE_MASK & l3unicastIndex);
667 final GroupKey l3groupkey = new DefaultGroupKey(
Yi Tsengef19de12017-04-24 11:33:05 -0700668 appKryo.serialize(l3unicastIndex));
Yi Tsengfa394de2017-02-01 11:26:40 -0800669 outerTtb.group(new GroupId(l2groupId));
Charles Chan188ebf52015-12-23 00:15:11 -0800670 // create the l3unicast group description to wait for the
671 // l2 interface group to be processed
672 GroupBucket l3unicastGroupBucket =
673 DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
674 outerGrpDesc = new DefaultGroupDescription(
675 deviceId,
676 GroupDescription.Type.INDIRECT,
Yi Tsengef19de12017-04-24 11:33:05 -0700677 new GroupBuckets(Collections.singletonList(l3unicastGroupBucket)),
Charles Chan188ebf52015-12-23 00:15:11 -0800678 l3groupkey,
679 l3groupId,
680 appId);
681 log.debug("Trying L3Unicast: device:{} gid:{} gkey:{} nextid:{}",
682 deviceId, Integer.toHexString(l3groupId),
683 l3groupkey, nextId);
684 }
Charles Chan188ebf52015-12-23 00:15:11 -0800685 // store l2groupkey with the groupChainElem for the outer-group that depends on it
Yi Tsengef19de12017-04-24 11:33:05 -0700686 GroupChainElem gce = new GroupChainElem(outerGrpDesc, 1, false, deviceId);
Charles Chan188ebf52015-12-23 00:15:11 -0800687 updatePendingGroups(l2groupkey, gce);
Yi Tsengef19de12017-04-24 11:33:05 -0700688 // create group description for the inner l2 interface group
Charles Chan5b9df8d2016-03-28 22:21:40 -0700689 GroupBucket l2InterfaceGroupBucket =
Charles Chan188ebf52015-12-23 00:15:11 -0800690 DefaultGroupBucket.createIndirectGroupBucket(innerTtb.build());
691 GroupDescription l2groupDescription =
Yi Tsengef19de12017-04-24 11:33:05 -0700692 new DefaultGroupDescription(deviceId,
693 GroupDescription.Type.INDIRECT,
694 new GroupBuckets(Collections.singletonList(l2InterfaceGroupBucket)),
695 l2groupkey,
696 l2groupId,
697 appId);
Charles Chan188ebf52015-12-23 00:15:11 -0800698 log.debug("Trying L2Interface: device:{} gid:{} gkey:{} nextId:{}",
699 deviceId, Integer.toHexString(l2groupId),
700 l2groupkey, nextId);
701 return new GroupInfo(l2groupDescription, outerGrpDesc);
Charles Chan188ebf52015-12-23 00:15:11 -0800702 }
703
704 /**
705 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
706 * a chain of groups. The broadcast Next Objective passed in by the application
707 * has to be broken up into a group chain comprising of an
Saurav Das1a129a02016-11-18 15:21:57 -0800708 * L2 Flood group or L3 Multicast group, whose buckets point to L2 Interface groups.
Charles Chan188ebf52015-12-23 00:15:11 -0800709 *
710 * @param nextObj the nextObjective of type BROADCAST
711 */
712 private void processBroadcastNextObjective(NextObjective nextObj) {
Yi Tsengef19de12017-04-24 11:33:05 -0700713 VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700714 if (assignedVlan == null) {
715 log.warn("VLAN ID required by broadcast next obj is missing. Abort.");
Yi Tsengef19de12017-04-24 11:33:05 -0700716 fail(nextObj, ObjectiveError.BADPARAMS);
Charles Chan188ebf52015-12-23 00:15:11 -0800717 return;
718 }
Charles Chan188ebf52015-12-23 00:15:11 -0800719
jayakumarthazhathad3636a2018-10-01 00:51:54 +0530720 // Handling L2 multicast cases.
721 MacAddress dstMac = readEthDstFromSelector(nextObj.meta());
722 if (dstMac != null && dstMac.isMulticast()) {
723 processL2MulticastNextObjective(nextObj);
Jayakumar Thazhathc4857832018-10-24 01:22:04 -0400724 return;
jayakumarthazhathad3636a2018-10-01 00:51:54 +0530725 }
Charles Chan5b9df8d2016-03-28 22:21:40 -0700726
jayakumarthazhathad3636a2018-10-01 00:51:54 +0530727 List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
Yi Tsengef19de12017-04-24 11:33:05 -0700728 IpPrefix ipDst = readIpDstFromSelector(nextObj.meta());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700729 if (ipDst != null) {
730 if (ipDst.isMulticast()) {
731 createL3MulticastGroup(nextObj, assignedVlan, groupInfos);
732 } else {
733 log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj);
Yi Tsengef19de12017-04-24 11:33:05 -0700734 fail(nextObj, ObjectiveError.BADPARAMS);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700735 }
736 } else {
737 createL2FloodGroup(nextObj, assignedVlan, groupInfos);
738 }
739 }
740
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700741 private List<GroupInfo> prepareL2InterfaceGroup(NextObjective nextObj,
742 VlanId assignedVlan) {
Charles Chan5b9df8d2016-03-28 22:21:40 -0700743 ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700744 // break up broadcast next objective to multiple groups
745 Collection<TrafficTreatment> buckets = nextObj.next();
Charles Chan188ebf52015-12-23 00:15:11 -0800746 // each treatment is converted to an L2 interface group
Charles Chan188ebf52015-12-23 00:15:11 -0800747 for (TrafficTreatment treatment : buckets) {
748 TrafficTreatment.Builder newTreatment = DefaultTrafficTreatment.builder();
749 PortNumber portNum = null;
Charles Chan5b9df8d2016-03-28 22:21:40 -0700750 VlanId egressVlan = null;
Charles Chan188ebf52015-12-23 00:15:11 -0800751 // ensure that the only allowed treatments are pop-vlan and output
752 for (Instruction ins : treatment.allInstructions()) {
753 if (ins.type() == Instruction.Type.L2MODIFICATION) {
754 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
755 switch (l2ins.subtype()) {
756 case VLAN_POP:
757 newTreatment.add(l2ins);
758 break;
Charles Chan5b9df8d2016-03-28 22:21:40 -0700759 case VLAN_ID:
760 egressVlan = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
761 break;
Charles Chan188ebf52015-12-23 00:15:11 -0800762 default:
763 log.debug("action {} not permitted for broadcast nextObj",
764 l2ins.subtype());
765 break;
766 }
767 } else if (ins.type() == Instruction.Type.OUTPUT) {
768 portNum = ((Instructions.OutputInstruction) ins).port();
769 newTreatment.add(ins);
770 } else {
Charles Chane849c192016-01-11 18:28:54 -0800771 log.debug("TrafficTreatment of type {} not permitted in " +
772 " broadcast nextObjective", ins.type());
Charles Chan188ebf52015-12-23 00:15:11 -0800773 }
774 }
Yi Tsengef19de12017-04-24 11:33:05 -0700775 if (portNum == null) {
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +0000776 log.debug("Can't find output port for the bucket {}.", treatment);
Yi Tsengef19de12017-04-24 11:33:05 -0700777 continue;
778 }
Charles Chan188ebf52015-12-23 00:15:11 -0800779 // assemble info for l2 interface group
Charles Chan5b9df8d2016-03-28 22:21:40 -0700780 VlanId l2InterfaceGroupVlan =
781 (egressVlan != null && !assignedVlan.equals(egressVlan)) ?
782 egressVlan : assignedVlan;
783 int l2gk = l2InterfaceGroupKey(deviceId, l2InterfaceGroupVlan, portNum.toLong());
784 final GroupKey l2InterfaceGroupKey =
Yi Tsengef19de12017-04-24 11:33:05 -0700785 new DefaultGroupKey(appKryo.serialize(l2gk));
Charles Chan372b63e2017-02-07 12:10:53 -0800786 int l2InterfaceGroupId = L2_INTERFACE_TYPE |
787 ((l2InterfaceGroupVlan.toShort() & THREE_BIT_MASK) << PORT_LEN) |
788 ((int) portNum.toLong() & FOUR_BIT_MASK);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700789 GroupBucket l2InterfaceGroupBucket =
Charles Chan188ebf52015-12-23 00:15:11 -0800790 DefaultGroupBucket.createIndirectGroupBucket(newTreatment.build());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700791 GroupDescription l2InterfaceGroupDescription =
Yi Tsengef19de12017-04-24 11:33:05 -0700792 new DefaultGroupDescription(deviceId,
793 GroupDescription.Type.INDIRECT,
794 new GroupBuckets(Collections.singletonList(
795 l2InterfaceGroupBucket)),
796 l2InterfaceGroupKey,
797 l2InterfaceGroupId,
798 nextObj.appId());
Charles Chan188ebf52015-12-23 00:15:11 -0800799 log.debug("Trying L2-Interface: device:{} gid:{} gkey:{} nextid:{}",
Charles Chan5b9df8d2016-03-28 22:21:40 -0700800 deviceId, Integer.toHexString(l2InterfaceGroupId),
801 l2InterfaceGroupKey, nextObj.id());
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +0000802
Charles Chan5b9df8d2016-03-28 22:21:40 -0700803 groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDescription,
804 l2InterfaceGroupDescription));
Charles Chan188ebf52015-12-23 00:15:11 -0800805 }
Charles Chan5b9df8d2016-03-28 22:21:40 -0700806 return groupInfoBuilder.build();
807 }
Charles Chan188ebf52015-12-23 00:15:11 -0800808
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +0000809 private GroupInfo prepareL3UnicastGroup(NextObjective nextObj, NextGroup next) {
810
811 ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder();
812 TrafficTreatment treatment = nextObj.next().iterator().next();
813
814 VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
815 if (assignedVlan == null) {
816 log.warn("VLAN ID required by next obj is missing. Abort.");
817 return null;
818 }
819
820 List<GroupInfo> l2GroupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
821 GroupDescription l2InterfaceGroupDesc = l2GroupInfos.get(0).innerMostGroupDesc();
822 GroupKey l2groupkey = l2InterfaceGroupDesc.appCookie();
823
824 TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
825 VlanId vlanid = null;
826 MacAddress srcMac;
827 MacAddress dstMac;
828 for (Instruction ins : treatment.allInstructions()) {
829 if (ins.type() == Instruction.Type.L2MODIFICATION) {
830 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
831 switch (l2ins.subtype()) {
832 case ETH_DST:
833 dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
834 outerTtb.setEthDst(dstMac);
835 break;
836 case ETH_SRC:
837 srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
838 outerTtb.setEthSrc(srcMac);
839 break;
840 case VLAN_ID:
841 vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
842 outerTtb.setVlanId(vlanid);
843 break;
844 default:
845 break;
846 }
847 } else {
848 log.debug("Driver does not handle this type of TrafficTreatment"
849 + " instruction in l2l3chain: {} - {}", ins.type(), ins);
850 }
851 }
852
853 GroupId l2groupId = new GroupId(l2InterfaceGroupDesc.givenGroupId());
854 outerTtb.group(l2groupId);
855
856 // we need the top level group's key to point the flow to it
857 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
858 GroupKey l3groupkey = gkeys.get(0).peekFirst();
859 GroupId grpId = groupService.getGroup(deviceId, l3groupkey).id();
860 int l3groupId = grpId.id();
861
862 // create the l3unicast group description to wait for the
863 // l2 interface group to be processed
864 GroupBucket l3UnicastGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
865
866 GroupDescription l3UnicastGroupDescription = new DefaultGroupDescription(deviceId,
867 GroupDescription.Type.INDIRECT,
868 new GroupBuckets(Collections.singletonList(
869 l3UnicastGroupBucket)), l3groupkey,
870 l3groupId, nextObj.appId());
871
872 // store l2groupkey with the groupChainElem for the outer-group that depends on it
873 GroupChainElem gce = new GroupChainElem(l3UnicastGroupDescription, 1, false, deviceId);
874 updatePendingGroups(l2groupkey, gce);
875
876 log.debug("Trying L3-Interface: device:{} gid:{} gkey:{} nextid:{}",
877 deviceId, Integer.toHexString(l3groupId), l3groupkey, nextObj.id());
878
879 groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDesc,
880 l3UnicastGroupDescription));
881
882 return groupInfoBuilder.build().iterator().next();
883 }
884
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700885 private void createL2FloodGroup(NextObjective nextObj, VlanId vlanId,
886 List<GroupInfo> groupInfos) {
887 // assemble info for l2 flood group. Since there can be only one flood
888 // group for a vlan, its index is always the same - 0
Yi Tsengef19de12017-04-24 11:33:05 -0700889 Integer l2FloodGroupId = L2_FLOOD_TYPE | (vlanId.toShort() << 16);
890 final GroupKey l2FloodGroupKey = l2FloodGroupKey(vlanId, deviceId);
Charles Chan188ebf52015-12-23 00:15:11 -0800891 // collection of group buckets pointing to all the l2 interface groups
Yi Tsengef19de12017-04-24 11:33:05 -0700892 List<GroupBucket> l2floodBuckets = generateNextGroupBuckets(groupInfos, ALL);
Charles Chan188ebf52015-12-23 00:15:11 -0800893 // create the l2flood group-description to wait for all the
894 // l2interface groups to be processed
895 GroupDescription l2floodGroupDescription =
896 new DefaultGroupDescription(
897 deviceId,
Yi Tseng78f51f42017-02-02 13:54:58 -0800898 ALL,
Charles Chan188ebf52015-12-23 00:15:11 -0800899 new GroupBuckets(l2floodBuckets),
Yi Tsengef19de12017-04-24 11:33:05 -0700900 l2FloodGroupKey,
901 l2FloodGroupId,
Charles Chan188ebf52015-12-23 00:15:11 -0800902 nextObj.appId());
Charles Chan188ebf52015-12-23 00:15:11 -0800903 log.debug("Trying L2-Flood: device:{} gid:{} gkey:{} nextid:{}",
Yi Tsengef19de12017-04-24 11:33:05 -0700904 deviceId, Integer.toHexString(l2FloodGroupId),
905 l2FloodGroupKey, nextObj.id());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700906 // Put all dependency information into allGroupKeys
907 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
908 groupInfos.forEach(groupInfo -> {
Yi Tsengef19de12017-04-24 11:33:05 -0700909 Deque<GroupKey> groupKeyChain = new ArrayDeque<>();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700910 // In this case we should have L2 interface group only
Yi Tsengef19de12017-04-24 11:33:05 -0700911 groupKeyChain.addFirst(groupInfo.nextGroupDesc().appCookie());
912 groupKeyChain.addFirst(l2FloodGroupKey);
913 allGroupKeys.add(groupKeyChain);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700914 });
Charles Chan5b9df8d2016-03-28 22:21:40 -0700915 // Point the next objective to this group
916 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
Yi Tsengef19de12017-04-24 11:33:05 -0700917 updatePendingNextObjective(l2FloodGroupKey, ofdpaGrp);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700918 GroupChainElem gce = new GroupChainElem(l2floodGroupDescription,
Yi Tsengef19de12017-04-24 11:33:05 -0700919 groupInfos.size(), false, deviceId);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700920 groupInfos.forEach(groupInfo -> {
921 // Point this group to the next group
Yi Tsengef19de12017-04-24 11:33:05 -0700922 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), gce);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700923 // Start installing the inner-most group
Yi Tsengef19de12017-04-24 11:33:05 -0700924 groupService.addGroup(groupInfo.innerMostGroupDesc());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700925 });
926 }
927
Pier Luigi7b7a29d2018-01-19 10:24:53 +0100928 private void createL3MulticastGroup(NextObjective nextObj, VlanId vlanId,
929 List<GroupInfo> groupInfos) {
930 // Let's create a new list mcast buckets
931 List<GroupBucket> l3McastBuckets = createL3MulticastBucket(groupInfos);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700932
933 int l3MulticastIndex = getNextAvailableIndex();
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700934 int l3MulticastGroupId = L3_MULTICAST_TYPE |
935 vlanId.toShort() << 16 | (TYPE_VLAN_MASK & l3MulticastIndex);
936 final GroupKey l3MulticastGroupKey =
Yi Tsengef19de12017-04-24 11:33:05 -0700937 new DefaultGroupKey(appKryo.serialize(l3MulticastIndex));
Charles Chan5b9df8d2016-03-28 22:21:40 -0700938
939 GroupDescription l3MulticastGroupDesc = new DefaultGroupDescription(deviceId,
Yi Tseng78f51f42017-02-02 13:54:58 -0800940 ALL,
Charles Chan5b9df8d2016-03-28 22:21:40 -0700941 new GroupBuckets(l3McastBuckets),
942 l3MulticastGroupKey,
943 l3MulticastGroupId,
944 nextObj.appId());
945
946 // Put all dependency information into allGroupKeys
947 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
948 groupInfos.forEach(groupInfo -> {
949 Deque<GroupKey> gkeyChain = new ArrayDeque<>();
Yi Tsengef19de12017-04-24 11:33:05 -0700950 gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700951 // Add L3 interface group to the chain if there is one.
Yi Tsengef19de12017-04-24 11:33:05 -0700952 if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
953 gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700954 }
955 gkeyChain.addFirst(l3MulticastGroupKey);
956 allGroupKeys.add(gkeyChain);
957 });
Charles Chan5b9df8d2016-03-28 22:21:40 -0700958 // Point the next objective to this group
959 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
960 updatePendingNextObjective(l3MulticastGroupKey, ofdpaGrp);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700961 GroupChainElem outerGce = new GroupChainElem(l3MulticastGroupDesc,
Yi Tsengef19de12017-04-24 11:33:05 -0700962 groupInfos.size(), false, deviceId);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700963 groupInfos.forEach(groupInfo -> {
964 // Point this group (L3 multicast) to the next group
Yi Tsengef19de12017-04-24 11:33:05 -0700965 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), outerGce);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700966 // Point next group to inner-most group, if any
Yi Tsengef19de12017-04-24 11:33:05 -0700967 if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
968 GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(),
969 1, false, deviceId);
970 updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700971 }
Charles Chan5b9df8d2016-03-28 22:21:40 -0700972 // Start installing the inner-most group
Yi Tsengef19de12017-04-24 11:33:05 -0700973 groupService.addGroup(groupInfo.innerMostGroupDesc());
Charles Chan5b9df8d2016-03-28 22:21:40 -0700974 });
Charles Chan188ebf52015-12-23 00:15:11 -0800975 }
976
Charles Chan188ebf52015-12-23 00:15:11 -0800977 /**
978 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
979 * a chain of groups. The hashed Next Objective passed in by the application
980 * has to be broken up into a group chain comprising of an
981 * L3 ECMP group as the top level group. Buckets of this group can point
982 * to a variety of groups in a group chain, depending on the whether
983 * MPLS labels are being pushed or not.
984 * <p>
985 * NOTE: We do not create MPLS ECMP groups as they are unimplemented in
986 * OF-DPA 2.0 (even though it is in the spec). Therefore we do not
987 * check the nextObjective meta to see what is matching before being
988 * sent to this nextObjective.
989 *
990 * @param nextObj the nextObjective of type HASHED
991 */
Pier Ventre140a8942016-11-02 07:26:38 -0700992 protected void processHashedNextObjective(NextObjective nextObj) {
Charles Chan188ebf52015-12-23 00:15:11 -0800993 // storage for all group keys in the chain of groups created
994 List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
995 List<GroupInfo> unsentGroups = new ArrayList<>();
996 createHashBucketChains(nextObj, allGroupKeys, unsentGroups);
Charles Chan188ebf52015-12-23 00:15:11 -0800997 // now we can create the outermost L3 ECMP group
998 List<GroupBucket> l3ecmpGroupBuckets = new ArrayList<>();
999 for (GroupInfo gi : unsentGroups) {
1000 // create ECMP bucket to point to the outer group
1001 TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();
Yi Tsengef19de12017-04-24 11:33:05 -07001002 ttb.group(new GroupId(gi.nextGroupDesc().givenGroupId()));
Charles Chan188ebf52015-12-23 00:15:11 -08001003 GroupBucket sbucket = DefaultGroupBucket
1004 .createSelectGroupBucket(ttb.build());
1005 l3ecmpGroupBuckets.add(sbucket);
1006 }
Saurav Das8be4e3a2016-03-11 17:19:07 -08001007 int l3ecmpIndex = getNextAvailableIndex();
1008 int l3ecmpGroupId = L3_ECMP_TYPE | (TYPE_MASK & l3ecmpIndex);
1009 GroupKey l3ecmpGroupKey = new DefaultGroupKey(
Yi Tsengef19de12017-04-24 11:33:05 -07001010 appKryo.serialize(l3ecmpIndex));
Charles Chan188ebf52015-12-23 00:15:11 -08001011 GroupDescription l3ecmpGroupDesc =
1012 new DefaultGroupDescription(
1013 deviceId,
Yi Tseng78f51f42017-02-02 13:54:58 -08001014 SELECT,
Charles Chan188ebf52015-12-23 00:15:11 -08001015 new GroupBuckets(l3ecmpGroupBuckets),
1016 l3ecmpGroupKey,
1017 l3ecmpGroupId,
1018 nextObj.appId());
1019 GroupChainElem l3ecmpGce = new GroupChainElem(l3ecmpGroupDesc,
1020 l3ecmpGroupBuckets.size(),
Yi Tsengef19de12017-04-24 11:33:05 -07001021 false, deviceId);
Charles Chan188ebf52015-12-23 00:15:11 -08001022
1023 // create objects for local and distributed storage
Yi Tsengef19de12017-04-24 11:33:05 -07001024 allGroupKeys.forEach(gKeyChain -> gKeyChain.addFirst(l3ecmpGroupKey));
Charles Chan188ebf52015-12-23 00:15:11 -08001025 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
Charles Chan188ebf52015-12-23 00:15:11 -08001026 // store l3ecmpGroupKey with the ofdpaGroupChain for the nextObjective
1027 // that depends on it
1028 updatePendingNextObjective(l3ecmpGroupKey, ofdpaGrp);
Charles Chan188ebf52015-12-23 00:15:11 -08001029 log.debug("Trying L3ECMP: device:{} gid:{} gkey:{} nextId:{}",
1030 deviceId, Integer.toHexString(l3ecmpGroupId),
1031 l3ecmpGroupKey, nextObj.id());
1032 // finally we are ready to send the innermost groups
1033 for (GroupInfo gi : unsentGroups) {
1034 log.debug("Sending innermost group {} in group chain on device {} ",
Yi Tsengef19de12017-04-24 11:33:05 -07001035 Integer.toHexString(gi.innerMostGroupDesc().givenGroupId()), deviceId);
1036 updatePendingGroups(gi.nextGroupDesc().appCookie(), l3ecmpGce);
1037 groupService.addGroup(gi.innerMostGroupDesc());
Charles Chan188ebf52015-12-23 00:15:11 -08001038 }
Charles Chan188ebf52015-12-23 00:15:11 -08001039 }
1040
1041 /**
1042 * Creates group chains for all buckets in a hashed group, and stores the
1043 * GroupInfos and GroupKeys for all the groups in the lists passed in, which
1044 * should be empty.
1045 * <p>
1046 * Does not create the top level ECMP group. Does not actually send the
1047 * groups to the groupService.
1048 *
1049 * @param nextObj the Next Objective with buckets that need to be converted
1050 * to group chains
1051 * @param allGroupKeys a list to store groupKey for each bucket-group-chain
1052 * @param unsentGroups a list to store GroupInfo for each bucket-group-chain
1053 */
Pier Ventre140a8942016-11-02 07:26:38 -07001054 protected void createHashBucketChains(NextObjective nextObj,
Yi Tsengef19de12017-04-24 11:33:05 -07001055 List<Deque<GroupKey>> allGroupKeys,
1056 List<GroupInfo> unsentGroups) {
Charles Chan188ebf52015-12-23 00:15:11 -08001057 // break up hashed next objective to multiple groups
1058 Collection<TrafficTreatment> buckets = nextObj.next();
1059
1060 for (TrafficTreatment bucket : buckets) {
1061 //figure out how many labels are pushed in each bucket
1062 int labelsPushed = 0;
1063 MplsLabel innermostLabel = null;
1064 for (Instruction ins : bucket.allInstructions()) {
1065 if (ins.type() == Instruction.Type.L2MODIFICATION) {
1066 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
1067 if (l2ins.subtype() == L2ModificationInstruction.L2SubType.MPLS_PUSH) {
1068 labelsPushed++;
1069 }
1070 if (l2ins.subtype() == L2ModificationInstruction.L2SubType.MPLS_LABEL) {
1071 if (innermostLabel == null) {
Yi Tsengef19de12017-04-24 11:33:05 -07001072 innermostLabel =
1073 ((L2ModificationInstruction.ModMplsLabelInstruction) l2ins).label();
Charles Chan188ebf52015-12-23 00:15:11 -08001074 }
1075 }
1076 }
1077 }
Yi Tsengef19de12017-04-24 11:33:05 -07001078 Deque<GroupKey> gKeyChain = new ArrayDeque<>();
Saurav Dasa89b95a2018-02-14 14:14:54 -08001079 // here we only deal with 0 and 1 label push
Charles Chan188ebf52015-12-23 00:15:11 -08001080 if (labelsPushed == 0) {
Yi Tsengef19de12017-04-24 11:33:05 -07001081 GroupInfo noLabelGroupInfo;
Pier Ventre140a8942016-11-02 07:26:38 -07001082 TrafficSelector metaSelector = nextObj.meta();
1083 if (metaSelector != null) {
1084 if (isNotMplsBos(metaSelector)) {
Yi Tsengef19de12017-04-24 11:33:05 -07001085 noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(),
1086 nextObj.appId(), true,
1087 nextObj.meta());
Pier Ventre140a8942016-11-02 07:26:38 -07001088 } else {
Yi Tsengef19de12017-04-24 11:33:05 -07001089 noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(),
1090 nextObj.appId(), false,
1091 nextObj.meta());
Pier Ventre140a8942016-11-02 07:26:38 -07001092 }
1093 } else {
Yi Tsengef19de12017-04-24 11:33:05 -07001094 noLabelGroupInfo = createL2L3Chain(bucket, nextObj.id(),
1095 nextObj.appId(), false,
1096 nextObj.meta());
Pier Ventre140a8942016-11-02 07:26:38 -07001097 }
Yi Tsengef19de12017-04-24 11:33:05 -07001098 if (noLabelGroupInfo == null) {
Charles Chan188ebf52015-12-23 00:15:11 -08001099 log.error("Could not process nextObj={} in dev:{}",
1100 nextObj.id(), deviceId);
1101 return;
1102 }
Yi Tsengef19de12017-04-24 11:33:05 -07001103 gKeyChain.addFirst(noLabelGroupInfo.innerMostGroupDesc().appCookie());
1104 gKeyChain.addFirst(noLabelGroupInfo.nextGroupDesc().appCookie());
Charles Chan188ebf52015-12-23 00:15:11 -08001105 // we can't send the inner group description yet, as we have to
1106 // create the dependent ECMP group first. So we store..
Yi Tsengef19de12017-04-24 11:33:05 -07001107 unsentGroups.add(noLabelGroupInfo);
Charles Chan188ebf52015-12-23 00:15:11 -08001108 } else if (labelsPushed == 1) {
1109 GroupInfo onelabelGroupInfo = createL2L3Chain(bucket, nextObj.id(),
1110 nextObj.appId(), true,
1111 nextObj.meta());
1112 if (onelabelGroupInfo == null) {
1113 log.error("Could not process nextObj={} in dev:{}",
1114 nextObj.id(), deviceId);
1115 return;
1116 }
1117 // we need to add another group to this chain - the L3VPN group
1118 TrafficTreatment.Builder l3vpnTtb = DefaultTrafficTreatment.builder();
Charles Chan0f43e472017-02-14 14:00:16 -08001119 if (requireVlanPopBeforeMplsPush()) {
1120 l3vpnTtb.popVlan();
1121 }
Charles Chan188ebf52015-12-23 00:15:11 -08001122 l3vpnTtb.pushMpls()
1123 .setMpls(innermostLabel)
Yi Tsengef19de12017-04-24 11:33:05 -07001124 .group(new GroupId(onelabelGroupInfo.nextGroupDesc().givenGroupId()));
Charles Chan40132b32017-01-22 00:19:37 -08001125 if (supportCopyTtl()) {
1126 l3vpnTtb.copyTtlOut();
1127 }
1128 if (supportSetMplsBos()) {
1129 l3vpnTtb.setMplsBos(true);
1130 }
Charles Chan0f43e472017-02-14 14:00:16 -08001131 if (requireVlanPopBeforeMplsPush()) {
1132 l3vpnTtb.pushVlan().setVlanId(VlanId.vlanId(VlanId.RESERVED));
1133 }
Charles Chan188ebf52015-12-23 00:15:11 -08001134 GroupBucket l3vpnGrpBkt =
1135 DefaultGroupBucket.createIndirectGroupBucket(l3vpnTtb.build());
Saurav Das8be4e3a2016-03-11 17:19:07 -08001136 int l3vpnIndex = getNextAvailableIndex();
Yi Tsengef19de12017-04-24 11:33:05 -07001137 int l3vpnGroupId = MPLS_L3VPN_SUBTYPE | (SUBTYPE_MASK & l3vpnIndex);
1138 GroupKey l3vpnGroupKey = new DefaultGroupKey(
1139 appKryo.serialize(l3vpnIndex));
Charles Chan188ebf52015-12-23 00:15:11 -08001140 GroupDescription l3vpnGroupDesc =
1141 new DefaultGroupDescription(
1142 deviceId,
1143 GroupDescription.Type.INDIRECT,
Yi Tsengef19de12017-04-24 11:33:05 -07001144 new GroupBuckets(Collections.singletonList(l3vpnGrpBkt)),
1145 l3vpnGroupKey,
1146 l3vpnGroupId,
Charles Chan188ebf52015-12-23 00:15:11 -08001147 nextObj.appId());
Yi Tsengef19de12017-04-24 11:33:05 -07001148 GroupChainElem l3vpnGce = new GroupChainElem(l3vpnGroupDesc,
1149 1,
1150 false,
1151 deviceId);
1152 updatePendingGroups(onelabelGroupInfo.nextGroupDesc().appCookie(), l3vpnGce);
Charles Chan188ebf52015-12-23 00:15:11 -08001153
Yi Tsengef19de12017-04-24 11:33:05 -07001154 gKeyChain.addFirst(onelabelGroupInfo.innerMostGroupDesc().appCookie());
1155 gKeyChain.addFirst(onelabelGroupInfo.nextGroupDesc().appCookie());
1156 gKeyChain.addFirst(l3vpnGroupKey);
Charles Chan188ebf52015-12-23 00:15:11 -08001157 //now we can replace the outerGrpDesc with the one we just created
Yi Tsengef19de12017-04-24 11:33:05 -07001158 onelabelGroupInfo.nextGroupDesc(l3vpnGroupDesc);
Charles Chan188ebf52015-12-23 00:15:11 -08001159 // we can't send the innermost group yet, as we have to create
1160 // the dependent ECMP group first. So we store ...
1161 unsentGroups.add(onelabelGroupInfo);
Yi Tsengef19de12017-04-24 11:33:05 -07001162 log.debug("Trying L3VPN: device:{} gid:{} group key:{} nextId:{}",
1163 deviceId, Integer.toHexString(l3vpnGroupId),
1164 l3vpnGroupKey, nextObj.id());
Charles Chan188ebf52015-12-23 00:15:11 -08001165 } else {
1166 log.warn("Driver currently does not handle more than 1 MPLS "
1167 + "labels. Not processing nextObjective {}", nextObj.id());
1168 return;
1169 }
Charles Chan188ebf52015-12-23 00:15:11 -08001170 // all groups in this chain
Yi Tsengef19de12017-04-24 11:33:05 -07001171 allGroupKeys.add(gKeyChain);
Charles Chan188ebf52015-12-23 00:15:11 -08001172 }
1173 }
1174
Pier Ventre42287df2016-11-09 14:17:26 -08001175 /**
1176 * Processes the pseudo wire related next objective.
1177 * This procedure try to reuse the mpls label groups,
1178 * the mpls interface group and the l2 interface group.
1179 *
1180 * @param nextObjective the objective to process.
1181 */
1182 protected void processPwNextObjective(NextObjective nextObjective) {
Saurav Das1547b3f2017-05-05 17:01:08 -07001183 log.warn("Pseudo wire extensions are not supported in OFDPA 2.0 {}",
1184 nextObjective.id());
Pier Ventre42287df2016-11-09 14:17:26 -08001185 }
1186
Saurav Das8be4e3a2016-03-11 17:19:07 -08001187 //////////////////////////////////////
1188 // Group Editing
1189 //////////////////////////////////////
Charles Chan188ebf52015-12-23 00:15:11 -08001190 /**
1191 * Adds a bucket to the top level group of a group-chain, and creates the chain.
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001192 * Ensures that bucket being added is not a duplicate, by checking existing
Yi Tsengef19de12017-04-24 11:33:05 -07001193 * buckets for the same output port.
Charles Chan188ebf52015-12-23 00:15:11 -08001194 *
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001195 * @param nextObjective the bucket information for a next group
Charles Chan188ebf52015-12-23 00:15:11 -08001196 * @param next the representation of the existing group-chain for this next objective
1197 */
1198 protected void addBucketToGroup(NextObjective nextObjective, NextGroup next) {
Saurav Das1a129a02016-11-18 15:21:57 -08001199 if (nextObjective.type() != NextObjective.Type.HASHED &&
1200 nextObjective.type() != NextObjective.Type.BROADCAST) {
Charles Chan188ebf52015-12-23 00:15:11 -08001201 log.warn("AddBuckets not applied to nextType:{} in dev:{} for next:{}",
Yi Tseng78f51f42017-02-02 13:54:58 -08001202 nextObjective.type(), deviceId, nextObjective.id());
Yi Tsengef19de12017-04-24 11:33:05 -07001203 fail(nextObjective, ObjectiveError.UNSUPPORTED);
Charles Chan188ebf52015-12-23 00:15:11 -08001204 return;
1205 }
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001206 // first check to see if bucket being added is not a duplicate of an
Yi Tsengef19de12017-04-24 11:33:05 -07001207 // existing bucket. If it is for an existing output port, then its a
1208 // duplicate.
Yi Tseng78f51f42017-02-02 13:54:58 -08001209 Set<TrafficTreatment> duplicateBuckets = Sets.newHashSet();
Yi Tsengef19de12017-04-24 11:33:05 -07001210 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
1211 Set<PortNumber> existingPorts = getExistingOutputPorts(allActiveKeys,
1212 groupService,
1213 deviceId);
Yi Tseng47f82dc2017-03-05 22:48:39 -08001214 Set<TrafficTreatment> nonDuplicateBuckets = Sets.newHashSet();
1215 NextObjective objectiveToAdd;
Yi Tseng78f51f42017-02-02 13:54:58 -08001216 nextObjective.next().forEach(trafficTreatment -> {
1217 PortNumber portNumber = readOutPortFromTreatment(trafficTreatment);
Yi Tseng78f51f42017-02-02 13:54:58 -08001218 if (portNumber == null) {
1219 return;
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001220 }
Yi Tseng78f51f42017-02-02 13:54:58 -08001221 if (existingPorts.contains(portNumber)) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001222 // its possible that portnumbers are same but labels are different
1223 int label = readLabelFromTreatment(trafficTreatment);
1224 if (label == -1) {
1225 duplicateBuckets.add(trafficTreatment);
1226 } else {
Saurav Dasceccf242017-08-03 18:30:35 -07001227 List<Integer> existing = existingPortAndLabel(allActiveKeys,
1228 groupService, deviceId,
1229 portNumber, label);
1230 if (!existing.isEmpty()) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001231 duplicateBuckets.add(trafficTreatment);
1232 } else {
1233 nonDuplicateBuckets.add(trafficTreatment);
1234 }
1235 }
Yi Tseng47f82dc2017-03-05 22:48:39 -08001236 } else {
1237 nonDuplicateBuckets.add(trafficTreatment);
Yi Tseng78f51f42017-02-02 13:54:58 -08001238 }
1239 });
Saurav Dasb28d5dd2017-03-24 19:03:58 -07001240 if (duplicateBuckets.isEmpty()) {
1241 // use the original objective
1242 objectiveToAdd = nextObjective;
1243 } else if (!nonDuplicateBuckets.isEmpty()) {
1244 // only use the non-duplicate buckets if there are any
1245 log.debug("Some buckets {} already exist in next id {}, duplicate "
1246 + "buckets will be ignored.", duplicateBuckets, nextObjective.id());
1247 // new next objective with non duplicate treatments
Yi Tseng47f82dc2017-03-05 22:48:39 -08001248 NextObjective.Builder builder = DefaultNextObjective.builder()
1249 .withType(nextObjective.type())
1250 .withId(nextObjective.id())
1251 .withMeta(nextObjective.meta())
1252 .fromApp(nextObjective.appId());
1253 nonDuplicateBuckets.forEach(builder::addTreatment);
Yi Tseng47f82dc2017-03-05 22:48:39 -08001254 ObjectiveContext context = nextObjective.context().orElse(null);
1255 objectiveToAdd = builder.addToExisting(context);
1256 } else {
Saurav Dasb28d5dd2017-03-24 19:03:58 -07001257 // buckets to add are already there - nothing to do
Saurav Das1547b3f2017-05-05 17:01:08 -07001258 log.debug("buckets already exist {} in next: {} ..ignoring bucket add",
1259 duplicateBuckets, nextObjective.id());
1260 pass(nextObjective);
Saurav Dasb28d5dd2017-03-24 19:03:58 -07001261 return;
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001262 }
Saurav Das1a129a02016-11-18 15:21:57 -08001263 if (nextObjective.type() == NextObjective.Type.HASHED) {
Yi Tseng47f82dc2017-03-05 22:48:39 -08001264 addBucketToHashGroup(objectiveToAdd, allActiveKeys);
Saurav Das1a129a02016-11-18 15:21:57 -08001265 } else if (nextObjective.type() == NextObjective.Type.BROADCAST) {
Yi Tseng47f82dc2017-03-05 22:48:39 -08001266 addBucketToBroadcastGroup(objectiveToAdd, allActiveKeys);
Saurav Das1a129a02016-11-18 15:21:57 -08001267 }
1268 }
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001269
Saurav Das1a129a02016-11-18 15:21:57 -08001270 private void addBucketToHashGroup(NextObjective nextObjective,
Yi Tseng78f51f42017-02-02 13:54:58 -08001271 List<Deque<GroupKey>> allActiveKeys) {
Charles Chan188ebf52015-12-23 00:15:11 -08001272 // storage for all group keys in the chain of groups created
1273 List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
1274 List<GroupInfo> unsentGroups = new ArrayList<>();
Yi Tsengef19de12017-04-24 11:33:05 -07001275 List<GroupBucket> newBuckets;
Charles Chan188ebf52015-12-23 00:15:11 -08001276 createHashBucketChains(nextObjective, allGroupKeys, unsentGroups);
Yi Tseng78f51f42017-02-02 13:54:58 -08001277 // now we can create the buckets to add to the outermost L3 ECMP group
1278 newBuckets = generateNextGroupBuckets(unsentGroups, SELECT);
Saurav Das1a129a02016-11-18 15:21:57 -08001279 // retrieve the original L3 ECMP group
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001280 Group l3ecmpGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
1281 groupService, nextObjective.id());
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001282 if (l3ecmpGroup == null) {
Yi Tsengef19de12017-04-24 11:33:05 -07001283 fail(nextObjective, ObjectiveError.GROUPMISSING);
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001284 return;
1285 }
Saurav Das1a129a02016-11-18 15:21:57 -08001286 GroupKey l3ecmpGroupKey = l3ecmpGroup.appCookie();
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001287 int l3ecmpGroupId = l3ecmpGroup.id().id();
Charles Chan188ebf52015-12-23 00:15:11 -08001288 // Although GroupDescriptions are not necessary for adding buckets to
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001289 // existing groups, we still use one in the GroupChainElem. When the latter is
Charles Chan188ebf52015-12-23 00:15:11 -08001290 // processed, the info will be extracted for the bucketAdd call to groupService
1291 GroupDescription l3ecmpGroupDesc =
Yi Tsengef19de12017-04-24 11:33:05 -07001292 new DefaultGroupDescription(deviceId,
1293 SELECT,
1294 new GroupBuckets(newBuckets),
1295 l3ecmpGroupKey,
1296 l3ecmpGroupId,
1297 nextObjective.appId());
Yi Tseng78f51f42017-02-02 13:54:58 -08001298 GroupChainElem l3ecmpGce = new GroupChainElem(l3ecmpGroupDesc,
1299 unsentGroups.size(),
Yi Tsengef19de12017-04-24 11:33:05 -07001300 true,
1301 deviceId);
Charles Chan188ebf52015-12-23 00:15:11 -08001302
Saurav Dasc88d4662017-05-15 15:34:25 -07001303 // update new bucket-chains
1304 List<Deque<GroupKey>> addedKeys = new ArrayList<>();
1305 for (Deque<GroupKey> newBucketChain : allGroupKeys) {
1306 newBucketChain.addFirst(l3ecmpGroupKey);
1307 addedKeys.add(newBucketChain);
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001308 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001309 updatePendingNextObjective(l3ecmpGroupKey,
1310 new OfdpaNextGroup(addedKeys, nextObjective));
Yi Tsengef19de12017-04-24 11:33:05 -07001311 log.debug("Adding to L3ECMP: device:{} gid:{} group key:{} nextId:{}",
Charles Chan188ebf52015-12-23 00:15:11 -08001312 deviceId, Integer.toHexString(l3ecmpGroupId),
1313 l3ecmpGroupKey, nextObjective.id());
Yi Tseng78f51f42017-02-02 13:54:58 -08001314 unsentGroups.forEach(groupInfo -> {
1315 // send the innermost group
1316 log.debug("Sending innermost group {} in group chain on device {} ",
Saurav Dasc88d4662017-05-15 15:34:25 -07001317 Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
1318 deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001319 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3ecmpGce);
1320 groupService.addGroup(groupInfo.innerMostGroupDesc());
Yi Tseng78f51f42017-02-02 13:54:58 -08001321 });
Saurav Das1a129a02016-11-18 15:21:57 -08001322 }
Charles Chan188ebf52015-12-23 00:15:11 -08001323
Saurav Das1a129a02016-11-18 15:21:57 -08001324 private void addBucketToBroadcastGroup(NextObjective nextObj,
Yi Tsengef19de12017-04-24 11:33:05 -07001325 List<Deque<GroupKey>> allActiveKeys) {
1326 VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
Saurav Das1a129a02016-11-18 15:21:57 -08001327 if (assignedVlan == null) {
1328 log.warn("VLAN ID required by broadcast next obj is missing. "
1329 + "Aborting add bucket to broadcast group for next:{} in dev:{}",
1330 nextObj.id(), deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001331 fail(nextObj, ObjectiveError.BADPARAMS);
Saurav Das1a129a02016-11-18 15:21:57 -08001332 return;
1333 }
Saurav Das1a129a02016-11-18 15:21:57 -08001334 List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
Yi Tsengef19de12017-04-24 11:33:05 -07001335 IpPrefix ipDst = readIpDstFromSelector(nextObj.meta());
Saurav Das1a129a02016-11-18 15:21:57 -08001336 if (ipDst != null) {
1337 if (ipDst.isMulticast()) {
Yi Tsengef19de12017-04-24 11:33:05 -07001338 addBucketToL3MulticastGroup(nextObj, allActiveKeys, groupInfos, assignedVlan);
Saurav Das1a129a02016-11-18 15:21:57 -08001339 } else {
1340 log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj);
Yi Tsengef19de12017-04-24 11:33:05 -07001341 fail(nextObj, ObjectiveError.BADPARAMS);
Saurav Das1a129a02016-11-18 15:21:57 -08001342 }
1343 } else {
Yi Tsengef19de12017-04-24 11:33:05 -07001344 addBucketToL2FloodGroup(nextObj, allActiveKeys, groupInfos, assignedVlan);
Saurav Das1a129a02016-11-18 15:21:57 -08001345 }
1346 }
1347
1348 private void addBucketToL2FloodGroup(NextObjective nextObj,
1349 List<Deque<GroupKey>> allActiveKeys,
1350 List<GroupInfo> groupInfos,
Yi Tseng78f51f42017-02-02 13:54:58 -08001351 VlanId assignedVlan) {
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001352 Group l2FloodGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
1353 groupService, nextObj.id());
Yi Tseng78f51f42017-02-02 13:54:58 -08001354
1355 if (l2FloodGroup == null) {
1356 log.warn("Can't find L2 flood group while adding bucket to it. NextObj = {}",
1357 nextObj);
Yi Tsengef19de12017-04-24 11:33:05 -07001358 fail(nextObj, ObjectiveError.GROUPMISSING);
Saurav Das1a129a02016-11-18 15:21:57 -08001359 return;
1360 }
Saurav Das1a129a02016-11-18 15:21:57 -08001361
Yi Tseng78f51f42017-02-02 13:54:58 -08001362 GroupKey l2floodGroupKey = l2FloodGroup.appCookie();
1363 int l2floodGroupId = l2FloodGroup.id().id();
1364 List<GroupBucket> newBuckets = generateNextGroupBuckets(groupInfos, ALL);
Yi Tseng78f51f42017-02-02 13:54:58 -08001365 GroupDescription l2FloodGroupDescription =
Yi Tsengef19de12017-04-24 11:33:05 -07001366 new DefaultGroupDescription(deviceId,
1367 ALL,
1368 new GroupBuckets(newBuckets),
1369 l2floodGroupKey,
1370 l2floodGroupId,
1371 nextObj.appId());
Yi Tseng78f51f42017-02-02 13:54:58 -08001372 GroupChainElem l2FloodGroupChainElement =
1373 new GroupChainElem(l2FloodGroupDescription,
1374 groupInfos.size(),
Yi Tsengef19de12017-04-24 11:33:05 -07001375 true,
1376 deviceId);
Yi Tseng78f51f42017-02-02 13:54:58 -08001377
Yi Tseng78f51f42017-02-02 13:54:58 -08001378
1379 //ensure assignedVlan applies to the chosen group
1380 VlanId floodGroupVlan = extractVlanIdFromGroupId(l2floodGroupId);
Yi Tseng78f51f42017-02-02 13:54:58 -08001381 if (!floodGroupVlan.equals(assignedVlan)) {
1382 log.warn("VLAN ID {} does not match Flood group {} to which bucket is "
1383 + "being added, for next:{} in dev:{}. Abort.", assignedVlan,
1384 Integer.toHexString(l2floodGroupId), nextObj.id(), deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001385 fail(nextObj, ObjectiveError.BADPARAMS);
Yi Tseng78f51f42017-02-02 13:54:58 -08001386 return;
1387 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001388 List<Deque<GroupKey>> addedKeys = new ArrayList<>();
Yi Tseng78f51f42017-02-02 13:54:58 -08001389 groupInfos.forEach(groupInfo -> {
1390 // update original NextGroup with new bucket-chain
Yi Tseng78f51f42017-02-02 13:54:58 -08001391 Deque<GroupKey> newBucketChain = new ArrayDeque<>();
Yi Tsengef19de12017-04-24 11:33:05 -07001392 newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie());
Yi Tseng78f51f42017-02-02 13:54:58 -08001393 newBucketChain.addFirst(l2floodGroupKey);
Saurav Dasc88d4662017-05-15 15:34:25 -07001394 addedKeys.add(newBucketChain);
Yi Tsengef19de12017-04-24 11:33:05 -07001395 log.debug("Adding to L2FLOOD: device:{} gid:{} group key:{} nextId:{}",
Yi Tseng78f51f42017-02-02 13:54:58 -08001396 deviceId, Integer.toHexString(l2floodGroupId),
1397 l2floodGroupKey, nextObj.id());
1398 // send the innermost group
1399 log.debug("Sending innermost group {} in group chain on device {} ",
Yi Tsengef19de12017-04-24 11:33:05 -07001400 Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
Yi Tseng78f51f42017-02-02 13:54:58 -08001401 deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001402 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l2FloodGroupChainElement);
Yi Tseng78f51f42017-02-02 13:54:58 -08001403
Yi Tsengef19de12017-04-24 11:33:05 -07001404 DeviceId innerMostGroupDevice = groupInfo.innerMostGroupDesc().deviceId();
1405 GroupKey innerMostGroupKey = groupInfo.innerMostGroupDesc().appCookie();
Yi Tseng78f51f42017-02-02 13:54:58 -08001406 Group existsL2IGroup = groupService.getGroup(innerMostGroupDevice, innerMostGroupKey);
1407
1408 if (existsL2IGroup != null) {
1409 // group already exist
1410 processPendingAddGroupsOrNextObjs(innerMostGroupKey, true);
1411 } else {
Yi Tsengef19de12017-04-24 11:33:05 -07001412 groupService.addGroup(groupInfo.innerMostGroupDesc());
Yi Tseng78f51f42017-02-02 13:54:58 -08001413 }
Yi Tseng78f51f42017-02-02 13:54:58 -08001414 });
Saurav Dasc88d4662017-05-15 15:34:25 -07001415
1416 updatePendingNextObjective(l2floodGroupKey,
1417 new OfdpaNextGroup(addedKeys, nextObj));
Yi Tseng78f51f42017-02-02 13:54:58 -08001418 }
1419
Saurav Das1a129a02016-11-18 15:21:57 -08001420 private void addBucketToL3MulticastGroup(NextObjective nextObj,
1421 List<Deque<GroupKey>> allActiveKeys,
1422 List<GroupInfo> groupInfos,
Yi Tseng78f51f42017-02-02 13:54:58 -08001423 VlanId assignedVlan) {
Pier Luigi7b7a29d2018-01-19 10:24:53 +01001424 // Create the buckets to add to the outermost L3 Multicast group
1425 List<GroupBucket> newBuckets = createL3MulticastBucket(groupInfos);
Saurav Das1a129a02016-11-18 15:21:57 -08001426
1427 // get the group being edited
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001428 Group l3mcastGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
1429 groupService, nextObj.id());
Saurav Das1a129a02016-11-18 15:21:57 -08001430 if (l3mcastGroup == null) {
Yi Tsengef19de12017-04-24 11:33:05 -07001431 fail(nextObj, ObjectiveError.GROUPMISSING);
Saurav Das1a129a02016-11-18 15:21:57 -08001432 return;
1433 }
1434 GroupKey l3mcastGroupKey = l3mcastGroup.appCookie();
1435 int l3mcastGroupId = l3mcastGroup.id().id();
1436
1437 //ensure assignedVlan applies to the chosen group
Yi Tseng78f51f42017-02-02 13:54:58 -08001438 VlanId expectedVlan = extractVlanIdFromGroupId(l3mcastGroupId);
Saurav Das1a129a02016-11-18 15:21:57 -08001439 if (!expectedVlan.equals(assignedVlan)) {
1440 log.warn("VLAN ID {} does not match L3 Mcast group {} to which bucket is "
1441 + "being added, for next:{} in dev:{}. Abort.", assignedVlan,
1442 Integer.toHexString(l3mcastGroupId), nextObj.id(), deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001443 fail(nextObj, ObjectiveError.BADPARAMS);
Saurav Das1a129a02016-11-18 15:21:57 -08001444 }
1445 GroupDescription l3mcastGroupDescription =
Yi Tsengef19de12017-04-24 11:33:05 -07001446 new DefaultGroupDescription(deviceId,
1447 ALL,
1448 new GroupBuckets(newBuckets),
1449 l3mcastGroupKey,
1450 l3mcastGroupId,
1451 nextObj.appId());
Saurav Das1a129a02016-11-18 15:21:57 -08001452 GroupChainElem l3mcastGce = new GroupChainElem(l3mcastGroupDescription,
Yi Tsengef19de12017-04-24 11:33:05 -07001453 groupInfos.size(),
1454 true,
1455 deviceId);
Saurav Dasc88d4662017-05-15 15:34:25 -07001456
1457 List<Deque<GroupKey>> addedKeys = new ArrayList<>();
Yi Tseng78f51f42017-02-02 13:54:58 -08001458 groupInfos.forEach(groupInfo -> {
1459 // update original NextGroup with new bucket-chain
1460 Deque<GroupKey> newBucketChain = new ArrayDeque<>();
Yi Tsengef19de12017-04-24 11:33:05 -07001461 newBucketChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
Yi Tseng78f51f42017-02-02 13:54:58 -08001462 // Add L3 interface group to the chain if there is one.
Yi Tsengef19de12017-04-24 11:33:05 -07001463 if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
1464 newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie());
Yi Tseng78f51f42017-02-02 13:54:58 -08001465 }
1466 newBucketChain.addFirst(l3mcastGroupKey);
Saurav Dasc88d4662017-05-15 15:34:25 -07001467 addedKeys.add(newBucketChain);
Yi Tseng78f51f42017-02-02 13:54:58 -08001468
Yi Tsengef19de12017-04-24 11:33:05 -07001469 updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3mcastGce);
Yi Tseng78f51f42017-02-02 13:54:58 -08001470 // Point next group to inner-most group, if any
Yi Tsengef19de12017-04-24 11:33:05 -07001471 if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
1472 GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(),
1473 1,
1474 false,
1475 deviceId);
1476 updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce);
Yi Tseng78f51f42017-02-02 13:54:58 -08001477 }
Yi Tsengef19de12017-04-24 11:33:05 -07001478 log.debug("Adding to L3MCAST: device:{} gid:{} group key:{} nextId:{}",
Yi Tseng78f51f42017-02-02 13:54:58 -08001479 deviceId, Integer.toHexString(l3mcastGroupId),
1480 l3mcastGroupKey, nextObj.id());
1481 // send the innermost group
1482 log.debug("Sending innermost group {} in group chain on device {} ",
Yi Tsengef19de12017-04-24 11:33:05 -07001483 Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
Yi Tseng78f51f42017-02-02 13:54:58 -08001484 deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001485 groupService.addGroup(groupInfo.innerMostGroupDesc());
Yi Tseng78f51f42017-02-02 13:54:58 -08001486
1487 });
1488
Saurav Das1a129a02016-11-18 15:21:57 -08001489 updatePendingNextObjective(l3mcastGroupKey,
Saurav Dasc88d4662017-05-15 15:34:25 -07001490 new OfdpaNextGroup(addedKeys, nextObj));
Charles Chan188ebf52015-12-23 00:15:11 -08001491 }
1492
1493 /**
Saurav Dasceccf242017-08-03 18:30:35 -07001494 * Removes buckets in the top level group of a possible group-chain. Does
Saurav Das1a129a02016-11-18 15:21:57 -08001495 * not remove the groups in the group-chain pointed to by this bucket, as they
Charles Chan188ebf52015-12-23 00:15:11 -08001496 * may be in use (referenced by other groups) elsewhere.
1497 *
Saurav Dasceccf242017-08-03 18:30:35 -07001498 * @param nextObjective a next objective that contains information for the
1499 * buckets to be removed from the group
1500 * @param next the representation of the existing group-chains for this next
1501 * objective, from which the top-level buckets to remove are determined
Charles Chan188ebf52015-12-23 00:15:11 -08001502 */
1503 protected void removeBucketFromGroup(NextObjective nextObjective, NextGroup next) {
Saurav Das1a129a02016-11-18 15:21:57 -08001504 if (nextObjective.type() != NextObjective.Type.HASHED &&
1505 nextObjective.type() != NextObjective.Type.BROADCAST) {
Charles Chan188ebf52015-12-23 00:15:11 -08001506 log.warn("RemoveBuckets not applied to nextType:{} in dev:{} for next:{}",
1507 nextObjective.type(), deviceId, nextObjective.id());
Yi Tsengef19de12017-04-24 11:33:05 -07001508 fail(nextObjective, ObjectiveError.UNSUPPORTED);
Charles Chan188ebf52015-12-23 00:15:11 -08001509 return;
1510 }
Yi Tsengef19de12017-04-24 11:33:05 -07001511 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
Saurav Dasceccf242017-08-03 18:30:35 -07001512 List<Integer> indicesToRemove = Lists.newArrayList();
1513 for (TrafficTreatment treatment : nextObjective.next()) {
1514 // find the top-level bucket in the group-chain by matching the
1515 // outport and label from different groups in the chain
1516 PortNumber portToRemove = readOutPortFromTreatment(treatment);
1517 int labelToRemove = readLabelFromTreatment(treatment);
1518 if (portToRemove == null) {
1519 log.warn("treatment {} of next objective {} has no outport.. "
1520 + "cannot remove bucket from group in dev: {}", treatment,
1521 nextObjective.id(), deviceId);
Charles Chan188ebf52015-12-23 00:15:11 -08001522 continue;
1523 }
Saurav Dasceccf242017-08-03 18:30:35 -07001524 List<Integer> existing = existingPortAndLabel(allActiveKeys,
1525 groupService, deviceId,
1526 portToRemove, labelToRemove);
1527 indicesToRemove.addAll(existing);
1528
Charles Chan188ebf52015-12-23 00:15:11 -08001529 }
Saurav Dasceccf242017-08-03 18:30:35 -07001530
1531 List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList();
1532 indicesToRemove.forEach(index -> chainsToRemove
1533 .add(allActiveKeys.get(index)));
Yi Tseng78f51f42017-02-02 13:54:58 -08001534 if (chainsToRemove.isEmpty()) {
Charles Chan188ebf52015-12-23 00:15:11 -08001535 log.warn("Could not find appropriate group-chain for removing bucket"
1536 + " for next id {} in dev:{}", nextObjective.id(), deviceId);
Yi Tsengef19de12017-04-24 11:33:05 -07001537 fail(nextObjective, ObjectiveError.BADPARAMS);
Saurav Das1a129a02016-11-18 15:21:57 -08001538 return;
Charles Chan188ebf52015-12-23 00:15:11 -08001539 }
Saurav Dasceccf242017-08-03 18:30:35 -07001540 removeBucket(chainsToRemove, nextObjective);
1541 }
1542
1543 /**
1544 * Removes top-level buckets from a group that represents the given next objective.
1545 *
1546 * @param chainsToRemove a list of group bucket chains to remove
1547 * @param nextObjective the next objective that contains information for the
1548 * buckets to be removed from the group
1549 */
1550 protected void removeBucket(List<Deque<GroupKey>> chainsToRemove,
1551 NextObjective nextObjective) {
Yi Tseng78f51f42017-02-02 13:54:58 -08001552 List<GroupBucket> bucketsToRemove = Lists.newArrayList();
1553 //first group key is the one we want to modify
1554 GroupKey modGroupKey = chainsToRemove.get(0).peekFirst();
Saurav Das1a129a02016-11-18 15:21:57 -08001555 Group modGroup = groupService.getGroup(deviceId, modGroupKey);
Ray Milkey8299dc92018-05-08 11:35:45 -07001556 if (modGroup == null) {
1557 log.warn("removeBucket(): Attempt to modify non-existent group {} for device {}", modGroupKey, deviceId);
1558 return;
1559 }
Yi Tseng78f51f42017-02-02 13:54:58 -08001560 for (Deque<GroupKey> foundChain : chainsToRemove) {
1561 //second group key is the one we wish to remove the reference to
1562 if (foundChain.size() < 2) {
Saurav Dasceccf242017-08-03 18:30:35 -07001563 // additional check to make sure second group key exists in
Yi Tseng78f51f42017-02-02 13:54:58 -08001564 // the chain.
1565 log.warn("Can't find second group key from chain {}",
1566 foundChain);
1567 continue;
Saurav Das1a129a02016-11-18 15:21:57 -08001568 }
Saurav Dasceccf242017-08-03 18:30:35 -07001569 GroupKey pointedGroupKey = foundChain.stream()
1570 .collect(Collectors.toList()).get(1);
Yi Tseng78f51f42017-02-02 13:54:58 -08001571 Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey);
Yi Tseng78f51f42017-02-02 13:54:58 -08001572 if (pointedGroup == null) {
1573 continue;
1574 }
1575
1576 GroupBucket bucket;
1577 if (nextObjective.type() == NextObjective.Type.HASHED) {
1578 bucket = DefaultGroupBucket.createSelectGroupBucket(
1579 DefaultTrafficTreatment.builder()
1580 .group(pointedGroup.id())
1581 .build());
1582 } else {
1583 bucket = DefaultGroupBucket.createAllGroupBucket(
1584 DefaultTrafficTreatment.builder()
1585 .group(pointedGroup.id())
1586 .build());
1587 }
Yi Tseng78f51f42017-02-02 13:54:58 -08001588 bucketsToRemove.add(bucket);
Saurav Das1a129a02016-11-18 15:21:57 -08001589 }
Yi Tseng78f51f42017-02-02 13:54:58 -08001590
1591 GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove);
1592 List<String> pointedGroupIds; // for debug log
1593 pointedGroupIds = bucketsToRemove.stream()
1594 .map(GroupBucket::treatment)
1595 .map(TrafficTreatment::allInstructions)
1596 .flatMap(List::stream)
1597 .filter(inst -> inst instanceof Instructions.GroupInstruction)
1598 .map(inst -> (Instructions.GroupInstruction) inst)
1599 .map(Instructions.GroupInstruction::groupId)
1600 .map(GroupId::id)
1601 .map(Integer::toHexString)
1602 .map(id -> HEX_PREFIX + id)
1603 .collect(Collectors.toList());
1604
Yi Tseng78f51f42017-02-02 13:54:58 -08001605 log.debug("Removing buckets from group id 0x{} pointing to group id(s) {} "
Saurav Das1a129a02016-11-18 15:21:57 -08001606 + "for next id {} in device {}", Integer.toHexString(modGroup.id().id()),
Yi Tseng78f51f42017-02-02 13:54:58 -08001607 pointedGroupIds, nextObjective.id(), deviceId);
1608 addPendingUpdateNextObjective(modGroupKey, nextObjective);
Saurav Das1a129a02016-11-18 15:21:57 -08001609 groupService.removeBucketsFromGroup(deviceId, modGroupKey,
1610 removeBuckets, modGroupKey,
1611 nextObjective.appId());
Saurav Dasceccf242017-08-03 18:30:35 -07001612 // update store - synchronize access as there may be multiple threads
1613 // trying to remove buckets from the same group, each with its own
1614 // potentially stale copy of allActiveKeys
Saurav Dasc88d4662017-05-15 15:34:25 -07001615 synchronized (flowObjectiveStore) {
Saurav Dasceccf242017-08-03 18:30:35 -07001616 // get a fresh copy of what the store holds
1617 NextGroup next = flowObjectiveStore.getNextGroup(nextObjective.id());
1618 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
Pier Luigiaeb11a72018-01-15 09:48:49 +01001619 allActiveKeys = Lists.newArrayList(allActiveKeys);
Saurav Dasc88d4662017-05-15 15:34:25 -07001620 // Note that since we got a new object, and ArrayDeque does not implement
Saurav Dasceccf242017-08-03 18:30:35 -07001621 // Object.equals(), we have to check the deque elems one by one
1622 allActiveKeys
1623 .removeIf(active ->
1624 chainsToRemove.stream().anyMatch(remove ->
1625 Arrays.equals(remove.toArray(new GroupKey[0]),
1626 active.toArray(new GroupKey[0]))));
Saurav Dasc88d4662017-05-15 15:34:25 -07001627 // If no buckets in the group, then retain an entry for the
1628 // top level group which still exists.
1629 if (allActiveKeys.isEmpty()) {
1630 ArrayDeque<GroupKey> top = new ArrayDeque<>();
1631 top.add(modGroupKey);
1632 allActiveKeys.add(top);
1633 }
1634 flowObjectiveStore.putNextGroup(nextObjective.id(),
Saurav Dasceccf242017-08-03 18:30:35 -07001635 new OfdpaNextGroup(allActiveKeys,
1636 nextObjective));
Saurav Das1a129a02016-11-18 15:21:57 -08001637 }
Charles Chan188ebf52015-12-23 00:15:11 -08001638 }
1639
1640 /**
Saurav Das961beb22017-03-29 19:09:17 -07001641 * Removes all groups in multiple possible group-chains that represent the next-obj.
Charles Chan188ebf52015-12-23 00:15:11 -08001642 *
1643 * @param nextObjective the next objective to remove
1644 * @param next the NextGroup that represents the existing group-chain for
1645 * this next objective
1646 */
1647 protected void removeGroup(NextObjective nextObjective, NextGroup next) {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -07001648
Yi Tsengef19de12017-04-24 11:33:05 -07001649 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
Charles Chanfc5c7802016-05-17 13:13:55 -07001650
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001651 List<GroupKey> groupKeys = allActiveKeys.stream()
Charles Chanfc5c7802016-05-17 13:13:55 -07001652 .map(Deque::getFirst).collect(Collectors.toList());
Yi Tsengef19de12017-04-24 11:33:05 -07001653 addPendingRemoveNextObjective(nextObjective, groupKeys);
Charles Chanfc5c7802016-05-17 13:13:55 -07001654
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -07001655 allActiveKeys
1656 .forEach(groupChain -> groupChain.forEach(groupKey -> groupService
1657 .removeGroup(deviceId, groupKey, nextObjective.appId())));
Charles Chan188ebf52015-12-23 00:15:11 -08001658 flowObjectiveStore.removeNextGroup(nextObjective.id());
1659 }
1660
Saurav Dasceccf242017-08-03 18:30:35 -07001661 /**
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +00001662 * modifies group with next objective.
1663 *
1664 * @param nextObjective the NextObjective
1665 * @param nextGroup the NextGroup
1666 */
1667 protected void modifyBucketFromGroup(NextObjective nextObjective, NextGroup nextGroup) {
1668 switch (nextObjective.type()) {
1669 case SIMPLE:
1670 Collection<TrafficTreatment> treatments = nextObjective.next();
1671 if (treatments.size() != 1) {
1672 log.error("Next Objectives of type Simple should only have a "
1673 + "single Traffic Treatment. Next Objective Id:{}",
1674 nextObjective.id());
1675 fail(nextObjective, ObjectiveError.BADPARAMS);
1676 return;
1677 }
1678 modifySimpleNextObjective(nextObjective, nextGroup);
1679 break;
1680 default:
1681 fail(nextObjective, ObjectiveError.UNKNOWN);
1682 log.warn("Unknown next objective type {}", nextObjective.type());
1683 }
1684 }
1685
1686 /**
1687 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
1688 * a chain of groups. The simple Next Objective passed in by the application
1689 * is broken up into a group chain. The following chains can be modified
1690 * depending on the parameters in the Next Objective.
1691 * 1. L2 Interface group (no chaining)
1692 * 2. L3 Unicast group -> L2 Interface group
1693 *
1694 * @param nextObj the nextObjective of type SIMPLE
1695 */
1696 private void modifySimpleNextObjective(NextObjective nextObj, NextGroup nextGroup) {
1697 TrafficTreatment treatment = nextObj.next().iterator().next();
1698 // determine if plain L2 or L3->L2 chain
1699 boolean plainL2 = true;
1700 for (Instruction ins : treatment.allInstructions()) {
1701 if (ins.type() == Instruction.Type.L2MODIFICATION) {
1702 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
1703 if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST ||
1704 l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC ||
1705 l2ins.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
1706 plainL2 = false;
1707 }
1708 }
1709 }
1710 if (plainL2) {
1711 modifyBucketInL2Group(nextObj, nextGroup);
1712 } else {
1713 modifyBucketInL3Group(nextObj, nextGroup);
1714 }
1715 return;
1716 }
1717
1718
1719 /**
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001720 * Modify buckets in the L2 interface group.
1721 *
1722 * @param nextObjective a next objective that contains information for the
1723 * buckets to be modified in the group
1724 * @param next the representation of the existing group-chains for this next
1725 * objective, from which the innermost group buckets to remove are determined
1726 */
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +00001727
1728 protected void modifyBucketInL2Group(NextObjective nextObjective, NextGroup next) {
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001729
1730 VlanId assignedVlan = readVlanFromSelector(nextObjective.meta());
1731 if (assignedVlan == null) {
1732 log.warn("VLAN ID required by simple next obj is missing. Abort.");
1733 fail(nextObjective, ObjectiveError.BADPARAMS);
1734 return;
1735 }
1736
1737 List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObjective, assignedVlan);
1738
1739 // There is only one L2 interface group in this case
1740 GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc();
1741
1742 // Replace group bucket for L2 interface group
1743 groupService.setBucketsForGroup(deviceId,
1744 l2InterfaceGroupDesc.appCookie(),
1745 l2InterfaceGroupDesc.buckets(),
1746 l2InterfaceGroupDesc.appCookie(),
1747 l2InterfaceGroupDesc.appId());
1748
1749 // update store - synchronize access as there may be multiple threads
1750 // trying to remove buckets from the same group, each with its own
1751 // potentially stale copy of allActiveKeys
1752 synchronized (flowObjectiveStore) {
Shibu Vijayakumar325bb9c2018-03-01 15:45:59 -08001753 // NOTE: The groupKey is computed by deviceId, VLAN and portNum. It remains the same when we modify L2IG.
1754 // Therefore we use the same groupKey of the existing group.
1755 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001756 flowObjectiveStore.putNextGroup(nextObjective.id(),
Shibu Vijayakumar325bb9c2018-03-01 15:45:59 -08001757 new OfdpaNextGroup(allActiveKeys,
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001758 nextObjective));
1759 }
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +00001760
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001761 }
1762
Ruchi Sahotaf77dc0f2019-01-28 01:08:18 +00001763 protected void modifyBucketInL3Group(NextObjective nextObjective, NextGroup next) {
1764
1765 //get l3 group
1766 GroupInfo groupInfo = prepareL3UnicastGroup(nextObjective, next);
1767 if (groupInfo == null) {
1768 log.warn("Null groupInfo retrieved for next obj. Abort.");
1769 fail(nextObjective, ObjectiveError.BADPARAMS);
1770 return;
1771 }
1772
1773 GroupDescription l3UnicastGroupDesc = groupInfo.nextGroupDesc();
1774
1775 // Replace group bucket for L3 UC interface group
1776 groupService.setBucketsForGroup(deviceId, l3UnicastGroupDesc.appCookie(),
1777 l3UnicastGroupDesc.buckets(), l3UnicastGroupDesc.appCookie(),
1778 l3UnicastGroupDesc.appId());
1779
1780 // create object for local and distributed storage
1781 Deque<GroupKey> gkeyChain = new ArrayDeque<>();
1782 gkeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
1783 gkeyChain.addFirst(groupInfo.nextGroupDesc().appCookie());
1784 List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
1785 allGroupKeys.add(gkeyChain);
1786 OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObjective);
1787 // store l3groupkey with the ofdpaNextGroup for the nextObjective that depends on it
1788 updatePendingNextObjective(groupInfo.nextGroupDesc().appCookie(), ofdpaGrp);
1789
1790 // update store - synchronize access as there may be multiple threads
1791 // trying to update bucket from the same group, each with its own
1792 // potentially stale copy of allActiveKeys
1793 synchronized (flowObjectiveStore) {
1794
1795 List<Deque<GroupKey>> modifiedGroupKeys = Lists.newArrayList();
1796 ArrayDeque<GroupKey> top = new ArrayDeque<>();
1797 top.add(l3UnicastGroupDesc.appCookie());
1798 top.add(groupInfo.innerMostGroupDesc().appCookie()); //l2 group key
1799 modifiedGroupKeys.add(top);
1800
1801 flowObjectiveStore.putNextGroup(nextObjective.id(),
1802 new OfdpaNextGroup(modifiedGroupKeys,
1803 nextObjective));
1804 }
1805 }
1806
1807
Jonghwan Hyun25199f22018-02-12 16:43:45 +09001808 /**
Saurav Dasceccf242017-08-03 18:30:35 -07001809 * Checks existing buckets in {@link NextGroup} to verify if they match
1810 * the buckets in the given {@link NextObjective}. Adds or removes buckets
1811 * to ensure that the buckets match up.
1812 *
1813 * @param nextObjective the next objective to verify
1814 * @param next the representation of the existing group which has to be
1815 * modified to match the given next objective
1816 */
1817 protected void verifyGroup(NextObjective nextObjective, NextGroup next) {
Pier Luigi3dfd8352018-01-25 16:16:02 +01001818 if (nextObjective.type() == NextObjective.Type.SIMPLE) {
1819 log.warn("verification not supported for indirect group");
Saurav Dasceccf242017-08-03 18:30:35 -07001820 fail(nextObjective, ObjectiveError.UNSUPPORTED);
1821 return;
1822 }
Charles Chan1a446ca2018-05-08 11:49:05 -07001823 log.trace("Call to verify device:{} nextId:{}", deviceId, nextObjective.id());
Saurav Dasceccf242017-08-03 18:30:35 -07001824 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
1825 List<TrafficTreatment> bucketsToCreate = Lists.newArrayList();
1826 List<Integer> indicesToRemove = Lists.newArrayList();
Pier Luigi4a7cdfa2018-01-29 10:30:59 +01001827
1828 // Iterating over the treatments of the next objective allows
1829 // to detect missing buckets and/or duplicate buckets (to be removed)
Saurav Dasceccf242017-08-03 18:30:35 -07001830 for (TrafficTreatment bkt : nextObjective.next()) {
1831 PortNumber portNumber = readOutPortFromTreatment(bkt);
1832 int label = readLabelFromTreatment(bkt);
1833 if (portNumber == null) {
1834 log.warn("treatment {} of next objective {} has no outport.. "
1835 + "cannot remove bucket from group in dev: {}", bkt,
1836 nextObjective.id(), deviceId);
1837 fail(nextObjective, ObjectiveError.BADPARAMS);
1838 return;
1839 }
1840 List<Integer> existing = existingPortAndLabel(allActiveKeys,
1841 groupService, deviceId,
1842 portNumber, label);
1843 if (existing.isEmpty()) {
1844 // if it doesn't exist, mark this bucket for creation
1845 bucketsToCreate.add(bkt);
1846 }
1847 if (existing.size() > 1) {
1848 // if it exists but there are duplicates, mark the others for removal
1849 existing.remove(0);
1850 indicesToRemove.addAll(existing);
1851 }
1852 }
1853
Pier Luigi4a7cdfa2018-01-29 10:30:59 +01001854 // Detect situation where the next data has more buckets
1855 // (not duplicates) respect to the next objective
Saurav Dasa89b95a2018-02-14 14:14:54 -08001856 if (allActiveKeys.size() > nextObjective.next().size() &&
1857 // ignore specific case of empty group
1858 !(nextObjective.next().size() == 0 && allActiveKeys.size() == 1
1859 && allActiveKeys.get(0).size() == 1)) {
Pier Luigi4a7cdfa2018-01-29 10:30:59 +01001860 log.warn("Mismatch detected between next and flowobjstore for device {}: " +
Saurav Dasa89b95a2018-02-14 14:14:54 -08001861 "nextId:{}, nextObjective-size:{} next-size:{} .. correcting",
1862 deviceId, nextObjective.id(), nextObjective.next().size(),
1863 allActiveKeys.size());
1864 List<Integer> otherIndices =
1865 indicesToRemoveFromNextGroup(allActiveKeys, nextObjective,
1866 groupService, deviceId);
Pier Luigi4a7cdfa2018-01-29 10:30:59 +01001867 // Filter out the indices not present
1868 otherIndices = otherIndices.stream()
1869 .filter(index -> !indicesToRemove.contains(index))
1870 .collect(Collectors.toList());
1871 // Add all to the final list
1872 indicesToRemove.addAll(otherIndices);
1873 }
1874
Charles Chan1a446ca2018-05-08 11:49:05 -07001875 log.trace("Buckets to create {}", bucketsToCreate);
1876 log.trace("Indices to remove {}", indicesToRemove);
Pier Luigi3dfd8352018-01-25 16:16:02 +01001877
Saurav Dasceccf242017-08-03 18:30:35 -07001878 if (!bucketsToCreate.isEmpty()) {
1879 log.info("creating {} buckets as part of nextId: {} verification",
1880 bucketsToCreate.size(), nextObjective.id());
1881 //create a nextObjective only with these buckets
1882 NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder()
1883 .withId(nextObjective.id())
Pier Luigi3dfd8352018-01-25 16:16:02 +01001884 .withType(nextObjective.type())
Saurav Dasceccf242017-08-03 18:30:35 -07001885 .withMeta(nextObjective.meta())
1886 .fromApp(nextObjective.appId());
Pier Luigi3dfd8352018-01-25 16:16:02 +01001887 bucketsToCreate.forEach(nextObjBuilder::addTreatment);
1888 // According to the next type we call the proper add function
1889 if (nextObjective.type() == NextObjective.Type.HASHED) {
1890 addBucketToHashGroup(nextObjBuilder.addToExisting(), allActiveKeys);
1891 } else {
1892 addBucketToBroadcastGroup(nextObjBuilder.addToExisting(), allActiveKeys);
1893 }
Saurav Dasceccf242017-08-03 18:30:35 -07001894 }
1895
1896 if (!indicesToRemove.isEmpty()) {
1897 log.info("removing {} buckets as part of nextId: {} verification",
1898 indicesToRemove.size(), nextObjective.id());
1899 List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList();
1900 indicesToRemove.forEach(index -> chainsToRemove
1901 .add(allActiveKeys.get(index)));
1902 removeBucket(chainsToRemove, nextObjective);
1903 }
1904
pier2107d0c2020-01-27 17:45:03 +01001905 log.trace("Checking mismatch with GroupStore device:{} nextId:{}",
1906 deviceId, nextObjective.id());
Saurav Das9df5b7c2017-08-14 16:44:43 -07001907 if (bucketsToCreate.isEmpty() && indicesToRemove.isEmpty()) {
1908 // flowObjective store record is in-sync with nextObjective passed-in
1909 // Nevertheless groupStore may not be in sync due to bug in the store
1910 // - see CORD-1844. XXX When this bug is fixed, the rest of this verify
1911 // method will not be required.
Pier Luigi3dfd8352018-01-25 16:16:02 +01001912 GroupKey topGroupKey = allActiveKeys.get(0).peekFirst();
1913 Group topGroup = groupService.getGroup(deviceId, topGroupKey);
Ravi Dewangan95d08902019-05-28 22:24:18 +00001914 // topGroup should not be null - adding guard
1915 if (topGroup == null) {
1916 log.warn("topGroup {} not found in GroupStore device:{}, nextId:{}",
1917 topGroupKey, deviceId, nextObjective.id());
pierb29eb232019-12-10 18:09:00 +01001918 fail(nextObjective, ObjectiveError.GROUPMISSING);
Ravi Dewangan95d08902019-05-28 22:24:18 +00001919 return;
1920 }
Pier Luigi3dfd8352018-01-25 16:16:02 +01001921 int actualGroupSize = topGroup.buckets().buckets().size();
Saurav Das9df5b7c2017-08-14 16:44:43 -07001922 int objGroupSize = nextObjective.next().size();
1923 if (actualGroupSize != objGroupSize) {
1924 log.warn("Mismatch detected in device:{}, nextId:{}, nextObjective-size"
1925 + ":{} group-size:{} .. correcting", deviceId, nextObjective.id(),
1926 objGroupSize, actualGroupSize);
1927 }
1928 if (actualGroupSize > objGroupSize) {
Pier Luigi3dfd8352018-01-25 16:16:02 +01001929 // Group in the device has more chains
Saurav Das9df5b7c2017-08-14 16:44:43 -07001930 List<GroupBucket> bucketsToRemove = Lists.newArrayList();
1931 //check every bucket in the actual group
Pier Luigi3dfd8352018-01-25 16:16:02 +01001932 for (GroupBucket bucket : topGroup.buckets().buckets()) {
Saurav Das9df5b7c2017-08-14 16:44:43 -07001933 GroupInstruction g = (GroupInstruction) bucket.treatment()
1934 .allInstructions().iterator().next();
1935 GroupId gidToCheck = g.groupId(); // the group pointed to
1936 boolean matches = false;
1937 for (Deque<GroupKey> validChain : allActiveKeys) {
1938 if (validChain.size() < 2) {
1939 continue;
1940 }
1941 GroupKey pointedGroupKey = validChain.stream()
1942 .collect(Collectors.toList()).get(1);
1943 Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey);
1944 if (pointedGroup != null && gidToCheck.equals(pointedGroup.id())) {
1945 matches = true;
1946 break;
1947 }
1948 }
1949 if (!matches) {
1950 log.warn("Removing bucket pointing to groupId:{}", gidToCheck);
1951 bucketsToRemove.add(bucket);
1952 }
1953 }
1954 // remove buckets for which there was no record in the obj store
1955 if (bucketsToRemove.isEmpty()) {
1956 log.warn("Mismatch detected but could not determine which"
1957 + "buckets to remove");
1958 } else {
1959 GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove);
Pier Luigi3dfd8352018-01-25 16:16:02 +01001960 groupService.removeBucketsFromGroup(deviceId, topGroupKey,
1961 removeBuckets, topGroupKey,
Saurav Das9df5b7c2017-08-14 16:44:43 -07001962 nextObjective.appId());
1963 }
1964 } else if (actualGroupSize < objGroupSize) {
Pier Luigi3dfd8352018-01-25 16:16:02 +01001965 // Group in the device has less chains
Saurav Das9df5b7c2017-08-14 16:44:43 -07001966 // should also add buckets not in group-store but in obj-store
1967 List<GroupBucket> bucketsToAdd = Lists.newArrayList();
1968 //check every bucket in the obj
1969 for (Deque<GroupKey> validChain : allActiveKeys) {
1970 if (validChain.size() < 2) {
1971 continue;
1972 }
1973 GroupKey pointedGroupKey = validChain.stream()
1974 .collect(Collectors.toList()).get(1);
1975 Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey);
1976 if (pointedGroup == null) {
1977 // group should exist, otherwise cannot be added as bucket
1978 continue;
1979 }
1980 boolean matches = false;
Pier Luigi3dfd8352018-01-25 16:16:02 +01001981 for (GroupBucket bucket : topGroup.buckets().buckets()) {
Saurav Das9df5b7c2017-08-14 16:44:43 -07001982 GroupInstruction g = (GroupInstruction) bucket.treatment()
1983 .allInstructions().iterator().next();
1984 GroupId gidToCheck = g.groupId(); // the group pointed to
1985 if (pointedGroup.id().equals(gidToCheck)) {
1986 matches = true;
1987 break;
1988 }
1989 }
1990 if (!matches) {
1991 log.warn("Adding bucket pointing to groupId:{}", pointedGroup);
1992 TrafficTreatment t = DefaultTrafficTreatment.builder()
1993 .group(pointedGroup.id())
1994 .build();
Pier Luigi3dfd8352018-01-25 16:16:02 +01001995 // Create the proper bucket according to the next type
1996 if (nextObjective.type() == NextObjective.Type.HASHED) {
1997 bucketsToAdd.add(DefaultGroupBucket.createSelectGroupBucket(t));
1998 } else {
1999 bucketsToAdd.add(DefaultGroupBucket.createAllGroupBucket(t));
2000 }
Saurav Das9df5b7c2017-08-14 16:44:43 -07002001 }
2002 }
2003 if (bucketsToAdd.isEmpty()) {
2004 log.warn("Mismatch detected but could not determine which "
2005 + "buckets to add");
2006 } else {
2007 GroupBuckets addBuckets = new GroupBuckets(bucketsToAdd);
Pier Luigi3dfd8352018-01-25 16:16:02 +01002008 groupService.addBucketsToGroup(deviceId, topGroupKey,
2009 addBuckets, topGroupKey,
Saurav Das9df5b7c2017-08-14 16:44:43 -07002010 nextObjective.appId());
2011 }
2012 }
2013 }
pier2107d0c2020-01-27 17:45:03 +01002014 log.trace("Verify done for device:{} nextId:{}", deviceId, nextObjective.id());
Saurav Dasceccf242017-08-03 18:30:35 -07002015 pass(nextObjective);
2016 }
2017
2018 //////////////////////////////////////
2019 // Helper methods and classes
2020 //////////////////////////////////////
2021
Yi Tsengef19de12017-04-24 11:33:05 -07002022 protected void updatePendingNextObjective(GroupKey groupKey, OfdpaNextGroup nextGrp) {
2023 pendingAddNextObjectives.asMap().compute(groupKey, (k, val) -> {
Saurav Das961beb22017-03-29 19:09:17 -07002024 if (val == null) {
Yi Tsengef19de12017-04-24 11:33:05 -07002025 val = new CopyOnWriteArrayList<>();
Saurav Das961beb22017-03-29 19:09:17 -07002026 }
Yi Tsengef19de12017-04-24 11:33:05 -07002027 val.add(nextGrp);
Saurav Das961beb22017-03-29 19:09:17 -07002028 return val;
2029 });
Saurav Das8be4e3a2016-03-11 17:19:07 -08002030 }
2031
Yi Tsengef19de12017-04-24 11:33:05 -07002032 protected void updatePendingGroups(GroupKey groupKey, GroupChainElem gce) {
2033 pendingGroups.asMap().compute(groupKey, (k, val) -> {
Saurav Das961beb22017-03-29 19:09:17 -07002034 if (val == null) {
2035 val = Sets.newConcurrentHashSet();
2036 }
2037 val.add(gce);
2038 return val;
2039 });
Saurav Das8be4e3a2016-03-11 17:19:07 -08002040 }
2041
Yi Tsengef19de12017-04-24 11:33:05 -07002042 protected void addPendingUpdateNextObjective(GroupKey groupKey,
2043 NextObjective nextObjective) {
Yi Tseng78f51f42017-02-02 13:54:58 -08002044 pendingUpdateNextObjectives.compute(groupKey, (gKey, nextObjs) -> {
2045 if (nextObjs != null) {
2046 nextObjs.add(nextObjective);
2047 } else {
2048 nextObjs = Sets.newHashSet(nextObjective);
2049 }
2050 return nextObjs;
2051 });
2052 }
2053
Saurav Das2c57bc82018-04-07 16:51:09 -07002054 protected void addPendingRemoveNextObjective(NextObjective nextObjective,
2055 List<GroupKey> groupKeys) {
2056 pendingRemoveNextObjectives.put(nextObjective, groupKeys);
Yi Tsengef19de12017-04-24 11:33:05 -07002057 }
2058
Saurav Das2c57bc82018-04-07 16:51:09 -07002059 protected int getNextAvailableIndex() {
2060 return (int) nextIndex.incrementAndGet();
2061 }
2062
2063 protected void processPendingUpdateNextObjs(GroupKey groupKey) {
2064 Set<NextObjective> nextObjs = pendingUpdateNextObjectives.remove(groupKey);
2065 if (nextObjs != null) {
2066 nextObjs.forEach(nextObj -> {
2067 log.debug("Group {} updated, update pending next objective {}.",
2068 groupKey, nextObj);
2069 pass(nextObj);
2070 });
2071 }
2072 }
2073
2074 protected void processPendingRemoveNextObjs(GroupKey key) {
Yi Tsengef19de12017-04-24 11:33:05 -07002075 pendingRemoveNextObjectives.asMap().forEach((nextObjective, groupKeys) -> {
jaegonkimc92a6f72018-07-09 23:23:10 +09002076 groupKeys.remove(key);
Yi Tsengef19de12017-04-24 11:33:05 -07002077 if (groupKeys.isEmpty()) {
2078 pendingRemoveNextObjectives.invalidate(nextObjective);
2079 pass(nextObjective);
Yi Tsengef19de12017-04-24 11:33:05 -07002080 }
2081 });
2082 }
2083
Yi Tsengef19de12017-04-24 11:33:05 -07002084 protected void processPendingAddGroupsOrNextObjs(GroupKey key, boolean added) {
2085 //first check for group chain
2086 Set<OfdpaGroupHandlerUtility.GroupChainElem> gceSet = pendingGroups.asMap().remove(key);
2087 if (gceSet != null) {
2088 for (GroupChainElem gce : gceSet) {
2089 log.debug("Group service {} group key {} in device {}. "
2090 + "Processing next group in group chain with group id 0x{}",
2091 (added) ? "ADDED" : "processed",
2092 key, deviceId,
2093 Integer.toHexString(gce.groupDescription().givenGroupId()));
2094 processGroupChain(gce);
2095 }
2096 } else {
2097 // otherwise chain complete - check for waiting nextObjectives
2098 List<OfdpaGroupHandlerUtility.OfdpaNextGroup> nextGrpList =
2099 pendingAddNextObjectives.getIfPresent(key);
2100 if (nextGrpList != null) {
2101 pendingAddNextObjectives.invalidate(key);
2102 nextGrpList.forEach(nextGrp -> {
2103 log.debug("Group service {} group key {} in device:{}. "
2104 + "Done implementing next objective: {} <<-->> gid:0x{}",
2105 (added) ? "ADDED" : "processed",
2106 key, deviceId, nextGrp.nextObjective().id(),
2107 Integer.toHexString(groupService.getGroup(deviceId, key)
2108 .givenGroupId()));
2109 pass(nextGrp.nextObjective());
Saurav Dasc88d4662017-05-15 15:34:25 -07002110 updateFlowObjectiveStore(nextGrp.nextObjective().id(), nextGrp);
Yi Tsengef19de12017-04-24 11:33:05 -07002111
2112 // check if addBuckets waiting for this completion
2113 pendingBuckets.compute(nextGrp.nextObjective().id(), (nextId, pendBkts) -> {
2114 if (pendBkts != null) {
2115 pendBkts.forEach(pendBkt -> addBucketToGroup(pendBkt, nextGrp));
2116 }
2117 return null;
2118 });
2119 });
2120 }
2121 }
2122 }
2123
Charles Chan188ebf52015-12-23 00:15:11 -08002124 /**
2125 * Processes next element of a group chain. Assumption is that if this
2126 * group points to another group, the latter has already been created
2127 * and this driver has received notification for it. A second assumption is
2128 * that if there is another group waiting for this group then the appropriate
2129 * stores already have the information to act upon the notification for the
2130 * creation of this group.
2131 * <p>
2132 * The processing of the GroupChainElement depends on the number of groups
2133 * this element is waiting on. For all group types other than SIMPLE, a
2134 * GroupChainElement could be waiting on multiple groups.
2135 *
2136 * @param gce the group chain element to be processed next
2137 */
2138 private void processGroupChain(GroupChainElem gce) {
2139 int waitOnGroups = gce.decrementAndGetGroupsWaitedOn();
2140 if (waitOnGroups != 0) {
2141 log.debug("GCE: {} not ready to be processed", gce);
2142 return;
2143 }
2144 log.debug("GCE: {} ready to be processed", gce);
Yi Tsengef19de12017-04-24 11:33:05 -07002145 if (gce.addBucketToGroup()) {
2146 groupService.addBucketsToGroup(gce.groupDescription().deviceId(),
2147 gce.groupDescription().appCookie(),
2148 gce.groupDescription().buckets(),
2149 gce.groupDescription().appCookie(),
2150 gce.groupDescription().appId());
Charles Chan188ebf52015-12-23 00:15:11 -08002151 } else {
Yi Tsengef19de12017-04-24 11:33:05 -07002152 groupService.addGroup(gce.groupDescription());
Charles Chan188ebf52015-12-23 00:15:11 -08002153 }
2154 }
2155
Saurav Dasc88d4662017-05-15 15:34:25 -07002156 private void updateFlowObjectiveStore(Integer nextId, OfdpaNextGroup nextGrp) {
2157 synchronized (flowObjectiveStore) {
2158 // get fresh copy of what the store holds
2159 NextGroup next = flowObjectiveStore.getNextGroup(nextId);
2160 if (next == null || nextGrp.nextObjective().op() == Operation.ADD) {
2161 flowObjectiveStore.putNextGroup(nextId, nextGrp);
2162 return;
2163 }
2164 if (nextGrp.nextObjective().op() == Operation.ADD_TO_EXISTING) {
2165 List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
Pier Luigiaeb11a72018-01-15 09:48:49 +01002166 allActiveKeys = Lists.newArrayList(allActiveKeys);
Saurav Dasc88d4662017-05-15 15:34:25 -07002167 // If active keys shows only the top-level group without a chain of groups,
2168 // then it represents an empty group. Update by replacing empty chain.
2169 if (allActiveKeys.size() == 1 && allActiveKeys.get(0).size() == 1) {
2170 allActiveKeys.clear();
2171 }
2172 allActiveKeys.addAll(nextGrp.allKeys());
2173 flowObjectiveStore.putNextGroup(nextId,
2174 new OfdpaNextGroup(allActiveKeys, nextGrp.nextObjective()));
2175 }
2176 }
2177 }
2178
Saurav Das8be4e3a2016-03-11 17:19:07 -08002179 private class InnerGroupListener implements GroupListener {
2180 @Override
2181 public void event(GroupEvent event) {
Charles Chanfc5c7802016-05-17 13:13:55 -07002182 switch (event.type()) {
2183 case GROUP_ADDED:
2184 processPendingAddGroupsOrNextObjs(event.subject().appCookie(), true);
2185 break;
2186 case GROUP_REMOVED:
2187 processPendingRemoveNextObjs(event.subject().appCookie());
2188 break;
Yi Tseng78f51f42017-02-02 13:54:58 -08002189 case GROUP_UPDATED:
2190 processPendingUpdateNextObjs(event.subject().appCookie());
2191 break;
Charles Chanfc5c7802016-05-17 13:13:55 -07002192 default:
2193 break;
Saurav Das8be4e3a2016-03-11 17:19:07 -08002194 }
2195 }
2196 }
Charles Chan188ebf52015-12-23 00:15:11 -08002197}