Updated yang model and added new notification.
Implemented parser and registered.
Updated MultiprotocolCapabilitiesUtil class.
Updated and added unit tests.
Change-Id: If389ff6e793bbbae49e8d2fb16071397e121518a
Signed-off-by: Iveta Halanova <ihalanov@cisco.com>
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.parser;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.RouteRefreshCapabilityBuilder;
-
-public final class MultiprotocolCapabilitiesUtil {
-
- public static final CParameters RR_CAPABILITY = new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setRouteRefreshCapability(new RouteRefreshCapabilityBuilder().build()).build()).build();
-
- // move common functionality will be added
-}
}
}
}
+
+ notification route-refresh {
+ description "ROUTE-REFRESH message";
+ reference "https://tools.ietf.org/html/rfc2918#section-3";
+ uses bgp-table-type;
+ }
}
import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPRouteRefreshMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Origin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginatorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.AddPathCapability;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.GracefulRestartCapability;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCapability;
final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
+
+ final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
+ final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
+ final BGPRouteRefreshMessageParser rrmp = new BGPRouteRefreshMessageParser(afiReg, safiReg);
+ regs.add(context.registerMessageParser(BGPRouteRefreshMessageParser.TYPE, rrmp));
+ regs.add(context.registerMessageSerializer(RouteRefresh.class, rrmp));
}
private void registerExtendedCommunities(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.impl.message;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
+import org.opendaylight.protocol.bgp.parser.spi.MultiprotocolCapabilitiesUtil;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefreshBuilder;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class BGPRouteRefreshMessageParser implements MessageParser, MessageSerializer {
+ // https://tools.ietf.org/html/rfc2918#section-3
+
+ private static final Logger LOG = LoggerFactory.getLogger(BGPRouteRefreshMessageParser.class);
+
+ public static final int TYPE = 5;
+ private static final int TRIPLET_BYTE_SIZE = 4;
+
+ private final AddressFamilyRegistry afiReg;
+ private final SubsequentAddressFamilyRegistry safiReg;
+
+ public BGPRouteRefreshMessageParser(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
+ this.afiReg = Preconditions.checkNotNull(afiReg);
+ this.safiReg = Preconditions.checkNotNull(safiReg);
+ }
+
+ /**
+ * Serializes BGP Route Refresh message.
+ *
+ * @param message to be serialized
+ * @param bytes ByteBuf where the message will be serialized
+ */
+ @Override
+ public void serializeMessage(final Notification message, final ByteBuf bytes) {
+ Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh.");
+ final RouteRefresh msg = (RouteRefresh) message;
+
+ final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE);
+ MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(), msgBuf);
+
+ LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf));
+ MessageUtil.formatMessage(TYPE, msgBuf, bytes);
+ }
+
+ /**
+ * Parses BGP Route Refresh message to bytes.
+ *
+ * @param body ByteBuf to be parsed
+ * @param messageLength the length of the message
+ * @return {@link RouteRefresh} which represents BGP notification message
+ * @throws BGPDocumentedException if parsing goes wrong
+ */
+ @Override
+ public RouteRefresh parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
+ Preconditions.checkArgument(body != null, "Body buffer cannot be null.");
+ if (body.readableBytes() < TRIPLET_BYTE_SIZE) {
+ throw BGPDocumentedException.badMessageLength("RouteRefresh message is too small.", messageLength);
+ }
+ try {
+ final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(body, this.afiReg, this.safiReg);
+ return new RouteRefreshBuilder().setAfi(parsedAfiSafi.getAfi()).setSafi(parsedAfiSafi.getSafi()).build();
+ } catch (final BGPParsingException e) {
+ throw new BGPDocumentedException("Unsupported afi/safi in Route Refresh message.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
+ }
+ }
+}
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil;
+import org.opendaylight.protocol.bgp.parser.spi.MultiprotocolCapabilitiesUtil;
import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCapability;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCapabilityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
public final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
public static final int CODE = 1;
private final AddressFamilyRegistry afiReg;
private final SubsequentAddressFamilyRegistry safiReg;
- private static final int RESERVED = 1;
-
public MultiProtocolCapabilityHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
this.afiReg = Preconditions.checkNotNull(afiReg);
this.safiReg = Preconditions.checkNotNull(safiReg);
@Override
public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
- final int afiVal = buffer.readUnsignedShort();
- final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
- if (afi == null) {
- throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
- }
- // skip reserved
- buffer.skipBytes(RESERVED);
- final int safiVal = buffer.readUnsignedByte();
- final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
- if (safi == null) {
- throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
- }
+ final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(buffer, this.afiReg, this.safiReg);
return new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build()).build();
+ new MultiprotocolCapabilityBuilder().setAfi(parsedAfiSafi.getAfi()).setSafi(parsedAfiSafi.getSafi()).build()).build()).build();
}
@Override
final MultiprotocolCapability mp = capability.getAugmentation(CParameters1.class).getMultiprotocolCapability();
final ByteBuf capBuffer = Unpooled.buffer();
- final Class<? extends AddressFamily> afi = mp.getAfi();
- final Integer afival = this.afiReg.numberForClass(afi);
- Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
- capBuffer.writeShort(afival);
-
- final Class<? extends SubsequentAddressFamily> safi = mp.getSafi();
- final Integer safival = this.safiReg.numberForClass(safi);
- Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
- capBuffer.writeZero(RESERVED);
- capBuffer.writeByte(safival);
+ MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, mp.getAfi(), mp.getSafi(), capBuffer);
CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
}
+
}
\ No newline at end of file
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.MultiprotocolCapabilitiesUtil;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil;
+import org.opendaylight.protocol.bgp.parser.spi.MultiprotocolCapabilitiesUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefreshBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yangtools.yang.binding.Notification;
public class ParserTest {
(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
};
+ 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) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01 };
+
static MessageRegistry reg;
@BeforeClass
@Test
public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
- new ProtocolVersion((short) 4)).build();
+ new ProtocolVersion((short) 4)).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
assertArrayEquals(openBMsg, ByteArray.getAllBytes(bytes));
@Test
public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
- BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
+ 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()));
}
fail();
}
+
+ @Test
+ public void testRouteRefreshMsg() throws BGPDocumentedException, BGPParsingException {
+ final Notification rrMsg = new RouteRefreshBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build();
+ final ByteBuf buffer = Unpooled.buffer();
+ ParserTest.reg.serializeMessage(rrMsg, buffer);
+ assertArrayEquals(RR_MSG, ByteArray.getAllBytes(buffer));
+
+ final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(ByteArray.getAllBytes(buffer)));
+
+ assertTrue(m instanceof RouteRefresh);
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.spi;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.RouteRefreshCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
+
+public final class MultiprotocolCapabilitiesUtil {
+
+ public static final CParameters RR_CAPABILITY = new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setRouteRefreshCapability(new RouteRefreshCapabilityBuilder().build()).build()).build();
+
+ private static final int RESERVED = 1;
+
+ public static void serializeMPAfiSafi(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg,
+ final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final ByteBuf capBuffer) {
+ final Integer afival = afiReg.numberForClass(afi);
+ Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
+ capBuffer.writeShort(afival);
+
+ capBuffer.writeZero(RESERVED);
+
+ final Integer safival = safiReg.numberForClass(safi);
+ Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
+ capBuffer.writeByte(safival);
+ }
+
+ public static BgpTableType parseMPAfiSafi(final ByteBuf buffer, final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) throws BGPParsingException {
+ final int afiVal = buffer.readUnsignedShort();
+ final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
+ if (afi == null) {
+ throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
+ }
+ // skip reserved
+ buffer.skipBytes(RESERVED);
+ final int safiVal = buffer.readUnsignedByte();
+ final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
+ if (safi == null) {
+ throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
+ }
+ return new BgpTableTypeImpl(afi, safi);
+ }
+}
package org.opendaylight.protocol.bgp.parser.spi;
import static org.junit.Assert.assertArrayEquals;
-
+import static org.junit.Assert.assertEquals;
import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
public class UtilsTest {
+ @Mock private AddressFamilyRegistry afiReg;
+ @Mock private SubsequentAddressFamilyRegistry safiReg;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.doReturn(1).when(this.afiReg).numberForClass(Ipv4AddressFamily.class);
+ Mockito.doReturn(Ipv4AddressFamily.class).when(this.afiReg).classForFamily(1);
+
+ Mockito.doReturn(1).when(this.safiReg).numberForClass(UnicastSubsequentAddressFamily.class);
+ Mockito.doReturn(UnicastSubsequentAddressFamily.class).when(this.safiReg).classForFamily(1);
+ }
+
@Test
public void testCapabilityUtil() {
final byte[] result = new byte[] { 1, 2, 4, 8 };
- ByteBuf aggregator = Unpooled.buffer();
+ final ByteBuf aggregator = Unpooled.buffer();
CapabilityUtil.formatCapability(1, Unpooled.wrappedBuffer(new byte[] { 4, 8 }),aggregator);
assertArrayEquals(result, ByteArray.getAllBytes(aggregator));
}
UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, 0, 23, 3, 32, 5, 14, 21 };
- ByteBuf formattedMessage = Unpooled.buffer();
+ final ByteBuf formattedMessage = Unpooled.buffer();
MessageUtil.formatMessage(3, Unpooled.wrappedBuffer(new byte[] { 32, 5, 14, 21 }), formattedMessage);
assertArrayEquals(result, ByteArray.getAllBytes(formattedMessage));
}
@Test
public void testParameterUtil() {
final byte[] result = new byte[] { 1, 2, 4, 8 };
- ByteBuf aggregator = Unpooled.buffer();
+ final ByteBuf aggregator = Unpooled.buffer();
ParameterUtil.formatParameter(1, Unpooled.wrappedBuffer(new byte[] { 4, 8 }), aggregator);
assertArrayEquals(result, ByteArray.getAllBytes(aggregator));
}
@Test
public void testAttributeUtil() {
final byte[] result = new byte[] { 0x40, 03, 04, 10, 00, 00, 02 };
- ByteBuf aggregator = Unpooled.buffer();
+ final ByteBuf aggregator = Unpooled.buffer();
AttributeUtil.formatAttribute(64 , 3 , Unpooled.wrappedBuffer(new byte[] { 10, 0, 0, 2 }), aggregator);
assertArrayEquals(result, ByteArray.getAllBytes(aggregator));
}
final byte[] result = new byte[262];
System.arraycopy(header, 0, result, 0, header.length);
System.arraycopy(value, 0, result, 4, value.length);
- ByteBuf aggregator = Unpooled.buffer();
+ final ByteBuf aggregator = Unpooled.buffer();
AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE , 3 , Unpooled.wrappedBuffer(value), aggregator);
assertArrayEquals(result, ByteArray.getAllBytes(aggregator));
}
+ @Test
+ public void testMultiprotocolCapabilitiesUtil() throws BGPParsingException {
+ final byte[] bytes = new byte[] {0, 1, 0, 1};
+ final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes);
+ final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, this.afiReg, this.safiReg);
+ assertEquals(Ipv4AddressFamily.class, parsedAfiSafi.getAfi());
+ assertEquals(UnicastSubsequentAddressFamily.class, parsedAfiSafi.getSafi());
+
+ final ByteBuf serializedAfiSafi = Unpooled.buffer(4);
+ MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, serializedAfiSafi);
+ assertArrayEquals(bytes, serializedAfiSafi.array());
+ }
+
@Test(expected=UnsupportedOperationException.class)
public void testAttributeUtilPrivateConstructor() throws Throwable {
final Constructor<AttributeUtil> c = AttributeUtil.class.getDeclaredConstructor();
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
import org.opendaylight.protocol.bgp.openconfig.spi.BGPOpenconfigMapper;
import org.opendaylight.protocol.bgp.openconfig.spi.InstanceConfigurationIdentifier;
import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPPeerInstanceConfiguration;
-import org.opendaylight.protocol.bgp.parser.MultiprotocolCapabilitiesUtil;
+import org.opendaylight.protocol.bgp.parser.spi.MultiprotocolCapabilitiesUtil;
import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;