a2e952c7b68c62c7aef52e356b47144e425d706c
[bgpcep.git] / bmp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / StatisticsReportHandlerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bmp.parser.message;
9
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;
13
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;
20
21 public class StatisticsReportHandlerTest extends AbstractBmpMessageTest {
22
23     private static final byte[] STATS_REPORT = {
24         /*
25          * 03 <- bmp version
26          * 00 00 00 c2 <- total length of stats message + common header lenght
27          * 01 <- bmp message type - statistcs report
28          *
29          * 00 <- global type
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
39          *
40          * 00 00 00 0E <- TLVs count
41          * 00 00 - rejected prefix type
42          * 00 04 - length
43          * 00 00 00 08 - value
44          * 00 01 <- duplicate prefix adv type
45          * 00 04 <- length
46          * 00 00 00 10 - value
47          * 00 02 <- duplicate withdraws type
48          * 00 04 <- length
49          * 00 00 00 0B <- value
50          * 00 03 <- invalidate cluster type
51          * 00 04 <- legnth
52          * 00 00 00 53 <- value
53          * 00 04 <- as path type
54          * 00 04 <- length
55          * 00 00 00 66 <- value
56          * 00 05 <- invalidate originator id type
57          * 00 04 <- length
58          * 00 00 00 70 <- value
59          * 00 06 <- invalidate as confed type
60          * 00 04 <- length
61          * 00 00 00 55 <- value
62          * 00 07 <- adj ribs in routes type
63          * 00 08 <- length
64          * 00 00 00 00 00 00 00 10
65          * 00 08 <- loc rib routes type
66          * 00 08 <- length
67          * 00 00 00 00 00 00 00 64 <- value
68          * 00 09 <- per afi safi adj rib routes type
69          * 00 0B <- length
70          * 00 01 <- afi
71          * 01    <- safi
72          * 00 00 00 00 00 00 00 09 <- value
73          * 00 0A <- per afi safi local rib type
74          * 00 0B <- length
75          * 00 01 <- afi
76          * 01    <- safi
77          * 00 00 00 00 00 00 00 0A <- value
78          * 00 0B <- updates treated as withdraw
79          * 00 04 <- length
80          * 00 00 00 0B  <- value
81          * 00 0C <- prefixes treated as withdraw
82          * 00 04 <- length
83          * 00 00 00 0C  <- value
84          * 00 0D <- duplicate updates
85          * 00 04 <- length
86          * 00 00 00 0D  <- value
87          */
88
89         (byte) 0x03,
90         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBA,
91         (byte) 0x01,
92
93         (byte) 0x00,
94         (byte) 0x00,
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
104
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,
120         (byte) 0x64,
121
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
143     };
144
145     @Test
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));
150     }
151
152     @Test
153     public void testParseStatsReportMessage() throws BmpDeserializationException {
154         final StatsReportsMessage parsedStatsReportsMsg = (StatsReportsMessage) getBmpMessageRegistry()
155                 .parseMessage(Unpooled.copiedBuffer(STATS_REPORT));
156         assertEquals(createStatsReportMsg(), parsedStatsReportsMsg);
157     }
158 }