use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AdminStatusObjectParser method localParseObject.
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
final AdminStatusObjectBuilder adm = new AdminStatusObjectBuilder();
final BitArray reflect = BitArray.valueOf(byteBuf, FLAGS_SIZE);
adm.setReflect(reflect.get(REFLECT));
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
final BitArray flags = BitArray.valueOf(byteBuf, FLAGS_SIZE);
adm.setTesting(flags.get(TESTING));
adm.setAdministrativelyDown(flags.get(DOWN));
adm.setDeletionInProgress(flags.get(DELETION));
return adm.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class ProtectionCommonParser method parseCommonProtectionBodyType1.
protected static ProtectionSubobject parseCommonProtectionBodyType1(final ByteBuf byteBuf) {
final BitArray bitArray = BitArray.valueOf(byteBuf.readByte());
final ProtectionSubobjectBuilder sub = new ProtectionSubobjectBuilder();
sub.setSecondary(bitArray.get(SECONDARY));
// Skip Reserved
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
final int linkFlags = byteBuf.readByte();
sub.setLinkFlags(LinkFlags.forValue(linkFlags));
return sub.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class ProtectionCommonParser method parseCommonProtectionBodyType2.
protected static ProtectionSubobject parseCommonProtectionBodyType2(final ByteBuf byteBuf) throws RSVPParsingException {
if (byteBuf.readableBytes() != CONTENT_LENGTH_C2) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + byteBuf.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH_C2 + ".");
}
final ProtectionSubobjectBuilder sub = new ProtectionSubobjectBuilder();
final BitArray protectionFlag = BitArray.valueOf(byteBuf.readByte());
sub.setSecondary(protectionFlag.get(SECONDARY));
sub.setProtecting(protectionFlag.get(PROTECTING));
sub.setNotification(protectionFlag.get(NOTIFICATION));
sub.setOperational(protectionFlag.get(OPERATIONAL));
final int lspFlags = byteBuf.readByte();
sub.setLspFlag(LspFlag.forValue(lspFlags)).build();
// Skip Reserved
byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
final int linkFlags = byteBuf.readByte();
sub.setLinkFlags(LinkFlags.forValue(linkFlags));
final BitArray bitArray2 = BitArray.valueOf(byteBuf.readByte());
sub.setInPlace(bitArray2.get(IN_PLACE));
sub.setRequired(bitArray2.get(REQUIRED));
final int segFlags = byteBuf.readByte();
sub.setSegFlag(LspFlag.forValue(segFlags));
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
return sub.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class LinkAttributesParser method parseLinkAttributes.
/**
* Parse Link Attributes.
*
* @param attributes key is the tlv type and value is the value of the tlv
* @param protocolId to differentiate parsing methods
* @return {@link LinkStateAttribute}
*/
static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
final List<SrAdjIds> srAdjIds = new ArrayList<>();
final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
final List<PeerSetSids> peerSetSids = new ArrayList<>();
for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
LOG.trace("Link attribute TLV {}", entry.getKey());
final int key = entry.getKey();
final ByteBuf value = entry.getValue();
switch(key) {
case TlvUtil.LOCAL_IPV4_ROUTER_ID:
builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
break;
case TlvUtil.LOCAL_IPV6_ROUTER_ID:
builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
break;
case REMOTE_IPV4_ROUTER_ID:
builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
break;
case REMOTE_IPV6_ROUTER_ID:
builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
break;
case ADMIN_GROUP:
builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case MAX_BANDWIDTH:
builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case MAX_RESERVABLE_BANDWIDTH:
builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case UNRESERVED_BANDWIDTH:
parseUnreservedBandwidth(value, builder);
break;
case TE_METRIC:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getTeMetric());
break;
case LINK_PROTECTION_TYPE:
builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
break;
case MPLS_PROTOCOL:
final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case METRIC:
// length can 3, 2 or 1
builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getMetric());
break;
case SHARED_RISK_LINK_GROUP:
parseSrlg(value, builder);
break;
case LINK_OPAQUE:
LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
break;
case LINK_NAME:
builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
LOG.debug("Parsed Link Name : {}", builder.getLinkName());
break;
case SR_ADJ_ID:
srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
break;
case SR_LAN_ADJ_ID:
srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
break;
case PEER_NODE_SID_CODE:
builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
break;
case PEER_ADJ_SID_CODE:
builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
break;
case PEER_SET_SID_CODE:
peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
break;
default:
LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
}
}
if (!srAdjIds.isEmpty()) {
builder.setSrAdjIds(srAdjIds);
}
if (!srLanAdjIds.isEmpty()) {
builder.setSrLanAdjIds(srLanAdjIds);
}
if (!peerSetSids.isEmpty()) {
builder.setPeerSetSids(peerSetSids);
}
LOG.trace("Finished parsing Link Attributes.");
return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class NodeAttributesParser method serializeNodeFlagBits.
private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
if (nodeFlagBits != null) {
final ByteBuf nodeFlagBuf = Unpooled.buffer(1);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
flags.set(ABBR_BIT, nodeFlagBits.isAbr());
flags.set(ROUTER_BIT, nodeFlagBits.isRouter());
flags.set(V6_BIT, nodeFlagBits.isV6());
flags.toByteBuf(nodeFlagBuf);
TlvUtil.writeTLV(NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
}
}
Aggregations