2 * Copyright (c) 2013 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.bgp.parser.impl;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertArrayEquals;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import java.net.UnknownHostException;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
24 import org.opendaylight.protocol.bgp.parser.BGPError;
25 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
28 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
29 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
30 import org.opendaylight.protocol.util.ByteArray;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Keepalive;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.KeepaliveBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Notify;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.ProtocolVersion;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.RouteRefresh;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.RouteRefreshBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
44 import org.opendaylight.yangtools.yang.binding.Notification;
45 import org.opendaylight.yangtools.yang.common.Uint16;
46 import org.opendaylight.yangtools.yang.common.Uint8;
48 public class ParserTest {
49 private static final byte[] OPEN_BMSG = new byte[] {
50 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
51 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
52 (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
53 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
56 private static final byte[] KEEPALIVE_BMSG = new byte[] {
57 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
58 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
59 (byte) 0x00, (byte) 0x13, (byte) 0x04
62 private static final byte[] NOTIFICATION_BMSG = new byte[] {
63 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
64 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
65 (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09
68 private static final byte[] UPD_MSG_WITH_UNRECOGNIZED_ATTRIBUTE = new byte[] {
69 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
70 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
71 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x79, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
72 (byte) 0x62, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x34, (byte) 0x40, (byte) 0x04, (byte) 0x47,
73 (byte) 0x04, (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b, (byte) 0x00, (byte) 0x00, (byte) 0x01,
74 (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
75 (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02,
76 (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02,
77 (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
78 (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
79 (byte) 0x43, (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00,
80 (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte )0x64, (byte) 0x00,
81 (byte) 0x63, (byte) 0x19, (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x4f, (byte) 0x66,
82 (byte) 0x2d, (byte) 0x39, (byte) 0x6b, (byte) 0x2d, (byte) 0x30, (byte) 0x33, (byte) 0x04, (byte) 0x03,
83 (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2b,
84 (byte) 0x2b, (byte) 0x2b, (byte) 0x2b
87 // Update message with one IPv4 prefix NLRI and all mandatory path attributes present
88 private static final byte[] UPD_MSG_WITH_MANDATORY_ATTRIBUTES_PRESENT = new byte[] {
89 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
90 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
91 (byte) 0x00, (byte) 0x38, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1c, (byte) 0x40,
92 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03,
93 (byte) 0x04, (byte) 0x0a, (byte) 0x12, (byte) 0xa2, (byte) 0xf1, (byte) 0x80, (byte) 0x04, (byte) 0x04,
94 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00,
95 (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20, (byte) 0xc0, (byte) 0xa8, (byte) 0xfe, (byte) 0x03
98 // Update message with one IPv4 prefix NLRI and all mandatory path attributes except ORIGIN present
99 private static final byte[] UPD_MSG_WITH_ONE_MANDATORY_ATTRIBUTE_NOT_PRESENT = new byte[] {
100 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
101 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
102 (byte) 0x00, (byte) 0x34, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x18, (byte) 0x40,
103 (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0x0a, (byte) 0x12, (byte) 0xa2,
104 (byte) 0xf1, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
105 (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20,
106 (byte) 0xc0, (byte) 0xa8, (byte) 0xfe, (byte) 0x03
109 // Update message with one IPv4 prefix NLRI and ORIGIN, AS_PATH and NEXT_HOP mandatory path attributes not present
110 private static final byte[] UPD_MSG_WITH_MULTIPLE_MANDATORY_ATTRIBUTES_NOT_PRESENT = new byte[] {
111 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
112 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
113 (byte) 0x00, (byte) 0x2a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0e, (byte) 0x80,
114 (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x05,
115 (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20, (byte) 0xc0, (byte) 0xa8,
116 (byte) 0xfe, (byte) 0x03
119 private static final byte[] RR_MSG = new byte[] {
120 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
121 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
122 (byte) 0x00, (byte) 0x17, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01
125 private static MessageRegistry reg;
128 public static void setupClass() throws Exception {
129 reg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
133 public void testHeaderErrors() throws BGPParsingException, BGPDocumentedException {
134 byte[] wrong = new byte[] {
135 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
136 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
139 wrong = ByteArray.cutBytes(wrong, 16);
141 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(wrong), null);
142 fail("Exception should have occcured.");
143 } catch (final IllegalArgumentException e) {
144 assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.",
152 public void testBadMsgType() throws BGPParsingException {
153 final byte[] bytes = {
154 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
155 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
156 (byte) 0x00, (byte) 0x13, (byte) 0x08
159 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
160 fail("Exception should have occured.");
161 } catch (final BGPDocumentedException e) {
162 assertEquals(BGPError.BAD_MSG_TYPE, e.getError());
169 public void testKeepAliveMsg() throws BGPParsingException, BGPDocumentedException {
170 final Notification keepAlive = new KeepaliveBuilder().build();
171 final ByteBuf buffer = Unpooled.buffer();
172 ParserTest.reg.serializeMessage(keepAlive, buffer);
173 assertArrayEquals(KEEPALIVE_BMSG, ByteArray.getAllBytes(buffer));
175 final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(ByteArray.getAllBytes(buffer)), null);
176 assertTrue(m instanceof Keepalive);
180 public void testBadKeepAliveMsg() throws BGPParsingException {
181 final byte[] bytes = new byte[] {
182 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
183 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
184 (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05
188 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
189 fail("Exception should have occured.");
190 } catch (final BGPDocumentedException e) {
191 assertThat(e.getMessage(), containsString("Message length field not within valid range."));
192 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
199 public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
200 final Notification open = new OpenBuilder()
201 .setMyAsNumber(Uint16.valueOf(100))
202 .setHoldTimer(Uint16.valueOf(180))
203 .setBgpIdentifier(new Ipv4Address("20.20.20.20"))
204 .setVersion(new ProtocolVersion(Uint8.valueOf(4)))
206 final ByteBuf bytes = Unpooled.buffer();
207 ParserTest.reg.serializeMessage(open, bytes);
208 assertArrayEquals(OPEN_BMSG, ByteArray.getAllBytes(bytes));
210 final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
211 assertTrue(m instanceof Open);
213 final Open mo = (Open) m;
214 assertEquals(100, mo.getMyAsNumber().intValue());
215 assertEquals(180, mo.getHoldTimer().intValue());
216 assertEquals(new Ipv4Address("20.20.20.20"), mo.getBgpIdentifier());
217 assertTrue(mo.getBgpParameters().isEmpty());
221 public void testBadHoldTimeError() throws BGPParsingException {
222 final byte[] bMsg = new byte[] {
223 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
224 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
225 (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0x01,
226 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
230 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
231 fail("Exception should have occured.");
232 } catch (final BGPDocumentedException e) {
233 assertEquals("Hold time value not acceptable.", e.getMessage());
234 assertEquals(BGPError.HOLD_TIME_NOT_ACC, e.getError());
241 public void testBadMsgLength() throws BGPParsingException {
242 final byte[] bMsg = new byte[] {
243 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
244 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
245 (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
246 (byte) 0xff, (byte) 0xff, (byte) 0xff
250 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
251 fail("Exception should have occured.");
252 } catch (final BGPDocumentedException e) {
253 assertEquals("Open message too small.", e.getMessage());
254 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
259 public void testBadVersion() throws BGPParsingException {
260 final byte[] bMsg = new byte[] {
261 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
262 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
263 (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
264 (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00
268 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
269 fail("Exception should have occured.");
270 } catch (final BGPDocumentedException e) {
271 assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
272 assertEquals(BGPError.VERSION_NOT_SUPPORTED, e.getError());
279 public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
280 Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
281 .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
282 final ByteBuf bytes = Unpooled.buffer();
283 ParserTest.reg.serializeMessage(notMsg, bytes);
284 assertArrayEquals(NOTIFICATION_BMSG, ByteArray.subByte(bytes.array(),0,bytes.writerIndex()));
286 Notification msg = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
288 assertTrue(msg instanceof Notify);
289 assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) msg).getErrorCode(),
290 ((Notify) msg).getErrorSubcode()));
291 assertArrayEquals(new byte[] { 4, 9 }, ((Notify) msg).getData());
293 notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
294 BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
298 ParserTest.reg.serializeMessage(notMsg, bytes);
300 msg = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
302 assertTrue(msg instanceof Notify);
303 assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) msg).getErrorCode(),
304 ((Notify) msg).getErrorSubcode()));
305 assertNull(((Notify) msg).getData());
309 public void testWrongLength() throws BGPParsingException {
310 final byte[] bMsg = new byte[] {
311 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
312 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
313 (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02
317 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
318 fail("Exception should have occured.");
319 } catch (final BGPDocumentedException e) {
320 assertEquals("Notification message too small.", e.getMessage());
321 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
328 public void testUnrecognizedError() throws BGPParsingException, BGPDocumentedException {
329 final byte[] bMsg = new byte[] {
330 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
331 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
332 (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa
336 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
337 fail("Exception should have occured.");
338 } catch (final IllegalArgumentException e) {
339 assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
346 public void testParseUpdMsgWithUnrecognizedAttribute() throws BGPDocumentedException, BGPParsingException {
348 reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_UNRECOGNIZED_ATTRIBUTE), null);
349 fail("Exception should have occured.");
350 } catch (final BGPDocumentedException e) {
351 assertEquals("Well known attribute not recognized.", e.getMessage());
352 assertEquals(BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED, e.getError());
359 public void testParseUpdMsgWithMandatoryAttributesPresent() throws BGPDocumentedException, BGPParsingException {
361 final Notification msg = reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_MANDATORY_ATTRIBUTES_PRESENT),
363 assertTrue(msg instanceof Update);
364 } catch (final BGPDocumentedException e) {
365 fail("Exception should not have occured.");
370 public void testParseUpdMsgWithOneMandatoryAttributeNotPresent()
371 throws BGPDocumentedException, BGPParsingException {
373 reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_ONE_MANDATORY_ATTRIBUTE_NOT_PRESENT), null);
374 fail("Exception should have occured.");
375 } catch (final BGPDocumentedException e) {
376 assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "ORIGIN", e.getMessage());
377 assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING, e.getError());
378 assertArrayEquals(new byte[] { OriginAttributeParser.TYPE }, e.getData());
385 public void testParseUpdMsgWithMultipleMandatoryAttributesNotPresent()
386 throws BGPDocumentedException, BGPParsingException {
388 reg.parseMessage(Unpooled.copiedBuffer(UPD_MSG_WITH_MULTIPLE_MANDATORY_ATTRIBUTES_NOT_PRESENT), null);
389 fail("Exception should have occured.");
390 } catch (final BGPDocumentedException e) {
391 assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "NEXT_HOP", e.getMessage());
392 assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING, e.getError());
393 assertArrayEquals(new byte[] { NextHopAttributeParser.TYPE }, e.getData());
400 public void testRouteRefreshMsg() throws BGPDocumentedException, BGPParsingException {
401 final Notification rrMsg = new RouteRefreshBuilder().setAfi(Ipv4AddressFamily.class)
402 .setSafi(UnicastSubsequentAddressFamily.class).build();
403 final ByteBuf buffer = Unpooled.buffer();
404 ParserTest.reg.serializeMessage(rrMsg, buffer);
405 assertArrayEquals(RR_MSG, ByteArray.getAllBytes(buffer));
407 final Notification m = ParserTest.reg.parseMessage(
408 Unpooled.copiedBuffer(ByteArray.getAllBytes(buffer)), null);
410 assertTrue(m instanceof RouteRefresh);