Search in sources :

Example 1 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class Layer2AttributesExtCom method parseExtendedCommunity.

@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
    final Layer2AttributesExtendedCommunityBuilder builder = new Layer2AttributesExtendedCommunityBuilder();
    final BitArray flags = BitArray.valueOf(body, FLAGS_SIZE);
    builder.setBackupPe(flags.get(BACKUP_PE_OFFSET));
    builder.setPrimaryPe(flags.get(PRIMARY_PE_OFFSET));
    builder.setControlWord(flags.get(CONTROL_WORD_OFFSET));
    builder.setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION)));
    builder.setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE)));
    builder.setL2Mtu(body.readUnsignedShort());
    body.skipBytes(RESERVED);
    return new Layer2AttributesExtendedCommunityCaseBuilder().setLayer2AttributesExtendedCommunity(builder.build()).build();
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray) Layer2AttributesExtendedCommunityCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCaseBuilder) Layer2AttributesExtendedCommunityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder)

Example 2 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class Layer2AttributesExtCom method serializeExtendedCommunity.

@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
    Preconditions.checkArgument(extendedCommunity instanceof Layer2AttributesExtendedCommunityCase, "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.", extendedCommunity);
    final Layer2AttributesExtendedCommunity extCom = ((Layer2AttributesExtendedCommunityCase) extendedCommunity).getLayer2AttributesExtendedCommunity();
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(PRIMARY_PE_OFFSET, extCom.isPrimaryPe());
    flags.set(BACKUP_PE_OFFSET, extCom.isBackupPe());
    flags.set(CONTROL_WORD_OFFSET, extCom.isControlWord());
    final byte[] res = flags.array();
    byte aux = 0;
    final OperationalMode modeOfOperation = extCom.getModeOfOperation();
    if (modeOfOperation != null) {
        aux = UnsignedBytes.checkedCast(modeOfOperation.getIntValue());
        aux = (byte) (aux << THREE_BITS_SHIFT);
        res[res.length - 1] = (byte) (res[res.length - 1] | aux);
    }
    final NormalizationType normalizationType = extCom.getOperatingPer();
    if (normalizationType != null) {
        aux = UnsignedBytes.checkedCast(normalizationType.getIntValue());
        aux = (byte) (aux << FIVE_BITS_SHIFT);
        res[res.length - 1] = (byte) (res[res.length - 1] | aux);
    }
    ByteBufWriteUtil.writeUnsignedShort((int) res[res.length - 1], body);
    ByteBufWriteUtil.writeUnsignedShort(extCom.getL2Mtu(), body);
    body.writeZero(RESERVED);
}
Also used : Layer2AttributesExtendedCommunityCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCase) NormalizationType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.NormalizationType) BitArray(org.opendaylight.protocol.util.BitArray) Layer2AttributesExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunity) OperationalMode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.OperationalMode)

Example 3 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class PCEPProcTimeObjectParser 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 ProcTimeBuilder builder = new ProcTimeBuilder();
    buffer.skipBytes(RESERVED);
    final BitArray flagBits = BitArray.valueOf(buffer, FLAGS);
    builder.setEstimated(flagBits.get(E_FLAG_POSITION));
    builder.setCurrentProcTime(buffer.readUnsignedInt());
    builder.setMinProcTime(buffer.readUnsignedInt());
    builder.setMaxProcTime(buffer.readUnsignedInt());
    builder.setAverageProcTime(buffer.readUnsignedInt());
    builder.setVarianceProcTime(buffer.readUnsignedInt());
    return builder.build();
}
Also used : ProcTimeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Example 4 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class PCEPProcTimeObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof ProcTime, "Wrong instance of PCEPObject. Passed %s. Needed ProcTimeObject.", object.getClass());
    final ProcTime procTime = (ProcTime) object;
    final ByteBuf body = Unpooled.buffer(BODY_SIZE);
    body.writeZero(RESERVED);
    final BitArray flagBits = new BitArray(FLAGS);
    flagBits.set(E_FLAG_POSITION, procTime.isEstimated());
    flagBits.toByteBuf(body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getAverageProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getVarianceProcTime(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : ProcTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class PCEPRequestParameterObjectParser method parseObject.

@Override
public Object 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 BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
    final RpBuilder builder = new RpBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    short priority = 0;
    priority |= flags.get(PRI_SF_OFFSET + 2) ? 1 : 0;
    priority |= (flags.get(PRI_SF_OFFSET + 1) ? 1 : 0) << 1;
    priority |= (flags.get(PRI_SF_OFFSET) ? 1 : 0) << 2;
    if (priority != 0) {
        builder.setPriority(priority);
    }
    builder.setFragmentation(flags.get(F_FLAG_OFFSET));
    builder.setP2mp(flags.get(N_FLAG_OFFSET));
    builder.setEroCompression(flags.get(E_FLAG_OFFSET));
    builder.setMakeBeforeBreak(flags.get(M_FLAG_OFFSET));
    builder.setOrder(flags.get(D_FLAG_OFFSET));
    builder.setPathKey(flags.get(P_FLAG_OFFSET));
    builder.setSupplyOf(flags.get(S_FLAG_OFFSET));
    builder.setLoose(flags.get(O_FLAG_OFFSET));
    builder.setBiDirectional(flags.get(B_FLAG_OFFSET));
    builder.setReoptimization(flags.get(R_FLAG_OFFSET));
    builder.setRequestId(new RequestId(bytes.readUnsignedInt()));
    final TlvsBuilder tlvsBuilder = new TlvsBuilder();
    parseTlvs(tlvsBuilder, bytes.slice());
    builder.setTlvs(tlvsBuilder.build());
    return builder.build();
}
Also used : TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder) RequestId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId) RpBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Aggregations

BitArray (org.opendaylight.protocol.util.BitArray)100 ByteBuf (io.netty.buffer.ByteBuf)27 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)8 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)8 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)6 IpPrefixSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject)4 IpPrefixCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCase)4 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 Weight (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)3 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)3 LabelType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType)3 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder)3 IpPrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder)3 IpPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder)3 ArrayList (java.util.ArrayList)2 ByteBufWriteUtil.writeFloat32 (org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32)2 Stateful1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.Stateful1)2 Nai (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.sr.subobject.Nai)2 RequestId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId)2 Flags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags)2