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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
14 import java.util.List;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.concepts.BGPObject;
20 import org.opendaylight.protocol.bgp.parser.BGPNode;
21 import org.opendaylight.protocol.bgp.parser.BGPUpdateEvent;
22 import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
23 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
24 import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
25 import org.opendaylight.protocol.util.ByteArray;
27 public class BGPUpdateMessageParserTest {
31 public void testNodeParsing() throws Exception {
32 final List<byte[]> result = HexDumpBGPFileParser.parseMessages(new File(this.getClass().getResource("/bgp-update-nodes.txt").getFile()));
33 assertEquals(1, result.size());
34 final byte[] body = ByteArray.cutBytes(result.get(0), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
35 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(result.get(0), BGPMessageFactoryImpl.MARKER_LENGTH,
36 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
37 final BGPUpdateEvent event = BGPUpdateMessageParser.parse(body, messageLength);
38 final BGPUpdateMessage updateMessage = (BGPUpdateMessage) event;
39 final Set<BGPObject> addedObjects = updateMessage.getAddedObjects();
40 assertEquals(14, addedObjects.size());
41 assertEquals(0, updateMessage.getRemovedObjects().size());
42 for (final BGPObject bgpObject : addedObjects) {
43 assertTrue(bgpObject instanceof BGPNode);