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
8 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
15 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ShortAsNumber;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.AsSpecificExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.AsSpecificExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder;
21 import org.opendaylight.yangtools.yang.common.Uint32;
23 public class AsTwoOctetSpecificEcHandlerTest {
25 private static final byte[] INPUT = {
30 public void testHandler() throws BGPDocumentedException, BGPParsingException {
31 final AsTwoOctetSpecificEcHandler handler = new AsTwoOctetSpecificEcHandler();
32 final AsSpecificExtendedCommunityCase expected = new AsSpecificExtendedCommunityCaseBuilder()
33 .setAsSpecificExtendedCommunity(new AsSpecificExtendedCommunityBuilder()
34 .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(54)))
35 .setLocalAdministrator(new byte[] { 0, 0, 1, 76 }).build())
38 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
39 Assert.assertEquals(expected, exComm);
41 final ByteBuf output = Unpooled.buffer(INPUT.length);
42 handler.serializeExtendedCommunity(expected, output);
43 Assert.assertArrayEquals(INPUT, output.array());