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