use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.pe.distinguisher.labels.attribute.PeDistinguisherLabelAttribute in project bgpcep by opendaylight.
the class PEDistinguisherLabelsAttributeHandler method serializeAttribute.
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final PeDistinguisherLabelsAttributeAugmentation att = attribute.augmentation(PeDistinguisherLabelsAttributeAugmentation.class);
if (att == null) {
return;
}
final List<PeDistinguisherLabelAttribute> distinguishers = att.getPeDistinguisherLabelsAttribute().getPeDistinguisherLabelAttribute();
final ByteBuf buffer = Unpooled.buffer();
for (final PeDistinguisherLabelAttribute peDist : distinguishers) {
if (peDist.getPeAddress().getIpv4AddressNoZone() != null) {
buffer.writeBytes(Ipv4Util.bytesForAddress(peDist.getPeAddress().getIpv4AddressNoZone()));
} else {
buffer.writeBytes(Ipv6Util.bytesForAddress(peDist.getPeAddress().getIpv6AddressNoZone()));
}
buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(peDist.getMplsLabel()));
}
formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, buffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.pe.distinguisher.labels.attribute.PeDistinguisherLabelAttribute in project bgpcep by opendaylight.
the class PEDistinguisherLabelsAttributeHandler method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (readable == 0) {
return;
}
final boolean isIpv4;
final int count;
if (readable % 7 == 0) {
count = readable / 7;
isIpv4 = true;
} else if (readable % 19 == 0) {
count = readable / 19;
isIpv4 = false;
} else {
// as though all the routes contained in this Update had been withdrawn.
throw new BGPTreatAsWithdrawException(BGPError.MALFORMED_ATTR_LIST, "PE Distinguisher Labels has incorrect length %s", readable);
}
final List<PeDistinguisherLabelAttribute> list = new ArrayList<>(count);
for (int i = 0; i < count; ++i) {
final PeDistinguisherLabelAttributeBuilder attribute = new PeDistinguisherLabelAttributeBuilder();
if (isIpv4) {
attribute.setPeAddress(new IpAddressNoZone(Ipv4Util.addressForByteBuf(buffer)));
} else {
attribute.setPeAddress(new IpAddressNoZone(Ipv6Util.addressForByteBuf(buffer)));
}
attribute.setMplsLabel(MplsLabelUtil.mplsLabelForByteBuf(buffer));
list.add(attribute.build());
}
builder.addAugmentation(new PeDistinguisherLabelsAttributeAugmentationBuilder().setPeDistinguisherLabelsAttribute(new PeDistinguisherLabelsAttributeBuilder().setPeDistinguisherLabelAttribute(list).build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.pe.distinguisher.labels.attribute.PeDistinguisherLabelAttribute in project bgpcep by opendaylight.
the class PEDistinguisherLabelsAttributeHandlerTest method buildPEDistinguisherLabelsAttributAttribute.
private static Attributes buildPEDistinguisherLabelsAttributAttribute() {
final List<PeDistinguisherLabelAttribute> peAtt = new ArrayList<>(2);
peAtt.add(new PeDistinguisherLabelAttributeBuilder().setPeAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).setMplsLabel(new MplsLabel(Uint32.ONE)).build());
peAtt.add(new PeDistinguisherLabelAttributeBuilder().setPeAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.2"))).setMplsLabel(new MplsLabel(Uint32.TWO)).build());
return new AttributesBuilder().addAugmentation(new PeDistinguisherLabelsAttributeAugmentationBuilder().setPeDistinguisherLabelsAttribute(new PeDistinguisherLabelsAttributeBuilder().setPeDistinguisherLabelAttribute(peAtt).build()).build()).build();
}
Aggregations