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 | */ |
Ray Milkey | 753ad63 | 2015-11-06 08:46:33 -0800 | [diff] [blame] | 16 | package org.onosproject.bgpio.protocol; |
Vidyashree Rama | 95e349d | 2015-10-30 15:10:16 +0530 | [diff] [blame] | 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.bgpio.exceptions.BGPParseException; |
Vidyashree Rama | 95e349d | 2015-10-30 15:10:16 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.types.BGPHeader; |
| 23 | |
Ray Milkey | 753ad63 | 2015-11-06 08:46:33 -0800 | [diff] [blame] | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.instanceOf; |
| 26 | import static org.hamcrest.core.Is.is; |
| 27 | |
Vidyashree Rama | 95e349d | 2015-10-30 15:10:16 +0530 | [diff] [blame] | 28 | /** |
| 29 | * Test case for BGP KEEPALIVE Message. |
| 30 | */ |
| 31 | public class BGPKeepaliveMsgTest { |
| 32 | |
| 33 | /** |
| 34 | * This test case checks BGP Keepalive message. |
| 35 | */ |
| 36 | @Test |
| 37 | public void keepaliveMessageTest1() throws BGPParseException { |
| 38 | |
| 39 | // BGP KEEPALIVE Message |
| 40 | byte[] keepaliveMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 41 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 42 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 43 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 44 | 0x00, 0x13, 0x04}; |
| 45 | |
| 46 | byte[] testKeepaliveMsg; |
| 47 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 48 | buffer.writeBytes(keepaliveMsg); |
| 49 | |
| 50 | BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader(); |
| 51 | BGPMessage message; |
| 52 | BGPHeader bgpHeader = new BGPHeader(); |
| 53 | |
| 54 | message = reader.readFrom(buffer, bgpHeader); |
| 55 | |
| 56 | assertThat(message, instanceOf(BGPKeepaliveMsg.class)); |
| 57 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 58 | message.writeTo(buf); |
| 59 | |
| 60 | int readLen = buf.writerIndex(); |
| 61 | testKeepaliveMsg = new byte[readLen]; |
| 62 | buf.readBytes(testKeepaliveMsg, 0, readLen); |
| 63 | |
| 64 | assertThat(testKeepaliveMsg, is(keepaliveMsg)); |
| 65 | } |
| 66 | } |