--- /dev/null
+/*
+ * 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;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+
+public final class ModelTestUtil {
+ public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> createContBuilder(final YangInstanceIdentifier
+ .NodeIdentifier nid) {
+ return ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(nid);
+ }
+
+ public static <T> ImmutableLeafNodeBuilder<T> createValueBuilder(final T value, YangInstanceIdentifier.NodeIdentifier nid) {
+ final ImmutableLeafNodeBuilder<T> valueBuilder = new ImmutableLeafNodeBuilder<>();
+ valueBuilder.withNodeIdentifier(nid).withValue(value);
+ return valueBuilder;
+ }
+}
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.AS_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LD_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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.AsGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.AsGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.as.generated._case.AsGenerated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.as.generated._case.AsGeneratedBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class ASGenParserTest extends AbstractParserTest {
+ private static final byte[] VALUE = {(byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private static final byte[] RESULT = {(byte) 0x05, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private static final AsNumber AS = new AsNumber(16843009L);
+ private ASGenParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new ASGenParser();
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
+
+ final AsGeneratedCase acb = new AsGeneratedCaseBuilder().setAsGenerated(new AsGeneratedBuilder().setAs(AS)
+ .setLocalDiscriminator(LD).build()).build();
+ this.parser.serializeEsi(acb, buff);
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(acb, acResult);
+
+ final ContainerNode cont = createContBuilder(new NodeIdentifier(AsGenerated.QNAME))
+ .addChild(createValueBuilder(16843009L, AS_NID).build())
+ .addChild(createValueBuilder(LD, LD_NID).build())
+ .build();
+ final Esi acmResult = this.parser.serializeEsi(cont);
+ assertEquals(acb, acmResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+
+abstract class AbstractParserTest {
+ protected static final int VALUE_SIZE = 9;
+ protected static final long LD = 33686018;
+ protected static final MacAddress MAC = new MacAddress("f2:0c:dd:80:9f:f7");
+}
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ARB_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.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.AsGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.arbitrary._case.Arbitrary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.arbitrary._case.ArbitraryBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class ArbitraryParserTest extends AbstractParserTest {
+ private static final byte[] ARB_VALUE = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
+ (byte) 0x08, (byte) 0x09};
+ private static final byte[] ARB_RESULT = {(byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06,
+ (byte) 0x07, (byte) 0x08, (byte) 0x09};
+ private ArbitraryParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new ArbitraryParser();
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
+
+ final ArbitraryCase acb = new ArbitraryCaseBuilder().setArbitrary(new ArbitraryBuilder().setArbitrary(ARB_VALUE).build()).build();
+ this.parser.serializeEsi(acb, buff);
+ assertArrayEquals(ARB_RESULT, ByteArray.getAllBytes(buff));
+
+ final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(ARB_VALUE));
+ assertEquals(acb, acResult);
+
+ final ContainerNode cont = createContBuilder(new NodeIdentifier(Arbitrary.QNAME))
+ .addChild(createValueBuilder(ARB_VALUE, ARB_NID).build()).build();
+ final Esi acmResult = this.parser.serializeEsi(cont);
+ assertEquals(acb, acmResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEsi(new AsGeneratedCaseBuilder().build(), null);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LACP_MAC_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.PK_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.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.LacpAutoGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.LacpAutoGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.lacp.auto.generated._case.LacpAutoGenerated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.lacp.auto.generated._case.LacpAutoGeneratedBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class LacpParserTest extends AbstractParserTest {
+ private static final Integer PORT = 514;
+ 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) 0x01, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private LacpParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new LacpParser();
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
+
+ final LacpAutoGeneratedCase acb = new LacpAutoGeneratedCaseBuilder().setLacpAutoGenerated(new LacpAutoGeneratedBuilder()
+ .setCeLacpMacAddress(MAC).setCeLacpPortKey(PORT).build()).build();
+ this.parser.serializeEsi(acb, buff);
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(acb, acResult);
+
+ final ContainerNode cont = createContBuilder( new NodeIdentifier(LacpAutoGenerated.QNAME))
+ .addChild(createValueBuilder(MAC, LACP_MAC_NID).build())
+ .addChild(createValueBuilder(PORT, PK_NID).build())
+ .build();
+ final Esi acmResult = this.parser.serializeEsi(cont);
+ assertEquals(acb, acmResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.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.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.LacpAutoGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.LanAutoGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.LanAutoGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.lan.auto.generated._case.LanAutoGenerated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.lan.auto.generated._case.LanAutoGeneratedBuilder;
+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 extends AbstractParserTest {
+ private static final Integer PRIORITY = 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<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(new NodeIdentifier(LacpAutoGeneratedCase.QNAME));
+ return choice.addChild(createLanCont()).build();
+ }
+
+ private static ContainerNode createLanCont() {
+ return createContBuilder(new NodeIdentifier(LanAutoGenerated.QNAME))
+ .addChild(createValueBuilder(MAC, BRIDGE_MAC_NID).build())
+ .addChild(createValueBuilder(PRIORITY, RBP_NID).build())
+ .build();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LD_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.SYSTEM_MAC_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.rev160321.Uint24;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.MacAutoGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.MacAutoGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.mac.auto.generated._case.MacAutoGenerated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.mac.auto.generated._case.MacAutoGeneratedBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class MacParserTest extends AbstractParserTest {
+ 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) 0x03, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private static final Uint24 UINT24_LD = new Uint24(131584L);
+ private MacParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new MacParser();
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
+
+ final MacAutoGeneratedCase acb = new MacAutoGeneratedCaseBuilder().setMacAutoGenerated(new MacAutoGeneratedBuilder()
+ .setLocalDiscriminator(UINT24_LD).setSystemMacAddress(MAC).build()).build();
+ this.parser.serializeEsi(acb, buff);
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(acb, acResult);
+
+ final ContainerNode cont = createContBuilder(new NodeIdentifier(MacAutoGenerated.QNAME))
+ .addChild(createValueBuilder(MAC, SYSTEM_MAC_NID).build())
+ .addChild(createValueBuilder(UINT24_LD, LD_NID).build())
+ .build();
+ final Esi acmResult = this.parser.serializeEsi(cont);
+ assertEquals(acb, acmResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.ModelTestUtil.createContBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.ModelTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LD_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.RD_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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.Esi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.ArbitraryCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.RouterIdGeneratedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.RouterIdGeneratedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.router.id.generated._case.RouterIdGenerated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.esi.router.id.generated._case.RouterIdGeneratedBuilder;
+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 RouterIdParserTest extends AbstractParserTest {
+ public static final byte[] RESULT = {(byte) 0x04, (byte) 0x2A, (byte) 0x2A, (byte) 0x2A, (byte) 0x2A, (byte) 0x02, (byte) 0x02, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private static final byte[] VALUE = {(byte) 0x2A, (byte) 0x2A, (byte) 0x2A, (byte) 0x2A, (byte) 0x02, (byte) 0x02, (byte) 0x02,
+ (byte) 0x02, (byte) 0x00};
+ private static final Ipv4Address ROUTE_ID = new Ipv4Address("42.42.42.42");
+ public static final RouterIdGeneratedCase ROUTE_ID_CASE = new RouterIdGeneratedCaseBuilder().setRouterIdGenerated(new RouterIdGeneratedBuilder()
+ .setLocalDiscriminator(LD).setRouterId(ROUTE_ID).build()).build();
+ private RouterIdParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new RouterIdParser();
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
+
+ this.parser.serializeEsi(ROUTE_ID_CASE, buff);
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(ROUTE_ID_CASE, acResult);
+
+ final Esi acmResult = this.parser.serializeEsi(RouterIdParserTest.createRouteContainer());
+ assertEquals(ROUTE_ID_CASE, acmResult);
+ }
+
+ public static ChoiceNode createRouterIdCase() {
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> nextHop = Builders.choiceBuilder();
+ nextHop.withNodeIdentifier(new NodeIdentifier(RouterIdGeneratedCase.QNAME));
+ return nextHop.addChild(createRouteContainer()).build();
+ }
+
+ private static ContainerNode createRouteContainer() {
+ return createContBuilder(new NodeIdentifier(RouterIdGenerated.QNAME))
+ .addChild(createValueBuilder(ROUTE_ID, RD_NID).build())
+ .addChild(createValueBuilder(LD, LD_NID).build())
+ .build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
+ }
+}
\ No newline at end of file