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;
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;
21 public class PeerUpHandlerTest extends AbstractBmpMessageTest {
23 private static final byte[] PEER_UP_NOTIFICATION = {
26 * 00 00 00 D3 <- total length of peer up message + common header lenght
27 * 00 <- bmp message type Route Monitor
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
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
45 * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
46 * 00 43 <- message length
49 * 00 48 <- as number (72)
50 * 03 E8 <- hold time (1000)
51 * 14 14 14 14 <- bgp id
53 * 02 0C 41 04 00 00 00 46 41 04 00 00 00 50 <- opt values
55 * 00 00 00 04 <- information tlv - type and length
56 * 61 61 61 61 <- value
59 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA2,
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,
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,
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,
85 (byte) 0x00, (byte) 0x48,
86 (byte) 0x03, (byte) 0xE8,
87 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
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,
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,
97 (byte) 0x00, (byte) 0x48,
98 (byte) 0x03, (byte) 0xE8,
99 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
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
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));
115 public void testParsePeerUpNotification() throws BmpDeserializationException {
116 final PeerUpNotification parsedPeerUpNotif = (PeerUpNotification) getBmpMessageRegistry().parseMessage(
117 Unpooled.copiedBuffer(PEER_UP_NOTIFICATION));
118 assertEquals(createPeerUpNotification(), parsedPeerUpNotif);