blob: 4d370f59a0c0db612557f0c3af0672608cfb25ff [file] [log] [blame]
Mahesh Poojary S1c356e32015-08-21 15:05:30 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Mahesh Poojary S1c356e32015-08-21 15:05:30 +05303 *
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 SHIMIZU3559c312015-11-04 14:59:31 -080016package org.onosproject.pcepio.protocol;
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053017
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053020import org.junit.Test;
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053021import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053022import org.onosproject.pcepio.exceptions.PcepParseException;
Sho SHIMIZU3559c312015-11-04 14:59:31 -080023
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.instanceOf;
26import static org.hamcrest.core.Is.is;
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053027/**
28 * Test cases for PCEP OPEN Message.
29 */
30public class PcepOpenMsgTest {
31
SureshBR3dab0972015-08-24 18:38:09 +053032 /**
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 S1c356e32015-08-21 15:05:30 +053036 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053037 public void openMessageTest1() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053038
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053039 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
Priyanka B21f4b732016-03-21 20:54:12 +053042 (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053043 };
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 S1c356e32015-08-21 15:05:30 +053051
SureshBR3dab0972015-08-24 18:38:09 +053052 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053053
Sho SHIMIZUe090a422015-09-04 17:35:49 -070054 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +053055 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
56 message.writeTo(buf);
57 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053058
SureshBR3dab0972015-08-24 18:38:09 +053059 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 S1c356e32015-08-21 15:05:30 +053065 }
66
SureshBR3dab0972015-08-24 18:38:09 +053067 /**
68 * This test case checks open object with STATEFUL-PCE-CAPABILITY-TLV in Pcep Open message.
69 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053070 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053071 public void openMessageTest2() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053072
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053073 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 S1c356e32015-08-21 15:05:30 +053083
SureshBR3dab0972015-08-24 18:38:09 +053084 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053085
Sho SHIMIZUe090a422015-09-04 17:35:49 -070086 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +053087 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
88 message.writeTo(buf);
89 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +053090
SureshBR3dab0972015-08-24 18:38:09 +053091 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 S1c356e32015-08-21 15:05:30 +053097 }
98
SureshBR3dab0972015-08-24 18:38:09 +053099 /**
100 * This test case checks open object with GmplsCapability tlv in Pcep Open message.
101 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530102 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530103 public void openMessageTest3() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530104
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530105 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 S1c356e32015-08-21 15:05:30 +0530116
SureshBR3dab0972015-08-24 18:38:09 +0530117 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530118
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700119 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530120 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
121 message.writeTo(buf);
122 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530123
SureshBR3dab0972015-08-24 18:38:09 +0530124 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 S1c356e32015-08-21 15:05:30 +0530131 }
132
SureshBR3dab0972015-08-24 18:38:09 +0530133 /**
134 * This test case checks open object with StatefulLspDbVer Tlv in Pcep Open message.
135 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530136 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530137 public void openMessageTest4() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530138
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530139 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 S1c356e32015-08-21 15:05:30 +0530149
SureshBR3dab0972015-08-24 18:38:09 +0530150 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530151
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700152 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530153 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
154 message.writeTo(buf);
155 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530156
SureshBR3dab0972015-08-24 18:38:09 +0530157 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 S1c356e32015-08-21 15:05:30 +0530163 }
164
SureshBR3dab0972015-08-24 18:38:09 +0530165 /**
166 * This test case checks open object with no tlv's in Pcep Open message.
167 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530168 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530169 public void openMessageTest5() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530170
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530171 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 S1c356e32015-08-21 15:05:30 +0530180
SureshBR3dab0972015-08-24 18:38:09 +0530181 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530182
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700183 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530184 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
185 message.writeTo(buf);
186 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530187
SureshBR3dab0972015-08-24 18:38:09 +0530188 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 S1c356e32015-08-21 15:05:30 +0530194 }
195
SureshBR3dab0972015-08-24 18:38:09 +0530196 /**
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 S1c356e32015-08-21 15:05:30 +0530200 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530201 public void openMessageTest6() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530202
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530203 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
Priyanka B21f4b732016-03-21 20:54:12 +0530207 (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530208 };
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 S1c356e32015-08-21 15:05:30 +0530216
SureshBR3dab0972015-08-24 18:38:09 +0530217 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530218
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700219 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530220 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
221 message.writeTo(buf);
222 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530223
SureshBR3dab0972015-08-24 18:38:09 +0530224 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 S1c356e32015-08-21 15:05:30 +0530230 }
231
SureshBR3dab0972015-08-24 18:38:09 +0530232 /**
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 S1c356e32015-08-21 15:05:30 +0530236 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530237 public void openMessageTest7() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530238
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530239 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
Priyanka B21f4b732016-03-21 20:54:12 +0530243 (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530244 };
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 S1c356e32015-08-21 15:05:30 +0530252
SureshBR3dab0972015-08-24 18:38:09 +0530253 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530254
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700255 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530256 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
257 message.writeTo(buf);
258 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530259
SureshBR3dab0972015-08-24 18:38:09 +0530260 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 S1c356e32015-08-21 15:05:30 +0530266 }
267
SureshBR3dab0972015-08-24 18:38:09 +0530268 /**
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 S1c356e32015-08-21 15:05:30 +0530272 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530273 public void openMessageTest8() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530274
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
Priyanka B21f4b732016-03-21 20:54:12 +0530282 (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530283 };
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 S1c356e32015-08-21 15:05:30 +0530291
SureshBR3dab0972015-08-24 18:38:09 +0530292 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530293
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700294 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530295 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
296 message.writeTo(buf);
297 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530298
SureshBR3dab0972015-08-24 18:38:09 +0530299 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 S1c356e32015-08-21 15:05:30 +0530305 }
306
SureshBR3dab0972015-08-24 18:38:09 +0530307 /**
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 S1c356e32015-08-21 15:05:30 +0530311 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530312 public void openMessageTest9() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530313
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530314 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
Priyanka B21f4b732016-03-21 20:54:12 +0530318 (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530319 };
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 S1c356e32015-08-21 15:05:30 +0530327
SureshBR3dab0972015-08-24 18:38:09 +0530328 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530329
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700330 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530331 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
332 message.writeTo(buf);
333 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530334
SureshBR3dab0972015-08-24 18:38:09 +0530335 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 S1c356e32015-08-21 15:05:30 +0530342 }
343
SureshBR3dab0972015-08-24 18:38:09 +0530344 /**
345 * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV
346 * in Pcep Open message.
347 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530348 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530349 public void openMessageTest10() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530350
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530351 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 S1c356e32015-08-21 15:05:30 +0530365
SureshBR3dab0972015-08-24 18:38:09 +0530366 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530367
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700368 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530369 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
370 message.writeTo(buf);
371 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530372
SureshBR3dab0972015-08-24 18:38:09 +0530373 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 S1c356e32015-08-21 15:05:30 +0530379 }
380
SureshBR3dab0972015-08-24 18:38:09 +0530381 /**
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 S1c356e32015-08-21 15:05:30 +0530385 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530386 public void openMessageTest11() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530387
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530388 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
Priyanka B21f4b732016-03-21 20:54:12 +0530393 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x07, 0x00, 0x04, // PCECC-CAPABILITY-TLV
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530394 0x00, 0x00, 0x00, 0x03, (byte) 0xFF, (byte) 0x00, 0x00, 0x04, // LS Capability TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530395 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 S1c356e32015-08-21 15:05:30 +0530403
SureshBR3dab0972015-08-24 18:38:09 +0530404 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530405
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700406 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530407 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
408 message.writeTo(buf);
409 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530410
SureshBR3dab0972015-08-24 18:38:09 +0530411 int readLen = buf.writerIndex() - 0;
412 testOpenMsg = new byte[readLen];
413 buf.readBytes(testOpenMsg, 0, readLen);
414
415 assertThat(testOpenMsg, is(openMsg));
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530416 }
417
SureshBR3dab0972015-08-24 18:38:09 +0530418 /**
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 S1c356e32015-08-21 15:05:30 +0530422 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530423 public void openMessageTest12() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530424
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530425 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
Priyanka B21f4b732016-03-21 20:54:12 +0530430 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x07, 0x00, 0x04, // PCECC-CAPABILITY-TLV
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530431 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 S1c356e32015-08-21 15:05:30 +0530439
SureshBR3dab0972015-08-24 18:38:09 +0530440 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530441
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700442 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530443 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
444 message.writeTo(buf);
445 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530446
SureshBR3dab0972015-08-24 18:38:09 +0530447 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 S1c356e32015-08-21 15:05:30 +0530453 }
454
SureshBR3dab0972015-08-24 18:38:09 +0530455 /**
456 * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV
457 * in Pcep Open message.
458 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530459 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530460 public void openMessageTest13() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530461
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530462 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 S1c356e32015-08-21 15:05:30 +0530475
SureshBR3dab0972015-08-24 18:38:09 +0530476 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530477
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700478 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530479 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
480 message.writeTo(buf);
481 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530482
SureshBR3dab0972015-08-24 18:38:09 +0530483 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 S1c356e32015-08-21 15:05:30 +0530490 }
491
SureshBR3dab0972015-08-24 18:38:09 +0530492 /**
493 * This test case checks open object with STATEFUL-PCE-CAPABILITY in Pcep Open message.
494 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530495 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530496 public void openMessageTest14() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530497
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530498 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 S1c356e32015-08-21 15:05:30 +0530510
SureshBR3dab0972015-08-24 18:38:09 +0530511 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530512
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700513 assertThat(message, instanceOf(PcepOpenMsg.class));
SureshBR3dab0972015-08-24 18:38:09 +0530514 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
515 message.writeTo(buf);
516 testOpenMsg = buf.array();
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530517
SureshBR3dab0972015-08-24 18:38:09 +0530518 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 S1c356e32015-08-21 15:05:30 +0530524 }
525
SureshBR3dab0972015-08-24 18:38:09 +0530526 /**
527 * This test case checks open object with no tlv Pcep Open message.
528 */
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530529 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530530 public void openMessageTest15() throws PcepParseException, PcepOutOfBoundMessageException {
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530531
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530532 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 S1c356e32015-08-21 15:05:30 +0530543
SureshBR3dab0972015-08-24 18:38:09 +0530544 message = reader.readFrom(buffer);
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530545
Sho SHIMIZUe090a422015-09-04 17:35:49 -0700546 assertThat(message, instanceOf(PcepOpenMsg.class));
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530547
SureshBR3dab0972015-08-24 18:38:09 +0530548 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 S1c356e32015-08-21 15:05:30 +0530557 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530558
559 /**
560 * This test case checks open object with LSR id encoded.
561 */
562 @Test
563 public void openMessageTest16() throws PcepParseException, PcepOutOfBoundMessageException {
564
565 byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, // common header
566 0x01, 0x10, 0x00, 0x14, // common object header
567 0x20, 0x05, 0x1E, 0x01, // OPEN object
568 (byte) 0xFF, 0x05, 0x00, 0x08, // Node attribute TLV
569 0x00, 0x11, 0x00, 0x04, // PCEP-LS-IPv4-ROUTER-ID sub tlv
570 0x02, 0x02, 0x02, 0x02
571 };
572
573 byte[] testOpenMsg = {0};
574 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
575 buffer.writeBytes(openMsg);
576
577 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
578 PcepMessage message = null;
579
580 message = reader.readFrom(buffer);
581
582 assertThat(message, instanceOf(PcepOpenMsg.class));
583
584 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
585 message.writeTo(buf);
586 testOpenMsg = buf.array();
587
588 int readLen = buf.writerIndex() - 0;
589 testOpenMsg = new byte[readLen];
590 buf.readBytes(testOpenMsg, 0, readLen);
591 assertThat(testOpenMsg, is(openMsg));
592
593 }
Mahesh Poojary S1c356e32015-08-21 15:05:30 +0530594}