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.impl.message.update;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import com.google.common.collect.Lists;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
20 import org.opendaylight.protocol.util.ByteArray;
21 import org.opendaylight.protocol.util.NoopReferenceCache;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Communities;
26 public class CommunitiesAttributeParserTest {
27 private static final byte[] COMMUNITIES_BYTES = {
28 (byte) 0xC0, (byte) 0x08, (byte) 0x18,
29 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01,
30 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x02,
31 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x03,
32 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x10,
33 (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x06,
34 (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x07
38 public void testCommunitiesAttributeParser() throws Exception {
39 final List<Communities> comms = Lists.newArrayList();
40 comms.add((Communities) CommunityUtil.NO_EXPORT);
41 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
42 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
43 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
44 comms.add((Communities) CommunityUtil.LLGR_STALE);
45 comms.add((Communities) CommunityUtil.NO_LLGR);
47 final AttributesBuilder paBuilder = new AttributesBuilder();
48 paBuilder.setCommunities(comms);
50 final ByteBuf actual = Unpooled.buffer();
51 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
52 .serializeAttribute(paBuilder.build(), actual);
53 assertArrayEquals(COMMUNITIES_BYTES, ByteArray.getAllBytes(actual));
54 final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
55 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
56 assertEquals(comms, attributeOut.getCommunities());
60 public void testParseEmptyListAttribute() {
61 final List<Communities> comms = Lists.newArrayList();
62 final ByteBuf actual = Unpooled.buffer();
63 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
64 .serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
65 assertEquals(Unpooled.buffer(), actual);
69 public void testParseEmptyAttribute() {
70 final ByteBuf actual = Unpooled.buffer();
71 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
72 .serializeAttribute(new AttributesBuilder().build(), actual);
73 assertEquals(Unpooled.buffer(), actual);