mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.isis.io.isispacket.tlv; |
| 17 | |
| 18 | import com.google.common.primitives.Bytes; |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 19 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 21 | |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 26 | * Representation of conversion of TLV's to bytes. |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 27 | */ |
| 28 | public final class TlvsToBytes { |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 29 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame^] | 30 | private static final Logger log = LoggerFactory.getLogger(TlvsToBytes.class); |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Creates an instance. |
| 34 | */ |
| 35 | private TlvsToBytes() { |
| 36 | } |
| 37 | |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 38 | /** |
| 39 | * Sets the ISIS TLV and returns in the form of bytes. |
| 40 | * |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 41 | * @param isisTlv isisTlv. |
| 42 | * @return tlvBytes |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 43 | */ |
| 44 | public static List<Byte> tlvToBytes(IsisTlv isisTlv) { |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 45 | List<Byte> tlvBytes = new ArrayList<>(); |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 46 | 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())); |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 61 | } 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 degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 85 | } else if (isisTlv instanceof IsExtendedReachability) { |
| 86 | IsExtendedReachability isExtendedReachability |
| 87 | = (IsExtendedReachability) isisTlv; |
| 88 | tlvBytes.addAll(Bytes.asList(isExtendedReachability.asBytes())); |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 89 | } else { |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 90 | log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 91 | } |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 92 | return tlvBytes; |
| 93 | } |
mohamed rahil | e04626f | 2016-04-05 20:42:53 +0530 | [diff] [blame] | 94 | } |