use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType in project bgpcep by opendaylight.
the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.
protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
final PeerType peerType = PeerType.forValue(bytes.readByte());
phBuilder.setType(peerType);
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
phBuilder.setIpv4(!flags.get(V_FLAG_POS));
switch(peerType) {
case L3vpn:
phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
break;
case Local:
phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
break;
case Global:
default:
bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
break;
}
if (phBuilder.getIpv4()) {
bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
phBuilder.setAddress(new IpAddressNoZone(Ipv4Util.addressForByteBuf(bytes)));
} else {
phBuilder.setAddress(new IpAddressNoZone(Ipv6Util.addressForByteBuf(bytes)));
}
phBuilder.setAs(new AsNumber(ByteBufUtils.readUint32(bytes)));
phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
phBuilder.setTimestampSec(new Timestamp(ByteBufUtils.readUint32(bytes)));
phBuilder.setTimestampMicro(new Timestamp(ByteBufUtils.readUint32(bytes)));
return phBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType in project bgpcep by opendaylight.
the class AbstractBmpPerPeerMessageParser method serializePerPeerHeader.
protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
checkArgument(peerHeader != null, "Per-peer header cannot be null.");
final PeerType peerType = peerHeader.getType();
output.writeByte(peerType.getIntValue());
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() != 0);
flags.set(V_FLAG_POS, !peerHeader.getIpv4());
flags.toByteBuf(output);
final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
switch(peerType) {
case L3vpn:
RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
break;
case Local:
output.writeBytes(peerDistinguisher.getBinary());
break;
case Global:
default:
output.writeZero(PEER_DISTINGUISHER_SIZE);
break;
}
if (peerHeader.getIpv4()) {
output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
Ipv4Util.writeIpv4Address(peerHeader.getAddress().getIpv4AddressNoZone(), output);
} else {
Ipv6Util.writeIpv6Address(peerHeader.getAddress().getIpv6AddressNoZone(), output);
}
ByteBufUtils.write(output, peerHeader.getAs().getValue());
Ipv4Util.writeIpv4Address(peerHeader.getBgpId(), output);
final Timestamp stampSec = peerHeader.getTimestampSec();
if (stampSec != null) {
ByteBufUtils.write(output, stampSec.getValue());
} else {
output.writeInt(0);
}
final Timestamp stampMicro = peerHeader.getTimestampMicro();
if (stampMicro != null) {
ByteBufUtils.write(output, stampMicro.getValue());
} else {
output.writeInt(0);
}
}
Aggregations