private static void validateAs(final AsNumber remoteAs, final Open openObj, final BGPSessionPreferences localPref) throws BGPDocumentedException {
if (!remoteAs.equals(localPref.getExpectedRemoteAs())) {
LOG.warn("Unexpected remote AS number. Expecting {}, got {}", remoteAs, localPref.getExpectedRemoteAs());
throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
}
if (openObj.getBgpIdentifier() != null && openObj.getBgpIdentifier().getValue().equals(localPref.getBgpId().getValue())) {
LOG.warn("Remote and local BGP Identifiers are the same: {}", openObj.getBgpIdentifier());
throw new BGPDocumentedException("Remote and local BGP Identifiers are the same.", BGPError.BAD_BGP_ID);
}
final List<BgpParameters> prefs = openObj.getBgpParameters();
if (prefs != null) {
if (getAs4BytesCapability(localPref.getParams()).isPresent() && !getAs4BytesCapability(prefs).isPresent()) {
throw new BGPDocumentedException("The peer must advertise AS4Bytes capability.", BGPError.UNSUPPORTED_CAPABILITY, serializeAs4BytesCapability(getAs4BytesCapability(localPref.getParams()).get()));
}
if (!prefs.containsAll(localPref.getParams())) {
LOG.info("BGP Open message session parameters differ, session still accepted.");
}
} else {
throw new BGPDocumentedException("Open message unacceptable. Check the configuration of BGP speaker.", BGPError.UNSPECIFIC_OPEN_ERROR);
}
}