MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / VrfRouteImportHandlerTest.java
1 /*
2  *  Copyright (c) 2018 AT&T Intellectual Property. 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.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
24
25 public class VrfRouteImportHandlerTest {
26
27     private static final byte[] INPUT = {
28             12, 51, 2, 5, 21, 45
29     };
30     private final VrfRouteImportHandler handler = new VrfRouteImportHandler();
31
32     @Test
33     public void testHandler() {
34         final VrfRouteImportExtendedCommunityCase expected = new VrfRouteImportExtendedCommunityCaseBuilder()
35                 .setVrfRouteImportExtendedCommunity(new VrfRouteImportExtendedCommunityBuilder()
36                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
37                                 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
38                                 .setLocalAdministrator(new byte[]{21, 45}).build())
39                         .build())
40                 .build();
41
42         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
43         Assert.assertEquals(expected, exComm);
44
45         final ByteBuf output = Unpooled.buffer(INPUT.length);
46         handler.serializeExtendedCommunity(expected, output);
47         Assert.assertArrayEquals(INPUT, output.array());
48
49         assertEquals(11, this.handler.getSubType());
50     }
51
52     @Test(expected = IllegalArgumentException.class)
53     public void testHandlerError() {
54         this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
55     }
56 }