ecc2761b8799da39643799eba543c18e615c7d44
[bgpcep.git] / rsvp / impl / src / main / java / org / opendaylight / protocol / rsvp / parser / impl / te / InformationalFastRerouteObjectParser.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.rsvp.parser.impl.te;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
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.protocol.util.ByteBufWriteUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
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.LegacyFastRerouteObject;
23 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
25 public final class InformationalFastRerouteObjectParser extends AbstractRSVPObjectParser {
26
27     public static final short CLASS_NUM = 205;
28     public static final short CTYPE = 7;
29     private static final int BODY_SIZE_C7 = 16;
30
31     @Override
32     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
33         final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder()
34                 .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
35                 .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
36                 .setHopLimit(ByteBufUtils.readUint8(byteBuf));
37
38         //skip reserved
39         byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
40         final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
41         builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
42         builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
43         builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
44         return builder.build();
45     }
46
47     @Override
48     public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
49         checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory.");
50         final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject;
51         serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator);
52
53         byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
54         byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
55         byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
56         byteAggregator.writeByte(0);
57         byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
58         writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
59         writeAttributeFilter(fastRerouteObject.getExcludeAny(), byteAggregator);
60     }
61 }