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;
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.BGPSessionPreferences;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionValidator;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Validates Bgp sessions established from current device to remote.
26 public class BGPClientSessionValidator implements BGPSessionValidator {
28 private static final Logger LOG = LoggerFactory.getLogger(BGPClientSessionValidator.class);
30 private final AsNumber remoteAs;
32 public BGPClientSessionValidator(final AsNumber remoteAs) {
33 this.remoteAs = remoteAs;
37 * Validates with exception:
39 * <li>correct remote AS attribute</li>
40 * <li>non empty BgpParameters collection</li>
43 * Validates with log message:
45 * <li>local BgpParameters are superset of remote BgpParameters</li>
49 public void validate(final Open openObj, final BGPSessionPreferences localPref) throws BGPDocumentedException {
50 final AsNumber as = AsNumberUtil.advertizedAsNumber(openObj);
51 if (!this.remoteAs.equals(as)) {
52 LOG.warn("Unexpected remote AS number. Expecting {}, got {}", this.remoteAs, as);
53 throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
56 final List<BgpParameters> prefs = openObj.getBgpParameters();
57 if (prefs != null && !prefs.isEmpty()) {
58 if (!prefs.containsAll(localPref.getParams())) {
59 LOG.info("BGP Open message session parameters differ, session still accepted.");
62 throw new BGPDocumentedException("Open message unacceptable. Check the configuration of BGP speaker.", BGPError.UNSPECIFIC_OPEN_ERROR);