blob: 4285d908bc17249b78fc1aa3880e8e2facb9bc14 [file] [log] [blame]
Dhruv Dhodyb5850122016-02-17 17:51:19 +05301/*
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 */
16package org.onosproject.ospf.controller.area;
17
18
19import org.junit.After;
20import org.junit.Assert;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.Ip4Address;
24import org.onosproject.ospf.controller.OspfNbr;
25import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
26import org.onosproject.ospf.controller.impl.Controller;
27import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler;
28import org.onosproject.ospf.controller.impl.OspfNbrImpl;
29import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
30import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
31import org.onosproject.ospf.protocol.util.OspfInterfaceState;
32
33import java.util.HashMap;
34
35import static org.hamcrest.MatcherAssert.assertThat;
36import static org.hamcrest.Matchers.is;
37import static org.hamcrest.Matchers.notNullValue;
38
39/**
40 * Unit test class for OspfInterfaceImpl.
41 */
42public class OspfInterfaceImplTest {
43
44 private OspfInterfaceImpl ospfInterface;
45 private OspfNbrImpl ospfNbr;
46 private OpaqueLsaHeader opaqueLsaHeader;
47 private int result;
48 private HashMap<String, OspfNbr> ospfNbrHashMap;
49 private TopologyForDeviceAndLink topologyForDeviceAndLink;
50
51 @Before
52 public void setUp() throws Exception {
53 ospfInterface = new OspfInterfaceImpl();
54 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
55 }
56
57 @After
58 public void tearDown() throws Exception {
59 ospfInterface = null;
60 ospfNbr = null;
61 opaqueLsaHeader = null;
62 ospfNbrHashMap = null;
63 }
64
65 /**
66 * Tests state() getter method.
67 */
68 @Test
69 public void testGetState() throws Exception {
70 ospfInterface.setState(OspfInterfaceState.DROTHER);
71 assertThat(ospfInterface.state(), is(OspfInterfaceState.DROTHER));
72 }
73
74 /**
75 * Tests state() setter method.
76 */
77 @Test
78 public void testSetState() throws Exception {
79 ospfInterface.setState(OspfInterfaceState.DROTHER);
80 assertThat(ospfInterface.state(), is(OspfInterfaceState.DROTHER));
81 }
82
83 /**
84 * Tests linkStateHeaders() method.
85 */
86 @Test
87 public void testGetLinkStateHeaders() throws Exception {
88
89 assertThat(ospfInterface.linkStateHeaders().size(), is(0));
90 }
91
92 /**
93 * Tests ipNetworkMask() getter method.
94 */
95 @Test
96 public void testGetIpNetworkMask() throws Exception {
97 ospfInterface.setIpNetworkMask(Ip4Address.valueOf("1.1.1.1"));
98 assertThat(ospfInterface.ipNetworkMask(), is(Ip4Address.valueOf("1.1.1.1")));
99 }
100
101 /**
102 * Tests ipNetworkMask() setter method.
103 */
104 @Test
105 public void testSetIpNetworkMask() throws Exception {
106 ospfInterface.setIpNetworkMask(Ip4Address.valueOf("1.1.1.1"));
107 assertThat(ospfInterface.ipNetworkMask(), is(Ip4Address.valueOf("1.1.1.1")));
108 }
109
110 /**
111 * Tests addNeighbouringRouter() method.
112 */
113 @Test
114 public void testAddNeighbouringRouter() throws Exception {
115 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
116 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
117 new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
118 new OspfInterfaceImpl())
119 , topologyForDeviceAndLink);
120 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
121 ospfInterface.addNeighbouringRouter(ospfNbr);
122 assertThat(ospfInterface, is(notNullValue()));
123
124 }
125
126 /**
127 * Tests neighbouringRouter() method.
128 */
129 @Test
130 public void testGetNeighbouringRouter() throws Exception {
131 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
132 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
133 new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
134 new OspfInterfaceImpl())
135 , topologyForDeviceAndLink);
136 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
137 ospfInterface.addNeighbouringRouter(ospfNbr);
138 assertThat(ospfInterface.neighbouringRouter("111.111.111.111"), is(notNullValue()));
139 }
140
141 /**
142 * Tests addLsaHeaderForDelayAck() method.
143 */
144 @Test
145 public void testAddLsaHeaderForDelayAck() throws Exception {
146 opaqueLsaHeader = new OpaqueLsaHeader();
147 opaqueLsaHeader.setLsType(10);
148 ospfInterface.addLsaHeaderForDelayAck(opaqueLsaHeader);
149 assertThat(ospfInterface, is(notNullValue()));
150 }
151
152 /**
153 * Tests removeLsaFromNeighborMap() method.
154 */
155 @Test
156 public void testRemoveLsaFromNeighborMap() throws Exception {
157 ospfInterface.removeLsaFromNeighborMap("lsa10");
158 assertThat(ospfInterface, is(notNullValue()));
159 }
160
161 /**
162 * Tests isNeighborInList() method.
163 */
164 @Test
165 public void testIsNeighborinList() throws Exception {
166 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
167 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
168 new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
169 new OspfInterfaceImpl())
170 , topologyForDeviceAndLink);
171 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
172 ospfInterface.addNeighbouringRouter(ospfNbr);
173 assertThat(ospfInterface.isNeighborInList("111.111.111.111"), is(notNullValue()));
174 }
175
176 /**
177 * Tests listOfNeighbors() getter method.
178 */
179 @Test
180 public void testGetListOfNeighbors() throws Exception {
181 ospfNbrHashMap = new HashMap();
182 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
183 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
184 new OspfInterfaceChannelHandler(new Controller(),
185 new OspfAreaImpl(),
186 new OspfInterfaceImpl())
187 , topologyForDeviceAndLink);
188 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
189 ospfNbrHashMap.put("111.111.111.111", ospfNbr);
190 ospfInterface.setListOfNeighbors(ospfNbrHashMap);
191 assertThat(ospfInterface.listOfNeighbors().size(), is(1));
192 }
193
194 /**
195 * Tests listOfNeighbors() setter method.
196 */
197 @Test
198 public void testSetListOfNeighbors() throws Exception {
199 ospfNbrHashMap = new HashMap();
200 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
201 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
202 new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
203 new OspfInterfaceImpl())
204 , topologyForDeviceAndLink);
205 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
206 ospfNbrHashMap.put("111.111.111.111", ospfNbr);
207 ospfInterface.setListOfNeighbors(ospfNbrHashMap);
208 assertThat(ospfInterface.listOfNeighbors().size(), is(1));
209 }
210
211 /**
212 * Tests ipAddress() getter method.
213 */
214 @Test
215 public void testGetIpAddress() throws Exception {
216 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
217 assertThat(ospfInterface.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
218 }
219
220 /**
221 * Tests ipAddress() getter method.
222 */
223 @Test
224 public void testSetIpAddress() throws Exception {
225 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
226 assertThat(ospfInterface.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
227 }
228
229 /**
230 * Tests routerPriority() getter method.
231 */
232 @Test
233 public void testGetRouterPriority() throws Exception {
234 ospfInterface.setRouterPriority(1);
235 Assert.assertEquals(1, ospfInterface.routerPriority());
236 }
237
238 /**
239 * Tests routerPriority() setter method.
240 */
241 @Test
242 public void testSetRouterPriority() throws Exception {
243 ospfInterface.setRouterPriority(1);
244 assertThat(ospfInterface.routerPriority(), is(1));
245 }
246
247 /**
248 * Tests areaId() getter method.
249 */
250 @Test
251 public void testGetAreaId() throws Exception {
252 ospfInterface.setAreaId(1);
253 assertThat(ospfInterface.areaId(), is(1));
254 }
255
256 /**
257 * Tests areaId() setter method.
258 */
259 @Test
260 public void testSetAreaId() throws Exception {
261 ospfInterface.setAreaId(1);
262 assertThat(ospfInterface.areaId(), is(1));
263 }
264
265 /**
266 * Tests helloIntervalTime() getter method.
267 */
268 @Test
269 public void testGetHelloIntervalTime() throws Exception {
270 ospfInterface.setHelloIntervalTime(10);
271 assertThat(ospfInterface.helloIntervalTime(), is(10));
272 }
273
274 /**
275 * Tests helloIntervalTime() setter method.
276 */
277 @Test
278 public void testSetHelloIntervalTime() throws Exception {
279 ospfInterface.setHelloIntervalTime(10);
280 assertThat(ospfInterface.helloIntervalTime(), is(10));
281 }
282
283 /**
284 * Tests routerDeadIntervalTime() getter method.
285 */
286 @Test
287 public void testGetRouterDeadIntervalTime() throws Exception {
288 ospfInterface.setRouterDeadIntervalTime(10);
289 assertThat(ospfInterface.routerDeadIntervalTime(), is(10));
290 }
291
292 /**
293 * Tests routerDeadIntervalTime() setter method.
294 */
295 @Test
296 public void testSetRouterDeadIntervalTime() throws Exception {
297 ospfInterface.setRouterDeadIntervalTime(10);
298 assertThat(ospfInterface.routerDeadIntervalTime(), is(10));
299 }
300
301 /**
302 * Tests interfaceType() getter method.
303 */
304 @Test
305 public void testGetInterfaceType() throws Exception {
306 ospfInterface.setInterfaceType(1);
307 assertThat(ospfInterface.interfaceType(), is(1));
308 }
309
310 /**
311 * Tests interfaceType() setter method.
312 */
313 @Test
314 public void testSetInterfaceType() throws Exception {
315 ospfInterface.setInterfaceType(1);
316 assertThat(ospfInterface.interfaceType(), is(1));
317 }
318
319 /**
320 * Tests interfaceCost() getter method.
321 */
322 @Test
323 public void testGetInterfaceCost() throws Exception {
324 ospfInterface.setInterfaceCost(100);
325 assertThat(ospfInterface.interfaceCost(), is(100));
326 }
327
328 /**
329 * Tests interfaceCost() setter method.
330 */
331 @Test
332 public void testSetInterfaceCost() throws Exception {
333 ospfInterface.setInterfaceCost(100);
334 assertThat(ospfInterface.interfaceCost(), is(100));
335 }
336
337 /**
338 * Tests authType() getter method.
339 */
340 @Test
341 public void testGetAuthType() throws Exception {
342 ospfInterface.setAuthType("00");
343 assertThat(ospfInterface.authType(), is("00"));
344 }
345
346 /**
347 * Tests authType() setter method.
348 */
349 @Test
350 public void testSetAuthType() throws Exception {
351 ospfInterface.setAuthType("00");
352 assertThat(ospfInterface.authType(), is("00"));
353 }
354
355 /**
356 * Tests authKey() getter method.
357 */
358 @Test
359 public void testGetAuthKey() throws Exception {
360 ospfInterface.setAuthKey("00");
361 assertThat(ospfInterface.authKey(), is("00"));
362 }
363
364 /**
365 * Tests authKey() setter method.
366 */
367 @Test
368 public void testSetAuthKey() throws Exception {
369 ospfInterface.setAuthKey("00");
370 assertThat(ospfInterface.authKey(), is("00"));
371 }
372
373 /**
374 * Tests pollInterval() getter method.
375 */
376 @Test
377 public void testGetPollInterval() throws Exception {
378 ospfInterface.setPollInterval(100);
379 assertThat(ospfInterface.pollInterval(), is(100));
380 }
381
382 /**
383 * Tests pollInterval() setter method.
384 */
385 @Test
386 public void testSetPollInterval() throws Exception {
387 ospfInterface.setPollInterval(100);
388 assertThat(ospfInterface.pollInterval(), is(100));
389 }
390
391 /**
392 * Tests mtu() getter method.
393 */
394 @Test
395 public void testGetMtu() throws Exception {
396 ospfInterface.setMtu(100);
397 assertThat(ospfInterface.mtu(), is(100));
398 }
399
400 /**
401 * Tests mtu() setter method.
402 */
403 @Test
404 public void testSetMtu() throws Exception {
405 ospfInterface.setMtu(100);
406 assertThat(ospfInterface.mtu(), is(100));
407 }
408
409 /**
410 * Tests reTransmitInterval() getter method.
411 */
412 @Test
413 public void testGetReTransmitInterval() throws Exception {
414 ospfInterface.setReTransmitInterval(100);
415 assertThat(ospfInterface.reTransmitInterval(), is(100));
416 }
417
418 /**
419 * Tests reTransmitInterval() setter method.
420 */
421 @Test
422 public void testSetReTransmitInterval() throws Exception {
423 ospfInterface.setReTransmitInterval(100);
424 assertThat(ospfInterface.reTransmitInterval(), is(100));
425 }
426
427 /**
428 * Tests dr() getter method.
429 */
430 @Test
431 public void testGetDr() throws Exception {
432 ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
433 assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1")));
434 }
435
436 /**
437 * Tests dr() setter method.
438 */
439 @Test
440 public void testSetDr() throws Exception {
441 ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
442 assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1")));
443 }
444
445 /**
446 * Tests bdr() getter method.
447 */
448 @Test
449 public void testGetBdr() throws Exception {
450 ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1"));
451 assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1")));
452 }
453
454 /**
455 * Tests bdr() setter method.
456 */
457 @Test
458 public void testSetBdr() throws Exception {
459 ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1"));
460 assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1")));
461 }
462
463 /**
464 * Tests transmitDelay() getter method.
465 */
466 @Test
467 public void testGetTransmitDelay() throws Exception {
468 ospfInterface.setTransmitDelay(100);
469 assertThat(ospfInterface.transmitDelay(), is(100));
470 }
471
472 /**
473 * Tests transmitDelay() setter method.
474 */
475 @Test
476 public void testSetTransmitDelay() throws Exception {
477 ospfInterface.setTransmitDelay(100);
478 assertThat(ospfInterface.transmitDelay(), is(100));
479 }
480
481 /**
482 * Tests equals() method.
483 */
484 @Test
485 public void testEquals() throws Exception {
486 assertThat(ospfInterface.equals(new OspfInterfaceImpl()), is(true));
487 }
488
489 /**
490 * Tests hashCode() method.
491 */
492 @Test
493 public void testHashCode() throws Exception {
494 result = ospfInterface.hashCode();
495 assertThat(result, is(notNullValue()));
496 }
497
498 /**
499 * Tests to string method.
500 */
501 @Test
502 public void testToString() throws Exception {
503 assertThat(ospfInterface.toString(), is(notNullValue()));
504 }
505}