Search in sources :

Example 31 with PathKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey in project bgpcep by opendaylight.

the class PCEPRequestMessageParser method getRequests.

protected List<Requests> getRequests(final Queue<Object> objects, final List<Message> errors) {
    final List<Requests> requests = new ArrayList<>();
    for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
        if (!(obj instanceof Rp)) {
            // if RP obj is missing return error only
            errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.empty()));
            return null;
        }
        final RequestsBuilder rBuilder = new RequestsBuilder();
        final Rp rpObj = (Rp) obj;
        objects.remove();
        if (rpObj.getProcessingRule()) {
            rBuilder.setRp(rpObj);
        } else {
            errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.empty()));
        }
        final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
        if (!vendorInfo.isEmpty()) {
            rBuilder.setVendorInformationObject(vendorInfo);
        }
        // expansion
        if (rpObj.getPathKey()) {
            // FIXME: this can fail on malformed messages (i.e. objects.isEmpty()), add an explicit check/error
            obj = objects.element();
            if (obj instanceof PathKey) {
                // FIXME: shouldn't we be also removing the object?
                rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) obj).build());
            }
        }
        obj = objects.peek();
        if (!(obj instanceof EndpointsObj)) {
            errors.add(createErrorMsg(PCEPErrors.END_POINTS_MISSING, Optional.of(rpObj)));
            return null;
        }
        if (!rpObj.getP2mp()) {
            // p2p
            // FIXME: explicit check for empty/type?
            final EndpointsObj ep = (EndpointsObj) objects.remove();
            final P2pBuilder p2pBuilder = new P2pBuilder();
            if (!ep.getProcessingRule()) {
                errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rpObj)));
            } else {
                p2pBuilder.setEndpointsObj(ep);
            }
            final SegmentComputation segm = getP2PSegmentComputation(p2pBuilder, objects, errors, rpObj);
            if (segm != null) {
                rBuilder.setSegmentComputation(segm);
            }
        } else {
            // p2mp
            final SegmentComputation segm = getP2MPSegmentComputation(objects, errors, rpObj);
            if (segm != null) {
                rBuilder.setSegmentComputation(segm);
            }
        }
        requests.add(rBuilder.build());
    }
    return requests;
}
Also used : ArrayList(java.util.ArrayList) Requests(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests) PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKey) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) PathKeyExpansionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.PathKeyExpansionBuilder) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object) RequestsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder) EndpointsObj(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObj) P2pBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.P2pBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp) SegmentComputation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.SegmentComputation)

Example 32 with PathKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey in project bgpcep by opendaylight.

the class RROPathKey32SubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
    checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance.Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
    final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
    final ByteBuf body = Unpooled.buffer();
    checkArgument(pk.getPceId() != null, "PceId is mandatory.");
    final byte[] pceId = pk.getPceId().getValue();
    if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
        RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
    }
    final PathKey pathKey = pk.getPathKey();
    checkArgument(pathKey != null, "PathKey is mandatory.");
    checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory.");
    ByteBufUtils.write(body, pathKey.getValue());
    body.writeBytes(pceId);
    RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) PathKeyCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.PathKeyCase)

Example 33 with PathKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey in project bgpcep by opendaylight.

the class EROSubobjectParserTest method testEROPathKey32Subobject.

@Test
public void testEROPathKey32Subobject() throws RSVPParsingException {
    final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setLoose(true);
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(Uint16.valueOf(4660)));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_32_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(PATH_KEY_32_BYTES, ByteArray.getAllBytes(buff));
    try {
        parser.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) PathKeyCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder) SubobjectContainerBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder) ByteBuf(io.netty.buffer.ByteBuf) EROPathKey32SubobjectParser(org.opendaylight.protocol.rsvp.parser.impl.subobject.ero.EROPathKey32SubobjectParser) Test(org.junit.Test)

Example 34 with PathKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey in project bgpcep by opendaylight.

the class XROSubobjectParserTest method testXROPathKey128Subobject.

@Test
public void testXROPathKey128Subobject() throws RSVPParsingException {
    final XROPathKey128SubobjectParser parser128 = new XROPathKey128SubobjectParser();
    final XROPathKey32SubobjectParser parser = new XROPathKey32SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setMandatory(true);
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(Uint16.valueOf(4660)));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(), parser128.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_128_BYTES, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(PATH_KEY_128_BYTES, ByteArray.getAllBytes(buff));
    try {
        parser128.parseSubobject(null, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser128.parseSubobject(Unpooled.EMPTY_BUFFER, true);
        Assert.fail();
    } catch (final IllegalArgumentException e) {
        Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) XROPathKey128SubobjectParser(org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROPathKey128SubobjectParser) PathKeyCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder) SubobjectContainerBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder) XROPathKey32SubobjectParser(org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROPathKey32SubobjectParser) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 35 with PathKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey in project bgpcep by opendaylight.

the class XROPathKey32SubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
    checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance.Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
    final ByteBuf body = serializePathKey(pk);
    final byte[] pceId = pk.getPceId().getValue();
    if (pceId.length == PCE_ID_F_LENGTH) {
        XROSubobjectUtil.formatSubobject(TYPE, subobject.getMandatory(), body, buffer);
    } else if (pceId.length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
        XROSubobjectUtil.formatSubobject(XROPathKey128SubobjectParser.TYPE, subobject.getMandatory(), body, buffer);
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PathKeyCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase)

Aggregations

PathKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey)34 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId)33 ByteBuf (io.netty.buffer.ByteBuf)29 Test (org.junit.Test)20 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder)18 PathKeyCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder)15 PathKeyCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder)6 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder)6 ArrayList (java.util.ArrayList)5 PathKeyCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase)5 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)4 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder)4 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)4 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)4 PathKeyCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.PathKeyCaseBuilder)3 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder)3 Before (org.junit.Before)2 EROPathKey128SubobjectParser (org.opendaylight.protocol.pcep.parser.subobject.EROPathKey128SubobjectParser)2 EROPathKey32SubobjectParser (org.opendaylight.protocol.pcep.parser.subobject.EROPathKey32SubobjectParser)2 RROPathKey128SubobjectParser (org.opendaylight.protocol.pcep.parser.subobject.RROPathKey128SubobjectParser)2