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.NotificationPublishService;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
20 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
21 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
22 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
23 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
24 import org.opendaylight.netvirt.vpnmanager.intervpnlink.InterVpnLinkListener;
25 import org.opendaylight.netvirt.vpnmanager.intervpnlink.InterVpnLinkNodeListener;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
30 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class VpnserviceProvider implements BindingAwareProvider, IVpnManager, AutoCloseable {
43 private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
44 private VpnInterfaceManager vpnInterfaceManager;
45 private VpnManager vpnManager;
46 private ArpScheduler arpscheduler;
47 private IBgpManager bgpManager;
48 private FibRpcService fibService;
49 private IFibManager fibManager;
50 private IMdsalApiManager mdsalManager;
51 private OdlInterfaceRpcService odlInterfaceRpcService;
52 private ItmRpcService itmProvider;
53 private IdManagerService idManager;
54 private OdlArputilService arpManager;
55 private NeutronvpnService neuService;
56 private NotificationService notificationService;
57 private RpcProviderRegistry rpcProviderRegistry;
58 private BindingAwareBroker.RpcRegistration<VpnRpcService> rpcRegistration;
59 private NotificationPublishService notificationPublishService;
60 private PacketProcessingService m_packetProcessingService;
61 private SubnetRoutePacketInHandler subnetRoutePacketInHandler;
62 private InterVpnLinkListener interVpnLinkListener;
63 private DataBroker dataBroker;
64 private InterVpnLinkNodeListener interVpnLinkNodeListener;
68 public void onSessionInitiated(ProviderContext session) {
69 LOG.info("VpnserviceProvider Session Initiated");
71 dataBroker = session.getSALService(DataBroker.class);
72 vpnManager = new VpnManager(dataBroker, bgpManager);
73 vpnManager.setIdManager(idManager);
74 vpnInterfaceManager = new VpnInterfaceManager(dataBroker, bgpManager, notificationService);
75 vpnInterfaceManager.setMdsalManager(mdsalManager);
76 vpnInterfaceManager.setIfaceMgrRpcService(odlInterfaceRpcService);
77 vpnInterfaceManager.setITMProvider(itmProvider);
78 vpnInterfaceManager.setIdManager(idManager);
79 vpnInterfaceManager.setArpManager(arpManager);
80 vpnInterfaceManager.setNeutronvpnManager(neuService);
81 vpnInterfaceManager.setNotificationPublishService(notificationPublishService);
82 vpnManager.setVpnInterfaceManager(vpnInterfaceManager);
83 fibService = rpcProviderRegistry.getRpcService(FibRpcService.class);
84 vpnInterfaceManager.setFibRpcService(fibService);
85 VpnRpcService vpnRpcService = new VpnRpcServiceImpl(idManager, vpnInterfaceManager, dataBroker);
86 rpcRegistration = getRpcProviderRegistry().addRpcImplementation(VpnRpcService.class, vpnRpcService);
87 //Handles subnet route entries
88 subnetRoutePacketInHandler = new SubnetRoutePacketInHandler(dataBroker, idManager);
89 m_packetProcessingService = session.getRpcService(PacketProcessingService.class);
90 subnetRoutePacketInHandler.setPacketProcessingService(m_packetProcessingService);
91 notificationService.registerNotificationListener(subnetRoutePacketInHandler);
92 interVpnLinkListener = new InterVpnLinkListener(dataBroker, idManager, mdsalManager, bgpManager,
93 notificationPublishService);
94 interVpnLinkNodeListener = new InterVpnLinkNodeListener(dataBroker, mdsalManager);
96 RouterInterfaceListener routerListener = new RouterInterfaceListener(dataBroker);
97 arpscheduler = new ArpScheduler(odlInterfaceRpcService, dataBroker);
98 routerListener.setVpnInterfaceManager(vpnInterfaceManager);
99 } catch (Exception e) {
100 LOG.error("Error initializing services", e);
104 public void setNotificationService(NotificationService notificationService) {
105 this.notificationService = notificationService;
108 public void setBgpManager(IBgpManager bgpManager) {
109 LOG.debug("BGP Manager reference initialized");
110 this.bgpManager = bgpManager;
113 public void setMdsalManager(IMdsalApiManager mdsalManager) {
114 this.mdsalManager = mdsalManager;
117 public void setOdlInterfaceRpcService(OdlInterfaceRpcService odlInterfaceRpcService) {
118 this.odlInterfaceRpcService = odlInterfaceRpcService;
121 public void setITMProvider(ItmRpcService itmProvider) {
122 this.itmProvider = itmProvider;
125 public void setIdManager(IdManagerService idManager) {
126 this.idManager = idManager;
129 public void setArpManager(OdlArputilService arpManager) {
130 this.arpManager = arpManager;
133 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
134 this.rpcProviderRegistry = rpcProviderRegistry;
137 private RpcProviderRegistry getRpcProviderRegistry() {
138 return rpcProviderRegistry;
141 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
142 this.notificationPublishService = notificationPublishService;
145 private void createIdPool() {
146 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
147 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
148 .setLow(VpnConstants.VPN_IDPOOL_START)
149 .setHigh(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE).longValue())
152 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
153 if ((result != null) && (result.get().isSuccessful())) {
154 LOG.debug("Created IdPool for VPN Service");
156 } catch (InterruptedException | ExecutionException e) {
157 LOG.error("Failed to create idPool for VPN Service",e);
162 public void close() throws Exception {
164 vpnInterfaceManager.close();
165 interVpnLinkListener.close();
166 interVpnLinkNodeListener.close();
171 public void setFibService(IFibManager fibManager) {
172 LOG.debug("Fib service reference is initialized in VPN Manager");
173 this.fibManager = fibManager;
174 vpnInterfaceManager.setFibManager(fibManager);
178 public void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
179 LOG.info("Adding extra route with destination {}, nextHop {} and label{}", destination, nextHop, label);
180 vpnInterfaceManager.addExtraRoute(destination, nextHop, rd, routerID, label, /*intfName*/ null);
184 public void delExtraRoute(String destination, String nextHop, String rd, String routerID) {
185 LOG.info("Deleting extra route with destination {} and nextHop {}", destination, nextHop);
186 vpnInterfaceManager.delExtraRoute(destination, nextHop, rd, routerID, null);
190 public boolean existsVpn(String vpnName) {
191 return vpnManager.getVpnInstance(vpnName) != null;
195 public boolean isVPNConfigured() {
196 return vpnManager.isVPNConfigured();