2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.bgpmanager;
10 import java.util.Collections;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.bgp.rev130715.BgpRouter;
22 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.bgp.rev130715.BgpNeighbors;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Optional;
27 import com.google.common.base.Preconditions;
29 public class BgpConfigurationManager {
30 private static final Logger LOG = LoggerFactory.getLogger(BgpConfigurationManager.class);
31 private ListenerRegistration<DataChangeListener> listenerRegistration;
32 private final DataBroker broker;
34 public BgpConfigurationManager(final DataBroker db) {
36 BgpRtrCfgManager rtrCfgManager = new BgpRtrCfgManager(db);
37 BgpNghbrCfgManager nghbrCfgManager = new BgpNghbrCfgManager(db);
40 public class BgpRtrCfgManager extends AbstractDataChangeListener<BgpRouter> implements AutoCloseable {
42 public BgpRtrCfgManager(final DataBroker db) {
43 super(BgpRouter.class);
47 private void registerListener(final DataBroker db) {
49 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
50 getWildCardPath(), BgpRtrCfgManager.this, DataChangeScope.SUBTREE);
51 } catch (final Exception e) {
52 LOG.error("BGP Configuration DataChange listener registration fail!", e);
53 throw new IllegalStateException("BGP Configuration registration Listener failed.", e);
58 protected void remove(InstanceIdentifier<BgpRouter> identifier,
60 // TODO Auto-generated method stub
64 protected void update(InstanceIdentifier<BgpRouter> identifier,
65 BgpRouter original, BgpRouter update) {
66 // TODO Auto-generated method stub
70 protected void add(InstanceIdentifier<BgpRouter> identifier,
72 LOG.info("key: " + identifier + ", value=" + value);
76 private InstanceIdentifier<BgpRouter> getWildCardPath() {
77 return InstanceIdentifier.create(BgpRouter.class);
81 public void close() throws Exception {
82 if (listenerRegistration != null) {
84 listenerRegistration.close();
85 } catch (final Exception e) {
86 LOG.error("Error when cleaning up DataChangeListener.", e);
88 listenerRegistration = null;
90 LOG.info("Bgp Router Manager Closed");
94 public class BgpNghbrCfgManager extends AbstractDataChangeListener<BgpNeighbors> implements AutoCloseable {
96 public BgpNghbrCfgManager(final DataBroker db) {
97 super(BgpNeighbors.class);
101 private void registerListener(final DataBroker db) {
103 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
104 getWildCardPath(), BgpNghbrCfgManager.this, DataChangeScope.SUBTREE);
105 } catch (final Exception e) {
106 LOG.error("BGP Neighbor DataChange listener registration fail!", e);
107 throw new IllegalStateException("BGP Neighbor registration Listener failed.", e);
112 protected void remove(InstanceIdentifier<BgpNeighbors> identifier,
114 // TODO Auto-generated method stub
118 protected void update(InstanceIdentifier<BgpNeighbors> identifier,
119 BgpNeighbors original, BgpNeighbors update) {
120 // TODO Auto-generated method stub
124 protected void add(InstanceIdentifier<BgpNeighbors> identifier,
125 BgpNeighbors value) {
126 LOG.info("key: " + identifier + ", value=" + value);
130 private InstanceIdentifier<?> getWildCardPath() {
131 return InstanceIdentifier.create(BgpNeighbors.class);
135 public void close() throws Exception {
136 if (listenerRegistration != null) {
138 listenerRegistration.close();
139 } catch (final Exception e) {
140 LOG.error("Error when cleaning up DataChangeListener.", e);
142 listenerRegistration = null;
144 LOG.info("Bgp Neighbor Manager Closed");