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
9 package org.opendaylight.protocol.bgp.evpn.impl.extended.communities;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
20 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
21 import org.opendaylight.protocol.util.ByteArray;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NormalizationType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.OperationalMode;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
30 public class Layer2AttributesExtComTest {
31 private static final byte[] EXPECTEDS = {(byte) 0x00, (byte) 0x07, (byte) 0x01, (byte) 0x01,
32 (byte) 0x00, (byte) 0x00};
33 private static final byte[] EVPN_VPWS = {(byte) 0x00, (byte) 0x2f, (byte) 0x01, (byte) 0x01,
34 (byte) 0x00, (byte) 0x00};
35 private static final byte[] EVPN_VPWS_2 = {(byte) 0x00, (byte) 0x57, (byte) 0x01, (byte) 0x01,
36 (byte) 0x00, (byte) 0x00};
37 private Layer2AttributesExtCom parser;
41 this.parser = new Layer2AttributesExtCom();
45 public void handlerTest() throws BGPParsingException, BGPDocumentedException {
46 final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
48 final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder()
49 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
50 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257).build()).build();
51 this.parser.serializeExtendedCommunity(expected, buff);
52 final byte[] resultByte = ByteArray.getAllBytes(buff);
53 assertArrayEquals(EXPECTEDS, resultByte);
55 final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EXPECTEDS));
56 assertEquals(expected, result);
60 public void evpnVpwsTest() throws BGPParsingException, BGPDocumentedException {
61 final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
63 final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder()
64 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
65 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257)
66 .setModeOfOperation(OperationalMode.VlanAwareFxc)
67 .setOperatingPer(NormalizationType.SingleVid)
69 this.parser.serializeExtendedCommunity(expected, buff);
70 final byte[] resultByte = ByteArray.getAllBytes(buff);
71 assertArrayEquals(EVPN_VPWS, resultByte);
73 final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS));
74 assertEquals(expected, result);
76 final ByteBuf buff2 = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
77 final Layer2AttributesExtendedCommunityCase expected2 = new Layer2AttributesExtendedCommunityCaseBuilder()
78 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
79 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257)
80 .setModeOfOperation(OperationalMode.VlanUnawareFxc)
81 .setOperatingPer(NormalizationType.DoubleVid)
83 this.parser.serializeExtendedCommunity(expected2, buff2);
84 final byte[] resultByte2 = ByteArray.getAllBytes(buff2);
85 assertArrayEquals(EVPN_VPWS_2, resultByte2);
87 final ExtendedCommunity result2 = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS_2));
88 assertEquals(expected2, result2);
91 @Test(expected = IllegalArgumentException.class)
92 public void wrongCaseTest() {
93 this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
97 public void testSubtype() {
98 assertEquals(4, this.parser.getSubType());