Search in sources :

Example 1 with Lspa

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa in project bgpcep by opendaylight.

the class PCEPRequestMessageParser method insertObject.

private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
    final Object obj = objects.get(0);
    switch(state) {
        case INIT:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                objects.remove(0);
                final Object nextObj = objects.get(0);
                if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
                    builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
                }
                return State.REPORTED_IN;
            }
        case REPORTED_IN:
            if (obj instanceof VendorInformationObject) {
                viObjects.add((VendorInformationObject) obj);
                return State.REPORTED_IN;
            }
        case VENDOR_INFO_LIST:
            if (obj instanceof LoadBalancing) {
                builder.setLoadBalancing((LoadBalancing) obj);
                return State.LOAD_BIN;
            }
        case LOAD_BIN:
            if (obj instanceof Lspa) {
                builder.setLspa((Lspa) obj);
                return State.LSPA_IN;
            }
        case LSPA_IN:
            if (obj instanceof Bandwidth) {
                builder.setBandwidth((Bandwidth) obj);
                return State.BANDWIDTH_IN;
            }
        case BANDWIDTH_IN:
            if (obj instanceof Metric) {
                metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
                return State.BANDWIDTH_IN;
            }
        case METRIC_IN:
            if (obj instanceof Iro) {
                builder.setIro((Iro) obj);
                return State.IRO_IN;
            }
        case IRO_IN:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                return State.RRO_IN;
            }
        case RRO_IN:
            if (obj instanceof Xro) {
                builder.setXro((Xro) obj);
                return State.XRO_IN;
            }
        case XRO_IN:
            if (obj instanceof Of) {
                builder.setOf((Of) obj);
                return State.OF_IN;
            }
        case OF_IN:
            if (obj instanceof ClassType) {
                final ClassType classType = (ClassType) obj;
                if (!classType.isProcessingRule()) {
                    errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
                } else {
                    builder.setClassType(classType);
                }
                return State.CT_IN;
            }
        case CT_IN:
        case END:
            return State.END;
        default:
            return state;
    }
}
Also used : Preconditions(com.google.common.base.Preconditions) Iro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro) Rro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro) MetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder) Xro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) ClassType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType) LoadBalancing(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancing) Of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric) Lspa(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa)

Example 2 with Lspa

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa in project bgpcep by opendaylight.

the class PCEPLspaObjectParser method parseObject.

@Override
public Lspa 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 LspaBuilder builder = new LspaBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    builder.setExcludeAny(new AttributeFilter(bytes.readUnsignedInt()));
    builder.setIncludeAll(new AttributeFilter(bytes.readUnsignedInt()));
    builder.setIncludeAny(new AttributeFilter(bytes.readUnsignedInt()));
    builder.setSetupPriority(bytes.readUnsignedByte());
    builder.setHoldPriority(bytes.readUnsignedByte());
    final BitArray flags = BitArray.valueOf(bytes.readByte());
    builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET));
    final TlvsBuilder tbuilder = new TlvsBuilder();
    bytes.skipBytes(RESERVED);
    parseTlvs(tbuilder, bytes.slice());
    builder.setTlvs(tbuilder.build());
    return builder.build();
}
Also used : LspaBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder) TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder) AttributeFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter) BitArray(org.opendaylight.protocol.util.BitArray)

Example 3 with Lspa

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa in project bgpcep by opendaylight.

the class PCEPLspaObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof Lspa, "Wrong instance of PCEPObject. Passed %s. Needed LspaObject.", object.getClass());
    final Lspa lspaObj = (Lspa) object;
    final ByteBuf body = Unpooled.buffer();
    writeAttributeFilter(lspaObj.getExcludeAny(), body);
    writeAttributeFilter(lspaObj.getIncludeAny(), body);
    writeAttributeFilter(lspaObj.getIncludeAll(), body);
    writeUnsignedByte(lspaObj.getSetupPriority(), body);
    writeUnsignedByte(lspaObj.getHoldPriority(), body);
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
    flags.toByteBuf(body);
    body.writeZero(RESERVED);
    serializeTlvs(lspaObj.getTlvs(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray) Lspa(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with Lspa

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testLspaObject.

@Test
public void testLspaObject() throws IOException, PCEPDeserializerException {
    final Stateful07LspaObjectParser parser = new Stateful07LspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final LspaBuilder builder = new LspaBuilder();
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin"));
    final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.SymbolicPathName(new byte[] { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d, (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65 })).build();
    builder.setIgnore(false);
    builder.setProcessingRule(false);
    builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
    builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
    builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
    builder.setHoldPriority((short) 0x02);
    builder.setSetupPriority((short) 0x03);
    builder.setLocalProtectionDesired(true);
    builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().addAugmentation(Tlvs2.class, new Tlvs2Builder().setSymbolicPathName(tlv).build()).build());
    // Tlvs container does not contain toString
    final Object o = parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4));
    assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName());
    // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
    // 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
Also used : LspaBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) SymbolicPathNameBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathNameBuilder) Tlvs2Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs2Builder) ByteBuf(io.netty.buffer.ByteBuf) Stateful07LspaObjectParser(org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspaObjectParser) AttributeFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter) SymbolicPathName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathName) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 BitArray (org.opendaylight.protocol.util.BitArray)2 Lspa (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa)2 LspaBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder)2 AttributeFilter (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter)2 Preconditions (com.google.common.base.Preconditions)1 Test (org.junit.Test)1 Stateful07LspaObjectParser (org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspaObjectParser)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1 Tlvs2Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs2Builder)1 SymbolicPathName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathName)1 SymbolicPathNameBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathNameBuilder)1 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)1 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth)1 ClassType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType)1 Xro (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro)1 Iro (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro)1 LoadBalancing (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancing)1 MetricsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder)1 TlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder)1