use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class FSIpv4FragmentHandler method serializeFragment.
@Override
protected final byte serializeFragment(final Fragment fragment) {
final BitArray bs = new BitArray(Byte.SIZE);
bs.set(DONT_FRAGMENT, fragment.isDoNot());
bs.set(FIRST_FRAGMENT, fragment.isFirst());
bs.set(IS_A_FRAGMENT, fragment.isIsA());
bs.set(LAST_FRAGMENT, fragment.isLast());
return bs.toByte();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class FSIpv6FragmentHandler method serializeFragment.
@Override
protected final byte serializeFragment(final Fragment fragment) {
final BitArray bs = new BitArray(Byte.SIZE);
bs.set(DONT_FRAGMENT, Boolean.FALSE);
bs.set(FIRST_FRAGMENT, fragment.isFirst());
bs.set(IS_A_FRAGMENT, fragment.isIsA());
bs.set(LAST_FRAGMENT, fragment.isLast());
return bs.toByte();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class SimpleAttributeRegistry method addAttribute.
private void addAttribute(final ByteBuf buffer, final Map<Integer, RawAttribute> attributes) throws BGPDocumentedException {
final BitArray flags = BitArray.valueOf(buffer.readByte());
final int type = buffer.readUnsignedByte();
final int len = (flags.get(EXTENDED_LENGTH_BIT)) ? buffer.readUnsignedShort() : buffer.readUnsignedByte();
if (!attributes.containsKey(type)) {
final AttributeParser parser = this.handlers.getParser(type);
if (parser == null) {
processUnrecognized(flags, type, buffer, len);
} else {
attributes.put(type, new RawAttribute(parser, buffer.readSlice(len)));
}
} else {
LOG.debug("Ignoring duplicate attribute type {}", type);
}
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.
protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
final PeerType peerType = PeerType.forValue(bytes.readByte());
phBuilder.setType(peerType);
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
phBuilder.setIpv4(!flags.get(V_FLAG_POS));
switch(peerType) {
case L3vpn:
phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
break;
case Local:
phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
break;
case Global:
default:
bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
break;
}
if (phBuilder.isIpv4()) {
bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
phBuilder.setAddress(new IpAddress(Ipv4Util.addressForByteBuf(bytes)));
} else {
phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
}
phBuilder.setAs(new AsNumber(bytes.readUnsignedInt()));
phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt()));
phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt()));
return phBuilder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AbstractMessageParser method parseObjects.
private List<Object> parseObjects(final ByteBuf bytes) throws PCEPDeserializerException {
final List<Object> objs = new ArrayList<>();
while (bytes.isReadable()) {
if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + ".");
}
final int objClass = bytes.readUnsignedByte();
final byte flagsByte = bytes.readByte();
final BitArray flags = BitArray.valueOf(flagsByte);
final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
final int objLength = bytes.readUnsignedShort();
if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + objLength + ".");
}
// copy bytes for deeper parsing
final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt());
final Optional<? extends Object> obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass);
if (obj.isPresent()) {
objs.add(obj.get());
}
} else {
// parseObject is required to return null for P=0 errored objects
final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
if (o != null) {
objs.add(o);
}
}
}
return objs;
}
Aggregations