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.vpnservice;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
17 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class VpnManager extends AbstractDataChangeListener<VpnInstance> implements AutoCloseable {
22 private static final Logger LOG = LoggerFactory.getLogger(VpnManager.class);
23 private ListenerRegistration<DataChangeListener> listenerRegistration;
24 private final DataBroker broker;
27 * Listens for data change related to VPN Instance
28 * Informs the BGP about VRF information
30 * @param db - dataBroker reference
32 public VpnManager(final DataBroker db) {
33 super(VpnInstance.class);
38 private void registerListener(final DataBroker db) {
40 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
41 getWildCardPath(), VpnManager.this, DataChangeScope.SUBTREE);
42 } catch (final Exception e) {
43 LOG.error("VPN Service DataChange listener registration fail!", e);
44 throw new IllegalStateException("VPN Service registration Listener failed.", e);
49 protected void remove(InstanceIdentifier<VpnInstance> identifier,
51 // TODO Auto-generated method stub
55 protected void update(InstanceIdentifier<VpnInstance> identifier,
56 VpnInstance original, VpnInstance update) {
57 // TODO Auto-generated method stub
61 protected void add(InstanceIdentifier<VpnInstance> identifier,
63 LOG.info("key: " + identifier + ", value=" + value);
64 //TODO: Generate VPN ID for this instance, where to store in model ... ?
66 //TODO: Add VRF to BGP
69 private InstanceIdentifier<?> getWildCardPath() {
70 return InstanceIdentifier.create(VpnInstances.class).child(VpnInstance.class);
74 public void close() throws Exception {
75 if (listenerRegistration != null) {
77 listenerRegistration.close();
78 } catch (final Exception e) {
79 LOG.error("Error when cleaning up DataChangeListener.", e);
81 listenerRegistration = null;
83 LOG.info("VPN Manager Closed");