blob: b721cdfed388b8b9352666dab66dd1dba182d3b9 [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 io.netty.buffer.ByteBuf;
19import org.onosproject.isis.io.util.IsisUtil;
20
21/**
22 * Represents TLV finder.
23 */
24public class TlvFinder extends TlvHeader {
25
26 /**
27 * Sets the value for TLV header and the body of the TLV.
28 *
29 * @param tlvHeader tlvHeader
30 * @param byteBuf byteBuf
31 * @return isisTlv ISIS TLV
32 */
33 public static IsisTlv findTlv(TlvHeader tlvHeader, ByteBuf byteBuf) {
34
35 IsisTlv isisTlv = null;
36
37 switch (tlvHeader.tlvType()) {
38 case IsisUtil.AREAADDRESS:
39 AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
40 areaAddressTlv.readFrom(byteBuf);
41 isisTlv = areaAddressTlv;
42 break;
43 case IsisUtil.IPINTERFACEADDRESS:
44 IpInterfaceAddressTlv ipTlv = new IpInterfaceAddressTlv(tlvHeader);
45 ipTlv.readFrom(byteBuf);
46 isisTlv = ipTlv;
47 break;
48 case IsisUtil.PROTOCOLSUPPORTED:
49 ProtocolSupportedTlv psTlv = new ProtocolSupportedTlv(tlvHeader);
50 psTlv.readFrom(byteBuf);
51 isisTlv = psTlv;
52 break;
53 case IsisUtil.ISNEIGHBORS:
54 IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
55 isisNeighborTlv.readFrom(byteBuf);
56 isisTlv = isisNeighborTlv;
57 break;
58 case IsisUtil.PADDING:
59 PaddingTlv paddingTlv = new PaddingTlv(tlvHeader);
60 paddingTlv.readFrom(byteBuf);
61 isisTlv = paddingTlv;
62 break;
63 default:
64 break;
65 }
66
67 return isisTlv;
68 }
69}