2 * Copyright (c) 2013 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
11 * Generated from: yang module name: bgp-rib-impl yang module local name: bgp-peer
12 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13 * Generated at: Sat Jan 25 11:00:14 CET 2014
15 * Do not modify this file unless it is present under src/main directory
17 package org.opendaylight.controller.config.yang.bgp.rib.impl;
19 import java.net.InetSocketAddress;
20 import java.util.List;
22 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
23 import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
24 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
25 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParametersBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.as4.bytes._case.As4BytesCapabilityBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.multiprotocol._case.MultiprotocolCapabilityBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import com.google.common.collect.Lists;
39 import com.google.common.net.InetAddresses;
44 public final class BGPPeerModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerModule
46 private static final Logger LOG = LoggerFactory.getLogger(BGPPeerModule.class);
48 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
49 super(identifier, dependencyResolver);
52 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
53 final BGPPeerModule oldModule, final java.lang.AutoCloseable oldInstance) {
55 super(identifier, dependencyResolver, oldModule, oldInstance);
59 protected void customValidation(){
60 JmxAttributeValidationException.checkNotNull(getHost(),
61 "value is not set.", hostJmxAttribute);
62 JmxAttributeValidationException.checkNotNull(getPort(),
63 "value is not set.", portJmxAttribute);
66 private InetSocketAddress createAddress() {
67 final IpAddress ip = getHost();
68 if (ip.getIpv4Address() != null) {
69 return new InetSocketAddress(InetAddresses.forString(ip.getIpv4Address().getValue()), getPort().getValue());
70 } else if (ip.getIpv6Address() != null) {
71 return new InetSocketAddress(InetAddresses.forString(ip.getIpv6Address().getValue()), getPort().getValue());
73 throw new IllegalStateException("Failed to handle host " + getHost());
77 private static String peerName(final IpAddress host) {
78 if (host.getIpv4Address() != null) {
79 return host.getIpv4Address().getValue();
81 if (host.getIpv6Address() != null) {
82 return host.getIpv6Address().getValue();
89 public java.lang.AutoCloseable createInstance() {
90 final RIB r = getRibDependency();
92 final List<BgpParameters> tlvs = Lists.newArrayList();
93 tlvs.add(new BgpParametersBuilder().setCParameters(
94 new As4BytesCaseBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(r.getLocalAs()).build()).build()).build());
96 for (final BgpTableType t : getAdvertizedTableDependency()) {
97 if (!r.getLocalTables().contains(t)) {
98 LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", t);
101 tlvs.add(new BgpParametersBuilder().setCParameters(
102 new MultiprotocolCaseBuilder().setMultiprotocolCapability(
103 new MultiprotocolCapabilityBuilder(t).build()).build()).build());
106 // Remote AS number defaults to our local AS
107 final AsNumber remoteAs;
108 if (getRemoteAs() != null) {
109 remoteAs = new AsNumber(getRemoteAs());
111 remoteAs = r.getLocalAs();
114 return new BGPPeer(peerName(getHost()), createAddress(),
115 new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), tlvs), remoteAs, r);