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 java.util.Collections;
\r
11 import java.util.Map;
\r
12 import java.util.Set;
\r
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
15 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
\r
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
\r
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
\r
19 import org.opendaylight.yangtools.yang.binding.DataObject;
\r
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
21 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
\r
22 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
\r
23 import org.slf4j.Logger;
\r
24 import org.slf4j.LoggerFactory;
\r
26 import com.google.common.base.Optional;
\r
27 import com.google.common.base.Preconditions;
\r
29 public class VpnManager extends AbstractDataChangeListener<VpnInstance> implements AutoCloseable{
\r
30 private static final Logger LOG = LoggerFactory.getLogger(VpnManager.class);
\r
31 private ListenerRegistration<DataChangeListener> listenerRegistration;
\r
32 private final DataBroker broker;
\r
34 public VpnManager(final DataBroker db) {
\r
35 super(VpnInstance.class);
\r
37 registerListener(db);
\r
40 private void registerListener(final DataBroker db) {
\r
42 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
\r
43 getWildCardPath(), VpnManager.this, DataChangeScope.SUBTREE);
\r
44 } catch (final Exception e) {
\r
45 LOG.error("VPN Service DataChange listener registration fail!", e);
\r
46 throw new IllegalStateException("VPN Service registration Listener failed.", e);
\r
51 protected void remove(InstanceIdentifier<VpnInstance> identifier,
\r
53 // TODO Auto-generated method stub
\r
57 protected void update(InstanceIdentifier<VpnInstance> identifier,
\r
58 VpnInstance original, VpnInstance update) {
\r
59 // TODO Auto-generated method stub
\r
63 protected void add(InstanceIdentifier<VpnInstance> identifier,
\r
64 VpnInstance value) {
\r
65 LOG.info("key: " + identifier + ", value=" + value);
\r
66 //TODO: Generate VPN ID for this instance, where to store in model ... ?
\r
68 //TODO: Add VRF to BGP
\r
71 private InstanceIdentifier<?> getWildCardPath() {
\r
72 return InstanceIdentifier.create(VpnInstances.class).child(VpnInstance.class);
\r
76 public void close() throws Exception {
\r
77 if (listenerRegistration != null) {
\r
79 listenerRegistration.close();
\r
80 } catch (final Exception e) {
\r
81 LOG.error("Error when cleaning up DataChangeListener.", e);
\r
83 listenerRegistration = null;
\r
85 LOG.info("VPN Manager Closed");
\r