--- /dev/null
+/*
+ * Copyright (c) 2014 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.concepts.util;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+/**
+ * Utility class for of CNextHop attribute serialization.
+ */
+public class NextHopUtil {
+
+ private NextHopUtil() {
+ }
+
+ public static void serializeNextHop(DataObject attribute, ByteBuf byteAggregator) {
+ serializeNextHop((CNextHop) attribute, byteAggregator);
+ }
+
+ /**
+ * Writes serialized cnextHop attribute ip address as byte value into byteAggregator without serializing attributes
+ * length.
+ *
+ * @param cnextHop
+ * @param byteAggregator
+ */
+ public static void serializeNextHopSimple(CNextHop cnextHop, ByteBuf byteAggregator) {
+ if (cnextHop instanceof Ipv4NextHopCase) {
+ Ipv4NextHopCase nextHop = (Ipv4NextHopCase) cnextHop;
+ serializeIpv4NextHop(nextHop, byteAggregator);
+ } else if (cnextHop instanceof Ipv6NextHopCase) {
+ Ipv6NextHopCase nextHop = (Ipv6NextHopCase) cnextHop;
+ serializeIpv6NextHop(nextHop, byteAggregator);
+ }
+ }
+
+ /**
+ * Writes serialized cnextHop attribute ip address as byte value into byteAggregator with serializing attributes
+ * length.
+ *
+ * @param cnextHop
+ * @param byteAggregator
+ */
+ public static void serializeNextHop(CNextHop cnextHop, ByteBuf byteAggregator) {
+ ByteBuf nextHopBuffer = Unpooled.buffer();
+ serializeNextHopSimple(cnextHop, nextHopBuffer);
+ byteAggregator.writeByte(nextHopBuffer.writerIndex());
+ byteAggregator.writeBytes(nextHopBuffer);
+ }
+
+ /**
+ * Writes nextHopCase attributes ipv4 address as bytes to byteAggregator.
+ *
+ * @param nextHopCase
+ * @param byteAggregator
+ */
+ public static void serializeIpv4NextHop(Ipv4NextHopCase nextHopCase, ByteBuf byteAggregator) {
+ byteAggregator.writeBytes(Ipv4Util.bytesForAddress(nextHopCase.getIpv4NextHop().getGlobal()));
+ }
+
+ /**
+ * Writes nextHopCase attributes ipv6 address as bytes to byteAggregator.
+ *
+ * @param nextHopCase
+ * @param byteAggregator
+ */
+ public static void serializeIpv6NextHop(Ipv6NextHopCase nextHopCase, ByteBuf byteAggregator) {
+ if (nextHopCase.getIpv6NextHop().getGlobal() != null) {
+ byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHopCase.getIpv6NextHop().getGlobal()));
+ }
+ if (nextHopCase.getIpv6NextHop().getLinkLocal() != null) {
+ byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHopCase.getIpv6NextHop().getLinkLocal()));
+ }
+
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.GracefulRestartCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
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.Ipv6AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
final ClusterIdAttributeParser clusterIdAttributeParser = new ClusterIdAttributeParser();
regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, clusterIdAttributeParser));
- regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(nlriReg)));
- regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(nlriReg)));
+ MPReachAttributeParser mpReachAttributeParser = new MPReachAttributeParser(nlriReg);
+ regs.add(context.registerAttributeSerializer(MpReachNlri.class,mpReachAttributeParser));
+ regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, mpReachAttributeParser ));
+
+ MPUnreachAttributeParser mpUnreachAttributeParser = new MPUnreachAttributeParser(nlriReg);
+ regs.add(context.registerAttributeSerializer(MpUnreachNlri.class,mpUnreachAttributeParser));
+ regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, mpUnreachAttributeParser));
final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new ExtendedCommunitiesAttributeParser(context.getReferenceCache());
regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
+
final CapabilityRegistry capReg = context.getCapabilityRegistry();
final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
messageBody.writeBytes(prefixBytes);
}
}
+
LOG.trace("Update message serialized to {}", ByteBufUtil.hexDump(messageBody));
//FIXME: switch to ByteBuf
bytes.writeBytes(MessageUtil.formatMessage(TYPE, ByteArray.getAllBytes(messageBody)));
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
-
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.parser.AttributeFlags;
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.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
import org.opendaylight.yangtools.yang.binding.DataObject;
-public final class MPReachAttributeParser implements AttributeParser,AttributeSerializer {
- public static final int TYPE = 14;
+public final class MPReachAttributeParser implements AttributeParser, AttributeSerializer {
+ public static final int TYPE = 14;
+ public static final int ATTR_LENGTH = 2;
+ public static final int MAX_ATTR_LENGTH_FOR_SINGLE_BYTE = 127;
private final NlriRegistry reg;
public MPReachAttributeParser(final NlriRegistry reg) {
@Override
public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) {
- //FIXME: implement this
+ PathAttributes pathAttributes = (PathAttributes) attribute;
+ PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
+ if (pathAttributes1 == null) {
+ return;
+ }
+ MpReachNlri mpReachNlri = pathAttributes1.getMpReachNlri();
+ ByteBuf reachBuffer = Unpooled.buffer();
+ this.reg.serializeMpReach(mpReachNlri, reachBuffer);
+
+ serializeAdvertizedRoutes(mpReachNlri.getAdvertizedRoutes(), reachBuffer);
+ if (reachBuffer.writerIndex() > MAX_ATTR_LENGTH_FOR_SINGLE_BYTE) {
+ byteAggregator.writeByte(AttributeFlags.OPTIONAL | AttributeFlags.EXTENDED);
+ byteAggregator.writeByte(TYPE);
+ byteAggregator.writeShort(reachBuffer.writerIndex());
+ } else {
+ byteAggregator.writeByte(AttributeFlags.OPTIONAL);
+ byteAggregator.writeByte(TYPE);
+ byteAggregator.writeByte(reachBuffer.writerIndex());
+ }
+ byteAggregator.writeBytes(reachBuffer);
+
+
+ }
+
+ private void serializeAdvertizedRoutes(AdvertizedRoutes advertizedRoutes, ByteBuf byteAggregator) {
+ DestinationType destinationType = advertizedRoutes.getDestinationType();
+ if (destinationType instanceof DestinationIpv4Case) {
+ DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) destinationType;
+ for (Ipv4Prefix ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
+ byteAggregator.writeByte(Ipv4Util.getPrefixLength(ipv4Prefix.getValue()));
+ byteAggregator.writeBytes(Ipv4Util.bytesForPrefixByPrefixLength(ipv4Prefix));
+ }
+ } else if (destinationType instanceof DestinationIpv6Case) {
+ DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) destinationType;
+ for (Ipv6Prefix ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
+ byteAggregator.writeByte(Ipv4Util.getPrefixLength(ipv6Prefix.getValue()));
+ byteAggregator.writeBytes(Ipv6Util.bytesForPrefixByPrefixLength(ipv6Prefix));
+ }
+ }
}
}
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
-
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.parser.AttributeFlags;
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.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
import org.opendaylight.yangtools.yang.binding.DataObject;
-public final class MPUnreachAttributeParser implements AttributeParser,AttributeSerializer {
-
+public final class MPUnreachAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 15;
+ public static final int MAX_ATTR_LENGTH_FOR_SINGLE_BYTE = 127;
private final NlriRegistry reg;
@Override
public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) {
- //FIME: implement this
+ PathAttributes pathAttributes = (PathAttributes) attribute;
+ PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
+ if (pathAttributes2 == null) {
+ return;
+ }
+ MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
+ ByteBuf unreachBuffer = Unpooled.buffer();
+ this.reg.serializeMpUnReach(mpUnreachNlri, unreachBuffer);
+
+ if (mpUnreachNlri.getWithdrawnRoutes() != null) {
+ if (mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationIpv4Case) {
+ DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
+ if (destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes() != null) {
+ for (Ipv4Prefix ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
+ unreachBuffer.writeByte(Ipv4Util.getPrefixLength(ipv4Prefix.getValue()));
+ unreachBuffer.writeBytes(Ipv4Util.bytesForPrefixByPrefixLength(ipv4Prefix));
+ }
+ }
+ }
+ if (mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationIpv6Case) {
+ DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
+ if (destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes() != null) {
+ for (Ipv6Prefix ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
+ unreachBuffer.writeByte(Ipv4Util.getPrefixLength(ipv6Prefix.getValue()));
+ unreachBuffer.writeBytes(Ipv6Util.bytesForPrefixByPrefixLength(ipv6Prefix));
+ }
+ }
+ }
+ }
+ if (unreachBuffer.writerIndex() > MAX_ATTR_LENGTH_FOR_SINGLE_BYTE) {
+ byteAggregator.writeByte(AttributeFlags.OPTIONAL | AttributeFlags.EXTENDED);
+ byteAggregator.writeByte(TYPE);
+ byteAggregator.writeShort(unreachBuffer.writerIndex());
+ } else {
+ byteAggregator.writeByte(AttributeFlags.OPTIONAL);
+ byteAggregator.writeByte(TYPE);
+ byteAggregator.writeByte(unreachBuffer.writerIndex());
+ }
+ byteAggregator.writeBytes(unreachBuffer);
}
}
package org.opendaylight.protocol.bgp.parser.impl;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.Segments;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
static final List<byte[]> inputBytes = new ArrayList<byte[]>();
private static BGPUpdateMessageParser updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
+
private static int COUNTER = 9;//17;
private static int MAX_SIZE = 300;
if (left.getOriginatorId() != null) {
assertEquals(left.getOriginatorId().getValue(), right.getOriginatorId().getValue());
}
+ if (left.getAugmentation(PathAttributes1.class) != null) {
+ assertNotNull(right.getAugmentation(PathAttributes1.class));
+ }
+ if (left.getAugmentation(PathAttributes2.class) != null) {
+ assertNotNull(right.getAugmentation(PathAttributes2.class));
+ }
}
private void assertEqualsClusterId(List<ClusterIdentifier> left, List<ClusterIdentifier> right) {
public interface NlriRegistry {
MpReachNlri parseMpReach(final ByteBuf buffer) throws BGPParsingException;
-
MpUnreachNlri parseMpUnreach(final ByteBuf buffer) throws BGPParsingException;
+ void serializeMpReach(final MpReachNlri mpReachNlri,final ByteBuf byteAggregator);
+ void serializeMpUnReach(final MpUnreachNlri mpUnreachNlri,final ByteBuf byteAggregator);
}
import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.opendaylight.protocol.bgp.concepts.util.NextHopUtil;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
final class SimpleNlriRegistry implements NlriRegistry {
+
private final ConcurrentMap<BgpTableType, NlriParser> handlers = new ConcurrentHashMap<>();
private final SubsequentAddressFamilyRegistry safiReg;
private final AddressFamilyRegistry afiReg;
this.safiReg = Preconditions.checkNotNull(safiReg);
}
- private static BgpTableType createKey(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
+ private static BgpTableType createKey(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
Preconditions.checkNotNull(afi);
Preconditions.checkNotNull(safi);
return new BgpTableTypeImpl(afi, safi);
}
synchronized AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi,
- final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser) {
+ final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser) {
final BgpTableType key = createKey(afi, safi);
final NlriParser prev = this.handlers.get(key);
Preconditions.checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
return builder.build();
}
+ @Override
+ public void serializeMpReach(MpReachNlri mpReachNlri, ByteBuf byteAggregator) {
+
+ byteAggregator.writeShort(this.afiReg.numberForClass(mpReachNlri.getAfi()));
+ byteAggregator.writeByte(this.safiReg.numberForClass(mpReachNlri.getSafi()));
+
+ ByteBuf nextHopBuffer = Unpooled.buffer();
+ NextHopUtil.serializeNextHopSimple(mpReachNlri.getCNextHop(), nextHopBuffer);
+
+ byteAggregator.writeByte(nextHopBuffer.writerIndex());
+ byteAggregator.writeBytes(nextHopBuffer);
+
+ //TODO how to calculate number of SNPAs Subnetwork Points of Attachment and serialize SNPAs ?
+ byteAggregator.writeByte(0);
+ }
+
+ @Override
+ public void serializeMpUnReach(MpUnreachNlri mpUnreachNlri, ByteBuf byteAggregator) {
+
+ byteAggregator.writeShort(this.afiReg.numberForClass(mpUnreachNlri.getAfi()));
+ byteAggregator.writeByte(this.safiReg.numberForClass(mpUnreachNlri.getSafi()));
+ }
+
@Override
public MpReachNlri parseMpReach(final ByteBuf buffer) throws BGPParsingException {
final MpReachNlriBuilder builder = new MpReachNlriBuilder();
return bits / 8;
}
+ /**
+ * Converts Ipv4Prefix to byte array of length equal to prefix length value.
+ *
+ * @param ipv4Prefix Ipv4Prefix to be converted
+ * @return byte array
+ */
+ public static byte[] bytesForPrefixByPrefixLength(Ipv4Prefix ipv4Prefix) {
+ return ByteArray.subByte(bytesForPrefix(ipv4Prefix), 0,
+ getPrefixLengthBytes(ipv4Prefix.getValue()));
+ }
+
/**
* Converts Ipv4Prefix to byte array.
*
import com.google.common.net.InetAddresses;
import com.google.common.primitives.Bytes;
import com.google.common.primitives.UnsignedBytes;
-
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
return a.getAddress();
}
+
+ /**
+ * Converts Ipv6Prefix to byte array of (prefix bit size/8) size.
+ *
+ * @param ipv6Prefix Ipv6Prefix to be converted
+ * @return byte array
+ */
+ public static byte[] bytesForPrefixByPrefixLength(Ipv6Prefix ipv6Prefix) {
+ return ByteArray.subByte(Ipv6Util.bytesForPrefix(ipv6Prefix), 0,
+ Ipv4Util.getPrefixLengthBytes(ipv6Prefix.getValue()));
+ }
+
+
/**
* Converts Ipv6Prefix to byte array.
*