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;
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.RouteMonitoringMessage;
22 public class RouteMonitoringMessageHandlerTest extends AbstractBmpMessageTest {
26 * 00 00 00 D3 <- total length of initiation 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 * FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF <- marker
41 * 00 A5 <- message length
42 * 02 <- Update message
44 private static final byte[] ROUTE_MONIT_MSG = {
46 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB4,
52 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
53 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
54 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
55 (byte) 0x00, (byte) 0x00, (byte) 0x00,
56 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
57 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
58 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
59 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
60 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
62 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
63 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
64 (byte) 0x00, (byte) 0x84,
66 (byte) 0x00, (byte) 0x0C, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x14, (byte) 0x18, (byte) 0x14,
68 (byte) 0x0A, (byte) 0x18, (byte) 0x1E, (byte) 0x0A, (byte) 0x0A, (byte) 0x00, (byte) 0x55, (byte) 0x40,
69 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x80, (byte) 0x1A, (byte) 0x0B, (byte) 0x01, (byte) 0x00,
70 (byte) 0x0B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
71 (byte) 0x01, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0x64,
72 (byte) 0x64, (byte) 0x64, (byte) 0x64, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00,
73 (byte) 0x00, (byte) 0x7B, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
74 (byte) 0x02, (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0xC0, (byte) 0x07, (byte) 0x08, (byte) 0x00,
75 (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0xC0,
76 (byte) 0x08, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x65, (byte) 0xFF, (byte) 0xFF,
77 (byte) 0xFF, (byte) 0x66, (byte) 0x80, (byte) 0x09, (byte) 0x04, (byte) 0x0C, (byte) 0x0C, (byte) 0x0C,
78 (byte) 0x0C, (byte) 0x80, (byte) 0x0A, (byte) 0x08, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E,
79 (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x18, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
80 (byte) 0x18, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x18, (byte) 0x1E, (byte) 0x1E, (byte) 0x1E
84 public void testSerializeRouteMonitMessage() throws BmpDeserializationException {
85 final ByteBuf buffer = Unpooled.buffer();
86 getBmpMessageRegistry().serializeMessage(createRouteMonitMsg(false), buffer);
87 assertArrayEquals(ROUTE_MONIT_MSG, ByteArray.readAllBytes(buffer));
91 public void testParseRouteMonitMessage() throws BmpDeserializationException {
92 final RouteMonitoringMessage parsedInitMsg = (RouteMonitoringMessage) getBmpMessageRegistry()
93 .parseMessage(Unpooled.copiedBuffer(ROUTE_MONIT_MSG));
94 assertEquals(createRouteMonitMsg(true), parsedInitMsg);