Promote MessageRegistry to pcep-api
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / SrRroSubobjectParser.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.segment.routing;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
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;
22
23 public class SrRroSubobjectParser extends AbstractSrSubobjectParser implements RROSubobjectParser,
24         RROSubobjectSerializer {
25
26     @Deprecated
27     private static final int LEGACY_TYPE = 6;
28     private static final int IANA_TYPE = 36;
29
30     @Deprecated
31     private final int type;
32
33     SrRroSubobjectParser() {
34         type = IANA_TYPE;
35     }
36
37     @Deprecated
38     SrRroSubobjectParser(final boolean isIanaAssignedType) {
39         type = isIanaAssignedType ? IANA_TYPE : LEGACY_TYPE;
40     }
41
42     @Override
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);
50     }
51
52     @Override
53     public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
54         return new SubobjectBuilder().setSubobjectType(new SrRroTypeBuilder(parseSrSubobject(buffer)).build()).build();
55     }
56
57     @Deprecated
58     public int getCodePoint() {
59         return type;
60     }
61 }