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.createStatsReportMsg;
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.rev171207.StatsReportsMessage;
21 public class StatisticsReportHandlerTest extends AbstractBmpMessageTest {
23 private static final byte[] STATS_REPORT = {
26 * 00 00 00 c2 <- total length of stats message + common header lenght
27 * 01 <- bmp message type - statistcs report
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 0E <- TLVs count
41 * 00 00 - rejected prefix type
44 * 00 01 <- duplicate prefix adv type
47 * 00 02 <- duplicate withdraws type
49 * 00 00 00 0B <- value
50 * 00 03 <- invalidate cluster type
52 * 00 00 00 53 <- value
53 * 00 04 <- as path type
55 * 00 00 00 66 <- value
56 * 00 05 <- invalidate originator id type
58 * 00 00 00 70 <- value
59 * 00 06 <- invalidate as confed type
61 * 00 00 00 55 <- value
62 * 00 07 <- adj ribs in routes type
64 * 00 00 00 00 00 00 00 10
65 * 00 08 <- loc rib routes type
67 * 00 00 00 00 00 00 00 64 <- value
68 * 00 09 <- per afi safi adj rib routes type
72 * 00 00 00 00 00 00 00 09 <- value
73 * 00 0A <- per afi safi local rib type
77 * 00 00 00 00 00 00 00 0A <- value
78 * 00 0B <- updates treated as withdraw
80 * 00 00 00 0B <- value
81 * 00 0C <- prefixes treated as withdraw
83 * 00 00 00 0C <- value
84 * 00 0D <- duplicate updates
86 * 00 00 00 0D <- value
90 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBA,
95 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
96 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
97 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
98 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // < - element 28
99 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
100 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
101 (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A,
102 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
103 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A, // <-element 48
105 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0E, // <- tlv counts
106 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
107 (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00,
108 (byte) 0x00, (byte) 0x00, (byte) 0x10,
109 (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0B,
110 (byte) 0x00, (byte) 0x03, (byte) 0x00,
111 (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x35, (byte) 0x00, (byte) 0x04, (byte) 0x00,
112 (byte) 0x04, (byte) 0x00, (byte) 0x00,
113 (byte) 0x00, (byte) 0x42, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00,
114 (byte) 0x00, (byte) 0x46, (byte) 0x00,
115 (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x37, (byte) 0x00,
116 (byte) 0x07, (byte) 0x00, (byte) 0x08,
117 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0A,
118 (byte) 0x00, (byte) 0x08, (byte) 0x00,
119 (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
122 (byte) 0x00, (byte) 0x09, // <- per afi safi adj rib routes type
123 (byte) 0x00, (byte) 0x0B, // <- length
124 (byte) 0x00, (byte) 0x01, // <- afi
125 (byte) 0x01, // <- safi
126 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
127 (byte) 0x09, // <- value
128 (byte) 0x00, (byte) 0x0A, // <- per afi safi local rib routes type
129 (byte) 0x00, (byte) 0x0B, // <- length
130 (byte) 0x00, (byte) 0x01, // <- afi
131 (byte) 0x01, // <- safi
132 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
133 (byte) 0x0A, // <- value
134 (byte) 0x00, (byte) 0x0B, // <- updates treated as withdraw
135 (byte) 0x00, (byte) 0x04, // <- length
136 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0B, // <- value
137 (byte) 0x00, (byte) 0x0C, // <- prefixes treated as withdraw
138 (byte) 0x00, (byte) 0x04, // <- length
139 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0C,// <- value
140 (byte) 0x00, (byte) 0x0D, // <- duplicate updates
141 (byte) 0x00, (byte) 0x04, // <- length
142 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0D // <- value
146 public void testSerializeStatsReportMessage() throws BmpDeserializationException {
147 final ByteBuf buffer = Unpooled.buffer(STATS_REPORT.length);
148 getBmpMessageRegistry().serializeMessage(createStatsReportMsg(), buffer);
149 assertArrayEquals(STATS_REPORT, ByteArray.readAllBytes(buffer));
153 public void testParseStatsReportMessage() throws BmpDeserializationException {
154 final StatsReportsMessage parsedStatsReportsMsg = (StatsReportsMessage) getBmpMessageRegistry()
155 .parseMessage(Unpooled.copiedBuffer(STATS_REPORT));
156 assertEquals(createStatsReportMsg(), parsedStatsReportsMsg);