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) 0x18,
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,
33 (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x06,
34 (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x07};
37 public void testCommunitiesAttributeParser() throws Exception {
38 final List<Communities> comms = Lists.newArrayList();
39 comms.add((Communities) CommunityUtil.NO_EXPORT);
40 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
41 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
42 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
43 comms.add((Communities) CommunityUtil.LLGR_STALE);
44 comms.add((Communities) CommunityUtil.NO_LLGR);
46 final AttributesBuilder paBuilder = new AttributesBuilder();
47 paBuilder.setCommunities(comms);
49 final ByteBuf actual = Unpooled.buffer();
50 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
51 .serializeAttribute(paBuilder.build(), actual);
52 assertArrayEquals(CommunitiesBytes, ByteArray.getAllBytes(actual));
53 final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
54 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
55 assertEquals(comms, attributeOut.getCommunities());
59 public void testParseEmptyListAttribute() {
60 final List<Communities> comms = Lists.newArrayList();
61 final ByteBuf actual = Unpooled.buffer();
62 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
63 .serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
64 assertEquals(Unpooled.buffer(), actual);
68 public void testParseEmptyAttribute() {
69 final ByteBuf actual = Unpooled.buffer();
70 ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
71 .serializeAttribute(new AttributesBuilder().build(), actual);
72 assertEquals(Unpooled.buffer(), actual);