2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
11 import java.util.Arrays;
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.stream.Collectors;
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.lisp.LispStateManager;
32 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
33 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
34 import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatManager;
35 import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AclManager;
36 import org.opendaylight.groupbasedpolicy.renderer.vpp.routing.RoutingManager;
37 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
38 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
39 import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
40 import org.opendaylight.groupbasedpolicy.util.IidFactory;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationKey;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.VhostUserCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.bridge.domain.base.attributes.PhysicalLocationRef;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VxlanVni;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.L2;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.base.attributes.Interconnection;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.base.attributes.interconnection.BridgeBased;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.BridgeDomains;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyVbridgeAugment;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev170327.TunnelTypeVxlan;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
70 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import com.google.common.base.Optional;
73 import com.google.common.base.Strings;
75 @RunWith(MockitoJUnitRunner.class)
76 public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
78 private static final InstanceIdentifier<RendererPolicy> RENDERER_POLICY_IID =
79 IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class);
80 private final static String SOCKET = "socket";
82 private MountedDataBrokerProvider mountedDataProviderMock;
83 private DataBroker mountPointDataBroker;
84 private DataBroker dataBroker;
86 private BridgeDomainManagerImpl bdManager;
87 private InterfaceManager ifaceManager;
88 private AclManager aclManager;
89 private ForwardingManager fwManager;
90 private NatManager natManager;
91 private RoutingManager routingManager;
92 private LispStateManager lispStateManager;
93 private LoopbackManager loopbackManager;
94 private FlatOverlayManager flatOverlayManager;
95 private VppRendererPolicyManager vppRendererPolicyManager;
98 public Collection<Class<?>> getClassesFromModules() {
99 return Arrays.asList(Node.class, VppEndpoint.class, Interfaces.class, BridgeDomains.class,
100 LocationProviders.class, L2FloodDomain.class, VxlanVni.class, TopologyVbridgeAugment.class,
101 TunnelTypeVxlan.class, PhysicalLocationRef.class);
105 public void init() throws Exception {
106 mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
107 mountPointDataBroker = getDataBroker();
108 setup(); // initialize new data broker for ODL data store
109 dataBroker = getDataBroker();
110 Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
111 .thenReturn(Optional.of(mountPointDataBroker));
112 ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker);
113 aclManager = new AclManager(mountedDataProviderMock);
114 natManager = new NatManager(dataBroker, mountedDataProviderMock);
115 routingManager = new RoutingManager(dataBroker, mountedDataProviderMock);
116 bdManager = new BridgeDomainManagerImpl(mountPointDataBroker);
117 lispStateManager = new LispStateManager(mountedDataProviderMock);
118 loopbackManager = new LoopbackManager(mountedDataProviderMock);
119 flatOverlayManager = new FlatOverlayManager(mountedDataProviderMock);
120 fwManager = new ForwardingManager(ifaceManager, aclManager, natManager, routingManager, bdManager,
121 lispStateManager, loopbackManager, flatOverlayManager, dataBroker);
122 vppRendererPolicyManager = new VppRendererPolicyManager(fwManager, aclManager, dataBroker);
123 fwManager.setTimer((byte) 1);
127 public void testRendererPolicyChanged_created_oneEpPerEpg() throws Exception {
128 String clientIp = "1.1.1.1/32";
129 String clientIfaceName = "client1";
130 AbsoluteLocation clientLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, clientIfaceName);
131 AddressEndpointWithLocation clientEp =
132 DtoFactory.createEndpoint(clientIp, DtoFactory.L2FD_CTX.getValue(), clientLocation);
133 String webIp = "2.2.2.2/32";
134 String webIfaceName = "web1";
135 AbsoluteLocation webLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, webIfaceName);
136 AddressEndpointWithLocation webEp =
137 DtoFactory.createEndpoint(webIp, DtoFactory.L2FD_CTX.getValue(), webLocation);
139 storeVppEndpoint(clientEp.getKey(), clientIfaceName, createVppEndpointIid(clientEp.getKey()));
140 storeVppEndpoint(webEp.getKey(), webIfaceName, createVppEndpointIid(webEp.getKey()));
142 Configuration configuration = DtoFactory.createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
143 RendererPolicy rendererPolicy =
144 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
145 RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
147 vppRendererPolicyManager.rendererPolicyChanged(event);
149 // assert state on data store behind mount point
150 Interface clientIface = readAndAssertInterface(clientIfaceName);
151 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), clientIface);
152 Interface webIface = readAndAssertInterface(webIfaceName);
153 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), webIface);
154 // assert state on ODL data store
155 ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
156 Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
157 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
159 Assert.assertTrue(optLocationProvider.isPresent());
160 List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
161 Assert.assertNotNull(epLocs);
162 Assert.assertEquals(2, epLocs.size());
163 assertProviderAddressEndpointLocation(clientEp.getKey(),
164 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), clientIfaceName),
166 assertProviderAddressEndpointLocation(webEp.getKey(),
167 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), webIfaceName),
172 public void testRendererPolicyChanged_update() throws Exception {
173 String client1IfaceName = "client1";
174 AbsoluteLocation client1LocationNodeNull =
175 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client1IfaceName);
176 AddressEndpointWithLocation client1Ep =
177 DtoFactory.createEndpoint("10.0.0.1/32", DtoFactory.L2FD_CTX.getValue(), client1LocationNodeNull);
178 String web1IfaceName = "web1";
179 AbsoluteLocation web1LocationNodeNull =
180 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web1IfaceName);
181 AddressEndpointWithLocation web1Ep =
182 DtoFactory.createEndpoint("20.0.0.1/32", DtoFactory.L2FD_CTX.getValue(), web1LocationNodeNull);
183 String client2IfaceName = "client2";
184 AbsoluteLocation client2LocationNodeNull =
185 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client2IfaceName);
186 AddressEndpointWithLocation client2Ep =
187 DtoFactory.createEndpoint("10.0.0.2/32", DtoFactory.L2FD_CTX.getValue(), client2LocationNodeNull);
188 String web2IfaceName = "web2";
189 AbsoluteLocation web2LocationNodeNull =
190 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web2IfaceName);
191 AddressEndpointWithLocation web2Ep =
192 DtoFactory.createEndpoint("20.0.0.2/32", DtoFactory.L2FD_CTX.getValue(), web2LocationNodeNull);
194 storeVppEndpoint(client1Ep.getKey(), client1IfaceName, createVppEndpointIid(client1Ep.getKey()));
195 storeVppEndpoint(web1Ep.getKey(), web1IfaceName, createVppEndpointIid(web1Ep.getKey()));
196 storeVppEndpoint(client2Ep.getKey(), client2IfaceName, createVppEndpointIid(client2Ep.getKey()));
197 storeVppEndpoint(web2Ep.getKey(), web2IfaceName, createVppEndpointIid(web2Ep.getKey()));
199 Configuration configuration =
200 DtoFactory.createConfiguration(Arrays.asList(client1Ep, client2Ep), Arrays.asList(web1Ep, web2Ep));
201 RendererPolicy rendererPolicy =
202 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
203 RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
205 vppRendererPolicyManager.rendererPolicyChanged(event);
207 // assert state on data store behind mount point ######################################
208 Interface client1Iface = readAndAssertInterface(client1IfaceName);
209 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
210 Interface web1Iface = readAndAssertInterface(web1IfaceName);
211 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
212 Interface client2Iface = readAndAssertInterface(client2IfaceName);
213 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
214 Interface web2Iface = readAndAssertInterface(web2IfaceName);
215 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
216 // assert state on ODL data store
217 ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
218 Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
219 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
221 Assert.assertTrue(optLocationProvider.isPresent());
222 List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
223 Assert.assertNotNull(epLocs);
224 Assert.assertEquals(4, epLocs.size());
225 assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
226 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
227 assertProviderAddressEndpointLocation(web1Ep.getKey(),
228 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
230 assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
231 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
232 assertProviderAddressEndpointLocation(web2Ep.getKey(),
233 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
235 // #####################################################################################
237 AbsoluteLocation client1Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
238 DtoFactory.L2FD_CTX.getValue(), client1IfaceName);
239 AbsoluteLocation web1Location =
240 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName);
241 AbsoluteLocation web2Location =
242 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName);
243 configuration = DtoFactory.createConfiguration(
244 Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
246 new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2LocationNodeNull)
248 Arrays.asList(new AddressEndpointWithLocationBuilder(web1Ep).setAbsoluteLocation(web1Location).build(),
249 new AddressEndpointWithLocationBuilder(web2Ep).setAbsoluteLocation(web2Location).build()));
250 RendererPolicy rendererPolicy2 =
251 new RendererPolicyBuilder().setVersion(2L).setConfiguration(configuration).build();
252 RendererPolicyConfEvent event2 =
253 new RendererPolicyConfEvent(RENDERER_POLICY_IID, rendererPolicy, rendererPolicy2);
255 vppRendererPolicyManager.rendererPolicyChanged(event2);
257 // assert state on data store behind mount point ######################################
258 client1Iface = readAndAssertInterface(client1IfaceName);
259 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
260 web1Iface = readAndAssertInterface(web1IfaceName);
261 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
262 client2Iface = readAndAssertInterface(client2IfaceName);
263 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
264 web2Iface = readAndAssertInterface(web2IfaceName);
265 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
266 // assert state on ODL data store
267 rTx = dataBroker.newReadOnlyTransaction();
268 optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
269 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
271 Assert.assertTrue(optLocationProvider.isPresent());
272 epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
273 Assert.assertNotNull(epLocs);
274 Assert.assertEquals(4, epLocs.size());
275 assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
276 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
277 assertProviderAddressEndpointLocation(web1Ep.getKey(),
278 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
280 assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
281 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
282 assertProviderAddressEndpointLocation(web2Ep.getKey(),
283 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
285 // #####################################################################################
287 AbsoluteLocation client2Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
288 DtoFactory.L2FD_CTX.getValue(), client2IfaceName);
289 configuration = DtoFactory.createConfiguration(
290 Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
292 new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2Location).build()),
293 Arrays.asList(new AddressEndpointWithLocationBuilder(web1Ep).setAbsoluteLocation(web1Location).build(),
294 new AddressEndpointWithLocationBuilder(web2Ep).setAbsoluteLocation(web2Location).build()));
295 RendererPolicy rendererPolicy3 =
296 new RendererPolicyBuilder().setVersion(3L).setConfiguration(configuration).build();
297 RendererPolicyConfEvent event3 =
298 new RendererPolicyConfEvent(RENDERER_POLICY_IID, rendererPolicy2, rendererPolicy3);
300 vppRendererPolicyManager.rendererPolicyChanged(event3);
302 // assert state on data store behind mount point ######################################
303 client1Iface = readAndAssertInterface(client1IfaceName);
304 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
305 web1Iface = readAndAssertInterface(web1IfaceName);
306 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
307 client2Iface = readAndAssertInterface(client2IfaceName);
308 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
309 web2Iface = readAndAssertInterface(web2IfaceName);
310 assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
311 // assert state on ODL data store
312 rTx = dataBroker.newReadOnlyTransaction();
313 optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
314 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
316 Assert.assertTrue(optLocationProvider.isPresent());
317 epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
318 Assert.assertNotNull(epLocs);
319 Assert.assertEquals(4, epLocs.size());
320 assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
321 DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
322 assertProviderAddressEndpointLocation(web1Ep.getKey(),
323 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
325 assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
326 DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
327 assertProviderAddressEndpointLocation(web2Ep.getKey(),
328 DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
330 // #####################################################################################
333 private InstanceIdentifier<VppEndpoint> createVppEndpointIid(AddressEndpointWithLocationKey key) {
334 return InstanceIdentifier.builder(Config.class)
335 .child(VppEndpoint.class, new VppEndpointKey(key.getAddress(), key.getAddressType(), key.getContextId(),
336 key.getContextType()))
340 private void assertProviderAddressEndpointLocation(AddressEndpointWithLocationKey expectedEpKey,
341 AbsoluteLocation expectedEpLoc, List<ProviderAddressEndpointLocation> providerEpLocs) {
342 List<ProviderAddressEndpointLocation> expectedProvEpLoc =
343 providerEpLocs.stream()
344 .filter(provEpLoc -> provEpLoc.getKey()
345 .equals(KeyFactory.providerAddressEndpointLocationKey(expectedEpKey)))
346 .collect(Collectors.toList());
347 Assert.assertFalse(expectedProvEpLoc.isEmpty());
348 Assert.assertEquals(1, expectedProvEpLoc.size());
349 Assert.assertEquals(expectedEpLoc, expectedProvEpLoc.get(0).getAbsoluteLocation());
352 private Interface readAndAssertInterface(String expectedInterface) throws Exception {
353 ReadOnlyTransaction rTxMount = mountPointDataBroker.newReadOnlyTransaction();
354 Optional<Interface> potentialIface = rTxMount.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
355 .builder(Interfaces.class).child(Interface.class, new InterfaceKey(expectedInterface)).build()).get();
356 Assert.assertTrue(potentialIface.isPresent());
357 return potentialIface.get();
360 private static void assertBridgeDomainOnInterface(String expectedBridgeDomain, Interface actualIface) {
361 VppInterfaceAugmentation vppIfaceAug = actualIface.getAugmentation(VppInterfaceAugmentation.class);
362 Assert.assertNotNull(vppIfaceAug);
363 if (!Strings.isNullOrEmpty(expectedBridgeDomain)) {
364 Interconnection interconnection = vppIfaceAug.getL2().getInterconnection();
365 Assert.assertNotNull(interconnection);
366 Assert.assertTrue(interconnection instanceof BridgeBased);
367 Assert.assertEquals(expectedBridgeDomain, ((BridgeBased) interconnection).getBridgeDomain());
369 if (vppIfaceAug != null) {
370 L2 l2 = vppIfaceAug.getL2();
372 Assert.assertNull(l2.getInterconnection());
378 private void storeVppEndpoint(AddressEndpointWithLocationKey epKey, String ifaceName,
379 InstanceIdentifier<VppEndpoint> vppEpIid) {
380 VppEndpoint vhostEp = new VppEndpointBuilder().setAddress(epKey.getAddress())
381 .setAddressType(epKey.getAddressType())
382 .setContextId(epKey.getContextId())
383 .setContextType(epKey.getContextType())
384 .setVppInterfaceName(ifaceName)
385 .setVppNodeId(DtoFactory.VPP_NODE_1_IID.firstKeyOf(Node.class).getNodeId())
386 .setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(SOCKET).build())
388 VppEndpointConfEvent vppEpEvent = new VppEndpointConfEvent(vppEpIid, null, vhostEp);
389 ifaceManager.vppEndpointChanged(vppEpEvent);