2fee2b53386676e1ab8f72b74ab03b33ee786927
[bgpcep.git] / bmp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / RouteMonitoringMessageHandlerTest.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
9 package org.opendaylight.protocol.bmp.parser.message;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createRouteMonitMsg;
14
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.rev171207.RouteMonitoringMessage;
21
22 public class RouteMonitoringMessageHandlerTest extends AbstractBmpMessageTest {
23
24     /*
25      * 03 <- bmp version
26      * 00 00 00 D3 <- total length of initiation message + common header lenght
27      * 00 <- bmp message type Route Monitor
28      *
29      * 00 <- global type
30      * 00 <- flags (L and V flag)
31      * 00 00 <- post flag padding - 2 bytes skipped
32      * 00 00 00 00 <- 4 bytes skipped (because global type) - without distinguisher
33      * 00 00 00 00 00 00 00 00 00 00 00 00 <- skip IPV6_LENGTH - IPV4_LENGTH - 12 bytes
34      * 0A 0A 0A 0A <- IPV4 address - 4 bytes
35      * 00 00 00 48 <- as number
36      * 0A 0A 0A 0A <- bgp id - ipv4 address - 4 bytes
37      * 00 00 00 05 <- time stamp - 4 bytes
38      * 00 00 00 0A <- time stamp micro - 4 bytes
39      *
40      * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
41      * 00 A5 <- message length
42      * 02 <- Update message
43      */
44     private static final byte[] ROUTE_MONIT_MSG = {
45         (byte) 0x03,
46         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB4,
47         (byte) 0x00,
48         (byte) 0x00,
49
50         (byte) 0x00,
51         (byte) 0x00,
52         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
53         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
54         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
55         (byte) 0x00, (byte) 0x00, (byte) 0x00,
56         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
57         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
58         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
59         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
60         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
61
62         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
63         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
64         (byte) 0x00, (byte) 0x84,
65         (byte) 0x02,
66         (byte) 0x00, (byte) 0x0C, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x14, (byte) 0x18, (byte) 0x14,
67         (byte) 0x14,
68         (byte) 0x0A, (byte) 0x18, (byte) 0x1E, (byte) 0x0A, (byte) 0x0A, (byte) 0x00, (byte) 0x55, (byte) 0x40,
69         (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x80, (byte) 0x1A, (byte) 0x0B, (byte) 0x01, (byte) 0x00,
70         (byte) 0x0B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
71         (byte) 0x01, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0x64,
72         (byte) 0x64, (byte) 0x64, (byte) 0x64, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00,
73         (byte) 0x00, (byte) 0x7B, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
74         (byte) 0x02, (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0xC0, (byte) 0x07, (byte) 0x08, (byte) 0x00,
75         (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0xC0,
76         (byte) 0x08, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x65, (byte) 0xFF, (byte) 0xFF,
77         (byte) 0xFF, (byte) 0x66, (byte) 0x80, (byte) 0x09, (byte) 0x04, (byte) 0x0C, (byte) 0x0C, (byte) 0x0C,
78         (byte) 0x0C, (byte) 0x80, (byte) 0x0A, (byte) 0x08, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E,
79         (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
80         (byte) 0x18, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x18, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E
81     };
82
83     @Test
84     public void testSerializeRouteMonitMessage() throws BmpDeserializationException  {
85         final ByteBuf buffer = Unpooled.buffer();
86         getBmpMessageRegistry().serializeMessage(createRouteMonitMsg(false), buffer);
87         assertArrayEquals(ROUTE_MONIT_MSG, ByteArray.readAllBytes(buffer));
88     }
89
90     @Test
91     public void testParseRouteMonitMessage() throws BmpDeserializationException {
92         final RouteMonitoringMessage parsedInitMsg = (RouteMonitoringMessage) getBmpMessageRegistry()
93                 .parseMessage(Unpooled.copiedBuffer(ROUTE_MONIT_MSG));
94         assertEquals(createRouteMonitMsg(true), parsedInitMsg);
95     }
96 }