Committed by
Gerrit Code Review
ONOS-4083, ONOS-4084, ONOS-4096, ONOS-4097:ISIS PDU Data Structures
Change-Id: I22d30e8f7ba7d414e75254fdec6d0865bf471ff9
Showing
43 changed files
with
2927 additions
and
247 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.isis.controller; | 16 | package org.onosproject.isis.controller; |
17 | 17 | ||
18 | import java.util.List; | 18 | import java.util.List; |
19 | +import java.util.Map; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Representation of an ISIS link state database. | 22 | * Representation of an ISIS link state database. |
... | @@ -93,4 +94,18 @@ public interface IsisLsdb { | ... | @@ -93,4 +94,18 @@ public interface IsisLsdb { |
93 | * @param lsp LSP instance | 94 | * @param lsp LSP instance |
94 | */ | 95 | */ |
95 | void deleteLsp(IsisMessage lsp); | 96 | void deleteLsp(IsisMessage lsp); |
96 | -} | 97 | + |
98 | + /** | ||
99 | + * Gets the neighbor database information. | ||
100 | + * | ||
101 | + * @return neighbor database information | ||
102 | + */ | ||
103 | + Map<String, LspWrapper> getL1Db(); | ||
104 | + | ||
105 | + /** | ||
106 | + * Gets the neighbor database information. | ||
107 | + * | ||
108 | + * @return neighbor database information | ||
109 | + */ | ||
110 | + Map<String, LspWrapper> getL2Db(); | ||
111 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -84,4 +84,18 @@ public interface IsisNeighbor { | ... | @@ -84,4 +84,18 @@ public interface IsisNeighbor { |
84 | * @param localExtendedCircuitId neighbor extended circuit ID | 84 | * @param localExtendedCircuitId neighbor extended circuit ID |
85 | */ | 85 | */ |
86 | void setLocalExtendedCircuitId(int localExtendedCircuitId); | 86 | void setLocalExtendedCircuitId(int localExtendedCircuitId); |
87 | + | ||
88 | + /** | ||
89 | + * Returns Holding time of neighbor. | ||
90 | + * | ||
91 | + * @return Holding time of neighbor | ||
92 | + */ | ||
93 | + int holdingTime(); | ||
94 | + | ||
95 | + /** | ||
96 | + * Sets Holding time of neighbor. | ||
97 | + * | ||
98 | + * @param holdingTime Holding time of neighbor | ||
99 | + */ | ||
100 | + void setHoldingTime(int holdingTime); | ||
87 | } | 101 | } | ... | ... |
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.exceptions; | ||
17 | + | ||
18 | +/** | ||
19 | + * Defines all error codes and error sub codes. | ||
20 | + */ | ||
21 | +public final class IsisErrorType { | ||
22 | + | ||
23 | + //Represents an invalid ISIS message header | ||
24 | + public static final byte MESSAGE_HEADER_ERROR = 1; | ||
25 | + //Represents an invalid ISIS message body | ||
26 | + public static final byte ISIS_MESSAGE_ERROR = 2; | ||
27 | + //Message Header error sub codes | ||
28 | + //Represents an invalid ISIS message length | ||
29 | + public static final byte BAD_MESSAGE_LENGTH = 3; | ||
30 | + //Represents an invalid ISIS message | ||
31 | + public static final byte BAD_MESSAGE = 4; | ||
32 | + | ||
33 | + /** | ||
34 | + * Creates an instance of ISIS error type. | ||
35 | + */ | ||
36 | + private IsisErrorType() { | ||
37 | + } | ||
38 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/exceptions/IsisParseException.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.exceptions; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +/** | ||
21 | + * Representation of a custom exception for ISIS. | ||
22 | + */ | ||
23 | +public class IsisParseException extends Exception { | ||
24 | + | ||
25 | + private static final long serialVersionUID = 1L; | ||
26 | + private byte errorCode; | ||
27 | + private byte errorSubCode; | ||
28 | + | ||
29 | + /** | ||
30 | + * Creates a new ISIS exception. | ||
31 | + */ | ||
32 | + public IsisParseException() { | ||
33 | + super(); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates a new ISIS exception based on the given arguments. | ||
38 | + * | ||
39 | + * @param message the detail of exception in string | ||
40 | + * @param cause underlying cause of the error | ||
41 | + */ | ||
42 | + public IsisParseException(final String message, final Throwable cause) { | ||
43 | + super(message, cause); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Creates a new ISIS exception for the given message. | ||
48 | + * | ||
49 | + * @param message the detail of exception in string | ||
50 | + */ | ||
51 | + public IsisParseException(final String message) { | ||
52 | + super(message); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Creates a new ISIS exception from throwable instance. | ||
57 | + * | ||
58 | + * @param cause underlying cause of the error | ||
59 | + */ | ||
60 | + public IsisParseException(final Throwable cause) { | ||
61 | + super(cause); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Creates a new ISIS exception from error code and error sub code. | ||
66 | + * | ||
67 | + * @param errorCode error code of ISIS message | ||
68 | + * @param errorSubCode error sub code of ISIS message | ||
69 | + */ | ||
70 | + public IsisParseException(final byte errorCode, final byte errorSubCode) { | ||
71 | + super(); | ||
72 | + this.errorCode = errorCode; | ||
73 | + this.errorSubCode = errorSubCode; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Returns error code for this exception. | ||
78 | + * | ||
79 | + * @return error code for this exception | ||
80 | + */ | ||
81 | + public byte errorCode() { | ||
82 | + return this.errorCode; | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Returns error sub code for this exception. | ||
87 | + * | ||
88 | + * @return error sub code for this exception | ||
89 | + */ | ||
90 | + public byte errorSubCode() { | ||
91 | + return this.errorSubCode; | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public String toString() { | ||
96 | + return MoreObjects.toStringHelper(getClass()) | ||
97 | + .omitNullValues() | ||
98 | + .add("errorCode", errorCode) | ||
99 | + .add("errorSubCode", errorSubCode) | ||
100 | + .toString(); | ||
101 | + } | ||
102 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * Implementation of the ISIS protocol exceptions. | ||
19 | + */ | ||
20 | +package org.onosproject.isis.exceptions; |
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; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.onlab.packet.MacAddress; | ||
20 | +import org.onosproject.isis.controller.IsisMessage; | ||
21 | +import org.onosproject.isis.controller.IsisPduType; | ||
22 | + | ||
23 | +/** | ||
24 | + * Representation of ISIS message header. | ||
25 | + */ | ||
26 | +public class IsisHeader implements IsisMessage { | ||
27 | + | ||
28 | + private MacAddress sourceMac; | ||
29 | + private int interfaceIndex; | ||
30 | + private MacAddress interfaceMac; | ||
31 | + private int isisPduType; | ||
32 | + private byte irpDiscriminator; | ||
33 | + private byte pduHeaderLength; | ||
34 | + private byte version2; | ||
35 | + private byte idLength; | ||
36 | + private byte version; | ||
37 | + private byte reserved; | ||
38 | + private byte maximumAreaAddresses; | ||
39 | + | ||
40 | + /** | ||
41 | + * Returns the interface index on which the message received. | ||
42 | + * | ||
43 | + * @return interface index on which the message received | ||
44 | + */ | ||
45 | + public int interfaceIndex() { | ||
46 | + return interfaceIndex; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Sets the interface index on which the message received. | ||
51 | + * | ||
52 | + * @param interfaceIndex interface index on which the message received | ||
53 | + */ | ||
54 | + public void setInterfaceIndex(int interfaceIndex) { | ||
55 | + this.interfaceIndex = interfaceIndex; | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns the interface mac address on which the message received. | ||
60 | + * | ||
61 | + * @return interface mac address on which the message received | ||
62 | + */ | ||
63 | + public MacAddress interfaceMac() { | ||
64 | + return interfaceMac; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Returns the mac address of the message sender. | ||
69 | + * | ||
70 | + * @return mac address of the message sender | ||
71 | + */ | ||
72 | + public MacAddress sourceMac() { | ||
73 | + return sourceMac; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Sets the mac address of the message sender. | ||
78 | + * | ||
79 | + * @param sourceMac mac address of the message sender | ||
80 | + */ | ||
81 | + public void setSourceMac(MacAddress sourceMac) { | ||
82 | + this.sourceMac = sourceMac; | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Sets the interface mac address on which the message received. | ||
87 | + * | ||
88 | + * @param interfaceMac mac address on which the message received | ||
89 | + */ | ||
90 | + public void setInterfaceMac(MacAddress interfaceMac) { | ||
91 | + this.interfaceMac = interfaceMac; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Returns the version of TLV header. | ||
96 | + * | ||
97 | + * @return version version of TLV header | ||
98 | + */ | ||
99 | + public byte version2() { | ||
100 | + return version2; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Sets the version of TLV header. | ||
105 | + * | ||
106 | + * @param version2 version of TLV header | ||
107 | + */ | ||
108 | + public void setVersion2(byte version2) { | ||
109 | + this.version2 = version2; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns maximum area address. | ||
114 | + * | ||
115 | + * @return maximum area address | ||
116 | + */ | ||
117 | + public byte maximumAreaAddresses() { | ||
118 | + return maximumAreaAddresses; | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Sets maximum area address. | ||
123 | + * | ||
124 | + * @param maximumAreaAddresses maximum area address | ||
125 | + */ | ||
126 | + public void setMaximumAreaAddresses(byte maximumAreaAddresses) { | ||
127 | + this.maximumAreaAddresses = maximumAreaAddresses; | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Returns reserved field value on which data received. | ||
132 | + * | ||
133 | + * @return reserved | ||
134 | + */ | ||
135 | + public byte reserved() { | ||
136 | + return reserved; | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Sets reserved. | ||
141 | + * | ||
142 | + * @param reserved reserved | ||
143 | + */ | ||
144 | + public void setReserved(byte reserved) { | ||
145 | + this.reserved = reserved; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Returns version. | ||
150 | + * | ||
151 | + * @return version | ||
152 | + */ | ||
153 | + public byte version() { | ||
154 | + return version; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Returns ID length. | ||
159 | + * | ||
160 | + * @return ID length | ||
161 | + */ | ||
162 | + public byte idLength() { | ||
163 | + return idLength; | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Sets ID length. | ||
168 | + * | ||
169 | + * @param idLength ID length | ||
170 | + */ | ||
171 | + public void setIdLength(byte idLength) { | ||
172 | + this.idLength = idLength; | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * Returns the PDU type. | ||
177 | + * | ||
178 | + * @return PDU type | ||
179 | + */ | ||
180 | + public int pduType() { | ||
181 | + | ||
182 | + return this.isisPduType; | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Sets PDU type. | ||
187 | + * | ||
188 | + * @param isisPduType PDU type | ||
189 | + */ | ||
190 | + public void setIsisPduType(int isisPduType) { | ||
191 | + this.isisPduType = isisPduType; | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * Sets protocol ID. | ||
196 | + * | ||
197 | + * @param version protocol ID | ||
198 | + */ | ||
199 | + public void setVersion(byte version) { | ||
200 | + this.version = version; | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Returns length indicator. | ||
205 | + * | ||
206 | + * @return length indicator | ||
207 | + */ | ||
208 | + public byte pduHeaderLength() { | ||
209 | + return pduHeaderLength; | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Sets length indicator. | ||
214 | + * | ||
215 | + * @param pduHeaderLength length indicator | ||
216 | + */ | ||
217 | + public void setPduHeaderLength(byte pduHeaderLength) { | ||
218 | + this.pduHeaderLength = pduHeaderLength; | ||
219 | + } | ||
220 | + | ||
221 | + /** | ||
222 | + * Returns IRP discriminator. | ||
223 | + * | ||
224 | + * @return IRP discriminator | ||
225 | + */ | ||
226 | + public byte irpDiscriminator() { | ||
227 | + return irpDiscriminator; | ||
228 | + } | ||
229 | + | ||
230 | + /** | ||
231 | + * Sets IRP discriminator. | ||
232 | + * | ||
233 | + * @param irpDiscriminator IRP discriminator | ||
234 | + */ | ||
235 | + public void setIrpDiscriminator(byte irpDiscriminator) { | ||
236 | + | ||
237 | + this.irpDiscriminator = irpDiscriminator; | ||
238 | + } | ||
239 | + | ||
240 | + @Override | ||
241 | + public IsisPduType isisPduType() { | ||
242 | + | ||
243 | + return IsisPduType.get(this.isisPduType); | ||
244 | + } | ||
245 | + | ||
246 | + @Override | ||
247 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
248 | + //implemented in the sub classes | ||
249 | + } | ||
250 | + | ||
251 | + @Override | ||
252 | + public byte[] asBytes() { | ||
253 | + return null; | ||
254 | + } | ||
255 | + | ||
256 | + /** | ||
257 | + * Populates ISIS header. | ||
258 | + * | ||
259 | + * @param isisHeader ISIS header | ||
260 | + */ | ||
261 | + public void populateHeader(IsisHeader isisHeader) { | ||
262 | + this.setIrpDiscriminator(isisHeader.irpDiscriminator()); | ||
263 | + this.setPduHeaderLength(isisHeader.pduHeaderLength()); | ||
264 | + this.setVersion(isisHeader.version()); | ||
265 | + this.setIdLength(isisHeader.idLength()); | ||
266 | + this.setIsisPduType(isisHeader.pduType()); | ||
267 | + this.setVersion2(isisHeader.version2()); | ||
268 | + this.setReserved(isisHeader.reserved()); | ||
269 | + this.setMaximumAreaAddresses(isisHeader.maximumAreaAddresses()); | ||
270 | + } | ||
271 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/IsisMessageReader.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; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.onosproject.isis.controller.IsisMessage; | ||
20 | +import org.onosproject.isis.exceptions.IsisErrorType; | ||
21 | +import org.onosproject.isis.exceptions.IsisParseException; | ||
22 | +import org.onosproject.isis.io.isispacket.pdu.Csnp; | ||
23 | +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; | ||
24 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
25 | +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; | ||
26 | +import org.onosproject.isis.io.isispacket.pdu.Psnp; | ||
27 | +import org.onosproject.isis.io.util.IsisConstants; | ||
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
30 | + | ||
31 | +/** | ||
32 | + * Represents ISIS message reader. | ||
33 | + */ | ||
34 | +public class IsisMessageReader { | ||
35 | + | ||
36 | + protected static final Logger log = LoggerFactory.getLogger(IsisMessageReader.class); | ||
37 | + | ||
38 | + /** | ||
39 | + * Reads from ISIS packet from buffer. | ||
40 | + * | ||
41 | + * @param channelBuffer buffer | ||
42 | + * @return ISIS message | ||
43 | + * @throws Exception exception | ||
44 | + */ | ||
45 | + public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { | ||
46 | + | ||
47 | + int dataLength = channelBuffer.readableBytes(); | ||
48 | + log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); | ||
49 | + if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { | ||
50 | + log.debug("Packet should have minimum length..."); | ||
51 | + throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); | ||
52 | + } | ||
53 | + IsisHeader isisHeader = getIsisHeader(channelBuffer); | ||
54 | + int totalLength = 0; | ||
55 | + IsisMessage isisMessage = null; | ||
56 | + switch (isisHeader.isisPduType()) { | ||
57 | + case L1HELLOPDU: | ||
58 | + case L2HELLOPDU: | ||
59 | + isisMessage = new L1L2HelloPdu(isisHeader); | ||
60 | + totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); | ||
61 | + break; | ||
62 | + case P2PHELLOPDU: | ||
63 | + isisMessage = new P2PHelloPdu(isisHeader); | ||
64 | + totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); | ||
65 | + break; | ||
66 | + case L1LSPDU: | ||
67 | + case L2LSPDU: | ||
68 | + isisMessage = new LsPdu(isisHeader); | ||
69 | + totalLength = channelBuffer.getShort(8); | ||
70 | + break; | ||
71 | + case L1CSNP: | ||
72 | + case L2CSNP: | ||
73 | + isisMessage = new Csnp(isisHeader); | ||
74 | + totalLength = channelBuffer.getShort(8); | ||
75 | + break; | ||
76 | + case L1PSNP: | ||
77 | + case L2PSNP: | ||
78 | + isisMessage = new Psnp(isisHeader); | ||
79 | + totalLength = channelBuffer.getShort(8); | ||
80 | + break; | ||
81 | + default: | ||
82 | + log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); | ||
83 | + break; | ||
84 | + } | ||
85 | + | ||
86 | + if (isisMessage != null) { | ||
87 | + try { | ||
88 | + int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; | ||
89 | + isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); | ||
90 | + | ||
91 | + } catch (Exception e) { | ||
92 | + throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, | ||
93 | + IsisErrorType.BAD_MESSAGE); | ||
94 | + } | ||
95 | + | ||
96 | + } | ||
97 | + | ||
98 | + return isisMessage; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Gets ISIS header. | ||
103 | + * | ||
104 | + * @param channelBuffer ISIS header | ||
105 | + * @return ISIS header | ||
106 | + * @throws Exception | ||
107 | + */ | ||
108 | + private IsisHeader getIsisHeader(ChannelBuffer channelBuffer) throws Exception { | ||
109 | + | ||
110 | + IsisHeader isisHeader = new IsisHeader(); | ||
111 | + isisHeader.setIrpDiscriminator(channelBuffer.readByte()); | ||
112 | + isisHeader.setPduHeaderLength(channelBuffer.readByte()); | ||
113 | + isisHeader.setVersion(channelBuffer.readByte()); | ||
114 | + isisHeader.setIdLength(channelBuffer.readByte()); | ||
115 | + isisHeader.setIsisPduType(channelBuffer.readByte()); | ||
116 | + isisHeader.setVersion2(channelBuffer.readByte()); | ||
117 | + isisHeader.setReserved(channelBuffer.readByte()); | ||
118 | + isisHeader.setMaximumAreaAddresses(channelBuffer.readByte()); | ||
119 | + | ||
120 | + return isisHeader; | ||
121 | + } | ||
122 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/AttachedToOtherAreas.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.pdu; | ||
17 | + | ||
18 | +import java.util.EnumSet; | ||
19 | +import java.util.HashMap; | ||
20 | +import java.util.Map; | ||
21 | + | ||
22 | +/** | ||
23 | + * Representation of attached to other areas. | ||
24 | + */ | ||
25 | +public enum AttachedToOtherAreas { | ||
26 | + DEFAULTMETRIC(1), | ||
27 | + DELAYMETRIC(2), | ||
28 | + EXPENSEMETRIC(4), | ||
29 | + ERRORMETRIC(8), | ||
30 | + NONE(0); | ||
31 | + // Reverse lookup table | ||
32 | + private static final Map<Integer, AttachedToOtherAreas> LOOKUP = new HashMap<>(); | ||
33 | + | ||
34 | + // Populate the lookup table on loading time | ||
35 | + static { | ||
36 | + for (AttachedToOtherAreas attachedToOtherAreas : | ||
37 | + EnumSet.allOf(AttachedToOtherAreas.class)) { | ||
38 | + LOOKUP.put(attachedToOtherAreas.value(), attachedToOtherAreas); | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + private int value; | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the attached to other areas value. | ||
46 | + * | ||
47 | + * @param value attached to other areas value | ||
48 | + */ | ||
49 | + AttachedToOtherAreas(int value) { | ||
50 | + this.value = value; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Returns the value for attached to other areas from pdu type value. | ||
55 | + * | ||
56 | + * @param pduTypeValue to get attached areas value | ||
57 | + * @return attachedToOtherAreas value of the enum | ||
58 | + */ | ||
59 | + public static AttachedToOtherAreas get(int pduTypeValue) { | ||
60 | + return LOOKUP.get(pduTypeValue); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Returns the value representing PDU type. | ||
65 | + * | ||
66 | + * @return value represents PDU type | ||
67 | + */ | ||
68 | + public int value() { | ||
69 | + return value; | ||
70 | + } | ||
71 | +} | ||
... | \ 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.pdu; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import com.google.common.primitives.Bytes; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
23 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.TlvFinder; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes; | ||
28 | +import org.onosproject.isis.io.util.IsisUtil; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * Representation of complete sequence number PDU. | ||
35 | + */ | ||
36 | +public class Csnp extends IsisHeader { | ||
37 | + | ||
38 | + /* | ||
39 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
40 | + | Intra-domain Routing Protocol Discriminator | | ||
41 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
42 | + | Length Indicator | | ||
43 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
44 | + | Version/Protocol ID Extension | | ||
45 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
46 | + | ID Length | | ||
47 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
48 | + | R | R | R | PDU Type | | ||
49 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
50 | + | Version | | ||
51 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
52 | + | Reserved | | ||
53 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
54 | + | Maximum area address | | ||
55 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
56 | + | PDU Length | | ||
57 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
58 | + | Source ID | | ||
59 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
60 | + | Start LSP ID | | ||
61 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
62 | + | End LSP ID | | ||
63 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
64 | + | Variable Lengths Fields | | ||
65 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
66 | + | ||
67 | + CSNP Message Format | ||
68 | + REFERENCE : ISO/IEC 10589 | ||
69 | + */ | ||
70 | + private int pduLength; | ||
71 | + private String sourceId; | ||
72 | + private String startLspId; | ||
73 | + private String endLspId; | ||
74 | + private List<IsisTlv> variableLengths = new ArrayList<>(); | ||
75 | + | ||
76 | + /** | ||
77 | + * Creates the instance for this class. | ||
78 | + * | ||
79 | + * @param isisHeader ISIS header | ||
80 | + */ | ||
81 | + public Csnp(IsisHeader isisHeader) { | ||
82 | + populateHeader(isisHeader); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Returns the list of all tlvs. | ||
87 | + * | ||
88 | + * @return variableLengths list of tlvs | ||
89 | + */ | ||
90 | + public List<IsisTlv> getAllTlv() { | ||
91 | + return variableLengths; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Returns the source ID of csnp. | ||
96 | + * | ||
97 | + * @return sourceId source ID | ||
98 | + */ | ||
99 | + public String sourceId() { | ||
100 | + return sourceId; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Sets the source ID for csnp. | ||
105 | + * | ||
106 | + * @param sourceId source ID | ||
107 | + */ | ||
108 | + public void setSourceId(String sourceId) { | ||
109 | + this.sourceId = sourceId; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns the initial link state packet ID of csnp. | ||
114 | + * | ||
115 | + * @return startLspId start link state packet ID | ||
116 | + */ | ||
117 | + public String startLspId() { | ||
118 | + return startLspId; | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Sets the initial link state packet ID for csnp. | ||
123 | + * | ||
124 | + * @param startLspId start link state packet ID | ||
125 | + */ | ||
126 | + public void setStartLspId(String startLspId) { | ||
127 | + this.startLspId = startLspId; | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Returns the end link state packet ID of csnp. | ||
132 | + * | ||
133 | + * @return endLspId end link state packet ID of csnp. | ||
134 | + */ | ||
135 | + public String endLspId() { | ||
136 | + return endLspId; | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Sets the end link state packet ID for csnp. | ||
141 | + * | ||
142 | + * @param endLspId end link state packet ID of csnp. | ||
143 | + */ | ||
144 | + public void setEndLspId(String endLspId) { | ||
145 | + this.endLspId = endLspId; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Returns the packet data unit length of link state packet. | ||
150 | + * Entire length of this PDU, in octets | ||
151 | + * | ||
152 | + * @return pduLength packet date unit length | ||
153 | + */ | ||
154 | + public int pduLength() { | ||
155 | + return pduLength; | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Sets the packet data unit length for link state packet. | ||
160 | + * Entire Length of this PDU, in octets | ||
161 | + * | ||
162 | + * @param pduLength packet data length | ||
163 | + */ | ||
164 | + public void setPduLength(int pduLength) { | ||
165 | + this.pduLength = pduLength; | ||
166 | + } | ||
167 | + | ||
168 | + @Override | ||
169 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
170 | + this.setPduLength(channelBuffer.readUnsignedShort()); | ||
171 | + //source id + 1 value | ||
172 | + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE]; | ||
173 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE); | ||
174 | + this.setSourceId(IsisUtil.systemIdPlus(tempByteArray)); | ||
175 | + //start lsp id + 2 value | ||
176 | + tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE]; | ||
177 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE); | ||
178 | + this.setStartLspId(IsisUtil.systemIdPlus(tempByteArray)); | ||
179 | + //end lsp id + 2 value | ||
180 | + tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE]; | ||
181 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE); | ||
182 | + this.setEndLspId(IsisUtil.systemIdPlus(tempByteArray)); | ||
183 | + //tlv here | ||
184 | + while (channelBuffer.readableBytes() > 0) { | ||
185 | + TlvHeader tlvHeader = new TlvHeader(); | ||
186 | + tlvHeader.setTlvType(channelBuffer.readUnsignedByte()); | ||
187 | + tlvHeader.setTlvLength(channelBuffer.readUnsignedByte()); | ||
188 | + TlvType tlvValue = TlvType.get(tlvHeader.tlvType()); | ||
189 | + if (tlvValue != null) { | ||
190 | + IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | ||
191 | + this.variableLengths.add(tlv); | ||
192 | + } else { | ||
193 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
194 | + } | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + @Override | ||
199 | + public byte[] asBytes() { | ||
200 | + byte[] csnpMessage = null; | ||
201 | + byte[] isisPduHeader = isisPduHeader(); | ||
202 | + byte[] csnpBody = completeSequenceNumberPduBody(); | ||
203 | + csnpMessage = Bytes.concat(isisPduHeader, csnpBody); | ||
204 | + return csnpMessage; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Builds ISIS PDU header for complete sequence numbers PDU. | ||
209 | + * | ||
210 | + * @return isisPduHeader ISIS PDU header | ||
211 | + */ | ||
212 | + public byte[] isisPduHeader() { | ||
213 | + List<Byte> headerList = new ArrayList<>(); | ||
214 | + headerList.add(this.irpDiscriminator()); | ||
215 | + headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType())); | ||
216 | + headerList.add(this.version()); | ||
217 | + headerList.add(this.idLength()); | ||
218 | + headerList.add((byte) this.pduType()); | ||
219 | + headerList.add(this.version2()); | ||
220 | + headerList.add(this.reserved()); | ||
221 | + headerList.add(this.maximumAreaAddresses()); | ||
222 | + return Bytes.toArray(headerList); | ||
223 | + } | ||
224 | + | ||
225 | + /** | ||
226 | + * Builds complete sequence numbers PDU body. | ||
227 | + * | ||
228 | + * @return bodyList complete sequence numbers PDU body | ||
229 | + */ | ||
230 | + public byte[] completeSequenceNumberPduBody() { | ||
231 | + List<Byte> bodyList = new ArrayList<>(); | ||
232 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength()))); | ||
233 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId())); | ||
234 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.startLspId())); | ||
235 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.endLspId())); | ||
236 | + for (IsisTlv isisTlv : variableLengths) { | ||
237 | + bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv)); | ||
238 | + } | ||
239 | + return Bytes.toArray(bodyList); | ||
240 | + } | ||
241 | + | ||
242 | + @Override | ||
243 | + public String toString() { | ||
244 | + return MoreObjects.toStringHelper(getClass()) | ||
245 | + .omitNullValues() | ||
246 | + .add("pduLength", pduLength) | ||
247 | + .add("sourceId", sourceId) | ||
248 | + .add("startLspId", startLspId) | ||
249 | + .add("endLspId", endLspId) | ||
250 | + .toString(); | ||
251 | + } | ||
252 | + | ||
253 | + @Override | ||
254 | + public boolean equals(Object o) { | ||
255 | + if (this == o) { | ||
256 | + return true; | ||
257 | + } | ||
258 | + if (o == null || getClass() != o.getClass()) { | ||
259 | + return false; | ||
260 | + } | ||
261 | + Csnp that = (Csnp) o; | ||
262 | + return Objects.equal(pduLength, that.pduLength) && | ||
263 | + Objects.equal(sourceId, that.sourceId) && | ||
264 | + Objects.equal(startLspId, that.startLspId) && | ||
265 | + Objects.equal(endLspId, that.endLspId); | ||
266 | + } | ||
267 | + | ||
268 | + @Override | ||
269 | + public int hashCode() { | ||
270 | + return Objects.hashCode(pduLength, sourceId, startLspId, endLspId); | ||
271 | + } | ||
272 | +} | ||
... | \ 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.pdu; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import org.onlab.packet.Ip4Address; | ||
21 | +import org.onlab.packet.MacAddress; | ||
22 | +import org.onosproject.isis.controller.IsisInterfaceState; | ||
23 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.IsisNeighborTlv; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * Representation of ISIS hello PDU. | ||
35 | + */ | ||
36 | +public abstract class HelloPdu extends IsisHeader { | ||
37 | + | ||
38 | + protected List<IsisTlv> variableLengths = new ArrayList<>(); | ||
39 | + private byte circuitType; | ||
40 | + private String sourceId; | ||
41 | + private int holdingTime; | ||
42 | + private int pduLength; | ||
43 | + | ||
44 | + public void addTlv(IsisTlv isisTlv) { | ||
45 | + variableLengths.add(isisTlv); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Returns the variable lengths. | ||
50 | + * | ||
51 | + * @return variable lengths | ||
52 | + */ | ||
53 | + public List<IsisTlv> tlvs() { | ||
54 | + return variableLengths; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the list of area addresses. | ||
59 | + * | ||
60 | + * @return areaAddresses area addresses | ||
61 | + */ | ||
62 | + public List<String> areaAddress() { | ||
63 | + List<String> areaAddresses = null; | ||
64 | + for (IsisTlv tlv : tlvs()) { | ||
65 | + if (tlv instanceof AreaAddressTlv) { | ||
66 | + areaAddresses = ((AreaAddressTlv) tlv).areaAddress(); | ||
67 | + } | ||
68 | + } | ||
69 | + return areaAddresses; | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Returns the list of interface IP addresses. | ||
74 | + * | ||
75 | + * @return interfaceIpAddresses list of interface IP addresses | ||
76 | + */ | ||
77 | + public List<Ip4Address> interfaceIpAddresses() { | ||
78 | + List<Ip4Address> interfaceIpAddresses = null; | ||
79 | + for (IsisTlv tlv : tlvs()) { | ||
80 | + if (tlv instanceof IpInterfaceAddressTlv) { | ||
81 | + interfaceIpAddresses = ((IpInterfaceAddressTlv) tlv).interfaceAddress(); | ||
82 | + } | ||
83 | + } | ||
84 | + return interfaceIpAddresses; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Returns the list of neighbor list. | ||
89 | + * | ||
90 | + * @return macAddresses list of neighbor MAC address | ||
91 | + */ | ||
92 | + public List<MacAddress> neighborList() { | ||
93 | + List<MacAddress> macAddresses = null; | ||
94 | + for (IsisTlv tlv : tlvs()) { | ||
95 | + if (tlv instanceof IsisNeighborTlv) { | ||
96 | + macAddresses = ((IsisNeighborTlv) tlv).neighbor(); | ||
97 | + } | ||
98 | + } | ||
99 | + return macAddresses; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Returns the adjacency state. | ||
104 | + * | ||
105 | + * @return interfaceState adjacency state | ||
106 | + */ | ||
107 | + public IsisInterfaceState adjacencyState() { | ||
108 | + IsisInterfaceState interfaceState = null; | ||
109 | + for (IsisTlv tlv : tlvs()) { | ||
110 | + if (tlv instanceof AdjacencyStateTlv) { | ||
111 | + interfaceState = IsisInterfaceState.get(((AdjacencyStateTlv) tlv).adjacencyType()); | ||
112 | + break; | ||
113 | + } | ||
114 | + } | ||
115 | + return interfaceState; | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Returns the source ID. | ||
120 | + * | ||
121 | + * @return sourceId source ID | ||
122 | + */ | ||
123 | + public String sourceId() { | ||
124 | + return sourceId; | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Sets source ID. | ||
129 | + * | ||
130 | + * @param sourceId source ID | ||
131 | + */ | ||
132 | + public void setSourceId(String sourceId) { | ||
133 | + this.sourceId = sourceId; | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * Returns the PDU length. | ||
138 | + * | ||
139 | + * @return pduLength PDU length | ||
140 | + */ | ||
141 | + public int pduLength() { | ||
142 | + return pduLength; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Sets the PDU length. | ||
147 | + * | ||
148 | + * @param pduLength PDU lenght | ||
149 | + */ | ||
150 | + public void setPduLength(int pduLength) { | ||
151 | + this.pduLength = pduLength; | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Returns the holding time. | ||
156 | + * | ||
157 | + * @return holdingTime holding time | ||
158 | + */ | ||
159 | + public int holdingTime() { | ||
160 | + return holdingTime; | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * Sets the holding time. | ||
165 | + * | ||
166 | + * @param holdingTime holding time | ||
167 | + */ | ||
168 | + public void setHoldingTime(int holdingTime) { | ||
169 | + this.holdingTime = holdingTime; | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Returns the circuit type. | ||
174 | + * | ||
175 | + * @return circuitType circuit type | ||
176 | + */ | ||
177 | + public byte circuitType() { | ||
178 | + return circuitType; | ||
179 | + } | ||
180 | + | ||
181 | + /** | ||
182 | + * Sets the circuit type. | ||
183 | + * | ||
184 | + * @param circuitType circuit type | ||
185 | + */ | ||
186 | + public void setCircuitType(byte circuitType) { | ||
187 | + this.circuitType = circuitType; | ||
188 | + } | ||
189 | + | ||
190 | + @Override | ||
191 | + public String toString() { | ||
192 | + return MoreObjects.toStringHelper(getClass()) | ||
193 | + .omitNullValues() | ||
194 | + .add("circuitType", circuitType) | ||
195 | + .add("sourceId", sourceId) | ||
196 | + .add("holdingTime", holdingTime) | ||
197 | + .add("pduLength", pduLength) | ||
198 | + .toString(); | ||
199 | + } | ||
200 | + | ||
201 | + @Override | ||
202 | + public boolean equals(Object o) { | ||
203 | + if (this == o) { | ||
204 | + return true; | ||
205 | + } | ||
206 | + if (o == null || getClass() != o.getClass()) { | ||
207 | + return false; | ||
208 | + } | ||
209 | + HelloPdu that = (HelloPdu) o; | ||
210 | + return Objects.equal(circuitType, that.circuitType) && | ||
211 | + Objects.equal(sourceId, that.sourceId) && | ||
212 | + Objects.equal(holdingTime, that.holdingTime) && | ||
213 | + Objects.equal(pduLength, that.pduLength); | ||
214 | + } | ||
215 | + | ||
216 | + @Override | ||
217 | + public int hashCode() { | ||
218 | + return Objects.hashCode(circuitType, sourceId, holdingTime, pduLength); | ||
219 | + } | ||
220 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/L1L2HelloPdu.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.pdu; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import com.google.common.primitives.Bytes; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
23 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.TlvFinder; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes; | ||
28 | +import org.onosproject.isis.io.util.IsisUtil; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * Representation of L1L2 hello PDU. | ||
35 | + */ | ||
36 | +public class L1L2HelloPdu extends HelloPdu { | ||
37 | + | ||
38 | + /* | ||
39 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
40 | + | Intra-domain Routing Protocol Discriminator | | ||
41 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
42 | + | Length Indicator | | ||
43 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
44 | + | Version/Protocol ID Extension | | ||
45 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
46 | + | ID Length | | ||
47 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
48 | + | R | R | R | PDU Type | | ||
49 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
50 | + | Version | | ||
51 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
52 | + | Reserved | | ||
53 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
54 | + | Maximum area address | | ||
55 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
56 | + | Circuit Type | | ||
57 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
58 | + | Source ID | | ||
59 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
60 | + | Holding Time | | ||
61 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
62 | + | PDU Length | | ||
63 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
64 | + | PDU Length | | ||
65 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
66 | + | R | Priority | | ||
67 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
68 | + | LAN ID | | ||
69 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
70 | + | Variable Lengths Fields | | ||
71 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
72 | + | ||
73 | + Hello Message Format | ||
74 | + REFERENCE : ISO/IEC 10589 | ||
75 | + */ | ||
76 | + | ||
77 | + private byte priority; | ||
78 | + private String lanId; | ||
79 | + | ||
80 | + /** | ||
81 | + * Parametrized constructor. | ||
82 | + * | ||
83 | + * @param isisHeader ISIs header | ||
84 | + */ | ||
85 | + public L1L2HelloPdu(IsisHeader isisHeader) { | ||
86 | + populateHeader(isisHeader); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns the LAN ID. | ||
91 | + * | ||
92 | + * @return LAN ID | ||
93 | + */ | ||
94 | + | ||
95 | + public String lanId() { | ||
96 | + return lanId; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets the LAN ID. | ||
101 | + * | ||
102 | + * @param lanId LAN ID | ||
103 | + */ | ||
104 | + public void setLanId(String lanId) { | ||
105 | + this.lanId = lanId; | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Returns the priority. | ||
110 | + * | ||
111 | + * @return priority | ||
112 | + */ | ||
113 | + public byte priority() { | ||
114 | + return priority; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Sets priority. | ||
119 | + * | ||
120 | + * @param priority priority | ||
121 | + */ | ||
122 | + public void setPriority(byte priority) { | ||
123 | + this.priority = priority; | ||
124 | + } | ||
125 | + | ||
126 | + @Override | ||
127 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
128 | + this.setCircuitType(channelBuffer.readByte()); | ||
129 | + //sorce id | ||
130 | + byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES]; | ||
131 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES); | ||
132 | + this.setSourceId(IsisUtil.systemId(tempByteArray)); | ||
133 | + this.setHoldingTime(channelBuffer.readUnsignedShort()); | ||
134 | + this.setPduLength(channelBuffer.readUnsignedShort()); | ||
135 | + this.setPriority(channelBuffer.readByte()); | ||
136 | + //landid id + 1 value | ||
137 | + tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE]; | ||
138 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE); | ||
139 | + this.setLanId(IsisUtil.systemIdPlus(tempByteArray)); | ||
140 | + //tlv here | ||
141 | + while (channelBuffer.readableBytes() > 0) { | ||
142 | + TlvHeader tlvHeader = new TlvHeader(); | ||
143 | + tlvHeader.setTlvType(channelBuffer.readUnsignedByte()); | ||
144 | + tlvHeader.setTlvLength(channelBuffer.readUnsignedByte()); | ||
145 | + TlvType tlvType = TlvType.get(tlvHeader.tlvType()); | ||
146 | + if (tlvType != null) { | ||
147 | + IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | ||
148 | + this.variableLengths.add(tlv); | ||
149 | + } else { | ||
150 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
151 | + } | ||
152 | + } | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public byte[] asBytes() { | ||
157 | + byte[] helloMessage = null; | ||
158 | + byte[] helloHeader = l1l2IsisPduHeader(); | ||
159 | + byte[] helloBody = l1l2HelloPduBody(); | ||
160 | + helloMessage = Bytes.concat(helloHeader, helloBody); | ||
161 | + return helloMessage; | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Parse the ISIS L1L2 PDU header. | ||
166 | + * | ||
167 | + * @return ISIS L1L2 PDU header | ||
168 | + */ | ||
169 | + public byte[] l1l2IsisPduHeader() { | ||
170 | + List<Byte> headerLst = new ArrayList<>(); | ||
171 | + headerLst.add(this.irpDiscriminator()); | ||
172 | + headerLst.add((byte) IsisUtil.getPduHeaderLength(this.pduType())); | ||
173 | + headerLst.add(this.version()); | ||
174 | + headerLst.add(this.idLength()); | ||
175 | + headerLst.add((byte) this.pduType()); | ||
176 | + headerLst.add(this.version2()); | ||
177 | + headerLst.add(this.reserved()); | ||
178 | + headerLst.add(this.maximumAreaAddresses()); | ||
179 | + return Bytes.toArray(headerLst); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Parse the ISIS L1L2 PDU body. | ||
184 | + * | ||
185 | + * @return ISIS L1L2 PDU body | ||
186 | + */ | ||
187 | + public byte[] l1l2HelloPduBody() { | ||
188 | + List<Byte> bodyLst = new ArrayList<>(); | ||
189 | + | ||
190 | + bodyLst.add(this.circuitType()); | ||
191 | + bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId())); | ||
192 | + bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime()))); | ||
193 | + bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength()))); | ||
194 | + bodyLst.add(this.priority); | ||
195 | + bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.lanId())); | ||
196 | + for (IsisTlv isisTlv : variableLengths) { | ||
197 | + bodyLst.addAll(TlvsToBytes.tlvToBytes(isisTlv)); | ||
198 | + } | ||
199 | + return Bytes.toArray(bodyLst); | ||
200 | + } | ||
201 | + | ||
202 | + @Override | ||
203 | + public String toString() { | ||
204 | + return MoreObjects.toStringHelper(getClass()) | ||
205 | + .omitNullValues() | ||
206 | + .add("priority", priority) | ||
207 | + .add("lanId", lanId) | ||
208 | + .toString(); | ||
209 | + } | ||
210 | + | ||
211 | + @Override | ||
212 | + public boolean equals(Object o) { | ||
213 | + if (this == o) { | ||
214 | + return true; | ||
215 | + } | ||
216 | + if (o == null || getClass() != o.getClass()) { | ||
217 | + return false; | ||
218 | + } | ||
219 | + L1L2HelloPdu that = (L1L2HelloPdu) o; | ||
220 | + return Objects.equal(priority, that.priority) && | ||
221 | + Objects.equal(lanId, that.lanId); | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public int hashCode() { | ||
226 | + return Objects.hashCode(priority, lanId); | ||
227 | + } | ||
228 | +} | ||
... | \ 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.pdu; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
21 | +import com.google.common.primitives.Bytes; | ||
22 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
23 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.TlvFinder; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes; | ||
29 | +import org.onosproject.isis.io.util.IsisUtil; | ||
30 | + | ||
31 | +import java.util.ArrayList; | ||
32 | +import java.util.List; | ||
33 | + | ||
34 | +/** | ||
35 | + * Representation of an ISIS Link State packet. | ||
36 | + * Each Link State packet carries a collection of TLVs | ||
37 | + * Several TLVs may be included in a single packet. | ||
38 | + */ | ||
39 | +public class LsPdu extends IsisHeader { | ||
40 | + | ||
41 | + /* | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + | Intra-domain Routing Protocol Discriminator | | ||
44 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
45 | + | Length Indicator | | ||
46 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
47 | + | Version/Protocol ID Extension | | ||
48 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
49 | + | ID Length | | ||
50 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
51 | + | R | R | R | PDU Type | | ||
52 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
53 | + | Version | | ||
54 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
55 | + | Reserved | | ||
56 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
57 | + | Maximum area address | | ||
58 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
59 | + | PDU Length | | ||
60 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
61 | + | Remaining Lifetime | | ||
62 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
63 | + | LSP ID | | ||
64 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
65 | + | PDU Length | | ||
66 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
67 | + | Sequence Number | | ||
68 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
69 | + | Checksum | | ||
70 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
71 | + | P | ATT | LSPDBOL | IS Type | | ||
72 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
73 | + | Variable Lengths Fields | | ||
74 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
75 | + | ||
76 | + LS PDU Format | ||
77 | + REFERENCE : ISO/IEC 10589 | ||
78 | + */ | ||
79 | + private int pduLength; | ||
80 | + private int remainingLifeTime; | ||
81 | + private String lspId; | ||
82 | + private int sequenceNumber; | ||
83 | + private int checkSum; | ||
84 | + private boolean partitionRepair; | ||
85 | + private AttachedToOtherAreas attachedToOtherAreas; | ||
86 | + private boolean lspDbol; | ||
87 | + private byte typeBlock; | ||
88 | + private byte intermediateSystemType; | ||
89 | + private List<IsisTlv> variableLengths = new ArrayList<>(); | ||
90 | + | ||
91 | + /** | ||
92 | + * Creates an instance of Link State packet. | ||
93 | + * Parameterized constructor which populate | ||
94 | + * | ||
95 | + * @param isisHeader isis header details | ||
96 | + */ | ||
97 | + public LsPdu(IsisHeader isisHeader) { | ||
98 | + populateHeader(isisHeader); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Adds the isis tlv to the list for the link state PDU. | ||
103 | + * | ||
104 | + * @param isisTlv isis tlv | ||
105 | + */ | ||
106 | + public void addTlv(IsisTlv isisTlv) { | ||
107 | + variableLengths.add(isisTlv); | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Returns the remaining time of the link state pdu. | ||
112 | + * Number of seconds before LSP considered expired | ||
113 | + * | ||
114 | + * @return remainingTime remaining time | ||
115 | + */ | ||
116 | + public int remainingLifeTime() { | ||
117 | + return remainingLifeTime; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Sets the remaining time for the link state pdu. | ||
122 | + * | ||
123 | + * @param remainingLifeTime remaining time | ||
124 | + */ | ||
125 | + public void setRemainingLifeTime(int remainingLifeTime) { | ||
126 | + this.remainingLifeTime = remainingLifeTime; | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * Returns the link state database overload. | ||
131 | + * | ||
132 | + * @return lspdbol link state database overload | ||
133 | + */ | ||
134 | + public boolean lspDbol() { | ||
135 | + return lspDbol; | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Sets the link state database overload for this pdu. | ||
140 | + * | ||
141 | + * @param lspDbol link state database overload | ||
142 | + */ | ||
143 | + public void setLspDbol(boolean lspDbol) { | ||
144 | + this.lspDbol = lspDbol; | ||
145 | + } | ||
146 | + | ||
147 | + /** | ||
148 | + * Returns the type block. | ||
149 | + * | ||
150 | + * @return type block | ||
151 | + */ | ||
152 | + public byte typeBlock() { | ||
153 | + return typeBlock; | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Sets the type block. | ||
158 | + * | ||
159 | + * @param typeBlock type block | ||
160 | + */ | ||
161 | + public void setTypeBlock(byte typeBlock) { | ||
162 | + this.typeBlock = typeBlock; | ||
163 | + } | ||
164 | + | ||
165 | + /** | ||
166 | + * Returns the sequence number of LSP. | ||
167 | + * | ||
168 | + * @return sequenceNumber sequence number | ||
169 | + */ | ||
170 | + public int sequenceNumber() { | ||
171 | + return sequenceNumber; | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Sets the sequence nubmer for LSP. | ||
176 | + * | ||
177 | + * @param sequenceNumber sequence number | ||
178 | + */ | ||
179 | + public void setSequenceNumber(int sequenceNumber) { | ||
180 | + this.sequenceNumber = sequenceNumber; | ||
181 | + } | ||
182 | + | ||
183 | + /** | ||
184 | + * Returns the checksum of LSP from Source ID to end. | ||
185 | + * | ||
186 | + * @return checkSum check sum | ||
187 | + */ | ||
188 | + public int checkSum() { | ||
189 | + return checkSum; | ||
190 | + } | ||
191 | + | ||
192 | + /** | ||
193 | + * Sets the checksum for LSP from Source ID to end. | ||
194 | + * | ||
195 | + * @param checkSum check sum | ||
196 | + */ | ||
197 | + public void setCheckSum(int checkSum) { | ||
198 | + this.checkSum = checkSum; | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * Returns the partition repair value of the intermediate system. | ||
203 | + * | ||
204 | + * @return partitionRepair partition repair | ||
205 | + */ | ||
206 | + public boolean partitionRepair() { | ||
207 | + return partitionRepair; | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Sets partition repair value for the intermediate system. | ||
212 | + * | ||
213 | + * @param partitionRepair partition repair | ||
214 | + */ | ||
215 | + public void setPartitionRepair(boolean partitionRepair) { | ||
216 | + this.partitionRepair = partitionRepair; | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * Returns the value of intermediate system attached field. | ||
221 | + * return values based on type Default Metric, Delay Metric, Expense Metric, Error Metric | ||
222 | + * | ||
223 | + * @return attachedToOtherAreas attached to other areas | ||
224 | + */ | ||
225 | + public AttachedToOtherAreas attachedToOtherAreas() { | ||
226 | + return attachedToOtherAreas; | ||
227 | + } | ||
228 | + | ||
229 | + /** | ||
230 | + * Sets the value for intermediate system attached field. | ||
231 | + * it will pass values based on type Default Metric, Delay Metric, Expense Metric, Error Metric | ||
232 | + * | ||
233 | + * @param attachedToOtherAreas attached to other areas | ||
234 | + */ | ||
235 | + public void setAttachedToOtherAreas(AttachedToOtherAreas attachedToOtherAreas) { | ||
236 | + this.attachedToOtherAreas = attachedToOtherAreas; | ||
237 | + } | ||
238 | + | ||
239 | + /** | ||
240 | + * Returns the intermediate system type. | ||
241 | + * type will be level 1 or level 2 | ||
242 | + * | ||
243 | + * @return intermediateSystemType intermediate system type | ||
244 | + */ | ||
245 | + public byte intermediateSystemType() { | ||
246 | + return intermediateSystemType; | ||
247 | + } | ||
248 | + | ||
249 | + /** | ||
250 | + * Sets the value for intermediate system. | ||
251 | + * type will be level 1 or level 2 | ||
252 | + * | ||
253 | + * @param intermediateSystemType intermediate system type | ||
254 | + */ | ||
255 | + public void setIntermediateSystemType(byte intermediateSystemType) { | ||
256 | + this.intermediateSystemType = intermediateSystemType; | ||
257 | + } | ||
258 | + | ||
259 | + /** | ||
260 | + * Returns the link state ID of link state packet. | ||
261 | + * System ID of the source of link state PDU | ||
262 | + * | ||
263 | + * @return lspId link state packet ID | ||
264 | + */ | ||
265 | + public String lspId() { | ||
266 | + return lspId; | ||
267 | + } | ||
268 | + | ||
269 | + /** | ||
270 | + * Sets the link state ID for link state packet. | ||
271 | + * System ID of the source of link state PDU | ||
272 | + * | ||
273 | + * @param lspId link state packet ID | ||
274 | + */ | ||
275 | + public void setLspId(String lspId) { | ||
276 | + this.lspId = lspId; | ||
277 | + } | ||
278 | + | ||
279 | + /** | ||
280 | + * Returns the packet data unit length of link state packet. | ||
281 | + * Entire length of this PDU, in octets | ||
282 | + * | ||
283 | + * @return pduLength packte date unit length | ||
284 | + */ | ||
285 | + public int pduLength() { | ||
286 | + return pduLength; | ||
287 | + } | ||
288 | + | ||
289 | + /** | ||
290 | + * Sets the packet data unit length for link state packet. | ||
291 | + * Entire Length of this PDU, in octets | ||
292 | + * | ||
293 | + * @param pduLength packte data length | ||
294 | + */ | ||
295 | + public void setPduLength(int pduLength) { | ||
296 | + this.pduLength = pduLength; | ||
297 | + } | ||
298 | + | ||
299 | + @Override | ||
300 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
301 | + | ||
302 | + this.setPduLength(channelBuffer.readUnsignedShort()); | ||
303 | + this.setRemainingLifeTime(channelBuffer.readUnsignedShort()); | ||
304 | + //lsp id + 2 value | ||
305 | + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE]; | ||
306 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE); | ||
307 | + this.setLspId(IsisUtil.systemIdPlus(tempByteArray)); | ||
308 | + //sequence number 4 | ||
309 | + this.setSequenceNumber(channelBuffer.readInt()); | ||
310 | + this.setCheckSum(channelBuffer.readUnsignedShort()); | ||
311 | + int typeTemp = channelBuffer.readUnsignedByte(); | ||
312 | + byte isTypeByte = (byte) typeTemp; | ||
313 | + String tempValue = String.format("%8s", Integer.toBinaryString(isTypeByte & 0xFF)).replace(' ', '0'); | ||
314 | + int pBit = Integer.parseInt(new Character(tempValue.charAt(0)).toString()); | ||
315 | + if (pBit == 1) { | ||
316 | + this.setPartitionRepair(true); | ||
317 | + } else { | ||
318 | + this.setPartitionRepair(false); | ||
319 | + } | ||
320 | + int attValue = Integer.parseInt(tempValue.substring(1, 5), 2); | ||
321 | + switch (AttachedToOtherAreas.get(attValue)) { | ||
322 | + case DEFAULTMETRIC: | ||
323 | + this.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC); | ||
324 | + break; | ||
325 | + case DELAYMETRIC: | ||
326 | + this.setAttachedToOtherAreas(AttachedToOtherAreas.DELAYMETRIC); | ||
327 | + break; | ||
328 | + case EXPENSEMETRIC: | ||
329 | + this.setAttachedToOtherAreas(AttachedToOtherAreas.EXPENSEMETRIC); | ||
330 | + break; | ||
331 | + case ERRORMETRIC: | ||
332 | + this.setAttachedToOtherAreas(AttachedToOtherAreas.ERRORMETRIC); | ||
333 | + break; | ||
334 | + case NONE: | ||
335 | + this.setAttachedToOtherAreas(AttachedToOtherAreas.NONE); | ||
336 | + break; | ||
337 | + default: | ||
338 | + break; | ||
339 | + } | ||
340 | + int lspdbol = Integer.parseInt(new Character(tempValue.charAt(5)).toString()); | ||
341 | + if (lspdbol == 1) { | ||
342 | + this.setLspDbol(true); | ||
343 | + } else { | ||
344 | + this.setLspDbol(false); | ||
345 | + } | ||
346 | + int isType = Integer.parseInt(tempValue.substring(6, 8), 2); | ||
347 | + byte isTypeByteValue = (byte) isType; | ||
348 | + this.setIntermediateSystemType(isTypeByteValue); | ||
349 | + //tlv here | ||
350 | + while (channelBuffer.readableBytes() > 0) { | ||
351 | + TlvHeader tlvHeader = new TlvHeader(); | ||
352 | + tlvHeader.setTlvType(channelBuffer.readUnsignedByte()); | ||
353 | + tlvHeader.setTlvLength(channelBuffer.readUnsignedByte()); | ||
354 | + TlvType tlvValue = TlvType.get(tlvHeader.tlvType()); | ||
355 | + if (tlvValue != null) { | ||
356 | + IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | ||
357 | + this.variableLengths.add(tlv); | ||
358 | + } else { | ||
359 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
360 | + } | ||
361 | + } | ||
362 | + } | ||
363 | + | ||
364 | + @Override | ||
365 | + public byte[] asBytes() { | ||
366 | + byte[] lspMessage = null; | ||
367 | + byte[] helloHeader = l1l2IsisPduHeader(); | ||
368 | + byte[] lspBody = l1l2LsPduBody(); | ||
369 | + lspMessage = Bytes.concat(helloHeader, lspBody); | ||
370 | + return lspMessage; | ||
371 | + } | ||
372 | + | ||
373 | + /** | ||
374 | + * Builds ISIS PDU header from ISIS message. | ||
375 | + * | ||
376 | + * @return headerList ISIS PDU header | ||
377 | + */ | ||
378 | + public byte[] l1l2IsisPduHeader() { | ||
379 | + List<Byte> headerList = new ArrayList<>(); | ||
380 | + headerList.add(this.irpDiscriminator()); | ||
381 | + headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType())); | ||
382 | + headerList.add(this.version()); | ||
383 | + headerList.add(this.idLength()); | ||
384 | + headerList.add((byte) this.pduType()); | ||
385 | + headerList.add(this.version2()); | ||
386 | + headerList.add(this.reserved()); | ||
387 | + headerList.add(this.maximumAreaAddresses()); | ||
388 | + return Bytes.toArray(headerList); | ||
389 | + } | ||
390 | + | ||
391 | + /** | ||
392 | + * Builds link state PDU body from ISIS message. | ||
393 | + * | ||
394 | + * @return bodyList link state PDU body | ||
395 | + */ | ||
396 | + public byte[] l1l2LsPduBody() { | ||
397 | + List<Byte> bodyList = new ArrayList<>(); | ||
398 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength()))); | ||
399 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.remainingLifeTime()))); | ||
400 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.lspId())); | ||
401 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.sequenceNumber()))); | ||
402 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.checkSum()))); | ||
403 | + String temString = ""; | ||
404 | + if (this.partitionRepair()) { | ||
405 | + temString = "1" + temString; | ||
406 | + } else { | ||
407 | + temString = "0" + temString; | ||
408 | + } | ||
409 | + switch (this.attachedToOtherAreas()) { | ||
410 | + case ERRORMETRIC: | ||
411 | + temString = temString + "1000"; | ||
412 | + break; | ||
413 | + case EXPENSEMETRIC: | ||
414 | + temString = temString + "0100"; | ||
415 | + break; | ||
416 | + case DELAYMETRIC: | ||
417 | + temString = temString + "0010"; | ||
418 | + break; | ||
419 | + case DEFAULTMETRIC: | ||
420 | + temString = temString + "0001"; | ||
421 | + break; | ||
422 | + case NONE: | ||
423 | + temString = temString + "0000"; | ||
424 | + break; | ||
425 | + default: | ||
426 | + break; | ||
427 | + } | ||
428 | + if (this.lspDbol()) { | ||
429 | + temString = temString + "1"; | ||
430 | + } else { | ||
431 | + temString = temString + "0"; | ||
432 | + } | ||
433 | + String isType = Integer.toBinaryString(this.intermediateSystemType()); | ||
434 | + if (isType.length() % 2 != 0) { | ||
435 | + isType = "0" + isType; | ||
436 | + } | ||
437 | + temString = temString + isType; | ||
438 | + bodyList.add((byte) Integer.parseInt(temString, 2)); | ||
439 | + for (IsisTlv isisTlv : variableLengths) { | ||
440 | + bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv)); | ||
441 | + } | ||
442 | + return Bytes.toArray(bodyList); | ||
443 | + } | ||
444 | + | ||
445 | + @Override | ||
446 | + public String toString() { | ||
447 | + return MoreObjects.toStringHelper(getClass()) | ||
448 | + .omitNullValues() | ||
449 | + .add("pduLength", pduLength) | ||
450 | + .add("remainingLifeTime", remainingLifeTime) | ||
451 | + .add("lspId", lspId) | ||
452 | + .add("sequenceNumber", sequenceNumber) | ||
453 | + .add("checkSum", checkSum) | ||
454 | + .add("partitionRepair", partitionRepair) | ||
455 | + .add("lspDbol", lspDbol) | ||
456 | + .add("typeBlock", typeBlock) | ||
457 | + .add("intermediateSystemType", intermediateSystemType) | ||
458 | + .toString(); | ||
459 | + } | ||
460 | + | ||
461 | + @Override | ||
462 | + public boolean equals(Object o) { | ||
463 | + if (this == o) { | ||
464 | + return true; | ||
465 | + } | ||
466 | + if (o == null || getClass() != o.getClass()) { | ||
467 | + return false; | ||
468 | + } | ||
469 | + LsPdu that = (LsPdu) o; | ||
470 | + return Objects.equal(pduLength, that.pduLength) && | ||
471 | + Objects.equal(remainingLifeTime, that.remainingLifeTime) && | ||
472 | + Objects.equal(lspId, that.lspId) && | ||
473 | + Objects.equal(sequenceNumber, that.sequenceNumber) && | ||
474 | + Objects.equal(checkSum, that.checkSum) && | ||
475 | + Objects.equal(partitionRepair, that.partitionRepair) && | ||
476 | + Objects.equal(lspDbol, that.lspDbol) && | ||
477 | + Objects.equal(typeBlock, that.typeBlock) && | ||
478 | + Objects.equal(intermediateSystemType, that.intermediateSystemType); | ||
479 | + } | ||
480 | + | ||
481 | + @Override | ||
482 | + public int hashCode() { | ||
483 | + return Objects.hashCode(pduLength, remainingLifeTime, lspId, sequenceNumber, | ||
484 | + checkSum, partitionRepair, lspDbol, typeBlock, intermediateSystemType); | ||
485 | + } | ||
486 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/P2PHelloPdu.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.pdu; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import com.google.common.primitives.Bytes; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
23 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.TlvFinder; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes; | ||
28 | +import org.onosproject.isis.io.util.IsisUtil; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * Representation of P2P hello. | ||
35 | + */ | ||
36 | +public class P2PHelloPdu extends HelloPdu { | ||
37 | + /* | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Intra-domain Routing Protocol Discriminator | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | Length Indicator | | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + | Version/Protocol ID Extension | | ||
44 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
45 | + | ID Length | | ||
46 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
47 | + | R | R | R | PDU Type | | ||
48 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
49 | + | Version | | ||
50 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
51 | + | Reserved | | ||
52 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
53 | + | Maximum area address | | ||
54 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
55 | + | Circuit Type | | ||
56 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
57 | + | Source ID | | ||
58 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
59 | + | Holding Time | | ||
60 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
61 | + | PDU Length | | ||
62 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
63 | + | Local Circuit Id | | ||
64 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
65 | + | Variable Lengths Fields | | ||
66 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
67 | + | ||
68 | + P2P Hello Message Format | ||
69 | + REFERENCE : ISO/IEC 10589 | ||
70 | + */ | ||
71 | + private byte localCircuitId; | ||
72 | + | ||
73 | + /** | ||
74 | + * Sets the ISIS header. | ||
75 | + * | ||
76 | + * @param isisHeader isisHeader | ||
77 | + */ | ||
78 | + public P2PHelloPdu(IsisHeader isisHeader) { | ||
79 | + populateHeader(isisHeader); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * Returns the local circuit ID. | ||
84 | + * | ||
85 | + * @return Local circuit ID | ||
86 | + */ | ||
87 | + public byte localCircuitId() { | ||
88 | + return localCircuitId; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * Sets the local circuit ID. | ||
93 | + * | ||
94 | + * @param localCircuitId Local circuit ID | ||
95 | + */ | ||
96 | + public void setLocalCircuitId(byte localCircuitId) { | ||
97 | + this.localCircuitId = localCircuitId; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Sets the variable lengths. | ||
102 | + * | ||
103 | + * @param variableLengths variable lengths. | ||
104 | + */ | ||
105 | + public void setVariableLengths(List<IsisTlv> variableLengths) { | ||
106 | + this.variableLengths = variableLengths; | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + @Override | ||
111 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
112 | + this.setCircuitType(channelBuffer.readByte()); | ||
113 | + //source id | ||
114 | + byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES]; | ||
115 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES); | ||
116 | + this.setSourceId(IsisUtil.systemId(tempByteArray)); | ||
117 | + this.setHoldingTime(channelBuffer.readUnsignedShort()); | ||
118 | + this.setPduLength(channelBuffer.readUnsignedShort()); | ||
119 | + this.setLocalCircuitId((byte) channelBuffer.readUnsignedByte()); | ||
120 | + while (channelBuffer.readableBytes() > 0) { | ||
121 | + TlvHeader tlvHeader = new TlvHeader(); | ||
122 | + tlvHeader.setTlvType(channelBuffer.readUnsignedByte()); | ||
123 | + tlvHeader.setTlvLength(channelBuffer.readUnsignedByte()); | ||
124 | + TlvType tlvType = TlvType.get(tlvHeader.tlvType()); | ||
125 | + if (tlvType != null) { | ||
126 | + IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | ||
127 | + this.variableLengths.add(tlv); | ||
128 | + } else { | ||
129 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
130 | + } | ||
131 | + } | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public byte[] asBytes() { | ||
136 | + byte[] helloMessage = null; | ||
137 | + byte[] helloHeader = p2PHeader(); | ||
138 | + byte[] helloBody = p2P2HelloPduBody(); | ||
139 | + helloMessage = Bytes.concat(helloHeader, helloBody); | ||
140 | + return helloMessage; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Builds the point to point header. | ||
145 | + * | ||
146 | + * @return headerList point to point header | ||
147 | + */ | ||
148 | + public byte[] p2PHeader() { | ||
149 | + List<Byte> headerList = new ArrayList<>(); | ||
150 | + headerList.add(this.irpDiscriminator()); | ||
151 | + headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType())); | ||
152 | + headerList.add(this.version()); | ||
153 | + headerList.add(this.idLength()); | ||
154 | + headerList.add((byte) this.pduType()); | ||
155 | + headerList.add(this.version2()); | ||
156 | + headerList.add(this.reserved()); | ||
157 | + headerList.add(this.maximumAreaAddresses()); | ||
158 | + return Bytes.toArray(headerList); | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Builds the point to point hello PDU body. | ||
163 | + * | ||
164 | + * @return bodyList point to point hello PDU body | ||
165 | + */ | ||
166 | + public byte[] p2P2HelloPduBody() { | ||
167 | + List<Byte> bodyList = new ArrayList<>(); | ||
168 | + bodyList.add(this.circuitType()); | ||
169 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId())); | ||
170 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime()))); | ||
171 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength()))); | ||
172 | + bodyList.add((byte) this.localCircuitId()); | ||
173 | + for (IsisTlv isisTlv : variableLengths) { | ||
174 | + bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv)); | ||
175 | + } | ||
176 | + return Bytes.toArray(bodyList); | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public String toString() { | ||
181 | + return MoreObjects.toStringHelper(getClass()) | ||
182 | + .omitNullValues() | ||
183 | + .add("localCircuitId", localCircuitId) | ||
184 | + .toString(); | ||
185 | + } | ||
186 | + | ||
187 | + @Override | ||
188 | + public boolean equals(Object o) { | ||
189 | + if (this == o) { | ||
190 | + return true; | ||
191 | + } | ||
192 | + if (o == null || getClass() != o.getClass()) { | ||
193 | + return false; | ||
194 | + } | ||
195 | + P2PHelloPdu that = (P2PHelloPdu) o; | ||
196 | + return Objects.equal(localCircuitId, that.localCircuitId); | ||
197 | + } | ||
198 | + | ||
199 | + @Override | ||
200 | + public int hashCode() { | ||
201 | + return Objects.hashCode(localCircuitId); | ||
202 | + } | ||
203 | +} | ||
... | \ 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.pdu; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import com.google.common.primitives.Bytes; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
23 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
24 | +import org.onosproject.isis.io.isispacket.tlv.TlvFinder; | ||
25 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes; | ||
28 | +import org.onosproject.isis.io.util.IsisUtil; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * Representation of partial sequence number PDU. | ||
35 | + */ | ||
36 | +public class Psnp extends IsisHeader { | ||
37 | + /* | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Intradomain Routing Protocol Discriminator | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | Length Indicator | | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + | Version/Protocol ID Extension | | ||
44 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
45 | + | ID Length | | ||
46 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
47 | + | R | R | R | PDU Type | | ||
48 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
49 | + | Version | | ||
50 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
51 | + | Reserved | | ||
52 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
53 | + | Maximum area address | | ||
54 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
55 | + | PDU Length | | ||
56 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
57 | + | Source ID | | ||
58 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
59 | + | Start LSP ID | | ||
60 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
61 | + | End LSP ID | | ||
62 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
63 | + | Variable Lengths Fields | | ||
64 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
65 | + | ||
66 | + Hello Message Format | ||
67 | + REFERENCE : ISO/IEC 10589 | ||
68 | + */ | ||
69 | + private int pduLength; | ||
70 | + private String sourceId; | ||
71 | + private List<IsisTlv> variableLengths = new ArrayList<>(); | ||
72 | + | ||
73 | + /** | ||
74 | + * Creates the instance for this class. | ||
75 | + * | ||
76 | + * @param isisHeader ISIS header | ||
77 | + */ | ||
78 | + public Psnp(IsisHeader isisHeader) { | ||
79 | + populateHeader(isisHeader); | ||
80 | + } | ||
81 | + | ||
82 | + public void addTlv(IsisTlv isisTlv) { | ||
83 | + variableLengths.add(isisTlv); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Returns the source ID of csnp. | ||
88 | + * | ||
89 | + * @return sourceId source ID | ||
90 | + */ | ||
91 | + public String sourceId() { | ||
92 | + return sourceId; | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * Sets the source ID for csnp. | ||
97 | + * | ||
98 | + * @param sourceId source ID | ||
99 | + */ | ||
100 | + public void setSourceId(String sourceId) { | ||
101 | + this.sourceId = sourceId; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Returns the packet data unit length of link state packet. | ||
106 | + * Entire length of this PDU, in octets | ||
107 | + * | ||
108 | + * @return pduLength packte date unit length | ||
109 | + */ | ||
110 | + public int pduLength() { | ||
111 | + return pduLength; | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * Sets the packet data unit length for link state packet. | ||
116 | + * Entire Length of this PDU, in octets | ||
117 | + * | ||
118 | + * @param pduLength packte data length | ||
119 | + */ | ||
120 | + public void setPduLength(int pduLength) { | ||
121 | + this.pduLength = pduLength; | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
126 | + this.setPduLength(channelBuffer.readUnsignedShort()); | ||
127 | + //source id + 2 value | ||
128 | + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE]; | ||
129 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE); | ||
130 | + this.setSourceId(IsisUtil.systemIdPlus(tempByteArray)); | ||
131 | + //tlv here | ||
132 | + while (channelBuffer.readableBytes() > 0) { | ||
133 | + TlvHeader tlvHeader = new TlvHeader(); | ||
134 | + tlvHeader.setTlvType(channelBuffer.readUnsignedByte()); | ||
135 | + tlvHeader.setTlvLength(channelBuffer.readUnsignedByte()); | ||
136 | + TlvType tlvValue = TlvType.get(tlvHeader.tlvType()); | ||
137 | + if (tlvValue != null) { | ||
138 | + IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | ||
139 | + this.variableLengths.add(tlv); | ||
140 | + } else { | ||
141 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
142 | + } | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + | ||
147 | + @Override | ||
148 | + public byte[] asBytes() { | ||
149 | + byte[] psnpMessage = null; | ||
150 | + byte[] isisPduHeader = isisPduHeader(); | ||
151 | + byte[] psnpBody = partialSequenceNumberPduBody(); | ||
152 | + psnpMessage = Bytes.concat(isisPduHeader, psnpBody); | ||
153 | + return psnpMessage; | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Builds the ISIS PDU header. | ||
158 | + * | ||
159 | + * @return headerList ISIS PDU header | ||
160 | + */ | ||
161 | + public byte[] isisPduHeader() { | ||
162 | + List<Byte> headerList = new ArrayList<>(); | ||
163 | + headerList.add(this.irpDiscriminator()); | ||
164 | + headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType())); | ||
165 | + headerList.add(this.version()); | ||
166 | + headerList.add(this.idLength()); | ||
167 | + headerList.add((byte) this.pduType()); | ||
168 | + headerList.add(this.version2()); | ||
169 | + headerList.add(this.reserved()); | ||
170 | + headerList.add(this.maximumAreaAddresses()); | ||
171 | + return Bytes.toArray(headerList); | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Builds the partial sequence number PDU body. | ||
176 | + * | ||
177 | + * @return bodyList partial sequence number PDU body | ||
178 | + */ | ||
179 | + public byte[] partialSequenceNumberPduBody() { | ||
180 | + List<Byte> bodyList = new ArrayList<>(); | ||
181 | + bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength()))); | ||
182 | + bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId())); | ||
183 | + for (IsisTlv isisTlv : variableLengths) { | ||
184 | + bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv)); | ||
185 | + } | ||
186 | + return Bytes.toArray(bodyList); | ||
187 | + } | ||
188 | + | ||
189 | + @Override | ||
190 | + public String toString() { | ||
191 | + return MoreObjects.toStringHelper(getClass()) | ||
192 | + .omitNullValues() | ||
193 | + .add("pduLength", pduLength) | ||
194 | + .add("sourceId", sourceId) | ||
195 | + .toString(); | ||
196 | + } | ||
197 | + | ||
198 | + @Override | ||
199 | + public boolean equals(Object o) { | ||
200 | + if (this == o) { | ||
201 | + return true; | ||
202 | + } | ||
203 | + if (o == null || getClass() != o.getClass()) { | ||
204 | + return false; | ||
205 | + } | ||
206 | + Psnp that = (Psnp) o; | ||
207 | + return Objects.equal(pduLength, that.pduLength); | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public int hashCode() { | ||
212 | + return Objects.hashCode(sourceId, pduLength); | ||
213 | + } | ||
214 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/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.pdu; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -36,7 +36,7 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { | ... | @@ -36,7 +36,7 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { |
36 | /** | 36 | /** |
37 | * Creates an instance of adjacency state TLV.. | 37 | * Creates an instance of adjacency state TLV.. |
38 | * | 38 | * |
39 | - * @param tlvHeader tlvHeader | 39 | + * @param tlvHeader TLV header |
40 | */ | 40 | */ |
41 | public AdjacencyStateTlv(TlvHeader tlvHeader) { | 41 | public AdjacencyStateTlv(TlvHeader tlvHeader) { |
42 | this.setTlvType(tlvHeader.tlvType()); | 42 | this.setTlvType(tlvHeader.tlvType()); |
... | @@ -118,8 +118,8 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { | ... | @@ -118,8 +118,8 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { |
118 | @Override | 118 | @Override |
119 | public void readFrom(ChannelBuffer channelBuffer) { | 119 | public void readFrom(ChannelBuffer channelBuffer) { |
120 | this.setAdjacencyType(channelBuffer.readByte()); | 120 | this.setAdjacencyType(channelBuffer.readByte()); |
121 | + this.setLocalCircuitId(channelBuffer.readInt()); | ||
121 | if (channelBuffer.readableBytes() > 0) { | 122 | if (channelBuffer.readableBytes() > 0) { |
122 | - this.setLocalCircuitId(channelBuffer.readInt()); | ||
123 | byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES]; | 123 | byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES]; |
124 | channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES); | 124 | channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES); |
125 | this.setNeighborSystemId(IsisUtil.systemId(tempByteArray)); | 125 | this.setNeighborSystemId(IsisUtil.systemId(tempByteArray)); |
... | @@ -146,8 +146,10 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { | ... | @@ -146,8 +146,10 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv { |
146 | List<Byte> bytes = new ArrayList<>(); | 146 | List<Byte> bytes = new ArrayList<>(); |
147 | bytes.add(this.adjacencyType); | 147 | bytes.add(this.adjacencyType); |
148 | bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId))); | 148 | bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId))); |
149 | + if (this.neighborSystemId != null) { | ||
149 | bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId)); | 150 | bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId)); |
150 | bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId))); | 151 | bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId))); |
152 | + } | ||
151 | return Bytes.toArray(bytes); | 153 | return Bytes.toArray(bytes); |
152 | } | 154 | } |
153 | 155 | ... | ... |
... | @@ -33,7 +33,7 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv { | ... | @@ -33,7 +33,7 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv { |
33 | /** | 33 | /** |
34 | * Creates an instance of area address TLV. | 34 | * Creates an instance of area address TLV. |
35 | * | 35 | * |
36 | - * @param tlvHeader tlvHeader | 36 | + * @param tlvHeader TLV header |
37 | */ | 37 | */ |
38 | public AreaAddressTlv(TlvHeader tlvHeader) { | 38 | public AreaAddressTlv(TlvHeader tlvHeader) { |
39 | this.setTlvType(tlvHeader.tlvType()); | 39 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -28,7 +28,7 @@ public class HostNameTlv extends TlvHeader { | ... | @@ -28,7 +28,7 @@ public class HostNameTlv extends TlvHeader { |
28 | /** | 28 | /** |
29 | * Creates an instance of host name TLV. | 29 | * Creates an instance of host name TLV. |
30 | * | 30 | * |
31 | - * @param tlvHeader tlvHeader. | 31 | + * @param tlvHeader TLV header |
32 | */ | 32 | */ |
33 | public HostNameTlv(TlvHeader tlvHeader) { | 33 | public HostNameTlv(TlvHeader tlvHeader) { |
34 | this.setTlvType(tlvHeader.tlvType()); | 34 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -29,7 +29,7 @@ public class IdrpInformationTlv extends TlvHeader implements IsisTlv { | ... | @@ -29,7 +29,7 @@ public class IdrpInformationTlv extends TlvHeader implements IsisTlv { |
29 | /** | 29 | /** |
30 | * Creates an instance of IDRP information TLV. | 30 | * Creates an instance of IDRP information TLV. |
31 | * | 31 | * |
32 | - * @param tlvHeader tlvHeader | 32 | + * @param tlvHeader TLV header |
33 | */ | 33 | */ |
34 | public IdrpInformationTlv(TlvHeader tlvHeader) { | 34 | public IdrpInformationTlv(TlvHeader tlvHeader) { |
35 | this.setTlvType(tlvHeader.tlvType()); | 35 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -21,6 +21,7 @@ import com.google.common.primitives.Bytes; | ... | @@ -21,6 +21,7 @@ import com.google.common.primitives.Bytes; |
21 | import org.jboss.netty.buffer.ChannelBuffer; | 21 | import org.jboss.netty.buffer.ChannelBuffer; |
22 | import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder; | 22 | import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder; |
23 | import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes; | 23 | import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes; |
24 | +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvType; | ||
24 | import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv; | 25 | import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv; |
25 | import org.onosproject.isis.io.util.IsisUtil; | 26 | import org.onosproject.isis.io.util.IsisUtil; |
26 | 27 | ||
... | @@ -32,15 +33,18 @@ import java.util.List; | ... | @@ -32,15 +33,18 @@ import java.util.List; |
32 | */ | 33 | */ |
33 | public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | 34 | public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
34 | 35 | ||
35 | - private String sysIdAndPseudoNumber; | 36 | + private boolean down; |
36 | - private int defaultMetric; | 37 | + private boolean subTlvPresence; |
38 | + private int prefixLength; | ||
39 | + private int metric; | ||
37 | private byte subTlvLength; | 40 | private byte subTlvLength; |
41 | + private String prefix; | ||
38 | private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>(); | 42 | private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>(); |
39 | 43 | ||
40 | /** | 44 | /** |
41 | * Creates an instance of IP external reachability TLV. | 45 | * Creates an instance of IP external reachability TLV. |
42 | * | 46 | * |
43 | - * @param tlvHeader tlvHeader | 47 | + * @param tlvHeader TLV header |
44 | */ | 48 | */ |
45 | public IpExtendedReachabilityTlv(TlvHeader tlvHeader) { | 49 | public IpExtendedReachabilityTlv(TlvHeader tlvHeader) { |
46 | this.setTlvType(tlvHeader.tlvType()); | 50 | this.setTlvType(tlvHeader.tlvType()); |
... | @@ -48,21 +52,75 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -48,21 +52,75 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
48 | } | 52 | } |
49 | 53 | ||
50 | /** | 54 | /** |
51 | - * Returns the system ID and pseudo number of IP external reachability TLV. | 55 | + * Returns the prefix of IP external reachability TLV. |
52 | * | 56 | * |
53 | - * @return sysIdAndPseudoNumber system ID and pseudo number | 57 | + * @return prefix |
54 | */ | 58 | */ |
55 | - public String sysIdAndPseudoNumber() { | 59 | + public String prefix() { |
56 | - return sysIdAndPseudoNumber; | 60 | + return prefix; |
57 | } | 61 | } |
58 | 62 | ||
59 | /** | 63 | /** |
60 | - * Sets the system ID and pseudo number for IP external reachability TLV. | 64 | + * Sets the prefix of IP external reachability TLV. |
61 | * | 65 | * |
62 | - * @param sysIdAndPseudoNumber system ID and pseudo number | 66 | + * @param prefix prefix |
63 | */ | 67 | */ |
64 | - public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) { | 68 | + public void setPrefix(String prefix) { |
65 | - this.sysIdAndPseudoNumber = sysIdAndPseudoNumber; | 69 | + this.prefix = prefix; |
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Returns if down true else false of IP external reachability TLV. | ||
74 | + * | ||
75 | + * @return if down true else false | ||
76 | + */ | ||
77 | + public boolean isDown() { | ||
78 | + return down; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Sets if down true else false of IP external reachability TLV. | ||
83 | + * | ||
84 | + * @param upOrDown if down true else false | ||
85 | + */ | ||
86 | + public void setDown(boolean upOrDown) { | ||
87 | + this.down = upOrDown; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Returns true if sub TLV present else false of IP external reachability TLV. | ||
92 | + * | ||
93 | + * @return true if present else false | ||
94 | + */ | ||
95 | + public boolean isSubTlvPresence() { | ||
96 | + return subTlvPresence; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets true if sub TLV present else false of IP external reachability TLV. | ||
101 | + * | ||
102 | + * @param subTlvPresence true if present else false | ||
103 | + */ | ||
104 | + public void setSubTlvPresence(boolean subTlvPresence) { | ||
105 | + this.subTlvPresence = subTlvPresence; | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Sets the prefix length of IP external reachability TLV. | ||
110 | + * | ||
111 | + * @return prefix length | ||
112 | + */ | ||
113 | + public int prefixLength() { | ||
114 | + return prefixLength; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Returns the prefix length of IP external reachability TLV. | ||
119 | + * | ||
120 | + * @param prefixLength the prefix length of IP external reachability TLV | ||
121 | + */ | ||
122 | + public void setPrefixLength(int prefixLength) { | ||
123 | + this.prefixLength = prefixLength; | ||
66 | } | 124 | } |
67 | 125 | ||
68 | /** | 126 | /** |
... | @@ -93,39 +151,70 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -93,39 +151,70 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
93 | } | 151 | } |
94 | 152 | ||
95 | /** | 153 | /** |
96 | - * Returns default metric of IP external reachability TLV. | 154 | + * Returns metric of IP external reachability TLV. |
97 | * | 155 | * |
98 | - * @return default metric | 156 | + * @return metric |
99 | */ | 157 | */ |
100 | - public int defaultMetric() { | 158 | + public int metric() { |
101 | - return defaultMetric; | 159 | + return metric; |
102 | } | 160 | } |
103 | 161 | ||
104 | /** | 162 | /** |
105 | * Sets default metric for IP external reachability TLV. | 163 | * Sets default metric for IP external reachability TLV. |
106 | * | 164 | * |
107 | - * @param defaultMetric default metric | 165 | + * @param metric default metric |
108 | */ | 166 | */ |
109 | - public void setDefaultMetric(int defaultMetric) { | 167 | + public void setMetric(int metric) { |
110 | - this.defaultMetric = defaultMetric; | 168 | + this.metric = metric; |
111 | } | 169 | } |
112 | 170 | ||
113 | @Override | 171 | @Override |
114 | public void readFrom(ChannelBuffer channelBuffer) { | 172 | public void readFrom(ChannelBuffer channelBuffer) { |
115 | - byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE]; | 173 | + this.setMetric(channelBuffer.readInt()); |
116 | - channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE); | 174 | + int controlInfo = channelBuffer.readByte(); |
117 | - this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray)); | 175 | + byte[] tempByteArray = null; |
118 | - this.setDefaultMetric(channelBuffer.readUnsignedMedium()); | 176 | + |
119 | - this.setSubTlvLength((byte) channelBuffer.readByte()); | 177 | + String string = IsisUtil.toEightBitBinary(Integer.toBinaryString(controlInfo)); |
120 | - while (channelBuffer.readableBytes() > 0) { | 178 | + if (string.charAt(0) == '0') { |
121 | - TlvHeader tlvHeader = new TlvHeader(); | 179 | + this.setDown(false); |
122 | - tlvHeader.setTlvType(channelBuffer.readByte()); | 180 | + } |
123 | - tlvHeader.setTlvLength(channelBuffer.readByte()); | 181 | + if (string.charAt(1) == '1') { |
124 | - this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader, | 182 | + this.setSubTlvPresence(true); |
125 | - channelBuffer.readBytes(tlvHeader.tlvLength()))); | 183 | + } |
184 | + this.setPrefixLength(Integer.parseInt(string.substring(2, string.length()), 2)); | ||
185 | + if (this.prefixLength >= 0 && this.prefixLength <= 8) { | ||
186 | + channelBuffer.readByte(); | ||
187 | + } else if (this.prefixLength >= 8 && this.prefixLength <= 16) { | ||
188 | + tempByteArray = new byte[IsisUtil.TWO_BYTES]; | ||
189 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.TWO_BYTES); | ||
190 | + this.setPrefix(IsisUtil.prefixConversion(tempByteArray)); | ||
191 | + } else if (this.prefixLength >= 17 && this.prefixLength <= 24) { | ||
192 | + tempByteArray = new byte[IsisUtil.THREE_BYTES]; | ||
193 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.THREE_BYTES); | ||
194 | + this.setPrefix(IsisUtil.prefixConversion(tempByteArray)); | ||
195 | + } else if (this.prefixLength >= 24 && this.prefixLength <= 32) { | ||
196 | + tempByteArray = new byte[IsisUtil.FOUR_BYTES]; | ||
197 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES); | ||
198 | + this.setPrefix(IsisUtil.prefixConversion(tempByteArray)); | ||
199 | + } | ||
200 | + if (this.isSubTlvPresence()) { | ||
201 | + this.setSubTlvLength(channelBuffer.readByte()); | ||
202 | + while (channelBuffer.readableBytes() > 0) { | ||
203 | + TlvHeader tlvHeader = new TlvHeader(); | ||
204 | + tlvHeader.setTlvType(channelBuffer.readByte()); | ||
205 | + tlvHeader.setTlvLength(channelBuffer.readByte()); | ||
206 | + SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType()); | ||
207 | + if (tlvValue != null) { | ||
208 | + this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader, | ||
209 | + channelBuffer.readBytes(tlvHeader.tlvLength()))); | ||
210 | + } else { | ||
211 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
212 | + } | ||
213 | + } | ||
126 | } | 214 | } |
127 | } | 215 | } |
128 | 216 | ||
217 | + | ||
129 | @Override | 218 | @Override |
130 | public byte[] asBytes() { | 219 | public byte[] asBytes() { |
131 | byte[] bytes = null; | 220 | byte[] bytes = null; |
... | @@ -145,11 +234,26 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -145,11 +234,26 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
145 | */ | 234 | */ |
146 | private byte[] tlvBodyAsBytes() { | 235 | private byte[] tlvBodyAsBytes() { |
147 | List<Byte> bodyLst = new ArrayList<>(); | 236 | List<Byte> bodyLst = new ArrayList<>(); |
148 | - bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber())); | 237 | + bodyLst.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.metric()))); |
149 | - bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric()))); | 238 | + String controlInfo = ""; |
150 | - bodyLst.add(this.subTlvLength()); | 239 | + if (this.isDown()) { |
151 | - for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) { | 240 | + controlInfo = controlInfo + "1"; |
152 | - bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv)); | 241 | + } else { |
242 | + controlInfo = controlInfo + "0"; | ||
243 | + } | ||
244 | + if (this.isSubTlvPresence()) { | ||
245 | + controlInfo = controlInfo + "1"; | ||
246 | + } else { | ||
247 | + controlInfo = controlInfo + "0"; | ||
248 | + } | ||
249 | + String prefixlength = IsisUtil.toEightBitBinary(Integer.toBinaryString(this.prefixLength())); | ||
250 | + controlInfo = controlInfo + prefixlength.substring(2, prefixlength.length()); | ||
251 | + bodyLst.add(Byte.parseByte(controlInfo, 2)); | ||
252 | + if (this.isSubTlvPresence()) { | ||
253 | + bodyLst.add(this.subTlvLength()); | ||
254 | + for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) { | ||
255 | + bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv)); | ||
256 | + } | ||
153 | } | 257 | } |
154 | return Bytes.toArray(bodyLst); | 258 | return Bytes.toArray(bodyLst); |
155 | } | 259 | } |
... | @@ -158,9 +262,12 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -158,9 +262,12 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
158 | public String toString() { | 262 | public String toString() { |
159 | return MoreObjects.toStringHelper(getClass()) | 263 | return MoreObjects.toStringHelper(getClass()) |
160 | .omitNullValues() | 264 | .omitNullValues() |
161 | - .add("sysIdAndPseudoNumber", sysIdAndPseudoNumber) | 265 | + .add("down", down) |
162 | - .add("defaultMetric", defaultMetric) | 266 | + .add("subTlvPresence", subTlvPresence) |
267 | + .add("prefixLength", prefixLength) | ||
268 | + .add("metric", metric) | ||
163 | .add("subTlvLength", subTlvLength) | 269 | .add("subTlvLength", subTlvLength) |
270 | + .add("prefix", prefix) | ||
164 | .add("trafEnginSubTlv", trafEnginSubTlv) | 271 | .add("trafEnginSubTlv", trafEnginSubTlv) |
165 | .toString(); | 272 | .toString(); |
166 | } | 273 | } | ... | ... |
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 |
... | @@ -34,7 +34,7 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv { | ... | @@ -34,7 +34,7 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv { |
34 | /** | 34 | /** |
35 | * Creates an instance of IP interface address TLV. | 35 | * Creates an instance of IP interface address TLV. |
36 | * | 36 | * |
37 | - * @param tlvHeader tlvHeader. | 37 | + * @param tlvHeader TLV header |
38 | */ | 38 | */ |
39 | public IpInterfaceAddressTlv(TlvHeader tlvHeader) { | 39 | public IpInterfaceAddressTlv(TlvHeader tlvHeader) { |
40 | 40 | ... | ... |
... | @@ -31,7 +31,7 @@ public class IpInternalReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -31,7 +31,7 @@ public class IpInternalReachabilityTlv extends TlvHeader implements IsisTlv { |
31 | /** | 31 | /** |
32 | * Creates an instance of IP internal reachability TLV. | 32 | * Creates an instance of IP internal reachability TLV. |
33 | * | 33 | * |
34 | - * @param tlvHeader tlvHeader. | 34 | + * @param tlvHeader TLV header |
35 | */ | 35 | */ |
36 | public IpInternalReachabilityTlv(TlvHeader tlvHeader) { | 36 | public IpInternalReachabilityTlv(TlvHeader tlvHeader) { |
37 | this.setTlvType(tlvHeader.tlvType()); | 37 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -33,7 +33,7 @@ public class IsReachabilityTlv extends TlvHeader { | ... | @@ -33,7 +33,7 @@ public class IsReachabilityTlv extends TlvHeader { |
33 | /** | 33 | /** |
34 | * Creates an instance of IS reachability TLV. | 34 | * Creates an instance of IS reachability TLV. |
35 | * | 35 | * |
36 | - * @param tlvHeader tlvHeader. | 36 | + * @param tlvHeader TLV header |
37 | */ | 37 | */ |
38 | public IsReachabilityTlv(TlvHeader tlvHeader) { | 38 | public IsReachabilityTlv(TlvHeader tlvHeader) { |
39 | this.setTlvType(tlvHeader.tlvType()); | 39 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -34,7 +34,7 @@ public class IsisNeighborTlv extends TlvHeader implements IsisTlv { | ... | @@ -34,7 +34,7 @@ public class IsisNeighborTlv extends TlvHeader implements IsisTlv { |
34 | /** | 34 | /** |
35 | * Creates an instance of ISIS neighbor TLV. | 35 | * Creates an instance of ISIS neighbor TLV. |
36 | * | 36 | * |
37 | - * @param tlvHeader tlvHeader | 37 | + * @param tlvHeader TLV header |
38 | */ | 38 | */ |
39 | public IsisNeighborTlv(TlvHeader tlvHeader) { | 39 | public IsisNeighborTlv(TlvHeader tlvHeader) { |
40 | this.setTlvType(tlvHeader.tlvType()); | 40 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -31,7 +31,7 @@ public class LspEntriesTlv extends TlvHeader implements IsisTlv { | ... | @@ -31,7 +31,7 @@ public class LspEntriesTlv extends TlvHeader implements IsisTlv { |
31 | /** | 31 | /** |
32 | * Creates an instance of LSP entries TLV. | 32 | * Creates an instance of LSP entries TLV. |
33 | * | 33 | * |
34 | - * @param tlvHeader tlvHeader. | 34 | + * @param tlvHeader TLV header |
35 | */ | 35 | */ |
36 | public LspEntriesTlv(TlvHeader tlvHeader) { | 36 | public LspEntriesTlv(TlvHeader tlvHeader) { |
37 | this.setTlvType(tlvHeader.tlvType()); | 37 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
... | @@ -46,7 +46,7 @@ public class LspEntry { | ... | @@ -46,7 +46,7 @@ public class LspEntry { |
46 | /** | 46 | /** |
47 | * Sets LSP sequenceNumber for LSP entry. | 47 | * Sets LSP sequenceNumber for LSP entry. |
48 | * | 48 | * |
49 | - * @param lspSequenceNumber lspSequenceNumber. | 49 | + * @param lspSequenceNumber lspSequenceNumber |
50 | */ | 50 | */ |
51 | public void setLspSequenceNumber(int lspSequenceNumber) { | 51 | public void setLspSequenceNumber(int lspSequenceNumber) { |
52 | this.lspSequenceNumber = lspSequenceNumber; | 52 | this.lspSequenceNumber = lspSequenceNumber; |
... | @@ -113,11 +113,11 @@ public class LspEntry { | ... | @@ -113,11 +113,11 @@ public class LspEntry { |
113 | */ | 113 | */ |
114 | public void readFrom(ChannelBuffer channelBuffer) { | 114 | public void readFrom(ChannelBuffer channelBuffer) { |
115 | this.setRemainingTime(channelBuffer.readUnsignedShort()); | 115 | this.setRemainingTime(channelBuffer.readUnsignedShort()); |
116 | - byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE]; | 116 | + byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE]; |
117 | - channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE); | 117 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE); |
118 | this.setLspId(IsisUtil.systemIdPlus(tempByteArray)); | 118 | this.setLspId(IsisUtil.systemIdPlus(tempByteArray)); |
119 | this.setLspSequenceNumber(channelBuffer.readInt()); | 119 | this.setLspSequenceNumber(channelBuffer.readInt()); |
120 | - this.setLspChecksum(channelBuffer.readUnsignedByte()); | 120 | + this.setLspChecksum(channelBuffer.readUnsignedShort()); |
121 | } | 121 | } |
122 | 122 | ||
123 | /** | 123 | /** | ... | ... |
... | @@ -226,7 +226,7 @@ public class MetricOfInternalReachability { | ... | @@ -226,7 +226,7 @@ public class MetricOfInternalReachability { |
226 | /** | 226 | /** |
227 | * Returns error metric of metric of internal reachability. | 227 | * Returns error metric of metric of internal reachability. |
228 | * | 228 | * |
229 | - * @return errorMetric error metic | 229 | + * @return errorMetric error metric |
230 | */ | 230 | */ |
231 | public byte errorMetric() { | 231 | public byte errorMetric() { |
232 | return errorMetric; | 232 | return errorMetric; | ... | ... |
... | @@ -217,7 +217,7 @@ public class MetricsOfReachability { | ... | @@ -217,7 +217,7 @@ public class MetricsOfReachability { |
217 | /** | 217 | /** |
218 | * Sets delay metric for metric of reachability. | 218 | * Sets delay metric for metric of reachability. |
219 | * | 219 | * |
220 | - * @param delayMetric delay metric. | 220 | + * @param delayMetric delay metric |
221 | */ | 221 | */ |
222 | public void setDelayMetric(byte delayMetric) { | 222 | public void setDelayMetric(byte delayMetric) { |
223 | this.delayMetric = delayMetric; | 223 | this.delayMetric = delayMetric; |
... | @@ -235,7 +235,7 @@ public class MetricsOfReachability { | ... | @@ -235,7 +235,7 @@ public class MetricsOfReachability { |
235 | /** | 235 | /** |
236 | * Sets Expense metric for metric of reachability. | 236 | * Sets Expense metric for metric of reachability. |
237 | * | 237 | * |
238 | - * @param expenseMetric Expense metric. | 238 | + * @param expenseMetric Expense metric |
239 | */ | 239 | */ |
240 | public void setExpenseMetric(byte expenseMetric) { | 240 | public void setExpenseMetric(byte expenseMetric) { |
241 | this.expenseMetric = expenseMetric; | 241 | this.expenseMetric = expenseMetric; |
... | @@ -253,7 +253,7 @@ public class MetricsOfReachability { | ... | @@ -253,7 +253,7 @@ public class MetricsOfReachability { |
253 | /** | 253 | /** |
254 | * Sets Error metric for metric of reachability. | 254 | * Sets Error metric for metric of reachability. |
255 | * | 255 | * |
256 | - * @param errorMetric Error metric. | 256 | + * @param errorMetric Error metric |
257 | */ | 257 | */ |
258 | public void setErrorMetric(byte errorMetric) { | 258 | public void setErrorMetric(byte errorMetric) { |
259 | this.errorMetric = errorMetric; | 259 | this.errorMetric = errorMetric; | ... | ... |
... | @@ -31,7 +31,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv { | ... | @@ -31,7 +31,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv { |
31 | /** | 31 | /** |
32 | * Creates an instance of padding TLV. | 32 | * Creates an instance of padding TLV. |
33 | * | 33 | * |
34 | - * @param tlvHeader tlvHeader. | 34 | + * @param tlvHeader TLV header |
35 | */ | 35 | */ |
36 | public PaddingTlv(TlvHeader tlvHeader) { | 36 | public PaddingTlv(TlvHeader tlvHeader) { |
37 | this.setTlvType(tlvHeader.tlvType()); | 37 | this.setTlvType(tlvHeader.tlvType()); | ... | ... |
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/ProtocolSupportedTlv.java
... | @@ -32,7 +32,7 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { | ... | @@ -32,7 +32,7 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv { |
32 | /** | 32 | /** |
33 | * Creates an instance of protocol supported TLV. | 33 | * Creates an instance of protocol supported TLV. |
34 | * | 34 | * |
35 | - * @param tlvHeader tlvHeader. | 35 | + * @param tlvHeader TLV header |
36 | */ | 36 | */ |
37 | public ProtocolSupportedTlv(TlvHeader tlvHeader) { | 37 | public ProtocolSupportedTlv(TlvHeader tlvHeader) { |
38 | 38 | ... | ... |
... | @@ -44,6 +44,11 @@ public class TlvFinder extends TlvHeader { | ... | @@ -44,6 +44,11 @@ public class TlvFinder extends TlvHeader { |
44 | case EXTENDEDISREACHABILITY: | 44 | case EXTENDEDISREACHABILITY: |
45 | //TODO | 45 | //TODO |
46 | break; | 46 | break; |
47 | + case HOSTNAME: | ||
48 | + HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader); | ||
49 | + hostNameTlv.readFrom(channelBuffer); | ||
50 | + isisTlv = hostNameTlv; | ||
51 | + break; | ||
47 | case IDRPINFORMATION: | 52 | case IDRPINFORMATION: |
48 | IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader); | 53 | IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader); |
49 | idrpInformationTlv.readFrom(channelBuffer); | 54 | idrpInformationTlv.readFrom(channelBuffer); | ... | ... |
... | @@ -40,7 +40,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering | ... | @@ -40,7 +40,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering |
40 | } | 40 | } |
41 | 41 | ||
42 | /** | 42 | /** |
43 | - * Gets administrative group value. | 43 | + * Returns administrative group value. |
44 | * | 44 | * |
45 | * @return administrative group value | 45 | * @return administrative group value |
46 | */ | 46 | */ |
... | @@ -58,7 +58,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering | ... | @@ -58,7 +58,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering |
58 | } | 58 | } |
59 | 59 | ||
60 | /** | 60 | /** |
61 | - * Gets administrative group value. | 61 | + * Returns administrative group value. |
62 | * | 62 | * |
63 | * @return administrativeGroup value | 63 | * @return administrativeGroup value |
64 | */ | 64 | */ |
... | @@ -93,7 +93,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering | ... | @@ -93,7 +93,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | - * Gets administrative group body as byte array. | 96 | + * Returns administrative group body as byte array. |
97 | * | 97 | * |
98 | * @return byte array of sub tlv administrative group | 98 | * @return byte array of sub tlv administrative group |
99 | */ | 99 | */ | ... | ... |
... | @@ -31,7 +31,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub | ... | @@ -31,7 +31,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub |
31 | /** | 31 | /** |
32 | * Creates an instance of maximum bandwidth. | 32 | * Creates an instance of maximum bandwidth. |
33 | * | 33 | * |
34 | - * @param header tlv header instance | 34 | + * @param header TLV header instance |
35 | */ | 35 | */ |
36 | public MaximumBandwidth(TlvHeader header) { | 36 | public MaximumBandwidth(TlvHeader header) { |
37 | this.setTlvType(header.tlvType()); | 37 | this.setTlvType(header.tlvType()); |
... | @@ -48,7 +48,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub | ... | @@ -48,7 +48,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | - * Gets value of maximum bandwidth. | 51 | + * Returns value of maximum bandwidth. |
52 | * | 52 | * |
53 | * @return maximumBandwidth value of maximum bandwidth | 53 | * @return maximumBandwidth value of maximum bandwidth |
54 | */ | 54 | */ |
... | @@ -69,7 +69,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub | ... | @@ -69,7 +69,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub |
69 | } | 69 | } |
70 | 70 | ||
71 | /** | 71 | /** |
72 | - * Gets byte array of maximum bandwidth sub tlv. | 72 | + * Returns byte array of maximum bandwidth sub tlv. |
73 | * | 73 | * |
74 | * @return byte array of maximum bandwidth sub tlv | 74 | * @return byte array of maximum bandwidth sub tlv |
75 | */ | 75 | */ |
... | @@ -83,7 +83,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub | ... | @@ -83,7 +83,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub |
83 | } | 83 | } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | - * Gets maximum bandwidth sub tlv byte array. | 86 | + * Returns maximum bandwidth sub tlv byte array. |
87 | * | 87 | * |
88 | * @return byte array of maximum bandwidth sub tlv | 88 | * @return byte array of maximum bandwidth sub tlv |
89 | */ | 89 | */ |
... | @@ -92,7 +92,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub | ... | @@ -92,7 +92,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub |
92 | linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth)); | 92 | linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth)); |
93 | return linkSubTypeBody; | 93 | return linkSubTypeBody; |
94 | } | 94 | } |
95 | - | 95 | + @Override |
96 | public String toString() { | 96 | public String toString() { |
97 | return MoreObjects.toStringHelper(getClass()) | 97 | return MoreObjects.toStringHelper(getClass()) |
98 | .add("maximumBandwidth", maximumBandwidth) | 98 | .add("maximumBandwidth", maximumBandwidth) | ... | ... |
... | @@ -31,7 +31,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi | ... | @@ -31,7 +31,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi |
31 | /** | 31 | /** |
32 | * Creates an instance of maximum reservable bandwidth. | 32 | * Creates an instance of maximum reservable bandwidth. |
33 | * | 33 | * |
34 | - * @param header tlv header | 34 | + * @param header TLV header |
35 | */ | 35 | */ |
36 | public MaximumReservableBandwidth(TlvHeader header) { | 36 | public MaximumReservableBandwidth(TlvHeader header) { |
37 | this.setTlvType(header.tlvType()); | 37 | this.setTlvType(header.tlvType()); |
... | @@ -48,7 +48,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi | ... | @@ -48,7 +48,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | - * Gets value of maximum reversible bandwidth. | 51 | + * Returns value of maximum reversible bandwidth. |
52 | * | 52 | * |
53 | * @return maximumBandwidth maximum reversible bandwidth | 53 | * @return maximumBandwidth maximum reversible bandwidth |
54 | */ | 54 | */ |
... | @@ -84,7 +84,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi | ... | @@ -84,7 +84,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi |
84 | } | 84 | } |
85 | 85 | ||
86 | /** | 86 | /** |
87 | - * Gets maximum reservable bandwidth sub tlv body as byte array. | 87 | + * Returns maximum reservable bandwidth sub tlv body as byte array. |
88 | * | 88 | * |
89 | * @return byte of maximum reservable bandwidth sub tlv body | 89 | * @return byte of maximum reservable bandwidth sub tlv body |
90 | */ | 90 | */ | ... | ... |
... | @@ -51,7 +51,7 @@ public enum SubTlvType { | ... | @@ -51,7 +51,7 @@ public enum SubTlvType { |
51 | } | 51 | } |
52 | 52 | ||
53 | /** | 53 | /** |
54 | - * Gets the enum instance from type value - reverse lookup purpose. | 54 | + * Returns the enum instance from type value - reverse lookup purpose. |
55 | * | 55 | * |
56 | * @param subTlvTypeValue TLV type value | 56 | * @param subTlvTypeValue TLV type value |
57 | * @return ISIS sub TLV type instance | 57 | * @return ISIS sub TLV type instance |
... | @@ -61,7 +61,7 @@ public enum SubTlvType { | ... | @@ -61,7 +61,7 @@ public enum SubTlvType { |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
64 | - * Gets value. | 64 | + * Returns value. |
65 | * | 65 | * |
66 | * @return value | 66 | * @return value |
67 | */ | 67 | */ | ... | ... |
... | @@ -47,7 +47,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine | ... | @@ -47,7 +47,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine |
47 | } | 47 | } |
48 | 48 | ||
49 | /** | 49 | /** |
50 | - * Gets TE metric value. | 50 | + * Returns TE metric value. |
51 | * | 51 | * |
52 | * @return value of traffic engineering metric | 52 | * @return value of traffic engineering metric |
53 | */ | 53 | */ |
... | @@ -67,7 +67,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine | ... | @@ -67,7 +67,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine |
67 | } | 67 | } |
68 | 68 | ||
69 | /** | 69 | /** |
70 | - * Gets instance as byte array. | 70 | + * Returns instance as byte array. |
71 | * | 71 | * |
72 | * @return instance as byte array | 72 | * @return instance as byte array |
73 | */ | 73 | */ |
... | @@ -82,7 +82,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine | ... | @@ -82,7 +82,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | - * Gets trafficEngineeringMetric as byte array . | 85 | + * Returns trafficEngineeringMetric as byte array . |
86 | * | 86 | * |
87 | * @return byte array of trafficEngineeringMetric | 87 | * @return byte array of trafficEngineeringMetric |
88 | */ | 88 | */ | ... | ... |
... | @@ -50,7 +50,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering | ... | @@ -50,7 +50,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering |
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
53 | - * Gets list of un reserved bandwidth . | 53 | + * Returns list of un reserved bandwidth . |
54 | * | 54 | * |
55 | * @return List of un reserved bandwidth | 55 | * @return List of un reserved bandwidth |
56 | */ | 56 | */ |
... | @@ -71,7 +71,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering | ... | @@ -71,7 +71,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering |
71 | } | 71 | } |
72 | 72 | ||
73 | /** | 73 | /** |
74 | - * Gets instance as byte array. | 74 | + * Returns instance as byte array. |
75 | * | 75 | * |
76 | * @return instance as byte array | 76 | * @return instance as byte array |
77 | */ | 77 | */ |
... | @@ -86,7 +86,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering | ... | @@ -86,7 +86,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | - * Gets unreserved bandwidth as byte array. | 89 | + * Returns unreserved bandwidth as byte array. |
90 | * | 90 | * |
91 | * @return unreserved bandwidth as byte array | 91 | * @return unreserved bandwidth as byte array |
92 | */ | 92 | */ | ... | ... |
... | @@ -32,6 +32,7 @@ public class ChecksumCalculator { | ... | @@ -32,6 +32,7 @@ public class ChecksumCalculator { |
32 | * @return true if valid else false | 32 | * @return true if valid else false |
33 | */ | 33 | */ |
34 | public boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2) { | 34 | public boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2) { |
35 | + | ||
35 | byte[] checksum = calculateLspChecksum(lspPacket, lspChecksumPos1, lspChecksumPos2); | 36 | byte[] checksum = calculateLspChecksum(lspPacket, lspChecksumPos1, lspChecksumPos2); |
36 | if (lspPacket[lspChecksumPos1] == checksum[0] && lspPacket[lspChecksumPos2] == checksum[1]) { | 37 | if (lspPacket[lspChecksumPos1] == checksum[0] && lspPacket[lspChecksumPos2] == checksum[1]) { |
37 | return true; | 38 | return true; | ... | ... |
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 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | + | ||
20 | +/** | ||
21 | + * Representation of ISIS config. | ||
22 | + */ | ||
23 | +public enum IsisConfig { | ||
24 | + INSTANCE; | ||
25 | + private JsonNode jsonNodes = null; | ||
26 | + | ||
27 | + /** | ||
28 | + * Returns the config value. | ||
29 | + * | ||
30 | + * @return jsonNodes json node | ||
31 | + */ | ||
32 | + public JsonNode config() { | ||
33 | + return jsonNodes; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Sets the config value for jsonNode. | ||
38 | + * | ||
39 | + * @param jsonNodes json node | ||
40 | + */ | ||
41 | + public void setConfig(JsonNode jsonNodes) { | ||
42 | + this.jsonNodes = jsonNodes; | ||
43 | + } | ||
44 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | package org.onosproject.isis.io.util; | 17 | package org.onosproject.isis.io.util; |
18 | 18 | ||
19 | /** | 19 | /** |
20 | - * Representation of ISIS constants. | 20 | + * Representation of ISIS Constants. |
21 | */ | 21 | */ |
22 | public final class IsisConstants { | 22 | public final class IsisConstants { |
23 | public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC | 23 | public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC | ... | ... |
... | @@ -17,7 +17,20 @@ package org.onosproject.isis.io.util; | ... | @@ -17,7 +17,20 @@ package org.onosproject.isis.io.util; |
17 | 17 | ||
18 | import com.google.common.primitives.Bytes; | 18 | import com.google.common.primitives.Bytes; |
19 | import org.onlab.packet.Ip4Address; | 19 | import org.onlab.packet.Ip4Address; |
20 | +import org.onlab.packet.MacAddress; | ||
21 | +import org.onosproject.isis.controller.IsisInterface; | ||
22 | +import org.onosproject.isis.controller.IsisInterfaceState; | ||
23 | +import org.onosproject.isis.controller.IsisNeighbor; | ||
24 | +import org.onosproject.isis.controller.IsisPduType; | ||
25 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; | ||
27 | +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
29 | +import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; | ||
30 | +import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv; | ||
31 | +import org.onosproject.isis.io.isispacket.tlv.IsisNeighborTlv; | ||
20 | import org.onosproject.isis.io.isispacket.tlv.PaddingTlv; | 32 | import org.onosproject.isis.io.isispacket.tlv.PaddingTlv; |
33 | +import org.onosproject.isis.io.isispacket.tlv.ProtocolSupportedTlv; | ||
21 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | 34 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; |
22 | import org.onosproject.isis.io.isispacket.tlv.TlvType; | 35 | import org.onosproject.isis.io.isispacket.tlv.TlvType; |
23 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
... | @@ -26,6 +39,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -26,6 +39,7 @@ import org.slf4j.LoggerFactory; |
26 | import javax.xml.bind.DatatypeConverter; | 39 | import javax.xml.bind.DatatypeConverter; |
27 | import java.util.ArrayList; | 40 | import java.util.ArrayList; |
28 | import java.util.List; | 41 | import java.util.List; |
42 | +import java.util.Set; | ||
29 | import java.util.StringTokenizer; | 43 | import java.util.StringTokenizer; |
30 | 44 | ||
31 | /** | 45 | /** |
... | @@ -37,6 +51,7 @@ public final class IsisUtil { | ... | @@ -37,6 +51,7 @@ public final class IsisUtil { |
37 | public static final int ID_PLUS_ONE_BYTE = 7; | 51 | public static final int ID_PLUS_ONE_BYTE = 7; |
38 | public static final int ID_PLUS_TWO_BYTE = 8; | 52 | public static final int ID_PLUS_TWO_BYTE = 8; |
39 | public static final int THREE_BYTES = 3; | 53 | public static final int THREE_BYTES = 3; |
54 | + public static final int TWO_BYTES = 2; | ||
40 | public static final int SIX_BYTES = 6; | 55 | public static final int SIX_BYTES = 6; |
41 | public static final int EIGHT_BYTES = 8; | 56 | public static final int EIGHT_BYTES = 8; |
42 | public static final int FOUR_BYTES = 4; | 57 | public static final int FOUR_BYTES = 4; |
... | @@ -103,17 +118,23 @@ public final class IsisUtil { | ... | @@ -103,17 +118,23 @@ public final class IsisUtil { |
103 | * @return systemIdPlus system ID | 118 | * @return systemIdPlus system ID |
104 | */ | 119 | */ |
105 | public static String systemIdPlus(byte[] bytes) { | 120 | public static String systemIdPlus(byte[] bytes) { |
121 | + int count = 1; | ||
106 | String systemId = ""; | 122 | String systemId = ""; |
107 | for (Byte byt : bytes) { | 123 | for (Byte byt : bytes) { |
108 | String hexa = Integer.toHexString(Byte.toUnsignedInt(byt)); | 124 | String hexa = Integer.toHexString(Byte.toUnsignedInt(byt)); |
109 | if (hexa.length() % 2 != 0) { | 125 | if (hexa.length() % 2 != 0) { |
110 | hexa = "0" + hexa; | 126 | hexa = "0" + hexa; |
111 | } | 127 | } |
112 | - systemId = systemId + hexa; | 128 | + if (count == 7 && bytes.length == 8) { |
129 | + systemId = systemId + hexa + "-"; | ||
130 | + } else { | ||
131 | + systemId = systemId + hexa; | ||
132 | + } | ||
113 | if (systemId.length() == 4 || systemId.length() == 9 | 133 | if (systemId.length() == 4 || systemId.length() == 9 |
114 | || systemId.length() == 14) { | 134 | || systemId.length() == 14) { |
115 | systemId = systemId + "."; | 135 | systemId = systemId + "."; |
116 | } | 136 | } |
137 | + count++; | ||
117 | } | 138 | } |
118 | return systemId; | 139 | return systemId; |
119 | } | 140 | } |
... | @@ -154,6 +175,38 @@ public final class IsisUtil { | ... | @@ -154,6 +175,38 @@ public final class IsisUtil { |
154 | } | 175 | } |
155 | 176 | ||
156 | /** | 177 | /** |
178 | + * Returns PDU headaer length. | ||
179 | + * | ||
180 | + * @param pduType PDU type | ||
181 | + * @return headerLength header length | ||
182 | + */ | ||
183 | + public static int getPduHeaderLength(int pduType) { | ||
184 | + int headerLength = 0; | ||
185 | + switch (IsisPduType.get(pduType)) { | ||
186 | + case L1HELLOPDU: | ||
187 | + case L2HELLOPDU: | ||
188 | + case L1LSPDU: | ||
189 | + case L2LSPDU: | ||
190 | + headerLength = IsisConstants.HELLOHEADERLENGTH; | ||
191 | + break; | ||
192 | + case P2PHELLOPDU: | ||
193 | + headerLength = IsisConstants.P2PHELLOHEADERLENGTH; | ||
194 | + break; | ||
195 | + case L1PSNP: | ||
196 | + case L2PSNP: | ||
197 | + headerLength = IsisConstants.PSNPDUHEADERLENGTH; | ||
198 | + break; | ||
199 | + case L1CSNP: | ||
200 | + case L2CSNP: | ||
201 | + headerLength = IsisConstants.CSNPDUHEADERLENGTH; | ||
202 | + break; | ||
203 | + default: | ||
204 | + break; | ||
205 | + } | ||
206 | + return headerLength; | ||
207 | + } | ||
208 | + | ||
209 | + /** | ||
157 | * Adds the PDU length in packet. | 210 | * Adds the PDU length in packet. |
158 | * | 211 | * |
159 | * @param isisPacket ISIS packet | 212 | * @param isisPacket ISIS packet |
... | @@ -186,7 +239,7 @@ public final class IsisUtil { | ... | @@ -186,7 +239,7 @@ public final class IsisUtil { |
186 | */ | 239 | */ |
187 | public static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2) { | 240 | public static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2) { |
188 | //Set the checksum for the packet | 241 | //Set the checksum for the packet |
189 | - //Convert the lenth to two bytes as the length field is 2 bytes | 242 | + //Convert the length to two bytes as the length field is 2 bytes |
190 | byte[] checksumInTwoBytes = new ChecksumCalculator().calculateLspChecksum( | 243 | byte[] checksumInTwoBytes = new ChecksumCalculator().calculateLspChecksum( |
191 | isisPacket, checksumBytePos1, checksumBytePos2); | 244 | isisPacket, checksumBytePos1, checksumBytePos2); |
192 | //isis header 3rd and 4th position represents length | 245 | //isis header 3rd and 4th position represents length |
... | @@ -296,7 +349,6 @@ public final class IsisUtil { | ... | @@ -296,7 +349,6 @@ public final class IsisUtil { |
296 | * @return numInBytes given number as bytes | 349 | * @return numInBytes given number as bytes |
297 | */ | 350 | */ |
298 | public static byte[] convertToFourBytes(int numberToConvert) { | 351 | public static byte[] convertToFourBytes(int numberToConvert) { |
299 | - | ||
300 | byte[] numInBytes = new byte[4]; | 352 | byte[] numInBytes = new byte[4]; |
301 | String s1 = Integer.toHexString(numberToConvert); | 353 | String s1 = Integer.toHexString(numberToConvert); |
302 | if (s1.length() % 2 != 0) { | 354 | if (s1.length() % 2 != 0) { |
... | @@ -328,6 +380,168 @@ public final class IsisUtil { | ... | @@ -328,6 +380,168 @@ public final class IsisUtil { |
328 | } | 380 | } |
329 | 381 | ||
330 | /** | 382 | /** |
383 | + * Returns the P2P hello PDU. | ||
384 | + * | ||
385 | + * @param isisInterface ISIS interface instance | ||
386 | + * @param paddingEnabled padding enabled or not | ||
387 | + * @return hello PDU | ||
388 | + */ | ||
389 | + public static byte[] getP2pHelloPdu(IsisInterface isisInterface, boolean paddingEnabled) { | ||
390 | + IsisHeader isisHeader = new IsisHeader(); | ||
391 | + isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | ||
392 | + isisHeader.setPduHeaderLength((byte) IsisConstants.P2PHELLOHEADERLENGTH); | ||
393 | + isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | ||
394 | + isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | ||
395 | + isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); | ||
396 | + isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); | ||
397 | + //isisHeader.setReserved((byte) IsisConstants.RESERVED); | ||
398 | + isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION); | ||
399 | + isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS); | ||
400 | + P2PHelloPdu p2pHelloPdu = new P2PHelloPdu(isisHeader); | ||
401 | + p2pHelloPdu.setCircuitType((byte) isisInterface.reservedPacketCircuitType()); | ||
402 | + p2pHelloPdu.setSourceId(isisInterface.systemId()); | ||
403 | + p2pHelloPdu.setHoldingTime(isisInterface.holdingTime()); | ||
404 | + p2pHelloPdu.setPduLength(IsisConstants.PDU_LENGTH); | ||
405 | + p2pHelloPdu.setLocalCircuitId((byte) IsisConstants.LOCALCIRCUITIDFORP2P); | ||
406 | + | ||
407 | + TlvHeader tlvHeader = new TlvHeader(); | ||
408 | + tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); | ||
409 | + tlvHeader.setTlvLength(0); | ||
410 | + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); | ||
411 | + areaAddressTlv.addAddress(isisInterface.areaAddress()); | ||
412 | + p2pHelloPdu.addTlv(areaAddressTlv); | ||
413 | + | ||
414 | + tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value()); | ||
415 | + tlvHeader.setTlvLength(0); | ||
416 | + ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader); | ||
417 | + protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED); | ||
418 | + p2pHelloPdu.addTlv(protocolSupportedTlv); | ||
419 | + | ||
420 | + tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value()); | ||
421 | + tlvHeader.setTlvLength(0); | ||
422 | + AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader); | ||
423 | + adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value()); | ||
424 | + adjacencyStateTlv.setLocalCircuitId(Integer.parseInt(isisInterface.circuitId())); | ||
425 | + Set<MacAddress> neighbors = isisInterface.neighbors(); | ||
426 | + if (neighbors.size() > 0) { | ||
427 | + IsisNeighbor neighbor = isisInterface.lookup(neighbors.iterator().next()); | ||
428 | + adjacencyStateTlv.setAdjacencyType((byte) neighbor.interfaceState().value()); | ||
429 | + adjacencyStateTlv.setNeighborSystemId(neighbor.neighborSystemId()); | ||
430 | + adjacencyStateTlv.setNeighborLocalCircuitId(neighbor.localExtendedCircuitId()); | ||
431 | + } | ||
432 | + p2pHelloPdu.addTlv(adjacencyStateTlv); | ||
433 | + | ||
434 | + tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value()); | ||
435 | + tlvHeader.setTlvLength(0); | ||
436 | + IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader); | ||
437 | + ipInterfaceAddressTlv.addInterfaceAddres(isisInterface.interfaceIpAddress()); | ||
438 | + p2pHelloPdu.addTlv(ipInterfaceAddressTlv); | ||
439 | + | ||
440 | + byte[] beforePadding = p2pHelloPdu.asBytes(); | ||
441 | + byte[] helloMessage; | ||
442 | + if (paddingEnabled) { | ||
443 | + byte[] paddingTlvs = getPaddingTlvs(beforePadding.length); | ||
444 | + helloMessage = Bytes.concat(beforePadding, paddingTlvs); | ||
445 | + } else { | ||
446 | + helloMessage = beforePadding; | ||
447 | + } | ||
448 | + return helloMessage; | ||
449 | + } | ||
450 | + | ||
451 | + /** | ||
452 | + * Returns the L1 hello PDU. | ||
453 | + * | ||
454 | + * @param isisInterface ISIS interface instance | ||
455 | + * @param paddingEnabled padding enabled or not | ||
456 | + * @return helloMessage hello PDU | ||
457 | + */ | ||
458 | + public static byte[] getL1HelloPdu(IsisInterface isisInterface, boolean paddingEnabled) { | ||
459 | + return getL1OrL2HelloPdu(isisInterface, IsisPduType.L1HELLOPDU, paddingEnabled); | ||
460 | + } | ||
461 | + | ||
462 | + /** | ||
463 | + * Returns the L2 hello PDU. | ||
464 | + * | ||
465 | + * @param isisInterface ISIS interface instance | ||
466 | + * @param paddingEnabled padding enabled or not | ||
467 | + * @return helloMessage hello PDU | ||
468 | + */ | ||
469 | + public static byte[] getL2HelloPdu(IsisInterface isisInterface, boolean paddingEnabled) { | ||
470 | + return getL1OrL2HelloPdu(isisInterface, IsisPduType.L2HELLOPDU, paddingEnabled); | ||
471 | + } | ||
472 | + | ||
473 | + /** | ||
474 | + * Returns the hello PDU. | ||
475 | + * | ||
476 | + * @param isisInterface ISIS interface instance | ||
477 | + * @param paddingEnabled padding enabled or not | ||
478 | + * @return helloMessage hello PDU | ||
479 | + */ | ||
480 | + private static byte[] getL1OrL2HelloPdu(IsisInterface isisInterface, IsisPduType isisPduType, | ||
481 | + boolean paddingEnabled) { | ||
482 | + String lanId = ""; | ||
483 | + IsisHeader isisHeader = new IsisHeader(); | ||
484 | + isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | ||
485 | + isisHeader.setPduHeaderLength((byte) IsisConstants.HELLOHEADERLENGTH); | ||
486 | + isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | ||
487 | + isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | ||
488 | + if (isisPduType == IsisPduType.L1HELLOPDU) { | ||
489 | + isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value()); | ||
490 | + lanId = isisInterface.l1LanId(); | ||
491 | + } else if (isisPduType == IsisPduType.L2HELLOPDU) { | ||
492 | + isisHeader.setIsisPduType(IsisPduType.L2HELLOPDU.value()); | ||
493 | + lanId = isisInterface.l2LanId(); | ||
494 | + } | ||
495 | + isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); | ||
496 | + isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION); | ||
497 | + isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS); | ||
498 | + L1L2HelloPdu l1L2HelloPdu = new L1L2HelloPdu(isisHeader); | ||
499 | + l1L2HelloPdu.setCircuitType((byte) isisInterface.reservedPacketCircuitType()); | ||
500 | + l1L2HelloPdu.setSourceId(isisInterface.systemId()); | ||
501 | + l1L2HelloPdu.setHoldingTime(isisInterface.holdingTime()); | ||
502 | + l1L2HelloPdu.setPduLength(IsisConstants.PDU_LENGTH); | ||
503 | + l1L2HelloPdu.setPriority((byte) isisInterface.priority()); | ||
504 | + l1L2HelloPdu.setLanId(lanId); | ||
505 | + TlvHeader tlvHeader = new TlvHeader(); | ||
506 | + tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); | ||
507 | + tlvHeader.setTlvLength(0); | ||
508 | + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); | ||
509 | + areaAddressTlv.addAddress(isisInterface.areaAddress()); | ||
510 | + l1L2HelloPdu.addTlv(areaAddressTlv); | ||
511 | + Set<MacAddress> neighbors = isisInterface.neighbors(); | ||
512 | + if (neighbors.size() > 0) { | ||
513 | + tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value()); | ||
514 | + tlvHeader.setTlvLength(0); | ||
515 | + IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader); | ||
516 | + for (MacAddress neighbor : neighbors) { | ||
517 | + isisNeighborTlv.addNeighbor(neighbor); | ||
518 | + } | ||
519 | + l1L2HelloPdu.addTlv(isisNeighborTlv); | ||
520 | + } | ||
521 | + tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value()); | ||
522 | + tlvHeader.setTlvLength(0); | ||
523 | + ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader); | ||
524 | + protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED); | ||
525 | + l1L2HelloPdu.addTlv(protocolSupportedTlv); | ||
526 | + | ||
527 | + tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value()); | ||
528 | + tlvHeader.setTlvLength(0); | ||
529 | + IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader); | ||
530 | + ipInterfaceAddressTlv.addInterfaceAddres(isisInterface.interfaceIpAddress()); | ||
531 | + l1L2HelloPdu.addTlv(ipInterfaceAddressTlv); | ||
532 | + | ||
533 | + byte[] beforePadding = l1L2HelloPdu.asBytes(); | ||
534 | + byte[] helloMessage; | ||
535 | + if (paddingEnabled) { | ||
536 | + byte[] paddingTlvs = getPaddingTlvs(beforePadding.length); | ||
537 | + helloMessage = Bytes.concat(beforePadding, paddingTlvs); | ||
538 | + } else { | ||
539 | + helloMessage = beforePadding; | ||
540 | + } | ||
541 | + return helloMessage; | ||
542 | + } | ||
543 | + | ||
544 | + /** | ||
331 | * Converts a byte to integer variable. | 545 | * Converts a byte to integer variable. |
332 | * | 546 | * |
333 | * @param bytesToConvert bytes to convert | 547 | * @param bytesToConvert bytes to convert |
... | @@ -461,4 +675,22 @@ public final class IsisUtil { | ... | @@ -461,4 +675,22 @@ public final class IsisUtil { |
461 | } | 675 | } |
462 | return numInBytes; | 676 | return numInBytes; |
463 | } | 677 | } |
464 | -} | 678 | + |
679 | + /** | ||
680 | + * Converts the bytes of prefix to string type value. | ||
681 | + * | ||
682 | + * @param bytes array of prefix | ||
683 | + * @return string value of prefix | ||
684 | + */ | ||
685 | + public static String prefixConversion(byte[] bytes) { | ||
686 | + String prefix = ""; | ||
687 | + for (int i = 0; i < bytes.length; i++) { | ||
688 | + if (i < (bytes.length - 1)) { | ||
689 | + prefix = prefix + bytes[i] + "."; | ||
690 | + } else { | ||
691 | + prefix = prefix + bytes[i]; | ||
692 | + } | ||
693 | + } | ||
694 | + return prefix; | ||
695 | + } | ||
696 | +} | ||
... | \ 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 | +import org.onlab.packet.Ip4Address; | ||
19 | +import org.onlab.packet.MacAddress; | ||
20 | +import org.onosproject.isis.controller.IsisInterface; | ||
21 | +import org.onosproject.isis.controller.IsisNeighbor; | ||
22 | +import org.onosproject.isis.controller.IsisNetworkType; | ||
23 | +import org.onosproject.isis.controller.IsisPduType; | ||
24 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
25 | +import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas; | ||
26 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.HostNameTlv; | ||
29 | +import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv; | ||
30 | +import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv; | ||
31 | +import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv; | ||
32 | +import org.onosproject.isis.io.isispacket.tlv.MetricOfInternalReachability; | ||
33 | +import org.onosproject.isis.io.isispacket.tlv.MetricsOfReachability; | ||
34 | +import org.onosproject.isis.io.isispacket.tlv.ProtocolSupportedTlv; | ||
35 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
36 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
37 | + | ||
38 | +import java.util.List; | ||
39 | + | ||
40 | +/** | ||
41 | + * Representation of link state PDU generator. | ||
42 | + */ | ||
43 | +public class LspGenerator { | ||
44 | + | ||
45 | + public LsPdu getLsp(IsisInterface isisInterface, String lspId, IsisPduType isisPduType, | ||
46 | + List<Ip4Address> allConfiguredInterfaceIps) { | ||
47 | + IsisHeader header = getHeader(isisPduType); | ||
48 | + LsPdu lsp = new LsPdu(header); | ||
49 | + | ||
50 | + lsp.setPduLength(0); | ||
51 | + lsp.setRemainingLifeTime(IsisConstants.LSPMAXAGE); | ||
52 | + lsp.setLspId(lspId); | ||
53 | + lsp.setSequenceNumber(isisInterface.isisLsdb().lsSequenceNumber(isisPduType)); | ||
54 | + lsp.setCheckSum(0); | ||
55 | + if (isisPduType == IsisPduType.L1LSPDU) { | ||
56 | + lsp.setTypeBlock((byte) 1); | ||
57 | + lsp.setIntermediateSystemType((byte) 1); | ||
58 | + } else if (isisPduType == IsisPduType.L2LSPDU) { | ||
59 | + lsp.setTypeBlock((byte) 3); | ||
60 | + lsp.setIntermediateSystemType((byte) 3); | ||
61 | + } | ||
62 | + lsp.setAttachedToOtherAreas(AttachedToOtherAreas.NONE); | ||
63 | + lsp.setPartitionRepair(false); | ||
64 | + lsp.setLspDbol(false); | ||
65 | + | ||
66 | + TlvHeader tlvHeader = new TlvHeader(); | ||
67 | + tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); | ||
68 | + tlvHeader.setTlvLength(0); | ||
69 | + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); | ||
70 | + areaAddressTlv.addAddress(isisInterface.areaAddress()); | ||
71 | + lsp.addTlv(areaAddressTlv); | ||
72 | + | ||
73 | + tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value()); | ||
74 | + tlvHeader.setTlvLength(0); | ||
75 | + ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader); | ||
76 | + protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED); | ||
77 | + lsp.addTlv(protocolSupportedTlv); | ||
78 | + | ||
79 | + tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value()); | ||
80 | + tlvHeader.setTlvLength(0); | ||
81 | + IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader); | ||
82 | + for (Ip4Address ipaddress : allConfiguredInterfaceIps) { | ||
83 | + ipInterfaceAddressTlv.addInterfaceAddres(ipaddress); | ||
84 | + } | ||
85 | + lsp.addTlv(ipInterfaceAddressTlv); | ||
86 | + | ||
87 | + tlvHeader.setTlvType(TlvType.HOSTNAME.value()); | ||
88 | + tlvHeader.setTlvLength(0); | ||
89 | + HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader); | ||
90 | + hostNameTlv.setHostName(isisInterface.intermediateSystemName()); | ||
91 | + lsp.addTlv(hostNameTlv); | ||
92 | + | ||
93 | + tlvHeader.setTlvType(TlvType.ISREACHABILITY.value()); | ||
94 | + tlvHeader.setTlvLength(0); | ||
95 | + IsReachabilityTlv isReachabilityTlv = new IsReachabilityTlv(tlvHeader); | ||
96 | + isReachabilityTlv.setReserved(0); | ||
97 | + MetricsOfReachability metricsOfReachability = new MetricsOfReachability(); | ||
98 | + metricsOfReachability.setDefaultMetric((byte) 10); | ||
99 | + metricsOfReachability.setDefaultIsInternal(true); | ||
100 | + metricsOfReachability.setDelayMetric((byte) 10); | ||
101 | + metricsOfReachability.setDelayIsInternal(true); | ||
102 | + metricsOfReachability.setDelayMetricSupported(true); | ||
103 | + metricsOfReachability.setExpenseMetric((byte) 10); | ||
104 | + metricsOfReachability.setExpenseIsInternal(true); | ||
105 | + metricsOfReachability.setExpenseMetricSupported(true); | ||
106 | + metricsOfReachability.setErrorMetric((byte) 10); | ||
107 | + metricsOfReachability.setErrorIsInternal(true); | ||
108 | + metricsOfReachability.setErrorMetricSupported(true); | ||
109 | + if (isisInterface.networkType() == IsisNetworkType.BROADCAST) { | ||
110 | + if (isisPduType == IsisPduType.L1LSPDU) { | ||
111 | + metricsOfReachability.setNeighborId(isisInterface.l1LanId()); | ||
112 | + } else if (isisPduType == IsisPduType.L2LSPDU) { | ||
113 | + metricsOfReachability.setNeighborId(isisInterface.l2LanId()); | ||
114 | + } | ||
115 | + } else if (isisInterface.networkType() == IsisNetworkType.P2P) { | ||
116 | + MacAddress neighborMac = isisInterface.neighbors().iterator().next(); | ||
117 | + IsisNeighbor neighbor = isisInterface.lookup(neighborMac); | ||
118 | + metricsOfReachability.setNeighborId(neighbor.neighborSystemId()); | ||
119 | + } | ||
120 | + | ||
121 | + isReachabilityTlv.addMeticsOfReachability(metricsOfReachability); | ||
122 | + lsp.addTlv(isReachabilityTlv); | ||
123 | + | ||
124 | + tlvHeader.setTlvType(TlvType.IPINTERNALREACHABILITY.value()); | ||
125 | + tlvHeader.setTlvLength(0); | ||
126 | + IpInternalReachabilityTlv ipInterReacTlv = new IpInternalReachabilityTlv(tlvHeader); | ||
127 | + MetricOfInternalReachability metricOfIntRea = new MetricOfInternalReachability(); | ||
128 | + metricOfIntRea.setDefaultMetric((byte) 10); | ||
129 | + metricOfIntRea.setDefaultIsInternal(true); | ||
130 | + metricOfIntRea.setDefaultDistributionDown(true); | ||
131 | + metricOfIntRea.setDelayMetric((byte) 0); | ||
132 | + metricOfIntRea.setDelayMetricSupported(false); | ||
133 | + metricOfIntRea.setDelayIsInternal(true); | ||
134 | + metricOfIntRea.setExpenseMetric((byte) 0); | ||
135 | + metricOfIntRea.setExpenseMetricSupported(false); | ||
136 | + metricOfIntRea.setExpenseIsInternal(true); | ||
137 | + metricOfIntRea.setErrorMetric((byte) 0); | ||
138 | + metricOfIntRea.setErrorMetricSupported(false); | ||
139 | + metricOfIntRea.setExpenseIsInternal(true); | ||
140 | + metricOfIntRea.setIpAddress(isisInterface.interfaceIpAddress()); | ||
141 | + metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask())); | ||
142 | + ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea); | ||
143 | + lsp.addTlv(ipInterReacTlv); | ||
144 | + return lsp; | ||
145 | + } | ||
146 | + | ||
147 | + public IsisHeader getHeader(IsisPduType pduType) { | ||
148 | + IsisHeader isisHeader = new IsisHeader(); | ||
149 | + isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | ||
150 | + isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value())); | ||
151 | + isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | ||
152 | + isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | ||
153 | + isisHeader.setIsisPduType(pduType.value()); | ||
154 | + isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); | ||
155 | + isisHeader.setReserved((byte) IsisConstants.RESERVED); | ||
156 | + isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS); | ||
157 | + return isisHeader; | ||
158 | + } | ||
159 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment