blob: eaba07b2da1ae6d3f25ac69ecc3c065b51f7151e [file] [log] [blame]
sunishvka1dfc3e2016-04-16 12:24:47 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sunishvka1dfc3e2016-04-16 12:24:47 +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.subtlv;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22import org.onosproject.isis.io.util.IsisUtil;
23
24
25/**
26 * Representation of an administrative group.
27 */
28public class AdministrativeGroup extends TlvHeader implements TrafficEngineeringSubTlv {
29
30 private int administrativeGroup;
31
32 /**
33 * Creates an administrative group instance.
34 *
35 * @param header Tlv Header instance
36 */
37 public AdministrativeGroup(TlvHeader header) {
38 this.setTlvType(header.tlvType());
39 this.setTlvLength(header.tlvLength());
40 }
41
42 /**
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053043 * Returns administrative group value.
sunishvka1dfc3e2016-04-16 12:24:47 +053044 *
45 * @return administrative group value
46 */
47 public int administrativeGroup() {
48 return administrativeGroup;
49 }
50
51 /**
52 * Sets administrative group value.
53 *
54 * @param administrativeGroup value
55 */
56 public void setAdministrativeGroup(int administrativeGroup) {
57 this.administrativeGroup = administrativeGroup;
58 }
59
60 /**
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053061 * Returns administrative group value.
sunishvka1dfc3e2016-04-16 12:24:47 +053062 *
63 * @return administrativeGroup value
64 */
65 public int getAdministrativeGroupValue() {
66 return this.administrativeGroup;
67 }
68
69 /**
70 * Reads bytes from channel buffer.
71 *
72 * @param channelBuffer Channel buffer instance
73 */
74 public void readFrom(ChannelBuffer channelBuffer) {
75 byte[] tempByteArray = new byte[tlvLength()];
76 channelBuffer.readBytes(tempByteArray, 0, tlvLength());
77 this.setAdministrativeGroup(IsisUtil.byteToInteger(tempByteArray));
78 }
79
80 /**
81 * Returns administrative group as byte array.
82 *
83 * @return administrative group instance as byte array
84 */
85 public byte[] asBytes() {
86 byte[] linkSubType = null;
87
88 byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
89 byte[] linkSubTlvBody = tlvBodyAsBytes();
90 linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
91
92 return linkSubType;
93 }
94
95 /**
Dhruv Dhodye64b93e2016-04-20 19:26:55 +053096 * Returns administrative group body as byte array.
sunishvka1dfc3e2016-04-16 12:24:47 +053097 *
98 * @return byte array of sub tlv administrative group
99 */
100 public byte[] tlvBodyAsBytes() {
101
102 byte[] linkSubTypeBody;
103 linkSubTypeBody = IsisUtil.convertToFourBytes(this.administrativeGroup);
104
105 return linkSubTypeBody;
106 }
107
108 @Override
109 public String toString() {
110 return MoreObjects.toStringHelper(getClass())
111 .add("administrativeGroup", administrativeGroup)
112 .toString();
113 }
114}