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;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.InitiationMessage;
22 public class InitiationHandlerTest extends AbstractBmpMessageTest {
24 private static final String STR_INFO = "The information field type 0";
25 private static final String SYS_DESCR = "SysDescr type 1";
26 private static final String SYS_NAME = "SysName type 2";
28 private static final byte[] INIT_MSG = {
31 * 00 00 00 4B <- total length of initiation message + common header lenght
32 * 04 <- bmp message type
33 * 00 02 <- initiation message type SYS_NAME
34 * 00 0E <- the length of SYS_NAME
35 * 53 79 73 4E 61 6D 65 20 74 79 70 65 20 32 <- value of SYS_NAME
36 * 00 01 <- initiation message type SYS_DESCR
37 * 00 0F <- the lenght of SYS_DESCR
38 * 53 79 73 44 65 73 63 72 20 74 79 70 65 20 31 <- value of SYS_DESCR
39 * 00 00 <- initiation message type STRING
40 * 00 1C <- the length of STRING
41 * 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
43 (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4B, (byte) 0x04, (byte) 0x00, (byte) 0x02,
44 (byte) 0x00, (byte) 0x0E,
45 (byte) 0x53, (byte) 0x79, (byte) 0x73, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x20,
46 (byte) 0x74, (byte) 0x79,
47 (byte) 0x70, (byte) 0x65, (byte) 0x20, (byte) 0x32, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x0F,
48 (byte) 0x53, (byte) 0x79,
49 (byte) 0x73, (byte) 0x44, (byte) 0x65, (byte) 0x73, (byte) 0x63, (byte) 0x72, (byte) 0x20, (byte) 0x74,
50 (byte) 0x79, (byte) 0x70,
51 (byte) 0x65, (byte) 0x20, (byte) 0x31, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1C, (byte) 0x54,
52 (byte) 0x68, (byte) 0x65,
53 (byte) 0x20, (byte) 0x69, (byte) 0x6E, (byte) 0x66, (byte) 0x6F, (byte) 0x72, (byte) 0x6D, (byte) 0x61,
54 (byte) 0x74, (byte) 0x69,
55 (byte) 0x6F, (byte) 0x6E, (byte) 0x20, (byte) 0x66, (byte) 0x69, (byte) 0x65, (byte) 0x6C, (byte) 0x64,
56 (byte) 0x20, (byte) 0x74,
57 (byte) 0x79, (byte) 0x70, (byte) 0x65, (byte) 0x20, (byte) 0x30
61 public void testSerializeInitiationMessage() throws BmpDeserializationException {
62 final ByteBuf buffer = Unpooled.buffer();
63 getBmpMessageRegistry().serializeMessage(createInitMsg(SYS_DESCR, SYS_NAME, STR_INFO), buffer);
64 assertArrayEquals(INIT_MSG, ByteArray.readAllBytes(buffer));
68 public void testParseInitiationMessage() throws BmpDeserializationException {
69 final InitiationMessage parsedInitMsg = (InitiationMessage) getBmpMessageRegistry()
70 .parseMessage(Unpooled.copiedBuffer(INIT_MSG));
71 assertEquals(createInitMsg(SYS_DESCR, SYS_NAME, STR_INFO), parsedInitMsg);