Interfacemgr: Added APIs
[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.List;
11 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
12
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
16 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
24
25     private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
26
27     private InterfaceManager interfaceManager;
28     private IfmNodeConnectorListener ifmNcListener;
29
30     @Override
31     public void onSessionInitiated(ProviderContext session) {
32         LOG.info("InterfacemgrProvider Session Initiated");
33         try {
34             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
35             interfaceManager = new InterfaceManager(dataBroker);
36             ifmNcListener = new IfmNodeConnectorListener(dataBroker, interfaceManager);
37         } catch (Exception e) {
38             LOG.error("Error initializing services", e);
39         }
40         //TODO: Make this debug
41         LOG.info("Interfacemgr services initiated");
42     }
43
44     @Override
45     public void close() throws Exception {
46         LOG.info("InterfacemgrProvider Closed");
47         interfaceManager.close();
48         ifmNcListener.close();
49     }
50
51     @Override
52     public Long getPortForInterface(String ifName) {
53         return interfaceManager.getPortForInterface(ifName);
54     }
55
56     @Override
57     public long getDpnForInterface(String ifName) {
58         return interfaceManager.getDpnForInterface(ifName);
59     }
60
61     @Override
62     public String getEndpointIpForDpn(long dpnId) {
63         return interfaceManager.getEndpointIpForDpn(dpnId);
64     }
65
66     @Override
67     public List<MatchInfo> getInterfaceIngressRule(String ifName) {
68         return interfaceManager.getInterfaceIngressRule(ifName);
69     }
70 }