2 * Copyright (c) 2013 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.parser.subobject;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
16 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
17 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
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;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
24 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
27 * Parser for {@link UnnumberedCase}.
29 public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
30 public static final int TYPE = 4;
32 private static final int RESERVED = 2;
33 private static final int CONTENT_LENGTH = 10;
36 public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
37 checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
38 if (buffer.readableBytes() != CONTENT_LENGTH) {
39 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
40 + "; Expected: " + CONTENT_LENGTH + ".");
42 buffer.skipBytes(RESERVED);
43 return new SubobjectBuilder()
45 .setSubobjectType(new UnnumberedCaseBuilder()
46 .setUnnumbered(new UnnumberedBuilder()
47 .setRouterId(ByteBufUtils.readUint32(buffer))
48 .setInterfaceId(ByteBufUtils.readUint32(buffer))
55 public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
56 checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
57 "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
58 final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
59 final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
60 body.writeZero(RESERVED);
61 ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
62 ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
63 EROSubobjectUtil.formatSubobject(TYPE, subobject.getLoose(), body, buffer);