blob: 57ab9d901bd1bd75b9b204f38b5b1b597bdee100 [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 */
16package org.onosproject.bgp;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.instanceOf;
20import static org.hamcrest.core.Is.is;
21
22import org.jboss.netty.buffer.ChannelBuffer;
23import org.jboss.netty.buffer.ChannelBuffers;
24import org.junit.Test;
25import org.onosproject.bgpio.exceptions.BGPParseException;
26import org.onosproject.bgpio.protocol.BGPFactories;
27import org.onosproject.bgpio.protocol.BGPKeepaliveMsg;
28import org.onosproject.bgpio.protocol.BGPMessage;
29import org.onosproject.bgpio.protocol.BGPMessageReader;
30import org.onosproject.bgpio.types.BGPHeader;
31
32/**
33 * Test case for BGP KEEPALIVE Message.
34 */
35public 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}