Correct PCEP timer definitions 52/102452/7
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Sep 2022 13:49:55 +0000 (15:49 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jan 2023 12:54:22 +0000 (13:54 +0100)
The timers have an uint8 range by definition, correct that.

JIRA: BGPCEP-1017
Change-Id: Ie2f59a1859c54883730cd2fd89b5f7efc67a8c7e
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/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/Main.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCsBuilder.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockTest.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java

index 84717e2848d9a16f735bc98160ce48eb4c2a43a8..18b7da1d7fd61004d8250306d333631360c7dd32 100644 (file)
@@ -40,15 +40,13 @@ module pcep-config {
 
     grouping pcep-session-timers {
         leaf dead-timer-value {
-            // FIXME: uint8
-            type uint16;
+            type uint8;
             default 120;
             units seconds;
         }
 
         leaf keep-alive-timer-value {
-            // FIXME: uint8
-            type uint16;
+            type uint8;
             default 30;
             units seconds;
         }
index dc8e8f0f5b0f0e953fa8dbf66c721c6a37e8a695..61f447c21bd9ab0ee0e95b7eac15bb374ce71916 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import java.net.InetSocketAddress;
@@ -29,53 +28,47 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal
     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 @NonNull Uint8 keepAlive;
+    private final @NonNull Uint8 deadTimer;
 
     public BasePCEPSessionProposalFactory(final PcepSessionTimers timers, final List<PCEPCapability> capabilities) {
-        this(timers.getDeadTimerValue().toJava(), timers.getKeepAliveTimerValue().toJava(), capabilities);
+        this(timers.getDeadTimerValue(), timers.getKeepAliveTimerValue(), capabilities);
     }
 
-    public BasePCEPSessionProposalFactory(final int deadTimer, final int keepAlive,
+    public BasePCEPSessionProposalFactory(final Uint8 deadTimer, final Uint8 keepAlive,
             final List<PCEPCapability> capabilities) {
-        if (keepAlive != 0) {
-            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);
-            }
-        }
-
-        this.deadTimer = deadTimer;
-        this.keepAlive = keepAlive;
+        this.keepAlive = requireNonNull(keepAlive);
         this.capabilities = requireNonNull(capabilities);
-    }
 
-    private void addTlvs(final InetSocketAddress address, final TlvsBuilder builder) {
-        for (final PCEPCapability capability : capabilities) {
-            capability.setCapabilityProposal(address, builder);
+        if (!Uint8.ZERO.equals(keepAlive)) {
+            this.deadTimer = requireNonNull(deadTimer);
+            if (!Uint8.ZERO.equals(deadTimer) && deadTimer.toJava() / keepAlive.toJava() != KA_TO_DEADTIMER_RATIO) {
+                LOG.warn("dead-timer-value ({}) should be {} times greater than keep-alive-timer-value ({}}",
+                    deadTimer, KA_TO_DEADTIMER_RATIO, keepAlive);
+            }
+        } else {
+            this.deadTimer = Uint8.ZERO;
         }
     }
 
     @Override
     public Open getSessionProposal(final InetSocketAddress address, final int sessionId,
             final PCEPPeerProposal peerProposal) {
-        final OpenBuilder oBuilder = new OpenBuilder()
-                .setSessionId(Uint8.valueOf(sessionId))
-                .setKeepalive(Uint8.valueOf(keepAlive));
-        if (keepAlive == 0) {
-            oBuilder.setDeadTimer(Uint8.ZERO);
-        } else {
-            oBuilder.setDeadTimer(Uint8.valueOf(deadTimer));
+        final var builder = new TlvsBuilder();
+        for (final var capability : capabilities) {
+            capability.setCapabilityProposal(address, builder);
         }
 
-        final TlvsBuilder builder = new TlvsBuilder();
-        addTlvs(address, builder);
-
         if (peerProposal != null) {
             peerProposal.setPeerSpecificProposal(address, builder);
         }
-        return oBuilder.setTlvs(builder.build()).build();
+
+        return new OpenBuilder()
+            .setSessionId(Uint8.valueOf(sessionId))
+            .setKeepalive(keepAlive)
+            .setDeadTimer(deadTimer)
+            .setTlvs(builder.build())
+            .build();
     }
 
     @Override
index c4c43b5d8642c0a9074b398f5dc6a460159cc543..b2614b1c87d1657342ca920a262c0c938c10bf99 100644 (file)
@@ -27,6 +27,7 @@ import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import org.checkerframework.checker.index.qual.NonNegative;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -120,12 +121,13 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler<Message> implem
             this.maxUnknownMessages = maxUnknownMessages;
         }
 
-        if (getDeadTimerValue() != 0) {
-            channel.eventLoop().schedule(this::handleDeadTimer, getDeadTimerValue(), TimeUnit.SECONDS);
+        final var deadValue = getDeadTimerValue();
+        if (deadValue != 0) {
+            channel.eventLoop().schedule(this::handleDeadTimer, deadValue, TimeUnit.SECONDS);
         }
-
-        if (getKeepAliveTimerValue() != 0) {
-            channel.eventLoop().schedule(this::handleKeepaliveTimer, getKeepAliveTimerValue(), TimeUnit.SECONDS);
+        final var keepAliveValue = getKeepAliveTimerValue();
+        if (keepAliveValue != 0) {
+            channel.eventLoop().schedule(this::handleKeepaliveTimer, keepAliveValue, TimeUnit.SECONDS);
         }
 
         LOG.info("Session {}[{}] <-> {}[{}] started",
@@ -133,12 +135,12 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler<Message> implem
         sessionState = new PCEPSessionState(remoteOpen, localOpen, channel);
     }
 
-    public final Integer getKeepAliveTimerValue() {
-        return localOpen.getKeepalive().intValue();
+    public final @NonNegative short getKeepAliveTimerValue() {
+        return localOpen.getKeepalive().toJava();
     }
 
-    public final Integer getDeadTimerValue() {
-        return remoteOpen.getDeadTimer().intValue();
+    public final @NonNegative short getDeadTimerValue() {
+        return remoteOpen.getDeadTimer().toJava();
     }
 
     /**
index 0ddbaf3de1a1cac162895c14c179bb75a339ae8f..3503a618617482f26ad26616a8d8fd538ccabc02 100644 (file)
@@ -53,11 +53,12 @@ import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.DefaultPCEPExtensionConsumerContext;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class PCEPDispatcherImplTest {
-    private static final short DEAD_TIMER = 120;
-    private static final short KEEP_ALIVE = 30;
+    private static final Uint8 DEAD_TIMER = Uint8.valueOf(120);
+    private static final Uint8 KEEP_ALIVE = Uint8.valueOf(30);
     private static final int RETRY_TIMER = 0;
     private static final int CONNECT_TIMEOUT = 500;
 
@@ -120,12 +121,12 @@ public class PCEPDispatcherImplTest {
 
         assertTrue(futureChannel.channel().isActive());
         assertEquals(clientAddr1.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
-        assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
-        assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
+        assertEquals(DEAD_TIMER.toJava(), session1.getDeadTimerValue());
+        assertEquals(KEEP_ALIVE.toJava(), session1.getKeepAliveTimerValue());
 
         assertEquals(clientAddr2.getAddress().getHostAddress(), session2.getPeerPref().getIpAddress());
-        assertEquals(DEAD_TIMER, session2.getDeadTimerValue().shortValue());
-        assertEquals(KEEP_ALIVE, session2.getKeepAliveTimerValue().shortValue());
+        assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
+        assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
 
         session1.close();
         session2.close();
@@ -171,16 +172,16 @@ public class PCEPDispatcherImplTest {
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
         assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
-        assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
-        assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
+        assertEquals(DEAD_TIMER.toJava(), session1.getDeadTimerValue());
+        assertEquals(KEEP_ALIVE.toJava(), session1.getKeepAliveTimerValue());
         session1.closeChannel().sync();
 
         final PCEPSessionImpl session2 = pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
         assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
-        assertEquals(DEAD_TIMER, session2.getDeadTimerValue().shortValue());
-        assertEquals(KEEP_ALIVE, session2.getKeepAliveTimerValue().shortValue());
+        assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
+        assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
 
         session2.close();
     }
index 846d7d640a44a3cf84a34199a5cf77314962a6ab..03335b24477f8973644bf9fead4277ac703508bf 100755 (executable)
@@ -20,6 +20,7 @@ import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.ietf.stateful.PCEPStatefulCapability;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,13 +29,13 @@ public final class Main {
 
     private static final int DEFAULT_REMOTE_PORT = 4189;
     private static final int DEFAULT_LOCAL_PORT = 0;
-    private static final short DEFAULT_KEEP_ALIVE = 30;
-    private static final short DEFAULT_DEAD_TIMER = 120;
+    private static final Uint8 DEFAULT_KEEP_ALIVE = Uint8.valueOf(30);
+    private static final Uint8 DEFAULT_DEAD_TIMER = Uint8.valueOf(120);
     private static final InetAddress LOCALHOST = InetAddresses.forString("127.0.0.1");
-    private static boolean triggeredInitSync = Boolean.FALSE;
-    private static boolean includeDbv = Boolean.FALSE;
-    private static boolean incrementalSync = Boolean.FALSE;
-    private static boolean triggeredResync = Boolean.FALSE;
+    private static boolean triggeredInitSync = false;
+    private static boolean includeDbv = false;
+    private static boolean incrementalSync = false;
+    private static boolean triggeredResync = false;
     private static Uint64 syncOptDBVersion;
     private static int reconnectAfterXSeconds;
     private static int disonnectAfterXSeconds;
@@ -51,8 +52,8 @@ public final class Main {
         int lsps = 1;
         boolean pcError = false;
         final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-        short ka = DEFAULT_KEEP_ALIVE;
-        short dt = DEFAULT_DEAD_TIMER;
+        Uint8 ka = DEFAULT_KEEP_ALIVE;
+        Uint8 dt = DEFAULT_DEAD_TIMER;
         String password = null;
         long reconnectTime = -1;
         int redelegationTimeout = 0;
@@ -82,11 +83,11 @@ public final class Main {
                     break;
                 case "--keepalive":
                 case "-ka":
-                    ka = Short.valueOf(args[++argIdx]);
+                    ka = Uint8.valueOf(args[++argIdx]);
                     break;
                 case "--deadtimer":
                 case "-d":
-                    dt = Short.valueOf(args[++argIdx]);
+                    dt = Uint8.valueOf(args[++argIdx]);
                     break;
                 case "--password":
                     password = args[++argIdx];
@@ -102,7 +103,7 @@ public final class Main {
                     break;
                 case "--state-sync-avoidance":
                     //"--state-sync-avoidance 10, 5, 10
-                    includeDbv = Boolean.TRUE;
+                    includeDbv = true;
                     final Long dbVersionAfterReconnect = Long.valueOf(args[++argIdx]);
                     disonnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
                     reconnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
@@ -110,8 +111,8 @@ public final class Main {
                     break;
                 case "--incremental-sync-procedure":
                     //TODO Check that DBv > Lsp always ??
-                    includeDbv = Boolean.TRUE;
-                    incrementalSync = Boolean.TRUE;
+                    includeDbv = true;
+                    incrementalSync = true;
                     //Version of database to be used after restart
                     final Long initialDbVersionAfterReconnect = Long.valueOf(args[++argIdx]);
                     disonnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
@@ -119,10 +120,10 @@ public final class Main {
                     syncOptDBVersion = Uint64.valueOf(initialDbVersionAfterReconnect);
                     break;
                 case "--triggered-initial-sync":
-                    triggeredInitSync = Boolean.TRUE;
+                    triggeredInitSync = true;
                     break;
                 case "--triggered-re-sync":
-                    triggeredResync = Boolean.TRUE;
+                    triggeredResync = true;
                     break;
                 default:
                     LOG.warn("WARNING: Unrecognized argument: {}", args[argIdx]);
index ce6e978ac1f9028085ab03fbdbf9fb11b6dc10f8..f623b393c77b4499e488375cdb5e638dd599abed 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.pcc.mock;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import io.netty.util.HashedWheelTimer;
@@ -29,6 +31,7 @@ import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCSessionListener;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.DefaultPCEPExtensionConsumerContext;
 import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 final class PCCsBuilder {
     private final int lsps;
@@ -36,8 +39,8 @@ final class PCCsBuilder {
     private final int pccCount;
     private final InetSocketAddress localAddress;
     private final List<InetSocketAddress> remoteAddress;
-    private final short keepAlive;
-    private final short deadTimer;
+    private final Uint8 keepAlive;
+    private final Uint8 deadTimer;
     private final String password;
     private final long reconnectTime;
     private final int redelegationTimeout;
@@ -48,15 +51,16 @@ final class PCCsBuilder {
 
     PCCsBuilder(final int lsps, final boolean pcError, final int pccCount,
             final @NonNull InetSocketAddress localAddress, final @NonNull List<InetSocketAddress> remoteAddress,
-            final short keepAlive, final short deadTimer, final @Nullable String password, final long reconnectTime,
-            final int redelegationTimeout, final int stateTimeout, final @NonNull PCEPCapability pcepCapabilities) {
+            final @NonNull Uint8 keepAlive, final @NonNull Uint8 deadTimer, final @Nullable String password,
+            final long reconnectTime, final int redelegationTimeout, final int stateTimeout,
+            final @NonNull PCEPCapability pcepCapabilities) {
         this.lsps = lsps;
         this.pcError = pcError;
         this.pccCount = pccCount;
         this.localAddress = localAddress;
         this.remoteAddress = remoteAddress;
-        this.keepAlive = keepAlive;
-        this.deadTimer = deadTimer;
+        this.keepAlive = requireNonNull(keepAlive);
+        this.deadTimer = requireNonNull(deadTimer);
         this.password = password;
         this.reconnectTime = reconnectTime;
         this.redelegationTimeout = redelegationTimeout;
index ede2a40d3178047b8aec522d9d3874019217d934..c8eb306ba85240335b531c9c963e8d6f67b138ca 100644 (file)
@@ -18,7 +18,7 @@ import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.Future;
 import java.net.InetSocketAddress;
-import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
 import org.junit.Before;
@@ -38,12 +38,13 @@ import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.DefaultPCEPExtensionConsumerContext;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class PCCDispatcherImplTest {
 
-    private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(10, 40,
-        new ArrayList<>());
+    private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(Uint8.TEN,
+        Uint8.valueOf(40), List.of());
     private final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(PROPOSAL, 0);
 
     private PCCDispatcherImpl dispatcher;
index 0962b836dde2c06dcb81f46b8a00b57e6e61cd79..1291c828b105c4b094788d53479b655c1ac13ab0 100644 (file)
@@ -60,10 +60,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.Reports;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
 import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public abstract class PCCMockCommon {
-    private static final short KEEP_ALIVE = 30;
-    private static final short DEAD_TIMER = 120;
+    private static final Uint8 KEEP_ALIVE = Uint8.valueOf(30);
+    private static final Uint8 DEAD_TIMER = Uint8.valueOf(120);
     private static final long SLEEP_FOR = 50;
     private final int port = InetSocketAddressUtil.getRandomPort();
     final InetSocketAddress remoteAddress = InetSocketAddressUtil
@@ -180,11 +181,11 @@ public abstract class PCCMockCommon {
         assertEquals(startingDBVersion, pceDBVersion);
     }
 
-    static void checkSession(final PCEPSession session, final int expectedDeadTimer,
-            final int expectedKeepAlive) {
+    static void checkSession(final PCEPSession session, final Uint8 expectedDeadTimer,
+            final Uint8 expectedKeepAlive) {
         assertNotNull(session);
-        assertEquals(expectedDeadTimer, session.getPeerPref().getDeadtimer().shortValue());
-        assertEquals(expectedKeepAlive, session.getPeerPref().getKeepalive().shortValue());
+        assertEquals(expectedDeadTimer, session.getPeerPref().getDeadtimer());
+        assertEquals(expectedKeepAlive, session.getPeerPref().getKeepalive());
         final Stateful1 stateful = session.getRemoteTlvs().augmentation(Tlvs1.class)
                 .getStateful().augmentation(Stateful1.class);
         assertTrue(stateful.getInitiation());
index 02884424199f3e8ac3cbf0a685a095a976e2c6d3..e625c3e56ced3bdffd9c92d0efad0156c12cdc55 100644 (file)
@@ -15,26 +15,27 @@ import java.util.List;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public final class PCCMockTest extends PCCMockCommon {
     private final String localAddress2 = "127.0.0.2";
     private final String localIpAddress = "127.0.0.1";
     private final String[] mainInput = new String[]{"--local-address", localIpAddress,
-        "--remote-address", InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1",
+        "--remote-address", InetSocketAddressUtil.toHostAndPort(remoteAddress).toString(), "--pcc", "1",
         "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
         "--redelegation-timeout", "0", "--state-timeout", "-1"};
 
     @Test
     public void testSessionEstablishment() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
-        final Channel channel = createServer(factory, this.remoteAddress);
-        Main.main(this.mainInput);
+        final Channel channel = createServer(factory, remoteAddress);
+        Main.main(mainInput);
         Thread.sleep(1000);
         //3 reported LSPs + syc
         final int numMessages = 4;
         final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory,
-                this.localIpAddress);
-        checkSession(sessionListener.getSession(), 40, 10);
+                localIpAddress);
+        checkSession(sessionListener.getSession(), Uint8.valueOf(40), Uint8.TEN);
     }
 
 
@@ -51,21 +52,21 @@ public final class PCCMockTest extends PCCMockCommon {
         final Channel channel2 = createServer(factory2, serverAddress3);
         final Channel channel3 = createServer(factory3, serverAddress4);
 
-        Main.main(new String[]{"--local-address", this.localIpAddress, "--remote-address",
+        Main.main(new String[]{"--local-address", localIpAddress, "--remote-address",
                 InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + ","
                         + InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + ","
                         + InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(), "--pcc", "2"});
         Thread.sleep(1000);
         //PCE1
         final int numMessages = 2;
-        checkSessionListener(numMessages, channel, factory, this.localIpAddress);
-        checkSessionListener(numMessages, channel, factory, this.localAddress2);
+        checkSessionListener(numMessages, channel, factory, localIpAddress);
+        checkSessionListener(numMessages, channel, factory, localAddress2);
         //PCE2
-        checkSessionListener(numMessages, channel2, factory2, this.localIpAddress);
-        checkSessionListener(numMessages, channel2, factory2, this.localAddress2);
+        checkSessionListener(numMessages, channel2, factory2, localIpAddress);
+        checkSessionListener(numMessages, channel2, factory2, localAddress2);
         //PCE3
-        checkSessionListener(numMessages, channel3, factory3, this.localIpAddress);
-        checkSessionListener(numMessages, channel3, factory3, this.localAddress2);
+        checkSessionListener(numMessages, channel3, factory3, localIpAddress);
+        checkSessionListener(numMessages, channel3, factory3, localAddress2);
     }
 
     @Override
index cbdf024b224655aa938e3d6ead75fc695836ee14..3ee6c3ca011d4422399e96fe1a3f2628f61a170f 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,7 +70,7 @@ public final class Main {
 
             + "With no parameters, this help is printed.";
     private static final int KA_TO_DEADTIMER_RATIO = 4;
-    private static final int KA_DEFAULT = 30;
+    private static final Uint8 KA_DEFAULT = Uint8.valueOf(30);
     private static final int MAX_UNKNOWN_MESSAGES = 5;
 
     private Main() {
@@ -83,8 +84,8 @@ public final class Main {
         }
 
         InetSocketAddress address = null;
-        int keepAliveValue = KA_DEFAULT;
-        int deadTimerValue = 0;
+        Uint8 keepAliveValue = KA_DEFAULT;
+        Uint8 deadTimerValue = Uint8.ZERO;
         boolean stateful = false;
         boolean active = false;
         boolean instant = false;
@@ -96,10 +97,10 @@ public final class Main {
                 address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
                 pos++;
             } else if (args[pos].equalsIgnoreCase("-d") || args[pos].equalsIgnoreCase("--deadtimer")) {
-                deadTimerValue = Integer.parseInt(args[pos + 1]);
+                deadTimerValue = Uint8.valueOf(args[pos + 1]);
                 pos++;
             } else if (args[pos].equalsIgnoreCase("-ka") || args[pos].equalsIgnoreCase("--keepalive")) {
-                keepAliveValue = Integer.parseInt(args[pos + 1]);
+                keepAliveValue = Uint8.valueOf(args[pos + 1]);
                 pos++;
             } else if (args[pos].equalsIgnoreCase("--stateful")) {
                 stateful = true;
@@ -114,12 +115,12 @@ public final class Main {
             }
             pos++;
         }
-        if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * KA_TO_DEADTIMER_RATIO) {
+        if (Uint8.ZERO.equals(deadTimerValue)) {
+            final var newValue = keepAliveValue.toJava() * KA_TO_DEADTIMER_RATIO;
+            deadTimerValue = newValue <= Uint8.MAX_VALUE.toJava() ? Uint8.valueOf(newValue) : Uint8.MAX_VALUE;
+        } else if (deadTimerValue.toJava() != keepAliveValue.toJava() * KA_TO_DEADTIMER_RATIO) {
             LOG.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
         }
-        if (deadTimerValue == 0) {
-            deadTimerValue = keepAliveValue * KA_TO_DEADTIMER_RATIO;
-        }
 
         final List<PCEPCapability> caps = new ArrayList<>();
         caps.add(new PCEPStatefulCapability(stateful, active, instant, false, false, false, false));
index a7a97e438d9620fdccd98ff7245f6c8413b70191..800c692d6bf2c6edf3debff4a3bebbadf4d38323 100644 (file)
@@ -7,22 +7,19 @@
  */
 package org.opendaylight.protocol.pcep.testtool;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import com.google.common.net.HostAndPort;
 import java.net.InetSocketAddress;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.protocol.concepts.KeyMapping;
-import org.opendaylight.protocol.pcep.PCEPCapability;
-import org.opendaylight.protocol.pcep.PCEPSession;
-import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
-import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
 import org.opendaylight.protocol.pcep.spi.pojo.DefaultPCEPExtensionConsumerContext;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public final class PCCMock {
     private PCCMock() {
@@ -30,17 +27,15 @@ public final class PCCMock {
     }
 
     public static void main(final String[] args) throws InterruptedException, ExecutionException {
-        Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
-        final List<PCEPCapability> caps = new ArrayList<>();
-        final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
-        final PCEPSessionNegotiatorFactory<? extends PCEPSession> snf
-            = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
-        final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
-        final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHost(), serverHostAndPort
-                .getPortOrDefault(12345));
-        final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
+        checkArgument(args.length > 0, "Host and port of server must be provided.");
+        final var proposal = new BasePCEPSessionProposalFactory(Uint8.valueOf(120), Uint8.valueOf(30), List.of());
+        final var snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
+        final var serverHostAndPort = HostAndPort.fromString(args[0]);
+        final var serverAddr = new InetSocketAddress(serverHostAndPort.getHost(),
+            serverHostAndPort.getPortOrDefault(12345));
+        final var clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
 
-        try (PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(
+        try (var pccDispatcher = new PCCDispatcherImpl(
                 new DefaultPCEPExtensionConsumerContext().getMessageHandlerRegistry())) {
             pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf, KeyMapping.of(), clientAddr)
                 .get();