Search in sources :

Example 6 with OptionalCapabilities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.

the class OpenTest method testSerializeLongOpen.

@Test
public void testSerializeLongOpen() throws BGPDocumentedException {
    final List<OptionalCapabilities> capabilities = new ArrayList<>();
    for (int i = 0; i < 200; ++i) {
        capabilities.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).build()).build());
    }
    final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("127.0.0.1")).setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(capabilities).build())).build();
    final ByteBuf msg = Unpooled.buffer();
    new BGPOpenMessageParser(registry).serializeMessage(open, msg);
    assertEquals(1235, msg.readableBytes());
    final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
    final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
    assertEquals(200, openResult.getBgpParameters().get(0).getOptionalCapabilities().size());
}
Also used : BGPOpenMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) ArrayList(java.util.ArrayList) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) ByteBuf(io.netty.buffer.ByteBuf) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) Test(org.junit.Test)

Example 7 with OptionalCapabilities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.

the class StrictBGPPeerRegistry method getAs4BytesCapability.

@Nullable
private static As4BytesCapability getAs4BytesCapability(final List<BgpParameters> prefs) {
    for (final BgpParameters param : prefs) {
        for (final OptionalCapabilities capa : param.nonnullOptionalCapabilities()) {
            final CParameters cParam = capa.getCParameters();
            final As4BytesCapability asCapa = cParam.getAs4BytesCapability();
            if (asCapa != null) {
                return asCapa;
            }
        }
    }
    return null;
}
Also used : CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) As4BytesCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 8 with OptionalCapabilities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.

the class BgpPeer method getBgpCapabilities.

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static List<OptionalCapabilities> getBgpCapabilities(final AfiSafis afiSafis, final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
    final List<OptionalCapabilities> caps = new ArrayList<>();
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
    final Collection<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(afiSafis, false).values();
    final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil.toAddPathCapability(afiSafi, tableTypeRegistry);
    if (!addPathCapability.isEmpty()) {
        caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability).build()).build()).build()).build());
    }
    final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
    for (final BgpTableType tableType : tableTypes) {
        if (!rib.getLocalTables().contains(tableType)) {
            LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", tableType);
        }
        caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder(tableType).build()).build()).build()).build());
    }
    return caps;
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder) AfiSafi(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi) ArrayList(java.util.ArrayList) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies) AddPathCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.AddPathCapabilityBuilder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with OptionalCapabilities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.

the class BGPSessionStateImpl method advertizeCapabilities.

@Override
public synchronized void advertizeCapabilities(final int newHoldTimerValue, final SocketAddress newRemoteAddress, final SocketAddress localAddress, final Set<BgpTableType> tableTypes, final List<BgpParameters> bgpParameters) {
    if (bgpParameters != null) {
        for (final BgpParameters parameters : bgpParameters) {
            for (final OptionalCapabilities optionalCapabilities : parameters.nonnullOptionalCapabilities()) {
                final CParameters cParam = optionalCapabilities.getCParameters();
                final CParameters1 capabilities = cParam.augmentation(CParameters1.class);
                if (capabilities != null) {
                    final MultiprotocolCapability mc = capabilities.getMultiprotocolCapability();
                    if (mc != null) {
                        this.multiProtocolCapability = true;
                    }
                    if (capabilities.getGracefulRestartCapability() != null) {
                        this.gracefulRestartCapability = true;
                    }
                    if (capabilities.getAddPathCapability() != null) {
                        this.addPathCapability = true;
                    }
                    if (capabilities.getRouteRefreshCapability() != null) {
                        this.routerRefreshCapability = true;
                    }
                }
                if (cParam.getAs4BytesCapability() != null) {
                    this.asn32Capability = true;
                }
            }
        }
    }
    this.holdTimerValue = newHoldTimerValue;
    this.remoteAddress = StrictBGPPeerRegistry.getIpAddress(newRemoteAddress);
    this.remotePort = new PortNumber(Uint16.valueOf(((InetSocketAddress) newRemoteAddress).getPort()));
    this.localPort = new PortNumber(Uint16.valueOf(((InetSocketAddress) localAddress).getPort()));
}
Also used : MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)

Example 10 with OptionalCapabilities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.

the class GracefulRestartUtilTest method getGracefulBgpParametersTest.

@Test
public void getGracefulBgpParametersTest() {
    final OptionalCapabilities cap1 = new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build();
    final OptionalCapabilities cap2 = new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build();
    final List<OptionalCapabilities> fixedCaps = new ArrayList<>();
    fixedCaps.add(cap1);
    fixedCaps.add(cap2);
    final Set<TablesKey> gracefulTables = new HashSet<>();
    gracefulTables.add(IPV4_KEY);
    gracefulTables.add(IPV6_KEY);
    final Set<TablesKey> preservedTables = new HashSet<>();
    preservedTables.add(IPV4_KEY);
    final Map<TablesKey, Boolean> gracefulMap = new HashMap<>();
    gracefulMap.put(IPV4_KEY, true);
    gracefulMap.put(IPV6_KEY, false);
    final OptionalCapabilities expectedGracefulCapability = new OptionalCapabilitiesBuilder().setCParameters(GracefulRestartUtil.getGracefulCapability(gracefulMap, RESTART_TIME, RESTARTING)).build();
    final Set<BgpPeerUtil.LlGracefulRestartDTO> llGracefulDTOs = Collections.singleton(new BgpPeerUtil.LlGracefulRestartDTO(IPV4_KEY, STALE_TIME, true));
    final OptionalCapabilities expectedLlGracefulCapability = new OptionalCapabilitiesBuilder().setCParameters(GracefulRestartUtil.getLlGracefulCapability(llGracefulDTOs)).build();
    final BgpParameters parameters = GracefulRestartUtil.getGracefulBgpParameters(fixedCaps, gracefulTables, preservedTables, RESTART_TIME, RESTARTING, llGracefulDTOs);
    final List<OptionalCapabilities> capabilities = parameters.getOptionalCapabilities();
    assertTrue(capabilities != null);
    assertEquals(4, capabilities.size());
    assertTrue(capabilities.contains(cap1));
    assertTrue(capabilities.contains(cap2));
    assertTrue(capabilities.contains(expectedGracefulCapability));
    assertTrue(capabilities.contains(expectedLlGracefulCapability));
}
Also used : OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) BgpPeerUtil(org.opendaylight.protocol.bgp.rib.impl.BgpPeerUtil) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)22 ArrayList (java.util.ArrayList)18 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder)15 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)14 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder)12 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)12 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)11 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder)11 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder)9 As4BytesCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder)9 Test (org.junit.Test)8 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)8 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters)8 ByteBuf (io.netty.buffer.ByteBuf)7 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion)7 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)6 CParameters1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1)5 InetSocketAddress (java.net.InetSocketAddress)4 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)4 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)4