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.xro;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static org.opendaylight.protocol.rsvp.parser.spi.subobjects.PathKeyUtils.parsePathKey;
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
15 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
21 * Parser for { PathKey}.
23 public class XROPathKey128SubobjectParser implements XROSubobjectParser {
24 public static final int TYPE = 65;
26 protected static final int PCE128_ID_F_LENGTH = 16;
28 private static final int CONTENT128_LENGTH = 2 + PCE128_ID_F_LENGTH;
31 public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
32 throws RSVPParsingException {
33 checkArgument(buffer != null && buffer.isReadable(),
34 "Array of bytes is mandatory. Can't be null or empty.");
35 if (buffer.readableBytes() != CONTENT128_LENGTH) {
36 throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
37 + "; " + "Expected: >" + CONTENT128_LENGTH + ".");
40 final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
41 builder.setMandatory(mandatory);
42 builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(parsePathKey(PCE128_ID_F_LENGTH, buffer)).build());
43 return builder.build();