Remove redundant names in paths
[netvirt.git] / bgpmanager / impl / src / test / java / org / opendaylight / netvirt / bgpmanager / test / MockFibManager.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.bgpmanager.test;
9
10 import java.util.Collection;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21
22 public class MockFibManager extends AbstractMockFibManager<VrfEntry> {
23
24     private int numFibEntries = 0;
25
26     private ListenerRegistration<MockFibManager> listenerRegistration;
27
28     public MockFibManager(final DataBroker db) {
29         super() ;
30         registerListener(db) ;
31     }
32
33     private void registerListener(final DataBroker db) {
34         final DataTreeIdentifier<VrfEntry> treeId =
35                 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
36         listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFibManager.this);
37     }
38
39     private InstanceIdentifier<VrfEntry> getWildCardPath() {
40         return InstanceIdentifier.create(FibEntries.class).child(VrfTables.class).child(VrfEntry.class);
41     }
42
43     @Override
44     public void onDataTreeChanged(Collection<DataTreeModification<VrfEntry>> changes) {
45         for (DataTreeModification<VrfEntry> change : changes) {
46             final InstanceIdentifier<VrfEntry> key = change.getRootPath().getRootIdentifier();
47             final DataObjectModification<VrfEntry> mod = change.getRootNode();
48
49             switch (mod.getModificationType()) {
50                 case DELETE:
51                     numFibEntries -= 1;
52                     break;
53                 case WRITE:
54                     if (mod.getDataBefore() == null) {
55                         numFibEntries += 1;
56                     } else {
57                         // UPDATE COUNT UNCHANGED
58                     }
59                     break;
60                 default:
61                     throw new IllegalArgumentException("Unhandled modification  type " + mod.getModificationType());
62             }
63         }
64     }
65
66     public int getDataChgCount() {
67         return numFibEntries;
68     }
69 }