2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bmp.parser.message;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createInitMsg;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.InitiationMessage;
21 public class InitiationHandlerTest extends AbstractBmpMessageTest {
23 private static final String STR_INFO = "The information field type 0";
24 private static final String SYS_DESCR = "SysDescr type 1";
25 private static final String SYS_NAME = "SysName type 2";
27 private static final byte[] INIT_MSG = {
30 * 00 00 00 4B <- total length of initiation message + common header lenght
31 * 04 <- bmp message type
32 * 00 02 <- initiation message type SYS_NAME
33 * 00 0E <- the length of SYS_NAME
34 * 53 79 73 4E 61 6D 65 20 74 79 70 65 20 32 <- value of SYS_NAME
35 * 00 01 <- initiation message type SYS_DESCR
36 * 00 0F <- the lenght of SYS_DESCR
37 * 53 79 73 44 65 73 63 72 20 74 79 70 65 20 31 <- value of SYS_DESCR
38 * 00 00 <- initiation message type STRING
39 * 00 1C <- the length of STRING
40 * 54 68 65 20 69 6E 66 6F 72 6D 61 74 69 6F 6E 20 66 69 65 6C 64 20 74 79 70 65 20 30 <- value of STRING
42 (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4B, (byte) 0x04, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x0E,
43 (byte) 0x53, (byte) 0x79, (byte) 0x73, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x20, (byte) 0x74, (byte) 0x79,
44 (byte) 0x70, (byte) 0x65, (byte) 0x20, (byte) 0x32, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x0F, (byte) 0x53, (byte) 0x79,
45 (byte) 0x73, (byte) 0x44, (byte) 0x65, (byte) 0x73, (byte) 0x63, (byte) 0x72, (byte) 0x20, (byte) 0x74, (byte) 0x79, (byte) 0x70,
46 (byte) 0x65, (byte) 0x20, (byte) 0x31, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1C, (byte) 0x54, (byte) 0x68, (byte) 0x65,
47 (byte) 0x20, (byte) 0x69, (byte) 0x6E, (byte) 0x66, (byte) 0x6F, (byte) 0x72, (byte) 0x6D, (byte) 0x61, (byte) 0x74, (byte) 0x69,
48 (byte) 0x6F, (byte) 0x6E, (byte) 0x20, (byte) 0x66, (byte) 0x69, (byte) 0x65, (byte) 0x6C, (byte) 0x64, (byte) 0x20, (byte) 0x74,
49 (byte) 0x79, (byte) 0x70, (byte) 0x65, (byte) 0x20, (byte) 0x30
53 public void testSerializeInitiationMessage() throws BmpDeserializationException {
54 final ByteBuf buffer = Unpooled.buffer();
55 getBmpMessageRegistry().serializeMessage(createInitMsg(SYS_DESCR, SYS_NAME, STR_INFO), buffer);
56 assertArrayEquals(INIT_MSG, ByteArray.readAllBytes(buffer));
60 public void testParseInitiationMessage() throws BmpDeserializationException {
61 final InitiationMessage parsedInitMsg = (InitiationMessage) getBmpMessageRegistry().parseMessage(Unpooled.copiedBuffer(INIT_MSG));
62 assertEquals(createInitMsg(SYS_DESCR, SYS_NAME, STR_INFO), parsedInitMsg);