Skip to content

Commit

Permalink
Merge pull request #252 from com-pas/232-rsr-630-network_configuratio…
Browse files Browse the repository at this point in the history
…n_of_control_blocks_refacto

feat(#232): RSR-630 configure network for GSE and SMV ControlBlocks -…
  • Loading branch information
massifben authored Mar 9, 2023
2 parents 99e17f5 + a13e030 commit 6a5da6b
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* - the Communication/SubNetwork/ConnectedAP/GSE element, which is the network configuration of a GSEControl block
* - the Communication/SubNetwork/ConnectedAP/SMV element, which is the network configuration of a SampledValueControl block
* It is a FunctionalInterface, so it can be implemented with a lambda expression.
*
* @see org.lfenergy.compas.sct.commons.util.ControlBlockNetworkSettingsCsvHelper
*/
@FunctionalInterface
public interface ControlBlockNetworkSettings {
Expand All @@ -27,10 +29,34 @@ public interface ControlBlockNetworkSettings {
*/
Settings getNetworkSettings(ControlBlockAdapter controlBlockAdapter);

record Settings(
Integer vlanId,
Byte vlanPriority,
TDurationInMilliSec minTime,
TDurationInMilliSec maxTime) {
/**
* Network settings for ControlBlock communication
*
* @param vlanId id of the vlan
* @param vlanPriority priority for the vlan
* @param minTime minTime for GSE communication element
* @param maxTime maxTime for GSE communication element
*/
record Settings(Integer vlanId, Byte vlanPriority, TDurationInMilliSec minTime, TDurationInMilliSec maxTime) {
}

/**
* NetworkRanges for GSEControl and SampledValueControl
*
* @param gse NetworkRanges for GSEControl
* @param sampledValue NetworkRanges for SampledValueControl
*/
record RangesPerCbType(NetworkRanges gse, NetworkRanges sampledValue) {
}

/**
* Range of APPID and range of MAC-Address
*
* @param appIdStart range start for APPID (inclusive)
* @param appIdEnd range end for APPID (inclusive)
* @param macAddressStart range start for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-00-00"
* @param macAddressEnd range end for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-01-FF"
*/
record NetworkRanges(long appIdStart, long appIdEnd, String macAddressStart, String macAddressEnd) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter;
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
import org.lfenergy.compas.sct.commons.util.ControlBlockNetworkSettingsCsvHelper;
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.io.Reader;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.NetworkRanges;
import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType;

@UtilityClass
public class ExtRefService {

Expand Down Expand Up @@ -159,27 +160,6 @@ private static SclReport createDataSetAndControlBlocks(SclRootAdapter sclRootAda
return new SclReport(sclRootAdapter, sclReportItems);
}

/**
* Shortcut for {@link ExtRefService#configureNetworkForAllControlBlocks(SCL, ControlBlockNetworkSettings, long, long, String, String, ControlBlockEnum)}
* using a CSV file to provide ControlBlockNetworkSettings.
*
* @param scd input SCD object. The object will be modified with the new DataGSESet and SMV elements
* @param csvSource a Reader for the CSV file, as specified in {@link ControlBlockNetworkSettingsCsvHelper}.
* @param appIdMin range start for APPID (inclusive)
* @param appIdMax range end for APPID (inclusive)
* @param macAddressMin range start for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-00-00"
* @param macAddressMax range end for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-01-FF"
* @return a report with all the errors encountered
* @see ControlBlockNetworkSettingsCsvHelper
* @see ControlBlockNetworkSettings
* @see ExtRefService#configureNetworkForAllControlBlocks(SCL, ControlBlockNetworkSettings, long, long, String, String, ControlBlockEnum)
*/
public static SclReport configureNetworkForAllControlBlocks(SCL scd, Reader csvSource,
long appIdMin, long appIdMax, String macAddressMin, String macAddressMax, ControlBlockEnum controlBlockEnum) {
ControlBlockNetworkSettings controlBlockNetworkSettings = new ControlBlockNetworkSettingsCsvHelper(csvSource);
return configureNetworkForAllControlBlocks(scd, controlBlockNetworkSettings, appIdMin, appIdMax, macAddressMin, macAddressMax, controlBlockEnum);
}

/**
* Configure the network for all the ControlBlocks.
* Create (or update if already existing) these elements
Expand All @@ -188,31 +168,37 @@ public static SclReport configureNetworkForAllControlBlocks(SCL scd, Reader csvS
*
* @param scd input SCD object. The object will be modified with the new DataGSESet and SMV elements
* @param controlBlockNetworkSettings a method tha gives the network configuration information for a given ControlBlock
* @param appIdMin range start for APPID (inclusive)
* @param appIdMax range end for APPID (inclusive)
* @param macAddressMin range start for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-00-00"
* @param macAddressMax range end for MAC-Addresses (inclusive). Ex: "01-0C-CD-01-01-FF"
* @param rangesPerCbType provide NetworkRanges for GSEControl and SampledValueControl. NetworkRanges contains :
* start-end app APPID range (long value), start-end MAC-Addresses (Mac-Addresses values: Ex: "01-0C-CD-01-01-FF")
* @return a report with all the errors encountered
* @see Utils#macAddressToLong(String) for the expected MAC address format
* @see ControlBlockNetworkSettings
* @see ControlBlockNetworkSettings.RangesPerCbType
* @see ControlBlockNetworkSettings.NetworkRanges
*/
public static SclReport configureNetworkForAllControlBlocks(SCL scd, ControlBlockNetworkSettings controlBlockNetworkSettings,
long appIdMin, long appIdMax, String macAddressMin, String macAddressMax, ControlBlockEnum controlBlockEnum) {
PrimitiveIterator.OfLong appIdIterator = Utils.sequence(appIdMin, appIdMax);
Iterator<String> macAddressIterator = Utils.macAddressSequence(macAddressMin, macAddressMax);
RangesPerCbType rangesPerCbType) {
List<SclReportItem> sclReportItems = new ArrayList<>();
sclReportItems.addAll(configureNetworkForControlBlocks(scd, controlBlockNetworkSettings, rangesPerCbType.gse(), ControlBlockEnum.GSE));
sclReportItems.addAll(configureNetworkForControlBlocks(scd, controlBlockNetworkSettings, rangesPerCbType.sampledValue(), ControlBlockEnum.SAMPLED_VALUE));
return new SclReport(new SclRootAdapter(scd), sclReportItems);
}

private static List<SclReportItem> configureNetworkForControlBlocks(SCL scd, ControlBlockNetworkSettings controlBlockNetworkSettings,
NetworkRanges networkRanges, ControlBlockEnum controlBlockEnum) {
PrimitiveIterator.OfLong appIdIterator = Utils.sequence(networkRanges.appIdStart(), networkRanges.appIdEnd());
Iterator<String> macAddressIterator = Utils.macAddressSequence(networkRanges.macAddressStart(), networkRanges.macAddressEnd());

SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
List<SclReportItem> sclReportItems =
sclRootAdapter.streamIEDAdapters()
.flatMap(iedAdapter ->
iedAdapter.streamLDeviceAdapters()
.filter(LDeviceAdapter::hasLN0)
.map(LDeviceAdapter::getLN0Adapter)
.flatMap(ln0Adapter -> ln0Adapter.streamControlBlocks(controlBlockEnum))
.map(controlBlockAdapter -> configureControlBlockNetwork(controlBlockNetworkSettings, appIdIterator, macAddressIterator, controlBlockAdapter)))
.flatMap(Optional::stream)
.toList();
return new SclReport(sclRootAdapter, sclReportItems);
return sclRootAdapter.streamIEDAdapters()
.flatMap(iedAdapter ->
iedAdapter.streamLDeviceAdapters()
.filter(LDeviceAdapter::hasLN0)
.map(LDeviceAdapter::getLN0Adapter)
.flatMap(ln0Adapter -> ln0Adapter.streamControlBlocks(controlBlockEnum))
.map(controlBlockAdapter -> configureControlBlockNetwork(controlBlockNetworkSettings, appIdIterator, macAddressIterator, controlBlockAdapter)))
.flatMap(Optional::stream)
.toList();
}

private static Optional<SclReportItem> configureControlBlockNetwork(ControlBlockNetworkSettings controlBlockNetworkSettings, PrimitiveIterator.OfLong appIdIterator, Iterator<String> macAddressIterator, ControlBlockAdapter controlBlockAdapter) {
Expand Down
Loading

0 comments on commit 6a5da6b

Please sign in to comment.