<properties>
<openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
<faas.version>1.0.0-SNAPSHOT</faas.version>
+ <powermock.version>1.5.2</powermock.version>
</properties>
<dependencies>
<version>${faas.version}</version>
</dependency>
<!-- testing dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-core</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!-- project build -->
}
}
- private SecurityRuleGroupsBuilder initSecurityGroupBuilder(Contract contract) {
+ protected SecurityRuleGroupsBuilder initSecurityGroupBuilder(Contract contract) {
LOG.trace("Start initSecurityGroupBuilder");
SecurityRuleGroupsBuilder builder = new SecurityRuleGroupsBuilder();
builder.setUuid(getFaasSecurityRulesId(contract.getId()));
}
}
- private void processEndpoint(Endpoint endpoint) {
+ protected void processEndpoint(Endpoint endpoint) {
Uuid tenantId = policyManager.getFaasTenantId(endpoint.getTenant());
if (tenantId == null) {
LOG.error("Failed Endpoint Registration. Couldn't find faas tenant Id. Endpoint {}", endpoint);
private final ListenerRegistration<DataChangeListener> registerListener;
private final ScheduledExecutorService executor;
private final DataBroker dataProvider;
- private final Map<Pair<EndpointGroupId, TenantId>, List<SubnetId>> epgSubnetsMap = new HashMap<>();
+ protected final Map<Pair<EndpointGroupId, TenantId>, List<SubnetId>> epgSubnetsMap = new HashMap<>();
private final ConcurrentHashMap<TenantId, Uuid> mappedTenants = new ConcurrentHashMap<>();
- private final ConcurrentHashMap<TenantId, ArrayList<ListenerRegistration<DataChangeListener>>> registeredTenants = new ConcurrentHashMap<TenantId, ArrayList<ListenerRegistration<DataChangeListener>>>();
+ protected final ConcurrentHashMap<TenantId, ArrayList<ListenerRegistration<DataChangeListener>>> registeredTenants = new ConcurrentHashMap<TenantId, ArrayList<ListenerRegistration<DataChangeListener>>>();
public FaasPolicyManager(DataBroker dataBroker, ScheduledExecutorService executor) {
this.dataProvider = dataBroker;
}
}
- private void createLayer3LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
+ protected void createLayer3LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
TenantId gbpTenantId, ServiceCommunicationLayer comLayer, ExternalImplicitGroup externalImplicitGroup) {
LOG.trace("Start createLayer3LogicalNetwork: Consumer EPG {} Provider Epg {} Contract {}", consEpg.getId()
.getValue(), provEpg.getId().getValue(), contractId);
contractId.getValue(), provEpg.getId().getValue());
}
- private void createLayer2LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
+ protected void createLayer2LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
TenantId gbpTenantId, ServiceCommunicationLayer comLayer, ExternalImplicitGroup externalImplicitGroup) {
LOG.trace("Start createLayer2LogicalNetwork: Consumer EPG {} Provider Epg {} Contract {}", consEpg.getId()
.getValue(), provEpg.getId().getValue(), contractId);
return null;
}
- private Uuid getFaasSecRulesId(ContractId contractId, TenantId gbpTenantId) {
+ protected Uuid getFaasSecRulesId(ContractId contractId, TenantId gbpTenantId) {
if (contractId != null) {
Optional<MappedContract> mContractOp = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
FaasIidFactory.mappedContractIid(gbpTenantId, contractId),
return builder;
}
- private boolean needToCreateLogicalNetwork(ServiceCommunicationLayer comLayer, List<SubnetId> consSubnetIds,
+ protected boolean needToCreateLogicalNetwork(ServiceCommunicationLayer comLayer, List<SubnetId> consSubnetIds,
List<SubnetId> provSubnetIds, TenantId tenantId, ContractId contractId, EndpointGroup providerEpg,
EndpointGroup consumerEpg, ExternalImplicitGroup externalImplicitGroup) {
Optional<LogicalNetwork> lnOp = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
return null;
}
- private L3Context readL3ContextInstance(TenantId tenantId, L3ContextId l3cId) {
+ protected L3Context readL3ContextInstance(TenantId tenantId, L3ContextId l3cId) {
ReadOnlyTransaction rTx = dataProvider.newReadOnlyTransaction();
InstanceIdentifier<L3Context> iid = IidFactory.l3ContextIid(tenantId, l3cId);
Optional<L3Context> l2Op = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, iid, rTx);
return l2Op.get();
}
- private L2BridgeDomain readL2BridgeDomainInstance(TenantId tenantId, L2BridgeDomainId l2bId) {
+ protected L2BridgeDomain readL2BridgeDomainInstance(TenantId tenantId, L2BridgeDomainId l2bId) {
ReadOnlyTransaction rTx = dataProvider.newReadOnlyTransaction();
InstanceIdentifier<L2BridgeDomain> iid = IidFactory.l2BridgeDomainIid(tenantId, l2bId);
Optional<L2BridgeDomain> l2Op = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, iid, rTx);
return l2Op.get();
}
- private L2FloodDomain readL2FloodDomain(L2FloodDomainId l2fId, TenantId tenantId) {
+ protected L2FloodDomain readL2FloodDomain(L2FloodDomainId l2fId, TenantId tenantId) {
ReadOnlyTransaction rTx = dataProvider.newReadOnlyTransaction();
InstanceIdentifier<L2FloodDomain> iid = IidFactory.l2FloodDomainIid(tenantId, l2fId);
Optional<L2FloodDomain> l2Op = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, iid, rTx);
}
}
- private SubnetBuilder initSubnetBuilder(Subnet gbpSubnet) {
+ protected SubnetBuilder initSubnetBuilder(Subnet gbpSubnet) {
SubnetBuilder builder = new SubnetBuilder();
if (gbpSubnet.getGateways() != null) {
List<ExternalGateways> gateways = new ArrayList<>();
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.faas.uln.datastore.api.UlnDatastoreApi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.security.rules.rev151013.security.rule.groups.attributes.security.rule.groups.container.SecurityRuleGroups;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.util.concurrent.CheckedFuture;
+
+@PrepareForTest(UlnDatastoreApi.class)
+@RunWith(PowerMockRunner.class)
+public class FaasContractManagerListenerTest {
+
+ private InstanceIdentifier<DataObject> contractId;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
+ private MockFaasContractManagerListener contractManagerListener;
+ private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime()
+ .availableProcessors());
+ private TenantId gbpTenantId = new TenantId("b4511aac-ae43-11e5-bf7f-feff819cdc9f");
+ private Uuid faasTenantId = new Uuid("b4511aac-ae43-11e5-bf7f-feff819cdc9f");
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() {
+ contractId = mock(InstanceIdentifier.class);
+ change = mock(AsyncDataChangeEvent.class);
+ contractId = mock(InstanceIdentifier.class);
+ DataBroker dataProvider = mock(DataBroker.class);
+ PowerMockito.mockStatic(UlnDatastoreApi.class);
+ WriteTransaction writeTransaction = mock(WriteTransaction.class);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = mock(CheckedFuture.class);
+ when(writeTransaction.submit()).thenReturn(checkedFuture);
+ contractManagerListener = new MockFaasContractManagerListener(dataProvider, gbpTenantId, faasTenantId, executor);
+
+ Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
+ removedPaths.add(contractId);
+ when(change.getRemovedPaths()).thenReturn(removedPaths);
+ }
+
+ @Test
+ public void testOnDataChangeContract() {
+ // prepare input test data
+ ArgumentCaptor<SecurityRuleGroups> captor = ArgumentCaptor.forClass(SecurityRuleGroups.class);
+ try {
+ PowerMockito.doNothing().when(UlnDatastoreApi.class, "submitSecurityGroupsToDs", captor.capture());
+ } catch (Exception e) {
+ fail("testOnDataChangeContract: Exception = " + e.toString());
+ }
+ Uuid expectedFaasSecId = new Uuid("c4511aac-ae43-11e5-bf7f-feff819cdc9f");
+ contractManagerListener.setExpectedFaasSecId(expectedFaasSecId);
+ DataObject testContract = makeTestContract();
+ contractManagerListener.setExpectedContract((Contract) testContract);
+ Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
+ testData.put(contractId, testContract);
+ when(change.getCreatedData()).thenReturn(testData);
+ when(change.getOriginalData()).thenReturn(testData);
+ when(change.getUpdatedData()).thenReturn(testData);
+ // invoke event -- expected data is verified in mocked classes
+ contractManagerListener.onDataChanged(change);
+ // make sure internal threads have completed
+ try {
+ executor.shutdown();
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ fail("testOnDataChangeSubnet: Exception = " + e.toString());
+ }
+ // Verify passed in values to fabric mapping engine
+ assertTrue("testOnDataChangeContract: Actual Faas Security Id is NOT as expected",
+ expectedFaasSecId.equals(captor.getValue().getUuid()));
+ }
+
+ private DataObject makeTestContract() {
+ ContractBuilder builder = new ContractBuilder();
+ builder.setId(new ContractId("b4511aac-ae43-11e5-bf7f-feff819cdc9f"));
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+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.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.faas.endpoint.rev151009.FaasEndpointContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.faas.endpoint.rev151009.FaasEndpointContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.util.concurrent.CheckedFuture;
+
+public class FaasEndpointManagerListenerTest {
+
+ private InstanceIdentifier<DataObject> endpointId;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
+ private MockFaasEndpointManagerListener endpointManagerListener;
+ private MockFaasPolicyManager policyManager;
+ private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime()
+ .availableProcessors());
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() {
+ endpointId = mock(InstanceIdentifier.class);
+ change = mock(AsyncDataChangeEvent.class);
+ endpointId = mock(InstanceIdentifier.class);
+ DataBroker dataProvider = mock(DataBroker.class);
+
+ WriteTransaction writeTransaction = mock(WriteTransaction.class);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = mock(CheckedFuture.class);
+ when(writeTransaction.submit()).thenReturn(checkedFuture);
+ policyManager = new MockFaasPolicyManager(dataProvider, executor);
+ endpointManagerListener = new MockFaasEndpointManagerListener(policyManager, dataProvider, executor);
+ Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
+ removedPaths.add(endpointId);
+ when(change.getRemovedPaths()).thenReturn(removedPaths);
+ }
+
+ @Test
+ public void testOnDataChangeEndpoint() {
+ // prepare input test data
+ DataObject testEndpoint = makeTestEndpoint();
+ endpointManagerListener.setExpectedEndpoint((Endpoint) testEndpoint);
+ Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
+ testData.put(endpointId, testEndpoint);
+ when(change.getCreatedData()).thenReturn(testData);
+ when(change.getOriginalData()).thenReturn(testData);
+ when(change.getUpdatedData()).thenReturn(testData);
+ // invoke event -- expected data is verified in mocked classes
+ endpointManagerListener.onDataChanged(change);
+ }
+
+ private DataObject makeTestEndpoint() {
+ EndpointBuilder builder = new EndpointBuilder();
+ builder.setL2Context(new L2BridgeDomainId("L2Context"));
+ List<L3Address> l3Addrs = new ArrayList<L3Address>();
+ L3AddressBuilder addb = new L3AddressBuilder();
+ addb.setIpAddress(new IpAddress(new String("10.0.0.2").toCharArray()));
+ addb.setL3Context(new L3ContextId("L3Context"));
+ l3Addrs.add(addb.build());
+ builder.setL3Address(l3Addrs);
+ builder.setMacAddress(new MacAddress("00:00:00:00:35:02"));
+ builder.setTenant(new TenantId("tenant"));
+ builder.setEndpointGroup(new EndpointGroupId("endpointGroupId"));
+ builder.setNetworkContainment(new NetworkDomainId("subnet"));
+ FaasEndpointContextBuilder faasAugb = new FaasEndpointContextBuilder();
+ faasAugb.setFaasPortRefId(new Uuid("165b3a20-adc7-11e5-bf7f-feff819cdc9f"));
+ builder.addAugmentation(FaasEndpointContext.class, faasAugb.build());
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.faas.uln.datastore.api.UlnDatastoreApi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.ServiceCommunicationLayer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy.ExternalImplicitGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.resolved.policy.PolicyRuleGroupWithEndpointConstraints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.resolved.policy.PolicyRuleGroupWithEndpointConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.resolved.policy.policy.rule.group.with.endpoint.constraints.PolicyRuleGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.resolved.policy.policy.rule.group.with.endpoint.constraints.PolicyRuleGroupBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.util.concurrent.CheckedFuture;
+
+@PrepareForTest(UlnDatastoreApi.class)
+@RunWith(PowerMockRunner.class)
+public class FaasPolicyManagerTest {
+
+ private InstanceIdentifier<DataObject> policyId;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
+ DataBroker dataProvider;
+ private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime()
+ .availableProcessors());
+ EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpgId");
+ SubnetId consumerSubnet = new SubnetId("consumerSubnet");
+ SubnetId providerSubnet = new SubnetId("providerSubnet");
+ EndpointGroupId providerEpgId = new EndpointGroupId("providerEpgId");
+ ContractId contractId = new ContractId("contractId");
+ TenantId tenantId = new TenantId("tenantId");
+ Uuid faasTenantId = new Uuid("0eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ Uuid faasSecRulesId = new Uuid("1eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ L3ContextId l3Context = new L3ContextId("l3ContextId");
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() {
+ policyId = mock(InstanceIdentifier.class);
+ change = mock(AsyncDataChangeEvent.class);
+ policyId = mock(InstanceIdentifier.class);
+ dataProvider = mock(DataBroker.class);
+ PowerMockito.mockStatic(UlnDatastoreApi.class);
+ WriteTransaction writeTransaction = mock(WriteTransaction.class);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = mock(CheckedFuture.class);
+ when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+ Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
+ removedPaths.add(policyId);
+ when(change.getRemovedPaths()).thenReturn(removedPaths);
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void testLayer2ResolvedPolicyWithImpExternalEpg() {
+ // prepare input test data
+ MockFaasPolicyManager policyManager = new MockFaasPolicyManager(dataProvider, executor);
+
+ // mock input test policy
+ policyManager.storeTestEpg(makeTestEndpointGroup(consumerEpgId));
+ policyManager.storeTestEpg(makeTestEndpointGroup(providerEpgId));
+ policyManager.storeTestFaasTenantId(tenantId, faasTenantId);
+ L2BridgeDomain brdg = makeTestBridgeDomain("bridge");
+ policyManager.storeTestL2BridgeDomain(brdg);
+ L2FloodDomain fld1 = makeTestL2FloodDomain("fld1", brdg.getId());
+ policyManager.storeTestL2FloodDomain(fld1);
+ policyManager.storeTestSubnet(makeTestSubnet(consumerSubnet, fld1.getId()));
+ L2FloodDomain fld2 = makeTestL2FloodDomain("fld2", brdg.getId());
+ policyManager.storeTestL2FloodDomain(fld2);
+ policyManager.storeTestSubnet(makeTestSubnet(providerSubnet, fld2.getId()));
+ policyManager.storeTestSecIdPerContract(contractId, faasSecRulesId);
+
+ // mock endpoint attached to consumer side
+ policyManager.registerTenant(tenantId, consumerEpgId);
+ policyManager.registerSubnetWithEpg(consumerEpgId, tenantId, consumerSubnet);
+ // mock endpoint attached to provider side
+ policyManager.registerTenant(tenantId, providerEpgId);
+ policyManager.registerSubnetWithEpg(providerEpgId, tenantId, providerSubnet);
+
+ // input test resolved policy
+ DataObject testPolicy = makeTestResolvedPolicyWithImpExternalEpg();
+ Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
+ testData.put(policyId, testPolicy);
+ when(change.getCreatedData()).thenReturn(testData);
+ when(change.getOriginalData()).thenReturn(testData);
+ when(change.getUpdatedData()).thenReturn(testData);
+ // invoke event -- expected data is verified in mocked classes
+ policyManager.onDataChanged(change);
+
+ // make sure internal threads have completed
+ try {
+ executor.shutdown();
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ fail("FaasPolicyManagerTest: Exception = " + e.toString());
+ }
+
+ // verify
+ assertTrue("FaasPolicyManagerTest", policyManager.getComLayer().equals(ServiceCommunicationLayer.Layer2));
+ assertTrue("FaasPolicyManagerTest", policyManager.getExternalImplicitGroup() != null);
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void testLayer3ResolvedPolicy() {
+ // prepare input test data
+ MockFaasPolicyManager policyManager = new MockFaasPolicyManager(dataProvider, executor);
+
+ // mock input test policy
+ policyManager.storeTestL3Contextes(makeTestL3Context());
+ policyManager.storeTestEpg(makeTestEndpointGroup(consumerEpgId));
+ policyManager.storeTestEpg(makeTestEndpointGroup(providerEpgId));
+ policyManager.storeTestFaasTenantId(tenantId, faasTenantId);
+ L2BridgeDomain brdg1 = makeTestBridgeDomain("bridge1");
+ policyManager.storeTestL2BridgeDomain(brdg1);
+ L2FloodDomain fld1 = makeTestL2FloodDomain("fld1", brdg1.getId());
+ policyManager.storeTestL2FloodDomain(fld1);
+ policyManager.storeTestSubnet(makeTestSubnet(consumerSubnet, fld1.getId()));
+ L2BridgeDomain brdg2 = makeTestBridgeDomain("bridge2");
+ policyManager.storeTestL2BridgeDomain(brdg2);
+ L2FloodDomain fld2 = makeTestL2FloodDomain("fld2", brdg2.getId());
+ policyManager.storeTestL2FloodDomain(fld2);
+ policyManager.storeTestSubnet(makeTestSubnet(providerSubnet, fld2.getId()));
+ policyManager.storeTestSecIdPerContract(contractId, faasSecRulesId);
+
+ // mock endpoint attached to consumer side
+ policyManager.registerTenant(tenantId, consumerEpgId);
+ policyManager.registerSubnetWithEpg(consumerEpgId, tenantId, consumerSubnet);
+ // mock endpoint attached to provider side
+ policyManager.registerTenant(tenantId, providerEpgId);
+ policyManager.registerSubnetWithEpg(providerEpgId, tenantId, providerSubnet);
+
+ // input test resolved policy
+ DataObject testPolicy = makeTestResolvedPolicy();
+ Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
+ testData.put(policyId, testPolicy);
+ when(change.getCreatedData()).thenReturn(testData);
+ when(change.getOriginalData()).thenReturn(testData);
+ when(change.getUpdatedData()).thenReturn(testData);
+ // invoke event -- expected data is verified in mocked classes
+ policyManager.onDataChanged(change);
+
+ // make sure internal threads have completed
+ try {
+ executor.shutdown();
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ fail("FaasPolicyManagerTest: Exception = " + e.toString());
+ }
+
+ // verify
+ assertTrue("FaasPolicyManagerTest", policyManager.getComLayer().equals(ServiceCommunicationLayer.Layer3));
+ assertTrue("FaasPolicyManagerTest", policyManager.getExternalImplicitGroup() == null);
+ }
+
+ private L3Context makeTestL3Context() {
+ L3ContextBuilder builder = new L3ContextBuilder();
+ builder.setId(l3Context);
+ return builder.build();
+ }
+
+ private L2FloodDomain makeTestL2FloodDomain(String id, L2BridgeDomainId brdgId) {
+ L2FloodDomainBuilder builder = new L2FloodDomainBuilder();
+ builder.setId(new L2FloodDomainId(id));
+ builder.setParent(brdgId);
+ return builder.build();
+ }
+
+ private L2BridgeDomain makeTestBridgeDomain(String id) {
+ L2BridgeDomainBuilder builder = new L2BridgeDomainBuilder();
+ builder.setId(new L2BridgeDomainId(id));
+ builder.setParent(l3Context);
+ return builder.build();
+ }
+
+ private EndpointGroup makeTestEndpointGroup(EndpointGroupId epgId) {
+ EndpointGroupBuilder builder = new EndpointGroupBuilder();
+ builder.setId(epgId);
+ return builder.build();
+ }
+
+ private Subnet makeTestSubnet(SubnetId subnetId, L2FloodDomainId l2FloodDomainId) {
+ SubnetBuilder builder = new SubnetBuilder();
+ builder.setId(subnetId);
+ builder.setParent(l2FloodDomainId);
+ return builder.build();
+
+ }
+
+ private DataObject makeTestResolvedPolicy() {
+ ResolvedPolicyBuilder builder = new ResolvedPolicyBuilder();
+ builder.setConsumerEpgId(consumerEpgId);
+ builder.setConsumerTenantId(tenantId);
+ builder.setProviderEpgId(providerEpgId);
+ builder.setProviderTenantId(tenantId);
+ List<PolicyRuleGroupWithEndpointConstraints> pRulesGrpsWEp = new ArrayList<>();
+ PolicyRuleGroupWithEndpointConstraintsBuilder pRulesGrpWEp = new PolicyRuleGroupWithEndpointConstraintsBuilder();
+ List<PolicyRuleGroup> pRulesGrps = new ArrayList<>();
+ PolicyRuleGroupBuilder pRulesGrp = new PolicyRuleGroupBuilder();
+ pRulesGrp.setContractId(contractId);
+ pRulesGrps.add(pRulesGrp.build());
+ pRulesGrpWEp.setPolicyRuleGroup(pRulesGrps);
+ pRulesGrpsWEp.add(pRulesGrpWEp.build());
+ builder.setPolicyRuleGroupWithEndpointConstraints(pRulesGrpsWEp);
+ return builder.build();
+ }
+
+ private DataObject makeTestResolvedPolicyWithImpExternalEpg() {
+ ResolvedPolicyBuilder builder = new ResolvedPolicyBuilder((ResolvedPolicy) makeTestResolvedPolicy());
+ builder.setExternalImplicitGroup(ExternalImplicitGroup.ConsumerEpg);
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.faas.uln.datastore.api.UlnDatastoreApi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.subnets.rev151013.subnets.container.subnets.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.util.concurrent.CheckedFuture;
+
+@PrepareForTest(UlnDatastoreApi.class)
+@RunWith(PowerMockRunner.class)
+public class FaasSubnetManagerListenerTest {
+
+ private InstanceIdentifier<DataObject> subnetId;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
+ private MockFaasSubnetManagerListener subnetManagerListener;
+ private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime()
+ .availableProcessors());
+ private TenantId gbpTenantId = new TenantId("b4511aac-ae43-11e5-bf7f-feff819cdc9f");
+ private Uuid faasTenantId = new Uuid("b4511aac-ae43-11e5-bf7f-feff819cdc9f");
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() {
+ subnetId = mock(InstanceIdentifier.class);
+ change = mock(AsyncDataChangeEvent.class);
+ subnetId = mock(InstanceIdentifier.class);
+ DataBroker dataProvider = mock(DataBroker.class);
+ PowerMockito.mockStatic(UlnDatastoreApi.class);
+ WriteTransaction writeTransaction = mock(WriteTransaction.class);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = mock(CheckedFuture.class);
+ when(writeTransaction.submit()).thenReturn(checkedFuture);
+ subnetManagerListener = new MockFaasSubnetManagerListener(dataProvider, gbpTenantId, faasTenantId, executor);
+
+ Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
+ removedPaths.add(subnetId);
+ when(change.getRemovedPaths()).thenReturn(removedPaths);
+ }
+
+ @Test
+ public void testOnDataChangeSubnet() {
+ // prepare input test data
+ ArgumentCaptor<Subnet> captor = ArgumentCaptor.forClass(Subnet.class);
+ try {
+ PowerMockito.doNothing().when(UlnDatastoreApi.class, "submitSubnetToDs", captor.capture());
+ } catch (Exception e) {
+ fail("testOnDataChangeSubnet: Exception = " + e.toString());
+ }
+ Uuid expectedFaasSubnetId = new Uuid("c4511aac-ae43-11e5-bf7f-feff819cdc9f");
+ subnetManagerListener.setExpectedFaasSubnetId(expectedFaasSubnetId);
+ DataObject testSubnet = makeTestSubnet();
+ subnetManagerListener.setExpectedGbpSubnet(testSubnet);
+ Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
+ testData.put(subnetId, testSubnet);
+ when(change.getCreatedData()).thenReturn(testData);
+ when(change.getOriginalData()).thenReturn(testData);
+ when(change.getUpdatedData()).thenReturn(testData);
+ // invoke event -- expected data is verified in mocked classes
+ subnetManagerListener.onDataChanged(change);
+
+ // make sure internal threads have completed
+ try {
+ executor.shutdown();
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ fail("testOnDataChangeSubnet: Exception = " + e.toString());
+ }
+ // Verify passed in values to fabric mapping engine
+ assertTrue("testOnDataChangeSubnet: Actual Faas SubnetId is NOT as expected",
+ expectedFaasSubnetId.equals(captor.getValue().getUuid()));
+ }
+
+ private DataObject makeTestSubnet() {
+ SubnetBuilder builder = new SubnetBuilder();
+ builder.setId(new SubnetId("b4511aac-ae43-11e5-bf7f-feff819cdc9f"));
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.security.rules.rev151013.security.rule.groups.attributes.security.rule.groups.container.SecurityRuleGroupsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;
+
+public class MockFaasContractManagerListener extends FaasContractManagerListener {
+
+ private Contract expectedContract;
+ private Uuid expectedFaasSecId;
+
+ public MockFaasContractManagerListener(DataBroker dataProvider, TenantId gbpTenantId, Uuid faasTenantId,
+ ScheduledExecutorService executor) {
+ super(dataProvider, gbpTenantId, faasTenantId, executor);
+ }
+
+ // *******************************************************
+ // Test Stubs
+ // *******************************************************
+ @Override
+ protected SecurityRuleGroupsBuilder initSecurityGroupBuilder(Contract contract) {
+ if (expectedContract != null)
+ assertTrue("FaasContractManagerListener.initSecurityGroupBuilder", expectedContract.equals(contract));
+ SecurityRuleGroupsBuilder sec = new SecurityRuleGroupsBuilder();
+ sec.setUuid(expectedFaasSecId);
+ return sec;
+ }
+
+ // *******************************************************
+ // The following Methods are to input test data
+ // *******************************************************
+ public void setExpectedContract(Contract expectedContract) {
+ this.expectedContract = expectedContract;
+ }
+
+ public void setExpectedFaasSecId(Uuid expectedFaasSecId) {
+ this.expectedFaasSecId = expectedFaasSecId;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+
+public class MockFaasEndpointManagerListener extends FaasEndpointManagerListener {
+
+ private Endpoint expectedEndpoint;
+
+ public MockFaasEndpointManagerListener(FaasPolicyManager policyManager, DataBroker dataProvider,
+ ScheduledExecutorService executor) {
+ super(policyManager, dataProvider, executor);
+ }
+
+ // *******************************************************
+ // Test Stubs
+ // *******************************************************
+ @Override
+ protected void processEndpoint(Endpoint endpoint) {
+ if (expectedEndpoint != null)
+ assertTrue("FaasEndpointManagerListener.processEndpoint", expectedEndpoint.equals(endpoint));
+ }
+
+ // *******************************************************
+ // The following Methods are to input test data
+ // *******************************************************
+ public void setExpectedEndpoint(Endpoint testEndpoint) {
+ this.expectedEndpoint = testEndpoint;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.faas.uln.datastore.api.Pair;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.ServiceCommunicationLayer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy.ExternalImplicitGroup;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+
+public class MockFaasPolicyManager extends FaasPolicyManager {
+
+ private Map<EndpointGroupId, EndpointGroup> testEndpointGroups = new HashMap<>();
+ private Map<SubnetId, Subnet> testSubnets = new HashMap<>();
+ private Map<L2FloodDomainId, L2FloodDomain> testL2FloodDomains = new HashMap<>();
+ private Map<L2BridgeDomainId, L2BridgeDomain> testL2BridgeDomains = new HashMap<>();
+ private Map<L3ContextId, L3Context> testL3Contextes = new HashMap<>();
+ private Map<ContractId, Uuid> testSecIdPerContract = new HashMap<>();
+ private Map<TenantId, Uuid> testFaasTenantId = new HashMap<>();
+ private ServiceCommunicationLayer comLayer;
+ private ExternalImplicitGroup externalImplicitGroup;
+
+ public MockFaasPolicyManager(DataBroker dataBroker, ScheduledExecutorService executor) {
+ super(dataBroker, executor);
+ }
+
+ // *******************************************************
+ // Test Stubs
+ // *******************************************************
+ @Override
+ public void registerTenant(TenantId tenantId, EndpointGroupId epgId) {
+ assertTrue("FaasPolicyManager.registerTenant: epgId != null", epgId != null);
+ assertTrue("FaasPolicyManager.registerTenant: tenantId != null", tenantId != null);
+
+ assertTrue("FaasPolicyManager.registerTenant: testEndpointGroups.containsKey(epgId)",
+ testEndpointGroups.containsKey(epgId));
+
+ registeredTenants.putIfAbsent(tenantId, new ArrayList<ListenerRegistration<DataChangeListener>>());
+ }
+
+ @Override
+ public void registerSubnetWithEpg(EndpointGroupId epgId, TenantId tenantId, SubnetId subnetId) {
+ assertTrue("FaasPolicyManager.registerTenant: epgId != null", epgId != null);
+ assertTrue("FaasPolicyManager.registerTenant: tenantId != null", tenantId != null);
+ assertTrue("FaasPolicyManager.registerTenant: subnetId != null", subnetId != null);
+
+ assertTrue("FaasPolicyManager.registerTenant: testEndpointGroups.containsKey(epgId)",
+ testEndpointGroups.containsKey(epgId));
+ assertTrue("FaasPolicyManager.registerTenant: registeredTenants.containsKey(tenantId)",
+ registeredTenants.containsKey(tenantId));
+ assertTrue("FaasPolicyManager.registerTenant: testSubnets.containsKey(subnetId)",
+ testSubnets.containsKey(subnetId));
+ List<SubnetId> subnets = epgSubnetsMap.get(new Pair<>(epgId, tenantId));
+ if (subnets == null) {
+ subnets = new ArrayList<>();
+ }
+ for (SubnetId id : subnets) {
+ if (id.equals(subnetId)) {
+ return;
+ }
+ }
+ subnets.add(subnetId);
+ epgSubnetsMap.put(new Pair<>(epgId, tenantId), subnets);
+ }
+
+ @Override
+ public EndpointGroup readEndpointGroup(EndpointGroupId epgId, TenantId tenantId) {
+ return testEndpointGroups.get(epgId);
+ }
+
+ @Override
+ public Subnet readSubnet(SubnetId subnetId, TenantId tenantId) {
+ return testSubnets.get(subnetId);
+ }
+
+ @Override
+ protected L2FloodDomain readL2FloodDomain(L2FloodDomainId l2fId, TenantId tenantId) {
+ return testL2FloodDomains.get(l2fId);
+ }
+
+ @Override
+ protected L2BridgeDomain readL2BridgeDomainInstance(TenantId tenantId, L2BridgeDomainId l2bId) {
+ return testL2BridgeDomains.get(l2bId);
+ }
+
+ @Override
+ protected L3Context readL3ContextInstance(TenantId tenantId, L3ContextId l3cId) {
+ return testL3Contextes.get(l3cId);
+ }
+
+ @Override
+ protected boolean needToCreateLogicalNetwork(ServiceCommunicationLayer comLayer, List<SubnetId> consSubnetIds,
+ List<SubnetId> provSubnetIds, TenantId tenantId, ContractId contractId, EndpointGroup providerEpg,
+ EndpointGroup consumerEpg, ExternalImplicitGroup externalImplicitGroup) {
+ return true;
+ }
+
+ @Override
+ protected Uuid getFaasSecRulesId(ContractId contractId, TenantId gbpTenantId) {
+ return testSecIdPerContract.get(contractId);
+ }
+
+ @Override
+ public Uuid getFaasTenantId(TenantId tenantId) {
+ return testFaasTenantId.get(tenantId);
+ }
+
+ @Override
+ protected void createLayer3LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
+ TenantId gbpTenantId, ServiceCommunicationLayer comLayer, ExternalImplicitGroup externalImplicitGroup) {
+ this.comLayer = comLayer;
+ this.externalImplicitGroup = externalImplicitGroup;
+ assertTrue("FaasPolicyManager.createLayer3LogicalNetwork", testEndpointGroups.containsKey(consEpg.getId()));
+ assertTrue("FaasPolicyManager.createLayer3LogicalNetwork", testEndpointGroups.containsKey(provEpg.getId()));
+ assertTrue("FaasPolicyManager.createLayer3LogicalNetwork", registeredTenants.containsKey(gbpTenantId));
+
+ }
+
+ @Override
+ protected void createLayer2LogicalNetwork(EndpointGroup consEpg, ContractId contractId, EndpointGroup provEpg,
+ TenantId gbpTenantId, ServiceCommunicationLayer comLayer, ExternalImplicitGroup externalImplicitGroup) {
+ this.comLayer = comLayer;
+ this.externalImplicitGroup = externalImplicitGroup;
+ assertTrue("FaasPolicyManager.createLayer2LogicalNetwork", testEndpointGroups.containsKey(consEpg.getId()));
+ assertTrue("FaasPolicyManager.createLayer2LogicalNetwork", testEndpointGroups.containsKey(provEpg.getId()));
+ assertTrue("FaasPolicyManager.createLayer2LogicalNetwork", registeredTenants.containsKey(gbpTenantId));
+ }
+
+ // *******************************************************
+ // The following Methods are to input test data
+ // *******************************************************
+
+ public void storeTestFaasTenantId(TenantId gbpTenantId, Uuid faasTenantId) {
+ testFaasTenantId.put(gbpTenantId, faasTenantId);
+ }
+
+ public void storeTestSecIdPerContract(ContractId contractId, Uuid secId) {
+ testSecIdPerContract.put(contractId, secId);
+ }
+
+ public void storeTestL2BridgeDomain(L2BridgeDomain brdg) {
+ if (brdg.getId() != null) {
+ testL2BridgeDomains.put(brdg.getId(), brdg);
+ }
+ }
+
+ public void storeTestL3Contextes(L3Context l3Context) {
+ if (l3Context.getId() != null) {
+ testL3Contextes.put(l3Context.getId(), l3Context);
+ }
+ }
+
+ public void storeTestL2FloodDomain(L2FloodDomain fld) {
+ if (fld.getId() != null) {
+ testL2FloodDomains.put(fld.getId(), fld);
+ }
+ }
+
+ public void storeTestSubnet(Subnet subnet) {
+ if (subnet.getId() != null) {
+ testSubnets.put(subnet.getId(), subnet);
+ }
+ }
+
+ public void storeTestEpg(EndpointGroup epg) {
+ if (epg.getId() != null) {
+ testEndpointGroups.put(epg.getId(), epg);
+ }
+ }
+
+ public ServiceCommunicationLayer getComLayer() {
+ return comLayer;
+ }
+
+ public ExternalImplicitGroup getExternalImplicitGroup() {
+ return externalImplicitGroup;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Huawei Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.faas;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.subnets.rev151013.subnets.container.subnets.SubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public class MockFaasSubnetManagerListener extends FaasSubnetManagerListener {
+
+ Subnet expectedGbpSubnet;
+ private Uuid expectedFaasSubnetId;
+
+ public MockFaasSubnetManagerListener(DataBroker dataProvider, TenantId gbpTenantId, Uuid faasTenantId,
+ ScheduledExecutorService executor) {
+ super(dataProvider, gbpTenantId, faasTenantId, executor);
+ }
+
+ // *******************************************************
+ // Test Stubs
+ // *******************************************************
+ @Override
+ protected SubnetBuilder initSubnetBuilder(Subnet subnet) {
+ if (expectedGbpSubnet != null)
+ assertTrue("FaasSubnetManagerListener.initSubnetBuilder", expectedGbpSubnet.equals(subnet));
+ SubnetBuilder builder = new SubnetBuilder();
+ builder.setUuid(expectedFaasSubnetId);
+ return builder;
+ }
+
+ // *******************************************************
+ // The following Methods are to input test data
+ // *******************************************************
+ public void setExpectedFaasSubnetId(Uuid expectedFaasSubnetId) {
+ this.expectedFaasSubnetId = expectedFaasSubnetId;
+ }
+
+ public void setExpectedGbpSubnet(DataObject obj) {
+ expectedGbpSubnet = (Subnet) obj;
+ }
+}