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);
72 RouterInterfaceListener routerListener = new RouterInterfaceListener(dataBroker);
73 routerListener.setVpnInterfaceManager(vpnInterfaceManager);
74 } catch (Exception e) {
75 LOG.error("Error initializing services", e);
79 public void setNotificationService(NotificationService notificationService) {
80 this.notificationService = notificationService;
83 public void setBgpManager(IBgpManager bgpManager) {
84 LOG.debug("BGP Manager reference initialized");
85 this.bgpManager = bgpManager;
88 public void setMdsalManager(IMdsalApiManager mdsalManager) {
89 this.mdsalManager = mdsalManager;
92 public void setInterfaceManager(OdlInterfaceRpcService interfaceManager) {
93 this.interfaceManager = interfaceManager;
96 public void setITMProvider(ItmRpcService itmProvider) {
97 this.itmProvider = itmProvider;
100 public void setIdManager(IdManagerService idManager) {
101 this.idManager = idManager;
104 public void setArpManager(OdlArputilService arpManager) {
105 this.arpManager = arpManager;
108 private void createIdPool() {
109 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
110 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
111 .setLow(VpnConstants.VPN_IDPOOL_START)
112 .setHigh(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE).longValue())
115 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
116 if ((result != null) && (result.get().isSuccessful())) {
117 LOG.debug("Created IdPool for VPN Service");
119 } catch (InterruptedException | ExecutionException e) {
120 LOG.error("Failed to create idPool for VPN Service",e);
125 public void close() throws Exception {
127 vpnInterfaceManager.close();
132 public void setFibService(IFibManager fibManager) {
133 LOG.debug("Fib service reference is initialized in VPN Manager");
134 this.fibManager = fibManager;
135 vpnInterfaceManager.setFibManager(fibManager);
139 public void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
140 LOG.info("Adding extra route with destination {} and nexthop {}", destination, nextHop);
141 vpnInterfaceManager.addExtraRoute(destination, nextHop, rd, routerID, label, null);
145 public void delExtraRoute(String destination, String rd, String routerID) {
146 LOG.info("Deleting extra route with destination {}", destination);
147 vpnInterfaceManager.delExtraRoute(destination, rd, routerID);
151 public boolean existsVpn(String vpnName) {
152 return vpnManager.getVpnInstance(vpnName) != null;
156 public boolean isVPNConfigured() {
157 return vpnManager.isVPNConfigured();