use of org.onosproject.net.driver.DriverService 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.driver.DriverService in project onos by opennetworkinglab.
the class DeviceInterfaceAddCommand method doExecute.
@Override
protected void doExecute() {
DriverService service = get(DriverService.class);
DeviceId deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
if (accessVlanString != null && trunkVlanStrings == null && limitString == null) {
// Access mode to be enabled for VLAN.
addAccessModeToIntf(interfaceConfig);
} else if (trunkVlanStrings != null && accessVlanString == null && limitString == null) {
// Trunk mode to be enabled for VLANs.
addTrunkModeToIntf(interfaceConfig);
} else if (limitString != null && accessVlanString == null && trunkVlanStrings == null) {
// Rate limit to be set on interface.
addRateLimitToIntf(interfaceConfig);
} else {
// Option has not been correctly set.
print(ONE_ACTION_ALLOWED);
}
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class DeviceInterfaceRemoveCommand method doExecute.
@Override
protected void doExecute() {
DriverService service = get(DriverService.class);
DeviceId deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
if (trunkMode && !accessMode && !rateLimit) {
// Trunk mode for VLAN to be removed.
removeTrunkModeFromIntf(interfaceConfig);
} else if (accessMode && !trunkMode && !rateLimit) {
// Access mode for VLAN to be removed.
removeAccessModeFromIntf(interfaceConfig);
} else if (rateLimit && !trunkMode && !accessMode) {
// Rate limit to be removed.
removeRateLimitFromIntf(interfaceConfig);
} else {
// Option has not been correctly set.
print(ONE_ACTION_ALLOWED);
}
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class DeviceSetControllersCommand method doExecute.
@Override
protected void doExecute() {
if (controllersListStrings == null && !removeCont && !removeAll) {
print("No controller are given, skipping.");
return;
}
if (controllersListStrings != null) {
Arrays.asList(controllersListStrings).forEach(cInfoString -> {
ControllerInfo controllerInfo = parseCInfoString(cInfoString);
if (controllerInfo != null) {
controllers.add(controllerInfo);
}
});
}
DriverService service = get(DriverService.class);
deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
ControllerConfig config = h.behaviour(ControllerConfig.class);
print("before:");
config.getControllers().forEach(c -> print(c.target()));
try {
if (removeAll) {
if (!controllers.isEmpty()) {
print("Controllers list should be empty to remove all controllers");
} else {
List<ControllerInfo> controllersToRemove = config.getControllers();
controllersToRemove.forEach(c -> print("Will remove " + c.target()));
config.removeControllers(controllersToRemove);
}
} else {
if (controllers.isEmpty()) {
print("Controllers list is empty, cannot set/remove empty controllers");
} else {
if (removeCont) {
print("Will remove specified controllers");
config.removeControllers(controllers);
} else {
print("Will add specified controllers");
config.setControllers(controllers);
}
}
}
} catch (NullPointerException e) {
print("No Device with requested parameters {} ", uri);
}
print("after:");
config.getControllers().forEach(c -> print(c.target()));
print("size %d", config.getControllers().size());
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class DriverNameCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
// Fetch our service and feed it's offerings to the string completer
DriverService service = AbstractShellCommand.get(DriverService.class);
service.getDrivers().forEach(d -> strings.add(d.name()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
Aggregations