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.util.concurrent.ExecutionException;
12 import java.math.BigInteger;
13 import java.util.List;
14 import java.util.concurrent.Future;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.idmanager.IdManager;
19 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
20 import org.opendaylight.vpnservice.mdsalutil.InstructionInfo;
21 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
30 private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
32 private InterfaceManager interfaceManager;
33 private IfmNodeConnectorListener ifmNcListener;
34 private IdManager idManager;
37 public void onSessionInitiated(ProviderContext session) {
38 LOG.info("InterfacemgrProvider Session Initiated");
40 final DataBroker dataBroker = session.getSALService(DataBroker.class);
41 idManager = new IdManager(dataBroker);
42 interfaceManager = new InterfaceManager(dataBroker, idManager);
43 ifmNcListener = new IfmNodeConnectorListener(dataBroker, interfaceManager);
45 } catch (Exception e) {
46 LOG.error("Error initializing services", e);
50 private void createIdPool() {
51 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
52 .setPoolName("interfaces")
54 .setPoolSize(new BigInteger("65535"))
56 //TODO: Error handling
57 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
59 if((result != null) && (result.get().isSuccessful())) {
60 LOG.debug("Created IdPool for InterfaceMgr");
62 } catch (InterruptedException | ExecutionException e) {
63 LOG.error("Failed to create idPool for InterfaceMgr",e);
68 public void close() throws Exception {
69 LOG.info("InterfacemgrProvider Closed");
70 interfaceManager.close();
71 ifmNcListener.close();
75 public Long getPortForInterface(String ifName) {
76 return interfaceManager.getPortForInterface(ifName);
80 public long getDpnForInterface(String ifName) {
81 return interfaceManager.getDpnForInterface(ifName);
85 public String getEndpointIpForDpn(long dpnId) {
86 return interfaceManager.getEndpointIpForDpn(dpnId);
90 public List<MatchInfo> getInterfaceIngressRule(String ifName) {
91 return interfaceManager.getInterfaceIngressRule(ifName);
95 public List<InstructionInfo> getInterfaceEgressActions(String ifName) {
96 return interfaceManager.getInterfaceEgressActions(ifName);