blob: 0131860a51e2c0983a2389766b330a2073eac6d4 [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +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 */
Sho SHIMIZU3559c312015-11-04 14:59:31 -080016package org.onosproject.pcepio.protocol;
bharat saraswalf7364db2015-08-11 13:39:31 +053017
bharat saraswalf7364db2015-08-11 13:39:31 +053018import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
bharat saraswalf7364db2015-08-11 13:39:31 +053020import org.junit.Assert;
bharat saraswalf7364db2015-08-11 13:39:31 +053021import org.junit.Test;
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053022import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
bharat saraswalf7364db2015-08-11 13:39:31 +053023import org.onosproject.pcepio.exceptions.PcepParseException;
bharat saraswalf7364db2015-08-11 13:39:31 +053024
Mahesh Poojary S99748322015-08-27 18:49:45 +053025import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.instanceOf;
27import static org.hamcrest.core.Is.is;
28
bharat saraswalf7364db2015-08-11 13:39:31 +053029public class PcepKeepaliveMsgTest {
30
bharat saraswale2e7a002015-08-21 22:47:30 +053031 /**
32 * Common header for keep alive message.
bharat saraswale2e7a002015-08-21 22:47:30 +053033 */
bharat saraswalf7364db2015-08-11 13:39:31 +053034 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053035 public void keepaliveMessageTest1() throws PcepParseException, PcepOutOfBoundMessageException {
bharat saraswalf7364db2015-08-11 13:39:31 +053036
37 byte[] keepaliveMsg = new byte[] {0x20, 0x02, 0x00, 0x04 };
38
bharat saraswale2e7a002015-08-21 22:47:30 +053039 byte[] testKeepaliveMsg = {0 };
bharat saraswalf7364db2015-08-11 13:39:31 +053040 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
41 buffer.writeBytes(keepaliveMsg);
42
43 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
44 PcepMessage message = null;
bharat saraswalf7364db2015-08-11 13:39:31 +053045
bharat saraswale2e7a002015-08-21 22:47:30 +053046 message = reader.readFrom(buffer);
Mahesh Poojary S99748322015-08-27 18:49:45 +053047 assertThat(message, instanceOf(PcepKeepaliveMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +053048 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
Mahesh Poojary S99748322015-08-27 18:49:45 +053049
bharat saraswale2e7a002015-08-21 22:47:30 +053050 message.writeTo(buf);
Mahesh Poojary S99748322015-08-27 18:49:45 +053051
bharat saraswale2e7a002015-08-21 22:47:30 +053052 testKeepaliveMsg = buf.array();
bharat saraswalf7364db2015-08-11 13:39:31 +053053
Mahesh Poojary S99748322015-08-27 18:49:45 +053054 int iReadLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +053055 testKeepaliveMsg = new byte[iReadLen];
56 buf.readBytes(testKeepaliveMsg, 0, iReadLen);
57
Mahesh Poojary S99748322015-08-27 18:49:45 +053058 Assert.assertThat(testKeepaliveMsg, is(keepaliveMsg));
bharat saraswalf7364db2015-08-11 13:39:31 +053059 }
60}