Search in sources :

Example 1 with Layer2AttributesExtendedCommunityCase

use of 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 in project bgpcep by opendaylight.

the class Layer2AttributesExtCom method serializeExtendedCommunity.

@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
    Preconditions.checkArgument(extendedCommunity instanceof Layer2AttributesExtendedCommunityCase, "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.", extendedCommunity);
    final Layer2AttributesExtendedCommunity extCom = ((Layer2AttributesExtendedCommunityCase) extendedCommunity).getLayer2AttributesExtendedCommunity();
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(PRIMARY_PE_OFFSET, extCom.isPrimaryPe());
    flags.set(BACKUP_PE_OFFSET, extCom.isBackupPe());
    flags.set(CONTROL_WORD_OFFSET, extCom.isControlWord());
    final byte[] res = flags.array();
    byte aux = 0;
    final OperationalMode modeOfOperation = extCom.getModeOfOperation();
    if (modeOfOperation != null) {
        aux = UnsignedBytes.checkedCast(modeOfOperation.getIntValue());
        aux = (byte) (aux << THREE_BITS_SHIFT);
        res[res.length - 1] = (byte) (res[res.length - 1] | aux);
    }
    final NormalizationType normalizationType = extCom.getOperatingPer();
    if (normalizationType != null) {
        aux = UnsignedBytes.checkedCast(normalizationType.getIntValue());
        aux = (byte) (aux << FIVE_BITS_SHIFT);
        res[res.length - 1] = (byte) (res[res.length - 1] | aux);
    }
    ByteBufWriteUtil.writeUnsignedShort((int) res[res.length - 1], body);
    ByteBufWriteUtil.writeUnsignedShort(extCom.getL2Mtu(), body);
    body.writeZero(RESERVED);
}
Also used : Layer2AttributesExtendedCommunityCase(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) NormalizationType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.NormalizationType) BitArray(org.opendaylight.protocol.util.BitArray) Layer2AttributesExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunity) OperationalMode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.OperationalMode)

Example 2 with Layer2AttributesExtendedCommunityCase

use of 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 in project bgpcep by opendaylight.

the class Layer2AttributesExtComTest method evpnVpwsTest.

@Test
public void evpnVpwsTest() throws BGPParsingException, BGPDocumentedException {
    final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
    final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder().setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true).setControlWord(true).setPrimaryPe(true).setL2Mtu(257).setModeOfOperation(OperationalMode.VlanAwareFxc).setOperatingPer(NormalizationType.SingleVid).build()).build();
    this.parser.serializeExtendedCommunity(expected, buff);
    final byte[] resultByte = ByteArray.getAllBytes(buff);
    assertArrayEquals(EVPN_VPWS, resultByte);
    final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS));
    assertEquals(expected, result);
    final ByteBuf buff2 = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
    final Layer2AttributesExtendedCommunityCase expected2 = new Layer2AttributesExtendedCommunityCaseBuilder().setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true).setControlWord(true).setPrimaryPe(true).setL2Mtu(257).setModeOfOperation(OperationalMode.VlanUnawareFxc).setOperatingPer(NormalizationType.DoubleVid).build()).build();
    this.parser.serializeExtendedCommunity(expected2, buff2);
    final byte[] resultByte2 = ByteArray.getAllBytes(buff2);
    assertArrayEquals(EVPN_VPWS_2, resultByte2);
    final ExtendedCommunity result2 = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EVPN_VPWS_2));
    assertEquals(expected2, result2);
}
Also used : Layer2AttributesExtendedCommunityCase(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) ExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity) Layer2AttributesExtendedCommunityCaseBuilder(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) ByteBuf(io.netty.buffer.ByteBuf) Layer2AttributesExtendedCommunityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder) Test(org.junit.Test)

Example 3 with Layer2AttributesExtendedCommunityCase

use of 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 in project bgpcep by opendaylight.

the class Layer2AttributesExtComTest method handlerTest.

@Test
public void handlerTest() throws BGPParsingException, BGPDocumentedException {
    final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
    final Layer2AttributesExtendedCommunityCase expected = new Layer2AttributesExtendedCommunityCaseBuilder().setLayer2AttributesExtendedCommunity(new Layer2AttributesExtendedCommunityBuilder().setBackupPe(true).setControlWord(true).setPrimaryPe(true).setL2Mtu(257).build()).build();
    this.parser.serializeExtendedCommunity(expected, buff);
    final byte[] resultByte = ByteArray.getAllBytes(buff);
    assertArrayEquals(EXPECTEDS, resultByte);
    final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(EXPECTEDS));
    assertEquals(expected, result);
}
Also used : Layer2AttributesExtendedCommunityCase(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) ExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity) Layer2AttributesExtendedCommunityCaseBuilder(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) ByteBuf(io.netty.buffer.ByteBuf) Layer2AttributesExtendedCommunityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder) Test(org.junit.Test)

Aggregations

Layer2AttributesExtendedCommunityCase (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)3 ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 Layer2AttributesExtendedCommunityCaseBuilder (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)2 Layer2AttributesExtendedCommunityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunityBuilder)2 ExtendedCommunity (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity)2 BitArray (org.opendaylight.protocol.util.BitArray)1 NormalizationType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.NormalizationType)1 OperationalMode (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.OperationalMode)1 Layer2AttributesExtendedCommunity (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.layer._2.attributes.extended.community.Layer2AttributesExtendedCommunity)1