Search in sources :

Example 1 with ParameterSerializer

use of org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer 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 2 with ParameterSerializer

use of org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer 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 3 with ParameterSerializer

use of org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer in project bgpcep by opendaylight.

the class SimpleParameterRegistry method serializeParameter.

public void serializeParameter(final BgpParameters parameter, ByteBuf bytes) {
    final ParameterSerializer serializer = this.handlers.getSerializer(parameter.getImplementedInterface());
    if (serializer == null) {
        return;
    }
    serializer.serializeParameter(parameter, bytes);
}
Also used : ParameterSerializer(org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer)

Aggregations

ParameterSerializer (org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer)3 ByteBuf (io.netty.buffer.ByteBuf)2 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)2 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)2 ParameterLengthOverflowException (org.opendaylight.protocol.bgp.parser.spi.ParameterLengthOverflowException)1