blob: 25e2ac6763a2b1e566973c7387ace740978b3bb1 [file] [log] [blame]
sunish vk1857c422016-02-17 18:05:52 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sunish vk1857c422016-02-17 18:05:52 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ospf.controller.impl;
17
18
19import org.easymock.EasyMock;
20import org.jboss.netty.channel.Channel;
21import org.junit.After;
sunish vk1857c422016-02-17 18:05:52 +053022import org.junit.Before;
23import org.junit.Test;
24import org.onlab.packet.Ip4Address;
sunishvkf7c56552016-07-18 16:02:39 +053025import org.onosproject.ospf.controller.OspfAreaAddressRange;
sunish vk1857c422016-02-17 18:05:52 +053026import org.onosproject.ospf.controller.OspfInterface;
27import org.onosproject.ospf.controller.OspfLsa;
28import org.onosproject.ospf.controller.OspfLsaType;
sunishvkf7c56552016-07-18 16:02:39 +053029import org.onosproject.ospf.controller.OspfMessage;
sunish vk1857c422016-02-17 18:05:52 +053030import org.onosproject.ospf.controller.OspfNeighborState;
31import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
sunishvkf7c56552016-07-18 16:02:39 +053032import org.onosproject.ospf.controller.area.OspfAreaAddressRangeImpl;
sunish vk1857c422016-02-17 18:05:52 +053033import org.onosproject.ospf.controller.area.OspfAreaImpl;
34import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
35import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
36import org.onosproject.ospf.controller.lsdb.LsdbAgeImpl;
sunishvkf7c56552016-07-18 16:02:39 +053037import org.onosproject.ospf.controller.util.OspfInterfaceType;
sunish vk1857c422016-02-17 18:05:52 +053038import org.onosproject.ospf.protocol.lsa.LsaHeader;
sunishvkf7c56552016-07-18 16:02:39 +053039import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
sunish vk1857c422016-02-17 18:05:52 +053040import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
sunishvkf7c56552016-07-18 16:02:39 +053041import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
sunish vk1857c422016-02-17 18:05:52 +053042import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
sunish vk1857c422016-02-17 18:05:52 +053043import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
44import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
45import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
46import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
47import org.onosproject.ospf.protocol.util.ChecksumCalculator;
sunishvkf7c56552016-07-18 16:02:39 +053048import org.onosproject.ospf.protocol.util.OspfInterfaceState;
sunish vk1857c422016-02-17 18:05:52 +053049import org.onosproject.ospf.protocol.util.OspfUtil;
50
51import java.net.SocketAddress;
sunishvkf7c56552016-07-18 16:02:39 +053052import java.net.UnknownHostException;
sunish vk1857c422016-02-17 18:05:52 +053053import java.util.ArrayList;
54import java.util.List;
55
56import static org.hamcrest.CoreMatchers.is;
57import static org.hamcrest.CoreMatchers.notNullValue;
58import static org.hamcrest.MatcherAssert.assertThat;
59
60/**
61 * Unit test class for OspfNbrImpl.
62 */
63public class OspfNbrImplTest {
sunishvkf7c56552016-07-18 16:02:39 +053064 private List<OspfAreaAddressRange> addressRanges = new ArrayList();
sunish vk1857c422016-02-17 18:05:52 +053065 private OspfNbrImpl ospfNbr;
sunishvkf7c56552016-07-18 16:02:39 +053066 private OspfNbrImpl ospfNbr1;
sunish vk1857c422016-02-17 18:05:52 +053067 private OspfInterfaceImpl ospfInterface;
68 private OspfAreaImpl ospfArea;
69 private OspfInterfaceImpl ospfInterface1;
70 private OspfInterfaceImpl ospfInterface2;
sunishvkf7c56552016-07-18 16:02:39 +053071 private List<OspfInterface> ospfInterfaces = new ArrayList();
sunish vk1857c422016-02-17 18:05:52 +053072 private List<OspfLsa> ospfLsaList;
73 private Channel channel;
74 private Channel channel1;
75 private Channel channel2;
76 private OspfMessage ospfMessage;
77 private TopologyForDeviceAndLink topologyForDeviceAndLink;
sunishvkf7c56552016-07-18 16:02:39 +053078 private LsaHeader lsaHeader;
sunish vk1857c422016-02-17 18:05:52 +053079
80 @Before
81 public void setUp() throws Exception {
sunishvkf7c56552016-07-18 16:02:39 +053082 lsaHeader = new LsaHeader();
83 lsaHeader.setLsType(OspfLsaType.ROUTER.value());
84 RouterLsa routerLsa = new RouterLsa(lsaHeader);
85 routerLsa.setLsType(OspfLsaType.ROUTER.value());
sunish vk1857c422016-02-17 18:05:52 +053086 ospfInterface = new OspfInterfaceImpl();
87 ospfInterface.setInterfaceType(2);
sunishvkf7c56552016-07-18 16:02:39 +053088 ospfInterface.setInterfaceIndex(1);
sunish vk1857c422016-02-17 18:05:52 +053089 ospfInterface.setRouterDeadIntervalTime(30);
90 ospfInterface.setReTransmitInterval(30);
91 ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
92 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
sunishvkf7c56552016-07-18 16:02:39 +053093 ospfInterface.setState(OspfInterfaceState.POINT2POINT);
94 ospfArea = createOspfArea();
95 ospfArea.addLsa(routerLsa, true, ospfInterface);
96 ospfInterface.setOspfArea(ospfArea);
sunish vk1857c422016-02-17 18:05:52 +053097 ospfInterface1 = new OspfInterfaceImpl();
98 ospfInterface1.setInterfaceType(2);
sunishvkf7c56552016-07-18 16:02:39 +053099 ospfInterface1.setInterfaceIndex(1);
sunish vk1857c422016-02-17 18:05:52 +0530100 ospfInterface1.setRouterDeadIntervalTime(30);
101 ospfInterface1.setReTransmitInterval(30);
102 ospfInterface1.setDr(Ip4Address.valueOf("7.7.7.7"));
103 ospfInterface1.setIpAddress(Ip4Address.valueOf("7.7.7.7"));
sunishvkf7c56552016-07-18 16:02:39 +0530104 ospfInterface1.setState(OspfInterfaceState.DOWN);
105 ospfInterface1.setOspfArea(ospfArea);
sunish vk1857c422016-02-17 18:05:52 +0530106 ospfInterface2 = new OspfInterfaceImpl();
107 ospfInterface2.setInterfaceType(2);
sunishvkf7c56552016-07-18 16:02:39 +0530108 ospfInterface2.setInterfaceIndex(1);
sunish vk1857c422016-02-17 18:05:52 +0530109 ospfInterface2.setRouterDeadIntervalTime(30);
110 ospfInterface2.setReTransmitInterval(30);
111 ospfInterface2.setDr(Ip4Address.valueOf("6.6.6.6"));
112 ospfInterface2.setIpAddress(Ip4Address.valueOf("6.6.6.6"));
sunishvkf7c56552016-07-18 16:02:39 +0530113 ospfInterface2.setOspfArea(ospfArea);
114 ospfInterface1.setState(OspfInterfaceState.DR);
sunish vk1857c422016-02-17 18:05:52 +0530115 ospfInterfaces = new ArrayList();
116 ospfInterfaces.add(ospfInterface);
117 ospfInterfaces.add(ospfInterface1);
118 ospfInterfaces.add(ospfInterface2);
sunishvkf7c56552016-07-18 16:02:39 +0530119 ospfArea.setOspfInterfaceList(ospfInterfaces);
120 ospfInterface.setState(OspfInterfaceState.POINT2POINT);
sunish vk1857c422016-02-17 18:05:52 +0530121 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
122 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
123 ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
124 Ip4Address.valueOf("2.2.2.2"), 2,
sunish vkaa48da82016-03-02 23:17:06 +0530125 topologyForDeviceAndLink);
sunish vk1857c422016-02-17 18:05:52 +0530126 }
127
128 @After
129 public void tearDown() throws Exception {
130 ospfNbr = null;
131 ospfArea = null;
132 ospfInterface = null;
133 ospfLsaList = null;
134 channel = null;
135 channel1 = null;
136 channel2 = null;
137 ospfMessage = null;
138
139 }
140
141 /**
142 * Tests neighborIpAddr() method.
143 */
144 @Test
145 public void testNeighborIpAddr() throws Exception {
146 assertThat(ospfNbr.neighborIpAddr(), is(notNullValue()));
147 }
148
149 /**
150 * Tests isOpaqueCapable() getter method.
151 */
152 @Test
153 public void testIsOpaqueCapable() throws Exception {
154 assertThat(ospfNbr.isOpaqueCapable(), is(false));
155 }
156
157 /**
158 * Tests isOpaqueCapable() setter method.
159 */
160 @Test
161 public void testSetIsOpaqueCapable() throws Exception {
162 ospfNbr.setIsOpaqueCapable(true);
163 assertThat(ospfNbr.isOpaqueCapable(), is(true));
164 }
165
166 /**
167 * Tests oneWayReceived() method.
168 */
169 @Test
170 public void testOneWayReceived() throws Exception {
171 ospfMessage = new HelloPacket();
172 ospfNbr.setState(OspfNeighborState.ATTEMPT);
173 channel = EasyMock.createMock(Channel.class);
174 ospfNbr.oneWayReceived(ospfMessage, channel);
175 channel1 = EasyMock.createMock(Channel.class);
176 ospfNbr.setState(OspfNeighborState.DOWN);
177 ospfNbr.oneWayReceived(ospfMessage, channel1);
178 channel2 = EasyMock.createMock(Channel.class);
179 ospfNbr.setState(OspfNeighborState.TWOWAY);
180 ospfNbr.oneWayReceived(ospfMessage, channel2);
181 assertThat(ospfNbr, is(notNullValue()));
182 }
183
184 /**
185 * Tests twoWayReceived() method.
186 */
187 @Test(expected = Exception.class)
188 public void testTwoWayReceived() throws Exception {
189 ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
190 ospfMessage = new HelloPacket();
191 ospfNbr.setState(OspfNeighborState.ATTEMPT);
192 ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
193 ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
194 channel = EasyMock.createMock(Channel.class);
195 SocketAddress socketAddress = EasyMock.createMock(SocketAddress.class);
196 channel.bind(socketAddress);
197 ospfNbr.twoWayReceived(ospfMessage, channel);
198 ospfInterface.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
199 channel1 = EasyMock.createMock(Channel.class);
200 ospfNbr.twoWayReceived(ospfMessage, channel1);
201 assertThat(ospfNbr, is(notNullValue()));
202 }
203
204 /**
205 * Tests negotiationDone() method.
206 */
sunishvkf7c56552016-07-18 16:02:39 +0530207 @Test
sunish vk1857c422016-02-17 18:05:52 +0530208 public void testNegotiationDone() throws Exception {
sunishvkf7c56552016-07-18 16:02:39 +0530209
sunish vk1857c422016-02-17 18:05:52 +0530210 ospfLsaList = new ArrayList();
sunishvkf7c56552016-07-18 16:02:39 +0530211 RouterLsa routerLsa = new RouterLsa();
212 routerLsa.setLsType(OspfLsaType.ROUTER.value());
213 ospfLsaList.add(routerLsa);
214 DdPacket ddPacket = new DdPacket();
215 ddPacket.setIsOpaqueCapable(true);
216 ospfMessage = ddPacket;
sunish vk1857c422016-02-17 18:05:52 +0530217 ospfNbr.setState(OspfNeighborState.EXSTART);
sunishvkf7c56552016-07-18 16:02:39 +0530218 ospfNbr.setIsOpaqueCapable(true);
219 channel = null;
sunish vk1857c422016-02-17 18:05:52 +0530220 channel = EasyMock.createMock(Channel.class);
221 ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel);
222 channel1 = EasyMock.createMock(Channel.class);
223 ospfNbr.negotiationDone(ospfMessage, false, ospfLsaList, channel1);
224 assertThat(ospfNbr, is(notNullValue()));
225 }
226
227 /**
228 * Tests processLsas() method.
229 */
230 @Test
231 public void testProcessLsas() throws Exception {
232 ospfLsaList = new ArrayList();
233 RouterLsa routerLsa = new RouterLsa();
234 routerLsa.setLsType(1);
235 ospfLsaList.add(routerLsa);
236 NetworkLsa networkLsa = new NetworkLsa();
237 routerLsa.setLsType(2);
238 ospfLsaList.add(networkLsa);
239 routerLsa.setLsType(3);
240 ospfLsaList.add(routerLsa);
241 ospfNbr.processLsas(ospfLsaList);
242 assertThat(ospfNbr, is(notNullValue()));
243 }
244
245 /**
246 * Tests seqNumMismatch() method.
247 */
248 @Test
249 public void testSeqNumMismatch() throws Exception {
250 ospfNbr.setState(OspfNeighborState.FULL);
251 assertThat(ospfNbr.seqNumMismatch("samelsa"), is(notNullValue()));
252 }
253
254 /**
255 * Tests badLSReq() method.
256 */
257 @Test
258 public void testBadLSReq() throws Exception {
259 channel = EasyMock.createMock(Channel.class);
sunishvkf7c56552016-07-18 16:02:39 +0530260 ospfNbr.setState(OspfNeighborState.EXCHANGE);
sunish vk1857c422016-02-17 18:05:52 +0530261 ospfNbr.badLSReq(channel);
262 assertThat(ospfNbr, is(notNullValue()));
263 }
264
265 /**
266 * Tests processDdPacket() method.
267 */
268 @Test
269 public void testProcessDdPacket() throws Exception {
270 ospfArea.addLsa(new RouterLsa(), false, ospfInterface);
271 ospfArea.addLsa(new RouterLsa(), ospfInterface);
272 ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
273 channel = EasyMock.createMock(Channel.class);
274 DdPacket ddPacket = new DdPacket();
275 ddPacket.addLsaHeader(new LsaHeader());
276 ospfNbr.processDdPacket(true, ddPacket, channel);
277 channel1 = EasyMock.createMock(Channel.class);
278 ddPacket.setIsMore(1);
279 ospfNbr.processDdPacket(false, ddPacket, channel1);
280 assertThat(ospfNbr, is(notNullValue()));
281 }
282
283 /**
284 * Tests exchangeDone() method.
285 */
286 @Test
287 public void testExchangeDone() throws Exception {
288 ospfMessage = new HelloPacket();
289 channel = EasyMock.createMock(Channel.class);
290 ospfNbr.setState(OspfNeighborState.EXCHANGE);
291 ospfNbr.exchangeDone(ospfMessage, channel);
292 assertThat(ospfNbr, is(notNullValue()));
293 }
294
295 /**
296 * Tests exchangeDone() method.
297 */
298 @Test
299 public void testExchangeDone1() throws Exception {
300 ospfMessage = new HelloPacket();
301 channel = EasyMock.createMock(Channel.class);
302 ospfNbr.setState(OspfNeighborState.EXCHANGE);
303 ospfLsaList = new ArrayList();
304 RouterLsa routerLsa = new RouterLsa();
305 routerLsa.setLsType(1);
306 ospfLsaList.add(routerLsa);
307 NetworkLsa networkLsa = new NetworkLsa();
308 routerLsa.setLsType(2);
309 ospfLsaList.add(networkLsa);
310 routerLsa.setLsType(3);
311 ospfLsaList.add(routerLsa);
312 ospfNbr.processLsas(ospfLsaList);
313 ospfNbr.setState(OspfNeighborState.EXCHANGE);
314 ospfNbr.exchangeDone(ospfMessage, channel);
315 assertThat(ospfNbr, is(notNullValue()));
316 }
317
318 /**
319 * Tests adjOk() method.
320 */
321 @Test
322 public void testAdjOk() throws Exception {
323 channel = EasyMock.createMock(Channel.class);
sunishvkf7c56552016-07-18 16:02:39 +0530324 ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
sunish vk1857c422016-02-17 18:05:52 +0530325 ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
sunishvkf7c56552016-07-18 16:02:39 +0530326 ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
327 Ip4Address.valueOf("2.2.2.2"), 2,
328 topologyForDeviceAndLink);
329 ospfNbr1.setState(OspfNeighborState.TWOWAY);
330 ospfNbr1.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
331 ospfNbr1.adjOk(channel);
332 assertThat(ospfNbr1, is(notNullValue()));
333
334 ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
335 ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
336 Ip4Address.valueOf("2.2.2.2"), 2,
337 topologyForDeviceAndLink);
338 channel = null;
339 channel = EasyMock.createMock(Channel.class);
340 ospfNbr1.adjOk(channel);
341 assertThat(ospfNbr1, is(notNullValue()));
sunish vk1857c422016-02-17 18:05:52 +0530342 }
343
344 /**
345 * Tests processLsUpdate() method.
346 */
347 @Test
348 public void testProcessLsUpdate() throws Exception {
349 LsUpdate ospfMessage = new LsUpdate();
350 ospfMessage.setSourceIp(Ip4Address.valueOf("10.10.10.10"));
351 ospfMessage.addLsa(new RouterLsa());
352 ospfMessage.addLsa(new NetworkLsa());
353 channel = EasyMock.createMock(Channel.class);
354 ospfNbr.setState(OspfNeighborState.EXCHANGE);
355 ospfNbr.processLsUpdate(ospfMessage, channel);
356 assertThat(ospfNbr, is(notNullValue()));
357 }
358
359 /**
360 * Tests loadingDone() method.
361 */
362 @Test
363 public void testLoadingDone() throws Exception {
sunishvkf7c56552016-07-18 16:02:39 +0530364 LsaHeader lsaHeader = new LsaHeader();
365 lsaHeader.setLsType(OspfLsaType.ROUTER.value());
366 RouterLsa routerLsa = new RouterLsa(lsaHeader);
367 ospfArea.addLsa(routerLsa, false, ospfInterface);
368 ospfArea.addLsa(routerLsa, ospfInterface);
sunish vk1857c422016-02-17 18:05:52 +0530369 ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
370 ospfNbr.loadingDone();
371 assertThat(ospfNbr, is(notNullValue()));
372 }
373
374 /**
375 * Tests processReceivedLsa() method.
376 */
377 @Test
378 public void testProcessReceivedLsa() throws Exception {
379 LsaWrapperImpl lsaWrapper = new LsaWrapperImpl();
380 LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
381 lsdbAge.ageLsaAndFlood();
382 lsaWrapper.setLsdbAge(lsdbAge);
383 lsaWrapper.setLsaHeader(new NetworkLsa());
384 RouterLsa routerlsa = new RouterLsa();
385 routerlsa.setLsType(1);
386 routerlsa.setOptions(2);
387 routerlsa.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
388 routerlsa.setAge(100);
389 routerlsa.setLinkStateId("2.2.2.2");
390 routerlsa.setLsSequenceNo(1010101);
391 lsaWrapper.setLsaHeader(new RouterLsa());
392 ospfArea.addLsa(routerlsa, false, ospfInterface);
393
394 lsaWrapper.addLsa(OspfLsaType.ROUTER, routerlsa);
395 ospfArea.addLsa(routerlsa, ospfInterface);
396 ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
397 byte[] res = routerlsa.asBytes();
398 routerlsa.setLsPacketLen(res.length);
399 res = new ChecksumCalculator().calculateLsaChecksum(routerlsa.asBytes(), 16, 17);
400 routerlsa.setLsCheckSum(OspfUtil.byteToInteger(res));
401 channel = EasyMock.createMock(Channel.class);
402 lsdbAge.ageLsaAndFlood();
403 assertThat(ospfNbr.processReceivedLsa(lsaWrapper.lsaHeader(), true, channel,
404 Ip4Address.valueOf("10.10.10.10")), is(true));
405 channel1 = EasyMock.createMock(Channel.class);
406 assertThat(ospfNbr.processReceivedLsa(routerlsa, true, channel1,
407 Ip4Address.valueOf("10.10.10.10")), is(true));
sunishvkf7c56552016-07-18 16:02:39 +0530408
sunish vk1857c422016-02-17 18:05:52 +0530409 }
410
411 /**
412 * Tests isNullorLatest() method.
413 */
414 @Test
415 public void testIsNullorLatest() throws Exception {
416
417 LsaWrapperImpl lsaWrapper = new LsaWrapperImpl();
418 LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
419 lsdbAge.ageLsaAndFlood();
420 lsaWrapper.setLsdbAge(lsdbAge);
421 lsaWrapper.setLsaHeader(new LsaHeader());
422 lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa());
423 assertThat(ospfNbr.isNullorLatest(lsaWrapper, new LsaHeader()), is(notNullValue()));
424 }
425
426 /**
427 * Tests processSelfOriginatedLsa() method.
428 */
429 @Test
430 public void testProcessSelfOriginatedLsa() throws Exception {
431 ospfNbr.processSelfOriginatedLsa();
432 assertThat(ospfNbr, is(notNullValue()));
433 }
434
435 /**
436 * Tests sendLsa() method.
437 */
438 @Test
439 public void testSendLsa() throws Exception {
440 channel = EasyMock.createMock(Channel.class);
sunishvkf7c56552016-07-18 16:02:39 +0530441 ospfNbr.sendLsa(lsaHeader, Ip4Address.valueOf("1.1.1.1"), channel);
sunish vk1857c422016-02-17 18:05:52 +0530442 assertThat(ospfNbr, is(notNullValue()));
443 }
444
445 /**
446 * Tests directAcknowledge() method.
447 */
448 @Test
449 public void testDirectAcknowledge() throws Exception {
450 channel = EasyMock.createMock(Channel.class);
451 ospfNbr.directAcknowledge(new LsaHeader(), channel, Ip4Address.valueOf("1.1.1.1"));
452 assertThat(ospfNbr, is(notNullValue()));
453 }
454
455 /**
456 * Tests neighborDown() method.
457 */
458 @Test(expected = Exception.class)
459 public void testNeighborDown() throws Exception {
460 ospfNbr.neighborDown();
461 assertThat(ospfNbr, is(notNullValue()));
462 }
463
464 /**
465 * Tests startFloodingTimer() method.
466 */
467 @Test
468 public void testStartFloodingTimer() throws Exception {
469 channel = EasyMock.createMock(Channel.class);
470 ospfNbr.startFloodingTimer(channel);
471 assertThat(ospfNbr, is(notNullValue()));
472 }
473
474 /**
475 * Tests lastDdPacket() getter method.
476 */
477 @Test
478 public void testGetLastDdPacket() throws Exception {
479 ospfNbr.setLastDdPacket(new DdPacket());
480 assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
481 }
482
483 /**
484 * Tests lastDdPacket() setter method.
485 */
486 @Test
487 public void testSetLastDdPacket() throws Exception {
488 ospfNbr.setLastDdPacket(new DdPacket());
489 assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
490 }
491
492 /**
493 * Tests neighborId() getter method.
494 */
495 @Test
496 public void testNeighborId() throws Exception {
497 ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
498 assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
499 }
500
501 /**
502 * Tests neighborId() setter method.
503 */
504 @Test
505 public void testSetNeighborId() throws Exception {
506 ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
507 assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
508 }
509
510 /**
511 * Tests neighborDr() getter method.
512 */
513 @Test
514 public void testNeighborDr() throws Exception {
515 ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
516 assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1")));
517 }
518
519 /**
520 * Tests neighborDr() setter method.
521 */
522 @Test
523 public void testSetNeighborDr() throws Exception {
524 ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
525 assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1")));
526 }
527
528 /**
529 * Tests neighborBdr() getter method.
530 */
531 @Test
532 public void testNeighborBdr() throws Exception {
533 ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1"));
534 assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1")));
535 }
536
537 /**
538 * Tests neighborBdr() setter method.
539 */
540 @Test
541 public void testSetNeighborBdr() throws Exception {
542 ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1"));
543 assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1")));
544 }
545
546 /**
547 * Tests routerPriority() getter method.
548 */
549 @Test
550 public void testRouterPriority() throws Exception {
551 ospfNbr.setRouterPriority(1);
552 assertThat(ospfNbr.routerPriority(), is(1));
553 }
554
555 /**
556 * Tests routerPriority() setter method.
557 */
558 @Test
559 public void testSetRouterPriority() throws Exception {
560 ospfNbr.setRouterPriority(1);
561 assertThat(ospfNbr.routerPriority(), is(1));
562 }
563
564 /**
565 * Tests options() getter method.
566 */
567 @Test
568 public void testGetOptions() throws Exception {
569 ospfNbr.setOptions(1);
570 assertThat(ospfNbr.options(), is(1));
571 }
572
573 /**
574 * Tests options() setter method.
575 */
576 @Test
577 public void testSetOptions() throws Exception {
578 ospfNbr.setOptions(1);
579 assertThat(ospfNbr.options(), is(1));
580 }
581
582 /**
583 * Tests ddSeqNum() getter method.
584 */
585 @Test
586 public void testGetDdSeqNum() throws Exception {
587 ospfNbr.setDdSeqNum(1);
588 assertThat(ospfNbr.ddSeqNum(), is(1L));
589 }
590
591 /**
592 * Tests ddSeqNum() setter method.
593 */
594 @Test
595 public void testSetDdSeqNum() throws Exception {
596 ospfNbr.setDdSeqNum(1);
597 assertThat(ospfNbr.ddSeqNum(), is(1L));
598 }
599
600 /**
601 * Tests isMaster() getter method.
602 */
603 @Test
604 public void testIsMaster() throws Exception {
605 ospfNbr.setIsMaster(1);
606 assertThat(ospfNbr.isMaster(), is(1));
607 }
608
609 /**
610 * Tests lastDdPacket() getter method.
611 */
612 @Test
613 public void testGetLastSentDdPacket() throws Exception {
614 ospfNbr.setLastDdPacket(new DdPacket());
615 assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
616 }
617
618 /**
619 * Tests lastDdPacket() setter method.
620 */
621 @Test
622 public void testSetLastSentDdPacket() throws Exception {
623 ospfNbr.setLastDdPacket(new DdPacket());
624 assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
625 }
626
627 /**
628 * Tests getLastSentLsrPacket() getter method.
629 */
630 @Test
631 public void testGetLastSentLsrPacket() throws Exception {
632 ospfNbr.setLastSentLsrPacket(new LsRequest());
633 assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue()));
634 }
635
636 /**
637 * Tests getLastSentLsrPacket() setter method.
638 */
639 @Test
640 public void testSetLastSentLsrPacket() throws Exception {
641 ospfNbr.setLastSentLsrPacket(new LsRequest());
642 assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue()));
643 }
644
645 /**
646 * Tests getState() getter method.
647 */
648 @Test
649 public void testGetState() throws Exception {
650 ospfNbr.setState(OspfNeighborState.EXCHANGE);
651 assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE));
652 }
653
654 /**
655 * Tests getState() setter method.
656 */
657 @Test
658 public void testSetState() throws Exception {
659 ospfNbr.setState(OspfNeighborState.EXCHANGE);
660 assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE));
661 }
662
663 /**
664 * Tests isMaster() setter method.
665 */
666 @Test
667 public void testSetIsMaster() throws Exception {
668 ospfNbr.setIsMaster(1);
669 assertThat(ospfNbr.isMaster(), is(1));
670 }
671
672 /**
673 * Tests getLsReqList() method.
674 */
675 @Test
676 public void testGetLsReqList() throws Exception {
677 assertThat(ospfNbr.getLsReqList(), is(notNullValue()));
678 }
679
680 /**
681 * Tests getReTxList() method.
682 */
683 @Test
684 public void testGetReTxList() throws Exception {
685 assertThat(ospfNbr.getReTxList(), is(notNullValue()));
686 }
687
688 /**
689 * Tests getPendingReTxList() method.
690 */
691 @Test
692 public void testGetPendingReTxList() throws Exception {
693 assertThat(ospfNbr.getPendingReTxList(), is(notNullValue()));
694 }
sunishvkf7c56552016-07-18 16:02:39 +0530695
696 /**
697 * Utility for test method.
698 */
699 private OspfAreaImpl createOspfArea() throws UnknownHostException {
700 OspfAreaAddressRangeImpl ospfAreaAddressRange;
701 ospfAreaAddressRange = createOspfAreaAddressRange();
702 addressRanges.add(ospfAreaAddressRange);
703 OspfAreaImpl ospfArea = new OspfAreaImpl();
704 ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164"));
705 ospfArea.setExternalRoutingCapability(true);
706 OspfInterfaceImpl ospfInterface = createOspfInterface();
707 ospfInterfaces.add(ospfInterface);
708 ospfArea.setOspfInterfaceList(ospfInterfaces);
709 RouterLsa routerLsa = new RouterLsa();
710 routerLsa.setLsType(1);
711 routerLsa.setLinkStateId("2.2.2.2");
712 routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
713 OpaqueLsaHeader opaqueLsaHeader = new OpaqueLsaHeader();
714 OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10(opaqueLsaHeader);
715 opaqueLsa10.setLsType(OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value());
716 opaqueLsa10.setLinkStateId("2.2.2.2");
717 opaqueLsa10.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
718 try {
719 ospfArea.addLsa(routerLsa, false, ospfInterface);
720 ospfArea.addLsa(opaqueLsa10, false, ospfInterface);
721 } catch (Exception e) {
722 System.out.println("ospfAreaImpl createOspfArea");
723 }
724 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
725
726 return ospfArea;
727 }
728
729 /**
730 * Utility for test method.
731 */
732 private OspfAreaAddressRangeImpl createOspfAreaAddressRange() {
733 OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
734 ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
735 ospfAreaAddressRange.setAdvertise(true);
736 ospfAreaAddressRange.setMask("mask");
737 return ospfAreaAddressRange;
738 }
739
740 /**
741 * Utility for test method.
742 */
743 private OspfInterfaceImpl createOspfInterface() throws UnknownHostException {
744 ospfInterface = new OspfInterfaceImpl();
745 OspfAreaImpl ospfArea = new OspfAreaImpl();
746 OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
747 OspfInterfaceChannelHandler.class);
748 ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
749 Ip4Address.valueOf("1.1.1.1"), 2,
750 topologyForDeviceAndLink);
751 ospfNbr.setState(OspfNeighborState.EXSTART);
752 ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
753 this.ospfInterface = new OspfInterfaceImpl();
754 this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
755 this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
756 this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
757 this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
758 this.ospfInterface.setHelloIntervalTime(20);
759 this.ospfInterface.setInterfaceType(2);
760 this.ospfInterface.setReTransmitInterval(2000);
761 this.ospfInterface.setMtu(6500);
762 this.ospfInterface.setRouterDeadIntervalTime(1000);
763 this.ospfInterface.setRouterPriority(1);
764 this.ospfInterface.setInterfaceType(1);
765 this.ospfInterface.addNeighbouringRouter(ospfNbr);
766 return this.ospfInterface;
767 }
sunish vk1857c422016-02-17 18:05:52 +0530768}