--- /dev/null
+package org.opendaylight.groupbasedpolicy.renderer.vpp;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppPathMapper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.network.containment.containment.ForwardingContextContainmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.ConfigurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.EndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RendererEndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RuleGroupsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.resolved.rules.ResolvedRuleBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Strings;
+
+public class DtoFactory {
+
+ public static final ContextId CTX_ID = new ContextId("ctx");
+ public static final ContextId L2FD_CTX = new ContextId("l2fd");
+ public static final ContractId CONTRACT_ID = new ContractId("contract");
+ public static final TenantId TENANT_ID = new TenantId("tenant");
+ public static final SubjectName SUBJECT_NAME = new SubjectName("subject");
+ public static final RuleName RULE_NAME = new RuleName("rule");
+ public static final RuleGroupWithRendererEndpointParticipation RULE_GROUP_WITH_CONSUMER =
+ new RuleGroupWithRendererEndpointParticipationBuilder().setContractId(CONTRACT_ID)
+ .setTenantId(TENANT_ID)
+ .setSubjectName(SUBJECT_NAME)
+ .setRendererEndpointParticipation(EndpointPolicyParticipation.CONSUMER)
+ .build();
+ public static final RuleGroupWithRendererEndpointParticipation RULE_GROUP_WITH_PROVIDER =
+ new RuleGroupWithRendererEndpointParticipationBuilder().setContractId(CONTRACT_ID)
+ .setTenantId(TENANT_ID)
+ .setSubjectName(SUBJECT_NAME)
+ .setRendererEndpointParticipation(EndpointPolicyParticipation.PROVIDER)
+ .build();
+ public static final RuleGroup RULE_GROUP = new RuleGroupBuilder().setContractId(CONTRACT_ID)
+ .setTenantId(TENANT_ID)
+ .setSubjectName(SUBJECT_NAME)
+ .setResolvedRule(Arrays.asList(new ResolvedRuleBuilder().setName(RULE_NAME).build()))
+ .build();
+ public final static TopologyKey TOPO_KEY = new TopologyKey(new TopologyId("topology-netconf"));
+ public final static InstanceIdentifier<Node> VPP_NODE_1_IID = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, TOPO_KEY)
+ .child(Node.class, new NodeKey(new NodeId("node1")))
+ .build();
+ public final static InstanceIdentifier<Node> VPP_NODE_2_IID = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, TOPO_KEY)
+ .child(Node.class, new NodeKey(new NodeId("node2")))
+ .build();
+
+ public static Configuration createConfiguration(List<AddressEndpointWithLocation> consumers,
+ List<AddressEndpointWithLocation> providers) {
+ List<AddressEndpointWithLocation> eps =
+ Stream.concat(consumers.stream(), providers.stream()).collect(Collectors.toList());
+ Endpoints endpoints = new EndpointsBuilder().setAddressEndpointWithLocation(eps).build();
+ List<RendererEndpoint> consumersAsRendererEps = consumers.stream().map(cons -> {
+ List<PeerEndpoint> peers = providers.stream()
+ .map(web -> new PeerEndpointBuilder().setKey(KeyFactory.peerEndpointKey(web.getKey()))
+ .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_CONSUMER))
+ .build())
+ .collect(Collectors.toList());
+ return new RendererEndpointBuilder().setKey(KeyFactory.rendererEndpointKey(cons.getKey()))
+ .setPeerEndpoint(peers)
+ .build();
+ }).collect(Collectors.toList());
+ List<RendererEndpoint> providersAsRendererEps = providers.stream().map(prov -> {
+ List<PeerEndpoint> peers = consumers.stream()
+ .map(client -> new PeerEndpointBuilder().setKey(KeyFactory.peerEndpointKey(client.getKey()))
+ .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_PROVIDER))
+ .build())
+ .collect(Collectors.toList());
+ return new RendererEndpointBuilder().setKey(KeyFactory.rendererEndpointKey(prov.getKey()))
+ .setPeerEndpoint(peers)
+ .build();
+ }).collect(Collectors.toList());
+ List<RendererEndpoint> rendererEps = Stream
+ .concat(consumersAsRendererEps.stream(), providersAsRendererEps.stream()).collect(Collectors.toList());
+ return new ConfigurationBuilder().setEndpoints(endpoints)
+ .setRendererEndpoints(new RendererEndpointsBuilder().setRendererEndpoint(rendererEps).build())
+ .setRuleGroups(new RuleGroupsBuilder().setRuleGroup(Arrays.asList(RULE_GROUP)).build())
+ .build();
+ }
+
+ public static AddressEndpointWithLocation createEndpoint(String ip, String l2FdIdAsNetCont,
+ AbsoluteLocation absoluteLocation) {
+ AddressEndpointWithLocationKey key =
+ new AddressEndpointWithLocationKey(ip, AddressType.class, CTX_ID, ContextType.class);
+ NetworkContainment networkContainment =
+ new NetworkContainmentBuilder().setContainment(new ForwardingContextContainmentBuilder()
+ .setContextType(L2FloodDomain.class).setContextId(new ContextId(l2FdIdAsNetCont)).build()).build();
+ return new AddressEndpointWithLocationBuilder().setKey(key)
+ .setNetworkContainment(networkContainment)
+ .setAbsoluteLocation(absoluteLocation)
+ .build();
+ }
+
+ public static AbsoluteLocation absoluteLocation(InstanceIdentifier<?> mountPoint, String nodeName,
+ String nodeConnectorName) {
+ ExternalLocationCaseBuilder extLocBuilder =
+ new ExternalLocationCaseBuilder().setExternalNodeMountPoint(mountPoint);
+ if (!Strings.isNullOrEmpty(nodeName)) {
+ extLocBuilder.setExternalNode(VppPathMapper.bridgeDomainToRestPath(nodeName));
+ }
+ if (!Strings.isNullOrEmpty(nodeConnectorName)) {
+ extLocBuilder.setExternalNodeConnector(VppPathMapper.interfaceToRestPath(nodeConnectorName));
+ }
+ return new AbsoluteLocationBuilder().setLocationType(extLocBuilder.build()).build();
+ }
+}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.DtoFactory;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.api.BridgeDomainManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
+import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.NetworkTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VlanNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanVni;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.SetMultimap;
+import com.google.common.util.concurrent.Futures;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ForwardingManagerTest extends CustomDataBrokerTest {
+
+ private static final String BD_1 = "bd1";
+ private static final NodeId NODE_1 = new NodeId("node1");
+ private static final VlanId VLAN_1 = new VlanId(1);
+ @Mock
+ private InterfaceManager ifaceManager;
+ @Mock
+ private BridgeDomainManager bdManager;
+
+ private ForwardingManager fwdManager;
+
+ @Before
+ public void init() {
+ fwdManager = new ForwardingManager(ifaceManager, bdManager, getDataBroker());
+ }
+
+ @Override
+ public Collection<Class<?>> getClassesFromModules() {
+ return Arrays.asList(BridgeDomain.class);
+ }
+
+ @Test
+ public void testReadBridgeDomainConfig() throws Exception {
+ BridgeDomain bd = new BridgeDomainBuilder().setId(BD_1).setType(NetworkTypeBase.class).build();
+ InstanceIdentifier<BridgeDomain> bdIid =
+ InstanceIdentifier.builder(Config.class).child(BridgeDomain.class, bd.getKey()).build();
+ Optional<BridgeDomain> bdOptional = fwdManager.readBridgeDomainConfig(bd.getId());
+ Assert.assertFalse(bdOptional.isPresent());
+
+ WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
+ wTx.put(LogicalDatastoreType.CONFIGURATION, bdIid, bd);
+ wTx.submit().get();
+
+ bdOptional = fwdManager.readBridgeDomainConfig(bd.getId());
+ Assert.assertTrue(bdOptional.isPresent());
+ Assert.assertEquals(bd, bdOptional.get());
+ }
+
+ @Test
+ public void testCreateBridgeDomainOnNodes_vxlan() throws Exception {
+ Mockito.when(bdManager.createVxlanBridgeDomainOnVppNode(Mockito.eq(BD_1), Mockito.any(VxlanVni.class),
+ Mockito.eq(NODE_1)))
+ .thenReturn(Futures.immediateFuture(null));
+ SetMultimap<String, NodeId> vppNodesByBd = ImmutableSetMultimap.of(BD_1, NODE_1);
+
+ fwdManager.createBridgeDomainOnNodes(vppNodesByBd);
+ Mockito.verify(bdManager).createVxlanBridgeDomainOnVppNode(Matchers.eq(BD_1), Matchers.any(VxlanVni.class),
+ Matchers.eq(NODE_1));
+ }
+
+ @Test
+ public void testCreateBridgeDomainOnNodes_vlan() throws Exception {
+ Mockito.when(bdManager.createVlanBridgeDomainOnVppNode(Mockito.eq(BD_1), Mockito.any(VlanId.class),
+ Mockito.eq(NODE_1)))
+ .thenReturn(Futures.immediateFuture(null));
+ BridgeDomain bd = new BridgeDomainBuilder().setId(BD_1).setType(VlanNetwork.class).setVlan(VLAN_1).build();
+ InstanceIdentifier<BridgeDomain> bdIid =
+ InstanceIdentifier.builder(Config.class).child(BridgeDomain.class, bd.getKey()).build();
+ WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
+ wTx.put(LogicalDatastoreType.CONFIGURATION, bdIid, bd);
+ wTx.submit().get();
+ SetMultimap<String, NodeId> vppNodesByBd = ImmutableSetMultimap.of(BD_1, NODE_1);
+
+ fwdManager.createBridgeDomainOnNodes(vppNodesByBd);
+ Mockito.verify(bdManager).createVlanBridgeDomainOnVppNode(Matchers.eq(BD_1), Matchers.eq(VLAN_1),
+ Matchers.eq(NODE_1));
+ }
+
+ @Test
+ public void testRemoveBridgeDomainOnNodes() throws Exception {
+ Mockito.when(bdManager.removeBridgeDomainFromVppNode(Mockito.eq(BD_1), Mockito.eq(NODE_1)))
+ .thenReturn(Futures.immediateFuture(null));
+ SetMultimap<String, NodeId> vppNodesByBd = ImmutableSetMultimap.of(BD_1, NODE_1);
+
+ bdManager.removeBridgeDomainFromVppNode(BD_1, NODE_1);
+ Mockito.verify(bdManager).removeBridgeDomainFromVppNode(Matchers.eq(BD_1), Matchers.eq(NODE_1));
+ }
+
+ @Test
+ public void testCreateForwardingForEndpoint() throws Exception {
+ String clientIp = "1.1.1.1";
+ String clientIfaceName = "client1";
+ AbsoluteLocation clientLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, clientIfaceName);
+ AddressEndpointWithLocation clientEp =
+ DtoFactory.createEndpoint(clientIp, DtoFactory.L2FD_CTX.getValue(), clientLocation);
+ String webIp = "2.2.2.2";
+ String webIfaceName = "web1";
+ AbsoluteLocation webLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, webIfaceName);
+ AddressEndpointWithLocation webEp =
+ DtoFactory.createEndpoint(webIp, DtoFactory.L2FD_CTX.getValue(), webLocation);
+ Configuration configuration = DtoFactory.createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
+ RendererPolicy rendererPolicy =
+ new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
+ PolicyContext policyCtx = new PolicyContext(rendererPolicy);
+ RendererEndpoint firstRendererEp = configuration.getRendererEndpoints().getRendererEndpoint().get(0);
+ AddressEndpointWithLocation firstAddrEpWithLoc =
+ policyCtx.getAddrEpByKey().get(KeyFactory.addressEndpointKey(firstRendererEp.getKey()));
+ Mockito.when(ifaceManager.addBridgeDomainToInterface(Mockito.eq(DtoFactory.L2FD_CTX.getValue()),
+ Mockito.eq(firstAddrEpWithLoc)))
+ .thenReturn(Futures.immediateFuture(null));
+
+ fwdManager.createForwardingForEndpoint(firstRendererEp.getKey(), policyCtx);
+ Mockito.verify(ifaceManager).addBridgeDomainToInterface(Matchers.eq(DtoFactory.L2FD_CTX.getValue()),
+ Matchers.eq(firstAddrEpWithLoc));
+ }
+
+ @Test
+ public void testRemoveForwardingForEndpoint() throws Exception {
+ String clientIp = "1.1.1.1";
+ String clientIfaceName = "client1";
+ String bdNameOnVpp = "bdRed";
+ AbsoluteLocation clientLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, bdNameOnVpp, clientIfaceName);
+ AddressEndpointWithLocation clientEp =
+ DtoFactory.createEndpoint(clientIp, DtoFactory.L2FD_CTX.getValue(), clientLocation);
+ String webIp = "2.2.2.2";
+ String webIfaceName = "web1";
+ AbsoluteLocation webLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, bdNameOnVpp, webIfaceName);
+ AddressEndpointWithLocation webEp =
+ DtoFactory.createEndpoint(webIp, DtoFactory.L2FD_CTX.getValue(), webLocation);
+ Configuration configuration = DtoFactory.createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
+ RendererPolicy rendererPolicy =
+ new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
+ PolicyContext policyCtx = new PolicyContext(rendererPolicy);
+ RendererEndpoint firstRendererEp = configuration.getRendererEndpoints().getRendererEndpoint().get(0);
+ AddressEndpointWithLocation firstAddrEpWithLoc =
+ policyCtx.getAddrEpByKey().get(KeyFactory.addressEndpointKey(firstRendererEp.getKey()));
+ Mockito.when(ifaceManager.deleteBridgeDomainFromInterface(
+ Mockito.eq(firstAddrEpWithLoc)))
+ .thenReturn(Futures.immediateFuture(null));
+
+ fwdManager.removeForwardingForEndpoint(firstRendererEp.getKey(), policyCtx);
+ Mockito.verify(ifaceManager).deleteBridgeDomainFromInterface(Matchers.eq(firstAddrEpWithLoc));
+ }
+
+}
package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
-import com.google.common.util.concurrent.MoreExecutors;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.DtoFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.api.BridgeDomainManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.RendererPolicyConfEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppEndpointLocationProvider;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppPathMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.network.containment.containment.ForwardingContextContainmentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.ConfigurationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.EndpointsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RendererEndpointsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RuleGroupsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpointBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.resolved.rules.ResolvedRuleBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyVbridgeAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev160429.TunnelTypeVxlan;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import com.google.common.base.Optional;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.MoreExecutors;
+
@RunWith(MockitoJUnitRunner.class)
public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
private static final InstanceIdentifier<RendererPolicy> RENDERER_POLICY_IID =
IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class);
- private static final ContextId CTX_ID = new ContextId("ctx");
- private static final ContextId L2FD_CTX = new ContextId("l2fd");
- private final static TopologyKey TOPO_KEY = new TopologyKey(new TopologyId("topology-netconf"));
- private final static InstanceIdentifier<Node> VPP_NODE_1_IID = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, TOPO_KEY)
- .child(Node.class, new NodeKey(new NodeId("node1")))
- .build();
- private final static InstanceIdentifier<Node> VPP_NODE_2_IID = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, TOPO_KEY)
- .child(Node.class, new NodeKey(new NodeId("node2")))
- .build();
- private static final ContractId CONTRACT_ID = new ContractId("contract");
- private static final TenantId TENANT_ID = new TenantId("tenant");
- private static final SubjectName SUBJECT_NAME = new SubjectName("subject");
- private static final RuleName RULE_NAME = new RuleName("rule");
- private static final RuleGroupWithRendererEndpointParticipation RULE_GROUP_WITH_CONSUMER =
- new RuleGroupWithRendererEndpointParticipationBuilder().setContractId(CONTRACT_ID)
- .setTenantId(TENANT_ID)
- .setSubjectName(SUBJECT_NAME)
- .setRendererEndpointParticipation(EndpointPolicyParticipation.CONSUMER)
- .build();
- private static final RuleGroupWithRendererEndpointParticipation RULE_GROUP_WITH_PROVIDER =
- new RuleGroupWithRendererEndpointParticipationBuilder().setContractId(CONTRACT_ID)
- .setTenantId(TENANT_ID)
- .setSubjectName(SUBJECT_NAME)
- .setRendererEndpointParticipation(EndpointPolicyParticipation.PROVIDER)
- .build();
- private static final RuleGroup RULE_GROUP = new RuleGroupBuilder().setContractId(CONTRACT_ID)
- .setTenantId(TENANT_ID)
- .setSubjectName(SUBJECT_NAME)
- .setResolvedRule(Arrays.asList(new ResolvedRuleBuilder().setName(RULE_NAME).build()))
- .build();
private final static String SOCKET = "socket";
private MountedDataBrokerProvider mountedDataProviderMock;
public void testRendererPolicyChanged_created_oneEpPerEpg() throws Exception {
String clientIp = "1.1.1.1";
String clientIfaceName = "client1";
- AbsoluteLocation clientLocation = absoluteLocation(VPP_NODE_1_IID, null, clientIfaceName);
- AddressEndpointWithLocation clientEp = createEndpoint(clientIp, L2FD_CTX.getValue(), clientLocation);
+ AbsoluteLocation clientLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, clientIfaceName);
+ AddressEndpointWithLocation clientEp =
+ DtoFactory.createEndpoint(clientIp, DtoFactory.L2FD_CTX.getValue(), clientLocation);
String webIp = "2.2.2.2";
String webIfaceName = "web1";
- AbsoluteLocation webLocation = absoluteLocation(VPP_NODE_1_IID, null, webIfaceName);
- AddressEndpointWithLocation webEp = createEndpoint(webIp, L2FD_CTX.getValue(), webLocation);
+ AbsoluteLocation webLocation = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, webIfaceName);
+ AddressEndpointWithLocation webEp =
+ DtoFactory.createEndpoint(webIp, DtoFactory.L2FD_CTX.getValue(), webLocation);
storeVppEndpoint(clientEp.getKey(), clientIfaceName, createVppEndpointIid(clientEp.getKey()));
storeVppEndpoint(webEp.getKey(), webIfaceName, createVppEndpointIid(webEp.getKey()));
- Configuration configuration = createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
+ Configuration configuration = DtoFactory.createConfiguration(Arrays.asList(clientEp), Arrays.asList(webEp));
RendererPolicy rendererPolicy =
new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
// assert state on data store behind mount point
Interface clientIface = readAndAssertInterface(clientIfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), clientIface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), clientIface);
Interface webIface = readAndAssertInterface(webIfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), webIface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), webIface);
// assert state on ODL data store
ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
Assert.assertNotNull(epLocs);
Assert.assertEquals(2, epLocs.size());
assertProviderAddressEndpointLocation(clientEp.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), clientIfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), clientIfaceName),
+ epLocs);
assertProviderAddressEndpointLocation(webEp.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), webIfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, DtoFactory.L2FD_CTX.getValue(), webIfaceName),
+ epLocs);
}
@Test
public void testRendererPolicyChanged_update() throws Exception {
String client1IfaceName = "client1";
- AbsoluteLocation client1LocationNodeNull = absoluteLocation(VPP_NODE_1_IID, null, client1IfaceName);
+ AbsoluteLocation client1LocationNodeNull =
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client1IfaceName);
AddressEndpointWithLocation client1Ep =
- createEndpoint("10.0.0.1", L2FD_CTX.getValue(), client1LocationNodeNull);
+ DtoFactory.createEndpoint("10.0.0.1", DtoFactory.L2FD_CTX.getValue(), client1LocationNodeNull);
String web1IfaceName = "web1";
- AbsoluteLocation web1LocationNodeNull = absoluteLocation(VPP_NODE_2_IID, null, web1IfaceName);
- AddressEndpointWithLocation web1Ep = createEndpoint("20.0.0.1", L2FD_CTX.getValue(), web1LocationNodeNull);
+ AbsoluteLocation web1LocationNodeNull =
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web1IfaceName);
+ AddressEndpointWithLocation web1Ep =
+ DtoFactory.createEndpoint("20.0.0.1", DtoFactory.L2FD_CTX.getValue(), web1LocationNodeNull);
String client2IfaceName = "client2";
- AbsoluteLocation client2LocationNodeNull = absoluteLocation(VPP_NODE_1_IID, null, client2IfaceName);
+ AbsoluteLocation client2LocationNodeNull =
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID, null, client2IfaceName);
AddressEndpointWithLocation client2Ep =
- createEndpoint("10.0.0.2", L2FD_CTX.getValue(), client2LocationNodeNull);
+ DtoFactory.createEndpoint("10.0.0.2", DtoFactory.L2FD_CTX.getValue(), client2LocationNodeNull);
String web2IfaceName = "web2";
- AbsoluteLocation web2LocationNodeNull = absoluteLocation(VPP_NODE_2_IID, null, web2IfaceName);
- AddressEndpointWithLocation web2Ep = createEndpoint("20.0.0.2", L2FD_CTX.getValue(), web2LocationNodeNull);
+ AbsoluteLocation web2LocationNodeNull =
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, null, web2IfaceName);
+ AddressEndpointWithLocation web2Ep =
+ DtoFactory.createEndpoint("20.0.0.2", DtoFactory.L2FD_CTX.getValue(), web2LocationNodeNull);
storeVppEndpoint(client1Ep.getKey(), client1IfaceName, createVppEndpointIid(client1Ep.getKey()));
storeVppEndpoint(web1Ep.getKey(), web1IfaceName, createVppEndpointIid(web1Ep.getKey()));
storeVppEndpoint(web2Ep.getKey(), web2IfaceName, createVppEndpointIid(web2Ep.getKey()));
Configuration configuration =
- createConfiguration(Arrays.asList(client1Ep, client2Ep), Arrays.asList(web1Ep, web2Ep));
+ DtoFactory.createConfiguration(Arrays.asList(client1Ep, client2Ep), Arrays.asList(web1Ep, web2Ep));
RendererPolicy rendererPolicy =
new RendererPolicyBuilder().setVersion(1L).setConfiguration(configuration).build();
RendererPolicyConfEvent event = new RendererPolicyConfEvent(RENDERER_POLICY_IID, null, rendererPolicy);
// assert state on data store behind mount point ######################################
Interface client1Iface = readAndAssertInterface(client1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
Interface web1Iface = readAndAssertInterface(web1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
Interface client2Iface = readAndAssertInterface(client2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
Interface web2Iface = readAndAssertInterface(web2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
// assert state on ODL data store
ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
Optional<LocationProvider> optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
List<ProviderAddressEndpointLocation> epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
Assert.assertNotNull(epLocs);
Assert.assertEquals(4, epLocs.size());
- assertProviderAddressEndpointLocation(client1Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client1IfaceName), epLocs);
+ assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
assertProviderAddressEndpointLocation(web1Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web1IfaceName), epLocs);
- assertProviderAddressEndpointLocation(client2Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
+ epLocs);
+ assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
assertProviderAddressEndpointLocation(web2Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
+ epLocs);
// #####################################################################################
- AbsoluteLocation client1Location =
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client1IfaceName);
+ AbsoluteLocation client1Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client1IfaceName);
AbsoluteLocation web1Location =
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web1IfaceName);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName);
AbsoluteLocation web2Location =
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web2IfaceName);
- configuration = createConfiguration(
- Arrays.asList(
- new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location).build(),
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName);
+ configuration = DtoFactory.createConfiguration(
+ Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
+ .build(),
new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2LocationNodeNull)
.build()),
Arrays.asList(new AddressEndpointWithLocationBuilder(web1Ep).setAbsoluteLocation(web1Location).build(),
// assert state on data store behind mount point ######################################
client1Iface = readAndAssertInterface(client1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
web1Iface = readAndAssertInterface(web1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
client2Iface = readAndAssertInterface(client2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
web2Iface = readAndAssertInterface(web2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
// assert state on ODL data store
rTx = dataBroker.newReadOnlyTransaction();
optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
Assert.assertNotNull(epLocs);
Assert.assertEquals(4, epLocs.size());
- assertProviderAddressEndpointLocation(client1Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client1IfaceName), epLocs);
+ assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
assertProviderAddressEndpointLocation(web1Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web1IfaceName), epLocs);
- assertProviderAddressEndpointLocation(client2Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
+ epLocs);
+ assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
assertProviderAddressEndpointLocation(web2Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
+ epLocs);
// #####################################################################################
- AbsoluteLocation client2Location =
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client2IfaceName);
- configuration = createConfiguration(
+ AbsoluteLocation client2Location = DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client2IfaceName);
+ configuration = DtoFactory.createConfiguration(
Arrays.asList(new AddressEndpointWithLocationBuilder(client1Ep).setAbsoluteLocation(client1Location)
.build(),
new AddressEndpointWithLocationBuilder(client2Ep).setAbsoluteLocation(client2Location).build()),
// assert state on data store behind mount point ######################################
client1Iface = readAndAssertInterface(client1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client1Iface);
web1Iface = readAndAssertInterface(web1IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web1Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web1Iface);
client2Iface = readAndAssertInterface(client2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), client2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), client2Iface);
web2Iface = readAndAssertInterface(web2IfaceName);
- assertBridgeDomainOnInterface(L2FD_CTX.getValue(), web2Iface);
+ assertBridgeDomainOnInterface(DtoFactory.L2FD_CTX.getValue(), web2Iface);
// assert state on ODL data store
rTx = dataBroker.newReadOnlyTransaction();
optLocationProvider = rTx.read(LogicalDatastoreType.CONFIGURATION,
epLocs = optLocationProvider.get().getProviderAddressEndpointLocation();
Assert.assertNotNull(epLocs);
Assert.assertEquals(4, epLocs.size());
- assertProviderAddressEndpointLocation(client1Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client1IfaceName), epLocs);
+ assertProviderAddressEndpointLocation(client1Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client1IfaceName), epLocs);
assertProviderAddressEndpointLocation(web1Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web1IfaceName), epLocs);
- assertProviderAddressEndpointLocation(client2Ep.getKey(),
- absoluteLocation(VPP_NODE_1_IID, L2FD_CTX.getValue(), client2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web1IfaceName),
+ epLocs);
+ assertProviderAddressEndpointLocation(client2Ep.getKey(), DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_1_IID,
+ DtoFactory.L2FD_CTX.getValue(), client2IfaceName), epLocs);
assertProviderAddressEndpointLocation(web2Ep.getKey(),
- absoluteLocation(VPP_NODE_2_IID, L2FD_CTX.getValue(), web2IfaceName), epLocs);
+ DtoFactory.absoluteLocation(DtoFactory.VPP_NODE_2_IID, DtoFactory.L2FD_CTX.getValue(), web2IfaceName),
+ epLocs);
// #####################################################################################
}
- private static AbsoluteLocation absoluteLocation(InstanceIdentifier<?> mountPoint, String nodeName,
- String nodeConnectorName) {
- ExternalLocationCaseBuilder extLocBuilder =
- new ExternalLocationCaseBuilder().setExternalNodeMountPoint(mountPoint);
- if (!Strings.isNullOrEmpty(nodeName)) {
- extLocBuilder.setExternalNode(VppPathMapper.bridgeDomainToRestPath(nodeName));
- }
- if (!Strings.isNullOrEmpty(nodeConnectorName)) {
- extLocBuilder.setExternalNodeConnector(VppPathMapper.interfaceToRestPath(nodeConnectorName));
- }
- return new AbsoluteLocationBuilder().setLocationType(extLocBuilder.build()).build();
- }
-
- private AddressEndpointWithLocation createEndpoint(String ip, String l2FdIdAsNetCont,
- AbsoluteLocation absoluteLocation) {
- AddressEndpointWithLocationKey key =
- new AddressEndpointWithLocationKey(ip, AddressType.class, CTX_ID, ContextType.class);
- NetworkContainment networkContainment =
- new NetworkContainmentBuilder().setContainment(new ForwardingContextContainmentBuilder()
- .setContextType(L2FloodDomain.class).setContextId(new ContextId(l2FdIdAsNetCont)).build()).build();
- return new AddressEndpointWithLocationBuilder().setKey(key)
- .setNetworkContainment(networkContainment)
- .setAbsoluteLocation(absoluteLocation)
- .build();
- }
-
private InstanceIdentifier<VppEndpoint> createVppEndpointIid(AddressEndpointWithLocationKey key) {
return InstanceIdentifier.builder(Config.class)
.child(VppEndpoint.class, new VppEndpointKey(key.getAddress(), key.getAddressType(), key.getContextId(),
.build();
}
- private Configuration createConfiguration(List<AddressEndpointWithLocation> consumers,
- List<AddressEndpointWithLocation> providers) {
- List<AddressEndpointWithLocation> eps =
- Stream.concat(consumers.stream(), providers.stream()).collect(Collectors.toList());
- Endpoints endpoints = new EndpointsBuilder().setAddressEndpointWithLocation(eps).build();
- List<RendererEndpoint> consumersAsRendererEps = consumers.stream().map(cons -> {
- List<PeerEndpoint> peers = providers.stream()
- .map(web -> new PeerEndpointBuilder()
- .setKey(KeyFactory.peerEndpointKey(web.getKey()))
- .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_CONSUMER))
- .build())
- .collect(Collectors.toList());
- return new RendererEndpointBuilder().setKey(KeyFactory.rendererEndpointKey(cons.getKey()))
- .setPeerEndpoint(peers)
- .build();
- }).collect(Collectors.toList());
- List<RendererEndpoint> providersAsRendererEps = providers.stream().map(prov -> {
- List<PeerEndpoint> peers = consumers.stream()
- .map(client -> new PeerEndpointBuilder()
- .setKey(KeyFactory.peerEndpointKey(client.getKey()))
- .setRuleGroupWithRendererEndpointParticipation(Arrays.asList(RULE_GROUP_WITH_PROVIDER))
- .build())
- .collect(Collectors.toList());
- return new RendererEndpointBuilder().setKey(KeyFactory.rendererEndpointKey(prov.getKey()))
- .setPeerEndpoint(peers)
- .build();
- }).collect(Collectors.toList());
- List<RendererEndpoint> rendererEps = Stream
- .concat(consumersAsRendererEps.stream(), providersAsRendererEps.stream()).collect(Collectors.toList());
- return new ConfigurationBuilder().setEndpoints(endpoints)
- .setRendererEndpoints(new RendererEndpointsBuilder().setRendererEndpoint(rendererEps).build())
- .setRuleGroups(new RuleGroupsBuilder().setRuleGroup(Arrays.asList(RULE_GROUP)).build())
- .build();
- }
-
private void assertProviderAddressEndpointLocation(AddressEndpointWithLocationKey expectedEpKey,
AbsoluteLocation expectedEpLoc, List<ProviderAddressEndpointLocation> providerEpLocs) {
List<ProviderAddressEndpointLocation> expectedProvEpLoc =
.setContextId(epKey.getContextId())
.setContextType(epKey.getContextType())
.setVppInterfaceName(ifaceName)
- .setVppNodePath(VPP_NODE_1_IID)
+ .setVppNodePath(DtoFactory.VPP_NODE_1_IID)
.setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(SOCKET).build())
.build();
VppEndpointConfEvent vppEpEvent = new VppEndpointConfEvent(vppEpIid, null, vhostEp);