2 * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
10 import static org.opendaylight.protocol.rsvp.parser.spi.subobjects.UnnumberedInterfaceSubobjectUtils.parseUnnumeredInterface;
11 import static org.opendaylight.protocol.rsvp.parser.spi.subobjects.UnnumberedInterfaceSubobjectUtils.serializeUnnumeredInterface;
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
17 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
18 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
19 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
25 * Parser for {@link UnnumberedCase}.
27 public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
28 public static final int TYPE = 4;
30 private static final int RESERVED = 2;
31 private static final int CONTENT_LENGTH = 10;
34 public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
35 Preconditions.checkArgument(buffer != null && buffer.isReadable(),
36 "Array of bytes is mandatory. Can't be null or empty.");
37 if (buffer.readableBytes() != CONTENT_LENGTH) {
38 throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
39 + "; Expected: " + CONTENT_LENGTH + ".");
41 final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
42 builder.setLoose(loose);
43 buffer.skipBytes(RESERVED);
44 builder.setSubobjectType(parseUnnumeredInterface(buffer));
45 return builder.build();
49 public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
50 Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
51 "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
52 subobject.getSubobjectType().getClass());
53 final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
54 body.writeZero(RESERVED);
55 serializeUnnumeredInterface(((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(), body);
56 EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);