blob: a7bb08f281a144d734e78d8990dbd857837c589e [file] [log] [blame]
sunishvka1dfc3e2016-04-16 12:24:47 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sunishvka1dfc3e2016-04-16 12:24:47 +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.subtlv;
17
18import com.google.common.primitives.Bytes;
19import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Representation of conversion of TLV's to bytes.
27 */
28public final class SubTlvToBytes {
29
Ray Milkey9c9cde42018-01-12 14:22:06 -080030 private static final Logger log = LoggerFactory.getLogger(SubTlvToBytes.class);
sunishvka1dfc3e2016-04-16 12:24:47 +053031
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()));
sunish vk7bdf4d42016-06-24 12:29:43 +053063 } else if (subTlv instanceof NeighborIpAddress) {
64 NeighborIpAddress interfaceIpAddress = (NeighborIpAddress) subTlv;
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053065 subTlvBytes.addAll(Bytes.asList(interfaceIpAddress.asBytes()));
sunishvka1dfc3e2016-04-16 12:24:47 +053066 } else {
67 log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
68 }
69
70 return subTlvBytes;
71 }
72}