This fixes all but one violation.
Change-Id: I4b34e87cc43946f9bddd485f57573355d076bebf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
twoOctetSpecificEcHandler.getSubType(), twoOctetSpecificEcHandler));
regs.add(context.registerExtendedCommunityParser(twoOctetSpecificEcHandler.getType(false),
twoOctetSpecificEcHandler.getSubType(), twoOctetSpecificEcHandler));
- regs.add(context.registerExtendedCommunitySerializer(AsSpecificExtendedCommunityCase.class, twoOctetSpecificEcHandler));
+ regs.add(context.registerExtendedCommunitySerializer(AsSpecificExtendedCommunityCase.class,
+ twoOctetSpecificEcHandler));
final Ipv4SpecificEcHandler ipv4SpecificEcHandler = new Ipv4SpecificEcHandler();
regs.add(context.registerExtendedCommunityParser(ipv4SpecificEcHandler.getType(true),
regs.add(context.registerExtendedCommunitySerializer(As4RouteTargetExtendedCommunityCase.class, rt4ASHandler));
final RouteOrigin4OctectASEcHandler rOrig4Oct = new RouteOrigin4OctectASEcHandler();
- regs.add(context.registerExtendedCommunityParser(rOrig4Oct.getType(true)
- , rOrig4Oct.getSubType(), rOrig4Oct));
+ regs.add(context.registerExtendedCommunityParser(rOrig4Oct.getType(true), rOrig4Oct.getSubType(), rOrig4Oct));
regs.add(context.registerExtendedCommunitySerializer(As4RouteOriginExtendedCommunityCase.class, rOrig4Oct));
final EncapsulationEC encapsulationECHandler = new EncapsulationEC();
}
/**
- * Parses given byte array to BGP Open message
+ * Parses given byte array to BGP Open message.
*
* @param body byte array representing BGP Open message, without header
* @param messageLength the length of the message
}
final Optional<BGPTreatAsWithdrawException> withdrawCause;
if (totalPathAttrLength > 0) {
- final ParsedAttributes attributes;
- try {
- attributes = this.reg.parseAttributes(buffer.readSlice(totalPathAttrLength), constraint);
- } catch (final RuntimeException | BGPParsingException e) {
- // Catch everything else and turn it into a BGPDocumentedException
- throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
- }
+ final ParsedAttributes attributes = parseAttributes(buffer, totalPathAttrLength, constraint);
builder.setAttributes(attributes.getAttributes());
withdrawCause = attributes.getWithdrawCause();
} else {
return msg;
}
+ @SuppressWarnings("checkstyle:illegalCatch")
+ private ParsedAttributes parseAttributes(final ByteBuf buffer, final int totalPathAttrLength,
+ final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
+ try {
+ return reg.parseAttributes(buffer.readSlice(totalPathAttrLength), constraint);
+ } catch (final RuntimeException | BGPParsingException e) {
+ // Catch everything else and turn it into a BGPDocumentedException
+ throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
+ }
+ }
+
/**
- * Check for presence of well known mandatory path attributes
- * ORIGIN, AS_PATH and NEXT_HOP in Update message
+ * Check for presence of well known mandatory path attributes ORIGIN, AS_PATH and NEXT_HOP in Update message.
*
* @param message Update message
- * @throws BGPDocumentedException
*/
private static void checkMandatoryAttributesPresence(final Update message) throws BGPDocumentedException {
requireNonNull(message, "Update message cannot be null");
}
final SendReceive sendReceive = SendReceive.forValue(buffer.readUnsignedByte());
if (sendReceive != null) {
- families.add(new AddressFamiliesBuilder().setAfi(afi).setSafi(safi).setSendReceive(sendReceive).build());
+ families.add(new AddressFamiliesBuilder().setAfi(afi).setSafi(safi).setSendReceive(sendReceive)
+ .build());
}
}
- return new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(families).build()).build()).build();
+ return new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder()
+ .setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(families).build()).build()).build();
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil;
public final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
public static final int CODE = 65;
+
@Override
- public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
- return new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(buffer.readUnsignedInt())).build()).build();
+ public CParameters parseCapability(final ByteBuf buffer) {
+ return new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder()
+ .setAsNumber(new AsNumber(buffer.readUnsignedInt())).build()).build();
}
@Override
@Override
public BgpParameters parseParameter(final ByteBuf buffer) throws BGPParsingException, BGPDocumentedException {
- Preconditions.checkArgument(buffer != null && buffer.readableBytes() != 0, "Byte array cannot be null or empty.");
+ Preconditions.checkArgument(buffer != null && buffer.readableBytes() != 0,
+ "Byte array cannot be null or empty.");
if (LOG.isTraceEnabled()) {
LOG.trace("Started parsing of BGP Capabilities: {}", Arrays.toString(ByteArray.getAllBytes(buffer)));
return new BgpParametersBuilder().setOptionalCapabilities(optionalCapas).build();
}
- private OptionalCapabilities parseOptionalCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+ private OptionalCapabilities parseOptionalCapability(final ByteBuf buffer) throws BGPDocumentedException,
+ BGPParsingException {
final int capCode = buffer.readUnsignedByte();
final int capLength = buffer.readUnsignedByte();
final ByteBuf paramBody = buffer.readSlice(capLength);
private final AddressFamilyRegistry afiReg;
private final SubsequentAddressFamilyRegistry safiReg;
- public GracefulCapabilityHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
+ public GracefulCapabilityHandler(final AddressFamilyRegistry afiReg,
+ final SubsequentAddressFamilyRegistry safiReg) {
this.afiReg = requireNonNull(afiReg);
this.safiReg = requireNonNull(safiReg);
}
continue;
}
final int flags = buffer.readUnsignedByte();
- tables.add(new TablesBuilder().setAfi(afi).setSafi(safi).setAfiFlags(new AfiFlags((flags & AFI_FLAG_FORWARDING_STATE) != 0)).build());
+ tables.add(new TablesBuilder().setAfi(afi).setSafi(safi)
+ .setAfiFlags(new AfiFlags((flags & AFI_FLAG_FORWARDING_STATE) != 0)).build());
}
cb.setTables(tables);
return new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.math.BigInteger;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
- PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
- if(!buffer.isReadable()) {
- return;
+ final PeerSpecificParserConstraint constraint) {
+ if (buffer.isReadable()) {
+ builder.setAigp(new AigpBuilder().setAigpTlv(parseAigpTLV(buffer)).build());
}
- builder.setAigp(new AigpBuilder().setAigpTlv(parseAigpTLV(buffer)).build());
}
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final Aigp aigpAttribute = attribute.getAigp();
- if (aigpAttribute == null) {
- return;
+ if (aigpAttribute != null) {
+ AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, serializeAigpTLV(aigpAttribute),
+ byteAggregator);
}
- AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, serializeAigpTLV(aigpAttribute), byteAggregator);
}
/**
/**
* Transform AIGP attribute data from instance of Aigp class into byte buffer representation.
*
- * @param aigp
- * instance of Aigp class
- * @return
- * byte buffer representation or empty buffer if AIGP TLV is null
+ * @param aigp instance of Aigp class
+ * @return byte buffer representation or empty buffer if AIGP TLV is null
*/
private static ByteBuf serializeAigpTLV(final Aigp aigp) {
final AigpTlv tlv = aigp.getAigpTlv();
if (asPath.getSegments() != null) {
for (final Segments segments : asPath.getSegments()) {
if (segments.getAsSequence() != null) {
- AsPathSegmentParser.serializeAsList(segments.getAsSequence(), SegmentType.AS_SEQUENCE, segmentsBuffer);
+ AsPathSegmentParser.serializeAsList(segments.getAsSequence(), SegmentType.AS_SEQUENCE,
+ segmentsBuffer);
} else if (segments.getAsSet() != null) {
AsPathSegmentParser.serializeAsList(segments.getAsSet(), SegmentType.AS_SET, segmentsBuffer);
} else {
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SEQUENCE;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SET;
+
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.Collections;
}
private AsPathSegmentParser() {
- throw new UnsupportedOperationException();
}
static int serializeType(final SegmentType type) {
switch (type) {
- case AS_SET:
- return 1;
- case AS_SEQUENCE:
- return 2;
- default:
- return 0;
+ case AS_SET:
+ return 1;
+ case AS_SEQUENCE:
+ return 2;
+ default:
+ return 0;
}
}
static SegmentType parseType(final int type) {
switch (type) {
- case 1:
- return AS_SET;
- case 2:
- return AS_SEQUENCE;
- default:
- return null;
+ case 1:
+ return AS_SET;
+ case 2:
+ return AS_SEQUENCE;
+ default:
+ return null;
}
}
for (int i = 0; i < count; i++) {
coll.add(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt())));
}
- return (coll.isEmpty()) ? Collections.emptyList() : coll;
+ return coll.isEmpty() ? Collections.emptyList() : coll;
}
static void serializeAsList(final List<AsNumber> asList, final SegmentType type, final ByteBuf byteAggregator) {
byteAggregator.writeByte(serializeType(type));
byteAggregator.writeByte(asList.size());
for (final AsNumber asNumber : asList) {
- byteAggregator.writeInt( asNumber.getValue().intValue());
+ byteAggregator.writeInt(asNumber.getValue().intValue());
}
}
}
if (readable % Ipv4Util.IP4_LENGTH != 0) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR,
"Length of CLUSTER_LIST should be a multiple of 4, but is %s", readable);
- }
+ }
final int count = readable / Ipv4Util.IP4_LENGTH;
final List<ClusterIdentifier> list = new ArrayList<>(count);
/**
* Parse known Community, if unknown, a new one will be created.
*
- * @param refCache
+ * @param refCache reference cache
* @param buffer byte array to be parsed
* @return new Community
- * @throws BGPDocumentedException
*/
private static Community parseCommunity(final ReferenceCache refCache, final ByteBuf buffer)
throws BGPDocumentedException {
return create(this.refCache, asn, semantics);
}
- /**
- * Creates a Community from its String representation.
- *
- * @param string String representation of a community
- * @return new Community
- */
- public Community valueOf(final String string) {
- return valueOf(this.refCache, string);
- }
-
/**
* Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
*
return refCache.getSharedReference(builder.build());
}
+ /**
+ * Creates a Community from its String representation.
+ *
+ * @param string String representation of a community
+ * @return new Community
+ */
+ public Community valueOf(final String string) {
+ return valueOf(this.refCache, string);
+ }
+
/**
* Creates a Community from its String representation.
*
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
-public final class MultiExitDiscriminatorAttributeParser extends AbstractAttributeParser implements AttributeSerializer {
-
+public final class MultiExitDiscriminatorAttributeParser extends AbstractAttributeParser
+ implements AttributeSerializer {
public static final int TYPE = 4;
@Override
@Test
public void testCapabilityHandler() throws BGPDocumentedException, BGPParsingException {
final List<AddressFamilies> family = new ArrayList<>();
- family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI).setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(1)).build());
+ family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI)
+ .setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(1)).build());
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer(6);
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safiRegistry);
assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode());
}
- @Test(expected=BGPParsingException.class)
+ @Test(expected = BGPParsingException.class)
public void testAfiException() throws BGPDocumentedException, BGPParsingException {
final ByteBuf bytes = this.parseWrongBytes.copy();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afirExpection, this.safiRegistry);
handler.parseCapability(bytes);
}
- @Test(expected=BGPParsingException.class)
+ @Test(expected = BGPParsingException.class)
public void testSafiException() throws BGPDocumentedException, BGPParsingException {
final ByteBuf bytes = this.parseWrongBytes.copy();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safirException);
@Test
public void testSendReceiveIgnored() throws BGPDocumentedException, BGPParsingException {
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(new ArrayList<>()).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(new ArrayList<>()).build()).build()).build();
final ByteBuf bytes = this.parseWrongBytes.copy();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safiRegistry);
assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode());
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledAfi() {
final List<AddressFamilies> family = new ArrayList<>();
- family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI).setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(2)).build());
+ family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI)
+ .setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(2)).build());
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afirExpection, this.safiRegistry);
handler.serializeCapability(capabilityToSerialize, bytes);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledSafi() {
final List<AddressFamilies> family = new ArrayList<>();
- family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI).setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(3)).build());
+ family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI)
+ .setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(3)).build());
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safirException);
handler.serializeCapability(capabilityToSerialize, bytes);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledSendReceive() {
final List<AddressFamilies> family = new ArrayList<>();
- family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI).setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(4)).build());
+ family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI)
+ .setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(4)).build());
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safiRegistry);
@Test
public void noSerializationTest() {
- final CParameters capabilityNoAugmentation = new CParametersBuilder().addAugmentation(CParameters1.class, null).build();
- final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().build()).build();
+ final CParameters capabilityNoAugmentation = new CParametersBuilder().addAugmentation(CParameters1.class, null)
+ .build();
+ final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().build()).build();
final ByteBuf bytes = Unpooled.buffer();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safirException);
public class BGPParserTest {
/**
- * Used by other tests as well
+ * Used by other tests as well.
*/
static final List<byte[]> inputBytes = new ArrayList<>();
private static final int LENGTH_FIELD_LENGTH = 2;
- private static final String multiPathHexFile = "/bgp-update-multipath.txt";
+ private static final String MULTIPATH_HEX_FILE = "/bgp-update-multipath.txt";
private static List<byte[]> updatesWithMultiplePath;
.getAttributeRegistry());
for (int i = 1; i <= COUNTER; i++) {
final String name = "/up" + i + ".bin";
- try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
+ try (InputStream is = BGPParserTest.class.getResourceAsStream(name)) {
if (is == null) {
throw new IOException("Failed to get resource " + name);
}
final ByteArrayOutputStream bis = new ByteArrayOutputStream();
final byte[] data = new byte[MAX_SIZE];
- int nRead = 0;
- while ((nRead = is.read(data, 0, data.length)) != -1) {
- bis.write(data, 0, nRead);
+ int numRead = 0;
+ while ((numRead = is.read(data, 0, data.length)) != -1) {
+ bis.write(data, 0, numRead);
}
bis.flush();
}
}
updatesWithMultiplePath = HexDumpBGPFileParser.parseMessages(BGPParserTest.class.getResourceAsStream(
- multiPathHexFile));
+ MULTIPATH_HEX_FILE));
constraint = mock(PeerSpecificParserConstraint.class);
mpSupport = mock(MultiPathSupport.class);
Mockito.doReturn(Optional.empty()).when(constraint).getPeerConstraint(Mockito.any());
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
-import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParameters;
@Test
public void testBGPParameter() {
- final MultiprotocolCapability cap = new MultiprotocolCapabilityBuilder().setAfi(Ipv6AddressFamily.class).setSafi(
- UnicastSubsequentAddressFamily.class).build();
+ final MultiprotocolCapability cap = new MultiprotocolCapabilityBuilder().setAfi(Ipv6AddressFamily.class)
+ .setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv1 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
.setMultiprotocolCapability(cap).build()).build();
- final MultiprotocolCapability cap1 = new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(
- UnicastSubsequentAddressFamily.class).build();
+ final MultiprotocolCapability cap1 = new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class)
+ .setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv2 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
.setMultiprotocolCapability(cap1).build()).build();
final List<Tables> tt = new ArrayList<>();
- tt.add(new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
- tt.add(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
+ tt.add(new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .build());
+ tt.add(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .build());
- final GracefulRestartCapability tlv3 = new GracefulRestartCapabilityBuilder().setRestartFlags(new RestartFlags(Boolean.FALSE)).setRestartTime(0).setTables(tt).build();
+ final GracefulRestartCapability tlv3 = new GracefulRestartCapabilityBuilder().setRestartFlags(
+ new RestartFlags(Boolean.FALSE)).setRestartTime(0).setTables(tt).build();
final CParameters tlv4 = new CParametersBuilder().setAs4BytesCapability(
new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build();
assertEquals(40, tlv4.getAs4BytesCapability().getAsNumber().getValue().longValue());
- assertEquals(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build(), tlv4);
+ assertEquals(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
+ new AsNumber((long) 40)).build()).build(), tlv4);
}
@Test
assertEquals(ipv4.getNetworkAddress(), ipv4i.getNetworkAddress());
}
-
- @Test(expected=UnsupportedOperationException.class)
- public void testAsPathSegmentParserPrivateConstructor() throws Throwable {
- final Constructor<AsPathSegmentParser> c = AsPathSegmentParser.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (final InvocationTargetException e) {
- throw e.getCause();
- }
- }
}
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer(capaBytes.length);
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
Assert.assertArrayEquals(capaBytes, buffer.array());
- Assert.assertEquals( new CParametersBuilder().addAugmentation(CParameters1.class,
+ Assert.assertEquals(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(),
handler.parseCapability(Unpooled.wrappedBuffer(capaBytes).slice(2, capaBytes.length - 2)));
tablesBuilder.setAfiFlags(new AfiFlags(false));
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
buffer.clear();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
Assert.assertArrayEquals(capaBytes2, buffer.array());
- Assert.assertEquals( new CParametersBuilder().addAugmentation(CParameters1.class,
+ Assert.assertEquals(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(),
handler.parseCapability(Unpooled.wrappedBuffer(capaBytes2).slice(2, capaBytes2.length - 2)));
capaBuilder.setRestartTime(null);
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
buffer.clear();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
Assert.assertArrayEquals(capaBytes2, buffer.array());
capaBuilder.setRestartFlags(new RestartFlags(false));
capaBuilder.setRestartTime(0);
capaBuilder.setTables(Collections.emptyList());
- Assert.assertEquals( new CParametersBuilder().addAugmentation(CParameters1.class,
+ Assert.assertEquals(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(),
handler.parseCapability(Unpooled.wrappedBuffer(capaBytes3).slice(2, capaBytes3.length - 2)));
(byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00
};
- Assert.assertEquals( new CParametersBuilder().addAugmentation(CParameters1.class,
+ Assert.assertEquals(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(),
handler.parseCapability(Unpooled.wrappedBuffer(capaBytes4).slice(2, capaBytes4.length - 2)));
final byte[] capaBytes5 = {
};
final ByteBuf b = Unpooled.buffer(capaBytes5.length);
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build()).build()).build(), b);
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build())
+ .build()).build(), b);
Assert.assertArrayEquals(capaBytes5, b.array());
Assert.assertEquals(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
- .setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartFlags(new RestartFlags(Boolean.FALSE))
+ .setGracefulRestartCapability(new GracefulRestartCapabilityBuilder()
+ .setRestartFlags(new RestartFlags(Boolean.FALSE))
.setRestartTime(0).setTables(Collections.emptyList()).build()).build()).build(),
handler.parseCapability(Unpooled.wrappedBuffer(capaBytes5).slice(2, capaBytes5.length - 2)));
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledAfi() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(),
this.ctx.getSubsequentAddressFamilyRegistry());
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledSafi() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(),
this.ctx.getSubsequentAddressFamilyRegistry());
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testRestartTimeMinValue() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(),
this.ctx.getSubsequentAddressFamilyRegistry());
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testRestartTimeMaxValue() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(),
this.ctx.getSubsequentAddressFamilyRegistry());
capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
- handler.serializeCapability( new CParametersBuilder().addAugmentation(CParameters1.class,
+ handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class,
new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
-
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
public class IPv6NextHopTest {
-
private Ipv6NextHop nextHopA;
private Ipv6NextHop nextHopB;
@Before
public void init() {
this.nextHopA = new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:7331")).build();
- this.nextHopB = new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:7331")).setLinkLocal(
- new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:0000")).build();
+ this.nextHopB = new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:7331"))
+ .setLinkLocal(new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:0000")).build();
}
@Test
public void testLongLivedGracefulCapabilityHandler() throws BGPParsingException, BGPDocumentedException {
final byte[] capaBytes = {
- //header
- (byte) 0x47, (byte) 0x0e,
- // Ipv4 Unicast, afiFlags = false, timer = 10
- (byte) 0x00, (byte) 0x01, (byte) 0x01,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
- // Ipv6 Unicast, afiFlags = true, timer = 160
- (byte) 0x00, (byte) 0x02, (byte) 0x01,
- (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xa0
+ //header
+ (byte) 0x47, (byte) 0x0e,
+ // Ipv4 Unicast, afiFlags = false, timer = 10
+ (byte) 0x00, (byte) 0x01, (byte) 0x01,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ // Ipv6 Unicast, afiFlags = true, timer = 160
+ (byte) 0x00, (byte) 0x02, (byte) 0x01,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xa0
};
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder()
.slice(2, capaBytes.length - 2)));
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnsupportedAfi() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder()
.setTables(Arrays.asList(new TablesBuilder()
this.handler.serializeCapability(cParameters, buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnsupportedSafi() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder()
.setTables(Arrays.asList(new TablesBuilder()
this.handler.serializeCapability(cParameters, buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMinStaleTime() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder()
.setTables(Arrays.asList(new TablesBuilder()
this.handler.serializeCapability(cParameters, buffer);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMaxStaleTime() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder()
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl;
import static org.junit.Assert.assertEquals;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
public class MultiProtocolCapabilityHandlerTest {
-
private static final Class<Ipv6AddressFamily> AFI = Ipv6AddressFamily.class;
private static final Class<UnicastSubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
@Test
public void testCapabilityHandler() throws BGPDocumentedException, BGPParsingException {
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI).setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI)
+ .setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safir);
assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode());
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledAfi() {
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI).setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI)
+ .setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
- final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afirExpection, this.safir);
+ final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afirExpection,
+ this.safir);
handler.serializeCapability(capabilityToSerialize, bytes);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnhandledSafi() {
- final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI).setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
+ final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI)
+ .setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
- final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safirException);
+ final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir,
+ this.safirException);
handler.serializeCapability(capabilityToSerialize, bytes);
}
@Test
public void noSerializationTest() {
- final CParameters capabilityNoAugmentation = new CParametersBuilder().addAugmentation(CParameters1.class, null).build();
- final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().build()).build();
+ final CParameters capabilityNoAugmentation = new CParametersBuilder().addAugmentation(CParameters1.class, null)
+ .build();
+ final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().build()).build();
final ByteBuf bytes = Unpooled.buffer();
- final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safirException);
+ final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir,
+ this.safirException);
handler.serializeCapability(capabilityNoAugmentation, bytes);
assertEquals(0, bytes.readableBytes());
handler.serializeCapability(capabilityNoMP, bytes);
@Test
public void testSerializeOpen() throws Exception {
final List<OptionalCapabilities> optionalCapas = Lists.newArrayList();
- final OptionalCapabilities optionalCapabilitiesBuilder= new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder()
- .setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).addAugmentation(
- CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder()
- .setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(0).setTables
- (Collections.emptyList()).build()).build()).build()).build();
+ final OptionalCapabilities optionalCapabilitiesBuilder = new OptionalCapabilitiesBuilder()
+ .setCParameters(new CParametersBuilder()
+ .setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build())
+ .addAugmentation(CParameters1.class, new CParameters1Builder()
+ .setGracefulRestartCapability(new GracefulRestartCapabilityBuilder()
+ .setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(0)
+ .setTables(Collections.emptyList()).build())
+ .build())
+ .build())
+ .build();
optionalCapas.add(optionalCapabilitiesBuilder);
- final List<BgpParameters> tlvs = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(optionalCapas).build());
- final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(
- new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
+ final List<BgpParameters> tlvs = Lists.newArrayList(new BgpParametersBuilder()
+ .setOptionalCapabilities(optionalCapas).build());
+ final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30)
+ .setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
final ByteBuf msg = Unpooled.buffer();
- new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry()).serializeMessage(open, msg);
+ new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry())
+ .serializeMessage(open, msg);
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
.getParameterRegistry()).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(open.getHoldTimer(), openResult.getHoldTimer());
assertEquals(open.getMyAsNumber(), openResult.getMyAsNumber());
boolean grace = false;
- if(openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability() != null ) {
+ if (openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters()
+ .getAs4BytesCapability() != null) {
grace = true;
}
- assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability(),
- openResult.getBgpParameters().get(0).getOptionalCapabilities().get(!grace ? 1 : 0).getCParameters().getAs4BytesCapability());
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters()
- .augmentation(CParameters1.class)
- .getGracefulRestartCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters()
+ .getAs4BytesCapability(),
+ openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 0 : 1).getCParameters()
+ .getAs4BytesCapability());
+ assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters()
+ .augmentation(CParameters1.class).getGracefulRestartCapability(),
+ openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters()
.augmentation(CParameters1.class).getGracefulRestartCapability());
}
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.net.UnknownHostException;
import org.opendaylight.yangtools.yang.binding.Notification;
public class ParserTest {
-
- private static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] OPEN_BMSG = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04,
- (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
- (byte) 0x00 };
+ (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+ (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
+ };
- private static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] KEEPALIVE_BMSG = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
+ (byte) 0x00, (byte) 0x13, (byte) 0x04
+ };
- private static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] NOTIFICATION_BMSG = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02,
- (byte) 0x04, (byte) 0x04, (byte) 0x09 };
+ (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09
+ };
- private static final byte[] updMsgWithUnrecognizedAttribute = new byte[] {
+ private static final byte[] UPD_MSG_WITH_UNRECOGNIZED_ATTRIBUTE = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x79, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x62, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x34, (byte) 0x40, (byte) 0x04, (byte) 0x47,
(byte) 0x04, (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b, (byte) 0x00, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte)0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02,
+ (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02,
(byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02,
- (byte)0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
- (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)0x00,
+ (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+ (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x43, (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00,
- (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)0x64, (byte) 0x00,
+ (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte )0x64, (byte) 0x00,
(byte) 0x63, (byte) 0x19, (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x4f, (byte) 0x66,
- (byte) 0x2d, (byte) 0x39, (byte) 0x6b, (byte) 0x2d, (byte) 0x30, (byte)0x33, (byte) 0x04, (byte) 0x03,
+ (byte) 0x2d, (byte) 0x39, (byte) 0x6b, (byte) 0x2d, (byte) 0x30, (byte) 0x33, (byte) 0x04, (byte) 0x03,
(byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2b,
(byte) 0x2b, (byte) 0x2b, (byte) 0x2b
};
// Update message with one IPv4 prefix NLRI and all mandatory path attributes present
- private static final byte[] updMsgWithMandatoryAttributesPresent = new byte[] {
+ private static final byte[] UPD_MSG_WITH_MANDATORY_ATTRIBUTES_PRESENT = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0x00, (byte) 0x38, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1c, (byte) 0x40,
};
// Update message with one IPv4 prefix NLRI and all mandatory path attributes except ORIGIN present
- private static final byte[] updMsgWithOneMandatoryAttributeNotPresent = new byte[] {
+ private static final byte[] UPD_MSG_WITH_ONE_MANDATORY_ATTRIBUTE_NOT_PRESENT = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0x00, (byte) 0x34, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x18, (byte) 0x40,
};
// Update message with one IPv4 prefix NLRI and ORIGIN, AS_PATH and NEXT_HOP mandatory path attributes not present
- private static final byte[] updMsgWithMultipleMandatoryAttributesNotPresent = new byte[] {
+ private static final byte[] UPD_MSG_WITH_MULTIPLE_MANDATORY_ATTRIBUTES_NOT_PRESENT = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0x00, (byte) 0x2a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0e, (byte) 0x80,
(byte) 0xfe, (byte) 0x03
};
- private static final byte[] RR_MSG = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] RR_MSG = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x05, (byte) 0x00, (byte) 0x01,
- (byte) 0x00, (byte) 0x01 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x17, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01
+ };
private static MessageRegistry reg;
@Test
public void testHeaderErrors() throws BGPParsingException, BGPDocumentedException {
- byte[] wrong = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ byte[] wrong = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00
+ };
wrong = ByteArray.cutBytes(wrong, 16);
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(wrong), null);
@Test
public void testBadMsgType() throws BGPParsingException {
- final byte[] bytes = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bytes = {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x08 };
+ (byte) 0x00, (byte) 0x13, (byte) 0x08
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
fail("Exception should have occured.");
final Notification keepAlive = new KeepaliveBuilder().build();
final ByteBuf buffer = Unpooled.buffer();
ParserTest.reg.serializeMessage(keepAlive, buffer);
- assertArrayEquals(keepAliveBMsg, ByteArray.getAllBytes(buffer));
-
- final Notification m = ParserTest.reg.parseMessage(Unpooled.
- copiedBuffer(ByteArray.getAllBytes(buffer)), null);
+ assertArrayEquals(KEEPALIVE_BMSG, ByteArray.getAllBytes(buffer));
+ final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(ByteArray.getAllBytes(buffer)), null);
assertTrue(m instanceof Keepalive);
}
@Test
public void testBadKeepAliveMsg() throws BGPParsingException {
- final byte[] bytes = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bytes = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
new ProtocolVersion((short) 4)).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
- assertArrayEquals(openBMsg, ByteArray.getAllBytes(bytes));
+ assertArrayEquals(OPEN_BMSG, ByteArray.getAllBytes(bytes));
final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
@Test
public void testBadHoldTimeError() throws BGPParsingException {
- final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bMsg = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64,
- (byte) 0x00, (byte) 0x01, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+ (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0x01,
+ (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
@Test
public void testBadMsgLength() throws BGPParsingException {
- final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bMsg = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64,
- (byte) 0x00, (byte) 0xb4, (byte) 0xff, (byte) 0xff, (byte) 0xff };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
@Test
public void testBadVersion() throws BGPParsingException {
- final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bMsg = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x64,
- (byte) 0x00, (byte) 0xb4, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+ (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+ (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
.setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(notMsg, bytes);
- assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(),0,bytes.writerIndex()));
+ assertArrayEquals(NOTIFICATION_BMSG, ByteArray.subByte(bytes.array(),0,bytes.writerIndex()));
- Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
+ Notification msg = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
- assertTrue(m instanceof Notify);
- assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(),
- ((Notify) m).getErrorSubcode()));
- assertArrayEquals(new byte[] { 4, 9 }, ((Notify) m).getData());
+ assertTrue(msg instanceof Notify);
+ assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) msg).getErrorCode(),
+ ((Notify) msg).getErrorSubcode()));
+ assertArrayEquals(new byte[] { 4, 9 }, ((Notify) msg).getData());
notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
ParserTest.reg.serializeMessage(notMsg, bytes);
- m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
+ msg = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
- assertTrue(m instanceof Notify);
- assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(),
- ((Notify) m).getErrorSubcode()));
- assertNull(((Notify) m).getData());
+ assertTrue(msg instanceof Notify);
+ assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) msg).getErrorCode(),
+ ((Notify) msg).getErrorSubcode()));
+ assertNull(((Notify) msg).getData());
}
@Test
public void testWrongLength() throws BGPParsingException {
- final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bMsg = new byte[] {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
@Test
public void testUnrecognizedError() throws BGPParsingException, BGPDocumentedException {
- final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ final byte[] bMsg = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
+ (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa
+ };
try {
ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
@Test
public void testParseUpdMsgWithUnrecognizedAttribute() throws BGPDocumentedException, BGPParsingException {
try {
- reg.parseMessage(Unpooled.copiedBuffer(updMsgWithUnrecognizedAttribute), null);
+ reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_UNRECOGNIZED_ATTRIBUTE), null);
fail("Exception should have occured.");
} catch (final BGPDocumentedException e) {
assertEquals("Well known attribute not recognized.", e.getMessage());
@Test
public void testParseUpdMsgWithMandatoryAttributesPresent() throws BGPDocumentedException, BGPParsingException {
try {
- final Notification msg = reg.parseMessage(Unpooled.copiedBuffer(updMsgWithMandatoryAttributesPresent),
+ final Notification msg = reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_MANDATORY_ATTRIBUTES_PRESENT),
null);
assertTrue(msg instanceof Update);
} catch (final BGPDocumentedException e) {
public void testParseUpdMsgWithOneMandatoryAttributeNotPresent()
throws BGPDocumentedException, BGPParsingException {
try {
- reg.parseMessage(Unpooled.copiedBuffer(updMsgWithOneMandatoryAttributeNotPresent), null);
+ reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_ONE_MANDATORY_ATTRIBUTE_NOT_PRESENT), null);
fail("Exception should have occured.");
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "ORIGIN", e.getMessage());
public void testParseUpdMsgWithMultipleMandatoryAttributesNotPresent()
throws BGPDocumentedException, BGPParsingException {
try {
- reg.parseMessage(Unpooled.copiedBuffer(updMsgWithMultipleMandatoryAttributesNotPresent), null);
+ reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_MULTIPLE_MANDATORY_ATTRIBUTES_NOT_PRESENT), null);
fail("Exception should have occured.");
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "NEXT_HOP", e.getMessage());
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AggregatorBuilder;
public class AggregatorAttributeParserTest {
-
- private static final byte[] ATTRIBUTE_BYTES = {(byte) 0xC0, (byte) 0x07, (byte) 0x08,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01};
+ private static final byte[] ATTRIBUTE_BYTES = {
+ (byte) 0xC0, (byte) 0x07, (byte) 0x08,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01
+ };
private static final Attributes RESULT = new AttributesBuilder()
.setAggregator(new AggregatorBuilder()
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.as.path.SegmentsBuilder;
public class AsPathAttributeParserTest {
-
- private static final byte[] ATTRIBUTE_BYTES = {(byte) 0x40, (byte) 0x02, (byte) 0x14,
- (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x02,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04};
- private static final byte[] EMPTY_ATTRIBUTE_BYTES = {(byte) 0x40, (byte) 0x02, (byte) 0x00};
+ private static final byte[] ATTRIBUTE_BYTES = {
+ (byte) 0x40, (byte) 0x02, (byte) 0x14,
+ (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x02,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04
+ };
+ private static final byte[] EMPTY_ATTRIBUTE_BYTES = { (byte) 0x40, (byte) 0x02, (byte) 0x00 };
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import static org.junit.Assert.assertArrayEquals;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
public class ClusterIdAttributeParserTest {
- private static final byte[] clusterIdBytes = {(byte) 0x80, (byte) 0x0A, (byte) 0x08,
- (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x1,
- (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x2};
+ private static final byte[] CLUSTER_ID_BYTES = {
+ (byte) 0x80, (byte) 0x0A, (byte) 0x08,
+ (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x1, (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x2
+ };
ClusterIdAttributeParser parser;
@Before
final Ipv4Address ip2 = new Ipv4Address("192.168.1.2");
list.add(new ClusterIdentifier(ip1));
list.add(new ClusterIdentifier(ip2));
- final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster
- (list).build()).build();
+ final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
+ .build()).build();
final ByteBuf output = Unpooled.buffer();
this.parser.serializeAttribute(clusterId, output);
- assertArrayEquals(clusterIdBytes, ByteArray.getAllBytes(output));
+ assertArrayEquals(CLUSTER_ID_BYTES, ByteArray.getAllBytes(output));
AttributesBuilder clusterIdOutput = new AttributesBuilder();
- this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(clusterIdBytes, 3)), clusterIdOutput,
+ this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(CLUSTER_ID_BYTES, 3)), clusterIdOutput,
null);
assertEquals(clusterId, clusterIdOutput.build());
}
@Test
public void testParseEmptyListAttribute() {
final List<ClusterIdentifier> list = Lists.newArrayList();
- final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster
- (list).build()).build();
+ final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
+ .build()).build();
final ByteBuf output = Unpooled.buffer();
this.parser.serializeAttribute(clusterId, output);
assertEquals(Unpooled.buffer(), output);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Communities;
public class CommunitiesAttributeParserTest {
-
- private static final byte[] CommunitiesBytes = {(byte) 0xC0, (byte) 0x08, (byte) 0x18,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x1,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x2,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x3,
+ private static final byte[] COMMUNITIES_BYTES = {
+ (byte) 0xC0, (byte) 0x08, (byte) 0x18,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x02,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x03,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x10,
(byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x06,
- (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x07};
+ (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x07
+ };
@Test
public void testCommunitiesAttributeParser() throws Exception {
final ByteBuf actual = Unpooled.buffer();
ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
.serializeAttribute(paBuilder.build(), actual);
- assertArrayEquals(CommunitiesBytes, ByteArray.getAllBytes(actual));
+ assertArrayEquals(COMMUNITIES_BYTES, ByteArray.getAllBytes(actual));
final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
.getAttributeRegistry().parseAttributes(actual, null).getAttributes();
assertEquals(comms, attributeOut.getCommunities());
@Before
public void setUp() {
- final ExtendedCommunityRegistry exReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getExtendedCommunityRegistry();
+ final ExtendedCommunityRegistry exReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
+ .getExtendedCommunityRegistry();
this.handler = new ExtendedCommunitiesAttributeParser(exReg);
}
@Test
public void testExtendedCommunityAttributeParser() throws BGPDocumentedException, BGPParsingException {
- final RouteOriginExtendedCommunityCase routeOrigin = new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
- new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(54L)).setLocalAdministrator(
- new byte[] { 0, 0, 1, 76 }).build()).build();
- final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setTransitive(false).setExtendedCommunity(routeOrigin).build();
+ final RouteOriginExtendedCommunityCase routeOrigin = new RouteOriginExtendedCommunityCaseBuilder()
+ .setRouteOriginExtendedCommunity(new RouteOriginExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber(54L))
+ .setLocalAdministrator(new byte[] { 0, 0, 1, 76 }).build())
+ .build();
+ final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setTransitive(false)
+ .setExtendedCommunity(routeOrigin).build();
final AttributesBuilder attBuilder = new AttributesBuilder();
this.handler.parseAttribute(Unpooled.copiedBuffer(INPUT), attBuilder, null);
public void testEmptyExtendedCommunityAttributeParser() throws BGPDocumentedException, BGPParsingException {
final ByteBuf output = Unpooled.buffer();
this.handler.serializeAttribute(new AttributesBuilder().build(), output);
- assertEquals( Unpooled.buffer(), output);
+ assertEquals(Unpooled.buffer(), output);
}
@Test
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
public class LocalPreferenceAttributeParserTest {
-
- private static final byte[] ATTRIBUTE_BYTES = {(byte) 0x40, (byte) 0x05, (byte) 0x04,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01};
+ private static final byte[] ATTRIBUTE_BYTES = {
+ (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
private static final Attributes RESULT = new AttributesBuilder()
.setLocalPref(new LocalPrefBuilder()
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
public class MultiExitDiscriminatorAttributeParserTest {
-
- private static final byte[] ATTRIBUTE_BYTES = {(byte) 0x80, (byte) 0x04, (byte) 0x04,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01};
+ private static final byte[] ATTRIBUTE_BYTES = {
+ (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
private static final Attributes RESULT = new AttributesBuilder()
.setMultiExitDisc(new MultiExitDiscBuilder().setMed(1L).build()).build();
public class NextHopAttributeParserTest {
- private static final byte[] IPV4_NEXT_HOP_BYTES = {(byte) 0x40, (byte) 0x03, (byte) 0x04,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
- private static final byte[] IPV6_NEXT_HOP_BYTES = {(byte) 0x40, (byte) 0x03, (byte) 0x20,
- (byte) 0xFF, (byte) 0xFF, (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,
- (byte) 0xFF, (byte) 0xFF, (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) 0x02};
+ private static final byte[] IPV4_NEXT_HOP_BYTES = {
+ (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+ };
+ private static final byte[] IPV6_NEXT_HOP_BYTES = {
+ (byte) 0x40, (byte) 0x03, (byte) 0x20, (byte) 0xFF, (byte) 0xFF, (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, (byte) 0xFF, (byte) 0xFF,
+ (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) 0x02
+ };
private static final Attributes IPV4_RESULT = new AttributesBuilder()
.setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
public class OriginatorIdAttributeParserTest {
- private static final byte[] ATTRIBUTE_BYTES = {(byte) 0x80, (byte) 0x09, (byte) 0x04,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
+ private static final byte[] ATTRIBUTE_BYTES = {
+ (byte) 0x80, (byte) 0x09, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+ };
private static final Attributes RESULT = new AttributesBuilder()
.setOriginatorId(new OriginatorIdBuilder()
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import static org.junit.Assert.assertArrayEquals;
@Test
public void testUnrecognizedAttributesSerializer() {
- final byte[] unrecognizedValue1 = { (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35 };
- final byte[] unrecognizedValue2 = { (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75 };
- final byte[] unrecognizedBytes = { (byte)0xe0, 0x65, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35,
- (byte)0xe0, 0x66, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75 };
+ final byte[] unrecognizedValue1 = {
+ (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35
+ };
+ final byte[] unrecognizedValue2 = {
+ (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75
+ };
+ final byte[] unrecognizedBytes = {
+ (byte)0xe0, 0x65, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35,
+ (byte)0xd3, 0x5d, 0x35, (byte)0xe0, 0x66, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35,
+ (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75
+ };
final List<UnrecognizedAttributes> unrecognizedAttrs = new ArrayList<>();
- final UnrecognizedAttributes unrecognizedAttribute1 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType((short) 101).setValue(unrecognizedValue1).build();
+ final UnrecognizedAttributes unrecognizedAttribute1 = new UnrecognizedAttributesBuilder().setPartial(true)
+ .setTransitive(true).setType((short) 101).setValue(unrecognizedValue1).build();
unrecognizedAttrs.add(unrecognizedAttribute1);
- final UnrecognizedAttributes unrecognizedAttribute2 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType((short) 102).setValue(unrecognizedValue2).build();
+ final UnrecognizedAttributes unrecognizedAttribute2 = new UnrecognizedAttributesBuilder().setPartial(true)
+ .setTransitive(true).setType((short) 102).setValue(unrecognizedValue2).build();
unrecognizedAttrs.add(unrecognizedAttribute2);
final Attributes attrs = new AttributesBuilder().setUnrecognizedAttributes(unrecognizedAttrs).build();
final ByteBuf buffer = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry().serializeAttribute(attrs, buffer);
+ ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry().serializeAttribute(attrs,
+ buffer);
assertArrayEquals(unrecognizedBytes, ByteArray.readAllBytes(buffer));
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
import io.netty.buffer.ByteBuf;
@Test
public void testHandler() throws BGPDocumentedException, BGPParsingException {
final AsTwoOctetSpecificEcHandler handler = new AsTwoOctetSpecificEcHandler();
- final AsSpecificExtendedCommunityCase expected = new AsSpecificExtendedCommunityCaseBuilder().setAsSpecificExtendedCommunity(
- new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(54L)).setLocalAdministrator(
- new byte[] { 0, 0, 1, 76 }).build()).build();
+ final AsSpecificExtendedCommunityCase expected = new AsSpecificExtendedCommunityCaseBuilder()
+ .setAsSpecificExtendedCommunity(new AsSpecificExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber(54L))
+ .setLocalAdministrator(new byte[] { 0, 0, 1, 76 }).build())
+ .build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
handler.serializeExtendedCommunity(expected, output);
Assert.assertArrayEquals(INPUT, output.array());
}
-
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
import static org.junit.Assert.assertArrayEquals;
public void testParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf buffer = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
- final EncapsulationCase expected = new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(new EncapsulationExtendedCommunityBuilder()
- .setTunnelType(TUNNEL_TYPE)
- .build()).build();
+ final EncapsulationCase expected = new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(
+ new EncapsulationExtendedCommunityBuilder().setTunnelType(TUNNEL_TYPE).build()).build();
this.parser.serializeExtendedCommunity(expected, buffer);
assertArrayEquals(RESULT, ByteArray.getAllBytes(buffer));
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOrigin4OctectASEcHandlerTest.AS_COMMON;
Generic4OctASEcHandler handler;
@Before
- public void Setup() {
+ public void before() {
this.handler = new Generic4OctASEcHandler();
}
Assert.assertArrayEquals(INPUT, output.array());
}
- @Test(expected=IllegalArgumentException.class)
- public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
+ @Test(expected = IllegalArgumentException.class)
+ public void testHandlerError() {
this.handler.serializeExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().build(), null);
}
}
\ No newline at end of file
public class Ipv4SpecificEcHandlerTest {
private static final byte[] INPUT = {
- 12, 51, 2, 5, 21, 45
+ 12, 51, 2, 5, 21, 45
};
@Test
public void parserTest() throws BGPParsingException, BGPDocumentedException {
final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
- final LinkBandwidthCase expected = new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
+ final LinkBandwidthCase expected = new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(
+ new LinkBandwidthExtendedCommunityBuilder()
.setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff}))
.build()).build();
this.parser.serializeExtendedCommunity(expected, buff);
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
import io.netty.buffer.ByteBuf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
public class OpaqueEcHandlerTest {
-
private static final byte[] INPUT = {
21, 45, 5, 4, 3, 1
};
@Test
public void testHandler() throws BGPDocumentedException, BGPParsingException {
final OpaqueEcHandler handler = new OpaqueEcHandler();
- final OpaqueExtendedCommunityCase expected = new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
- new OpaqueExtendedCommunityBuilder().setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()).build();
+ final OpaqueExtendedCommunityCase expected = new OpaqueExtendedCommunityCaseBuilder()
+ .setOpaqueExtendedCommunity(new OpaqueExtendedCommunityBuilder()
+ .setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()).build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
handler.serializeExtendedCommunity(expected, output);
Assert.assertArrayEquals(INPUT, output.array());
}
-
}
};
public static final As4SpecificCommon AS_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L))
.setLocalAdministrator(100).build();
- RouteOrigin4OctectASEcHandler handler;
+
+ private RouteOrigin4OctectASEcHandler handler;
@Before
- public void Setup() {
+ public void before() {
this.handler = new RouteOrigin4OctectASEcHandler();
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
import io.netty.buffer.ByteBuf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
public class RouteOriginAsTwoOctetEcHandlerTest {
-
private static final byte[] INPUT = {
0, 24, 4, 2, 8, 7
};
@Test
public void testHandler() throws BGPDocumentedException, BGPParsingException {
final RouteOriginAsTwoOctetEcHandler handler = new RouteOriginAsTwoOctetEcHandler();
- final RouteOriginExtendedCommunityCase expected = new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
- new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(24L)).setLocalAdministrator(
- new byte[] { 4, 2, 8, 7 }).build()).build();
+ final RouteOriginExtendedCommunityCase expected = new RouteOriginExtendedCommunityCaseBuilder()
+ .setRouteOriginExtendedCommunity(new RouteOriginExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber(24L))
+ .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build())
+ .build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
handler.serializeExtendedCommunity(expected, output);
Assert.assertArrayEquals(INPUT, output.array());
}
-
}