f9921efd60fb07370658102a977fea9b09dc0384
[onosfw.git] /
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.protocol;
17
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.buffer.ChannelBuffers;
20 import org.junit.Test;
21 import org.onosproject.pcepio.exceptions.PcepParseException;
22
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.instanceOf;
25 import static org.hamcrest.core.Is.is;
26
27 public class PcepReportMsgExtTest {
28
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.
33      */
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
39                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
40                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
41                 0x07, 0x10, 0x00, 0x14, //ERO Object
42                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
43                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
44                 0x21, 0x10, 0x00, 0x0C,  0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x01, //SRP object
45                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
46                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
47                 0x07, 0x10, 0x00, 0x14, //ERO object
48                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
49                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
50                 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);
65         assertThat(message, instanceOf(PcepReportMsg.class));
66         ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
67         message.writeTo(buf);
68
69         int readLen = buf.writerIndex();
70         testReportMsg = new byte[readLen];
71         buf.readBytes(testReportMsg, 0, readLen);
72
73         assertThat(testReportMsg, is(reportMsg));
74     }
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.
80      */
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
86                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
87                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
88                 0x07, 0x10, 0x00, 0x14, //ERO object
89                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
90                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
91                 0x21, 0x10, 0x00, 0x0C,  0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x01, //SRP object
92                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
93                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
94                 0x07, 0x10, 0x00, 0x14, //ERO object
95                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
96                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00};
97
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);
106         assertThat(message, instanceOf(PcepReportMsg.class));
107         ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
108         message.writeTo(buf);
109
110         int readLen = buf.writerIndex();
111         testReportMsg = new byte[readLen];
112         buf.readBytes(testReportMsg, 0, readLen);
113
114         assertThat(testReportMsg, is(reportMsg));
115     }
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.
121      */
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
127                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
128                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
129                 0x07, 0x10, 0x00, 0x14, //ERO object
130                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
131                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
132                 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
135                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
136                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
137                 0x07, 0x10, 0x00, 0x14, //ERO object
138                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
139                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
140                 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);
151         assertThat(message, instanceOf(PcepReportMsg.class));
152         ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
153         message.writeTo(buf);
154
155         int readLen = buf.writerIndex();
156         testReportMsg = new byte[readLen];
157         buf.readBytes(testReportMsg, 0, readLen);
158
159         assertThat(testReportMsg, is(reportMsg));
160     }
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.
167      */
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
173                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
174                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
175                 0x07, 0x10, 0x00, 0x14, //ERO object
176                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
177                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
178                 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
183                 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
184                 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
185                 0x07, 0x10, 0x00, 0x14, //ERO object
186                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
187                 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
188                 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
208         assertThat(message, instanceOf(PcepReportMsg.class));
209         ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
210         message.writeTo(buf);
211
212         int readLen = buf.writerIndex();
213         testReportMsg = new byte[readLen];
214         buf.readBytes(testReportMsg, 0, readLen);
215
216         assertThat(testReportMsg, is(reportMsg));
217     }
218 }