blob: 50c469946f408eb7fbe04221320b2b3bc1017647 [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
bharat saraswalf7364db2015-08-11 13:39:31 +05303 *
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
Ray Milkey9c9cde42018-01-12 14:22:06 -080043 private static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class);
bharat saraswalf7364db2015-08-11 13:39:31 +053044
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 *
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530119 * @param cb of type channel buffer
bharat saraswalf7364db2015-08-11 13:39:31 +0530120 * @return object length index
121 */
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530122 public int write(ChannelBuffer cb) {
123 int objLenIndex = cb.writerIndex();
124 objLen = 0;
125 cb.writeShort(objLen);
126 cb.writeByte(objClassNum);
127 cb.writeByte(objClassType);
128 return objLenIndex;
bharat saraswalf7364db2015-08-11 13:39:31 +0530129 }
130
131 /**
132 * Reads the PcepRsvpObjectHeader.
133 *
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530134 * @param cb of type channel buffer
bharat saraswalf7364db2015-08-11 13:39:31 +0530135 * @return PcepRsvpObjectHeader
136 */
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530137 public static PcepRsvpSpecObjHeader read(ChannelBuffer cb) {
bharat saraswalf7364db2015-08-11 13:39:31 +0530138 byte objClassNum;
139 byte objClassType;
140 short objLen;
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530141 objLen = cb.readShort();
142 objClassNum = cb.readByte();
143 objClassType = cb.readByte();
bharat saraswalf7364db2015-08-11 13:39:31 +0530144
145 return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType);
146 }
147
bharat saraswalf7364db2015-08-11 13:39:31 +0530148 @Override
149 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700150 return MoreObjects.toStringHelper(getClass())
151 .add("ObjectClassNum: ", objClassNum)
152 .add("ObjectCType: ", objClassType)
153 .add("ObjectLength: ", objLen)
154 .toString();
bharat saraswalf7364db2015-08-11 13:39:31 +0530155 }
156}