blob: bddcb89817b4735ef75b4d3f6d36fd71abc6f485 [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 /**
bharat saraswale1806302015-08-21 12:16:46 +053055 * Constructor to initialize class num, length and type.
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053056 *
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 /**
bharat saraswale1806302015-08-21 12:16:46 +053068 * Sets the Class-Num.
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053069 *
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 *
bharat saraswale1806302015-08-21 12:16:46 +0530124 * @param cb of type channel buffer
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530125 * @return object length index in channel buffer
126 */
bharat saraswale1806302015-08-21 12:16:46 +0530127 public int write(ChannelBuffer cb) {
128 int iLenStartIndex = cb.writerIndex();
129 cb.writeShort((short) 0);
130 cb.writeByte(this.objClassNum);
131 cb.writeByte(this.objClassType);
132 return cb.writerIndex() - iLenStartIndex;
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530133 }
134
135 /**
136 * Reads the PcepRsvpObjectHeader.
137 *
bharat saraswale1806302015-08-21 12:16:46 +0530138 * @param cb input channel buffer
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530139 * @return PcepRsvpObjectHeader
140 */
bharat saraswale1806302015-08-21 12:16:46 +0530141 public static PcepRsvpObjectHeader read(ChannelBuffer cb) {
142 log.debug("read ");
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530143 byte objClassNum;
144 byte objClassType;
145 short objLen;
bharat saraswale1806302015-08-21 12:16:46 +0530146 objLen = cb.readShort();
147 objClassNum = cb.readByte();
148 objClassType = cb.readByte();
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530149
150 return new PcepRsvpObjectHeader(objClassNum, objClassType, objLen);
151 }
152
bharat saraswalf7364db2015-08-11 13:39:31 +0530153 @Override
154 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700155 return MoreObjects.toStringHelper(getClass())
156 .add("ObjectClassNum", objClassNum)
157 .add("ObjectCType", objClassType)
158 .add("ObjectLength", objLen)
159 .toString();
bharat saraswalf7364db2015-08-11 13:39:31 +0530160 }
Phaneendra Manda1c0061d2015-08-06 12:29:38 +0530161}