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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
14 import org.opendaylight.protocol.util.ByteArray;
15 import org.opendaylight.protocol.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.FastRerouteFlags;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.basic.fast.reroute.object._case.BasicFastRerouteObject;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.basic.fast.reroute.object._case.BasicFastRerouteObjectBuilder;
23 public final class FastRerouteObjectParser extends AbstractRSVPObjectParser {
24 public static final short CLASS_NUM = 205;
25 public static final short CTYPE = 1;
26 private static final int BODY_SIZE_C1 = 20;
29 protected RsvpTeObject localParseObject(final ByteBuf byteBuf) {
30 final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder()
31 .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
32 .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
33 .setHopLimit(ByteBufUtils.readUint8(byteBuf))
34 .setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte()));
35 final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
38 .setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)))
39 .setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
40 .setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
41 .setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
46 public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
47 Preconditions.checkArgument(teLspObject instanceof BasicFastRerouteObject, "FastRerouteObject is mandatory.");
48 final BasicFastRerouteObject fastRerouteObject = (BasicFastRerouteObject) teLspObject;
50 serializeAttributeHeader(BODY_SIZE_C1, CLASS_NUM, CTYPE, byteAggregator);
51 byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
52 byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
53 byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
54 byteAggregator.writeByte(fastRerouteObject.getFlags().getIntValue());
55 byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
56 writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
57 writeAttributeFilter(fastRerouteObject.getExcludeAny(), byteAggregator);
58 writeAttributeFilter(fastRerouteObject.getIncludeAll(), byteAggregator);