2 * Copyright (c) 2016 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.evpn.impl.esi.types;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC_MODEL;
14 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VALUE_SIZE;
15 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder;
16 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
17 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.BRIDGE_MAC_NID;
18 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.RBP_NID;
20 import io.netty.buffer.ByteBuf;
21 import io.netty.buffer.Unpooled;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.protocol.util.ByteArray;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.ArbitraryCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.LanAutoGeneratedCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.LanAutoGeneratedCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.lan.auto.generated._case.LanAutoGenerated;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.lan.auto.generated._case.LanAutoGeneratedBuilder;
31 import org.opendaylight.yangtools.yang.common.Uint16;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
35 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
36 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
38 public class LanParserTest {
39 private static final Uint16 PRIORITY = Uint16.valueOf(514);
40 public static final LanAutoGeneratedCase LAN_AUT_GEN_CASE = new LanAutoGeneratedCaseBuilder()
41 .setLanAutoGenerated(new LanAutoGeneratedBuilder()
42 .setRootBridgeMacAddress(MAC).setRootBridgePriority(PRIORITY).build()).build();
43 private static final byte[] VALUE = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7,
44 (byte) 0x02, (byte) 0x02, (byte) 0x00};
45 private static final byte[] RESULT = {(byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f,
46 (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00};
47 private LanParser parser;
51 this.parser = new LanParser();
55 public void parserTest() {
56 final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
57 this.parser.serializeEsi(LAN_AUT_GEN_CASE, buff);
58 assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
60 final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
61 assertEquals(LAN_AUT_GEN_CASE, acResult);
63 final Esi acmResult = this.parser.serializeEsi(createLanCont());
64 assertEquals(LAN_AUT_GEN_CASE, acmResult);
67 @Test(expected = IllegalArgumentException.class)
68 public void wrongCaseTest() {
69 this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
72 public static ChoiceNode createLanChoice() {
73 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
74 choice.withNodeIdentifier(NodeIdentifier.create(Esi.QNAME));
75 return choice.addChild(createLanCont()).build();
78 private static ContainerNode createLanCont() {
79 return createContBuilder(new NodeIdentifier(LanAutoGenerated.QNAME))
80 .addChild(createValueBuilder(MAC_MODEL, BRIDGE_MAC_NID).build())
81 .addChild(createValueBuilder(PRIORITY, RBP_NID).build()).build();