Committed by
Gerrit Code Review
[ONOS-2623] UT test cases for Open and Error messages.
Change-Id: I13736e921b0678573095c8a600b12af70dc524d1
Showing
4 changed files
with
1715 additions
and
22 deletions
... | @@ -22,6 +22,10 @@ import org.onosproject.pcepio.protocol.PcepBandwidthObject; | ... | @@ -22,6 +22,10 @@ import org.onosproject.pcepio.protocol.PcepBandwidthObject; |
22 | import org.onosproject.pcepio.protocol.PcepCloseMsg; | 22 | import org.onosproject.pcepio.protocol.PcepCloseMsg; |
23 | import org.onosproject.pcepio.protocol.PcepEndPointsObject; | 23 | import org.onosproject.pcepio.protocol.PcepEndPointsObject; |
24 | import org.onosproject.pcepio.protocol.PcepEroObject; | 24 | import org.onosproject.pcepio.protocol.PcepEroObject; |
25 | +import org.onosproject.pcepio.protocol.PcepErrorInfo; | ||
26 | +import org.onosproject.pcepio.protocol.PcepError; | ||
27 | +import org.onosproject.pcepio.protocol.PcepErrorMsg; | ||
28 | +import org.onosproject.pcepio.protocol.PcepErrorObject; | ||
25 | import org.onosproject.pcepio.protocol.PcepFactory; | 29 | import org.onosproject.pcepio.protocol.PcepFactory; |
26 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; | 30 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; |
27 | import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; | 31 | import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; |
... | @@ -31,6 +35,8 @@ import org.onosproject.pcepio.protocol.PcepMessage; | ... | @@ -31,6 +35,8 @@ import org.onosproject.pcepio.protocol.PcepMessage; |
31 | import org.onosproject.pcepio.protocol.PcepMessageReader; | 35 | import org.onosproject.pcepio.protocol.PcepMessageReader; |
32 | import org.onosproject.pcepio.protocol.PcepMetricObject; | 36 | import org.onosproject.pcepio.protocol.PcepMetricObject; |
33 | import org.onosproject.pcepio.protocol.PcepMsgPath; | 37 | import org.onosproject.pcepio.protocol.PcepMsgPath; |
38 | +import org.onosproject.pcepio.protocol.PcepOpenMsg; | ||
39 | +import org.onosproject.pcepio.protocol.PcepOpenObject; | ||
34 | import org.onosproject.pcepio.protocol.PcepSrpObject; | 40 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
35 | import org.onosproject.pcepio.protocol.PcepUpdateMsg; | 41 | import org.onosproject.pcepio.protocol.PcepUpdateMsg; |
36 | import org.onosproject.pcepio.protocol.PcepUpdateRequest; | 42 | import org.onosproject.pcepio.protocol.PcepUpdateRequest; |
... | @@ -41,15 +47,13 @@ public class PcepFactoryVer1 implements PcepFactory { | ... | @@ -41,15 +47,13 @@ public class PcepFactoryVer1 implements PcepFactory { |
41 | public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1(); | 47 | public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1(); |
42 | 48 | ||
43 | @Override | 49 | @Override |
44 | - public org.onosproject.pcepio.protocol.PcepOpenMsg.Builder buildOpenMsg() { | 50 | + public PcepOpenMsg.Builder buildOpenMsg() { |
45 | - // TODO Auto-generated method stub | 51 | + return new PcepOpenMsgVer1.Builder(); |
46 | - return null; | ||
47 | } | 52 | } |
48 | 53 | ||
49 | @Override | 54 | @Override |
50 | - public org.onosproject.pcepio.protocol.PcepOpenObject.Builder buildOpenObject() { | 55 | + public PcepOpenObject.Builder buildOpenObject() { |
51 | - // TODO Auto-generated method stub | 56 | + return new PcepOpenObjectVer1.Builder(); |
52 | - return null; | ||
53 | } | 57 | } |
54 | 58 | ||
55 | @Override | 59 | @Override |
... | @@ -180,15 +184,13 @@ public class PcepFactoryVer1 implements PcepFactory { | ... | @@ -180,15 +184,13 @@ public class PcepFactoryVer1 implements PcepFactory { |
180 | } | 184 | } |
181 | 185 | ||
182 | @Override | 186 | @Override |
183 | - public org.onosproject.pcepio.protocol.PcepErrorMsg.Builder buildPcepErrorMsg() { | 187 | + public PcepErrorMsg.Builder buildPcepErrorMsg() { |
184 | - // TODO Auto-generated method stub | 188 | + return new PcepErrorMsgVer1.Builder(); |
185 | - return null; | ||
186 | } | 189 | } |
187 | 190 | ||
188 | @Override | 191 | @Override |
189 | - public org.onosproject.pcepio.protocol.PcepErrorObject.Builder buildPcepErrorObject() { | 192 | + public PcepErrorObject.Builder buildPcepErrorObject() { |
190 | - // TODO Auto-generated method stub | 193 | + return new PcepErrorObjectVer1.Builder(); |
191 | - return null; | ||
192 | } | 194 | } |
193 | 195 | ||
194 | @Override | 196 | @Override |
... | @@ -198,15 +200,13 @@ public class PcepFactoryVer1 implements PcepFactory { | ... | @@ -198,15 +200,13 @@ public class PcepFactoryVer1 implements PcepFactory { |
198 | } | 200 | } |
199 | 201 | ||
200 | @Override | 202 | @Override |
201 | - public org.onosproject.pcepio.protocol.PcepErrorInfo.Builder buildPcepErrorInfo() { | 203 | + public PcepErrorInfo.Builder buildPcepErrorInfo() { |
202 | - // TODO Auto-generated method stub | 204 | + return new PcepErrorInfoVer1.Builder(); |
203 | - return null; | ||
204 | } | 205 | } |
205 | 206 | ||
206 | @Override | 207 | @Override |
207 | - public org.onosproject.pcepio.protocol.PcepError.Builder buildPcepError() { | 208 | + public PcepError.Builder buildPcepError() { |
208 | - // TODO Auto-generated method stub | 209 | + return new PcepErrorVer1.Builder(); |
209 | - return null; | ||
210 | } | 210 | } |
211 | 211 | ||
212 | @Override | 212 | @Override | ... | ... |
... | @@ -73,8 +73,7 @@ public abstract class PcepMessageVer1 { | ... | @@ -73,8 +73,7 @@ public abstract class PcepMessageVer1 { |
73 | case OPEN_MSG_TYPE: | 73 | case OPEN_MSG_TYPE: |
74 | log.debug("OPEN MESSAGE is received"); | 74 | log.debug("OPEN MESSAGE is received"); |
75 | // message type value 1 means it is open message | 75 | // message type value 1 means it is open message |
76 | - // return | 76 | + return PcepOpenMsgVer1.READER.readFrom(cb.readBytes(length)); |
77 | - // TODO: Read open message from channel buffer. | ||
78 | case KEEPALIVE_MSG_TYPE: | 77 | case KEEPALIVE_MSG_TYPE: |
79 | log.debug("KEEPALIVE MESSAGE is received"); | 78 | log.debug("KEEPALIVE MESSAGE is received"); |
80 | // message type value 2 means it is Keepalive message | 79 | // message type value 2 means it is Keepalive message |
... | @@ -82,8 +81,7 @@ public abstract class PcepMessageVer1 { | ... | @@ -82,8 +81,7 @@ public abstract class PcepMessageVer1 { |
82 | case ERROR_MSG_TYPE: | 81 | case ERROR_MSG_TYPE: |
83 | log.debug("ERROR MESSAGE is received"); | 82 | log.debug("ERROR MESSAGE is received"); |
84 | // message type value 6 means it is error message | 83 | // message type value 6 means it is error message |
85 | - // return | 84 | + return PcepErrorMsgVer1.READER.readFrom(cb.readBytes(length)); |
86 | - // TODO: Read Error message from channel buffer. | ||
87 | case REPORT_MSG_TYPE: | 85 | case REPORT_MSG_TYPE: |
88 | log.debug("REPORT MESSAGE is received"); | 86 | log.debug("REPORT MESSAGE is received"); |
89 | // message type value 10 means it is Report message | 87 | // message type value 10 means it is Report message | ... | ... |
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.PcepErrorMsg; | ||
28 | +import org.onosproject.pcepio.protocol.PcepFactories; | ||
29 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
30 | +import org.onosproject.pcepio.protocol.PcepMessageReader; | ||
31 | +import org.slf4j.Logger; | ||
32 | +import org.slf4j.LoggerFactory; | ||
33 | + | ||
34 | +/** | ||
35 | + * Test cases for PCEP ERROR Message. | ||
36 | + */ | ||
37 | +public class PcepErrorMsgTest { | ||
38 | + | ||
39 | + protected static final Logger log = LoggerFactory.getLogger(PcepErrorMsgTest.class); | ||
40 | + | ||
41 | + @Before | ||
42 | + public void startUp() { | ||
43 | + | ||
44 | + } | ||
45 | + | ||
46 | + @After | ||
47 | + public void tearDown() { | ||
48 | + | ||
49 | + } | ||
50 | + | ||
51 | + @Test | ||
52 | + public void errorMessageTest1() throws PcepParseException { | ||
53 | + | ||
54 | + /* PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, | ||
55 | + * PCECC-CAPABILITY-TLV, TED Capability TLV) | ||
56 | + */ | ||
57 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x34, // common header | ||
58 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
59 | + 0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x28, // OPEN object header | ||
60 | + 0x20, 0x05, 0x1E, 0x01, // OPEN object | ||
61 | + 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY | ||
62 | + 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV | ||
63 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV | ||
64 | + 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV | ||
65 | + 0x00, 0x00, 0x00, 0x00 }; | ||
66 | + | ||
67 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
68 | + buffer.writeBytes(errorMsg); | ||
69 | + | ||
70 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
71 | + PcepMessage message = null; | ||
72 | + try { | ||
73 | + message = reader.readFrom(buffer); | ||
74 | + } catch (PcepParseException e) { | ||
75 | + e.printStackTrace(); | ||
76 | + } | ||
77 | + | ||
78 | + byte[] testErrorMsg = {0}; | ||
79 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
80 | + if (message instanceof PcepErrorMsg) { | ||
81 | + message.writeTo(buf); | ||
82 | + int iReadLen = buf.writerIndex() - 0; | ||
83 | + testErrorMsg = new byte[iReadLen]; | ||
84 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
85 | + | ||
86 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
87 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
88 | + log.debug("Pcep Error Msg are Equal "); | ||
89 | + } else { | ||
90 | + Assert.fail("test case failed"); | ||
91 | + log.debug("not equal"); | ||
92 | + } | ||
93 | + } else { | ||
94 | + Assert.fail("test case failed"); | ||
95 | + log.debug("not equal"); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + @Test | ||
100 | + public void errorMessageTest2() throws PcepParseException { | ||
101 | + | ||
102 | + /* PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, | ||
103 | + * PCECC-CAPABILITY-TLV, TED Capability TLV) | ||
104 | + */ | ||
105 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header | ||
106 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
107 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
108 | + 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x28, // OPEN object header | ||
109 | + 0x20, 0x05, 0x1E, 0x01, // OPEN object | ||
110 | + 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY | ||
111 | + 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV | ||
112 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV | ||
113 | + 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV | ||
114 | + 0x00, 0x00, 0x00, 0x00 }; | ||
115 | + | ||
116 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
117 | + buffer.writeBytes(errorMsg); | ||
118 | + | ||
119 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
120 | + PcepMessage message = null; | ||
121 | + try { | ||
122 | + message = reader.readFrom(buffer); | ||
123 | + } catch (PcepParseException e) { | ||
124 | + e.printStackTrace(); | ||
125 | + } | ||
126 | + | ||
127 | + byte[] testErrorMsg = {0}; | ||
128 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
129 | + if (message instanceof PcepErrorMsg) { | ||
130 | + message.writeTo(buf); | ||
131 | + int iReadLen = buf.writerIndex() - 0; | ||
132 | + testErrorMsg = new byte[iReadLen]; | ||
133 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
134 | + | ||
135 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
136 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
137 | + log.debug("Pcep Error Msg are Equal "); | ||
138 | + } else { | ||
139 | + Assert.fail("test case failed"); | ||
140 | + log.debug("not equal"); | ||
141 | + } | ||
142 | + } else { | ||
143 | + Assert.fail("test case failed"); | ||
144 | + log.debug("not equal"); | ||
145 | + } | ||
146 | + } | ||
147 | + | ||
148 | + @Test | ||
149 | + public void errorMessageTest3() throws PcepParseException { | ||
150 | + | ||
151 | + /* PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, | ||
152 | + * PCECC-CAPABILITY-TLV) | ||
153 | + */ | ||
154 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x34, // common header | ||
155 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
156 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
157 | + 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x20, // OPEN object header | ||
158 | + 0x20, 0x05, 0x1E, 0x01, // OPEN object | ||
159 | + 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY | ||
160 | + 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV | ||
161 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV | ||
162 | + 0x00, 0x00, 0x00, 0x03 }; | ||
163 | + | ||
164 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
165 | + buffer.writeBytes(errorMsg); | ||
166 | + | ||
167 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
168 | + PcepMessage message = null; | ||
169 | + try { | ||
170 | + message = reader.readFrom(buffer); | ||
171 | + } catch (PcepParseException e) { | ||
172 | + e.printStackTrace(); | ||
173 | + } | ||
174 | + | ||
175 | + byte[] testErrorMsg = {0}; | ||
176 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
177 | + if (message instanceof PcepErrorMsg) { | ||
178 | + message.writeTo(buf); | ||
179 | + int iReadLen = buf.writerIndex() - 0; | ||
180 | + testErrorMsg = new byte[iReadLen]; | ||
181 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
182 | + | ||
183 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
184 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
185 | + log.debug("Pcep Error Msg are Equal "); | ||
186 | + } else { | ||
187 | + Assert.fail("test case failed"); | ||
188 | + log.debug("not equal"); | ||
189 | + } | ||
190 | + } else { | ||
191 | + Assert.fail("test case failed"); | ||
192 | + log.debug("not equal"); | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | + @Test | ||
197 | + public void errorMessageTest4() throws PcepParseException { | ||
198 | + | ||
199 | + //PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV) | ||
200 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2c, // common header | ||
201 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
202 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
203 | + 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x18, // OPEN object header | ||
204 | + 0x20, 0x05, 0x1E, 0x01, // OPEN object | ||
205 | + 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY | ||
206 | + 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV | ||
207 | + 0x00, 0x00, 0x00, 0x00 }; | ||
208 | + | ||
209 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
210 | + buffer.writeBytes(errorMsg); | ||
211 | + | ||
212 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
213 | + PcepMessage message = null; | ||
214 | + try { | ||
215 | + message = reader.readFrom(buffer); | ||
216 | + } catch (PcepParseException e) { | ||
217 | + e.printStackTrace(); | ||
218 | + } | ||
219 | + | ||
220 | + byte[] testErrorMsg = {0}; | ||
221 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
222 | + if (message instanceof PcepErrorMsg) { | ||
223 | + message.writeTo(buf); | ||
224 | + int iReadLen = buf.writerIndex() - 0; | ||
225 | + testErrorMsg = new byte[iReadLen]; | ||
226 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
227 | + | ||
228 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
229 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
230 | + log.debug("Pcep Error Msg are Equal "); | ||
231 | + } else { | ||
232 | + Assert.fail("test case failed"); | ||
233 | + log.debug("not equal"); | ||
234 | + } | ||
235 | + } else { | ||
236 | + Assert.fail("test case failed"); | ||
237 | + log.debug("not equal"); | ||
238 | + } | ||
239 | + } | ||
240 | + | ||
241 | + @Test | ||
242 | + public void errorMessageTest5() throws PcepParseException { | ||
243 | + | ||
244 | + //PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY) | ||
245 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header | ||
246 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
247 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
248 | + 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x10, // OPEN object header | ||
249 | + 0x20, 0x05, 0x1E, 0x01, // OPEN object | ||
250 | + 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY | ||
251 | + 0x00, 0x00, 0x00, 0x05 }; | ||
252 | + | ||
253 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
254 | + buffer.writeBytes(errorMsg); | ||
255 | + | ||
256 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
257 | + PcepMessage message = null; | ||
258 | + try { | ||
259 | + message = reader.readFrom(buffer); | ||
260 | + } catch (PcepParseException e) { | ||
261 | + e.printStackTrace(); | ||
262 | + } | ||
263 | + | ||
264 | + byte[] testErrorMsg = {0}; | ||
265 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
266 | + if (message instanceof PcepErrorMsg) { | ||
267 | + message.writeTo(buf); | ||
268 | + int iReadLen = buf.writerIndex() - 0; | ||
269 | + testErrorMsg = new byte[iReadLen]; | ||
270 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
271 | + | ||
272 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
273 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
274 | + log.debug("Pcep Error Msg are Equal "); | ||
275 | + } else { | ||
276 | + Assert.fail("test case failed"); | ||
277 | + log.debug("not equal"); | ||
278 | + } | ||
279 | + } else { | ||
280 | + Assert.fail("test case failed"); | ||
281 | + log.debug("not equal"); | ||
282 | + } | ||
283 | + } | ||
284 | + | ||
285 | + @Test | ||
286 | + public void errorMessageTest6() throws PcepParseException { | ||
287 | + | ||
288 | + //PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object | ||
289 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x1C, // common header | ||
290 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
291 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
292 | + 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x08, // OPEN object header | ||
293 | + 0x20, 0x05, 0x1E, 0x01 // OPEN object | ||
294 | + }; | ||
295 | + | ||
296 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
297 | + buffer.writeBytes(errorMsg); | ||
298 | + | ||
299 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
300 | + PcepMessage message = null; | ||
301 | + try { | ||
302 | + message = reader.readFrom(buffer); | ||
303 | + } catch (PcepParseException e) { | ||
304 | + e.printStackTrace(); | ||
305 | + } | ||
306 | + | ||
307 | + byte[] testErrorMsg = {0}; | ||
308 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
309 | + if (message instanceof PcepErrorMsg) { | ||
310 | + message.writeTo(buf); | ||
311 | + int iReadLen = buf.writerIndex() - 0; | ||
312 | + testErrorMsg = new byte[iReadLen]; | ||
313 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
314 | + | ||
315 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
316 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
317 | + log.debug("Pcep Error Msg are Equal "); | ||
318 | + } else { | ||
319 | + Assert.fail("test case failed"); | ||
320 | + log.debug("not equal"); | ||
321 | + } | ||
322 | + } else { | ||
323 | + Assert.fail("test case failed"); | ||
324 | + log.debug("not equal"); | ||
325 | + } | ||
326 | + } | ||
327 | + | ||
328 | + @Test | ||
329 | + public void errorMessageTest7() throws PcepParseException { | ||
330 | + | ||
331 | + //PCEP-ERROR Object, OPEN Object | ||
332 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header | ||
333 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
334 | + 0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x08, // OPEN object header | ||
335 | + 0x20, 0x05, 0x1E, 0x01 // OPEN object | ||
336 | + }; | ||
337 | + | ||
338 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
339 | + buffer.writeBytes(errorMsg); | ||
340 | + | ||
341 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
342 | + PcepMessage message = null; | ||
343 | + try { | ||
344 | + message = reader.readFrom(buffer); | ||
345 | + } catch (PcepParseException e) { | ||
346 | + e.printStackTrace(); | ||
347 | + } | ||
348 | + | ||
349 | + byte[] testErrorMsg = {0}; | ||
350 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
351 | + if (message instanceof PcepErrorMsg) { | ||
352 | + message.writeTo(buf); | ||
353 | + int iReadLen = buf.writerIndex() - 0; | ||
354 | + testErrorMsg = new byte[iReadLen]; | ||
355 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
356 | + | ||
357 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
358 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
359 | + log.debug("Pcep Error Msg are Equal "); | ||
360 | + } else { | ||
361 | + Assert.fail("test case failed"); | ||
362 | + log.debug("not equal"); | ||
363 | + } | ||
364 | + } else { | ||
365 | + Assert.fail("test case failed"); | ||
366 | + log.debug("not equal"); | ||
367 | + } | ||
368 | + } | ||
369 | + | ||
370 | + @Test | ||
371 | + public void errorMessageTest8() throws PcepParseException { | ||
372 | + | ||
373 | + //PCEP-ERROR Object, RP Object, PCEP-ERROR Object | ||
374 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x20, // common header | ||
375 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
376 | + 0x00, 0x00, 0x01, 0x01, | ||
377 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
378 | + 0x00, 0x00, 0x00, 0x00, | ||
379 | + 0x00, 0x00, 0x00, 0x03, | ||
380 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
381 | + 0x00, 0x00, 0x01, 0x03}; | ||
382 | + | ||
383 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
384 | + buffer.writeBytes(errorMsg); | ||
385 | + | ||
386 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
387 | + PcepMessage message = null; | ||
388 | + try { | ||
389 | + message = reader.readFrom(buffer); | ||
390 | + } catch (PcepParseException e) { | ||
391 | + e.printStackTrace(); | ||
392 | + } | ||
393 | + | ||
394 | + byte[] testErrorMsg = {0}; | ||
395 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
396 | + if (message instanceof PcepErrorMsg) { | ||
397 | + message.writeTo(buf); | ||
398 | + int iReadLen = buf.writerIndex() - 0; | ||
399 | + testErrorMsg = new byte[iReadLen]; | ||
400 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
401 | + | ||
402 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
403 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
404 | + log.debug("Pcep Error Msg are Equal "); | ||
405 | + } else { | ||
406 | + Assert.fail("test case failed"); | ||
407 | + log.debug("not equal"); | ||
408 | + } | ||
409 | + } else { | ||
410 | + Assert.fail("test case failed"); | ||
411 | + log.debug("not equal"); | ||
412 | + } | ||
413 | + } | ||
414 | + | ||
415 | + @Test | ||
416 | + public void errorMessageTest9() throws PcepParseException { | ||
417 | + | ||
418 | + //PCEP-ERROR Object, PCEP-ERROR Object | ||
419 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header | ||
420 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
421 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
422 | + 0x00, 0x00, 0x01, 0x01 }; | ||
423 | + | ||
424 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
425 | + buffer.writeBytes(errorMsg); | ||
426 | + | ||
427 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
428 | + PcepMessage message = null; | ||
429 | + try { | ||
430 | + message = reader.readFrom(buffer); | ||
431 | + } catch (PcepParseException e) { | ||
432 | + e.printStackTrace(); | ||
433 | + } | ||
434 | + | ||
435 | + byte[] testErrorMsg = {0}; | ||
436 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
437 | + if (message instanceof PcepErrorMsg) { | ||
438 | + message.writeTo(buf); | ||
439 | + int iReadLen = buf.writerIndex() - 0; | ||
440 | + testErrorMsg = new byte[iReadLen]; | ||
441 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
442 | + | ||
443 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
444 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
445 | + log.debug("Pcep Error Msg are Equal "); | ||
446 | + } else { | ||
447 | + Assert.fail("test case failed"); | ||
448 | + log.debug("not equal"); | ||
449 | + } | ||
450 | + } else { | ||
451 | + Assert.fail("test case failed"); | ||
452 | + log.debug("not equal"); | ||
453 | + } | ||
454 | + } | ||
455 | + | ||
456 | + @Test | ||
457 | + public void errorMessageTest10() throws PcepParseException { | ||
458 | + | ||
459 | + //PCEP-ERROR Object, PCEP-ERROR Object | ||
460 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header | ||
461 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
462 | + 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
463 | + 0x00, 0x00, 0x01, 0x01 }; | ||
464 | + | ||
465 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
466 | + buffer.writeBytes(errorMsg); | ||
467 | + | ||
468 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
469 | + PcepMessage message = null; | ||
470 | + try { | ||
471 | + message = reader.readFrom(buffer); | ||
472 | + } catch (PcepParseException e) { | ||
473 | + e.printStackTrace(); | ||
474 | + } | ||
475 | + | ||
476 | + byte[] testErrorMsg = {0}; | ||
477 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
478 | + if (message instanceof PcepErrorMsg) { | ||
479 | + message.writeTo(buf); | ||
480 | + int iReadLen = buf.writerIndex() - 0; | ||
481 | + testErrorMsg = new byte[iReadLen]; | ||
482 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
483 | + | ||
484 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
485 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
486 | + log.debug("Pcep Error Msg are Equal "); | ||
487 | + } else { | ||
488 | + Assert.fail("test case failed"); | ||
489 | + log.debug("not equal"); | ||
490 | + } | ||
491 | + } else { | ||
492 | + Assert.fail("test case failed"); | ||
493 | + log.debug("not equal"); | ||
494 | + } | ||
495 | + } | ||
496 | + | ||
497 | + @Test | ||
498 | + public void errorMessageTest11() throws PcepParseException { | ||
499 | + | ||
500 | + //TE Object, PCEP-ERROR Object | ||
501 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x18, // common header | ||
502 | + 0x65, 0x13, 0x00, 0x0C, // TE Object Header | ||
503 | + 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
504 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
505 | + 0x00, 0x00, 0x01, 0x01 }; | ||
506 | + | ||
507 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
508 | + buffer.writeBytes(errorMsg); | ||
509 | + | ||
510 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
511 | + PcepMessage message = null; | ||
512 | + try { | ||
513 | + message = reader.readFrom(buffer); | ||
514 | + } catch (PcepParseException e) { | ||
515 | + e.printStackTrace(); | ||
516 | + } | ||
517 | + | ||
518 | + byte[] testErrorMsg = {0}; | ||
519 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
520 | + if (message instanceof PcepErrorMsg) { | ||
521 | + message.writeTo(buf); | ||
522 | + int iReadLen = buf.writerIndex() - 0; | ||
523 | + testErrorMsg = new byte[iReadLen]; | ||
524 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
525 | + | ||
526 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
527 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
528 | + log.debug("Pcep Error Msg are Equal "); | ||
529 | + } else { | ||
530 | + Assert.fail("test case failed"); | ||
531 | + log.debug("not equal"); | ||
532 | + } | ||
533 | + } else { | ||
534 | + Assert.fail("test case failed"); | ||
535 | + log.debug("not equal"); | ||
536 | + } | ||
537 | + } | ||
538 | + | ||
539 | + @Test | ||
540 | + public void errorMessageTest12() throws PcepParseException { | ||
541 | + | ||
542 | + //RP Object, PCEP-ERROR Object | ||
543 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x18, // common header | ||
544 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
545 | + 0x00, 0x00, 0x00, 0x00, | ||
546 | + 0x00, 0x00, 0x00, 0x03, | ||
547 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
548 | + 0x00, 0x00, 0x01, 0x01}; | ||
549 | + | ||
550 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
551 | + buffer.writeBytes(errorMsg); | ||
552 | + | ||
553 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
554 | + PcepMessage message = null; | ||
555 | + try { | ||
556 | + message = reader.readFrom(buffer); | ||
557 | + } catch (PcepParseException e) { | ||
558 | + e.printStackTrace(); | ||
559 | + } | ||
560 | + | ||
561 | + byte[] testErrorMsg = {0}; | ||
562 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
563 | + if (message instanceof PcepErrorMsg) { | ||
564 | + message.writeTo(buf); | ||
565 | + int iReadLen = buf.writerIndex() - 0; | ||
566 | + testErrorMsg = new byte[iReadLen]; | ||
567 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
568 | + | ||
569 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
570 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
571 | + log.debug("Pcep Error Msg are Equal "); | ||
572 | + } else { | ||
573 | + Assert.fail("test case failed"); | ||
574 | + log.debug("not equal"); | ||
575 | + } | ||
576 | + } else { | ||
577 | + Assert.fail("test case failed"); | ||
578 | + log.debug("not equal"); | ||
579 | + } | ||
580 | + } | ||
581 | + | ||
582 | + @Test | ||
583 | + public void errorMessageTest13() throws PcepParseException { | ||
584 | + | ||
585 | + //RP Object, RP Object, PCEP-ERROR Object | ||
586 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header | ||
587 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
588 | + 0x00, 0x00, 0x00, 0x00, | ||
589 | + 0x00, 0x00, 0x00, 0x03, | ||
590 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
591 | + 0x00, 0x00, 0x00, 0x00, | ||
592 | + 0x00, 0x00, 0x00, 0x04, | ||
593 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
594 | + 0x00, 0x00, 0x01, 0x01}; | ||
595 | + | ||
596 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
597 | + buffer.writeBytes(errorMsg); | ||
598 | + | ||
599 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
600 | + PcepMessage message = null; | ||
601 | + try { | ||
602 | + message = reader.readFrom(buffer); | ||
603 | + } catch (PcepParseException e) { | ||
604 | + e.printStackTrace(); | ||
605 | + } | ||
606 | + | ||
607 | + byte[] testErrorMsg = {0}; | ||
608 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
609 | + if (message instanceof PcepErrorMsg) { | ||
610 | + message.writeTo(buf); | ||
611 | + int iReadLen = buf.writerIndex() - 0; | ||
612 | + testErrorMsg = new byte[iReadLen]; | ||
613 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
614 | + | ||
615 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
616 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
617 | + log.debug("Pcep Error Msg are Equal "); | ||
618 | + } else { | ||
619 | + Assert.fail("test case failed"); | ||
620 | + log.debug("not equal"); | ||
621 | + } | ||
622 | + } else { | ||
623 | + Assert.fail("test case failed"); | ||
624 | + log.debug("not equal"); | ||
625 | + } | ||
626 | + } | ||
627 | + | ||
628 | + @Test | ||
629 | + public void errorMessageTest14() throws PcepParseException { | ||
630 | + | ||
631 | + //TE Object, TE Object, PCEP-ERROR Object | ||
632 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header | ||
633 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
634 | + 0x01, 0x00, 0x00, 0x03, | ||
635 | + 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
636 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
637 | + 0x01, 0x00, 0x00, 0x03, | ||
638 | + 0x00, 0x00, 0x00, 0x11, // TE-ID | ||
639 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
640 | + 0x00, 0x00, 0x01, 0x01}; | ||
641 | + | ||
642 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
643 | + buffer.writeBytes(errorMsg); | ||
644 | + | ||
645 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
646 | + PcepMessage message = null; | ||
647 | + try { | ||
648 | + message = reader.readFrom(buffer); | ||
649 | + } catch (PcepParseException e) { | ||
650 | + e.printStackTrace(); | ||
651 | + } | ||
652 | + | ||
653 | + byte[] testErrorMsg = {0}; | ||
654 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
655 | + if (message instanceof PcepErrorMsg) { | ||
656 | + message.writeTo(buf); | ||
657 | + int iReadLen = buf.writerIndex() - 0; | ||
658 | + testErrorMsg = new byte[iReadLen]; | ||
659 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
660 | + | ||
661 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
662 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
663 | + log.debug("Pcep Error Msg are Equal "); | ||
664 | + } else { | ||
665 | + Assert.fail("test case failed"); | ||
666 | + log.debug("not equal"); | ||
667 | + } | ||
668 | + } else { | ||
669 | + Assert.fail("test case failed"); | ||
670 | + log.debug("not equal"); | ||
671 | + } | ||
672 | + } | ||
673 | + | ||
674 | + @Test | ||
675 | + public void errorMessageTest15() throws PcepParseException { | ||
676 | + | ||
677 | + //PCEP-ERROR Object, TE Object, PCEP-ERROR Object | ||
678 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x20, // common header | ||
679 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
680 | + 0x00, 0x00, 0x01, 0x01, | ||
681 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
682 | + 0x01, 0x00, 0x00, 0x03, | ||
683 | + 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
684 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
685 | + 0x00, 0x00, 0x01, 0x03}; | ||
686 | + | ||
687 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
688 | + buffer.writeBytes(errorMsg); | ||
689 | + | ||
690 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
691 | + PcepMessage message = null; | ||
692 | + try { | ||
693 | + message = reader.readFrom(buffer); | ||
694 | + } catch (PcepParseException e) { | ||
695 | + e.printStackTrace(); | ||
696 | + } | ||
697 | + | ||
698 | + byte[] testErrorMsg = {0}; | ||
699 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
700 | + if (message instanceof PcepErrorMsg) { | ||
701 | + message.writeTo(buf); | ||
702 | + int iReadLen = buf.writerIndex() - 0; | ||
703 | + testErrorMsg = new byte[iReadLen]; | ||
704 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
705 | + | ||
706 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
707 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
708 | + log.debug("Pcep Error Msg are Equal "); | ||
709 | + } else { | ||
710 | + Assert.fail("test case failed"); | ||
711 | + log.debug("not equal"); | ||
712 | + } | ||
713 | + } else { | ||
714 | + Assert.fail("test case failed"); | ||
715 | + log.debug("not equal"); | ||
716 | + } | ||
717 | + } | ||
718 | + | ||
719 | + @Test | ||
720 | + public void errorMessageTest16() throws PcepParseException { | ||
721 | + | ||
722 | + //PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object | ||
723 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2C, // common header | ||
724 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
725 | + 0x00, 0x00, 0x01, 0x01, | ||
726 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
727 | + 0x00, 0x00, 0x00, 0x00, | ||
728 | + 0x00, 0x00, 0x00, 0x03, | ||
729 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
730 | + 0x00, 0x00, 0x00, 0x00, | ||
731 | + 0x00, 0x00, 0x00, 0x04, | ||
732 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
733 | + 0x00, 0x00, 0x01, 0x03}; | ||
734 | + | ||
735 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
736 | + buffer.writeBytes(errorMsg); | ||
737 | + | ||
738 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
739 | + PcepMessage message = null; | ||
740 | + try { | ||
741 | + message = reader.readFrom(buffer); | ||
742 | + } catch (PcepParseException e) { | ||
743 | + e.printStackTrace(); | ||
744 | + } | ||
745 | + | ||
746 | + byte[] testErrorMsg = {0}; | ||
747 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
748 | + if (message instanceof PcepErrorMsg) { | ||
749 | + message.writeTo(buf); | ||
750 | + int iReadLen = buf.writerIndex() - 0; | ||
751 | + testErrorMsg = new byte[iReadLen]; | ||
752 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
753 | + | ||
754 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
755 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
756 | + log.debug("Pcep Error Msg are Equal "); | ||
757 | + } else { | ||
758 | + Assert.fail("test case failed"); | ||
759 | + log.debug("not equal"); | ||
760 | + } | ||
761 | + } else { | ||
762 | + Assert.fail("test case failed"); | ||
763 | + log.debug("not equal"); | ||
764 | + } | ||
765 | + } | ||
766 | + | ||
767 | + @Test | ||
768 | + public void errorMessageTest17() throws PcepParseException { | ||
769 | + | ||
770 | + //PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object | ||
771 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2C, // common header | ||
772 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
773 | + 0x00, 0x00, 0x01, 0x01, | ||
774 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
775 | + 0x01, 0x00, 0x00, 0x03, | ||
776 | + 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
777 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
778 | + 0x01, 0x00, 0x00, 0x03, | ||
779 | + 0x00, 0x00, 0x00, 0x11, // TE-ID | ||
780 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
781 | + 0x00, 0x00, 0x01, 0x03}; | ||
782 | + | ||
783 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
784 | + buffer.writeBytes(errorMsg); | ||
785 | + | ||
786 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
787 | + PcepMessage message = null; | ||
788 | + try { | ||
789 | + message = reader.readFrom(buffer); | ||
790 | + } catch (PcepParseException e) { | ||
791 | + e.printStackTrace(); | ||
792 | + } | ||
793 | + | ||
794 | + byte[] testErrorMsg = {0}; | ||
795 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
796 | + if (message instanceof PcepErrorMsg) { | ||
797 | + message.writeTo(buf); | ||
798 | + int iReadLen = buf.writerIndex() - 0; | ||
799 | + testErrorMsg = new byte[iReadLen]; | ||
800 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
801 | + | ||
802 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
803 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
804 | + log.debug("Pcep Error Msg are Equal "); | ||
805 | + } else { | ||
806 | + Assert.fail("test case failed"); | ||
807 | + log.debug("not equal"); | ||
808 | + } | ||
809 | + } else { | ||
810 | + Assert.fail("test case failed"); | ||
811 | + log.debug("not equal"); | ||
812 | + } | ||
813 | + } | ||
814 | + | ||
815 | + @Test | ||
816 | + public void errorMessageTest18() throws PcepParseException { | ||
817 | + | ||
818 | + //PCEP-ERROR Object, PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object | ||
819 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header | ||
820 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
821 | + 0x00, 0x00, 0x01, 0x01, | ||
822 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
823 | + 0x00, 0x00, 0x01, 0x03, | ||
824 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
825 | + 0x00, 0x00, 0x00, 0x00, | ||
826 | + 0x00, 0x00, 0x00, 0x03, | ||
827 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
828 | + 0x00, 0x00, 0x00, 0x00, | ||
829 | + 0x00, 0x00, 0x00, 0x04, | ||
830 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
831 | + 0x00, 0x00, 0x01, 0x04, | ||
832 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
833 | + 0x00, 0x00, 0x01, 0x06}; | ||
834 | + | ||
835 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
836 | + buffer.writeBytes(errorMsg); | ||
837 | + | ||
838 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
839 | + PcepMessage message = null; | ||
840 | + try { | ||
841 | + message = reader.readFrom(buffer); | ||
842 | + } catch (PcepParseException e) { | ||
843 | + e.printStackTrace(); | ||
844 | + } | ||
845 | + | ||
846 | + byte[] testErrorMsg = {0}; | ||
847 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
848 | + if (message instanceof PcepErrorMsg) { | ||
849 | + message.writeTo(buf); | ||
850 | + int iReadLen = buf.writerIndex() - 0; | ||
851 | + testErrorMsg = new byte[iReadLen]; | ||
852 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
853 | + | ||
854 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
855 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
856 | + log.debug("Pcep Error Msg are Equal "); | ||
857 | + } else { | ||
858 | + Assert.fail("test case failed"); | ||
859 | + log.debug("not equal"); | ||
860 | + } | ||
861 | + } else { | ||
862 | + Assert.fail("test case failed"); | ||
863 | + log.debug("not equal"); | ||
864 | + } | ||
865 | + } | ||
866 | + | ||
867 | + @Test | ||
868 | + public void errorMessageTest19() throws PcepParseException { | ||
869 | + | ||
870 | + //PCEP-ERROR Object, PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object, PCEP-ERROR Object | ||
871 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header | ||
872 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
873 | + 0x00, 0x00, 0x01, 0x01, | ||
874 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
875 | + 0x00, 0x00, 0x01, 0x03, | ||
876 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
877 | + 0x01, 0x00, 0x00, 0x03, | ||
878 | + 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
879 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
880 | + 0x01, 0x00, 0x00, 0x03, | ||
881 | + 0x00, 0x00, 0x00, 0x11, // TE-ID | ||
882 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
883 | + 0x00, 0x00, 0x01, 0x04, | ||
884 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
885 | + 0x00, 0x00, 0x01, 0x06}; | ||
886 | + | ||
887 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
888 | + buffer.writeBytes(errorMsg); | ||
889 | + | ||
890 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
891 | + PcepMessage message = null; | ||
892 | + try { | ||
893 | + message = reader.readFrom(buffer); | ||
894 | + } catch (PcepParseException e) { | ||
895 | + e.printStackTrace(); | ||
896 | + } | ||
897 | + | ||
898 | + byte[] testErrorMsg = {0}; | ||
899 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
900 | + if (message instanceof PcepErrorMsg) { | ||
901 | + message.writeTo(buf); | ||
902 | + int iReadLen = buf.writerIndex() - 0; | ||
903 | + testErrorMsg = new byte[iReadLen]; | ||
904 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
905 | + | ||
906 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
907 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
908 | + log.debug("Pcep Error Msg are Equal "); | ||
909 | + } else { | ||
910 | + Assert.fail("test case failed"); | ||
911 | + log.debug("not equal"); | ||
912 | + } | ||
913 | + } else { | ||
914 | + Assert.fail("test case failed"); | ||
915 | + log.debug("not equal"); | ||
916 | + } | ||
917 | + } | ||
918 | + | ||
919 | + @Test | ||
920 | + public void errorMessageTest20() throws PcepParseException { | ||
921 | + | ||
922 | + /* PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object, | ||
923 | + * TE Object, PCEP-ERROR Object | ||
924 | + */ | ||
925 | + byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x48, // common header | ||
926 | + 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header | ||
927 | + 0x00, 0x00, 0x01, 0x01, | ||
928 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
929 | + 0x00, 0x00, 0x00, 0x00, | ||
930 | + 0x00, 0x00, 0x00, 0x03, | ||
931 | + 0x02, 0x10, 0x00, 0x0C, // RP Object Header | ||
932 | + 0x00, 0x00, 0x00, 0x00, | ||
933 | + 0x00, 0x00, 0x00, 0x04, | ||
934 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
935 | + 0x00, 0x00, 0x01, 0x04, | ||
936 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
937 | + 0x00, 0x00, 0x01, 0x06, | ||
938 | + 0x65, 0x10, 0x00, 0x0C, // TE Object Header | ||
939 | + 0x01, 0x00, 0x00, 0x03, | ||
940 | + 0x00, 0x00, 0x00, 0x10, // TE-ID | ||
941 | + 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header | ||
942 | + 0x00, 0x00, 0x01, 0x06}; | ||
943 | + | ||
944 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
945 | + buffer.writeBytes(errorMsg); | ||
946 | + | ||
947 | + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); | ||
948 | + PcepMessage message = null; | ||
949 | + try { | ||
950 | + message = reader.readFrom(buffer); | ||
951 | + } catch (PcepParseException e) { | ||
952 | + e.printStackTrace(); | ||
953 | + } | ||
954 | + | ||
955 | + byte[] testErrorMsg = {0}; | ||
956 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
957 | + if (message instanceof PcepErrorMsg) { | ||
958 | + message.writeTo(buf); | ||
959 | + int iReadLen = buf.writerIndex() - 0; | ||
960 | + testErrorMsg = new byte[iReadLen]; | ||
961 | + buf.readBytes(testErrorMsg, 0, iReadLen); | ||
962 | + | ||
963 | + if (Arrays.equals(errorMsg, testErrorMsg)) { | ||
964 | + Assert.assertArrayEquals(errorMsg, testErrorMsg); | ||
965 | + log.debug("Pcep Error Msg are Equal "); | ||
966 | + } else { | ||
967 | + Assert.fail("test case failed"); | ||
968 | + log.debug("not equal"); | ||
969 | + } | ||
970 | + } else { | ||
971 | + Assert.fail("test case failed"); | ||
972 | + log.debug("not equal"); | ||
973 | + } | ||
974 | + } | ||
975 | +} |
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 | +} |
-
Please register or login to post a comment