package org.opendaylight.protocol.bgp.evpn.impl;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisherBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
public static final Integer PORT = 514;
public static final MplsLabel MPLS_LABEL = new MplsLabel(24001L);
public static final int COMMUNITY_VALUE_SIZE = 6;
+ public static final long VLAN = 10L;
+ public static final String IP_MODEL = "127.0.0.1";
+ public static final IpAddress IP = new IpAddress(new Ipv4Address(IP_MODEL));
+ public static final String IPV6_MODEL = "2001::1";
+ public static final IpAddress IPV6 = new IpAddress(new Ipv6Address(IPV6_MODEL));
+ public static final long MPLS_LABEL_MODEL = 24001L;
+ public static final MplsLabel MPLS_LABEL2 = new MplsLabel(24002L);
+ public static final long MPLS_LABEL2_MODEL = 24002L;
+ public static final String RD_MODEL = "1.2.3.4:258";
+ public static final RouteDistinguisher RD = RouteDistinguisherBuilder.getDefaultInstance(RD_MODEL);
public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> createContBuilder(final YangInstanceIdentifier
.NodeIdentifier nid) {
--- /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.nlri;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VLAN;
+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.LanParserTest.LAN_AUT_GEN_CASE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.MACIpAdvRParserTest.createEti;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.MPLS_NID;
+import static org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEvpnNlriRegistryTest.EVPN_NID;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.LanParserTest;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.ethernet.a.d.route.EthernetADRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.ethernet.tag.id.EthernetTagId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.ethernet.tag.id.EthernetTagIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EsRouteCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EthernetADRouteCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EthernetADRouteCaseBuilder;
+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 EthADRParserTest {
+ public static final byte[] RESULT = {
+ (byte) 0x01, (byte) 0x19,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x05, (byte) 0xdc, (byte) 0x10
+ };
+ public static final byte[] ROUDE_DISTIN = {
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02
+ };
+ static final EthernetTagId ETI = new EthernetTagIdBuilder().setVlanId(VLAN).build();
+ private static final EthernetADRouteCase ETHERNET_AD_ROUTE_CASE_KEY = new EthernetADRouteCaseBuilder().setEthernetADRoute(new EthernetADRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI).build()).build();
+ public static final EthernetADRouteCase ETHERNET_AD_ROUTE_CASE = new EthernetADRouteCaseBuilder().setEthernetADRoute(new EthernetADRouteBuilder()
+ .setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI).setMplsLabel(MPLS_LABEL).build()).build();
+ static final byte[] WRONG_VALUE = {(byte) 0x00};
+ private static final byte[] VALUE = {
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x05, (byte) 0xdc, (byte) 0x10
+ };
+ private EthADRParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new EthADRParser();
+ ESIActivator.registerEsiTypeParsers(new ArrayList<>());
+ }
+
+ @Test
+ public void parserTest() {
+ final ByteBuf buff = this.parser.serializeEvpn(ETHERNET_AD_ROUTE_CASE, Unpooled.wrappedBuffer(ROUDE_DISTIN));
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(ETHERNET_AD_ROUTE_CASE, result);
+
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(EthADRParserTest.createArbitraryContainer());
+ assertEquals(ETHERNET_AD_ROUTE_CASE, modelResult);
+
+ final EvpnChoice keyResult = this.parser.createRouteKey(EthADRParserTest.createArbitraryContainer());
+ assertEquals(ETHERNET_AD_ROUTE_CASE_KEY, keyResult);
+ }
+
+ public static ChoiceNode createEthADRModel() {
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(EVPN_NID);
+ return choice.addChild(createArbitraryContainer()).build();
+ }
+
+ private static ContainerNode createArbitraryContainer() {
+ final ChoiceNode esiModel = LanParserTest.createLanChoice();
+ return createContBuilder(EthADRParser.ETH_AD_ROUTE_NID).addChild(esiModel).addChild(createEti())
+ .addChild(createValueBuilder(MPLS_LABEL_MODEL, MPLS_NID).build()).build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEvpn(new EsRouteCaseBuilder().build(), null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongSizeTest() {
+ this.parser.parseEvpn(Unpooled.wrappedBuffer(WRONG_VALUE));
+ }
+}
\ 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.nlri;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IPV6;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IPV6_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP_MODEL;
+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.LanParserTest.LAN_AUT_GEN_CASE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ROUDE_DISTIN;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.WRONG_VALUE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.ORI_NID;
+
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.LanParserTest;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.es.route.EsRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EsRouteCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EsRouteCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.MacIpAdvRouteCaseBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+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 EthSegRParserTest {
+ private static final byte[] VALUE = {
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
+ private static final byte[] RESULT = {
+ (byte) 0x04, (byte) 0x17,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
+ private static final byte[] VALUE2 = {
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x10,//IPV6
+ (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ };
+ private static final byte[] RESULT2 = {
+ (byte) 0x04, (byte) 0x23,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x10,//IPV6
+ (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ };
+ private EthSegRParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new EthSegRParser();
+ ESIActivator.registerEsiTypeParsers(new ArrayList<>());
+ }
+
+ @Test
+ public void parserTest() {
+ final EsRouteCase expected = new EsRouteCaseBuilder().setEsRoute(new EsRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setOrigRouteIp(IP).build()).build();
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(this.parser.serializeEvpn(expected, Unpooled.wrappedBuffer(ROUDE_DISTIN))));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(expected, result);
+
+ final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(EthSegRParser.ES_ROUTE_NID);
+ final ContainerNode arbitraryC = createContBuilder(EthSegRParser.ES_ROUTE_NID).addChild(LanParserTest.createLanChoice())
+ .addChild(createValueBuilder(IP_MODEL, ORI_NID).build()).build();
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(arbitraryC);
+ assertEquals(expected, modelResult);
+
+ final EvpnChoice keyResult = this.parser.createRouteKey(arbitraryC);
+ assertEquals(expected, keyResult);
+ }
+
+ @Test
+ public void parser2Test() {
+ final EsRouteCase expected = new EsRouteCaseBuilder().setEsRoute(new EsRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setOrigRouteIp(IPV6).build()).build();
+ assertArrayEquals(RESULT2, ByteArray.getAllBytes(this.parser.serializeEvpn(expected, Unpooled.wrappedBuffer(ROUDE_DISTIN))));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE2));
+ assertEquals(expected, result);
+
+ final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(EthSegRParser.ES_ROUTE_NID);
+ final ContainerNode arbitraryC = createContBuilder(EthSegRParser.ES_ROUTE_NID).addChild(LanParserTest.createLanChoice())
+ .addChild(createValueBuilder(IPV6_MODEL, ORI_NID).build()).build();
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(arbitraryC);
+ assertEquals(expected, modelResult);
+
+ final EvpnChoice keyResult = this.parser.createRouteKey(arbitraryC);
+ assertEquals(expected, keyResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEvpn(new MacIpAdvRouteCaseBuilder().build(), null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongSizeTest() {
+ this.parser.parseEvpn(Unpooled.wrappedBuffer(WRONG_VALUE));
+ }
+}
\ 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.nlri;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.RD_NID;
+import static org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEvpnNlriRegistryTest.EVPN_NID;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.evpn._case.DestinationEvpnBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+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.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
+
+public class EvpnNlriParserTest {
+ private static final NodeIdentifier EVPN_CHOICE_NID = new NodeIdentifier(EvpnChoice.QNAME);
+ private List<EvpnDestination> dest;
+ private EvpnNlriParser parser;
+
+ @Before
+ public void setUp() {
+ ESIActivator.registerEsiTypeParsers(new ArrayList<>());
+ NlriActivator.registerNlriParsers(new ArrayList<>());
+ this.dest = Collections.singletonList(new EvpnDestinationBuilder()
+ .setRouteDistinguisher(RD)
+ .setEvpnChoice(IncMultEthTagRParserTest.createIncMultiCase()).build());
+ this.parser = new EvpnNlriParser();
+ }
+
+ @Test
+ public void testSerializeNlri() throws BGPParsingException {
+ final ByteBuf buffer = Unpooled.buffer();
+ EvpnNlriParser.serializeNlri(this.dest, buffer);
+ assertArrayEquals(IncMultEthTagRParserTest.RESULT, ByteArray.getAllBytes(buffer));
+
+ }
+
+ @Test
+ public void testMpUnreach() throws BGPParsingException {
+ final MpUnreachNlriBuilder mpReach = new MpUnreachNlriBuilder();
+ this.parser.parseNlri(Unpooled.wrappedBuffer(IncMultEthTagRParserTest.RESULT), mpReach);
+ assertEquals(createUnreach(), mpReach.build());
+ }
+
+ private MpUnreachNlri createUnreach() {
+ final MpUnreachNlriBuilder mpReachExpected = new MpUnreachNlriBuilder();
+ final WithdrawnRoutes wd = new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+ bgp.evpn.rev160321.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCaseBuilder().setDestinationEvpn(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.unreach.nlri.withdrawn.routes.
+ destination.type.destination.evpn._case.DestinationEvpnBuilder().setEvpnDestination(this.dest).build()).build()).build();
+ return mpReachExpected.setWithdrawnRoutes(wd).build();
+ }
+
+ @Test
+ public void testMpReach() throws BGPParsingException {
+ final MpReachNlriBuilder mpReach = new MpReachNlriBuilder();
+ this.parser.parseNlri(Unpooled.wrappedBuffer(IncMultEthTagRParserTest.RESULT), mpReach);
+
+ final MpReachNlriBuilder mpReachExpected = new MpReachNlriBuilder();
+ final AdvertizedRoutes wd = new AdvertizedRoutesBuilder().setDestinationType(new DestinationEvpnCaseBuilder().setDestinationEvpn(
+ new DestinationEvpnBuilder().setEvpnDestination(this.dest).build()).build()).build();
+ mpReachExpected.setAdvertizedRoutes(wd);
+ assertEquals(mpReachExpected.build(), mpReach.build());
+ }
+
+ @Test
+ public void testNullMpReachNlri() throws BGPParsingException {
+ final MpReachNlriBuilder mpb = new MpReachNlriBuilder();
+ this.parser.parseNlri(Unpooled.buffer(), mpb);
+ assertEquals(new MpReachNlriBuilder().build(), mpb.build());
+ }
+
+ @Test
+ public void testNullMpUnReachNlri() throws BGPParsingException {
+ final MpUnreachNlriBuilder mpb = new MpUnreachNlriBuilder();
+ this.parser.parseNlri(Unpooled.buffer(), mpb);
+ assertEquals(new MpUnreachNlriBuilder().build(), mpb.build());
+ }
+
+ @Test
+ public void testExtractEvpnDestination() throws BGPParsingException {
+ final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create();
+ evpnBI.withNodeIdentifier(EVPN_NID);
+ evpnBI.withChild(createMACIpAdvChoice());
+ evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build());
+ final EvpnDestination destResult = EvpnNlriParser.extractEvpnDestination(evpnBI.build());
+ final EvpnDestination expected = new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(MACIpAdvRParserTest.createdExpectedResult()).build();
+ assertEquals(expected, destResult);
+ }
+
+
+ public static ChoiceNode createMACIpAdvChoice() {
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(EVPN_CHOICE_NID);
+ return choice.addChild(MACIpAdvRParserTest.createMacIpCont()).build();
+ }
+
+ @Test
+ public void testExtractRouteKey() throws BGPParsingException {
+ final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create();
+ evpnBI.withNodeIdentifier(EVPN_CHOICE_NID);
+ evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build());
+ evpnBI.withChild(createMACIpAdvChoice());
+ final EvpnDestination destResult = EvpnNlriParser.extractRouteKeyDestination(evpnBI.build());
+ final EvpnDestination expected = new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(MACIpAdvRParserTest.createdExpectedRouteKey()).build();
+ assertEquals(expected, destResult);
+ }
+}
\ 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.nlri;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP_MODEL;
+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.nlri.EthADRParserTest.ETI;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ROUDE_DISTIN;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.WRONG_VALUE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.MACIpAdvRParserTest.createEti;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.ORI_NID;
+
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EsRouteCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.IncMultiEthernetTagResCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.IncMultiEthernetTagResCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.inc.multi.ethernet.tag.res.IncMultiEthernetTagResBuilder;
+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 IncMultEthTagRParserTest {
+ static final byte[] RESULT = {
+ (byte) 0x03, (byte) 0x11,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
+ private static final byte[] VALUE = {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x04, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
+ };
+ private IncMultEthTagRParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new IncMultEthTagRParser();
+ ESIActivator.registerEsiTypeParsers(new ArrayList<>());
+ }
+
+ @Test
+ public void parserTest() {
+
+ final IncMultiEthernetTagResCase expected = IncMultEthTagRParserTest.createIncMultiCase();
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(this.parser.serializeEvpn(expected, Unpooled.wrappedBuffer(ROUDE_DISTIN))));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(expected, result);
+
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(IncMultEthTagRParser.INC_MULT_ROUTE_NID);
+ final ContainerNode incMult = createContBuilder(IncMultEthTagRParser.INC_MULT_ROUTE_NID).addChild(createEti())
+ .addChild(createValueBuilder(IP_MODEL, ORI_NID).build()).build();
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(incMult);
+ assertEquals(expected, modelResult);
+
+ final EvpnChoice keyResult = this.parser.createRouteKey(incMult);
+ assertEquals(expected, keyResult);
+ }
+
+ public static IncMultiEthernetTagResCase createIncMultiCase() {
+ return new IncMultiEthernetTagResCaseBuilder().setIncMultiEthernetTagRes(new IncMultiEthernetTagResBuilder().setEthernetTagId(ETI)
+ .setOrigRouteIp(IP).build()).build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEvpn(new EsRouteCaseBuilder().build(), null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongSizeTest() {
+ this.parser.parseEvpn(Unpooled.wrappedBuffer(WRONG_VALUE));
+ }
+}
\ 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.nlri;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IPV6;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IPV6_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP_MODEL;
+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.MPLS_LABEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL2;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL2_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL_MODEL;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VLAN;
+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.LanParserTest.LAN_AUT_GEN_CASE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETI;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ROUDE_DISTIN;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.ETI_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.IP_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.MAC_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.MPLS1_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.MPLS2_NID;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.VLAN_NID;
+
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.LanParserTest;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.EsRouteCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.MacIpAdvRouteCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.evpn.choice.MacIpAdvRouteCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.mac.ip.adv.route.MacIpAdvRouteBuilder;
+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 MACIpAdvRParserTest {
+ private static final byte[] VALUE = {
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x30, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7,
+ (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x10,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x20
+ };
+ private static final byte[] RESULT = {
+ (byte) 0x02, (byte) 0x28,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x30, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7,
+ (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x10,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x20
+ };
+ private static final byte[] VALUE2 = {
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x30, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7,
+ (byte) 0x80, 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x10,
+ };
+ private static final byte[] RESULT2 = {
+ (byte) 0x02, (byte) 0x31,
+ (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, //RD
+ (byte) 0x02, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00, //ESI
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // ETI
+ (byte) 0x30, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, // MAC
+ (byte) 0x80,//IPV6
+ (byte) 0x20, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x05, (byte) 0xdc, (byte) 0x10, //MPLS
+ };
+
+ private MACIpAdvRParser parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new MACIpAdvRParser();
+ ESIActivator.registerEsiTypeParsers(new ArrayList<>());
+ }
+
+ @Test
+ public void parserCase1Test() {
+ final MacIpAdvRouteCase expected = createdExpectedResult();
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(this.parser.serializeEvpn(expected, Unpooled.wrappedBuffer(ROUDE_DISTIN))));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
+ assertEquals(expected, result);
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(createMacIpCont());
+ assertEquals(expected, modelResult);
+
+ final EvpnChoice keyResult = this.parser.createRouteKey(createMacIpCont());
+ assertEquals(createdExpectedRouteKey(), keyResult);
+ }
+
+ static MacIpAdvRouteCase createdExpectedResult() {
+ return new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(new MacIpAdvRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI)
+ .setMacAddress(MAC).setIpAddress(IP).setMplsLabel1(MPLS_LABEL).setMplsLabel2(MPLS_LABEL2).build()).build();
+ }
+
+ static MacIpAdvRouteCase createdExpectedRouteKey() {
+ return new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(new MacIpAdvRouteBuilder().setEthernetTagId(ETI).setMacAddress(MAC)
+ .setIpAddress(IP).build()).build();
+ }
+
+ static ContainerNode createMacIpCont() {
+ return createContBuilder(MACIpAdvRParser.MAC_IP_ADV_ROUTE_NID)
+ .addChild(LanParserTest.createLanChoice())
+ .addChild(createEti())
+ .addChild(createValueBuilder(MAC_MODEL, MAC_NID).build())
+ .addChild(createValueBuilder(IP_MODEL, IP_NID).build())
+ .addChild(createValueBuilder(MPLS_LABEL_MODEL, MPLS1_NID).build())
+ .addChild(createValueBuilder(MPLS_LABEL2_MODEL, MPLS2_NID).build())
+ .build();
+ }
+
+ public static ContainerNode createEti() {
+ return createContBuilder(ETI_NID).withChild(createValueBuilder(VLAN, VLAN_NID).build()).build();
+ }
+
+ @Test
+ public void parserCase2Test() {
+
+ final MacIpAdvRouteCase expected = new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(new MacIpAdvRouteBuilder().setEsi(LAN_AUT_GEN_CASE)
+ .setEthernetTagId(ETI).setMacAddress(MAC).setIpAddress(IPV6).setMplsLabel1(MPLS_LABEL).build()).build();
+ assertArrayEquals(RESULT2, ByteArray.getAllBytes(this.parser.serializeEvpn(expected, Unpooled.wrappedBuffer(ROUDE_DISTIN))));
+
+ final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE2));
+ assertEquals(expected, result);
+
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
+ choice.withNodeIdentifier(MACIpAdvRParser.MAC_IP_ADV_ROUTE_NID);
+ final ContainerNode macIp = createContBuilder(MACIpAdvRParser.MAC_IP_ADV_ROUTE_NID).addChild(LanParserTest.createLanChoice()).addChild(createEti())
+ .addChild(createValueBuilder(MAC_MODEL, MAC_NID).build()).addChild(createValueBuilder(IPV6_MODEL, IP_NID).build())
+ .addChild(createValueBuilder(MPLS_LABEL_MODEL, MPLS1_NID).build()).build();
+ final EvpnChoice modelResult = this.parser.serializeEvpnModel(macIp);
+
+ assertEquals(expected, modelResult);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeEvpn(new EsRouteCaseBuilder().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.spi.pojo;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+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.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ROUDE_DISTIN;
+import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.createEthADRModel;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest;
+import org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriActivator;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.Evpn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.EvpnChoice;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+
+public final class SimpleEvpnNlriRegistryTest {
+ public static final YangInstanceIdentifier.NodeIdentifier EVPN_NID = new YangInstanceIdentifier.NodeIdentifier(EvpnChoice.QNAME);
+
+ private class notRegistered implements EvpnChoice {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return notRegistered.class;
+ }
+ }
+
+ @Before
+ public void setUp() {
+ final ArrayList<AutoCloseable> reg = new ArrayList<>();
+ ESIActivator.registerEsiTypeParsers(reg);
+ NlriActivator.registerNlriParsers(reg);
+ }
+
+ @Test
+ public void registryTest() {
+ final ByteBuf buff = SimpleEvpnNlriRegistry.getInstance().serializeEvpn(ETHERNET_AD_ROUTE_CASE, Unpooled.wrappedBuffer(ROUDE_DISTIN));
+ assertArrayEquals(EthADRParserTest.RESULT, ByteArray.getAllBytes(buff));
+ final EvpnChoice resultModel = SimpleEvpnNlriRegistry.getInstance().serializeEvpnModel(createEthADRModel());
+ assertEquals(ETHERNET_AD_ROUTE_CASE, resultModel);
+ final NlriType type = NlriType.forValue(buff.readUnsignedByte());
+ buff.skipBytes(VALUE_SIZE); // length + RD
+ assertEquals(ETHERNET_AD_ROUTE_CASE, SimpleEvpnNlriRegistry.getInstance().parseEvpn(type, buff));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void registryParseTest() {
+ SimpleEvpnNlriRegistry.getInstance().parseEvpn(NlriType.EthADDisc, null);
+ }
+
+ @Test
+ public void registryNullTest() {
+ final ByteBuf body = Unpooled.buffer();
+ SimpleEvpnNlriRegistry.getInstance().serializeEvpn(new notRegistered(), body);
+ assertEquals(0, body.readableBytes());
+ }
+
+ @Test
+ public void registryNullModelTest() {
+ final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder().withNodeIdentifier(EVPN_NID);
+ choice.addChild(createContBuilder(new YangInstanceIdentifier.NodeIdentifier(QName.create(Evpn.QNAME, "test").intern())).build()).build();
+ assertNull(SimpleEvpnNlriRegistry.getInstance().serializeEvpnModel(choice.build()));
+ }
+}
\ No newline at end of file