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
9 package org.opendaylight.protocol.pcep.segment.routing;
11 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
17 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
18 import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrSubobject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.add.lsp.input.arguments.rro.subobject.subobject.type.SrRroTypeBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder;
24 public class SrRroSubobjectParser extends AbstractSrSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
26 private static final int LEGACY_TYPE = 6;
27 private static final int PROPOSED_TYPE = 36;
29 private final int type;
31 SrRroSubobjectParser(final boolean isIanaAssignedType) {
32 this.type = (isIanaAssignedType) ? PROPOSED_TYPE : LEGACY_TYPE;
35 public void serializeSubobject(Subobject subobject, ByteBuf buffer) {
36 Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject,
37 "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType()
39 final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
40 final ByteBuf body = serializeSubobject(srSubobject);
41 RROSubobjectUtil.formatSubobject(this.type, body, buffer);
45 public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
46 final SrRroTypeBuilder srRroSubobjectBuilder = new SrRroTypeBuilder(parseSrSubobject(buffer));
47 final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
48 subobjectBuilder.setSubobjectType(srRroSubobjectBuilder.build());
49 return subobjectBuilder.build();
52 public int getCodePoint() {