use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class DistributedGroupStore 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 K8sServiceHandler method setStatefulGroupFlowRules.
private void setStatefulGroupFlowRules(DeviceId deviceId, long ctState, long ctMask, Service service, boolean install) {
List<GroupBucket> buckets = Lists.newArrayList();
String serviceName = service.getMetadata().getName();
String serviceIp = service.getSpec().getClusterIP();
// TODO: multi-ports case should be addressed
Integer servicePort = service.getSpec().getPorts().get(0).getPort();
String serviceProtocol = service.getSpec().getPorts().get(0).getProtocol();
String svcStr = servicePortStr(serviceIp, servicePort, serviceProtocol);
int groupId = svcStr.hashCode();
List<Endpoints> endpointses = k8sEndpointsService.endpointses().stream().filter(ep -> serviceName.equals(ep.getMetadata().getName())).collect(Collectors.toList());
Map<String, String> nodeIpGatewayIpMap = nodeIpGatewayIpMap(k8sNodeService, k8sNetworkService);
for (Endpoints endpoints : endpointses) {
for (EndpointSubset endpointSubset : endpoints.getSubsets()) {
List<EndpointPort> ports = endpointSubset.getPorts().stream().filter(p -> p.getProtocol().equals(TCP)).collect(Collectors.toList());
for (EndpointAddress address : endpointSubset.getAddresses()) {
String podIp = nodeIpGatewayIpMap.containsKey(address.getIp()) ? nodeIpGatewayIpMap.get(address.getIp()) : address.getIp();
NiciraConnTrackTreatmentBuilder connTreatmentBuilder = niciraConnTrackTreatmentBuilder(driverService, deviceId).commit(true).natAction(true).natIp(IpAddress.valueOf(podIp)).natFlag(CT_NAT_DST_FLAG);
ports.forEach(p -> {
ExtensionTreatment ctNatTreatment = connTreatmentBuilder.natPortMin(TpPort.tpPort(p.getPort())).natPortMax(TpPort.tpPort(p.getPort())).build();
ExtensionTreatment resubmitTreatment = buildResubmitExtension(deviceService.getDevice(deviceId), ACL_TABLE);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().extension(ctNatTreatment, deviceId).extension(resubmitTreatment, deviceId).build();
buckets.add(buildGroupBucket(treatment, SELECT, (short) -1));
});
}
}
}
if (!buckets.isEmpty()) {
k8sGroupRuleService.setRule(appId, deviceId, groupId, SELECT, buckets, install);
setTrackNew(deviceId, ctState, ctMask, IpAddress.valueOf(serviceIp), TpPort.tpPort(servicePort), NAT_TABLE, groupId, PRIORITY_CT_RULE, install);
}
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testUpdateGroupDescription.
/**
* Tests updating of group descriptions.
*/
@Test
public void testUpdateGroupDescription() {
GroupBuckets buckets = new GroupBuckets(ImmutableList.of(allGroupBucket2));
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
GroupKey newKey = new DefaultGroupKey("123".getBytes());
groupStore.updateGroupDescription(deviceId1, groupKey1, ADD, buckets, newKey);
Group group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(2));
buckets = new GroupBuckets(ImmutableList.of(allGroupBucket, allGroupBucket2));
groupStore.updateGroupDescription(deviceId1, newKey, ADD, buckets, newKey);
group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(2));
for (GroupBucket bucket : group1.buckets().buckets()) {
assertTrue(bucket.treatment().equals(treatment) || bucket.treatment().equals(treatment2));
}
buckets = new GroupBuckets(ImmutableList.of(allGroupBucket2));
groupStore.updateGroupDescription(deviceId1, newKey, SET, buckets, newKey);
group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(1));
GroupBucket onlyBucket = group1.buckets().buckets().iterator().next();
assertEquals(treatment2, onlyBucket.treatment());
}
use of org.onosproject.net.group.GroupBucket 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.GroupBucket in project onos by opennetworkinglab.
the class SelectGroupHandler method updateGatewayGroupBuckets.
/**
* Updates groupBuckets in select type group.
*
* @param deviceId target device id to update the group
* @param nodeList updated gateway node list for bucket action
* @param isInsert update type(add or remove)
*/
public void updateGatewayGroupBuckets(DeviceId deviceId, List<GatewayNode> nodeList, boolean isInsert) {
List<GroupBucket> bucketList = generateBucketsForSelectGroup(deviceId, nodeList);
GroupKey groupKey = getGroupKey(deviceId);
if (isInsert) {
groupService.addBucketsToGroup(deviceId, groupKey, new GroupBuckets(bucketList), groupKey, appId);
} else {
groupService.removeBucketsFromGroup(deviceId, groupKey, new GroupBuckets(bucketList), groupKey, appId);
}
}
Aggregations