Wire app config to BasePCEPSessionProposalFactory 51/102451/7
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Sep 2022 10:28:03 +0000 (12:28 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jan 2023 12:54:18 +0000 (13:54 +0100)
Make sure we tie together the proposal factory with its configuration,
so that we can easily create it from users.

JIRA: BGPCEP-962
Change-Id: I99beebf370cecb25272c84df913389aa15480132
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/api/src/main/yang/pcep-config.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BasePCEPSessionProposalFactory.java
pcep/impl/src/main/resources/OSGI-INF/blueprint/pcep-impl.xml
pcep/impl/src/main/yang/pcep-app-config.yang
pcep/topology/topology-api/src/main/yang/network-topology-pcep.yang
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPStatefulPeerProposal.java

index f7beace5f4182d2d8b11cbd45dc93bea71debe2c..84717e2848d9a16f735bc98160ce48eb4c2a43a8 100644 (file)
@@ -20,6 +20,11 @@ module pcep-config {
          accompanies this distribution, and is available at
          http://www.eclipse.org/legal/epl-v10.html";
 
+    revision 2023-01-12 {
+        description "Updated timer definitions to uint8 and split them off
+                     into pcep-session-timers grouping";
+    }
+
     revision 2022-03-28 {
         description "Add ted-name key";
     }
@@ -33,6 +38,22 @@ module pcep-config {
             "Initial revision.";
     }
 
+    grouping pcep-session-timers {
+        leaf dead-timer-value {
+            // FIXME: uint8
+            type uint16;
+            default 120;
+            units seconds;
+        }
+
+        leaf keep-alive-timer-value {
+            // FIXME: uint8
+            type uint16;
+            default 30;
+            units seconds;
+        }
+    }
+
     grouping pcep-config {
         container session-config {
             description "PCEP topology config";
@@ -53,22 +74,12 @@ module pcep-config {
                 default 4189;
             }
 
-            leaf dead-timer-value {
-                type uint16;
-                default 120;
-                units seconds;
-            }
-
-            leaf keep-alive-timer-value {
-                type uint16;
-                default 30;
-                units seconds;
-            }
-
             leaf ted-name {
                 type string;
                 default "example-linkstate-topology";
             }
+
+            uses pcep-session-timers;
         }
     }
 
index fdf6861ad9bff5204731b15905c4a7cb71e9b5b0..dc8e8f0f5b0f0e953fa8dbf66c721c6a37e8a695 100644 (file)
@@ -7,14 +7,16 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import java.net.InetSocketAddress;
 import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.PCEPPeerProposal;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTimers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
@@ -26,14 +28,18 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal
     private static final Logger LOG = LoggerFactory.getLogger(BasePCEPSessionProposalFactory.class);
     private static final int KA_TO_DEADTIMER_RATIO = 4;
 
+    private final @NonNull List<PCEPCapability> capabilities;
     private final int keepAlive;
     private final int deadTimer;
-    private final List<PCEPCapability> capabilities;
+
+    public BasePCEPSessionProposalFactory(final PcepSessionTimers timers, final List<PCEPCapability> capabilities) {
+        this(timers.getDeadTimerValue().toJava(), timers.getKeepAliveTimerValue().toJava(), capabilities);
+    }
 
     public BasePCEPSessionProposalFactory(final int deadTimer, final int keepAlive,
             final List<PCEPCapability> capabilities) {
         if (keepAlive != 0) {
-            Preconditions.checkArgument(keepAlive >= 1, "Minimum value for keep-alive-timer-value is 1");
+            checkArgument(keepAlive >= 1, "Minimum value for keep-alive-timer-value is 1");
             if (deadTimer != 0 && deadTimer / keepAlive != KA_TO_DEADTIMER_RATIO) {
                 LOG.warn("dead-timer-value should be {} times greater than keep-alive-timer-value",
                     KA_TO_DEADTIMER_RATIO);
@@ -46,7 +52,7 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal
     }
 
     private void addTlvs(final InetSocketAddress address, final TlvsBuilder builder) {
-        for (final PCEPCapability capability : this.capabilities) {
+        for (final PCEPCapability capability : capabilities) {
             capability.setCapabilityProposal(address, builder);
         }
     }
@@ -56,11 +62,11 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal
             final PCEPPeerProposal peerProposal) {
         final OpenBuilder oBuilder = new OpenBuilder()
                 .setSessionId(Uint8.valueOf(sessionId))
-                .setKeepalive(Uint8.valueOf(BasePCEPSessionProposalFactory.this.keepAlive));
-        if (BasePCEPSessionProposalFactory.this.keepAlive == 0) {
+                .setKeepalive(Uint8.valueOf(keepAlive));
+        if (keepAlive == 0) {
             oBuilder.setDeadTimer(Uint8.ZERO);
         } else {
-            oBuilder.setDeadTimer(Uint8.valueOf(BasePCEPSessionProposalFactory.this.deadTimer));
+            oBuilder.setDeadTimer(Uint8.valueOf(deadTimer));
         }
 
         final TlvsBuilder builder = new TlvsBuilder();
@@ -74,6 +80,6 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal
 
     @Override
     public List<PCEPCapability> getCapabilities() {
-        return this.capabilities;
+        return capabilities;
     }
 }
index 0e16b74bee82393c6769554f6748a8ede34b1758..0707dc5e7a193bbb0769ee7f7c3de39636f91b7c 100644 (file)
       binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PcepSessionConfig"/>
 
   <bean id="sessionProposalFactory" class="org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory">
-    <argument>
-      <bean factory-ref="pcepSessionConfig" factory-method="getDeadTimerValue"/>
-    </argument>
-    <argument>
-      <bean factory-ref="pcepSessionConfig" factory-method="getKeepAliveTimerValue"/>
-    </argument>
+    <argument ref="pcepSessionConfig"/>
     <argument ref="pcepCapabilities"/>
   </bean>
 
index e517bf2997330c5a520e0658b3f2370a7573dc1f..e3da559bb67cacc751e0efee40a728883850a78f 100644 (file)
@@ -1,33 +1,27 @@
 module pcep-app-config {
-    yang-version 1;
     namespace "urn:opendaylight:params:xml:ns:yang:controller:pcep:app-config";
     prefix "pcep-app-config";
 
     description
-      "Configuration for the PCEP implementation.";
+        "Configuration for the PCEP implementation.
 
-    revision "2016-07-07" {
-        description
-            "Initial revision.
+         Copyright (c) 2016 Brocade Communications Systems, Inc. All rights reserved.
 
-            Copyright (c) 2016 Brocade Communications Systems, Inc. All rights reserved.
+         This program and the accompanying materials are made available
+         under the terms of the Eclipse Public License v1.0 which
+         accompanies this distribution, and is available at
+         http://www.eclipse.org/legal/epl-v10.html";
 
-            This program and the accompanying materials are made available
-            under the terms of the Eclipse Public License v1.0 which
-            accompanies this distribution, and is available at
-            http://www.eclipse.org/legal/epl-v10.html";
+    revision "2016-07-07" {
+        description
+            "Initial revision.";
     }
 
-    container pcep-session-config {
-        leaf dead-timer-value {
-            type uint16;
-            default 120;
-        }
+    import pcep-config { prefix pc; }
 
-        leaf keep-alive-timer-value {
-            type uint16;
-            default 30;
-        }
+    container pcep-session-config {
+        // FIXME: remove this container
+        uses pc:pcep-session-timers;
     }
 
     typedef path-type {
@@ -101,4 +95,4 @@ module pcep-app-config {
             }
         }
     }
-}
\ No newline at end of file
+}
index 13647ee521c3e1c04f6bea9276059101e246c60f..1018a40a6b37507127541f90820927edc4308c21 100644 (file)
@@ -9,7 +9,7 @@ module network-topology-pcep {
     import odl-network-topology { prefix ont; revision-date 2014-01-13; }
     import pcep-types { prefix pcep; revision-date 2018-11-09; }
     import rsvp { prefix rsvp; revision-date 2015-08-20; }
-    import pcep-config { prefix pdc; revision-date 2022-03-28; }
+    import pcep-config { prefix pdc; }
 
     organization "Cisco Systems, Inc.";
     contact "Robert Varga <rovarga@cisco.com>";
index 6791683c57207245db133df7b06290f53354256e..dd1ef27ff916232300e008924b667cf7af8113fe 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.Tlvs3Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.lsp.db.version.tlv.LspDbVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.speaker.entity.id.tlv.SpeakerEntityIdBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev220328.pcep.node.config.SessionConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.node.config.SessionConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Tlvs1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.Node1;