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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
13 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.SrSubobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.add.lsp.input.arguments.ero.subobject.subobject.type.SrEroTypeBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
21 public class SrEroSubobjectParser extends AbstractSrSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
23 private static final int LEGACY_TYPE = 5;
24 private static final int PROPOSED_TYPE = 36;
26 private final int type;
28 SrEroSubobjectParser(final boolean isIanaAssignedType) {
29 this.type = (isIanaAssignedType) ? PROPOSED_TYPE : LEGACY_TYPE;
33 public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
34 Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject,
35 "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType()
38 final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
39 final ByteBuf body = serializeSubobject(srSubobject);
40 EROSubobjectUtil.formatSubobject(this.type, subobject.isLoose(), body, buffer);
44 public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
45 final SrEroTypeBuilder srEroSubobjectBuilder = new SrEroTypeBuilder(parseSrSubobject(buffer));
46 final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
47 subobjectBuilder.setLoose(loose);
48 subobjectBuilder.setSubobjectType(srEroSubobjectBuilder.build());
49 return subobjectBuilder.build();
52 public int getCodePoint() {