Policy exclusions & parallel netconf transactions
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / policy / VppRendererPolicyManagerTest.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.groupbasedpolicy.renderer.vpp.policy;
10
11 import java.util.AbstractMap;
12 import java.util.Arrays;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.locks.ReentrantLock;
17 import java.util.stream.Collectors;
18
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mockito;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import org.opendaylight.controller.config.yang.config.vpp_provider.impl.VppRenderer;
26 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
27 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
28 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
30 import org.opendaylight.groupbasedpolicy.renderer.vpp.DtoFactory;
31 import org.opendaylight.groupbasedpolicy.renderer.vpp.dhcp.DhcpRelayHandler;
32 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.RendererPolicyConfEvent;
33 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
34 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
35 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppEndpointLocationProvider;
36 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
37 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
38 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
39 import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatManager;
40 import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AclManager;
41 import org.opendaylight.groupbasedpolicy.renderer.vpp.routing.RoutingManager;
42 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
43 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
44 import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
45 import org.opendaylight.groupbasedpolicy.util.IidFactory;
46 import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.Endpoints;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.AddressEndpoints;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.L2FloodDomain;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.VhostUserCaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.bridge.domain.base.attributes.PhysicalLocationRef;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.BridgeDomains;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VxlanVni;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.Interconnection;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBased;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyVbridgeAugment;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev170327.TunnelTypeVxlan;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev170327.network.topology.topology.tunnel.parameters.VxlanTunnelParameters;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
84 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
85
86 import com.google.common.base.Optional;
87 import com.google.common.base.Strings;
88
89 @RunWith(MockitoJUnitRunner.class)
90 public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
91
92     private static final InstanceIdentifier<RendererPolicy> RENDERER_POLICY_IID =
93             IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class);
94     private final static String SOCKET = "socket";
95
96     private MountedDataBrokerProvider mountedDataProviderMock;
97     private DataBroker mountPointDataBroker;
98     private DataBroker dataBroker;
99
100     private BridgeDomainManagerImpl bdManager;
101     private InterfaceManager ifaceManager;
102     private AclManager aclManager;
103     private ForwardingManager fwManager;
104     private NatManager natManager;
105     private RoutingManager routingManager;
106     private LispStateManager lispStateManager;
107     private LoopbackManager loopbackManager;
108     private FlatOverlayManager flatOverlayManager;
109     private DhcpRelayHandler dhcpRelayHandler;
110     private VppRendererPolicyManager vppRendererPolicyManager;
111
112     @Override
113     public Collection<Class<?>> getClassesFromModules() {
114         return Arrays.asList(Node.class, VppEndpoint.class, Interfaces.class, BridgeDomains.class,
115                 LocationProviders.class, L2FloodDomain.class, VxlanVni.class, TopologyVbridgeAugment.class,
116                 TunnelTypeVxlan.class, PhysicalLocationRef.class, AccessLists.class,
117                 VppInterfaceAugmentation.class, VppAclInterfaceAugmentation.class, VxlanTunnelParameters.class);
118     }
119
120     @Before
121     public void init() throws Exception {
122         mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
123         mountPointDataBroker = getDataBroker();
124         setup(); // initialize new data broker for ODL data store
125         dataBroker = getDataBroker();
126         Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
127             .thenReturn(Optional.of(mountPointDataBroker));
128         lispStateManager = new LispStateManager(mountedDataProviderMock);
129         loopbackManager = new LoopbackManager(mountedDataProviderMock);
130         flatOverlayManager = new FlatOverlayManager(dataBroker, mountedDataProviderMock);
131         ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker, flatOverlayManager);
132         aclManager = new AclManager(mountedDataProviderMock, ifaceManager);
133         natManager = new NatManager(dataBroker, mountedDataProviderMock);
134         routingManager = new RoutingManager(dataBroker, mountedDataProviderMock);
135         bdManager = new BridgeDomainManagerImpl(mountPointDataBroker);
136         dhcpRelayHandler = new DhcpRelayHandler(dataBroker, mountedDataProviderMock);
137         fwManager = new ForwardingManager(ifaceManager, aclManager, natManager, routingManager, bdManager,
138                 lispStateManager, loopbackManager, flatOverlayManager, dhcpRelayHandler, dataBroker);
139         vppRendererPolicyManager = new VppRendererPolicyManager(fwManager, aclManager, dataBroker);
140         fwManager.setTimer((byte) 1);
141         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(DtoFactory.VPP_NODE_1_IID,
142                 new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
143         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(DtoFactory.VPP_NODE_2_IID,
144                 new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
145     }
146
147     @Test
148     public void testRendererPolicyChanged_created_oneEpPerEpg() throws Exception {
149         String clientIp = "1.1.1.1/32";
150         String clientIfaceName = "client1";
151         AbsoluteLocation clientLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, clientIfaceName);
152         AddressEndpointWithLocation clientEp =
153                 DtoFactory.createEndpoint(clientIp, DtoFactory.L2FD_CTX.getValue(), clientLocation);
154         String webIp = "2.2.2.2/32";
155         String webIfaceName = "web1";
156         AbsoluteLocation webLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, webIfaceName);
157         AddressEndpointWithLocation webEp =
158                 DtoFactory.createEndpoint(webIp, DtoFactory.L2FD_CTX.getValue(), webLocation);
159
160         storeVppEndpoint(clientEp.getKey(), clientIfaceName, createVppEndpointIid(clientEp.getKey()));
161         storeVppEndpoint(webEp.getKey(), webIfaceName, createVppEndpointIid(webEp.getKey()));
162
163         Configuration configuration = DtoFactory.createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
164         RendererPolicy rendererPolicy =
165                 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
166         RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
167
168         vppRendererPolicyManager.rendererPolicyChanged(event);
169
170         // assert state on data store behind mount point
171         Interface clientIface = readAndAssertInterface(clientIfaceName);
172         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), clientIface);
173         Interface webIface = readAndAssertInterface(webIfaceName);
174         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), webIface);
175         // assert state on ODL data store
176         ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
177         Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
178                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
179             .get();
180         Assert.assertTrue(optLocationProvider.isPresent());
181         System.out.println("DEBUGG " + optLocationProvider.get());
182         List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
183         Assert.assertNotNull(epLocs);
184         Assert.assertEquals(2, epLocs.size());
185         assertProviderAddressEndpointLocation(clientEp.getKey(),
186                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), clientIfaceName),
187                 epLocs);
188         assertProviderAddressEndpointLocation(webEp.getKey(),
189                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), webIfaceName),
190                 epLocs);
191     }
192
193     @Test
194     public void testRendererPolicyChanged_update() throws Exception {
195         String client1IfaceName = "client1";
196         AbsoluteLocation client1LocationNodeNull =
197                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client1IfaceName);
198         AddressEndpointWithLocation client1Ep =
199                 DtoFactory.createEndpoint("10.0.0.1/32", DtoFactory.L2FD_CTX.getValue(), client1LocationNodeNull);
200         String web1IfaceName = "web1";
201         AbsoluteLocation web1LocationNodeNull =
202                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web1IfaceName);
203         AddressEndpointWithLocation web1Ep =
204                 DtoFactory.createEndpoint("20.0.0.1/32", DtoFactory.L2FD_CTX.getValue(), web1LocationNodeNull);
205         String client2IfaceName = "client2";
206         AbsoluteLocation client2LocationNodeNull =
207                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client2IfaceName);
208         AddressEndpointWithLocation client2Ep =
209                 DtoFactory.createEndpoint("10.0.0.2/32", DtoFactory.L2FD_CTX.getValue(), client2LocationNodeNull);
210         String web2IfaceName = "web2";
211         AbsoluteLocation web2LocationNodeNull =
212                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web2IfaceName);
213         AddressEndpointWithLocation web2Ep =
214                 DtoFactory.createEndpoint("20.0.0.2/32", DtoFactory.L2FD_CTX.getValue(), web2LocationNodeNull);
215
216         storeVppEndpoint(client1Ep.getKey(), client1IfaceName, createVppEndpointIid(client1Ep.getKey()));
217         storeVppEndpoint(web1Ep.getKey(), web1IfaceName, createVppEndpointIid(web1Ep.getKey()));
218         storeVppEndpoint(client2Ep.getKey(), client2IfaceName, createVppEndpointIid(client2Ep.getKey()));
219         storeVppEndpoint(web2Ep.getKey(), web2IfaceName, createVppEndpointIid(web2Ep.getKey()));
220
221         Configuration configuration =
222                 DtoFactory.createConfiguration(Arrays.asList(client1Ep, client2Ep), Arrays.asList(web1Ep, web2Ep));
223         RendererPolicy rendererPolicy =
224                 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
225         RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
226
227         vppRendererPolicyManager.rendererPolicyChanged(event);
228
229         // assert state on data store behind mount point ######################################
230         Interface client1Iface = readAndAssertInterface(client1IfaceName);
231         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
232         Interface web1Iface = readAndAssertInterface(web1IfaceName);
233         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
234         Interface client2Iface = readAndAssertInterface(client2IfaceName);
235         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
236         Interface web2Iface = readAndAssertInterface(web2IfaceName);
237         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
238         // assert state on ODL data store
239         ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
240         Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
241                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
242             .get();
243         Assert.assertTrue(optLocationProvider.isPresent());
244         List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
245         Assert.assertNotNull(epLocs);
246         Assert.assertEquals(4, epLocs.size());
247         assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
248                 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
249         assertProviderAddressEndpointLocation(web1Ep.getKey(),
250                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
251                 epLocs);
252         assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
253                 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
254         assertProviderAddressEndpointLocation(web2Ep.getKey(),
255                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
256                 epLocs);
257         // #####################################################################################
258
259         AbsoluteLocation client1Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
260                 DtoFactory.L2FD_CTX.getValue(), client1IfaceName);
261         AbsoluteLocation web1Location =
262                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName);
263         AbsoluteLocation web2Location =
264                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName);
265         configuration = DtoFactory.createConfiguration(
266                 Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
267                     .build(),
268                         new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2LocationNodeNull)
269                             .build()),
270                 Arrays.asList(new AddressEndpointWithLocationBuilder(web1Ep).setAbsoluteLocation(web1Location).build(),
271                         new AddressEndpointWithLocationBuilder(web2Ep).setAbsoluteLocation(web2Location).build()));
272         RendererPolicy rendererPolicy2 =
273                 new RendererPolicyBuilder().setVersion(2L).setConfiguration(configuration).build();
274         RendererPolicyConfEvent event2 =
275                 new RendererPolicyConfEvent(RENDERER_POLICY_IID, rendererPolicy, rendererPolicy2);
276
277         vppRendererPolicyManager.rendererPolicyChanged(event2);
278
279         // assert state on data store behind mount point ######################################
280         client1Iface = readAndAssertInterface(client1IfaceName);
281         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
282         web1Iface = readAndAssertInterface(web1IfaceName);
283         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
284         client2Iface = readAndAssertInterface(client2IfaceName);
285         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
286         web2Iface = readAndAssertInterface(web2IfaceName);
287         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
288         // assert state on ODL data store
289         rTx = dataBroker.newReadOnlyTransaction();
290         optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
291                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
292             .get();
293         Assert.assertTrue(optLocationProvider.isPresent());
294         epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
295         Assert.assertNotNull(epLocs);
296         Assert.assertEquals(4, epLocs.size());
297         assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
298                 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
299         assertProviderAddressEndpointLocation(web1Ep.getKey(),
300                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
301                 epLocs);
302         assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
303                 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
304         assertProviderAddressEndpointLocation(web2Ep.getKey(),
305                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
306                 epLocs);
307         // #####################################################################################
308
309         AbsoluteLocation client2Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
310                 DtoFactory.L2FD_CTX.getValue(), client2IfaceName);
311         configuration = DtoFactory.createConfiguration(
312                 Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
313                     .build(),
314                         new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2Location).build()),
315                 Arrays.asList(new AddressEndpointWithLocationBuilder(web1Ep).setAbsoluteLocation(web1Location).build(),
316                         new AddressEndpointWithLocationBuilder(web2Ep).setAbsoluteLocation(web2Location).build()));
317         RendererPolicy rendererPolicy3 =
318                 new RendererPolicyBuilder().setVersion(3L).setConfiguration(configuration).build();
319         RendererPolicyConfEvent event3 =
320                 new RendererPolicyConfEvent(RENDERER_POLICY_IID, rendererPolicy2, rendererPolicy3);
321
322         vppRendererPolicyManager.rendererPolicyChanged(event3);
323
324         // assert state on data store behind mount point ######################################
325         client1Iface = readAndAssertInterface(client1IfaceName);
326         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
327         web1Iface = readAndAssertInterface(web1IfaceName);
328         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
329         client2Iface = readAndAssertInterface(client2IfaceName);
330         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
331         web2Iface = readAndAssertInterface(web2IfaceName);
332         assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
333         // assert state on ODL data store
334         rTx = dataBroker.newReadOnlyTransaction();
335         optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
336                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
337             .get();
338         Assert.assertTrue(optLocationProvider.isPresent());
339         epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
340         Assert.assertNotNull(epLocs);
341         Assert.assertEquals(4, epLocs.size());
342         assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
343                 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
344         assertProviderAddressEndpointLocation(web1Ep.getKey(),
345                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
346                 epLocs);
347         assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
348                 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
349         assertProviderAddressEndpointLocation(web2Ep.getKey(),
350                 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
351                 epLocs);
352         // #####################################################################################
353     }
354
355     private InstanceIdentifier<VppEndpoint> createVppEndpointIid(AddressEndpointWithLocationKey key) {
356         return InstanceIdentifier.builder(Config.class)
357             .child(VppEndpoint.class, new VppEndpointKey(key.getAddress(), key.getAddressType(), key.getContextId(),
358                     key.getContextType()))
359             .build();
360     }
361
362     private void assertProviderAddressEndpointLocation(AddressEndpointWithLocationKey expectedEpKey,
363             AbsoluteLocation expectedEpLoc, List<ProviderAddressEndpointLocation> providerEpLocs) {
364         List<ProviderAddressEndpointLocation> expectedProvEpLoc =
365                 providerEpLocs.stream()
366                     .filter(provEpLoc -> provEpLoc.getKey()
367                         .equals(KeyFactory.providerAddressEndpointLocationKey(expectedEpKey)))
368                     .collect(Collectors.toList());
369         Assert.assertFalse(expectedProvEpLoc.isEmpty());
370         Assert.assertEquals(1, expectedProvEpLoc.size());
371         Assert.assertEquals(expectedEpLoc, expectedProvEpLoc.get(0).getAbsoluteLocation());
372     }
373
374     private Interface readAndAssertInterface(String expectedInterface) throws Exception {
375         ReadOnlyTransaction rTxMount = mountPointDataBroker.newReadOnlyTransaction();
376         Optional<Interface> potentialIface = rTxMount.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
377             .builder(Interfaces.class).child(Interface.class, new InterfaceKey(expectedInterface)).build()).get();
378         Assert.assertTrue(potentialIface.isPresent());
379         return potentialIface.get();
380     }
381
382     private static void assertBridgeDomainOnInterface(String expectedBridgeDomain, Interface actualIface) {
383         VppInterfaceAugmentation vppIfaceAug = actualIface.getAugmentation(VppInterfaceAugmentation.class);
384         Assert.assertNotNull(vppIfaceAug);
385         if (!Strings.isNullOrEmpty(expectedBridgeDomain)) {
386             Interconnection interconnection = vppIfaceAug.getL2().getInterconnection();
387             Assert.assertNotNull(interconnection);
388             Assert.assertTrue(interconnection instanceof BridgeBased);
389             Assert.assertEquals(expectedBridgeDomain, ((BridgeBased) interconnection).getBridgeDomain());
390         } else {
391             if (vppIfaceAug != null) {
392                 L2 l2 = vppIfaceAug.getL2();
393                 if (l2 != null) {
394                     Assert.assertNull(l2.getInterconnection());
395                 }
396             }
397         }
398     }
399
400     private void storeVppEndpoint(AddressEndpointWithLocationKey clientEp, String ifaceName,
401             InstanceIdentifier<VppEndpoint> vppEpIid) {
402         AddressEndpoint addrEp = new AddressEndpointBuilder().setKey(new AddressEndpointKey(clientEp.getAddress(),
403                 clientEp.getAddressType(), clientEp.getContextId(), clientEp.getContextType()))
404             .build();
405         InstanceIdentifier<AddressEndpoint> iid = InstanceIdentifier.create(Endpoints.class)
406             .child(AddressEndpoints.class)
407             .child(AddressEndpoint.class, addrEp.getKey());
408         WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
409         wTx.put(LogicalDatastoreType.OPERATIONAL, iid, addrEp);
410         try {
411             wTx.submit().get();
412         } catch (InterruptedException | ExecutionException e) {
413             e.printStackTrace();
414         }
415
416         VppEndpoint vhostEp = new VppEndpointBuilder().setAddress(clientEp.getAddress())
417             .setAddressType(clientEp.getAddressType())
418             .setContextId(clientEp.getContextId())
419             .setContextType(clientEp.getContextType())
420             .setVppInterfaceName(ifaceName)
421             .setVppNodeId(DtoFactory.VPP_NODE_1_IID.firstKeyOf(Node.class).getNodeId())
422             .setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(SOCKET).build())
423             .build();
424         VppEndpointConfEvent vppEpEvent = new VppEndpointConfEvent(vppEpIid, null, vhostEp);
425         ifaceManager.vppEndpointChanged(vppEpEvent);
426     }
427
428 }