2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.parser.spi;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import java.util.Optional;
13 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.RouteRefreshCapabilityBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public final class MultiprotocolCapabilitiesUtil {
25 public static final CParameters RR_CAPABILITY = new CParametersBuilder()
26 .addAugmentation(new CParameters1Builder()
27 .setRouteRefreshCapability(new RouteRefreshCapabilityBuilder().build())
31 private static final Logger LOG = LoggerFactory.getLogger(MultiprotocolCapabilitiesUtil.class);
32 private static final int RESERVED = 1;
34 private MultiprotocolCapabilitiesUtil() {
38 public static void serializeMPAfiSafi(final AddressFamilyRegistry afiReg,
39 final SubsequentAddressFamilyRegistry safiReg, final AddressFamily afi, final SubsequentAddressFamily safi,
40 final ByteBuf capBuffer) {
41 final Integer afival = afiReg.numberForClass(afi);
42 Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
43 capBuffer.writeShort(afival);
45 capBuffer.writeZero(RESERVED);
47 final Integer safival = safiReg.numberForClass(safi);
48 Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
49 capBuffer.writeByte(safival);
52 public static Optional<BgpTableType> parseMPAfiSafi(final ByteBuf buffer, final AddressFamilyRegistry afiReg,
53 final SubsequentAddressFamilyRegistry safiReg) {
54 final int afiVal = buffer.readUnsignedShort();
55 final AddressFamily afi = afiReg.classForFamily(afiVal);
57 LOG.info("Unsupported AFI {} parsed.", afiVal);
58 return Optional.empty();
61 buffer.skipBytes(RESERVED);
62 final int safiVal = buffer.readUnsignedByte();
63 final SubsequentAddressFamily safi = safiReg.classForFamily(safiVal);
65 LOG.info("Unsupported SAFI {} parsed.", safiVal);
66 return Optional.empty();
68 return Optional.of(new BgpTableTypeImpl(afi, safi));