/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.junit.Assert; import org.junit.Test; import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.AsSpecificExtendedCommunityCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.AsSpecificExtendedCommunityCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder; import org.opendaylight.yangtools.yang.common.Uint32; public class AsTwoOctetSpecificEcHandlerTest { private static final byte[] INPUT = { 0, 54, 0, 0, 1, 76 }; @Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final AsTwoOctetSpecificEcHandler handler = new AsTwoOctetSpecificEcHandler(); final AsSpecificExtendedCommunityCase expected = new AsSpecificExtendedCommunityCaseBuilder() .setAsSpecificExtendedCommunity(new AsSpecificExtendedCommunityBuilder() .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(54))) .setLocalAdministrator(new byte[] { 0, 0, 1, 76 }).build()) .build(); final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); } }