2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bmp.parser.message;
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;
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.PeerDownNotification;
22 public class PeerDownHandlerTest extends AbstractBmpMessageTest {
24 private static final byte[] PEER_DOWN_FSM_DATA = {
27 * 00 00 00 31 <- total length of peer down notification + common header lenght
28 * 02 <- bmp message type (2 - peer down notification)
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
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.)
45 (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x33, (byte) 0x02,
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,
59 (byte) 0x02, (byte) 0x00, (byte) 0x18
62 private static final byte[] PEER_DOWN_NOTIFICATION = {
65 * 00 00 00 44 <- total length of peer down notification + common header lenght
66 * 02 <- bmp message type (2 - peer down notification)
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)
71 * 00 00 - number of withdrawn routes
72 * 00 00 - total path attributes lengths
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
85 * 01 <- Reason why the session was terminated (1 - the local system closed the session + BGP Notification)
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
93 (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0x02,
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,
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,
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));
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));
132 public void testParsePeerDownNotificationFSM() throws BmpDeserializationException {
133 final PeerDownNotification parsedPeerDownFSM = (PeerDownNotification) getBmpMessageRegistry().parseMessage(
134 Unpooled.copiedBuffer(PEER_DOWN_FSM_DATA));
135 assertEquals(createPeerDownFSM(), parsedPeerDownFSM);
139 public void testParsePeerDownNotification() throws BmpDeserializationException {
140 final PeerDownNotification parsedPeerDownNotif = (PeerDownNotification) getBmpMessageRegistry().parseMessage(
141 Unpooled.copiedBuffer(PEER_DOWN_NOTIFICATION));
142 assertEquals(createPeerDownNotification(), parsedPeerDownNotif);