Search in sources :

Example 6 with Ero

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero in project bgpcep by opendaylight.

the class EROLabelSubobjectParser method parseSubobject.

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() < HEADER_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + HEADER_LENGTH + ".");
    }
    final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
    final short cType = buffer.readUnsignedByte();
    final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
    if (labelType == null) {
        LOG.warn("Ignoring ERO label subobject with unknown C-TYPE: {}", cType);
        return null;
    }
    final LabelBuilder lbuilder = new LabelBuilder().setUniDirectional(reserved.get(U_FLAG_OFFSET)).setLabelType(labelType);
    final SubobjectBuilder builder = new SubobjectBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(lbuilder.build()).build());
    return builder.build();
}
Also used : LabelType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType) LabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.label._case.LabelBuilder) BitArray(org.opendaylight.protocol.util.BitArray) LabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCaseBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)

Example 7 with Ero

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero in project bgpcep by opendaylight.

the class AbstractEROWithSubobjectsParser method parseSubobjects.

protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException {
    // Explicit approval of empty ERO
    Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
    final List<Subobject> subs = new ArrayList<>();
    while (buffer.isReadable()) {
        final boolean loose = (buffer.getUnsignedByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0;
        final int type = buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES & ~(1 << Values.FIRST_BIT_OFFSET);
        final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
        if (length > buffer.readableBytes()) {
            throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes());
        }
        LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
        final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose);
        if (sub == null) {
            LOG.warn("Parsing failed for subobject type: {}. Ignoring subobject.", type);
        } else {
            LOG.debug("Subobject was parsed. {}", sub);
            subs.add(sub);
        }
    }
    return subs;
}
Also used : Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject) ArrayList(java.util.ArrayList) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 8 with Ero

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero in project bgpcep by opendaylight.

the class PCEPValidatorTest method testUnexpectedRroObjectInPcUpdMsg.

@Test
public void testUnexpectedRroObjectInPcUpdMsg() throws PCEPDeserializerException {
    final byte[] badUpdateMsg = { (byte) 0x20, (byte) 0x0b, (byte) 0x00, (byte) 0x50, /* SRP, LSP and ERO objects */
    (byte) 0x21, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x20, (byte) 0x10, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x09, (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x14, (byte) 0x01, (byte) 0x08, (byte) 0x05, (byte) 0x05, (byte) 0x05, (byte) 0x03, (byte) 0x18, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x04, (byte) 0x18, (byte) 0x00, /* RRO object */
    (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x24, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x83, (byte) 0x20, (byte) 0x20, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x09, (byte) 0xde, (byte) 0x20, (byte) 0x00, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
    new InitiatedActivator().start(ctx);
    final StatefulPCUpdateRequestMessageParser parser = new StatefulPCUpdateRequestMessageParser(this.ctx.getObjectHandlerRegistry());
    final ByteBuf buf = Unpooled.wrappedBuffer(badUpdateMsg);
    final List<Message> errors = new ArrayList<>();
    parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
    assertFalse(errors.isEmpty());
    assertEquals(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().setErrors(List.of(new ErrorsBuilder().setErrorObject(new ErrorObjectBuilder().setType(Uint8.valueOf(6)).setValue(Uint8.valueOf(10)).build()).build())).build()).build(), errors.get(0));
}
Also used : StatefulPCUpdateRequestMessageParser(org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCUpdateRequestMessageParser) PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder) InitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated.InitiatedActivator) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) ArrayList(java.util.ArrayList) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.ErrorsBuilder) ByteBuf(io.netty.buffer.ByteBuf) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessageBuilder) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder) Test(org.junit.Test)

Example 9 with Ero

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero in project bgpcep by opendaylight.

the class StatefulPCReportMessageParser method validatePath.

private static boolean validatePath(final Queue<Object> objects, final List<Message> errors, final ReportsBuilder builder) {
    final PathBuilder pBuilder = new PathBuilder();
    Object object = objects.remove();
    if (object instanceof Ero) {
        pBuilder.setEro((Ero) object);
    } else {
        errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.empty()));
        return false;
    }
    parsePath(objects, pBuilder);
    builder.setPath(pBuilder.build());
    return true;
}
Also used : PathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.reports.PathBuilder) Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)

Example 10 with Ero

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testEmptyEroObject.

@Test
public void testEmptyEroObject() throws PCEPDeserializerException {
    final Object object = this.ctx.getObjectHandlerRegistry().parseObject(7, 1, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
    assertNotNull(object);
    assertTrue(object instanceof Ero);
    final Ero eroObject = (Ero) object;
    assertNull(eroObject.getSubobject());
    final ByteBuf buffer = Unpooled.buffer();
    this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
    final byte[] expected = { 0x07, 0x13, 0x00, 0x04 };
    assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
}
Also used : Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)16 Ero (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero)8 ByteBuf (io.netty.buffer.ByteBuf)7 Test (org.junit.Test)7 EroBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder)7 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)5 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject)5 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)5 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)4 LspBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.LspBuilder)4 ArrayDeque (java.util.ArrayDeque)2 InitiatedActivator (org.opendaylight.protocol.pcep.ietf.initiated.InitiatedActivator)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)2 BitArray (org.opendaylight.protocol.util.BitArray)2 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)2 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)2 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)2 SrRange (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrRange)2 SrRangeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrRangeBuilder)2