sunishvk
Committed by Gerrit Code Review

ONOS-4083,ONOS-4084:ISIS PDU TLV Data Structures

Change-Id: Ice0d42f2c886fa5f398b562e126614ed45f858a2
Showing 40 changed files with 3378 additions and 288 deletions
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
37 </dependency> 37 </dependency>
38 <dependency> 38 <dependency>
39 <groupId>io.netty</groupId> 39 <groupId>io.netty</groupId>
40 - <artifactId>netty-buffer</artifactId> 40 + <artifactId>netty</artifactId>
41 </dependency> 41 </dependency>
42 <dependency> 42 <dependency>
43 <groupId>org.easymock</groupId> 43 <groupId>org.easymock</groupId>
......
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.util.IsisUtil;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +/**
27 + * Representation of adjacency state TLV of P2P neighbor.
28 + */
29 +public class AdjacencyStateTlv extends TlvHeader implements IsisTlv {
30 +
31 + private byte adjacencyType;
32 + private int localCircuitId;
33 + private String neighborSystemId;
34 + private int neighborLocalCircuitId;
35 +
36 + /**
37 + * Creates an instance of adjacency state TLV..
38 + *
39 + * @param tlvHeader tlvHeader
40 + */
41 + public AdjacencyStateTlv(TlvHeader tlvHeader) {
42 + this.setTlvType(tlvHeader.tlvType());
43 + this.setTlvLength(tlvHeader.tlvLength());
44 + }
45 +
46 + /**
47 + * Returns local circuit ID for adjacency state TLV.
48 + *
49 + * @return local circuit ID
50 + */
51 + public int localCircuitId() {
52 + return localCircuitId;
53 + }
54 +
55 + /**
56 + * Sets local circuit ID for adjacency state TLV.
57 + *
58 + * @param localCircuitId local circuit Id
59 + */
60 + public void setLocalCircuitId(int localCircuitId) {
61 + this.localCircuitId = localCircuitId;
62 + }
63 +
64 + /**
65 + * Returns neighbor system ID for adjacency state TLV.
66 + *
67 + * @return neighbor system ID
68 + */
69 + public String neighborSystemId() {
70 + return neighborSystemId;
71 + }
72 +
73 + /**
74 + * Sets neighbor system ID for adjacency state TLV.
75 + *
76 + * @param neighborSystemId neighbor system ID
77 + */
78 + public void setNeighborSystemId(String neighborSystemId) {
79 + this.neighborSystemId = neighborSystemId;
80 + }
81 +
82 + /**
83 + * Returns neighbor local circuit ID for adjacency state TLV.
84 + *
85 + * @return neighbor local circuit ID
86 + */
87 + public int neighborLocalCircuitId() {
88 + return neighborLocalCircuitId;
89 + }
90 +
91 + /**
92 + * Sets neighbor local circuit ID for adjacency state TLV.
93 + *
94 + * @param neighborLocalCircuitId neighbor local circuit ID
95 + */
96 + public void setNeighborLocalCircuitId(int neighborLocalCircuitId) {
97 + this.neighborLocalCircuitId = neighborLocalCircuitId;
98 + }
99 +
100 + /**
101 + * Returns adjacency type of adjacency state TLV.
102 + *
103 + * @return adjacency type
104 + */
105 + public byte adjacencyType() {
106 + return adjacencyType;
107 + }
108 +
109 + /**
110 + * Sets adjacency type for adjacency state TLV.
111 + *
112 + * @param adjacencyType adjacency type
113 + */
114 + public void setAdjacencyType(byte adjacencyType) {
115 + this.adjacencyType = adjacencyType;
116 + }
117 +
118 + @Override
119 + public void readFrom(ChannelBuffer channelBuffer) {
120 + this.setAdjacencyType(channelBuffer.readByte());
121 + if (channelBuffer.readableBytes() > 0) {
122 + this.setLocalCircuitId(channelBuffer.readInt());
123 + byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
124 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
125 + this.setNeighborSystemId(IsisUtil.systemId(tempByteArray));
126 + this.setNeighborLocalCircuitId(channelBuffer.readInt());
127 + }
128 + }
129 +
130 + @Override
131 + public byte[] asBytes() {
132 + byte[] bytes = null;
133 + byte[] tlvHeader = tlvHeaderAsByteArray();
134 + byte[] tlvBody = tlvBodyAsBytes();
135 + tlvHeader[1] = (byte) tlvBody.length;
136 + bytes = Bytes.concat(tlvHeader, tlvBody);
137 + return bytes;
138 + }
139 +
140 + /**
141 + * Returns adjacency type TLV body as byte array.
142 + *
143 + * @return byteArray TLV body of area address TLV
144 + */
145 + private byte[] tlvBodyAsBytes() {
146 + List<Byte> bytes = new ArrayList<>();
147 + bytes.add(this.adjacencyType);
148 + bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId)));
149 + bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId));
150 + bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId)));
151 + return Bytes.toArray(bytes);
152 + }
153 +
154 + @Override
155 + public String toString() {
156 + return MoreObjects.toStringHelper(getClass())
157 + .omitNullValues()
158 + .add("adjacencyType", adjacencyType)
159 + .add("localCircuitId", localCircuitId)
160 + .add("neighborSystemId", neighborSystemId)
161 + .add("neighborLocalCircuitId", neighborLocalCircuitId)
162 + .toString();
163 + }
164 +}
...@@ -13,52 +13,58 @@ ...@@ -13,52 +13,58 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -
17 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
18 17
19 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
20 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
21 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onosproject.isis.io.util.IsisUtil; 21 import org.onosproject.isis.io.util.IsisUtil;
23 22
24 import java.util.ArrayList; 23 import java.util.ArrayList;
25 import java.util.List; 24 import java.util.List;
26 25
27 /** 26 /**
28 - * Represents the area address TLV. 27 + * Representation of area address TLV.
29 */ 28 */
30 public class AreaAddressTlv extends TlvHeader implements IsisTlv { 29 public class AreaAddressTlv extends TlvHeader implements IsisTlv {
31 30
32 - private List<String> areaAddress = new ArrayList(); 31 + private List<String> areaAddress = new ArrayList<>();
33 32
34 /** 33 /**
35 - * Sets TLV type and TLV length of area address TLV. 34 + * Creates an instance of area address TLV.
36 * 35 *
37 - * @param tlvHeader tlvHeader. 36 + * @param tlvHeader tlvHeader
38 */ 37 */
39 public AreaAddressTlv(TlvHeader tlvHeader) { 38 public AreaAddressTlv(TlvHeader tlvHeader) {
40 -
41 this.setTlvType(tlvHeader.tlvType()); 39 this.setTlvType(tlvHeader.tlvType());
42 this.setTlvLength(tlvHeader.tlvLength()); 40 this.setTlvLength(tlvHeader.tlvLength());
41 + }
43 42
43 + /**
44 + * Adds the area address to the area address TLV.
45 + *
46 + * @param areaAddress area address
47 + */
48 + public void addAddress(String areaAddress) {
49 + this.areaAddress.add(areaAddress);
44 } 50 }
45 51
46 /** 52 /**
47 - * Gets the area address of area address TLV. 53 + * Returns the area address of area address TLV.
48 * 54 *
49 - * @return area address 55 + * @return areaAddress area address
50 */ 56 */
51 public List<String> areaAddress() { 57 public List<String> areaAddress() {
52 return this.areaAddress; 58 return this.areaAddress;
53 } 59 }
54 60
55 @Override 61 @Override
56 - public void readFrom(ByteBuf byteBuf) { 62 + public void readFrom(ChannelBuffer channelBuffer) {
57 - while (byteBuf.readableBytes() > 0) { 63 + while (channelBuffer.readableBytes() > 0) {
58 - int addressLength = byteBuf.readByte(); 64 + int addressLength = channelBuffer.readByte();
59 - byte[] addressBytes = new byte[IsisUtil.THREE_BYTES]; 65 + byte[] addressbytes = new byte[addressLength];
60 - byteBuf.readBytes(addressBytes, 0, IsisUtil.THREE_BYTES); 66 + channelBuffer.readBytes(addressbytes, 0, addressLength);
61 - String areaAddress = IsisUtil.areaAddres(addressBytes); 67 + String areaAddress = IsisUtil.areaAddres(addressbytes);
62 this.areaAddress.add(areaAddress); 68 this.areaAddress.add(areaAddress);
63 } 69 }
64 } 70 }
...@@ -66,38 +72,32 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv { ...@@ -66,38 +72,32 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv {
66 @Override 72 @Override
67 public byte[] asBytes() { 73 public byte[] asBytes() {
68 byte[] bytes = null; 74 byte[] bytes = null;
69 -
70 byte[] tlvHeader = tlvHeaderAsByteArray(); 75 byte[] tlvHeader = tlvHeaderAsByteArray();
71 byte[] tlvBody = tlvBodyAsBytes(); 76 byte[] tlvBody = tlvBodyAsBytes();
77 + tlvHeader[1] = (byte) tlvBody.length;
72 bytes = Bytes.concat(tlvHeader, tlvBody); 78 bytes = Bytes.concat(tlvHeader, tlvBody);
73 -
74 return bytes; 79 return bytes;
75 } 80 }
76 81
77 /** 82 /**
78 - * Gets TLV body of area address TLV. 83 + * Returns TLV body of area address TLV.
79 * 84 *
80 * @return byteArray TLV body of area address TLV 85 * @return byteArray TLV body of area address TLV
81 */ 86 */
82 - public byte[] tlvBodyAsBytes() { 87 + private byte[] tlvBodyAsBytes() {
83 - 88 + List<Byte> bytes = new ArrayList<>();
84 - List<Byte> bytes = new ArrayList();
85 for (String areaAddress : this.areaAddress) { 89 for (String areaAddress : this.areaAddress) {
86 bytes.add((byte) (areaAddress.length() / 2)); 90 bytes.add((byte) (areaAddress.length() / 2));
87 - bytes.addAll(IsisUtil.areaAddresToBytes(areaAddress)); 91 + bytes.addAll(IsisUtil.areaAddressToBytes(areaAddress));
88 - }
89 - byte[] byteArray = new byte[bytes.size()];
90 - int i = 0;
91 - for (byte byt : bytes) {
92 - byteArray[i++] = byt;
93 } 92 }
94 - return byteArray; 93 + return Bytes.toArray(bytes);
95 } 94 }
96 95
97 @Override 96 @Override
98 public String toString() { 97 public String toString() {
99 return MoreObjects.toStringHelper(getClass()) 98 return MoreObjects.toStringHelper(getClass())
100 .omitNullValues() 99 .omitNullValues()
100 + .add("areaAddress", areaAddress)
101 .toString(); 101 .toString();
102 } 102 }
103 } 103 }
...\ No newline at end of file ...\ No newline at end of file
......
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +
22 +/**
23 + * Representation of host name TLV.
24 + */
25 +public class HostNameTlv extends TlvHeader {
26 + private String hostName;
27 +
28 + /**
29 + * Creates an instance of host name TLV.
30 + *
31 + * @param tlvHeader tlvHeader.
32 + */
33 + public HostNameTlv(TlvHeader tlvHeader) {
34 + this.setTlvType(tlvHeader.tlvType());
35 + this.setTlvLength(tlvHeader.tlvLength());
36 +
37 + }
38 +
39 + /**
40 + * Returns host name of host name TLV.
41 + *
42 + * @return host name
43 + */
44 + public String hostName() {
45 + return hostName;
46 + }
47 +
48 + /**
49 + * Sets host name for host name TLV.
50 + *
51 + * @param hostName host name.
52 + */
53 + public void setHostName(String hostName) {
54 + this.hostName = hostName;
55 + }
56 +
57 + @Override
58 + public void readFrom(ChannelBuffer channelBuffer) {
59 + byte[] addressbytes = new byte[this.tlvLength()];
60 + channelBuffer.readBytes(addressbytes, 0, this.tlvLength());
61 + this.hostName = new String(addressbytes);
62 + }
63 +
64 + @Override
65 + public byte[] asBytes() {
66 + byte[] bytes = null;
67 + byte[] tlvHeader = tlvHeaderAsByteArray();
68 + byte[] tlvBody = tlvBodyAsBytes();
69 + tlvHeader[1] = (byte) tlvBody.length;
70 + bytes = Bytes.concat(tlvHeader, tlvBody);
71 + return bytes;
72 + }
73 +
74 + /**
75 + * Returns TLV body of host name TLV.
76 + *
77 + * @return byteArray TLV body of host name TLV
78 + */
79 + private byte[] tlvBodyAsBytes() {
80 + byte[] bytes = this.hostName.getBytes();
81 + return bytes;
82 + }
83 +
84 + @Override
85 + public String toString() {
86 + return MoreObjects.toStringHelper(getClass())
87 + .omitNullValues()
88 + .add("hostName", hostName)
89 + .toString();
90 + }
91 +}
...\ No newline at end of file ...\ No newline at end of file
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +
21 +/**
22 + * Representation of IDRP information TLV.
23 + */
24 +public class IdrpInformationTlv extends TlvHeader implements IsisTlv {
25 +
26 + private byte irdpInformationType;
27 + private int externalInformation;
28 +
29 + /**
30 + * Creates an instance of IDRP information TLV.
31 + *
32 + * @param tlvHeader tlvHeader
33 + */
34 + public IdrpInformationTlv(TlvHeader tlvHeader) {
35 + this.setTlvType(tlvHeader.tlvType());
36 + this.setTlvLength(tlvHeader.tlvLength());
37 + }
38 +
39 + /**
40 + * Returns the external information of IDRP information TLV.
41 + *
42 + * @return external information
43 + */
44 + public int externalInformation() {
45 + return externalInformation;
46 + }
47 +
48 + /**
49 + * Sets the external information for IDRP information TLV.
50 + *
51 + * @param externalInformation external information
52 + */
53 + public void setExternalInformation(int externalInformation) {
54 + this.externalInformation = externalInformation;
55 + }
56 +
57 + /**
58 + * Returns the IDRP information of IDRP information TLV.
59 + *
60 + * @return IDRP information type
61 + */
62 + public byte irdpInformationType() {
63 + return irdpInformationType;
64 + }
65 +
66 + /**
67 + * Sets the IDRP information for IDRP information TLV.
68 + *
69 + * @param irdpInformationType IDRP information type
70 + */
71 + public void setIrdpInformationType(byte irdpInformationType) {
72 + this.irdpInformationType = irdpInformationType;
73 + }
74 +
75 + @Override
76 + public void readFrom(ChannelBuffer channelBuffer) {
77 + //TODO
78 + }
79 +
80 +
81 + @Override
82 + public byte[] asBytes() {
83 + //TODO
84 + return null;
85 + }
86 +
87 + @Override
88 + public String toString() {
89 + return MoreObjects.toStringHelper(getClass())
90 + .omitNullValues()
91 + .add("externalInformation", externalInformation)
92 + .add("irdpInformationType", irdpInformationType)
93 + .toString();
94 + }
95 +}
...\ No newline at end of file ...\ No newline at end of file
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 +
17 +package org.onosproject.isis.io.isispacket.tlv;
18 +
19 +import com.google.common.base.MoreObjects;
20 +import com.google.common.primitives.Bytes;
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
23 +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
24 +import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
25 +import org.onosproject.isis.io.util.IsisUtil;
26 +
27 +import java.util.ArrayList;
28 +import java.util.List;
29 +
30 +/**
31 + * Representation of IP extended reachability TLV.
32 + */
33 +public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
34 +
35 + private String sysIdAndPseudoNumber;
36 + private int defaultMetric;
37 + private byte subTlvLength;
38 + private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
39 +
40 + /**
41 + * Creates an instance of IP external reachability TLV.
42 + *
43 + * @param tlvHeader tlvHeader
44 + */
45 + public IpExtendedReachabilityTlv(TlvHeader tlvHeader) {
46 + this.setTlvType(tlvHeader.tlvType());
47 + this.setTlvLength(tlvHeader.tlvLength());
48 + }
49 +
50 + /**
51 + * Returns the system ID and pseudo number of IP external reachability TLV.
52 + *
53 + * @return sysIdAndPseudoNumber system ID and pseudo number
54 + */
55 + public String sysIdAndPseudoNumber() {
56 + return sysIdAndPseudoNumber;
57 + }
58 +
59 + /**
60 + * Sets the system ID and pseudo number for IP external reachability TLV.
61 + *
62 + * @param sysIdAndPseudoNumber system ID and pseudo number
63 + */
64 + public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
65 + this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
66 + }
67 +
68 + /**
69 + * Adds the traffic engineering sub TLV to IP external reachability TLV.
70 + *
71 + * @param trafEnginSubTlv traffic engineering sub TLV
72 + */
73 + public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
74 + this.trafEnginSubTlv.add(trafEnginSubTlv);
75 + }
76 +
77 + /**
78 + * Returns the sub TLV length of IP external reachability TLV.
79 + *
80 + * @return sub TLV length
81 + */
82 + public byte subTlvLength() {
83 + return subTlvLength;
84 + }
85 +
86 + /**
87 + * Sets the sub TLV length for IP external reachability TLV.
88 + *
89 + * @param subTlvLength sub TLV length
90 + */
91 + public void setSubTlvLength(byte subTlvLength) {
92 + this.subTlvLength = subTlvLength;
93 + }
94 +
95 + /**
96 + * Returns default metric of IP external reachability TLV.
97 + *
98 + * @return default metric
99 + */
100 + public int defaultMetric() {
101 + return defaultMetric;
102 + }
103 +
104 + /**
105 + * Sets default metric for IP external reachability TLV.
106 + *
107 + * @param defaultMetric default metric
108 + */
109 + public void setDefaultMetric(int defaultMetric) {
110 + this.defaultMetric = defaultMetric;
111 + }
112 +
113 + @Override
114 + public void readFrom(ChannelBuffer channelBuffer) {
115 + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
116 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
117 + this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
118 + this.setDefaultMetric(channelBuffer.readUnsignedMedium());
119 + this.setSubTlvLength((byte) channelBuffer.readByte());
120 + while (channelBuffer.readableBytes() > 0) {
121 + TlvHeader tlvHeader = new TlvHeader();
122 + tlvHeader.setTlvType(channelBuffer.readByte());
123 + tlvHeader.setTlvLength(channelBuffer.readByte());
124 + this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
125 + channelBuffer.readBytes(tlvHeader.tlvLength())));
126 + }
127 + }
128 +
129 + @Override
130 + public byte[] asBytes() {
131 + byte[] bytes = null;
132 + byte[] tlvHeader = tlvHeaderAsByteArray();
133 + byte[] tlvBody = tlvBodyAsBytes();
134 + //systemID + pseudo number+length of subtlv=11l
135 + tlvBody[10] = (byte) (tlvBody.length - 11);
136 + tlvHeader[1] = (byte) tlvBody.length;
137 + bytes = Bytes.concat(tlvHeader, tlvBody);
138 + return bytes;
139 + }
140 +
141 + /**
142 + * Returns TLV body of IP external reachability TLV.
143 + *
144 + * @return byteArray TLV body of IP external reachability TLV.
145 + */
146 + private byte[] tlvBodyAsBytes() {
147 + List<Byte> bodyLst = new ArrayList<>();
148 + bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
149 + bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
150 + bodyLst.add(this.subTlvLength());
151 + for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
152 + bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
153 + }
154 + return Bytes.toArray(bodyLst);
155 + }
156 +
157 + @Override
158 + public String toString() {
159 + return MoreObjects.toStringHelper(getClass())
160 + .omitNullValues()
161 + .add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
162 + .add("defaultMetric", defaultMetric)
163 + .add("subTlvLength", subTlvLength)
164 + .add("trafEnginSubTlv", trafEnginSubTlv)
165 + .toString();
166 + }
167 +}
...\ No newline at end of file ...\ No newline at end of file
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 +
17 +package org.onosproject.isis.io.isispacket.tlv;
18 +
19 +import com.google.common.base.MoreObjects;
20 +import com.google.common.primitives.Bytes;
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
23 +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
24 +import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
25 +import org.onosproject.isis.io.util.IsisUtil;
26 +
27 +import java.util.ArrayList;
28 +import java.util.List;
29 +
30 +/**
31 + * Representation of IP external reachability TLV.
32 + */
33 +public class IpExternalReachabilityTlv extends TlvHeader implements IsisTlv {
34 +
35 + private String sysIdAndPseudoNumber;
36 + private int defaultMetric;
37 + private byte subTlvLength;
38 + private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
39 +
40 + /**
41 + * Sets TLV type and TLV length for IP external reachability TLV.
42 + *
43 + * @param tlvHeader tlvHeader
44 + */
45 + public IpExternalReachabilityTlv(TlvHeader tlvHeader) {
46 + this.setTlvType(tlvHeader.tlvType());
47 + this.setTlvLength(tlvHeader.tlvLength());
48 + }
49 +
50 + /**
51 + * Gets the system ID and pseudo number of IP external reachability TLV.
52 + *
53 + * @return sysIdAndPseudoNumber system ID and pseudo number
54 + */
55 + public String sysIdAndPseudoNumber() {
56 + return sysIdAndPseudoNumber;
57 + }
58 +
59 + /**
60 + * Gets the system ID and pseudo number for IP external reachability TLV.
61 + *
62 + * @param sysIdAndPseudoNumber system ID and pseudo number
63 + */
64 + public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
65 + this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
66 + }
67 +
68 + /**
69 + * Adds the traffic engineering sub TLV to IP external reachability TLV.
70 + *
71 + * @param trafEnginSubTlv traffic engineering sub TLV
72 + */
73 + public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
74 + this.trafEnginSubTlv.add(trafEnginSubTlv);
75 + }
76 +
77 + /**
78 + * Gets the sub TLV length of IP external reachability TLV.
79 + *
80 + * @return sub TLV length
81 + */
82 + public byte subTlvLength() {
83 + return subTlvLength;
84 + }
85 +
86 + /**
87 + * Sets the sub TLV length for IP external reachability TLV.
88 + *
89 + * @param subTlvLength sub TLV length
90 + */
91 + public void setSubTlvLength(byte subTlvLength) {
92 + this.subTlvLength = subTlvLength;
93 + }
94 +
95 + /**
96 + * Gets default metric of IP external reachability TLV.
97 + *
98 + * @return default metric
99 + */
100 + public int defaultMetric() {
101 + return defaultMetric;
102 + }
103 +
104 + /**
105 + * Sets default metric for IP external reachability TLV.
106 + *
107 + * @param defaultMetric default metric
108 + */
109 + public void setDefaultMetric(int defaultMetric) {
110 + this.defaultMetric = defaultMetric;
111 + }
112 +
113 + @Override
114 + public void readFrom(ChannelBuffer channelBuffer) {
115 + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
116 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
117 + this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
118 + this.setDefaultMetric(channelBuffer.readUnsignedMedium());
119 + this.setSubTlvLength((byte) channelBuffer.readByte());
120 + while (channelBuffer.readableBytes() > 0) {
121 + TlvHeader tlvHeader = new TlvHeader();
122 + tlvHeader.setTlvType(channelBuffer.readByte());
123 + tlvHeader.setTlvLength(channelBuffer.readByte());
124 + this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
125 + channelBuffer.readBytes(tlvHeader.tlvLength())));
126 + }
127 + }
128 +
129 + @Override
130 + public byte[] asBytes() {
131 + byte[] bytes = null;
132 + byte[] tlvHeader = tlvHeaderAsByteArray();
133 + byte[] tlvBody = tlvBodyAsBytes();
134 + //systemID + pseudo number+length of subtlv=11l
135 + tlvBody[10] = (byte) (tlvBody.length - 11);
136 + tlvHeader[1] = (byte) tlvBody.length;
137 + bytes = Bytes.concat(tlvHeader, tlvBody);
138 + return bytes;
139 + }
140 +
141 + /**
142 + * Gets TLV body of IP external reachability TLV.
143 + *
144 + * @return byteArray TLV body of IP external reachability TLV.
145 + */
146 + public byte[] tlvBodyAsBytes() {
147 + List<Byte> bodyLst = new ArrayList<>();
148 + bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
149 + bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
150 + bodyLst.add(this.subTlvLength());
151 + for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
152 + bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
153 + }
154 + return Bytes.toArray(bodyLst);
155 + }
156 +
157 + @Override
158 + public String toString() {
159 + return MoreObjects.toStringHelper(getClass())
160 + .omitNullValues()
161 + .add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
162 + .add("defaultMetric", defaultMetric)
163 + .add("subTlvLength", subTlvLength)
164 + .toString();
165 + }
166 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv; ...@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
20 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
22 import org.onosproject.isis.io.util.IsisUtil; 22 import org.onosproject.isis.io.util.IsisUtil;
23 23
...@@ -25,13 +25,14 @@ import java.util.ArrayList; ...@@ -25,13 +25,14 @@ import java.util.ArrayList;
25 import java.util.List; 25 import java.util.List;
26 26
27 /** 27 /**
28 - * Represents IP interface address TLV. 28 + * Representation of IP interface address TLV.
29 */ 29 */
30 public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv { 30 public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
31 - private List<Ip4Address> interfaceAddress = new ArrayList(); 31 +
32 + private List<Ip4Address> interfaceAddress = new ArrayList<>();
32 33
33 /** 34 /**
34 - * Sets TLV type and TLV length of IP interface address TLV. 35 + * Creates an instance of IP interface address TLV.
35 * 36 *
36 * @param tlvHeader tlvHeader. 37 * @param tlvHeader tlvHeader.
37 */ 38 */
...@@ -43,58 +44,60 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv { ...@@ -43,58 +44,60 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
43 } 44 }
44 45
45 /** 46 /**
46 - * Gets interface address of interface address TLV. 47 + * Adds the interface address to IP interface address TLV.
48 + *
49 + * @param interfaceAddress interface address
50 + */
51 + public void addInterfaceAddres(Ip4Address interfaceAddress) {
52 + this.interfaceAddress.add(interfaceAddress);
53 + }
54 +
55 + /**
56 + * Returns the interface address of IP interface address TLV.
47 * 57 *
48 - * @return interfaceAddress interface address 58 + * @return interface address
49 */ 59 */
50 public List<Ip4Address> interfaceAddress() { 60 public List<Ip4Address> interfaceAddress() {
51 return interfaceAddress; 61 return interfaceAddress;
52 } 62 }
53 63
54 @Override 64 @Override
55 - public void readFrom(ByteBuf byteBuf) { 65 + public void readFrom(ChannelBuffer channelBuffer) {
56 - while (byteBuf.readableBytes() >= 4) { 66 + while (channelBuffer.readableBytes() >= 4) {
57 byte[] addressbytes = new byte[IsisUtil.FOUR_BYTES]; 67 byte[] addressbytes = new byte[IsisUtil.FOUR_BYTES];
58 - byteBuf.readBytes(addressbytes, 0, IsisUtil.FOUR_BYTES); 68 + channelBuffer.readBytes(addressbytes, 0, IsisUtil.FOUR_BYTES);
59 this.interfaceAddress.add(Ip4Address.valueOf(addressbytes)); 69 this.interfaceAddress.add(Ip4Address.valueOf(addressbytes));
60 } 70 }
61 -
62 } 71 }
63 72
64 @Override 73 @Override
65 public byte[] asBytes() { 74 public byte[] asBytes() {
66 byte[] bytes = null; 75 byte[] bytes = null;
67 -
68 byte[] tlvHeader = tlvHeaderAsByteArray(); 76 byte[] tlvHeader = tlvHeaderAsByteArray();
69 byte[] tlvBody = tlvBodyAsBytes(); 77 byte[] tlvBody = tlvBodyAsBytes();
78 + tlvHeader[1] = (byte) tlvBody.length;
70 bytes = Bytes.concat(tlvHeader, tlvBody); 79 bytes = Bytes.concat(tlvHeader, tlvBody);
71 -
72 return bytes; 80 return bytes;
73 } 81 }
74 82
75 /** 83 /**
76 - * Gets TLV body of interface address TLV. 84 + * Returns TLV body of IP interface address TLV.
77 * 85 *
78 - * @return byteArray TLV body of interface address TLV. 86 + * @return byteArray TLV body of IP interface address TLV
79 */ 87 */
80 - public byte[] tlvBodyAsBytes() { 88 + private byte[] tlvBodyAsBytes() {
81 - 89 + List<Byte> bytes = new ArrayList<>();
82 - List<Byte> bytes = new ArrayList();
83 for (Ip4Address ip4Address : this.interfaceAddress) { 90 for (Ip4Address ip4Address : this.interfaceAddress) {
84 bytes.addAll(Bytes.asList(ip4Address.toOctets())); 91 bytes.addAll(Bytes.asList(ip4Address.toOctets()));
85 } 92 }
86 - byte[] byteArray = new byte[bytes.size()]; 93 + return Bytes.toArray(bytes);
87 - int i = 0;
88 - for (byte byt : bytes) {
89 - byteArray[i++] = byt;
90 - }
91 - return byteArray;
92 } 94 }
93 95
94 @Override 96 @Override
95 public String toString() { 97 public String toString() {
96 return MoreObjects.toStringHelper(getClass()) 98 return MoreObjects.toStringHelper(getClass())
97 .omitNullValues() 99 .omitNullValues()
100 + .add("interfaceAddress", interfaceAddress)
98 .toString(); 101 .toString();
99 } 102 }
100 } 103 }
...\ No newline at end of file ...\ No newline at end of file
......
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +
22 +import java.util.ArrayList;
23 +import java.util.List;
24 +
25 +/**
26 + * Representation of IP internal reachability TLV.
27 + */
28 +public class IpInternalReachabilityTlv extends TlvHeader implements IsisTlv {
29 + private List<MetricOfInternalReachability> metricOfInternalReachability = new ArrayList<>();
30 +
31 + /**
32 + * Creates an instance of IP internal reachability TLV.
33 + *
34 + * @param tlvHeader tlvHeader.
35 + */
36 + public IpInternalReachabilityTlv(TlvHeader tlvHeader) {
37 + this.setTlvType(tlvHeader.tlvType());
38 + this.setTlvLength(tlvHeader.tlvLength());
39 + }
40 +
41 + /**
42 + * Adds the metric of internal reachability to internal reachability TLV.
43 + *
44 + * @param metricValue metric of internal reachability
45 + */
46 + public void addInternalReachabilityMetric(MetricOfInternalReachability metricValue) {
47 + this.metricOfInternalReachability.add(metricValue);
48 + }
49 +
50 + @Override
51 + public void readFrom(ChannelBuffer channelBuffer) {
52 + while (channelBuffer.readableBytes() > 0) {
53 + MetricOfInternalReachability metricOfInternalReachability = new MetricOfInternalReachability();
54 + metricOfInternalReachability.readFrom(channelBuffer);
55 + this.metricOfInternalReachability.add(metricOfInternalReachability);
56 + }
57 + }
58 +
59 + @Override
60 + public byte[] asBytes() {
61 + byte[] bytes = null;
62 + byte[] tlvHeader = tlvHeaderAsByteArray();
63 + byte[] tlvBody = tlvBodyAsBytes();
64 + tlvHeader[1] = (byte) tlvBody.length;
65 + bytes = Bytes.concat(tlvHeader, tlvBody);
66 + return bytes;
67 + }
68 +
69 + /**
70 + * Returns TLV body of internal reachability TLV.
71 + *
72 + * @return byteArray TLV body of area address TLV
73 + */
74 + private byte[] tlvBodyAsBytes() {
75 + List<Byte> bytes = new ArrayList<>();
76 + for (MetricOfInternalReachability metricOfInternalReachability :
77 + this.metricOfInternalReachability) {
78 + bytes.addAll(Bytes.asList(metricOfInternalReachability.asBytes()));
79 + }
80 + return Bytes.toArray(bytes);
81 + }
82 +
83 + @Override
84 + public String toString() {
85 + return MoreObjects.toStringHelper(getClass())
86 + .omitNullValues()
87 + .add("metricOfInternalReachability", metricOfInternalReachability)
88 + .toString();
89 + }
90 +}
...\ No newline at end of file ...\ No newline at end of file
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +
22 +import java.util.ArrayList;
23 +import java.util.List;
24 +
25 +/**
26 + * Representation of IS reachability TLV.
27 + */
28 +public class IsReachabilityTlv extends TlvHeader {
29 +
30 + private int reserved;
31 + private List<MetricsOfReachability> metricsOfReachabilities = new ArrayList<>();
32 +
33 + /**
34 + * Creates an instance of IS reachability TLV.
35 + *
36 + * @param tlvHeader tlvHeader.
37 + */
38 + public IsReachabilityTlv(TlvHeader tlvHeader) {
39 + this.setTlvType(tlvHeader.tlvType());
40 + this.setTlvLength(tlvHeader.tlvLength());
41 + }
42 +
43 + /**
44 + * Returns the reserved value of IS reachability TLV.
45 + *
46 + * @return reserved
47 + */
48 + public int reserved() {
49 + return reserved;
50 + }
51 +
52 + /**
53 + * Sets the reserved value for IS reachability TLV.
54 + *
55 + * @param reserved reserved
56 + */
57 + public void setReserved(int reserved) {
58 + this.reserved = reserved;
59 + }
60 +
61 + /**
62 + * Adds the metric of reachability to IS reachability TLV..
63 + *
64 + * @param metricsOfReachability metric of reachability
65 + */
66 + public void addMeticsOfReachability(MetricsOfReachability metricsOfReachability) {
67 + this.metricsOfReachabilities.add(metricsOfReachability);
68 + }
69 +
70 + @Override
71 + public void readFrom(ChannelBuffer channelBuffer) {
72 + this.setReserved(channelBuffer.readByte());
73 + while (channelBuffer.readableBytes() > 0) {
74 + MetricsOfReachability metricsOfReachability = new MetricsOfReachability();
75 + metricsOfReachability.readFrom(channelBuffer);
76 + this.metricsOfReachabilities.add(metricsOfReachability);
77 + }
78 + }
79 +
80 + @Override
81 + public byte[] asBytes() {
82 + byte[] bytes = null;
83 + byte[] tlvHeader = tlvHeaderAsByteArray();
84 + byte[] tlvBody = tlvBodyAsBytes();
85 + tlvHeader[1] = (byte) tlvBody.length;
86 + bytes = Bytes.concat(tlvHeader, tlvBody);
87 + return bytes;
88 + }
89 +
90 + /**
91 + * Returns TLV body of IS reachability TLV.
92 + *
93 + * @return byteArray TLV body of area address TLV
94 + */
95 + private byte[] tlvBodyAsBytes() {
96 + List<Byte> bytes = new ArrayList<>();
97 + bytes.add((byte) this.reserved());
98 + for (MetricsOfReachability metricsOfReachability : this.metricsOfReachabilities) {
99 + bytes.addAll(Bytes.asList(metricsOfReachability.asBytes()));
100 + }
101 + return Bytes.toArray(bytes);
102 + }
103 +
104 + @Override
105 + public String toString() {
106 + return MoreObjects.toStringHelper(getClass())
107 + .omitNullValues()
108 + .add("metricsOfReachabilities", metricsOfReachabilities)
109 + .toString();
110 + }
111 +}
...@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv; ...@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
20 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onlab.packet.MacAddress; 21 import org.onlab.packet.MacAddress;
22 import org.onosproject.isis.io.util.IsisUtil; 22 import org.onosproject.isis.io.util.IsisUtil;
23 23
...@@ -25,78 +25,77 @@ import java.util.ArrayList; ...@@ -25,78 +25,77 @@ import java.util.ArrayList;
25 import java.util.List; 25 import java.util.List;
26 26
27 /** 27 /**
28 - * Represents ISIS neighbor TLV. 28 + * Representation of ISIS neighbor TLV.
29 */ 29 */
30 public class IsisNeighborTlv extends TlvHeader implements IsisTlv { 30 public class IsisNeighborTlv extends TlvHeader implements IsisTlv {
31 31
32 - private List<MacAddress> neighbor = new ArrayList(); 32 + private List<MacAddress> neighbor = new ArrayList<>();
33 33
34 /** 34 /**
35 - * Sets TLV type and TLV length of ISIS neighbor TLV. 35 + * Creates an instance of ISIS neighbor TLV.
36 * 36 *
37 - * @param tlvHeader tlvHeader. 37 + * @param tlvHeader tlvHeader
38 */ 38 */
39 public IsisNeighborTlv(TlvHeader tlvHeader) { 39 public IsisNeighborTlv(TlvHeader tlvHeader) {
40 -
41 this.setTlvType(tlvHeader.tlvType()); 40 this.setTlvType(tlvHeader.tlvType());
42 this.setTlvLength(tlvHeader.tlvLength()); 41 this.setTlvLength(tlvHeader.tlvLength());
42 + }
43 43
44 + /**
45 + * Adds the MAC address of the neighbor to ISIS neighbor TLV.
46 + *
47 + * @param macAddress MAC address
48 + */
49 + public void addNeighbor(MacAddress macAddress) {
50 + neighbor.add(macAddress);
44 } 51 }
45 52
46 /** 53 /**
47 - * Gets the MAC address of the neighbor TLV. 54 + * Returns the MAC address of the ISIS neighbor TLV.
48 * 55 *
49 - * @return neighbor MAC address of the neighbor TLV 56 + * @return neighbor
50 */ 57 */
51 public List<MacAddress> neighbor() { 58 public List<MacAddress> neighbor() {
52 return this.neighbor; 59 return this.neighbor;
53 } 60 }
54 61
55 @Override 62 @Override
56 - public void readFrom(ByteBuf byteBuf) { 63 + public void readFrom(ChannelBuffer channelBuffer) {
57 - while (byteBuf.readableBytes() >= 6) { 64 + while (channelBuffer.readableBytes() >= 6) {
58 byte[] addressbytes = new byte[IsisUtil.SIX_BYTES]; 65 byte[] addressbytes = new byte[IsisUtil.SIX_BYTES];
59 - byteBuf.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES); 66 + channelBuffer.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES);
60 this.neighbor.add(MacAddress.valueOf(addressbytes)); 67 this.neighbor.add(MacAddress.valueOf(addressbytes));
61 } 68 }
62 -
63 } 69 }
64 70
65 @Override 71 @Override
66 public byte[] asBytes() { 72 public byte[] asBytes() {
67 byte[] bytes = null; 73 byte[] bytes = null;
68 -
69 byte[] tlvHeader = tlvHeaderAsByteArray(); 74 byte[] tlvHeader = tlvHeaderAsByteArray();
70 byte[] tlvBody = tlvBodyAsBytes(); 75 byte[] tlvBody = tlvBodyAsBytes();
76 + tlvHeader[1] = (byte) tlvBody.length;
71 bytes = Bytes.concat(tlvHeader, tlvBody); 77 bytes = Bytes.concat(tlvHeader, tlvBody);
72 -
73 return bytes; 78 return bytes;
74 -
75 } 79 }
76 80
77 /** 81 /**
78 - * Gets TLV body of neighbor TLV. 82 + * Returns TLV body of ISIS neighbor TLV.
79 * 83 *
80 - * @return byteArray TLV body of neighbor TLV 84 + * @return byteArray TLV body of area address TLV
81 */ 85 */
82 - public byte[] tlvBodyAsBytes() { 86 + private byte[] tlvBodyAsBytes() {
83 - 87 + List<Byte> bytes = new ArrayList<>();
84 - List<Byte> bytes = new ArrayList();
85 for (MacAddress macAddress : this.neighbor) { 88 for (MacAddress macAddress : this.neighbor) {
86 bytes.addAll(Bytes.asList(macAddress.toBytes())); 89 bytes.addAll(Bytes.asList(macAddress.toBytes()));
87 } 90 }
88 - byte[] byteArray = new byte[bytes.size()]; 91 + return Bytes.toArray(bytes);
89 - int i = 0;
90 - for (byte byt : bytes) {
91 - byteArray[i++] = byt;
92 - }
93 - return byteArray;
94 } 92 }
95 93
96 @Override 94 @Override
97 public String toString() { 95 public String toString() {
98 return MoreObjects.toStringHelper(getClass()) 96 return MoreObjects.toStringHelper(getClass())
99 .omitNullValues() 97 .omitNullValues()
98 + .add("neighbor", neighbor)
100 .toString(); 99 .toString();
101 } 100 }
102 } 101 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
17 17
18 /** 18 /**
19 - * Represents ISIS TLV. 19 + * Representation of ISIS TLV.
20 */ 20 */
21 public interface IsisTlv { 21 public interface IsisTlv {
22 } 22 }
...\ No newline at end of file ...\ No newline at end of file
......
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +
22 +import java.util.ArrayList;
23 +import java.util.List;
24 +
25 +/**
26 + * Representation of LSP entries TLV.
27 + */
28 +public class LspEntriesTlv extends TlvHeader implements IsisTlv {
29 + private List<LspEntry> lspEntryList = new ArrayList<>();
30 +
31 + /**
32 + * Creates an instance of LSP entries TLV.
33 + *
34 + * @param tlvHeader tlvHeader.
35 + */
36 + public LspEntriesTlv(TlvHeader tlvHeader) {
37 + this.setTlvType(tlvHeader.tlvType());
38 + this.setTlvLength(tlvHeader.tlvLength());
39 + }
40 +
41 + /**
42 + * Returns the LSP entry of LSP entries TLV.
43 + *
44 + * @return LSP entries
45 + */
46 + public List<LspEntry> lspEntry() {
47 + return lspEntryList;
48 + }
49 +
50 + /**
51 + * Adds the the LSP entry to LSP entries TLV.
52 + *
53 + * @param lspEntry LSP entry
54 + */
55 + public void addLspEntry(LspEntry lspEntry) {
56 + this.lspEntryList.add(lspEntry);
57 + }
58 +
59 + @Override
60 + public void readFrom(ChannelBuffer channelBuffer) {
61 + while (channelBuffer.readableBytes() >= 16) {
62 + LspEntry lspEntry = new LspEntry();
63 + lspEntry.readFrom(channelBuffer.readBytes(16));
64 + lspEntryList.add(lspEntry);
65 + }
66 + }
67 +
68 + @Override
69 + public byte[] asBytes() {
70 + byte[] bytes = null;
71 + byte[] tlvHeader = tlvHeaderAsByteArray();
72 + byte[] tlvBody = tlvBodyAsBytes();
73 + tlvHeader[1] = (byte) tlvBody.length;
74 + bytes = Bytes.concat(tlvHeader, tlvBody);
75 + return bytes;
76 + }
77 +
78 + /**
79 + * Returns TLV body of LSP entries TLV.
80 + *
81 + * @return byteArray TLV body of LSP entries TLV
82 + */
83 + private byte[] tlvBodyAsBytes() {
84 + List<Byte> bytes = new ArrayList<>();
85 + for (LspEntry lspEntry : lspEntryList) {
86 + bytes.addAll(Bytes.asList(lspEntry.lspEntryAsBytes()));
87 + }
88 + return Bytes.toArray(bytes);
89 + }
90 +
91 + @Override
92 + public String toString() {
93 + return MoreObjects.toStringHelper(getClass())
94 + .omitNullValues()
95 + .add("lspEntryList", lspEntryList)
96 + .toString();
97 + }
98 +}
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.util.IsisUtil;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +/**
27 + * Representation of LSP entry.
28 + */
29 +public class LspEntry {
30 +
31 + private int lspSequenceNumber;
32 + private int lspChecksum;
33 + private int remainingTime;
34 + private String lspId;
35 +
36 +
37 + /**
38 + * Returns LSP sequence number of LSP entry.
39 + *
40 + * @return LSP sequence number
41 + */
42 + public int lspSequenceNumber() {
43 + return lspSequenceNumber;
44 + }
45 +
46 + /**
47 + * Sets LSP sequenceNumber for LSP entry.
48 + *
49 + * @param lspSequenceNumber lspSequenceNumber.
50 + */
51 + public void setLspSequenceNumber(int lspSequenceNumber) {
52 + this.lspSequenceNumber = lspSequenceNumber;
53 + }
54 +
55 + /**
56 + * Returns LSP checksum of LSP entry.
57 + *
58 + * @return LSP checksum
59 + */
60 + public int lspChecksum() {
61 + return lspChecksum;
62 + }
63 +
64 + /**
65 + * Sets LSP checksum for LSP entry.
66 + *
67 + * @param lspChecksum LSP checksum
68 + */
69 + public void setLspChecksum(int lspChecksum) {
70 + this.lspChecksum = lspChecksum;
71 + }
72 +
73 + /**
74 + * Returns remaining time of LSP entry.
75 + *
76 + * @return remaining time
77 + */
78 + public int remainingTime() {
79 + return remainingTime;
80 + }
81 +
82 + /**
83 + * Sets remaining time for LSP entry.
84 + *
85 + * @param remainingTime remaining time
86 + */
87 + public void setRemainingTime(int remainingTime) {
88 + this.remainingTime = remainingTime;
89 + }
90 +
91 + /**
92 + * Returns LSP ID of LSP entry.
93 + *
94 + * @return LSP ID
95 + */
96 + public String lspId() {
97 + return lspId;
98 + }
99 +
100 + /**
101 + * Sets LSP ID for LSp entry.
102 + *
103 + * @param lspId LSP ID
104 + */
105 + public void setLspId(String lspId) {
106 + this.lspId = lspId;
107 + }
108 +
109 + /**
110 + * Sets the LSP entry values for LSP entry from byte buffer.
111 + *
112 + * @param channelBuffer channel Buffer instance
113 + */
114 + public void readFrom(ChannelBuffer channelBuffer) {
115 + this.setRemainingTime(channelBuffer.readUnsignedShort());
116 + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
117 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
118 + this.setLspId(IsisUtil.systemIdPlus(tempByteArray));
119 + this.setLspSequenceNumber(channelBuffer.readInt());
120 + this.setLspChecksum(channelBuffer.readUnsignedByte());
121 + }
122 +
123 + /**
124 + * Returns LSP entry values as bytes of LSP entry.
125 + *
126 + * @return byteArray LSP entry values as bytes of LSP entry
127 + */
128 + public byte[] lspEntryAsBytes() {
129 + List<Byte> bytes = new ArrayList<>();
130 + bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.remainingTime())));
131 + bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.lspId()));
132 + bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.lspSequenceNumber())));
133 + bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.lspChecksum())));
134 + return Bytes.toArray(bytes);
135 + }
136 +
137 + @Override
138 + public String toString() {
139 + return MoreObjects.toStringHelper(getClass())
140 + .omitNullValues()
141 + .add("lspSequenceNumber", lspSequenceNumber)
142 + .add("lspChecksum", lspChecksum)
143 + .add("remainingTime", remainingTime)
144 + .add("lspId", lspId)
145 + .toString();
146 + }
147 +}
...\ No newline at end of file ...\ No newline at end of file
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +import java.util.ArrayList;
25 +import java.util.List;
26 +
27 +/**
28 + * Representation of metric of internal reachability.
29 + */
30 +public class MetricOfInternalReachability {
31 + private Ip4Address ipAddress;
32 + private Ip4Address subnetAddres;
33 + private byte defaultMetric;
34 + private byte delayMetric;
35 + private byte expenseMetric;
36 + private byte errorMetric;
37 + private boolean delayMetricSupported;
38 + private boolean expenseMetricSupported;
39 + private boolean errorMetricSupported;
40 + private boolean defaultIsInternal;
41 + private boolean defaultDistributionDown;
42 + private boolean delayIsInternal;
43 + private boolean expenseIsInternal;
44 + private boolean errorIsInternal;
45 +
46 + /**
47 + * Returns the IP address of metric of internal reachability.
48 + *
49 + * @return ipAddress IP address of metric of internal reachability
50 + */
51 + public Ip4Address getIpAddress() {
52 + return ipAddress;
53 + }
54 +
55 + /**
56 + * Sets the IP address for metric of internal reachability.
57 + *
58 + * @param ipAddress ip address
59 + */
60 + public void setIpAddress(Ip4Address ipAddress) {
61 + this.ipAddress = ipAddress;
62 + }
63 +
64 + /**
65 + * Returns the subnet address of metric of internal reachability.
66 + *
67 + * @return subnetAddres subnet address of metric of internal reachability
68 + */
69 + public Ip4Address getSubnetAddres() {
70 + return subnetAddres;
71 + }
72 +
73 + /**
74 + * Sets the subnet address for metric of internal reachability.
75 + *
76 + * @param subnetAddres subnet address
77 + */
78 + public void setSubnetAddres(Ip4Address subnetAddres) {
79 + this.subnetAddres = subnetAddres;
80 + }
81 +
82 + /**
83 + * Returns error metric is internal or not.
84 + *
85 + * @return true if internal else false
86 + */
87 + public boolean isErrorIsInternal() {
88 + return errorIsInternal;
89 + }
90 +
91 + /**
92 + * Sets error metric is internal or not.
93 + *
94 + * @param errorIsInternal true if internal else false
95 + */
96 + public void setErrorIsInternal(boolean errorIsInternal) {
97 + this.errorIsInternal = errorIsInternal;
98 + }
99 +
100 + /**
101 + * Returns expense metric is internal or not.
102 + *
103 + * @return true if internal else false
104 + */
105 + public boolean isExpenseIsInternal() {
106 + return expenseIsInternal;
107 + }
108 +
109 + /**
110 + * Sets expense metric is internal or not.
111 + *
112 + * @param expenseIsInternal true if internal else false
113 + */
114 + public void setExpenseIsInternal(boolean expenseIsInternal) {
115 + this.expenseIsInternal = expenseIsInternal;
116 + }
117 +
118 + /**
119 + * Returns delays metric is internal or not.
120 + *
121 + * @return true if internal else false
122 + */
123 + public boolean isDelayIsInternal() {
124 + return delayIsInternal;
125 + }
126 +
127 + /**
128 + * Sets delay metric is internal or not.
129 + *
130 + * @param delayIsInternal true if internal else false
131 + */
132 + public void setDelayIsInternal(boolean delayIsInternal) {
133 + this.delayIsInternal = delayIsInternal;
134 + }
135 +
136 + /**
137 + * Returns is default distribution is up or down.
138 + *
139 + * @return true if down else false
140 + */
141 + public boolean isDefaultDistributionDown() {
142 + return defaultDistributionDown;
143 + }
144 +
145 + /**
146 + * Sets default distribution is up or down.
147 + *
148 + * @param defaultDistributionDown true if down else false
149 + */
150 + public void setDefaultDistributionDown(boolean defaultDistributionDown) {
151 + this.defaultDistributionDown = defaultDistributionDown;
152 + }
153 +
154 + /**
155 + * Returns is default metric is internal or not.
156 + *
157 + * @return true if internal else false
158 + */
159 + public boolean isDefaultIsInternal() {
160 + return defaultIsInternal;
161 + }
162 +
163 + /**
164 + * Sets default metric is internal or not.
165 + *
166 + * @param defaultIsInternal true is internal else false
167 + */
168 + public void setDefaultIsInternal(boolean defaultIsInternal) {
169 + this.defaultIsInternal = defaultIsInternal;
170 + }
171 +
172 + /**
173 + * Returns error metric is supported or not.
174 + *
175 + * @return true if supported else false
176 + */
177 + public boolean isErrorMetricSupported() {
178 + return errorMetricSupported;
179 + }
180 +
181 + /**
182 + * Sets error metric is supported or not.
183 + *
184 + * @param errorMetricSupported true if supported else false
185 + */
186 + public void setErrorMetricSupported(boolean errorMetricSupported) {
187 + this.errorMetricSupported = errorMetricSupported;
188 + }
189 +
190 + /**
191 + * Returns expense metric is supported or not.
192 + *
193 + * @return true if supported else false
194 + */
195 + public boolean isExpenseMetricSupported() {
196 + return expenseMetricSupported;
197 + }
198 +
199 + /**
200 + * Sets expense metric is supported or not.
201 + *
202 + * @param expenseMetricSupported true if supported else false
203 + */
204 + public void setExpenseMetricSupported(boolean expenseMetricSupported) {
205 + this.expenseMetricSupported = expenseMetricSupported;
206 + }
207 +
208 + /**
209 + * Returns delay metric is supported or not.
210 + *
211 + * @return true if supported else false
212 + */
213 + public boolean isDelayMetricSupported() {
214 + return delayMetricSupported;
215 + }
216 +
217 + /**
218 + * Sets delay metric is supported or not.
219 + *
220 + * @param delayMetricSupported true if supported else false
221 + */
222 + public void setDelayMetricSupported(boolean delayMetricSupported) {
223 + this.delayMetricSupported = delayMetricSupported;
224 + }
225 +
226 + /**
227 + * Returns error metric of metric of internal reachability.
228 + *
229 + * @return errorMetric error metic
230 + */
231 + public byte errorMetric() {
232 + return errorMetric;
233 + }
234 +
235 + /**
236 + * Sets error metric for metric of internal reachability.
237 + *
238 + * @param errorMetric error metric
239 + */
240 + public void setErrorMetric(byte errorMetric) {
241 + this.errorMetric = errorMetric;
242 + }
243 +
244 + /**
245 + * Returns expense metric of metric of internal reachability.
246 + *
247 + * @return expense metric
248 + */
249 + public byte expenseMetric() {
250 + return expenseMetric;
251 + }
252 +
253 + /**
254 + * Sets expense metric for metric of internal reachability.
255 + *
256 + * @param expenseMetric expense metric
257 + */
258 + public void setExpenseMetric(byte expenseMetric) {
259 + this.expenseMetric = expenseMetric;
260 + }
261 +
262 + /**
263 + * Returns delay metric of metric of internal reachability.
264 + *
265 + * @return delay metric
266 + */
267 + public byte delayMetric() {
268 + return delayMetric;
269 + }
270 +
271 + /**
272 + * Sets delay metric for metric of internal reachability.
273 + *
274 + * @param delayMetric delay metric
275 + */
276 + public void setDelayMetric(byte delayMetric) {
277 + this.delayMetric = delayMetric;
278 + }
279 +
280 + /**
281 + * Returns default metric of metric of internal reachability.
282 + *
283 + * @return default metric
284 + */
285 + public byte defaultMetric() {
286 + return defaultMetric;
287 + }
288 +
289 + /**
290 + * Sets default metric for metric of internal reachability.
291 + *
292 + * @param defaultMetric default metric
293 + */
294 + public void setDefaultMetric(byte defaultMetric) {
295 + this.defaultMetric = defaultMetric;
296 + }
297 +
298 + /**
299 + * Sets the metric of internal reachability
300 + * values for metric of internal reachability from byte buffer.
301 + *
302 + * @param channelBuffer channel Buffer instance
303 + */
304 + public void readFrom(ChannelBuffer channelBuffer) {
305 + byte metric = channelBuffer.readByte();
306 + this.setDefaultMetric(metric);
307 + String metricInBinary = Integer.toBinaryString(Byte.toUnsignedInt(metric));
308 + metricInBinary = IsisUtil.toEightBitBinary(metricInBinary);
309 + if (metricInBinary.charAt(1) == 0) {
310 + this.setDefaultIsInternal(true);
311 + } else {
312 + this.setDefaultIsInternal(false);
313 + }
314 + if (metricInBinary.charAt(0) == 0) {
315 + this.setDefaultDistributionDown(true);
316 + } else {
317 + this.setDefaultDistributionDown(false);
318 + }
319 + byte delayMetric = channelBuffer.readByte();
320 + metricInBinary = Integer.toBinaryString(Byte.toUnsignedInt(delayMetric));
321 + metricInBinary = IsisUtil.toEightBitBinary(metricInBinary);
322 + this.setDelayMetric(Byte.parseByte(metricInBinary.substring(5, metricInBinary.length()), 2));
323 + if (metricInBinary.charAt(1) == 0) {
324 + this.setDelayIsInternal(true);
325 + } else {
326 + this.setDelayIsInternal(false);
327 + }
328 + if (metricInBinary.charAt(0) == 0) {
329 + this.setDelayMetricSupported(true);
330 + } else {
331 + this.setDelayMetricSupported(false);
332 + }
333 + byte expenseMetric = channelBuffer.readByte();
334 + metricInBinary = Integer.toBinaryString(Byte.toUnsignedInt(expenseMetric));
335 + metricInBinary = IsisUtil.toEightBitBinary(metricInBinary);
336 + this.setExpenseMetric(Byte.parseByte(metricInBinary.substring(5, metricInBinary.length()), 2));
337 + if (metricInBinary.charAt(1) == 0) {
338 + this.setExpenseIsInternal(true);
339 + } else {
340 + this.setExpenseIsInternal(false);
341 + }
342 + if (metricInBinary.charAt(0) == 0) {
343 + this.setExpenseMetricSupported(true);
344 + } else {
345 + this.setExpenseMetricSupported(false);
346 + }
347 + byte errorMetric = channelBuffer.readByte();
348 + metricInBinary = Integer.toBinaryString(Byte.toUnsignedInt(errorMetric));
349 + metricInBinary = IsisUtil.toEightBitBinary(metricInBinary);
350 + this.setErrorMetric(Byte.parseByte(metricInBinary.substring(5, metricInBinary.length()), 2));
351 + if (metricInBinary.charAt(1) == 0) {
352 + this.setErrorIsInternal(true);
353 + } else {
354 + this.setErrorIsInternal(false);
355 + }
356 + if (metricInBinary.charAt(0) == 0) {
357 + this.setErrorMetricSupported(true);
358 + } else {
359 + this.setErrorMetricSupported(false);
360 + }
361 + List<Byte> byteList = new ArrayList<>();
362 + while (channelBuffer.readableBytes() > 0) {
363 + byteList.add(channelBuffer.readByte());
364 + }
365 + byte[] tempByteArray = new byte[IsisUtil.FOUR_BYTES];
366 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES);
367 + this.setIpAddress(Ip4Address.valueOf(tempByteArray));
368 +
369 + tempByteArray = new byte[IsisUtil.FOUR_BYTES];
370 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES);
371 + this.setSubnetAddres(Ip4Address.valueOf(tempByteArray));
372 + }
373 +
374 + /**
375 + * Returns metric of internal reachability values as bytes of metric of internal reachability.
376 + *
377 + * @return byteArray metric of internal reachability values as bytes of metric of internal reachability
378 + */
379 + public byte[] asBytes() {
380 + List<Byte> bytes = new ArrayList<>();
381 + bytes.add(this.defaultMetric());
382 + int temp = this.delayMetric();
383 + String hsbBits = "";
384 + if (this.isDelayMetricSupported()) {
385 + hsbBits = "0" + hsbBits;
386 + } else {
387 + hsbBits = "1" + hsbBits;
388 + }
389 + if (this.isDelayIsInternal()) {
390 + hsbBits = hsbBits + "0";
391 + } else {
392 + hsbBits = hsbBits + "1";
393 + }
394 + hsbBits = hsbBits + "00";
395 + String binary = hsbBits + IsisUtil.toFourBitBinary(Integer.toBinaryString(temp));
396 + bytes.add((byte) Integer.parseInt(binary, 2));
397 +
398 + temp = this.expenseMetric();
399 + hsbBits = "";
400 + if (this.isExpenseMetricSupported()) {
401 + hsbBits = "0" + hsbBits;
402 + } else {
403 + hsbBits = "1" + hsbBits;
404 + }
405 + if (this.isExpenseIsInternal()) {
406 + hsbBits = hsbBits + "0";
407 + } else {
408 + hsbBits = hsbBits + "1";
409 + }
410 + hsbBits = hsbBits + "00";
411 + binary = hsbBits + IsisUtil.toFourBitBinary(Integer.toBinaryString(temp));
412 + bytes.add((byte) Integer.parseInt(binary, 2));
413 +
414 + temp = this.errorMetric();
415 + hsbBits = "";
416 + if (this.isErrorMetricSupported()) {
417 + hsbBits = "0" + hsbBits;
418 + } else {
419 + hsbBits = "1" + hsbBits;
420 + }
421 + if (this.isExpenseIsInternal()) {
422 + hsbBits = hsbBits + "0";
423 + } else {
424 + hsbBits = hsbBits + "1";
425 + }
426 + hsbBits = hsbBits + "00";
427 + binary = hsbBits + IsisUtil.toFourBitBinary(Integer.toBinaryString(temp));
428 + bytes.add((byte) Integer.parseInt(binary, 2));
429 +
430 + bytes.addAll(Bytes.asList(this.getIpAddress().toOctets()));
431 + bytes.addAll(Bytes.asList(this.getSubnetAddres().toOctets()));
432 + return Bytes.toArray(bytes);
433 + }
434 +
435 + @Override
436 + public String toString() {
437 + return MoreObjects.toStringHelper(getClass())
438 + .omitNullValues()
439 + .add("ipAddress", ipAddress)
440 + .add("subnetAddres", subnetAddres)
441 + .add("defaultMetric", defaultMetric)
442 + .add("delayMetric", delayMetric)
443 + .add("expenseMetric", expenseMetric)
444 + .add("errorMetric", errorMetric)
445 + .add("delayMetricSupported", delayMetricSupported)
446 + .add("expenseMetricSupported", expenseMetricSupported)
447 + .add("errorMetricSupported", errorMetricSupported)
448 + .add("defaultIsInternal", defaultIsInternal)
449 + .add("defaultDistributionDown", defaultDistributionDown)
450 + .add("delayIsInternal", delayIsInternal)
451 + .add("expenseIsInternal", expenseIsInternal)
452 + .add("errorIsInternal", errorIsInternal)
453 + .toString();
454 + }
455 +}
...\ No newline at end of file ...\ No newline at end of file
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;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.util.IsisUtil;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +/**
27 + * Representation of metric of reachability.
28 + */
29 +public class MetricsOfReachability {
30 + private final String value1 = "10000000";
31 + private final String value2 = "00000000";
32 + private String neighborId;
33 + private byte defaultMetric;
34 + private byte delayMetric;
35 + private byte expenseMetric;
36 + private byte errorMetric;
37 + private boolean delayMetricSupported;
38 + private boolean expenseMetricSupported;
39 + private boolean errorMetricSupported;
40 + private boolean defaultIsInternal;
41 + private boolean delayIsInternal;
42 + private boolean expenseIsInternal;
43 + private boolean errorIsInternal;
44 +
45 + /**
46 + * Returns delay metric is internal or not.
47 + *
48 + * @return true if internal else false
49 + */
50 + public boolean isDelayIsInternal() {
51 + return delayIsInternal;
52 + }
53 +
54 + /**
55 + * Sets delay metric is internal or not.
56 + *
57 + * @param delayIsInternal true if internal else false
58 + */
59 + public void setDelayIsInternal(boolean delayIsInternal) {
60 + this.delayIsInternal = delayIsInternal;
61 + }
62 +
63 + /**
64 + * Returns expense metric is internal or not.
65 + *
66 + * @return true if internal else false
67 + */
68 + public boolean isExpenseIsInternal() {
69 + return expenseIsInternal;
70 + }
71 +
72 + /**
73 + * Sets expense metric is internal or not.
74 + *
75 + * @param expenseIsInternal true if internal else false
76 + */
77 + public void setExpenseIsInternal(boolean expenseIsInternal) {
78 + this.expenseIsInternal = expenseIsInternal;
79 + }
80 +
81 + /**
82 + * Returns error metric is internal or not.
83 + *
84 + * @return true if internal else false
85 + */
86 + public boolean isErrorIsInternal() {
87 + return errorIsInternal;
88 + }
89 +
90 + /**
91 + * Sets error metric is internal or not.
92 + *
93 + * @param errorIsInternal true if internal else false
94 + */
95 + public void setErrorIsInternal(boolean errorIsInternal) {
96 + this.errorIsInternal = errorIsInternal;
97 + }
98 +
99 + /**
100 + * Returns default metric is internal or not.
101 + *
102 + * @return true if internal else false
103 + */
104 + public boolean isDefaultIsInternal() {
105 + return defaultIsInternal;
106 + }
107 +
108 + /**
109 + * Sets default metric is internal or not.
110 + *
111 + * @param defaultIsInternal true if internal else false
112 + */
113 + public void setDefaultIsInternal(boolean defaultIsInternal) {
114 + this.defaultIsInternal = defaultIsInternal;
115 + }
116 +
117 + /**
118 + * Returns delay metric is supported or not.
119 + *
120 + * @return true if supported else false
121 + */
122 + public boolean isDelayMetricSupported() {
123 + return delayMetricSupported;
124 + }
125 +
126 + /**
127 + * Sets delay metric is supported or not.
128 + *
129 + * @param delayMetricSupported true if supported else false
130 + */
131 + public void setDelayMetricSupported(boolean delayMetricSupported) {
132 + this.delayMetricSupported = delayMetricSupported;
133 + }
134 +
135 + /**
136 + * Returns expense metric is supported or not.
137 + *
138 + * @return true if supported else false
139 + */
140 + public boolean isExpenseMetricSupported() {
141 + return expenseMetricSupported;
142 + }
143 +
144 + /**
145 + * Sets expense metric is supported or not.
146 + *
147 + * @param expenseMetricSupported true if supported else false
148 + */
149 + public void setExpenseMetricSupported(boolean expenseMetricSupported) {
150 + this.expenseMetricSupported = expenseMetricSupported;
151 + }
152 +
153 + /**
154 + * Returns error metric is supported or not.
155 + *
156 + * @return true if supported else false
157 + */
158 + public boolean isErrorMetricSupported() {
159 + return errorMetricSupported;
160 + }
161 +
162 + /**
163 + * Sets error metric is supported or not.
164 + *
165 + * @param errorMetricSupported true if supported else false
166 + */
167 + public void setErrorMetricSupported(boolean errorMetricSupported) {
168 + this.errorMetricSupported = errorMetricSupported;
169 + }
170 +
171 + /**
172 + * Returns neighbor ID of metric of reachability.
173 + *
174 + * @return neighbor ID
175 + */
176 + public String neighborId() {
177 + return neighborId;
178 + }
179 +
180 + /**
181 + * Sets neighbor ID for metric of reachability.
182 + *
183 + * @param neighborId neighbor ID
184 + */
185 + public void setNeighborId(String neighborId) {
186 + this.neighborId = neighborId;
187 + }
188 +
189 +
190 + /**
191 + * Returns default metric of metric of reachability.
192 + *
193 + * @return default metric
194 + */
195 + public byte defaultMetric() {
196 + return defaultMetric;
197 + }
198 +
199 + /**
200 + * Sets default metric for of reachability.
201 + *
202 + * @param defaultMetric default metric
203 + */
204 + public void setDefaultMetric(byte defaultMetric) {
205 + this.defaultMetric = defaultMetric;
206 + }
207 +
208 + /**
209 + * Returns delay metric of metric of reachability.
210 + *
211 + * @return delay metric
212 + */
213 + public byte delayMetric() {
214 + return delayMetric;
215 + }
216 +
217 + /**
218 + * Sets delay metric for metric of reachability.
219 + *
220 + * @param delayMetric delay metric.
221 + */
222 + public void setDelayMetric(byte delayMetric) {
223 + this.delayMetric = delayMetric;
224 + }
225 +
226 + /**
227 + * Returns Expense metric of metric of reachability.
228 + *
229 + * @return Expense metric
230 + */
231 + public byte expenseMetric() {
232 + return expenseMetric;
233 + }
234 +
235 + /**
236 + * Sets Expense metric for metric of reachability.
237 + *
238 + * @param expenseMetric Expense metric.
239 + */
240 + public void setExpenseMetric(byte expenseMetric) {
241 + this.expenseMetric = expenseMetric;
242 + }
243 +
244 + /**
245 + * Returns Error metric of metric of reachability.
246 + *
247 + * @return Error metric
248 + */
249 + public byte errorMetric() {
250 + return errorMetric;
251 + }
252 +
253 + /**
254 + * Sets Error metric for metric of reachability.
255 + *
256 + * @param errorMetric Error metric.
257 + */
258 + public void setErrorMetric(byte errorMetric) {
259 + this.errorMetric = errorMetric;
260 + }
261 +
262 + /**
263 + * Sets the metric of reachability values for metric of reachability from byte buffer.
264 + *
265 + * @param channelBuffer channel Buffer instance
266 + */
267 + public void readFrom(ChannelBuffer channelBuffer) {
268 + byte metric = channelBuffer.readByte();
269 + String metricInBinary = Integer.toBinaryString(Byte.toUnsignedInt(metric));
270 + metricInBinary = IsisUtil.toEightBitBinary(metricInBinary);
271 + this.setDefaultMetric(metric);
272 + this.setDelayMetric(metric);
273 + this.setExpenseMetric(metric);
274 + this.setErrorMetric(metric);
275 + this.setDelayMetric(metric);
276 + if (metricInBinary.charAt(0) == 0) {
277 + this.setDefaultIsInternal(true);
278 + } else {
279 + this.setDefaultIsInternal(false);
280 + }
281 + if (metricInBinary.charAt(0) == 0) {
282 + this.setDelayMetricSupported(true);
283 + this.setExpenseMetricSupported(true);
284 + this.setErrorMetricSupported(true);
285 + } else {
286 + this.setDelayMetricSupported(false);
287 + this.setExpenseMetricSupported(false);
288 + this.setErrorMetricSupported(false);
289 + }
290 + byte temp = channelBuffer.readByte();
291 + String internalBit = Integer.toBinaryString(Byte.toUnsignedInt(temp));
292 + internalBit = IsisUtil.toEightBitBinary(internalBit);
293 + if (internalBit.charAt(1) == 0) {
294 + this.setDelayIsInternal(true);
295 + }
296 + temp = channelBuffer.readByte();
297 + internalBit = Integer.toBinaryString(Byte.toUnsignedInt(temp));
298 + internalBit = IsisUtil.toEightBitBinary(internalBit);
299 + if (internalBit.charAt(1) == 0) {
300 + this.setExpenseIsInternal(true);
301 + }
302 + temp = channelBuffer.readByte();
303 + internalBit = Integer.toBinaryString(Byte.toUnsignedInt(temp));
304 + internalBit = IsisUtil.toEightBitBinary(internalBit);
305 + if (internalBit.charAt(1) == 0) {
306 + this.setErrorIsInternal(true);
307 + }
308 + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
309 + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
310 + this.setNeighborId(IsisUtil.systemIdPlus(tempByteArray));
311 + }
312 +
313 + /**
314 + * Returns metric of reachability values as bytes of metric of reachability.
315 + *
316 + * @return byteArray metric of reachability values as bytes of metric of reachability
317 + */
318 + public byte[] asBytes() {
319 + List<Byte> bytes = new ArrayList<>();
320 + bytes.add((byte) this.defaultMetric());
321 + if (this.isDelayIsInternal()) {
322 + bytes.add((byte) Integer.parseInt(value1));
323 + } else {
324 + bytes.add((byte) Integer.parseInt(value2));
325 + }
326 + if (this.isExpenseIsInternal()) {
327 + bytes.add((byte) Integer.parseInt(value1));
328 + } else {
329 + bytes.add((byte) Integer.parseInt(value2));
330 + }
331 + if (this.isErrorIsInternal()) {
332 + bytes.add((byte) Integer.parseInt(value1));
333 + } else {
334 + bytes.add((byte) Integer.parseInt(value2));
335 + }
336 + bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId()));
337 + return Bytes.toArray(bytes);
338 + }
339 +
340 + @Override
341 + public String toString() {
342 + return MoreObjects.toStringHelper(getClass())
343 + .omitNullValues()
344 + .add("neighborId", neighborId)
345 + .add("defaultMetric", defaultMetric)
346 + .add("delayMetric", delayMetric)
347 + .add("expenseMetric", expenseMetric)
348 + .add("errorMetric", errorMetric)
349 + .add("delayMetricSupported", delayMetricSupported)
350 + .add("expenseMetricSupported", expenseMetricSupported)
351 + .add("errorMetricSupported", errorMetricSupported)
352 + .add("defaultIsInternal", defaultIsInternal)
353 + .add("delayIsInternal", delayIsInternal)
354 + .add("expenseIsInternal", expenseIsInternal)
355 + .add("errorIsInternal", errorIsInternal)
356 + .toString();
357 + }
358 +}
...@@ -17,19 +17,19 @@ package org.onosproject.isis.io.isispacket.tlv; ...@@ -17,19 +17,19 @@ package org.onosproject.isis.io.isispacket.tlv;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
20 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
21 21
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 import java.util.List; 23 import java.util.List;
24 24
25 /** 25 /**
26 - * Represents padding TLV. 26 + * Representation of padding TLV.
27 */ 27 */
28 public class PaddingTlv extends TlvHeader implements IsisTlv { 28 public class PaddingTlv extends TlvHeader implements IsisTlv {
29 - private List<Byte> paddings = new ArrayList(); 29 + private List<Byte> paddings = new ArrayList<>();
30 30
31 /** 31 /**
32 - * Sets TLV type and TLV length of padding TLV. 32 + * Creates an instance of padding TLV.
33 * 33 *
34 * @param tlvHeader tlvHeader. 34 * @param tlvHeader tlvHeader.
35 */ 35 */
...@@ -39,9 +39,9 @@ public class PaddingTlv extends TlvHeader implements IsisTlv { ...@@ -39,9 +39,9 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
39 } 39 }
40 40
41 @Override 41 @Override
42 - public void readFrom(ByteBuf byteBuf) { 42 + public void readFrom(ChannelBuffer channelBuffer) {
43 - while (byteBuf.readableBytes() > 0) { 43 + while (channelBuffer.readableBytes() > 0) {
44 - this.paddings.add(byteBuf.readByte()); 44 + this.paddings.add(channelBuffer.readByte());
45 } 45 }
46 } 46 }
47 47
...@@ -51,17 +51,18 @@ public class PaddingTlv extends TlvHeader implements IsisTlv { ...@@ -51,17 +51,18 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
51 51
52 byte[] tlvHeader = tlvHeaderAsByteArray(); 52 byte[] tlvHeader = tlvHeaderAsByteArray();
53 byte[] tlvBody = tlvBodyAsBytes(); 53 byte[] tlvBody = tlvBodyAsBytes();
54 + tlvHeader[1] = (byte) tlvBody.length;
54 bytes = Bytes.concat(tlvHeader, tlvBody); 55 bytes = Bytes.concat(tlvHeader, tlvBody);
55 56
56 return bytes; 57 return bytes;
57 } 58 }
58 59
59 /** 60 /**
60 - * Gets TLV body padding TLV. 61 + * Returns TLV body of padding TLV.
61 * 62 *
62 - * @return areaArea TLV body padding TLV\\ 63 + * @return byteArray TLV body of padding TLV
63 */ 64 */
64 - public byte[] tlvBodyAsBytes() { 65 + private byte[] tlvBodyAsBytes() {
65 byte[] areaArea = new byte[this.tlvLength()]; 66 byte[] areaArea = new byte[this.tlvLength()];
66 return areaArea; 67 return areaArea;
67 } 68 }
...@@ -70,6 +71,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv { ...@@ -70,6 +71,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
70 public String toString() { 71 public String toString() {
71 return MoreObjects.toStringHelper(getClass()) 72 return MoreObjects.toStringHelper(getClass())
72 .omitNullValues() 73 .omitNullValues()
74 + .add("paddings", paddings)
73 .toString(); 75 .toString();
74 } 76 }
75 } 77 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,21 +15,22 @@ ...@@ -15,21 +15,22 @@
15 */ 15 */
16 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
17 17
18 +import com.google.common.base.MoreObjects;
18 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
19 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
20 21
21 import java.util.ArrayList; 22 import java.util.ArrayList;
22 import java.util.List; 23 import java.util.List;
23 24
24 /** 25 /**
25 - * Represents Protocol supported TLV. 26 + * Representation of protocol supported TLV.
26 */ 27 */
27 public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { 28 public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
28 29
29 - private List<Byte> protocolSupported = new ArrayList(); 30 + private List<Byte> protocolSupported = new ArrayList<>();
30 31
31 /** 32 /**
32 - * Sets TLV type and TLV length of protocol supported TLV. 33 + * Creates an instance of protocol supported TLV.
33 * 34 *
34 * @param tlvHeader tlvHeader. 35 * @param tlvHeader tlvHeader.
35 */ 36 */
...@@ -41,21 +42,27 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { ...@@ -41,21 +42,27 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
41 } 42 }
42 43
43 /** 44 /**
44 - * Gets the Protocol Supported by the TLV. 45 + * Adds the protocol supported to protocol supported TLV.
45 * 46 *
46 - * @return Protocol Supported 47 + * @param protocolValue protocol supported
47 */ 48 */
48 - public List<Byte> protocolSupported() { 49 + public void addProtocolSupported(byte protocolValue) {
50 + protocolSupported.add(protocolValue);
51 + }
49 52
53 + /**
54 + * Returns protocols supported of protocol supported TLV.
55 + *
56 + * @return protocol supported
57 + */
58 + public List<Byte> protocolSupported() {
50 return this.protocolSupported; 59 return this.protocolSupported;
51 -
52 } 60 }
53 61
54 @Override 62 @Override
55 - public void readFrom(ByteBuf byteBuf) { 63 + public void readFrom(ChannelBuffer channelBuffer) {
56 - 64 + while (channelBuffer.readableBytes() > 0) {
57 - while (byteBuf.readableBytes() > 0) { 65 + this.protocolSupported.add(channelBuffer.readByte());
58 - this.protocolSupported.add(byteBuf.readByte());
59 } 66 }
60 } 67 }
61 68
...@@ -65,8 +72,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { ...@@ -65,8 +72,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
65 72
66 byte[] tlvHeader = tlvHeaderAsByteArray(); 73 byte[] tlvHeader = tlvHeaderAsByteArray();
67 byte[] tlvBody = tlvBodyAsBytes(); 74 byte[] tlvBody = tlvBodyAsBytes();
75 + tlvHeader[1] = (byte) tlvBody.length;
68 bytes = Bytes.concat(tlvHeader, tlvBody); 76 bytes = Bytes.concat(tlvHeader, tlvBody);
69 -
70 return bytes; 77 return bytes;
71 } 78 }
72 79
...@@ -75,9 +82,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { ...@@ -75,9 +82,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
75 * 82 *
76 * @return byteArray TLV body of protocol supported TLV 83 * @return byteArray TLV body of protocol supported TLV
77 */ 84 */
78 - public byte[] tlvBodyAsBytes() { 85 + private byte[] tlvBodyAsBytes() {
79 - 86 + List<Byte> bytes = new ArrayList<>();
80 - List<Byte> bytes = new ArrayList();
81 for (byte byt : this.protocolSupported) { 87 for (byte byt : this.protocolSupported) {
82 bytes.add(byt); 88 bytes.add(byt);
83 } 89 }
...@@ -88,4 +94,12 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { ...@@ -88,4 +94,12 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
88 } 94 }
89 return byteArray; 95 return byteArray;
90 } 96 }
97 +
98 + @Override
99 + public String toString() {
100 + return MoreObjects.toStringHelper(getClass())
101 + .omitNullValues()
102 + .add("protocolSupported", protocolSupported)
103 + .toString();
104 + }
91 } 105 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,55 +15,90 @@ ...@@ -15,55 +15,90 @@
15 */ 15 */
16 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
17 17
18 -import io.netty.buffer.ByteBuf; 18 +import org.jboss.netty.buffer.ChannelBuffer;
19 -import org.onosproject.isis.io.util.IsisUtil;
20 19
21 /** 20 /**
22 - * Represents TLV finder. 21 + * Representation of TLV Finder.
23 */ 22 */
24 public class TlvFinder extends TlvHeader { 23 public class TlvFinder extends TlvHeader {
25 24
26 /** 25 /**
27 - * Sets the value for TLV header and the body of the TLV. 26 + * Sets the value for TLV header.
28 * 27 *
29 - * @param tlvHeader tlvHeader 28 + * @param tlvHeader tlvHeader
30 - * @param byteBuf byteBuf 29 + * @param channelBuffer byteBuf
31 - * @return isisTlv ISIS TLV 30 + * @return isisTlv
32 */ 31 */
33 - public static IsisTlv findTlv(TlvHeader tlvHeader, ByteBuf byteBuf) { 32 + public static IsisTlv findTlv(TlvHeader tlvHeader, ChannelBuffer channelBuffer) {
34 33
35 IsisTlv isisTlv = null; 34 IsisTlv isisTlv = null;
36 - 35 + switch (TlvType.get(tlvHeader.tlvType())) {
37 - switch (tlvHeader.tlvType()) { 36 + case AREAADDRESS:
38 - case IsisUtil.AREAADDRESS:
39 AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); 37 AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
40 - areaAddressTlv.readFrom(byteBuf); 38 + areaAddressTlv.readFrom(channelBuffer);
41 isisTlv = areaAddressTlv; 39 isisTlv = areaAddressTlv;
42 break; 40 break;
43 - case IsisUtil.IPINTERFACEADDRESS: 41 + case AUTHENTICATION:
42 + //TODO
43 + break;
44 + case EXTENDEDISREACHABILITY:
45 + //TODO
46 + break;
47 + case IDRPINFORMATION:
48 + IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader);
49 + idrpInformationTlv.readFrom(channelBuffer);
50 + isisTlv = idrpInformationTlv;
51 + break;
52 + case IPEXTENDEDREACHABILITY:
53 + IpExtendedReachabilityTlv iperTlv = new IpExtendedReachabilityTlv(tlvHeader);
54 + iperTlv.readFrom(channelBuffer);
55 + isisTlv = iperTlv;
56 + break;
57 + case IPINTERFACEADDRESS:
44 IpInterfaceAddressTlv ipTlv = new IpInterfaceAddressTlv(tlvHeader); 58 IpInterfaceAddressTlv ipTlv = new IpInterfaceAddressTlv(tlvHeader);
45 - ipTlv.readFrom(byteBuf); 59 + ipTlv.readFrom(channelBuffer);
46 isisTlv = ipTlv; 60 isisTlv = ipTlv;
47 break; 61 break;
48 - case IsisUtil.PROTOCOLSUPPORTED: 62 + case IPINTERNALREACHABILITY:
63 + IpInternalReachabilityTlv iprTlv = new IpInternalReachabilityTlv(tlvHeader);
64 + iprTlv.readFrom(channelBuffer);
65 + isisTlv = iprTlv;
66 + break;
67 + case ISALIAS:
68 + break;
69 + case PROTOCOLSUPPORTED:
49 ProtocolSupportedTlv psTlv = new ProtocolSupportedTlv(tlvHeader); 70 ProtocolSupportedTlv psTlv = new ProtocolSupportedTlv(tlvHeader);
50 - psTlv.readFrom(byteBuf); 71 + psTlv.readFrom(channelBuffer);
51 isisTlv = psTlv; 72 isisTlv = psTlv;
52 break; 73 break;
53 - case IsisUtil.ISNEIGHBORS: 74 + case ISREACHABILITY:
75 + IsReachabilityTlv isrTlv = new IsReachabilityTlv(tlvHeader);
76 + isrTlv.readFrom(channelBuffer);
77 + isisTlv = isrTlv;
78 + break;
79 + case ISNEIGHBORS:
54 IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader); 80 IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
55 - isisNeighborTlv.readFrom(byteBuf); 81 + isisNeighborTlv.readFrom(channelBuffer);
56 isisTlv = isisNeighborTlv; 82 isisTlv = isisNeighborTlv;
57 break; 83 break;
58 - case IsisUtil.PADDING: 84 + case LSPENTRY:
85 + LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
86 + lspEntriesTlv.readFrom(channelBuffer);
87 + isisTlv = lspEntriesTlv;
88 + break;
89 + case PADDING:
59 PaddingTlv paddingTlv = new PaddingTlv(tlvHeader); 90 PaddingTlv paddingTlv = new PaddingTlv(tlvHeader);
60 - paddingTlv.readFrom(byteBuf); 91 + paddingTlv.readFrom(channelBuffer);
61 isisTlv = paddingTlv; 92 isisTlv = paddingTlv;
62 break; 93 break;
94 + case ADJACENCYSTATE:
95 + AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
96 + adjacencyStateTlv.readFrom(channelBuffer);
97 + isisTlv = adjacencyStateTlv;
98 + break;
63 default: 99 default:
64 break; 100 break;
65 } 101 }
66 -
67 return isisTlv; 102 return isisTlv;
68 } 103 }
69 } 104 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,29 +17,29 @@ package org.onosproject.isis.io.isispacket.tlv; ...@@ -17,29 +17,29 @@ package org.onosproject.isis.io.isispacket.tlv;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import com.google.common.primitives.Bytes; 19 import com.google.common.primitives.Bytes;
20 -import io.netty.buffer.ByteBuf; 20 +import org.jboss.netty.buffer.ChannelBuffer;
21 21
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 import java.util.List; 23 import java.util.List;
24 24
25 /** 25 /**
26 - * Represents TLV header. 26 + * Representation of TLV header.
27 */ 27 */
28 public class TlvHeader implements IsisTlv { 28 public class TlvHeader implements IsisTlv {
29 private int tlvType; 29 private int tlvType;
30 private int tlvLength; 30 private int tlvLength;
31 31
32 /** 32 /**
33 - * Gets the TLV length of the TLV. 33 + * Returns TLV length of TLV.
34 * 34 *
35 - * @return tlvLength TLV length 35 + * @return TLV length
36 */ 36 */
37 public int tlvLength() { 37 public int tlvLength() {
38 return tlvLength; 38 return tlvLength;
39 } 39 }
40 40
41 /** 41 /**
42 - * Sets the TLV length for the mTLV. 42 + * Sets TLV length for TLV.
43 * 43 *
44 * @param tlvLength TLV length 44 * @param tlvLength TLV length
45 */ 45 */
...@@ -48,16 +48,16 @@ public class TlvHeader implements IsisTlv { ...@@ -48,16 +48,16 @@ public class TlvHeader implements IsisTlv {
48 } 48 }
49 49
50 /** 50 /**
51 - * Gets the TLV type of the TLV. 51 + * Returns TLV type of TLV.
52 * 52 *
53 - * @return tlvType TLV type 53 + * @return TLV type
54 */ 54 */
55 public int tlvType() { 55 public int tlvType() {
56 return tlvType; 56 return tlvType;
57 } 57 }
58 58
59 /** 59 /**
60 - * Sets TLV type for the TLV. 60 + * Sets TLV type for TLV.
61 * 61 *
62 * @param tlvType TLV type 62 * @param tlvType TLV type
63 */ 63 */
...@@ -66,32 +66,31 @@ public class TlvHeader implements IsisTlv { ...@@ -66,32 +66,31 @@ public class TlvHeader implements IsisTlv {
66 } 66 }
67 67
68 /** 68 /**
69 - * Sets the TLV values of TLV from b yte buffer. 69 + * Sets TLV values from channel buffer.
70 * 70 *
71 - * @param byteBuf byteBuf. 71 + * @param channelBuffer channel Buffer instance
72 */ 72 */
73 - public void readFrom(ByteBuf byteBuf) { 73 + public void readFrom(ChannelBuffer channelBuffer) {
74 //implemented in sub classes 74 //implemented in sub classes
75 } 75 }
76 76
77 77
78 /** 78 /**
79 - * Gets the TLV of the TLV as bytes. 79 + * Returns TLV as byte array.
80 * 80 *
81 - * @return null 81 + * @return byteArray TLV body of area address TLV
82 */ 82 */
83 public byte[] asBytes() { 83 public byte[] asBytes() {
84 - //implemented the subclasses
85 return null; 84 return null;
86 } 85 }
87 86
88 /** 87 /**
89 - * Gets the TLV header of the TLV. 88 + * Returns TLV header of TLV as bytes.
90 * 89 *
91 - * @return headerLst TLV of the TLV 90 + * @return TLV header as bytes
92 */ 91 */
93 public byte[] tlvHeaderAsByteArray() { 92 public byte[] tlvHeaderAsByteArray() {
94 - List<Byte> headerLst = new ArrayList(); 93 + List<Byte> headerLst = new ArrayList<>();
95 headerLst.add((byte) this.tlvType); 94 headerLst.add((byte) this.tlvType);
96 headerLst.add((byte) this.tlvLength); 95 headerLst.add((byte) this.tlvLength);
97 return Bytes.toArray(headerLst); 96 return Bytes.toArray(headerLst);
......
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
15 */ 15 */
16 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
17 17
18 +import java.util.EnumSet;
19 +import java.util.HashMap;
20 +import java.util.Map;
21 +
18 /** 22 /**
19 - * Represents various values for TLV types. 23 + * Representation of various values for TLV types.
20 */ 24 */
21 public enum TlvType { 25 public enum TlvType {
22 AREAADDRESS(1), 26 AREAADDRESS(1),
...@@ -25,19 +29,32 @@ public enum TlvType { ...@@ -25,19 +29,32 @@ public enum TlvType {
25 PADDING(8), 29 PADDING(8),
26 LSPENTRY(9), 30 LSPENTRY(9),
27 AUTHENTICATION(10), 31 AUTHENTICATION(10),
28 - CHECKSUM(12), 32 + HOSTNAME(137),
29 EXTENDEDISREACHABILITY(22), 33 EXTENDEDISREACHABILITY(22),
30 ISALIAS(24), 34 ISALIAS(24),
31 IPINTERNALREACHABILITY(128), 35 IPINTERNALREACHABILITY(128),
32 PROTOCOLSUPPORTED(129), 36 PROTOCOLSUPPORTED(129),
33 IPEXTERNALREACHABILITY(130), 37 IPEXTERNALREACHABILITY(130),
38 + IPEXTENDEDREACHABILITY(135),
34 IDRPINFORMATION(131), 39 IDRPINFORMATION(131),
35 - IPINTERFACEADDRESS(132); 40 + IPINTERFACEADDRESS(132),
41 + ADJACENCYSTATE(240);
42 +
43 + // Reverse lookup table
44 + private static final Map<Integer, TlvType> LOOKUP = new HashMap<>();
45 +
46 + // Populate the lookup table on loading time
47 + static {
48 + for (TlvType isisTlvType : EnumSet.allOf(TlvType.class)) {
49 + LOOKUP.put(isisTlvType.value(), isisTlvType);
50 + }
51 + }
36 52
37 private int value; 53 private int value;
38 54
39 /** 55 /**
40 * Sets the TLV type value. 56 * Sets the TLV type value.
57 + *
41 * @param value value. 58 * @param value value.
42 */ 59 */
43 TlvType(int value) { 60 TlvType(int value) {
...@@ -45,10 +62,21 @@ public enum TlvType { ...@@ -45,10 +62,21 @@ public enum TlvType {
45 } 62 }
46 63
47 /** 64 /**
65 + * Gets the enum instance from type value - reverse lookup purpose.
66 + *
67 + * @param tlvTypeValue TLV type value
68 + * @return ISIS TLV type instance
69 + */
70 + public static TlvType get(int tlvTypeValue) {
71 + return LOOKUP.get(tlvTypeValue);
72 + }
73 +
74 + /**
48 * Gets value. 75 * Gets value.
76 + *
49 * @return value 77 * @return value
50 */ 78 */
51 public int value() { 79 public int value() {
52 return value; 80 return value;
53 } 81 }
54 -} 82 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,23 +16,33 @@ ...@@ -16,23 +16,33 @@
16 package org.onosproject.isis.io.isispacket.tlv; 16 package org.onosproject.isis.io.isispacket.tlv;
17 17
18 import com.google.common.primitives.Bytes; 18 import com.google.common.primitives.Bytes;
19 +import org.slf4j.Logger;
20 +import org.slf4j.LoggerFactory;
19 21
20 import java.util.ArrayList; 22 import java.util.ArrayList;
21 import java.util.List; 23 import java.util.List;
22 24
23 /** 25 /**
24 - * Represents conversion of TLV's to bytes. 26 + * Representation of conversion of TLV's to bytes.
25 */ 27 */
26 public final class TlvsToBytes { 28 public final class TlvsToBytes {
29 +
30 + protected static final Logger log = LoggerFactory.getLogger(TlvsToBytes.class);
31 +
32 + /**
33 + * Creates an instance.
34 + */
35 + private TlvsToBytes() {
36 + }
37 +
27 /** 38 /**
28 * Sets the ISIS TLV and returns in the form of bytes. 39 * Sets the ISIS TLV and returns in the form of bytes.
29 * 40 *
30 - * @param isisTlv isisTlv 41 + * @param isisTlv isisTlv.
31 - * @return tlvBytes TLV bytes 42 + * @return tlvBytes
32 */ 43 */
33 public static List<Byte> tlvToBytes(IsisTlv isisTlv) { 44 public static List<Byte> tlvToBytes(IsisTlv isisTlv) {
34 - 45 + List<Byte> tlvBytes = new ArrayList<>();
35 - List<Byte> tlvBytes = new ArrayList();
36 if (isisTlv instanceof AreaAddressTlv) { 46 if (isisTlv instanceof AreaAddressTlv) {
37 AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv; 47 AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv;
38 tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes())); 48 tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes()));
...@@ -48,16 +58,33 @@ public final class TlvsToBytes { ...@@ -48,16 +58,33 @@ public final class TlvsToBytes {
48 } else if (isisTlv instanceof IsisNeighborTlv) { 58 } else if (isisTlv instanceof IsisNeighborTlv) {
49 IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv; 59 IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv;
50 tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes())); 60 tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes()));
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()));
51 } else { 85 } else {
52 - System.out.println("UNKNOWN TLV TYPE ::TlvsToBytes "); 86 + log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
53 } 87 }
54 -
55 return tlvBytes; 88 return tlvBytes;
56 } 89 }
57 - /**
58 - * Creates an instance.
59 - */
60 - private TlvsToBytes() {
61 - //private constructor
62 - }
63 } 90 }
...\ No newline at end of file ...\ No newline at end of file
......
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.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +
25 +/**
26 + * Representation of an administrative group.
27 + */
28 +public class AdministrativeGroup extends TlvHeader implements TrafficEngineeringSubTlv {
29 +
30 + private int administrativeGroup;
31 +
32 + /**
33 + * Creates an administrative group instance.
34 + *
35 + * @param header Tlv Header instance
36 + */
37 + public AdministrativeGroup(TlvHeader header) {
38 + this.setTlvType(header.tlvType());
39 + this.setTlvLength(header.tlvLength());
40 + }
41 +
42 + /**
43 + * Gets administrative group value.
44 + *
45 + * @return administrative group value
46 + */
47 + public int administrativeGroup() {
48 + return administrativeGroup;
49 + }
50 +
51 + /**
52 + * Sets administrative group value.
53 + *
54 + * @param administrativeGroup value
55 + */
56 + public void setAdministrativeGroup(int administrativeGroup) {
57 + this.administrativeGroup = administrativeGroup;
58 + }
59 +
60 + /**
61 + * Gets administrative group value.
62 + *
63 + * @return administrativeGroup value
64 + */
65 + public int getAdministrativeGroupValue() {
66 + return this.administrativeGroup;
67 + }
68 +
69 + /**
70 + * Reads bytes from channel buffer.
71 + *
72 + * @param channelBuffer Channel buffer instance
73 + */
74 + public void readFrom(ChannelBuffer channelBuffer) {
75 + byte[] tempByteArray = new byte[tlvLength()];
76 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
77 + this.setAdministrativeGroup(IsisUtil.byteToInteger(tempByteArray));
78 + }
79 +
80 + /**
81 + * Returns administrative group as byte array.
82 + *
83 + * @return administrative group instance as byte array
84 + */
85 + public byte[] asBytes() {
86 + byte[] linkSubType = null;
87 +
88 + byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
89 + byte[] linkSubTlvBody = tlvBodyAsBytes();
90 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
91 +
92 + return linkSubType;
93 + }
94 +
95 + /**
96 + * Gets administrative group body as byte array.
97 + *
98 + * @return byte array of sub tlv administrative group
99 + */
100 + public byte[] tlvBodyAsBytes() {
101 +
102 + byte[] linkSubTypeBody;
103 + linkSubTypeBody = IsisUtil.convertToFourBytes(this.administrativeGroup);
104 +
105 + return linkSubTypeBody;
106 + }
107 +
108 + @Override
109 + public String toString() {
110 + return MoreObjects.toStringHelper(getClass())
111 + .add("administrativeGroup", administrativeGroup)
112 + .toString();
113 + }
114 +}
...\ No newline at end of file ...\ No newline at end of file
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.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +
25 +/**
26 + * Representation of maximum bandwidth TE value.
27 + */
28 +public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
29 + private float maximumBandwidth;
30 +
31 + /**
32 + * Creates an instance of maximum bandwidth.
33 + *
34 + * @param header tlv header instance
35 + */
36 + public MaximumBandwidth(TlvHeader header) {
37 + this.setTlvType(header.tlvType());
38 + this.setTlvLength(header.tlvLength());
39 + }
40 +
41 + /**
42 + * Sets value of maximum bandwidth.
43 + *
44 + * @param maximumBandwidth value of maximum bandwidth
45 + */
46 + public void setMaximumBandwidth(float maximumBandwidth) {
47 + this.maximumBandwidth = maximumBandwidth;
48 + }
49 +
50 + /**
51 + * Gets value of maximum bandwidth.
52 + *
53 + * @return maximumBandwidth value of maximum bandwidth
54 + */
55 + public float getMaximumBandwidthValue() {
56 + return this.maximumBandwidth;
57 + }
58 +
59 + /**
60 + * Reads bytes from channel buffer.
61 + *
62 + * @param channelBuffer channel buffer instance
63 + */
64 + public void readFrom(ChannelBuffer channelBuffer) {
65 + byte[] tempByteArray = new byte[tlvLength()];
66 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
67 + int maxBandwidth = (IsisUtil.byteToInteger(tempByteArray));
68 + this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
69 + }
70 +
71 + /**
72 + * Gets byte array of maximum bandwidth sub tlv.
73 + *
74 + * @return byte array of maximum bandwidth sub tlv
75 + */
76 + public byte[] asBytes() {
77 + byte[] linkSubType = null;
78 + byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
79 + byte[] linkSubTlvBody = tlvBodyAsBytes();
80 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
81 +
82 + return linkSubType;
83 + }
84 +
85 + /**
86 + * Gets maximum bandwidth sub tlv byte array.
87 + *
88 + * @return byte array of maximum bandwidth sub tlv
89 + */
90 + public byte[] tlvBodyAsBytes() {
91 + byte[] linkSubTypeBody;
92 + linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth));
93 + return linkSubTypeBody;
94 + }
95 +
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass())
98 + .add("maximumBandwidth", maximumBandwidth)
99 + .toString();
100 + }
101 +}
...\ No newline at end of file ...\ No newline at end of file
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.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +
25 +/**
26 + * Representation of maximum reservable bandwidth TE value.
27 + */
28 +public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
29 + private float maximumReservableBandwidth;
30 +
31 + /**
32 + * Creates an instance of maximum reservable bandwidth.
33 + *
34 + * @param header tlv header
35 + */
36 + public MaximumReservableBandwidth(TlvHeader header) {
37 + this.setTlvType(header.tlvType());
38 + this.setTlvLength(header.tlvLength());
39 + }
40 +
41 + /**
42 + * Sets value of maximum reversible bandwidth.
43 + *
44 + * @param maximumBandwidth maximum reversible bandwidth
45 + */
46 + public void setMaximumBandwidth(float maximumBandwidth) {
47 + this.maximumReservableBandwidth = maximumBandwidth;
48 + }
49 +
50 + /**
51 + * Gets value of maximum reversible bandwidth.
52 + *
53 + * @return maximumBandwidth maximum reversible bandwidth
54 + */
55 + public float getMaximumBandwidthValue() {
56 + return this.maximumReservableBandwidth;
57 + }
58 +
59 + /**
60 + * Reads bytes from channel buffer.
61 + *
62 + * @param channelBuffer channel buffer instance
63 + */
64 + public void readFrom(ChannelBuffer channelBuffer) {
65 + byte[] tempByteArray = new byte[tlvLength()];
66 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
67 + int maxBandwidth = (IsisUtil.byteToInteger(tempByteArray));
68 + this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
69 + }
70 +
71 + /**
72 + * Returns byte array of maximum reservable bandwidth.
73 + *
74 + * @return byte array of maximum reservable bandwidth
75 + */
76 + public byte[] asBytes() {
77 + byte[] linkSubType = null;
78 +
79 + byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
80 + byte[] linkSubTlvBody = tlvBodyAsBytes();
81 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
82 + return linkSubType;
83 +
84 + }
85 +
86 + /**
87 + * Gets maximum reservable bandwidth sub tlv body as byte array.
88 + *
89 + * @return byte of maximum reservable bandwidth sub tlv body
90 + */
91 + public byte[] tlvBodyAsBytes() {
92 + byte[] linkSubTypeBody;
93 + linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumReservableBandwidth));
94 +
95 + return linkSubTypeBody;
96 + }
97 +
98 + @Override
99 + public String toString() {
100 + return MoreObjects.toStringHelper(getClass())
101 + .add("maximumReservableBandwidth", maximumReservableBandwidth)
102 + .toString();
103 + }
104 +}
...\ No newline at end of file ...\ No newline at end of file
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 org.jboss.netty.buffer.ChannelBuffer;
19 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
20 +
21 +/**
22 + * Representation of sub tlv finder.
23 + */
24 +public final class SubTlvFinder {
25 + /**
26 + * Creates an instance.
27 + */
28 + private SubTlvFinder() {
29 +
30 + }
31 +
32 + /**
33 + * Sets the value for TLV header and to find sub TLV and populate.
34 + *
35 + * @param tlvHeader tlvHeader
36 + * @param channelBuffer byteBuf
37 + * @return subTlv traffic engineering sub tlv
38 + */
39 + public static TrafficEngineeringSubTlv findSubTlv(TlvHeader tlvHeader, ChannelBuffer channelBuffer) {
40 +
41 + TrafficEngineeringSubTlv subTlv = null;
42 +
43 + switch (SubTlvType.get(tlvHeader.tlvType())) {
44 + case ADMINISTRATIVEGROUP:
45 + AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
46 + administrativeGroup.readFrom(channelBuffer);
47 + subTlv = administrativeGroup;
48 + break;
49 + case MAXIMUMBANDWIDTH:
50 + MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
51 + maximumBandwidth.readFrom(channelBuffer);
52 + subTlv = maximumBandwidth;
53 + break;
54 + case MAXIMUMRESERVABLEBANDWIDTH:
55 + MaximumReservableBandwidth maxResBandwidth = new MaximumReservableBandwidth(tlvHeader);
56 + maxResBandwidth.readFrom(channelBuffer);
57 + subTlv = maxResBandwidth;
58 + break;
59 + case TRAFFICENGINEERINGMETRIC:
60 + TrafficEngineeringMetric teMetric = new TrafficEngineeringMetric(tlvHeader);
61 + teMetric.readFrom(channelBuffer);
62 + subTlv = teMetric;
63 + break;
64 + case UNRESERVEDBANDWIDTH:
65 + UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
66 + unreservedBandwidth.readFrom(channelBuffer);
67 + subTlv = unreservedBandwidth;
68 + break;
69 + default:
70 + //TODO
71 + break;
72 + }
73 + return subTlv;
74 + }
75 +}
...\ No newline at end of file ...\ No newline at end of file
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()));
63 + } else {
64 + log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
65 + }
66 +
67 + return subTlvBytes;
68 + }
69 +}
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 java.util.EnumSet;
19 +import java.util.HashMap;
20 +import java.util.Map;
21 +
22 +/**
23 + * Representation of sub tlv type.
24 + */
25 +public enum SubTlvType {
26 + ADMINISTRATIVEGROUP(9),
27 + MAXIMUMBANDWIDTH(6),
28 + MAXIMUMRESERVABLEBANDWIDTH(7),
29 + TRAFFICENGINEERINGMETRIC(5),
30 + UNRESERVEDBANDWIDTH(8);
31 +
32 + // Reverse lookup table
33 + private static final Map<Integer, SubTlvType> LOOKUP = new HashMap<>();
34 +
35 + // Populate the lookup table on loading time
36 + static {
37 + for (SubTlvType subTlvType : EnumSet.allOf(SubTlvType.class)) {
38 + LOOKUP.put(subTlvType.value(), subTlvType);
39 + }
40 + }
41 +
42 + private int value;
43 +
44 + /**
45 + * Sets the sub TLV type value.
46 + *
47 + * @param value value.
48 + */
49 + SubTlvType(int value) {
50 + this.value = value;
51 + }
52 +
53 + /**
54 + * Gets the enum instance from type value - reverse lookup purpose.
55 + *
56 + * @param subTlvTypeValue TLV type value
57 + * @return ISIS sub TLV type instance
58 + */
59 + public static SubTlvType get(int subTlvTypeValue) {
60 + return LOOKUP.get(subTlvTypeValue);
61 + }
62 +
63 + /**
64 + * Gets value.
65 + *
66 + * @return value
67 + */
68 + public int value() {
69 + return value;
70 + }
71 +}
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.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +/**
25 + * Representation of traffic engineering metric TE value.
26 + */
27 +public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngineeringSubTlv {
28 + private long trafficEngineeringMetric;
29 +
30 + /**
31 + * Creates an instance of traffic engineering metric .
32 + *
33 + * @param header tlv header instance
34 + */
35 + public TrafficEngineeringMetric(TlvHeader header) {
36 + this.setTlvType(header.tlvType());
37 + this.setTlvLength(header.tlvLength());
38 + }
39 +
40 + /**
41 + * Sets TE metric value.
42 + *
43 + * @param trafficEngineeringMetric value of trafficEngineeringMetric
44 + */
45 + public void setTrafficEngineeringMetric(long trafficEngineeringMetric) {
46 + this.trafficEngineeringMetric = trafficEngineeringMetric;
47 + }
48 +
49 + /**
50 + * Gets TE metric value.
51 + *
52 + * @return value of traffic engineering metric
53 + */
54 + public long getTrafficEngineeringMetricValue() {
55 + return this.trafficEngineeringMetric;
56 + }
57 +
58 + /**
59 + * Reads bytes from channel buffer .
60 + *
61 + * @param channelBuffer channel buffer instance
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) {
64 + byte[] tempByteArray = new byte[tlvLength()];
65 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 + this.setTrafficEngineeringMetric(IsisUtil.byteToLong(tempByteArray));
67 + }
68 +
69 + /**
70 + * Gets instance as byte array.
71 + *
72 + * @return instance as byte array
73 + */
74 + public byte[] asBytes() {
75 + byte[] linkSubType = null;
76 +
77 + byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
78 + byte[] linkSubTlvBody = tlvBodyAsBytes();
79 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
80 +
81 + return linkSubType;
82 + }
83 +
84 + /**
85 + * Gets trafficEngineeringMetric as byte array .
86 + *
87 + * @return byte array of trafficEngineeringMetric
88 + */
89 + public byte[] tlvBodyAsBytes() {
90 +
91 + byte[] linkSubTypeBody;
92 + linkSubTypeBody = IsisUtil.convertToFourBytes(this.trafficEngineeringMetric);
93 +
94 + return linkSubTypeBody;
95 + }
96 +
97 + @Override
98 + public String toString() {
99 + return MoreObjects.toStringHelper(getClass())
100 + .omitNullValues()
101 + .add("trafficEngineeringMetric", trafficEngineeringMetric)
102 + .toString();
103 + }
104 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -14,28 +14,10 @@ ...@@ -14,28 +14,10 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.isis.io.isispacket; 17 +package org.onosproject.isis.io.isispacket.tlv.subtlv;
18 18
19 /** 19 /**
20 - * Represents ISIS constant parameters. 20 + * Representation of traffic engineering sub tlv.
21 */ 21 */
22 -public final class IsisConstantParameters { 22 +public interface TrafficEngineeringSubTlv {
23 - 23 +}
24 - public static final int IRPDISCRIMINATOR = 131;
25 - public static final int PROOCOLID = 1;
26 - public static final int VERSION = 1;
27 - public static final int RESERVED = 0;
28 - public static final int MAXAREAADDRESS = 3;
29 - public static final int IDLENGTH = 6;
30 - public static final int PROTOCOLSUPPORTED = 6;
31 - public static final int PACKETMINIMUMLENGTH = 27;
32 - public static final int PDULENGTHPOSITION = 17;
33 - public static final int PDUHEADERFORREADFROM = 8;
34 -
35 - /**
36 - * Creates an instance of this class.
37 - */
38 - private IsisConstantParameters() {
39 -
40 - }
41 -}
...\ No newline at end of file ...\ No newline at end of file
......
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.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.util.IsisUtil;
23 +
24 +import java.util.ArrayList;
25 +import java.util.List;
26 +
27 +/**
28 + * Representation of an unreserved band width TE value.
29 + */
30 +public class UnreservedBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
31 + private List<Float> unReservedBandwidth = new ArrayList<>();
32 +
33 + /**
34 + * Creates an instance of unreserved band width.
35 + *
36 + * @param header tlv header instance
37 + */
38 + public UnreservedBandwidth(TlvHeader header) {
39 + this.setTlvType(header.tlvType());
40 + this.setTlvLength(header.tlvLength());
41 + }
42 +
43 + /**
44 + * Adds value of un reserved bandwidth .
45 + *
46 + * @param unreservedBandwidth value of un reserved bandwidth
47 + */
48 + public void addUnReservedBandwidth(float unreservedBandwidth) {
49 + this.unReservedBandwidth.add(unreservedBandwidth);
50 + }
51 +
52 + /**
53 + * Gets list of un reserved bandwidth .
54 + *
55 + * @return List of un reserved bandwidth
56 + */
57 + public List<Float> getUnReservedBandwidthValue() {
58 + return this.unReservedBandwidth;
59 + }
60 +
61 + /**
62 + * Reads bytes from channel buffer .
63 + *
64 + * @param channelBuffer channel buffer instance
65 + */
66 + public void readFrom(ChannelBuffer channelBuffer) {
67 + while (channelBuffer.readableBytes() >= IsisUtil.FOUR_BYTES) {
68 + int maxReversibleBandwidth = channelBuffer.readInt();
69 + this.addUnReservedBandwidth(Float.intBitsToFloat(maxReversibleBandwidth));
70 + }
71 + }
72 +
73 + /**
74 + * Gets instance as byte array.
75 + *
76 + * @return instance as byte array
77 + */
78 + public byte[] asBytes() {
79 + byte[] linkSubType = null;
80 +
81 + byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
82 + byte[] linkSubTlvBody = tlvBodyAsBytes();
83 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
84 +
85 + return linkSubType;
86 + }
87 +
88 + /**
89 + * Gets unreserved bandwidth as byte array.
90 + *
91 + * @return unreserved bandwidth as byte array
92 + */
93 + public byte[] tlvBodyAsBytes() {
94 + List<Byte> linkSubTypeBody = new ArrayList<>();
95 + if (this.unReservedBandwidth.size() < 8) {
96 + int size = IsisUtil.EIGHT_BYTES - this.unReservedBandwidth.size();
97 + for (int i = 0; i < size; i++) {
98 + linkSubTypeBody.addAll(Bytes.asList(IsisUtil.convertToFourBytes(IsisUtil.INITIAL_BANDWIDTH)));
99 + }
100 + }
101 + for (Float unreservedBandwidth : this.unReservedBandwidth) {
102 + int unresBandwidth = Float.floatToIntBits(unreservedBandwidth);
103 + linkSubTypeBody.addAll(Bytes.asList(IsisUtil.convertToFourBytes(unresBandwidth)));
104 + }
105 +
106 + return Bytes.toArray(linkSubTypeBody);
107 + }
108 +
109 + @Override
110 + public String toString() {
111 + return MoreObjects.toStringHelper(getClass())
112 + .omitNullValues()
113 + .add("unReservedBandwidth", unReservedBandwidth)
114 + .toString();
115 + }
116 +}
...\ No newline at end of file ...\ No newline at end of file
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 +
17 +/**
18 + * Implementation of the ISIS protocol.
19 + */
20 +package org.onosproject.isis.io.isispacket.tlv.subtlv;
...\ No newline at end of file ...\ No newline at end of file
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
15 */ 15 */
16 16
17 /** 17 /**
18 - * Implementation of the ISIS protocol. 18 + * Implementation of the ISIS protocol IO.
19 */ 19 */
20 package org.onosproject.isis.io; 20 package org.onosproject.isis.io;
...\ No newline at end of file ...\ No newline at end of file
......
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.util;
17 +
18 +
19 +import java.util.Arrays;
20 +
21 +/**
22 + * Calculates checksum for ISIS LSP packets.
23 + */
24 +public class ChecksumCalculator {
25 +
26 + /**
27 + * Verifies the checksum is valid in given LSP packet bytes.
28 + *
29 + * @param lspPacket lsp as byte array
30 + * @param lspChecksumPos1 position of checksum bit in packet
31 + * @param lspChecksumPos2 position of checksum bit in packet
32 + * @return true if valid else false
33 + */
34 + public boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2) {
35 + byte[] checksum = calculateLspChecksum(lspPacket, lspChecksumPos1, lspChecksumPos2);
36 + if (lspPacket[lspChecksumPos1] == checksum[0] && lspPacket[lspChecksumPos2] == checksum[1]) {
37 + return true;
38 + }
39 + return false;
40 + }
41 +
42 +
43 + /**
44 + * Calculates the LSP checksum.
45 + *
46 + * @param lspBytes as byte array
47 + * @param lspChecksumPos1 position of checksum bit in packet
48 + * @param lspChecksumPos2 position of checksum bit in packet
49 + * @return checksum bytes
50 + */
51 + public byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) {
52 +
53 + byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length);
54 +
55 + int[] checksumOut = {0, 0};
56 + tempLsaByte[lspChecksumPos1] = 0;
57 + tempLsaByte[lspChecksumPos2] = 0;
58 + byte[] byteCheckSum = {0, 0};
59 + if (lspBytes != null) {
60 + for (int i = 12; i < tempLsaByte.length; i++) {
61 + checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF);
62 + checksumOut[1] = checksumOut[1] + checksumOut[0];
63 + }
64 + checksumOut[0] = checksumOut[0] % 255;
65 + checksumOut[1] = checksumOut[1] % 255;
66 + }
67 + int byte1 = (int) ((tempLsaByte.length - lspChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255;
68 + if (byte1 <= 0) {
69 + byte1 += 255;
70 + }
71 + int byte2 = 510 - checksumOut[0] - byte1;
72 + if (byte2 > 255) {
73 + byte2 -= 255;
74 + }
75 +
76 + byteCheckSum[0] = (byte) byte1;
77 + byteCheckSum[1] = (byte) byte2;
78 +
79 + return byteCheckSum;
80 + }
81 +}
...\ No newline at end of file ...\ No newline at end of file
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 +
17 +package org.onosproject.isis.io.util;
18 +
19 +/**
20 + * Representation of ISIS constants.
21 + */
22 +public final class IsisConstants {
23 + public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC
24 + public static final int MINIMUM_FRAME_LEN = 1521;
25 + public static final int METADATA_LEN = 7;
26 + public static final String SHOST = "127.0.0.1";
27 + public static final int SPORT = 3000;
28 + public static final byte L2 = 1;
29 + public static final int IRPDISCRIMINATOR = 131;
30 + public static final int ISISVERSION = 1;
31 + public static final int RESERVED = 0;
32 + public static final int MAXAREAADDRESS = 0;
33 + public static final int IDLENGTH = 0;
34 + public static final int PROTOCOLSUPPORTED = 204;
35 + public static final int LOCALCIRCUITIDFORP2P = 130;
36 + public static final int P2PHELLOHEADERLENGTH = 20;
37 + public static final int HELLOHEADERLENGTH = 27;
38 + public static final int CSNPDUHEADERLENGTH = 33;
39 + public static final int PSNPDUHEADERLENGTH = 17;
40 + public static final int PDULENGTHPOSITION = 17;
41 + public static final int COMMONHEADERLENGTH = 8;
42 + public static final int LSPMAXAGE = 1200;
43 + public static final int LSPREFRESH = 900;
44 + public static final int MAXSEQUENCENUMBER = Integer.MAX_VALUE;
45 + public static final int STARTLSSEQUENCENUM = 1;
46 + public static final int LENGTHPOSITION = 8;
47 + public static final int RESERVEDPOSITION = 6;
48 + public static final int CHECKSUMPOSITION = 24;
49 + public static final String REFRESHLSP = "refreshLsp";
50 + public static final String MAXAGELSP = "maxAgeLsp";
51 +
52 + /**
53 + * Non parameterized constructor.
54 + */
55 + private IsisConstants() {
56 + }
57 +}
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
15 */ 15 */
16 package org.onosproject.isis.io.util; 16 package org.onosproject.isis.io.util;
17 17
18 -
19 -import com.google.common.base.MoreObjects;
20 import com.google.common.primitives.Bytes; 18 import com.google.common.primitives.Bytes;
19 +import org.onlab.packet.Ip4Address;
21 import org.onosproject.isis.io.isispacket.tlv.PaddingTlv; 20 import org.onosproject.isis.io.isispacket.tlv.PaddingTlv;
22 import org.onosproject.isis.io.isispacket.tlv.TlvHeader; 21 import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
22 +import org.onosproject.isis.io.isispacket.tlv.TlvType;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
23 25
24 import javax.xml.bind.DatatypeConverter; 26 import javax.xml.bind.DatatypeConverter;
25 import java.util.ArrayList; 27 import java.util.ArrayList;
...@@ -27,56 +29,57 @@ import java.util.List; ...@@ -27,56 +29,57 @@ import java.util.List;
27 import java.util.StringTokenizer; 29 import java.util.StringTokenizer;
28 30
29 /** 31 /**
30 - * Represents ISIS utils. 32 + * Representation of ISIS utils.
31 */ 33 */
32 public final class IsisUtil { 34 public final class IsisUtil {
33 - public static final int AREAADDRESS = 1; 35 + public static final int ETHER_HEADER_LEN = 17;
34 - public static final int ISREACHABILITY = 2;
35 - public static final int ISNEIGHBORS = 6;
36 - public static final int PADDING = 8;
37 - public static final int LSPENTRY = 9;
38 - public static final int AUTHENTICATION = 10;
39 - public static final int CHECKSUM = 12;
40 - public static final int EXTENDEDISREACHABILITY = 22;
41 - public static final int ISALIAS = 24;
42 - public static final int IPINTERNALREACHABILITY = 128;
43 - public static final int PROTOCOLSUPPORTED = 129;
44 - public static final int IPEXTERNALREACHABILITY = 130;
45 - public static final int IDRPINFORMATION = 131;
46 - public static final int IPINTERFACEADDRESS = 132;
47 - public static final int L1HELLOPDU = 1;
48 - public static final int L2HELLOPDU = 2;
49 - public static final int P2PHELLOPDU = 3;
50 - public static final int L1LSPDU = 18;
51 - public static final int L2LSPDU = 20;
52 - public static final int L1CSNP = 24;
53 - public static final int L2CSNP = 25;
54 - public static final int L1PSNP = 26;
55 - public static final int L2PSNP = 27;
56 - public static final int L1L2_LS_PDUHEADERLENGTH = 27;
57 - public static final int P2PPDUHEADERLENGTH = 20;
58 - public static final int PSNPPDUHEADERLENGTH = 17;
59 - public static final char ETHER_FRAME_LEN = 1514;
60 public static final int ID_SIX_BYTES = 6; 36 public static final int ID_SIX_BYTES = 6;
61 public static final int ID_PLUS_ONE_BYTE = 7; 37 public static final int ID_PLUS_ONE_BYTE = 7;
62 public static final int ID_PLUS_TWO_BYTE = 8; 38 public static final int ID_PLUS_TWO_BYTE = 8;
63 public static final int THREE_BYTES = 3; 39 public static final int THREE_BYTES = 3;
64 public static final int SIX_BYTES = 6; 40 public static final int SIX_BYTES = 6;
41 + public static final int EIGHT_BYTES = 8;
65 public static final int FOUR_BYTES = 4; 42 public static final int FOUR_BYTES = 4;
66 public static final int PADDING_FIXED_LENGTH = 255; 43 public static final int PADDING_FIXED_LENGTH = 255;
44 + public static final int TLVHEADERLENGTH = 2;
45 + public static final int INITIAL_BANDWIDTH = 12500000;
46 + private static final Logger log = LoggerFactory.getLogger(IsisUtil.class);
67 47
68 /** 48 /**
69 - * Creates an instance of this class. 49 + * Creates an instance.
70 */ 50 */
71 private IsisUtil() { 51 private IsisUtil() {
72 52
73 } 53 }
74 54
75 /** 55 /**
56 + * Checks given IPs are in same network or not.
57 + *
58 + * @param ip1 IP address
59 + * @param ip2 IP address
60 + * @param mask network mask
61 + * @return true if both are in same network else false
62 + */
63 + public static boolean sameNetwork(Ip4Address ip1, Ip4Address ip2, byte[] mask) {
64 + try {
65 + byte[] a1 = ip1.toOctets();
66 + byte[] a2 = ip2.toOctets();
67 + for (int i = 0; i < a1.length; i++) {
68 + if ((a1[i] & mask[i]) != (a2[i] & mask[i])) {
69 + return false;
70 + }
71 + }
72 + } catch (Exception e) {
73 + log.debug("Exception::IsisUtil::sameNetwork:: {}", e.getMessage());
74 + }
75 + return true;
76 + }
77 +
78 + /**
76 * Parse byte array to string system ID. 79 * Parse byte array to string system ID.
77 * 80 *
78 * @param bytes system ID 81 * @param bytes system ID
79 - * @return systemId system ID. 82 + * @return systemId system ID
80 */ 83 */
81 public static String systemId(byte[] bytes) { 84 public static String systemId(byte[] bytes) {
82 String systemId = ""; 85 String systemId = "";
...@@ -97,7 +100,7 @@ public final class IsisUtil { ...@@ -97,7 +100,7 @@ public final class IsisUtil {
97 * Parse byte array to LAN ID. 100 * Parse byte array to LAN ID.
98 * 101 *
99 * @param bytes LAN ID 102 * @param bytes LAN ID
100 - * @return systemId system ID. 103 + * @return systemIdPlus system ID
101 */ 104 */
102 public static String systemIdPlus(byte[] bytes) { 105 public static String systemIdPlus(byte[] bytes) {
103 String systemId = ""; 106 String systemId = "";
...@@ -119,23 +122,18 @@ public final class IsisUtil { ...@@ -119,23 +122,18 @@ public final class IsisUtil {
119 * Parse byte array to area address. 122 * Parse byte array to area address.
120 * 123 *
121 * @param bytes area address 124 * @param bytes area address
122 - * @return areaAddress area address 125 + * @return areaAddres area address
123 */ 126 */
124 public static String areaAddres(byte[] bytes) { 127 public static String areaAddres(byte[] bytes) {
125 - int count = 0; 128 + String areaAddres = "";
126 - String areaAddress = "";
127 for (Byte byt : bytes) { 129 for (Byte byt : bytes) {
128 String hexa = Integer.toHexString(Byte.toUnsignedInt(byt)); 130 String hexa = Integer.toHexString(Byte.toUnsignedInt(byt));
129 if (hexa.length() % 2 != 0) { 131 if (hexa.length() % 2 != 0) {
130 hexa = "0" + hexa; 132 hexa = "0" + hexa;
131 } 133 }
132 - if (count == 0) { 134 + areaAddres = areaAddres + hexa;
133 - hexa = hexa + ".";
134 - }
135 - areaAddress = areaAddress + hexa;
136 - count++;
137 } 135 }
138 - return areaAddress; 136 + return areaAddres;
139 } 137 }
140 138
141 /** 139 /**
...@@ -144,76 +142,98 @@ public final class IsisUtil { ...@@ -144,76 +142,98 @@ public final class IsisUtil {
144 * @param address area address 142 * @param address area address
145 * @return areaAddress area address 143 * @return areaAddress area address
146 */ 144 */
147 - public static List<Byte> areaAddresToBytes(String address) { 145 + public static List<Byte> areaAddressToBytes(String address) {
148 - List<Byte> idLst = new ArrayList(); 146 + List<Byte> idList = new ArrayList<>();
149 - StringTokenizer tokenizer = new StringTokenizer(address, "."); 147 + for (int i = 0; i < address.length(); i = i + 2) {
150 - int count = 0; 148 + Character c1 = address.charAt(i);
151 - while (tokenizer.hasMoreElements()) { 149 + Character c2 = address.charAt(i + 1);
152 - String str = tokenizer.nextToken(); 150 + String str = c1.toString() + c2.toString();
153 - if (str.length() % 2 != 0) { 151 + idList.add((byte) Integer.parseInt(str, 16));
154 - str = "0" + str;
155 - }
156 - if (count > 0) {
157 -
158 - for (int i = 0; i < str.length(); i = i + 2) {
159 - idLst.add((byte) Integer.parseInt(str.substring(i, i + 2), 16));
160 - }
161 - } else {
162 - idLst.add((byte) Integer.parseInt(str, 16));
163 - }
164 - count++;
165 } 152 }
166 - return idLst; 153 + return idList;
154 + }
155 +
156 + /**
157 + * Adds the PDU length in packet.
158 + *
159 + * @param isisPacket ISIS packet
160 + * @param lengthBytePos1 length byte position
161 + * @param lengthBytePos2 length byte position
162 + * @param reservedBytePos reserved byte position
163 + * @return byte array with PDU length
164 + */
165 + public static byte[] addLengthAndMarkItInReserved(byte[] isisPacket, int lengthBytePos1,
166 + int lengthBytePos2, int reservedBytePos) {
167 + //Set the length of the packet
168 + //Get the total length of the packet
169 + int length = isisPacket.length;
170 + //Convert the lenth to two bytes as the length field is 2 bytes
171 + byte[] lenthInTwoBytes = IsisUtil.convertToTwoBytes(length);
172 + //isis header 3rd and 4th position represents length
173 + isisPacket[lengthBytePos1] = lenthInTwoBytes[0]; //assign 1st byte in lengthBytePos1
174 + isisPacket[lengthBytePos2] = lenthInTwoBytes[1]; //assign 2st byte in lengthBytePos2
175 + isisPacket[reservedBytePos] = (byte) lengthBytePos1;
176 + return isisPacket;
167 } 177 }
168 178
169 /** 179 /**
170 - * Gets PDU header length. 180 + * Adds the checksum in packet.
171 * 181 *
172 - * @param pduType PDU type 182 + * @param isisPacket ISIS packet
173 - * @return headerLength header length 183 + * @param checksumBytePos1 checksum byte position
184 + * @param checksumBytePos2 checksum byte position
185 + * @return byte array with PDU length
174 */ 186 */
175 - public static int getPduHeaderLength(int pduType) { 187 + public static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2) {
176 - int headerLength = 0; 188 + //Set the checksum for the packet
177 - switch (pduType) { 189 + //Convert the lenth to two bytes as the length field is 2 bytes
178 - case L1HELLOPDU: 190 + byte[] checksumInTwoBytes = new ChecksumCalculator().calculateLspChecksum(
179 - case L2HELLOPDU: 191 + isisPacket, checksumBytePos1, checksumBytePos2);
180 - case L1LSPDU: 192 + //isis header 3rd and 4th position represents length
181 - case L2LSPDU: 193 + isisPacket[checksumBytePos1] = checksumInTwoBytes[0];
182 - headerLength = L1L2_LS_PDUHEADERLENGTH; 194 + isisPacket[checksumBytePos2] = checksumInTwoBytes[1];
183 - break; 195 + return isisPacket;
184 - case P2PHELLOPDU: 196 + }
185 - headerLength = P2PPDUHEADERLENGTH; 197 +
186 - break; 198 + /**
187 - case L1PSNP: 199 + * Adds frame a packet of 1498 of size.
188 - case L2PSNP: 200 + *
189 - headerLength = PSNPPDUHEADERLENGTH; 201 + * @param isisPacket ISIS packet
190 - break; 202 + * @param interfaceIndex interface index
191 - default: 203 + * @return byte array with 1498 is the length
192 - break; 204 + */
205 + public static byte[] framePacket(byte[] isisPacket, int interfaceIndex) {
206 + //Set the length of the packet
207 + //Get the total length of the packet
208 + int length = isisPacket.length;
209 + //PDU_LENGTH + 1 byte for interface index
210 + if (length < IsisConstants.PDU_LENGTH + 1) {
211 + byte[] bytes = new byte[IsisConstants.PDU_LENGTH + 1];
212 + System.arraycopy(isisPacket, 0, bytes, 0, length);
213 + bytes[IsisConstants.PDU_LENGTH] = (byte) interfaceIndex;
214 + return bytes;
193 } 215 }
194 - return headerLength; 216 + return isisPacket;
195 } 217 }
196 218
197 /** 219 /**
198 * Parse source and LAN ID. 220 * Parse source and LAN ID.
199 * 221 *
200 * @param id source and LAN ID 222 * @param id source and LAN ID
201 - * @return sourceAndLanIdToBytes source and LAN ID 223 + * @return source and LAN ID
202 */ 224 */
203 public static List<Byte> sourceAndLanIdToBytes(String id) { 225 public static List<Byte> sourceAndLanIdToBytes(String id) {
204 - List<Byte> idLst = new ArrayList(); 226 + List<Byte> idList = new ArrayList<>();
205 - 227 + StringTokenizer tokenizer = new StringTokenizer(id, "." + "-");
206 - StringTokenizer tokenizer = new StringTokenizer(id, ".");
207 while (tokenizer.hasMoreElements()) { 228 while (tokenizer.hasMoreElements()) {
208 int i = 0; 229 int i = 0;
209 String str = tokenizer.nextToken(); 230 String str = tokenizer.nextToken();
210 - idLst.add((byte) Integer.parseInt(str.substring(0, i + 2), 16)); 231 + idList.add((byte) Integer.parseInt(str.substring(0, i + 2), 16));
211 if (str.length() > 2) { 232 if (str.length() > 2) {
212 - idLst.add((byte) Integer.parseInt(str.substring(i + 2, str.length()), 16)); 233 + idList.add((byte) Integer.parseInt(str.substring(i + 2, str.length()), 16));
213 } 234 }
214 -
215 } 235 }
216 - return idLst; 236 + return idList;
217 } 237 }
218 238
219 /** 239 /**
...@@ -222,20 +242,20 @@ public final class IsisUtil { ...@@ -222,20 +242,20 @@ public final class IsisUtil {
222 * @param currentLength current length 242 * @param currentLength current length
223 * @return byteArray padding array 243 * @return byteArray padding array
224 */ 244 */
225 - public static byte[] paddingForPdu(int currentLength) { 245 + public static byte[] getPaddingTlvs(int currentLength) {
226 List<Byte> bytes = new ArrayList<>(); 246 List<Byte> bytes = new ArrayList<>();
227 - while (ETHER_FRAME_LEN > currentLength) { 247 + while (IsisConstants.PDU_LENGTH > currentLength) {
228 - int length = ETHER_FRAME_LEN - currentLength; 248 + int length = IsisConstants.PDU_LENGTH - currentLength;
229 TlvHeader tlvHeader = new TlvHeader(); 249 TlvHeader tlvHeader = new TlvHeader();
230 - tlvHeader.setTlvType(PADDING); 250 + tlvHeader.setTlvType(TlvType.PADDING.value());
231 if (length >= PADDING_FIXED_LENGTH) { 251 if (length >= PADDING_FIXED_LENGTH) {
232 tlvHeader.setTlvLength(PADDING_FIXED_LENGTH); 252 tlvHeader.setTlvLength(PADDING_FIXED_LENGTH);
233 } else { 253 } else {
234 - tlvHeader.setTlvLength(ETHER_FRAME_LEN - currentLength); 254 + tlvHeader.setTlvLength(IsisConstants.PDU_LENGTH - (currentLength + TLVHEADERLENGTH));
235 } 255 }
236 PaddingTlv tlv = new PaddingTlv(tlvHeader); 256 PaddingTlv tlv = new PaddingTlv(tlvHeader);
237 bytes.addAll(Bytes.asList(tlv.asBytes())); 257 bytes.addAll(Bytes.asList(tlv.asBytes()));
238 - currentLength = currentLength + tlv.tlvLength(); 258 + currentLength = currentLength + tlv.tlvLength() + TLVHEADERLENGTH;
239 } 259 }
240 byte[] byteArray = new byte[bytes.size()]; 260 byte[] byteArray = new byte[bytes.size()];
241 int i = 0; 261 int i = 0;
...@@ -243,7 +263,6 @@ public final class IsisUtil { ...@@ -243,7 +263,6 @@ public final class IsisUtil {
243 byteArray[i++] = byt; 263 byteArray[i++] = byt;
244 } 264 }
245 return byteArray; 265 return byteArray;
246 -
247 } 266 }
248 267
249 /** 268 /**
...@@ -308,10 +327,138 @@ public final class IsisUtil { ...@@ -308,10 +327,138 @@ public final class IsisUtil {
308 return numInBytes; 327 return numInBytes;
309 } 328 }
310 329
311 - @Override 330 + /**
312 - public String toString() { 331 + * Converts a byte to integer variable.
313 - return MoreObjects.toStringHelper(getClass()) 332 + *
314 - .omitNullValues() 333 + * @param bytesToConvert bytes to convert
315 - .toString(); 334 + * @return integer representation of bytes
335 + */
336 + public static int byteToInteger(byte[] bytesToConvert) {
337 + final StringBuilder builder = new StringBuilder();
338 + for (byte eachByte : bytesToConvert) {
339 + builder.append(String.format("%02x", eachByte));
340 + }
341 + int number = Integer.parseInt(builder.toString(), 16);
342 + return number;
343 + }
344 +
345 + /**
346 + * Converts a byte to long variable.
347 + *
348 + * @param bytesToConvert bytes to convert
349 + * @return long representation of bytes
350 + */
351 + public static long byteToLong(byte[] bytesToConvert) {
352 + final StringBuilder builder = new StringBuilder();
353 + for (byte eachByte : bytesToConvert) {
354 + builder.append(String.format("%02x", eachByte));
355 + }
356 + long number = Long.parseLong(builder.toString(), 16);
357 + return number;
358 + }
359 +
360 + /**
361 + * Converts a number to four bytes.
362 + *
363 + * @param numberToConvert number to convert
364 + * @return numInBytes given number as bytes
365 + */
366 + public static byte[] convertToFourBytes(long numberToConvert) {
367 + byte[] numInBytes = new byte[4];
368 + String s1 = Long.toHexString(numberToConvert);
369 + if (s1.length() % 2 != 0) {
370 + s1 = "0" + s1;
371 + }
372 + if (s1.length() == 16) {
373 + s1 = s1.substring(8, s1.length());
374 + }
375 + byte[] hexas = DatatypeConverter.parseHexBinary(s1);
376 + if (hexas.length == 1) {
377 + numInBytes[0] = 0;
378 + numInBytes[1] = 0;
379 + numInBytes[2] = 0;
380 + numInBytes[3] = hexas[0];
381 + } else if (hexas.length == 2) {
382 + numInBytes[0] = 0;
383 + numInBytes[1] = 0;
384 + numInBytes[2] = hexas[0];
385 + numInBytes[3] = hexas[1];
386 + } else if (hexas.length == 3) {
387 + numInBytes[0] = 0;
388 + numInBytes[1] = hexas[0];
389 + numInBytes[2] = hexas[1];
390 + numInBytes[3] = hexas[2];
391 + } else {
392 + numInBytes[0] = hexas[0];
393 + numInBytes[1] = hexas[1];
394 + numInBytes[2] = hexas[2];
395 + numInBytes[3] = hexas[3];
396 + }
397 + return numInBytes;
398 + }
399 +
400 + /**
401 + * Converts a number to eight bit binary.
402 + *
403 + * @param binaryString string to binary
404 + * @return numInBytes given number as bytes
405 + */
406 + public static String toEightBitBinary(String binaryString) {
407 + String eightBit = binaryString;
408 + if (eightBit.length() % 8 != 0) {
409 + int numOfZero = 8 - eightBit.length();
410 + while (numOfZero > 0) {
411 + eightBit = "0" + eightBit;
412 + numOfZero--;
413 + }
414 + }
415 + return eightBit;
416 + }
417 +
418 + /**
419 + * Converts a number to four bit binary.
420 + *
421 + * @param binaryString string to binary
422 + * @return numInBytes given number as bytes
423 + */
424 + public static String toFourBitBinary(String binaryString) {
425 + String fourBit = binaryString;
426 + if (fourBit.length() % 4 != 0) {
427 + int numOfZero = 4 - fourBit.length();
428 + while (numOfZero > 0) {
429 + fourBit = "0" + fourBit;
430 + numOfZero--;
431 + }
432 + }
433 + return fourBit;
434 + }
435 +
436 + /**
437 + * Converts a number to three bytes.
438 + *
439 + * @param numberToConvert number to convert
440 + * @return given number as bytes
441 + */
442 + public static byte[] convertToThreeBytes(int numberToConvert) {
443 + byte[] numInBytes = new byte[4];
444 + String s1 = Integer.toHexString(numberToConvert);
445 + if (s1.length() % 2 != 0) {
446 + s1 = "0" + s1;
447 + }
448 + byte[] hexas = DatatypeConverter.parseHexBinary(s1);
449 + if (hexas.length == 1) {
450 + numInBytes[0] = 0;
451 + numInBytes[1] = 0;
452 + numInBytes[2] = hexas[0];
453 + } else if (hexas.length == 2) {
454 + numInBytes[0] = 0;
455 + numInBytes[1] = hexas[0];
456 + numInBytes[2] = hexas[1];
457 + } else {
458 + numInBytes[0] = hexas[0];
459 + numInBytes[1] = hexas[1];
460 + numInBytes[2] = hexas[2];
461 + }
462 + return numInBytes;
316 } 463 }
317 -}
...\ No newline at end of file ...\ No newline at end of file
464 +}
......
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
15 */ 15 */
16 16
17 /** 17 /**
18 - * Implementation of the ISIS protocol. 18 + * Implementation of the ISIS protocol util.
19 */ 19 */
20 package org.onosproject.isis.io.util; 20 package org.onosproject.isis.io.util;
...\ No newline at end of file ...\ No newline at end of file
......