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