8dd5d97612a30e30a66505a6d4881be1c0c1cedd
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / config / BgpDeployerImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.protocol.bgp.rib.impl.config;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.eq;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
18 import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
19 import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.WRITE;
20 import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.TABLES_KEY;
21 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAddPath;
22 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createConfig;
23 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createRR;
24 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTimers;
25 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTransport;
26 import static org.powermock.api.mockito.PowerMockito.spy;
27 import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
28
29 import com.google.common.primitives.Shorts;
30 import com.google.common.util.concurrent.CheckedFuture;
31 import java.util.ArrayList;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.Dictionary;
35 import java.util.Optional;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.Mockito;
41 import org.mockito.MockitoAnnotations;
42 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
43 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
44 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
45 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
46 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
47 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
48 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
49 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
50 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
51 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
52 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
53 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
54 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
55 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
56 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
57 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
58 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
59 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
60 import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
61 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
62 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
63 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
64 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafis;
65 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
66 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.Config;
67 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.ConfigBuilder;
68 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
69 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
70 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
71 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
72 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
73 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
74 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType;
75 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
76 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
77 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
78 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
79 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceBuilder;
80 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceKey;
81 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
82 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.ProtocolsBuilder;
83 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
84 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
85 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
86 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
87 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
88 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1Builder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.Protocol1;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
98 import org.opendaylight.yangtools.concepts.ListenerRegistration;
99 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
100 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
101 import org.osgi.framework.BundleContext;
102 import org.osgi.framework.ServiceRegistration;
103 import org.osgi.service.blueprint.container.BlueprintContainer;
104 import org.powermock.core.classloader.annotations.PrepareForTest;
105 import org.powermock.modules.junit4.PowerMockRunner;
106
107 @RunWith(PowerMockRunner.class)
108 @PrepareForTest({BgpDeployerImpl.class})
109 public class BgpDeployerImplTest {
110     private static final String NETWORK_INSTANCE_NAME = "network-test";
111     private static final AsNumber AS = new AsNumber(72L);
112     private static final IpAddress IPADDRESS = new IpAddress(new Ipv4Address("127.0.0.1"));
113     private static final BgpId BGP_ID = new BgpId(IPADDRESS.getIpv4Address());
114     private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class,
115             UnicastSubsequentAddressFamily.class);
116
117     private static final short SHORT = 0;
118
119     @Mock
120     private DataObjectModification<?> dObject;
121     @Mock
122     private BlueprintContainer blueprintContainer;
123     @Mock
124     private BundleContext bundleContext;
125     @Mock
126     private DataBroker dataBroker;
127     @Mock
128     private BGPTableTypeRegistryConsumer tableTypeRegistry;
129     @Mock
130     private WriteTransaction wTx;
131     @Mock
132     private DataTreeModification<Bgp> modification;
133     @Mock
134     private ListenerRegistration<?> dataTreeRegistration;
135     @Mock
136     private ServiceRegistration<?> registration;
137     @Mock
138     private ClusterSingletonServiceProvider singletonServiceProvider;
139
140     private Collection<DataTreeModification<Bgp>> collection = Collections.singleton(this.modification);
141
142     private static Neighbor createNeighborExpected(final Class<? extends AfiSafiType> afi) {
143         return new NeighborBuilder()
144                 .setAfiSafis(createAfiSafi(afi))
145                 .setConfig(createConfig())
146                 .setNeighborAddress(IPADDRESS)
147                 .setRouteReflector(createRR())
148                 .setTimers(createTimers())
149                 .setTransport(createTransport())
150                 .setAddPaths(createAddPath())
151                 .build();
152     }
153
154     private static org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafis createAfiSafi(final Class<? extends AfiSafiType> afi) {
155         return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder()
156                 .setAfiSafi(Collections.singletonList(new AfiSafiBuilder().setAfiSafiName(afi)
157                         .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(SHORT).build()).build())).build();
158     }
159
160     @Before
161     public void setUp() throws Exception {
162         MockitoAnnotations.initMocks(this);
163         final DOMDataBroker domDataBroker = mock(DOMDataBroker.class);
164
165         doReturn(this.wTx).when(this.dataBroker).newWriteOnlyTransaction();
166         doReturn("mapping").when(this.tableTypeRegistry).toString();
167
168         doReturn(null).when(domDataBroker).createTransactionChain(any());
169         doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, mock(DOMDataBrokerExtension.class)))
170                 .when(domDataBroker).getSupportedExtensions();
171
172         doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
173         doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
174         Mockito.doNothing().when(this.registration).unregister();
175         doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any()
176                 , any(Dictionary.class));
177         doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any()
178                 , any(Dictionary.class));
179
180
181         Mockito.doNothing().when(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
182                 any(NetworkInstance.class));
183         final CheckedFuture<?, ?> future = mock(CheckedFuture.class);
184         doReturn(future).when(this.wTx).submit();
185         Mockito.doNothing().when(future).addListener(any(), any());
186         doReturn(this.dataTreeRegistration).when(this.dataBroker).registerDataTreeChangeListener(any(), any());
187         Mockito.doNothing().when(this.dataTreeRegistration).close();
188
189         final InstanceIdentifier<Bgp> bgpIID = InstanceIdentifier.create(NetworkInstances.class)
190                 .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME)).child(Protocols.class)
191                 .child(Protocol.class, new ProtocolKey(BGP.class, "bgp"))
192                 .augmentation(Protocol1.class).child(Bgp.class);
193
194         doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, bgpIID))
195                 .when(this.modification).getRootPath();
196         doReturn(this.dObject).when(this.modification).getRootNode();
197         doReturn("bgpPeer").when(this.modification).toString();
198
199         doReturn(Collections.singleton(this.dObject)).when(this.dObject).getModifiedChildren();
200         doReturn("dObject").when(this.dObject).toString();
201
202         final RIBExtensionConsumerContext extension = mock(RIBExtensionConsumerContext.class);
203         doReturn(mock(GeneratedClassLoadingStrategy.class)).when(extension).getClassLoadingStrategy();
204
205         final ClusterSingletonServiceRegistration serviceRegistration = mock(ClusterSingletonServiceRegistration.class);
206         doReturn(serviceRegistration).when(this.singletonServiceProvider).registerClusterSingletonService(any());
207         Mockito.doNothing().when(serviceRegistration).close();
208
209         final DOMSchemaService schemaService = mock(DOMSchemaService.class);
210         Mockito.doNothing().when(this.dataTreeRegistration).close();
211
212         doReturn(this.dataTreeRegistration).when(schemaService).registerSchemaContextListener(any());
213
214         final RibImpl ribImpl = new RibImpl(extension, mock(BGPDispatcher.class), mock(BindingCodecTreeFactory.class),
215                 domDataBroker, schemaService);
216         doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
217
218         final BgpPeer bgpPeer = new BgpPeer(mock(RpcProviderRegistry.class));
219         doReturn(bgpPeer).when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
220         this.collection = Collections.singleton(this.modification);
221     }
222
223     @Test
224     public void testDeployerRib() throws Exception {
225         doReturn(Global.class).when(this.dObject).getDataType();
226         final BgpDeployerImpl deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider,
227                 this.blueprintContainer, this.bundleContext, this.dataBroker, this.tableTypeRegistry);
228         final BgpDeployerImpl spyDeployer = spy(deployer);
229         deployer.init();
230         configureGlobal(IPV4UNICAST.class);
231         doReturn(WRITE).when(this.dObject).getModificationType();
232
233         final KeyedInstanceIdentifier<NetworkInstance, NetworkInstanceKey> networkInstanceIId =
234                 InstanceIdentifier.create(NetworkInstances.class)
235                         .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME));
236         final NetworkInstance netII = new NetworkInstanceBuilder()
237                 .setName(networkInstanceIId.firstKeyOf(NetworkInstance.class).getName())
238                 .setProtocols(new ProtocolsBuilder().build()).build();
239         verify(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), eq(netII));
240         verify(this.dataBroker).registerDataTreeChangeListener(any(DataTreeIdentifier.class),
241                 any(BgpDeployerImpl.class));
242
243         assertEquals(this.tableTypeRegistry, spyDeployer.getTableTypeRegistry());
244
245         spyDeployer.onDataTreeChanged(this.collection);
246         verifyPrivate(spyDeployer).invoke("onGlobalChanged", any(DataObjectModification.class),
247                 any(InstanceIdentifier.class));
248         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
249         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
250         verify(spyDeployer).onDataTreeChanged(any(Collection.class));
251
252         //change with same rib already existing
253         spyDeployer.onDataTreeChanged(this.collection);
254         verifyPrivate(spyDeployer, times(2)).invoke("onGlobalChanged",
255                 any(DataObjectModification.class), any(InstanceIdentifier.class));
256         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
257         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
258         verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
259
260         //Update for existing rib
261         configureGlobal(IPV6UNICAST.class);
262         spyDeployer.onDataTreeChanged(this.collection);
263         verifyPrivate(spyDeployer, times(3)).invoke("onGlobalChanged",
264                 any(DataObjectModification.class), any(InstanceIdentifier.class));
265         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
266         verify(this.bundleContext, times(2)).registerService(eq(InstanceType.RIB.getServices()),
267                 any(), any(Dictionary.class));
268         verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
269         verify(this.dataTreeRegistration).close();
270         verify(this.registration).unregister();
271         verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
272
273         //Delete for existing rib
274         doReturn(DELETE).when(this.dObject).getModificationType();
275
276         spyDeployer.onDataTreeChanged(this.collection);
277         verifyPrivate(spyDeployer, times(4)).invoke("onGlobalChanged",
278                 any(DataObjectModification.class), any(InstanceIdentifier.class));
279         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
280         verify(this.bundleContext, times(2))
281                 .registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
282         verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
283         verify(this.dataTreeRegistration, times(2)).close();
284         verify(this.registration, times(2)).unregister();
285         verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
286
287         deployer.close();
288     }
289
290     private void configureGlobal(final Class<? extends AfiSafiType> afi) {
291         final Config config = new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build();
292         final ArrayList<AfiSafi> afiSafiList = new ArrayList<>();
293         afiSafiList.add(new AfiSafiBuilder().setAfiSafiName(afi).addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true)
294                 .setSendMax(Shorts.checkedCast(0L)).build()).build());
295         final AfiSafis afiSafi = new AfiSafisBuilder().setAfiSafi(afiSafiList).build();
296         doReturn(new GlobalBuilder().setConfig(config).setAfiSafis(afiSafi).build()).when(this.dObject).getDataAfter();
297     }
298
299     /**
300      * Test create Rib
301      */
302     @Test
303     public void testDeployerCreateNeighbor() throws Exception {
304
305         final BgpDeployerImpl deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider,
306                 this.blueprintContainer, this.bundleContext, this.dataBroker, this.tableTypeRegistry);
307         final BgpDeployerImpl spyDeployer = spy(deployer);
308         deployer.init();
309         //First create Rib
310         doReturn(Global.class).when(this.dObject).getDataType();
311         doReturn(WRITE).when(this.dObject).getModificationType();
312         configureGlobal(IPV4UNICAST.class);
313
314         spyDeployer.onDataTreeChanged(this.collection);
315         verifyPrivate(spyDeployer).invoke("onGlobalChanged", any(DataObjectModification.class),
316                 any(InstanceIdentifier.class));
317         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
318         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
319         verify(spyDeployer).onDataTreeChanged(any(Collection.class));
320
321         doReturn(Neighbors.class).when(this.dObject).getDataType();
322         doReturn(WRITE).when(this.dObject).getModificationType();
323         configureNeighbor(IPV4UNICAST.class);
324
325         final KeyedInstanceIdentifier<NetworkInstance, NetworkInstanceKey> networkInstanceIId =
326                 InstanceIdentifier.create(NetworkInstances.class)
327                         .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME));
328         final NetworkInstance netII = new NetworkInstanceBuilder()
329                 .setName(networkInstanceIId.firstKeyOf(NetworkInstance.class).getName())
330                 .setProtocols(new ProtocolsBuilder().build()).build();
331         verify(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), eq(netII));
332         verify(this.dataBroker)
333                 .registerDataTreeChangeListener(any(DataTreeIdentifier.class), any(BgpDeployerImpl.class));
334
335         assertEquals(this.tableTypeRegistry, spyDeployer.getTableTypeRegistry());
336
337         spyDeployer.onDataTreeChanged(this.collection);
338         verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
339         verifyPrivate(spyDeployer).invoke("onNeighborsChanged",
340                 any(DataObjectModification.class), any(InstanceIdentifier.class));
341         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
342         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
343                 any(BgpPeer.class), any(Dictionary.class));
344
345         //change with same peer already existing
346         spyDeployer.onDataTreeChanged(this.collection);
347         verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
348         verifyPrivate(spyDeployer, times(2)).invoke("onNeighborsChanged",
349                 any(DataObjectModification.class), any(InstanceIdentifier.class));
350         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
351         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
352                 any(BgpPeer.class), any(Dictionary.class));
353
354         //Update for existing rib
355         configureNeighbor(IPV6UNICAST.class);
356         spyDeployer.onDataTreeChanged(this.collection);
357         verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
358         verifyPrivate(spyDeployer, times(3)).invoke("onNeighborsChanged",
359                 any(DataObjectModification.class), any(InstanceIdentifier.class));
360         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
361         verify(this.bundleContext, times(2))
362                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
363
364         //Delete existing Peer
365         doReturn(DELETE).when(this.dObject).getModificationType();
366
367         spyDeployer.onDataTreeChanged(this.collection);
368         verify(spyDeployer, times(5)).onDataTreeChanged(any(Collection.class));
369         verify(this.dObject).getDataBefore();
370         verifyPrivate(spyDeployer, times(4)).invoke("onNeighborsChanged",
371                 any(DataObjectModification.class), any(InstanceIdentifier.class));
372         verify(this.bundleContext, times(2))
373                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
374
375         deployer.close();
376     }
377
378     private void configureNeighbor(final Class<? extends AfiSafiType> afi) {
379         doReturn(createNeighborExpected(afi)).when(this.dObject).getDataAfter();
380         doReturn(createNeighborExpected(afi)).when(this.dObject).getDataBefore();
381     }
382 }