Fix FindBugs violations and enable enforcement in qosservice
[netvirt.git] / vpnservice / qosservice / impl / src / main / java / org / opendaylight / netvirt / qosservice / QosNodeListener.java
1 /*
2  * Copyright (c) 2017 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.netvirt.qosservice;
9
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.annotation.PostConstruct;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
19 import org.opendaylight.genius.mdsalutil.ActionInfo;
20 import org.opendaylight.genius.mdsalutil.FlowEntity;
21 import org.opendaylight.genius.mdsalutil.InstructionInfo;
22 import org.opendaylight.genius.mdsalutil.MDSALUtil;
23 import org.opendaylight.genius.mdsalutil.MatchInfo;
24 import org.opendaylight.genius.mdsalutil.NwConstants;
25 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
26 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
27 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 @Singleton
37 public class QosNodeListener extends AsyncDataTreeChangeListenerBase<FlowCapableNode, QosNodeListener> {
38     private static final Logger LOG = LoggerFactory.getLogger(QosNodeListener.class);
39
40     private final DataBroker dataBroker;
41     private final IMdsalApiManager mdsalUtils;
42
43     @Inject
44     public QosNodeListener(final DataBroker dataBroker, final IMdsalApiManager mdsalUtils) {
45         super(FlowCapableNode.class, QosNodeListener.class);
46         this.dataBroker = dataBroker;
47         this.mdsalUtils = mdsalUtils;
48         LOG.debug("{} created",  getClass().getSimpleName());
49     }
50
51     @Override
52     @PostConstruct
53     public void init() {
54         registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
55         LOG.debug("{} init and registerListener done", getClass().getSimpleName());
56     }
57
58     @Override
59     protected InstanceIdentifier<FlowCapableNode> getWildCardPath() {
60         return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
61     }
62
63     @Override
64     protected void remove(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModification) {
65         //do nothing
66     }
67
68     @Override
69     protected void update(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModificationBefore,
70                           FlowCapableNode dataObjectModificationAfter) {
71         //do nothing
72     }
73
74     @Override
75     protected void add(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModification) {
76         NodeKey nodeKey = key.firstKeyOf(Node.class);
77         BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(nodeKey.getId());
78         createTableMissEntry(dpId);
79     }
80
81     @Override
82     protected QosNodeListener getDataTreeChangeListener() {
83         return QosNodeListener.this;
84     }
85
86     public void createTableMissEntry(BigInteger dpnId) {
87         List<MatchInfo> matches = new ArrayList<>();
88         List<InstructionInfo> instructions = new ArrayList<>();
89         List<ActionInfo> actionsInfos = new ArrayList<>();
90         actionsInfos.add(new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
91         instructions.add(new InstructionApplyActions(actionsInfos));
92         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.QOS_DSCP_TABLE, "QoSTableMissFlow",
93                 0, "QoS Table Miss Flow", 0, 0,
94                 NwConstants.COOKIE_QOS_TABLE, matches, instructions);
95         mdsalUtils.installFlow(flowEntity);
96     }
97 }
98
99