1 package org.opendaylight.vpnservice.test;
3 import java.util.Collection;
5 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
6 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
7 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
8 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
9 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 public class MockFlowForwarder extends AbstractMockForwardingRulesManager<Flow> {
20 private int nFlowCount = 0;
22 private ListenerRegistration<MockFlowForwarder> listenerRegistration;
24 public MockFlowForwarder( final DataBroker db) {
26 registerListener(db) ;
29 private void registerListener(final DataBroker db) {
30 final DataTreeIdentifier<Flow> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
32 listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFlowForwarder.this);
33 } catch (final Exception e) {
34 throw new IllegalStateException("FlowForwarder registration Listener fail! System needs restart.", e);
38 private InstanceIdentifier<Flow> getWildCardPath() {
39 return InstanceIdentifier.create(Nodes.class).child(Node.class)
40 .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
44 public void onDataTreeChanged(Collection<DataTreeModification<Flow>> changes) {
45 for (DataTreeModification<Flow> change : changes) {
46 final InstanceIdentifier<Flow> key = change.getRootPath().getRootIdentifier();
47 final DataObjectModification<Flow> mod = change.getRootNode();
49 switch (mod.getModificationType()) {
53 case SUBTREE_MODIFIED:
57 if (mod.getDataBefore() == null) {
60 // UPDATE COUNT UNCHANGED
64 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
69 public int getDataChgCount() {