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
8 package org.opendaylight.protocol.bmp.parser.message;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createTerminationMsg;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.TerminationMessage;
20 public class TerminationHandlerTest extends AbstractBmpMessageTest {
22 private static final byte[] TERMINATION_MESSAGE = {
25 * 00 00 00 20 <- total length of termination message + common header lenght
26 * 05 <- bmp message type - termination
27 * 00 01 <- type REASON
29 * 00 00 <- reason = 0 (Session administratively closed)
30 * 00 00 <- type STRING
32 * 65 72 72 6F 72 31 <- value error1
33 * 00 00 <- type STRING
35 * 65 72 72 6F 72 31 <- value error1
38 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20,
40 (byte) 0x00, (byte) 0x01,
41 (byte) 0x00, (byte) 0x02,
42 (byte) 0x00, (byte) 0x00,
43 (byte) 0x00, (byte) 0x00,
44 (byte) 0x00, (byte) 0x06,
45 (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31,
46 (byte) 0x00, (byte) 0x00,
47 (byte) 0x00, (byte) 0x06,
48 (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31
52 public void testSerializeTerminationMessage() throws BmpDeserializationException {
53 final ByteBuf buffer = Unpooled.buffer();
54 getBmpMessageRegistry().serializeMessage(createTerminationMsg(), buffer);
55 assertArrayEquals(TERMINATION_MESSAGE, ByteArray.readAllBytes(buffer));
60 public void testParseTerminationMessage() throws BmpDeserializationException {
61 final TerminationMessage parsedInitMsg = (TerminationMessage) getBmpMessageRegistry().parseMessage(Unpooled.copiedBuffer(TERMINATION_MESSAGE));
62 assertEquals(createTerminationMsg(), parsedInitMsg);