2 * Copyright (c) 2015 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.interfacemgr;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
12 import java.math.BigInteger;
13 import java.util.List;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Future;
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.ActionInfo;
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;
29 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
31 private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
33 private InterfaceManager interfaceManager;
34 private IfmNodeConnectorListener ifmNcListener;
35 private IdManager idManager;
38 public void onSessionInitiated(ProviderContext session) {
39 LOG.info("InterfacemgrProvider Session Initiated");
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);
46 } catch (Exception e) {
47 LOG.error("Error initializing services", e);
51 private void createIdPool() {
52 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
53 .setPoolName(IfmConstants.IFM_IDPOOL_NAME)
54 .setIdStart(IfmConstants.IFM_IDPOOL_START)
55 .setPoolSize(new BigInteger(IfmConstants.IFM_IDPOOL_SIZE))
57 //TODO: Error handling
58 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
60 if ((result != null) && (result.get().isSuccessful())) {
61 LOG.debug("Created IdPool for InterfaceMgr");
63 } catch (InterruptedException | ExecutionException e) {
64 LOG.error("Failed to create idPool for InterfaceMgr",e);
69 public void close() throws Exception {
70 LOG.info("InterfacemgrProvider Closed");
71 interfaceManager.close();
72 ifmNcListener.close();
76 public Long getPortForInterface(String ifName) {
77 return interfaceManager.getPortForInterface(ifName);
81 public Long getPortForInterface(Interface intf) {
82 return interfaceManager.getPortForInterface(intf);
87 public BigInteger getDpnForInterface(String ifName) {
88 return interfaceManager.getDpnForInterface(ifName);
92 public String getEndpointIpForDpn(BigInteger dpnId) {
93 return interfaceManager.getEndpointIpForDpn(dpnId);
97 public List<MatchInfo> getInterfaceIngressRule(String ifName) {
98 return interfaceManager.getInterfaceIngressRule(ifName);
102 public List<ActionInfo> getInterfaceEgressActions(String ifName) {
103 return interfaceManager.getInterfaceEgressActions(ifName);
107 public BigInteger getDpnForInterface(Interface intrf) {
108 // TODO Auto-generated method stub
109 return interfaceManager.getDpnForInterface(intrf);