MRI version bumpup for Aluminium
[netvirt.git] / statistics / impl / src / main / java / org / opendaylight / netvirt / statistics / AbstractCountersService.java
1 /*
2  * Copyright (c) 2017 HPE, Inc. 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.netvirt.statistics;
9
10 import java.math.BigInteger;
11 import java.util.List;
12 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
13 import org.opendaylight.genius.mdsalutil.FlowEntity;
14 import org.opendaylight.genius.mdsalutil.InstructionInfo;
15 import org.opendaylight.genius.mdsalutil.MDSALUtil;
16 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
17 import org.opendaylight.genius.mdsalutil.NwConstants;
18 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20
21 public abstract class AbstractCountersService {
22
23     protected final DataBroker db;
24     protected final IInterfaceManager interfaceManager;
25     protected final IMdsalApiManager mdsalManager;
26
27     public AbstractCountersService(DataBroker db, IInterfaceManager interfaceManager, IMdsalApiManager mdsalManager) {
28         this.db = db;
29         this.interfaceManager = interfaceManager;
30         this.mdsalManager = mdsalManager;
31     }
32
33     public abstract void bind(String interfaceId);
34
35     public abstract void unBindService(String interfaceId);
36
37     public abstract void installDefaultCounterRules(String interfaceId);
38
39     public abstract void syncCounterFlows(ElementCountersRequest ecr, int operation);
40
41     public void bindService(String interfaceId) {
42         bind(interfaceId);
43         installDefaultCounterRules(interfaceId);
44     }
45
46     public void installCounterRules(ElementCountersRequest ecr) {
47         syncCounterFlows(ecr, NwConstants.ADD_FLOW);
48     }
49
50     public void deleteCounterRules(ElementCountersRequest ecr) {
51         syncCounterFlows(ecr, NwConstants.DEL_FLOW);
52     }
53
54     protected void syncFlow(BigInteger dpId, short tableId, String flowId, int priority, String flowName,
55             int idleTimeOut, int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> matches,
56             List<InstructionInfo> instructions, int operation) {
57         if (NwConstants.DEL_FLOW == operation) {
58             FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority, flowName, idleTimeOut,
59                     hardTimeOut, cookie, matches, null);
60             mdsalManager.removeFlow(flowEntity);
61         } else if (NwConstants.ADD_FLOW == operation) {
62             FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority, flowName, idleTimeOut,
63                     hardTimeOut, cookie, matches, instructions);
64             mdsalManager.installFlow(flowEntity);
65         }
66     }
67
68 }