use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class OvsOfdpaGroupHandler method createUnfilteredL2L3Chain.
/**
* Internal implementation of createL2L3Chain to handle double-tagged vlan.
* L3UG Group carries dummyVlanId and output port information in its groupId,
* and does not set vlan.
* L2UG Group only has OUTPUT instruction.
*
* @param treatment that needs to be broken up to create the group chain
* @param nextId of the next objective that needs this group chain
* @param appId of the application that sent this next objective
* @return GroupInfo containing the GroupDescription of the
* L2 Unfiltered Interface group(inner) and the GroupDescription of the (outer)
* L3Unicast group. May return null if there is an error in processing the chain.
*/
private GroupInfo createUnfilteredL2L3Chain(TrafficTreatment treatment, int nextId, ApplicationId appId) {
// for the l2 unfiltered interface group, get port info
// for the l3 unicast group, get the src/dst mac, and vlan info
TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
VlanId vlanId = VlanId.NONE;
long portNum = 0;
MacAddress srcMac;
MacAddress dstMac;
for (Instruction ins : treatment.allInstructions()) {
if (ins.type() == Instruction.Type.L2MODIFICATION) {
L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
switch(l2ins.subtype()) {
case ETH_DST:
dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
outerTtb.setEthDst(dstMac);
break;
case ETH_SRC:
srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
outerTtb.setEthSrc(srcMac);
break;
case VLAN_ID:
vlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
break;
default:
break;
}
} else if (ins.type() == Instruction.Type.OUTPUT) {
portNum = ((Instructions.OutputInstruction) ins).port().toLong();
innerTtb.add(ins);
} else {
log.debug("Driver does not handle this type of TrafficTreatment" + " instruction in l2l3chain: {} - {}", ins.type(), ins);
}
}
// assemble information for ofdpa l2 unfiltered interface group
int l2groupId = l2UnfilteredGroupId(portNum);
// a globally unique groupkey that is different for ports in the same device,
// but different for the same portnumber on different devices. Also different
// for the various group-types created out of the same next objective.
int l2gk = l2UnfilteredGroupKey(deviceId, portNum);
final GroupKey l2groupkey = new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(l2gk));
// assemble information for outer group (L3Unicast)
GroupDescription outerGrpDesc;
int l3groupId = doubleVlanL3UnicastGroupId(vlanId, portNum);
final GroupKey l3groupkey = new DefaultGroupKey(Ofdpa3Pipeline.appKryo.serialize(doubleVlanL3UnicastGroupKey(deviceId, vlanId, portNum)));
outerTtb.group(new GroupId(l2groupId));
// create the l3unicast group description to wait for the
// l2 unfiltered interface group to be processed
GroupBucket l3unicastGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
outerGrpDesc = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(l3unicastGroupBucket)), l3groupkey, l3groupId, appId);
log.debug("Trying L3Unicast: device:{} gid:{} gkey:{} nextid:{}", deviceId, Integer.toHexString(l3groupId), l3groupkey, nextId);
// store l2groupkey with the groupChainElem for the outer-group that depends on it
OfdpaGroupHandlerUtility.GroupChainElem gce = new OfdpaGroupHandlerUtility.GroupChainElem(outerGrpDesc, 1, false, deviceId);
updatePendingGroups(l2groupkey, gce);
// create group description for the inner l2 unfiltered interface group
GroupBucket l2InterfaceGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(innerTtb.build());
GroupDescription l2groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(l2InterfaceGroupBucket)), l2groupkey, l2groupId, appId);
log.debug("Trying L2Unfiltered: device:{} gid:{} gkey:{} nextId:{}", deviceId, Integer.toHexString(l2groupId), l2groupkey, nextId);
return new OfdpaGroupHandlerUtility.GroupInfo(l2groupDescription, outerGrpDesc);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class GroupCodecTest method codecDecodeTest.
@Test
public void codecDecodeTest() throws IOException {
Group group = getGroup("simple-group.json");
checkCommonData(group);
assertThat(group.buckets().buckets().size(), is(1));
GroupBucket groupBucket = group.buckets().buckets().get(0);
assertThat(groupBucket.type().toString(), is("ALL"));
assertThat(groupBucket.treatment().allInstructions().size(), is(1));
Instruction instruction1 = groupBucket.treatment().allInstructions().get(0);
assertThat(instruction1.type(), is(Instruction.Type.OUTPUT));
assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.portNumber(2)));
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStore method getUpdatedBucketList.
private List<GroupBucket> getUpdatedBucketList(Group oldGroup, UpdateType type, GroupBuckets buckets) {
if (type == UpdateType.SET) {
return buckets.buckets();
}
List<GroupBucket> oldBuckets = oldGroup.buckets().buckets();
List<GroupBucket> updatedBucketList = new ArrayList<>();
boolean groupDescUpdated = false;
if (type == UpdateType.ADD) {
List<GroupBucket> newBuckets = buckets.buckets();
// Add old buckets that will not be updated and check if any will be updated.
for (GroupBucket oldBucket : oldBuckets) {
int newBucketIndex = newBuckets.indexOf(oldBucket);
if (newBucketIndex != -1) {
GroupBucket newBucket = newBuckets.get(newBucketIndex);
if (!newBucket.hasSameParameters(oldBucket)) {
// Bucket will be updated
groupDescUpdated = true;
}
} else {
// Old bucket will remain the same - add it.
updatedBucketList.add(oldBucket);
}
}
// Add all new buckets
updatedBucketList.addAll(newBuckets);
if (!oldBuckets.containsAll(newBuckets)) {
groupDescUpdated = true;
}
} else if (type == UpdateType.REMOVE) {
List<GroupBucket> bucketsToRemove = buckets.buckets();
// Check which old buckets should remain
for (GroupBucket oldBucket : oldBuckets) {
if (!bucketsToRemove.contains(oldBucket)) {
updatedBucketList.add(oldBucket);
} else {
groupDescUpdated = true;
}
}
}
if (groupDescUpdated) {
return updatedBucketList;
} else {
return null;
}
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testGroupOperationFailure.
@Test
public void testGroupOperationFailure() {
simpleGroupStore.deviceInitialAuditCompleted(D1, true);
ApplicationId appId = new DefaultApplicationId(2, "org.groupstore.test");
GroupKey key = new DefaultGroupKey("group1".getBytes());
PortNumber[] ports = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
List<PortNumber> outPorts = new ArrayList<>();
outPorts.add(ports[0]);
outPorts.add(ports[1]);
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);
GroupDescription groupDesc = new DefaultGroupDescription(D1, Group.Type.SELECT, groupBuckets, key, null, appId);
InternalGroupStoreDelegate checkStoreGroupDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_REQUESTED);
simpleGroupStore.setDelegate(checkStoreGroupDelegate);
// Testing storeGroup operation
simpleGroupStore.storeGroupDescription(groupDesc);
simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
// Testing Group add operation failure
Group createdGroup = simpleGroupStore.getGroup(D1, key);
checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
GroupOperation groupAddOp = GroupOperation.createAddGroupOperation(createdGroup.id(), createdGroup.type(), createdGroup.buckets());
InternalGroupStoreDelegate checkGroupAddFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_FAILED);
simpleGroupStore.setDelegate(checkGroupAddFailureDelegate);
simpleGroupStore.groupOperationFailed(D1, groupAddOp);
// Testing Group modify operation failure
simpleGroupStore.unsetDelegate(checkGroupAddFailureDelegate);
GroupOperation groupModOp = GroupOperation.createModifyGroupOperation(createdGroup.id(), createdGroup.type(), createdGroup.buckets());
InternalGroupStoreDelegate checkGroupModFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_UPDATE_FAILED);
simpleGroupStore.setDelegate(checkGroupModFailureDelegate);
simpleGroupStore.groupOperationFailed(D1, groupModOp);
// Testing Group modify operation failure
simpleGroupStore.unsetDelegate(checkGroupModFailureDelegate);
GroupOperation groupDelOp = GroupOperation.createDeleteGroupOperation(createdGroup.id(), createdGroup.type());
InternalGroupStoreDelegate checkGroupDelFailureDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_REMOVE_FAILED);
simpleGroupStore.setDelegate(checkGroupDelFailureDelegate);
simpleGroupStore.groupOperationFailed(D1, groupDelOp);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testSetBuckets.
// Testing updateGroupDescription for SET operation from northbound
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);
}
Aggregations