cf5214c5a01b36660e7d6f8ea47bdcd7a97471e3
[netvirt.git] /
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.listeners;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
13 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class L2GatewayConnectionListener extends AsyncClusteredDataTreeChangeListenerBase<L2gatewayConnection,
22         L2GatewayConnectionListener> {
23     private static final Logger LOG = LoggerFactory.getLogger(L2GatewayConnectionListener.class);
24
25     private final DataBroker broker;
26     private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
27
28     public L2GatewayConnectionListener(final DataBroker db, L2GatewayConnectionUtils l2GatewayConnectionUtils) {
29         super(L2gatewayConnection.class, L2GatewayConnectionListener.class);
30         this.broker = db;
31         this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
32     }
33
34     public void init() {
35         registerListener(LogicalDatastoreType.CONFIGURATION, broker);
36     }
37
38     @Override
39     protected void add(final InstanceIdentifier<L2gatewayConnection> identifier, final L2gatewayConnection input) {
40         LOG.trace("Adding L2gatewayConnection: {}", input);
41
42         // Get associated L2GwId from 'input'
43         // Create logical switch in each of the L2GwDevices part of L2Gw
44         // Logical switch name is network UUID
45         // Add L2GwDevices to ELAN
46         l2GatewayConnectionUtils.addL2GatewayConnection(input);
47     }
48
49     @Override
50     protected void remove(InstanceIdentifier<L2gatewayConnection> identifier, L2gatewayConnection input) {
51         LOG.trace("Removing L2gatewayConnection: {}", input);
52
53         l2GatewayConnectionUtils.deleteL2GatewayConnection(input);
54     }
55
56     @Override
57     protected void update(InstanceIdentifier<L2gatewayConnection> identifier, L2gatewayConnection original,
58             L2gatewayConnection update) {
59         LOG.trace("Updating L2gatewayConnection : original value={}, updated value={}", original, update);
60     }
61
62     @Override
63     protected InstanceIdentifier<L2gatewayConnection> getWildCardPath() {
64         return InstanceIdentifier.create(Neutron.class).child(L2gatewayConnections.class)
65             .child(L2gatewayConnection.class);
66     }
67
68     @Override
69     protected L2GatewayConnectionListener getDataTreeChangeListener() {
70         return this;
71     }
72 }