blob: 68ce3070058ef537189674616d384a4cb8b70334 [file] [log] [blame]
Vidyashree Rama95e349d2015-10-30 15:10:16 +05301/*
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 Milkey753ad632015-11-06 08:46:33 -080016package org.onosproject.bgpio.protocol;
Vidyashree Rama95e349d2015-10-30 15:10:16 +053017
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.junit.Test;
21import org.onosproject.bgpio.exceptions.BGPParseException;
Vidyashree Rama95e349d2015-10-30 15:10:16 +053022import org.onosproject.bgpio.types.BGPHeader;
23
Ray Milkey753ad632015-11-06 08:46:33 -080024import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.instanceOf;
26import static org.hamcrest.core.Is.is;
27
Vidyashree Rama95e349d2015-10-30 15:10:16 +053028/**
29 * Test case for BGP KEEPALIVE Message.
30 */
31public 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}