chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.isis.controller.impl; |
| 17 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.jboss.netty.channel.Channel; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 22 | import org.junit.After; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
| 25 | import org.onlab.packet.Ip4Address; |
| 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onosproject.isis.controller.IsisInterface; |
| 28 | import org.onosproject.isis.controller.IsisInterfaceState; |
| 29 | import org.onosproject.isis.controller.IsisLsdb; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 30 | import org.onosproject.isis.controller.IsisMessage; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 31 | import org.onosproject.isis.controller.IsisNeighbor; |
| 32 | import org.onosproject.isis.controller.IsisNetworkType; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 33 | import org.onosproject.isis.controller.IsisPduType; |
| 34 | import org.onosproject.isis.controller.IsisRouterType; |
| 35 | import org.onosproject.isis.controller.impl.lsdb.DefaultIsisLsdb; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 36 | import org.onosproject.isis.io.isispacket.IsisHeader; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 37 | import org.onosproject.isis.io.isispacket.pdu.Csnp; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 38 | import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 39 | import org.onosproject.isis.io.isispacket.pdu.LsPdu; |
| 40 | import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; |
| 41 | import org.onosproject.isis.io.isispacket.pdu.Psnp; |
| 42 | import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; |
| 43 | import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; |
| 44 | import org.onosproject.isis.io.isispacket.tlv.LspEntriesTlv; |
| 45 | import org.onosproject.isis.io.isispacket.tlv.LspEntry; |
| 46 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; |
| 47 | import org.onosproject.isis.io.isispacket.tlv.TlvType; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 48 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 49 | import java.util.ArrayList; |
| 50 | import java.util.List; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 51 | import java.util.Set; |
| 52 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 53 | import static org.hamcrest.CoreMatchers.*; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 54 | import static org.junit.Assert.assertThat; |
| 55 | |
| 56 | /** |
| 57 | * Unit test case for DefaultIsisInterface. |
| 58 | */ |
| 59 | public class DefaultIsisInterfaceTest { |
| 60 | private final MacAddress macAddress = MacAddress.valueOf("AA:BB:CC:DD:EE:FF"); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 61 | private final MacAddress macAddress1 = MacAddress.valueOf("AA:CC:CC:DD:EE:FF"); |
| 62 | private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.0.0"); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 63 | private final byte[] mask = { |
| 64 | (byte) 255, (byte) 255, (byte) 255, (byte) 224 |
| 65 | }; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 66 | private final byte[] mask1 = { |
| 67 | (byte) 0, (byte) 0, (byte) 0, (byte) 0 |
| 68 | }; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 69 | private final String intSysName = "ROUTER"; |
| 70 | private final String sysId = "1111.1111.1111"; |
| 71 | private final String areaAddr = "49.002"; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 72 | private final byte[] csnpBytes = { |
| 73 | 0, 67, 18, 52, 18, 52, 0, |
| 74 | 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, |
| 75 | -1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0, |
| 76 | 0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0, |
| 77 | 0, 0, 0, 0, 1, 91, 126 |
| 78 | }; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 79 | private IsisInterfaceState resultIfState; |
| 80 | private DefaultIsisInterface defaultIsisInterface; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 81 | private IsisHeader isisHeader; |
| 82 | private IsisInterface isisInterface; |
| 83 | private Set<MacAddress> resultSet; |
| 84 | private int resultInt; |
| 85 | private IsisLsdb resultLsdb; |
| 86 | private IsisNeighbor resultNeighborList; |
| 87 | private Ip4Address resultIPv4Addr; |
| 88 | private MacAddress resultMacAddr; |
| 89 | private byte[] resultByteArr; |
| 90 | private String resultStr; |
| 91 | private IsisNetworkType resultNwType; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 92 | private List<Ip4Address> ip4Addresses = new ArrayList<>(); |
| 93 | private DefaultIsisNeighbor defaultIsisNeighbor; |
| 94 | private IsisNeighbor result; |
| 95 | private IsisLsdb result1; |
| 96 | private Set<MacAddress> result2; |
| 97 | private Channel result3; |
| 98 | private IsisMessage isisMessage; |
| 99 | private IsisLsdb isisLsdb; |
| 100 | private Channel channel; |
| 101 | private L1L2HelloPdu helloPdu; |
| 102 | private LsPdu lsPdu; |
| 103 | private Csnp csnp; |
| 104 | private Psnp psnp; |
| 105 | private P2PHelloPdu p2PHelloPdu; |
| 106 | private boolean result4; |
| 107 | private String result5; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 108 | |
| 109 | @Before |
| 110 | public void setUp() throws Exception { |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 111 | channel = EasyMock.createNiceMock(Channel.class); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 112 | defaultIsisInterface = new DefaultIsisInterface(); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 113 | defaultIsisInterface.setInterfaceMacAddress(macAddress); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 114 | isisHeader = new IsisHeader(); |
| 115 | isisHeader.setIrpDiscriminator((byte) 1); |
| 116 | helloPdu = new L1L2HelloPdu(isisHeader); |
| 117 | isisInterface = new DefaultIsisInterface(); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 118 | defaultIsisNeighbor = new DefaultIsisNeighbor(helloPdu, isisInterface); |
| 119 | defaultIsisNeighbor.setNeighborMacAddress(macAddress); |
| 120 | isisLsdb = new DefaultIsisLsdb(); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @After |
| 124 | public void tearDown() throws Exception { |
| 125 | defaultIsisInterface = null; |
| 126 | helloPdu = null; |
| 127 | isisInterface = null; |
| 128 | resultNeighborList = null; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Tests interfaceIndex() getter method. |
| 133 | */ |
| 134 | @Test |
| 135 | public void testInterfaceIndex() throws Exception { |
| 136 | defaultIsisInterface.setInterfaceIndex(2); |
| 137 | resultInt = defaultIsisInterface.interfaceIndex(); |
| 138 | assertThat(resultInt, is(2)); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Tests interfaceIndex() setter method. |
| 143 | */ |
| 144 | @Test |
| 145 | public void testSetInterfaceIndex() throws Exception { |
| 146 | defaultIsisInterface.setInterfaceIndex(2); |
| 147 | resultInt = defaultIsisInterface.interfaceIndex(); |
| 148 | assertThat(resultInt, is(2)); |
| 149 | |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Tests interfaceIpAddress() getter method. |
| 154 | */ |
| 155 | @Test |
| 156 | public void testInterfaceIpAddress() throws Exception { |
| 157 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 158 | resultIPv4Addr = defaultIsisInterface.interfaceIpAddress(); |
| 159 | assertThat(resultIPv4Addr, is(ip4Address)); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Tests interfaceIpAddress() setter method. |
| 164 | */ |
| 165 | @Test |
| 166 | public void testSetInterfaceIpAddress() throws Exception { |
| 167 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 168 | resultIPv4Addr = defaultIsisInterface.interfaceIpAddress(); |
| 169 | assertThat(resultIPv4Addr, is(ip4Address)); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Tests networkMask() getter method. |
| 174 | */ |
| 175 | @Test |
| 176 | public void testNetworkMask() throws Exception { |
| 177 | defaultIsisInterface.setNetworkMask(mask); |
| 178 | resultByteArr = defaultIsisInterface.networkMask(); |
| 179 | assertThat(resultByteArr, is(mask)); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Tests networkMask() setter method. |
| 184 | */ |
| 185 | @Test |
| 186 | public void testSetNetworkMask() throws Exception { |
| 187 | defaultIsisInterface.setNetworkMask(mask); |
| 188 | resultByteArr = defaultIsisInterface.networkMask(); |
| 189 | assertThat(resultByteArr, is(mask)); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Tests getInterfaceMacAddress() getter method. |
| 194 | */ |
| 195 | @Test |
| 196 | public void testGetInterfaceMacAddress() throws Exception { |
| 197 | defaultIsisInterface.setInterfaceMacAddress(macAddress); |
| 198 | resultMacAddr = defaultIsisInterface.getInterfaceMacAddress(); |
| 199 | assertThat(resultMacAddr, is(macAddress)); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Tests getInterfaceMacAddress() setter method. |
| 204 | */ |
| 205 | @Test |
| 206 | public void testSetInterfaceMacAddress() throws Exception { |
| 207 | defaultIsisInterface.setInterfaceMacAddress(macAddress); |
| 208 | resultMacAddr = defaultIsisInterface.getInterfaceMacAddress(); |
| 209 | assertThat(resultMacAddr, is(macAddress)); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Tests intermediateSystemName() getter method. |
| 214 | */ |
| 215 | @Test |
| 216 | public void testIntermediateSystemName() throws Exception { |
| 217 | defaultIsisInterface.setIntermediateSystemName(intSysName); |
| 218 | resultStr = defaultIsisInterface.intermediateSystemName(); |
| 219 | assertThat(resultStr, is(intSysName)); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Tests intermediateSystemName() setter method. |
| 224 | */ |
| 225 | @Test |
| 226 | public void testSetIntermediateSystemName() throws Exception { |
| 227 | defaultIsisInterface.setIntermediateSystemName(intSysName); |
| 228 | resultStr = defaultIsisInterface.intermediateSystemName(); |
| 229 | assertThat(resultStr, is(intSysName)); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Tests systemId() getter method. |
| 234 | */ |
| 235 | @Test |
| 236 | public void testSystemId() throws Exception { |
| 237 | defaultIsisInterface.setSystemId(sysId); |
| 238 | resultStr = defaultIsisInterface.systemId(); |
| 239 | assertThat(resultStr, is(sysId)); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Tests systemId() setter method. |
| 244 | */ |
| 245 | @Test |
| 246 | public void testSetSystemId() throws Exception { |
| 247 | defaultIsisInterface.setSystemId(sysId); |
| 248 | resultStr = defaultIsisInterface.systemId(); |
| 249 | assertThat(resultStr, is(sysId)); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Tests l1LanId() getter method. |
| 254 | */ |
| 255 | @Test |
| 256 | public void testL1LanId() throws Exception { |
| 257 | defaultIsisInterface.setL1LanId(sysId); |
| 258 | resultStr = defaultIsisInterface.l1LanId(); |
| 259 | assertThat(resultStr, is(sysId)); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Tests l1LanId() setter method. |
| 264 | */ |
| 265 | @Test |
| 266 | public void testSetL1LanId() throws Exception { |
| 267 | defaultIsisInterface.setL1LanId(sysId); |
| 268 | resultStr = defaultIsisInterface.l1LanId(); |
| 269 | assertThat(resultStr, is(sysId)); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Tests l2LanId() getter method. |
| 274 | */ |
| 275 | @Test |
| 276 | public void testL2LanId() throws Exception { |
| 277 | defaultIsisInterface.setL2LanId(sysId); |
| 278 | resultStr = defaultIsisInterface.l2LanId(); |
| 279 | assertThat(resultStr, is(sysId)); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Tests l2LanId() setter method. |
| 284 | */ |
| 285 | @Test |
| 286 | public void testSetL2LanId() throws Exception { |
| 287 | defaultIsisInterface.setL2LanId(sysId); |
| 288 | resultStr = defaultIsisInterface.l2LanId(); |
| 289 | assertThat(resultStr, is(sysId)); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Tests getIdLength() getter method. |
| 294 | */ |
| 295 | @Test |
| 296 | public void testGetIdLength() throws Exception { |
| 297 | defaultIsisInterface.setIdLength(8); |
| 298 | resultInt = defaultIsisInterface.getIdLength(); |
| 299 | assertThat(resultInt, is(8)); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Tests getIdLength() setter method. |
| 304 | */ |
| 305 | @Test |
| 306 | public void testSetIdLength() throws Exception { |
| 307 | defaultIsisInterface.setIdLength(8); |
| 308 | resultInt = defaultIsisInterface.getIdLength(); |
| 309 | assertThat(resultInt, is(8)); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Tests getMaxAreaAddresses() getter method. |
| 314 | */ |
| 315 | @Test |
| 316 | public void testGetMaxAreaAddresses() throws Exception { |
| 317 | defaultIsisInterface.setMaxAreaAddresses(3); |
| 318 | resultInt = defaultIsisInterface.getMaxAreaAddresses(); |
| 319 | assertThat(resultInt, is(3)); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Tests getMaxAreaAddresses() setter method. |
| 324 | */ |
| 325 | @Test |
| 326 | public void testSetMaxAreaAddresses() throws Exception { |
| 327 | defaultIsisInterface.setMaxAreaAddresses(3); |
| 328 | resultInt = defaultIsisInterface.getMaxAreaAddresses(); |
| 329 | assertThat(resultInt, is(3)); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Tests setReservedPacketCircuitType() getter method. |
| 334 | */ |
| 335 | @Test |
| 336 | public void testReservedPacketCircuitType() throws Exception { |
| 337 | defaultIsisInterface.setReservedPacketCircuitType(1); |
| 338 | resultInt = defaultIsisInterface.reservedPacketCircuitType(); |
| 339 | assertThat(resultInt, is(1)); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Tests setReservedPacketCircuitType() setter method. |
| 344 | */ |
| 345 | @Test |
| 346 | public void testSetReservedPacketCircuitType() throws Exception { |
| 347 | defaultIsisInterface.setReservedPacketCircuitType(1); |
| 348 | resultInt = defaultIsisInterface.reservedPacketCircuitType(); |
| 349 | assertThat(resultInt, is(1)); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Tests networkType() getter method. |
| 354 | */ |
| 355 | @Test |
| 356 | public void testNetworkType() throws Exception { |
| 357 | defaultIsisInterface.setNetworkType(IsisNetworkType.BROADCAST); |
| 358 | resultNwType = defaultIsisInterface.networkType(); |
| 359 | assertThat(resultNwType, is(IsisNetworkType.BROADCAST)); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Tests networkType() setter method. |
| 364 | */ |
| 365 | @Test |
| 366 | public void testSetNetworkType() throws Exception { |
| 367 | defaultIsisInterface.setNetworkType(IsisNetworkType.BROADCAST); |
| 368 | resultNwType = defaultIsisInterface.networkType(); |
| 369 | assertThat(resultNwType, is(IsisNetworkType.BROADCAST)); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Tests areaAddress() getter method. |
| 374 | */ |
| 375 | @Test |
| 376 | public void testAreaAddress() throws Exception { |
| 377 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 378 | resultStr = defaultIsisInterface.areaAddress(); |
| 379 | assertThat(resultStr, is(areaAddr)); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Tests areaAddress() setter method. |
| 384 | */ |
| 385 | @Test |
| 386 | public void testSetAreaAddress() throws Exception { |
| 387 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 388 | resultStr = defaultIsisInterface.areaAddress(); |
| 389 | assertThat(resultStr, is(areaAddr)); |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Tests getAreaLength() getter method. |
| 394 | */ |
| 395 | |
| 396 | @Test |
| 397 | public void testGetAreaLength() throws Exception { |
| 398 | defaultIsisInterface.setAreaLength(3); |
| 399 | resultInt = defaultIsisInterface.getAreaLength(); |
| 400 | assertThat(resultInt, is(3)); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Tests getAreaLength() setter method. |
| 405 | */ |
| 406 | @Test |
| 407 | public void testSetAreaLength() throws Exception { |
| 408 | defaultIsisInterface.setAreaLength(3); |
| 409 | resultInt = defaultIsisInterface.getAreaLength(); |
| 410 | assertThat(resultInt, is(3)); |
| 411 | } |
| 412 | |
| 413 | /** |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 414 | * Tests holdingTime() getter method. |
| 415 | */ |
| 416 | @Test |
| 417 | public void testHoldingTime() throws Exception { |
| 418 | defaultIsisInterface.setHoldingTime(10); |
| 419 | resultInt = defaultIsisInterface.holdingTime(); |
| 420 | assertThat(resultInt, is(10)); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Tests holdingTime() setter method. |
| 425 | */ |
| 426 | @Test |
| 427 | public void testSetHoldingTime() throws Exception { |
| 428 | defaultIsisInterface.setHoldingTime(10); |
| 429 | resultInt = defaultIsisInterface.holdingTime(); |
| 430 | assertThat(resultInt, is(10)); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Tests priority() getter method. |
| 435 | */ |
| 436 | @Test |
| 437 | public void testPriority() throws Exception { |
| 438 | defaultIsisInterface.setPriority(1); |
| 439 | resultInt = defaultIsisInterface.priority(); |
| 440 | assertThat(resultInt, is(1)); |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Tests priority() setter method. |
| 445 | */ |
| 446 | @Test |
| 447 | public void testSetPriority() throws Exception { |
| 448 | defaultIsisInterface.setPriority(1); |
| 449 | resultInt = defaultIsisInterface.priority(); |
| 450 | assertThat(resultInt, is(1)); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Tests helloInterval() getter method. |
| 455 | */ |
| 456 | @Test |
| 457 | public void testHelloInterval() throws Exception { |
| 458 | defaultIsisInterface.setHelloInterval(10); |
| 459 | resultInt = defaultIsisInterface.helloInterval(); |
| 460 | assertThat(resultInt, is(10)); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Tests helloInterval() setter method. |
| 465 | */ |
| 466 | @Test |
| 467 | public void testSetHelloInterval() throws Exception { |
| 468 | defaultIsisInterface.setHelloInterval(10); |
| 469 | resultInt = defaultIsisInterface.helloInterval(); |
| 470 | assertThat(resultInt, is(10)); |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * Tests interfaceState() getter method. |
| 475 | */ |
| 476 | @Test |
| 477 | public void testInterfaceState() throws Exception { |
| 478 | defaultIsisInterface.setInterfaceState(IsisInterfaceState.UP); |
| 479 | resultIfState = defaultIsisInterface.interfaceState(); |
| 480 | assertThat(resultIfState, is(IsisInterfaceState.UP)); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Tests interfaceState() setter method. |
| 485 | */ |
| 486 | @Test |
| 487 | public void testSetInterfaceState() throws Exception { |
| 488 | defaultIsisInterface.setInterfaceState(IsisInterfaceState.UP); |
| 489 | resultIfState = defaultIsisInterface.interfaceState(); |
| 490 | assertThat(resultIfState, is(IsisInterfaceState.UP)); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Tests setCircuitId() getter method. |
| 495 | */ |
| 496 | @Test |
| 497 | public void testCircuitId() throws Exception { |
| 498 | defaultIsisInterface.setCircuitId(sysId); |
| 499 | resultStr = defaultIsisInterface.circuitId(); |
| 500 | assertThat(resultStr, is(sysId)); |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Tests setCircuitId() setter method. |
| 505 | */ |
| 506 | @Test |
| 507 | public void testSetCircuitId() throws Exception { |
| 508 | defaultIsisInterface.setCircuitId(sysId); |
| 509 | resultStr = defaultIsisInterface.circuitId(); |
| 510 | assertThat(resultStr, is(sysId)); |
| 511 | } |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 512 | |
| 513 | /** |
| 514 | * Tests setAllConfiguredInterfaceIps() setter method. |
| 515 | */ |
| 516 | @Test |
| 517 | public void testSetAllConfiguredInterfaceIps() throws Exception { |
| 518 | ip4Addresses.add(ip4Address); |
| 519 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 520 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Tests setAllConfiguredInterfaceIps() method. |
| 525 | */ |
| 526 | @Test |
| 527 | public void testRemoveNeighbor() throws Exception { |
| 528 | defaultIsisInterface.removeNeighbor(defaultIsisNeighbor); |
| 529 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * Tests lookup() method. |
| 534 | */ |
| 535 | @Test |
| 536 | public void testLookup() throws Exception { |
| 537 | result = defaultIsisInterface.lookup(defaultIsisNeighbor.neighborMacAddress()); |
| 538 | assertThat(result, is(nullValue())); |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Tests isisLsdb() method. |
| 543 | */ |
| 544 | @Test |
| 545 | public void testIsisLsdb() throws Exception { |
| 546 | result1 = defaultIsisInterface.isisLsdb(); |
| 547 | assertThat(result1, is(nullValue())); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Tests neighbors() method. |
| 552 | */ |
| 553 | @Test |
| 554 | public void testNeighbors() throws Exception { |
| 555 | result2 = defaultIsisInterface.neighbors(); |
| 556 | assertThat(result2, is(notNullValue())); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Tests channel() method. |
| 561 | */ |
| 562 | @Test |
| 563 | public void testChannel() throws Exception { |
| 564 | result3 = defaultIsisInterface.channel(); |
| 565 | assertThat(result3, is(nullValue())); |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Tests processIsisMessage() method. |
| 570 | */ |
| 571 | @Test |
| 572 | public void testProcessIsisMessage() throws Exception { |
| 573 | helloPdu = new L1L2HelloPdu(isisHeader); |
| 574 | helloPdu.setSourceMac(macAddress1); |
| 575 | helloPdu.setIsisPduType(IsisPduType.L2HELLOPDU.value()); |
| 576 | defaultIsisInterface.setNetworkType(IsisNetworkType.BROADCAST); |
| 577 | isisMessage = helloPdu; |
| 578 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 579 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Tests processIsisMessage() method. |
| 584 | */ |
| 585 | @Test(expected = Exception.class) |
| 586 | public void testProcessIsisMessage1() throws Exception { |
| 587 | lsPdu = new LsPdu(isisHeader); |
| 588 | lsPdu.setSourceMac(macAddress1); |
| 589 | lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value()); |
| 590 | isisMessage = lsPdu; |
| 591 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 592 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Tests processIsisMessage() method. |
| 597 | */ |
| 598 | @Test |
| 599 | public void testProcessIsisMessage2() throws Exception { |
| 600 | csnp = new Csnp(isisHeader); |
| 601 | csnp.setSourceMac(macAddress1); |
| 602 | csnp.setIsisPduType(IsisPduType.L2CSNP.value()); |
| 603 | isisMessage = csnp; |
| 604 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 605 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Tests processIsisMessage() method. |
| 610 | */ |
| 611 | @Test |
| 612 | public void testProcessIsisMessage3() throws Exception { |
| 613 | psnp = new Psnp(isisHeader); |
| 614 | psnp.setSourceMac(macAddress1); |
| 615 | psnp.setIsisPduType(IsisPduType.L2PSNP.value()); |
| 616 | isisMessage = psnp; |
| 617 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 618 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Tests processIsisMessage() method. |
| 623 | */ |
| 624 | @Test |
| 625 | public void testProcessIsisMessage4() throws Exception { |
| 626 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 627 | p2PHelloPdu.setSourceMac(macAddress1); |
| 628 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 629 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 630 | isisMessage = p2PHelloPdu; |
| 631 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 632 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Tests validateHelloMessage() method. |
| 637 | */ |
| 638 | @Test |
| 639 | public void testValidateHelloMessage() throws Exception { |
| 640 | helloPdu = new L1L2HelloPdu(isisHeader); |
| 641 | result4 = defaultIsisInterface.validateHelloMessage(helloPdu); |
| 642 | assertThat(result4, is(false)); |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Tests processL1L2HelloPduMessage() method. |
| 647 | */ |
| 648 | @Test(expected = Exception.class) |
| 649 | public void testProcessL1L2HelloPduMessage() throws Exception { |
| 650 | helloPdu = new L1L2HelloPdu(isisHeader); |
| 651 | helloPdu.setSourceMac(macAddress1); |
| 652 | helloPdu.setCircuitType((byte) IsisRouterType.L2.value()); |
| 653 | defaultIsisInterface.processL1L2HelloPduMessage(helloPdu, channel); |
| 654 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * Tests processP2pHelloPduMessage() method. |
| 659 | */ |
| 660 | @Test(expected = Exception.class) |
| 661 | public void testProcessP2pHelloPduMessagee() throws Exception { |
| 662 | defaultIsisInterface.setSystemId(sysId); |
| 663 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 664 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 665 | p2PHelloPdu.setSourceMac(macAddress1); |
| 666 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value()); |
| 667 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 668 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 669 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * Tests processP2pHelloPduMessage() method. |
| 674 | */ |
| 675 | @Test(expected = Exception.class) |
| 676 | public void testProcessP2pHelloPduMessagee1() throws Exception { |
| 677 | defaultIsisInterface.setSystemId(sysId); |
| 678 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 679 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 680 | p2PHelloPdu.setSourceMac(macAddress1); |
| 681 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value()); |
| 682 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 683 | defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L2.value()); |
| 684 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 685 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 686 | defaultIsisInterface.setNetworkMask(mask1); |
| 687 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 688 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Tests processP2pHelloPduMessage() method. |
| 693 | */ |
| 694 | @Test(expected = Exception.class) |
| 695 | public void testProcessP2pHelloPduMessagee2() throws Exception { |
| 696 | defaultIsisInterface.setSystemId(sysId); |
| 697 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 698 | TlvHeader tlvHeader = new TlvHeader(); |
| 699 | tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); |
| 700 | AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); |
| 701 | areaAddressTlv.addAddress(areaAddr); |
| 702 | p2PHelloPdu.addTlv(areaAddressTlv); |
| 703 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 704 | p2PHelloPdu.setSourceMac(macAddress1); |
| 705 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value()); |
| 706 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 707 | defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value()); |
| 708 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 709 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 710 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 711 | defaultIsisInterface.setNetworkMask(mask1); |
| 712 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 713 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Tests processP2pHelloPduMessage() method. |
| 718 | */ |
| 719 | @Test(expected = Exception.class) |
| 720 | public void testProcessP2pHelloPduMessagee3() throws Exception { |
| 721 | defaultIsisInterface.setSystemId(sysId); |
| 722 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 723 | TlvHeader tlvHeader = new TlvHeader(); |
| 724 | tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value()); |
| 725 | AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader); |
| 726 | adjacencyStateTlv.setNeighborSystemId(sysId); |
| 727 | adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value()); |
| 728 | p2PHelloPdu.addTlv(adjacencyStateTlv); |
| 729 | tlvHeader = new TlvHeader(); |
| 730 | tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); |
| 731 | AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); |
| 732 | areaAddressTlv.addAddress(areaAddr); |
| 733 | p2PHelloPdu.addTlv(areaAddressTlv); |
| 734 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 735 | p2PHelloPdu.setSourceMac(macAddress1); |
| 736 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value()); |
| 737 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 738 | defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value()); |
| 739 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 740 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 741 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 742 | defaultIsisInterface.setNetworkMask(mask1); |
| 743 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 744 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Tests processP2pHelloPduMessage() method. |
| 749 | */ |
| 750 | @Test(expected = Exception.class) |
| 751 | public void testProcessP2pHelloPduMessagee4() throws Exception { |
| 752 | defaultIsisInterface.setSystemId(sysId); |
| 753 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 754 | TlvHeader tlvHeader = new TlvHeader(); |
| 755 | tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value()); |
| 756 | AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader); |
| 757 | adjacencyStateTlv.setNeighborSystemId(sysId); |
| 758 | adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.INITIAL.value()); |
| 759 | p2PHelloPdu.addTlv(adjacencyStateTlv); |
| 760 | tlvHeader = new TlvHeader(); |
| 761 | tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); |
| 762 | AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); |
| 763 | areaAddressTlv.addAddress(areaAddr); |
| 764 | p2PHelloPdu.addTlv(areaAddressTlv); |
| 765 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 766 | p2PHelloPdu.setSourceMac(macAddress1); |
| 767 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value()); |
| 768 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 769 | defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value()); |
| 770 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 771 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 772 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 773 | defaultIsisInterface.setNetworkMask(mask1); |
| 774 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 775 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 776 | } |
| 777 | |
| 778 | @Test(expected = Exception.class) |
| 779 | public void testProcessP2pHelloPduMessagee5() throws Exception { |
| 780 | defaultIsisInterface.setSystemId(sysId); |
| 781 | p2PHelloPdu = new P2PHelloPdu(isisHeader); |
| 782 | TlvHeader tlvHeader = new TlvHeader(); |
| 783 | tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value()); |
| 784 | AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader); |
| 785 | adjacencyStateTlv.setNeighborSystemId(sysId); |
| 786 | adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.UP.value()); |
| 787 | p2PHelloPdu.addTlv(adjacencyStateTlv); |
| 788 | tlvHeader = new TlvHeader(); |
| 789 | tlvHeader.setTlvType(TlvType.AREAADDRESS.value()); |
| 790 | AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader); |
| 791 | areaAddressTlv.addAddress(areaAddr); |
| 792 | p2PHelloPdu.addTlv(areaAddressTlv); |
| 793 | p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 794 | p2PHelloPdu.setSourceMac(macAddress1); |
| 795 | p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value()); |
| 796 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 797 | defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value()); |
| 798 | defaultIsisInterface.setAreaAddress(areaAddr); |
| 799 | defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses); |
| 800 | defaultIsisInterface.setInterfaceIpAddress(ip4Address); |
| 801 | defaultIsisInterface.setNetworkMask(mask1); |
| 802 | defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel); |
| 803 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Tests startHelloSender() method. |
| 808 | */ |
| 809 | @Test(expected = Exception.class) |
| 810 | public void testStartHelloSender() throws Exception { |
| 811 | defaultIsisInterface.startHelloSender(channel); |
| 812 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Tests lspKeyP2P() method. |
| 817 | */ |
| 818 | @Test |
| 819 | public void testLspKeyP2P() throws Exception { |
| 820 | result5 = defaultIsisInterface.lspKeyP2P(sysId); |
| 821 | assertThat(result5, is(notNullValue())); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Tests processLsPduMessage() method. |
| 826 | */ |
| 827 | @Test |
| 828 | public void testProcessLsPduMessage() throws Exception { |
| 829 | lsPdu = new LsPdu(isisHeader); |
| 830 | lsPdu.setSourceMac(macAddress1); |
| 831 | lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value()); |
| 832 | lsPdu.setLspId(sysId); |
| 833 | isisMessage = lsPdu; |
| 834 | defaultIsisInterface.setNetworkType(IsisNetworkType.P2P); |
| 835 | defaultIsisInterface.setSystemId(sysId); |
| 836 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 837 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 838 | } |
| 839 | |
| 840 | /** |
| 841 | * Tests processPsnPduMessage() method. |
| 842 | */ |
| 843 | @Test |
| 844 | public void testProcessPsnPduMessage() throws Exception { |
| 845 | psnp = new Psnp(isisHeader); |
| 846 | psnp.setSourceMac(macAddress1); |
| 847 | psnp.setIsisPduType(IsisPduType.L2PSNP.value()); |
| 848 | TlvHeader tlvHeader = new TlvHeader(); |
| 849 | tlvHeader.setTlvType(TlvType.LSPENTRY.value()); |
| 850 | tlvHeader.setTlvLength(0); |
| 851 | LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader); |
| 852 | LspEntry lspEntry = new LspEntry(); |
| 853 | lspEntry.setLspChecksum(0); |
| 854 | lspEntry.setLspSequenceNumber(0); |
| 855 | lspEntry.setRemainingTime(0); |
| 856 | lspEntriesTlv.addLspEntry(lspEntry); |
| 857 | psnp.addTlv(lspEntriesTlv); |
| 858 | isisMessage = psnp; |
| 859 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 860 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Tests processCsnPduMessage() method. |
| 865 | */ |
| 866 | @Test(expected = Exception.class) |
| 867 | public void testProcessCsnPduMessage() throws Exception { |
| 868 | ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); |
| 869 | csnp = new Csnp(isisHeader); |
| 870 | csnp.readFrom(channelBuffer); |
| 871 | csnp.setSourceMac(macAddress1); |
| 872 | csnp.setIsisPduType(IsisPduType.L2CSNP.value()); |
| 873 | isisMessage = csnp; |
| 874 | defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); |
| 875 | assertThat(defaultIsisInterface, is(notNullValue())); |
| 876 | } |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 877 | } |