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.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;
22 public class SrEroSubobjectParser extends AbstractSrSubobjectParser implements EROSubobjectParser,
23 EROSubobjectSerializer {
26 private static final int LEGACY_TYPE = 5;
27 private static final int IANA_TYPE = 36;
30 private final int type;
32 SrEroSubobjectParser() {
37 SrEroSubobjectParser(final boolean isIanaAssignedType) {
38 type = isIanaAssignedType ? IANA_TYPE : LEGACY_TYPE;
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()
47 final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
48 final ByteBuf body = serializeSubobject(srSubobject);
49 EROSubobjectUtil.formatSubobject(type, subobject.getLoose(), body, buffer);
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();
62 public int getCodePoint() {