blob: 22b0d67ccaba2fe598df9408b5c661a6472ba6a7 [file] [log] [blame]
Kiran Ramachandra959353a2016-02-16 22:12:07 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Kiran Ramachandra959353a2016-02-16 22:12:07 +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.ospf.protocol.lsa;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import org.onosproject.ospf.protocol.util.OspfUtil;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Representation of a TLV header.
27 */
28public class TlvHeader {
29 private int tlvType;
30 private int tlvLength;
31
32 /**
33 * Gets TLV length.
34 *
35 * @return TLV length
36 */
37 public int tlvLength() {
38 return tlvLength;
39 }
40
41 /**
42 * Sets TLV length.
43 *
44 * @param tlvLength TLV length
45 */
46 public void setTlvLength(int tlvLength) {
47 this.tlvLength = tlvLength;
48 }
49
50 /**
51 * Gets TLV type.
52 *
53 * @return TLV type
54 */
55 public int tlvType() {
56 return tlvType;
57 }
58
59 /**
60 * Sets TLV type.
61 *
62 * @param tlvType TLV type
63 */
64 public void setTlvType(int tlvType) {
65 this.tlvType = tlvType;
66 }
67
68 /**
69 * Gets TLV header as bytes.
70 *
71 * @return TLV header as bytes
72 */
73 public byte[] getTlvHeaderAsByteArray() {
74 List<Byte> headerLst = new ArrayList();
75 headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvType)));
76 headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvLength)));
77 return Bytes.toArray(headerLst);
78 }
79
80 @Override
81 public String toString() {
82 return MoreObjects.toStringHelper(getClass())
83 .omitNullValues()
84 .add("tlvType", tlvType)
85 .add("tlvLength", tlvLength)
86 .toString();
87 }
88}