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;
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.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
20 import org.opendaylight.genius.mdsalutil.MDSALUtil;
21 import org.opendaylight.genius.mdsalutil.NwConstants;
22 import org.opendaylight.netvirt.policyservice.util.PolicyServiceFlowUtil;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class PolicyNodeListener extends AsyncDataTreeChangeListenerBase<FlowCapableNode, PolicyNodeListener> {
32 private static final Logger LOG = LoggerFactory.getLogger(PolicyNodeListener.class);
34 private final DataBroker dataBroker;
35 private final PolicyServiceFlowUtil policyFlowUtil;
38 public PolicyNodeListener(final DataBroker dataBroker, final PolicyServiceFlowUtil policyFlowUtil) {
39 this.dataBroker = dataBroker;
40 this.policyFlowUtil = policyFlowUtil;
47 registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
51 protected PolicyNodeListener getDataTreeChangeListener() {
56 protected InstanceIdentifier<FlowCapableNode> getWildCardPath() {
57 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
61 protected void remove(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode flowCapableNode) {
66 protected void update(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode origFlowCapableNode,
67 FlowCapableNode updatedFlowCapableNode) {
72 protected void add(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode flowCapableNode) {
73 BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(key.firstKeyOf(Node.class).getId());
74 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
75 createTableMissFlow(dpId, NwConstants.EGRESS_POLICY_CLASSIFIER_TABLE,
76 NwConstants.EGRESS_POLICY_CLASSIFIER_COOKIE, tx);
77 createTableMissFlow(dpId, NwConstants.EGRESS_POLICY_ROUTING_TABLE, NwConstants.EGRESS_POLICY_ROUTING_COOKIE,
82 private void createTableMissFlow(BigInteger dpId, short tableId, BigInteger cookie, WriteTransaction tx) {
83 policyFlowUtil.updateFlowToTx(dpId, tableId, tableId + "_Miss", NwConstants.TABLE_MISS_PRIORITY, cookie,
84 Collections.emptyList(), policyFlowUtil.getTableMissInstructions(), NwConstants.ADD_FLOW, tx);