blob: 80bf9a9c3df23327883b9f2c0e87ce92bce131d7 [file] [log] [blame]
sunishvka1dfc3e2016-04-16 12:24:47 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sunishvka1dfc3e2016-04-16 12:24:47 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.isis.io.isispacket.tlv.subtlv;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22import org.onosproject.isis.io.util.IsisUtil;
23
24
25/**
26 * Representation of maximum reservable bandwidth TE value.
27 */
28public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
29 private float maximumReservableBandwidth;
30
31 /**
32 * Creates an instance of maximum reservable bandwidth.
33 *
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053034 * @param header TLV header
sunishvka1dfc3e2016-04-16 12:24:47 +053035 */
36 public MaximumReservableBandwidth(TlvHeader header) {
37 this.setTlvType(header.tlvType());
38 this.setTlvLength(header.tlvLength());
39 }
40
41 /**
42 * Sets value of maximum reversible bandwidth.
43 *
44 * @param maximumBandwidth maximum reversible bandwidth
45 */
46 public void setMaximumBandwidth(float maximumBandwidth) {
47 this.maximumReservableBandwidth = maximumBandwidth;
48 }
49
50 /**
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053051 * Returns value of maximum reversible bandwidth.
sunishvka1dfc3e2016-04-16 12:24:47 +053052 *
53 * @return maximumBandwidth maximum reversible bandwidth
54 */
55 public float getMaximumBandwidthValue() {
56 return this.maximumReservableBandwidth;
57 }
58
59 /**
60 * Reads bytes from channel buffer.
61 *
62 * @param channelBuffer channel buffer instance
63 */
64 public void readFrom(ChannelBuffer channelBuffer) {
65 byte[] tempByteArray = new byte[tlvLength()];
66 channelBuffer.readBytes(tempByteArray, 0, tlvLength());
67 int maxBandwidth = (IsisUtil.byteToInteger(tempByteArray));
68 this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
69 }
70
71 /**
72 * Returns byte array of maximum reservable bandwidth.
73 *
74 * @return byte array of maximum reservable bandwidth
75 */
76 public byte[] asBytes() {
77 byte[] linkSubType = null;
78
79 byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
80 byte[] linkSubTlvBody = tlvBodyAsBytes();
81 linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
82 return linkSubType;
83
84 }
85
86 /**
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053087 * Returns maximum reservable bandwidth sub tlv body as byte array.
sunishvka1dfc3e2016-04-16 12:24:47 +053088 *
89 * @return byte of maximum reservable bandwidth sub tlv body
90 */
91 public byte[] tlvBodyAsBytes() {
92 byte[] linkSubTypeBody;
93 linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumReservableBandwidth));
94
95 return linkSubTypeBody;
96 }
97
98 @Override
99 public String toString() {
100 return MoreObjects.toStringHelper(getClass())
101 .add("maximumReservableBandwidth", maximumReservableBandwidth)
102 .toString();
103 }
104}