2 * Copyright (c) 2015 - 2016 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.netvirt.vpnmanager;
10 import java.math.BigInteger;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
19 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
20 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
22 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class VpnserviceProvider implements BindingAwareProvider, IVpnManager, AutoCloseable {
36 private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
37 private VpnInterfaceManager vpnInterfaceManager;
38 private VpnManager vpnManager;
39 private IBgpManager bgpManager;
40 private IFibManager fibManager;
41 private IMdsalApiManager mdsalManager;
42 private OdlInterfaceRpcService interfaceManager;
43 private ItmRpcService itmProvider;
44 private IdManagerService idManager;
45 private OdlArputilService arpManager;
46 private NeutronvpnService neuService;
47 private PacketProcessingService m_packetProcessingService;
48 private SubnetRoutePacketInHandler subnetRoutePacketInHandler;
49 private NotificationService notificationService;
52 public void onSessionInitiated(ProviderContext session) {
53 LOG.info("VpnserviceProvider Session Initiated");
55 final DataBroker dataBroker = session.getSALService(DataBroker.class);
56 vpnManager = new VpnManager(dataBroker, bgpManager);
57 vpnManager.setIdManager(idManager);
58 vpnInterfaceManager = new VpnInterfaceManager(dataBroker, bgpManager, notificationService);
59 vpnInterfaceManager.setMdsalManager(mdsalManager);
60 vpnInterfaceManager.setInterfaceManager(interfaceManager);
61 vpnInterfaceManager.setITMProvider(itmProvider);
62 vpnInterfaceManager.setIdManager(idManager);
63 vpnInterfaceManager.setArpManager(arpManager);
64 vpnInterfaceManager.setNeutronvpnManager(neuService);
65 //Handles subnet route entries
66 subnetRoutePacketInHandler = new SubnetRoutePacketInHandler(dataBroker, idManager);
67 m_packetProcessingService = session.getRpcService(PacketProcessingService.class);
68 subnetRoutePacketInHandler.setPacketProcessingService(m_packetProcessingService);
69 notificationService.registerNotificationListener(subnetRoutePacketInHandler);
70 vpnManager.setVpnInterfaceManager(vpnInterfaceManager);
73 RouterInterfaceListener routerListener = new RouterInterfaceListener(dataBroker);
74 routerListener.setVpnInterfaceManager(vpnInterfaceManager);
75 } catch (Exception e) {
76 LOG.error("Error initializing services", e);
80 public void setNotificationService(NotificationService notificationService) {
81 this.notificationService = notificationService;
84 public void setBgpManager(IBgpManager bgpManager) {
85 LOG.debug("BGP Manager reference initialized");
86 this.bgpManager = bgpManager;
89 public void setMdsalManager(IMdsalApiManager mdsalManager) {
90 this.mdsalManager = mdsalManager;
93 public void setInterfaceManager(OdlInterfaceRpcService interfaceManager) {
94 this.interfaceManager = interfaceManager;
97 public void setITMProvider(ItmRpcService itmProvider) {
98 this.itmProvider = itmProvider;
101 public void setIdManager(IdManagerService idManager) {
102 this.idManager = idManager;
105 public void setArpManager(OdlArputilService arpManager) {
106 this.arpManager = arpManager;
109 private void createIdPool() {
110 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
111 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
112 .setLow(VpnConstants.VPN_IDPOOL_START)
113 .setHigh(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE).longValue())
116 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
117 if ((result != null) && (result.get().isSuccessful())) {
118 LOG.debug("Created IdPool for VPN Service");
120 } catch (InterruptedException | ExecutionException e) {
121 LOG.error("Failed to create idPool for VPN Service",e);
126 public void close() throws Exception {
128 vpnInterfaceManager.close();
133 public void setFibService(IFibManager fibManager) {
134 LOG.debug("Fib service reference is initialized in VPN Manager");
135 this.fibManager = fibManager;
136 vpnInterfaceManager.setFibManager(fibManager);
140 public void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
141 LOG.info("Adding extra route with destination {} and nexthop {}", destination, nextHop);
142 vpnInterfaceManager.addExtraRoute(destination, nextHop, rd, routerID, label, null);
146 public void delExtraRoute(String destination, String rd, String routerID) {
147 LOG.info("Deleting extra route with destination {}", destination);
148 vpnInterfaceManager.delExtraRoute(destination, rd, routerID);
152 public boolean existsVpn(String vpnName) {
153 if (vpnManager != null) {
154 return vpnManager.getVpnInstance(vpnName) != null;
156 LOG.info("Could not acquire handle to vpnManager, returning false for existsVpn({})", vpnName);
161 public boolean isVPNConfigured() {
162 return vpnManager.isVPNConfigured();