use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class SessionAttributeLspRaObjectParser method localSerializeObject.
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
Preconditions.checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities, "SessionAttributeObject is mandatory.");
final SessionAttributeObjectWithResourcesAffinities sessionObject = (SessionAttributeObjectWithResourcesAffinities) teLspObject;
final ByteBuf sessionName = Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject.getSessionName()));
final int pad = SessionAttributeLspObjectParser.getPadding(sessionName.readableBytes());
serializeAttributeHeader(BODY_SIZE_C1 + pad + sessionName.readableBytes(), CLASS_NUM, CTYPE, output);
writeAttributeFilter(sessionObject.getIncludeAny(), output);
writeAttributeFilter(sessionObject.getExcludeAny(), output);
writeAttributeFilter(sessionObject.getIncludeAll(), output);
output.writeByte(sessionObject.getSetupPriority());
output.writeByte(sessionObject.getHoldPriority());
final BitArray bs = new BitArray(FLAGS_SIZE);
bs.set(SessionAttributeLspObjectParser.LOCAL_PROTECTION, sessionObject.isLocalProtectionDesired());
bs.set(SessionAttributeLspObjectParser.LABEL_RECORDING, sessionObject.isLabelRecordingDesired());
bs.set(SessionAttributeLspObjectParser.SE_STYLE, sessionObject.isSeStyleDesired());
bs.toByteBuf(output);
output.writeByte(sessionName.readableBytes());
output.writeBytes(Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject.getSessionName())));
output.writeZero(pad);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class SessionAttributeLspRaObjectParser method localParseObject.
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new SessionAttributeObjectWithResourcesAffinitiesBuilder();
builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
builder.setSetupPriority(byteBuf.readUnsignedByte());
builder.setHoldPriority(byteBuf.readUnsignedByte());
final BitArray bs = BitArray.valueOf(byteBuf.readByte());
builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION));
builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING));
builder.setSeStyleDesired(bs.get(SessionAttributeLspObjectParser.SE_STYLE));
final short nameLenght = byteBuf.readUnsignedByte();
final ByteBuf auxBuf = byteBuf.readSlice(nameLenght);
final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII);
builder.setSessionName(name);
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class MetricObjectParser method localParseObject.
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
final MetricObjectBuilder builder = new MetricObjectBuilder();
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
final BitArray flags = BitArray.valueOf(byteBuf.readByte());
builder.setBound(flags.get(BOUND));
builder.setComputed(flags.get(COMPUTED));
builder.setMetricType(byteBuf.readUnsignedByte());
builder.setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class MetricObjectParser method localSerializeObject.
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
Preconditions.checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory.");
final MetricObject metric = (MetricObject) teLspObject;
serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
final BitArray reflect = new BitArray(FLAGS_SIZE);
reflect.set(BOUND, metric.isBound());
reflect.set(COMPUTED, metric.isComputed());
reflect.toByteBuf(output);
output.writeByte(metric.getMetricType());
writeFloat32(metric.getValue(), output);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AbstractBmpPerPeerMessageParser method serializePerPeerHeader.
protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
Preconditions.checkArgument(peerHeader != null, "Per-peer header cannot be null.");
final PeerType peerType = peerHeader.getType();
output.writeByte(peerType.getIntValue());
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() != 0);
flags.set(V_FLAG_POS, !peerHeader.isIpv4());
flags.toByteBuf(output);
final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
switch(peerType) {
case L3vpn:
RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
break;
case Local:
output.writeBytes(peerDistinguisher.getBinary());
break;
case Global:
default:
output.writeZero(PEER_DISTINGUISHER_SIZE);
break;
}
if (peerHeader.isIpv4()) {
output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
ByteBufWriteUtil.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
} else {
ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
}
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getAs().getValue(), output);
ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
if (peerHeader.getTimestampSec() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampSec().getValue(), output);
} else {
output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
}
if (peerHeader.getTimestampMicro() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampMicro().getValue(), output);
} else {
output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
}
}
Aggregations