Search in sources :

Example 6 with BgpParameters

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

the class BGPOpenMessageParser method normalSerializeParameters.

private ByteBuf normalSerializeParameters(final List<BgpParameters> params) {
    final ByteBuf buffer = Unpooled.buffer();
    for (final BgpParameters param : params) {
        final Optional<ParameterSerializer> optSer = reg.findSerializer(param);
        if (optSer.isPresent()) {
            try {
                optSer.get().serializeParameter(param, buffer);
            } catch (ParameterLengthOverflowException e) {
                LOG.debug("Forcing extended parameter serialization", e);
                return null;
            }
        } else {
            LOG.debug("Ingnoring unregistered parameter {}", param);
        }
    }
    final int length = buffer.writerIndex();
    if (length > Values.UNSIGNED_BYTE_MAX_VALUE) {
        LOG.debug("Final parameter size is {}, forcing extended serialization", length);
        return null;
    }
    return buffer;
}
Also used : ParameterLengthOverflowException(org.opendaylight.protocol.bgp.parser.spi.ParameterLengthOverflowException) ByteBuf(io.netty.buffer.ByteBuf) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) ParameterSerializer(org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 7 with BgpParameters

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

the class BGPOpenMessageParser method serializeParameters.

private void serializeParameters(final List<BgpParameters> params, final ByteBuf msgBody) {
    if (params == null || params.isEmpty()) {
        msgBody.writeByte(0);
        return;
    }
    final ByteBuf normal = normalSerializeParameters(params);
    if (normal != null) {
        final int length = normal.writerIndex();
        verify(length <= Values.UNSIGNED_BYTE_MAX_VALUE);
        msgBody.writeByte(length);
        msgBody.writeBytes(normal);
        return;
    }
    final ByteBuf buffer = Unpooled.buffer();
    for (final BgpParameters param : params) {
        final Optional<ParameterSerializer> optSer = reg.findSerializer(param);
        if (optSer.isPresent()) {
            optSer.get().serializeExtendedParameter(param, buffer);
        } else {
            LOG.debug("Ignoring unregistered parameter {}", param);
        }
    }
    final int length = buffer.writerIndex();
    checkState(length <= Values.UNSIGNED_SHORT_MAX_VALUE);
    // The non-extended Optional Parameters Length field MUST be set to 255
    msgBody.writeByte(Values.UNSIGNED_BYTE_MAX_VALUE);
    // The subsequent one-octet field, that in the non-extended format would
    // be the first Optional Parameter Type field, MUST be set to 255
    msgBody.writeByte(OPT_PARAM_EXT_PARAM);
    // Extended Optional Parameters Length
    msgBody.writeShort(length);
    msgBody.writeBytes(buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) ParameterSerializer(org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 8 with BgpParameters

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

the class BGPMessageParserMockTest method testGetOpenMessage.

@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
    final Map<ByteBuf, Notification> openMap = new HashMap<>();
    final Set<BgpTableType> type = new HashSet<>();
    type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
    final List<BgpParameters> params = new ArrayList<>();
    final CParameters par = new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build()).build();
    params.add(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(par).build())).build());
    final byte[] input = new byte[] { 5, 8, 13, 21 };
    openMap.put(Unpooled.copiedBuffer(input), new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(30)).setBgpParameters(params).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build());
    final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
    final Set<BgpTableType> result = new HashSet<>();
    for (final BgpParameters p : ((Open) mockParser.parseMessage(Unpooled.copiedBuffer(input), null)).getBgpParameters()) {
        for (final OptionalCapabilities capa : p.getOptionalCapabilities()) {
            final CParameters cp = capa.getCParameters();
            if (cp.augmentation(CParameters1.class) != null && cp.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
                final BgpTableType t = new BgpTableTypeImpl(cp.augmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.augmentation(CParameters1.class).getMultiprotocolCapability().getSafi());
                result.add(t);
            }
        }
    }
    assertEquals(type, result);
}
Also used : HashMap(java.util.HashMap) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily) ArrayList(java.util.ArrayList) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters) ByteBuf(io.netty.buffer.ByteBuf) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1) Notification(org.opendaylight.yangtools.yang.binding.Notification) 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) HashSet(java.util.HashSet) 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) MplsLabeledVpnSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.MplsLabeledVpnSubsequentAddressFamily) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) Test(org.junit.Test)

Example 9 with BgpParameters

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

the class SimpleRegistryTest method testSimpleParameter.

@Test
public void testSimpleParameter() throws Exception {
    final ParameterRegistry paramReg = this.ctx.getParameterRegistry();
    final BgpParameters param = mock(BgpParameters.class);
    Mockito.doReturn(BgpParameters.class).when(param).implementedInterface();
    assertEquals(Optional.of(activator.paramParser), paramReg.findParser(0));
    assertEquals(Optional.of(activator.paramSerializer), paramReg.findSerializer(param));
}
Also used : ParameterRegistry(org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) Test(org.junit.Test)

Example 10 with BgpParameters

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

the class BGPPeer method setGracefulPreferences.

private synchronized void setGracefulPreferences(final boolean localRestarting, final Set<TablesKey> preservedTables) {
    final Set<TablesKey> gracefulTables = this.tables.stream().filter(this::isGracefulRestartAdvertized).collect(Collectors.toSet());
    final BgpParameters bgpParameters = GracefulRestartUtil.getGracefulBgpParameters(this.bgpPeer.getBgpFixedCapabilities(), gracefulTables, preservedTables, this.bgpPeer.getGracefulRestartTimer(), localRestarting, Collections.emptySet());
    final BGPSessionPreferences oldPrefs = this.rib.getDispatcher().getBGPPeerRegistry().getPeerPreferences(getNeighborAddress());
    final BGPSessionPreferences newPrefs = new BGPSessionPreferences(oldPrefs.getMyAs(), oldPrefs.getHoldTime(), oldPrefs.getBgpId(), oldPrefs.getExpectedRemoteAs(), Collections.singletonList(bgpParameters), oldPrefs.getMd5Password());
    this.rib.getDispatcher().getBGPPeerRegistry().updatePeerPreferences(getNeighborAddress(), newPrefs);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)

Aggregations

BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)27 ArrayList (java.util.ArrayList)17 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)16 Test (org.junit.Test)12 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder)11 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder)10 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)9 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)8 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder)8 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)8 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)8 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder)8 ByteBuf (io.netty.buffer.ByteBuf)7 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)7 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters)6 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)5 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)5 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)5 CParameters1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1)5 BgpId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId)5