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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
13 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
14 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
15 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
16 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonPathKeyParser;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
23 * Parser for {PathKey}.
25 public class EROPathKey32SubobjectParser extends CommonPathKeyParser implements EROSubobjectParser,
26 EROSubobjectSerializer {
28 public static final int TYPE = 64;
30 private static final int PCE_ID_F_LENGTH = 4;
32 private static final int CONTENT_LENGTH = 2 + PCE_ID_F_LENGTH;
35 public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
36 Preconditions.checkArgument(buffer != null && buffer.isReadable(),
37 "Array of bytes is mandatory. Can't be null or empty.");
38 if (buffer.readableBytes() != CONTENT_LENGTH) {
39 throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
40 + "Expected: >" + CONTENT_LENGTH + ".");
43 final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
44 builder.setLoose(loose);
45 builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(parsePathKey(PCE_ID_F_LENGTH, buffer)).build());
46 return builder.build();
50 public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
51 Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
52 "Unknown subobject instance.Passed %s. Needed PathKey.",
53 subobject.getSubobjectType().getClass());
54 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
55 .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType())
57 final ByteBuf body = serializePathKey(pk);
58 if (pk.getPceId().getBinary().length == PCE_ID_F_LENGTH) {
59 EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
60 } else if (pk.getPceId().getBinary().length == EROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
61 EROSubobjectUtil.formatSubobject(EROPathKey128SubobjectParser.TYPE, subobject.isLoose(), body, buffer);