blob: f9a9bb8bceb41c6dfa855efd952cc1dff692607a [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.primitives.Bytes;
19
20import java.util.ArrayList;
21import java.util.List;
22
23/**
24 * Represents conversion of TLV's to bytes.
25 */
26public final class TlvsToBytes {
27 /**
28 * Sets the ISIS TLV and returns in the form of bytes.
29 *
30 * @param isisTlv isisTlv
31 * @return tlvBytes TLV bytes
32 */
33 public static List<Byte> tlvToBytes(IsisTlv isisTlv) {
34
35 List<Byte> tlvBytes = new ArrayList();
36 if (isisTlv instanceof AreaAddressTlv) {
37 AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv;
38 tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes()));
39 } else if (isisTlv instanceof IpInterfaceAddressTlv) {
40 IpInterfaceAddressTlv ipInterfaceAddressTlv = (IpInterfaceAddressTlv) isisTlv;
41 tlvBytes.addAll(Bytes.asList(ipInterfaceAddressTlv.asBytes()));
42 } else if (isisTlv instanceof ProtocolSupportedTlv) {
43 ProtocolSupportedTlv protocolSupportedTlv = (ProtocolSupportedTlv) isisTlv;
44 tlvBytes.addAll(Bytes.asList(protocolSupportedTlv.asBytes()));
45 } else if (isisTlv instanceof PaddingTlv) {
46 PaddingTlv paddingTlv = (PaddingTlv) isisTlv;
47 tlvBytes.addAll(Bytes.asList(paddingTlv.asBytes()));
48 } else if (isisTlv instanceof IsisNeighborTlv) {
49 IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv;
50 tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes()));
51 } else {
52 System.out.println("UNKNOWN TLV TYPE ::TlvsToBytes ");
53 }
54
55 return tlvBytes;
56 }
57 /**
58 * Creates an instance.
59 */
60 private TlvsToBytes() {
61 //private constructor
62 }
63}