Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +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 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onosproject.ospf.controller.OspfArea; |
| 24 | import org.onosproject.ospf.controller.OspfAreaAddressRange; |
| 25 | import org.onosproject.ospf.controller.OspfInterface; |
| 26 | import org.onosproject.ospf.controller.OspfNbr; |
| 27 | import org.onosproject.ospf.controller.OspfNeighborState; |
| 28 | import org.onosproject.ospf.controller.TopologyForDeviceAndLink; |
| 29 | import org.onosproject.ospf.controller.impl.Controller; |
| 30 | import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler; |
| 31 | import org.onosproject.ospf.controller.impl.OspfNbrImpl; |
| 32 | import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl; |
| 33 | import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl; |
| 34 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
| 35 | import org.onosproject.ospf.protocol.lsa.types.NetworkLsa; |
| 36 | import org.onosproject.ospf.protocol.lsa.types.RouterLsa; |
| 37 | import org.onosproject.ospf.protocol.util.OspfInterfaceState; |
| 38 | |
| 39 | import java.util.ArrayList; |
| 40 | import java.util.HashMap; |
| 41 | import java.util.List; |
| 42 | |
| 43 | import static org.hamcrest.MatcherAssert.assertThat; |
| 44 | import static org.hamcrest.Matchers.*; |
| 45 | |
| 46 | /** |
| 47 | * Unit test class for OspfAreaImpl. |
| 48 | */ |
| 49 | public class OspfAreaImplTest { |
| 50 | |
| 51 | private OspfAreaImpl ospfArea; |
| 52 | private int result; |
| 53 | private OspfInterfaceImpl ospfInterface; |
| 54 | private HashMap<String, OspfNbr> ospfNbrList; |
| 55 | private List<OspfInterface> ospfInterfaces; |
| 56 | private OspfInterfaceImpl ospfInterface1; |
| 57 | private OspfInterfaceImpl ospfInterface2; |
| 58 | private OspfInterfaceImpl ospfInterface3; |
| 59 | private OspfInterfaceImpl ospfInterface4; |
| 60 | private OspfInterfaceImpl ospfInterface5; |
| 61 | private OspfInterfaceImpl ospfInterface6; |
| 62 | private NetworkLsa networkLsa; |
| 63 | private OspfNbrImpl ospfNbr; |
| 64 | private RouterLsa routerLsa; |
| 65 | private List<OspfAreaAddressRange> ospfAreaAddressRanges; |
| 66 | private LsaHeader lsaHeader; |
| 67 | private TopologyForDeviceAndLink topologyForDeviceAndLink; |
| 68 | |
| 69 | @Before |
| 70 | public void setUp() throws Exception { |
| 71 | ospfArea = new OspfAreaImpl(); |
| 72 | topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); |
| 73 | } |
| 74 | |
| 75 | @After |
| 76 | public void tearDown() throws Exception { |
| 77 | ospfArea = null; |
| 78 | ospfInterface = null; |
| 79 | ospfNbrList = null; |
| 80 | ospfInterfaces = null; |
| 81 | ospfAreaAddressRanges = null; |
| 82 | lsaHeader = null; |
| 83 | routerLsa = null; |
| 84 | ospfNbr = null; |
| 85 | networkLsa = null; |
| 86 | ospfInterface1 = null; |
| 87 | ospfInterface2 = null; |
| 88 | ospfInterface3 = null; |
| 89 | ospfInterface4 = null; |
| 90 | ospfInterface5 = null; |
| 91 | ospfInterface6 = null; |
| 92 | |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Tests equals() method. |
| 97 | */ |
| 98 | @Test |
| 99 | public void testEquals() throws Exception { |
| 100 | ospfArea = new OspfAreaImpl(); |
| 101 | ospfInterface = new OspfInterfaceImpl(); |
| 102 | ospfArea.setTransitCapability(true); |
| 103 | ospfArea.setExternalRoutingCapability(true); |
| 104 | ospfArea.setStubCost(100); |
| 105 | ospfArea.initializeDb(); |
| 106 | ospfArea.setAddressRanges(ospfAreaAddressRanges); |
| 107 | assertThat(ospfArea.equals(ospfArea), is(true)); |
| 108 | ospfArea = EasyMock.createMock(OspfAreaImpl.class); |
| 109 | assertThat(ospfArea.equals(ospfArea), is(true)); |
| 110 | OspfArea ospfArea = new OspfAreaImpl(); |
| 111 | assertThat(ospfArea.equals(ospfArea), is(true)); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Tests hashCode() method. |
| 116 | */ |
| 117 | @Test |
| 118 | public void testHashCode() throws Exception { |
| 119 | result = ospfArea.hashCode(); |
| 120 | assertThat(result, is(notNullValue())); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Tests routerId() getter method. |
| 125 | */ |
| 126 | @Test |
| 127 | public void testGetRouterId() throws Exception { |
| 128 | ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1")); |
| 129 | assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1"))); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Tests routerId() setter method. |
| 134 | */ |
| 135 | @Test |
| 136 | public void testSetRouterId() throws Exception { |
| 137 | ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1")); |
| 138 | assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1"))); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Tests isOpaqueEnabled() getter method. |
| 143 | */ |
| 144 | @Test |
| 145 | public void testSetisOpaqueEnabled() throws Exception { |
| 146 | ospfArea.setIsOpaqueEnabled(true); |
| 147 | assertThat(ospfArea.isOpaqueEnabled(), is(true)); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Tests isOpaqueEnabled() setter method. |
| 152 | */ |
| 153 | @Test |
| 154 | public void testIsOpaqueEnabled() throws Exception { |
| 155 | ospfArea.setIsOpaqueEnabled(true); |
| 156 | assertThat(ospfArea.isOpaqueEnabled(), is(true)); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Tests initializeDb() method. |
| 161 | */ |
| 162 | @Test |
| 163 | public void testInitializeDb() throws Exception { |
| 164 | ospfArea.initializeDb(); |
| 165 | assertThat(ospfArea, is(notNullValue())); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Tests refreshArea() method. |
| 170 | */ |
| 171 | @Test |
| 172 | public void testRefreshArea() throws Exception { |
| 173 | |
| 174 | ospfInterface = new OspfInterfaceImpl(); |
| 175 | ospfInterface.setState(OspfInterfaceState.DR); |
| 176 | ospfNbrList = new HashMap(); |
| 177 | ospfNbrList.put("1.1.1.1", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 178 | Ip4Address.valueOf("1.1.1.1"), |
| 179 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 180 | new OspfInterfaceChannelHandler(new Controller(), |
| 181 | new OspfAreaImpl(), |
| 182 | new OspfInterfaceImpl()), |
| 183 | topologyForDeviceAndLink)); |
| 184 | ospfNbrList.put("2.2.2.2", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 185 | Ip4Address.valueOf("1.1.1.1"), |
| 186 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 187 | new OspfInterfaceChannelHandler(new Controller(), |
| 188 | new OspfAreaImpl(), |
| 189 | new OspfInterfaceImpl()) |
| 190 | , topologyForDeviceAndLink)); |
| 191 | ospfNbrList.put("3.3.3.3", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 192 | Ip4Address.valueOf("1.1.1.1"), |
| 193 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 194 | new OspfInterfaceChannelHandler(new Controller(), |
| 195 | new OspfAreaImpl(), |
| 196 | new OspfInterfaceImpl()) |
| 197 | , topologyForDeviceAndLink)); |
| 198 | ospfNbrList.put("4.4.4.4", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 199 | Ip4Address.valueOf("1.1.1.1"), |
| 200 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 201 | new OspfInterfaceChannelHandler(new Controller(), |
| 202 | new OspfAreaImpl(), |
| 203 | new OspfInterfaceImpl()) |
| 204 | , topologyForDeviceAndLink)); |
| 205 | |
| 206 | ospfInterface.setListOfNeighbors(ospfNbrList); |
| 207 | ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10")); |
| 208 | ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); |
| 209 | ospfInterfaces = new ArrayList(); |
| 210 | ospfInterface1 = new OspfInterfaceImpl(); |
| 211 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 212 | ospfInterfaces.add(ospfInterface1); |
| 213 | ospfInterface2 = new OspfInterfaceImpl(); |
| 214 | ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); |
| 215 | ospfInterfaces.add(ospfInterface2); |
| 216 | ospfInterface3 = new OspfInterfaceImpl(); |
| 217 | ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 218 | ospfInterfaces.add(ospfInterface3); |
| 219 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 220 | ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); |
| 221 | networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"), |
| 222 | Ip4Address.valueOf("255.255.255.255")); |
| 223 | ospfArea.refreshArea(ospfInterface); |
| 224 | assertThat(ospfNbrList.size(), is(4)); |
| 225 | assertThat(networkLsa, is(notNullValue())); |
| 226 | assertThat(ospfArea, is(notNullValue())); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Tests buildNetworkLsa() method. |
| 231 | */ |
| 232 | @Test |
| 233 | public void testBuildNetworkLsa() throws Exception { |
| 234 | ospfInterfaces = new ArrayList(); |
| 235 | ospfInterface1 = new OspfInterfaceImpl(); |
| 236 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 237 | ospfInterfaces.add(ospfInterface1); |
| 238 | ospfInterface2 = new OspfInterfaceImpl(); |
| 239 | ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); |
| 240 | ospfInterfaces.add(ospfInterface2); |
| 241 | ospfInterface3 = new OspfInterfaceImpl(); |
| 242 | ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 243 | ospfInterfaces.add(ospfInterface3); |
| 244 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 245 | ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); |
| 246 | networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"), |
| 247 | Ip4Address.valueOf("255.255.255.255")); |
| 248 | assertThat(ospfInterfaces.size(), is(3)); |
| 249 | assertThat(networkLsa, is(notNullValue())); |
| 250 | assertThat(ospfArea, is(notNullValue())); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Tests buildNetworkLsa() method. |
| 255 | */ |
| 256 | @Test |
| 257 | public void testBuildNetworkLsa1() throws Exception { |
| 258 | ospfInterfaces = new ArrayList(); |
| 259 | ospfInterface1 = new OspfInterfaceImpl(); |
| 260 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 261 | ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); |
| 262 | ospfInterface1.setState(OspfInterfaceState.POINT2POINT); |
| 263 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 264 | Ip4Address.valueOf("1.1.1.1"), |
| 265 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 266 | new OspfInterfaceChannelHandler(new Controller(), |
| 267 | new OspfAreaImpl(), |
| 268 | new OspfInterfaceImpl()) |
| 269 | , topologyForDeviceAndLink); |
| 270 | ospfNbr.setState(OspfNeighborState.FULL); |
| 271 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 272 | ospfInterfaces.add(ospfInterface1); |
| 273 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 274 | ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); |
| 275 | networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"), |
| 276 | Ip4Address.valueOf("255.255.255.255")); |
| 277 | assertThat(ospfInterfaces.size(), is(1)); |
| 278 | assertThat(networkLsa, is(notNullValue())); |
| 279 | assertThat(ospfArea, is(notNullValue())); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Tests buildRouterLsa() method. |
| 284 | */ |
| 285 | @Test |
| 286 | public void testBuildRouterLsa() throws Exception { |
| 287 | ospfNbrList = new HashMap(); |
| 288 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 289 | Ip4Address.valueOf("1.1.1.1"), |
| 290 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 291 | new OspfInterfaceChannelHandler(new Controller(), |
| 292 | new OspfAreaImpl(), |
| 293 | new OspfInterfaceImpl()) |
| 294 | , topologyForDeviceAndLink); |
| 295 | ospfNbr.setState(OspfNeighborState.FULL); |
| 296 | ospfInterfaces = new ArrayList(); |
| 297 | ospfInterface1 = new OspfInterfaceImpl(); |
| 298 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 299 | ospfInterface1.setState(OspfInterfaceState.DOWN); |
| 300 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 301 | ospfInterfaces.add(ospfInterface1); |
| 302 | ospfInterface2 = new OspfInterfaceImpl(); |
| 303 | ospfInterface2.setState(OspfInterfaceState.LOOPBACK); |
| 304 | ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); |
| 305 | ospfInterface2.addNeighbouringRouter(ospfNbr); |
| 306 | ospfInterfaces.add(ospfInterface2); |
| 307 | ospfInterface3 = new OspfInterfaceImpl(); |
| 308 | ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 309 | ospfInterface3.setState(OspfInterfaceState.POINT2POINT); |
| 310 | ospfInterface3.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); |
| 311 | ospfInterface3.addNeighbouringRouter(ospfNbr); |
| 312 | ospfInterface3.setListOfNeighbors(ospfNbrList); |
| 313 | ospfInterfaces.add(ospfInterface3); |
| 314 | ospfInterface4 = new OspfInterfaceImpl(); |
| 315 | ospfInterface4.setState(OspfInterfaceState.WAITING); |
| 316 | ospfInterface4.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 317 | ospfInterface4.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); |
| 318 | ospfInterfaces.add(ospfInterface4); |
| 319 | ospfInterface5 = new OspfInterfaceImpl(); |
| 320 | ospfInterface5.setState(OspfInterfaceState.DR); |
| 321 | ospfInterface5.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 322 | ospfInterfaces.add(ospfInterface5); |
| 323 | ospfInterface6 = new OspfInterfaceImpl(); |
| 324 | ospfInterface6.setState(OspfInterfaceState.BDR); |
| 325 | ospfInterface6.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 326 | ospfInterface6.setDr(Ip4Address.valueOf("3.3.3.3")); |
| 327 | ospfInterfaces.add(ospfInterface6); |
| 328 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 329 | ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); |
| 330 | assertThat(ospfInterfaces.size(), is(6)); |
| 331 | routerLsa = ospfArea.buildRouterLsa(ospfInterface1); |
| 332 | assertThat(routerLsa, is(notNullValue())); |
| 333 | routerLsa = ospfArea.buildRouterLsa(ospfInterface2); |
| 334 | assertThat(routerLsa, is(notNullValue())); |
| 335 | routerLsa = ospfArea.buildRouterLsa(ospfInterface3); |
| 336 | assertThat(routerLsa, is(notNullValue())); |
| 337 | assertThat(ospfArea, is(notNullValue())); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Tests buildRouterLsa() method. |
| 342 | */ |
| 343 | @Test |
| 344 | public void testBuildRouterLsa1() throws Exception { |
| 345 | ospfInterfaces = new ArrayList(); |
| 346 | ospfInterface1 = new OspfInterfaceImpl(); |
| 347 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 348 | ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); |
| 349 | ospfInterface1.setState(OspfInterfaceState.POINT2POINT); |
| 350 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 351 | Ip4Address.valueOf("1.1.1.1"), |
| 352 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 353 | new OspfInterfaceChannelHandler(new Controller(), |
| 354 | new OspfAreaImpl(), |
| 355 | new OspfInterfaceImpl()) |
| 356 | , topologyForDeviceAndLink); |
| 357 | ospfNbr.setState(OspfNeighborState.FULL); |
| 358 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 359 | ospfInterfaces.add(ospfInterface1); |
| 360 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 361 | ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); |
| 362 | routerLsa = ospfArea.buildRouterLsa(ospfInterface1); |
| 363 | assertThat(routerLsa, is(notNullValue())); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Tests areaId() getter method. |
| 368 | */ |
| 369 | @Test |
| 370 | public void testGetAreaId() throws Exception { |
| 371 | ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1")); |
| 372 | assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1"))); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Tests areaId() setter method. |
| 377 | */ |
| 378 | @Test |
| 379 | public void testSetAreaId() throws Exception { |
| 380 | ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1")); |
| 381 | assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1"))); |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Tests addressRanges() getter method. |
| 386 | */ |
| 387 | @Test |
| 388 | public void testGetAddressRanges() throws Exception { |
| 389 | ospfAreaAddressRanges = new ArrayList(); |
| 390 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 391 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 392 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 393 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 394 | ospfArea.setAddressRanges(ospfAreaAddressRanges); |
| 395 | assertThat(ospfArea.addressRanges().size(), is(4)); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Tests addressRanges() setter method. |
| 400 | */ |
| 401 | @Test |
| 402 | public void testSetAddressRanges() throws Exception { |
| 403 | ospfAreaAddressRanges = new ArrayList(); |
| 404 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 405 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 406 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 407 | ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl()); |
| 408 | ospfArea.setAddressRanges(ospfAreaAddressRanges); |
| 409 | assertThat(ospfArea.addressRanges().size(), is(4)); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Tests isTransitCapability() getter method. |
| 414 | */ |
| 415 | @Test |
| 416 | public void testIsTransitCapability() throws Exception { |
| 417 | ospfArea.setTransitCapability(true); |
| 418 | assertThat(ospfArea.isTransitCapability(), is(true)); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Tests isTransitCapability() setter method. |
| 423 | */ |
| 424 | @Test |
| 425 | public void testSetTransitCapability() throws Exception { |
| 426 | ospfArea.setTransitCapability(true); |
| 427 | assertThat(ospfArea.isTransitCapability(), is(true)); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Tests isExternalRoutingCapability() getter method. |
| 432 | */ |
| 433 | @Test |
| 434 | public void testIsExternalRoutingCapability() throws Exception { |
| 435 | ospfArea.setExternalRoutingCapability(true); |
| 436 | assertThat(ospfArea.isExternalRoutingCapability(), is(true)); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Tests isExternalRoutingCapability() setter method. |
| 441 | */ |
| 442 | @Test |
| 443 | public void testSetExternalRoutingCapability() throws Exception { |
| 444 | ospfArea.setExternalRoutingCapability(true); |
| 445 | assertThat(ospfArea.isExternalRoutingCapability(), is(true)); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Tests stubCost() getter method. |
| 450 | */ |
| 451 | @Test |
| 452 | public void testGetStubCost() throws Exception { |
| 453 | ospfArea.setStubCost(100); |
| 454 | assertThat(ospfArea.stubCost(), is(100)); |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Tests stubCost() setter method. |
| 459 | */ |
| 460 | @Test |
| 461 | public void testSetStubCost() throws Exception { |
| 462 | ospfArea.setStubCost(100); |
| 463 | assertThat(ospfArea.stubCost(), is(100)); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Tests getInterfacesLst() getter method. |
| 468 | */ |
| 469 | @Test |
| 470 | public void testGetInterfacesLst() throws Exception { |
| 471 | ospfInterfaces = new ArrayList(); |
| 472 | ospfInterface1 = new OspfInterfaceImpl(); |
| 473 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 474 | ospfInterfaces.add(ospfInterface1); |
| 475 | ospfInterface2 = new OspfInterfaceImpl(); |
| 476 | ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); |
| 477 | ospfInterfaces.add(ospfInterface2); |
| 478 | ospfInterface3 = new OspfInterfaceImpl(); |
| 479 | ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 480 | ospfInterfaces.add(ospfInterface3); |
| 481 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 482 | assertThat(ospfInterfaces.size(), is(3)); |
| 483 | assertThat(ospfArea.getInterfacesLst(), is(notNullValue())); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Tests setInterfacesLst() setter method. |
| 488 | */ |
| 489 | @Test |
| 490 | public void testSetInterfacesLst() throws Exception { |
| 491 | ospfInterfaces = new ArrayList(); |
| 492 | ospfInterface1 = new OspfInterfaceImpl(); |
| 493 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 494 | ospfInterfaces.add(ospfInterface1); |
| 495 | ospfInterface2 = new OspfInterfaceImpl(); |
| 496 | ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); |
| 497 | ospfInterfaces.add(ospfInterface2); |
| 498 | ospfInterface3 = new OspfInterfaceImpl(); |
| 499 | ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); |
| 500 | ospfInterfaces.add(ospfInterface3); |
| 501 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 502 | assertThat(ospfInterfaces.size(), is(3)); |
| 503 | assertThat(ospfArea.getInterfacesLst(), is(notNullValue())); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Tests noNeighborInLsaExchangeProcess() method. |
| 508 | */ |
| 509 | @Test |
| 510 | public void testNoNeighborInLsaExchangeProcess() throws Exception { |
| 511 | ospfInterfaces = new ArrayList(); |
| 512 | ospfInterface1 = new OspfInterfaceImpl(); |
| 513 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 514 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 515 | Ip4Address.valueOf("1.1.1.1"), |
| 516 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 517 | new OspfInterfaceChannelHandler(new Controller(), |
| 518 | new OspfAreaImpl(), |
| 519 | new OspfInterfaceImpl()) |
| 520 | , topologyForDeviceAndLink); |
| 521 | ospfNbr.setState(OspfNeighborState.EXCHANGE.EXCHANGE); |
| 522 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 523 | ospfInterfaces.add(ospfInterface1); |
| 524 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 525 | assertThat(ospfArea.noNeighborInLsaExchangeProcess(), is(false)); |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * Tests getLsaHeaders() method. |
| 530 | */ |
| 531 | @Test |
| 532 | public void testGetLsaHeaders() throws Exception { |
| 533 | assertThat(ospfArea.getLsaHeaders(true, true).size(), is(0)); |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Tests getLsa() method. |
| 538 | */ |
| 539 | @Test |
| 540 | public void testGetLsa() throws Exception { |
| 541 | assertThat(ospfArea.getLsa(1, "1.1.1.1", "1.1.1.1"), is(nullValue())); |
| 542 | assertThat(ospfArea.getLsa(10, "1.1.1.1", "1.1.1.1"), is(nullValue())); |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Tests lsaLookup() method. |
| 547 | */ |
| 548 | @Test |
| 549 | public void testLsaLookup() throws Exception { |
| 550 | assertThat(ospfArea.lsaLookup(new RouterLsa()), is(nullValue())); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Tests isNewerOrSameLsa() method. |
| 555 | */ |
| 556 | @Test |
| 557 | public void testIsNewerOrSameLsa() throws Exception { |
| 558 | assertThat(ospfArea.isNewerOrSameLsa(new RouterLsa(), new RouterLsa()), is("same")); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Tests addLsa() method. |
| 563 | */ |
| 564 | @Test |
| 565 | public void testAddLsa() throws Exception { |
| 566 | ospfArea.addLsa(new RouterLsa(), new OspfInterfaceImpl()); |
| 567 | assertThat(ospfArea, is(notNullValue())); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Tests addLsa() method. |
| 572 | */ |
| 573 | @Test |
| 574 | public void testAddLsa1() throws Exception { |
| 575 | ospfArea.addLsa(new RouterLsa(), false, new OspfInterfaceImpl()); |
| 576 | assertThat(ospfArea, is(notNullValue())); |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Tests addLsaToMaxAgeBin() method. |
| 581 | */ |
| 582 | @Test |
| 583 | public void testAddLsaToMaxAgeBin() throws Exception { |
| 584 | ospfArea.addLsaToMaxAgeBin("111", new LsaWrapperImpl()); |
| 585 | assertThat(ospfArea, is(notNullValue())); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Tests setDbRouterSequenceNumber() method. |
| 590 | */ |
| 591 | @Test |
| 592 | public void testSetDbRouterSequenceNumber() throws Exception { |
| 593 | ospfArea.setDbRouterSequenceNumber(123456); |
| 594 | assertThat(ospfArea, is(notNullValue())); |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * Tests deleteLsa() method. |
| 599 | */ |
| 600 | @Test |
| 601 | public void testDeleteLsa() throws Exception { |
| 602 | ospfArea.deleteLsa(new LsaHeader()); |
| 603 | assertThat(ospfArea, is(notNullValue())); |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Tests removeLsaFromBin() method. |
| 608 | */ |
| 609 | @Test |
| 610 | public void testRemoveLsaFromBin() throws Exception { |
| 611 | ospfArea.removeLsaFromBin(new LsaWrapperImpl()); |
| 612 | assertThat(ospfArea, is(notNullValue())); |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Tests to string method. |
| 617 | */ |
| 618 | @Test |
| 619 | public void testToString() throws Exception { |
| 620 | assertThat(ospfArea.toString(), is(notNullValue())); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Tests getNeighborsInFullState() method. |
| 625 | */ |
| 626 | @Test |
| 627 | public void testGetNeighborsinFullState() throws Exception { |
| 628 | ospfInterfaces = new ArrayList(); |
| 629 | ospfInterface1 = new OspfInterfaceImpl(); |
| 630 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 631 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 632 | Ip4Address.valueOf("1.1.1.1"), |
| 633 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 634 | new OspfInterfaceChannelHandler(new Controller(), |
| 635 | new OspfAreaImpl(), |
| 636 | new OspfInterfaceImpl()) |
| 637 | , topologyForDeviceAndLink); |
| 638 | ospfNbr.setState(OspfNeighborState.FULL); |
| 639 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 640 | ospfInterfaces.add(ospfInterface1); |
| 641 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 642 | assertThat(ospfArea.getNeighborsInFullState(ospfInterface1).size(), is(1)); |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Tests getLsaKey() method. |
| 647 | */ |
| 648 | @Test |
| 649 | public void testGetLsaKey() throws Exception { |
| 650 | lsaHeader = new LsaHeader(); |
| 651 | lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1")); |
| 652 | assertThat(ospfArea.getLsaKey(lsaHeader), is(notNullValue())); |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Tests addToOtherNeighborLsaTxList() method. |
| 657 | */ |
| 658 | @Test |
| 659 | public void testAddToOtherNeighborLsaTxList() throws Exception { |
| 660 | ospfInterfaces = new ArrayList(); |
| 661 | ospfInterface1 = new OspfInterfaceImpl(); |
| 662 | ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); |
| 663 | ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), |
| 664 | Ip4Address.valueOf("1.1.1.1"), |
| 665 | Ip4Address.valueOf("2.2.2.2"), 2, |
| 666 | new OspfInterfaceChannelHandler(new Controller(), |
| 667 | new OspfAreaImpl(), |
| 668 | new OspfInterfaceImpl()) |
| 669 | , topologyForDeviceAndLink); |
| 670 | ospfNbr.setState(OspfNeighborState.FULL); |
| 671 | ospfInterface1.addNeighbouringRouter(ospfNbr); |
| 672 | ospfInterfaces.add(ospfInterface1); |
| 673 | ospfArea.setInterfacesLst(ospfInterfaces); |
| 674 | lsaHeader = new LsaHeader(); |
| 675 | lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1")); |
| 676 | ospfArea.addToOtherNeighborLsaTxList(lsaHeader); |
| 677 | assertThat(ospfArea, is(notNullValue())); |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Tests options() getter method. |
| 682 | */ |
| 683 | @Test |
| 684 | public void testGetOptions() throws Exception { |
| 685 | ospfArea.setOptions(2); |
| 686 | assertThat(ospfArea.options(), is(2)); |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Tests options() setter method. |
| 691 | */ |
| 692 | @Test |
| 693 | public void testSetOptions() throws Exception { |
| 694 | ospfArea.setOptions(2); |
| 695 | assertThat(ospfArea.options(), is(2)); |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Tests isOpaqueEnabled() method. |
| 700 | */ |
| 701 | @Test |
| 702 | public void testGetOpaqueEnabledOptions() throws Exception { |
| 703 | ospfArea.setIsOpaqueEnabled(true); |
| 704 | assertThat(ospfArea.isOpaqueEnabled(), is(true)); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Tests database() method. |
| 709 | */ |
| 710 | @Test |
| 711 | public void testGetDatabase() throws Exception { |
| 712 | assertThat(ospfArea.database(), is(notNullValue())); |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * Tests opaqueEnabledOptions() method. |
| 717 | */ |
| 718 | @Test |
| 719 | public void testOpaqueEnabledOptionsa() throws Exception { |
| 720 | assertThat(ospfArea.opaqueEnabledOptions(), is(66)); |
| 721 | } |
| 722 | } |