2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.segment.routing;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
14 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
15 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.add.lsp.input.arguments.rro.subobject.subobject.type.SrRroTypeBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.SubobjectType;
23 public class SrRroSubobjectParser extends AbstractSrSubobjectParser implements RROSubobjectParser,
24 RROSubobjectSerializer {
27 private static final int LEGACY_TYPE = 6;
28 private static final int IANA_TYPE = 36;
31 private final int type;
33 SrRroSubobjectParser() {
38 SrRroSubobjectParser(final boolean isIanaAssignedType) {
39 type = isIanaAssignedType ? IANA_TYPE : LEGACY_TYPE;
43 public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
44 final SubobjectType subobjType = subobject.getSubobjectType();
45 checkArgument(subobjType instanceof SrSubobject, "Unknown subobject instance. Passed %s. Needed SrSubobject.",
46 subobjType.getClass());
47 final SrSubobject srSubobject = (SrSubobject) subobjType;
48 final ByteBuf body = serializeSubobject(srSubobject);
49 RROSubobjectUtil.formatSubobject(type, body, buffer);
53 public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
54 return new SubobjectBuilder().setSubobjectType(new SrRroTypeBuilder(parseSrSubobject(buffer)).build()).build();
58 public int getCodePoint() {