2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
20 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;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
23 public class Ipv4SpecificEcHandlerTest {
25 private static final byte[] INPUT = {
30 public void testHandlerDeprecated() {
31 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
32 final Inet4SpecificExtendedCommunityCase input
33 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
34 new Inet4SpecificExtendedCommunityBuilder()
35 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
36 .setLocalAdministrator(new byte[]{21, 45}).build()).build();
38 final Inet4SpecificExtendedCommunityCase expected
39 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
40 new Inet4SpecificExtendedCommunityBuilder()
41 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
42 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
43 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
45 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
46 assertEquals(expected, exComm);
48 final ByteBuf output = Unpooled.buffer(INPUT.length);
49 handler.serializeExtendedCommunity(input, output);
50 assertArrayEquals(INPUT, output.array());
54 public void testHandle() {
55 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
56 final Inet4SpecificExtendedCommunityCase expected
57 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
58 new Inet4SpecificExtendedCommunityBuilder()
59 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
60 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
61 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
64 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
65 assertEquals(expected, exComm);
67 final ByteBuf output = Unpooled.buffer(INPUT.length);
68 handler.serializeExtendedCommunity(expected, output);
69 assertArrayEquals(INPUT, output.array());