blob: f9921efd60fb07370658102a977fea9b09dc0384 [file] [log] [blame]
bharat saraswale2e7a002015-08-21 22:47:30 +05301/*
2 * Copyright 2014-2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Sho SHIMIZU3559c312015-11-04 14:59:31 -080016package org.onosproject.pcepio.protocol;
bharat saraswale2e7a002015-08-21 22:47:30 +053017
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
bharat saraswale2e7a002015-08-21 22:47:30 +053020import org.junit.Test;
21import org.onosproject.pcepio.exceptions.PcepParseException;
Sho SHIMIZU3559c312015-11-04 14:59:31 -080022
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.instanceOf;
25import static org.hamcrest.core.Is.is;
bharat saraswale2e7a002015-08-21 22:47:30 +053026
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053027public class PcepReportMsgExtTest {
bharat saraswale2e7a002015-08-21 22:47:30 +053028
29 /**
30 * This test case checks forSRP Object,LSP Object(symbolic path tlv),ERO Object
31 * SRP Object,LSP Object(symbolic path tlv,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object
32 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +053033 */
34 @Test
35 public void reportMessageTest39() throws PcepParseException {
36
37 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x98,
38 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053039 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053040 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
41 0x07, 0x10, 0x00, 0x14, //ERO Object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053042 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
43 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053044 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053045 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053046 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
47 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053048 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
49 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053050 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object
51 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
52 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
53 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
54 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
55 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00};
56
57 byte[] testReportMsg = {0};
58 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
59 buffer.writeBytes(reportMsg);
60
61 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
62 PcepMessage message = null;
63
64 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053065 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +053066 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
67 message.writeTo(buf);
68
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053069 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +053070 testReportMsg = new byte[readLen];
71 buf.readBytes(testReportMsg, 0, readLen);
72
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053073 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +053074 }
75
76 /**
77 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object
78 * SRP Object,LSP Object(symbolic path tlv),ERO Object
79 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +053080 */
81 @Test
82 public void reportMessageTest40() throws PcepParseException {
83
84 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x64,
85 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053086 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053087 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
88 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053089 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
90 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053091 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053092 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053093 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
94 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053095 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
96 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00};
bharat saraswale2e7a002015-08-21 22:47:30 +053097
98 byte[] testReportMsg = {0};
99 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
100 buffer.writeBytes(reportMsg);
101
102 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
103 PcepMessage message = null;
104
105 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530106 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530107 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
108 message.writeTo(buf);
109
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530110 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530111 testReportMsg = new byte[readLen];
112 buf.readBytes(testReportMsg, 0, readLen);
113
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530114 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530115 }
116
117 /**
118 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object
119 * SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object
120 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +0530121 */
122 @Test
123 public void reportMessageTest41() throws PcepParseException {
124
125 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x8c,
126 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530127 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530128 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
129 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530130 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
131 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530132 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530135 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530136 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
137 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530138 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
139 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530140 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA object
141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
142
143 byte[] testReportMsg = {0};
144 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
145 buffer.writeBytes(reportMsg);
146
147 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
148 PcepMessage message = null;
149
150 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530151 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530152 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
153 message.writeTo(buf);
154
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530155 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530156 testReportMsg = new byte[readLen];
157 buf.readBytes(testReportMsg, 0, readLen);
158
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530159 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530160 }
161
162 /**
163 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,
164 * Metric-list SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,Metric-list,
165 * RRO Object
166 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +0530167 */
168 @Test
169 public void reportMessageTest42() throws PcepParseException {
170
171 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0xE8,
172 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530173 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530174 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
175 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530176 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
177 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530178 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
181 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object
182 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530183 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530184 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
185 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530186 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
187 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530188 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
191 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object
192 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object
193 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
194 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
195 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
196 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
197 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00};
198
199 byte[] testReportMsg = {0};
200 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
201 buffer.writeBytes(reportMsg);
202
203 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
204 PcepMessage message = null;
205
206 message = reader.readFrom(buffer);
207
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530208 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530209 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
210 message.writeTo(buf);
211
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530212 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530213 testReportMsg = new byte[readLen];
214 buf.readBytes(testReportMsg, 0, readLen);
215
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530216 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530217 }
218}