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;
}
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);
}
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);
}
Aggregations