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 java.math.BigInteger;
11 import java.util.List;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
17 import org.opendaylight.idmanager.IdManager;
18 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
19 import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
20 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
29 private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
31 private InterfaceManager interfaceManager;
32 private IfmNodeConnectorListener ifmNcListener;
33 private IdManager idManager;
36 public void onSessionInitiated(ProviderContext session) {
37 LOG.info("InterfacemgrProvider Session Initiated");
39 final DataBroker dataBroker = session.getSALService(DataBroker.class);
40 idManager = new IdManager(dataBroker);
41 interfaceManager = new InterfaceManager(dataBroker, idManager);
42 ifmNcListener = new IfmNodeConnectorListener(dataBroker, interfaceManager);
44 } catch (Exception e) {
45 LOG.error("Error initializing services", e);
49 private void createIdPool() {
50 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
51 .setPoolName(IfmConstants.IFM_IDPOOL_NAME)
52 .setIdStart(IfmConstants.IFM_IDPOOL_START)
53 .setPoolSize(new BigInteger(IfmConstants.IFM_IDPOOL_SIZE))
55 //TODO: Error handling
56 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
58 if ((result != null) && (result.get().isSuccessful())) {
59 LOG.debug("Created IdPool for InterfaceMgr");
61 } catch (InterruptedException | ExecutionException e) {
62 LOG.error("Failed to create idPool for InterfaceMgr",e);
67 public void close() throws Exception {
68 LOG.info("InterfacemgrProvider Closed");
69 interfaceManager.close();
70 ifmNcListener.close();
74 public Long getPortForInterface(String ifName) {
75 return interfaceManager.getPortForInterface(ifName);
79 public BigInteger getDpnForInterface(String ifName) {
80 return interfaceManager.getDpnForInterface(ifName);
84 public String getEndpointIpForDpn(BigInteger dpnId) {
85 return interfaceManager.getEndpointIpForDpn(dpnId);
89 public List<MatchInfo> getInterfaceIngressRule(String ifName) {
90 return interfaceManager.getInterfaceIngressRule(ifName);
94 public List<ActionInfo> getInterfaceEgressActions(String ifName) {
95 return interfaceManager.getInterfaceEgressActions(ifName);