blob: 659ef57d1c04290e5bfa84505301e81ffda150e1 [file] [log] [blame]
mohamed rahile04626f2016-04-05 20:42:53 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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;
sunishvka1dfc3e2016-04-16 12:24:47 +053019import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
mohamed rahile04626f2016-04-05 20:42:53 +053021
22import java.util.ArrayList;
23import java.util.List;
24
25/**
sunishvka1dfc3e2016-04-16 12:24:47 +053026 * Representation of conversion of TLV's to bytes.
mohamed rahile04626f2016-04-05 20:42:53 +053027 */
28public final class TlvsToBytes {
sunishvka1dfc3e2016-04-16 12:24:47 +053029
Ray Milkey9c9cde42018-01-12 14:22:06 -080030 private static final Logger log = LoggerFactory.getLogger(TlvsToBytes.class);
sunishvka1dfc3e2016-04-16 12:24:47 +053031
32 /**
33 * Creates an instance.
34 */
35 private TlvsToBytes() {
36 }
37
mohamed rahile04626f2016-04-05 20:42:53 +053038 /**
39 * Sets the ISIS TLV and returns in the form of bytes.
40 *
sunishvka1dfc3e2016-04-16 12:24:47 +053041 * @param isisTlv isisTlv.
42 * @return tlvBytes
mohamed rahile04626f2016-04-05 20:42:53 +053043 */
44 public static List<Byte> tlvToBytes(IsisTlv isisTlv) {
sunishvka1dfc3e2016-04-16 12:24:47 +053045 List<Byte> tlvBytes = new ArrayList<>();
mohamed rahile04626f2016-04-05 20:42:53 +053046 if (isisTlv instanceof AreaAddressTlv) {
47 AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv;
48 tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes()));
49 } else if (isisTlv instanceof IpInterfaceAddressTlv) {
50 IpInterfaceAddressTlv ipInterfaceAddressTlv = (IpInterfaceAddressTlv) isisTlv;
51 tlvBytes.addAll(Bytes.asList(ipInterfaceAddressTlv.asBytes()));
52 } else if (isisTlv instanceof ProtocolSupportedTlv) {
53 ProtocolSupportedTlv protocolSupportedTlv = (ProtocolSupportedTlv) isisTlv;
54 tlvBytes.addAll(Bytes.asList(protocolSupportedTlv.asBytes()));
55 } else if (isisTlv instanceof PaddingTlv) {
56 PaddingTlv paddingTlv = (PaddingTlv) isisTlv;
57 tlvBytes.addAll(Bytes.asList(paddingTlv.asBytes()));
58 } else if (isisTlv instanceof IsisNeighborTlv) {
59 IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv;
60 tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes()));
sunishvka1dfc3e2016-04-16 12:24:47 +053061 } else if (isisTlv instanceof AdjacencyStateTlv) {
62 AdjacencyStateTlv isisAdjacencyState
63 = (AdjacencyStateTlv) isisTlv;
64 tlvBytes.addAll(Bytes.asList(isisAdjacencyState.asBytes()));
65 } else if (isisTlv instanceof HostNameTlv) {
66 HostNameTlv hostNameTlv
67 = (HostNameTlv) isisTlv;
68 tlvBytes.addAll(Bytes.asList(hostNameTlv.asBytes()));
69 } else if (isisTlv instanceof IpExtendedReachabilityTlv) {
70 IpExtendedReachabilityTlv ipExtendedReachabilityTlv
71 = (IpExtendedReachabilityTlv) isisTlv;
72 tlvBytes.addAll(Bytes.asList(ipExtendedReachabilityTlv.asBytes()));
73 } else if (isisTlv instanceof IpInternalReachabilityTlv) {
74 IpInternalReachabilityTlv ipInternalReachabilityTlv
75 = (IpInternalReachabilityTlv) isisTlv;
76 tlvBytes.addAll(Bytes.asList(ipInternalReachabilityTlv.asBytes()));
77 } else if (isisTlv instanceof IsReachabilityTlv) {
78 IsReachabilityTlv isReachabilityTlv
79 = (IsReachabilityTlv) isisTlv;
80 tlvBytes.addAll(Bytes.asList(isReachabilityTlv.asBytes()));
81 } else if (isisTlv instanceof LspEntriesTlv) {
82 LspEntriesTlv lspEntriesTlv
83 = (LspEntriesTlv) isisTlv;
84 tlvBytes.addAll(Bytes.asList(lspEntriesTlv.asBytes()));
tejeshwer degala3fe1ed52016-04-22 17:04:01 +053085 } else if (isisTlv instanceof IsExtendedReachability) {
86 IsExtendedReachability isExtendedReachability
87 = (IsExtendedReachability) isisTlv;
88 tlvBytes.addAll(Bytes.asList(isExtendedReachability.asBytes()));
mohamed rahile04626f2016-04-05 20:42:53 +053089 } else {
sunishvka1dfc3e2016-04-16 12:24:47 +053090 log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
mohamed rahile04626f2016-04-05 20:42:53 +053091 }
mohamed rahile04626f2016-04-05 20:42:53 +053092 return tlvBytes;
93 }
mohamed rahile04626f2016-04-05 20:42:53 +053094}