Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014-2015 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.pcepio; |
| 17 | |
| 18 | import java.util.Arrays; |
| 19 | |
| 20 | import org.jboss.netty.buffer.ChannelBuffer; |
| 21 | import org.jboss.netty.buffer.ChannelBuffers; |
| 22 | import org.junit.After; |
| 23 | import org.junit.Assert; |
| 24 | import org.junit.Before; |
| 25 | import org.junit.Test; |
| 26 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 27 | import org.onosproject.pcepio.protocol.PcepFactories; |
| 28 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 29 | import org.onosproject.pcepio.protocol.PcepMessageReader; |
| 30 | import org.onosproject.pcepio.protocol.PcepOpenMsg; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | /** |
| 35 | * Test cases for PCEP OPEN Message. |
| 36 | */ |
| 37 | public class PcepOpenMsgTest { |
| 38 | |
| 39 | protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgTest.class); |
| 40 | |
| 41 | @Before |
| 42 | public void startUp() { |
| 43 | } |
| 44 | |
| 45 | @After |
| 46 | public void tearDown() { |
| 47 | |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void openMessageTest1() throws PcepParseException { |
| 52 | |
| 53 | // OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, ) |
| 54 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 55 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 56 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 57 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 58 | }; |
| 59 | |
| 60 | byte[] testOpenMsg = {0}; |
| 61 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 62 | buffer.writeBytes(openMsg); |
| 63 | |
| 64 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 65 | PcepMessage message = null; |
| 66 | try { |
| 67 | message = reader.readFrom(buffer); |
| 68 | } catch (PcepParseException e) { |
| 69 | e.printStackTrace(); |
| 70 | } |
| 71 | |
| 72 | if (message instanceof PcepOpenMsg) { |
| 73 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 74 | message.writeTo(buf); |
| 75 | testOpenMsg = buf.array(); |
| 76 | |
| 77 | int iReadLen = buf.writerIndex() - 0; |
| 78 | testOpenMsg = new byte[iReadLen]; |
| 79 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 80 | |
| 81 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 82 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 83 | log.debug("openMsg are equal :" + openMsg); |
| 84 | } else { |
| 85 | Assert.fail("test case failed"); |
| 86 | log.debug("not equal"); |
| 87 | } |
| 88 | } else { |
| 89 | Assert.fail("test case failed"); |
| 90 | log.debug("not equal"); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void openMessageTest2() throws PcepParseException { |
| 96 | |
| 97 | // OPEN OBJECT (STATEFUL-PCE-CAPABILITY). |
| 98 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 99 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 100 | 0x20, 0x1E, 0x78, 0x01, // OPEN object |
| 101 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f}; // STATEFUL-PCE-CAPABILITY |
| 102 | byte[] testOpenMsg = {0}; |
| 103 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 104 | buffer.writeBytes(openMsg); |
| 105 | |
| 106 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 107 | PcepMessage message = null; |
| 108 | try { |
| 109 | message = reader.readFrom(buffer); |
| 110 | } catch (PcepParseException e) { |
| 111 | e.printStackTrace(); |
| 112 | } |
| 113 | |
| 114 | if (message instanceof PcepOpenMsg) { |
| 115 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 116 | message.writeTo(buf); |
| 117 | testOpenMsg = buf.array(); |
| 118 | |
| 119 | int iReadLen = buf.writerIndex() - 0; |
| 120 | testOpenMsg = new byte[iReadLen]; |
| 121 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 122 | |
| 123 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 124 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 125 | log.debug("openMsg are equal :" + openMsg); |
| 126 | } else { |
| 127 | Assert.fail("test case failed"); |
| 128 | log.debug("not equal"); |
| 129 | } |
| 130 | } else { |
| 131 | Assert.fail("test case failed"); |
| 132 | log.debug("not equal"); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void openMessageTest3() throws PcepParseException { |
| 138 | |
| 139 | // OPEN OBJECT (GmplsCapability). |
| 140 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 141 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 142 | 0x20, 0x1E, 0x78, 0x01, // OPEN object |
| 143 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //GMPLS-CAPABILITY-TLV |
| 144 | |
| 145 | byte[] testOpenMsg = {0}; |
| 146 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 147 | buffer.writeBytes(openMsg); |
| 148 | |
| 149 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 150 | PcepMessage message = null; |
| 151 | try { |
| 152 | message = reader.readFrom(buffer); |
| 153 | } catch (PcepParseException e) { |
| 154 | e.printStackTrace(); |
| 155 | } |
| 156 | |
| 157 | if (message instanceof PcepOpenMsg) { |
| 158 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 159 | message.writeTo(buf); |
| 160 | testOpenMsg = buf.array(); |
| 161 | |
| 162 | int iReadLen = buf.writerIndex() - 0; |
| 163 | testOpenMsg = new byte[iReadLen]; |
| 164 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 165 | |
| 166 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 167 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 168 | log.debug("openMsg are equal :" + openMsg); |
| 169 | } else { |
| 170 | Assert.fail("test case failed"); |
| 171 | log.debug("not equal"); |
| 172 | } |
| 173 | } else { |
| 174 | Assert.fail("test case failed"); |
| 175 | log.debug("not equal"); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | @Test |
| 180 | public void openMessageTest4() throws PcepParseException { |
| 181 | |
| 182 | // OPEN OBJECT (StatefulLspDbVerTlv). |
| 183 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, |
| 184 | 0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20, |
| 185 | 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv |
| 186 | |
| 187 | byte[] testOpenMsg = {0}; |
| 188 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 189 | buffer.writeBytes(openMsg); |
| 190 | |
| 191 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 192 | PcepMessage message = null; |
| 193 | try { |
| 194 | message = reader.readFrom(buffer); |
| 195 | } catch (PcepParseException e) { |
| 196 | e.printStackTrace(); |
| 197 | } |
| 198 | |
| 199 | if (message instanceof PcepOpenMsg) { |
| 200 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 201 | message.writeTo(buf); |
| 202 | testOpenMsg = buf.array(); |
| 203 | |
| 204 | int iReadLen = buf.writerIndex() - 0; |
| 205 | testOpenMsg = new byte[iReadLen]; |
| 206 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 207 | |
| 208 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 209 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 210 | log.debug("openMsg are equal :" + openMsg); |
| 211 | } else { |
| 212 | Assert.fail("test case failed"); |
| 213 | log.debug("not equal"); |
| 214 | } |
| 215 | } else { |
| 216 | Assert.fail("test case failed"); |
| 217 | log.debug("not equal"); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | @Test |
| 222 | public void openMessageTest5() throws PcepParseException { |
| 223 | |
| 224 | // OPEN OBJECT (no Tlvs). |
| 225 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C, |
| 226 | 0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage |
| 227 | |
| 228 | byte[] testOpenMsg = {0}; |
| 229 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 230 | buffer.writeBytes(openMsg); |
| 231 | |
| 232 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 233 | PcepMessage message = null; |
| 234 | try { |
| 235 | message = reader.readFrom(buffer); |
| 236 | } catch (PcepParseException e) { |
| 237 | e.printStackTrace(); |
| 238 | } |
| 239 | |
| 240 | if (message instanceof PcepOpenMsg) { |
| 241 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 242 | message.writeTo(buf); |
| 243 | testOpenMsg = buf.array(); |
| 244 | |
| 245 | int iReadLen = buf.writerIndex() - 0; |
| 246 | testOpenMsg = new byte[iReadLen]; |
| 247 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 248 | |
| 249 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 250 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 251 | log.debug("openMsg are equal :" + openMsg); |
| 252 | } else { |
| 253 | Assert.fail("test case failed"); |
| 254 | log.debug("not equal"); |
| 255 | } |
| 256 | } else { |
| 257 | Assert.fail("test case failed"); |
| 258 | log.debug("not equal"); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | @Test |
| 263 | public void openMessageTest6() throws PcepParseException { |
| 264 | |
| 265 | /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) with |
| 266 | p bit not set & i bit set. |
| 267 | */ |
| 268 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set |
| 269 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 270 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY |
| 271 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 272 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 273 | }; |
| 274 | |
| 275 | byte[] testOpenMsg = {0}; |
| 276 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 277 | buffer.writeBytes(openMsg); |
| 278 | |
| 279 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 280 | PcepMessage message = null; |
| 281 | try { |
| 282 | message = reader.readFrom(buffer); |
| 283 | } catch (PcepParseException e) { |
| 284 | e.printStackTrace(); |
| 285 | } |
| 286 | |
| 287 | if (message instanceof PcepOpenMsg) { |
| 288 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 289 | message.writeTo(buf); |
| 290 | testOpenMsg = buf.array(); |
| 291 | |
| 292 | int iReadLen = buf.writerIndex() - 0; |
| 293 | testOpenMsg = new byte[iReadLen]; |
| 294 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 295 | |
| 296 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 297 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 298 | log.debug("openMsg are equal :" + openMsg); |
| 299 | } else { |
| 300 | Assert.fail("test case failed"); |
| 301 | log.debug("not equal"); |
| 302 | } |
| 303 | } else { |
| 304 | Assert.fail("test case failed"); |
| 305 | log.debug("not equal"); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | @Test |
| 310 | public void openMessageTest7() throws PcepParseException { |
| 311 | |
| 312 | /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) |
| 313 | with p bit set & i bit not set. |
| 314 | */ |
| 315 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set |
| 316 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 317 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 318 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 319 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 320 | }; |
| 321 | |
| 322 | byte[] testOpenMsg = {0}; |
| 323 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 324 | buffer.writeBytes(openMsg); |
| 325 | |
| 326 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 327 | PcepMessage message = null; |
| 328 | try { |
| 329 | message = reader.readFrom(buffer); |
| 330 | } catch (PcepParseException e) { |
| 331 | e.printStackTrace(); |
| 332 | } |
| 333 | |
| 334 | if (message instanceof PcepOpenMsg) { |
| 335 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 336 | message.writeTo(buf); |
| 337 | testOpenMsg = buf.array(); |
| 338 | |
| 339 | int iReadLen = buf.writerIndex() - 0; |
| 340 | testOpenMsg = new byte[iReadLen]; |
| 341 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 342 | |
| 343 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 344 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 345 | log.debug("openMsg are equal :" + openMsg); |
| 346 | } else { |
| 347 | Assert.fail("test case failed"); |
| 348 | log.debug("not equal"); |
| 349 | } |
| 350 | } else { |
| 351 | Assert.fail("test case failed"); |
| 352 | log.debug("not equal"); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | @Test |
| 357 | public void openMessageTest8() throws PcepParseException { |
| 358 | |
| 359 | /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) |
| 360 | with p bit set & i bit set. |
| 361 | */ |
| 362 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set |
| 363 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 364 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 365 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 366 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 367 | }; |
| 368 | |
| 369 | byte[] testOpenMsg = {0}; |
| 370 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 371 | buffer.writeBytes(openMsg); |
| 372 | |
| 373 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 374 | PcepMessage message = null; |
| 375 | try { |
| 376 | message = reader.readFrom(buffer); |
| 377 | } catch (PcepParseException e) { |
| 378 | e.printStackTrace(); |
| 379 | } |
| 380 | |
| 381 | if (message instanceof PcepOpenMsg) { |
| 382 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 383 | message.writeTo(buf); |
| 384 | testOpenMsg = buf.array(); |
| 385 | |
| 386 | int iReadLen = buf.writerIndex() - 0; |
| 387 | testOpenMsg = new byte[iReadLen]; |
| 388 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 389 | |
| 390 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 391 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 392 | log.debug("openMsg are equal :" + openMsg); |
| 393 | } else { |
| 394 | Assert.fail("test case failed"); |
| 395 | log.debug("not equal"); |
| 396 | } |
| 397 | } else { |
| 398 | Assert.fail("test case failed"); |
| 399 | log.debug("not equal"); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | @Test |
| 404 | public void openMessageTest9() throws PcepParseException { |
| 405 | |
| 406 | /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) |
| 407 | with p bit set & i bit set. |
| 408 | */ |
| 409 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set |
| 410 | 0x20, 0x1e, 0x78, 0x00, //invalid sessionID |
| 411 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 412 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 413 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 414 | }; |
| 415 | |
| 416 | byte[] testOpenMsg = {0}; |
| 417 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 418 | buffer.writeBytes(openMsg); |
| 419 | |
| 420 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 421 | PcepMessage message = null; |
| 422 | try { |
| 423 | message = reader.readFrom(buffer); |
| 424 | } catch (PcepParseException e) { |
| 425 | e.printStackTrace(); |
| 426 | } |
| 427 | |
| 428 | if (message instanceof PcepOpenMsg) { |
| 429 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 430 | message.writeTo(buf); |
| 431 | testOpenMsg = buf.array(); |
| 432 | |
| 433 | int iReadLen = buf.writerIndex() - 0; |
| 434 | testOpenMsg = new byte[iReadLen]; |
| 435 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 436 | |
| 437 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 438 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 439 | log.debug("openMsg are equal :" + openMsg); |
| 440 | } else { |
| 441 | Assert.fail("test case failed"); |
| 442 | log.debug("not equal"); |
| 443 | } |
| 444 | } else { |
| 445 | Assert.fail("test case failed"); |
| 446 | log.debug("not equal"); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | @Test |
| 451 | public void openMessageTest10() throws PcepParseException { |
| 452 | |
| 453 | //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV). |
| 454 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header |
| 455 | 0x01, 0x10, 0x00, 0x18, // common object header |
| 456 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 457 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 458 | 0x00, 0x00, 0x00, 0x05, |
| 459 | 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 460 | 0x00, 0x00, 0x00, 0x00}; |
| 461 | |
| 462 | byte[] testOpenMsg = {0}; |
| 463 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 464 | buffer.writeBytes(openMsg); |
| 465 | |
| 466 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 467 | PcepMessage message = null; |
| 468 | try { |
| 469 | message = reader.readFrom(buffer); |
| 470 | } catch (PcepParseException e) { |
| 471 | e.printStackTrace(); |
| 472 | } |
| 473 | |
| 474 | if (message instanceof PcepOpenMsg) { |
| 475 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 476 | message.writeTo(buf); |
| 477 | testOpenMsg = buf.array(); |
| 478 | |
| 479 | int iReadLen = buf.writerIndex() - 0; |
| 480 | testOpenMsg = new byte[iReadLen]; |
| 481 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 482 | |
| 483 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 484 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 485 | log.debug("openMsg are equal :" + openMsg); |
| 486 | } else { |
| 487 | Assert.fail("test case failed"); |
| 488 | log.debug("not equal"); |
| 489 | } |
| 490 | } else { |
| 491 | Assert.fail("test case failed"); |
| 492 | log.debug("not equal"); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | @Test |
| 497 | public void openMessageTest11() throws PcepParseException { |
| 498 | |
| 499 | //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, TED Capability TLV). |
| 500 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header |
| 501 | 0x01, 0x10, 0x00, 0x28, // common object header |
| 502 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 503 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 504 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 505 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV |
| 506 | 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV |
| 507 | 0x00, 0x00, 0x00, 0x00 }; |
| 508 | |
| 509 | byte[] testOpenMsg = {0}; |
| 510 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 511 | buffer.writeBytes(openMsg); |
| 512 | |
| 513 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 514 | PcepMessage message = null; |
| 515 | try { |
| 516 | message = reader.readFrom(buffer); |
| 517 | } catch (PcepParseException e) { |
| 518 | e.printStackTrace(); |
| 519 | } |
| 520 | |
| 521 | if (message instanceof PcepOpenMsg) { |
| 522 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 523 | message.writeTo(buf); |
| 524 | testOpenMsg = buf.array(); |
| 525 | |
| 526 | int iReadLen = buf.writerIndex() - 0; |
| 527 | testOpenMsg = new byte[iReadLen]; |
| 528 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 529 | |
| 530 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 531 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 532 | log.debug("openMsg are equal :" + openMsg); |
| 533 | } else { |
| 534 | Assert.fail("test case failed"); |
| 535 | log.debug("not equal"); |
| 536 | } |
| 537 | } else { |
| 538 | Assert.fail("test case failed"); |
| 539 | log.debug("not equal"); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | @Test |
| 544 | public void openMessageTest12() throws PcepParseException { |
| 545 | |
| 546 | //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV). |
| 547 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header |
| 548 | 0x01, 0x10, 0x00, 0x20, // common object header |
| 549 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 550 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 551 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 552 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV |
| 553 | 0x00, 0x00, 0x00, 0x03}; |
| 554 | |
| 555 | byte[] testOpenMsg = {0}; |
| 556 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 557 | buffer.writeBytes(openMsg); |
| 558 | |
| 559 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 560 | PcepMessage message = null; |
| 561 | try { |
| 562 | message = reader.readFrom(buffer); |
| 563 | } catch (PcepParseException e) { |
| 564 | e.printStackTrace(); |
| 565 | } |
| 566 | |
| 567 | if (message instanceof PcepOpenMsg) { |
| 568 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 569 | message.writeTo(buf); |
| 570 | testOpenMsg = buf.array(); |
| 571 | |
| 572 | int iReadLen = buf.writerIndex() - 0; |
| 573 | testOpenMsg = new byte[iReadLen]; |
| 574 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 575 | |
| 576 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 577 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 578 | log.debug("openMsg are equal :" + openMsg); |
| 579 | } else { |
| 580 | Assert.fail("test case failed"); |
| 581 | log.debug("not equal"); |
| 582 | } |
| 583 | } else { |
| 584 | Assert.fail("test case failed"); |
| 585 | log.debug("not equal"); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | @Test |
| 590 | public void openMessageTest13() throws PcepParseException { |
| 591 | |
| 592 | //OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV). |
| 593 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header |
| 594 | 0x01, 0x10, 0x00, 0x18, // common object header |
| 595 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 596 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 597 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 598 | 0x00, 0x00, 0x00, 0x00}; |
| 599 | |
| 600 | byte[] testOpenMsg = {0}; |
| 601 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 602 | buffer.writeBytes(openMsg); |
| 603 | |
| 604 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 605 | PcepMessage message = null; |
| 606 | try { |
| 607 | message = reader.readFrom(buffer); |
| 608 | } catch (PcepParseException e) { |
| 609 | e.printStackTrace(); |
| 610 | } |
| 611 | |
| 612 | if (message instanceof PcepOpenMsg) { |
| 613 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 614 | message.writeTo(buf); |
| 615 | testOpenMsg = buf.array(); |
| 616 | |
| 617 | int iReadLen = buf.writerIndex() - 0; |
| 618 | testOpenMsg = new byte[iReadLen]; |
| 619 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 620 | |
| 621 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 622 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 623 | log.debug("openMsg are equal :" + openMsg); |
| 624 | } else { |
| 625 | Assert.fail("test case failed"); |
| 626 | log.debug("not equal"); |
| 627 | } |
| 628 | } else { |
| 629 | Assert.fail("test case failed "); |
| 630 | log.debug("not equal"); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | @Test |
| 635 | public void openMessageTest14() throws PcepParseException { |
| 636 | |
| 637 | //OPEN OBJECT (STATEFUL-PCE-CAPABILITY). |
| 638 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 639 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 640 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 641 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 642 | 0x00, 0x00, 0x00, 0x05}; |
| 643 | |
| 644 | byte[] testOpenMsg = {0}; |
| 645 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 646 | buffer.writeBytes(openMsg); |
| 647 | |
| 648 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 649 | PcepMessage message = null; |
| 650 | try { |
| 651 | message = reader.readFrom(buffer); |
| 652 | } catch (PcepParseException e) { |
| 653 | e.printStackTrace(); |
| 654 | } |
| 655 | |
| 656 | if (message instanceof PcepOpenMsg) { |
| 657 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 658 | message.writeTo(buf); |
| 659 | testOpenMsg = buf.array(); |
| 660 | |
| 661 | int iReadLen = buf.writerIndex() - 0; |
| 662 | testOpenMsg = new byte[iReadLen]; |
| 663 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 664 | |
| 665 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 666 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 667 | log.debug("openMsg are equal :" + openMsg); |
| 668 | } else { |
| 669 | Assert.fail("test case failed"); |
| 670 | log.debug("not equal"); |
| 671 | } |
| 672 | } else { |
| 673 | Assert.fail("test case failed"); |
| 674 | log.debug("not equal"); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | @Test |
| 679 | public void openMessageTest15() throws PcepParseException { |
| 680 | |
| 681 | // OPEN OBJECT. |
| 682 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header |
| 683 | 0x01, 0x10, 0x00, 0x08, // common object header |
| 684 | 0x20, 0x05, 0x1E, 0x01 // OPEN object |
| 685 | }; |
| 686 | |
| 687 | byte[] testOpenMsg = {0}; |
| 688 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 689 | buffer.writeBytes(openMsg); |
| 690 | |
| 691 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 692 | PcepMessage message = null; |
| 693 | try { |
| 694 | message = reader.readFrom(buffer); |
| 695 | } catch (PcepParseException e) { |
| 696 | e.printStackTrace(); |
| 697 | } |
| 698 | |
| 699 | if (message instanceof PcepOpenMsg) { |
| 700 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 701 | message.writeTo(buf); |
| 702 | testOpenMsg = buf.array(); |
| 703 | |
| 704 | int iReadLen = buf.writerIndex() - 0; |
| 705 | testOpenMsg = new byte[iReadLen]; |
| 706 | buf.readBytes(testOpenMsg, 0, iReadLen); |
| 707 | |
| 708 | if (Arrays.equals(openMsg, testOpenMsg)) { |
| 709 | Assert.assertArrayEquals(openMsg, testOpenMsg); |
| 710 | log.debug("openMsg are equal :" + openMsg); |
| 711 | } else { |
| 712 | Assert.fail("test case failed"); |
| 713 | log.debug("not equal"); |
| 714 | } |
| 715 | } else { |
| 716 | Assert.fail("test case failed"); |
| 717 | log.debug("not equal"); |
| 718 | } |
| 719 | } |
| 720 | } |