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.vpnservice;
10 import java.math.BigInteger;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
14 import org.opendaylight.bgpmanager.api.IBgpManager;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
19 import org.opendaylight.fibmanager.api.IFibManager;
20 import org.opendaylight.vpnmanager.api.IVpnManager;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
23 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.OdlArputilService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class VpnserviceProvider implements BindingAwareProvider, IVpnManager,
35 private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
36 private VpnInterfaceManager vpnInterfaceManager;
37 private VpnManager vpnManager;
38 private IBgpManager bgpManager;
39 private IFibManager fibManager;
40 private IMdsalApiManager mdsalManager;
41 private OdlInterfaceRpcService interfaceManager;
42 private ItmRpcService itmProvider;
43 private IdManagerService idManager;
44 private OdlArputilService arpManager;
45 private NotificationService notificationService;
48 public void onSessionInitiated(ProviderContext session) {
49 LOG.info("VpnserviceProvider Session Initiated");
51 final DataBroker dataBroker = session.getSALService(DataBroker.class);
52 vpnManager = new VpnManager(dataBroker, bgpManager);
53 vpnManager.setIdManager(idManager);
54 vpnInterfaceManager = new VpnInterfaceManager(dataBroker, bgpManager, notificationService);
55 vpnInterfaceManager.setMdsalManager(mdsalManager);
56 vpnInterfaceManager.setInterfaceManager(interfaceManager);
57 vpnInterfaceManager.setITMProvider(itmProvider);
58 vpnInterfaceManager.setIdManager(idManager);
59 vpnInterfaceManager.setArpManager(arpManager);
60 vpnManager.setVpnInterfaceManager(vpnInterfaceManager);
62 } catch (Exception e) {
63 LOG.error("Error initializing services", e);
67 public void setNotificationService(NotificationService notificationService) {
68 this.notificationService = notificationService;
71 public void setBgpManager(IBgpManager bgpManager) {
72 LOG.debug("BGP Manager reference initialized");
73 this.bgpManager = bgpManager;
76 public void setMdsalManager(IMdsalApiManager mdsalManager) {
77 this.mdsalManager = mdsalManager;
80 public void setFibManager(IFibManager fibManager) {
81 this.fibManager = fibManager;
84 public void setInterfaceManager(OdlInterfaceRpcService interfaceManager) {
85 this.interfaceManager = interfaceManager;
88 public void setITMProvider(ItmRpcService itmProvider) {
89 this.itmProvider = itmProvider;
92 public void setIdManager(IdManagerService idManager) {
93 this.idManager = idManager;
96 public void setArpManager(OdlArputilService arpManager) {
97 this.arpManager = arpManager;
100 private void createIdPool() {
101 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
102 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
103 .setLow(VpnConstants.VPN_IDPOOL_START)
104 .setHigh(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE).longValue())
107 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
108 if ((result != null) && (result.get().isSuccessful())) {
109 LOG.debug("Created IdPool for VPN Service");
111 } catch (InterruptedException | ExecutionException e) {
112 LOG.error("Failed to create idPool for VPN Service",e);
117 public void close() throws Exception {
119 vpnInterfaceManager.close();
124 public void setFibService(IFibManager fibManager) {
125 LOG.debug("Fib service reference is initialized in VPN Manager");
126 this.fibManager = fibManager;
127 vpnInterfaceManager.setFibManager(fibManager);
131 public void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
132 LOG.info("Adding extra route with destination {} and nexthop {}", destination, nextHop);
133 vpnInterfaceManager.addExtraRoute(destination, nextHop, rd, routerID, label, null);
137 public void delExtraRoute(String destination, String rd, String routerID) {
138 LOG.info("Deleting extra route with destination {}", destination);
139 vpnInterfaceManager.delExtraRoute(destination, rd, routerID);