Java Code Examples for org.onosproject.net.group.DefaultGroupBucket#createSelectGroupBucket()
The following examples show how to use
org.onosproject.net.group.DefaultGroupBucket#createSelectGroupBucket() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RulePopulatorUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Returns the group bucket with given traffic treatment and group type. * * @param treatment traffic treatment * @param type group type * @param weight weight (only for select type) * @return group bucket */ public static GroupBucket buildGroupBucket(TrafficTreatment treatment, Type type, short weight) { switch (type) { case ALL: return DefaultGroupBucket.createAllGroupBucket(treatment); case SELECT: if (weight == -1) { return DefaultGroupBucket.createSelectGroupBucket(treatment); } else { return DefaultGroupBucket.createSelectGroupBucket(treatment, weight); } case INDIRECT: return DefaultGroupBucket.createIndirectGroupBucket(treatment); default: return null; } }
Example 2
Source File: RulePopulatorUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Returns the group bucket with given traffic treatment and group type. * * @param treatment traffic treatment * @param type group type * @param weight weight (only for select type) * @return group bucket */ public static GroupBucket buildGroupBucket(TrafficTreatment treatment, GroupDescription.Type type, short weight) { switch (type) { case ALL: return DefaultGroupBucket.createAllGroupBucket(treatment); case SELECT: if (weight == -1) { return DefaultGroupBucket.createSelectGroupBucket(treatment); } else { return DefaultGroupBucket.createSelectGroupBucket(treatment, weight); } case INDIRECT: return DefaultGroupBucket.createIndirectGroupBucket(treatment); default: return null; } }
Example 3
Source File: SpringOpenTTP.java From onos with Apache License 2.0 | 5 votes |
private void addBucketToGroup(NextObjective nextObjective) { log.debug("addBucketToGroup in {}: for next objective id {}", deviceId, nextObjective.id()); Collection<TrafficTreatment> treatments = nextObjective.next(); TrafficTreatment treatment = treatments.iterator().next(); final GroupKey key = new DefaultGroupKey( appKryo.serialize(nextObjective .id())); Group group = groupService.getGroup(deviceId, key); if (group == null) { log.warn("Group is not found in {} for {}", deviceId, key); return; } GroupBucket bucket; if (group.type() == GroupDescription.Type.INDIRECT) { bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.SELECT) { bucket = DefaultGroupBucket.createSelectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.ALL) { bucket = DefaultGroupBucket.createAllGroupBucket(treatment); } else { log.warn("Unsupported Group type {}", group.type()); return; } GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket)); log.debug("Adding buckets to group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId); groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId); }
Example 4
Source File: SpringOpenTTP.java From onos with Apache License 2.0 | 5 votes |
private void removeBucketFromGroup(NextObjective nextObjective) { log.debug("removeBucketFromGroup in {}: for next objective id {}", deviceId, nextObjective.id()); NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); if (nextGroup != null) { Collection<TrafficTreatment> treatments = nextObjective.next(); TrafficTreatment treatment = treatments.iterator().next(); final GroupKey key = new DefaultGroupKey( appKryo.serialize(nextObjective .id())); Group group = groupService.getGroup(deviceId, key); if (group == null) { log.warn("Group is not found in {} for {}", deviceId, key); return; } GroupBucket bucket; if (group.type() == GroupDescription.Type.INDIRECT) { bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.SELECT) { bucket = DefaultGroupBucket.createSelectGroupBucket(treatment); } else if (group.type() == GroupDescription.Type.ALL) { bucket = DefaultGroupBucket.createAllGroupBucket(treatment); } else { log.warn("Unsupported Group type {}", group.type()); return; } GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket)); log.debug("Removing buckets from group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId); groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId); } }
Example 5
Source File: GroupBucketEntryBuilder.java From onos with Apache License 2.0 | 5 votes |
/** * Builds a GroupBuckets. * * @return GroupBuckets object, a list of GroupBuckets */ public GroupBuckets build() { List<GroupBucket> bucketList = Lists.newArrayList(); for (OFBucket bucket: ofBuckets) { TrafficTreatment treatment = buildTreatment(bucket.getActions()); // TODO: Use GroupBucketEntry GroupBucket groupBucket = null; switch (type) { case INDIRECT: groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment); break; case SELECT: groupBucket = DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight()); break; case FF: PortNumber port = PortNumber.portNumber(bucket.getWatchPort().getPortNumber()); GroupId groupId = new GroupId(bucket.getWatchGroup().getGroupNumber()); groupBucket = DefaultGroupBucket.createFailoverGroupBucket(treatment, port, groupId); break; case ALL: groupBucket = DefaultGroupBucket.createAllGroupBucket(treatment); break; default: log.error("Unsupported Group type : {}", type); } if (groupBucket != null) { bucketList.add(groupBucket); } } return new GroupBuckets(bucketList); }
Example 6
Source File: OpenFlowGroupProviderTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void addGroup() { GroupId groupId = new GroupId(1); List<GroupBucket> bucketList = Lists.newArrayList(); TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); builder.setOutput(PortNumber.portNumber(1)); GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build()); bucketList.add(bucket); GroupBuckets buckets = new GroupBuckets(bucketList); List<GroupOperation> operationList = Lists.newArrayList(); GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets); operationList.add(operation); GroupOperations operations = new GroupOperations(operationList); provider.performGroupOperation(deviceId, operations); final Dpid dpid = Dpid.dpid(deviceId.uri()); TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid); assertNotNull("Switch should not be nul", sw); assertNotNull("OFGroupMsg should not be null", sw.msg); }
Example 7
Source File: OpenFlowGroupProviderTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void groupModFailure() { TestOpenFlowGroupProviderService testProviderService = (TestOpenFlowGroupProviderService) providerService; GroupId groupId = new GroupId(1); List<GroupBucket> bucketList = Lists.newArrayList(); TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); builder.setOutput(PortNumber.portNumber(1)); GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build()); bucketList.add(bucket); GroupBuckets buckets = new GroupBuckets(bucketList); List<GroupOperation> operationList = Lists.newArrayList(); GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets); operationList.add(operation); GroupOperations operations = new GroupOperations(operationList); provider.performGroupOperation(deviceId, operations); OFGroupModFailedErrorMsg.Builder errorBuilder = OFFactories.getFactory(OFVersion.OF_13).errorMsgs().buildGroupModFailedErrorMsg(); OFGroupMod.Builder groupBuilder = OFFactories.getFactory(OFVersion.OF_13).buildGroupModify(); groupBuilder.setGroupType(OFGroupType.ALL); groupBuilder.setGroup(OFGroup.of(1)); errorBuilder.setCode(OFGroupModFailedCode.GROUP_EXISTS); errorBuilder.setXid(provider.getXidAndAdd(0) - 1); controller.processPacket(dpid1, errorBuilder.build()); assertNotNull("Operation failed should not be null", testProviderService.failedOperation); }
Example 8
Source File: OFAgentVirtualGroupBucketEntryBuilder.java From onos with Apache License 2.0 | 5 votes |
/** * Builds a GroupBuckets. * * @return GroupBuckets object, a list of GroupBuckets */ public GroupBuckets build() { List<GroupBucket> bucketList = Lists.newArrayList(); for (OFBucket bucket: ofBuckets) { TrafficTreatment treatment = buildTreatment(bucket.getActions()); // TODO: Use GroupBucketEntry GroupBucket groupBucket = null; switch (type) { case INDIRECT: groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment); break; case SELECT: groupBucket = DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight()); break; case FF: PortNumber port = PortNumber.portNumber(bucket.getWatchPort().getPortNumber()); GroupId groupId = new GroupId(bucket.getWatchGroup().getGroupNumber()); groupBucket = DefaultGroupBucket.createFailoverGroupBucket(treatment, port, groupId); break; case ALL: groupBucket = DefaultGroupBucket.createAllGroupBucket(treatment); break; default: log.error("Unsupported Group type : {}", type); } if (groupBucket != null) { bucketList.add(groupBucket); } } return new GroupBuckets(bucketList); }
Example 9
Source File: PiGroupTranslatorImplTest.java From onos with Apache License 2.0 | 5 votes |
private static GroupBucket selectOutputBucket(int portNum) { ImmutableByteSequence paramVal = copyFrom(portNum); PiActionParam param = new PiActionParam(PORT, paramVal); PiTableAction action = PiAction.builder() .withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT) .withParameter(param).build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .add(Instructions.piTableAction(action)) .build(); return DefaultGroupBucket.createSelectGroupBucket(treatment); }
Example 10
Source File: SimpleGroupStoreTest.java From onos with Apache License 2.0 | 5 votes |
private void testUpdateGroupEntryFromSB(GroupKey currKey) { Group existingGroup = simpleGroupStore.getGroup(D1, currKey); int totalPkts = 0; int totalBytes = 0; List<GroupBucket> newBucketList = new ArrayList<>(); for (GroupBucket bucket:existingGroup.buckets().buckets()) { StoredGroupBucketEntry newBucket = (StoredGroupBucketEntry) DefaultGroupBucket.createSelectGroupBucket(bucket.treatment()); newBucket.setPackets(10); newBucket.setBytes(10 * 256 * 8); totalPkts += 10; totalBytes += 10 * 256 * 8; newBucketList.add(newBucket); } GroupBuckets updatedBuckets = new GroupBuckets(newBucketList); Group updatedGroup = new DefaultGroup(existingGroup.id(), existingGroup.deviceId(), existingGroup.type(), updatedBuckets); ((StoredGroupEntry) updatedGroup).setPackets(totalPkts); ((StoredGroupEntry) updatedGroup).setBytes(totalBytes); InternalGroupStoreDelegate updateGroupEntryDelegate = new InternalGroupStoreDelegate(currKey, updatedBuckets, GroupEvent.Type.GROUP_UPDATED); simpleGroupStore.setDelegate(updateGroupEntryDelegate); simpleGroupStore.addOrUpdateGroupEntry(updatedGroup); simpleGroupStore.unsetDelegate(updateGroupEntryDelegate); }
Example 11
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 4 votes |
/** * Removes top-level buckets from a group that represents the given next objective. * * @param chainsToRemove a list of group bucket chains to remove * @param nextObjective the next objective that contains information for the * buckets to be removed from the group */ protected void removeBucket(List<Deque<GroupKey>> chainsToRemove, NextObjective nextObjective) { List<GroupBucket> bucketsToRemove = Lists.newArrayList(); //first group key is the one we want to modify GroupKey modGroupKey = chainsToRemove.get(0).peekFirst(); Group modGroup = groupService.getGroup(deviceId, modGroupKey); if (modGroup == null) { log.warn("removeBucket(): Attempt to modify non-existent group {} for device {}", modGroupKey, deviceId); return; } for (Deque<GroupKey> foundChain : chainsToRemove) { //second group key is the one we wish to remove the reference to if (foundChain.size() < 2) { // additional check to make sure second group key exists in // the chain. log.warn("Can't find second group key from chain {}", foundChain); continue; } GroupKey pointedGroupKey = foundChain.stream() .collect(Collectors.toList()).get(1); Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey); if (pointedGroup == null) { continue; } GroupBucket bucket; if (nextObjective.type() == NextObjective.Type.HASHED) { bucket = DefaultGroupBucket.createSelectGroupBucket( DefaultTrafficTreatment.builder() .group(pointedGroup.id()) .build()); } else { bucket = DefaultGroupBucket.createAllGroupBucket( DefaultTrafficTreatment.builder() .group(pointedGroup.id()) .build()); } bucketsToRemove.add(bucket); } GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove); List<String> pointedGroupIds; // for debug log pointedGroupIds = bucketsToRemove.stream() .map(GroupBucket::treatment) .map(TrafficTreatment::allInstructions) .flatMap(List::stream) .filter(inst -> inst instanceof Instructions.GroupInstruction) .map(inst -> (Instructions.GroupInstruction) inst) .map(Instructions.GroupInstruction::groupId) .map(GroupId::id) .map(Integer::toHexString) .map(id -> HEX_PREFIX + id) .collect(Collectors.toList()); log.debug("Removing buckets from group id 0x{} pointing to group id(s) {} " + "for next id {} in device {}", Integer.toHexString(modGroup.id().id()), pointedGroupIds, nextObjective.id(), deviceId); addPendingUpdateNextObjective(modGroupKey, nextObjective); groupService.removeBucketsFromGroup(deviceId, modGroupKey, removeBuckets, modGroupKey, nextObjective.appId()); // update store - synchronize access as there may be multiple threads // trying to remove buckets from the same group, each with its own // potentially stale copy of allActiveKeys synchronized (flowObjectiveStore) { // get a fresh copy of what the store holds NextGroup next = flowObjectiveStore.getNextGroup(nextObjective.id()); List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data()); allActiveKeys = Lists.newArrayList(allActiveKeys); // Note that since we got a new object, and ArrayDeque does not implement // Object.equals(), we have to check the deque elems one by one allActiveKeys .removeIf(active -> chainsToRemove.stream().anyMatch(remove -> Arrays.equals(remove.toArray(new GroupKey[0]), active.toArray(new GroupKey[0])))); // If no buckets in the group, then retain an entry for the // top level group which still exists. if (allActiveKeys.isEmpty()) { ArrayDeque<GroupKey> top = new ArrayDeque<>(); top.add(modGroupKey); allActiveKeys.add(top); } flowObjectiveStore.putNextGroup(nextObjective.id(), new OfdpaNextGroup(allActiveKeys, nextObjective)); } }
Example 12
Source File: GroupBucketCodec.java From onos with Apache License 2.0 | 4 votes |
@Override public GroupBucket decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } // build traffic treatment ObjectNode treatmentJson = get(json, TREATMENT); TrafficTreatment trafficTreatment = null; if (treatmentJson != null) { JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class); trafficTreatment = treatmentCodec.decode(treatmentJson, context); } // parse group type String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); GroupBucket groupBucket = null; switch (type) { case "SELECT": // parse weight int weightInt = nullIsIllegal(json.get(WEIGHT), WEIGHT + MISSING_MEMBER_MESSAGE).asInt(); groupBucket = DefaultGroupBucket.createSelectGroupBucket(trafficTreatment, (short) weightInt); break; case "INDIRECT": groupBucket = DefaultGroupBucket.createIndirectGroupBucket(trafficTreatment); break; case "ALL": groupBucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment); break; case "FAILOVER": // parse watchPort PortNumber watchPort = PortNumber.portNumber(nullIsIllegal(json.get(WATCH_PORT), WATCH_PORT + MISSING_MEMBER_MESSAGE).asText()); // parse watchGroup int groupIdInt = nullIsIllegal(json.get(WATCH_GROUP), WATCH_GROUP + MISSING_MEMBER_MESSAGE).asInt(); GroupId watchGroup = new GroupId((short) groupIdInt); groupBucket = DefaultGroupBucket.createFailoverGroupBucket(trafficTreatment, watchPort, watchGroup); break; default: DefaultGroupBucket.createAllGroupBucket(trafficTreatment); } return groupBucket; }