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 OFAgentVirtualGroupBucketEntryBuilder 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 SelectGroupHandler method generateBucketsForSelectGroup.
private List<GroupBucket> generateBucketsForSelectGroup(DeviceId deviceId, List<GatewayNode> nodeList) {
List<GroupBucket> bucketList = Lists.newArrayList();
nodeList.forEach(node -> {
TrafficTreatment tBuilder = DefaultTrafficTreatment.builder().extension(buildNiciraExtenstion(deviceId, node.getDataIpAddress()), deviceId).setOutput(getTunnelPort(deviceId)).build();
bucketList.add(createSelectGroupBucket(tBuilder));
});
return bucketList;
}
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);
}
}
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);
}
Aggregations