76bdb6e863da34888a828b67fdc2afa3de976388
[vpnservice.git] / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / vpnservice / elan / l2gw / internal / ElanL2GatewayProvider.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.vpnservice.elan.l2gw.internal;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.elanmanager.utils.ElanL2GwCacheUtils;
15 import org.opendaylight.vpnservice.elan.internal.ElanInstanceManager;
16 import org.opendaylight.vpnservice.elan.internal.ElanInterfaceManager;
17 import org.opendaylight.vpnservice.elan.internal.ElanServiceProvider;
18 import org.opendaylight.vpnservice.elan.l2gw.listeners.HwvtepLocalUcastMacListener;
19 import org.opendaylight.vpnservice.elan.l2gw.listeners.HwvtepNodeListener;
20 import org.opendaylight.vpnservice.elan.l2gw.listeners.L2GatewayConnectionListener;
21 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
22 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
24 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * Elan L2 Gateway provider class.
30  */
31 public class ElanL2GatewayProvider implements AutoCloseable {
32
33     private static final Logger LOG = LoggerFactory.getLogger(ElanL2GatewayProvider.class);
34
35     private DataBroker broker;
36     private EntityOwnershipService entityOwnershipService;
37     private BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
38     private ItmRpcService itmRpcService;
39     private ElanInstanceManager elanInstanceManager;
40     private ElanInterfaceManager elanInterfaceManager;
41
42     private L2GatewayConnectionListener l2GwConnListener;
43     private HwvtepNodeListener hwvtepNodeListener;
44     private HwvtepLocalUcastMacListener torMacsListener;
45
46     /**
47      * Instantiates a new elan l2 gateway provider.
48      *
49      * @param elanServiceProvider
50      *            the elan service provider
51      */
52     public ElanL2GatewayProvider(ElanServiceProvider elanServiceProvider) {
53         this.broker = elanServiceProvider.getBroker();
54         this.entityOwnershipService = elanServiceProvider.getEntityOwnershipService();
55         this.bindingNormalizedNodeSerializer = elanServiceProvider.getBindingNormalizedNodeSerializer();
56         this.itmRpcService = elanServiceProvider.getItmRpcService();
57         this.elanInstanceManager = elanServiceProvider.getElanInstanceManager();
58         this.elanInterfaceManager = elanServiceProvider.getElanInterfaceManager();
59
60         init();
61
62         LOG.info("ElanL2GatewayProvider Initialized");
63     }
64
65     /**
66      * Initialize Elan L2 Gateway.
67      */
68     private void init() {
69         ElanL2GwCacheUtils.createElanL2GwDeviceCache();
70         ElanL2GatewayUtils.setDataBroker(broker);
71         ElanL2GatewayUtils.setItmRpcService(itmRpcService);
72
73         ElanL2GatewayMulticastUtils.setBroker(broker);
74         ElanL2GatewayMulticastUtils.setElanInstanceManager(elanInstanceManager);
75         ElanL2GatewayMulticastUtils.setElanInterfaceManager(elanInterfaceManager);
76
77         this.torMacsListener = new HwvtepLocalUcastMacListener(broker, entityOwnershipService,
78                 bindingNormalizedNodeSerializer);
79         this.l2GwConnListener = new L2GatewayConnectionListener(broker, entityOwnershipService,
80                 bindingNormalizedNodeSerializer, elanInstanceManager);
81         this.hwvtepNodeListener = new HwvtepNodeListener(broker, entityOwnershipService,
82                 bindingNormalizedNodeSerializer, elanInstanceManager, itmRpcService);
83         this.hwvtepNodeListener.registerListener(LogicalDatastoreType.OPERATIONAL, broker);
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see java.lang.AutoCloseable#close()
90      */
91     @Override
92     public void close() throws Exception {
93         this.torMacsListener.close();
94         this.l2GwConnListener.close();
95         this.hwvtepNodeListener.close();
96         LOG.info("ElanL2GatewayProvider Closed");
97     }
98 }