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.bgpmanager.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.vpnservice.fibmanager.rev150330.FibEntries;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTables;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.vrfentries.VrfEntry;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 public class MockFibManager extends AbstractMockFibManager<VrfEntry> {
25 private int nFibEntries = 0;
27 private ListenerRegistration<MockFibManager> listenerRegistration;
29 public MockFibManager( final DataBroker db) {
31 registerListener(db) ;
34 private void registerListener(final DataBroker db) {
35 final DataTreeIdentifier<VrfEntry> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
37 listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFibManager.this);
38 } catch (final Exception e) {
39 throw new IllegalStateException("FibManager registration Listener fail! System needs restart.", e);
43 private InstanceIdentifier<VrfEntry> getWildCardPath() {
44 return InstanceIdentifier.create(FibEntries.class).child(VrfTables.class).child(VrfEntry.class);
48 public void onDataTreeChanged(Collection<DataTreeModification<VrfEntry>> changes) {
49 for (DataTreeModification<VrfEntry> change : changes) {
50 final InstanceIdentifier<VrfEntry> key = change.getRootPath().getRootIdentifier();
51 final DataObjectModification<VrfEntry> mod = change.getRootNode();
53 switch (mod.getModificationType()) {
58 if (mod.getDataBefore() == null) {
61 // UPDATE COUNT UNCHANGED
65 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
70 public int getDataChgCount() {