From 7d4f682d48155fdc6c3b4ad1b1c05e58919f2655 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Tue, 31 Aug 2021 11:59:25 +0200 Subject: [PATCH] Refactor OLM timers management OLM timer values are defined by OpenROADM whitepaper specifications. For this reason, they are hardcoded with constants in the current code. Though, there are at least 2 reasons to make them configurable: 1- At least one vendor product needs more than the OpenROADM whitepaper recommandation because it is not supporting GainLoss with target-output-power. 2- The OlmUtils constants are patched in functional tests to speed-up tests because the simulators needs less time to set the OLM up than real devices. As a consequence, - remove OlmUtils timers constants - remove related command to patch them in tests scripts - create a new constructor PowerMgmtImpl to allow any timers values - modify OLM OSGi blueprint to set default values for these timers (Default values are the ones recommended in the OpenROADM whitepaper) - modify lighty build to retrieve these timers from new CLI options - adapt tests scripts and assembly ressources accordingly JIRA: TRNSPRTPCE-496 Signed-off-by: guillaume.lambert Change-Id: I71f9bdfd38c11ea3427ca2e661cd3590bc2863bf --- .../ressources/post_install_for_tests.sh | 3 ++ .../resources/clean-start-controller.sh | 2 +- .../java/io/lighty/controllers/tpce/Main.java | 36 ++++++++++++++----- .../tpce/module/TransportPCEImpl.java | 5 +-- .../io/lighty/controllers/tpce/MaintTest.java | 4 +-- .../transportpce/olm/power/PowerMgmtImpl.java | 34 ++++++++++++++++-- .../transportpce/olm/util/OlmUtils.java | 2 -- .../OSGI-INF/blueprint/olm-blueprint.xml | 15 +++++++- tests/build_controller.sh | 4 --- 9 files changed, 82 insertions(+), 23 deletions(-) diff --git a/karaf/src/main/assembly/ressources/post_install_for_tests.sh b/karaf/src/main/assembly/ressources/post_install_for_tests.sh index 813d9c3f0..a39ebb4f9 100755 --- a/karaf/src/main/assembly/ressources/post_install_for_tests.sh +++ b/karaf/src/main/assembly/ressources/post_install_for_tests.sh @@ -9,6 +9,9 @@ sed 's/8101/ODL_SHELL_PORT/' ../etc/org.apache.karaf.shell.cfg > org.apache.kara sed -e 's/1099/ODL_RMI_REGISTRY_PORT/' -e 's/44444/ODL_RMI_SERVER_PORT/' ../etc/org.apache.karaf.management.cfg > org.apache.karaf.management._template.cfg sed 's/^[#|]websocket-port=8185/websocket-port=ODL_WEBSOCKET_PORT/' ../system/org/opendaylight/netconf/sal-rest-connector-config/[0-9.]*/sal-rest-connector-config-[0-9.]*-restconf.cfg >org.opendaylight.restconf._template.cfg +echo 'timer1=3000' >../etc/org.opendaylight.transportpce.olm.cfg +echo 'timer2=2000' >>../etc/org.opendaylight.transportpce.olm.cfg + sed -i'_' -e '1 a\ \ . \$(dirname \$0)/\.\./\.\./\.\./\.\./tests/reflectwarn.sh\ diff --git a/lighty/src/main/assembly/resources/clean-start-controller.sh b/lighty/src/main/assembly/resources/clean-start-controller.sh index 5fc070765..ad4926ddc 100755 --- a/lighty/src/main/assembly/resources/clean-start-controller.sh +++ b/lighty/src/main/assembly/resources/clean-start-controller.sh @@ -33,4 +33,4 @@ cat config_template.json | sed -e "s/ODL_RESTCONF_PORT/$RESTCONF_PORT/" -e "s/OD cat akka-default_template.conf | sed -e "s/ODL_AKKA_PORT/$AKKA_PORT/" -e "s/ODL_AKKA_MGT_PORT/$AKKA_MGT_PORT/" >singlenode/akka-default.conf #start controller -java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar -restconf config.json +java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar -restconf config.json -olmtimer1 3000 -olmtimer2 2000 diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/Main.java b/lighty/src/main/java/io/lighty/controllers/tpce/Main.java index a1b74f68f..0d84d5e99 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/Main.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/Main.java @@ -46,19 +46,21 @@ import org.slf4j.LoggerFactory; public class Main { private static final String RESTCONF_OPTION_NAME = "restconf"; - private static final String NBINOTIFICATION_OPTION_NAME = "nbinotification"; + private static final String OLMTIMER1_OPTION_NAME = "olmtimer1"; + private static final String OLMTIMER2_OPTION_NAME = "olmtimer2"; private static final Logger LOG = LoggerFactory.getLogger(Main.class); private ShutdownHook shutdownHook; public void start() { - start(null, false, false); + start(null, false, null, null, false); } @SuppressWarnings("checkstyle:Illegalcatch") - public void start(String restConfConfigurationFile, boolean activateNbiNotification, boolean registerShutdownHook) { + public void start(String restConfConfigurationFile, boolean activateNbiNotification, + String olmtimer1, String olmtimer2, boolean registerShutdownHook) { long startTime = System.nanoTime(); TpceBanner.print(); RestConfConfiguration restConfConfig = null; @@ -83,7 +85,7 @@ public class Main { // 3. NETCONF SBP configuration NetconfConfiguration netconfSBPConfig = NetconfConfigUtils.createDefaultNetconfConfiguration(); startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook, - activateNbiNotification); + activateNbiNotification, olmtimer1, olmtimer2); float duration = (System.nanoTime() - startTime) / 1_000_000f; LOG.info("lighty.io and RESTCONF-NETCONF started in {}ms", duration); } catch (ConfigurationException | ExecutionException | IOException e) { @@ -119,15 +121,29 @@ public class Main { .hasArg(false) .required(false) .build(); + Option olmTimer1Option = Option.builder(OLMTIMER1_OPTION_NAME) + .desc("OLM timer 1 value") + .argName(OLMTIMER1_OPTION_NAME) + .hasArg(true) + .required(false) + .build(); + Option olmTimer2Option = Option.builder(OLMTIMER2_OPTION_NAME) + .desc("OLM timer 2 value") + .argName(OLMTIMER1_OPTION_NAME) + .hasArg(true) + .required(false) + .build(); Options options = new Options(); options.addOption(restconfFileOption); options.addOption(useNbiNotificationsOption); + options.addOption(olmTimer1Option); + options.addOption(olmTimer2Option); return options; } private void startLighty(ControllerConfiguration controllerConfiguration, RestConfConfiguration restConfConfiguration, NetconfConfiguration netconfSBPConfiguration, - boolean registerShutdownHook, boolean activateNbiNotification) + boolean registerShutdownHook, boolean activateNbiNotification, String olmtimer1, String olmtimer2) throws ConfigurationException, ExecutionException, InterruptedException { // 1. initialize and start Lighty controller (MD-SAL, Controller, YangTools, @@ -156,7 +172,8 @@ public class Main { netconfSouthboundPlugin.start().get(); // 4. start TransportPCE beans - TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification); + TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification, + olmtimer1, olmtimer2); transportPCE.start().get(); // 5. Register shutdown hook for graceful shutdown. @@ -176,15 +193,18 @@ public class Main { CommandLine commandLine = new DefaultParser().parse(options, args); String restConfConfigurationFile = commandLine.getOptionValue(RESTCONF_OPTION_NAME, null); boolean useNbiNotifications = commandLine.hasOption(NBINOTIFICATION_OPTION_NAME); + String olmtimer1 = commandLine.getOptionValue(OLMTIMER1_OPTION_NAME, null); + String olmtimer2 = commandLine.getOptionValue(OLMTIMER2_OPTION_NAME, null); Main app = new Main(); - app.start(restConfConfigurationFile, useNbiNotifications, true); + app.start(restConfConfigurationFile, useNbiNotifications, olmtimer1, olmtimer2, true); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java -ms -mx -XX:MaxMetaspaceSize= -jar tpce.jar " + "[-restconf ] [-nbinotification]" + " e.g. java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar" - + "-restconf ../src/test/resources/config.json -nbinotification", + + "-restconf ../src/test/resources/config.json -nbinotification" + + "-olmtimer1 120000 -olmtimer2 20000", options); System.exit(1); } diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index 7ea47d278..2f1b3d9f8 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -126,7 +126,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP "ServiceHandler", "RendererListener"); private final List publisherTopicAlarmList = Arrays.asList("ServiceListener"); - public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification) { + public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification, + String olmtimer1, String olmtimer2) { LOG.info("Initializing transaction providers ..."); deviceTransactionManager = new DeviceTransactionManagerImpl(lightyServices.getBindingMountPointService(), MAX_DURATION_TO_SUBMIT_TRANSACTION); @@ -167,7 +168,7 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP LOG.info("Creating OLM beans ..."); CrossConnect crossConnect = initCrossConnect(mappingUtils); PowerMgmt powerMgmt = new PowerMgmtImpl(lightyServices.getBindingDataBroker(), openRoadmInterfaces, - crossConnect, deviceTransactionManager); + crossConnect, deviceTransactionManager, olmtimer1, olmtimer2); OlmPowerService olmPowerService = new OlmPowerServiceImpl(lightyServices.getBindingDataBroker(), powerMgmt, deviceTransactionManager, portMapping, mappingUtils, openRoadmInterfaces); olmProvider = new OlmProvider(lightyServices.getRpcProviderService(), olmPowerService); diff --git a/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java b/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java index de130a4db..872cb5205 100644 --- a/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java +++ b/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java @@ -48,7 +48,7 @@ public class MaintTest { @Test public void startNoConfigFileTest() throws Exception { - main.start(null, false, true); + main.start(null, false, "3000", "2000", true); ContentResponse response = client.GET("http://localhost:8181/restconf/config/ietf-network:networks/network/openroadm-topology"); assertEquals("Response code should be 200", 200, response.getStatus()); } @@ -56,7 +56,7 @@ public class MaintTest { @Test public void startConfigFileTest() throws Exception { File configFile = new File("src/test/resources/config.json"); - main.start(configFile.getAbsolutePath(), false, true); + main.start(configFile.getAbsolutePath(), false, "3000", "2000", true); ContentResponse response = client.GET("http://localhost:8888/restconfCustom/config/ietf-network:networks/network/openroadm-topology"); assertEquals("Response code should be 200", 200, response.getStatus()); } diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java index 407bfae2d..4538ef9b0 100644 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java +++ b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java @@ -41,6 +41,11 @@ public class PowerMgmtImpl implements PowerMgmt { private static final BigDecimal DEFAULT_TPDR_PWR_400G = new BigDecimal(0); private static final String INTERFACE_NOT_PRESENT = "Interface {} on node {} is not present!"; + private long timer1 = 120000; + // openroadm spec value is 120000, functest value is 3000 + private long timer2 = 20000; + // openroadm spec value is 20000, functest value is 2000 + public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces, CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager) { this.db = db; @@ -49,6 +54,29 @@ public class PowerMgmtImpl implements PowerMgmt { this.deviceTransactionManager = deviceTransactionManager; } + public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces, + CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager, + String timer1, String timer2) { + this.db = db; + this.openRoadmInterfaces = openRoadmInterfaces; + this.crossConnect = crossConnect; + this.deviceTransactionManager = deviceTransactionManager; + try { + this.timer1 = Long.parseLong(timer1); + } catch (NumberFormatException e) { + this.timer1 = 120000; + LOG.warn("Failed to retrieve Olm timer1 value from configuration - using default value {}", + this.timer1, e); + } + try { + this.timer2 = Long.parseLong(timer2); + } catch (NumberFormatException e) { + this.timer2 = 20000; + LOG.warn("Failed to retrieve Olm timer2 value from configuration - using default value {}", + this.timer2, e); + } + } + /** * This methods measures power requirement for turning up a WL * from the Spanloss at OTS transmit direction and update @@ -108,7 +136,7 @@ public class PowerMgmtImpl implements PowerMgmt { LOG.info("Transponder OCH connection: {} power updated ", interfaceName); try { LOG.info("Now going in sleep mode"); - Thread.sleep(OlmUtils.OLM_TIMER_1); + Thread.sleep(timer1); } catch (InterruptedException e) { LOG.info("Transponder warmup failed for OCH connection: {}", interfaceName, e); // FIXME shouldn't it be LOG.warn or LOG.error? @@ -159,7 +187,7 @@ public class PowerMgmtImpl implements PowerMgmt { return false; } LOG.info("Roadm-connection: {} updated ", connectionNumber); - Thread.sleep(OlmUtils.OLM_TIMER_2); + Thread.sleep(timer2); // TODO make this timer value configurable via OSGi blueprint // although the value recommended by the white paper is 20 seconds. // At least one vendor product needs 60 seconds @@ -395,7 +423,7 @@ public class PowerMgmtImpl implements PowerMgmt { LOG.warn("Power down failed for Roadm-connection: {}", connectionNumber); return false; } - Thread.sleep(OlmUtils.OLM_TIMER_2); + Thread.sleep(timer2); if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) { LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber); return false; diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java b/olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java index 89455198f..a0b5243d6 100644 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java +++ b/olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java @@ -29,8 +29,6 @@ public final class OlmUtils { private static final Logger LOG = LoggerFactory.getLogger(OlmUtils.class); private static long DATABROKER_READ_TIMEOUT_SECONDS = 120; - public static final long OLM_TIMER_1 = 120000; //#FUNCTESTVAL= 3000; - public static final long OLM_TIMER_2 = 20000; //#FUNCTESTVAL= 2000; /** * This static method returns the port mapping {@link Nodes} for node. diff --git a/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml b/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml index 1460aec5b..10ef220e0 100644 --- a/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml +++ b/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml @@ -9,8 +9,20 @@ and is available at http://www.eclipse.org/legal/epl-v10.html --> + + + + + + + + + + + + + - diff --git a/tests/build_controller.sh b/tests/build_controller.sh index b261d951b..1df5a6cf2 100755 --- a/tests/build_controller.sh +++ b/tests/build_controller.sh @@ -10,8 +10,6 @@ cd $(dirname $0) which mvn >/dev/null || ./installMavenCentOS.sh cd ../ -#patch OLM constant to speed up tests, unnecessary for PCE tests -sed -i'_' 's@=.*//#FUNCTESTVAL=@=@g' olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java if [ "$USE_LIGHTY" != "True" ]; then for suffix in 121 221 71; do rm -rf "karaf$suffix" @@ -23,8 +21,6 @@ fi . "$current_dir"/reflectwarn.sh mvn clean install -B -q -s tests/odl_settings.xml -DskipTests -Dmaven.javadoc.skip=true -Dodlparent.spotbugs.skip -Dodlparent.checkstyle.skip -mv olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java_ olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java - #patch Karaf exec for the same reason at runtime and also to have the possibility to use alternative ports ./karaf/target/assembly/ressources/post_install_for_tests.sh -- 2.36.6