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.rev171213.NormalizationType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.OperationalMode;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.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.rev171213.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.rev171213.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.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
30 public class Layer2AttributesExtComTest {
31 private static final byte[] EXPECTEDS = {(byte) 0x00, (byte) 0x07, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00};
32 private static final byte[] EVPN_VPWS = {(byte) 0x00, (byte) 0x2f, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00};
33 private static final byte[] EVPN_VPWS_2 = {(byte) 0x00, (byte) 0x57, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00};
34 private Layer2AttributesExtCom parser;
38 this.parser = new Layer2AttributesExtCom();
42 public void handlerTest() throws BGPParsingException, BGPDocumentedException {
43 final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
45 final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder()
46 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
47 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257).build()).build();
48 this.parser.serializeExtendedCommunity(expected, buff);
49 final byte[] resultByte = ByteArray.getAllBytes(buff);
50 assertArrayEquals(EXPECTEDS, resultByte);
52 final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EXPECTEDS));
53 assertEquals(expected, result);
57 public void evpnVpwsTest() throws BGPParsingException, BGPDocumentedException {
58 final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
60 final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder()
61 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
62 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257)
63 .setModeOfOperation(OperationalMode.VlanAwareFxc)
64 .setOperatingPer(NormalizationType.SingleVid)
66 this.parser.serializeExtendedCommunity(expected, buff);
67 final byte[] resultByte = ByteArray.getAllBytes(buff);
68 assertArrayEquals(EVPN_VPWS, resultByte);
70 final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS));
71 assertEquals(expected, result);
73 final ByteBuf buff2 = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
74 final Layer2AttributesExtendedCommunityCase expected2 = new Layer2AttributesExtendedCommunityCaseBuilder()
75 .setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true)
76 .setControlWord(true).setPrimaryPe(true).setL2Mtu(257)
77 .setModeOfOperation(OperationalMode.VlanUnawareFxc)
78 .setOperatingPer(NormalizationType.DoubleVid)
80 this.parser.serializeExtendedCommunity(expected2, buff2);
81 final byte[] resultByte2 = ByteArray.getAllBytes(buff2);
82 assertArrayEquals(EVPN_VPWS_2, resultByte2);
84 final ExtendedCommunity result2 = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS_2));
85 assertEquals(expected2, result2);
88 @Test(expected = IllegalArgumentException.class)
89 public void wrongCaseTest() {
90 this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
94 public void testSubtype() {
95 assertEquals(4, this.parser.getSubType());