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.rev200120.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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.rev200120.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 = new Inet4SpecificExtendedCommunityCaseBuilder()
33 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
34 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
35 .setLocalAdministrator(new byte[]{21, 45}).build()).build();
37 final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder()
38 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
39 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
40 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
41 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
43 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
44 assertEquals(expected, exComm);
46 final ByteBuf output = Unpooled.buffer(INPUT.length);
47 handler.serializeExtendedCommunity(input, output);
48 assertArrayEquals(INPUT, output.array());
52 public void testHandle() {
53 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
54 final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder()
55 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
56 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
57 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
58 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
61 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
62 assertEquals(expected, exComm);
64 final ByteBuf output = Unpooled.buffer(INPUT.length);
65 handler.serializeExtendedCommunity(expected, output);
66 assertArrayEquals(INPUT, output.array());