From: guillaume.lambert Date: Mon, 14 Oct 2019 09:34:05 +0000 (+0200) Subject: clean pcep/impl X-Git-Tag: release/magnesium~59 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=2ca13d429f46caeb10c245c3bf352282d8964eeb;p=bgpcep.git clean pcep/impl - Fix remaining checkstyle errors, mainly IllegalCatch - Remove superfluous from PCEPValidatorTest, PcepXROSubobjectParserTest, PcepRROSubobjectParserTest and PcepEROSubobjectParserTest - Remove call to deprecated functions JIRA: BGPCEP-715 Signed-off-by: guillaume.lambert Co-authored-by: Olivier Dugeon Change-Id: Ifff40512f2861246692fbad41de77882c461b2d0 Signed-off-by: Olivier Dugeon --- diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractSessionNegotiator.java index 5d6407dde3..85cdc6ec1b 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractSessionNegotiator.java @@ -55,6 +55,7 @@ public abstract class AbstractSessionNegotiator extends ChannelInboundHandlerAda } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public final void channelActive(final ChannelHandlerContext ctx) { LOG.debug("Starting session negotiation on channel {}", this.channel); @@ -68,6 +69,7 @@ public abstract class AbstractSessionNegotiator extends ChannelInboundHandlerAda } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public final void channelRead(final ChannelHandlerContext ctx, final Object msg) { LOG.debug("Negotiation read invoked on channel {}", this.channel); diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java index e676f403b1..b24189d8de 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java @@ -16,6 +16,7 @@ import org.opendaylight.protocol.pcep.PCEPSessionListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls; 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.yangtools.yang.common.Uint8; public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator { private final PCEPSessionListener listener; @@ -27,9 +28,12 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot super(promise, channel); super.setTlsConfiguration(tlsConfiguration); this.maxUnknownMessages = maxUnknownMessages; - this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()) - .setDeadTimer(localPrefs.getDeadTimer()).setSessionId( - sessionId).setTlvs(localPrefs.getTlvs()).build(); + this.myLocalPrefs = new OpenBuilder() + .setKeepalive(localPrefs.getKeepalive()) + .setDeadTimer(localPrefs.getDeadTimer()) + .setSessionId(Uint8.valueOf(sessionId)) + .setTlvs(localPrefs.getTlvs()) + .build(); this.listener = requireNonNull(listener); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPProtocolSessionPromise.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPProtocolSessionPromise.java old mode 100755 new mode 100644 index 80aa22248f..971ce73441 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPProtocolSessionPromise.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPProtocolSessionPromise.java @@ -45,6 +45,7 @@ public final class PCEPProtocolSessionPromise extends Def this.bootstrap = requireNonNull(bootstrap); } + @SuppressWarnings("checkstyle:IllegalCatch") synchronized void connect() { final PCEPProtocolSessionPromise lock = this; @@ -59,7 +60,7 @@ public final class PCEPProtocolSessionPromise extends Def final ChannelFuture connectFuture = this.bootstrap.connect(); connectFuture.addListener(new BootstrapConnectListener()); this.pending = connectFuture; - } catch (Exception e) { + } catch (RuntimeException e) { LOG.info("Failed to connect to {}", this.address, e); this.setFailure(e); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java index ba52e0ef2b..ef17f90f4d 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java @@ -50,6 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder; 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.open.Tlvs; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -248,7 +249,7 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler implem LOG.info("Closing PCEP session with reason {}: {}", reason, this); sendMessage(new CloseBuilder().setCCloseMessage( new CCloseMessageBuilder().setCClose(new CCloseBuilder() - .setReason(reason.getShortValue()).build()).build()).build()); + .setReason(Uint8.valueOf(reason.getShortValue())).build()).build()).build()); } else { LOG.info("Closing PCEP session: {}", this); } @@ -370,10 +371,11 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler implem } @VisibleForTesting + @SuppressWarnings("checkstyle:IllegalCatch") void sessionUp() { try { this.listener.onSessionUp(this); - } catch (final Exception e) { + } catch (final RuntimeException e) { handleException(e); throw e; } @@ -405,15 +407,11 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler implem } @Override - public final synchronized void channelInactive(final ChannelHandlerContext ctx) { + //similar to bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java + public final synchronized void channelInactive(final ChannelHandlerContext ctx) throws Exception { LOG.debug("Channel {} inactive.", ctx.channel()); endOfInput(); - - try { - super.channelInactive(ctx); - } catch (final Exception e) { - throw new IllegalStateException("Failed to delegate channel inactive event on channel " + ctx.channel(), e); - } + super.channelInactive(ctx); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionNegotiator.java index a6cdeade71..022e3f1ee4 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionNegotiator.java @@ -38,6 +38,8 @@ public class PCEPSessionNegotiator extends AbstractSessionNegotiator { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") + //similar to bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java protected void startNegotiation() throws ExecutionException { final Object lock = this; diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionState.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionState.java index 72edcd73be..ce5dd96852 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionState.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionState.java @@ -26,6 +26,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage; 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.pcep.error.object.ErrorObject; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; final class PCEPSessionState { private final Open localOpen; @@ -55,15 +57,15 @@ final class PCEPSessionState { } Messages getMessages(final int unknownMessagesCount) { - this.errorsBuilder.setReceivedErrorMsgCount(this.receivedErrMsgCount); - this.errorsBuilder.setSentErrorMsgCount(this.sentErrMsgCount); - this.errorsBuilder.setLastReceivedError(this.lastReceivedErrorBuilder.build()); - this.errorsBuilder.setLastSentError(this.lastSentErrorBuilder.build()); - this.msgsBuilder.setLastSentMsgTimestamp(this.lastSentMsgTimestamp); - this.msgsBuilder.setReceivedMsgCount(this.receivedMsgCount); - this.msgsBuilder.setSentMsgCount(this.sentMsgCount); - this.msgsBuilder.setUnknownMsgReceived(unknownMessagesCount); - this.msgsBuilder.setErrorMessages(this.errorsBuilder.build()); + this.errorsBuilder.setReceivedErrorMsgCount(Uint32.valueOf(this.receivedErrMsgCount)) + .setSentErrorMsgCount(Uint32.valueOf(this.sentErrMsgCount)) + .setLastReceivedError(this.lastReceivedErrorBuilder.build()) + .setLastSentError(this.lastSentErrorBuilder.build()); + this.msgsBuilder.setLastSentMsgTimestamp(Uint32.valueOf(this.lastSentMsgTimestamp)) + .setReceivedMsgCount(Uint32.valueOf(this.receivedMsgCount)) + .setSentMsgCount(Uint32.valueOf(this.sentMsgCount)) + .setUnknownMsgReceived(Uint16.valueOf(unknownMessagesCount)) + .setErrorMessages(this.errorsBuilder.build()); return this.msgsBuilder.build(); } @@ -72,11 +74,11 @@ final class PCEPSessionState { } private static LocalPref getLocalPref(final Open open, final Channel channel) { - final LocalPrefBuilder peerBuilder = new LocalPrefBuilder(); - peerBuilder.setDeadtimer(open.getDeadTimer()); - peerBuilder.setKeepalive(open.getKeepalive()); - peerBuilder.setIpAddress(((InetSocketAddress) channel.localAddress()).getAddress().getHostAddress()); - peerBuilder.setSessionId(open.getSessionId().intValue()); + final LocalPrefBuilder peerBuilder = new LocalPrefBuilder() + .setDeadtimer(open.getDeadTimer()) + .setKeepalive(open.getKeepalive()) + .setIpAddress(((InetSocketAddress) channel.localAddress()).getAddress().getHostAddress()) + .setSessionId(Uint16.valueOf(open.getSessionId().intValue())); return peerBuilder.build(); } @@ -87,15 +89,13 @@ final class PCEPSessionState { void setLastSentError(final Message msg) { this.sentErrMsgCount++; final ErrorObject errObj = getErrorObject(msg); - this.lastSentErrorBuilder.setErrorType(errObj.getType()); - this.lastSentErrorBuilder.setErrorValue(errObj.getValue()); + this.lastSentErrorBuilder.setErrorType(errObj.getType()).setErrorValue(errObj.getValue()); } void setLastReceivedError(final Message msg) { final ErrorObject errObj = getErrorObject(msg); this.receivedErrMsgCount++; - this.lastReceivedErrorBuilder.setErrorType(errObj.getType()); - this.lastReceivedErrorBuilder.setErrorValue(errObj.getValue()); + this.lastReceivedErrorBuilder.setErrorType(errObj.getType()).setErrorValue(errObj.getValue()); } void updateLastReceivedMsg() { @@ -116,10 +116,10 @@ final class PCEPSessionState { private static PeerPref getRemotePref(final Open open, final Channel channel) { final PeerPrefBuilder peerBuilder = new PeerPrefBuilder(); - peerBuilder.setDeadtimer(open.getDeadTimer()); - peerBuilder.setKeepalive(open.getKeepalive()); - peerBuilder.setIpAddress(((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress()); - peerBuilder.setSessionId(open.getSessionId().intValue()); + peerBuilder.setDeadtimer(open.getDeadTimer()) + .setKeepalive(open.getKeepalive()) + .setIpAddress(((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress()) + .setSessionId(Uint16.valueOf(open.getSessionId().intValue())); return peerBuilder.build(); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/spi/Util.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/spi/Util.java index 4b7619874e..ca2330208a 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/spi/Util.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/spi/Util.java @@ -29,16 +29,17 @@ public final class Util { throw new UnsupportedOperationException(); } - public static Message createErrorMessage(final PCEPErrors error, final Open t) { + public static Message createErrorMessage(final PCEPErrors error, final Open openObject) { final PcerrBuilder errMessageBuilder = new PcerrBuilder(); final ErrorObject err = new ErrorObjectBuilder().setType(error.getErrorType()).setValue(error.getErrorValue()).build(); - if (t == null) { + if (openObject == null) { return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList( new ErrorsBuilder().setErrorObject(err).build())).build()).build(); } - final ErrorType type = new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(t).build()).build(); + final ErrorType type = + new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(openObject).build()).build(); return errMessageBuilder.setPcerrMessage( new PcerrMessageBuilder() .setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())) diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslContextFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslContextFactory.java index 1681ec59b8..bd71f1f274 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslContextFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslContextFactory.java @@ -10,8 +10,11 @@ package org.opendaylight.protocol.pcep.impl.tls; import static java.util.Objects.requireNonNull; import java.io.IOException; +import java.security.KeyManagementException; import java.security.KeyStore; +import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -57,7 +60,7 @@ public class SslContextFactory { final SSLContext serverContext = SSLContext.getInstance(PROTOCOL); serverContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); return serverContext; - } catch (final IOException e) { + } catch (final IOException | KeyStoreException e) { LOG.warn( "IOException - Failed to load keystore / truststore. Failed to initialize the server-side SSLContext", e); @@ -65,8 +68,10 @@ public class SslContextFactory { LOG.warn( "NoSuchAlgorithmException - Unsupported algorithm. Failed to initialize the server-side SSLContext", e); } catch (final CertificateException e) { - LOG.warn("CertificateException - Unable to access certificate (check password). Failed to initialize the server-side SSLContext", e); - } catch (final Exception e) { + LOG.warn( + "CertificateException - Unable to get a certificate (check password) to set the server-side SSLContext", + e); + } catch (final KeyManagementException | UnrecoverableKeyException | NullPointerException e) { LOG.warn("Exception - Failed to initialize the server-side SSLContext", e); } //TODO try to use default SSLContext instance? diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java index 0749d17766..b3d2a67cb6 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java @@ -82,14 +82,15 @@ public class AbstractPCEPSessionTest { protected SimpleSessionListener listener; + @SuppressWarnings("unchecked") @Before public final void setUp() { MockitoAnnotations.initMocks(this); - final ChannelFuture future = new DefaultChannelPromise(this.channel); + final ChannelFuture cfuture = new DefaultChannelPromise(this.channel); doAnswer(invocation -> { final Object[] args = invocation.getArguments(); AbstractPCEPSessionTest.this.msgsSend.add((Notification) args[0]); - return future; + return cfuture; }).when(this.channel).writeAndFlush(any(Notification.class)); doReturn(this.channelFuture).when(this.channel).closeFuture(); doReturn(this.channelFuture).when(this.channelFuture).addListener(any(GenericFutureListener.class)); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java old mode 100755 new mode 100644 index 8369fc6115..a72396ec66 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java @@ -245,6 +245,7 @@ public class PCEPDispatcherImplTest { return p; } + @SuppressWarnings("checkstyle:EmptyBlock") private static void setChannelFactory(final Bootstrap bootstrap) { try { bootstrap.channel(NioSocketChannel.class); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java index b6009dc547..6efb76b257 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java @@ -71,7 +71,8 @@ public class PCEPSessionImplTest extends AbstractPCEPSessionTest { Assert.assertTrue(this.msgsSend.get(0) instanceof Pcerr); final Pcerr pcErr = (Pcerr) this.msgsSend.get(0); final ErrorObject errorObj = pcErr.getPcerrMessage().getErrors().get(0).getErrorObject(); - Assert.assertEquals(PCEPErrors.ATTEMPT_2ND_SESSION, PCEPErrors.forValue(errorObj.getType(), errorObj.getValue())); + Assert.assertEquals( + PCEPErrors.ATTEMPT_2ND_SESSION, PCEPErrors.forValue(errorObj.getType(), errorObj.getValue())); } @Test @@ -162,6 +163,7 @@ public class PCEPSessionImplTest extends AbstractPCEPSessionTest { } @Test + @SuppressWarnings({"checkstyle:IllegalCatch","checkstyle:EmptyBlock"}) public void testSessionRecoveryOnException() { this.listener = new SimpleExceptionSessionListener(); this.session = Mockito.spy(new PCEPSessionImpl(this.listener, 0, this.channel, diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java index 3239ffc27d..eed8c4e849 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java @@ -473,15 +473,15 @@ public class PCEPValidatorTest { new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message .pcreq.message.RequestsBuilder(); rBuilder1.setRp(this.rpTrue); - final P2pBuilder p2pBuilder = new P2pBuilder(); - p2pBuilder.setEndpointsObj(this.endpoints); - p2pBuilder.setMetrics(Lists.newArrayList(this.metrics)); - p2pBuilder.setIro(this.iro); + final P2pBuilder p2pBuilder = new P2pBuilder() + .setEndpointsObj(this.endpoints) + .setMetrics(Lists.newArrayList(this.metrics)) + .setIro(this.iro); rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build()); reqs2.add(rBuilder1.build()); - builder.setRequests(reqs2); - builder.setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep - .types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build())); + builder.setRequests(reqs2) + .setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep + .types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build())); assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); @@ -498,10 +498,10 @@ public class PCEPValidatorTest { new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message .pcreq.message.RequestsBuilder(); rBuilder2.setRp(new RpBuilder(this.rpTrue).setP2mp(true).build()); - final EndpointsObjBuilder epBuilder = new EndpointsObjBuilder(); - epBuilder.setIgnore(false); - epBuilder.setProcessingRule(true); - epBuilder.setAddressFamily(new P2mpIpv4CaseBuilder() + final EndpointsObjBuilder epBuilder = new EndpointsObjBuilder() + .setIgnore(false) + .setProcessingRule(true) + .setAddressFamily(new P2mpIpv4CaseBuilder() .setP2mpIpv4(new P2mpIpv4Builder() .setP2mpLeaves(P2mpLeaves.NewLeavesToAdd) .setSourceIpv4Address(new Ipv4AddressNoZone("255.255.255.255")) @@ -565,8 +565,7 @@ public class PCEPValidatorTest { .build()); rBuilder2.setSegmentComputation(new SegmentComputationBuilder().setP2mp(p2mpBuilder.build()).build()); reqs3.add(rBuilder2.build()); - builder.setRequests(reqs3); - builder.setSvec(null); + builder.setRequests(reqs3).setSvec(null); assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); @@ -651,12 +650,12 @@ public class PCEPValidatorTest { repliesBuilder = new RepliesBuilder(); repliesBuilder.setRp(this.rpTrue); final List paths = new ArrayList<>(); - final PathsBuilder paBuilder = new PathsBuilder(); - paBuilder.setEro(this.ero); - paBuilder.setLspa(this.lspa); - paBuilder.setMetrics(Lists.newArrayList(this.metrics)); - paBuilder.setIro(this.iro); - paBuilder.setOf(this.of); + final PathsBuilder paBuilder = new PathsBuilder() + .setEro(this.ero) + .setLspa(this.lspa) + .setMetrics(Lists.newArrayList(this.metrics)) + .setIro(this.iro) + .setOf(this.of); paths.add(paBuilder.build()); repliesBuilder.setResult(new SuccessCaseBuilder() .setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build(); @@ -833,9 +832,9 @@ public class PCEPValidatorTest { RepliesBuilder repliesBuilder = new RepliesBuilder(); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin")); final List replies = new ArrayList<>(); - repliesBuilder = new RepliesBuilder(); - repliesBuilder.setRp(this.rpTrue); - repliesBuilder.setVendorInformationObject(this.viObjects); + repliesBuilder = new RepliesBuilder() + .setRp(this.rpTrue) + .setVendorInformationObject(this.viObjects); final List paths = new ArrayList<>(); final PathsBuilder paBuilder = new PathsBuilder(); paBuilder.setEro(this.ero); @@ -856,9 +855,9 @@ public class PCEPValidatorTest { public void testMonRepMsg() throws PCEPDeserializerException, IOException { final PCEPMonitoringReplyMessageParser parser = new PCEPMonitoringReplyMessageParser(this.objectRegistry); final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder(); - builder.setMonitoring(this.monitoring); - builder.setMonitoringMetricsList(new GeneralMetricsListBuilder() - .setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build()); + builder.setMonitoring(this.monitoring) + .setMonitoringMetricsList(new GeneralMetricsListBuilder() + .setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build()); final byte[] msgBytes = { 0x20, 0x09, 0x00, 0x18, @@ -911,18 +910,18 @@ public class PCEPValidatorTest { final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin")); final List replies4 = new ArrayList<>(); - repliesBuilder = new RepliesBuilder(); - repliesBuilder.setRp(this.rpTrue); - repliesBuilder.setMonitoring(this.monitoring); - repliesBuilder.setPccIdReq(this.pccIdReq); - repliesBuilder.setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())); + repliesBuilder = new RepliesBuilder() + .setRp(this.rpTrue) + .setMonitoring(this.monitoring) + .setPccIdReq(this.pccIdReq) + .setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())); final List paths = new ArrayList<>(); - final PathsBuilder paBuilder = new PathsBuilder(); - paBuilder.setEro(this.ero); - paBuilder.setLspa(this.lspa); - paBuilder.setMetrics(Lists.newArrayList(this.metrics)); - paBuilder.setIro(this.iro); - paBuilder.setOf(this.of); + final PathsBuilder paBuilder = new PathsBuilder() + .setEro(this.ero) + .setLspa(this.lspa) + .setMetrics(Lists.newArrayList(this.metrics)) + .setIro(this.iro) + .setOf(this.of); paths.add(paBuilder.build()); repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()) .build()).build(); @@ -949,16 +948,15 @@ public class PCEPValidatorTest { .message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message .pcreq.message.RequestsBuilder(); - rBuilder.setRp(this.rpTrue); - rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder() - .setEndpointsObj(this.endpoints).build()).build()); + rBuilder.setRp(this.rpTrue) + .setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder() + .setEndpointsObj(this.endpoints).build()).build()); reqs1.add(rBuilder.build()); - final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder(); - monReqBuilder.setMonitoring(this.monitoring); - monReqBuilder.setPccIdReq(this.pccIdReq); - monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build())); - builder.setMonitoringRequest(monReqBuilder.build()); - builder.setRequests(reqs1); + final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder() + .setMonitoring(this.monitoring) + .setPccIdReq(this.pccIdReq) + .setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build())); + builder.setMonitoringRequest(monReqBuilder.build()).setRequests(reqs1); assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); @@ -973,9 +971,9 @@ public class PCEPValidatorTest { final PCEPMonitoringRequestMessageParser parser = new PCEPMonitoringRequestMessageParser(this.objectRegistry); final PcreqMessageBuilder builder = new PcreqMessageBuilder(); - final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder(); - monReqBuilder.setMonitoring(this.monitoring); - monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build())); + final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder() + .setMonitoring(this.monitoring) + .setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build())); builder.setMonitoringRequest(monReqBuilder.build()); final byte[] msgBytes = { 0x20, 0x08, 0x00, 0x18, @@ -999,17 +997,16 @@ public class PCEPValidatorTest { new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message .pcreq.message.RequestsBuilder(); rBuilder1.setRp(this.rpTrue); - final P2pBuilder p2pBuilder = new P2pBuilder(); - p2pBuilder.setEndpointsObj(this.endpoints); - p2pBuilder.setMetrics(Lists.newArrayList(this.metrics)); - p2pBuilder.setIro(this.iro); + final P2pBuilder p2pBuilder = new P2pBuilder() + .setEndpointsObj(this.endpoints) + .setMetrics(Lists.newArrayList(this.metrics)) + .setIro(this.iro); rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build()); reqs2.add(rBuilder1.build()); - builder.setRequests(reqs2); - builder.setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep - .types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build())); - monReqBuilder.setMonitoring(this.monitoring); - monReqBuilder.setPccIdReq(this.pccIdReq); + builder.setRequests(reqs2) + .setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep + .types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build())); + monReqBuilder.setMonitoring(this.monitoring).setPccIdReq(this.pccIdReq); final PceIdList pceIdList = new PceIdListBuilder().setPceId(this.pceId).build(); monReqBuilder.setPceIdList(Lists.newArrayList(pceIdList, pceIdList)); builder.setMonitoringRequest(monReqBuilder.build()); @@ -1040,10 +1037,10 @@ public class PCEPValidatorTest { repliesBuilder = new RepliesBuilder(); repliesBuilder.setRp(this.rpTrue); final List paths = new ArrayList<>(); - final PathsBuilder paBuilder1 = new PathsBuilder(); - paBuilder1.setEro(this.ero); - paBuilder1.setBandwidth(bwBuilder.build()); - paBuilder1.setMetrics(Lists.newArrayList(this.metrics)); + final PathsBuilder paBuilder1 = new PathsBuilder() + .setEro(this.ero) + .setBandwidth(bwBuilder.build()) + .setMetrics(Lists.newArrayList(this.metrics)); paths.add(paBuilder1.build()); final PathsBuilder paBuilder2 = new PathsBuilder(); paBuilder2.setEro(this.ero); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PcepEROSubobjectParserTest.java similarity index 93% rename from pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java rename to pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PcepEROSubobjectParserTest.java index 0ce2bf7dd9..b93ae3effb 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PcepEROSubobjectParserTest.java @@ -53,7 +53,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; -public class PCEPEROSubobjectParserTest { +public class PcepEROSubobjectParserTest { private static final byte[] IP4_PREFIX_BYTES = { (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 }; @@ -95,10 +95,11 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROIp4PrefixSubobject() throws PCEPDeserializerException { final EROIpv4PrefixSubobjectParser parser = new EROIpv4PrefixSubobjectParser(); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix( - new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build()); + final SubobjectBuilder subs = new SubobjectBuilder() + .setLoose(true) + .setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix( + new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()) + .build()); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(IP4_PREFIX_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); @@ -215,11 +216,10 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROPathKey32Subobject() throws PCEPDeserializerException { final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser(); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - final PathKeyBuilder pBuilder = new PathKeyBuilder(); - pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })); - pBuilder.setPathKey(new PathKey(Uint16.valueOf(4660))); + final SubobjectBuilder subs = new SubobjectBuilder().setLoose(true); + final PathKeyBuilder pBuilder = new PathKeyBuilder() + .setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })) + .setPathKey(new PathKey(Uint16.valueOf(4660))); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY32_BYTES, 2)), true)); @@ -244,15 +244,14 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROPathKey128Subobject() throws PCEPDeserializerException { final EROPathKey128SubobjectParser parser = new EROPathKey128SubobjectParser(); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - final PathKeyBuilder pBuilder = new PathKeyBuilder(); - pBuilder.setPceId(new PceId(new byte[] { - (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, - (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00 - })); - pBuilder.setPathKey(new PathKey(Uint16.valueOf(4660))); + final SubobjectBuilder subs = new SubobjectBuilder().setLoose(true); + final PathKeyBuilder pBuilder = new PathKeyBuilder() + .setPceId(new PceId(new byte[] { + (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, + (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00 + })) + .setPathKey(new PathKey(Uint16.valueOf(4660))); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY128_BYTES, 2)), true)); @@ -311,7 +310,7 @@ public class PCEPEROSubobjectParserTest { } @Test - public void testEROEXRSSubobject() throws Exception { + public void testERO_EXRSSubobject() throws Exception { final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser( this.ctx.getXROSubobjectHandlerRegistry()); final List c = Util.class.getDeclaredConstructor(); c.setAccessible(true);