/* * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.bgp.evpn.impl.esi.types; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC; import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC_MODEL; import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VALUE_SIZE; import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder; import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder; import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.BRIDGE_MAC_NID; import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.RBP_NID; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.ArbitraryCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.LanAutoGeneratedCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.LanAutoGeneratedCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.lan.auto.generated._case.LanAutoGenerated; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.lan.auto.generated._case.LanAutoGeneratedBuilder; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; public class LanParserTest { private static final Uint16 PRIORITY = Uint16.valueOf(514); public static final LanAutoGeneratedCase LAN_AUT_GEN_CASE = new LanAutoGeneratedCaseBuilder() .setLanAutoGenerated(new LanAutoGeneratedBuilder() .setRootBridgeMacAddress(MAC).setRootBridgePriority(PRIORITY).build()).build(); private static final byte[] VALUE = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00}; private static final byte[] RESULT = {(byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00}; private LanParser parser; @Before public void setUp() { this.parser = new LanParser(); } @Test public void parserTest() { final ByteBuf buff = Unpooled.buffer(VALUE_SIZE); this.parser.serializeEsi(LAN_AUT_GEN_CASE, buff); assertArrayEquals(RESULT, ByteArray.getAllBytes(buff)); final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE)); assertEquals(LAN_AUT_GEN_CASE, acResult); final Esi acmResult = this.parser.serializeEsi(createLanCont()); assertEquals(LAN_AUT_GEN_CASE, acmResult); } @Test(expected = IllegalArgumentException.class) public void wrongCaseTest() { this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null); } public static ChoiceNode createLanChoice() { final DataContainerNodeBuilder choice = Builders.choiceBuilder(); choice.withNodeIdentifier(NodeIdentifier.create(Esi.QNAME)); return choice.addChild(createLanCont()).build(); } private static ContainerNode createLanCont() { return createContBuilder(new NodeIdentifier(LanAutoGenerated.QNAME)) .addChild(createValueBuilder(MAC_MODEL, BRIDGE_MAC_NID).build()) .addChild(createValueBuilder(PRIORITY, RBP_NID).build()).build(); } }