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.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.rev150512.PeerUpNotification;
20 public class PeerUpHandlerTest extends AbstractBmpMessageTest {
22 private static final byte[] PEER_UP_NOTIFICATION = {
25 * 00 00 00 D3 <- total length of peer up message + common header lenght
26 * 00 <- bmp message type Route Monitor
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
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
44 * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
45 * 00 43 <- message length
48 * 00 48 <- as number (72)
49 * 03 E8 <- hold time (1000)
50 * 14 14 14 14 <- bgp id
52 * 02 0C 41 04 00 00 00 46 41 04 00 00 00 50 <- opt values
54 * 00 00 00 04 <- information tlv - type and length
55 * 61 61 61 61 <- value
58 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA2,
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,
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,
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,
81 (byte) 0x00, (byte) 0x48,
82 (byte) 0x03, (byte) 0xE8,
83 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
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,
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,
91 (byte) 0x00, (byte) 0x48,
92 (byte) 0x03, (byte) 0xE8,
93 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
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
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));
108 public void testParsePeerUpNotification() throws BmpDeserializationException {
109 final PeerUpNotification parsedPeerUpNotif = (PeerUpNotification) getBmpMessageRegistry().parseMessage(
110 Unpooled.copiedBuffer(PEER_UP_NOTIFICATION));
111 assertEquals(createPeerUpNotification(), parsedPeerUpNotif);