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