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