Vidyashree Rama | 95e349d | 2015-10-30 15:10:16 +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.bgp; |
| 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.BGPKeepaliveMsg; |
| 28 | import org.onosproject.bgpio.protocol.BGPMessage; |
| 29 | import org.onosproject.bgpio.protocol.BGPMessageReader; |
| 30 | import org.onosproject.bgpio.types.BGPHeader; |
| 31 | |
| 32 | /** |
| 33 | * Test case for BGP KEEPALIVE Message. |
| 34 | */ |
| 35 | public class BGPKeepaliveMsgTest { |
| 36 | |
| 37 | /** |
| 38 | * This test case checks BGP Keepalive message. |
| 39 | */ |
| 40 | @Test |
| 41 | public void keepaliveMessageTest1() throws BGPParseException { |
| 42 | |
| 43 | // BGP KEEPALIVE Message |
| 44 | byte[] keepaliveMsg = new byte[] {(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, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 48 | 0x00, 0x13, 0x04}; |
| 49 | |
| 50 | byte[] testKeepaliveMsg; |
| 51 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 52 | buffer.writeBytes(keepaliveMsg); |
| 53 | |
| 54 | BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader(); |
| 55 | BGPMessage message; |
| 56 | BGPHeader bgpHeader = new BGPHeader(); |
| 57 | |
| 58 | message = reader.readFrom(buffer, bgpHeader); |
| 59 | |
| 60 | assertThat(message, instanceOf(BGPKeepaliveMsg.class)); |
| 61 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 62 | message.writeTo(buf); |
| 63 | |
| 64 | int readLen = buf.writerIndex(); |
| 65 | testKeepaliveMsg = new byte[readLen]; |
| 66 | buf.readBytes(testKeepaliveMsg, 0, readLen); |
| 67 | |
| 68 | assertThat(testKeepaliveMsg, is(keepaliveMsg)); |
| 69 | } |
| 70 | } |