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