blob: 859199e0c31bb8444f6a067fd6e8c9b69308a1d3 [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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.pcepio.types;
17
18import java.util.Objects;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.pcepio.protocol.PcepVersion;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import com.google.common.base.MoreObjects;
26
27/**
28 * Provides Unreserved Bandwidth Tlv.
29 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053030public class UnreservedBandwidthSubTlv implements PcepValueType {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070031
32 /* Reference :[RFC5305]/3.6
33 0 1 2 3
34 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 | Type=[TDB36] | Length=4 |
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | Unreserved Bandwidth |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 */
41
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053042 protected static final Logger log = LoggerFactory.getLogger(UnreservedBandwidthSubTlv.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070043
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053044 public static final short TYPE = 25;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070045 public static final short LENGTH = 4;
46
47 private final int rawValue;
48
49 /**
50 * Constructor to initialize rawValue.
51 *
52 * @param rawValue Unreserved Bandwidth
53 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053054 public UnreservedBandwidthSubTlv(int rawValue) {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070055 this.rawValue = rawValue;
56 }
57
58 /**
59 * Returns newly created UnreservedBandwidthTlv object.
60 *
61 * @param raw as Unreserved Bandwidth
62 * @return object of UnreservedBandwidthTlv
63 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053064 public static UnreservedBandwidthSubTlv of(final int raw) {
65 return new UnreservedBandwidthSubTlv(raw);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070066 }
67
68 /**
69 * Returns Unreserved Bandwidth.
70 *
71 * @return rawValue Unreserved Bandwidth
72 */
73 public int getInt() {
74 return rawValue;
75 }
76
77 @Override
78 public PcepVersion getVersion() {
79 return PcepVersion.PCEP_1;
80 }
81
82 @Override
83 public short getType() {
84 return TYPE;
85 }
86
87 @Override
88 public short getLength() {
89 return LENGTH;
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(rawValue);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
101 }
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530102 if (obj instanceof UnreservedBandwidthSubTlv) {
103 UnreservedBandwidthSubTlv other = (UnreservedBandwidthSubTlv) obj;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700104 return Objects.equals(this.rawValue, other.rawValue);
105 }
106 return false;
107 }
108
109 @Override
110 public int write(ChannelBuffer c) {
111 int iLenStartIndex = c.writerIndex();
112 c.writeShort(TYPE);
113 c.writeShort(LENGTH);
114 c.writeInt(rawValue);
115 return c.writerIndex() - iLenStartIndex;
116 }
117
118 /**
119 * Reads byte stream from channel buffer and returns object of UnreservedBandwidthTlv.
120 *
121 * @param c input channel buffer
122 * @return object of UnreservedBandwidthTlv
123 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530124 public static UnreservedBandwidthSubTlv read(ChannelBuffer c) {
125 return UnreservedBandwidthSubTlv.of(c.readInt());
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700126 }
127
128 @Override
129 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700130 return MoreObjects.toStringHelper(getClass())
131 .add("Type", TYPE)
132 .add("Length", LENGTH)
133 .add("Value", rawValue)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700134 .toString();
135 }
136}