2 * Copyright (c) 2017 Hewlett Packard Enterprise, Co. 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
9 package org.opendaylight.netvirt.policyservice.listeners;
11 import java.math.BigInteger;
12 import java.util.Collections;
14 import javax.annotation.PostConstruct;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
22 import org.opendaylight.genius.mdsalutil.MDSALUtil;
23 import org.opendaylight.genius.mdsalutil.NwConstants;
24 import org.opendaylight.netvirt.policyservice.util.PolicyServiceFlowUtil;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 @SuppressWarnings("deprecation")
34 public class PolicyNodeListener extends AsyncDataTreeChangeListenerBase<FlowCapableNode, PolicyNodeListener> {
35 private static final Logger LOG = LoggerFactory.getLogger(PolicyNodeListener.class);
37 private final DataBroker dataBroker;
38 private final PolicyServiceFlowUtil policyFlowUtil;
41 public PolicyNodeListener(final DataBroker dataBroker, final PolicyServiceFlowUtil policyFlowUtil) {
42 this.dataBroker = dataBroker;
43 this.policyFlowUtil = policyFlowUtil;
50 registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
54 protected PolicyNodeListener getDataTreeChangeListener() {
59 protected InstanceIdentifier<FlowCapableNode> getWildCardPath() {
60 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
64 protected void remove(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode flowCapableNode) {
69 protected void update(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode origFlowCapableNode,
70 FlowCapableNode updatedFlowCapableNode) {
75 protected void add(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode flowCapableNode) {
76 BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(key.firstKeyOf(Node.class).getId());
77 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
78 createTableMissFlow(dpId, NwConstants.EGRESS_POLICY_CLASSIFIER_TABLE,
79 NwConstants.EGRESS_POLICY_CLASSIFIER_COOKIE, tx);
80 createTableMissFlow(dpId, NwConstants.EGRESS_POLICY_ROUTING_TABLE, NwConstants.EGRESS_POLICY_ROUTING_COOKIE,
85 private void createTableMissFlow(BigInteger dpId, short tableId, BigInteger cookie, WriteTransaction tx) {
86 policyFlowUtil.updateFlowToTx(dpId, tableId, tableId + "_Miss", NwConstants.TABLE_MISS_PRIORITY, cookie,
87 Collections.emptyList(), policyFlowUtil.getTableMissInstructions(), NwConstants.ADD_FLOW, tx);