2 * Copyright (c) 2016, 2017 Red Hat, 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.ipv6service;
10 import java.util.ArrayList;
11 import java.util.List;
12 import javax.annotation.PostConstruct;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
18 import org.opendaylight.genius.mdsalutil.ActionInfo;
19 import org.opendaylight.genius.mdsalutil.FlowEntity;
20 import org.opendaylight.genius.mdsalutil.InstructionInfo;
21 import org.opendaylight.genius.mdsalutil.MDSALUtil;
22 import org.opendaylight.genius.mdsalutil.MatchInfo;
23 import org.opendaylight.genius.mdsalutil.NwConstants;
24 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
25 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
26 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.Uint64;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 public class Ipv6NodeListener extends AsyncClusteredDataTreeChangeListenerBase<FlowCapableNode, Ipv6NodeListener> {
38 private static final Logger LOG = LoggerFactory.getLogger(Ipv6NodeListener.class);
39 private final DataBroker dataBroker;
40 private final IMdsalApiManager mdsalUtil;
41 private final Ipv6ServiceEosHandler ipv6ServiceEosHandler;
44 public Ipv6NodeListener(final DataBroker dataBroker, final IMdsalApiManager mdsalUtil,
45 final Ipv6ServiceEosHandler ipv6ServiceEosHandler) {
46 this.dataBroker = dataBroker;
47 this.mdsalUtil = mdsalUtil;
48 this.ipv6ServiceEosHandler = ipv6ServiceEosHandler;
53 LOG.info("{} init", getClass().getSimpleName());
54 registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
58 protected InstanceIdentifier<FlowCapableNode> getWildCardPath() {
59 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
63 protected void update(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModificationBefore,
64 FlowCapableNode dataObjectModificationAfter) {
69 protected void add(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModification) {
70 LOG.trace("FlowCapableNode Added: key: {}", key);
72 NodeKey nodeKey = key.firstKeyOf(Node.class);
73 Uint64 dpnId = MDSALUtil.getDpnIdFromNodeName(nodeKey.getId());
74 createTableMissEntry(dpnId);
77 private void createTableMissEntry(Uint64 dpnId) {
78 if (!ipv6ServiceEosHandler.isClusterOwner()) {
79 LOG.trace("Not a cluster Owner, skip flow programming.");
83 List<MatchInfo> matches = new ArrayList<>();
84 List<InstructionInfo> instructions = new ArrayList<>();
85 List<ActionInfo> actionsInfos = new ArrayList<>();
86 actionsInfos.add(new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
87 instructions.add(new InstructionApplyActions(actionsInfos));
88 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.IPV6_TABLE, "IPv6TableMissFlow",
89 0, "IPv6 Table Miss Flow", 0, 0,
90 NwConstants.COOKIE_IPV6_TABLE, matches, instructions);
91 mdsalUtil.installFlow(flowEntity);
95 protected void remove(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModification) {
100 * @see org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase#getDataTreeChangeListener()
103 protected Ipv6NodeListener getDataTreeChangeListener() {
104 return Ipv6NodeListener.this;