1. nexthopMgr intg with MdSalUtil & IdMgr
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / InterfacemgrProvider.java
1 /*
2  * Copyright (c) 2015 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.vpnservice.interfacemgr;
9
10 import java.util.concurrent.ExecutionException;
11 import java.math.BigInteger;
12 import java.util.List;
13 import java.util.concurrent.Future;
14 import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
15 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
19 import org.opendaylight.idmanager.IdManager;
20 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
21 import org.opendaylight.vpnservice.mdsalutil.InstructionInfo;
22 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
30
31     private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
32
33     private InterfaceManager interfaceManager;
34     private IfmNodeConnectorListener ifmNcListener;
35     private IdManager idManager;
36
37     @Override
38     public void onSessionInitiated(ProviderContext session) {
39         LOG.info("InterfacemgrProvider Session Initiated");
40         try {
41             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
42             idManager = new IdManager(dataBroker);
43             interfaceManager = new InterfaceManager(dataBroker, idManager);
44             ifmNcListener = new IfmNodeConnectorListener(dataBroker, interfaceManager);
45             createIdPool();
46         } catch (Exception e) {
47             LOG.error("Error initializing services", e);
48         }
49     }
50
51     private void createIdPool() {
52         CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
53         .setPoolName("interfaces")
54         .setIdStart(1L)
55         .setPoolSize(new BigInteger("65535"))
56         .build();
57         //TODO: Error handling
58         Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
59         try {
60             if((result != null) && (result.get().isSuccessful())) {
61                 LOG.debug("Created IdPool for InterfaceMgr");
62             }
63         } catch (InterruptedException | ExecutionException e) {
64             LOG.error("Failed to create idPool for InterfaceMgr",e);
65         }
66     }
67
68     @Override
69     public void close() throws Exception {
70         LOG.info("InterfacemgrProvider Closed");
71         interfaceManager.close();
72         ifmNcListener.close();
73     }
74
75     @Override
76     public Long getPortForInterface(String ifName) {
77         return interfaceManager.getPortForInterface(ifName);
78     }
79
80     @Override
81     public long getDpnForInterface(String ifName) {
82         return interfaceManager.getDpnForInterface(ifName);
83     }
84
85     @Override
86     public String getEndpointIpForDpn(long dpnId) {
87         return interfaceManager.getEndpointIpForDpn(dpnId);
88     }
89
90     @Override
91     public List<MatchInfo> getInterfaceIngressRule(String ifName) {
92         return interfaceManager.getInterfaceIngressRule(ifName);
93     }
94
95     @Override
96     public List<ActionInfo> getInterfaceEgressActions(String ifName) {
97         return interfaceManager.getInterfaceEgressActions(ifName);
98     }
99 }