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
9 package org.opendaylight.protocol.bmp.parser.message;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createRouteMonitMsg;
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.rev150512.RouteMonitoringMessage;
21 public class RouteMonitoringMessageHandlerTest extends AbstractBmpMessageTest {
25 * 00 00 00 D3 <- total length of initiation 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 * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
40 * 00 A5 <- message length
41 * 02 <- Update message
43 private static final byte[] ROUTE_MONIT_MSG = {
45 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB4,
51 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
52 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
53 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
54 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
55 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
56 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
57 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
58 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
60 (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,
61 (byte) 0x00, (byte) 0x84,
63 (byte) 0x00, (byte) 0x0C, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x14, (byte) 0x18, (byte) 0x14, (byte) 0x14,
64 (byte) 0x0A, (byte) 0x18, (byte) 0x1E, (byte) 0x0A, (byte) 0x0A, (byte) 0x00, (byte) 0x55, (byte) 0x40,
65 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x80, (byte) 0x1A, (byte) 0x0B, (byte) 0x01, (byte) 0x00,
66 (byte) 0x0B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
67 (byte) 0x01, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0x64,
68 (byte) 0x64, (byte) 0x64, (byte) 0x64, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00,
69 (byte) 0x00, (byte) 0x7B, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
70 (byte) 0x02, (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0xC0, (byte) 0x07, (byte) 0x08, (byte) 0x00,
71 (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0xC0,
72 (byte) 0x08, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x65, (byte) 0xFF, (byte) 0xFF,
73 (byte) 0xFF, (byte) 0x66, (byte) 0x80, (byte) 0x09, (byte) 0x04, (byte) 0x0C, (byte) 0x0C, (byte) 0x0C,
74 (byte) 0x0C, (byte) 0x80, (byte) 0x0A, (byte) 0x08, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E,
75 (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
76 (byte) 0x18, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x18, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E
80 public void testSerializeRouteMonitMessage() throws BmpDeserializationException {
81 final ByteBuf buffer = Unpooled.buffer();
82 getBmpMessageRegistry().serializeMessage(createRouteMonitMsg(false), buffer);
83 assertArrayEquals(ROUTE_MONIT_MSG, ByteArray.readAllBytes(buffer));
87 public void testParseRouteMonitMessage() throws BmpDeserializationException {
88 final RouteMonitoringMessage parsedInitMsg = (RouteMonitoringMessage) getBmpMessageRegistry().parseMessage(Unpooled.copiedBuffer(ROUTE_MONIT_MSG));
89 assertEquals(createRouteMonitMsg(true), parsedInitMsg);