Fix rsvp.yang
[bgpcep.git] / rsvp / impl / src / main / java / org / opendaylight / protocol / rsvp / parser / impl / te / BandwidthObjectParser.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 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.RSVPParsingException;
14 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
15 import org.opendaylight.protocol.util.ByteArray;
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.RsvpTeObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.bandwidth.object.bandwidth.object.basic.bandwidth.object._case.BasicBandwidthObject;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.bandwidth.object.bandwidth.object.basic.bandwidth.object._case.BasicBandwidthObjectBuilder;
20
21 public final class BandwidthObjectParser extends AbstractRSVPObjectParser {
22     public static final short CLASS_NUM = 5;
23     public static final short CTYPE = 1;
24     static final Integer BODY_SIZE = 4;
25
26     @Override
27     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
28         final BasicBandwidthObjectBuilder builder = new BasicBandwidthObjectBuilder();
29         final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
30         builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
31         return builder.build();
32     }
33
34     @Override
35     public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
36         Preconditions.checkArgument(teLspObject instanceof BasicBandwidthObject,
37             "BandwidthObject is mandatory.");
38         final BasicBandwidthObject bandObject = (BasicBandwidthObject) teLspObject;
39         serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
40         final Bandwidth band = bandObject.getBandwidth();
41         output.writeBytes(Unpooled.wrappedBuffer(band.getValue()));
42     }
43 }