MVPN RFC6514 Extendend communities
[bgpcep.git] / bmp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / PeerDownHandlerTest.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.createPeerDownFSM;
13 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createPeerDownNotification;
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.rev180329.PeerDownNotification;
21
22 public class PeerDownHandlerTest extends AbstractBmpMessageTest {
23
24     private static final byte[] PEER_DOWN_FSM_DATA = {
25         /*
26          * 03 <- bmp version
27          * 00 00 00 31 <- total length of peer down notification + common header lenght
28          * 02 <- bmp message type (2 - peer down notification)
29          *
30          * 00 <- global type
31          * 00 <- flags (L and V flag)
32          * 00 00 <- post flag padding - 2 bytes skipped
33          * 00 00 00 00 <- 4 bytes skipped (because global type) - without distinguisher
34          * 00 00 00 00 00 00 00 00 00 00 00 00 - skip IPV6_LENGTH - IPV4_LENGTH - 12 bytes
35          * 01 02 02 04 01 02 02 04 01 02 02 04 01 02 02 04 - IPV6 address - 16 bytes
36          * 00 00 00 48 - as number
37          * 0A 0A 0A 0A - bgp id - ipv4 address - 4 bytes
38          * 00 00 00 05 - time stamp - 4 bytes
39          * 00 00 00 0A - time stamp micro - 4 bytes
40          *
41          * 02 <- Reason why the session was terminated (2 - the local system closed the session)
42          * 00 18 <- the code of FSM event (24 - NotifMsgVerErr - An event is generated when a
43           * Notification message with "version error" is received.)
44          */
45         (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x33, (byte) 0x02,
46
47         (byte) 0x00,
48         (byte) 0x00,
49         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
50         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
51         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
52         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
53         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
54         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
55         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
56         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
57         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
58
59         (byte) 0x02, (byte) 0x00, (byte) 0x18
60     };
61
62     private static final byte[] PEER_DOWN_NOTIFICATION = {
63         /*
64          * 03 <- bmp version
65          * 00 00 00 44 <- total length of peer down notification + common header lenght
66          * 02 <- bmp message type (2 - peer down notification)
67          *
68          * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF - marker
69          * 00 17 - mesage length (greater than 19 bytes == COMMON_HEADER_LENGTH)
70          * 02 - message type
71          * 00 00 - number of withdrawn routes
72          * 00 00 - total path attributes lengths
73          *
74          * 00 <- global type
75          * 00 <- flags (L and V flag)
76          * 00 00 <- post flag padding - 2 bytes skipped
77          * 00 00 00 00 <- 4 bytes skipped (because global type) - without distinguisher
78          * 00 00 00 00 00 00 00 00 00 00 00 00 - skip IPV6_LENGTH - IPV4_LENGTH - 12 bytes
79          * 0A 0A 0A 0A - IPV4 address - 4 bytes
80          * 00 00 00 48 - as number
81          * 0A 0A 0A 0A - bgp id - ipv4 address - 4 bytes
82          * 00 00 00 05 - time stamp - 4 bytes
83          * 00 00 00 0A - time stamp micro - 4 bytes
84          *
85          * 01 <- Reason why the session was terminated (1 - the local system closed the session + BGP Notification)
86          *
87          * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF - marker
88          * 00 15 - message length (should be > COMMON-HEADER-LENGTH), COMMON-HEADER-LENGTH = 19 bytes
89          * 03 - message type NOTIFICATION
90          * 01 - error code - message header error
91          * 01 - connection not synchronized
92          */
93         (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0x02,
94
95         (byte) 0x00,
96         (byte) 0x00,
97         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
98         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
99         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
100         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
101         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
102         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
103         (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
104         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
105         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
106
107         (byte) 0x01,
108
109         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
110         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
111         (byte) 0x00, (byte) 0x15,
112         (byte) 0x03,
113         (byte) 0x01,
114         (byte) 0x01
115     };
116
117     @Test
118     public void testSerializePeerDownNotificationFSM() throws BmpDeserializationException {
119         final ByteBuf buffer = Unpooled.buffer();
120         getBmpMessageRegistry().serializeMessage(createPeerDownFSM(), buffer);
121         assertArrayEquals(PEER_DOWN_FSM_DATA, ByteArray.readAllBytes(buffer));
122     }
123
124     @Test
125     public void testSerializePeerDownNotification() throws BmpDeserializationException {
126         final ByteBuf buffer = Unpooled.buffer();
127         getBmpMessageRegistry().serializeMessage(createPeerDownNotification(), buffer);
128         assertArrayEquals(PEER_DOWN_NOTIFICATION, ByteArray.readAllBytes(buffer));
129     }
130
131     @Test
132     public void testParsePeerDownNotificationFSM() throws BmpDeserializationException {
133         final PeerDownNotification parsedPeerDownFSM = (PeerDownNotification) getBmpMessageRegistry().parseMessage(
134                 Unpooled.copiedBuffer(PEER_DOWN_FSM_DATA));
135         assertEquals(createPeerDownFSM(), parsedPeerDownFSM);
136     }
137
138     @Test
139     public void testParsePeerDownNotification() throws BmpDeserializationException {
140         final PeerDownNotification parsedPeerDownNotif = (PeerDownNotification) getBmpMessageRegistry().parseMessage(
141                 Unpooled.copiedBuffer(PEER_DOWN_NOTIFICATION));
142         assertEquals(createPeerDownNotification(), parsedPeerDownNotif);
143     }
144 }