+ if (msg instanceof Update) {
+ onUpdateMessage((Update) msg);
+ } else {
+ onRouteRefreshMessage((RouteRefresh) msg, session);
+ }
+ }
+
+ private void onRouteRefreshMessage(final RouteRefresh message, final BGPSession session) {
+ final Class<? extends AddressFamily> rrAfi = message.getAfi();
+ final Class<? extends SubsequentAddressFamily> rrSafi = message.getSafi();
+
+ final TablesKey key = new TablesKey(rrAfi, rrSafi);
+ final AdjRibOutListener listener = this.adjRibOutListenerSet.get(key);
+ if (listener != null) {
+ listener.close();
+ this.adjRibOutListenerSet.remove(key);
+ createAdjRibOutListener(RouterIds.createPeerId(session.getBgpId()), key, listener.isMpSupported());
+ } else {
+ LOG.info("Ignoring RouteRefresh message. Afi/Safi is not supported: {}, {}.", rrAfi, rrSafi);
+ }
+ }
+
+ /**
+ * 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 });
+ }
+ }
+ }
+
+ /**
+ * Process Update message received.
+ * Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
+ *
+ * @param message Update message
+ * @throws BGPDocumentedException
+ */
+ private void onUpdateMessage(final Update message) throws BGPDocumentedException {
+ checkMandatoryAttributesPresence(message);
+