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 | */ |
Sho SHIMIZU | 3559c31 | 2015-11-04 14:59:31 -0800 | [diff] [blame] | 16 | package org.onosproject.pcepio.protocol; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 20 | import org.junit.Test; |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 21 | import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 22 | import org.onosproject.pcepio.exceptions.PcepParseException; |
Sho SHIMIZU | 3559c31 | 2015-11-04 14:59:31 -0800 | [diff] [blame] | 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.instanceOf; |
| 26 | import static org.hamcrest.core.Is.is; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 27 | /** |
| 28 | * Test cases for PCEP OPEN Message. |
| 29 | */ |
| 30 | public class PcepOpenMsgTest { |
| 31 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 32 | /** |
| 33 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, |
| 34 | * PCECC-CAPABILITY-TLV in Pcep Open message. |
| 35 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 36 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 37 | public void openMessageTest1() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 38 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 39 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 40 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 41 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 42 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 43 | }; |
| 44 | |
| 45 | byte[] testOpenMsg = {0}; |
| 46 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 47 | buffer.writeBytes(openMsg); |
| 48 | |
| 49 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 50 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 51 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 52 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 53 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 54 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 55 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 56 | message.writeTo(buf); |
| 57 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 58 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 59 | int readLen = buf.writerIndex() - 0; |
| 60 | testOpenMsg = new byte[readLen]; |
| 61 | buf.readBytes(testOpenMsg, 0, readLen); |
| 62 | |
| 63 | assertThat(testOpenMsg, is(openMsg)); |
| 64 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 65 | } |
| 66 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 67 | /** |
| 68 | * This test case checks open object with STATEFUL-PCE-CAPABILITY-TLV in Pcep Open message. |
| 69 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 70 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 71 | public void openMessageTest2() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 72 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 73 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 74 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 75 | 0x20, 0x1E, 0x78, 0x01, // OPEN object |
| 76 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f}; // STATEFUL-PCE-CAPABILITY |
| 77 | byte[] testOpenMsg = {0}; |
| 78 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 79 | buffer.writeBytes(openMsg); |
| 80 | |
| 81 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 82 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 83 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 84 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 85 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 86 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 87 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 88 | message.writeTo(buf); |
| 89 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 90 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 91 | int readLen = buf.writerIndex() - 0; |
| 92 | testOpenMsg = new byte[readLen]; |
| 93 | buf.readBytes(testOpenMsg, 0, readLen); |
| 94 | |
| 95 | assertThat(testOpenMsg, is(openMsg)); |
| 96 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 97 | } |
| 98 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 99 | /** |
| 100 | * This test case checks open object with GmplsCapability tlv in Pcep Open message. |
| 101 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 102 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 103 | public void openMessageTest3() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 104 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 105 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 106 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 107 | 0x20, 0x1E, 0x78, 0x01, // OPEN object |
| 108 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //GMPLS-CAPABILITY-TLV |
| 109 | |
| 110 | byte[] testOpenMsg = {0}; |
| 111 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 112 | buffer.writeBytes(openMsg); |
| 113 | |
| 114 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 115 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 116 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 117 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 118 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 119 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 120 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 121 | message.writeTo(buf); |
| 122 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 123 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 124 | int readLen = buf.writerIndex() - 0; |
| 125 | testOpenMsg = new byte[readLen]; |
| 126 | buf.readBytes(testOpenMsg, 0, readLen); |
| 127 | |
| 128 | |
| 129 | assertThat(testOpenMsg, is(openMsg)); |
| 130 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 131 | } |
| 132 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 133 | /** |
| 134 | * This test case checks open object with StatefulLspDbVer Tlv in Pcep Open message. |
| 135 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 136 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 137 | public void openMessageTest4() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 138 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 139 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, |
| 140 | 0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20, |
| 141 | 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv |
| 142 | |
| 143 | byte[] testOpenMsg = {0}; |
| 144 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 145 | buffer.writeBytes(openMsg); |
| 146 | |
| 147 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 148 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 149 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 150 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 151 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 152 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 153 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 154 | message.writeTo(buf); |
| 155 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 156 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 157 | int readLen = buf.writerIndex() - 0; |
| 158 | testOpenMsg = new byte[readLen]; |
| 159 | buf.readBytes(testOpenMsg, 0, readLen); |
| 160 | |
| 161 | assertThat(testOpenMsg, is(openMsg)); |
| 162 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 163 | } |
| 164 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 165 | /** |
| 166 | * This test case checks open object with no tlv's in Pcep Open message. |
| 167 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 168 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 169 | public void openMessageTest5() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 170 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 171 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C, |
| 172 | 0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage |
| 173 | |
| 174 | byte[] testOpenMsg = {0}; |
| 175 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 176 | buffer.writeBytes(openMsg); |
| 177 | |
| 178 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 179 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 180 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 181 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 182 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 183 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 184 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 185 | message.writeTo(buf); |
| 186 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 187 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 188 | int readLen = buf.writerIndex() - 0; |
| 189 | testOpenMsg = new byte[readLen]; |
| 190 | buf.readBytes(testOpenMsg, 0, readLen); |
| 191 | |
| 192 | assertThat(testOpenMsg, is(openMsg)); |
| 193 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 194 | } |
| 195 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 196 | /** |
| 197 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV |
| 198 | * with I bit set in Pcep Open message. |
| 199 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 200 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 201 | public void openMessageTest6() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 202 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 203 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set |
| 204 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 205 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY |
| 206 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 207 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 208 | }; |
| 209 | |
| 210 | byte[] testOpenMsg = {0}; |
| 211 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 212 | buffer.writeBytes(openMsg); |
| 213 | |
| 214 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 215 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 216 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 217 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 218 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 219 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 220 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 221 | message.writeTo(buf); |
| 222 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 223 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 224 | int readLen = buf.writerIndex() - 0; |
| 225 | testOpenMsg = new byte[readLen]; |
| 226 | buf.readBytes(testOpenMsg, 0, readLen); |
| 227 | |
| 228 | assertThat(testOpenMsg, is(openMsg)); |
| 229 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 230 | } |
| 231 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 232 | /** |
| 233 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV |
| 234 | * with P bit set in Pcep Open message. |
| 235 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 236 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 237 | public void openMessageTest7() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 238 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 239 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set |
| 240 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 241 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 242 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 243 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 244 | }; |
| 245 | |
| 246 | byte[] testOpenMsg = {0}; |
| 247 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 248 | buffer.writeBytes(openMsg); |
| 249 | |
| 250 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 251 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 252 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 253 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 254 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 255 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 256 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 257 | message.writeTo(buf); |
| 258 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 259 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 260 | int readLen = buf.writerIndex() - 0; |
| 261 | testOpenMsg = new byte[readLen]; |
| 262 | buf.readBytes(testOpenMsg, 0, readLen); |
| 263 | |
| 264 | assertThat(testOpenMsg, is(openMsg)); |
| 265 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 266 | } |
| 267 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 268 | /** |
| 269 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV |
| 270 | * with P & I bits set in Pcep Open message. |
| 271 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 272 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 273 | public void openMessageTest8() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 274 | |
| 275 | /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) |
| 276 | with p bit set & i bit set. |
| 277 | */ |
| 278 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set |
| 279 | 0x20, 0x1e, 0x78, (byte) 0xbd, |
| 280 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 281 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 282 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 283 | }; |
| 284 | |
| 285 | byte[] testOpenMsg = {0}; |
| 286 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 287 | buffer.writeBytes(openMsg); |
| 288 | |
| 289 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 290 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 291 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 292 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 293 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 294 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 295 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 296 | message.writeTo(buf); |
| 297 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 298 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 299 | int readLen = buf.writerIndex() - 0; |
| 300 | testOpenMsg = new byte[readLen]; |
| 301 | buf.readBytes(testOpenMsg, 0, readLen); |
| 302 | |
| 303 | assertThat(testOpenMsg, is(openMsg)); |
| 304 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 305 | } |
| 306 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 307 | /** |
| 308 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV |
| 309 | * with P & I bits set and invalid session id in Pcep Open message. |
| 310 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 311 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 312 | public void openMessageTest9() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 313 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 314 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set |
| 315 | 0x20, 0x1e, 0x78, 0x00, //invalid sessionID |
| 316 | 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY |
| 317 | 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV |
| 318 | 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV |
| 319 | }; |
| 320 | |
| 321 | byte[] testOpenMsg = {0}; |
| 322 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 323 | buffer.writeBytes(openMsg); |
| 324 | |
| 325 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 326 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 327 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 328 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 329 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 330 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 331 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 332 | message.writeTo(buf); |
| 333 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 334 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 335 | int readLen = buf.writerIndex() - 0; |
| 336 | testOpenMsg = new byte[readLen]; |
| 337 | buf.readBytes(testOpenMsg, 0, readLen); |
| 338 | |
| 339 | |
| 340 | assertThat(testOpenMsg, is(openMsg)); |
| 341 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 342 | } |
| 343 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 344 | /** |
| 345 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV |
| 346 | * in Pcep Open message. |
| 347 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 348 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 349 | public void openMessageTest10() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 350 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 351 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header |
| 352 | 0x01, 0x10, 0x00, 0x18, // common object header |
| 353 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 354 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 355 | 0x00, 0x00, 0x00, 0x05, |
| 356 | 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 357 | 0x00, 0x00, 0x00, 0x00}; |
| 358 | |
| 359 | byte[] testOpenMsg = {0}; |
| 360 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 361 | buffer.writeBytes(openMsg); |
| 362 | |
| 363 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 364 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 365 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 366 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 367 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 368 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 369 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 370 | message.writeTo(buf); |
| 371 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 372 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 373 | int readLen = buf.writerIndex() - 0; |
| 374 | testOpenMsg = new byte[readLen]; |
| 375 | buf.readBytes(testOpenMsg, 0, readLen); |
| 376 | |
| 377 | assertThat(testOpenMsg, is(openMsg)); |
| 378 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 379 | } |
| 380 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 381 | /** |
| 382 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, |
| 383 | * PCECC-CAPABILITY-TLV, TED Capability TLV in Pcep Open message. |
| 384 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 385 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 386 | public void openMessageTest11() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 387 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 388 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header |
| 389 | 0x01, 0x10, 0x00, 0x28, // common object header |
| 390 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 391 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 392 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 393 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 394 | 0x00, 0x00, 0x00, 0x03, (byte) 0xFF, (byte) 0x00, 0x00, 0x04, // LS Capability TLV |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 395 | 0x00, 0x00, 0x00, 0x00 }; |
| 396 | |
| 397 | byte[] testOpenMsg = {0}; |
| 398 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 399 | buffer.writeBytes(openMsg); |
| 400 | |
| 401 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 402 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 403 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 404 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 405 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 406 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 407 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 408 | message.writeTo(buf); |
| 409 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 410 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 411 | int readLen = buf.writerIndex() - 0; |
| 412 | testOpenMsg = new byte[readLen]; |
| 413 | buf.readBytes(testOpenMsg, 0, readLen); |
| 414 | |
| 415 | assertThat(testOpenMsg, is(openMsg)); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 416 | } |
| 417 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 418 | /** |
| 419 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, |
| 420 | * PCECC-CAPABILITY-TLV in Pcep Open message. |
| 421 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 422 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 423 | public void openMessageTest12() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 424 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 425 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header |
| 426 | 0x01, 0x10, 0x00, 0x20, // common object header |
| 427 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 428 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 429 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 430 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV |
| 431 | 0x00, 0x00, 0x00, 0x03}; |
| 432 | |
| 433 | byte[] testOpenMsg = {0}; |
| 434 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 435 | buffer.writeBytes(openMsg); |
| 436 | |
| 437 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 438 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 439 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 440 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 441 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 442 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 443 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 444 | message.writeTo(buf); |
| 445 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 446 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 447 | int readLen = buf.writerIndex() - 0; |
| 448 | testOpenMsg = new byte[readLen]; |
| 449 | buf.readBytes(testOpenMsg, 0, readLen); |
| 450 | |
| 451 | assertThat(testOpenMsg, is(openMsg)); |
| 452 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 453 | } |
| 454 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 455 | /** |
| 456 | * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV |
| 457 | * in Pcep Open message. |
| 458 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 459 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 460 | public void openMessageTest13() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 461 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 462 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header |
| 463 | 0x01, 0x10, 0x00, 0x18, // common object header |
| 464 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 465 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 466 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV |
| 467 | 0x00, 0x00, 0x00, 0x00}; |
| 468 | |
| 469 | byte[] testOpenMsg = {0}; |
| 470 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 471 | buffer.writeBytes(openMsg); |
| 472 | |
| 473 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 474 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 475 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 476 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 477 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 478 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 479 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 480 | message.writeTo(buf); |
| 481 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 482 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 483 | int readLen = buf.writerIndex() - 0; |
| 484 | testOpenMsg = new byte[readLen]; |
| 485 | buf.readBytes(testOpenMsg, 0, readLen); |
| 486 | |
| 487 | |
| 488 | assertThat(testOpenMsg, is(openMsg)); |
| 489 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 490 | } |
| 491 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 492 | /** |
| 493 | * This test case checks open object with STATEFUL-PCE-CAPABILITY in Pcep Open message. |
| 494 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 495 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 496 | public void openMessageTest14() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 497 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 498 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header |
| 499 | 0x01, 0x10, 0x00, 0x10, // common object header |
| 500 | 0x20, 0x05, 0x1E, 0x01, // OPEN object |
| 501 | 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY |
| 502 | 0x00, 0x00, 0x00, 0x05}; |
| 503 | |
| 504 | byte[] testOpenMsg = {0}; |
| 505 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 506 | buffer.writeBytes(openMsg); |
| 507 | |
| 508 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 509 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 510 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 511 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 512 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 513 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 514 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 515 | message.writeTo(buf); |
| 516 | testOpenMsg = buf.array(); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 517 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 518 | int readLen = buf.writerIndex() - 0; |
| 519 | testOpenMsg = new byte[readLen]; |
| 520 | buf.readBytes(testOpenMsg, 0, readLen); |
| 521 | |
| 522 | assertThat(testOpenMsg, is(openMsg)); |
| 523 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 524 | } |
| 525 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 526 | /** |
| 527 | * This test case checks open object with no tlv Pcep Open message. |
| 528 | */ |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 529 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 530 | public void openMessageTest15() throws PcepParseException, PcepOutOfBoundMessageException { |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 531 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 532 | byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header |
| 533 | 0x01, 0x10, 0x00, 0x08, // common object header |
| 534 | 0x20, 0x05, 0x1E, 0x01 // OPEN object |
| 535 | }; |
| 536 | |
| 537 | byte[] testOpenMsg = {0}; |
| 538 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 539 | buffer.writeBytes(openMsg); |
| 540 | |
| 541 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 542 | PcepMessage message = null; |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 543 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 544 | message = reader.readFrom(buffer); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 545 | |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 546 | assertThat(message, instanceOf(PcepOpenMsg.class)); |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 547 | |
SureshBR | 3dab097 | 2015-08-24 18:38:09 +0530 | [diff] [blame] | 548 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 549 | message.writeTo(buf); |
| 550 | testOpenMsg = buf.array(); |
| 551 | |
| 552 | int readLen = buf.writerIndex() - 0; |
| 553 | testOpenMsg = new byte[readLen]; |
| 554 | buf.readBytes(testOpenMsg, 0, readLen); |
| 555 | assertThat(testOpenMsg, is(openMsg)); |
| 556 | |
Mahesh Poojary S | 1c356e3 | 2015-08-21 15:05:30 +0530 | [diff] [blame] | 557 | } |
| 558 | } |