d9929fe31677f24f6d556db33778e8540fa7bb88
[bgpcep.git] / bgp / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / ESImpRouteTargetExtComTest.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 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC;
14
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
20 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
21 import org.opendaylight.protocol.util.ByteArray;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.es._import.route.extended.community.EsImportRouteExtendedCommunityBuilder;
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.EsImportRouteExtendedCommunityCase;
25 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.EsImportRouteExtendedCommunityCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
27
28 public class ESImpRouteTargetExtComTest {
29     private static final byte[] RESULT = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7};
30     private ESImpRouteTargetExtCom parser;
31
32     @Before
33     public void setUp() {
34         this.parser = new ESImpRouteTargetExtCom();
35     }
36
37     @Test
38     public void parserTest() throws BGPParsingException, BGPDocumentedException {
39         final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
40
41         final EsImportRouteExtendedCommunityCase expected = new EsImportRouteExtendedCommunityCaseBuilder()
42                 .setEsImportRouteExtendedCommunity(
43                         new EsImportRouteExtendedCommunityBuilder().setEsImport(MAC).build()).build();
44         this.parser.serializeExtendedCommunity(expected, buff);
45         assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
46
47         final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
48         assertEquals(expected, result);
49     }
50
51     @Test(expected = IllegalArgumentException.class)
52     public void wrongCaseTest() {
53         this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
54     }
55
56     @Test
57     public void testSubtype() {
58         assertEquals(2, this.parser.getSubType());
59     }
60 }