import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Values;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param bytes ByteBuf where the message will be serialized
*/
@Override
- public void serializeMessage(final Notification msg, final ByteBuf bytes) {
+ public void serializeMessage(final Notification<?> msg, final ByteBuf bytes) {
checkArgument(msg instanceof Open, "Message needs to be of type Open, not %s", msg);
final Open open = (Open) msg;
final ByteBuf msgBody = Unpooled.buffer()
.writeByte(BGP_VERSION);
// When our AS number does not fit into two bytes, we report it as AS_TRANS
- int openAS = open.getMyAsNumber();
+ int openAS = open.getMyAsNumber().toJava();
if (openAS > Values.UNSIGNED_SHORT_MAX_VALUE) {
openAS = AS_TRANS;
}
msgBody
.writeShort(openAS)
- .writeShort(open.getHoldTimer())
+ .writeShort(open.getHoldTimer().toJava())
.writeBytes(Ipv4Util.bytesForAddress(open.getBgpIdentifier()));
serializeParameters(open.getBgpParameters(), msgBody);
throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.",
BGPError.VERSION_NOT_SUPPORTED);
}
- final AsNumber as = new AsNumber((long) body.readUnsignedShort());
- final int holdTime = body.readUnsignedShort();
- if (holdTime == 1 || holdTime == 2) {
+ final AsNumber as = new AsNumber(Uint32.valueOf(body.readUnsignedShort()));
+ final Uint16 holdTime = ByteBufUtils.readUint16(body);
+ if (Uint16.ONE.equals(holdTime) || Uint16.TWO.equals(holdTime)) {
throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
}
- Ipv4Address bgpId;
+ final Ipv4AddressNoZone bgpId;
try {
bgpId = Ipv4Util.addressForByteBuf(body);
} catch (final IllegalArgumentException e) {
final List<BgpParameters> optParams = parseParameters(body.slice(), optLength);
LOG.debug("BGP Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as,
holdTime, bgpId, optParams);
- return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer(holdTime)
+ return new OpenBuilder().setMyAsNumber(Uint16.valueOf(as.getValue())).setHoldTimer(holdTime)
.setBgpIdentifier(bgpId).setBgpParameters(optParams).build();
}