use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPMonitoringObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final MonitoringBuilder builder = new MonitoringBuilder();
buffer.readBytes(RESERVED);
final BitArray flagBits = BitArray.valueOf(buffer, FLAGS_SIZE);
final Flags flags = new Flags(flagBits.get(G_FLAG_POS), flagBits.get(I_FLAG_POS), flagBits.get(L_FLAG_POS), flagBits.get(C_FLAG_POS), flagBits.get(P_FLAG_POS));
builder.setFlags(flags);
builder.setMonitoringId(buffer.readUnsignedInt());
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, buffer.slice());
builder.setTlvs(tbuilder.build());
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPNoPathObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof NoPath, "Wrong instance of PCEPObject. Passed %s. Needed NoPathObject.", object.getClass());
final NoPath nPObj = (NoPath) object;
final ByteBuf body = Unpooled.buffer();
Preconditions.checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
writeUnsignedByte(nPObj.getNatureOfIssue(), body);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
flags.toByteBuf(body);
body.writeZero(RESERVED_F_LENGTH);
serializeTlvs(nPObj.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPNoPathObjectParser method parseObject.
@Override
public NoPath parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final NoPathBuilder builder = new NoPathBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
builder.setNatureOfIssue(bytes.readUnsignedByte());
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET));
bytes.skipBytes(RESERVED_F_LENGTH);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class TrafficActionEcHandler method serializeExtendedCommunity.
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
Preconditions.checkArgument(extendedCommunity instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.TrafficActionExtendedCommunity, "The extended community %s is not TrafficActionExtendedCommunityCase type.", extendedCommunity);
final TrafficActionExtendedCommunity trafficAction = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.TrafficActionExtendedCommunity) extendedCommunity).getTrafficActionExtendedCommunity();
byteAggregator.writeZero(RESERVED);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(SAMPLE_BIT, trafficAction.isSample());
flags.set(TERMINAL_BIT, trafficAction.isTerminalAction());
flags.toByteBuf(byteAggregator);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class BitmaskOperandParser method serialize.
@Override
public void serialize(final BitmaskOperand op, final int length, final boolean endOfList, final ByteBuf buffer) {
final BitArray bs = new BitArray(OPERAND_LENGTH);
bs.set(END_OF_LIST, endOfList);
bs.set(AND_BIT, op.isAndBit());
bs.set(MATCH, op.isMatch());
bs.set(NOT, op.isNot());
final byte len = (byte) (Integer.numberOfTrailingZeros(length) << LENGTH_SHIFT);
buffer.writeByte(bs.toByte() | len);
}
Aggregations