/*
* 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 ContextService {
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 eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceEvent;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ApplicationScoped
public class ContextServiceImpl implements ContextService {
private final ContextGateway contextGateway;
@Inject
public ContextServiceImpl(ContextGateway contextGateway) {
this.contextGateway = contextGateway;
}
@Override
public Uni<Device> getDevice(String deviceId) {
return contextGateway.getDevice(deviceId);
}
@Override
public Multi<DeviceEvent> getDeviceEvents() {
return contextGateway.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.model;
public enum ConfigActionEnum {
UNDEFINED,
SET,
DELETE
}
/*
* 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.model;
public class ConfigRule {
private final ConfigActionEnum configActionEnum;
private final ConfigRuleType<?> configRuleType;
public ConfigRule(ConfigActionEnum configActionEnum, ConfigRuleType<?> configRuleType) {
this.configActionEnum = configActionEnum;
this.configRuleType = configRuleType;
}
public ConfigActionEnum getConfigActionEnum() {
return configActionEnum;
}
public ConfigRuleType getConfigRuleType() {
return configRuleType;
}
@Override
public String toString() {
return String.format(
"%s:{configActionEnum:\"%s\", %s}",
getClass().getSimpleName(), configActionEnum, configRuleType);
}
}
/*
* 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.model;
import eu.teraflow.automation.acl.AclRuleSet;
public class ConfigRuleAcl {
private final EndPointId endPointId;
private final AclRuleSet ruleSet;
public ConfigRuleAcl(EndPointId endPointId, AclRuleSet ruleSet) {
this.endPointId = endPointId;
this.ruleSet = ruleSet;
}
public EndPointId getEndPointId() {
return endPointId;
}
public AclRuleSet getRuleSet() {
return ruleSet;
}
@Override
public String toString() {
return String.format("%s:{%s, %s}", getClass().getSimpleName(), endPointId, ruleSet);
}
}
/*
* 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.model;
public class ConfigRuleCustom {
private final String resourceKey;
private final String resourceValue;
public ConfigRuleCustom(String resourceKey, String resourceValue) {
this.resourceKey = resourceKey;
this.resourceValue = resourceValue;
}
public String getResourceKey() {
return resourceKey;
}
public String getResourceValue() {
return resourceValue;
}
@Override
public String toString() {
return String.format("%s:{%s, %s}", getClass().getSimpleName(), resourceKey, resourceValue);
}
}
/*
* 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.model;
public interface ConfigRuleType<T> {
public T getConfigRuleType();
}
/*
* 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.model;
public class ConfigRuleTypeAcl implements ConfigRuleType<ConfigRuleAcl> {
private final ConfigRuleAcl configRuleAcl;
public ConfigRuleTypeAcl(ConfigRuleAcl configRuleAcl) {
this.configRuleAcl = configRuleAcl;
}
@Override
public ConfigRuleAcl getConfigRuleType() {
return this.configRuleAcl;
}
@Override
public String toString() {
return String.format("%s:%s}", getClass().getSimpleName(), configRuleAcl);
}
}
/*
* 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.model;
public class ConfigRuleTypeCustom implements ConfigRuleType<ConfigRuleCustom> {
private final ConfigRuleCustom configRuleCustom;
public ConfigRuleTypeCustom(ConfigRuleCustom configRuleCustom) {
this.configRuleCustom = configRuleCustom;
}
@Override
public ConfigRuleCustom getConfigRuleType() {
return this.configRuleCustom;
}
@Override
public String toString() {
return String.format("%s:%s}", getClass().getSimpleName(), configRuleCustom);
}
}
/*
* 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.model;
import eu.teraflow.automation.common.Util;
import java.util.List;
public class Device {
private final String deviceId;
private final String deviceName;
private final String deviceType;
private DeviceConfig deviceConfig;
private DeviceOperationalStatus deviceOperationalStatus;
private List<DeviceDriverEnum> deviceDrivers;
private List<EndPoint> endPoints;
public Device(
String deviceId,
String deviceName,
String deviceType,
DeviceConfig deviceConfig,
DeviceOperationalStatus deviceOperationalStatus,
List<DeviceDriverEnum> deviceDrivers,
List<EndPoint> endPoints) {
this.deviceId = deviceId;
this.deviceName = deviceName;
this.deviceType = deviceType;
this.deviceConfig = deviceConfig;
this.deviceOperationalStatus = deviceOperationalStatus;
this.deviceDrivers = deviceDrivers;
this.endPoints = endPoints;
}
public Device(
String deviceId,
String deviceName,
String deviceType,
DeviceOperationalStatus deviceOperationalStatus,
List<DeviceDriverEnum> deviceDrivers,
List<EndPoint> endPoints) {
this.deviceId = deviceId;
this.deviceName = deviceName;
this.deviceType = deviceType;
this.deviceOperationalStatus = deviceOperationalStatus;
this.deviceDrivers = deviceDrivers;
this.endPoints = endPoints;
}
public boolean isEnabled() {
return deviceOperationalStatus == DeviceOperationalStatus.ENABLED;
}
public boolean isDisabled() {
return deviceOperationalStatus == DeviceOperationalStatus.DISABLED;
}
public void enableDevice() {
this.deviceOperationalStatus = DeviceOperationalStatus.ENABLED;
}
public void disableDevice() {
this.deviceOperationalStatus = DeviceOperationalStatus.DISABLED;
}
public String getDeviceId() {
return deviceId;
}
public String getDeviceName() {
return deviceName;
}
public String getDeviceType() {
return deviceType;
}
public DeviceConfig getDeviceConfig() {
return deviceConfig;
}
public List<DeviceDriverEnum> getDeviceDrivers() {
return deviceDrivers;
}
public List<EndPoint> getEndPoints() {
return endPoints;
}
public DeviceOperationalStatus getDeviceOperationalStatus() {
return deviceOperationalStatus;
}
public void setDeviceConfiguration(DeviceConfig deviceConfig) {
this.deviceConfig = deviceConfig;
}
@Override
public String toString() {
return String.format(
"%s:{deviceId:\"%s\", deviceName:\"%s\", deviceType:\"%s\", %s, deviceOperationalStatus=\"%s\", [%s], [%s]}",
getClass().getSimpleName(),
deviceId,
deviceName,
deviceType,
deviceConfig,
deviceOperationalStatus.toString(),
Util.toString(deviceDrivers),
Util.toString(endPoints));
}
}
/*
* 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.model;
import java.util.List;
import java.util.stream.Collectors;
public class DeviceConfig {
private final List<ConfigRule> configRules;
public DeviceConfig(List<ConfigRule> configRules) {
this.configRules = configRules;
}
public List<ConfigRule> getConfigRules() {
return configRules;
}
@Override
public String toString() {
final var configRulesDescription =
configRules.stream().map(ConfigRule::toString).collect(Collectors.joining(", "));
return String.format("%s[%s]", getClass().getSimpleName(), configRulesDescription);
}
}
/*
* 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.model;
public enum DeviceDriverEnum {
UNDEFINED,
OPENCONFIG,
TRANSPORT_API,
P4,
IETF_NETWORK_TOPOLOGY,
ONF_TR_352,
XR,
IETF_L2VPN
}
/*
* 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.model;
public enum DeviceOperationalStatus {
UNDEFINED,
DISABLED,
ENABLED
}
/*
* 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.model;
public class Empty {
public Empty() {
// Empty constructor to represent the Empty rpc message of context service
}
}
/*
* 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.model;
import eu.teraflow.automation.common.Util;
import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType;
import java.util.List;
public class EndPoint {
private final EndPointId endPointId;
private final String endPointType;
private final List<KpiSampleType> kpiSampleTypes;
private final Location endPointLocation;
EndPoint(EndPointBuilder builder) {
this.endPointId = builder.endPointId;
this.endPointType = builder.endPointType;
this.kpiSampleTypes = builder.kpiSampleTypes;
this.endPointLocation = builder.endPointLocation;
}
public EndPointId getEndPointId() {
return endPointId;
}
public String getEndPointType() {
return endPointType;
}
public List<KpiSampleType> getKpiSampleTypes() {
return kpiSampleTypes;
}
public Location getEndPointLocation() {
return endPointLocation;
}
@Override
public String toString() {
return String.format(
"%s:{%s, endPointType:\"%s\", [%s], %s}",
getClass().getSimpleName(),
endPointId,
endPointType,
Util.toString(kpiSampleTypes),
endPointLocation);
}
public static class EndPointBuilder {
private final EndPointId endPointId;
private final String endPointType;
private final List<KpiSampleType> kpiSampleTypes;
private Location endPointLocation;
public EndPointBuilder(
EndPointId endPointId, String endPointType, List<KpiSampleType> kpiSampleTypes) {
this.endPointId = endPointId;
this.endPointType = endPointType;
this.kpiSampleTypes = kpiSampleTypes;
}
public EndPointBuilder location(Location endPointLocation) {
this.endPointLocation = endPointLocation;
return this;
}
public EndPoint build() {
EndPoint endPoint = new EndPoint(this);
validateEndPointObject(endPoint);
return endPoint;
}
private void validateEndPointObject(EndPoint endPoint) {
final var validatedEndPointId = endPoint.getEndPointId();
final var validatedEndPointType = endPoint.getEndPointType();
final var validatedKpiSampleTypes = endPoint.getKpiSampleTypes();
if (validatedEndPointId == null) {
throw new IllegalStateException("EndPoint ID cannot be null");
}
if (validatedEndPointType == null) {
throw new IllegalStateException("EndPoint type cannot be null");
}
if (validatedKpiSampleTypes == null) {
throw new IllegalStateException("Kpi sample types cannot be null");
}
}
}
}
/*
* 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.model;
public class EndPointId {
private final TopologyId topologyId;
private final String deviceId;
private final String id;
public EndPointId(TopologyId topologyId, String deviceId, String id) {
this.topologyId = topologyId;
this.deviceId = deviceId;
this.id = id;
}
public TopologyId getTopologyId() {
return topologyId;
}
public String getDeviceId() {
return deviceId;
}
public String getId() {
return id;
}
@Override
public String toString() {
return String.format(
"%s:{%s, deviceId:\"%s\", id:\"%s\"}",
getClass().getSimpleName(), topologyId, deviceId, id);
}
}
/*
* 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.model;
public class Event {
// TODO convert double to meaningful timestamp type
private final double timestamp;
private final EventTypeEnum eventType;
public Event(double timestamp, EventTypeEnum eventType) {
this.timestamp = timestamp;
this.eventType = eventType;
}
public double getTimestamp() {
return timestamp;
}
public EventTypeEnum getEventTypeEnum() {
return eventType;
}
@Override
public String toString() {
return String.format(
"%s{timestamp=\"%f\", eventType=\"%s\"}",
getClass().getSimpleName(), timestamp, eventType.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.context.model;
public enum EventTypeEnum {
UNDEFINED,
CREATE,
UPDATE,
REMOVE
}
/*
* 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.model;
public class GpsPosition {
private final float latitude;
private final float longitude;
public GpsPosition(float latitude, float longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public float getLatitude() {
return latitude;
}
public float getLongitude() {
return longitude;
}
@Override
public String toString() {
return String.format(
"%s:{latitude:\"%f\", longitude:\"%f\"}", getClass().getSimpleName(), latitude, longitude);
}
}
/*
* 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.model;
public class Location {
private final LocationType<?> locationType;
public Location(LocationType<?> locationType) {
this.locationType = locationType;
}
public LocationType getLocationType() {
return locationType;
}
@Override
public String toString() {
return String.format("%s:{%s}", getClass().getSimpleName(), locationType);
}
}