use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class K8sGroupRuleManager method setRule.
@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId, Type type, List<GroupBucket> buckets, boolean install) {
if (install) {
GroupDescription groupDesc = new DefaultGroupDescription(deviceId, type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
groupService.addGroup(groupDesc);
} else {
groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
}
}
use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testPushGroupMetrics.
/**
* Tests pushing group metrics.
*/
@Test
public void testPushGroupMetrics() {
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
GroupDescription groupDescription3 = new DefaultGroupDescription(deviceId1, ALL, allGroupBuckets, new DefaultGroupKey("aaa".getBytes()), null, APP_ID);
groupStore.storeGroupDescription(groupDescription1);
groupStore.storeGroupDescription(groupDescription2);
groupStore.storeGroupDescription(groupDescription3);
Group group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1, instanceOf(DefaultGroup.class));
DefaultGroup defaultGroup1 = (DefaultGroup) group1;
defaultGroup1.setPackets(55L);
defaultGroup1.setBytes(66L);
groupStore.pushGroupMetrics(deviceId1, ImmutableList.of(group1));
// Make sure the group was updated.
Group requeryGroup1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(requeryGroup1.packets(), is(55L));
assertThat(requeryGroup1.bytes(), is(66L));
}
use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class OpenstackVtapManager method createGroupTable.
private void createGroupTable(DeviceId deviceId, int groupId, List<Integer> tableIds, List<PortNumber> ports) {
List<GroupBucket> buckets = Lists.newArrayList();
if (tableIds != null) {
tableIds.forEach(tableId -> {
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().extension(buildResubmitExtension(deviceId, tableId), deviceId);
GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment.build());
buckets.add(bucket);
});
}
if (ports != null) {
ports.forEach(port -> {
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setOutput(port);
GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment.build());
buckets.add(bucket);
});
}
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
groupService.addGroup(groupDescription);
}
use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class SpringOpenTTP method addGroup.
private void addGroup(NextObjective nextObjective) {
log.debug("addGroup with type{} for nextObjective id {}", nextObjective.type(), nextObjective.id());
List<GroupBucket> buckets;
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() == 1) {
// Spring Open TTP converts simple nextObjective to flow-actions
// in a dummy group
TrafficTreatment treatment = nextObjective.next().iterator().next();
log.debug("Converting SIMPLE group for next objective id {} " + "to {} flow-actions in device:{}", nextObjective.id(), treatment.allInstructions().size(), deviceId);
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
}
break;
case HASHED:
// we convert MPLS ECMP groups to flow-actions for a single
// bucket(output port).
boolean mplsEcmp = false;
if (nextObjective.meta() != null) {
for (Criterion c : nextObjective.meta().criteria()) {
if (c.type() == Type.MPLS_LABEL) {
mplsEcmp = true;
}
}
}
if (mplsEcmp) {
// covert to flow-actions in a dummy group by choosing the first bucket
log.debug("Converting HASHED group for next objective id {} " + "to flow-actions in device:{}", nextObjective.id(), deviceId);
TrafficTreatment treatment = nextObjective.next().iterator().next();
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
} else {
// process as ECMP group
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating HASHED group for next objective id {}" + " in dev:{}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
}
break;
case BROADCAST:
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating BROADCAST group for next objective id {} " + "in device {}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
break;
case FAILOVER:
log.debug("FAILOVER next objectives not supported");
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());
}
}
use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class CentecV350Pipeline method next.
@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();
// Since we do not support strip_vlan in PORT_VLAN table, we use mod_vlan
// to modify the packet to desired vlan.
// Note: if we use push_vlan here, the switch will add a second VLAN tag to the outgoing
// packet, which is not what we want.
TrafficTreatment.Builder treatmentWithoutPushVlan = DefaultTrafficTreatment.builder();
VlanId modVlanId;
for (Instruction ins : treatment.allInstructions()) {
if (ins.type() == Instruction.Type.L2MODIFICATION) {
L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
switch(l2ins.subtype()) {
case ETH_DST:
treatmentWithoutPushVlan.setEthDst(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case ETH_SRC:
treatmentWithoutPushVlan.setEthSrc(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case VLAN_ID:
modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
treatmentWithoutPushVlan.setVlanId(modVlanId);
break;
default:
break;
}
} else if (ins.type() == Instruction.Type.OUTPUT) {
// long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
treatmentWithoutPushVlan.add(ins);
} else {
// Ignore the vlan_pcp action since it's does matter much.
log.warn("Driver does not handle this type of TrafficTreatment" + " instruction in nextObjectives: {}", ins.type());
}
}
GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(treatmentWithoutPushVlan.build());
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(bucket)), key, // let group service determine group id
null, nextObjective.appId());
groupService.addGroup(groupDescription);
pendingGroups.put(key, 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());
}
}
Aggregations