Bug-6562: Support add-path in base BGP NLRI
[bgpcep.git] / bmp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / PeerUpHandlerTest.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.createPeerUpNotification;
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.rev171207.PeerUpNotification;
19
20 public class PeerUpHandlerTest extends AbstractBmpMessageTest {
21
22     private static final byte[] PEER_UP_NOTIFICATION = {
23         /*
24          * 03 <- bmp version
25          * 00 00 00 D3 <- total length of peer up message + common header lenght
26          * 00 <- bmp message type Route Monitor
27          *
28          * 00 <- global type
29          * 00 <- flags (L and V flag)
30          * 00 00 <- post flag padding - 2 bytes skipped
31          * 00 00 00 00 <- 4 bytes skipped (because global type) - without distinguisher
32          * 00 00 00 00 00 00 00 00 00 00 00 00 <- skip IPV6_LENGTH - IPV4_LENGTH - 12 bytes
33          * 0A 0A 0A 0A <- IPV4 address - 4 bytes
34          * 00 00 00 48 <- as number
35          * 0A 0A 0A 0A <- bgp id - ipv4 address - 4 bytes
36          * 00 00 00 05 <- time stamp - 4 bytes
37          * 00 00 00 0A <- time stamp micro - 4 bytes
38          *
39          * 00 00 00 00 00 00 00 00 00 00 00 00 <- skipped bytes
40          * 0A 0A 0A 0A <- notification Ipv4 local address
41          * 00 DC <- local port number
42          * 13 88 <- remote port number
43          *
44          * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
45          * 00 43 <- message length
46          * 01 <- Open message
47          * 04 <- bgp version
48          * 00 48 <- as number (72)
49          * 03 E8 <- hold time (1000)
50          * 14 14 14 14 <- bgp id
51          * 0E <- number of opt
52          * 02 0C 41 04 00 00 00 46 41 04 00 00 00 50 <- opt values
53          *
54          * 00 00 00 04 <- information tlv - type and length
55          * 61 61 61 61 <- value
56          */
57         (byte) 0x03,
58         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA2,
59         (byte) 0x03,
60
61         (byte) 0x00,
62         (byte) 0x00,
63         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
64         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
65         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
66         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
67         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
68         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
69         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
70         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
71
72         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
73         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
74         (byte) 0x00, (byte) 0xDC,
75         (byte) 0x13, (byte) 0x88,
76
77         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
78         (byte) 0x00, (byte) 0x2B,
79         (byte) 0x01,
80         (byte) 0x04,
81         (byte) 0x00, (byte) 0x48,
82         (byte) 0x03, (byte) 0xE8,
83         (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
84         (byte) 0x0E,
85         (byte) 0x02, (byte) 0x0C, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50,
86
87         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
88         (byte) 0x00, (byte) 0x2B,
89         (byte) 0x01,
90         (byte) 0x04,
91         (byte) 0x00, (byte) 0x48,
92         (byte) 0x03, (byte) 0xE8,
93         (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
94         (byte) 0x0E,
95         (byte) 0x02, (byte) 0x0C, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50,
96         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04,
97         (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61
98     };
99
100     @Test
101     public void testSerializePeerUpNotification() throws BmpDeserializationException {
102         final ByteBuf buffer = Unpooled.buffer();
103         getBmpMessageRegistry().serializeMessage(createPeerUpNotification(), buffer);
104         assertArrayEquals(PEER_UP_NOTIFICATION, ByteArray.readAllBytes(buffer));
105     }
106
107     @Test
108     public void testParsePeerUpNotification() throws BmpDeserializationException {
109         final PeerUpNotification parsedPeerUpNotif = (PeerUpNotification) getBmpMessageRegistry().parseMessage(
110                 Unpooled.copiedBuffer(PEER_UP_NOTIFICATION));
111         assertEquals(createPeerUpNotification(), parsedPeerUpNotif);
112     }
113 }