blob: 346caf8733a3b2f8d353edbc9b823c4d7272a627 [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 */
16package org.onosproject.pcepio;
17
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053018import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.instanceOf;
20import static org.hamcrest.core.Is.is;
bharat saraswale2e7a002015-08-21 22:47:30 +053021import org.jboss.netty.buffer.ChannelBuffer;
22import org.jboss.netty.buffer.ChannelBuffers;
bharat saraswale2e7a002015-08-21 22:47:30 +053023import org.junit.Test;
24import org.onosproject.pcepio.exceptions.PcepParseException;
25import org.onosproject.pcepio.protocol.PcepFactories;
26import org.onosproject.pcepio.protocol.PcepMessage;
27import org.onosproject.pcepio.protocol.PcepMessageReader;
28import org.onosproject.pcepio.protocol.PcepReportMsg;
29
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053030public class PcepReportMsgExtTest {
bharat saraswale2e7a002015-08-21 22:47:30 +053031
32 /**
33 * This test case checks forSRP Object,LSP Object(symbolic path tlv),ERO Object
34 * SRP Object,LSP Object(symbolic path tlv,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object
35 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +053036 */
37 @Test
38 public void reportMessageTest39() throws PcepParseException {
39
40 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x98,
41 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053042 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053043 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
44 0x07, 0x10, 0x00, 0x14, //ERO Object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053045 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
46 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053047 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053048 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053049 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
50 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053051 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
52 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053053 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object
54 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
55 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
56 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
57 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
58 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00};
59
60 byte[] testReportMsg = {0};
61 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
62 buffer.writeBytes(reportMsg);
63
64 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
65 PcepMessage message = null;
66
67 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053068 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +053069 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
70 message.writeTo(buf);
71
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053072 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +053073 testReportMsg = new byte[readLen];
74 buf.readBytes(testReportMsg, 0, readLen);
75
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +053076 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +053077 }
78
79 /**
80 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object
81 * SRP Object,LSP Object(symbolic path tlv),ERO Object
82 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +053083 */
84 @Test
85 public void reportMessageTest40() throws PcepParseException {
86
87 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x64,
88 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053089 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053090 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
91 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053092 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
93 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +053094 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053095 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +053096 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
97 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +053098 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
99 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00};
bharat saraswale2e7a002015-08-21 22:47:30 +0530100
101 byte[] testReportMsg = {0};
102 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
103 buffer.writeBytes(reportMsg);
104
105 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
106 PcepMessage message = null;
107
108 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530109 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530110 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
111 message.writeTo(buf);
112
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530113 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530114 testReportMsg = new byte[readLen];
115 buf.readBytes(testReportMsg, 0, readLen);
116
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530117 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530118 }
119
120 /**
121 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object
122 * SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object
123 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +0530124 */
125 @Test
126 public void reportMessageTest41() throws PcepParseException {
127
128 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x8c,
129 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530130 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530131 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
132 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530133 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
134 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530135 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530138 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530139 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
140 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530141 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
142 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530143 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA object
144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
145
146 byte[] testReportMsg = {0};
147 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
148 buffer.writeBytes(reportMsg);
149
150 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
151 PcepMessage message = null;
152
153 message = reader.readFrom(buffer);
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530154 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530155 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
156 message.writeTo(buf);
157
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530158 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530159 testReportMsg = new byte[readLen];
160 buf.readBytes(testReportMsg, 0, readLen);
161
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530162 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530163 }
164
165 /**
166 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,
167 * Metric-list SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,Metric-list,
168 * RRO Object
169 * in PcRpt message.
bharat saraswale2e7a002015-08-21 22:47:30 +0530170 */
171 @Test
172 public void reportMessageTest42() throws PcepParseException {
173
174 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0xE8,
175 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530176 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530177 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
178 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530179 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
180 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530181 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
184 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object
185 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530186 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
bharat saraswale2e7a002015-08-21 22:47:30 +0530187 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
188 0x07, 0x10, 0x00, 0x14, //ERO object
bharat saraswalb4e5cbe2015-09-02 19:33:20 +0530189 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
190 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
bharat saraswale2e7a002015-08-21 22:47:30 +0530191 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
194 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object
195 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object
196 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
197 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
198 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
199 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
200 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00};
201
202 byte[] testReportMsg = {0};
203 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
204 buffer.writeBytes(reportMsg);
205
206 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
207 PcepMessage message = null;
208
209 message = reader.readFrom(buffer);
210
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530211 assertThat(message, instanceOf(PcepReportMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +0530212 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
213 message.writeTo(buf);
214
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530215 int readLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +0530216 testReportMsg = new byte[readLen];
217 buf.readBytes(testReportMsg, 0, readLen);
218
Priyanka bhaskar3e1a6972015-08-27 15:31:54 +0530219 assertThat(testReportMsg, is(reportMsg));
bharat saraswale2e7a002015-08-21 22:47:30 +0530220 }
221}