org.onosproject.net.group.DefaultGroupBucket Java Examples
The following examples show how to use
org.onosproject.net.group.DefaultGroupBucket.
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: Utils.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) { final GroupKey groupKey = new PiGroupKey( PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId); final List<GroupBucket> buckets = actions.stream() .map(action -> DefaultTrafficTreatment.builder() .piTableAction(action).build()) .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); return new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId); }
Example #2
Source File: Utils.java From ngsdn-tutorial with Apache License 2.0 | 6 votes |
public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) { final GroupKey groupKey = new PiGroupKey( PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId); final List<GroupBucket> buckets = actions.stream() .map(action -> DefaultTrafficTreatment.builder() .piTableAction(action).build()) .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); return new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId); }
Example #3
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 #4
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 #5
Source File: VirtualNetworkGroupManagerTest.java From onos with Apache License 2.0 | 6 votes |
private Group createSouthboundGroupEntry(GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) { List<PortNumber> outPorts = new ArrayList<>(); outPorts.addAll(ports); List<GroupBucket> buckets = new ArrayList<>(); for (PortNumber portNumber : outPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) .pushMpls() .setMpls(MplsLabel.mplsLabel(106)); buckets.add(DefaultGroupBucket.createSelectGroupBucket( tBuilder.build())); } GroupBuckets groupBuckets = new GroupBuckets(buckets); StoredGroupEntry group = new DefaultGroup( gId, deviceId, Group.Type.SELECT, groupBuckets); group.setReferenceCount(referenceCount); return group; }
Example #6
Source File: PointToPointIntentCompiler.java From onos with Apache License 2.0 | 6 votes |
/** * Creates a new failover group with the initial ports of the links * from the primary and backup path. * * @param links links from the primary path * @param backupLinks links from the backup path * @param intent intent from which this call originates */ private void createFailoverTreatmentGroup(List<Link> links, List<Link> backupLinks, PointToPointIntent intent) { List<GroupBucket> buckets = new ArrayList<>(); TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); ConnectPoint src = links.get(0).src(); tBuilderIn.setOutput(src.port()); TrafficTreatment.Builder tBuilderIn2 = DefaultTrafficTreatment.builder(); ConnectPoint src2 = backupLinks.get(0).src(); tBuilderIn2.setOutput(src2.port()); buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null)); buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn2.build(), src2.port(), null)); GroupBuckets groupBuckets = new GroupBuckets(buckets); GroupDescription groupDesc = new DefaultGroupDescription(src.deviceId(), Group.Type.FAILOVER, groupBuckets, makeGroupKey(intent.id()), null, intent.appId()); log.trace("adding failover group {}", groupDesc); groupService.addGroup(groupDesc); }
Example #7
Source File: GroupManagerTest.java From onos with Apache License 2.0 | 6 votes |
private static Group createSouthboundGroupEntry(GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) { List<PortNumber> outPorts = new ArrayList<>(); outPorts.addAll(ports); List<GroupBucket> buckets = new ArrayList<>(); for (PortNumber portNumber : outPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) .pushMpls() .setMpls(MplsLabel.mplsLabel(106)); buckets.add(DefaultGroupBucket.createSelectGroupBucket( tBuilder.build())); } GroupBuckets groupBuckets = new GroupBuckets(buckets); StoredGroupEntry group = new DefaultGroup( gId, deviceId, Group.Type.SELECT, groupBuckets); group.setReferenceCount(referenceCount); return group; }
Example #8
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 6 votes |
/** * 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); }
Example #9
Source File: OvsOfdpaPipeline.java From onos with Apache License 2.0 | 6 votes |
/** * Builds a indirect group contains pop_vlan and punt actions. * <p> * Using group instead of immediate action to ensure that * the copy of packet on the data plane is not affected by the pop vlan action. */ private void initPopVlanPuntGroup() { GroupKey groupKey = popVlanPuntGroupKey(); TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder() .popVlan().punt().build(); GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment); GroupDescription groupDesc = new DefaultGroupDescription( deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(bucket)), groupKey, POP_VLAN_PUNT_GROUP_ID, driverId); groupService.addGroup(groupDesc); log.info("Initialized pop vlan punt group on {}", deviceId); }
Example #10
Source File: OfdpaGroupHandlerUtility.java From onos with Apache License 2.0 | 6 votes |
static List<GroupBucket> createL3MulticastBucket(List<GroupInfo> groupInfos) { List<GroupBucket> l3McastBuckets = new ArrayList<>(); // For each inner group groupInfos.forEach(groupInfo -> { // Points to L3 interface group if there is one. // Otherwise points to L2 interface group directly. GroupDescription nextGroupDesc = (groupInfo.nextGroupDesc() != null) ? groupInfo.nextGroupDesc() : groupInfo.innerMostGroupDesc(); TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder(); ttb.group(new GroupId(nextGroupDesc.givenGroupId())); GroupBucket abucket = DefaultGroupBucket.createAllGroupBucket(ttb.build()); l3McastBuckets.add(abucket); }); // Done return the new list of buckets return l3McastBuckets; }
Example #11
Source File: Utils.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) { final GroupKey groupKey = new PiGroupKey( PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId); final List<GroupBucket> buckets = actions.stream() .map(action -> DefaultTrafficTreatment.builder() .piTableAction(action).build()) .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); return new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId); }
Example #12
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 #13
Source File: GroupCodecTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void codecEncodeTest() { GroupBucket bucket1 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment()); GroupBucket bucket2 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment()); GroupBucket bucket3 = DefaultGroupBucket.createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment()); GroupBuckets allBuckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2)); GroupBuckets indirectBuckets = new GroupBuckets(ImmutableList.of(bucket3)); DefaultGroup group = new DefaultGroup( new GroupId(1), NetTestTools.did("d1"), ALL, allBuckets); DefaultGroup group1 = new DefaultGroup( new GroupId(2), NetTestTools.did("d2"), INDIRECT, indirectBuckets); MockCodecContext context = new MockCodecContext(); GroupCodec codec = new GroupCodec(); ObjectNode groupJson = codec.encode(group, context); ObjectNode groupJsonIndirect = codec.encode(group1, context); assertThat(groupJson, matchesGroup(group)); assertThat(groupJsonIndirect, matchesGroup(group1)); }
Example #14
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 #15
Source File: PointToPointIntentCompiler.java From onos with Apache License 2.0 | 5 votes |
private void updateFailoverGroup(PointToPointIntent intent, List<Link> links) { GroupKey groupKey = makeGroupKey(intent.id()); TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); ConnectPoint src = links.get(0).src(); tBuilderIn.setOutput(src.port()); GroupBucket bucket = DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null); GroupBuckets addBuckets = new GroupBuckets(Collections.singletonList(bucket)); groupService.addBucketsToGroup(src.deviceId(), groupKey, addBuckets, groupKey, intent.appId()); }
Example #16
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 #17
Source File: SimpleGroupStoreTest.java From onos with Apache License 2.0 | 5 votes |
private void testSetBuckets(GroupKey currKey, GroupKey setKey) { List<GroupBucket> toSetBuckets = new ArrayList<>(); short weight = 5; PortNumber portNumber = PortNumber.portNumber(42); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) .setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) .pushMpls() .setMpls(MplsLabel.mplsLabel(106)); toSetBuckets.add(DefaultGroupBucket.createSelectGroupBucket( tBuilder.build(), weight)); GroupBuckets toSetGroupBuckets = new GroupBuckets(toSetBuckets); InternalGroupStoreDelegate updateGroupDescDelegate = new InternalGroupStoreDelegate(setKey, toSetGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED); simpleGroupStore.setDelegate(updateGroupDescDelegate); simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.SET, toSetGroupBuckets, setKey); simpleGroupStore.unsetDelegate(updateGroupDescDelegate); }
Example #18
Source File: NextObjectiveTranslator.java From onos with Apache License 2.0 | 5 votes |
private int selectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException { final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED; final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true); final List<TrafficTreatment> piTreatments = Lists.newArrayList(); for (DefaultNextTreatment t : defaultNextTreatments) { // Map treatment to PI... piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId)); // ...and handle egress if necessary. handleEgress(obj, t.treatment(), resultBuilder, false); } final List<GroupBucket> bucketList = piTreatments.stream() .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); final int groupId = obj.id(); final PiGroupKey groupKey = new PiGroupKey( hashedTableId, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, groupId); resultBuilder.addGroup(new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(bucketList), groupKey, groupId, obj.appId())); return groupId; }
Example #19
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 #20
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 #21
Source File: AbstractCorsaPipeline.java From onos with Apache License 2.0 | 5 votes |
@Override public void next(NextObjective nextObjective) { switch (nextObjective.type()) { case SIMPLE: Collection<TrafficTreatment> treatments = nextObjective.next(); if (treatments.size() == 1) { TrafficTreatment treatment = treatments.iterator().next(); CorsaTrafficTreatment corsaTreatment = processNextTreatment(treatment); final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id())); if (corsaTreatment.type() == CorsaTrafficTreatmentType.GROUP) { GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(corsaTreatment.treatment()); GroupBuckets buckets = new GroupBuckets(Collections.singletonList(bucket)); // group id == null, let group service determine group id GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, buckets, key, null, nextObjective.appId()); groupService.addGroup(groupDescription); pendingGroups.put(key, nextObjective); } else if (corsaTreatment.type() == CorsaTrafficTreatmentType.ACTIONS) { pendingNext.put(nextObjective.id(), nextObjective); flowObjectiveStore.putNextGroup(nextObjective.id(), new CorsaGroup(key)); nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective)); } } break; case HASHED: case BROADCAST: case FAILOVER: fail(nextObjective, ObjectiveError.UNSUPPORTED); log.warn("Unsupported next objective type {}", nextObjective.type()); break; default: fail(nextObjective, ObjectiveError.UNKNOWN); log.warn("Unknown next objective type {}", nextObjective.type()); } }
Example #22
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 #23
Source File: OfdpaGroupHandlerUtility.java From onos with Apache License 2.0 | 5 votes |
/** * Generates a list of group buckets from given list of group information * and group bucket type. * * @param groupInfos a list of group information * @param bucketType group bucket type * @return list of group bucket generate from group information */ static List<GroupBucket> generateNextGroupBuckets(List<GroupInfo> groupInfos, GroupDescription.Type bucketType) { List<GroupBucket> newBuckets = Lists.newArrayList(); groupInfos.forEach(groupInfo -> { GroupDescription groupDesc = groupInfo.nextGroupDesc(); TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); treatmentBuilder.group(new GroupId(groupDesc.givenGroupId())); GroupBucket newBucket = null; switch (bucketType) { case ALL: newBucket = DefaultGroupBucket.createAllGroupBucket(treatmentBuilder.build()); break; case INDIRECT: newBucket = DefaultGroupBucket.createIndirectGroupBucket(treatmentBuilder.build()); break; case SELECT: newBucket = DefaultGroupBucket.createSelectGroupBucket(treatmentBuilder.build()); break; case FAILOVER: // TODO: support failover bucket type default: log.warn("Unknown bucket type: {}", bucketType); break; } if (newBucket != null) { newBuckets.add(newBucket); } }); return ImmutableList.copyOf(newBuckets); }
Example #24
Source File: Ofdpa3GroupHandler.java From onos with Apache License 2.0 | 5 votes |
/** * Helper method to create a mpls tunnel label group. * * @param nextGroupId the next group in the chain * @param subtype the mpls tunnel label group subtype * @param index the index of the group * @param instructions the instructions to push * @param applicationId the application id * @return the group description */ private GroupDescription createMplsTunnelLabelGroup(int nextGroupId, OfdpaMplsGroupSubType subtype, int index, List<Instruction> instructions, ApplicationId applicationId) { TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); // We add all the instructions. instructions.forEach(treatment::add); // 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 ); }
Example #25
Source File: Ofdpa3GroupHandler.java From onos with Apache License 2.0 | 5 votes |
/** * Helper method to create a mpls l2 vpn group. * * @param nextGroupId the next group in the chain * @param index the index of the group * @param instructions the instructions to push * @param applicationId the application id * @return the group description */ private GroupDescription createMplsL2VpnGroup(int nextGroupId, int index, List<Instruction> instructions, ApplicationId applicationId) { TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); // We add the extensions and the instructions. treatment.extension(new Ofdpa3PushL2Header(), deviceId); treatment.pushVlan(); instructions.forEach(treatment::add); treatment.extension(new Ofdpa3PushCw(), deviceId); // 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(OfdpaMplsGroupSubType.L2_VPN, index); GroupKey groupKey = new DefaultGroupKey( Ofdpa2Pipeline.appKryo.serialize(index) ); return new DefaultGroupDescription( deviceId, INDIRECT, new GroupBuckets(Collections.singletonList(groupBucket)), groupKey, groupId, applicationId ); }
Example #26
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 #27
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 #28
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 5 votes |
private void createL2MulticastGroup(NextObjective nextObj, VlanId vlanId, List<GroupInfo> groupInfos) { // Realize & represent L2 multicast group in OFDPA driver layer // TODO : Need to identify significance of OfdpaNextGroup. Integer l2MulticastGroupId = L2_MULTICAST_TYPE | (vlanId.toShort() << 16); final GroupKey l2MulticastGroupKey = l2MulticastGroupKey(vlanId, deviceId); List<Deque<GroupKey>> l2MulticastAllGroup = Lists.newArrayList(); groupInfos.forEach(groupInfo -> { Deque<GroupKey> groupKeyChain = new ArrayDeque<>(); groupKeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie()); groupKeyChain.addFirst(l2MulticastGroupKey); l2MulticastAllGroup.add(groupKeyChain); }); OfdpaNextGroup ofdpaL2MulticastGroup = new OfdpaNextGroup(l2MulticastAllGroup, nextObj); updatePendingNextObjective(l2MulticastGroupKey, ofdpaL2MulticastGroup); // Group Chain Hierarchy creation using group service and thus in device level List<GroupBucket> l2McastBuckets = new ArrayList<>(); groupInfos.forEach(groupInfo -> { // Points to L2 interface group directly. TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder(); trafficTreatment.group(new GroupId(groupInfo.innerMostGroupDesc().givenGroupId())); GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment.build()); l2McastBuckets.add(bucket); }); GroupDescription l2MulticastGroupDescription = new DefaultGroupDescription( deviceId, ALL, new GroupBuckets(l2McastBuckets), l2MulticastGroupKey, l2MulticastGroupId, nextObj.appId()); GroupChainElem l2MulticastGce = new GroupChainElem(l2MulticastGroupDescription, groupInfos.size(), false, deviceId); groupInfos.forEach(groupInfo -> { updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), l2MulticastGce); groupService.addGroup(groupInfo.innerMostGroupDesc()); }); }
Example #29
Source File: DistributedGroupStore.java From onos with Apache License 2.0 | 4 votes |
@Activate public void activate(ComponentContext context) { cfgService.registerProperties(getClass()); modified(context); KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() .register(KryoNamespaces.API) .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID) .register(DefaultGroup.class, DefaultGroupBucket.class, DefaultGroupDescription.class, DefaultGroupKey.class, GroupDescription.Type.class, Group.GroupState.class, GroupBuckets.class, GroupStoreMessage.class, GroupStoreMessage.Type.class, UpdateType.class, GroupStoreMessageSubjects.class, MultiValuedTimestamp.class, GroupStoreKeyMapKey.class, GroupStoreIdMapKey.class, GroupStoreMapKey.class ); clusterMsgSerializer = kryoBuilder.build("GroupStore"); Serializer serializer = Serializer.using(clusterMsgSerializer); messageHandlingExecutor = Executors. newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE, groupedThreads("onos/store/group", "message-handlers", log)); clusterCommunicator.addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, clusterMsgSerializer::deserialize, this::process, messageHandlingExecutor); log.debug("Creating Consistent map onos-group-store-keymap"); groupStoreEntriesByKey = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() .withName("onos-group-store-keymap") .withSerializer(serializer) .build(); groupStoreEntriesByKey.addListener(mapListener); log.debug("Current size of groupstorekeymap:{}", groupStoreEntriesByKey.size()); synchronizeGroupStoreEntries(); log.debug("Creating GroupStoreId Map From GroupStoreKey Map"); matchGroupEntries(); executor = newSingleThreadScheduledExecutor(groupedThreads("onos/group", "store", log)); statusChangeListener = status -> { if (status == Status.ACTIVE) { executor.execute(this::matchGroupEntries); } }; groupStoreEntriesByKey.addStatusChangeListener(statusChangeListener); log.debug("Creating Consistent map pendinggroupkeymap"); auditPendingReqQueue = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() .withName("onos-pending-group-keymap") .withSerializer(serializer) .build(); log.debug("Current size of pendinggroupkeymap:{}", auditPendingReqQueue.size()); groupTopic = getOrCreateGroupTopic(serializer); groupTopic.subscribe(this::processGroupMessage); local = clusterService.getLocalNode().id(); log.info("Started"); }
Example #30
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; }