blob: a6458925dc9916674967c90a070f5c2f1ce0a923 [file] [log] [blame]
mohamed rahile04626f2016-04-05 20:42:53 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
mohamed rahile04626f2016-04-05 20:42:53 +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 */
16package org.onosproject.isis.io.isispacket.tlv;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import io.netty.buffer.ByteBuf;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Represents TLV header.
27 */
28public class TlvHeader implements IsisTlv {
29 private int tlvType;
30 private int tlvLength;
31
32 /**
33 * Gets the TLV length of the TLV.
34 *
35 * @return tlvLength TLV length
36 */
37 public int tlvLength() {
38 return tlvLength;
39 }
40
41 /**
42 * Sets the TLV length for the mTLV.
43 *
44 * @param tlvLength TLV length
45 */
46 public void setTlvLength(int tlvLength) {
47 this.tlvLength = tlvLength;
48 }
49
50 /**
51 * Gets the TLV type of the TLV.
52 *
53 * @return tlvType TLV type
54 */
55 public int tlvType() {
56 return tlvType;
57 }
58
59 /**
60 * Sets TLV type for the TLV.
61 *
62 * @param tlvType TLV type
63 */
64 public void setTlvType(int tlvType) {
65 this.tlvType = tlvType;
66 }
67
68 /**
69 * Sets the TLV values of TLV from b yte buffer.
70 *
71 * @param byteBuf byteBuf.
72 */
73 public void readFrom(ByteBuf byteBuf) {
74 //implemented in sub classes
75 }
76
77
78 /**
79 * Gets the TLV of the TLV as bytes.
80 *
81 * @return null
82 */
83 public byte[] asBytes() {
84 //implemented the subclasses
85 return null;
86 }
87
88 /**
89 * Gets the TLV header of the TLV.
90 *
91 * @return headerLst TLV of the TLV
92 */
93 public byte[] tlvHeaderAsByteArray() {
94 List<Byte> headerLst = new ArrayList();
95 headerLst.add((byte) this.tlvType);
96 headerLst.add((byte) this.tlvLength);
97 return Bytes.toArray(headerLst);
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(getClass())
103 .omitNullValues()
104 .add("tlvType", tlvType)
105 .add("tlvLength", tlvLength)
106 .toString();
107 }
108}