Committed by
Gerrit Code Review
ONOS-4083,ONOS-4084:ISIS PDU TLV Data Structures
Change-Id: Ice0d42f2c886fa5f398b562e126614ed45f858a2
Showing
40 changed files
with
2314 additions
and
184 deletions
protocols/isis/isisio/pom.xml
100755 → 100644
... | @@ -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> | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/package-info.java
100755 → 100644
File mode changed
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AdjacencyStateTlv.java
0 → 100644
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 | +} |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/AreaAddressTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/HostNameTlv.java
0 → 100644
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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IdrpInformationTlv.java
0 → 100644
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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IpInterfaceAddressTlv.java
100755 → 100644
... | @@ -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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsReachabilityTlv.java
0 → 100644
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 | +} |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisNeighborTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/IsisTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/LspEntriesTlv.java
0 → 100644
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 |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/PaddingTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvFinder.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvHeader.java
100755 → 100644
... | @@ -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); | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvType.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/TlvsToBytes.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/package-info.java
100755 → 100644
File mode changed
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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvFinder.java
0 → 100644
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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvToBytes.java
0 → 100644
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 | +} |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/SubTlvType.java
0 → 100644
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 |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/subtlv/package-info.java
0 → 100644
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 | +} |
This diff is collapsed. Click to expand it.
... | @@ -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 | ... | ... |
File mode changed
-
Please register or login to post a comment