2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.pcepio.types;
19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import com.google.common.base.MoreObjects;
26 * Provides PcepRsvpObjectHeader.
28 public class PcepRsvpSpecObjHeader {
32 +-------------+-------------+-------------+-------------+
33 | Length (bytes) | Class-Num | C-Type |
34 +-------------+-------------+-------------+-------------+
36 // (Object contents) //
38 +-------------+-------------+-------------+-------------+
40 ERROR_SPEC object Header
43 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class);
46 private byte objClassNum;
47 private byte objClassType;
50 * Constructor to initialize length, class num and type.
52 * @param objLen object length
53 * @param objClassNum pcep rsvp error spec object class num
54 * @param objClassType pcep rsvp error spec object class type
56 public PcepRsvpSpecObjHeader(short objLen, byte objClassNum, byte objClassType) {
58 this.objClassNum = objClassNum;
59 this.objClassType = objClassType;
65 * @param value pcep rsvp error spec object class num
67 public void setObjClassNum(byte value) {
68 this.objClassNum = value;
72 * Sets the Class type.
74 * @param value pcep rsvp error spec object class type
76 public void setObjClassType(byte value) {
77 this.objClassType = value;
81 * Sets the Class Length.
83 * @param value pcep rsvp error spec object length
85 public void setObjLen(short value) {
90 * Returns Object Length.
92 * @return objLen pcep rsvp error spec object length
94 public short getObjLen() {
101 * @return objClassNum pcep rsvp error spec object class num
103 public byte getObjClassNum() {
104 return this.objClassNum;
108 * Returns Object type.
110 * @return objClassType pcep rsvp error spec object class type
112 public byte getObjClassType() {
113 return this.objClassType;
117 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
119 * @param cb of type channel buffer
120 * @return object length index
122 public int write(ChannelBuffer cb) {
123 int objLenIndex = cb.writerIndex();
125 cb.writeShort(objLen);
126 cb.writeByte(objClassNum);
127 cb.writeByte(objClassType);
132 * Reads the PcepRsvpObjectHeader.
134 * @param cb of type channel buffer
135 * @return PcepRsvpObjectHeader
137 public static PcepRsvpSpecObjHeader read(ChannelBuffer cb) {
141 objLen = cb.readShort();
142 objClassNum = cb.readByte();
143 objClassType = cb.readByte();
145 return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType);
149 public String toString() {
150 return MoreObjects.toStringHelper(getClass())
151 .add("ObjectClassNum: ", objClassNum)
152 .add("ObjectCType: ", objClassType)
153 .add("ObjectLength: ", objLen)