735dcf208a66f91fa5477e98db17175f1344fb59
[bgpcep.git] / bgp / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / esi / types / LacpParserTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.evpn.impl.esi.types;
9
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.PORT;
15 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VALUE_SIZE;
16 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder;
17 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
18 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LACP_MAC_NID;
19 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.PK_NID;
20
21 import io.netty.buffer.ByteBuf;
22 import io.netty.buffer.Unpooled;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.protocol.util.ByteArray;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.Esi;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.ArbitraryCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.LacpAutoGeneratedCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.LacpAutoGeneratedCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.lacp.auto.generated._case.LacpAutoGenerated;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.lacp.auto.generated._case.LacpAutoGeneratedBuilder;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34
35 public final class LacpParserTest {
36     private static final byte[] VALUE = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02,
37         (byte) 0x02, (byte) 0x00};
38     private static final byte[] RESULT = {(byte) 0x01, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7, (byte) 0x02,
39         (byte) 0x02, (byte) 0x00};
40     private LacpParser parser;
41
42     @Before
43     public void setUp() {
44         this.parser = new LacpParser();
45     }
46
47     @Test
48     public void parserTest() {
49         final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
50
51         final LacpAutoGeneratedCase lanAuto = new LacpAutoGeneratedCaseBuilder().setLacpAutoGenerated(new LacpAutoGeneratedBuilder()
52             .setCeLacpMacAddress(MAC).setCeLacpPortKey(PORT).build()).build();
53         this.parser.serializeEsi(lanAuto, buff);
54         assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
55
56         final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
57         assertEquals(lanAuto, acResult);
58
59         final ContainerNode cont = createContBuilder( new NodeIdentifier(LacpAutoGenerated.QNAME))
60             .addChild(createValueBuilder(MAC_MODEL, LACP_MAC_NID).build())
61             .addChild(createValueBuilder(PORT, PK_NID).build())
62             .build();
63         final Esi acmResult = this.parser.serializeEsi(cont);
64         assertEquals(lanAuto, acmResult);
65     }
66
67     @Test(expected = IllegalArgumentException.class)
68     public void wrongCaseTest() {
69         this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
70     }
71 }