use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class VirtualNetworkGroupManagerTest method testAddBuckets.
// Test group add bucket operations
private void testAddBuckets(NetworkId networkId, DeviceId deviceId) {
VirtualNetworkGroupManager groupManager;
VirtualGroupProviderService providerService;
TestGroupListener listener;
if (networkId.id() == 1) {
groupManager = groupManager1;
providerService = providerService1;
listener = listener1;
} else {
groupManager = groupManager2;
providerService = providerService2;
listener = listener2;
}
GroupKey addKey = new DefaultGroupKey("group1AddBuckets".getBytes());
GroupKey prevKey = new DefaultGroupKey("group1BeforeAudit".getBytes());
Group createdGroup = groupManager.getGroup(deviceId, prevKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(createdGroup.buckets().buckets());
PortNumber[] addPorts = { PortNumber.portNumber(51), PortNumber.portNumber(52) };
List<PortNumber> outPorts;
outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(addPorts));
List<GroupBucket> addBuckets;
addBuckets = 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));
addBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupAddBuckets = new GroupBuckets(addBuckets);
groupManager.addBucketsToGroup(deviceId, prevKey, groupAddBuckets, addKey, appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Collections.singletonList(GroupOperation.createModifyGroupOperation(createdGroup.id(), Group.Type.SELECT, updatedBuckets));
if (deviceId.equals(VDID1)) {
provider.validate(networkId, deviceId, expectedGroupOps);
}
Group existingGroup = groupManager.getGroup(deviceId, addKey);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(deviceId, groupEntries);
listener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class VirtualNetworkGroupManagerTest method testRemoveBuckets.
// Test group remove bucket operations
private void testRemoveBuckets(NetworkId networkId, DeviceId deviceId) {
VirtualNetworkGroupManager groupManager;
VirtualGroupProviderService providerService;
TestGroupListener listener;
if (networkId.id() == 1) {
groupManager = groupManager1;
providerService = providerService1;
listener = listener1;
} else {
groupManager = groupManager2;
providerService = providerService2;
listener = listener2;
}
GroupKey removeKey = new DefaultGroupKey("group1RemoveBuckets".getBytes());
GroupKey prevKey = new DefaultGroupKey("group1AddBuckets".getBytes());
Group createdGroup = groupManager.getGroup(deviceId, prevKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(createdGroup.buckets().buckets());
PortNumber[] removePorts = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
List<PortNumber> outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(removePorts));
List<GroupBucket> removeBuckets = 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));
removeBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
buckets.remove(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupRemoveBuckets = new GroupBuckets(removeBuckets);
groupManager.removeBucketsFromGroup(deviceId, prevKey, groupRemoveBuckets, removeKey, appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Collections.singletonList(GroupOperation.createModifyGroupOperation(createdGroup.id(), Group.Type.SELECT, updatedBuckets));
if (deviceId.equals(VDID1)) {
provider.validate(networkId, deviceId, expectedGroupOps);
}
Group existingGroup = groupManager.getGroup(deviceId, removeKey);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(deviceId, groupEntries);
listener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method pushGroupMetrics.
@Override
public void pushGroupMetrics(NetworkId networkId, DeviceId deviceId, Collection<Group> groupEntries) {
boolean deviceInitialAuditStatus = deviceInitialAuditStatus(networkId, deviceId);
Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries);
Set<Group> storedGroupEntries = Sets.newHashSet(getGroups(networkId, deviceId));
Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(networkId, deviceId));
if (log.isTraceEnabled()) {
log.trace("pushGroupMetrics: Displaying all ({}) " + "southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId);
for (Group group : southboundGroupEntries) {
log.trace("Group {} in device {}", group, deviceId);
}
log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId);
for (Group group : storedGroupEntries) {
log.trace("Stored Group {} for device {}", group, deviceId);
}
}
for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext(); ) {
Group group = it2.next();
if (storedGroupEntries.remove(group)) {
// we both have the group, let's update some info then.
log.trace("Group AUDIT: group {} exists " + "in both planes for device {}", group.id(), deviceId);
groupAdded(networkId, group);
it2.remove();
}
}
for (Group group : southboundGroupEntries) {
if (getGroup(networkId, group.deviceId(), group.id()) != null) {
// in progress while we got a stale info from switch
if (!storedGroupEntries.remove(getGroup(networkId, group.deviceId(), group.id()))) {
log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table");
}
} else {
// there are groups in the switch that aren't in the store
log.trace("Group AUDIT: extraneous group {} exists " + "in data plane for device {}", group.id(), deviceId);
extraneousStoredEntries.remove(group);
extraneousGroup(networkId, group);
}
}
for (Group group : storedGroupEntries) {
// there are groups in the store that aren't in the switch
log.trace("Group AUDIT: group {} missing " + "in data plane for device {}", group.id(), deviceId);
groupMissing(networkId, group);
}
for (Group group : extraneousStoredEntries) {
// there are groups in the extraneous store that
// aren't in the switch
log.trace("Group AUDIT: clearing extransoeus group {} " + "from store for device {}", group.id(), deviceId);
removeExtraneousGroupEntry(networkId, group);
}
if (!deviceInitialAuditStatus) {
log.debug("Group AUDIT: Setting device {} initial " + "AUDIT completed", deviceId);
deviceInitialAuditCompleted(networkId, deviceId, true);
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method deviceInitialAuditCompleted.
@Override
public void deviceInitialAuditCompleted(NetworkId networkId, DeviceId deviceId, boolean completed) {
deviceAuditStatus.computeIfAbsent(networkId, k -> new HashMap<>());
HashMap<DeviceId, Boolean> deviceAuditStatusByNetwork = deviceAuditStatus.get(networkId);
synchronized (deviceAuditStatusByNetwork) {
if (completed) {
log.debug("deviceInitialAuditCompleted: AUDIT " + "completed for device {}", deviceId);
deviceAuditStatusByNetwork.put(deviceId, true);
// Execute all pending group requests
ConcurrentMap<GroupKey, StoredGroupEntry> pendingGroupRequests = getPendingGroupKeyTable(networkId, deviceId);
for (Group group : pendingGroupRequests.values()) {
GroupDescription tmp = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.givenGroupId(), group.appId());
storeGroupDescriptionInternal(networkId, tmp);
}
getPendingGroupKeyTable(networkId, deviceId).clear();
} else {
if (deviceAuditStatusByNetwork.get(deviceId)) {
log.debug("deviceInitialAuditCompleted: Clearing AUDIT " + "status for device {}", deviceId);
deviceAuditStatusByNetwork.put(deviceId, false);
}
}
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class AbstractCorsaPipeline 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();
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());
}
}
Aggregations