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