blob: 12f4a7338965b0284d83f002e6437fb023e532a9 [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.linksubtype;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.ospf.protocol.lsa.TlvHeader;
22
23/**
24 * Representation of an unknown or experimental TE value.
25 */
26public class UnknownLinkSubType extends TlvHeader implements LinkSubType {
27
28 private byte[] value;
29
30 /**
31 * Creates an instance of this.
32 *
33 * @param header tlv header
34 */
35 public UnknownLinkSubType(TlvHeader header) {
36 this.setTlvType(header.tlvType());
37 this.setTlvLength(header.tlvLength());
38 }
39
40 /**
41 * Gets the unknown subtype value .
42 *
43 * @return unknown subtype value
44 */
45 public byte[] value() {
46 return value;
47 }
48
49 /**
50 * Sets unknown subtype value.
51 *
52 * @param value unknown subtype value.
53 */
54 public void setValue(byte[] value) {
55 this.value = value;
56 }
57
58 /**
59 * Reads bytes from channel buffer .
60 *
61 * @param channelBuffer channel buffer instance
62 */
63 public void readFrom(ChannelBuffer channelBuffer) {
64 byte[] tempByteArray = new byte[tlvLength()];
65 channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 this.setValue(tempByteArray);
67 }
68
69 /**
70 * Returns instance as byte array.
71 *
72 * @return instance as byte array
73 */
74 public byte[] asBytes() {
75 byte[] linkSubType = null;
76
77 byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
78 byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
79 linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
80 return linkSubType;
81
82 }
83
84 /**
85 * Gets instance body as byte array.
86 *
87 * @return instance body as byte array
88 */
89 public byte[] getLinkSubTypeTlvBodyAsByteArray() {
90 return value;
91 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .omitNullValues()
97 .add("value", value)
98 .toString();
99 }
100}