use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method addBucketToL3MulticastGroup.
private void addBucketToL3MulticastGroup(NextObjective nextObj, List<Deque<GroupKey>> allActiveKeys, List<GroupInfo> groupInfos, VlanId assignedVlan) {
// Create the buckets to add to the outermost L3 Multicast group
List<GroupBucket> newBuckets = createL3MulticastBucket(groupInfos);
// get the group being edited
Group l3mcastGroup = retrieveTopLevelGroup(allActiveKeys, deviceId, groupService, nextObj.id());
if (l3mcastGroup == null) {
fail(nextObj, ObjectiveError.GROUPMISSING);
return;
}
GroupKey l3mcastGroupKey = l3mcastGroup.appCookie();
int l3mcastGroupId = l3mcastGroup.id().id();
// ensure assignedVlan applies to the chosen group
VlanId expectedVlan = extractVlanIdFromGroupId(l3mcastGroupId);
if (!expectedVlan.equals(assignedVlan)) {
log.warn("VLAN ID {} does not match L3 Mcast group {} to which bucket is " + "being added, for next:{} in dev:{}. Abort.", assignedVlan, Integer.toHexString(l3mcastGroupId), nextObj.id(), deviceId);
fail(nextObj, ObjectiveError.BADPARAMS);
}
GroupDescription l3mcastGroupDescription = new DefaultGroupDescription(deviceId, ALL, new GroupBuckets(newBuckets), l3mcastGroupKey, l3mcastGroupId, nextObj.appId());
GroupChainElem l3mcastGce = new GroupChainElem(l3mcastGroupDescription, groupInfos.size(), true, deviceId);
List<Deque<GroupKey>> addedKeys = new ArrayList<>();
groupInfos.forEach(groupInfo -> {
// update original NextGroup with new bucket-chain
Deque<GroupKey> newBucketChain = new ArrayDeque<>();
newBucketChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
// Add L3 interface group to the chain if there is one.
if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie());
}
newBucketChain.addFirst(l3mcastGroupKey);
addedKeys.add(newBucketChain);
updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3mcastGce);
// Point next group to inner-most group, if any
if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(), 1, false, deviceId);
updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce);
}
log.debug("Adding to L3MCAST: device:{} gid:{} group key:{} nextId:{}", deviceId, Integer.toHexString(l3mcastGroupId), l3mcastGroupKey, nextObj.id());
// send the innermost group
log.debug("Sending innermost group {} in group chain on device {} ", Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()), deviceId);
groupService.addGroup(groupInfo.innerMostGroupDesc());
});
updatePendingNextObjective(l3mcastGroupKey, new OfdpaNextGroup(addedKeys, nextObj));
}
use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method createL2InterfaceGroup.
/**
* Creates a simple L2 Interface Group.
* @param nextObj the next Objective
*/
private void createL2InterfaceGroup(NextObjective nextObj) {
VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
if (assignedVlan == null) {
log.warn("VLAN ID required by simple next obj is missing. Abort.");
fail(nextObj, ObjectiveError.BADPARAMS);
return;
}
List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
// There is only one L2 interface group in this case
GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc();
// Put all dependency information into allGroupKeys
List<Deque<GroupKey>> allGroupKeys = Lists.newArrayList();
Deque<GroupKey> gkeyChain = new ArrayDeque<>();
gkeyChain.addFirst(l2InterfaceGroupDesc.appCookie());
allGroupKeys.add(gkeyChain);
// Point the next objective to this group
OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
updatePendingNextObjective(l2InterfaceGroupDesc.appCookie(), ofdpaGrp);
// Start installing the inner-most group
groupService.addGroup(l2InterfaceGroupDesc);
}
use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method init.
public void init(DeviceId deviceId, PipelinerContext context) {
ServiceDirectory serviceDirectory = context.directory();
this.deviceId = deviceId;
this.flowObjectiveStore = context.store();
this.groupService = serviceDirectory.get(GroupService.class);
this.storageService = serviceDirectory.get(StorageService.class);
this.nextIndex = storageService.getAtomicCounter("group-id-index-counter");
pendingAddNextObjectives = CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.SECONDS).removalListener((RemovalNotification<GroupKey, List<OfdpaNextGroup>> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED && Objects.nonNull(notification.getValue())) {
notification.getValue().forEach(ofdpaNextGrp -> fail(ofdpaNextGrp.nextObjective(), ObjectiveError.GROUPINSTALLATIONFAILED));
}
}).build();
pendingRemoveNextObjectives = CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.SECONDS).removalListener((RemovalNotification<NextObjective, List<GroupKey>> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
fail(notification.getKey(), ObjectiveError.GROUPREMOVALFAILED);
}
}).build();
pendingGroups = CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.SECONDS).removalListener((RemovalNotification<GroupKey, Set<GroupChainElem>> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
log.error("Unable to install group with key {} and pending GCEs: {}", notification.getKey(), notification.getValue());
}
}).build();
pendingUpdateNextObjectives = new ConcurrentHashMap<>();
GroupChecker groupChecker = new GroupChecker(this);
groupCheckerExecutor.scheduleAtFixedRate(groupChecker, 0, 500, TimeUnit.MILLISECONDS);
groupService.addListener(innerGroupListener);
}
use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method processL2HashedNextObjective.
/**
* Create L2 hash group.
*
* @param nextObj next objective
*/
private void processL2HashedNextObjective(NextObjective nextObj) {
int l2LbIndex = Optional.ofNullable(nextObj.meta().getCriterion(IN_PORT)).map(c -> (PortCriterion) c).map(PortCriterion::port).map(PortNumber::toLong).map(Long::intValue).orElse(-1);
if (l2LbIndex == -1) {
log.warn("l2LbIndex is not found in the meta of L2 hash objective. Abort");
return;
}
// Storage for all group keys in the chain of groups created
List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
List<GroupInfo> unsentGroups = new ArrayList<>();
createL2HashBuckets(nextObj, allGroupKeys, unsentGroups);
// Create L2 load balancing group
List<GroupBucket> l2LbGroupBuckets = new ArrayList<>();
for (GroupInfo gi : unsentGroups) {
// create load balancing bucket to point to the outer group
TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();
ttb.group(new GroupId(gi.nextGroupDesc().givenGroupId()));
GroupBucket sbucket = DefaultGroupBucket.createSelectGroupBucket(ttb.build());
l2LbGroupBuckets.add(sbucket);
}
int l2LbGroupId = L2_LB_TYPE | (TYPE_MASK & l2LbIndex);
int l2lbgk = l2HashGroupKey(deviceId, l2LbIndex);
GroupKey l2LbGroupKey = new DefaultGroupKey(appKryo.serialize(l2lbgk));
GroupDescription l2LbGroupDesc = new DefaultGroupDescription(deviceId, SELECT, new GroupBuckets(l2LbGroupBuckets), l2LbGroupKey, l2LbGroupId, nextObj.appId());
GroupChainElem l2LbGce = new GroupChainElem(l2LbGroupDesc, l2LbGroupBuckets.size(), false, deviceId);
// Create objects for local and distributed storage
allGroupKeys.forEach(gKeyChain -> gKeyChain.addFirst(l2LbGroupKey));
OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
// Store l2LbGroupKey with the ofdpaGroupChain for the nextObjective that depends on it
updatePendingNextObjective(l2LbGroupKey, ofdpaGrp);
log.debug("Trying L2-LB: device:{} gid:{} gkey:{} nextId:{}", deviceId, Integer.toHexString(l2LbGroupId), l2LbGroupKey, nextObj.id());
// finally we are ready to send the innermost groups
for (GroupInfo gi : unsentGroups) {
log.debug("Sending innermost group {} in group chain on device {} ", Integer.toHexString(gi.innerMostGroupDesc().givenGroupId()), deviceId);
updatePendingGroups(gi.nextGroupDesc().appCookie(), l2LbGce);
groupService.addGroup(gi.innerMostGroupDesc());
}
}
use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method createMplsSwap.
/**
* Creates an Mpls group of type swap.
*
* @param nextGroupId the next group in the chain
* @param subtype the mpls swap label group subtype
* @param index the index of the group
* @param mplsLabel the mpls label to swap
* @param applicationId the application id
* @return the group description
*/
protected GroupDescription createMplsSwap(int nextGroupId, OfdpaMplsGroupSubType subtype, int index, MplsLabel mplsLabel, ApplicationId applicationId) {
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.setMpls(mplsLabel);
// We point the group to the next group.
treatment.group(new GroupId(nextGroupId));
GroupBucket groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment.build());
// Finally we build the group description.
int groupId = makeMplsLabelGroupId(subtype, index);
GroupKey groupKey = new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(index));
return new DefaultGroupDescription(deviceId, INDIRECT, new GroupBuckets(Collections.singletonList(groupBucket)), groupKey, groupId, applicationId);
}
Aggregations