c43dea6443ba70ee7397aae1a58597809fa95a5d
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / policy / VppRendererPolicyManagerTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
10
11 import java.util.Arrays;
12 import java.util.Collection;
13 import java.util.List;
14
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mockito;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.controller.config.yang.config.vpp_provider.impl.VppRenderer;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.RendererPolicyConfEvent;
26 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
27 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
28 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppEndpointLocationProvider;
29 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppPathMapper;
30 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
31 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
32 import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
33 import org.opendaylight.groupbasedpolicy.util.IidFactory;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainment;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.network.containment.containment.ForwardingContextContainmentBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipation;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipationBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.ConfigurationBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.EndpointsBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RendererEndpointsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RuleGroupsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpointWithPolicyBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroup;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.resolved.rules.ResolvedRuleBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.vpp.endpoint._interface.type.choice.VhostUserCaseBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.attributes.Interconnection;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.attributes.interconnection.BridgeBased;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
90 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
91
92 import com.google.common.base.Optional;
93
94 @RunWith(MockitoJUnitRunner.class)
95 public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
96
97     private static final InstanceIdentifier<RendererPolicy> RENDERER_POLICY_IID =
98             IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class);
99     private static final ContextId CTX_ID = new ContextId("ctx");
100     private static final AddressEndpointWithLocationKey CLIENT_EP_KEY =
101             new AddressEndpointWithLocationKey("1.1.1.1", AddressType.class, CTX_ID, ContextType.class);
102     private static final AddressEndpointWithLocationKey WEB_EP_KEY =
103             new AddressEndpointWithLocationKey("2.2.2.2", AddressType.class, CTX_ID, ContextType.class);
104     private static final ContextId L2FD_CTX = new ContextId("l2fd");
105     private static final NetworkContainment L2FD_NET_CONT =
106             new NetworkContainmentBuilder().setContainment(new ForwardingContextContainmentBuilder()
107                 .setContextType(L2FloodDomain.class).setContextId(L2FD_CTX).build()).build();
108     private final static TopologyKey TOPO_KEY = new TopologyKey(new TopologyId("topo1"));
109     private final static NodeKey NODE_KEY = new NodeKey(new NodeId("node1"));
110     private final static InstanceIdentifier<Node> VPP_NODE_IID = InstanceIdentifier.builder(NetworkTopology.class)
111         .child(Topology.class, TOPO_KEY)
112         .child(Node.class, NODE_KEY)
113         .build();
114     private static final String IFACE_NAME_CLIENT_EP = "interfaceClient";
115     private static final String NODE_CONNECTOR_CLIENT_EP = VppPathMapper.interfaceToRestPath(IFACE_NAME_CLIENT_EP);
116     private static final String IFACE_NAME_WEB_EP = "interfaceWeb";
117     private static final String NODE_CONNECTOR_WEB_EP = VppPathMapper.interfaceToRestPath(IFACE_NAME_WEB_EP);
118     private static final ContractId CONTRACT_ID = new ContractId("contract");
119     private static final TenantId TENANT_ID = new TenantId("tenant");
120     private static final SubjectName SUBJECT_NAME = new SubjectName("subject");
121     private static final RuleName RULE_NAME = new RuleName("rule");
122     private static final RuleGroupWithRendererEndpointParticipation RULE_GROUP_WITH_REND_EP_PART =
123             new RuleGroupWithRendererEndpointParticipationBuilder().setContractId(CONTRACT_ID)
124                 .setTenantId(TENANT_ID)
125                 .setSubjectName(SUBJECT_NAME)
126                 .setRendererEndpointParticipation(EndpointPolicyParticipation.CONSUMER)
127                 .build();
128     private static final RuleGroup RULE_GROUP = new RuleGroupBuilder().setContractId(CONTRACT_ID)
129         .setTenantId(TENANT_ID)
130         .setSubjectName(SUBJECT_NAME)
131         .setResolvedRule(Arrays.asList(new ResolvedRuleBuilder().setName(RULE_NAME).build()))
132         .build();
133     // data for InterfaceManager
134     private final static InstanceIdentifier<VppEndpoint> BASIC_VPP_CLIENT_EP_IID =
135             InstanceIdentifier.builder(Config.class)
136                 .child(VppEndpoint.class, new VppEndpointKey(CLIENT_EP_KEY.getAddress(), CLIENT_EP_KEY.getAddressType(),
137                         CLIENT_EP_KEY.getContextId(), CLIENT_EP_KEY.getContextType()))
138                 .build();
139     private final static InstanceIdentifier<VppEndpoint> BASIC_VPP_WEB_EP_IID = InstanceIdentifier.builder(Config.class)
140         .child(VppEndpoint.class, new VppEndpointKey(WEB_EP_KEY.getAddress(), WEB_EP_KEY.getAddressType(),
141                 WEB_EP_KEY.getContextId(), WEB_EP_KEY.getContextType()))
142         .build();
143     private final static String SOCKET = "socket";
144
145     private MountedDataBrokerProvider mountedDataProviderMock;
146     private DataBroker mountPointDataBroker;
147     private DataBroker dataBroker;
148
149     private InterfaceManager ifaceManager;
150     private VppRendererPolicyManager vppRendererPolicyManager;
151
152     @Override
153     public Collection<Class<?>> getClassesFromModules() {
154         return Arrays.asList(Node.class, VppEndpoint.class, Interfaces.class, BridgeDomains.class,
155                 LocationProviders.class, L2FloodDomain.class);
156     }
157
158     @Before
159     public void init() throws Exception {
160         mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
161         mountPointDataBroker = getDataBroker();
162         setup(); // initialize new data broker for ODL data store
163         dataBroker = getDataBroker();
164         Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
165             .thenReturn(Optional.of(mountPointDataBroker));
166         ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker);
167         vppRendererPolicyManager = new VppRendererPolicyManager(ifaceManager, dataBroker);
168     }
169
170     @Test
171     public void testRendererPolicyChanged_createdClient() throws Exception {
172         storeInterfaceFor(CLIENT_EP_KEY, IFACE_NAME_CLIENT_EP, BASIC_VPP_CLIENT_EP_IID);
173
174         AddressEndpointWithLocation clientEp = new AddressEndpointWithLocationBuilder().setKey(CLIENT_EP_KEY)
175             .setNetworkContainment(L2FD_NET_CONT)
176             .setAbsoluteLocation(absoluteLocation(VPP_NODE_IID, null, NODE_CONNECTOR_CLIENT_EP))
177             .build();
178         AddressEndpointWithLocation webEp = new AddressEndpointWithLocationBuilder().setKey(WEB_EP_KEY)
179             .setNetworkContainment(L2FD_NET_CONT)
180             .setAbsoluteLocation(absoluteLocation(VPP_NODE_IID, null, NODE_CONNECTOR_WEB_EP))
181             .build();
182         Endpoints endpoints =
183                 new EndpointsBuilder().setAddressEndpointWithLocation(Arrays.asList(clientEp, webEp)).build();
184         RendererEndpoint rendererEndpoint = new RendererEndpointBuilder()
185             .setKey(KeyFactory.rendererEndpointKey(CLIENT_EP_KEY))
186             .setPeerEndpointWithPolicy(Arrays.asList(new PeerEndpointWithPolicyBuilder()
187                 .setKey(KeyFactory.peerEndpointWithPolicyKey(WEB_EP_KEY))
188                 .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_REND_EP_PART))
189                 .build()))
190             .build();
191         Configuration configuration = new ConfigurationBuilder().setEndpoints(endpoints)
192             .setRendererEndpoints(
193                     new RendererEndpointsBuilder().setRendererEndpoint(Arrays.asList(rendererEndpoint)).build())
194             .setRuleGroups(new RuleGroupsBuilder().setRuleGroup(Arrays.asList(RULE_GROUP)).build())
195             .build();
196         RendererPolicy rendererPolicy =
197                 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
198         RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
199
200         vppRendererPolicyManager.rendererPolicyChanged(event);
201
202         // assert state on data store behind mount point
203         ReadOnlyTransaction rTxMount = mountPointDataBroker.newReadOnlyTransaction();
204         Optional<Interface> potentialIface = rTxMount.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
205             .builder(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME_CLIENT_EP)).build()).get();
206         Assert.assertTrue(potentialIface.isPresent());
207         Interface iface = potentialIface.get();
208         VppInterfaceAugmentation vppIfaceAug = iface.getAugmentation(VppInterfaceAugmentation.class);
209         Assert.assertNotNull(vppIfaceAug);
210         Interconnection interconnection = vppIfaceAug.getL2().getInterconnection();
211         Assert.assertNotNull(interconnection);
212         Assert.assertTrue(interconnection instanceof BridgeBased);
213         Assert.assertEquals(L2FD_CTX.getValue(), ((BridgeBased) interconnection).getBridgeDomain());
214         // assert state on ODL data store
215         ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
216         Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
217                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
218             .get();
219         Assert.assertTrue(optLocationProvider.isPresent());
220         List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
221         Assert.assertNotNull(epLocs);
222         Assert.assertEquals(1, epLocs.size());
223         Assert.assertEquals(absoluteLocation(VPP_NODE_IID, VppPathMapper.bridgeDomainToRestPath(L2FD_CTX.getValue()),
224                 NODE_CONNECTOR_CLIENT_EP), epLocs.get(0).getAbsoluteLocation());
225     }
226
227     @Test
228     public void testRendererPolicyChanged_createdClientAndThenWeb() throws Exception {
229         testRendererPolicyChanged_createdClient();
230
231         storeInterfaceFor(WEB_EP_KEY, IFACE_NAME_WEB_EP, BASIC_VPP_WEB_EP_IID);
232
233         AddressEndpointWithLocation webEp = new AddressEndpointWithLocationBuilder().setKey(WEB_EP_KEY)
234             .setNetworkContainment(L2FD_NET_CONT)
235             .setAbsoluteLocation(absoluteLocation(VPP_NODE_IID, null, NODE_CONNECTOR_WEB_EP))
236             .build();
237         AddressEndpointWithLocation clientEp = new AddressEndpointWithLocationBuilder().setKey(CLIENT_EP_KEY)
238             .setNetworkContainment(L2FD_NET_CONT)
239             .setAbsoluteLocation(absoluteLocation(VPP_NODE_IID, null, NODE_CONNECTOR_CLIENT_EP))
240             .build();
241         Endpoints endpoints =
242                 new EndpointsBuilder().setAddressEndpointWithLocation(Arrays.asList(webEp, clientEp)).build();
243         RendererEndpoint rendererEndpoint = new RendererEndpointBuilder()
244             .setKey(KeyFactory.rendererEndpointKey(WEB_EP_KEY))
245             .setPeerEndpointWithPolicy(Arrays.asList(new PeerEndpointWithPolicyBuilder()
246                 .setKey(KeyFactory.peerEndpointWithPolicyKey(CLIENT_EP_KEY))
247                 .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_REND_EP_PART))
248                 .build()))
249             .build();
250         Configuration configuration = new ConfigurationBuilder().setEndpoints(endpoints)
251             .setRendererEndpoints(
252                     new RendererEndpointsBuilder().setRendererEndpoint(Arrays.asList(rendererEndpoint)).build())
253             .setRuleGroups(new RuleGroupsBuilder().setRuleGroup(Arrays.asList(RULE_GROUP)).build())
254             .build();
255         RendererPolicy rendererPolicy =
256                 new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
257         RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
258
259         vppRendererPolicyManager.rendererPolicyChanged(event);
260
261         // assert state on data store behind mount point
262         ReadOnlyTransaction rTxMount = mountPointDataBroker.newReadOnlyTransaction();
263         Optional<Interface> potentialIface = rTxMount.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
264             .builder(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME_WEB_EP)).build()).get();
265         Assert.assertTrue(potentialIface.isPresent());
266         Interface iface = potentialIface.get();
267         VppInterfaceAugmentation vppIfaceAug = iface.getAugmentation(VppInterfaceAugmentation.class);
268         Assert.assertNotNull(vppIfaceAug);
269         Interconnection interconnection = vppIfaceAug.getL2().getInterconnection();
270         Assert.assertNotNull(interconnection);
271         Assert.assertTrue(interconnection instanceof BridgeBased);
272         Assert.assertEquals(L2FD_CTX.getValue(), ((BridgeBased) interconnection).getBridgeDomain());
273         // assert state on ODL data store
274         ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
275         Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
276                 IidFactory.locationProviderIid(VppEndpointLocationProvider.VPP_ENDPOINT_LOCATION_PROVIDER))
277             .get();
278         Assert.assertTrue(optLocationProvider.isPresent());
279         List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
280         Assert.assertNotNull(epLocs);
281         Assert.assertEquals(2, epLocs.size());
282         if (epLocs.get(0).getAddress().equals(CLIENT_EP_KEY.getAddress())) {
283             Assert.assertEquals(absoluteLocation(VPP_NODE_IID,
284                     VppPathMapper.bridgeDomainToRestPath(L2FD_CTX.getValue()), NODE_CONNECTOR_CLIENT_EP),
285                     epLocs.get(0).getAbsoluteLocation());
286             Assert.assertEquals(absoluteLocation(VPP_NODE_IID,
287                     VppPathMapper.bridgeDomainToRestPath(L2FD_CTX.getValue()), NODE_CONNECTOR_WEB_EP),
288                     epLocs.get(1).getAbsoluteLocation());
289         } else {
290             Assert.assertEquals(absoluteLocation(VPP_NODE_IID,
291                     VppPathMapper.bridgeDomainToRestPath(L2FD_CTX.getValue()), NODE_CONNECTOR_CLIENT_EP),
292                     epLocs.get(1).getAbsoluteLocation());
293             Assert.assertEquals(absoluteLocation(VPP_NODE_IID,
294                     VppPathMapper.bridgeDomainToRestPath(L2FD_CTX.getValue()), NODE_CONNECTOR_WEB_EP),
295                     epLocs.get(0).getAbsoluteLocation());
296         }
297     }
298
299     private void storeInterfaceFor(AddressEndpointWithLocationKey epKey, String ifaceName,
300             InstanceIdentifier<VppEndpoint> vppEpIid) {
301         VppEndpoint vhostEp = new VppEndpointBuilder().setAddress(epKey.getAddress())
302             .setAddressType(epKey.getAddressType())
303             .setContextId(epKey.getContextId())
304             .setContextType(epKey.getContextType())
305             .setVppInterfaceName(ifaceName)
306             .setVppNodePath(VPP_NODE_IID)
307             .setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(SOCKET).build())
308             .build();
309         VppEndpointConfEvent vppEpEvent = new VppEndpointConfEvent(vppEpIid, null, vhostEp);
310         ifaceManager.vppEndpointChanged(vppEpEvent);
311     }
312
313     private static AbsoluteLocation absoluteLocation(InstanceIdentifier<?> mountPoint, String node,
314             String nodeConnector) {
315         return new AbsoluteLocationBuilder()
316             .setLocationType(new ExternalLocationCaseBuilder().setExternalNodeMountPoint(mountPoint)
317                 .setExternalNode(node)
318                 .setExternalNodeConnector(nodeConnector)
319                 .build())
320             .build();
321     }
322
323 }