MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / DefaultGatewayExtComTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.evpn.impl.extended.communities;
9
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;
13
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.rev180329._default.gateway.extended.community.DefaultGatewayExtendedCommunityBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.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.rev180329.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.rev180329.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.rev180329.extended.community.ExtendedCommunity;
26
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;
30
31     @Before
32     public void setUp() {
33         this.parser = new DefaultGatewayExtCom();
34     }
35
36     @Test
37     public void parserTest() throws BGPParsingException, BGPDocumentedException {
38         final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
39
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));
45
46         final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
47         assertEquals(expected, result);
48     }
49
50     @Test(expected = IllegalArgumentException.class)
51     public void wrongCaseTest() {
52         this.parser.serializeExtendedCommunity(new EsiLabelExtendedCommunityCaseBuilder().build(), null);
53     }
54
55     @Test(expected = IllegalArgumentException.class)
56     public void wrongSizeTest() throws BGPParsingException, BGPDocumentedException {
57         this.parser.parseExtendedCommunity(Unpooled.buffer(8));
58     }
59
60     @Test
61     public void testSubtype() {
62         assertEquals(13, this.parser.getSubType());
63     }
64 }