2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.test;
10 import java.util.Collection;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 public class MockFlowForwarder extends AbstractMockForwardingRulesManager<Flow> {
27 private int nFlowCount = 0;
29 private ListenerRegistration<MockFlowForwarder> listenerRegistration;
31 public MockFlowForwarder( final DataBroker db) {
33 registerListener(db) ;
36 private void registerListener(final DataBroker db) {
37 final DataTreeIdentifier<Flow> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
39 listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFlowForwarder.this);
40 } catch (final Exception e) {
41 throw new IllegalStateException("FlowForwarder registration Listener fail! System needs restart.", e);
45 private InstanceIdentifier<Flow> getWildCardPath() {
46 return InstanceIdentifier.create(Nodes.class).child(Node.class)
47 .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
51 public void onDataTreeChanged(Collection<DataTreeModification<Flow>> changes) {
52 for (DataTreeModification<Flow> change : changes) {
53 final InstanceIdentifier<Flow> key = change.getRootPath().getRootIdentifier();
54 final DataObjectModification<Flow> mod = change.getRootNode();
56 switch (mod.getModificationType()) {
60 case SUBTREE_MODIFIED:
64 if (mod.getDataBefore() == null) {
67 // UPDATE COUNT UNCHANGED
71 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
76 public int getDataChgCount() {