Shashikanth VH | 5826066 | 2016-02-13 01:12:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.bgpio.types; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.instanceOf; |
| 20 | import static org.hamcrest.core.Is.is; |
| 21 | |
| 22 | import org.jboss.netty.buffer.ChannelBuffer; |
| 23 | import org.jboss.netty.buffer.ChannelBuffers; |
| 24 | import org.junit.Test; |
| 25 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| 26 | import org.onosproject.bgpio.protocol.BgpFactories; |
| 27 | import org.onosproject.bgpio.protocol.BgpMessage; |
| 28 | import org.onosproject.bgpio.protocol.BgpMessageReader; |
| 29 | import org.onosproject.bgpio.protocol.ver4.BgpUpdateMsgVer4; |
| 30 | |
| 31 | /** |
| 32 | * Test for MP unreach NLRI encoding and decoding. |
| 33 | */ |
| 34 | public class MpUnReachNlriTest { |
| 35 | |
| 36 | /** |
| 37 | * This testcase checks BGP update message. |
| 38 | */ |
| 39 | @Test |
| 40 | public void mpUnReachNlriTest() throws BgpParseException { |
| 41 | |
| 42 | // BGP flow spec Message |
| 43 | byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 44 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 45 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 46 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 47 | (byte) 0xff, 0x00, 0x2b, 0x02, 0x00, 0x00, 0x00, 0x14, |
| 48 | (byte) 0x90, 0x0f, 0x00, 0x10, 0x00, 0x01, (byte) 0x85, |
| 49 | 0x0c, 0x02, 0x20, (byte) 0xc0, (byte) 0xa8, 0x07, 0x36, |
| 50 | 0x03, (byte) 0x81, 0x67, 0x04, (byte) 0x81, 0x01}; |
| 51 | |
| 52 | byte[] testFsMsg; |
| 53 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 54 | buffer.writeBytes(flowSpecMsg); |
| 55 | |
| 56 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 57 | BgpMessage message; |
| 58 | BgpHeader bgpHeader = new BgpHeader(); |
| 59 | |
| 60 | message = reader.readFrom(buffer, bgpHeader); |
| 61 | |
| 62 | assertThat(message, instanceOf(BgpUpdateMsgVer4.class)); |
| 63 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 64 | message.writeTo(buf); |
| 65 | |
| 66 | int readLen = buf.writerIndex(); |
| 67 | testFsMsg = new byte[readLen]; |
| 68 | buf.readBytes(testFsMsg, 0, readLen); |
| 69 | |
| 70 | assertThat(testFsMsg, is(flowSpecMsg)); |
| 71 | } |
| 72 | } |