MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / Ipv4SpecificEcHandlerTest.java
1 /*
2  * Copyright (c) 2015 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
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.Assert;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
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 Ipv4SpecificEcHandlerTest {
26
27     private static final byte[] INPUT = {
28             12, 51, 2, 5, 21, 45
29     };
30
31     @Test
32     public void testHandlerDeprecated() {
33         final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
34         final Inet4SpecificExtendedCommunityCase input
35                 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
36                 new Inet4SpecificExtendedCommunityBuilder()
37                         .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
38                         .setLocalAdministrator(new byte[]{21, 45}).build()).build();
39
40         final Inet4SpecificExtendedCommunityCase expected
41                 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
42                 new Inet4SpecificExtendedCommunityBuilder()
43                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
44                                 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
45                                 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
46                 .build();
47         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
48         assertEquals(expected, exComm);
49
50         final ByteBuf output = Unpooled.buffer(INPUT.length);
51         handler.serializeExtendedCommunity(input, output);
52         assertArrayEquals(INPUT, output.array());
53     }
54
55     @Test
56     public void testHandle() {
57         final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
58         final Inet4SpecificExtendedCommunityCase expected
59                 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
60                 new Inet4SpecificExtendedCommunityBuilder()
61                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
62                                 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
63                                 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
64                 .build();
65
66         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
67         assertEquals(expected, exComm);
68
69         final ByteBuf output = Unpooled.buffer(INPUT.length);
70         handler.serializeExtendedCommunity(expected, output);
71         assertArrayEquals(INPUT, output.array());
72     }
73
74 }