bharat saraswal | e2e7a00 | 2015-08-21 22:47:30 +0530 | [diff] [blame] | 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 org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.Assert; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 23 | import org.onosproject.pcepio.protocol.PcepFactories; |
| 24 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 25 | import org.onosproject.pcepio.protocol.PcepMessageReader; |
| 26 | import org.onosproject.pcepio.protocol.PcepReportMsg; |
| 27 | |
| 28 | public class PcepReportMsgTest2 { |
| 29 | |
| 30 | /** |
| 31 | * This test case checks forSRP Object,LSP Object(symbolic path tlv),ERO Object |
| 32 | * SRP Object,LSP Object(symbolic path tlv,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object |
| 33 | * in PcRpt message. |
| 34 | * |
| 35 | * @throws PcepParseException while parsing PCEP message |
| 36 | */ |
| 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 |
| 42 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 43 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 44 | 0x07, 0x10, 0x00, 0x14, //ERO Object |
| 45 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 46 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 47 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 48 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 49 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 50 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 51 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 52 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 53 | 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); |
| 68 | Assert.assertTrue("PcepMessage is not instance of PcRpt", message instanceof PcepReportMsg); |
| 69 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 70 | message.writeTo(buf); |
| 71 | |
| 72 | int readLen = buf.writerIndex() - 0; |
| 73 | testReportMsg = new byte[readLen]; |
| 74 | buf.readBytes(testReportMsg, 0, readLen); |
| 75 | |
| 76 | Assert.assertArrayEquals("PcRpt messages are not equal", reportMsg, testReportMsg); |
| 77 | } |
| 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. |
| 83 | * |
| 84 | * @throws PcepParseException while parsing PCEP message |
| 85 | */ |
| 86 | @Test |
| 87 | public void reportMessageTest40() throws PcepParseException { |
| 88 | |
| 89 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x64, |
| 90 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 91 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 92 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 93 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 94 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 95 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 96 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 97 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 98 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 99 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 100 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 101 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; |
| 102 | |
| 103 | byte[] testReportMsg = {0}; |
| 104 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 105 | buffer.writeBytes(reportMsg); |
| 106 | |
| 107 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 108 | PcepMessage message = null; |
| 109 | |
| 110 | message = reader.readFrom(buffer); |
| 111 | Assert.assertTrue("PcepMessage is not instance of PcRpt", message instanceof PcepReportMsg); |
| 112 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 113 | message.writeTo(buf); |
| 114 | |
| 115 | int readLen = buf.writerIndex() - 0; |
| 116 | testReportMsg = new byte[readLen]; |
| 117 | buf.readBytes(testReportMsg, 0, readLen); |
| 118 | |
| 119 | Assert.assertArrayEquals("PcRpt messages are not equal", reportMsg, testReportMsg); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object |
| 124 | * SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object |
| 125 | * in PcRpt message. |
| 126 | * |
| 127 | * @throws PcepParseException while parsing PCEP message |
| 128 | */ |
| 129 | @Test |
| 130 | public void reportMessageTest41() throws PcepParseException { |
| 131 | |
| 132 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x8c, |
| 133 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 134 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 135 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 136 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 137 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 138 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 139 | 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object |
| 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 141 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 142 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 143 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 144 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 145 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 146 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 147 | 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA object |
| 148 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 149 | |
| 150 | byte[] testReportMsg = {0}; |
| 151 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 152 | buffer.writeBytes(reportMsg); |
| 153 | |
| 154 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 155 | PcepMessage message = null; |
| 156 | |
| 157 | message = reader.readFrom(buffer); |
| 158 | Assert.assertTrue("PcepMessage is not instance of PcRpt", message instanceof PcepReportMsg); |
| 159 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 160 | message.writeTo(buf); |
| 161 | |
| 162 | int readLen = buf.writerIndex() - 0; |
| 163 | testReportMsg = new byte[readLen]; |
| 164 | buf.readBytes(testReportMsg, 0, readLen); |
| 165 | |
| 166 | Assert.assertArrayEquals("PcRpt messages are not equal", reportMsg, testReportMsg); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object, |
| 171 | * Metric-list SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,Metric-list, |
| 172 | * RRO Object |
| 173 | * in PcRpt message. |
| 174 | * |
| 175 | * @throws PcepParseException while parsing PCEP message |
| 176 | */ |
| 177 | @Test |
| 178 | public void reportMessageTest42() throws PcepParseException { |
| 179 | |
| 180 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0xE8, |
| 181 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 182 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 183 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 184 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 185 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 186 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 187 | 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 189 | 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object |
| 190 | 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object |
| 191 | 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 192 | 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, (byte) 0x83, //LSP object |
| 193 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 194 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 195 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, |
| 196 | (byte) 0x81, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 197 | 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object |
| 198 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 199 | 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object |
| 200 | 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object |
| 201 | 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object |
| 202 | 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, |
| 203 | 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, |
| 204 | 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, |
| 205 | 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, |
| 206 | 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; |
| 207 | |
| 208 | byte[] testReportMsg = {0}; |
| 209 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 210 | buffer.writeBytes(reportMsg); |
| 211 | |
| 212 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 213 | PcepMessage message = null; |
| 214 | |
| 215 | message = reader.readFrom(buffer); |
| 216 | |
| 217 | Assert.assertTrue("PcepMessage is not instance of PcRpt", message instanceof PcepReportMsg); |
| 218 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 219 | message.writeTo(buf); |
| 220 | |
| 221 | int readLen = buf.writerIndex() - 0; |
| 222 | testReportMsg = new byte[readLen]; |
| 223 | buf.readBytes(testReportMsg, 0, readLen); |
| 224 | |
| 225 | Assert.assertArrayEquals("PcRpt messages are not equal", reportMsg, testReportMsg); |
| 226 | } |
| 227 | } |