/** * Check for presence of well known mandatory attribute LOCAL_PREF in Update message * * @param message Update message * @throws BGPDocumentedException */ private void checkMandatoryAttributesPresence(final Update message) throws BGPDocumentedException { if (MessageUtil.isAnyNlriPresent(message)) { final Attributes attrs = message.getAttributes(); if (this.peerRole == PeerRole.Ibgp && (attrs == null || attrs.getLocalPref() == null)) { throw new BGPDocumentedException(BGPError.MANDATORY_ATTR_MISSING_MSG + "LOCAL_PREF", BGPError.WELL_KNOWN_ATTR_MISSING, new byte[] { LocalPreferenceAttributeParser.TYPE }); } } }
/** * Serializes BGP Notification message. * * @param msg to be serialized * @param bytes ByteBuf where the message will be serialized */ @Override public void serializeMessage(final Notification msg, final ByteBuf bytes) { Preconditions.checkArgument(msg instanceof Notify, "Message needs to be of type Notify"); final Notify ntf = (Notify) msg; final ByteBuf msgBody = Unpooled.buffer(); msgBody.writeByte(ntf.getErrorCode()); msgBody.writeByte(ntf.getErrorSubcode()); final byte[] data = ntf.getData(); if (data != null) { msgBody.writeBytes(data); } LOG.trace("Notification message serialized to: {}", ByteBufUtil.hexDump(msgBody)); MessageUtil.formatMessage(TYPE, msgBody, bytes); }
mpReach = prefixesToMpReach(message); } else { mpReach = MessageUtil.getMpReachNlri(attrs); mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced); } else { mpUnreach = MessageUtil.getMpUnreachNlri(attrs);
if (MessageUtil.isAnyNlriPresent(message)) { if (attrs == null || attrs.getOrigin() == null) { throw new BGPDocumentedException(BGPError.MANDATORY_ATTR_MISSING_MSG + "ORIGIN",
/** * Serializes BGP Route Refresh message. * * @param message to be serialized * @param bytes ByteBuf where the message will be serialized */ @Override public void serializeMessage(final Notification message, final ByteBuf bytes) { Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh."); final RouteRefresh msg = (RouteRefresh) message; final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE); MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(), msgBuf); LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf)); MessageUtil.formatMessage(TYPE, msgBuf, bytes); }
/** * Serializes given BGP Open message to byte array, without the header. * * @param msg BGP Open message to be serialized. * @param bytes ByteBuf where the message will be serialized */ @Override public void serializeMessage(final Notification msg, final ByteBuf bytes) { Preconditions.checkArgument(msg instanceof Open, "Message needs to be of type Open"); final Open open = (Open) msg; final ByteBuf msgBody = Unpooled.buffer(); msgBody.writeByte(BGP_VERSION); // When our AS number does not fit into two bytes, we report it as AS_TRANS int openAS = open.getMyAsNumber(); if (openAS > Values.UNSIGNED_SHORT_MAX_VALUE) { openAS = AS_TRANS; } msgBody.writeShort(openAS); msgBody.writeShort(open.getHoldTimer()); msgBody.writeBytes(Ipv4Util.bytesForAddress(open.getBgpIdentifier())); final ByteBuf paramsBuffer = Unpooled.buffer(); if (open.getBgpParameters() != null) { for (final BgpParameters param : open.getBgpParameters()) { this.reg.serializeParameter(param, paramsBuffer); } } msgBody.writeByte(paramsBuffer.writerIndex()); msgBody.writeBytes(paramsBuffer); MessageUtil.formatMessage(TYPE, msgBody, bytes); }
MessageUtil.formatMessage(TYPE, messageBody, bytes);