2 * Copyright (c) 2017 HPE, Inc. 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.netvirt.statistics;
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;
21 public abstract class AbstractCountersService {
23 protected final DataBroker db;
24 protected final IInterfaceManager interfaceManager;
25 protected final IMdsalApiManager mdsalManager;
27 public AbstractCountersService(DataBroker db, IInterfaceManager interfaceManager, IMdsalApiManager mdsalManager) {
29 this.interfaceManager = interfaceManager;
30 this.mdsalManager = mdsalManager;
33 public abstract void bind(String interfaceId);
35 public abstract void unBindService(String interfaceId);
37 public abstract void installDefaultCounterRules(String interfaceId);
39 public abstract void syncCounterFlows(ElementCountersRequest ecr, int operation);
41 public void bindService(String interfaceId) {
43 installDefaultCounterRules(interfaceId);
46 public void installCounterRules(ElementCountersRequest ecr) {
47 syncCounterFlows(ecr, NwConstants.ADD_FLOW);
50 public void deleteCounterRules(ElementCountersRequest ecr) {
51 syncCounterFlows(ecr, NwConstants.DEL_FLOW);
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);