</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
void onSessionUp(BmpSession session);
- void onSessionDown(Exception e);
+ void onSessionDown(Exception exception);
void onMessage(Notification message);
}
import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.BMP_VERSION;
import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.COMMON_HEADER_LENGTH;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractBmpMessageWithTlvParser<T extends Builder<?>> extends AbstractBmpMessageParser {
+public abstract class AbstractBmpMessageWithTlvParser<T extends Builder<?>> extends AbstractBmpMessageParser {
private static final Logger LOG = LoggerFactory.getLogger(AbstractBmpMessageWithTlvParser.class);
final int type = bytes.readUnsignedShort();
final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
- throw new BmpDeserializationException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes()
- + ".");
+ throw new BmpDeserializationException("Wrong length specified. Passed: " + length
+ + "; Expected: <= " + bytes.readableBytes() + ".");
}
final ByteBuf tlvBytes = bytes.readSlice(length);
LOG.trace("Parsing BMP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
final Tlv tlv = this.tlvRegistry.parseTlv(type, tlvBytes);
- if(tlv != null) {
+ if (tlv != null) {
LOG.trace("Parsed BMP TLV {}.", tlv);
addTlv(builder, tlv);
}
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.Notification;
-public abstract class AbstractBmpPerPeerMessageParser<T extends Builder<?>> extends AbstractBmpMessageWithTlvParser<T> {
+public abstract class AbstractBmpPerPeerMessageParser<T extends Builder<?>> extends AbstractBmpMessageWithTlvParser<T> {
private static final int L_FLAG_POS = 1;
private static final int V_FLAG_POS = 0;
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
- if (message instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerHeader) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerHeader messageWithPerPeerHeader =
- (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerHeader) message;
+ if (message
+ instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512
+ .PeerHeader) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerHeader
+ messageWithPerPeerHeader = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp
+ .message.rev150512.PeerHeader) message;
serializePerPeerHeader(messageWithPerPeerHeader.getPeerHeader(), buffer);
}
}
- protected static final PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
+ protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
final PeerType peerType = PeerType.forValue(bytes.readByte());
phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
phBuilder.setIpv4(!flags.get(V_FLAG_POS));
switch (peerType) {
- case L3vpn:
- phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
- break;
- case Local:
- phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
- break;
- case Global:
- default:
- bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
- break;
+ case L3vpn:
+ phBuilder.setPeerDistinguisher(
+ new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
+ break;
+ case Local:
+ phBuilder.setPeerDistinguisher(
+ new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
+ break;
+ case Global:
+ default:
+ bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
+ break;
}
if (phBuilder.isIpv4()) {
bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
final PeerType peerType = peerHeader.getType();
output.writeByte(peerType.getIntValue());
final BitArray flags = new BitArray(FLAGS_SIZE);
- flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() == 0 ? false : true);
+ flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() != 0);
flags.set(V_FLAG_POS, !peerHeader.isIpv4());
flags.toByteBuf(output);
final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
switch (peerType) {
- case L3vpn:
- RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
- break;
- case Local:
- output.writeBytes(peerDistinguisher.getBinary());
- break;
- case Global:
- default:
- output.writeZero(PEER_DISTINGUISHER_SIZE);
- break;
+ case L3vpn:
+ RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
+ break;
+ case Local:
+ output.writeBytes(peerDistinguisher.getBinary());
+ break;
+ case Global:
+ default:
+ output.writeZero(PEER_DISTINGUISHER_SIZE);
+ break;
}
if (peerHeader.isIpv4()) {
output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
package org.opendaylight.protocol.bmp.spi.parser;
-public class BmpDeserializationException extends Exception {
+public final class BmpDeserializationException extends Exception {
private static final long serialVersionUID = -7486453568941661756L;
/**
* Creates new BmpDeserializationException with specific error message.
+ *
* @param message message bound with this exception
*/
public BmpDeserializationException(final String message) {
super(message, null);
}
+
/**
+ * Deserialize existent exception.
+ *
* @param message message bound with this exception
* @param cause cause for the error
*/
public interface BmpMessageParser {
- Notification parseMessage(final ByteBuf bytes) throws BmpDeserializationException;
+ Notification parseMessage(ByteBuf bytes) throws BmpDeserializationException;
}
\ No newline at end of file
public interface BmpMessageSerializer {
- void serializeMessage(final Notification message, final ByteBuf buffer);
+ void serializeMessage(Notification message, ByteBuf buffer);
}
import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.LONG_BYTES_LENGTH;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.SHORT_BYTES_LENGTH;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
-/**
- * Created by cgasparini on 13.5.2015.
- */
public final class TlvUtil {
private TlvUtil() {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Created by cgasparini on 15.5.2015.
- */
public abstract class AbstractBmpExtensionProviderActivator implements AutoCloseable, BmpExtensionProviderActivator {
private static final Logger LOG = LoggerFactory.getLogger(AbstractBmpExtensionProviderActivator.class);
private List<AutoCloseable> registrations;
@GuardedBy("this")
- protected abstract List<AutoCloseable> startImpl(final BmpExtensionProviderContext context);
+ protected abstract List<AutoCloseable> startImpl(BmpExtensionProviderContext context);
@Override
public final void close() {
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public final synchronized void stop() {
Preconditions.checkState(this.registrations != null);
-
- for (final AutoCloseable r : this.registrations) {
+ this.registrations.iterator().forEachRemaining(reg -> {
try {
- r.close();
+ reg.close();
} catch (final Exception e) {
LOG.warn("Failed to close registration", e);
}
- }
-
+ });
this.registrations = null;
}
}
AutoCloseable registerBmpMessageParser(int messageType, BmpMessageParser parser);
- AutoCloseable registerBmpMessageSerializer(Class<? extends Notification> messageClass, BmpMessageSerializer serializer);
+ AutoCloseable registerBmpMessageSerializer(Class<? extends Notification> messageClass,
+ BmpMessageSerializer serializer);
}
}
@Override
- public AutoCloseable registerBmpMessageSerializer(final Class<? extends Notification> messageClass, final BmpMessageSerializer serializer) {
+ public AutoCloseable registerBmpMessageSerializer(final Class<? extends Notification> messageClass,
+ final BmpMessageSerializer serializer) {
return this.bmpMessageRegistry.registerBmpMessageSerializer(messageClass, serializer);
}
}
@Override
- public AutoCloseable registerBmpStatisticsTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpStatisticsTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.bmpStatisticsTlvRegistry.registerBmpTlvSerializer(tlvClass, serializer);
}
}
@Override
- public AutoCloseable registerBmpPeerUpTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpPeerUpTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.bmpPeerUpTlvRegistry.registerBmpTlvSerializer(tlvClass, serializer);
}
}
@Override
- public AutoCloseable registerBmpInitiationTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpInitiationTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.bmpInitiationTlvRegistry.registerBmpTlvSerializer(tlvClass, serializer);
}
}
@Override
- public AutoCloseable registerBmpTerminationTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpTerminationTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.bmpTerminationTlvRegistry.registerBmpTlvSerializer(tlvClass, serializer);
}
}
@Override
- public AutoCloseable registerBmpRouteMirroringTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpRouteMirroringTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.bmpRouteMirroringTlvRegistry.registerBmpTlvSerializer(tlvClass, serializer);
}
public void start() {
LOG.debug("Starting {} BmpExtensionProviderActivator instances", this.extensionActivators.size());
-
- for(final BmpExtensionProviderActivator e : this.extensionActivators) {
- e.start(this.providerContext);
- }
+ this.extensionActivators.forEach(e -> e.start(this.providerContext));
}
@Override
public void close() {
LOG.debug("Stopping {} BmpExtensionProviderActivator instances", this.extensionActivators.size());
-
- for(final BmpExtensionProviderActivator e : this.extensionActivators) {
- e.stop();
- }
+ this.extensionActivators.forEach(BmpExtensionProviderActivator::stop);
}
}
private static final Logger LOG = LoggerFactory.getLogger(SimpleBmpMessageRegistry.class);
- private final HandlerRegistry<DataContainer, BmpMessageParser, BmpMessageSerializer> handlers = new HandlerRegistry<>();
+ private final HandlerRegistry<DataContainer, BmpMessageParser, BmpMessageSerializer> handlers =
+ new HandlerRegistry<>();
@Override
public AutoCloseable registerBmpMessageParser(final int messageType, final BmpMessageParser parser) {
}
@Override
- public AutoCloseable registerBmpMessageSerializer(final Class<? extends Notification> msgClass, final BmpMessageSerializer serializer) {
+ public AutoCloseable registerBmpMessageSerializer(final Class<? extends Notification> msgClass,
+ final BmpMessageSerializer serializer) {
return this.handlers.registerSerializer(msgClass, serializer);
}
}
private static int parseMessageHeader(final ByteBuf buffer) throws BmpDeserializationException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes cannot be null or empty.");
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(),
+ "Array of bytes cannot be null or empty.");
Preconditions.checkArgument(buffer.readableBytes() >= COMMON_HEADER_LENGTH,
- "Too few bytes in passed array. Passed: %s. Expected: >= %s.", buffer.readableBytes(), COMMON_HEADER_LENGTH);
+ "Too few bytes in passed array. Passed: %s. Expected: >= %s.",
+ buffer.readableBytes(), COMMON_HEADER_LENGTH);
final short messageVersion = buffer.readUnsignedByte();
if (messageVersion != BMP_VERSION) {
- throw new BmpDeserializationException("Unsuppoted BMP version. Passed: " + messageVersion + "; Expected: " + BMP_VERSION + ".");
+ throw new BmpDeserializationException("Unsuppoted BMP version. Passed: "
+ + messageVersion + "; Expected: " + BMP_VERSION + ".");
}
final long messageLength = buffer.readUnsignedInt();
final short msgType = buffer.readUnsignedByte();
}
@Override
- public AutoCloseable registerBmpTlvSerializer(final Class<? extends Tlv> tlvClass, final BmpTlvSerializer serializer) {
+ public AutoCloseable registerBmpTlvSerializer(final Class<? extends Tlv> tlvClass,
+ final BmpTlvSerializer serializer) {
return this.handlers.registerSerializer(tlvClass, serializer);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
private final SimpleBmpTlvRegistry registry = new SimpleBmpTlvRegistry();
private final SimpleHandler parser = new SimpleHandler(this.registry);
- private static final byte[] DATA = { 0, 1, 0, 4, 't', 'e', 's', 't' };
+ private static final byte[] DATA = {0, 1, 0, 4, 't', 'e', 's', 't'};
private static final int TYPE = 1;
- public static final BmpTlvSerializer DESCRIPTION_TLV_SERIALIZER = (tlv, output) -> {
+ private static final BmpTlvSerializer DESCRIPTION_TLV_SERIALIZER = (tlv, output) -> {
Preconditions.checkArgument(tlv instanceof DescriptionTlv, "DescriptionTlv is mandatory.");
TlvUtil.formatTlvAscii(TYPE, ((DescriptionTlv) tlv).getDescription(), output);
};
- public static final BmpTlvParser DESCRIPTION_TLV_PARSER = buffer -> {
+ private static final BmpTlvParser DESCRIPTION_TLV_PARSER = buffer -> {
if (buffer == null) {
return null;
}
assertArrayEquals(DATA, ByteArray.getAllBytes(output));
}
- @Test(expected=BmpDeserializationException.class)
+ @Test(expected = BmpDeserializationException.class)
public void testParseCorruptedTlv() throws BmpDeserializationException {
- final byte[] wrongData = { 0, 1, 0, 10, 't', 'e', 's', 't' };
+ final byte[] wrongData = {0, 1, 0, 10, 't', 'e', 's', 't'};
this.parser.parseTlvs(new TlvsBuilder(), Unpooled.wrappedBuffer(wrongData));
}
private static final class SimpleHandler extends AbstractBmpMessageWithTlvParser<TlvsBuilder> {
- public SimpleHandler(final BmpTlvRegistry tlvRegistry) {
+ SimpleHandler(final BmpTlvRegistry tlvRegistry) {
super(tlvRegistry);
}
+
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
}
+
@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
return null;
}
+
@Override
public int getBmpMessageType() {
return 0;
}
+
@Override
protected void addTlv(final TlvsBuilder builder, final Tlv tlv) {
- if(tlv != null && tlv instanceof DescriptionTlv) {
- builder.setDescriptionTlv((DescriptionTlv)tlv);
+ if (tlv != null && tlv instanceof DescriptionTlv) {
+ builder.setDescriptionTlv((DescriptionTlv) tlv);
}
}
}
private AbstractBmpPerPeerMessageParser<?> parser;
private final byte[] ipv6MsgWithDistinguishergBytes = {
(byte) 0x01, (byte) 0xc0,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, //Distinguisher
- (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, //IPV6
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, //2001::01
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, //AS 168
- (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, //Peer BGP ID 1.1.1.2
+ //Distinguisher
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
+ //IPV6 //2001::01
+ (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ //AS 168
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8,
+ //Peer BGP ID 1.1.1.2
+ (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02,
0, 0, 0, 0, 0, 0, 0, 0
};
final byte[] msgBytes = {
(byte) 0x00, (byte) 0x40, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, //IPV4
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01, //192.168.1.1
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, //AS 168
- (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, //Peer BGP ID 1.1.1.1
- (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, // Timestamp
+ //IPV4 192.168.1.1
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01,
+ //AS 168
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8,
+ //Peer BGP ID 1.1.1.1
+ (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01,
+ // Timestamp
+ (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
};
- final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(msgBytes));
+ final PeerHeader perHeader = AbstractBmpPerPeerMessageParser
+ .parsePerPeerHeader(Unpooled.wrappedBuffer(msgBytes));
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
phBuilder.setType(PeerType.forValue(0));
public void testPerPeerHeaderIpv6() {
final PeerHeader perHeader = AbstractBmpPerPeerMessageParser
- .parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
+ .parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
phBuilder.setType(PeerType.L3vpn);
phBuilder.setPeerDistinguisher(new PeerDistinguisher(
- new RouteDistinguisher(new RdTwoOctetAs("0:" + RD))));
+ new RouteDistinguisher(new RdTwoOctetAs("0:" + RD))));
phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
phBuilder.setIpv4(false);
phBuilder.setAddress(new IpAddress(new Ipv6Address("2001::1")));
@Test
public void testSerializeMessageBody() {
final PeerHeader perHeader = AbstractBmpPerPeerMessageParser
- .parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
+ .parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
final PeerUpNotification peerNotif = new PeerUpNotificationBuilder().setPeerHeader(perHeader).build();
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
-/**
- * Created by cgasparini on 19.5.2015.
- */
public class TlvUtilTest {
private static final byte[] TLV_IN = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05};
}
@Test
- public void testFormatTlvASCII() throws Exception {
+ public void testFormatTlvAscii() throws Exception {
ByteBuf out = Unpooled.buffer(TLV_ASCII_OUT.length);
TlvUtil.formatTlvAscii(1, "Name", out);
Assert.assertArrayEquals(TLV_ASCII_OUT, ByteArray.getAllBytes(out));
TlvUtil.formatTlvAscii(1, null, out);
Assert.assertFalse(out.isReadable());
}
-
- @Test(expected=UnsupportedOperationException.class)
- public void testBmpMessageConstantsPrivateConstructor() throws Throwable {
- final Constructor<BmpMessageConstants> c = BmpMessageConstants.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (final InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
- @Test(expected=UnsupportedOperationException.class)
- public void testTlvUtilPrivateConstructor() throws Throwable {
- final Constructor<TlvUtil> c = TlvUtil.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (final InvocationTargetException e) {
- throw e.getCause();
- }
- }
}
\ No newline at end of file
public class AbstractBmpExtensionProviderActivatorTest {
- private final SimpleAbstractBmpExtensionProviderActivator activator = new SimpleAbstractBmpExtensionProviderActivator();
- private static final SimpleBmpExtensionProviderContext context = new SimpleBmpExtensionProviderContext();
+ private final SimpleAbstractBmpExtensionProviderActivator activator =
+ new SimpleAbstractBmpExtensionProviderActivator();
+ private static final SimpleBmpExtensionProviderContext CONTEXT = new SimpleBmpExtensionProviderContext();
@Test
public void testStartActivator() throws BmpDeserializationException {
- this.activator.start(context);
+ this.activator.start(CONTEXT);
this.activator.close();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testStopActivator() {
this.activator.close();
}
package org.opendaylight.protocol.bmp.spi.registry;
import static org.junit.Assert.assertNotNull;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
private static final SimpleBmpMessageRegistry MESSAGE_REGISTRY = new SimpleBmpMessageRegistry();
private static final SimpleBmpExtensionProviderContext CONTEXT = new SimpleBmpExtensionProviderContext();
private static final int TEST_TYPE = 1;
- @Mock BmpTlvParser tlvParser;
- @Mock BmpTlvSerializer tlvSerializer;
+ @Mock
+ private BmpTlvParser tlvParser;
+ @Mock
+ private BmpTlvSerializer tlvSerializer;
@Before
public void setUp() {
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
this.registry.registerBmpMessageSerializer(BmpTestMessage.class, bmpTestParser);
final BmpTestMessage message = new BmpTestMessage(257);
- assertEquals(message.toString(), this.registry.parseMessage(Unpooled.copiedBuffer(BMP_TEST_MESSAGE)).toString());
+ assertEquals(message.toString(), this.registry
+ .parseMessage(Unpooled.copiedBuffer(BMP_TEST_MESSAGE)).toString());
final ByteBuf aggregator = Unpooled.buffer(BMP_TEST_MESSAGE.length);
this.registry.serializeMessage(message, aggregator);
assertArrayEquals(BMP_TEST_MESSAGE, ByteArray.getAllBytes(aggregator));
}
- @Test(expected=BmpDeserializationException.class)
+ @Test(expected = BmpDeserializationException.class)
public void testNotBmpTypeException() throws BmpDeserializationException {
this.exceptionMessage[0] = 0x01;
this.registry.parseMessage(Unpooled.copiedBuffer(this.exceptionMessage));
}
- @Test(expected=BmpDeserializationException.class)
+ @Test(expected = BmpDeserializationException.class)
public void testLengthException() throws BmpDeserializationException {
this.exceptionMessage[4] = 0x01;
this.registry.parseMessage(Unpooled.copiedBuffer(this.exceptionMessage));
}
- @Test(expected=BmpDeserializationException.class)
+ @Test(expected = BmpDeserializationException.class)
public void testInvalidMessageContextException() throws BmpDeserializationException {
- this.registry.parseMessage(Unpooled.copiedBuffer(this.exceptionMessage, 0, this.exceptionMessage.length-2));
+ this.registry.parseMessage(Unpooled.copiedBuffer(this.exceptionMessage, 0,
+ this.exceptionMessage.length - 2));
}
private static final class BmpTestParser extends AbstractBmpMessageParser {
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
- ByteBufWriteUtil.writeUnsignedInt(((BmpTestMessage)message).getValue(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(((BmpTestMessage) message).getValue(), buffer);
}
@Override
private final long value;
- public BmpTestMessage(final long value) {
+ BmpTestMessage(final long value) {
this.value = value;
}
- public long getValue() {
+ long getValue() {
return this.value;
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Before;
public class SimpleBmpTlvRegistryTest {
private final SimpleBmpTlvRegistry bmpTlvRegistry = new SimpleBmpTlvRegistry();
- private final byte[] bytes = new byte[] {
- 1, 2, 3
- };
+ private final byte[] bytes = new byte[]{1, 2, 3};
private final ByteBuf input = Unpooled.wrappedBuffer(this.bytes);
-
- @Mock private BmpTlvParser descriptionTlvParser;
- private static final int descriptionTlvType = 1;
- private static final int otherTlvType = 2;
- @Mock private BmpTlvSerializer descriptionTlvSerializer;
+ private static final int DESCRIPTION_TLV_TYPE = 1;
+ private static final int OTHER_TLV_TYPE = 2;
+ @Mock
+ private BmpTlvParser descriptionTlvParser;
+ @Mock
+ private BmpTlvSerializer descriptionTlvSerializer;
@Before
public void setUp() throws BmpDeserializationException {
MockitoAnnotations.initMocks(this);
- this.bmpTlvRegistry.registerBmpTlvParser(descriptionTlvType, this.descriptionTlvParser);
+ this.bmpTlvRegistry.registerBmpTlvParser(DESCRIPTION_TLV_TYPE, this.descriptionTlvParser);
this.bmpTlvRegistry.registerBmpTlvSerializer(MockDescriptionTlv.class, this.descriptionTlvSerializer);
Mockito.doReturn(new MockDescriptionTlv()).when(this.descriptionTlvParser).parseTlv(this.input);
final ArgumentCaptor<Tlv> tlvArg = ArgumentCaptor.forClass(Tlv.class);
@Test
public void testParserRegistration() {
- assertNotNull(this.bmpTlvRegistry.registerBmpTlvParser(descriptionTlvType, this.descriptionTlvParser));
+ assertNotNull(this.bmpTlvRegistry.registerBmpTlvParser(DESCRIPTION_TLV_TYPE, this.descriptionTlvParser));
}
@Test
public void testSerializerRegistration() {
- assertNotNull(this.bmpTlvRegistry.registerBmpTlvSerializer(MockDescriptionTlv.class, this.descriptionTlvSerializer));
+ assertNotNull(this.bmpTlvRegistry.registerBmpTlvSerializer(MockDescriptionTlv.class,
+ this.descriptionTlvSerializer));
}
@Test
public void testUnrecognizedType() throws BmpDeserializationException {
- assertNull(this.bmpTlvRegistry.parseTlv(otherTlvType, this.input));
+ assertNull(this.bmpTlvRegistry.parseTlv(OTHER_TLV_TYPE, this.input));
final ByteBuf output = Unpooled.EMPTY_BUFFER;
this.bmpTlvRegistry.serializeTlv(new MockTlv(), output);
assertEquals(0, output.readableBytes());
@Test
public void testParseTlv() throws BmpDeserializationException {
- final Tlv output = this.bmpTlvRegistry.parseTlv(descriptionTlvType, this.input);
+ final Tlv output = this.bmpTlvRegistry.parseTlv(DESCRIPTION_TLV_TYPE, this.input);
assertNotNull(output);
assertTrue(output instanceof MockDescriptionTlv);