2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.rib.impl.client;
11 import java.util.List;
12 import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPError;
15 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionValidator;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Validates Bgp sessions established from current device to remote.
27 public class BGPClientSessionValidator implements BGPSessionValidator {
29 private static final Logger LOG = LoggerFactory.getLogger(BGPClientSessionValidator.class);
31 private final AsNumber remoteAs;
32 private final BGPPeerRegistry peerRegistry;
34 public BGPClientSessionValidator(final AsNumber remoteAs, final BGPPeerRegistry peerRegistry) {
35 this.remoteAs = remoteAs;
36 this.peerRegistry = peerRegistry;
40 * Validates with exception:
42 * <li>correct remote AS attribute</li>
43 * <li>non empty BgpParameters collection</li>
46 * Validates with log message:
48 * <li>local BgpParameters are superset of remote BgpParameters</li>
52 public void validate(final Open openObj, final BGPSessionPreferences localPref) throws BGPDocumentedException {
53 final AsNumber as = AsNumberUtil.advertizedAsNumber(openObj);
54 if (!this.remoteAs.equals(as)) {
55 LOG.warn("Unexpected remote AS number. Expecting {}, got {}", this.remoteAs, as);
56 throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
59 final List<BgpParameters> prefs = openObj.getBgpParameters();
60 if (prefs != null && !prefs.isEmpty()) {
61 if (!prefs.containsAll(localPref.getParams())) {
62 LOG.info("BGP Open message session parameters differ, session still accepted.");
65 throw new BGPDocumentedException("Open message unacceptable. Check the configuration of BGP speaker.", BGPError.UNSPECIFIC_OPEN_ERROR);