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
9 package org.opendaylight.protocol.bgp.parser.spi.pojo;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
15 import io.netty.buffer.Unpooled;
16 import java.util.List;
17 import org.junit.Rule;
18 import org.junit.Test;
19 import org.junit.rules.ExpectedException;
20 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
21 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
22 import org.opendaylight.protocol.util.ByteArray;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributesKey;
26 public class UnrecognizedAttributesTest {
28 private static final int UNRECOGNIZED_ATTRIBUTE_COUNT = 1;
29 private static final int FIRST_ATTRIBUTE = 0;
30 private static final short NON_EXISTENT_TYPE = 0;
31 private static final int NON_VALUE_BYTES = 3;
33 private static final SimpleAttributeRegistry simpleAttrReg = new SimpleAttributeRegistry();
36 public ExpectedException expException = ExpectedException.none();
39 public void testUnrecognizedAttributesWithoutOptionalFlag() throws BGPDocumentedException, BGPParsingException {
40 this.expException.expect(BGPDocumentedException.class);
41 this.expException.expectMessage("Well known attribute not recognized.");
42 simpleAttrReg.parseAttributes(Unpooled.wrappedBuffer(new byte[] { 0x03, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 }));
46 public void testUnrecognizedAttributes() throws BGPDocumentedException, BGPParsingException {
47 final byte[] attributeBytes = { (byte)0xe0, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 };
48 final List<UnrecognizedAttributes> unrecogAttribs = simpleAttrReg.parseAttributes(Unpooled.wrappedBuffer(attributeBytes)).getUnrecognizedAttributes();
49 assertEquals(UNRECOGNIZED_ATTRIBUTE_COUNT, unrecogAttribs.size());
50 final UnrecognizedAttributes unrecogAttrib = unrecogAttribs.get(FIRST_ATTRIBUTE);
51 final UnrecognizedAttributesKey expectedAttribKey = new UnrecognizedAttributesKey(unrecogAttrib.getType().shortValue());
53 assertTrue(unrecogAttrib.isPartial());
54 assertTrue(unrecogAttrib.isTransitive());
55 assertArrayEquals(ByteArray.cutBytes(attributeBytes, NON_VALUE_BYTES), unrecogAttrib.getValue());
56 assertEquals(NON_EXISTENT_TYPE, unrecogAttrib.getType().shortValue());
57 assertEquals(expectedAttribKey, unrecogAttrib.getKey());