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.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertThat;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.net.UnknownHostException;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
23 import org.opendaylight.protocol.bgp.parser.BGPError;
24 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
25 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
27 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
28 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
29 import org.opendaylight.protocol.util.ByteArray;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Keepalive;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.KeepaliveBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Notify;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.ProtocolVersion;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.RouteRefresh;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.RouteRefreshBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
43 import org.opendaylight.yangtools.yang.binding.Notification;
45 public class ParserTest {
47 private static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
48 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
49 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04,
50 (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14,
53 private static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
54 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
55 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
57 private static final byte[] notificationBMsg = new byte[] { (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) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02,
60 (byte) 0x04, (byte) 0x04, (byte) 0x09 };
62 private static final byte[] updMsgWithUnrecognizedAttribute = new byte[] {
63 (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) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x79, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
66 (byte) 0x62, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x34, (byte) 0x40, (byte) 0x04, (byte) 0x47,
67 (byte) 0x04, (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b, (byte) 0x00, (byte) 0x00, (byte) 0x01,
68 (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
69 (byte) 0x00, (byte)0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02,
70 (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02,
71 (byte)0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
72 (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)0x00,
73 (byte) 0x43, (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00,
74 (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)0x64, (byte) 0x00,
75 (byte) 0x63, (byte) 0x19, (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x4f, (byte) 0x66,
76 (byte) 0x2d, (byte) 0x39, (byte) 0x6b, (byte) 0x2d, (byte) 0x30, (byte)0x33, (byte) 0x04, (byte) 0x03,
77 (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2b,
78 (byte) 0x2b, (byte) 0x2b, (byte) 0x2b
81 // Update message with one IPv4 prefix NLRI and all mandatory path attributes present
82 private static final byte[] updMsgWithMandatoryAttributesPresent = new byte[] {
83 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
84 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
85 (byte) 0x00, (byte) 0x38, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1c, (byte) 0x40,
86 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03,
87 (byte) 0x04, (byte) 0x0a, (byte) 0x12, (byte) 0xa2, (byte) 0xf1, (byte) 0x80, (byte) 0x04, (byte) 0x04,
88 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00,
89 (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20, (byte) 0xc0, (byte) 0xa8, (byte) 0xfe, (byte) 0x03
92 // Update message with one IPv4 prefix NLRI and all mandatory path attributes except ORIGIN present
93 private static final byte[] updMsgWithOneMandatoryAttributeNotPresent = new byte[] {
94 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
95 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
96 (byte) 0x00, (byte) 0x34, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x18, (byte) 0x40,
97 (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x04, (byte) 0x0a, (byte) 0x12, (byte) 0xa2,
98 (byte) 0xf1, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
99 (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20,
100 (byte) 0xc0, (byte) 0xa8, (byte) 0xfe, (byte) 0x03
103 // Update message with one IPv4 prefix NLRI and ORIGIN, AS_PATH and NEXT_HOP mandatory path attributes not present
104 private static final byte[] updMsgWithMultipleMandatoryAttributesNotPresent = new byte[] {
105 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
106 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
107 (byte) 0x00, (byte) 0x2a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0e, (byte) 0x80,
108 (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x05,
109 (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x20, (byte) 0xc0, (byte) 0xa8,
110 (byte) 0xfe, (byte) 0x03
113 private static final byte[] RR_MSG = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
114 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
115 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x05, (byte) 0x00, (byte) 0x01,
116 (byte) 0x00, (byte) 0x01 };
118 private static MessageRegistry reg;
121 public static void setupClass() throws Exception {
122 reg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
126 public void testHeaderErrors() throws BGPParsingException, BGPDocumentedException {
127 byte[] wrong = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
128 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
129 (byte) 0xff, (byte) 0xff, (byte) 0x00 };
130 wrong = ByteArray.cutBytes(wrong, 16);
132 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(wrong), null);
133 fail("Exception should have occcured.");
134 } catch (final IllegalArgumentException e) {
135 assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.",
143 public void testBadMsgType() throws BGPParsingException {
144 final byte[] bytes = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
145 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
146 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x08 };
148 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
149 fail("Exception should have occured.");
150 } catch (final BGPDocumentedException e) {
151 assertEquals(BGPError.BAD_MSG_TYPE, e.getError());
158 public void testKeepAliveMsg() throws BGPParsingException, BGPDocumentedException {
159 final Notification keepAlive = new KeepaliveBuilder().build();
160 final ByteBuf buffer = Unpooled.buffer();
161 ParserTest.reg.serializeMessage(keepAlive, buffer);
162 assertArrayEquals(keepAliveBMsg, ByteArray.getAllBytes(buffer));
164 final Notification m = ParserTest.reg.parseMessage(Unpooled.
165 copiedBuffer(ByteArray.getAllBytes(buffer)), null);
167 assertTrue(m instanceof Keepalive);
171 public void testBadKeepAliveMsg() throws BGPParsingException {
172 final byte[] bytes = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
173 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
174 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
177 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
178 fail("Exception should have occured.");
179 } catch (final BGPDocumentedException e) {
180 assertThat(e.getMessage(), containsString("Message length field not within valid range."));
181 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
188 public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
189 final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180)
190 .setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
191 new ProtocolVersion((short) 4)).build();
192 final ByteBuf bytes = Unpooled.buffer();
193 ParserTest.reg.serializeMessage(open, bytes);
194 assertArrayEquals(openBMsg, ByteArray.getAllBytes(bytes));
196 final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
198 assertTrue(m instanceof Open);
199 assertEquals(100, ((Open) m).getMyAsNumber().intValue());
200 assertEquals(180, ((Open) m).getHoldTimer().intValue());
201 assertEquals(new Ipv4Address("20.20.20.20"), ((Open) m).getBgpIdentifier());
202 assertTrue(((Open) m).getBgpParameters().isEmpty());
206 public void testBadHoldTimeError() throws BGPParsingException {
207 final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
208 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
209 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64,
210 (byte) 0x00, (byte) 0x01, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
213 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
214 fail("Exception should have occured.");
215 } catch (final BGPDocumentedException e) {
216 assertEquals("Hold time value not acceptable.", e.getMessage());
217 assertEquals(BGPError.HOLD_TIME_NOT_ACC, e.getError());
224 public void testBadMsgLength() throws BGPParsingException {
225 final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
226 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
227 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64,
228 (byte) 0x00, (byte) 0xb4, (byte) 0xff, (byte) 0xff, (byte) 0xff };
231 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
232 fail("Exception should have occured.");
233 } catch (final BGPDocumentedException e) {
234 assertEquals("Open message too small.", e.getMessage());
235 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
240 public void testBadVersion() throws BGPParsingException {
241 final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
242 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
243 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x64,
244 (byte) 0x00, (byte) 0xb4, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
247 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
248 fail("Exception should have occured.");
249 } catch (final BGPDocumentedException e) {
250 assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
251 assertEquals(BGPError.VERSION_NOT_SUPPORTED, e.getError());
258 public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
259 Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
260 .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
261 final ByteBuf bytes = Unpooled.buffer();
262 ParserTest.reg.serializeMessage(notMsg, bytes);
263 assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(),0,bytes.writerIndex()));
265 Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
267 assertTrue(m instanceof Notify);
268 assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(),
269 ((Notify) m).getErrorSubcode()));
270 assertArrayEquals(new byte[] { 4, 9 }, ((Notify) m).getData());
272 notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
273 BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
277 ParserTest.reg.serializeMessage(notMsg, bytes);
279 m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
281 assertTrue(m instanceof Notify);
282 assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(),
283 ((Notify) m).getErrorSubcode()));
284 assertNull(((Notify) m).getData());
288 public void testWrongLength() throws BGPParsingException {
289 final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
290 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
291 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
294 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
295 fail("Exception should have occured.");
296 } catch (final BGPDocumentedException e) {
297 assertEquals("Notification message too small.", e.getMessage());
298 assertEquals(BGPError.BAD_MSG_LENGTH, e.getError());
305 public void testUnrecognizedError() throws BGPParsingException, BGPDocumentedException {
306 final byte[] bMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
307 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
308 (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
311 ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bMsg), null);
312 fail("Exception should have occured.");
313 } catch (final IllegalArgumentException e) {
314 assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
321 public void testParseUpdMsgWithUnrecognizedAttribute() throws BGPDocumentedException, BGPParsingException {
323 reg.parseMessage(Unpooled.copiedBuffer(updMsgWithUnrecognizedAttribute), null);
324 fail("Exception should have occured.");
325 } catch (final BGPDocumentedException e) {
326 assertEquals("Well known attribute not recognized.", e.getMessage());
327 assertEquals(BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED, e.getError());
334 public void testParseUpdMsgWithMandatoryAttributesPresent() throws BGPDocumentedException, BGPParsingException {
336 final Notification msg = reg.parseMessage(Unpooled.copiedBuffer(updMsgWithMandatoryAttributesPresent),
338 assertTrue(msg instanceof Update);
339 } catch (final BGPDocumentedException e) {
340 fail("Exception should not have occured.");
345 public void testParseUpdMsgWithOneMandatoryAttributeNotPresent()
346 throws BGPDocumentedException, BGPParsingException {
348 reg.parseMessage(Unpooled.copiedBuffer(updMsgWithOneMandatoryAttributeNotPresent), null);
349 fail("Exception should have occured.");
350 } catch (final BGPDocumentedException e) {
351 assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "ORIGIN", e.getMessage());
352 assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING, e.getError());
353 assertArrayEquals(new byte[] { OriginAttributeParser.TYPE }, e.getData());
360 public void testParseUpdMsgWithMultipleMandatoryAttributesNotPresent()
361 throws BGPDocumentedException, BGPParsingException {
363 reg.parseMessage(Unpooled.copiedBuffer(updMsgWithMultipleMandatoryAttributesNotPresent), null);
364 fail("Exception should have occured.");
365 } catch (final BGPDocumentedException e) {
366 assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "NEXT_HOP", e.getMessage());
367 assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING, e.getError());
368 assertArrayEquals(new byte[] { NextHopAttributeParser.TYPE }, e.getData());
375 public void testRouteRefreshMsg() throws BGPDocumentedException, BGPParsingException {
376 final Notification rrMsg = new RouteRefreshBuilder().setAfi(Ipv4AddressFamily.class)
377 .setSafi(UnicastSubsequentAddressFamily.class).build();
378 final ByteBuf buffer = Unpooled.buffer();
379 ParserTest.reg.serializeMessage(rrMsg, buffer);
380 assertArrayEquals(RR_MSG, ByteArray.getAllBytes(buffer));
382 final Notification m = ParserTest.reg.parseMessage(
383 Unpooled.copiedBuffer(ByteArray.getAllBytes(buffer)), null);
385 assertTrue(m instanceof RouteRefresh);