use of org.onosproject.core.GroupId 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.core.GroupId 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.core.GroupId in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method storeGroupDescriptionInternal.
private void storeGroupDescriptionInternal(NetworkId networkId, GroupDescription groupDesc) {
// Check if a group is existing with the same key
if (getGroup(networkId, groupDesc.deviceId(), groupDesc.appCookie()) != null) {
return;
}
GroupId id = null;
if (groupDesc.givenGroupId() == null) {
// Get a new group identifier
id = new GroupId(getFreeGroupIdValue(networkId, groupDesc.deviceId()));
} else {
id = new GroupId(groupDesc.givenGroupId());
}
// Create a group entry object
StoredGroupEntry group = new DefaultGroup(id, groupDesc);
// Insert the newly created group entry into concurrent key and id maps
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, groupDesc.deviceId());
keyTable.put(groupDesc.appCookie(), group);
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, groupDesc.deviceId());
idTable.put(id, group);
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
use of org.onosproject.core.GroupId in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method removeGroupEntry.
@Override
public void removeGroupEntry(NetworkId networkId, Group group) {
StoredGroupEntry existing = null;
if (groupEntriesById.get(networkId) != null && groupEntriesById.get(networkId).get(group.deviceId()) != null) {
existing = groupEntriesById.get(networkId).get(group.deviceId()).get(group.id());
}
if (existing != null) {
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, existing.deviceId());
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, existing.deviceId());
idTable.remove(existing.id());
keyTable.remove(existing.appCookie());
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVED, existing));
}
}
use of org.onosproject.core.GroupId in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method groupOperationFailed.
@Override
public void groupOperationFailed(NetworkId networkId, DeviceId deviceId, GroupOperation operation) {
StoredGroupEntry existing = null;
if (groupEntriesById.get(networkId) != null && groupEntriesById.get(networkId).get(deviceId) != null) {
existing = groupEntriesById.get(networkId).get(deviceId).get(operation.groupId());
}
if (existing == null) {
log.warn("No group entry with ID {} found ", operation.groupId());
return;
}
switch(operation.opType()) {
case ADD:
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_ADD_FAILED, existing));
break;
case MODIFY:
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_UPDATE_FAILED, existing));
break;
case DELETE:
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVE_FAILED, existing));
break;
default:
log.warn("Unknown group operation type {}", operation.opType());
}
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, existing.deviceId());
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, existing.deviceId());
idTable.remove(existing.id());
keyTable.remove(existing.appCookie());
}
Aggregations