blob: 682c1bc089aa5297d32d77041816f0e3af8b5fb8 [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;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053021import org.onosproject.bgpio.exceptions.BgpParseException;
22import org.onosproject.bgpio.types.BgpHeader;
Vidyashree Rama95e349d2015-10-30 15:10:16 +053023
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 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053031public class BgpKeepaliveMsgTest {
Vidyashree Rama95e349d2015-10-30 15:10:16 +053032
33 /**
34 * This test case checks BGP Keepalive message.
35 */
36 @Test
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053037 public void keepaliveMessageTest1() throws BgpParseException {
Vidyashree Rama95e349d2015-10-30 15:10:16 +053038
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
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053050 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
51 BgpMessage message;
52 BgpHeader bgpHeader = new BgpHeader();
Vidyashree Rama95e349d2015-10-30 15:10:16 +053053
54 message = reader.readFrom(buffer, bgpHeader);
55
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053056 assertThat(message, instanceOf(BgpKeepaliveMsg.class));
Vidyashree Rama95e349d2015-10-30 15:10:16 +053057 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}