blob: 37ee9fc00c8ee16f560cafd18181ab79dcef1aca [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
23/**
24 * Provides PcepRsvpObjectHeader.
25 */
26public class PcepRsvpObjectHeader {
27
28 /*
29 0 1 2 3
30 +-------------+-------------+-------------+-------------+
31 | Length (bytes) | Class-Num | C-Type |
32 +-------------+-------------+-------------+-------------+
33 | |
34 // (Object contents) //
35 | |
36 +-------------+-------------+-------------+-------------+
37
38 ERROR_SPEC object Header
39 */
40
41 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpObjectHeader.class);
42
43 public static final boolean REQ_OBJ_MUST_PROCESS = true;
44 public static final boolean REQ_OBJ_OPTIONAL_PROCESS = false;
45 public static final boolean RSP_OBJ_IGNORED = true;
46 public static final boolean RSP_OBJ_PROCESSED = false;
47 public static final int OBJECT_TYPE_SHIFT_VALUE = 4;
48 private byte objClassNum;
49 private byte objClassType;
50 private short objLen;
51
52 /**
53 * Constructor to initialize class num , length and type.
54 *
55 * @param objClassNum object class number
56 * @param objClassType object class type
57 * @param objLen object length
58 */
59 public PcepRsvpObjectHeader(byte objClassNum, byte objClassType, short objLen) {
60 this.objClassNum = objClassNum;
61 this.objClassType = objClassType;
62 this.objLen = objLen;
63 }
64
65 /**
66 * Sets the Class num.
67 *
68 * @param value object class number
69 */
70 public void setObjClassNum(byte value) {
71 this.objClassNum = value;
72 }
73
74 /**
75 * Sets the Class type.
76 *
77 * @param value object class type
78 */
79 public void setObjClassType(byte value) {
80 this.objClassType = value;
81 }
82
83 /**
84 * Sets the Class Length.
85 *
86 * @param value object length
87 */
88 public void setObjLen(short value) {
89 this.objLen = value;
90 }
91
92 /**
93 * Returns Object Length.
94 *
95 * @return objLen
96 */
97 public short getObjLen() {
98 return this.objLen;
99 }
100
101 /**
102 * Returns Object num.
103 *
104 * @return objClassNum
105 */
106 public byte getObjClassNum() {
107 return this.objClassNum;
108 }
109
110 /**
111 * Returns Object type.
112 *
113 * @return objClassType
114 */
115 public byte getObjClassType() {
116 return this.objClassType;
117 }
118
119 /**
120 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
121 *
122 * @param bb of type channel buffer
123 * @return object length index in channel buffer
124 */
125 public int write(ChannelBuffer bb) {
126 int iLenStartIndex = bb.writerIndex();
127 bb.writeShort((short) 0);
128 bb.writeByte(this.objClassNum);
129 bb.writeByte(this.objClassType);
130 return bb.writerIndex() - iLenStartIndex;
131 }
132
133 /**
134 * Reads the PcepRsvpObjectHeader.
135 *
136 * @param bb of type channel buffer
137 * @return PcepRsvpObjectHeader
138 */
139 public static PcepRsvpObjectHeader read(ChannelBuffer bb) {
140 log.debug("PcepRsvpObjectHeader ::read ");
141 byte objClassNum;
142 byte objClassType;
143 short objLen;
144 objLen = bb.readShort();
145 objClassNum = bb.readByte();
146 objClassType = bb.readByte();
147
148 return new PcepRsvpObjectHeader(objClassNum, objClassType, objLen);
149 }
150
151 /**
152 * Prints the attribute of PcepRsvpObjectHeader.
153 */
154 public void print() {
155
156 log.debug("PcepObjectHeader");
157 log.debug("Object Class-Num: " + objClassNum);
158 log.debug("Object C-Type: " + objClassType);
159 log.debug("Object Length: " + objLen);
160 }
161}