YANG revision dates mass-update
[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
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.rev200120.PeerUpNotification;
20
21 public class PeerUpHandlerTest extends AbstractBmpMessageTest {
22
23     private static final byte[] PEER_UP_NOTIFICATION = {
24         /*
25          * 03 <- bmp version
26          * 00 00 00 D3 <- total length of peer up 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          * 00 00 00 00 00 00 00 00 00 00 00 00 <- skipped bytes
41          * 0A 0A 0A 0A <- notification Ipv4 local address
42          * 00 DC <- local port number
43          * 13 88 <- remote port number
44          *
45          * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
46          * 00 43 <- message length
47          * 01 <- Open message
48          * 04 <- bgp version
49          * 00 48 <- as number (72)
50          * 03 E8 <- hold time (1000)
51          * 14 14 14 14 <- bgp id
52          * 0E <- number of opt
53          * 02 0C 41 04 00 00 00 46 41 04 00 00 00 50 <- opt values
54          *
55          * 00 00 00 04 <- information tlv - type and length
56          * 61 61 61 61 <- value
57          */
58         (byte) 0x03,
59         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA2,
60         (byte) 0x03,
61
62         (byte) 0x00,
63         (byte) 0x00,
64         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
65         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
66         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
67         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
68         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
69         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
70         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
71         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
72         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
73
74         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
75         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
76         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
77         (byte) 0x00, (byte) 0xDC,
78         (byte) 0x13, (byte) 0x88,
79
80         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
81         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
82         (byte) 0x00, (byte) 0x2B,
83         (byte) 0x01,
84         (byte) 0x04,
85         (byte) 0x00, (byte) 0x48,
86         (byte) 0x03, (byte) 0xE8,
87         (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
88         (byte) 0x0E,
89         (byte) 0x02, (byte) 0x0C, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46,
90         (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50,
91
92         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
93         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
94         (byte) 0x00, (byte) 0x2B,
95         (byte) 0x01,
96         (byte) 0x04,
97         (byte) 0x00, (byte) 0x48,
98         (byte) 0x03, (byte) 0xE8,
99         (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
100         (byte) 0x0E,
101         (byte) 0x02, (byte) 0x0C, (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46,
102         (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50,
103         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04,
104         (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61
105     };
106
107     @Test
108     public void testSerializePeerUpNotification() throws BmpDeserializationException {
109         final ByteBuf buffer = Unpooled.buffer();
110         getBmpMessageRegistry().serializeMessage(createPeerUpNotification(), buffer);
111         assertArrayEquals(PEER_UP_NOTIFICATION, ByteArray.readAllBytes(buffer));
112     }
113
114     @Test
115     public void testParsePeerUpNotification() throws BmpDeserializationException {
116         final PeerUpNotification parsedPeerUpNotif = (PeerUpNotification) getBmpMessageRegistry().parseMessage(
117                 Unpooled.copiedBuffer(PEER_UP_NOTIFICATION));
118         assertEquals(createPeerUpNotification(), parsedPeerUpNotif);
119     }
120 }