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.ArrayList;
12 import java.util.List;
13 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
14 import org.opendaylight.genius.mdsalutil.ActionInfo;
15 import org.opendaylight.genius.mdsalutil.InstructionInfo;
16 import org.opendaylight.genius.mdsalutil.MDSALUtil;
17 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
18 import org.opendaylight.genius.mdsalutil.NwConstants;
19 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
20 import org.opendaylight.mdsal.binding.api.DataBroker;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 public class IngressCountersServiceImpl extends AbstractCountersService {
29 public IngressCountersServiceImpl(DataBroker db, IInterfaceManager interfaceManager,
30 IMdsalApiManager mdsalApiManager) {
31 super(db, interfaceManager, mdsalApiManager);
35 public void bind(String interfaceId) {
36 int instructionKey = 0;
37 List<Instruction> instructions = new ArrayList<>();
39 .add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.INGRESS_COUNTERS_TABLE, ++instructionKey));
40 BoundServices serviceInfo =
41 CountersServiceUtils.getBoundServices(String.format("%s.%s", "counters-ingress", interfaceId),
42 CountersServiceUtils.INGRESS_COUNTERS_SERVICE_INDEX,
43 CountersServiceUtils.INGRESS_COUNTERS_DEFAULT_FLOW_PRIORITY,
44 CountersServiceUtils.COOKIE_COUNTERS_BASE, instructions);
45 InstanceIdentifier<BoundServices> serviceId = CountersServiceUtils.buildServiceId(interfaceId,
46 CountersServiceUtils.INGRESS_COUNTERS_SERVICE_INDEX, ServiceModeIngress.class);
47 MDSALUtil.syncWrite(db, LogicalDatastoreType.CONFIGURATION, serviceId, serviceInfo);
51 public void installDefaultCounterRules(String interfaceId) {
52 BigInteger dpn = interfaceManager.getDpnForInterface(interfaceId);
53 String defaultFlowName = CountersServiceUtils.DEFAULT_INGRESS_COUNTER_FLOW_PREFIX + dpn + interfaceId;
54 List<MatchInfoBase> defaultFlowMatches = new ArrayList<>();
55 List<ActionInfo> actionsInfos = new ArrayList<>();
56 List<InstructionInfo> instructions = CountersServiceUtils.getDispatcherTableResubmitInstructions(actionsInfos,
57 ElementCountersDirection.INGRESS);
58 syncFlow(dpn, NwConstants.INGRESS_COUNTERS_TABLE, defaultFlowName,
59 CountersServiceUtils.COUNTER_TABLE_DEFAULT_FLOW_PRIORITY, CountersServiceUtils.COUNTER_FLOW_NAME, 0, 0,
60 CountersServiceUtils.COOKIE_COUNTERS_BASE, defaultFlowMatches, instructions, NwConstants.ADD_FLOW);
64 public void syncCounterFlows(ElementCountersRequest ecr, int operation) {
65 int lportTag = ecr.getLportTag();
66 List<MatchInfoBase> flowMatches =
67 CountersServiceUtils.getCounterFlowMatch(ecr, lportTag, ElementCountersDirection.INGRESS);
68 List<ActionInfo> actionsInfos = new ArrayList<>();
69 List<InstructionInfo> instructions = CountersServiceUtils.getDispatcherTableResubmitInstructions(actionsInfos,
70 ElementCountersDirection.INGRESS);
72 BigInteger dpn = ecr.getDpn();
73 String flowName = createFlowName(ecr, lportTag, dpn);
75 syncFlow(dpn, NwConstants.INGRESS_COUNTERS_TABLE, flowName,
76 CountersServiceUtils.COUNTER_TABLE_COUNTER_FLOW_PRIORITY, CountersServiceUtils.COUNTER_FLOW_NAME, 0, 0,
77 CountersServiceUtils.COOKIE_COUNTERS_BASE, flowMatches, instructions, operation);
80 private String createFlowName(ElementCountersRequest ecr, int lportTag, BigInteger dpn) {
81 return "Ingress_Counters" + dpn + "_" + lportTag + "_" + ecr.toString().hashCode();
85 public void unBindService(String interfaceId) {
86 InstanceIdentifier<BoundServices> serviceId = CountersServiceUtils.buildServiceId(interfaceId,
87 CountersServiceUtils.INGRESS_COUNTERS_SERVICE_INDEX, ServiceModeIngress.class);
88 MDSALUtil.syncDelete(db, LogicalDatastoreType.CONFIGURATION, serviceId);