use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity in project bgpcep by opendaylight.
the class Layer2AttributesExtCom method parseExtendedCommunity.
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
final BitArray flags = BitArray.valueOf(body, FLAGS_SIZE);
final Layer2AttributesExtendedCommunityBuilder builder = new Layer2AttributesExtendedCommunityBuilder().setBackupPe(flags.get(BACKUP_PE_OFFSET)).setPrimaryPe(flags.get(PRIMARY_PE_OFFSET)).setControlWord(flags.get(CONTROL_WORD_OFFSET)).setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION))).setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE))).setL2Mtu(ByteBufUtils.readUint16(body));
body.skipBytes(RESERVED);
return new Layer2AttributesExtendedCommunityCaseBuilder().setLayer2AttributesExtendedCommunity(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity 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.getPrimaryPe());
flags.set(BACKUP_PE_OFFSET, extCom.getBackupPe());
flags.set(CONTROL_WORD_OFFSET, extCom.getControlWord());
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);
}
body.writeShort(res[res.length - 1]);
ByteBufUtils.writeOrZero(body, extCom.getL2Mtu());
body.writeZero(RESERVED);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity 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(Uint16.valueOf(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(Uint16.valueOf(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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity in project bgpcep by opendaylight.
the class RedirectAsTwoOctetEcHandler method parseExtendedCommunity.
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
final ShortAsNumber as1 = new ShortAsNumber(Uint32.valueOf(ByteBufUtils.readUint16(buffer)));
final byte[] byteValue = ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE);
return new RedirectExtendedCommunityCaseBuilder().setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder().setGlobalAdministrator(as1).setLocalAdministrator(byteValue).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity in project bgpcep by opendaylight.
the class RedirectAsTwoOctetEcHandler method serializeExtendedCommunity.
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
checkArgument(extendedCommunity instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.RedirectExtendedCommunity, "The extended community %s is not RedirectExtendedCommunityCase type.", extendedCommunity);
final RedirectExtendedCommunity redirect = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.RedirectExtendedCommunity) extendedCommunity).getRedirectExtendedCommunity();
byteAggregator.writeShort(redirect.getGlobalAdministrator().getValue().intValue());
byteAggregator.writeBytes(redirect.getLocalAdministrator());
}
Aggregations