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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
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.Inet4SpecificExtendedCommunityCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
21 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;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
24 public class Ipv4SpecificEcHandlerTest {
26 private static final byte[] INPUT = {
31 public void testHandlerDeprecated() {
32 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
33 final Inet4SpecificExtendedCommunityCase input
34 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
35 new Inet4SpecificExtendedCommunityBuilder()
36 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
37 .setLocalAdministrator(new byte[]{21, 45}).build()).build();
39 final Inet4SpecificExtendedCommunityCase expected
40 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
41 new Inet4SpecificExtendedCommunityBuilder()
42 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
43 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
44 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
46 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
47 assertEquals(expected, exComm);
49 final ByteBuf output = Unpooled.buffer(INPUT.length);
50 handler.serializeExtendedCommunity(input, output);
51 assertArrayEquals(INPUT, output.array());
55 public void testHandle() {
56 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
57 final Inet4SpecificExtendedCommunityCase expected
58 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
59 new Inet4SpecificExtendedCommunityBuilder()
60 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
61 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
62 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
65 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
66 assertEquals(expected, exComm);
68 final ByteBuf output = Unpooled.buffer(INPUT.length);
69 handler.serializeExtendedCommunity(expected, output);
70 assertArrayEquals(INPUT, output.array());