Neutron port listener updated to support allowed address pair with security group...
[netvirt.git] / vpnservice / dhcpservice / dhcpservice-impl / src / main / java / org / opendaylight / netvirt / dhcpservice / DhcpProvider.java
1 /*
2  * Copyright (c) 2015 - 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 package org.opendaylight.netvirt.dhcpservice;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
17 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class DhcpProvider implements BindingAwareProvider, AutoCloseable {
26
27     private static final Logger LOG = LoggerFactory.getLogger(DhcpProvider.class);
28     private IMdsalApiManager mdsalManager;
29     private DhcpPktHandler dhcpPktHandler;
30     private Registration packetListener = null;
31     private NotificationProviderService notificationService;
32     private DhcpManager dhcpManager;
33     private NodeListener dhcpNodeListener;
34     private INeutronVpnManager neutronVpnManager;
35     private DhcpConfigListener dhcpConfigListener;
36     private OdlInterfaceRpcService interfaceManagerRpc;
37     private DhcpInterfaceEventListener dhcpInterfaceEventListener;
38     private DhcpExternalTunnelManager dhcpExternalTunnelManager;
39     private DhcpNeutronPortListener dhcpNeutronPortListener;
40     private DhcpLogicalSwitchListener dhcpLogicalSwitchListener;
41     private DhcpUCastMacListener dhcpUCastMacListener;
42     private ItmRpcService itmRpcService;
43     private DhcpInterfaceConfigListener dhcpInterfaceConfigListener;
44     private EntityOwnershipService entityOwnershipService;
45     private DhcpDesignatedDpnListener dhcpDesignatedDpnListener;
46     private DhcpL2GatewayConnectionListener dhcpL2GatewayConnectionListener;
47     private boolean controllerDhcpEnabled = true;
48
49     @Override
50     public void onSessionInitiated(ProviderContext session) {
51         LOG.info("DhcpProvider Session Initiated");
52         try {
53             final DataBroker dataBroker = session.getSALService(DataBroker.class);
54             final PacketProcessingService pktProcessingService = session.getRpcService(PacketProcessingService.class);
55             dhcpManager = new DhcpManager(dataBroker);
56             dhcpManager.setMdsalManager(mdsalManager);
57             dhcpManager.setNeutronVpnService(neutronVpnManager);
58             dhcpExternalTunnelManager = new DhcpExternalTunnelManager(dataBroker, mdsalManager, itmRpcService, entityOwnershipService);
59             dhcpPktHandler = new DhcpPktHandler(dataBroker, dhcpManager, dhcpExternalTunnelManager);
60             dhcpPktHandler.setPacketProcessingService(pktProcessingService);
61             dhcpPktHandler.setInterfaceManagerRpc(interfaceManagerRpc);
62             packetListener = notificationService.registerNotificationListener(dhcpPktHandler);
63             dhcpNodeListener = new NodeListener(dataBroker, dhcpManager, dhcpExternalTunnelManager);
64             dhcpConfigListener = new DhcpConfigListener(dataBroker, dhcpManager);
65             dhcpLogicalSwitchListener = new DhcpLogicalSwitchListener(dhcpExternalTunnelManager, dataBroker);
66             dhcpUCastMacListener = new DhcpUCastMacListener(dhcpExternalTunnelManager, dataBroker);
67             dhcpUCastMacListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
68             dhcpNeutronPortListener = new DhcpNeutronPortListener(dataBroker, dhcpExternalTunnelManager);
69             dhcpNeutronPortListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
70             dhcpDesignatedDpnListener = new DhcpDesignatedDpnListener(dhcpExternalTunnelManager, dataBroker);
71             dhcpDesignatedDpnListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
72             dhcpL2GatewayConnectionListener = new DhcpL2GatewayConnectionListener(dataBroker, dhcpExternalTunnelManager);
73             dhcpL2GatewayConnectionListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
74
75             if (controllerDhcpEnabled) {
76                 dhcpInterfaceEventListener = new DhcpInterfaceEventListener(dhcpManager, dataBroker, dhcpExternalTunnelManager);
77                 dhcpInterfaceConfigListener = new DhcpInterfaceConfigListener(dataBroker, dhcpExternalTunnelManager);
78             }
79
80         } catch (Exception e) {
81             LOG.error("Error initializing services {}", e);
82         }
83     }
84
85     public void setMdsalManager(IMdsalApiManager mdsalManager) {
86         this.mdsalManager = mdsalManager;
87     }
88
89     public void setNeutronVpnManager(INeutronVpnManager neutronVpnManager) {
90         this.neutronVpnManager = neutronVpnManager;
91     }
92
93     @Override
94     public void close() throws Exception {
95         if(packetListener != null) {
96             packetListener.close();
97         }
98         if(dhcpPktHandler != null) {
99             dhcpPktHandler.close();
100         }
101         if(dhcpNodeListener != null) {
102             dhcpNodeListener.close();
103         }
104         LOG.info("DhcpProvider closed");
105     }
106
107     public void setNotificationProviderService(NotificationProviderService notificationServiceDependency) {
108         this.notificationService = notificationServiceDependency;
109     }
110
111     public void setInterfaceManagerRpc(OdlInterfaceRpcService interfaceManagerRpc) {
112         this.interfaceManagerRpc = interfaceManagerRpc;
113     }
114
115     public void setItmRpcService(ItmRpcService itmRpcService) {
116         this.itmRpcService = itmRpcService;
117     }
118
119     public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
120         this.entityOwnershipService = entityOwnershipService;
121     }
122
123     public void setControllerDhcpEnabled(boolean controllerDhcpEnabled) {
124         this.controllerDhcpEnabled = controllerDhcpEnabled;
125     }
126 }