sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.subtlv; |
| 17 | |
| 18 | import com.google.common.primitives.Bytes; |
| 19 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; |
| 21 | |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
| 26 | * Representation of conversion of TLV's to bytes. |
| 27 | */ |
| 28 | public final class SubTlvToBytes { |
| 29 | |
| 30 | protected static final Logger log = LoggerFactory.getLogger(SubTlvToBytes.class); |
| 31 | |
| 32 | /** |
| 33 | * Creates an instance. |
| 34 | */ |
| 35 | private SubTlvToBytes() { |
| 36 | //private constructor |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Sets the ISIS sub TLV and returns in the form of bytes. |
| 41 | * |
| 42 | * @param subTlv isisTlv. |
| 43 | * @return subTlvBytes |
| 44 | */ |
| 45 | public static List<Byte> tlvToBytes(TrafficEngineeringSubTlv subTlv) { |
| 46 | |
| 47 | List<Byte> subTlvBytes = new ArrayList<>(); |
| 48 | if (subTlv instanceof AdministrativeGroup) { |
| 49 | AdministrativeGroup administrativeGroup = (AdministrativeGroup) subTlv; |
| 50 | subTlvBytes.addAll(Bytes.asList(administrativeGroup.asBytes())); |
| 51 | } else if (subTlv instanceof MaximumBandwidth) { |
| 52 | MaximumBandwidth maximumBandwidth = (MaximumBandwidth) subTlv; |
| 53 | subTlvBytes.addAll(Bytes.asList(maximumBandwidth.asBytes())); |
| 54 | } else if (subTlv instanceof MaximumReservableBandwidth) { |
| 55 | MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) subTlv; |
| 56 | subTlvBytes.addAll(Bytes.asList(maximumReservableBandwidth.asBytes())); |
| 57 | } else if (subTlv instanceof TrafficEngineeringMetric) { |
| 58 | TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) subTlv; |
| 59 | subTlvBytes.addAll(Bytes.asList(trafficEngineeringMetric.asBytes())); |
| 60 | } else if (subTlv instanceof UnreservedBandwidth) { |
| 61 | UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) subTlv; |
| 62 | subTlvBytes.addAll(Bytes.asList(unreservedBandwidth.asBytes())); |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame^] | 63 | } else if (subTlv instanceof InterfaceIpAddress) { |
| 64 | InterfaceIpAddress interfaceIpAddress = (InterfaceIpAddress) subTlv; |
| 65 | subTlvBytes.addAll(Bytes.asList(interfaceIpAddress.asBytes())); |
sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [diff] [blame] | 66 | } else { |
| 67 | log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); |
| 68 | } |
| 69 | |
| 70 | return subTlvBytes; |
| 71 | } |
| 72 | } |