# TeraFlowSDN Automation service
This repository hosts the TeraFlowSDN Automation service, also known as Zero-Touch Provisioning (ZTP) service.
Follow the instructions below to build, test, and run this service on your local environment.
## TeraFlowSDN Automation service architecture
The TeraFlowSDN Automation architecture consists of six (6) interfaces listed below:
Interfaces |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1. The `AutomationGateway` interface that implements all the RPC functions that are described in `automation.proto` file. |
| 2. The `ContextGateway` interface that communicates with a `Context` Service gRPC client to invoke key RPC functions described in `context.proto` file. |
| 3. The `DeviceGateway` interface that communicates with a `Device` Service gRPC client to invoke key RPC functions described in `device.proto` file. |
| 4. The `AutomationService` interface that implements the `addDevice()`, `updateDevice()`, and `deleteDevice()` methods by communicating with a `Context` gRPC client and a `Device` gRPC client through the use of `ContextService` interface and `DeviceService` interface respectively. |
| 5. The `ContextService` interface that implements the `getDevice()` and `getDeviceEvents()` methods by communicating with a `Context` gRPC client through the use of `ContextGateway` interface. |
| 6. The `DeviceService` interface that implements the `getInitialConfiguration()`, `configureDevice()`, and `deleteDevice()` methods by communicating with a `Device` gRPC client through the use of `DeviceGateway` interface. |
## Prerequisites
The Automation service is currently tested against Ubuntu 20.04 and Java 11.
To quickly install Java 11 on a Debian-based Linux distro do:
```bash
sudo apt-get install openjdk-11-jdk -y
```
Feel free to try more recent Java versions.
## Compile
```bash
./mvnw compile
```
## Run tests
```bash
./mvnw test
```
## Run service
```bash
./mvnw quarkus:dev
````
## Clean
```bash
./mvnw clean
```
## Deploying on a Kubernetes cluster
To create the K8s manifest file under `target/kubernetes/kubernetes.yml` to be used run
```bash
./mvnw clean package -DskipUTs -DskipITs
```
To deploy the application in a K8s cluster run
```bash
kubectl apply -f "manifests/automationservice.yaml"
```
## Maintainers
This TeraFlowSDN service is implemented by [UBITECH](https://www.ubitech.eu).
Feel free to contact Georgios Katsikas (gkatsikas at ubitech dot eu) in case you have questions.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.teraflow</groupId>
<artifactId>automation</artifactId>
<version>0.2.0</version>
<name>TeraFlow Automation Component</name>
<description>TeraFlow Automation Component</description>
<properties>
<java.version>11</java.version>
<!-- https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#parameters -->
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.version>3.8.1</maven.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<assertj.version>3.20.2</assertj.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<jacoco.report.unit-test>jacoco-unit-tests.exec</jacoco.report.unit-test>
<jacoco.report.integration-test>jacoco-integration-tests.exec</jacoco.report.integration-test>
<jacoco.version>0.8.6</jacoco.version>
<!-- Maven plugins -->
<docker-maven-plugin.version>0.34.1</docker-maven-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
<maven-install-plugin.version>3.0.0-M1</maven-install-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<sonarsource-scanner-plugin.version>3.8.0.2131</sonarsource-scanner-plugin.version>
<spotless-plugin.version>2.10.3</spotless-plugin.version>
<versions-maven-plugin.version>2.8.1</versions-maven-plugin.version>
<quarkus-maven-plugin.version>${quarkus.platform.version}</quarkus-maven-plugin.version>
<!-- Third-party Dependencies -->
<quarkus.platform.version>2.2.2.Final</quarkus.platform.version>
</properties>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${env.CI_SERVER_URL}/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${env.CI_SERVER_URL}/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<!-- Property resolution occurs only after parent POM has been resolved. Source: https://stackoverflow.com/a/59813598 -->
<repositories>
<!-- Explicitly define Maven central (first), so that CI job tries to fetch from it first. -->
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>quarkus-bouncycastle</artifactId>
<version>1.2.2.Final</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-service-binding</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
<version>${jacoco.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-metrics</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<arg>-Xlint:deprecation</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/${jacoco.report.integration-test}</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skipTests>${skipUTs}</skipTests>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/${jacoco.report.unit-test}</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonarsource-scanner-plugin.version}</version>
</plugin>
<!-- https://quarkus.io/guides/maven-tooling#logging-quarkus-application-build-classpath-tree -->
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>${quarkus-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-maven-plugin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>automation/*</exclude>
<exclude>context/*</exclude>
<exclude>device/*</exclude>
<exclude>monitoring/*</exclude>
<exclude>kpi_sample_types/*</exclude>
<exclude>acl/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>instrument-unit-tests</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-unit-tests</id>
<phase>test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report-unit-tests</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/${jacoco.report.unit-test}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-tests</outputDirectory>
</configuration>
</execution>
<execution>
<id>instrument-integration-tests</id>
<phase>pre-integration-test</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-integration-tests</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report-integration-tests</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/${jacoco.report.integration-test}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-tests</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>analyze-dependencies</id>
<goals>
<goal>analyze-only</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<configuration>
<rules>
<requireJavaVersion>
<version>${java.version}</version>
</requireJavaVersion>
<requireMavenVersion>
<version>${maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-plugin.version}</version>
<configuration>
<java>
<!--
Allow toggling spotless, as per:
https://github.com/diffplug/spotless/tree/main/plugin-maven#spotlessoff-and-spotlesson
-->
<toggleOffOn>
<off>fmt:off</off>
<on>fmt:on</on>
</toggleOffOn>
<googleJavaFormat>
<version>1.10.0</version>
<style>GOOGLE</style>
</googleJavaFormat>
<!-- Custom configuration -->
<indent>
<tabs>true</tabs>
<spacesPerTab>2</spacesPerTab>
</indent>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</java>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>generate-consolidated-coverage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<!--
Build consolidated coverage report as per
https://quarkus.io/version/1.11/guides/tests-with-coverage#instrumenting-the-classes-instead
-->
<execution>
<id>merge-results</id>
<phase>verify</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-merge-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import io.smallrye.config.ConfigMapping;
@ConfigMapping(prefix = "automation")
public interface AutomationConfiguration {
boolean shouldSubscribeToContextComponent();
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import automation.AutomationService;
public interface AutomationGateway extends AutomationService {}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import automation.Automation;
import automation.Automation.DeviceRoleConfig;
import automation.Automation.DeviceRoleState;
import context.ContextOuterClass;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.model.DeviceRoleId;
import eu.teraflow.automation.model.DeviceState;
import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Uni;
import javax.inject.Inject;
import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Timed;
@GrpcService
public class AutomationGatewayImpl implements AutomationGateway {
private final AutomationService automationService;
private final Serializer serializer;
@Inject
public AutomationGatewayImpl(AutomationService automationService, Serializer serializer) {
this.automationService = automationService;
this.serializer = serializer;
}
@Override
@Counted(name = "automation_ztpGetDeviceRole_counter")
@Timed(name = "automation_ztpGetDeviceRole_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<Automation.DeviceRole> ztpGetDeviceRole(Automation.DeviceRoleId request) {
return Uni.createFrom()
.item(() -> Automation.DeviceRole.newBuilder().setDevRoleId(request).build());
}
@Override
@Counted(name = "automation_ztpGetDeviceRolesByDeviceId_counter")
@Timed(name = "automation_ztpGetDeviceRolesByDeviceId_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<Automation.DeviceRoleList> ztpGetDeviceRolesByDeviceId(
ContextOuterClass.DeviceId request) {
return Uni.createFrom().item(() -> Automation.DeviceRoleList.newBuilder().build());
}
@Override
@Counted(name = "automation_ztpAdd_counter")
@Timed(name = "automation_ztpAdd_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<Automation.DeviceRoleState> ztpAdd(Automation.DeviceRole request) {
final var devRoleId = request.getDevRoleId().getDevRoleId().getUuid();
final var deviceId = serializer.deserialize(request.getDevRoleId().getDevId());
return automationService
.addDevice(deviceId)
.onItem()
.transform(device -> transformToDeviceRoleState(device, devRoleId, DeviceState.CREATED));
}
@Override
@Counted(name = "automation_ztpUpdate_counter")
@Timed(name = "automation_ztpUpdate_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<DeviceRoleState> ztpUpdate(DeviceRoleConfig request) {
final var devRoleId = request.getDevRole().getDevRoleId().getDevRoleId().getUuid();
final var deviceId = serializer.deserialize(request.getDevRole().getDevRoleId().getDevId());
final var deviceConfig = serializer.deserialize(request.getDevConfig());
return automationService
.updateDevice(deviceId, deviceConfig)
.onItem()
.transform(device -> transformToDeviceRoleState(device, devRoleId, DeviceState.UPDATED));
}
@Override
@Counted(name = "automation_ztpDelete_counter")
@Timed(name = "automation_ztpDelete_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<Automation.DeviceRoleState> ztpDelete(Automation.DeviceRole request) {
final var devRoleId = request.getDevRoleId().getDevRoleId().getUuid();
return automationService
.deleteDevice(devRoleId)
.onItem()
.transform(device -> transformToDeviceRoleState(device, devRoleId, DeviceState.DELETED));
}
@Override
@Counted(name = "automation_ztpDeleteAll_counter")
@Timed(name = "automation_ztpDeleteAll_histogram", unit = MetricUnits.MILLISECONDS)
public Uni<Automation.DeviceDeletionResult> ztpDeleteAll(ContextOuterClass.Empty empty) {
return Uni.createFrom().item(() -> Automation.DeviceDeletionResult.newBuilder().build());
}
private Automation.DeviceRoleState transformToDeviceRoleState(
Device device, String devRoleId, DeviceState deviceState) {
final var deviceRoleId = new DeviceRoleId(devRoleId, device.getDeviceId());
final var serializeDeviceRoleId = serializer.serialize(deviceRoleId);
final var serializedDeviceState = serializer.serialize(deviceState);
return Automation.DeviceRoleState.newBuilder()
.setDevRoleId(serializeDeviceRoleId)
.setDevRoleState(serializedDeviceState)
.build();
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceConfig;
import io.smallrye.mutiny.Uni;
public interface AutomationService {
Uni<Device> addDevice(String deviceId);
Uni<Device> deleteDevice(String deviceId);
Uni<Device> updateDevice(String deviceId, DeviceConfig deviceConfig);
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import eu.teraflow.automation.context.ContextService;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.device.DeviceService;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.jboss.logging.Logger;
@ApplicationScoped
public class AutomationServiceImpl implements AutomationService {
private static final Logger LOGGER = Logger.getLogger(AutomationServiceImpl.class);
// private static final String MESSAGE = "Retrieved %s";
private final DeviceService deviceService;
private final ContextService contextService;
@Inject
public AutomationServiceImpl(DeviceService deviceService, ContextService contextService) {
this.deviceService = deviceService;
this.contextService = contextService;
}
@Override
public Uni<Device> addDevice(String deviceId) {
final var deserializedDeviceUni = contextService.getDevice(deviceId);
deserializedDeviceUni
.onFailure()
.recoverWithNull()
.subscribe()
.with(
device -> {
final var id = deviceId;
if (device == null) {
LOGGER.warnf("%s is null. Ignoring...", device);
return;
}
if (device.isEnabled()) {
LOGGER.warnf("%s has already been enabled. Ignoring...", device);
return;
}
// LOGGER.infof(MESSAGE, device);
final var initialConfiguration =
deviceService.getInitialConfiguration(device.getDeviceId());
device.enableDevice();
LOGGER.infof("Enabled device [%s]", id);
initialConfiguration
.subscribe()
.with(
deviceConfig -> {
device.setDeviceConfiguration(deviceConfig);
final var configuredDeviceIdUni = deviceService.configureDevice(device);
configuredDeviceIdUni
.subscribe()
.with(
configuredDeviceId ->
LOGGER.infof(
"Device [%s] has been successfully enabled and configured with %s.\n",
id, deviceConfig));
});
});
return deserializedDeviceUni;
}
@Override
public Uni<Device> deleteDevice(String deviceId) {
final var deserializedDeviceUni = contextService.getDevice(deviceId);
deserializedDeviceUni
.onFailure()
.recoverWithNull()
.subscribe()
.with(
device -> {
final var id = deviceId;
if (device == null) {
LOGGER.warnf("%s is null. Ignoring...", device);
return;
}
if (device.isDisabled()) {
LOGGER.warnf("%s has already been disabled. Ignoring...", device);
return;
}
device.disableDevice();
LOGGER.infof("Disabled device [%s]", id);
// LOGGER.infof(MESSAGE, device);
final var empty = deviceService.deleteDevice(device.getDeviceId());
empty
.subscribe()
.with(
emptyMessage ->
LOGGER.infof("Device [%s] has been successfully deleted.\n", id));
});
return deserializedDeviceUni;
}
@Override
public Uni<Device> updateDevice(String deviceId, DeviceConfig deviceConfig) {
final var deserializedDeviceUni = contextService.getDevice(deviceId);
deserializedDeviceUni
.onFailure()
.recoverWithNull()
.subscribe()
.with(
device -> {
final var id = deviceId;
if (device == null) {
LOGGER.warnf("%s is null. Ignoring...", device);
return;
}
if (!device.isEnabled()) {
LOGGER.warnf("Cannot update disabled device %s. Ignoring...", device);
return;
}
// LOGGER.infof(MESSAGE, device);
device.setDeviceConfiguration(deviceConfig);
final var updatedDeviceIdUni = deviceService.configureDevice(device);
updatedDeviceIdUni
.subscribe()
.with(
configuredDeviceId ->
LOGGER.infof(
"Device [%s] has been successfully updated with %s.\n",
id, deviceConfig));
});
return deserializedDeviceUni;
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import acl.Acl;
import automation.Automation;
import automation.Automation.ZtpDeviceState;
import context.ContextOuterClass;
import context.ContextOuterClass.ConfigRule_ACL;
import context.ContextOuterClass.ConfigRule_Custom;
import context.ContextOuterClass.ContextId;
import context.ContextOuterClass.DeviceId;
import context.ContextOuterClass.DeviceOperationalStatusEnum;
import context.ContextOuterClass.Location.LocationCase;
import context.ContextOuterClass.Uuid;
import eu.teraflow.automation.acl.AclAction;
import eu.teraflow.automation.acl.AclEntry;
import eu.teraflow.automation.acl.AclForwardActionEnum;
import eu.teraflow.automation.acl.AclLogActionEnum;
import eu.teraflow.automation.acl.AclMatch;
import eu.teraflow.automation.acl.AclRuleSet;
import eu.teraflow.automation.acl.AclRuleTypeEnum;
import eu.teraflow.automation.context.model.ConfigActionEnum;
import eu.teraflow.automation.context.model.ConfigRule;
import eu.teraflow.automation.context.model.ConfigRuleAcl;
import eu.teraflow.automation.context.model.ConfigRuleCustom;
import eu.teraflow.automation.context.model.ConfigRuleTypeAcl;
import eu.teraflow.automation.context.model.ConfigRuleTypeCustom;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.context.model.DeviceDriverEnum;
import eu.teraflow.automation.context.model.DeviceEvent;
import eu.teraflow.automation.context.model.DeviceOperationalStatus;
import eu.teraflow.automation.context.model.Empty;
import eu.teraflow.automation.context.model.EndPoint;
import eu.teraflow.automation.context.model.EndPointId;
import eu.teraflow.automation.context.model.Event;
import eu.teraflow.automation.context.model.EventTypeEnum;
import eu.teraflow.automation.context.model.GpsPosition;
import eu.teraflow.automation.context.model.Location;
import eu.teraflow.automation.context.model.LocationTypeGpsPosition;
import eu.teraflow.automation.context.model.LocationTypeRegion;
import eu.teraflow.automation.context.model.TopologyId;
import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType;
import eu.teraflow.automation.model.DeviceRole;
import eu.teraflow.automation.model.DeviceRoleConfig;
import eu.teraflow.automation.model.DeviceRoleId;
import eu.teraflow.automation.model.DeviceRoleType;
import eu.teraflow.automation.model.DeviceState;
import java.util.stream.Collectors;
import javax.inject.Singleton;
import kpi_sample_types.KpiSampleTypes;
@Singleton
public class Serializer {
public DeviceId serializeDeviceId(String expectedDeviceId) {
final var builder = DeviceId.newBuilder();
final var uuid = serializeUuid(expectedDeviceId);
builder.setDeviceUuid(uuid);
return builder.build();
}
public String deserialize(DeviceId deviceId) {
return deviceId.getDeviceUuid().getUuid();
}
public Automation.DeviceRoleId serialize(DeviceRoleId deviceRoleId) {
final var builder = Automation.DeviceRoleId.newBuilder();
final var deviceRoleDevRoleId = deviceRoleId.getId();
final var deviceRoleDeviceId = deviceRoleId.getDeviceId();
final var deviceRoleDevRoleIdUuid = serializeUuid(deviceRoleDevRoleId);
final var deviceRoleDeviceIdUuid = serializeUuid(deviceRoleDeviceId);
final var deviceId = DeviceId.newBuilder().setDeviceUuid(deviceRoleDeviceIdUuid);
builder.setDevRoleId(deviceRoleDevRoleIdUuid);
builder.setDevId(deviceId);
return builder.build();
}
public DeviceRoleId deserialize(Automation.DeviceRoleId deviceRoleId) {
final var devRoleId = deserialize(deviceRoleId.getDevRoleId());
final var devId = deserialize(deviceRoleId.getDevId());
return new DeviceRoleId(devRoleId, devId);
}
public Automation.DeviceRoleType serialize(DeviceRoleType deviceRoleType) {
switch (deviceRoleType) {
case NONE:
return Automation.DeviceRoleType.NONE;
case DEV_OPS:
return Automation.DeviceRoleType.DEV_OPS;
case DEV_CONF:
return Automation.DeviceRoleType.DEV_CONF;
case PIPELINE_CONF:
return Automation.DeviceRoleType.PIPELINE_CONF;
default:
return Automation.DeviceRoleType.UNRECOGNIZED;
}
}
public DeviceRoleType deserialize(Automation.DeviceRoleType serializedDeviceRoleType) {
switch (serializedDeviceRoleType) {
case DEV_OPS:
return DeviceRoleType.DEV_OPS;
case DEV_CONF:
return DeviceRoleType.DEV_CONF;
case PIPELINE_CONF:
return DeviceRoleType.PIPELINE_CONF;
case NONE:
case UNRECOGNIZED:
default:
return DeviceRoleType.NONE;
}
}
public Automation.ZtpDeviceState serialize(DeviceState deviceState) {
switch (deviceState) {
case CREATED:
return ZtpDeviceState.ZTP_DEV_STATE_CREATED;
case UPDATED:
return ZtpDeviceState.ZTP_DEV_STATE_UPDATED;
case DELETED:
return ZtpDeviceState.ZTP_DEV_STATE_DELETED;
case UNDEFINED:
return ZtpDeviceState.ZTP_DEV_STATE_UNDEFINED;
default:
return ZtpDeviceState.UNRECOGNIZED;
}
}
public DeviceState deserialize(Automation.ZtpDeviceState serializedDeviceState) {
switch (serializedDeviceState) {
case ZTP_DEV_STATE_CREATED:
return DeviceState.CREATED;
case ZTP_DEV_STATE_UPDATED:
return DeviceState.UPDATED;
case ZTP_DEV_STATE_DELETED:
return DeviceState.DELETED;
case ZTP_DEV_STATE_UNDEFINED:
case UNRECOGNIZED:
default:
return DeviceState.UNDEFINED;
}
}
public Automation.DeviceRole serialize(DeviceRole deviceRole) {
final var builder = Automation.DeviceRole.newBuilder();
final var serializedDeviceRoleId = serialize(deviceRole.getDeviceRoleId());
final var serializedDeviceRoleType = serialize(deviceRole.getType());
builder.setDevRoleId(serializedDeviceRoleId);
builder.setDevRoleType(serializedDeviceRoleType);
return builder.build();
}
public DeviceRole deserialize(Automation.DeviceRole deviceRole) {
final var deviceRoleId = deserialize(deviceRole.getDevRoleId());
final var deviceRoleType = deserialize(deviceRole.getDevRoleType());
return new DeviceRole(deviceRoleId, deviceRoleType);
}
public Automation.DeviceRoleConfig serialize(DeviceRoleConfig deviceRoleConfig) {
final var builder = Automation.DeviceRoleConfig.newBuilder();
final var serializedDeviceRole = serialize(deviceRoleConfig.getDeviceRole());
final var serializedDeviceConfig = serialize(deviceRoleConfig.getDeviceConfig());
builder.setDevRole(serializedDeviceRole);
builder.setDevConfig(serializedDeviceConfig);
return builder.build();
}
public DeviceRoleConfig deserialize(Automation.DeviceRoleConfig deviceRoleConfig) {
final var deviceRole = deserialize(deviceRoleConfig.getDevRole());
final var deviceConfig = deserialize(deviceRoleConfig.getDevConfig());
return new DeviceRoleConfig(deviceRole, deviceConfig);
}
public ContextOuterClass.EventTypeEnum serialize(EventTypeEnum eventTypeEnum) {
switch (eventTypeEnum) {
case CREATE:
return ContextOuterClass.EventTypeEnum.EVENTTYPE_CREATE;
case REMOVE:
return ContextOuterClass.EventTypeEnum.EVENTTYPE_REMOVE;
case UPDATE:
return ContextOuterClass.EventTypeEnum.EVENTTYPE_UPDATE;
case UNDEFINED:
return ContextOuterClass.EventTypeEnum.EVENTTYPE_UNDEFINED;
default:
return ContextOuterClass.EventTypeEnum.UNRECOGNIZED;
}
}
public EventTypeEnum deserialize(ContextOuterClass.EventTypeEnum serializedEventType) {
switch (serializedEventType) {
case EVENTTYPE_CREATE:
return EventTypeEnum.CREATE;
case EVENTTYPE_REMOVE:
return EventTypeEnum.REMOVE;
case EVENTTYPE_UPDATE:
return EventTypeEnum.UPDATE;
case EVENTTYPE_UNDEFINED:
case UNRECOGNIZED:
default:
return EventTypeEnum.UNDEFINED;
}
}
public ContextOuterClass.Timestamp serialize(double timestamp) {
final var builder = ContextOuterClass.Timestamp.newBuilder();
builder.setTimestamp(timestamp);
return builder.build();
}
public double deserialize(ContextOuterClass.Timestamp serializedTimeStamp) {
return serializedTimeStamp.getTimestamp();
}
public ContextOuterClass.Event serialize(Event event) {
final var builder = ContextOuterClass.Event.newBuilder();
final var eventType = serialize(event.getEventTypeEnum());
final var timestamp = serialize(event.getTimestamp());
builder.setEventType(eventType);
builder.setTimestamp(timestamp);
return builder.build();
}
public Event deserialize(ContextOuterClass.Event serializedEvent) {
final var timestamp = deserialize(serializedEvent.getTimestamp());
final var eventType = deserialize(serializedEvent.getEventType());
return new Event(timestamp, eventType);
}
public ContextOuterClass.DeviceEvent serialize(DeviceEvent deviceEvent) {
final var builder = ContextOuterClass.DeviceEvent.newBuilder();
final var deviceIdUuid = serializeUuid(deviceEvent.getDeviceId());
final var deviceId = DeviceId.newBuilder().setDeviceUuid(deviceIdUuid);
builder.setDeviceId(deviceId);
builder.setEvent(serialize(deviceEvent.getEvent()));
builder.setDeviceConfig(serialize(deviceEvent.getDeviceConfig().orElse(null)));
return builder.build();
}
public DeviceEvent deserialize(ContextOuterClass.DeviceEvent deviceEvent) {
final var deviceId = deserialize(deviceEvent.getDeviceId());
final var event = deserialize(deviceEvent.getEvent());
final var deviceConfig = deserialize(deviceEvent.getDeviceConfig());
return new DeviceEvent(deviceId, event, deviceConfig);
}
public ContextOuterClass.ConfigActionEnum serialize(ConfigActionEnum configAction) {
switch (configAction) {
case SET:
return ContextOuterClass.ConfigActionEnum.CONFIGACTION_SET;
case DELETE:
return ContextOuterClass.ConfigActionEnum.CONFIGACTION_DELETE;
case UNDEFINED:
default:
return ContextOuterClass.ConfigActionEnum.CONFIGACTION_UNDEFINED;
}
}
public ConfigActionEnum deserialize(ContextOuterClass.ConfigActionEnum serializedConfigAction) {
switch (serializedConfigAction) {
case CONFIGACTION_SET:
return ConfigActionEnum.SET;
case CONFIGACTION_DELETE:
return ConfigActionEnum.DELETE;
case UNRECOGNIZED:
case CONFIGACTION_UNDEFINED:
default:
return ConfigActionEnum.UNDEFINED;
}
}
public ContextId serializeContextId(String expectedContextId) {
final var builder = ContextId.newBuilder();
final var uuid = serializeUuid(expectedContextId);
builder.setContextUuid(uuid);
return builder.build();
}
public String deserialize(ContextId contextId) {
return contextId.getContextUuid().getUuid();
}
public ContextOuterClass.TopologyId serialize(TopologyId topologyId) {
final var builder = ContextOuterClass.TopologyId.newBuilder();
final var topologyIdContextId = topologyId.getContextId();
final var topologyIdId = topologyId.getId();
final var contextId = serializeContextId(topologyIdContextId);
final var topologyIdIdUuid = serializeUuid(topologyIdId);
builder.setContextId(contextId);
builder.setTopologyUuid(topologyIdIdUuid);
return builder.build();
}
public TopologyId deserialize(ContextOuterClass.TopologyId topologyId) {
final var topologyIdContextId = deserialize(topologyId.getContextId());
final var topologyIdId = deserialize(topologyId.getTopologyUuid());
return new TopologyId(topologyIdContextId, topologyIdId);
}
public ContextOuterClass.EndPointId serialize(EndPointId endPointId) {
final var builder = ContextOuterClass.EndPointId.newBuilder();
final var endPointIdTopologyId = endPointId.getTopologyId();
final var endPointIdDeviceId = endPointId.getDeviceId();
final var endPointIdId = endPointId.getId();
final var serializedTopologyId = serialize(endPointIdTopologyId);
final var serializedDeviceId = serializeDeviceId(endPointIdDeviceId);
final var serializedEndPointIdId = serializeUuid(endPointIdId);
builder.setTopologyId(serializedTopologyId);
builder.setDeviceId(serializedDeviceId);
builder.setEndpointUuid(serializedEndPointIdId);
return builder.build();
}
public EndPointId deserialize(ContextOuterClass.EndPointId serializedEndPointId) {
final var serializedTopologyId = serializedEndPointId.getTopologyId();
final var serializedDeviceId = serializedEndPointId.getDeviceId();
final var serializedId = serializedEndPointId.getEndpointUuid();
final var topologyId = deserialize(serializedTopologyId);
final var deviceId = deserialize(serializedDeviceId);
final var id = deserialize(serializedId);
return new EndPointId(topologyId, deviceId, id);
}
public Acl.AclRuleTypeEnum serialize(AclRuleTypeEnum aclRuleTypeEnum) {
switch (aclRuleTypeEnum) {
case IPV4:
return Acl.AclRuleTypeEnum.ACLRULETYPE_IPV4;
case IPV6:
return Acl.AclRuleTypeEnum.ACLRULETYPE_IPV6;
case L2:
return Acl.AclRuleTypeEnum.ACLRULETYPE_L2;
case MPLS:
return Acl.AclRuleTypeEnum.ACLRULETYPE_MPLS;
case MIXED:
return Acl.AclRuleTypeEnum.ACLRULETYPE_MIXED;
case UNDEFINED:
return Acl.AclRuleTypeEnum.ACLRULETYPE_UNDEFINED;
default:
return Acl.AclRuleTypeEnum.UNRECOGNIZED;
}
}
public AclRuleTypeEnum deserialize(Acl.AclRuleTypeEnum serializedAclRuleTypeEnum) {
switch (serializedAclRuleTypeEnum) {
case ACLRULETYPE_IPV4:
return AclRuleTypeEnum.IPV4;
case ACLRULETYPE_IPV6:
return AclRuleTypeEnum.IPV6;
case ACLRULETYPE_L2:
return AclRuleTypeEnum.L2;
case ACLRULETYPE_MPLS:
return AclRuleTypeEnum.MPLS;
case ACLRULETYPE_MIXED:
return AclRuleTypeEnum.MIXED;
case UNRECOGNIZED:
default:
return AclRuleTypeEnum.UNDEFINED;
}
}
public Acl.AclMatch serialize(AclMatch aclMatch) {
final var builder = Acl.AclMatch.newBuilder();
final var dscp = aclMatch.getDscp();
final var protocol = aclMatch.getProtocol();
final var srcAddress = aclMatch.getSrcAddress();
final var dstAddress = aclMatch.getDstAddress();
final var srcPort = aclMatch.getSrcPort();
final var dstPort = aclMatch.getDstPort();
final var startMplsLabel = aclMatch.getStartMplsLabel();
final var endMplsLabel = aclMatch.getEndMplsLabel();
builder.setDscp(dscp);
builder.setProtocol(protocol);
builder.setSrcAddress(srcAddress);
builder.setDstAddress(dstAddress);
builder.setSrcPort(srcPort);
builder.setDstPort(dstPort);
builder.setStartMplsLabel(startMplsLabel);
builder.setEndMplsLabel(endMplsLabel);
return builder.build();
}
public AclMatch deserialize(Acl.AclMatch serializedAclMatch) {
final var dscp = serializedAclMatch.getDscp();
final var protocol = serializedAclMatch.getProtocol();
final var srcAddress = serializedAclMatch.getSrcAddress();
final var dstAddress = serializedAclMatch.getDstAddress();
final var srcPort = serializedAclMatch.getSrcPort();
final var dstPort = serializedAclMatch.getDstPort();
final var startMplsLabel = serializedAclMatch.getStartMplsLabel();
final var endMplsLabel = serializedAclMatch.getEndMplsLabel();
return new AclMatch(
dscp, protocol, srcAddress, dstAddress, srcPort, dstPort, startMplsLabel, endMplsLabel);
}
public Acl.AclForwardActionEnum serialize(AclForwardActionEnum aclForwardActionEnum) {
switch (aclForwardActionEnum) {
case DROP:
return Acl.AclForwardActionEnum.ACLFORWARDINGACTION_DROP;
case ACCEPT:
return Acl.AclForwardActionEnum.ACLFORWARDINGACTION_ACCEPT;
case REJECT:
return Acl.AclForwardActionEnum.ACLFORWARDINGACTION_REJECT;
case UNDEFINED:
return Acl.AclForwardActionEnum.ACLFORWARDINGACTION_UNDEFINED;
default:
return Acl.AclForwardActionEnum.UNRECOGNIZED;
}
}
public AclForwardActionEnum deserialize(Acl.AclForwardActionEnum serializedAclForwardActionEnum) {
switch (serializedAclForwardActionEnum) {
case ACLFORWARDINGACTION_DROP:
return AclForwardActionEnum.DROP;
case ACLFORWARDINGACTION_ACCEPT:
return AclForwardActionEnum.ACCEPT;
case ACLFORWARDINGACTION_REJECT:
return AclForwardActionEnum.REJECT;
case UNRECOGNIZED:
default:
return AclForwardActionEnum.UNDEFINED;
}
}
public Acl.AclLogActionEnum serialize(AclLogActionEnum aclLogActionEnum) {
switch (aclLogActionEnum) {
case NO_LOG:
return Acl.AclLogActionEnum.ACLLOGACTION_NOLOG;
case SYSLOG:
return Acl.AclLogActionEnum.ACLLOGACTION_SYSLOG;
case UNDEFINED:
return Acl.AclLogActionEnum.ACLLOGACTION_UNDEFINED;
default:
return Acl.AclLogActionEnum.UNRECOGNIZED;
}
}
public AclLogActionEnum deserialize(Acl.AclLogActionEnum serializedAclLogActionEnum) {
switch (serializedAclLogActionEnum) {
case ACLLOGACTION_NOLOG:
return AclLogActionEnum.NO_LOG;
case ACLLOGACTION_SYSLOG:
return AclLogActionEnum.SYSLOG;
case UNRECOGNIZED:
default:
return AclLogActionEnum.UNDEFINED;
}
}
public Acl.AclAction serialize(AclAction aclAction) {
final var builder = Acl.AclAction.newBuilder();
final var aclForwardActionEnum = aclAction.getAclForwardActionEnum();
final var aclLogActionEnum = aclAction.getAclLogActionEnum();
final var serializedAclForwardActionEnum = serialize(aclForwardActionEnum);
final var serializedAclLogActionEnum = serialize(aclLogActionEnum);
builder.setForwardAction(serializedAclForwardActionEnum);
builder.setLogAction(serializedAclLogActionEnum);
return builder.build();
}
public AclAction deserialize(Acl.AclAction serializedAclAction) {
final var serializedAclForwardActionEnum = serializedAclAction.getForwardAction();
final var serializedAclLogActionEnum = serializedAclAction.getLogAction();
final var aclForwardActionEnum = deserialize(serializedAclForwardActionEnum);
final var aclLogActionEnum = deserialize(serializedAclLogActionEnum);
return new AclAction(aclForwardActionEnum, aclLogActionEnum);
}
public Acl.AclEntry serialize(AclEntry aclEntry) {
final var builder = Acl.AclEntry.newBuilder();
final var sequenceId = aclEntry.getSequenceId();
final var description = aclEntry.getDescription();
final var aclMatch = aclEntry.getMatch();
final var aclAction = aclEntry.getAction();
final var serializedAclMatch = serialize(aclMatch);
final var serializedAclAction = serialize(aclAction);
builder.setSequenceId(sequenceId);
builder.setDescription(description);
builder.setMatch(serializedAclMatch);
builder.setAction(serializedAclAction);
return builder.build();
}
public AclEntry deserialize(Acl.AclEntry serializedAclEntry) {
final var sequenceId = serializedAclEntry.getSequenceId();
final var description = serializedAclEntry.getDescription();
final var serializedAclMatch = serializedAclEntry.getMatch();
final var serializedAclAction = serializedAclEntry.getAction();
final var aclMatch = deserialize(serializedAclMatch);
final var aclAction = deserialize(serializedAclAction);
return new AclEntry(sequenceId, description, aclMatch, aclAction);
}
public Acl.AclRuleSet serialize(AclRuleSet aclRuleSet) {
final var builder = Acl.AclRuleSet.newBuilder();
final var name = aclRuleSet.getName();
final var type = aclRuleSet.getType();
final var description = aclRuleSet.getDescription();
final var userId = aclRuleSet.getUserId();
final var entries = aclRuleSet.getEntries();
final var serializedType = serialize(type);
final var serializedEntries =
entries.stream().map(this::serialize).collect(Collectors.toList());
builder.setName(name);
builder.setType(serializedType);
builder.setDescription(description);
builder.setUserId(userId);
builder.addAllEntries(serializedEntries);
return builder.build();
}
public AclRuleSet deserialize(Acl.AclRuleSet serializedAclRuleSet) {
final var serializedName = serializedAclRuleSet.getName();
final var serializedType = serializedAclRuleSet.getType();
final var serializedDescription = serializedAclRuleSet.getDescription();
final var serializedUserId = serializedAclRuleSet.getUserId();
final var serializedEntries = serializedAclRuleSet.getEntriesList();
final var type = deserialize(serializedType);
final var entries =
serializedEntries.stream().map(this::deserialize).collect(Collectors.toList());
return new AclRuleSet(serializedName, type, serializedDescription, serializedUserId, entries);
}
public ConfigRule_ACL serialize(ConfigRuleAcl configRuleAcl) {
final var builder = ContextOuterClass.ConfigRule_ACL.newBuilder();
final var endPointId = configRuleAcl.getEndPointId();
final var aclRuleSet = configRuleAcl.getRuleSet();
final var serializedEndPointId = serialize(endPointId);
final var serializedAclRuleSet = serialize(aclRuleSet);
builder.setEndpointId(serializedEndPointId);
builder.setRuleSet(serializedAclRuleSet);
return builder.build();
}
public ConfigRuleAcl deserialize(ConfigRule_ACL serializedConfigRuleAcl) {
final var serializedEndPointId = serializedConfigRuleAcl.getEndpointId();
final var serializedAclRuleSet = serializedConfigRuleAcl.getRuleSet();
final var endPointId = deserialize(serializedEndPointId);
final var aclRuleSet = deserialize(serializedAclRuleSet);
return new ConfigRuleAcl(endPointId, aclRuleSet);
}
public ConfigRule_Custom serialize(ConfigRuleCustom configRuleCustom) {
final var builder = ConfigRule_Custom.newBuilder();
final var resourceKey = configRuleCustom.getResourceKey();
final var resourceValue = configRuleCustom.getResourceValue();
builder.setResourceKey(resourceKey);
builder.setResourceValue(resourceValue);
return builder.build();
}
public ConfigRuleCustom deserialize(ConfigRule_Custom serializedConfigRuleCustom) {
final var serializedResourceKey = serializedConfigRuleCustom.getResourceKey();
final var serializedResourceValue = serializedConfigRuleCustom.getResourceValue();
return new ConfigRuleCustom(serializedResourceKey, serializedResourceValue);
}
public ContextOuterClass.ConfigRule serialize(ConfigRule configRule) {
final var builder = ContextOuterClass.ConfigRule.newBuilder();
final var configActionEnum = configRule.getConfigActionEnum();
final var configRuleType = configRule.getConfigRuleType();
final var configRuleTypeSpecificType = configRuleType.getConfigRuleType();
if (configRuleTypeSpecificType instanceof ConfigRuleAcl) {
final var endPointId = ((ConfigRuleAcl) configRuleTypeSpecificType).getEndPointId();
final var aclRuleSet = ((ConfigRuleAcl) configRuleTypeSpecificType).getRuleSet();
final var serializedEndPointId = serialize(endPointId);
final var serializedAclRuleSet = serialize(aclRuleSet);
final var serializedConfigRuleAcl =
ConfigRule_ACL.newBuilder()
.setEndpointId(serializedEndPointId)
.setRuleSet(serializedAclRuleSet)
.build();
builder.setAcl(serializedConfigRuleAcl);
}
if (configRuleTypeSpecificType instanceof ConfigRuleCustom) {
final var configRuleCustomResourceKey =
((ConfigRuleCustom) configRuleTypeSpecificType).getResourceKey();
final var configRuleCustomResourceValue =
((ConfigRuleCustom) configRuleTypeSpecificType).getResourceValue();
final var serializedConfigRuleCustom =
ConfigRule_Custom.newBuilder()
.setResourceKey(configRuleCustomResourceKey)
.setResourceValue(configRuleCustomResourceValue)
.build();
builder.setCustom(serializedConfigRuleCustom);
}
final var serializedConfigActionEnum = serialize(configActionEnum);
builder.setAction(serializedConfigActionEnum);
return builder.build();
}
public ConfigRule deserialize(ContextOuterClass.ConfigRule serializedConfigRule) {
final var serializedConfigActionEnum = serializedConfigRule.getAction();
final var typeOfConfigRule = serializedConfigRule.getConfigRuleCase();
final var configActionEnum = deserialize(serializedConfigActionEnum);
switch (typeOfConfigRule) {
case ACL:
final var serializedConfigRuleAcl = serializedConfigRule.getAcl();
final var configRuleAcl = deserialize(serializedConfigRuleAcl);
final var configRuleTypeAcl = new ConfigRuleTypeAcl(configRuleAcl);
return new ConfigRule(configActionEnum, configRuleTypeAcl);
case CUSTOM:
final var serializedConfigRuleCustom = serializedConfigRule.getCustom();
final var configRuleCustom = deserialize(serializedConfigRuleCustom);
final var configRuleTypeCustom = new ConfigRuleTypeCustom(configRuleCustom);
return new ConfigRule(configActionEnum, configRuleTypeCustom);
default:
case CONFIGRULE_NOT_SET:
throw new IllegalStateException("Config Rule not set");
}
}
public ContextOuterClass.DeviceConfig serialize(DeviceConfig deviceConfig) {
final var builder = ContextOuterClass.DeviceConfig.newBuilder();
final var serializedConfigRules =
deviceConfig.getConfigRules().stream().map(this::serialize).collect(Collectors.toList());
builder.addAllConfigRules(serializedConfigRules);
return builder.build();
}
public DeviceConfig deserialize(ContextOuterClass.DeviceConfig deviceConfig) {
final var configRules =
deviceConfig.getConfigRulesList().stream()
.map(this::deserialize)
.collect(Collectors.toList());
return new DeviceConfig(configRules);
}
public ContextOuterClass.DeviceOperationalStatusEnum serialize(DeviceOperationalStatus opStatus) {
switch (opStatus) {
case ENABLED:
return DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED;
case DISABLED:
return DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED;
case UNDEFINED:
default:
return DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_UNDEFINED;
}
}
public DeviceOperationalStatus deserialize(
ContextOuterClass.DeviceOperationalStatusEnum opStatus) {
switch (opStatus) {
case DEVICEOPERATIONALSTATUS_ENABLED:
return DeviceOperationalStatus.ENABLED;
case DEVICEOPERATIONALSTATUS_DISABLED:
return DeviceOperationalStatus.DISABLED;
case DEVICEOPERATIONALSTATUS_UNDEFINED:
case UNRECOGNIZED:
default:
return DeviceOperationalStatus.UNDEFINED;
}
}
public KpiSampleTypes.KpiSampleType serialize(KpiSampleType kpiSampleType) {
switch (kpiSampleType) {
case PACKETS_TRANSMITTED:
return KpiSampleTypes.KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED;
case PACKETS_RECEIVED:
return KpiSampleTypes.KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED;
case BYTES_TRANSMITTED:
return KpiSampleTypes.KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED;
case BYTES_RECEIVED:
return KpiSampleTypes.KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED;
case UNKNOWN:
return KpiSampleTypes.KpiSampleType.KPISAMPLETYPE_UNKNOWN;
default:
return KpiSampleTypes.KpiSampleType.UNRECOGNIZED;
}
}
public KpiSampleType deserialize(KpiSampleTypes.KpiSampleType serializedKpiSampleType) {
switch (serializedKpiSampleType) {
case KPISAMPLETYPE_PACKETS_TRANSMITTED:
return KpiSampleType.PACKETS_TRANSMITTED;
case KPISAMPLETYPE_PACKETS_RECEIVED:
return KpiSampleType.PACKETS_RECEIVED;
case KPISAMPLETYPE_BYTES_TRANSMITTED:
return KpiSampleType.BYTES_TRANSMITTED;
case KPISAMPLETYPE_BYTES_RECEIVED:
return KpiSampleType.BYTES_RECEIVED;
case KPISAMPLETYPE_UNKNOWN:
default:
return KpiSampleType.UNKNOWN;
}
}
public ContextOuterClass.Location serialize(Location location) {
final var builder = ContextOuterClass.Location.newBuilder();
final var locationType = location.getLocationType();
final var locationTypeSpecificType = locationType.getLocationType();
if (locationTypeSpecificType instanceof GpsPosition) {
final var latitude = ((GpsPosition) locationTypeSpecificType).getLatitude();
final var longitude = ((GpsPosition) locationTypeSpecificType).getLongitude();
final var serializedGpsPosition =
ContextOuterClass.GPS_Position.newBuilder()
.setLatitude(latitude)
.setLongitude(longitude)
.build();
builder.setGpsPosition(serializedGpsPosition);
}
if (locationTypeSpecificType instanceof String) {
final var region = ((String) locationTypeSpecificType);
builder.setRegion(region);
}
return builder.build();
}
public Location deserialize(ContextOuterClass.Location serializedLocation) {
final var typeOfLocation = serializedLocation.getLocationCase();
switch (typeOfLocation) {
case REGION:
final var region = serializedLocation.getRegion();
final var locationTypeRegion = new LocationTypeRegion(region);
return new Location(locationTypeRegion);
case GPS_POSITION:
final var serializedGpsPosition = serializedLocation.getGpsPosition();
final var latitude = serializedGpsPosition.getLatitude();
final var longitude = serializedGpsPosition.getLongitude();
final var gpsPosition = new GpsPosition(latitude, longitude);
final var locationTypeGpsPosition = new LocationTypeGpsPosition(gpsPosition);
return new Location(locationTypeGpsPosition);
default:
case LOCATION_NOT_SET:
throw new IllegalStateException("Location value not set");
}
}
public ContextOuterClass.DeviceDriverEnum serialize(DeviceDriverEnum deviceDriverEnum) {
switch (deviceDriverEnum) {
case OPENCONFIG:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG;
case TRANSPORT_API:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_TRANSPORT_API;
case P4:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_P4;
case IETF_NETWORK_TOPOLOGY:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_IETF_NETWORK_TOPOLOGY;
case ONF_TR_352:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_ONF_TR_352;
case XR:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_XR;
case IETF_L2VPN:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN;
case UNDEFINED:
default:
return ContextOuterClass.DeviceDriverEnum.DEVICEDRIVER_UNDEFINED;
}
}
public DeviceDriverEnum deserialize(
ContextOuterClass.DeviceDriverEnum serializedDeviceDriverEnum) {
switch (serializedDeviceDriverEnum) {
case DEVICEDRIVER_OPENCONFIG:
return DeviceDriverEnum.OPENCONFIG;
case DEVICEDRIVER_TRANSPORT_API:
return DeviceDriverEnum.TRANSPORT_API;
case DEVICEDRIVER_P4:
return DeviceDriverEnum.P4;
case DEVICEDRIVER_IETF_NETWORK_TOPOLOGY:
return DeviceDriverEnum.IETF_NETWORK_TOPOLOGY;
case DEVICEDRIVER_ONF_TR_352:
return DeviceDriverEnum.ONF_TR_352;
case DEVICEDRIVER_XR:
return DeviceDriverEnum.XR;
case DEVICEDRIVER_IETF_L2VPN:
return DeviceDriverEnum.IETF_L2VPN;
case DEVICEDRIVER_UNDEFINED:
case UNRECOGNIZED:
default:
return DeviceDriverEnum.UNDEFINED;
}
}
public ContextOuterClass.EndPoint serialize(EndPoint endPoint) {
final var builder = ContextOuterClass.EndPoint.newBuilder();
final var endPointId = endPoint.getEndPointId();
final var endPointType = endPoint.getEndPointType();
final var kpiSampleTypes = endPoint.getKpiSampleTypes();
final var endPointLocation = endPoint.getEndPointLocation();
final var serializedEndPointId = serialize(endPointId);
final var serializedKpiSampleTypes =
kpiSampleTypes.stream().map(this::serialize).collect(Collectors.toList());
if (endPointLocation != null) {
final var serializedEndPointLocation = serialize(endPointLocation);
builder.setEndpointLocation(serializedEndPointLocation);
}
builder.setEndpointId(serializedEndPointId);
builder.setEndpointType(endPointType);
builder.addAllKpiSampleTypes(serializedKpiSampleTypes);
return builder.build();
}
public EndPoint deserialize(ContextOuterClass.EndPoint serializedEndPoint) {
final var serializedEndPointId = serializedEndPoint.getEndpointId();
final var endPointType = serializedEndPoint.getEndpointType();
final var serializedKpiSampleTypes = serializedEndPoint.getKpiSampleTypesList();
final var serializedEndPointLocation = serializedEndPoint.getEndpointLocation();
final var endPointId = deserialize(serializedEndPointId);
final var kpiSampleTypes =
serializedKpiSampleTypes.stream().map(this::deserialize).collect(Collectors.toList());
if (serializedEndPointLocation.getLocationCase() != LocationCase.LOCATION_NOT_SET) {
final var endPointLocation = deserialize(serializedEndPointLocation);
return new EndPoint.EndPointBuilder(endPointId, endPointType, kpiSampleTypes)
.location(endPointLocation)
.build();
}
return new EndPoint.EndPointBuilder(endPointId, endPointType, kpiSampleTypes).build();
}
public ContextOuterClass.Device serialize(Device device) {
final var builder = ContextOuterClass.Device.newBuilder();
final var deviceIdUuid = serializeUuid(device.getDeviceId());
final var deviceId = DeviceId.newBuilder().setDeviceUuid(deviceIdUuid);
final var deviceName = device.getDeviceName();
final var deviceType = device.getDeviceType();
final var deviceConfig = device.getDeviceConfig();
final var deviceOperationalStatus = device.getDeviceOperationalStatus();
final var deviceDrivers = device.getDeviceDrivers();
final var deviceEndPoints = device.getEndPoints();
final var serializedDeviceConfig = serialize(deviceConfig);
final var serializedDeviceOperationalStatus = serialize(deviceOperationalStatus);
final var serializedDeviceDrivers =
deviceDrivers.stream().map(this::serialize).collect(Collectors.toList());
final var serializedDeviceEndPoints =
deviceEndPoints.stream().map(this::serialize).collect(Collectors.toList());
builder.setDeviceId(deviceId);
builder.setName(deviceName);
builder.setDeviceType(deviceType);
builder.setDeviceConfig(serializedDeviceConfig);
builder.setDeviceOperationalStatus(serializedDeviceOperationalStatus);
builder.addAllDeviceDrivers(serializedDeviceDrivers);
builder.addAllDeviceEndpoints(serializedDeviceEndPoints);
return builder.build();
}
public Device deserialize(ContextOuterClass.Device device) {
final var serializedDeviceId = device.getDeviceId();
final var deviceName = device.getName();
final var deviceType = device.getDeviceType();
final var serializedDeviceConfig = device.getDeviceConfig();
final var serializedDeviceOperationalStatus = device.getDeviceOperationalStatus();
final var serializedDeviceDrivers = device.getDeviceDriversList();
final var serializedDeviceEndPoints = device.getDeviceEndpointsList();
final var deviceId = deserialize(serializedDeviceId);
final var deviceConfig = deserialize(serializedDeviceConfig);
final var deviceOperationalStatus = deserialize(serializedDeviceOperationalStatus);
final var deviceDrivers =
serializedDeviceDrivers.stream().map(this::deserialize).collect(Collectors.toList());
final var deviceEndPoints =
serializedDeviceEndPoints.stream().map(this::deserialize).collect(Collectors.toList());
return new Device(
deviceId,
deviceName,
deviceType,
deviceConfig,
deviceOperationalStatus,
deviceDrivers,
deviceEndPoints);
}
public ContextOuterClass.Empty serializeEmpty(Empty empty) {
final var builder = ContextOuterClass.Empty.newBuilder();
return builder.build();
}
public Empty deserializeEmpty(ContextOuterClass.Empty serializedEmpty) {
return new Empty();
}
public Uuid serializeUuid(String uuid) {
return Uuid.newBuilder().setUuid(uuid).build();
}
public String deserialize(Uuid uuid) {
return uuid.getUuid();
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
@Liveness
@ApplicationScoped
public class SimpleLivenessCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.up("Automation Service is live");
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation;
import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;
@Readiness
@ApplicationScoped
public class SimpleReadinessCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.up("Automation Service is ready");
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public class AclAction {
private final AclForwardActionEnum aclForwardActionEnum;
private final AclLogActionEnum aclLogActionEnum;
public AclAction(AclForwardActionEnum aclForwardActionEnum, AclLogActionEnum aclLogActionEnum) {
this.aclForwardActionEnum = aclForwardActionEnum;
this.aclLogActionEnum = aclLogActionEnum;
}
public AclForwardActionEnum getAclForwardActionEnum() {
return aclForwardActionEnum;
}
public AclLogActionEnum getAclLogActionEnum() {
return aclLogActionEnum;
}
@Override
public String toString() {
return String.format(
"%s:{aclForwardActionEnum:\"%s\", aclLogActionEnum:\"%s\"}",
getClass().getSimpleName(), aclForwardActionEnum.toString(), aclLogActionEnum.toString());
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public class AclEntry {
private final int sequenceId;
private final String description;
private final AclMatch match;
private final AclAction action;
public AclEntry(int sequenceId, String description, AclMatch match, AclAction action) {
this.sequenceId = sequenceId;
this.description = description;
this.match = match;
this.action = action;
}
public int getSequenceId() {
return sequenceId;
}
public String getDescription() {
return description;
}
public AclMatch getMatch() {
return match;
}
public AclAction getAction() {
return action;
}
@Override
public String toString() {
return String.format(
"%s:{sequenceId:\"%d\", description:\"%s\", %s, %s}",
getClass().getSimpleName(), sequenceId, description, match, action);
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public enum AclForwardActionEnum {
UNDEFINED,
DROP,
ACCEPT,
REJECT,
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public enum AclLogActionEnum {
UNDEFINED,
NO_LOG,
SYSLOG
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public class AclMatch {
private final int dscp;
private final int protocol;
private final String srcAddress;
private final String dstAddress;
private final int srcPort;
private final int dstPort;
private final int startMplsLabel;
private final int endMplsLabel;
public AclMatch(
int dscp,
int protocol,
String srcAddress,
String dstAddress,
int srcPort,
int dstPort,
int startMplsLabel,
int endMplsLabel) {
this.dscp = dscp;
this.protocol = protocol;
this.srcAddress = srcAddress;
this.dstAddress = dstAddress;
this.srcPort = srcPort;
this.dstPort = dstPort;
this.startMplsLabel = startMplsLabel;
this.endMplsLabel = endMplsLabel;
}
public int getDscp() {
return dscp;
}
public int getProtocol() {
return protocol;
}
public String getSrcAddress() {
return srcAddress;
}
public String getDstAddress() {
return dstAddress;
}
public int getSrcPort() {
return srcPort;
}
public int getDstPort() {
return dstPort;
}
public int getStartMplsLabel() {
return startMplsLabel;
}
public int getEndMplsLabel() {
return endMplsLabel;
}
@Override
public String toString() {
return String.format(
"%s:{dscp:\"%d\", protocol:\"%d\", srcAddress:\"%s\", dstAddress:\"%s\", srcPort:\"%d\", dstPort:\"%d\", startMplsLabel:\"%d\", endMplsLabel:\"%d\"}",
getClass().getSimpleName(),
dscp,
protocol,
srcAddress,
dstAddress,
srcPort,
dstPort,
startMplsLabel,
endMplsLabel);
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
import eu.teraflow.automation.common.Util;
import java.util.List;
public class AclRuleSet {
private final String name;
private final AclRuleTypeEnum type;
private final String description;
private final String userId;
private final List<AclEntry> entries;
public AclRuleSet(
String name,
AclRuleTypeEnum type,
String description,
String userId,
List<AclEntry> entries) {
this.name = name;
this.type = type;
this.description = description;
this.userId = userId;
this.entries = entries;
}
public String getName() {
return name;
}
public AclRuleTypeEnum getType() {
return type;
}
public String getDescription() {
return description;
}
public String getUserId() {
return userId;
}
public List<AclEntry> getEntries() {
return entries;
}
@Override
public String toString() {
return String.format(
"%s:{name:\"%s\", type:\"%s\", description:\"%s\", userId:\"%s\", [%s]}",
getClass().getSimpleName(),
name,
type.toString(),
description,
userId,
Util.toString(entries));
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.acl;
public enum AclRuleTypeEnum {
UNDEFINED,
IPV4,
IPV6,
L2,
MPLS,
MIXED
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.common;
import java.util.List;
import java.util.stream.Collectors;
public class Util {
private Util() {}
public static <T> String toString(List<T> list) {
return list.stream().map(T::toString).collect(Collectors.joining(", "));
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.context;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceEvent;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
public interface ContextGateway {
Uni<Device> getDevice(String deviceId);
Multi<DeviceEvent> getDeviceEvents();
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.teraflow.automation.context;
import context.ContextOuterClass;
import context.MutinyContextServiceGrpc.MutinyContextServiceStub;
import eu.teraflow.automation.Serializer;
import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceEvent;
import io.quarkus.grpc.GrpcClient;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ApplicationScoped
public class ContextGatewayImpl implements ContextGateway {
@GrpcClient("context")
MutinyContextServiceStub streamingDelegateContext;
private final Serializer serializer;
@Inject
public ContextGatewayImpl(Serializer serializer) {
this.serializer = serializer;
}
@Override
public Multi<DeviceEvent> getDeviceEvents() {
final var serializedEmpty = ContextOuterClass.Empty.newBuilder().build();
return streamingDelegateContext
.getDeviceEvents(serializedEmpty)
.onItem()
.transform(serializer::deserialize);
}
@Override
public Uni<Device> getDevice(String deviceId) {
final var serializedDeviceId = serializer.serializeDeviceId(deviceId);
return streamingDelegateContext
.getDevice(serializedDeviceId)
.onItem()
.transform(serializer::deserialize);
}
}