2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.vpnservice;
\r
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
11 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
\r
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
\r
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
\r
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
16 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
\r
17 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
\r
18 import org.slf4j.Logger;
\r
19 import org.slf4j.LoggerFactory;
\r
21 public class VpnManager extends AbstractDataChangeListener<VpnInstance> implements AutoCloseable {
\r
22 private static final Logger LOG = LoggerFactory.getLogger(VpnManager.class);
\r
23 private ListenerRegistration<DataChangeListener> listenerRegistration;
\r
24 private final DataBroker broker;
\r
27 * Listens for data change related to VPN Instance
\r
28 * Informs the BGP about VRF information
\r
30 * @param db - dataBroker reference
\r
32 public VpnManager(final DataBroker db) {
\r
33 super(VpnInstance.class);
\r
35 registerListener(db);
\r
38 private void registerListener(final DataBroker db) {
\r
40 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
\r
41 getWildCardPath(), VpnManager.this, DataChangeScope.SUBTREE);
\r
42 } catch (final Exception e) {
\r
43 LOG.error("VPN Service DataChange listener registration fail!", e);
\r
44 throw new IllegalStateException("VPN Service registration Listener failed.", e);
\r
49 protected void remove(InstanceIdentifier<VpnInstance> identifier,
\r
51 // TODO Auto-generated method stub
\r
55 protected void update(InstanceIdentifier<VpnInstance> identifier,
\r
56 VpnInstance original, VpnInstance update) {
\r
57 // TODO Auto-generated method stub
\r
61 protected void add(InstanceIdentifier<VpnInstance> identifier,
\r
62 VpnInstance value) {
\r
63 LOG.info("key: " + identifier + ", value=" + value);
\r
64 //TODO: Generate VPN ID for this instance, where to store in model ... ?
\r
66 //TODO: Add VRF to BGP
\r
69 private InstanceIdentifier<?> getWildCardPath() {
\r
70 return InstanceIdentifier.create(VpnInstances.class).child(VpnInstance.class);
\r
74 public void close() throws Exception {
\r
75 if (listenerRegistration != null) {
\r
77 listenerRegistration.close();
\r
78 } catch (final Exception e) {
\r
79 LOG.error("Error when cleaning up DataChangeListener.", e);
\r
81 listenerRegistration = null;
\r
83 LOG.info("VPN Manager Closed");
\r