use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class GroupJsonMatcher method matchesSafely.
@Override
public boolean matchesSafely(JsonNode jsonGroup, Description description) {
// check id
String jsonGroupId = jsonGroup.get("id").asText();
String groupId = group.id().id().toString();
if (!jsonGroupId.equals(groupId)) {
description.appendText("group id was " + jsonGroupId);
return false;
}
// check state
String jsonState = jsonGroup.get("state").asText();
String state = group.state().toString();
if (!jsonState.equals(state)) {
description.appendText("state was " + jsonState);
return false;
}
// check life
long jsonLife = jsonGroup.get("life").asLong();
long life = group.life();
if (life != jsonLife) {
description.appendText("life was " + jsonLife);
return false;
}
// check bytes
long jsonBytes = jsonGroup.get("bytes").asLong();
long bytes = group.bytes();
if (bytes != jsonBytes) {
description.appendText("bytes was " + jsonBytes);
return false;
}
// check packets
long jsonPackets = jsonGroup.get("packets").asLong();
long packets = group.packets();
if (packets != jsonPackets) {
description.appendText("packets was " + jsonPackets);
return false;
}
// check size of bucket array
JsonNode jsonBuckets = jsonGroup.get("buckets");
if (jsonBuckets.size() != group.buckets().buckets().size()) {
description.appendText("buckets size was " + jsonBuckets.size());
return false;
}
// Check buckets
for (GroupBucket bucket : group.buckets().buckets()) {
boolean bucketFound = false;
for (int bucketIndex = 0; bucketIndex < jsonBuckets.size(); bucketIndex++) {
GroupBucketJsonMatcher bucketMatcher = GroupBucketJsonMatcher.matchesGroupBucket(bucket);
if (bucketMatcher.matches(jsonBuckets.get(bucketIndex))) {
bucketFound = true;
break;
}
}
if (!bucketFound) {
description.appendText("bucket not found " + bucket.toString());
return false;
}
}
return true;
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class FabricPipeliner method getBucketToFlowMapping.
private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
NextObjective newNextObjective;
ObjectiveTranslation result;
FlowRule dummyFlow = getDummyFlow(nextObjective);
FlowRule egFlow;
GroupBucket groupBucket;
GroupDescription group;
for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
result = nextTranslator.translate(newNextObjective);
if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
return Collections.emptyMap();
}
group = result.groups().iterator().next();
egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
return Collections.emptyMap();
}
groupBucket = group.buckets().buckets().iterator().next();
if (egFlow == null) {
mapping.put(groupBucket, dummyFlow);
} else {
mapping.put(groupBucket, egFlow);
}
}
return mapping;
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class GroupBucketEntryBuilder method build.
/**
* 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);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class OpenFlowGroupProvider method checkFailoverGroup.
/**
* Checks whether the first live port in the failover group's bucket
* has failed over.
*
* @param group failover group to be checked for failover
* @param id device ID of switch whose port's status changed
* @param portNumber port number of port that was disabled
* @return whether the failover group experienced failover
*/
private boolean checkFailoverGroup(Group group, DeviceId id, PortNumber portNumber) {
boolean portReached = false;
boolean portEnabled = false;
Iterator<GroupBucket> bIterator = group.buckets().buckets().iterator();
GroupBucket bucket;
while (bIterator.hasNext() && !portReached) {
bucket = bIterator.next();
if (deviceService.getPort(id, bucket.watchPort()).isEnabled()) {
portEnabled = true;
}
if (bucket.watchPort().equals(portNumber)) {
portReached = true;
}
}
return portReached && !portEnabled;
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class OpenFlowGroupProviderTest method addGroup.
@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);
}
Aggregations