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.nlri;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.IP_MODEL;
14 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder;
15 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
16 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETI;
17 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ROUDE_DISTIN;
18 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.WRONG_VALUE;
19 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.MACIpAdvRParserTest.createEti;
20 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.ORI_NID;
22 import io.netty.buffer.Unpooled;
23 import java.util.ArrayList;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
27 import org.opendaylight.protocol.util.ByteArray;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.EvpnChoice;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.evpn.choice.EsRouteCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.evpn.choice.IncMultiEthernetTagResCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.evpn.choice.IncMultiEthernetTagResCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.inc.multi.ethernet.tag.res.IncMultiEthernetTagResBuilder;
33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
34 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
36 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
37 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
39 public class IncMultEthTagRParserTest {
40 static final byte[] RESULT = {
41 (byte) 0x03, (byte) 0x11,
42 (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02,
43 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
44 (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
46 private static final byte[] VALUE = {
47 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
48 (byte) 0x20, (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01
50 private IncMultEthTagRParser parser;
54 this.parser = new IncMultEthTagRParser();
55 ESIActivator.registerEsiTypeParsers(new ArrayList<>());
59 public void parserTest() {
61 final IncMultiEthernetTagResCase expected = IncMultEthTagRParserTest.createIncMultiCase();
62 assertArrayEquals(RESULT, ByteArray.getAllBytes(this.parser.serializeEvpn(expected,
63 Unpooled.wrappedBuffer(ROUDE_DISTIN))));
65 final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
66 assertEquals(expected, result);
68 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice = Builders.choiceBuilder();
69 choice.withNodeIdentifier(IncMultEthTagRParser.INC_MULT_ROUTE_NID);
70 final ContainerNode incMult = createContBuilder(IncMultEthTagRParser.INC_MULT_ROUTE_NID).addChild(createEti())
71 .addChild(createValueBuilder(IP_MODEL, ORI_NID).build()).build();
72 final EvpnChoice modelResult = this.parser.serializeEvpnModel(incMult);
73 assertEquals(expected, modelResult);
75 final EvpnChoice keyResult = this.parser.createRouteKey(incMult);
76 assertEquals(expected, keyResult);
79 static IncMultiEthernetTagResCase createIncMultiCase() {
80 return new IncMultiEthernetTagResCaseBuilder().setIncMultiEthernetTagRes(
81 new IncMultiEthernetTagResBuilder().setEthernetTagId(ETI).setOrigRouteIp(IP).build()).build();
84 @Test(expected = IllegalArgumentException.class)
85 public void wrongCaseTest() {
86 this.parser.serializeEvpn(new EsRouteCaseBuilder().build(), null);
89 @Test(expected = IllegalArgumentException.class)
90 public void wrongSizeTest() {
91 this.parser.parseEvpn(Unpooled.wrappedBuffer(WRONG_VALUE));