/* * Copyright (c) 2016 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 static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.util.ByteArray; 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.Inet4SpecificExtendedCommunityCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.LinkBandwidthCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.LinkBandwidthCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth; public class LinkBandwidthECTest { private static final byte[] RESULT = {(byte) 0x5b, (byte) 0xa0, 0x00, 0x00, (byte) 0xff, (byte) 0xff}; private static final int COMMUNITY_VALUE_SIZE = 6; private LinkBandwidthEC parser; @Before public void setUp() { this.parser = new LinkBandwidthEC(); } @Test public void parserTest() throws BGPParsingException, BGPDocumentedException { final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE); final LinkBandwidthCase expected = new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity( new LinkBandwidthExtendedCommunityBuilder() .setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff})) .build()).build(); this.parser.serializeExtendedCommunity(expected, buff); assertArrayEquals(RESULT, ByteArray.getAllBytes(buff)); final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT)); assertEquals(expected, result); } @Test(expected = IllegalArgumentException.class) public void wrongCaseTest() { this.parser.serializeExtendedCommunity(new Inet4SpecificExtendedCommunityCaseBuilder().build(), null); } @Test public void testSubtype() { assertEquals(4, this.parser.getSubType()); } }