f177f17b07ac25a87eed75f13c0f6fafc4d8bfe0
[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
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;
27
28 public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable, IInterfaceManager {
29
30     private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
31
32     private InterfaceManager interfaceManager;
33     private IfmNodeConnectorListener ifmNcListener;
34     private IdManager idManager;
35
36     @Override
37     public void onSessionInitiated(ProviderContext session) {
38         LOG.info("InterfacemgrProvider Session Initiated");
39         try {
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);
44             createIdPool();
45         } catch (Exception e) {
46             LOG.error("Error initializing services", e);
47         }
48     }
49
50     private void createIdPool() {
51         CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
52         .setPoolName("interfaces")
53         .setIdStart(1L)
54         .setPoolSize(new BigInteger("65535"))
55         .build();
56         //TODO: Error handling
57         Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
58         try {
59             if((result != null) && (result.get().isSuccessful())) {
60                 LOG.debug("Created IdPool for InterfaceMgr");
61             }
62         } catch (InterruptedException | ExecutionException e) {
63             LOG.error("Failed to create idPool for InterfaceMgr",e);
64         }
65     }
66
67     @Override
68     public void close() throws Exception {
69         LOG.info("InterfacemgrProvider Closed");
70         interfaceManager.close();
71         ifmNcListener.close();
72     }
73
74     @Override
75     public Long getPortForInterface(String ifName) {
76         return interfaceManager.getPortForInterface(ifName);
77     }
78
79     @Override
80     public long getDpnForInterface(String ifName) {
81         return interfaceManager.getDpnForInterface(ifName);
82     }
83
84     @Override
85     public String getEndpointIpForDpn(long dpnId) {
86         return interfaceManager.getEndpointIpForDpn(dpnId);
87     }
88
89     @Override
90     public List<MatchInfo> getInterfaceIngressRule(String ifName) {
91         return interfaceManager.getInterfaceIngressRule(ifName);
92     }
93
94     @Override
95     public List<InstructionInfo> getInterfaceEgressActions(String ifName) {
96         return interfaceManager.getInterfaceEgressActions(ifName);
97     }
98 }