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.te;
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.rsvp.parser.spi.RSVPParsingException;
15 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
16 import org.opendaylight.protocol.util.ByteArray;
17 import org.opendaylight.protocol.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.legacy.fast.reroute.object._case.LegacyFastRerouteObject;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.legacy.fast.reroute.object._case.LegacyFastRerouteObjectBuilder;
24 public final class InformationalFastRerouteObjectParser extends AbstractRSVPObjectParser {
26 public static final short CLASS_NUM = 205;
27 public static final short CTYPE = 7;
28 private static final int BODY_SIZE_C7 = 16;
31 protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
32 final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder()
33 .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
34 .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
35 .setHopLimit(ByteBufUtils.readUint8(byteBuf));
38 byteBuf.skipBytes(Byte.BYTES);
39 final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
40 builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
41 builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
42 builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
43 return builder.build();
47 public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
48 checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory.");
49 final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject;
50 serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator);
52 byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
53 byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
54 byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
55 byteAggregator.writeByte(0);
56 byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
57 writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
58 writeAttributeFilter(fastRerouteObject.getExcludeAny(), byteAggregator);