MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / EncapsulationECTest.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
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.types.rev180329.EncapsulationTunnelType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.EncapsulationCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.EncapsulationCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.LinkBandwidthCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.encapsulation._case.EncapsulationExtendedCommunityBuilder;
27
28 public class EncapsulationECTest {
29     private static final byte[] RESULT = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a };
30     private static final int COMMUNITY_VALUE_SIZE = 6;
31     private static final EncapsulationTunnelType TUNNEL_TYPE = EncapsulationTunnelType.Mpls;
32     private EncapsulationEC parser;
33
34     @Before
35     public void setUp() {
36         this.parser = new EncapsulationEC();
37     }
38
39     @Test
40     public void testParser() throws BGPParsingException, BGPDocumentedException {
41         final ByteBuf buffer = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
42
43         final EncapsulationCase expected = new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(new EncapsulationExtendedCommunityBuilder()
44             .setTunnelType(TUNNEL_TYPE)
45             .build()).build();
46         this.parser.serializeExtendedCommunity(expected, buffer);
47         assertArrayEquals(RESULT, ByteArray.getAllBytes(buffer));
48
49         final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
50         assertEquals(expected, result);
51     }
52
53     @Test(expected = IllegalArgumentException.class)
54     public void testWrongCase() {
55         this.parser.serializeExtendedCommunity(new LinkBandwidthCaseBuilder().build(), null);
56     }
57
58     @Test
59     public void testSubtype() {
60         assertEquals(EncapsulationEC.SUBTYPE, this.parser.getSubType());
61     }
62 }