Chidambar babu
Committed by Thomas Vachuska

ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding

Change-Id: I4bf4b7eb26a0e2b5006b41b24d67c7f21450b11b
Showing 21 changed files with 2063 additions and 0 deletions
1 +<!--
2 + ~ Copyright 2014 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 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 + xmlns="http://maven.apache.org/POM/4.0.0"
18 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19 + <modelVersion>4.0.0</modelVersion>
20 +
21 + <parent>
22 + <groupId>org.onosproject</groupId>
23 + <artifactId>onos-ospf</artifactId>
24 + <version>1.4.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 +
28 + <artifactId>onos-ospf-protocol</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <description>ONOS Ospf controller protocol</description>
32 + <dependencies>
33 + <dependency>
34 + <groupId>org.onosproject</groupId>
35 + <artifactId>onos-ospf-api</artifactId>
36 + <version>${project.version}</version>
37 + </dependency>
38 + <dependency>
39 + <groupId>org.onosproject</groupId>
40 + <artifactId>onos-ospf-api</artifactId>
41 + <version>1.4.0-SNAPSHOT</version>
42 + </dependency>
43 + </dependencies>
44 +
45 +</project>
1 +/*
2 + * Copyright 2016 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.ospf.exceptions;
17 +
18 +/**
19 + * Defines all error codes and error sub codes.
20 + */
21 +public final class OspfErrorType {
22 +
23 + //Represents an invalid OSPF message header
24 + public static final byte MESSAGE_HEADER_ERROR = 1;
25 + //Represents an invalid OSPF message body
26 + public static final byte OSPF_MESSAGE_ERROR = 2;
27 + //Message Header error sub codes
28 + //Represents an invalid OSPF message length
29 + public static final byte BAD_MESSAGE_LENGTH = 2;
30 + //Represents an invalid OSPF message
31 + public static final byte BAD_MESSAGE = 4;
32 +
33 + /**
34 + * Creates an instance of OSPF error type.
35 + */
36 + private OspfErrorType() {
37 + }
38 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 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.ospf.exceptions;
17 +
18 +import com.google.common.base.MoreObjects;
19 +
20 +/**
21 + * Representation of a custom exception for OSPF.
22 + */
23 +public class OspfParseException extends Exception {
24 +
25 + private static final long serialVersionUID = 1L;
26 + private byte errorCode;
27 + private byte errorSubCode;
28 +
29 + /**
30 + * Creates a new OSPF exception.
31 + */
32 + public OspfParseException() {
33 + super();
34 + }
35 +
36 + /**
37 + * Creates a new OSPF 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 OspfParseException(final String message, final Throwable cause) {
43 + super(message, cause);
44 + }
45 +
46 + /**
47 + * Creates a new OSPF exception for the given message.
48 + *
49 + * @param message the detail of exception in string
50 + */
51 + public OspfParseException(final String message) {
52 + super(message);
53 + }
54 +
55 + /**
56 + * Creates a new OSPF exception from throwable instance.
57 + *
58 + * @param cause underlying cause of the error
59 + */
60 + public OspfParseException(final Throwable cause) {
61 + super(cause);
62 + }
63 +
64 + /**
65 + * Creates a new OSPF exception from error code and error sub code.
66 + *
67 + * @param errorCode error code of OSPF message
68 + * @param errorSubCode error sub code of OSPF message
69 + */
70 + public OspfParseException(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 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 OSPF exception types.
19 + */
20 +package org.onosproject.ospf.exceptions;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 ospf protocol.
19 + */
20 +package org.onosproject.ospf;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.lsa;
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.onlab.packet.Ip4Address;
23 +import org.onosproject.ospf.controller.OspfLsa;
24 +import org.onosproject.ospf.controller.OspfLsaType;
25 +import org.onosproject.ospf.protocol.util.OspfUtil;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import java.net.InetAddress;
30 +import java.util.ArrayList;
31 +import java.util.List;
32 +
33 +/**
34 + * Defines the LSA header, fields and the methods to access them.
35 + */
36 +public class LsaHeader implements OspfLsa {
37 +
38 + /*
39 + 0 1 2 3
40 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | LS age | Options | LS type |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + | Link State ID |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + | Advertising Router |
47 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 + | LS sequence number |
49 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 + | LS checksum | length |
51 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 + LSA header format
53 + REFERENCE : RFC 2328
54 + */
55 + protected static final Logger log = LoggerFactory.getLogger(LsaHeader.class);
56 + private int age;
57 + private int options;
58 + private int lsType;
59 + private long lsSequenceNo;
60 + private int lsCheckSum;
61 + private int lsPacketLen;
62 + private String linkStateId;
63 + private Ip4Address advertisingRouter;
64 +
65 + /**
66 + * Gets LSA age.
67 + *
68 + * @return LSA age
69 + */
70 + public int age() {
71 + return age;
72 + }
73 +
74 + /**
75 + * Sets LSA age.
76 + *
77 + * @param age LSA age
78 + */
79 + public void setAge(int age) {
80 + this.age = age;
81 + }
82 +
83 + /**
84 + * Gets options value.
85 + *
86 + * @return options header value
87 + */
88 + public int options() {
89 + return options;
90 + }
91 +
92 + /**
93 + * Sets options header value.
94 + *
95 + * @param options header value
96 + */
97 + public void setOptions(int options) {
98 + this.options = options;
99 + }
100 +
101 + /**
102 + * Gets LSA type.
103 + *
104 + * @return LSA type
105 + */
106 + public int lsType() {
107 + return lsType;
108 + }
109 +
110 + /**
111 + * Sets LSA type.
112 + *
113 + * @param lsType LSA type
114 + */
115 + public void setLsType(int lsType) {
116 + this.lsType = lsType;
117 + }
118 +
119 + /**
120 + * Gets link state id.
121 + *
122 + * @return linkStateId link state id
123 + */
124 + public String linkStateId() {
125 + return linkStateId;
126 + }
127 +
128 + /**
129 + * Sets link state id.
130 + *
131 + * @param linkStateId link state id
132 + */
133 + public void setLinkStateId(String linkStateId) {
134 + this.linkStateId = linkStateId;
135 + }
136 +
137 + /**
138 + * Gets advertising router IP.
139 + *
140 + * @return advertising router
141 + */
142 + public Ip4Address advertisingRouter() {
143 + return advertisingRouter;
144 + }
145 +
146 + /**
147 + * Sets advertising router.
148 + *
149 + * @param advertisingRouter advertising router
150 + */
151 + public void setAdvertisingRouter(Ip4Address advertisingRouter) {
152 + this.advertisingRouter = advertisingRouter;
153 + }
154 +
155 + /**
156 + * Gets LSA sequence number.
157 + *
158 + * @return LSA sequence number
159 + */
160 + public long lsSequenceNo() {
161 + return lsSequenceNo;
162 + }
163 +
164 + /**
165 + * Sets LSA sequence number.
166 + *
167 + * @param lsSequenceNo LSA sequence number
168 + */
169 + public void setLsSequenceNo(long lsSequenceNo) {
170 + this.lsSequenceNo = lsSequenceNo;
171 + }
172 +
173 + /**
174 + * Gets LSA check sum.
175 + *
176 + * @return lsCheckSum LSA checksum
177 + */
178 + public int lsCheckSum() {
179 + return lsCheckSum;
180 + }
181 +
182 + /**
183 + * Sets LSA checksum.
184 + *
185 + * @param lsCheckSum LSA checksum
186 + */
187 + public void setLsCheckSum(int lsCheckSum) {
188 + this.lsCheckSum = lsCheckSum;
189 + }
190 +
191 + /**
192 + * Gets lsa packet length.
193 + *
194 + * @return lsPacketLen LSA packet length
195 + */
196 + public int lsPacketLen() {
197 + return lsPacketLen;
198 + }
199 +
200 + /**
201 + * Sets LSA packet length.
202 + *
203 + * @param lsPacketLen LSA packet length
204 + */
205 + public void setLsPacketLen(int lsPacketLen) {
206 + this.lsPacketLen = lsPacketLen;
207 + }
208 +
209 + @Override
210 + public OspfLsaType getOspfLsaType() {
211 + if (lsType == OspfLsaType.ROUTER.value()) {
212 + return OspfLsaType.ROUTER;
213 + } else if (lsType == OspfLsaType.NETWORK.value()) {
214 + return OspfLsaType.NETWORK;
215 + } else if (lsType == OspfLsaType.SUMMARY.value()) {
216 + return OspfLsaType.SUMMARY;
217 + } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) {
218 + return OspfLsaType.ASBR_SUMMARY;
219 + } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) {
220 + return OspfLsaType.EXTERNAL_LSA;
221 + } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) {
222 + return OspfLsaType.LINK_LOCAL_OPAQUE_LSA;
223 + } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) {
224 + return OspfLsaType.AREA_LOCAL_OPAQUE_LSA;
225 + } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) {
226 + return OspfLsaType.AS_OPAQUE_LSA;
227 + }
228 +
229 + return OspfLsaType.UNDEFINED;
230 + }
231 +
232 + @Override
233 + public OspfLsa lsaHeader() {
234 + return this;
235 + }
236 +
237 + /**
238 + * Gets the LSA header as bytes.
239 + *
240 + * @return LSA header as bytes
241 + */
242 + public byte[] getLsaHeaderAsByteArray() {
243 + List<Byte> headerLst = new ArrayList<>();
244 + try {
245 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.age())));
246 + headerLst.add((byte) this.options());
247 + headerLst.add((byte) this.lsType());
248 + headerLst.addAll(Bytes.asList(InetAddress.getByName(this.linkStateId()).getAddress()));
249 + headerLst.addAll(Bytes.asList(this.advertisingRouter().toOctets()));
250 + headerLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.lsSequenceNo())));
251 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsCheckSum())));
252 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsPacketLen())));
253 + } catch (Exception e) {
254 + log.debug("Error::getLsaHeaderAsByteArray {}", e.getMessage());
255 + return Bytes.toArray(headerLst);
256 + }
257 + return Bytes.toArray(headerLst);
258 + }
259 +
260 + /**
261 + * Populates the header from the LSA header instance.
262 + *
263 + * @param lsaHeader LSA header instance
264 + */
265 + public void populateHeader(LsaHeader lsaHeader) {
266 + //assign all the header values
267 + this.setAge(lsaHeader.age());
268 + this.setOptions(lsaHeader.options());
269 + this.setLsType(lsaHeader.lsType());
270 + this.setLinkStateId(lsaHeader.linkStateId());
271 + this.setAdvertisingRouter(lsaHeader.advertisingRouter());
272 + this.setLsSequenceNo(lsaHeader.lsSequenceNo());
273 + this.setLsCheckSum(lsaHeader.lsCheckSum());
274 + this.setLsPacketLen(lsaHeader.lsPacketLen());
275 + }
276 +
277 + @Override
278 + public boolean equals(Object o) {
279 + if (this == o) {
280 + return true;
281 + }
282 + if (o == null || getClass() != o.getClass()) {
283 + return false;
284 + }
285 + LsaHeader that = (LsaHeader) o;
286 + return Objects.equal(age, that.age) &&
287 + Objects.equal(options, that.options) &&
288 + Objects.equal(lsType, that.lsType) &&
289 + Objects.equal(lsSequenceNo, that.lsSequenceNo) &&
290 + Objects.equal(lsCheckSum, that.lsCheckSum) &&
291 + Objects.equal(lsPacketLen, that.lsPacketLen) &&
292 + Objects.equal(linkStateId, that.linkStateId) &&
293 + Objects.equal(advertisingRouter, that.advertisingRouter);
294 + }
295 +
296 + @Override
297 + public int hashCode() {
298 + return Objects.hashCode(age, options, lsType, lsSequenceNo, lsCheckSum,
299 + lsPacketLen, linkStateId, advertisingRouter);
300 + }
301 +
302 + @Override
303 + public String toString() {
304 + return MoreObjects.toStringHelper(getClass())
305 + .omitNullValues()
306 + .add("age", age)
307 + .add("options", options)
308 + .add("lsType", lsType)
309 + .add("lsSequenceNo", lsSequenceNo)
310 + .add("lsCheckSum", lsCheckSum)
311 + .add("lsPacketLen", lsPacketLen)
312 + .add("linkStateId;", linkStateId)
313 + .add("advertisingRouter", advertisingRouter)
314 + .toString();
315 + }
316 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.lsa;
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.onosproject.ospf.protocol.util.OspfUtil;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +/**
27 + * Defines the Opaque LSA header, fields and the methods to access them.
28 + */
29 +public class OpaqueLsaHeader extends LsaHeader {
30 + /*
31 + 0 1 2 3
32 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
33 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 + | LS age | Options | 9, 10, or 11 |
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Opaque Type | Opaque ID |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Advertising Router |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | LS Sequence Number |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | LS checksum | Length |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + Opaque LSA header format
45 + REFERENCE : RFC 5250
46 + */
47 + private int opaqueId;
48 + private int opaqueType;
49 +
50 + /**
51 + * Populates the header from the lsaHeader instance.
52 + *
53 + * @param lsaHeader lsa header instance.
54 + */
55 + public void populateHeader(OpaqueLsaHeader lsaHeader) {
56 + //assign all the header values
57 + this.setAge(lsaHeader.age());
58 + this.setOptions(lsaHeader.options());
59 + this.setLsType(lsaHeader.lsType());
60 + this.setLinkStateId(lsaHeader.linkStateId());
61 + this.setAdvertisingRouter(lsaHeader.advertisingRouter());
62 + this.setLsSequenceNo(lsaHeader.lsSequenceNo());
63 + this.setLsCheckSum(lsaHeader.lsCheckSum());
64 + this.setLsPacketLen(lsaHeader.lsPacketLen());
65 + this.setOpaqueId(lsaHeader.opaqueId());
66 + this.setOpaqueType(lsaHeader.opaqueType());
67 + }
68 +
69 + /**
70 + * Gets the opaque id.
71 + *
72 + * @return opaque id
73 + */
74 + public int opaqueId() {
75 + return opaqueId;
76 + }
77 +
78 + /**
79 + * Sets the opaque id.
80 + *
81 + * @param opaqueId opaque id
82 + */
83 + public void setOpaqueId(int opaqueId) {
84 + this.opaqueId = opaqueId;
85 + }
86 +
87 + /**
88 + * Gets opaque type.
89 + *
90 + * @return opaque type
91 + */
92 + public int opaqueType() {
93 + return opaqueType;
94 + }
95 +
96 + /**
97 + * Sets opaque type.
98 + *
99 + * @param opaqueType opaque type
100 + */
101 + public void setOpaqueType(int opaqueType) {
102 + this.opaqueType = opaqueType;
103 + }
104 +
105 + /**
106 + * Gets header as byte array.
107 + *
108 + * @return header as byte array
109 + */
110 + public byte[] getOpaqueLsaHeaderAsByteArray() {
111 + List<Byte> headerLst = new ArrayList<>();
112 + try {
113 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.age())));
114 + headerLst.add((byte) this.options());
115 + headerLst.add((byte) this.lsType());
116 + headerLst.add((byte) this.opaqueType());
117 + headerLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(this.opaqueId())));
118 + headerLst.addAll(Bytes.asList(this.advertisingRouter().toOctets()));
119 + headerLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.lsSequenceNo())));
120 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsCheckSum())));
121 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsPacketLen())));
122 + } catch (Exception e) {
123 + log.debug("Error::getLsaHeaderAsByteArray {}", e.getMessage());
124 + return Bytes.toArray(headerLst);
125 + }
126 + return Bytes.toArray(headerLst);
127 + }
128 +
129 + @Override
130 + public boolean equals(Object o) {
131 + if (this == o) {
132 + return true;
133 + }
134 + if (o == null || getClass() != o.getClass()) {
135 + return false;
136 + }
137 + OpaqueLsaHeader that = (OpaqueLsaHeader) o;
138 + return Objects.equal(opaqueId, that.opaqueId) &&
139 + Objects.equal(opaqueType, that.opaqueType) &&
140 + Objects.equal(age(), that.age()) &&
141 + Objects.equal(options(), that.options()) &&
142 + Objects.equal(lsType(), that.lsType()) &&
143 + Objects.equal(lsSequenceNo(), that.lsSequenceNo()) &&
144 + Objects.equal(lsCheckSum(), that.lsCheckSum()) &&
145 + Objects.equal(lsPacketLen(), that.lsPacketLen()) &&
146 + Objects.equal(linkStateId(), that.linkStateId()) &&
147 + Objects.equal(advertisingRouter(), that.advertisingRouter());
148 + }
149 +
150 + @Override
151 + public int hashCode() {
152 + return Objects.hashCode(opaqueId, opaqueType);
153 + }
154 +
155 + @Override
156 + public String toString() {
157 + return MoreObjects.toStringHelper(getClass())
158 + .omitNullValues()
159 + .add("opaqueId", this.opaqueId)
160 + .add("opaqueType", opaqueType)
161 + .toString();
162 + }
163 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 OSPF LSA.
19 + */
20 +package org.onosproject.ospf.protocol.lsa;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.ospfpacket;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.onlab.packet.Ip4Address;
20 +import org.onosproject.ospf.exceptions.OspfParseException;
21 +import org.onosproject.ospf.protocol.util.OspfPacketType;
22 +
23 +/**
24 + * Representation of an OSPF message.
25 + */
26 +public interface OspfMessage {
27 +
28 + /**
29 + * Returns the type of OSPF message.
30 + *
31 + * @return OSPF message type
32 + */
33 + public OspfPacketType ospfMessageType();
34 +
35 + /**
36 + * Reads from ChannelBuffer and initializes the type of LSA.
37 + *
38 + * @param channelBuffer channel buffer instance
39 + * @throws OspfParseException might throws exception while parsing buffer
40 + */
41 + void readFrom(ChannelBuffer channelBuffer) throws OspfParseException;
42 +
43 + /**
44 + * Returns OSPFMessage as byte array.
45 + *
46 + * @return OSPF message as bytes
47 + */
48 + byte[] asBytes();
49 +
50 + /**
51 + * Sets the source IP address.
52 + *
53 + * @param sourceIp IP address
54 + */
55 + public void setSourceIp(Ip4Address sourceIp);
56 +
57 + /**
58 + * Gets the destination IP address.
59 + *
60 + * @return destination IP address
61 + */
62 + public Ip4Address destinationIp();
63 +
64 + /**
65 + * Sets destination IP.
66 + *
67 + * @param destinationIp destination IP address
68 + */
69 + public void setDestinationIp(Ip4Address destinationIp);
70 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.ospfpacket;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onlab.packet.Ip4Address;
21 +import org.onosproject.ospf.exceptions.OspfParseException;
22 +import org.onosproject.ospf.protocol.util.OspfPacketType;
23 +
24 +/**
25 + * Defines the OSPF Packet Header, fields and access methods.
26 + * Every OSPF packet starts with a standard 24 byte header.
27 + * This header contains all the information necessary to determine whether
28 + * the packet should be accepted for further processing
29 + */
30 +public class OspfPacketHeader implements OspfMessage {
31 +
32 + /*
33 + 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Version # | Type | Packet length |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Router ID |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Area ID |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | Checksum | AuType |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + | Authentication |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + | Authentication |
47 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 + */
49 +
50 + private int ospfVer;
51 + private int ospfType;
52 + private int ospfPackLength;
53 + private Ip4Address routerId;
54 + private Ip4Address areaId;
55 + private int checkSum;
56 + private int auType;
57 + private int authentication;
58 + private Ip4Address destinationIp;
59 + private Ip4Address sourceIp;
60 +
61 + /**
62 + * Gets the source IP.
63 + *
64 + * @return source IP address
65 + */
66 + public Ip4Address sourceIp() {
67 + return sourceIp;
68 + }
69 +
70 + /**
71 + * Sets the source IP address.
72 + *
73 + * @param sourceIp source IP address
74 + */
75 + public void setSourceIp(Ip4Address sourceIp) {
76 + this.sourceIp = sourceIp;
77 + }
78 +
79 + @Override
80 + public OspfPacketType ospfMessageType() {
81 + //default impl
82 + return null;
83 + }
84 +
85 + @Override
86 + public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
87 + //default impl
88 + }
89 +
90 + @Override
91 + public byte[] asBytes() {
92 + //default impl
93 + return new byte[0];
94 + }
95 +
96 + /**
97 + * Gets OSPF version.
98 + *
99 + * @return OSPF version
100 + */
101 + public int ospfVersion() {
102 + return ospfVer;
103 + }
104 +
105 + /**
106 + * Sets OSPF version.
107 + *
108 + * @param ospfVer OSPF version
109 + */
110 + public void setOspfVer(int ospfVer) {
111 + this.ospfVer = ospfVer;
112 + }
113 +
114 + /**
115 + * Gets OSPF packet type.
116 + *
117 + * @return OSPF packet type
118 + */
119 + public int ospfType() {
120 + return ospfType;
121 + }
122 +
123 + /**
124 + * Sets OSPF packet type.
125 + *
126 + * @param ospfType packet type
127 + */
128 + public void setOspftype(int ospfType) {
129 + this.ospfType = ospfType;
130 + }
131 +
132 + /**
133 + * Gets ospf packet length.
134 + *
135 + * @return OSPF packet length
136 + */
137 + public int ospfPacLength() {
138 + return ospfPackLength;
139 + }
140 +
141 + /**
142 + * Sets OSPF packet length.
143 + *
144 + * @param ospfPacLength packet length
145 + */
146 + public void setOspfPacLength(int ospfPacLength) {
147 + this.ospfPackLength = ospfPacLength;
148 + }
149 +
150 + /**
151 + * Gets router id.
152 + *
153 + * @return routerId
154 + */
155 + public Ip4Address routerId() {
156 + return routerId;
157 + }
158 +
159 + /**
160 + * Sets router id.
161 + *
162 + * @param routerId router id
163 + */
164 + public void setRouterId(Ip4Address routerId) {
165 + this.routerId = routerId;
166 + }
167 +
168 + /**
169 + * Gets area id.
170 + *
171 + * @return areaId area id
172 + */
173 + public Ip4Address areaId() {
174 + return areaId;
175 + }
176 +
177 + /**
178 + * Sets area id.
179 + *
180 + * @param areaId area id
181 + */
182 + public void setAreaId(Ip4Address areaId) {
183 + this.areaId = areaId;
184 + }
185 +
186 + /**
187 + * Gets checksum value.
188 + *
189 + * @return checkSum check sum value
190 + */
191 + public int checksum() {
192 + return checkSum;
193 + }
194 +
195 + /**
196 + * Sets checksum.
197 + *
198 + * @param checkSum check sum value
199 + */
200 + public void setChecksum(int checkSum) {
201 + this.checkSum = checkSum;
202 + }
203 +
204 + /**
205 + * Gets auth type.
206 + *
207 + * @return authType authentication type
208 + */
209 + public int authType() {
210 + return auType;
211 + }
212 +
213 + /**
214 + * Sets auth Type.
215 + *
216 + * @param auType authentication type
217 + */
218 + public void setAuthType(int auType) {
219 + this.auType = auType;
220 + }
221 +
222 + /**
223 + * Gets authentication.
224 + *
225 + * @return authentication
226 + */
227 + public int authentication() {
228 + return authentication;
229 + }
230 +
231 + /**
232 + * Sets authentication.
233 + *
234 + * @param authentication authentication
235 + */
236 + public void setAuthentication(int authentication) {
237 + this.authentication = authentication;
238 + }
239 +
240 + /**
241 + * Gets destination IP.
242 + *
243 + * @return destination IP
244 + */
245 + public Ip4Address destinationIp() {
246 + return destinationIp;
247 + }
248 +
249 + /**
250 + * Sets destination IP.
251 + *
252 + * @param destinationIp destination IP
253 + */
254 + public void setDestinationIp(Ip4Address destinationIp) {
255 + this.destinationIp = destinationIp;
256 + }
257 +
258 + /**
259 + * Populates the header from the packetHeader instance.
260 + *
261 + * @param ospfPacketHeader packet header instance.
262 + */
263 + public void populateHeader(OspfPacketHeader ospfPacketHeader) {
264 + this.setSourceIp(ospfPacketHeader.sourceIp());
265 + this.setOspfVer(ospfPacketHeader.ospfVersion());
266 + this.setOspftype(ospfPacketHeader.ospfType());
267 + this.setOspfPacLength(ospfPacketHeader.ospfPacLength());
268 + this.setRouterId(ospfPacketHeader.routerId());
269 + this.setAreaId(ospfPacketHeader.areaId());
270 + this.setChecksum(ospfPacketHeader.checksum());
271 + this.setAuthType(ospfPacketHeader.authType());
272 + this.setAuthentication(ospfPacketHeader.authentication());
273 + }
274 +
275 + @Override
276 + public String toString() {
277 + return MoreObjects.toStringHelper(getClass())
278 + .omitNullValues()
279 + .add("ospfVersion", ospfVer)
280 + .add("ospfType", ospfType)
281 + .add("ospfPackLength", ospfPackLength)
282 + .add("routerId", routerId)
283 + .add("areaId", areaId)
284 + .add("checkSum", checkSum)
285 + .add("auType", auType)
286 + .add("authentication", authentication)
287 + .add("destinationIP", destinationIp)
288 + .toString();
289 + }
290 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 different types of OSPF Packets.
19 + */
20 +package org.onosproject.ospf.protocol.ospfpacket;
1 +/*
2 + * Copyright 2016 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 OSPF protocol..
19 + */
20 +package org.onosproject.ospf.protocol;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.util;
17 +
18 +/**
19 + * Representation of an OSPF Interface states.
20 + */
21 +public enum OspfInterfaceState {
22 +
23 + DOWN(1),
24 + LOOPBACK(2),
25 + WAITING(3),
26 + POINT2POINT(4),
27 + DROTHER(5),
28 + BDR(6),
29 + DR(7);
30 +
31 + private int value;
32 +
33 + /**
34 + * Creates an instance of Interface State.
35 + *
36 + * @param value Interface State value
37 + */
38 + OspfInterfaceState(int value) {
39 + this.value = value;
40 + }
41 +
42 + /**
43 + * Gets value for Interface State.
44 + *
45 + * @return value Interface State
46 + */
47 + public int value() {
48 + return value;
49 + }
50 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.util;
17 +
18 +/**
19 + * Representation of different OSPF packet types.
20 + */
21 +public enum OspfPacketType {
22 +
23 + HELLO(1),
24 + DD(2),
25 + LSREQUEST(3),
26 + LSUPDATE(4),
27 + LSAACK(5);
28 +
29 + private int value;
30 +
31 + /**
32 + * Creates instance of OSPF packet types.
33 + *
34 + * @param value
35 + */
36 + OspfPacketType(int value) {
37 + this.value = value;
38 + }
39 +
40 + /**
41 + * Gets the value.
42 + *
43 + * @return value
44 + */
45 + public int value() {
46 + return value;
47 + }
48 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.util;
17 +
18 +/**
19 + * Representation of an OSPF configuration parameters and constants.
20 + */
21 +public final class OspfParameters {
22 +
23 + public static final int LSREFRESHTIME = 1800; //max time between updates;
24 + public static final int MINLSINTERVAL = 5; // set to 5 second
25 + public static final int MINLSARRIVAL = 1; // set to 1 second
26 + public static final int MAXAGE = 3600; // set to 1 hour in seconds
27 + public static final int CHECKAGE = 300; // set to 5 mins
28 + public static final int MAXAGEDIFF = 900; // set to 15 mins
29 + public static final long MAXSEQUENCENUMBER = 2147483647;
30 + public static final long STARTLSSEQUENCENUM = -2147483647;
31 + public static final int AGECOUNTER = 1;
32 + public static final String VERIFYCHECKSUM = "verifyChecksum";
33 + public static final String REFRESHLSA = "refreshLsa";
34 + public static final String MAXAGELSA = "maxAgeLsa";
35 + public static final int START_NOW = 0;
36 + public static final int TRAFFIC_ENGINEERING = 1;
37 + public static final int INITIAL_BANDWIDTH = 12500000;
38 + public static final int ROUTER = 1;
39 + public static final int NETWORK = 2;
40 + public static final int SUMMARY = 3;
41 + public static final int ASBR_SUMMARY = 4;
42 + public static final int EXTERNAL_LSA = 5;
43 + public static final int LINK_LOCAL_OPAQUE_LSA = 9;
44 + public static final int AREA_LOCAL_OPAQUE_LSA = 10;
45 + public static final int AS_OPAQUE_LSA = 11;
46 + public static final int HELLO = 1;
47 + public static final int DD = 2;
48 + public static final int LSREQUEST = 3;
49 + public static final int LSUPDATE = 4;
50 + public static final int LSACK = 5;
51 + public static final int INFTRA_NS_DELAY = 1;
52 + public static final int BDR = 6;
53 + public static final int DR = 7;
54 + public static final String OPAQUE_ENABLED_OPTION_VALUE = "01000010";
55 +
56 + private OspfParameters() {
57 + }
58 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 ospf protocol utilities.
19 + */
20 +package org.onosproject.ospf.protocol.util;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.lsa;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onosproject.ospf.controller.OspfLsaType;
23 +
24 +import static org.hamcrest.MatcherAssert.assertThat;
25 +import static org.hamcrest.Matchers.*;
26 +
27 +/**
28 + * Unit test class for LsaHeader.
29 + */
30 +public class LsaHeaderTest {
31 +
32 + private LsaHeader lsaHeader;
33 + private int result;
34 + private Ip4Address result1;
35 + private long result2;
36 + private OspfLsaType ospflsaType;
37 + private LsaHeader header;
38 + private byte[] result3;
39 + private LsaHeader lsaHeader1;
40 + private String result4;
41 +
42 + @Before
43 + public void setUp() throws Exception {
44 + lsaHeader = new LsaHeader();
45 + }
46 +
47 + @After
48 + public void tearDown() throws Exception {
49 + lsaHeader = null;
50 + result1 = null;
51 + ospflsaType = null;
52 + header = null;
53 + result3 = null;
54 + lsaHeader1 = null;
55 + }
56 +
57 + /**
58 + * Tests equals() method.
59 + */
60 + @Test
61 + public void testEquals() throws Exception {
62 + assertThat(lsaHeader.equals(new LsaHeader()), is(true));
63 + }
64 +
65 + /**
66 + * Tests hashCode() method.
67 + */
68 + @Test
69 + public void testHashCode() throws Exception {
70 + result = lsaHeader.hashCode();
71 + assertThat(result, is(notNullValue()));
72 + }
73 +
74 + /**
75 + * Tests age() getter method.
76 + */
77 + @Test
78 + public void testGetAge() throws Exception {
79 + lsaHeader.setAge(10);
80 + result = lsaHeader.age();
81 + assertThat(result, is(10));
82 + }
83 +
84 + /**
85 + * Tests age() setter method.
86 + */
87 + @Test
88 + public void testSetAge() throws Exception {
89 + lsaHeader.setAge(10);
90 + result = lsaHeader.age();
91 + assertThat(result, is(10));
92 + }
93 +
94 + /**
95 + * Tests options() getter method.
96 + */
97 + @Test
98 + public void testGetOptions() throws Exception {
99 + lsaHeader.setOptions(2);
100 + result = lsaHeader.options();
101 + assertThat(result, is(2));
102 + }
103 +
104 + /**
105 + * Tests options() setter method.
106 + */
107 + @Test
108 + public void testSetOptions() throws Exception {
109 + lsaHeader.setOptions(2);
110 + result = lsaHeader.options();
111 + assertThat(result, is(2));
112 + }
113 +
114 + /**
115 + * Tests lsType() getter method.
116 + */
117 + @Test
118 + public void testGetLsType() throws Exception {
119 + lsaHeader.setLsType(1);
120 + result = lsaHeader.lsType();
121 + assertThat(result, is(1));
122 + }
123 +
124 + /**
125 + * Tests lsType() setter method.
126 + */
127 + @Test
128 + public void testSetLsType() throws Exception {
129 + lsaHeader.setLsType(1);
130 + result = lsaHeader.lsType();
131 + assertThat(result, is(1));
132 + }
133 +
134 + /**
135 + * Tests linkStateId() getter method.
136 + */
137 + @Test
138 + public void testGetLinkStateId() throws Exception {
139 + lsaHeader.setLinkStateId("10.226.165.164");
140 + result4 = lsaHeader.linkStateId();
141 + assertThat(result4, is("10.226.165.164"));
142 + }
143 +
144 + /**
145 + * Tests linkStateId() setter method.
146 + */
147 + @Test
148 + public void testSetLinkStateId() throws Exception {
149 + lsaHeader.setLinkStateId("10.226.165.164");
150 + result4 = lsaHeader.linkStateId();
151 + assertThat(result4, is("10.226.165.164"));
152 + }
153 +
154 + /**
155 + * Tests advertisingRouter() setter method.
156 + */
157 + @Test
158 + public void testGetAdvertisingRouter() throws Exception {
159 + lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164"));
160 + result1 = lsaHeader.advertisingRouter();
161 + assertThat(result1, is(Ip4Address.valueOf("10.226.165.164")));
162 + }
163 +
164 + /**
165 + * Tests advertisingRouter() setter method.
166 + */
167 + @Test
168 + public void testSetAdvertisingRouter() throws Exception {
169 + lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164"));
170 + result1 = lsaHeader.advertisingRouter();
171 + assertThat(result1, is(Ip4Address.valueOf("10.226.165.164")));
172 + }
173 +
174 + /**
175 + * Tests lsSequenceNo() getter method.
176 + */
177 + @Test
178 + public void testGetLsSequenceNo() throws Exception {
179 + lsaHeader.setLsSequenceNo(222);
180 + result2 = lsaHeader.lsSequenceNo();
181 + assertThat(result2, is(222L));
182 + }
183 +
184 + /**
185 + * Tests lsSequenceNo() setter method.
186 + */
187 + @Test
188 + public void testSetLsSequenceNo() throws Exception {
189 + lsaHeader.setLsSequenceNo(222);
190 + result2 = lsaHeader.lsSequenceNo();
191 + assertThat(result2, is(222L));
192 + }
193 +
194 + /**
195 + * Tests lsCheckSum() getter method.
196 + */
197 + @Test
198 + public void testGetLsChecksum() throws Exception {
199 + lsaHeader.setLsCheckSum(2);
200 + result = lsaHeader.lsCheckSum();
201 + assertThat(result, is(2));
202 + }
203 +
204 + /**
205 + * Tests lsCheckSum() setter method.
206 + */
207 + @Test
208 + public void testSetLsChecksum() throws Exception {
209 + lsaHeader.setLsCheckSum(2);
210 + result = lsaHeader.lsCheckSum();
211 + assertThat(result, is(2));
212 + }
213 +
214 + /**
215 + * Tests lsPacketLen() getter method.
216 + */
217 + @Test
218 + public void testGetLsPacketLen() throws Exception {
219 + lsaHeader.setLsPacketLen(48);
220 + result = lsaHeader.lsPacketLen();
221 + assertThat(result, is(48));
222 + }
223 +
224 + /**
225 + * Tests lsPacketLen() getter method.
226 + */
227 + @Test
228 + public void testSetLsPacketLen() throws Exception {
229 + lsaHeader.setLsPacketLen(48);
230 + result = lsaHeader.lsPacketLen();
231 + assertThat(result, is(48));
232 + }
233 +
234 + /**
235 + * Tests getOspfLsaType() getter method.
236 + */
237 + @Test
238 + public void testGetOspfLsaType() throws Exception {
239 + lsaHeader.setLsType(1);
240 + ospflsaType = lsaHeader.getOspfLsaType();
241 + assertThat(ospflsaType, is(notNullValue()));
242 + assertThat(ospflsaType, is(OspfLsaType.ROUTER));
243 + lsaHeader.setLsType(2);
244 + ospflsaType = lsaHeader.getOspfLsaType();
245 + assertThat(ospflsaType, is(notNullValue()));
246 + assertThat(ospflsaType, is(OspfLsaType.NETWORK));
247 + lsaHeader.setLsType(3);
248 + ospflsaType = lsaHeader.getOspfLsaType();
249 + assertThat(ospflsaType, is(notNullValue()));
250 + assertThat(ospflsaType, is(OspfLsaType.SUMMARY));
251 + lsaHeader.setLsType(4);
252 + ospflsaType = lsaHeader.getOspfLsaType();
253 + assertThat(ospflsaType, is(notNullValue()));
254 + assertThat(ospflsaType, is(OspfLsaType.ASBR_SUMMARY));
255 + lsaHeader.setLsType(5);
256 + ospflsaType = lsaHeader.getOspfLsaType();
257 + assertThat(ospflsaType, is(notNullValue()));
258 + assertThat(ospflsaType, is(OspfLsaType.EXTERNAL_LSA));
259 + lsaHeader.setLsType(6);
260 + ospflsaType = lsaHeader.getOspfLsaType();
261 + assertThat(ospflsaType, is(notNullValue()));
262 + assertThat(ospflsaType, is(OspfLsaType.UNDEFINED));
263 + }
264 +
265 + /**
266 + * Tests lsaHeader() getter method.
267 + */
268 + @Test
269 + public void testGetLsaHeader() throws Exception {
270 + header = (LsaHeader) lsaHeader.lsaHeader();
271 + assertThat(header, instanceOf(LsaHeader.class));
272 + }
273 +
274 + /**
275 + * Tests getLsaHeaderAsByteArray() method.
276 + */
277 + @Test
278 + public void testGetLsaHeaderAsByteArray() throws Exception {
279 + result3 = lsaHeader.getLsaHeaderAsByteArray();
280 + assertThat(result3, is(notNullValue()));
281 + }
282 +
283 + /**
284 + * Tests to string method.
285 + */
286 + @Test
287 + public void testToString() throws Exception {
288 + assertThat(lsaHeader.toString(), is(notNullValue()));
289 + }
290 +
291 + /**
292 + * Tests populateHeader() method.
293 + */
294 + @Test
295 + public void testPopulateHeader() throws Exception {
296 + lsaHeader1 = new LsaHeader();
297 + lsaHeader1.setLsPacketLen(10);
298 + lsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
299 + lsaHeader1.setOptions(2);
300 + lsaHeader1.setAge(20);
301 + lsaHeader1.setLsType(3);
302 + lsaHeader1.setLinkStateId("2.2.2.2");
303 + lsaHeader1.setLsCheckSum(1234);
304 + lsaHeader1.setLsSequenceNo(456789);
305 + lsaHeader.populateHeader(lsaHeader1);
306 + assertThat(lsaHeader1, is(notNullValue()));
307 + }
308 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.lsa;
17 +
18 +import org.hamcrest.Matchers;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onlab.packet.Ip4Address;
23 +
24 +import static org.hamcrest.CoreMatchers.notNullValue;
25 +import static org.hamcrest.Matchers.is;
26 +import static org.junit.Assert.assertThat;
27 +
28 +/**
29 + * Unit test class for OpaqueLsaHeader.
30 + */
31 +public class OpaqueLsaHeaderTest {
32 +
33 + private OpaqueLsaHeader opaqueHeader;
34 + private OpaqueLsaHeader opaqueLsaHeader1;
35 + private int num;
36 + private byte[] result;
37 + private int result1;
38 +
39 + @Before
40 + public void setUp() throws Exception {
41 + opaqueHeader = new OpaqueLsaHeader();
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + opaqueHeader = null;
47 + opaqueLsaHeader1 = null;
48 + result = null;
49 + }
50 +
51 + /**
52 + * Tests populateHeader() method.
53 + */
54 + @Test
55 + public void testPopulateHeader() throws Exception {
56 + opaqueLsaHeader1 = new OpaqueLsaHeader();
57 + opaqueLsaHeader1.setLsPacketLen(10);
58 + opaqueLsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
59 + opaqueLsaHeader1.setOptions(2);
60 + opaqueLsaHeader1.setAge(20);
61 + opaqueLsaHeader1.setLsType(3);
62 + opaqueLsaHeader1.setOpaqueId(1);
63 + opaqueLsaHeader1.setOpaqueType(3);
64 + opaqueLsaHeader1.setLsCheckSum(1234);
65 + opaqueLsaHeader1.setLsSequenceNo(456789);
66 + opaqueLsaHeader1.populateHeader(opaqueLsaHeader1);
67 + assertThat(opaqueLsaHeader1, is(notNullValue()));
68 + }
69 +
70 + /**
71 + * Tests opaqueId() getter method.
72 + */
73 + @Test
74 + public void testGetOpaqueId() throws Exception {
75 + opaqueHeader.setOpaqueId(1);
76 + num = opaqueHeader.opaqueId();
77 + assertThat(num, is(1));
78 + }
79 +
80 + /**
81 + * Tests opaqueId() setter method.
82 + */
83 + @Test
84 + public void testSetOpaqueId() throws Exception {
85 + opaqueHeader.setOpaqueId(1);
86 + num = opaqueHeader.opaqueId();
87 + assertThat(num, is(1));
88 + }
89 +
90 + /**
91 + * Tests opaqueType() getter method.
92 + */
93 + @Test
94 + public void testGetOpaqueType() throws Exception {
95 + opaqueHeader.setOpaqueType(1);
96 + num = opaqueHeader.opaqueType();
97 + assertThat(num, is(1));
98 + }
99 +
100 + /**
101 + * Tests opaqueType() setter method.
102 + */
103 + @Test
104 + public void testSetOpaqueType() throws Exception {
105 + opaqueHeader.setOpaqueType(1);
106 + num = opaqueHeader.opaqueType();
107 + assertThat(num, is(1));
108 + }
109 +
110 + /**
111 + * Tests getOpaqueLsaHeaderAsByteArray() method.
112 + */
113 + @Test
114 + public void testGetOpaqueLsaHeaderAsByteArray() throws Exception {
115 + result = opaqueHeader.getOpaqueLsaHeaderAsByteArray();
116 + assertThat(result, is(notNullValue()));
117 + }
118 +
119 + /**
120 + * Tests to string method.
121 + */
122 + @Test
123 + public void testToString() throws Exception {
124 + assertThat(opaqueHeader.toString(), is(notNullValue()));
125 + }
126 +
127 + /**
128 + * Tests hashCode() method.
129 + */
130 + @Test
131 + public void testHashcode() throws Exception {
132 +
133 + result1 = opaqueHeader.hashCode();
134 + assertThat(result1, is(Matchers.notNullValue()));
135 +
136 + }
137 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.protocol.ospfpacket;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Assert;
22 +import org.junit.Before;
23 +import org.junit.Test;
24 +import org.onlab.packet.Ip4Address;
25 +
26 +import static org.hamcrest.CoreMatchers.*;
27 +import static org.junit.Assert.assertThat;
28 +
29 +/**
30 + * Unit test class for OspfPacketHeader.
31 + */
32 +public class OspfPacketHeaderTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 0};
35 + private OspfPacketHeader ospfPacketHeader;
36 + private ChannelBuffer channelBuffer;
37 + private byte[] result2;
38 + private int result;
39 + private Ip4Address result1;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + ospfPacketHeader = new OspfPacketHeader();
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + ospfPacketHeader = null;
49 + ospfPacketHeader = null;
50 + channelBuffer = null;
51 + result2 = null;
52 + result1 = null;
53 + }
54 +
55 + /**
56 + * Tests sourceIp() getter method.
57 + */
58 + @Test
59 + public void testGetSourceIP() throws Exception {
60 + ospfPacketHeader.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
61 + assertThat(ospfPacketHeader.sourceIp(), is(Ip4Address.valueOf("1.1.1.1")));
62 + }
63 +
64 + /**
65 + * Tests sourceIp() setter method.
66 + */
67 + @Test
68 + public void testSetSourceIP() throws Exception {
69 + ospfPacketHeader.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
70 + assertThat(result, is(notNullValue()));
71 + assertThat(ospfPacketHeader.sourceIp(), is(Ip4Address.valueOf("1.1.1.1")));
72 + }
73 +
74 + /**
75 + * Tests ospfMessageType() getter method.
76 + */
77 + @Test
78 + public void testGetOspfMessageType() throws Exception {
79 + assertThat(ospfPacketHeader.ospfMessageType(), nullValue());
80 + }
81 +
82 + /**
83 + * Tests readFrom() method.
84 + */
85 + @Test
86 + public void testReadFrom() throws Exception {
87 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
88 + ospfPacketHeader.readFrom(channelBuffer);
89 + assertThat(ospfPacketHeader, is(notNullValue()));
90 + }
91 +
92 + /**
93 + * Tests asBytes() method.
94 + */
95 + @Test
96 + public void testAsBytes() throws Exception {
97 + result2 = ospfPacketHeader.asBytes();
98 + assertThat(result2, is(notNullValue()));
99 + }
100 +
101 + /**
102 + * Tests ospfVersion() getter method.
103 + */
104 + @Test
105 + public void testGetOspfVer() throws Exception {
106 + ospfPacketHeader.setOspfVer(2);
107 + result = ospfPacketHeader.ospfVersion();
108 + assertThat(result, is(notNullValue()));
109 + assertThat(result, is(2));
110 + }
111 +
112 + /**
113 + * Tests ospfVersion() setter method.
114 + */
115 + @Test
116 + public void testSetOspfVer() throws Exception {
117 + ospfPacketHeader.setOspfVer(2);
118 + result = ospfPacketHeader.ospfVersion();
119 + assertThat(result, is(notNullValue()));
120 + assertThat(result, is(2));
121 + }
122 +
123 + /**
124 + * Tests ospfType() getter method.
125 + */
126 + @Test
127 + public void testGetOspfType() throws Exception {
128 + ospfPacketHeader.setOspftype(3);
129 + result = ospfPacketHeader.ospfType();
130 + assertThat(result, is(notNullValue()));
131 + assertThat(result, is(3));
132 + }
133 +
134 + /**
135 + * Tests ospfType() setter method.
136 + */
137 + @Test
138 + public void testSetOspfType() throws Exception {
139 + ospfPacketHeader.setOspftype(3);
140 + result = ospfPacketHeader.ospfType();
141 + assertThat(result, is(notNullValue()));
142 + assertThat(result, is(3));
143 + }
144 +
145 + /**
146 + * Tests ospfPacLength() getter method.
147 + */
148 + @Test
149 + public void testGetOspfPacLength() throws Exception {
150 + ospfPacketHeader.setOspfPacLength(3);
151 + result = ospfPacketHeader.ospfPacLength();
152 + assertThat(result, is(notNullValue()));
153 + assertThat(result, is(3));
154 + }
155 +
156 + /**
157 + * Tests ospfPacLength() setter method.
158 + */
159 + @Test
160 + public void testSetOspfPacLength() throws Exception {
161 + ospfPacketHeader.setOspfPacLength(3);
162 + int result = ospfPacketHeader.ospfPacLength();
163 + assertThat(result, is(notNullValue()));
164 + assertThat(result, is(3));
165 + }
166 +
167 + /**
168 + * Tests routerId()getter method.
169 + */
170 + @Test
171 + public void testGetRouterId() throws Exception {
172 +
173 + ospfPacketHeader.setRouterId(Ip4Address.valueOf("1.1.1.1"));
174 + result1 = ospfPacketHeader.routerId();
175 + assertThat(result1, is(notNullValue()));
176 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
177 +
178 + }
179 +
180 + /**
181 + * Tests routerId() setter method.
182 + */
183 + @Test
184 + public void testSetRouterId() throws Exception {
185 + ospfPacketHeader.setRouterId(Ip4Address.valueOf("1.1.1.1"));
186 + result1 = ospfPacketHeader.routerId();
187 + assertThat(result1, is(notNullValue()));
188 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
189 + }
190 +
191 + /**
192 + * Tests areaId() getter method.
193 + */
194 + @Test
195 + public void testGetAreaId() throws Exception {
196 + ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
197 + result1 = ospfPacketHeader.areaId();
198 + assertThat(result1, is(notNullValue()));
199 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
200 + }
201 +
202 + /**
203 + * Tests areaId() setter method.
204 + */
205 + @Test
206 + public void testSetAreaId() throws Exception {
207 + ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
208 + result1 = ospfPacketHeader.areaId();
209 + assertThat(result1, is(notNullValue()));
210 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
211 + }
212 +
213 + /**
214 + * Tests checksum() getter method.
215 + */
216 + @Test
217 + public void testGetChecksum() throws Exception {
218 + ospfPacketHeader.setChecksum(3);
219 + result = ospfPacketHeader.checksum();
220 + assertThat(result, is(notNullValue()));
221 + assertThat(result, is(3));
222 + }
223 +
224 + /**
225 + * Tests checksum() setter method.
226 + */
227 + @Test
228 + public void testSetChecksum() throws Exception {
229 + ospfPacketHeader.setChecksum(3);
230 + result = ospfPacketHeader.checksum();
231 + assertThat(result, is(notNullValue()));
232 + assertThat(result, is(3));
233 + }
234 +
235 + /**
236 + * Tests authType() getter method.
237 + */
238 + @Test
239 + public void testGetAutype() throws Exception {
240 + ospfPacketHeader.setAuthType(3);
241 + result = ospfPacketHeader.authType();
242 + Assert.assertNotNull(result);
243 + Assert.assertEquals(3, result);
244 + }
245 +
246 + /**
247 + * Tests authType() setter method.
248 + */
249 + @Test
250 + public void testSetAutype() throws Exception {
251 + ospfPacketHeader.setAuthType(3);
252 + result = ospfPacketHeader.authType();
253 + assertThat(result, is(notNullValue()));
254 + assertThat(result, is(3));
255 + }
256 +
257 + /**
258 + * Tests authentication() getter method.
259 + */
260 + @Test
261 + public void testGetAuthentication() throws Exception {
262 + ospfPacketHeader.setAuthentication(3);
263 + result = ospfPacketHeader.authentication();
264 + assertThat(result, is(notNullValue()));
265 + assertThat(result, is(3));
266 + }
267 +
268 + /**
269 + * Tests authentication() setter method.
270 + */
271 + @Test
272 + public void testSetAuthentication() throws Exception {
273 + ospfPacketHeader.setAuthentication(3);
274 + result = ospfPacketHeader.authentication();
275 + assertThat(result, is(notNullValue()));
276 + assertThat(result, is(3));
277 + }
278 +
279 + /**
280 + * Tests destinationIp() getter method.
281 + */
282 + @Test
283 + public void testGetDestinationIP() throws Exception {
284 + ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("1.1.1.1"));
285 + result1 = ospfPacketHeader.destinationIp();
286 + assertThat(result1, is(notNullValue()));
287 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
288 + }
289 +
290 + /**
291 + * Tests destinationIp() setter method.
292 + */
293 + @Test
294 + public void testSetDestinationIP() throws Exception {
295 + ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("1.1.1.1"));
296 + result1 = ospfPacketHeader.destinationIp();
297 + assertThat(result1, is(notNullValue()));
298 + assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
299 + }
300 +
301 + /**
302 + * Tests to string method.
303 + */
304 + @Test
305 + public void testToString() throws Exception {
306 + assertThat(ospfPacketHeader.toString(), is(notNullValue()));
307 + }
308 +
309 + /**
310 + * Tests populateHeader() method.
311 + */
312 + @Test
313 + public void testPopulateHeader() throws Exception {
314 + ospfPacketHeader.populateHeader(new OspfPacketHeader());
315 + assertThat(ospfPacketHeader, is(notNullValue()));
316 + }
317 +
318 +}
...\ No newline at end of file ...\ No newline at end of file