Refactor OLM timers management 67/97367/3
authorguillaume.lambert <guillaume.lambert@orange.com>
Tue, 31 Aug 2021 09:59:25 +0000 (11:59 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Tue, 31 Aug 2021 19:56:40 +0000 (21:56 +0200)
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 <guillaume.lambert@orange.com>
Change-Id: I71f9bdfd38c11ea3427ca2e661cd3590bc2863bf

karaf/src/main/assembly/ressources/post_install_for_tests.sh
lighty/src/main/assembly/resources/clean-start-controller.sh
lighty/src/main/java/io/lighty/controllers/tpce/Main.java
lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java
olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java
olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java
olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml
tests/build_controller.sh

index 813d9c3f05933a67603da05200a1e5851b953f62..a39ebb4f9c0a41bfb1a2e57c0171c53dec4259f2 100755 (executable)
@@ -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\
index 5fc0707656b937ef9ae8b379ed69e1d81295399e..ad4926ddc42df34c97dfae4afc89f5c037ac02a8 100755 (executable)
@@ -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
index a1b74f68f05838ae71c1eae650c63d872003cf9d..0d84d5e99b38af82d45d6339b57a6d0d85f3ef9f 100644 (file)
@@ -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<size> -mx<size> -XX:MaxMetaspaceSize=<size> -jar tpce.jar "
                     + "[-restconf <restconfConfigurationFile>] [-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);
         }
index 7ea47d2780420d1884ea15bcb063c62226a892a0..2f1b3d9f8cbf7479d3ec362ca6a767b4ba6d7c3a 100644 (file)
@@ -126,7 +126,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
             "ServiceHandler", "RendererListener");
     private final List<String> 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);
index de130a4db56548b2e51af3d34c31aa2051ea95b0..872cb52050706e17fc6381076409d6f0b677350b 100644 (file)
@@ -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());
     }
index 407bfae2d22426a8d2931ff90f49c7cfafa8536e..4538ef9b0940e2b99cb53d751b71b44641675713 100644 (file)
@@ -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;
index 89455198f50370c1d4eb73a7374d9c6d0c479149..a0b5243d6e680f0bcfc3926a3bcabacb1717c979 100644 (file)
@@ -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.
index 1460aec5b4373f53c2fcd780a171dfcbf8fc93f9..10ef220e0edf39425c85d9ed9ca3c5504ff2b4d1 100644 (file)
@@ -9,8 +9,20 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+      xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
       odl:use-default-for-reference-types="true">
 
+    <cm:property-placeholder persistent-id="org.opendaylight.transportpce.olm" update-strategy="reload">
+        <cm:default-properties>
+            <cm:property name="timer1" value="120000" />
+            <cm:property name="timer2" value="20000" />
+            <!--The following values are used to speed-up tests with simulators without convergence times-->
+            <!--cm:property name="timer1" value="3000" /-->
+            <!--cm:property name="timer2" value="2000" /-->
+        </cm:default-properties>
+    </cm:property-placeholder>
+
+
   <reference id="dataBroker"
         interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
   <reference id="rpcProviderService"
@@ -41,6 +53,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <argument ref="openRoadmInterfaces" />
     <argument ref="crossConnect" />
     <argument ref="deviceTransactionManager" />
+    <argument value="${timer1}"/>
+    <argument value="${timer2}"/>
   </bean>
 
   <bean id="provider"
@@ -52,5 +66,4 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <service ref="olmPowerServiceImpl"
         interface="org.opendaylight.transportpce.olm.service.OlmPowerService"/>
-
 </blueprint>
index b261d951b2516d82b0f3d1996cf552396af3fe30..1df5a6cf2abd87bf44644e6a9b7c28acf2927865 100755 (executable)
@@ -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