blob: 6de06e160a4346a79d187bcca66b6b68f37ce318 [file] [log] [blame]
Phaneendra Manda1c0061d2015-08-06 12:29:38 +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
bharat saraswalf7364db2015-08-11 13:39:31 +053023import com.google.common.base.MoreObjects;
24
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053025/**
26 * Provides PcepRsvpObjectHeader.
27 */
28public class PcepRsvpObjectHeader {
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
bharat saraswalf7364db2015-08-11 13:39:31 +053041 */
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053042
43 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpObjectHeader.class);
44
45 public static final boolean REQ_OBJ_MUST_PROCESS = true;
46 public static final boolean REQ_OBJ_OPTIONAL_PROCESS = false;
47 public static final boolean RSP_OBJ_IGNORED = true;
48 public static final boolean RSP_OBJ_PROCESSED = false;
49 public static final int OBJECT_TYPE_SHIFT_VALUE = 4;
50 private byte objClassNum;
51 private byte objClassType;
52 private short objLen;
53
54 /**
55 * Constructor to initialize class num , length and type.
56 *
57 * @param objClassNum object class number
58 * @param objClassType object class type
59 * @param objLen object length
60 */
61 public PcepRsvpObjectHeader(byte objClassNum, byte objClassType, short objLen) {
62 this.objClassNum = objClassNum;
63 this.objClassType = objClassType;
64 this.objLen = objLen;
65 }
66
67 /**
68 * Sets the Class num.
69 *
70 * @param value object class number
71 */
72 public void setObjClassNum(byte value) {
73 this.objClassNum = value;
74 }
75
76 /**
77 * Sets the Class type.
78 *
79 * @param value object class type
80 */
81 public void setObjClassType(byte value) {
82 this.objClassType = value;
83 }
84
85 /**
86 * Sets the Class Length.
87 *
88 * @param value object length
89 */
90 public void setObjLen(short value) {
91 this.objLen = value;
92 }
93
94 /**
95 * Returns Object Length.
96 *
97 * @return objLen
98 */
99 public short getObjLen() {
100 return this.objLen;
101 }
102
103 /**
104 * Returns Object num.
105 *
106 * @return objClassNum
107 */
108 public byte getObjClassNum() {
109 return this.objClassNum;
110 }
111
112 /**
113 * Returns Object type.
114 *
115 * @return objClassType
116 */
117 public byte getObjClassType() {
118 return this.objClassType;
119 }
120
121 /**
122 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
123 *
124 * @param bb of type channel buffer
125 * @return object length index in channel buffer
126 */
127 public int write(ChannelBuffer bb) {
128 int iLenStartIndex = bb.writerIndex();
129 bb.writeShort((short) 0);
130 bb.writeByte(this.objClassNum);
131 bb.writeByte(this.objClassType);
132 return bb.writerIndex() - iLenStartIndex;
133 }
134
135 /**
136 * Reads the PcepRsvpObjectHeader.
137 *
138 * @param bb of type channel buffer
139 * @return PcepRsvpObjectHeader
140 */
141 public static PcepRsvpObjectHeader read(ChannelBuffer bb) {
142 log.debug("PcepRsvpObjectHeader ::read ");
143 byte objClassNum;
144 byte objClassType;
145 short objLen;
146 objLen = bb.readShort();
147 objClassNum = bb.readByte();
148 objClassType = bb.readByte();
149
150 return new PcepRsvpObjectHeader(objClassNum, objClassType, objLen);
151 }
152
153 /**
154 * Prints the attribute of PcepRsvpObjectHeader.
155 */
156 public void print() {
157
158 log.debug("PcepObjectHeader");
159 log.debug("Object Class-Num: " + objClassNum);
160 log.debug("Object C-Type: " + objClassType);
161 log.debug("Object Length: " + objLen);
162 }
bharat saraswalf7364db2015-08-11 13:39:31 +0530163
164 @Override
165 public String toString() {
166 return MoreObjects.toStringHelper(getClass())
167 .add("Object Class-Num: " , objClassNum)
168 .add("Object C-Type: " , objClassType)
169 .add("Object Length: " , objLen)
170 .toString();
171 }
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530172}