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