2 * Copyright (c) 2016 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.evpn.impl.extended.communities;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
19 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
20 import org.opendaylight.protocol.util.ByteArray;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213._default.gateway.extended.community.DefaultGatewayExtendedCommunityBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
27 public class DefaultGatewayExtComTest {
28 private static final byte[] RESULT = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
29 private DefaultGatewayExtCom parser;
33 this.parser = new DefaultGatewayExtCom();
37 public void parserTest() throws BGPParsingException, BGPDocumentedException {
38 final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
40 final DefaultGatewayExtendedCommunityCase expected = new DefaultGatewayExtendedCommunityCaseBuilder()
41 .setDefaultGatewayExtendedCommunity(
42 new DefaultGatewayExtendedCommunityBuilder().build()).build();
43 this.parser.serializeExtendedCommunity(expected, buff);
44 assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
46 final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
47 assertEquals(expected, result);
50 @Test(expected = IllegalArgumentException.class)
51 public void wrongCaseTest() {
52 this.parser.serializeExtendedCommunity(new EsiLabelExtendedCommunityCaseBuilder().build(), null);
55 @Test(expected = IllegalArgumentException.class)
56 public void wrongSizeTest() throws BGPParsingException, BGPDocumentedException {
57 this.parser.parseExtendedCommunity(Unpooled.buffer(8));
61 public void testSubtype() {
62 assertEquals(13, this.parser.getSubType());