MVPN RFC6514 Extendend communities
[bgpcep.git] / bmp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / TerminationHandlerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bmp.parser.message;
9
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
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.rev180329.TerminationMessage;
20
21 public class TerminationHandlerTest extends AbstractBmpMessageTest {
22
23     private static final byte[] TERMINATION_MESSAGE = {
24         /*
25          * 03 <- bmp version
26          * 00 00 00 20 <- total length of termination message + common header lenght
27          * 05 <- bmp message type - termination
28          * 00 01 <- type REASON
29          * 00 02 <- length
30          * 00 00 <- reason = 0 (Session administratively closed)
31          * 00 00 <- type STRING
32          * 00 06 <- length
33          * 65 72 72 6F 72 31 <- value error1
34          * 00 00 <- type STRING
35          * 00 06 <- length
36          * 65 72 72 6F 72 31 <- value error1
37          */
38         (byte) 0x03,
39         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20,
40         (byte) 0x05,
41         (byte) 0x00, (byte) 0x01,
42         (byte) 0x00, (byte) 0x02,
43         (byte) 0x00, (byte) 0x00,
44         (byte) 0x00, (byte) 0x00,
45         (byte) 0x00, (byte) 0x06,
46         (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31,
47         (byte) 0x00, (byte) 0x00,
48         (byte) 0x00, (byte) 0x06,
49         (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31
50     };
51
52     @Test
53     public void testSerializeTerminationMessage() throws BmpDeserializationException {
54         final ByteBuf buffer = Unpooled.buffer();
55         getBmpMessageRegistry().serializeMessage(createTerminationMsg(), buffer);
56         assertArrayEquals(TERMINATION_MESSAGE, ByteArray.readAllBytes(buffer));
57     }
58
59
60     @Test
61     public void testParseTerminationMessage() throws BmpDeserializationException {
62         final TerminationMessage parsedInitMsg = (TerminationMessage) getBmpMessageRegistry()
63                 .parseMessage(Unpooled.copiedBuffer(TERMINATION_MESSAGE));
64         assertEquals(createTerminationMsg(), parsedInitMsg);
65     }
66 }