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 {
28 private static final byte[] CommunitiesBytes = {(byte) 0xC0, (byte) 0x08, (byte) 0x10,
29 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x1,
30 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x2,
31 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x3,
32 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x10};
35 public void testCommunitiesAttributeParser() throws Exception {
36 final List<Communities> comms = Lists.newArrayList();
37 comms.add((Communities) CommunityUtil.NO_EXPORT);
38 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
39 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
40 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
42 final AttributesBuilder paBuilder = new AttributesBuilder();
43 paBuilder.setCommunities(comms);
45 final ByteBuf actual = Unpooled.buffer();
46 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
47 .serializeAttribute(paBuilder.build(), actual);
48 assertArrayEquals(CommunitiesBytes, ByteArray.getAllBytes(actual));
49 final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
50 .getAttributeRegistry().parseAttributes(actual, null);
51 assertEquals(comms, attributeOut.getCommunities());
55 public void testParseEmptyListAttribute() {
56 final List<Communities> comms = Lists.newArrayList();
57 final ByteBuf actual = Unpooled.buffer();
58 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
59 .serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
60 assertEquals(Unpooled.buffer(), actual);
64 public void testParseEmptyAttribute() {
65 final ByteBuf actual = Unpooled.buffer();
66 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
67 .serializeAttribute(new AttributesBuilder().build(), actual);
68 assertEquals(Unpooled.buffer(), actual);