blob: b39bfde03156d6a1eee9f7d1ba121e6c9c7e7dfe [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +05301/*
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 */
16
17package org.onosproject.pcepio.types;
18
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23import com.google.common.base.MoreObjects;
24
25/**
26 * Provides PcepRsvpObjectHeader.
27 */
28public class PcepRsvpSpecObjHeader {
29
30 /*
31 0 1 2 3
32 +-------------+-------------+-------------+-------------+
33 | Length (bytes) | Class-Num | C-Type |
34 +-------------+-------------+-------------+-------------+
35 | |
36 // (Object contents) //
37 | |
38 +-------------+-------------+-------------+-------------+
39
40 ERROR_SPEC object Header
41 */
42
43 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class);
44
45 private short objLen;
46 private byte objClassNum;
47 private byte objClassType;
48
49 /**
50 * Constructor to initialize length, class num and type.
51 *
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
55 */
56 public PcepRsvpSpecObjHeader(short objLen, byte objClassNum, byte objClassType) {
57 this.objLen = objLen;
58 this.objClassNum = objClassNum;
59 this.objClassType = objClassType;
60 }
61
62 /**
63 * Sets the Class num.
64 *
65 * @param value pcep rsvp error spec object class num
66 */
67 public void setObjClassNum(byte value) {
68 this.objClassNum = value;
69 }
70
71 /**
72 * Sets the Class type.
73 *
74 * @param value pcep rsvp error spec object class type
75 */
76 public void setObjClassType(byte value) {
77 this.objClassType = value;
78 }
79
80 /**
81 * Sets the Class Length.
82 *
83 * @param value pcep rsvp error spec object length
84 */
85 public void setObjLen(short value) {
86 this.objLen = value;
87 }
88
89 /**
90 * Returns Object Length.
91 *
92 * @return objLen pcep rsvp error spec object length
93 */
94 public short getObjLen() {
95 return this.objLen;
96 }
97
98 /**
99 * Returns Object num.
100 *
101 * @return objClassNum pcep rsvp error spec object class num
102 */
103 public byte getObjClassNum() {
104 return this.objClassNum;
105 }
106
107 /**
108 * Returns Object type.
109 *
110 * @return objClassType pcep rsvp error spec object class type
111 */
112 public byte getObjClassType() {
113 return this.objClassType;
114 }
115
116 /**
117 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
118 *
119 * @param bb of type channel buffer
120 * @return object length index
121 */
122 public int write(ChannelBuffer bb) {
123 int objLenIndex = bb.writerIndex();
124 bb.writeShort(objLen);
125 bb.writeByte(objClassNum);
126 bb.writeByte(objClassType);
127 return bb.writerIndex() - objLenIndex;
128 }
129
130 /**
131 * Reads the PcepRsvpObjectHeader.
132 *
133 * @param bb of type channel buffer
134 * @return PcepRsvpObjectHeader
135 */
136 public static PcepRsvpSpecObjHeader read(ChannelBuffer bb) {
137 byte objClassNum;
138 byte objClassType;
139 short objLen;
140 objLen = bb.readShort();
141 objClassNum = bb.readByte();
142 objClassType = bb.readByte();
143
144 return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType);
145 }
146
147 /**
148 * Prints the attribute of PcepRsvpObjectHeader.
149 */
150 public void print() {
151
152 log.debug("PcepObjectHeader");
153 log.debug("Object Class-Num: " + objClassNum);
154 log.debug("Object C-Type: " + objClassType);
155 log.debug("Object Length: " + objLen);
156 }
157 @Override
158 public String toString() {
159 return MoreObjects.toStringHelper(getClass())
160 .add("Object Class-Num: " , objClassNum)
161 .add("Object C-Type: " , objClassType)
162 .add("Object Length: " , objLen)
163 .toString();
164 }
165}