Reduce noise from BGPSessionImpl
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / SrEroSubobjectParser.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.EROSubobjectParser;
15 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
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.ero.subobject.subobject.type.SrEroTypeBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
21
22 public class SrEroSubobjectParser extends AbstractSrSubobjectParser implements EROSubobjectParser,
23         EROSubobjectSerializer {
24
25     @Deprecated
26     private static final int LEGACY_TYPE = 5;
27     private static final int IANA_TYPE = 36;
28
29     @Deprecated
30     private final int type;
31
32     SrEroSubobjectParser() {
33         type = IANA_TYPE;
34     }
35
36     @Deprecated
37     SrEroSubobjectParser(final boolean isIanaAssignedType) {
38         type = isIanaAssignedType ? IANA_TYPE : LEGACY_TYPE;
39     }
40
41     @Override
42     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
43         checkArgument(subobject.getSubobjectType() instanceof SrSubobject,
44                 "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType()
45                         .getClass());
46
47         final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
48         final ByteBuf body = serializeSubobject(srSubobject);
49         EROSubobjectUtil.formatSubobject(type, subobject.getLoose(), body, buffer);
50     }
51
52     @Override
53     public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
54         final SrEroTypeBuilder srEroSubobjectBuilder = new SrEroTypeBuilder(parseSrSubobject(buffer));
55         final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
56         subobjectBuilder.setLoose(loose);
57         subobjectBuilder.setSubobjectType(srEroSubobjectBuilder.build());
58         return subobjectBuilder.build();
59     }
60
61     @Deprecated
62     public int getCodePoint() {
63         return type;
64     }
65 }