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;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 public class MockGroupForwarder extends AbstractMockForwardingRulesManager<Group>{
25 private int nGroupCount = 0;
26 private ListenerRegistration<MockGroupForwarder> listenerRegistration ;
28 public MockGroupForwarder( final DataBroker db) {
30 registerListener(db) ;
33 private void registerListener(final DataBroker db) {
34 final DataTreeIdentifier<Group> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
36 listenerRegistration = db.registerDataTreeChangeListener(treeId, MockGroupForwarder.this);
37 } catch (final Exception e) {
38 throw new IllegalStateException("GroupForwarder registration Listener fail! System needs restart.", e);
42 private InstanceIdentifier<Group> getWildCardPath() {
43 return InstanceIdentifier.create(Nodes.class).child(Node.class).
44 augmentation(FlowCapableNode.class).child(Group.class);
48 public void onDataTreeChanged(Collection<DataTreeModification<Group>> changes) {
49 for (DataTreeModification<Group> change : changes) {
50 final InstanceIdentifier<Group> key = change.getRootPath().getRootIdentifier();
51 final DataObjectModification<Group> mod = change.getRootNode();
53 switch (mod.getModificationType()) {
57 case SUBTREE_MODIFIED:
61 if (mod.getDataBefore() == null) {
64 // UPDATE COUNT UNCHANGED
68 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
73 public int getDataChgCount() {