From 971bd55860d9ad779d42d9d58715216ac9908823 Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Wed, 25 Oct 2017 15:13:41 +0200 Subject: [PATCH] apply checkstyle check during build for neutron-mapper enabling checkstyle checks on build which should prevent checkstyle violations in future. Change-Id: Ibe476cc7aed6f6b9b65dd998245b6f0108eef31b Signed-off-by: Michal Cmarada --- neutron-mapper/pom.xml | 16 ++ .../gbp/util/NeutronGbpIidFactory.java | 27 +-- .../neutron/mapper/EndpointRegistrator.java | 75 ++++--- .../neutron/mapper/NeutronMapper.java | 49 +++-- .../infrastructure/MetadataService.java | 48 ++-- .../mapper/infrastructure/NetworkClient.java | 24 +- .../mapper/infrastructure/NetworkService.java | 79 +++---- .../mapper/infrastructure/ServiceUtil.java | 106 +++++---- .../neutron/mapper/mapping/NeutronAware.java | 3 +- .../mapping/NeutronFloatingIpAware.java | 7 +- .../mapper/mapping/NeutronNetworkAware.java | 43 ++-- .../mapper/mapping/NeutronPortAware.java | 77 ++++--- .../mapper/mapping/NeutronRouterAware.java | 205 ++++++++++-------- .../mapping/NeutronSecurityGroupAware.java | 15 +- .../mapper/mapping/NeutronSubnetAware.java | 24 +- .../rule/NeutronGbpMapperServiceImpl.java | 108 --------- .../rule/NeutronSecurityRuleAware.java | 91 ++++---- .../mapping/rule/SecRuleEntityDecoder.java | 44 ++-- .../mapping/rule/SecRuleNameDecoder.java | 5 +- .../mapping/rule/SingleClassifierRule.java | 14 +- .../mapping/rule/SingleRuleContract.java | 7 +- .../neutron/mapper/util/NetworkUtils.java | 6 +- .../neutron/mapper/util/PortUtils.java | 4 +- .../neutron/mapper/util/RouterUtils.java | 4 +- .../mapper/util/SecurityGroupUtils.java | 8 +- .../mapper/util/SecurityRuleUtils.java | 14 +- .../neutron/mapper/util/SubnetUtils.java | 4 +- .../neutron/mapper/util/Utils.java | 8 +- .../gbp/util/NeutronGbpIidFactoryTest.java | 42 ++-- .../neutron/mapper/NeutronMapperTest.java | 12 +- .../NeutronNetworkAwareDataStoreTest.java | 11 +- .../NeutronPortAwareDataStoreTest.java | 14 +- .../NeutronRouterAwareDataStoreTest.java | 120 +++++----- ...eutronSecurityGroupAwareDataStoreTest.java | 6 +- .../NeutronSubnetAwareDataStoreTest.java | 83 +++---- ...NeutronSecurityRuleAwareDataStoreTest.java | 162 +++++++------- .../rule/NeutronSecurityRuleAwareTest.java | 2 +- .../rule/SecRuleEntityDecoderTest.java | 19 +- .../mapping/rule/SecRuleNameDecoderTest.java | 4 +- .../rule/SingleClassifierRuleTest.java | 67 +++--- .../mapper/test/ConfigDataStoreReader.java | 11 +- .../mapper/test/CustomDataBrokerTest.java | 10 +- .../mapper/test/NeutronEntityFactory.java | 10 +- .../mapper/test/NeutronMapperAssert.java | 13 +- .../test/NeutronMapperDataBrokerTest.java | 15 +- .../neutron/mapper/test/PolicyAssert.java | 22 +- 46 files changed, 877 insertions(+), 861 deletions(-) delete mode 100644 neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronGbpMapperServiceImpl.java diff --git a/neutron-mapper/pom.xml b/neutron-mapper/pom.xml index 167c0da1d..f24cc5cf6 100644 --- a/neutron-mapper/pom.xml +++ b/neutron-mapper/pom.xml @@ -124,6 +124,22 @@ + + maven-checkstyle-plugin + + org/opendaylight/yang/gen/**,**/yang/** + true + checkstyle.violationSeverity=error + + + + + check + + process-sources + + + diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactory.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactory.java index 42232b0e3..0a84688b3 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactory.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactory.java @@ -19,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.IpPrefixType; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.NeutronByGbpMappings; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts; @@ -48,8 +49,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class NeutronGbpIidFactory { public static InstanceIdentifier baseEndpointByPortIid(UniqueId portId) { - return InstanceIdentifier.builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + return InstanceIdentifier.builder(Mappings.class) .child(GbpByNeutronMappings.class) .child(BaseEndpointsByPorts.class) .child(BaseEndpointByPort.class, new BaseEndpointByPortKey(portId)) @@ -59,8 +59,7 @@ public class NeutronGbpIidFactory { @Deprecated public static InstanceIdentifier endpointByPortIid(UniqueId portId) { return InstanceIdentifier - .builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + .builder(Mappings.class) .child(GbpByNeutronMappings.class) .child(EndpointsByPorts.class) .child(EndpointByPort.class, new EndpointByPortKey(portId)) @@ -68,8 +67,7 @@ public class NeutronGbpIidFactory { } public static InstanceIdentifier portByBaseEndpointIid(PortByBaseEndpointKey baseEpkey) { - return InstanceIdentifier.builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + return InstanceIdentifier.builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(PortsByBaseEndpoints.class) .child(PortByBaseEndpoint.class, baseEpkey) @@ -79,8 +77,7 @@ public class NeutronGbpIidFactory { @Deprecated public static InstanceIdentifier portByEndpointIid(L2BridgeDomainId l2BdId, MacAddress mac) { return InstanceIdentifier - .builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + .builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(PortsByEndpoints.class) .child(PortByEndpoint.class, new PortByEndpointKey(l2BdId, mac)) @@ -94,8 +91,7 @@ public class NeutronGbpIidFactory { IpPrefixType.class, contextId, contextType); - return InstanceIdentifier.builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + return InstanceIdentifier.builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(ExternalGatewaysAsEndpoints.class) .child(ExternalGatewayAsEndpoint.class, key) @@ -106,8 +102,7 @@ public class NeutronGbpIidFactory { public static InstanceIdentifier externalGatewayAsL3Endpoint(L3ContextId l3Context, IpAddress ipAddress) { return InstanceIdentifier - .builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + .builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(ExternalGatewaysAsL3Endpoints.class) .child(ExternalGatewayAsL3Endpoint.class, new ExternalGatewayAsL3EndpointKey(ipAddress, l3Context)) @@ -116,8 +111,7 @@ public class NeutronGbpIidFactory { public static InstanceIdentifier providerPhysicalNetworkAsL2FloodDomainIid( TenantId tenantId, ContextId domainId) { - return InstanceIdentifier.builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + return InstanceIdentifier.builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(ProviderNetworksAsL2FloodDomains.class) .child(ProviderPhysicalNetworkAsL2FloodDomain.class, @@ -126,10 +120,11 @@ public class NeutronGbpIidFactory { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public static InstanceIdentifier providerPhysicalNetworkAsL2FloodDomainIid( TenantId tenantId, L2FloodDomainId l2FdId) { - return InstanceIdentifier.builder( - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) + return InstanceIdentifier.builder(Mappings.class) .child(NeutronByGbpMappings.class) .child(ProviderPhysicalNetworksAsL2FloodDomains.class) .child(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.provider.physical.networks.as.l2.flood.domains.ProviderPhysicalNetworkAsL2FloodDomain.class, diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/EndpointRegistrator.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/EndpointRegistrator.java index 551a84357..5ecfd508e 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/EndpointRegistrator.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/EndpointRegistrator.java @@ -8,12 +8,15 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper; -import javax.annotation.Nullable; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; + +import javax.annotation.Nullable; + import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; @@ -71,43 +74,47 @@ public class EndpointRegistrator { } } - public boolean unregisterEndpoint(AddressEndpointUnreg addrEpUnreg) { - UnregisterEndpointInput input = new UnregisterEndpointInputBuilder().setAddressEndpointUnreg( - ImmutableList.of(new AddressEndpointUnregBuilder().setKey(addrEpUnreg.getKey()) - .build())).build(); - return unregisterEndpoint(input); - } - - public boolean unregisterEndpoint(UnregisterEndpointInput input) { + @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. + public boolean registerEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput regEndpointInput) { try { - RpcResult rpcResult = baseEpService.unregisterEndpoint(input).get(); + RpcResult rpcResult = epService.registerEndpoint(regEndpointInput).get(); if (!rpcResult.isSuccessful()) { - LOG.warn("Illegal state - unregisterEndpoint was not successful. Input of RPC: {}", input); + LOG.warn("Illegal state - register Endpoint was not successful. Input of RPC: {}", regEndpointInput); return false; } return true; } catch (InterruptedException | ExecutionException e) { - LOG.error("unregisterEndpoint failed. {}", input, e); + LOG.error("registerEndpoint failed. {}", regEndpointInput, e); return false; } } - @Deprecated - public boolean registerEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput regEndpointInput) { + public boolean unregisterEndpoint(AddressEndpointUnreg addrEpUnreg) { + UnregisterEndpointInput input = new UnregisterEndpointInputBuilder().setAddressEndpointUnreg( + ImmutableList.of(new AddressEndpointUnregBuilder().setKey(addrEpUnreg.getKey()) + .build())).build(); + return unregisterEndpoint(input); + } + + public boolean unregisterEndpoint(UnregisterEndpointInput input) { try { - RpcResult rpcResult = epService.registerEndpoint(regEndpointInput).get(); + RpcResult rpcResult = baseEpService.unregisterEndpoint(input).get(); if (!rpcResult.isSuccessful()) { - LOG.warn("Illegal state - register Endpoint was not successful. Input of RPC: {}", regEndpointInput); + LOG.warn("Illegal state - unregisterEndpoint was not successful. Input of RPC: {}", input); return false; } return true; } catch (InterruptedException | ExecutionException e) { - LOG.error("registerEndpoint failed. {}", regEndpointInput, e); + LOG.error("unregisterEndpoint failed. {}", input, e); return false; } } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public boolean unregisterEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregEndpointInput) { try { RpcResult rpcResult = epService.unregisterEndpoint(unregEndpointInput).get(); @@ -154,17 +161,20 @@ public class EndpointRegistrator { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public boolean registerL3EpAsExternalGateway(TenantId tenantId, IpAddress ipAddress, L3ContextId l3Context, NetworkDomainId networkContainment) { - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput registerEndpointInput = - new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder() - .setL3Address(ImmutableList - .of(new L3AddressBuilder().setL3Context(l3Context).setIpAddress(ipAddress).build())) - .setTenant(tenantId) - .setNetworkContainment(networkContainment) - .setEndpointGroups(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID)) - .setTimestamp(System.currentTimeMillis()) - .build(); + org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput + registerEndpointInput = + new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder() + .setL3Address( + ImmutableList.of(new L3AddressBuilder().setL3Context(l3Context).setIpAddress(ipAddress).build())) + .setTenant(tenantId) + .setNetworkContainment(networkContainment) + .setEndpointGroups(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID)) + .setTimestamp(System.currentTimeMillis()) + .build(); try { RpcResult rpcResult = epService.registerEndpoint(registerEndpointInput).get(); if (!rpcResult.isSuccessful()) { @@ -180,12 +190,13 @@ public class EndpointRegistrator { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public boolean unregisterL3EpAsExternalGateway(IpAddress ipAddress, L3ContextId l3Context) { - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregisterEndpointInput = + org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput + unregisterEndpointInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder() - .setL3(ImmutableList.of(new L3Builder().setL3Context(l3Context) - .setIpAddress(ipAddress) - .build())) + .setL3(ImmutableList.of(new L3Builder().setL3Context(l3Context).setIpAddress(ipAddress).build())) .build(); try { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java index da456032c..35b39b7be 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java @@ -7,6 +7,12 @@ */ package org.opendaylight.groupbasedpolicy.neutron.mapper; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Iterators; +import com.google.common.collect.PeekingIterator; + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -60,37 +66,31 @@ import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Iterators; -import com.google.common.collect.PeekingIterator; - public class NeutronMapper implements ClusteredDataTreeChangeListener, AutoCloseable { - private static final String EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA = "Unknown modification type within data "; + private static final String EXC_MSG_UNKNOWN_MODIFICATION_TYPE_IN_DATA = "Unknown modification type within data "; - private final static SecurityRuleBuilder EIG_INGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder() + private static final SecurityRuleBuilder EIG_INGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder() .setUuid(new Uuid("0a629f80-2408-11e6-b67b-9e71128cae77")) .setDirection(DirectionIngress.class) .setEthertype(EthertypeV4.class) .setSecurityGroupId(MappingUtils.EIG_UUID); - private final static SecurityRuleBuilder EIG_EGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder() + private static final SecurityRuleBuilder EIG_EGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder() .setUuid(new Uuid("0f1789be-2408-11e6-b67b-9e71128cae77")) .setDirection(DirectionEgress.class) .setEthertype(EthertypeV4.class) .setSecurityGroupId(MappingUtils.EIG_UUID); - private final static SecurityRuleBuilder EIG_INGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder() + private static final SecurityRuleBuilder EIG_INGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder() .setUuid(new Uuid("139b7f90-2408-11e6-b67b-9e71128cae77")) .setDirection(DirectionIngress.class) .setEthertype(EthertypeV6.class) .setSecurityGroupId(MappingUtils.EIG_UUID); - private final static SecurityRuleBuilder EIG_EGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder() + private static final SecurityRuleBuilder EIG_EGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder() .setUuid(new Uuid("17517202-2408-11e6-b67b-9e71128cae77")) .setDirection(DirectionEgress.class) .setEthertype(EthertypeV6.class) .setSecurityGroupId(MappingUtils.EIG_UUID); - private final static SecurityGroupBuilder EIG_SEC_GROUP_BUILDER = + private static final SecurityGroupBuilder EIG_SEC_GROUP_BUILDER = new SecurityGroupBuilder().setUuid(MappingUtils.EIG_UUID); private final NeutronNetworkAware networkAware; @@ -148,16 +148,20 @@ public class NeutronMapper implements ClusteredDataTreeChangeListener, findModifiedData(NeutronSecurityRuleAware.SECURITY_RULE_WILDCARD_IID, neutronModif); onDataObjectModification(secRuleModifs, securityRuleAware); // subnet - List> subnetModifs = findModifiedData(NeutronSubnetAware.SUBNET_WILDCARD_IID, neutronModif); + List> subnetModifs = + findModifiedData(NeutronSubnetAware.SUBNET_WILDCARD_IID, neutronModif); onDataObjectModification(subnetModifs, subnetAware); // port - List> portModifs = findModifiedData(NeutronPortAware.PORT_WILDCARD_IID, neutronModif); + List> portModifs = + findModifiedData(NeutronPortAware.PORT_WILDCARD_IID, neutronModif); onDataObjectModification(portModifs, portAware); // router - List> routerModifs = findModifiedData(NeutronRouterAware.ROUTER_WILDCARD_IID, neutronModif); + List> routerModifs = + findModifiedData(NeutronRouterAware.ROUTER_WILDCARD_IID, neutronModif); onDataObjectModification(routerModifs, routerAware); // floating IP - List> floatingIpModifs = findModifiedData(NeutronFloatingIpAware.FLOATING_IP_WILDCARD_IID, neutronModif); + List> floatingIpModifs = + findModifiedData(NeutronFloatingIpAware.FLOATING_IP_WILDCARD_IID, neutronModif); onDataObjectModification(floatingIpModifs, floatingIpAware); } } @@ -169,15 +173,12 @@ public class NeutronMapper implements ClusteredDataTreeChangeListener, final T dataAfter = dataModif.getDataAfter(); if (dataBefore == null && dataAfter != null) { neutronAware.onCreated(dataAfter, neutronAfter); - } - else if (dataBefore != null && dataAfter != null) { + } else if (dataBefore != null && dataAfter != null) { neutronAware.onUpdated(dataBefore, dataAfter, neutronBefore, neutronAfter); - } - else if (dataBefore != null) { + } else if (dataBefore != null) { neutronAware.onDeleted(dataBefore, neutronBefore, neutronAfter); - } - else { - throw new IllegalStateException(EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA + dataModif); + } else { + throw new IllegalStateException(EXC_MSG_UNKNOWN_MODIFICATION_TYPE_IN_DATA + dataModif); } } } @@ -277,7 +278,7 @@ public class NeutronMapper implements ClusteredDataTreeChangeListener, /** * Finds all modified subnodes of given type in {@link Neutron} node. * - * @param + * @param dataObject type * @param iid path to data in root node * @param rootNode modified data of {@link Neutron} node * @return {@link List} of modified subnodes diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/MetadataService.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/MetadataService.java index 5fe122044..09a0efa79 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/MetadataService.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/MetadataService.java @@ -8,6 +8,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure; +import com.google.common.collect.ImmutableList; + import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -44,8 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; -import com.google.common.collect.ImmutableList; - public class MetadataService extends ServiceUtil { private static final ClassifierName METADATA_SERVER_TO_CLIENT_NAME = @@ -57,17 +57,16 @@ public class MetadataService extends ServiceUtil { new Description("Allow METADATA management communication between server and client."); /** - * Id of {@link #METADATA_CONTRACT} + * Id of {@link #METADATA_CONTRACT}. */ public static final ContractId METADATA_CONTRACT_ID = new ContractId("be0675b7-b0d6-46cc-acf1-247ed31cf572"); /** - * Contains rules with action {@link MappingUtils#ACTION_REF_ALLOW} matching ICMP and SSH - * communication + * Contains rules with action {@link MappingUtils#ACTION_REF_ALLOW} matching ICMP and SSH communication * between Client and Server. */ public static final Contract METADATA_CONTRACT; /** - * {@link ConsumerNamedSelector} pointing to {@link #METADATA_CONTRACT} + * {@link ConsumerNamedSelector} pointing to {@link #METADATA_CONTRACT}. */ public static final ConsumerNamedSelector METADATA_CONTRACT_CONSUMER_SELECTOR; @@ -75,11 +74,11 @@ public class MetadataService extends ServiceUtil { private static final Name METADATA_SERVICE_EPG_NAME = new Name("NETWORK_SERVICE"); private static final Description METADATA_SERVICE_EPG_DESC = new Description("Represents DHCP and DNS servers."); /** - * ID of {@link #EPG} + * ID of {@link #EPG}. */ public static final EndpointGroupId EPG_ID = new EndpointGroupId("ffff1111-dfe5-11e4-8a00-1681e6b88ec1"); /** - * Network-service endpoint-group providing {@link #METADATA_CONTRACT} + * Network-service endpoint-group providing {@link #METADATA_CONTRACT}. */ public static final EndpointGroup EPG; @@ -112,37 +111,44 @@ public class MetadataService extends ServiceUtil { * * @param tenantId location of {@link #METADATA_CONTRACT} * @param ipPrefix used in {@link L3EndpointIdentificationConstraints} - * @param wTx transaction where entities are written + * @param writeTx transaction where entities are written */ public static void writeMetadataClauseWithConsProvEic(TenantId tenantId, @Nullable IpPrefix ipPrefix, - WriteTransaction wTx) { + WriteTransaction writeTx) { Clause clause = createClauseWithConsProvEic(ipPrefix, METADATA_SUBJECT_NAME); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, METADATA_CONTRACT_ID, clause.getName()), - clause, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, METADATA_CONTRACT_ID, + clause.getName()), clause, true); } /** * Puts network service entities (classifier-instances, {@link #METADATA_CONTRACT}, - * and {@link #EPG}) to {@link LogicalDatastoreType#CONFIGURATION} + * and {@link #EPG}) to {@link LogicalDatastoreType#CONFIGURATION}. * * @param tenantId location of network-service entities - * @param wTx transaction where network-service entities are written + * @param writeTx transaction where network-service entities are written + * @param metadataPort port for metadata */ - public static void writeNetworkServiceEntitiesToTenant(TenantId tenantId, WriteTransaction wTx, long metadataPort) { + public static void writeNetworkServiceEntitiesToTenant(TenantId tenantId, WriteTransaction writeTx, + long metadataPort) { + Set classifierInstances = getAllClassifierInstances(metadataPort); for (ClassifierInstance ci : classifierInstances) { - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.classifierInstanceIid(tenantId, ci.getName()), ci, - true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.classifierInstanceIid(tenantId, ci.getName()), + ci, true); } for (ActionInstance ai : Collections.singleton(MappingUtils.ACTION_ALLOW)) { - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.actionInstanceIid(tenantId, ai.getName()), ai, true); - } - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, METADATA_CONTRACT_ID), METADATA_CONTRACT, + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.actionInstanceIid(tenantId, ai.getName()), ai, true); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); + } + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, METADATA_CONTRACT_ID), + METADATA_CONTRACT, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); } /** + * Used to get all classifier-instances used in {@link #METADATA_CONTRACT} for specified port. + * + * @param metadataPort port for metadata * @return All classifier-instances used in {@link #METADATA_CONTRACT} */ public static Set getAllClassifierInstances(long metadataPort) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java index 75a7907a0..d693ec9b3 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java @@ -8,6 +8,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure; +import com.google.common.base.Preconditions; + import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.groupbasedpolicy.util.IidFactory; @@ -18,18 +20,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev 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.endpoint.group.ConsumerNamedSelector; -import com.google.common.base.Preconditions; - public class NetworkClient extends ServiceUtil { private static final Name NETWORK_CLIENT_EPG_NAME = new Name("NETWORK_CLIENT"); private static final Description NETWORK_CLIENT_EPG_DESC = new Description("Represents DHCP and DNS clients."); /** - * ID of {@link #EPG} + * ID of {@link #EPG}. */ public static final EndpointGroupId EPG_ID = new EndpointGroupId("ccc5e444-573c-11e5-885d-feff819cdc9f"); /** - * Network-client endpoint-group consuming no contract + * Network-client endpoint-group consuming no contract. */ public static final EndpointGroup EPG; @@ -42,26 +42,26 @@ public class NetworkClient extends ServiceUtil { } /** - * Puts {@link #EPG} to {@link LogicalDatastoreType#CONFIGURATION} + * Puts {@link #EPG} to {@link LogicalDatastoreType#CONFIGURATION}. * * @param tenantId location of {@link #EPG} - * @param wTx transaction where {@link #EPG} is written + * @param writeTx transaction where {@link #EPG} is written */ - public static void writeNetworkClientEntitiesToTenant(TenantId tenantId, WriteTransaction wTx) { - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); + public static void writeNetworkClientEntitiesToTenant(TenantId tenantId, WriteTransaction writeTx) { + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); } /** - * Puts consumer-named-selector to {@link #EPG} in {@link LogicalDatastoreType#CONFIGURATION} + * Puts consumer-named-selector to {@link #EPG} in {@link LogicalDatastoreType#CONFIGURATION}. * * @param tenantId tenantId location of {@link #EPG} * @param consumerNamedSelector is added to {@link #EPG} - * @param wTx transaction where the given consumer-named-selector is written + * @param writeTx transaction where the given consumer-named-selector is written */ public static void writeConsumerNamedSelector(TenantId tenantId, ConsumerNamedSelector consumerNamedSelector, - WriteTransaction wTx) { + WriteTransaction writeTx) { Preconditions.checkNotNull(consumerNamedSelector); - wTx.put(LogicalDatastoreType.CONFIGURATION, + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.consumerNamedSelectorIid(tenantId, EPG_ID, consumerNamedSelector.getName()), consumerNamedSelector, true); } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkService.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkService.java index 5dad3f059..c62c58334 100755 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkService.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkService.java @@ -8,6 +8,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure; +import com.google.common.collect.ImmutableList; + import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -44,12 +46,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; -import com.google.common.collect.ImmutableList; - public class NetworkService extends ServiceUtil { /** - * Unit tests {@link NetworkServiceTest} + * Unit tests {@link NetworkServiceTest}. */ // ########### DHCP private static final long DHCP_IPV4_SERVER_PORT = 67; @@ -69,7 +69,7 @@ public class NetworkService extends ServiceUtil { new Description("Allow DHCP communication between client and server."); /** - * Id of {@link #DHCP_CONTRACT} + * Id of {@link #DHCP_CONTRACT}. */ public static final ContractId DHCP_CONTRACT_ID = new ContractId("11118d2e-dddd-11e5-885d-feff819cdc9f"); /** @@ -78,7 +78,7 @@ public class NetworkService extends ServiceUtil { */ public static final Contract DHCP_CONTRACT; /** - * {@link ConsumerNamedSelector} pointing to {@link #DHCP_CONTRACT} + * {@link ConsumerNamedSelector} pointing to {@link #DHCP_CONTRACT}. */ public static final ConsumerNamedSelector DHCP_CONTRACT_CONSUMER_SELECTOR; @@ -104,7 +104,7 @@ public class NetworkService extends ServiceUtil { private static final Description DNS_CONTRACT_DESC = new Description("Allow DNS communication between client and server."); /** - * ID of {@link #DNS_CONTRACT} + * ID of {@link #DNS_CONTRACT}. */ public static final ContractId DNS_CONTRACT_ID = new ContractId("22218d2e-dddd-11e5-885d-feff819cdc9f"); /** @@ -113,7 +113,7 @@ public class NetworkService extends ServiceUtil { */ public static final Contract DNS_CONTRACT; /** - * {@link ConsumerNamedSelector} pointing to {@link #DNS_CONTRACT} + * {@link ConsumerNamedSelector} pointing to {@link #DNS_CONTRACT}. */ public static final ConsumerNamedSelector DNS_CONTRACT_CONSUMER_SELECTOR; @@ -136,17 +136,16 @@ public class NetworkService extends ServiceUtil { new Description("Allow ICMP and SSH management communication between server and client."); /** - * Id of {@link #MGMT_CONTRACT} + * Id of {@link #MGMT_CONTRACT}. */ public static final ContractId MGMT_CONTRACT_ID = new ContractId("33318d2e-dddd-11e5-885d-feff819cdc9f"); /** - * Contains rules with action {@link MappingUtils#ACTION_REF_ALLOW} matching ICMP and SSH - * communication + * Contains rules with action {@link MappingUtils#ACTION_REF_ALLOW} matching ICMP and SSH communication * between Client and Server. */ public static final Contract MGMT_CONTRACT; /** - * {@link ConsumerNamedSelector} pointing to {@link #MGMT_CONTRACT} + * {@link ConsumerNamedSelector} pointing to {@link #MGMT_CONTRACT}. */ public static final ConsumerNamedSelector MGMT_CONTRACT_CONSUMER_SELECTOR; @@ -154,11 +153,11 @@ public class NetworkService extends ServiceUtil { private static final Name NETWORK_SERVICE_EPG_NAME = new Name("NETWORK_SERVICE"); private static final Description NETWORK_SERVICE_EPG_DESC = new Description("Represents DHCP and DNS servers."); /** - * ID of {@link #EPG} + * ID of {@link #EPG}. */ public static final EndpointGroupId EPG_ID = new EndpointGroupId("ddd6cfe6-dfe5-11e4-8a00-1681e6b88ec1"); /** - * Network-service endpoint-group providing {@link #DHCP_CONTRACT} and {@link #DNS_CONTRACT} + * Network-service endpoint-group providing {@link #DHCP_CONTRACT} and {@link #DNS_CONTRACT}. */ public static final EndpointGroup EPG; @@ -237,13 +236,13 @@ public class NetworkService extends ServiceUtil { * * @param tenantId location of {@link #DHCP_CONTRACT} * @param ipPrefix used in {@link L3EndpointIdentificationConstraints} - * @param wTx transaction where entities are written + * @param writeTx transaction where entities are written */ public static void writeDhcpClauseWithConsProvEic(TenantId tenantId, @Nullable IpPrefix ipPrefix, - WriteTransaction wTx) { + WriteTransaction writeTx) { Clause clause = createClauseWithConsProvEic(ipPrefix, DHCP_SUBJECT_NAME); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, DHCP_CONTRACT_ID, clause.getName()), - clause, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, DHCP_CONTRACT_ID, + clause.getName()), clause, true); } /** @@ -252,13 +251,13 @@ public class NetworkService extends ServiceUtil { * * @param tenantId location of {@link #DNS_CONTRACT} * @param ipPrefix used in {@link L3EndpointIdentificationConstraints} - * @param wTx transaction where entities are written + * @param writeTx transaction where entities are written */ public static void writeDnsClauseWithConsProvEic(TenantId tenantId, @Nullable IpPrefix ipPrefix, - WriteTransaction wTx) { + WriteTransaction writeTx) { Clause clause = createClauseWithConsProvEic(ipPrefix, DNS_SUBJECT_NAME); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, DNS_CONTRACT_ID, clause.getName()), - clause, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, DNS_CONTRACT_ID, + clause.getName()), clause, true); } /** @@ -267,44 +266,46 @@ public class NetworkService extends ServiceUtil { * * @param tenantId location of {@link #MGMT_CONTRACT} * @param ipPrefix used in {@link L3EndpointIdentificationConstraints} - * @param wTx transaction where entities are written + * @param writeTx transaction where entities are written */ public static void writeMgmtClauseWithConsProvEic(TenantId tenantId, @Nullable IpPrefix ipPrefix, - WriteTransaction wTx) { + WriteTransaction writeTx) { Clause clause = createClauseWithConsProvEic(ipPrefix, MGMT_SUBJECT_NAME); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, MGMT_CONTRACT_ID, clause.getName()), - clause, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.clauseIid(tenantId, MGMT_CONTRACT_ID, + clause.getName()), clause, true); } /** * Puts network service entities (classifier-instances, {@link #DHCP_CONTRACT}, * {@link #DNS_CONTRACT}, {@link #MGMT_CONTRACT} and {@link #EPG}) to - * {@link LogicalDatastoreType#CONFIGURATION} + * {@link LogicalDatastoreType#CONFIGURATION}. * * @param tenantId location of network-service entities - * @param wTx transaction where network-service entities are written + * @param writeTx transaction where network-service entities are written */ - public static void writeNetworkServiceEntitiesToTenant(TenantId tenantId, WriteTransaction wTx) { + public static void writeNetworkServiceEntitiesToTenant(TenantId tenantId, WriteTransaction writeTx) { Set classifierInstances = getAllClassifierInstances(); for (ClassifierInstance ci : classifierInstances) { - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.classifierInstanceIid(tenantId, ci.getName()), ci, - true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.classifierInstanceIid(tenantId, ci.getName()), + ci, true); } for (ActionInstance ai : Collections.singleton(MappingUtils.ACTION_ALLOW)) { - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.actionInstanceIid(tenantId, ai.getName()), ai, true); - } - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, DHCP_CONTRACT_ID), DHCP_CONTRACT, - true); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, DNS_CONTRACT_ID), DNS_CONTRACT, + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.actionInstanceIid(tenantId, ai.getName()), ai, true); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, MGMT_CONTRACT_ID), MGMT_CONTRACT, - true); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); + } + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, DHCP_CONTRACT_ID), + DHCP_CONTRACT, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, DNS_CONTRACT_ID), DNS_CONTRACT, + true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, MGMT_CONTRACT_ID), + MGMT_CONTRACT, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true); } /** + * Used to get all Classifier instances. * @return All classifier-instances used in {@link #DHCP_CONTRACT}, {@link #DNS_CONTRACT} and - * {@link #MGMT_CONTRACT} + * {@link #MGMT_CONTRACT}. */ public static Set getAllClassifierInstances() { HashSet cis = new HashSet<>(); diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/ServiceUtil.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/ServiceUtil.java index db66f120f..31c6c5423 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/ServiceUtil.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/ServiceUtil.java @@ -8,6 +8,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure; +import com.google.common.collect.ImmutableList; + import java.util.ArrayList; import java.util.List; @@ -41,8 +43,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder; 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.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup.IntraGroupPolicy; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Clause; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject; @@ -59,8 +61,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder; -import com.google.common.collect.ImmutableList; - public class ServiceUtil { protected static Contract createContract(ContractId cid, List subjects, Description description) { @@ -68,7 +68,7 @@ public class ServiceUtil { } protected static ClassifierInstance createClassifInstance(ClassifierName name, ClassifierDefinitionId id, - List pv) { + List pv) { return new ClassifierInstanceBuilder().setName(name) .setClassifierDefinitionId(id) .setParameterValue(pv) @@ -83,7 +83,7 @@ public class ServiceUtil { } protected static List createParams(long etherType, long proto, @Nullable Long srcPort, - @Nullable Long dstPort) { + @Nullable Long dstPort) { List params = new ArrayList<>(); if (srcPort != null) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)) @@ -105,62 +105,54 @@ public class ServiceUtil { } protected static Clause createClauseWithConsProvEic(@Nullable IpPrefix ipPrefix, SubjectName subjectName) { - ConsumerMatchers consumerMatchers = null; - ProviderMatchers providerMatchers = null; - StringBuilder clauseName = new StringBuilder(); - clauseName.append(subjectName.getValue()); - if (ipPrefix != null) { - clauseName.append(MappingUtils.NAME_DOUBLE_DELIMETER).append(Utils.getStringIpPrefix(ipPrefix)); - consumerMatchers = - new ConsumerMatchersBuilder() - .setEndpointIdentificationConstraints(new EndpointIdentificationConstraintsBuilder() - .setL3EndpointIdentificationConstraints(new L3EndpointIdentificationConstraintsBuilder() - .setPrefixConstraint( - ImmutableList.of(new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build())) - .build()) - .build()) - .build(); - providerMatchers = - new ProviderMatchersBuilder() - .setEndpointIdentificationConstraints(new EndpointIdentificationConstraintsBuilder() - .setL3EndpointIdentificationConstraints(new L3EndpointIdentificationConstraintsBuilder() - .setPrefixConstraint( - ImmutableList.of(new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build())) - .build()) - .build()) - .build(); - } - return new ClauseBuilder().setName(new ClauseName(clauseName.toString())) - .setSubjectRefs(ImmutableList.of(subjectName)) - .setConsumerMatchers(consumerMatchers) - .setProviderMatchers(providerMatchers) - .build(); - } + ConsumerMatchers consumerMatchers = null; + ProviderMatchers providerMatchers = null; + StringBuilder clauseName = new StringBuilder(); + clauseName.append(subjectName.getValue()); + if (ipPrefix != null) { + clauseName.append(MappingUtils.NAME_DOUBLE_DELIMETER).append(Utils.getStringIpPrefix(ipPrefix)); + consumerMatchers = + new ConsumerMatchersBuilder().setEndpointIdentificationConstraints( + new EndpointIdentificationConstraintsBuilder().setL3EndpointIdentificationConstraints( + new L3EndpointIdentificationConstraintsBuilder().setPrefixConstraint( + ImmutableList.of(new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build())).build()) + .build()).build(); + providerMatchers = + new ProviderMatchersBuilder().setEndpointIdentificationConstraints( + new EndpointIdentificationConstraintsBuilder().setL3EndpointIdentificationConstraints( + new L3EndpointIdentificationConstraintsBuilder().setPrefixConstraint( + ImmutableList.of(new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build())).build()) + .build()).build(); + } + return new ClauseBuilder().setName(new ClauseName(clauseName.toString())) + .setSubjectRefs(ImmutableList.of(subjectName)) + .setConsumerMatchers(consumerMatchers) + .setProviderMatchers(providerMatchers) + .build(); + } protected static Rule createRuleAllow(ClassifierName classifierName, Direction direction) { - ClassifierName name = - new ClassifierName(direction.name() + MappingUtils.NAME_DOUBLE_DELIMETER + classifierName.getValue()); - ClassifierRef classifierRef = new ClassifierRefBuilder().setName(name) - .setInstanceName(classifierName) - .setDirection(direction) - .build(); - return new RuleBuilder().setName(new RuleName(name)) - .setActionRef(ImmutableList.of(MappingUtils.ACTION_REF_ALLOW)) - .setClassifierRef(ImmutableList.of(classifierRef)) - .build(); - } + ClassifierName name = + new ClassifierName(direction.name() + MappingUtils.NAME_DOUBLE_DELIMETER + classifierName.getValue()); + ClassifierRef classifierRef = + new ClassifierRefBuilder().setName(name).setInstanceName(classifierName).setDirection(direction).build(); + return new RuleBuilder().setName(new RuleName(name)) + .setActionRef(ImmutableList.of(MappingUtils.ACTION_REF_ALLOW)) + .setClassifierRef(ImmutableList.of(classifierRef)) + .build(); + } protected static ProviderNamedSelector createProviderSelector(Contract contract) { - SelectorName selectorName = new SelectorName(contract.getSubject().get(0).getName().getValue()); - return new ProviderNamedSelectorBuilder().setName(selectorName) - .setContract(ImmutableList.of(contract.getId())) - .build(); - } + SelectorName selectorName = new SelectorName(contract.getSubject().get(0).getName().getValue()); + return new ProviderNamedSelectorBuilder().setName(selectorName) + .setContract(ImmutableList.of(contract.getId())) + .build(); + } protected static ConsumerNamedSelector createConsumerSelector(Contract contract) { - SelectorName selectorName = new SelectorName(contract.getSubject().get(0).getName().getValue()); - return new ConsumerNamedSelectorBuilder().setName(selectorName) - .setContract(ImmutableList.of(contract.getId())) - .build(); - } + SelectorName selectorName = new SelectorName(contract.getSubject().get(0).getName().getValue()); + return new ConsumerNamedSelectorBuilder().setName(selectorName) + .setContract(ImmutableList.of(contract.getId())) + .build(); + } } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronAware.java index 9bc876f9d..605fd0a7b 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronAware.java @@ -14,7 +14,8 @@ import org.opendaylight.yangtools.yang.binding.DataObject; public interface NeutronAware { void onCreated(T createdItem, Neutron neutron); + void onUpdated(T oldItem, T newItem, Neutron oldNeutron, Neutron newNeutron); - void onDeleted(T deletedItem, Neutron oldNeutron, Neutron newNeutron); + void onDeleted(T deletedItem, Neutron oldNeutron, Neutron newNeutron); } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronFloatingIpAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronFloatingIpAware.java index 2c7b97af2..6b6ff535a 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronFloatingIpAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronFloatingIpAware.java @@ -10,6 +10,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Objects; + import java.util.concurrent.ExecutionException; import org.opendaylight.controller.md.sal.binding.api.DataBroker; @@ -19,10 +21,7 @@ import org.opendaylight.groupbasedpolicy.neutron.mapper.util.Utils; import org.opendaylight.groupbasedpolicy.util.DataStoreHelper; import org.opendaylight.groupbasedpolicy.util.IidFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.IpPrefixType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.L3Context; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floatingips.attributes.Floatingips; @@ -33,8 +32,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Objects; - public class NeutronFloatingIpAware implements NeutronAware { private static final Logger LOG = LoggerFactory.getLogger(NeutronFloatingIpAware.class); diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java index 00342dcb2..f5bba0e22 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java @@ -9,6 +9,9 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Optional; +import com.google.common.base.Strings; + import java.util.HashSet; import java.util.Set; @@ -48,9 +51,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.base.Strings; - public class NeutronNetworkAware implements NeutronAware { private static final Logger LOG = LoggerFactory.getLogger(NeutronNetworkAware.class); @@ -68,18 +68,16 @@ public class NeutronNetworkAware implements NeutronAware { @Override public void onCreated(Network network, Neutron neutron) { LOG.trace("created network - {}", network); - ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); - TenantId tenantId = new TenantId(network.getTenantId().getValue()); Name name; ContextId ctxId = new ContextId(network.getUuid().getValue()); ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder() - .setContextId(ctxId) - .setContextType(MappingUtils.L3_CONTEXT); + .setContextId(ctxId) + .setContextType(MappingUtils.L3_CONTEXT); if (!Strings.isNullOrEmpty(network.getName())) { try { name = new Name(network.getName()); fwdCtxBuilder.setName(name); - } catch (Exception e) { + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name of Neutron Network '{}' is ignored.", network.getName()); LOG.debug("Name exception", e); } @@ -88,14 +86,15 @@ public class NeutronNetworkAware implements NeutronAware { ForwardingContext l3Context = fwdCtxBuilder.build(); fwdCtxBuilder.setContextType(MappingUtils.L2_BRDIGE_DOMAIN) - - .setParent(MappingUtils.createParent(ctxId, MappingUtils.L3_CONTEXT)); + .setParent(MappingUtils.createParent(ctxId, MappingUtils.L3_CONTEXT)); ForwardingContext l2Bd = fwdCtxBuilder.build(); - fwdCtxBuilder.setContextType(MappingUtils.L2_FLOOD_DOMAIN).setParent( - MappingUtils.createParent(ctxId, MappingUtils.L2_BRDIGE_DOMAIN)); + fwdCtxBuilder.setContextType(MappingUtils.L2_FLOOD_DOMAIN) + .setParent(MappingUtils.createParent(ctxId, MappingUtils.L2_BRDIGE_DOMAIN)); ForwardingContext l2Fd = fwdCtxBuilder.build(); + ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); + TenantId tenantId = new TenantId(network.getTenantId().getValue()); rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l3ContextIid(tenantId, ctxId), l3Context, true); rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, ctxId), l2Bd, true); rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2FloodDomainIid(tenantId, ctxId), l2Fd, true); @@ -140,8 +139,7 @@ public class NeutronNetworkAware implements NeutronAware { l3CtxBuilder.setName(name); l2FdBuilder.setName(name); l2BdBuilder.setName(name); - } catch (Exception e) { - name = null; + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name of Neutron Network '{}' is ignored.", network.getName()); LOG.debug("Name exception", e); } @@ -149,7 +147,8 @@ public class NeutronNetworkAware implements NeutronAware { L2FloodDomainId l2FdId = new L2FloodDomainId(network.getUuid().getValue()); L3ContextId l3ContextId = new L3ContextId(l2FdId); L3Context l3Context = l3CtxBuilder.setId(l3ContextId).build(); - rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3Context.getId()), l3Context, true); + rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3Context.getId()), l3Context, + true); L2BridgeDomainId l2BdId = new L2BridgeDomainId(l2FdId); L2BridgeDomain l2Bd = l2BdBuilder.setId(l2BdId).setParent(l3Context.getId()).build(); @@ -160,25 +159,27 @@ public class NeutronNetworkAware implements NeutronAware { } private void addProviderPhysicalNetworkMapping(TenantId tenantId, ContextId ctxId, String segmentationId, - WriteTransaction wTx) { - ProviderPhysicalNetworkAsL2FloodDomain provNetAsL2Fd = new ProviderPhysicalNetworkAsL2FloodDomainBuilder().setTenantId( - tenantId) + WriteTransaction writeTx) { + ProviderPhysicalNetworkAsL2FloodDomain provNetAsL2Fd = + new ProviderPhysicalNetworkAsL2FloodDomainBuilder().setTenantId(tenantId) .setL2FloodDomainId(ctxId) .setSegmentationId(segmentationId) .build(); - wTx.put(LogicalDatastoreType.OPERATIONAL, + writeTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.providerPhysicalNetworkAsL2FloodDomainIid(tenantId, ctxId), provNetAsL2Fd); } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void addProviderPhysicalNetworkMapping(TenantId tenantId, L2FloodDomainId l2FdId, String segmentationId, - WriteTransaction wTx) { + WriteTransaction writeTx) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.provider.physical.networks.as.l2.flood.domains.ProviderPhysicalNetworkAsL2FloodDomain provNetAsL2Fd = new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.provider.physical.networks.as.l2.flood.domains.ProviderPhysicalNetworkAsL2FloodDomainBuilder().setTenantId( tenantId) .setL2FloodDomainId(new L2FloodDomainId(l2FdId.getValue())) .setSegmentationId(segmentationId) .build(); - wTx.put(LogicalDatastoreType.OPERATIONAL, + writeTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.providerPhysicalNetworkAsL2FloodDomainIid(tenantId, l2FdId), provNetAsL2Fd); } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java index 951d59385..6eed62dbb 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java @@ -9,11 +9,14 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -94,10 +97,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - public class NeutronPortAware implements NeutronAware { private static final Logger LOG = LoggerFactory.getLogger(NeutronPortAware.class); @@ -119,6 +118,8 @@ public class NeutronPortAware implements NeutronAware { onCreated(createdItem, neutron, true); } + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void onCreated(Port port, Neutron neutron, boolean addBaseEpMapping) { LOG.trace("created port - {}", port); if (PortUtils.isRouterInterfacePort(port)) { @@ -129,12 +130,12 @@ public class NeutronPortAware implements NeutronAware { LOG.warn("Illegal state - router interface port does not contain fixed IPs {}", port); return; } - FixedIps portIpWithSubnet = potentialPortIpWithSubnet.get(); - ContextId routerL3Context = new ContextId(port.getDeviceId()); - ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); + final FixedIps portIpWithSubnet = potentialPortIpWithSubnet.get(); + final ContextId routerL3Context = new ContextId(port.getDeviceId()); AddressEndpointKey addrEpKey = new AddressEndpointKey(port.getMacAddress().getValue(), MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN); UniqueId portId = new UniqueId(port.getUuid().getValue()); + ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); addBaseEndpointMappings(addrEpKey, portId, rwTx); // Add Qrouter and VPProuter port as Endpoint if (port.getAugmentation(PortBindingExtension.class) != null && PortUtils.DEVICE_VIF_TYPE @@ -299,6 +300,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void processTenantForwarding(Subnet routerPortSubnet, ContextId routerL3Context, FixedIps portIpWithSubnet, TenantId tenantId, ReadWriteTransaction rwTx) { L2BridgeDomainId l2BdId = new L2BridgeDomainId(routerPortSubnet.getNetworkId().getValue()); @@ -317,6 +320,8 @@ public class NeutronPortAware implements NeutronAware { * Creates registration input for L3 endpoint if fixedIps argument is not null. */ @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder createEndpointRegFromPort( Port port, FixedIps fixedIps, NetworkDomainId networkContainment, List endpointGroupIds, Neutron neutron) { @@ -426,6 +431,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void modifyL3ContextForEndpoints(Port port, FixedIps resolvedPortFixedIp, ContextId newContextId) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder epInBuilder = createBasicEndpointInputBuilder(port); @@ -511,6 +518,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder createBasicEndpointInputBuilder( Port port) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder() @@ -532,6 +541,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void registerEndpointAndStoreMapping( org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput regEpInput, Port port, ReadWriteTransaction rwTx) { @@ -555,6 +566,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void unregisterEndpointAndRemoveMapping( org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregEpInput, Port port, ReadWriteTransaction rwTx) { @@ -572,8 +585,23 @@ public class NeutronPortAware implements NeutronAware { } } + private void unregisterEndpointAndRemoveMapping(UnregisterEndpointInput baseEpUnreg, Port port, + ReadWriteTransaction rwTx, boolean removeBaseEpMappings) { + boolean isUnregisteredBaseEndpoint = epRegistrator.unregisterEndpoint(baseEpUnreg); + if (isUnregisteredBaseEndpoint) { + UniqueId portId = new UniqueId(port.getUuid().getValue()); + PortByBaseEndpointKey portByBaseEndpointKey = new PortByBaseEndpointKey(port.getMacAddress().getValue(), + MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN); + LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", + port.getUuid().getValue(), port.getDeviceOwner(), portByBaseEndpointKey); + if (removeBaseEpMappings) { + removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx); + } + } + } + private void registerBaseEndpointAndStoreMapping(List addrEpRegs, Port port, - WriteTransaction wTx, boolean addBaseEpMappings) { + WriteTransaction writeTx, boolean addBaseEpMappings) { RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder().setAddressEndpointReg(addrEpRegs).build(); @@ -589,36 +617,21 @@ public class NeutronPortAware implements NeutronAware { port.getUuid()); AddressEndpointKey addrEpKey = new AddressEndpointKey(addrEpReg.getAddress(), addrEpReg.getAddressType(), addrEpReg.getContextId(), addrEpReg.getContextType()); - addBaseEndpointMappings(addrEpKey, portId, wTx); + addBaseEndpointMappings(addrEpKey, portId, writeTx); } } } - private void addBaseEndpointMappings(AddressEndpointKey addrEpKey, UniqueId portId, WriteTransaction wTx) { + private void addBaseEndpointMappings(AddressEndpointKey addrEpKey, UniqueId portId, WriteTransaction writeTx) { BaseEndpointByPort baseEndpointByPort = MappingFactory.createBaseEndpointByPort(addrEpKey, portId); - wTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.baseEndpointByPortIid(portId), + writeTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.baseEndpointByPortIid(portId), baseEndpointByPort, true); PortByBaseEndpoint portByBaseEndpoint = MappingFactory.createPortByBaseEndpoint(portId, addrEpKey); - wTx.put(LogicalDatastoreType.OPERATIONAL, + writeTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.portByBaseEndpointIid(new PortByBaseEndpointKey(portByBaseEndpoint.getKey())), portByBaseEndpoint, true); } - private void unregisterEndpointAndRemoveMapping(UnregisterEndpointInput baseEpUnreg, Port port, - ReadWriteTransaction rwTx, boolean removeBaseEpMappings) { - boolean isUnregisteredBaseEndpoint = epRegistrator.unregisterEndpoint(baseEpUnreg); - if (isUnregisteredBaseEndpoint) { - UniqueId portId = new UniqueId(port.getUuid().getValue()); - PortByBaseEndpointKey portByBaseEndpointKey = new PortByBaseEndpointKey(port.getMacAddress().getValue(), - MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN); - LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", - port.getUuid().getValue(), port.getDeviceOwner(), portByBaseEndpointKey); - if (removeBaseEpMappings) { - removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx); - } - } - } - private void removeBaseEndpointMappings(PortByBaseEndpointKey portByBaseEndpointKey, UniqueId portId, ReadWriteTransaction rwTx) { DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, @@ -722,6 +735,8 @@ public class NeutronPortAware implements NeutronAware { } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void modifyForwardingOnDelete(Subnet routerPortSubnet, L3ContextId l3contextId, TenantId tenantId, ReadWriteTransaction rwTx) { L2BridgeDomainId l2BdId = new L2BridgeDomainId(routerPortSubnet.getNetworkId().getValue()); @@ -734,9 +749,10 @@ public class NeutronPortAware implements NeutronAware { tenantSubnet); } + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput createUnregisterBaseEndpointInput( Port port, Neutron neutron) { - UnregisterEndpointInputBuilder inputBuilder = new UnregisterEndpointInputBuilder(); List list = new ArrayList<>(); AddressEndpointUnregBuilder addrL2EpUnregBuilder = new AddressEndpointUnregBuilder(); addrL2EpUnregBuilder.setAddress(port.getMacAddress().getValue()) @@ -755,11 +771,14 @@ public class NeutronPortAware implements NeutronAware { .setContextType(L3Context.class); list.add(addrL3EpUnregBuilder.build()); } + UnregisterEndpointInputBuilder inputBuilder = new UnregisterEndpointInputBuilder(); inputBuilder.setAddressEndpointUnreg(list); return inputBuilder.build(); } @Deprecated + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput createUnregisterEndpointInput( Port port, Neutron neutron) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder inputBuilder = diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAware.java index b06a408f8..fc1fb2342 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAware.java @@ -108,7 +108,7 @@ public class NeutronRouterAware implements NeutronAware { try { routerName = new Name(router.getName()); fwdCtxBuilder.setName(routerName); - } catch (Exception e) { + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", router.getName(), router.getUuid().getValue()); LOG.debug("Name exception", e); @@ -117,23 +117,27 @@ public class NeutronRouterAware implements NeutronAware { ForwardingContext routerl3Context = fwdCtxBuilder.setContextId(routerl3ContextId) .setContextType(MappingUtils.L3_CONTEXT) .build(); - WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); - wTx.put(LogicalDatastoreType.CONFIGURATION, routerL3CtxIid, routerl3Context, true); - createTenantL3Context(new L3ContextId(routerl3ContextId), tenantId, routerName, wTx); - DataStoreHelper.submitToDs(wTx); + WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); + writeTx.put(LogicalDatastoreType.CONFIGURATION, routerL3CtxIid, routerl3Context, true); + createTenantL3Context(new L3ContextId(routerl3ContextId), tenantId, routerName, writeTx); + DataStoreHelper.submitToDs(writeTx); } @Deprecated - private void createTenantL3Context(L3ContextId l3ContextId, TenantId tenantId, Name name, WriteTransaction wTx) { + private void createTenantL3Context(L3ContextId l3ContextId, TenantId tenantId, Name name, + WriteTransaction writeTx) { L3ContextBuilder l3ContextBuilder = new L3ContextBuilder(); if (name != null) { l3ContextBuilder.setName(name); } L3Context l3Context = l3ContextBuilder.setId(l3ContextId).build(); - wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3ContextId), l3Context, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3ContextId), l3Context, + true); } @Override + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void onUpdated(Router oldRouter, Router newRouter, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("updated router - OLD: {}\nNEW: {}", oldRouter, newRouter); @@ -204,7 +208,7 @@ public class NeutronRouterAware implements NeutronAware { L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx); if (!optBd.isPresent()) { LOG.warn( - "Could not read L2-Bridge-Domain {}. Modification of its parent to L3-Context of router {} aborted.", + "Could not read L2BridgeDomain {}. Modification of its parent to L3Context of router {} aborted.", l2BdId, newRouter.getUuid()); rwTx.cancel(); return; @@ -249,101 +253,114 @@ public class NeutronRouterAware implements NeutronAware { return epRegistrator.unregisterEndpoint(addrEpBuilder.build()); } -private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, NetworkDomainId subnetId, List gateways) { - Subnet subnet = new SubnetBuilder() - .setVirtualRouterIp(MappingUtils.ipPrefixToIpAddress(gatewayIp.getValue())) - .setGateways(gateways) - .build(); + private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, NetworkDomainId subnetId, + List gateways) { + + Subnet subnet = + new SubnetBuilder().setVirtualRouterIp(MappingUtils.ipPrefixToIpAddress(gatewayIp.getValue())) + .setGateways(gateways) + .build(); return new NetworkDomainBuilder().setKey(new NetworkDomainKey(subnetId, MappingUtils.SUBNET)) .addAugmentation(SubnetAugmentForwarding.class, - new SubnetAugmentForwardingBuilder().setSubnet(subnet).build()) + new SubnetAugmentForwardingBuilder().setSubnet(subnet).build()) .build(); } @Deprecated - private void updateTenantForwarding(Neutron newNeutron, Router oldRouter, Router newRouter, L3ContextId l3ContextId, TenantId tenantId, ReadWriteTransaction rwTx) { - InstanceIdentifier l3ContextIid = - IidFactory.l3ContextIid(tenantId, l3ContextId); - Optional optL3Context = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rwTx); - L3Context l3Context; + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. + private void updateTenantForwarding(Neutron newNeutron, Router oldRouter, Router newRouter, L3ContextId l3ContextId, + TenantId tenantId, ReadWriteTransaction rwTx) { + + InstanceIdentifier l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId); + Optional optL3Context = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, + rwTx); + L3Context l3Context; if (!optL3Context.isPresent()) { // add L3 context if missing l3Context = createL3CtxFromRouter(newRouter); rwTx.put(LogicalDatastoreType.CONFIGURATION, l3ContextIid, l3Context, true); } if (newRouter.getGatewayPortId() != null && oldRouter.getGatewayPortId() == null) { - // external network is attached to router - Uuid gatewayPortId = newRouter.getGatewayPortId(); - Optional potentialGwPort = PortUtils.findPort(gatewayPortId, newNeutron.getPorts()); - if (!potentialGwPort.isPresent()) { - LOG.warn("Illegal state - router gateway port {} does not exist for router {}.", - gatewayPortId.getValue(), newRouter); - rwTx.cancel(); - return; - } - - Port gwPort = potentialGwPort.get(); - List fixedIpsFromGwPort = gwPort.getFixedIps(); - if (fixedIpsFromGwPort == null || fixedIpsFromGwPort.isEmpty()) { - LOG.warn("Illegal state - router gateway port {} does not contain fixed IPs {}", - gatewayPortId.getValue(), gwPort); - rwTx.cancel(); - return; - } - - // router can have only one external network - FixedIps ipWithSubnetFromGwPort = fixedIpsFromGwPort.get(0); - Optional potentialSubnet = SubnetUtils.findSubnet(ipWithSubnetFromGwPort.getSubnetId(), newNeutron.getSubnets()); - if (!potentialSubnet.isPresent()) { - LOG.warn("Illegal state - Subnet {} does not exist for router {}.", - ipWithSubnetFromGwPort.getSubnetId(), newRouter); - rwTx.cancel(); - return; - } - IpAddress gatewayIp = potentialSubnet.get().getGatewayIp(); - NetworkDomainId networkContainment = new NetworkDomainId(ipWithSubnetFromGwPort.getSubnetId().getValue()); - boolean registeredExternalGateway = epRegistrator.registerL3EpAsExternalGateway(tenantId, gatewayIp, - l3ContextId, networkContainment); - if (!registeredExternalGateway) { - LOG.warn("Could not add L3Prefix as gateway of default route. Gateway port {}", gwPort); - rwTx.cancel(); - return; - } - EndpointL3Key epL3Key = new EndpointL3Key(gatewayIp, l3ContextId); - addNeutronExtGwMapping(epL3Key, rwTx); - - boolean registeredDefaultRoute = epRegistrator.registerExternalL3PrefixEndpoint(MappingUtils.DEFAULT_ROUTE, - l3ContextId, gatewayIp, tenantId); - if (!registeredDefaultRoute) { - LOG.warn("Could not add EndpointL3Prefix as default route. Gateway port {}", gwPort); - rwTx.cancel(); - return; - } - org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet subnetWithGw = - new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder().setId(new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue())) - .setVirtualRouterIp(gatewayIp) - .build(); - rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetWithGw.getId()), - subnetWithGw); - L2BridgeDomainId l2BdId = new L2BridgeDomainId(potentialSubnet.get().getNetworkId().getValue()); - Optional optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, - IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx); - if (!optBd.isPresent()) { - LOG.warn( - "Could not read L2-Bridge-Domain {}. Modification of its parent to L3-Context of router {} aborted.", - l2BdId, newRouter.getUuid()); - rwTx.cancel(); - return; - } - L2BridgeDomain l2BdWithGw = new L2BridgeDomainBuilder(optBd.get()) - .setParent(new L3ContextId(l3ContextId.getValue())) - .build(); - rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), - l2BdWithGw); - } + // external network is attached to router + Uuid gatewayPortId = newRouter.getGatewayPortId(); + Optional potentialGwPort = PortUtils.findPort(gatewayPortId, newNeutron.getPorts()); + if (!potentialGwPort.isPresent()) { + LOG.warn("Illegal state - router gateway port {} does not exist for router {}.", + gatewayPortId.getValue(), newRouter); + rwTx.cancel(); + return; + } + + Port gwPort = potentialGwPort.get(); + List fixedIpsFromGwPort = gwPort.getFixedIps(); + if (fixedIpsFromGwPort == null || fixedIpsFromGwPort.isEmpty()) { + LOG.warn("Illegal state - router gateway port {} does not contain fixed IPs {}", + gatewayPortId.getValue(), gwPort); + rwTx.cancel(); + return; + } + + // router can have only one external network + FixedIps ipWithSubnetFromGwPort = fixedIpsFromGwPort.get(0); + Optional + potentialSubnet = SubnetUtils.findSubnet(ipWithSubnetFromGwPort.getSubnetId(), newNeutron.getSubnets()); + if (!potentialSubnet.isPresent()) { + LOG.warn("Illegal state - Subnet {} does not exist for router {}.", + ipWithSubnetFromGwPort.getSubnetId(), newRouter); + rwTx.cancel(); + return; + } + IpAddress gatewayIp = potentialSubnet.get().getGatewayIp(); + NetworkDomainId networkContainment = new NetworkDomainId(ipWithSubnetFromGwPort.getSubnetId().getValue()); + boolean registeredExternalGateway = + epRegistrator.registerL3EpAsExternalGateway(tenantId, gatewayIp, l3ContextId, networkContainment); + if (!registeredExternalGateway) { + LOG.warn("Could not add L3Prefix as gateway of default route. Gateway port {}", gwPort); + rwTx.cancel(); + return; + } + EndpointL3Key epL3Key = new EndpointL3Key(gatewayIp, l3ContextId); + addNeutronExtGwMapping(epL3Key, rwTx); + + boolean registeredDefaultRoute = epRegistrator.registerExternalL3PrefixEndpoint(MappingUtils.DEFAULT_ROUTE, + l3ContextId, gatewayIp, tenantId); + if (!registeredDefaultRoute) { + LOG.warn("Could not add EndpointL3Prefix as default route. Gateway port {}", gwPort); + rwTx.cancel(); + return; + } + org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet + subnetWithGw = + new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder() + .setId(new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue())) + .setVirtualRouterIp(gatewayIp) + .build(); + rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetWithGw.getId()), + subnetWithGw); + L2BridgeDomainId l2BdId = new L2BridgeDomainId(potentialSubnet.get().getNetworkId().getValue()); + Optional optBd = + DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, + l2BdId), rwTx); + if (!optBd.isPresent()) { + LOG.warn( + "Could not read L2BridgeDomain {}. Modification of its parent to L3Context of router {} aborted.", + l2BdId, newRouter.getUuid()); + rwTx.cancel(); + return; + } + L2BridgeDomain + l2BdWithGw = + new L2BridgeDomainBuilder(optBd.get()).setParent(new L3ContextId(l3ContextId.getValue())).build(); + rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2BdWithGw); + } } - private void deleteTenantForwarding(Neutron newNeutron, Router oldRouter, L3ContextId l3ContextId, TenantId tenantId, ReadWriteTransaction rwTx) { + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. + private void deleteTenantForwarding(Neutron newNeutron, Router oldRouter, L3ContextId l3ContextId, + TenantId tenantId, ReadWriteTransaction rwTx) { + InstanceIdentifier l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId); LOG.trace("Deleting router from TenantForwarding {}", l3ContextIid); @@ -408,9 +425,9 @@ private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, Networ IidFactory.subnetIid(tenantId, new SubnetId(ipWithSubnetFromGwPort.getSubnetId().getValue())), subnet); L2BridgeDomainId l2BdId = new L2BridgeDomainId(potentialSubnet.get().getNetworkId().getValue()); - L3ContextId l3Context = new L3ContextId( potentialSubnet.get().getNetworkId().getValue()); + L3ContextId l3Context = new L3ContextId(potentialSubnet.get().getNetworkId().getValue()); Optional optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, - IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx); + IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx); if (optBd.isPresent()) { L2BridgeDomain l2BdWithGw = new L2BridgeDomainBuilder(optBd.get()).setParent(l3Context).build(); LOG.trace("Setting parent for L2BridgeDomain {} back to network {}.", l2BdWithGw, l3Context); @@ -447,8 +464,8 @@ private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, Networ private static void addNeutronExtGwGbpMapping(ContextId contextId, IpPrefix ipPrefix, ReadWriteTransaction rwTx) { ExternalGatewayAsEndpoint externalGatewayL3Endpoint = MappingFactory.createEaxternalGatewayAsEndpoint( contextId, ipPrefix); - rwTx.put(LogicalDatastoreType.OPERATIONAL, - NeutronGbpIidFactory.externalGatewayAsEndpoint(contextId, ipPrefix, MappingUtils.L3_CONTEXT), externalGatewayL3Endpoint, true); + rwTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.externalGatewayAsEndpoint(contextId, + ipPrefix, MappingUtils.L3_CONTEXT), externalGatewayL3Endpoint, true); } @Deprecated @@ -481,6 +498,8 @@ private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, Networ DataStoreHelper.submitToDs(rwTx); } + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. private void deleteExtGw(Router router, TenantId tenantId, Neutron newNeutron, ReadWriteTransaction rwTx) { ContextId routerL3CtxId = new ContextId(router.getUuid().getValue()); if (router.getGatewayPortId() != null) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAware.java index 90ecae618..3ec4c43b2 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAware.java @@ -9,6 +9,9 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Optional; +import com.google.common.base.Strings; + import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -31,9 +34,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.base.Strings; - public class NeutronSecurityGroupAware implements NeutronAware { private static final Logger LOG = LoggerFactory.getLogger(NeutronSecurityGroupAware.class); @@ -66,24 +66,25 @@ public class NeutronSecurityGroupAware implements NeutronAware { // TODO This needs to be reworked, SecGroups shouldn't use TenantId, Neutron doesn't always configure it return true; } - TenantId tId = new TenantId(secGroup.getTenantId().getValue()); + TenantId tenantId = new TenantId(secGroup.getTenantId().getValue()); EndpointGroupId epgId = new EndpointGroupId(secGroup.getUuid().getValue()); if (epgId.getValue().equals(MappingUtils.EIG_UUID.getValue())) { ExternalImplicitGroup eig = new ExternalImplicitGroupBuilder().setId(epgId).build(); - rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.externalImplicitGroupIid(tId, epgId), eig, true); + rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.externalImplicitGroupIid(tenantId, epgId), eig, + true); } EndpointGroupBuilder epgBuilder = new EndpointGroupBuilder().setId(epgId); if (!Strings.isNullOrEmpty(secGroup.getName())) { try { epgBuilder.setName(new Name(secGroup.getName())); - } catch (Exception e) { + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name '{}' of Neutron Security-group '{}' is ignored.", secGroup.getName(), secGroup.getUuid().getValue()); LOG.debug("Name exception", e); } } epgBuilder.setIntraGroupPolicy(IntraGroupPolicy.RequireContract); - rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tId, epgId), + rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, epgId), epgBuilder.build(), true); return true; } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAware.java index db22e962f..0c2c7a85e 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAware.java @@ -9,6 +9,9 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Optional; +import com.google.common.base.Strings; + import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -51,13 +54,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.base.Strings; - +@SuppressWarnings("checkstyle:LineLength") // Longer lines in this class are caused by long package names, + // this will be removed when deprecated classes will be cleared. public class NeutronSubnetAware implements NeutronAware { - private final static Logger LOG = LoggerFactory.getLogger(NeutronSubnetAware.class); + private static final Logger LOG = LoggerFactory.getLogger(NeutronSubnetAware.class); public static final InstanceIdentifier SUBNET_WILDCARD_IID = InstanceIdentifier.builder(Neutron.class) .child(Subnets.class) @@ -148,7 +150,8 @@ public class NeutronSubnetAware implements .stream() .filter(net -> net.getUuid().equals(port.getNetworkId())) .filter(net -> net.getAugmentation(NetworkProviderExtension.class) != null) - .anyMatch(net -> net.getAugmentation(NetworkProviderExtension.class).getPhysicalNetwork() != null)) { + .anyMatch( + net -> net.getAugmentation(NetworkProviderExtension.class).getPhysicalNetwork() != null)) { // add virtual router IP only in case it is provider physical network sb.setVirtualRouterIp(subnet.getGatewayIp()); } @@ -184,14 +187,15 @@ public class NeutronSubnetAware implements if (!Strings.isNullOrEmpty(subnet.getName())) { try { ndb.setName(new Name(subnet.getName())); - } catch (Exception e) { + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", subnet.getName(), subnet.getUuid().getValue()); LOG.debug("Name exception", e); } } ndb.setNetworkDomainId(new NetworkDomainId(subnet.getUuid().getValue())); ndb.setNetworkDomainType(MappingUtils.SUBNET); - ndb.setParent(MappingUtils.createParent(new NetworkDomainId(subnet.getNetworkId().getValue()), L2FloodDomain.class)); + ndb.setParent( + MappingUtils.createParent(new NetworkDomainId(subnet.getNetworkId().getValue()), L2FloodDomain.class)); ndb.addAugmentation(SubnetAugmentForwarding.class, new SubnetAugmentForwardingBuilder().setSubnet(sb.build()) .build()); return ndb.build(); @@ -230,7 +234,7 @@ public class NeutronSubnetAware implements if (!Strings.isNullOrEmpty(subnet.getName())) { try { subnetBuilder.setName(new Name(subnet.getName())); - } catch (Exception e) { + } catch (NullPointerException | IllegalArgumentException e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", subnet.getName(), subnet.getUuid().getValue()); LOG.debug("Name exception", e); @@ -258,8 +262,8 @@ public class NeutronSubnetAware implements ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); NetworkDomainId subnetId = new NetworkDomainId(neutronSubnet.getUuid().getValue()); TenantId tenantId = new TenantId(neutronSubnet.getTenantId().getValue()); - Optional potentialSubnetDomain = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, - L2L3IidFactory.subnetIid(tenantId, subnetId), rwTx); + Optional potentialSubnetDomain = DataStoreHelper.removeIfExists( + LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetId), rwTx); if (!potentialSubnetDomain.isPresent()) { LOG.warn("Illegal state - subnet network domain {} does not exist.", subnetId.getValue()); rwTx.cancel(); diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronGbpMapperServiceImpl.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronGbpMapperServiceImpl.java deleted file mode 100644 index 480831d82..000000000 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronGbpMapperServiceImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. 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.neutron.mapper.mapping.rule; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.groupbasedpolicy.neutron.mapper.util.SecurityRuleUtils; -import org.opendaylight.groupbasedpolicy.util.DataStoreHelper; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.ChangeActionOfSecurityGroupRulesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.NeutronGbpMapperService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.SecurityGroupRule; -import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron; -import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.Futures; - -public class NeutronGbpMapperServiceImpl implements NeutronGbpMapperService { - - private static final Logger LOG = LoggerFactory.getLogger(NeutronGbpMapperServiceImpl.class); - private NeutronSecurityRuleAware secRuleAware; - private DataBroker dataProvider; - - public NeutronGbpMapperServiceImpl(DataBroker dataProvider, NeutronSecurityRuleAware secRuleAware) { - this.dataProvider = checkNotNull(dataProvider); - this.secRuleAware = checkNotNull(secRuleAware); - } - - @Override - public Future> changeActionOfSecurityGroupRules(ChangeActionOfSecurityGroupRulesInput input) { - List securityGroupRules = input.getSecurityGroupRule(); - if (securityGroupRules == null || input.getAction() == null) { - LOG.debug("Missing params in request:\n{}", input); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withError(ErrorType.PROTOCOL, "Missing params. Changing to action " - + input.getAction().getActionChoice() + " was not successful.") - .build()); - } - - ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); - Optional potentialNeutron; - try { - potentialNeutron = rwTx.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).build()).get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("Exception during neutron reading.", e); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withError(ErrorType.PROTOCOL, "Cannot read from CONF DS.") - .build()); - } - if (!potentialNeutron.isPresent()) { - return Futures.immediateFuture(RpcResultBuilder.failed() - .withError(ErrorType.PROTOCOL, "No neutron data in CONF DS.") - .build()); - } - Neutron neutron = potentialNeutron.get(); - for (SecurityGroupRule secGrpRule : securityGroupRules) { - Uuid uuid = secGrpRule.getUuid(); - Optional potentialSecRule = SecurityRuleUtils.findSecurityRule(uuid, neutron.getSecurityRules()); - if (!potentialSecRule.isPresent()) { - LOG.warn("Security rule {} does not exist.", uuid); - continue; - } - LOG.trace("Changing action to {} in security group rule {}", input.getAction().getActionChoice(), uuid); - boolean isSuccessful = - secRuleAware.changeActionOfNeutronSecurityRule(potentialSecRule.get(), input.getAction().getActionChoice(), neutron, rwTx); - if (!isSuccessful) { - rwTx.cancel(); - LOG.warn("Changing action to {} in security group rule {} was not successful.", - input.getAction().getActionChoice(), uuid); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Changing to action " + input.getAction().getActionChoice() + " was not successful.") - .build()); - } - } - boolean isSubmittedToDs = DataStoreHelper.submitToDs(rwTx); - if (!isSubmittedToDs) { - LOG.warn("Changing action to {} in security group rules {} was not successful.", - input.getAction().getActionChoice(), input.getSecurityGroupRule()); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, "Storing to datastore was not successful. Changing to action " - + input.getAction().getActionChoice() + " was not successful.") - .build()); - } - return Futures.immediateFuture(RpcResultBuilder.success().build()); - } - -} diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAware.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAware.java index 4ada57606..57ccc47e4 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAware.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAware.java @@ -10,6 +10,14 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Multiset; +import com.google.common.collect.Sets; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -72,14 +80,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.HashMultiset; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Multiset; -import com.google.common.collect.Sets; - public class NeutronSecurityRuleAware implements NeutronAware { private static final Logger LOG = LoggerFactory.getLogger(NeutronSecurityRuleAware.class); @@ -91,8 +91,8 @@ public class NeutronSecurityRuleAware implements NeutronAware { private final Multiset> createdActionInstances; private final Map pendingCreatedRules; private final Map pendingDeletedGroups; - final static String PROVIDED_BY = "provided_by-"; - final static String POSSIBLE_CONSUMER = "possible_consumer-"; + private static final String PROVIDED_BY = "provided_by-"; + private static final String POSSIBLE_CONSUMER = "possible_consumer-"; private final EndpointRegistrator epRegistrator; public NeutronSecurityRuleAware(DataBroker dataProvider, EndpointRegistrator epRegistrator) { @@ -175,9 +175,11 @@ public class NeutronSecurityRuleAware implements NeutronAware { Description contractDescription = createContractDescription(secRule, neutron); SingleRuleContract singleRuleContract = createSingleRuleContract(secRule, contractDescription, action, neutron); Contract contract = singleRuleContract.getContract(); - rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, contract.getId()), contract, true); + rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, contract.getId()), contract, + true); SelectorName providerSelector = getSelectorNameWithConsumer(secRule, neutron); - writeProviderNamedSelectorToEpg(providerSelector, contract.getId(), new EpgKeyDto(providerEpgId, tenantId), rwTx); + writeProviderNamedSelectorToEpg(providerSelector, contract.getId(), new EpgKeyDto(providerEpgId, tenantId), + rwTx); if (secRule.getRemoteGroupId() != null) { Uuid consumerSecGroupId = secRule.getRemoteGroupId(); @@ -185,8 +187,10 @@ public class NeutronSecurityRuleAware implements NeutronAware { designContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, neutron, rwTx); } else { for (Uuid consumerSecGroupId : SecurityRuleUtils.findSecurityGroupsHavingSecurityRules(neutron)) { - designContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, neutron, rwTx); - designContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, neutron, rwTx); + designContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, neutron, + rwTx); + designContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, neutron, + rwTx); } } @@ -220,16 +224,16 @@ public class NeutronSecurityRuleAware implements NeutronAware { .filter(net -> NetworkUtils.isRouterExternal(net)) .findAny(); if (publicNet.isPresent()) { - WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); - wTx.merge(LogicalDatastoreType.CONFIGURATION, + WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); + writeTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.externalImplicitGroupIid(new TenantId(secRule.getTenantId().getValue()), MappingUtils.EPG_EXTERNAL_ID), new ExternalImplicitGroupBuilder().setId(MappingUtils.EPG_EXTERNAL_ID).build(), true); - wTx.merge(LogicalDatastoreType.CONFIGURATION, + writeTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(new TenantId(secRule.getTenantId().getValue()), MappingUtils.EPG_EXTERNAL_ID), new EndpointGroupBuilder().setId(MappingUtils.EPG_EXTERNAL_ID).build(), true); - DataStoreHelper.submitToDs(wTx); + DataStoreHelper.submitToDs(writeTx); AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder() .setAddress(String.valueOf(secRule.getRemoteIpPrefix().getValue())) .setAddressType(IpPrefixType.class) @@ -271,8 +275,9 @@ public class NeutronSecurityRuleAware implements NeutronAware { @VisibleForTesting Set getProvidedSecRulesBetween(Uuid provSecGroup, Uuid consSecGroup, Neutron neutron) { - return Sets.union(SecurityRuleUtils.findSecurityRulesBySecGroupAndRemoteSecGroup(provSecGroup, consSecGroup, neutron), - SecurityRuleUtils.findSecurityRulesBySecGroupAndRemoteSecGroup(provSecGroup, null, neutron)); + return Sets.union( + SecurityRuleUtils.findSecurityRulesBySecGroupAndRemoteSecGroup(provSecGroup, consSecGroup, neutron), + SecurityRuleUtils.findSecurityRulesBySecGroupAndRemoteSecGroup(provSecGroup, null, neutron)); } @VisibleForTesting @@ -289,7 +294,9 @@ public class NeutronSecurityRuleAware implements NeutronAware { return false; } - public boolean changeActionOfNeutronSecurityRule(SecurityRule secRule, ActionChoice action, Neutron neutron, ReadWriteTransaction rwTx) { + public boolean changeActionOfNeutronSecurityRule(SecurityRule secRule, ActionChoice action, Neutron neutron, + ReadWriteTransaction rwTx) { + addSfcChainActionInstance(action, new TenantId(secRule.getTenantId().getValue()), rwTx); LOG.trace("Changing to action {} for secuirity group rule {}", action, secRule); return addNeutronSecurityRuleWithAction(secRule, neutron, action, rwTx); @@ -313,32 +320,32 @@ public class NeutronSecurityRuleAware implements NeutronAware { } private void writeProviderNamedSelectorToEpg(SelectorName providerSelector, ContractId contractId, EpgKeyDto epgKey, - WriteTransaction wTx) { + WriteTransaction writeTx) { ProviderNamedSelector providerNamedSelector = new ProviderNamedSelectorBuilder().setName(providerSelector) .setContract(ImmutableList.of(contractId)) .build(); - wTx.put(LogicalDatastoreType.CONFIGURATION, + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.providerNamedSelectorIid(epgKey.getTenantId(), epgKey.getEpgId(), providerNamedSelector.getName()), providerNamedSelector, true); } private void writeConsumerNamedSelectorToEpg(SelectorName consumerSelector, ContractId contractId, EpgKeyDto epgKey, - WriteTransaction wTx) { + WriteTransaction writeTx) { ConsumerNamedSelector consumerNamedSelector = new ConsumerNamedSelectorBuilder().setName(consumerSelector) .setContract(ImmutableList.of(contractId)) .build(); - wTx.put(LogicalDatastoreType.CONFIGURATION, + writeTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.consumerNamedSelectorIid(epgKey.getTenantId(), epgKey.getEpgId(), consumerNamedSelector.getName()), consumerNamedSelector, true); } @VisibleForTesting void createClassifierInstanceIfNotExists(TenantId tenantId, ClassifierInstance classifierInstance, - WriteTransaction wTx) { + WriteTransaction writeTx) { InstanceIdentifier classifierInstanceIid = IidFactory.classifierInstanceIid(tenantId, classifierInstance.getName()); if (!createdClassifierInstances.contains(classifierInstanceIid)) { - wTx.put(LogicalDatastoreType.CONFIGURATION, classifierInstanceIid, classifierInstance, true); + writeTx.put(LogicalDatastoreType.CONFIGURATION, classifierInstanceIid, classifierInstance, true); } createdClassifierInstances.add(classifierInstanceIid); } @@ -408,12 +415,16 @@ public class NeutronSecurityRuleAware implements NeutronAware { if (secRule.getRemoteGroupId() != null) { Uuid consumerSecGroupId = secRule.getRemoteGroupId(); - undesignContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, secRule, neutron, rwTx); - undesignContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, secRule, neutron, rwTx); + undesignContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, secRule, + neutron, rwTx); + undesignContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, secRule, + neutron, rwTx); } else { for (Uuid consumerSecGroupId : SecurityRuleUtils.findSecurityGroupsHavingSecurityRules(neutron)) { - undesignContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, secRule, neutron, rwTx); - undesignContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, secRule, neutron, rwTx); + undesignContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, secRule, + neutron, rwTx); + undesignContractsBetweenProviderAndConsumer(tenantId, consumerSecGroupId, providerSecGroupId, secRule, + neutron, rwTx); } } @@ -432,7 +443,8 @@ public class NeutronSecurityRuleAware implements NeutronAware { Set consSecRules = getProvidedSecRulesBetween(consSecGroupId, provSecGroupId, neutron); EndpointGroupId consEpgId = new EndpointGroupId(consSecGroupId.getValue()); for (SecurityRule provSecRule : provSecRules) { - if (isProvidersSecRuleSuitableForConsumersSecRulesAndGoodToRemove(provSecRule, consSecRules, removedSecRule)) { + if (isProvidersSecRuleSuitableForConsumersSecRulesAndGoodToRemove(provSecRule, consSecRules, + removedSecRule)) { SelectorName consumerSelector = getSelectorNameWithProvider(provSecRule, neutron); deleteConsumerNamedSelector(consumerSelector, new EpgKeyDto(consEpgId, tenantId), rwTx); } @@ -552,17 +564,22 @@ public class NeutronSecurityRuleAware implements NeutronAware { @VisibleForTesting static boolean isOneWithinTwo(SecurityRule one, SecurityRule two) { - if (!isOneGroupIdWithinTwoRemoteGroupId(one, two) || !isOneGroupIdWithinTwoRemoteGroupId(two, one)) + if (!isOneGroupIdWithinTwoRemoteGroupId(one, two) || !isOneGroupIdWithinTwoRemoteGroupId(two, one)) { return false; - if (!SecRuleEntityDecoder.isEtherTypeOfOneWithinTwo(one, two)) + } + if (!SecRuleEntityDecoder.isEtherTypeOfOneWithinTwo(one, two)) { return false; - if (!SecRuleEntityDecoder.isProtocolOfOneWithinTwo(one, two)) + } + if (!SecRuleEntityDecoder.isProtocolOfOneWithinTwo(one, two)) { return false; - if (!SecRuleEntityDecoder.isPortsOfOneWithinTwo(one, two)) + } + if (!SecRuleEntityDecoder.isPortsOfOneWithinTwo(one, two)) { return false; + } if (two.getRemoteIpPrefix() != null - && one.getRemoteIpPrefix() == null) + && one.getRemoteIpPrefix() == null) { return false; + } return true; } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java index c5255bbfd..6fe1d1ebe 100755 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java @@ -10,6 +10,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableList; + import java.util.ArrayList; import java.util.List; @@ -50,7 +52,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV4; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV6; -import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmp; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmpV6; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolTcp; @@ -58,12 +59,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import com.google.common.collect.ImmutableList; - public class SecRuleEntityDecoder { private SecRuleEntityDecoder() { - throw new UnsupportedOperationException("Cannot create an instace."); + throw new UnsupportedOperationException("Cannot create an instance."); } public static ContractId getContractId(SecurityRule secRule) { @@ -82,7 +81,8 @@ public class SecRuleEntityDecoder { .setIntValue(portMin.longValue()) .build()); } else { - params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) + params.add(new ParameterValueBuilder() + .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); @@ -93,7 +93,8 @@ public class SecRuleEntityDecoder { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } - params.add(new ParameterValueBuilder().setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) + params.add(new ParameterValueBuilder() + .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } @@ -102,7 +103,8 @@ public class SecRuleEntityDecoder { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } - params.add(new ParameterValueBuilder().setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) + params.add(new ParameterValueBuilder() + .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } @@ -111,7 +113,7 @@ public class SecRuleEntityDecoder { } public static ActionRef createActionRefFromActionChoice(ActionChoice action) { - if(action instanceof SfcActionCase){ + if (action instanceof SfcActionCase) { return MappingUtils.createSfcActionRef(((SfcActionCase) action).getSfcChainName()); } else if (action instanceof AllowActionCase) { return MappingUtils.ACTION_REF_ALLOW; @@ -131,7 +133,9 @@ public class SecRuleEntityDecoder { } /** - * @param secRule + * Resolves Direction for provided secRule. + * + * @param secRule rule for which Direction is resolved. * @return direction resolved from {@link SecurityRule#getDirection()} * @throws IllegalArgumentException if return value of * {@link SecurityRule#getDirection()} is other than {@link DirectionIngress} or @@ -153,6 +157,8 @@ public class SecRuleEntityDecoder { } /** + * Resolves Clause for provided secRule. + * * @param secRule {@link SecurityRule#getRemoteIpPrefix()} is used for EIC * and subject selection * @return clause with the subject and with a consumer matcher containing EIC @@ -160,8 +166,10 @@ public class SecRuleEntityDecoder { public static Clause getClause(SecurityRule secRule) { checkNotNull(secRule); SubjectName subjectName = SecRuleNameDecoder.getSubjectName(secRule); - ClauseBuilder clauseBuilder = - new ClauseBuilder().setSubjectRefs(ImmutableList.of(subjectName)).setName(SecRuleNameDecoder.getClauseName(secRule)); + ClauseBuilder clauseBuilder = new ClauseBuilder() + .setSubjectRefs(ImmutableList.of(subjectName)) + .setName(SecRuleNameDecoder + .getClauseName(secRule)); IpPrefix remoteIpPrefix = secRule.getRemoteIpPrefix(); if (remoteIpPrefix != null) { clauseBuilder.setConsumerMatchers(createConsumerMatchersWithEic(remoteIpPrefix)); @@ -192,10 +200,12 @@ public class SecRuleEntityDecoder { } private static boolean twoIsNullOrEqualsOne(T one, T two) { - if (two == null) + if (two == null) { return true; - if (two.equals(one)) + } + if (two.equals(one)) { return true; + } return false; } @@ -215,7 +225,9 @@ public class SecRuleEntityDecoder { } /** - * @param secRule + * Resolves EtherType for provided secRule. + * + * @param secRule rule for which EtherType is resolved. * @return {@code null} if {@link SecurityRule#getEthertype()} is null; Otherwise ethertype * number * @throws IllegalArgumentException if return value of @@ -237,7 +249,9 @@ public class SecRuleEntityDecoder { } /** - * @param secRule + * Resolves Protocol for provided secRule. + * + * @param secRule rule for which Protocol is resolved. * @return {@code null} if {@link SecurityRule#getProtocol()} is null; Otherwise protocol number * @throws IllegalArgumentException if return value of * {@link SecurityRule#getProtocol()} is other than {@link ProtocolTcp}, diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoder.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoder.java index 6ec2dc1dd..8ceafab88 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoder.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoder.java @@ -20,14 +20,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeBase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; public class SecRuleNameDecoder { - final static String MIN_PORT = "_min"; - final static String MAX_PORT = "_max"; + static final String MIN_PORT = "_min"; + static final String MAX_PORT = "_max"; private SecRuleNameDecoder() { throw new UnsupportedOperationException("Cannot create an instance."); diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRule.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRule.java index d17f1c9f5..1ae414403 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRule.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRule.java @@ -8,6 +8,9 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; + import java.util.List; import javax.annotation.concurrent.Immutable; @@ -24,9 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; - @Immutable public class SingleClassifierRule { @@ -110,14 +110,14 @@ public class SingleClassifierRule { private static boolean isRangePortParam(ParameterValue pv) { String pvName = pv.getName().getValue(); - return pv.getRangeValue() != null - && (pvName.equals(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM) || pvName.equals(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)); + return pv.getRangeValue() != null && (pvName.equals(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM) + || pvName.equals(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)); } private static boolean isSrcOrDstPortParam(ParameterValue pv) { String pvName = pv.getName().getValue(); - return pv.getIntValue() != null - && (pvName.equals(L4ClassifierDefinition.SRC_PORT_PARAM) || pvName.equals(L4ClassifierDefinition.DST_PORT_PARAM)); + return pv.getIntValue() != null && (pvName.equals(L4ClassifierDefinition.SRC_PORT_PARAM) + || pvName.equals(L4ClassifierDefinition.DST_PORT_PARAM)); } } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleRuleContract.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleRuleContract.java index 54103be75..1403357e2 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleRuleContract.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleRuleContract.java @@ -10,6 +10,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableList; + import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -23,8 +25,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import com.google.common.collect.ImmutableList; - @Immutable public class SingleRuleContract { @@ -34,7 +34,8 @@ public class SingleRuleContract { private final Clause clause; private final Contract contract; - public SingleRuleContract(SecurityRule secRule, int subjectAndRuleOrder, @Nullable Description contractDescription, ActionChoice action) { + public SingleRuleContract(SecurityRule secRule, int subjectAndRuleOrder, @Nullable Description contractDescription, + ActionChoice action) { this(secRule, new SingleClassifierRule(secRule, subjectAndRuleOrder, action), contractDescription); } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NetworkUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NetworkUtils.java index eff8541e5..c8ccfafcd 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NetworkUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NetworkUtils.java @@ -8,6 +8,9 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Optional; +import com.google.common.base.Strings; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -21,9 +24,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712. import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension; -import com.google.common.base.Optional; -import com.google.common.base.Strings; - public class NetworkUtils { public static List findRouterExternalNetworks(@Nullable Networks networks) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/PortUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/PortUtils.java index 621f3b15d..fc53e315b 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/PortUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/PortUtils.java @@ -8,6 +8,8 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Optional; + import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -22,8 +24,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.por import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port; -import com.google.common.base.Optional; - public class PortUtils { public static final String DEVICE_OWNER_DHCP = "network:dhcp"; diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/RouterUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/RouterUtils.java index cb6fe7c06..c81cb7baf 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/RouterUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/RouterUtils.java @@ -8,14 +8,14 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Optional; + import javax.annotation.Nullable; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router; -import com.google.common.base.Optional; - public class RouterUtils { public static Optional findRouter(Uuid uuid, @Nullable Routers routers) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityGroupUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityGroupUtils.java index 0d28041cd..0c2a4e02a 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityGroupUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityGroupUtils.java @@ -8,16 +8,16 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + import javax.annotation.Nullable; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.SecurityGroups; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.security.groups.SecurityGroup; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; - public class SecurityGroupUtils { public static Optional findSecurityGroup(Uuid secGrpUuid, @Nullable SecurityGroups securityGroups) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityRuleUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityRuleUtils.java index b85576306..f672a9791 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityRuleUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SecurityRuleUtils.java @@ -8,6 +8,13 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; + import java.util.Collections; import java.util.List; import java.util.Set; @@ -19,13 +26,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.SecurityRules; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import com.google.common.base.Function; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; - public class SecurityRuleUtils { public static Optional findSecurityRule(Uuid uuid, @Nullable SecurityRules securityRules) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SubnetUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SubnetUtils.java index e368c9d70..5bef2bb1a 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SubnetUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/SubnetUtils.java @@ -8,14 +8,14 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; +import com.google.common.base.Optional; + import javax.annotation.Nullable; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet; -import com.google.common.base.Optional; - public class SubnetUtils { public static Optional findSubnet(Uuid uuid, @Nullable Subnets subnets) { diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/Utils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/Utils.java index 015ddfc09..4f3bb1faf 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/Utils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/Utils.java @@ -9,6 +9,10 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.util; import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import com.google.common.net.InetAddresses; + import java.net.Inet4Address; import java.net.InetAddress; @@ -31,10 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floati import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.net.InetAddresses; - public class Utils { private static final String MASK_32 = "/32"; diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactoryTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactoryTest.java index d053ca652..6190e6a3e 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactoryTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/gbp/util/NeutronGbpIidFactoryTest.java @@ -32,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gb import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.EndpointsByPorts; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ExternalGatewaysAsEndpoints; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ExternalGatewaysAsL3Endpoints; @@ -53,8 +52,8 @@ public class NeutronGbpIidFactoryTest { UniqueId portId = mock(UniqueId.class); InstanceIdentifier id = NeutronGbpIidFactory.endpointByPortIid(portId); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, GbpByNeutronMappings.class, EndpointsByPorts.class, - EndpointByPort.class}; + Class[] expectedTypes = + {Mappings.class, GbpByNeutronMappings.class, EndpointsByPorts.class, EndpointByPort.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(EndpointByPort.class, id.getTargetType()); assertFalse(id.isWildcarded()); @@ -67,8 +66,8 @@ public class NeutronGbpIidFactoryTest { MacAddress mac = mock(MacAddress.class); InstanceIdentifier id = NeutronGbpIidFactory.portByEndpointIid(l2BdId, mac); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class, PortsByEndpoints.class, - PortByEndpoint.class}; + Class[] expectedTypes = + {Mappings.class, NeutronByGbpMappings.class, PortsByEndpoints.class, PortByEndpoint.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(PortByEndpoint.class, id.getTargetType()); assertFalse(id.isWildcarded()); @@ -80,11 +79,12 @@ public class NeutronGbpIidFactoryTest { public void portByBaseEndpointIidTest() { String address = "00:00:00:00:00:00:01"; ContextId ctxId = new ContextId("00000000-1111-2222-3333-44444555566667777"); - PortByBaseEndpointKey key = new PortByBaseEndpointKey(address, MacAddressType.class, ctxId, MappingUtils.L2_BRDIGE_DOMAIN); + PortByBaseEndpointKey key = + new PortByBaseEndpointKey(address, MacAddressType.class, ctxId, MappingUtils.L2_BRDIGE_DOMAIN); InstanceIdentifier id = NeutronGbpIidFactory.portByBaseEndpointIid(key); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class, PortsByBaseEndpoints.class, - PortByBaseEndpoint.class}; + Class[] expectedTypes = + {Mappings.class, NeutronByGbpMappings.class, PortsByBaseEndpoints.class, PortByBaseEndpoint.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(PortByBaseEndpoint.class, id.getTargetType()); assertFalse(id.isWildcarded()); @@ -102,8 +102,8 @@ public class NeutronGbpIidFactoryTest { InstanceIdentifier id = NeutronGbpIidFactory.baseEndpointByPortIid(portId); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, GbpByNeutronMappings.class, BaseEndpointsByPorts.class, - BaseEndpointByPort.class}; + Class[] expectedTypes = + {Mappings.class, GbpByNeutronMappings.class, BaseEndpointsByPorts.class, BaseEndpointByPort.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(BaseEndpointByPort.class, id.getTargetType()); assertFalse(id.isWildcarded()); @@ -117,7 +117,8 @@ public class NeutronGbpIidFactoryTest { InstanceIdentifier id = NeutronGbpIidFactory.externalGatewayAsL3Endpoint( l3Context, ipAddress); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsL3Endpoints.class, + Class[] expectedTypes = + {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsL3Endpoints.class, ExternalGatewayAsL3Endpoint.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(ExternalGatewayAsL3Endpoint.class, id.getTargetType()); @@ -133,22 +134,19 @@ public class NeutronGbpIidFactoryTest { String ipAddress = "192.168.50.20/32"; IpPrefix ipPrefix = new IpPrefix(ipAddress.toCharArray()); ContextId ctxId = new ContextId("00000000-1111-2222-3333-44444555566667777"); - InstanceIdentifier id = NeutronGbpIidFactory.externalGatewayAsEndpoint( - ctxId, ipPrefix, MappingUtils.L3_CONTEXT); + InstanceIdentifier id = + NeutronGbpIidFactory.externalGatewayAsEndpoint(ctxId, ipPrefix, MappingUtils.L3_CONTEXT); assertNotNull(id); - Class[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsEndpoints.class, + Class[] expectedTypes = + {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsEndpoints.class, ExternalGatewayAsEndpoint.class}; assertPathArgumentTypes(id.getPathArguments(), expectedTypes); assertEquals(ExternalGatewayAsEndpoint.class, id.getTargetType()); assertFalse(id.isWildcarded()); - assertEquals(ctxId, id.firstKeyOf(ExternalGatewayAsEndpoint.class) - .getContextId()); - assertEquals(MappingUtils.L3_CONTEXT, id.firstKeyOf(ExternalGatewayAsEndpoint.class) - .getContextType()); - assertEquals(ipAddress, id.firstKeyOf(ExternalGatewayAsEndpoint.class) - .getAddress()); - assertEquals(IpPrefixType.class, id.firstKeyOf(ExternalGatewayAsEndpoint.class) - .getAddressType()); + assertEquals(ctxId, id.firstKeyOf(ExternalGatewayAsEndpoint.class).getContextId()); + assertEquals(MappingUtils.L3_CONTEXT, id.firstKeyOf(ExternalGatewayAsEndpoint.class).getContextType()); + assertEquals(ipAddress, id.firstKeyOf(ExternalGatewayAsEndpoint.class).getAddress()); + assertEquals(IpPrefixType.class, id.firstKeyOf(ExternalGatewayAsEndpoint.class).getAddressType()); } private static void assertPathArgumentTypes(Iterable pathArguments, Class[] expectedTypes) { diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java index 5525dd436..472737604 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java @@ -16,6 +16,10 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + import java.io.IOException; import java.util.Set; @@ -53,10 +57,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.security.groups.SecurityGroupBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - public class NeutronMapperTest extends NeutronMapperDataBrokerTest { private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); @@ -194,11 +194,11 @@ public class NeutronMapperTest extends NeutronMapperDataBrokerTest { } private Optional getL3ContextOptional(Network network) { - ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); + ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); TenantId tenantId = new TenantId(network.getTenantId().getValue()); ContextId l3CtxId = new ContextId(network.getUuid().getValue()); L3ContextId l3ContextId = new L3ContextId(l3CtxId); InstanceIdentifier l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId); - return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rTx); + return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, readTx); } } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java index e18818bd4..e81d7134f 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java @@ -14,11 +14,11 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.base.Optional; + import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import com.google.common.base.Optional; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,8 +29,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest; import org.opendaylight.groupbasedpolicy.util.DataStoreHelper; import org.opendaylight.groupbasedpolicy.util.IidFactory; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId; @@ -49,7 +47,6 @@ public class NeutronNetworkAwareDataStoreTest extends NeutronMapperDataBrokerTes private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); private final Uuid networkUuid = new Uuid("dddddddd-dddd-dddd-dddd-dddddddddddd"); private static final long METADATA_IPV4_SERVER_PORT = 80; - private static final IpPrefix METADATA_IP_PREFIX = new IpPrefix(new Ipv4Prefix("169.254.169.254/32")); private DataBroker dataBroker; private NeutronNetworkAware networkAware; @@ -156,12 +153,12 @@ public class NeutronNetworkAwareDataStoreTest extends NeutronMapperDataBrokerTes } private Optional getL3ContextOptional(Network network) { - ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); + ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); TenantId tenantId = new TenantId(network.getTenantId().getValue()); ContextId l3CtxId = new ContextId(network.getUuid().getValue()); L3ContextId l3ContextId = new L3ContextId(l3CtxId); InstanceIdentifier l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId); - return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rTx); + return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, readTx); } } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAwareDataStoreTest.java index 61cd99d7d..5208ceba4 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAwareDataStoreTest.java @@ -12,6 +12,8 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableList; + import java.util.Collections; import java.util.List; @@ -45,8 +47,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.s import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetBuilder; -import com.google.common.collect.ImmutableList; - public class NeutronPortAwareDataStoreTest extends NeutronMapperDataBrokerTest { private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); @@ -61,18 +61,20 @@ public class NeutronPortAwareDataStoreTest extends NeutronMapperDataBrokerTest { private Neutron neutron; @Before + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void init() { dataBroker = getDataBroker(); neutron = mock(Neutron.class); epRegistrator = mock(EndpointRegistrator.class); when(epRegistrator.registerEndpoint(any(RegisterEndpointInput.class))).thenReturn(true); when(epRegistrator.registerEndpoint( - any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput.class))) - .thenReturn(true); + any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput.class))) + .thenReturn(true); when(epRegistrator.unregisterEndpoint(any(UnregisterEndpointInput.class))).thenReturn(true); when(epRegistrator.unregisterEndpoint( - any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput.class))) - .thenReturn(true); + any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput.class))) + .thenReturn(true); portAware = new NeutronPortAware(dataBroker, epRegistrator, new IpPrefix(new Ipv4Prefix("192.168.192.168/32"))); } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAwareDataStoreTest.java index 813d8df7d..e6aa72d9e 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAwareDataStoreTest.java @@ -15,11 +15,12 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; + import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,9 +34,7 @@ import org.opendaylight.groupbasedpolicy.neutron.mapper.util.Utils; import org.opendaylight.groupbasedpolicy.util.DataStoreHelper; import org.opendaylight.groupbasedpolicy.util.IidFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId; @@ -64,15 +63,14 @@ import org.opendaylight.yangtools.yang.common.RpcResult; public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest { - private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); - private final Uuid routerUuid = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"); - private final Uuid newRouterUuid = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbb2"); - private final Uuid subnetUuid = new Uuid("cccccccc-cccc-cccc-cccc-cccccccccccc"); - private final Uuid networkUuid = new Uuid("dddddddd-dddd-dddd-dddd-dddddddddddd"); - private final Uuid gatewayPortUuid = new Uuid("dddddddd-dddd-dddd-dddd-ddddddddddd1"); - private final IpAddress ipAddress = new IpAddress(new Ipv4Address("10.0.0.2")); + private static final Uuid TENANT_UUID = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); + private static final Uuid ROUTER_UUID = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"); + private static final Uuid NEW_ROUTER_UUID = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbb2"); + private static final Uuid SUBNET_UUID = new Uuid("cccccccc-cccc-cccc-cccc-cccccccccccc"); + private static final Uuid NETWORK_UUID = new Uuid("dddddddd-dddd-dddd-dddd-dddddddddddd"); + private static final Uuid GATEWAY_PORT_UUID = new Uuid("dddddddd-dddd-dddd-dddd-ddddddddddd1"); + private static final IpAddress IP_ADDRESS = new IpAddress(new Ipv4Address("10.0.0.2")); private static final long METADATA_IPV4_SERVER_PORT = 80; - private static final IpPrefix METADATA_IP_PREFIX = new IpPrefix(new Ipv4Prefix("169.254.169.254/32")); private DataBroker dataBroker; private NeutronRouterAware routerAware; @@ -88,6 +86,8 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest private Network network; @Before + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void init() throws ExecutionException, InterruptedException { futureRpcResult = mock(Future.class); futureRpcFail = mock(Future.class); @@ -113,7 +113,7 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest epRegistrator = new EndpointRegistrator(epService, baseEpService); networkAware = new NeutronNetworkAware(dataBroker, METADATA_IPV4_SERVER_PORT); - network = new NetworkBuilder().setTenantId(tenantUuid).setUuid(networkUuid).setName("networkName").build(); + network = new NetworkBuilder().setTenantId(TENANT_UUID).setUuid(NETWORK_UUID).setName("networkName").build(); routerAware = new NeutronRouterAware(dataBroker, epRegistrator); } @@ -129,7 +129,7 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest @Test public void testOnCreated() { - Router router = new RouterBuilder().setTenantId(tenantUuid).setName("routerName").setUuid(routerUuid).build(); + Router router = new RouterBuilder().setTenantId(TENANT_UUID).setName("routerName").setUuid(ROUTER_UUID).build(); routerAware.onCreated(router, neutron); @@ -138,7 +138,7 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest @Test public void testOnCreated_incorrectName() { - Router router = new RouterBuilder().setTenantId(tenantUuid).setName("123").setUuid(routerUuid).build(); + Router router = new RouterBuilder().setTenantId(TENANT_UUID).setName("123").setUuid(ROUTER_UUID).build(); routerAware.onCreated(router, neutron); @@ -151,18 +151,13 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest when(neutron.getSubnets()).thenReturn(subnets); when(neutron.getNetworks()).thenReturn(new NetworksBuilder().setNetwork(ImmutableList.of(network)).build()); - FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(ipAddress).setSubnetId(subnetUuid).build(); - Port port = new PortBuilder().setUuid(gatewayPortUuid).setFixedIps(ImmutableList.of(fixedIps)).build(); + FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(IP_ADDRESS).setSubnetId(SUBNET_UUID).build(); + Port port = new PortBuilder().setUuid(GATEWAY_PORT_UUID).setFixedIps(ImmutableList.of(fixedIps)).build(); Ports ports = new PortsBuilder().setPort(ImmutableList.of(port)).build(); when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) - .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) - .build(); + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); networkAware.onCreated(network, neutron); @@ -171,6 +166,13 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest routerAware.onCreated(oldRouter, neutron); assertRouterExists(oldRouter); + + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) + .setName("newRouterName") + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) + .build(); + assertRouterNotExists(newRouter); routerAware.onUpdated(oldRouter, newRouter, neutron, neutron); @@ -184,7 +186,7 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest Subnets subnets = createSubnets(); when(neutron.getSubnets()).thenReturn(subnets); - FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(ipAddress).setSubnetId(subnetUuid).build(); + FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(IP_ADDRESS).setSubnetId(SUBNET_UUID).build(); Port port = new PortBuilder().setUuid(new Uuid("dddddddd-dddd-dddd-dddd-000000000000")) .setFixedIps(ImmutableList.of(fixedIps)) .build(); @@ -192,11 +194,11 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) .build(); routerAware.onCreated(oldRouter, neutron); @@ -210,16 +212,16 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest Subnets subnets = createSubnets(); when(neutron.getSubnets()).thenReturn(subnets); - Port port = new PortBuilder().setUuid(gatewayPortUuid).build(); + Port port = new PortBuilder().setUuid(GATEWAY_PORT_UUID).build(); Ports ports = new PortsBuilder().setPort(ImmutableList.of(port)).build(); when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) .build(); routerAware.onCreated(oldRouter, neutron); @@ -233,17 +235,17 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest Subnets subnets = createSubnets(); when(neutron.getSubnets()).thenReturn(subnets); - FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(ipAddress).build(); - Port port = new PortBuilder().setUuid(gatewayPortUuid).setFixedIps(ImmutableList.of(fixedIps)).build(); + FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(IP_ADDRESS).build(); + Port port = new PortBuilder().setUuid(GATEWAY_PORT_UUID).setFixedIps(ImmutableList.of(fixedIps)).build(); Ports ports = new PortsBuilder().setPort(ImmutableList.of(port)).build(); when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) .build(); routerAware.onCreated(oldRouter, neutron); @@ -253,6 +255,8 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest } @Test + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void testOnUpdated_ExtGatewayNotRegistered() { when(baseEpService.registerEndpoint( any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInput.class))) @@ -261,17 +265,17 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest Subnets subnets = createSubnets(); when(neutron.getSubnets()).thenReturn(subnets); - FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(ipAddress).setSubnetId(subnetUuid).build(); - Port port = new PortBuilder().setUuid(gatewayPortUuid).setFixedIps(ImmutableList.of(fixedIps)).build(); + FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(IP_ADDRESS).setSubnetId(SUBNET_UUID).build(); + Port port = new PortBuilder().setUuid(GATEWAY_PORT_UUID).setFixedIps(ImmutableList.of(fixedIps)).build(); Ports ports = new PortsBuilder().setPort(ImmutableList.of(port)).build(); when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) .build(); routerAware.onCreated(oldRouter, neutron); @@ -286,17 +290,17 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest when(neutron.getSubnets()).thenReturn(subnets); when(neutron.getNetworks()).thenReturn(new NetworksBuilder().setNetwork(ImmutableList.of(network)).build()); - FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(ipAddress).setSubnetId(subnetUuid).build(); - Port port = new PortBuilder().setUuid(gatewayPortUuid).setFixedIps(ImmutableList.of(fixedIps)).build(); + FixedIps fixedIps = new FixedIpsBuilder().setIpAddress(IP_ADDRESS).setSubnetId(SUBNET_UUID).build(); + Port port = new PortBuilder().setUuid(GATEWAY_PORT_UUID).setFixedIps(ImmutableList.of(fixedIps)).build(); Ports ports = new PortsBuilder().setPort(ImmutableList.of(port)).build(); when(neutron.getPorts()).thenReturn(ports); Router oldRouter = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); - Router newRouter = new RouterBuilder().setTenantId(tenantUuid) + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); + Router newRouter = new RouterBuilder().setTenantId(TENANT_UUID) .setName("newRouterName") - .setUuid(newRouterUuid) - .setGatewayPortId(gatewayPortUuid) + .setUuid(NEW_ROUTER_UUID) + .setGatewayPortId(GATEWAY_PORT_UUID) .build(); routerAware.onCreated(oldRouter, neutron); @@ -308,7 +312,7 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest @Test public void testOnDeleted() { Router router = - new RouterBuilder().setTenantId(tenantUuid).setName("oldRouterName").setUuid(routerUuid).build(); + new RouterBuilder().setTenantId(TENANT_UUID).setName("oldRouterName").setUuid(ROUTER_UUID).build(); routerAware.onCreated(router, neutron); routerAware.onDeleted(router, neutron, neutron); @@ -316,11 +320,11 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest } private Subnets createSubnets() { - Subnet subnet = new SubnetBuilder().setTenantId(tenantUuid) - .setUuid(subnetUuid) + Subnet subnet = new SubnetBuilder().setTenantId(TENANT_UUID) + .setUuid(SUBNET_UUID) .setName("subnetName") - .setNetworkId(networkUuid) - .setGatewayIp(ipAddress) + .setNetworkId(NETWORK_UUID) + .setGatewayIp(IP_ADDRESS) .setCidr(Utils.createIpPrefix("10.0.0.0/24")) .build(); return new SubnetsBuilder().setSubnet(ImmutableList.of(subnet)).build(); @@ -343,12 +347,12 @@ public class NeutronRouterAwareDataStoreTest extends NeutronMapperDataBrokerTest } private Optional getL3ContextOptional(Router router) { - ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); + ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); TenantId tenantId = new TenantId(router.getTenantId().getValue()); ContextId routerL3CtxId = new ContextId(router.getUuid().getValue()); L3ContextId l3ContextId = new L3ContextId(routerL3CtxId); InstanceIdentifier l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId); - return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rTx); + return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, readTx); } } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAwareDataStoreTest.java index c4bfd09b6..069a37e96 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAwareDataStoreTest.java @@ -12,16 +12,15 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.apache.commons.lang3.StringUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest; import org.opendaylight.groupbasedpolicy.neutron.mapper.EndpointRegistrator; import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.NeutronSecurityRuleAware; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronEntityFactory; +import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.PolicyAssert; import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; @@ -44,6 +43,8 @@ public class NeutronSecurityGroupAwareDataStoreTest extends NeutronMapperDataBro private EndpointRegistrator epRegistrator; @Before + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void init() { dataBroker = getDataBroker(); @@ -136,7 +137,6 @@ public class NeutronSecurityGroupAwareDataStoreTest extends NeutronMapperDataBro @Test public void testAddNeutronSecurityGroup_incorrectNameDescription() throws Exception { String uuid = "dddddddd-dddd-dddd-dddd-dddddddddddd"; - String longDescription = StringUtils.repeat("a", 4100); SecurityGroup secGroupA = new SecurityGroupBuilder().setUuid(new Uuid(uuid)) .setTenantId(new Uuid(tenantId)) .setName("123") diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAwareDataStoreTest.java index f337fd83f..54d6c16cd 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAwareDataStoreTest.java @@ -12,6 +12,8 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableList; + import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -41,17 +43,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.s import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetBuilder; import org.opendaylight.yangtools.yang.common.RpcResult; -import com.google.common.collect.ImmutableList; - public class NeutronSubnetAwareDataStoreTest extends NeutronMapperDataBrokerTest { - private static final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); - private static final Uuid networkUuid = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"); - private static final Uuid subnetUuid = new Uuid("cccccccc-cccc-cccc-cccc-cccccccccccc"); - private static final Uuid subnetUuid2 = new Uuid("cccccccc-cccc-cccc-cccc-ccccccccccc2"); - private static final IpAddress ipAddress = new IpAddress(new Ipv4Address("10.0.0.2")); - private static final IpAddress ipAddress2 = new IpAddress(new Ipv4Address("10.0.2.2")); - private static final IpPrefix ipPrefix = new IpPrefix(new Ipv4Prefix("10.0.0.0/24")); + private static final Uuid TENANT_UUID = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); + private static final Uuid NETWORK_UUID = new Uuid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"); + private static final Uuid SUBNET_UUID = new Uuid("cccccccc-cccc-cccc-cccc-cccccccccccc"); + private static final Uuid SUBNET_UUID_2 = new Uuid("cccccccc-cccc-cccc-cccc-ccccccccccc2"); + private static final IpAddress IP_ADDRESS = new IpAddress(new Ipv4Address("10.0.0.2")); + private static final IpAddress IP_ADDRESS_2 = new IpAddress(new Ipv4Address("10.0.2.2")); + private static final IpPrefix IP_PREFIX = new IpPrefix(new Ipv4Prefix("10.0.0.0/24")); private DataBroker dataBroker; private Neutron neutron; @@ -62,22 +62,24 @@ public class NeutronSubnetAwareDataStoreTest extends NeutronMapperDataBrokerTest private RpcResult rpcResult; private RpcResult rpcFail; private NeutronSubnetAware subnetAware; - private static final Subnet subnet = new SubnetBuilder().setTenantId(tenantUuid) - .setUuid(subnetUuid) + private static final Subnet SUBNET = new SubnetBuilder().setTenantId(TENANT_UUID) + .setUuid(SUBNET_UUID) .setName("subnetName") - .setNetworkId(networkUuid) - .setGatewayIp(ipAddress) - .setCidr(ipPrefix) + .setNetworkId(NETWORK_UUID) + .setGatewayIp(IP_ADDRESS) + .setCidr(IP_PREFIX) .build(); - private static final Subnet subnet2 = new SubnetBuilder().setTenantId(tenantUuid) - .setUuid(subnetUuid2) + private static final Subnet SUBNET_2 = new SubnetBuilder().setTenantId(TENANT_UUID) + .setUuid(SUBNET_UUID_2) .setName("subnetName2") - .setNetworkId(networkUuid) - .setGatewayIp(ipAddress2) - .setCidr(ipPrefix) + .setNetworkId(NETWORK_UUID) + .setGatewayIp(IP_ADDRESS_2) + .setCidr(IP_PREFIX) .build(); @Before + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. public void init() throws ExecutionException, InterruptedException { futureRpcResult = mock(Future.class); rpcResult = mock(RpcResult.class); @@ -115,15 +117,15 @@ public class NeutronSubnetAwareDataStoreTest extends NeutronMapperDataBrokerTest NetworkProviderExtension networkProviderExtension = new NetworkProviderExtensionBuilder().setPhysicalNetwork("physicalNetwork").build(); - Network network = new NetworkBuilder().setUuid(networkUuid) + Network network = new NetworkBuilder().setUuid(NETWORK_UUID) .addAugmentation(NetworkProviderExtension.class, networkProviderExtension) .build(); Networks networks = new NetworksBuilder().setNetwork(ImmutableList.of(network)).build(); when(neutron.getNetworks()).thenReturn(networks); - subnetAware.onCreated(subnet, neutron); + subnetAware.onCreated(SUBNET, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); } @Test @@ -132,57 +134,58 @@ public class NeutronSubnetAwareDataStoreTest extends NeutronMapperDataBrokerTest Networks networks = new NetworksBuilder().setNetwork(ImmutableList.of()).build(); when(neutron.getNetworks()).thenReturn(networks); - subnetAware.onCreated(subnet, neutron); + subnetAware.onCreated(SUBNET, neutron); - NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); } @Test public void testOnUpdated() { - Network network = new NetworkBuilder().setUuid(networkUuid).build(); + Network network = new NetworkBuilder().setUuid(NETWORK_UUID).build(); Networks networks = new NetworksBuilder().setNetwork(ImmutableList.of(network)).build(); when(neutron.getNetworks()).thenReturn(networks); - subnetAware.onCreated(subnet, neutron); + subnetAware.onCreated(SUBNET, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet, neutron, null); - NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, tenantUuid, subnet2, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); + NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, TENANT_UUID, SUBNET_2, neutron, null); - subnetAware.onUpdated(subnet, subnet2, neutron, neutron); + subnetAware.onUpdated(SUBNET, SUBNET_2, neutron, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet2, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET_2, neutron, null); } @Test public void testOnDeleted() { - Network network = new NetworkBuilder().setUuid(networkUuid).build(); + Network network = new NetworkBuilder().setUuid(NETWORK_UUID).build(); Networks networks = new NetworksBuilder().setNetwork(ImmutableList.of(network)).build(); when(neutron.getNetworks()).thenReturn(networks); - subnetAware.onCreated(subnet, neutron); + subnetAware.onCreated(SUBNET, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); - subnetAware.onDeleted(subnet, neutron, neutron); + subnetAware.onDeleted(SUBNET, neutron, neutron); - NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainNotExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); } + @Test public void testOnDeleted_wrongSubnet() { - Network network = new NetworkBuilder().setUuid(networkUuid).build(); + Network network = new NetworkBuilder().setUuid(NETWORK_UUID).build(); Networks networks = new NetworksBuilder().setNetwork(ImmutableList.of(network)).build(); when(neutron.getNetworks()).thenReturn(networks); - subnetAware.onCreated(subnet, neutron); + subnetAware.onCreated(SUBNET, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); - subnetAware.onDeleted(subnet2, neutron, neutron); + subnetAware.onDeleted(SUBNET_2, neutron, neutron); - NeutronMapperAssert.assertNetworkDomainExists(dataBroker, tenantUuid, subnet, neutron, null); + NeutronMapperAssert.assertNetworkDomainExists(dataBroker, TENANT_UUID, SUBNET, neutron, null); } } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareDataStoreTest.java index 5e7320797..0ae156084 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareDataStoreTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareDataStoreTest.java @@ -10,6 +10,10 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + import java.util.ArrayList; import java.util.List; @@ -47,13 +51,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRuleBuilder; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - /** - * END 2 END TESTING - inputs are Neutron entities and expected outputs are GBP entities in - * datastore + * END 2 END TESTING - inputs are Neutron entities and expected outputs are GBP entities in datastore. */ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrokerTest { @@ -67,36 +66,38 @@ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrok @Test public final void testAddNeutronSecurityRule_rulesWithRemoteIpPrefix() throws Exception { - String tenant = "ad4c6c25-2424-4ad3-97ee-f9691ce03645"; - String goldSecGrp = "fe40e28f-ad6a-4a2d-b12a-47510876344a"; - SecurityRule goldInIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, EthertypeV4.class, DirectionIngress.class, goldSecGrp, - null); - SecurityRule goldOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, EthertypeV4.class, DirectionEgress.class, goldSecGrp, - null); - String serverSecGrp = "71cf4fe5-b146-409e-8151-cd921298ce32"; - SecurityRuleAttributes.Protocol protocolTcp = new SecurityRuleAttributes.Protocol(ProtocolTcp.class); - SecurityRule serverIn80Tcp10_1_1_0 = new SecurityRuleBuilder().setUuid(new Uuid("9dbb533d-d9b2-4dc9-bae7-ee60c8df184d")) - .setTenantId(new Uuid(tenant)) - .setEthertype(EthertypeV4.class) - .setProtocol(protocolTcp) - .setPortRangeMin(80) - .setPortRangeMax(80) - .setDirection(DirectionIngress.class) - .setSecurityGroupId(new Uuid(serverSecGrp)) - .setRemoteIpPrefix(new IpPrefix(new Ipv4Prefix("10.1.1.0/24"))) - .build(); - SecurityRule serverInIp20_1_1_0 = new SecurityRuleBuilder().setUuid(new Uuid("adf7e558-de47-4f9e-a9b8-96e19db5d1ac")) - .setTenantId(new Uuid(tenant)) - .setEthertype(EthertypeV4.class) - .setDirection(DirectionIngress.class) - .setSecurityGroupId(new Uuid(serverSecGrp)) - .setRemoteIpPrefix(new IpPrefix(new Ipv4Prefix("20.1.1.0/24"))) - .build(); - SecurityRule serverOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, EthertypeV4.class, DirectionEgress.class, serverSecGrp, - null); + final String tenant = "ad4c6c25-2424-4ad3-97ee-f9691ce03645"; + final String goldSecGrp = "fe40e28f-ad6a-4a2d-b12a-47510876344a"; + final SecurityRule goldInIpv4 = NeutronEntityFactory.securityRuleWithEtherType( + "166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, EthertypeV4.class, DirectionIngress.class, goldSecGrp, + null); + final SecurityRule goldOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( + "dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, EthertypeV4.class, DirectionEgress.class, goldSecGrp, + null); + final String serverSecGrp = "71cf4fe5-b146-409e-8151-cd921298ce32"; + final SecurityRuleAttributes.Protocol protocolTcp = new SecurityRuleAttributes.Protocol(ProtocolTcp.class); + final SecurityRule serverIn80Tcp10_1_1_0 = new SecurityRuleBuilder() + .setUuid(new Uuid("9dbb533d-d9b2-4dc9-bae7-ee60c8df184d")) + .setTenantId(new Uuid(tenant)) + .setEthertype(EthertypeV4.class) + .setProtocol(protocolTcp) + .setPortRangeMin(80) + .setPortRangeMax(80) + .setDirection(DirectionIngress.class) + .setSecurityGroupId(new Uuid(serverSecGrp)) + .setRemoteIpPrefix(new IpPrefix(new Ipv4Prefix("10.1.1.0/24"))) + .build(); + final SecurityRule serverInIp20_1_1_0 = new SecurityRuleBuilder() + .setUuid(new Uuid("adf7e558-de47-4f9e-a9b8-96e19db5d1ac")) + .setTenantId(new Uuid(tenant)) + .setEthertype(EthertypeV4.class) + .setDirection(DirectionIngress.class) + .setSecurityGroupId(new Uuid(serverSecGrp)) + .setRemoteIpPrefix(new IpPrefix(new Ipv4Prefix("20.1.1.0/24"))) + .build(); + final SecurityRule serverOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( + "8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, EthertypeV4.class, DirectionEgress.class, serverSecGrp, + null); DataBroker dataBroker = getDataBroker(); List secGroups = new ArrayList<>(); secGroups.add(NeutronEntityFactory.securityGroup(goldSecGrp, tenant)); @@ -175,12 +176,12 @@ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrok final String secRuleId1 = "dddddddd-dddd-dddd-dddd-dddddddddddd"; final String secRuleId2 = "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee"; - List secGroups = new ArrayList<>(); + final List secGroups = new ArrayList<>(); secGroups.add(NeutronEntityFactory.securityGroup(secGroupId1, tenantId)); secGroups.add(NeutronEntityFactory.securityGroup(secGroupId2, tenantId)); - SecurityRule secRule1 = NeutronEntityFactory.securityRuleWithEtherType(secRuleId1, tenantId, + final SecurityRule secRule1 = NeutronEntityFactory.securityRuleWithEtherType(secRuleId1, tenantId, EthertypeV4.class, DirectionEgress.class, secGroupId1, secGroupId2); - SecurityRule secRule2 = NeutronEntityFactory.securityRuleWithEtherType(secRuleId2, tenantId, + final SecurityRule secRule2 = NeutronEntityFactory.securityRuleWithEtherType(secRuleId2, tenantId, EthertypeV4.class, DirectionIngress.class, secGroupId2, secGroupId1); NeutronBuilder neutronBuilder = new NeutronBuilder() .setSecurityGroups(new SecurityGroupsBuilder().setSecurityGroup(secGroups).build()) @@ -269,19 +270,19 @@ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrok public final void testAddNeutronSecurityRule_rulesWithoutRemote() throws Exception { String tenant = "ad4c6c25-2424-4ad3-97ee-f9691ce03645"; String goldSecGrp = "fe40e28f-ad6a-4a2d-b12a-47510876344a"; - SecurityRule goldInIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, EthertypeV4.class, DirectionIngress.class, goldSecGrp, - null); - SecurityRule goldOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, EthertypeV4.class, DirectionEgress.class, goldSecGrp, - null); + SecurityRule goldInIpv4 = + NeutronEntityFactory.securityRuleWithEtherType("166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, + EthertypeV4.class, DirectionIngress.class, goldSecGrp, null); + SecurityRule goldOutIpv4 = + NeutronEntityFactory.securityRuleWithEtherType("dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, + EthertypeV4.class, DirectionEgress.class, goldSecGrp, null); String serverSecGrp = "71cf4fe5-b146-409e-8151-cd921298ce32"; - SecurityRule serverOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, EthertypeV4.class, DirectionEgress.class, serverSecGrp, - null); - SecurityRule serverInIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "adf7e558-de47-4f9e-a9b8-96e19db5d1ac", tenant, EthertypeV4.class, DirectionIngress.class, serverSecGrp, - null); + SecurityRule serverOutIpv4 = + NeutronEntityFactory.securityRuleWithEtherType("8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, + EthertypeV4.class, DirectionEgress.class, serverSecGrp, null); + SecurityRule serverInIpv4 = + NeutronEntityFactory.securityRuleWithEtherType("adf7e558-de47-4f9e-a9b8-96e19db5d1ac", tenant, + EthertypeV4.class, DirectionIngress.class, serverSecGrp, null); DataBroker dataBroker = getDataBroker(); List secGroups = new ArrayList<>(); secGroups.add(NeutronEntityFactory.securityGroup(goldSecGrp, tenant)); @@ -344,25 +345,26 @@ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrok String tenant = "ad4c6c25-2424-4ad3-97ee-f9691ce03645"; String goldSecGrp = "fe40e28f-ad6a-4a2d-b12a-47510876344a"; SecurityRule goldInIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, EthertypeV4.class, DirectionIngress.class, goldSecGrp, - null); + "166aedab-fdf5-4788-9e36-2b00b5f8722f", tenant, EthertypeV4.class, DirectionIngress.class, goldSecGrp, + null); SecurityRule goldOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, EthertypeV4.class, DirectionEgress.class, goldSecGrp, - null); + "dabfd4da-af89-45dd-85f8-181768c1b4c9", tenant, EthertypeV4.class, DirectionEgress.class, goldSecGrp, + null); String serverSecGrp = "71cf4fe5-b146-409e-8151-cd921298ce32"; SecurityRule serverOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, EthertypeV4.class, DirectionEgress.class, serverSecGrp, - null); + "8b9c48d3-44a8-46be-be35-6f3237d98071", tenant, EthertypeV4.class, DirectionEgress.class, serverSecGrp, + null); SecurityRuleAttributes.Protocol protocolTcp = new SecurityRuleAttributes.Protocol(ProtocolTcp.class); - SecurityRule serverIn80TcpIpv4 = new SecurityRuleBuilder().setUuid(new Uuid("adf7e558-de47-4f9e-a9b8-96e19db5d1ac")) - .setTenantId(new Uuid(tenant)) - .setEthertype(EthertypeV4.class) - .setProtocol(protocolTcp) - .setPortRangeMin(80) - .setPortRangeMax(80) - .setDirection(DirectionIngress.class) - .setSecurityGroupId(new Uuid(serverSecGrp)) - .build(); + SecurityRule serverIn80TcpIpv4 = new SecurityRuleBuilder() + .setUuid(new Uuid("adf7e558-de47-4f9e-a9b8-96e19db5d1ac")) + .setTenantId(new Uuid(tenant)) + .setEthertype(EthertypeV4.class) + .setProtocol(protocolTcp) + .setPortRangeMin(80) + .setPortRangeMax(80) + .setDirection(DirectionIngress.class) + .setSecurityGroupId(new Uuid(serverSecGrp)) + .build(); DataBroker dataBroker = getDataBroker(); List secGroups = new ArrayList<>(); secGroups.add(NeutronEntityFactory.securityGroup(goldSecGrp, tenant)); @@ -421,20 +423,20 @@ public class NeutronSecurityRuleAwareDataStoreTest extends NeutronMapperDataBrok @Test public final void testAddNeutronSecurityRule_defaultSecGrp() throws Exception { - String tenant = "111aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; - String defaultSecGrp = "111fffff-ffff-ffff-ffff-ffffffffffff"; - SecurityRule defaultInIpv4Default = NeutronEntityFactory.securityRuleWithEtherType( - "111ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionIngress.class, defaultSecGrp, - defaultSecGrp); - SecurityRule defaultInIpv6Default = NeutronEntityFactory.securityRuleWithEtherType( - "222ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionIngress.class, defaultSecGrp, - defaultSecGrp); - SecurityRule defaultOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( - "333ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionEgress.class, defaultSecGrp, - null); - SecurityRule defaultOutIpv6 = NeutronEntityFactory.securityRuleWithEtherType( - "444ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionEgress.class, defaultSecGrp, - null); + final String tenant = "111aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; + final String defaultSecGrp = "111fffff-ffff-ffff-ffff-ffffffffffff"; + final SecurityRule defaultInIpv4Default = NeutronEntityFactory.securityRuleWithEtherType( + "111ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionIngress.class, defaultSecGrp, + defaultSecGrp); + final SecurityRule defaultInIpv6Default = NeutronEntityFactory.securityRuleWithEtherType( + "222ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionIngress.class, defaultSecGrp, + defaultSecGrp); + final SecurityRule defaultOutIpv4 = NeutronEntityFactory.securityRuleWithEtherType( + "333ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionEgress.class, defaultSecGrp, + null); + final SecurityRule defaultOutIpv6 = NeutronEntityFactory.securityRuleWithEtherType( + "444ccccc-111c-cccc-cccc-cccccccccccc", tenant, EthertypeV4.class, DirectionEgress.class, defaultSecGrp, + null); DataBroker dataBroker = getDataBroker(); List secGroups = new ArrayList<>(); secGroups.add(NeutronEntityFactory.securityGroup(defaultSecGrp, tenant)); diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java index 0f0951ee0..514fca9bb 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java @@ -21,8 +21,8 @@ import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.groupbasedpolicy.neutron.mapper.EndpointRegistrator; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.ConfigDataStoreReader; -import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronEntityFactory; +import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.PolicyAssert; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java index 4510aee6c..dffd50259 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java @@ -154,8 +154,6 @@ public class SecRuleEntityDecoderTest { .append(MappingUtils.NAME_VALUE_DELIMETER) .append(EthertypeV4.class.getSimpleName()) .toString(); - System.out.println(expectedName); - System.out.println(ci.getName().getValue()); Assert.assertEquals(expectedName, ci.getName().getValue()); List parameterValues = ci.getParameterValue(); Assert.assertNotNull(parameterValues); @@ -184,7 +182,7 @@ public class SecRuleEntityDecoderTest { Assert.assertTrue("Classifier-instance does not contain destination port parameter", containsDstPortParam); } - private final void assertClassifierParameterValue(ParameterValue parameter, Long expectedIntValue, + private void assertClassifierParameterValue(ParameterValue parameter, Long expectedIntValue, String expectedStringValue, RangeValue expectedRangeValue) { Assert.assertEquals(expectedIntValue, parameter.getIntValue()); Assert.assertEquals(expectedStringValue, parameter.getStringValue()); @@ -447,13 +445,15 @@ public class SecRuleEntityDecoderTest { @Test public final void testGetEtherType_ethertypeIPv4() { secRuleBuilder.setEthertype(EthertypeV4.class); - Assert.assertEquals(EtherTypeClassifierDefinition.IPv4_VALUE, SecRuleEntityDecoder.getEtherType(secRuleBuilder.build())); + Assert.assertEquals(EtherTypeClassifierDefinition.IPv4_VALUE, + SecRuleEntityDecoder.getEtherType(secRuleBuilder.build())); } @Test public final void testGetEtherType_ethertypeIPv6() { secRuleBuilder.setEthertype(EthertypeV6.class); - Assert.assertEquals(EtherTypeClassifierDefinition.IPv6_VALUE, SecRuleEntityDecoder.getEtherType(secRuleBuilder.build())); + Assert.assertEquals(EtherTypeClassifierDefinition.IPv6_VALUE, + SecRuleEntityDecoder.getEtherType(secRuleBuilder.build())); } @Test @@ -476,21 +476,24 @@ public class SecRuleEntityDecoderTest { public final void testGetProtocol_protoTcp() { SecurityRuleAttributes.Protocol protocolTcp = new SecurityRuleAttributes.Protocol(ProtocolTcp.class); secRuleBuilder.setProtocol(protocolTcp); - Assert.assertEquals(IpProtoClassifierDefinition.TCP_VALUE, SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); + Assert.assertEquals(IpProtoClassifierDefinition.TCP_VALUE, + SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); } @Test public final void testGetProtocol_protoUdp() { SecurityRuleAttributes.Protocol protocolUdp = new SecurityRuleAttributes.Protocol(ProtocolUdp.class); secRuleBuilder.setProtocol(protocolUdp); - Assert.assertEquals(IpProtoClassifierDefinition.UDP_VALUE, SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); + Assert.assertEquals(IpProtoClassifierDefinition.UDP_VALUE, + SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); } @Test public final void testGetProtocol_protoIcmp() { SecurityRuleAttributes.Protocol protocolIcmp = new SecurityRuleAttributes.Protocol(ProtocolIcmp.class); secRuleBuilder.setProtocol(protocolIcmp); - Assert.assertEquals(IpProtoClassifierDefinition.ICMP_VALUE, SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); + Assert.assertEquals(IpProtoClassifierDefinition.ICMP_VALUE, + SecRuleEntityDecoder.getProtocol(secRuleBuilder.build())); } @Test diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoderTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoderTest.java index d78fc4411..52a43a58d 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoderTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleNameDecoderTest.java @@ -75,8 +75,8 @@ public class SecRuleNameDecoderTest { .append(EtherTypeClassifierDefinition.DEFINITION.getName().getValue()) .append(MappingUtils.NAME_VALUE_DELIMETER) .append("%s"); - String frmtClsfName = String.format(frmtBuilder.toString(), 8010, 8020, secRule.getProtocol().getIdentityref().getSimpleName(), - secRule.getEthertype().getSimpleName()); + String frmtClsfName = String.format(frmtBuilder.toString(), 8010, 8020, + secRule.getProtocol().getIdentityref().getSimpleName(), secRule.getEthertype().getSimpleName()); ClassifierName expectedClsfInstanceName = new ClassifierName(frmtClsfName); assertEquals(expectedClsfInstanceName, SecRuleNameDecoder.getClassifierInstanceName(secRule.build())); } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRuleTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRuleTest.java index ae2eca73b..34398017d 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRuleTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SingleClassifierRuleTest.java @@ -81,35 +81,44 @@ public class SingleClassifierRuleTest { @Test public final void updateOrderBasedOnL4ClassifTest() throws Exception { - ParameterValue sPort = createIntParameterValue(L4ClassifierDefinition.SRC_PORT_PARAM, Long.valueOf(4999)); - ParameterValue dPort = createIntParameterValue(L4ClassifierDefinition.DST_PORT_PARAM, Long.valueOf(8080)); - ParameterValue sMiniRange = createRangeParameterValue(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, 1000, 1000); - ParameterValue dMiniRange = createRangeParameterValue(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, 2000, 2000); - ParameterValue sPortRange = createRangeParameterValue(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, 3335, 3336); - ParameterValue dPortRange = createRangeParameterValue(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, 9998, 9999); - ClassifierInstance ci; - ci = createClassifierInstance(L4ClassifierDefinition.ID, dPortRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 180); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sPortRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 180); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sPort); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 170); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sMiniRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 170); - ci = createClassifierInstance(L4ClassifierDefinition.ID, dPort); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 170); - ci = createClassifierInstance(L4ClassifierDefinition.ID, dMiniRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 170); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sPortRange, dPortRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 160); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sPortRange, dPort); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 150); - ci = createClassifierInstance(L4ClassifierDefinition.ID, sPortRange, dMiniRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 150); - ci = createClassifierInstance(L4ClassifierDefinition.ID, dPortRange, sPort); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 150); - ci = createClassifierInstance(L4ClassifierDefinition.ID, dPortRange, sMiniRange); - assertEquals(SingleClassifierRule.updateOrderBasedOn(ci, allow, 0), 150); + final ParameterValue sourcePort = createIntParameterValue(L4ClassifierDefinition.SRC_PORT_PARAM, 4999L); + final ParameterValue destPort = createIntParameterValue(L4ClassifierDefinition.DST_PORT_PARAM, 8080L); + final ParameterValue + sourceMiniRange = + createRangeParameterValue(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, 1000, 1000); + final ParameterValue + destinationMiniRange = + createRangeParameterValue(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, 2000, 2000); + final ParameterValue + sourcePortRange = + createRangeParameterValue(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, 3335, 3336); + final ParameterValue + destinationPortRange = + createRangeParameterValue(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, 9998, 9999); + + ClassifierInstance classifierInstance; + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, destinationPortRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 180); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourcePortRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 180); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourcePort); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 170); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourceMiniRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 170); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, destPort); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 170); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, destinationMiniRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 170); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourcePortRange, destinationPortRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 160); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourcePortRange, destPort); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 150); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, sourcePortRange, destinationMiniRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 150); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, destinationPortRange, sourcePort); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 150); + classifierInstance = createClassifierInstance(L4ClassifierDefinition.ID, destinationPortRange, sourceMiniRange); + assertEquals(SingleClassifierRule.updateOrderBasedOn(classifierInstance, allow, 0), 150); } private ParameterValue createIntParameterValue(String paramName, Long value) { diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/ConfigDataStoreReader.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/ConfigDataStoreReader.java index f3437756b..7647f74c0 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/ConfigDataStoreReader.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/ConfigDataStoreReader.java @@ -7,6 +7,8 @@ */ package org.opendaylight.groupbasedpolicy.neutron.mapper.test; +import com.google.common.base.Optional; + 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; @@ -28,8 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import com.google.common.base.Optional; - public final class ConfigDataStoreReader { private ConfigDataStoreReader() { @@ -76,8 +76,8 @@ public final class ConfigDataStoreReader { } } - public static Optional readConsumerNamedSelector(DataBroker dataBroker, String tenantId, String egId, - String selectorName) { + public static Optional readConsumerNamedSelector(DataBroker dataBroker, String tenantId, + String egId, String selectorName) { InstanceIdentifier cnsIid = IidFactory.consumerNamedSelectorIid(new TenantId(tenantId), new EndpointGroupId(egId), new SelectorName(selectorName)); try (ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction()) { @@ -85,7 +85,8 @@ public final class ConfigDataStoreReader { } } - public static Optional readClause(DataBroker dataBroker, String tenantId, String contractId, String clauseName) { + public static Optional readClause(DataBroker dataBroker, String tenantId, String contractId, + String clauseName) { InstanceIdentifier clauseIid = IidFactory.clauseIid(new TenantId(tenantId), new ContractId(contractId), new ClauseName(clauseName)); try (ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction()) { diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/CustomDataBrokerTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/CustomDataBrokerTest.java index f13748b29..44b1acad6 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/CustomDataBrokerTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/CustomDataBrokerTest.java @@ -10,12 +10,14 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.test; import static com.google.common.base.Preconditions.checkState; -import javax.annotation.Nonnull; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + import java.io.IOException; import java.util.Collection; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; +import javax.annotation.Nonnull; + import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.opendaylight.yangtools.yang.binding.util.BindingReflections; @@ -37,6 +39,8 @@ public abstract class CustomDataBrokerTest extends AbstractDataBrokerTest { } /** + * Used to get classes from yang modules. + * * @return a class from every yang module which needs to be loaded. Cannot return {@code null} * or empty collection. */ diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronEntityFactory.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronEntityFactory.java index b6d564ef9..a2d2e163f 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronEntityFactory.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronEntityFactory.java @@ -7,6 +7,8 @@ */ package org.opendaylight.groupbasedpolicy.neutron.mapper.test; +import com.google.common.base.Strings; + import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeBase; @@ -17,8 +19,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRuleBuilder; -import com.google.common.base.Strings; - public final class NeutronEntityFactory { private NeutronEntityFactory() { @@ -33,8 +33,10 @@ public final class NeutronEntityFactory { return new SecurityGroupBuilder().setUuid(new Uuid(id)).setTenantId(new Uuid(tenantId)).setName(name).build(); } - public static SecurityRule securityRuleWithoutGroupIds(String id, String tenant, Class etherType, - Class direction, Class protocol, int portMin, int portMax) { + public static SecurityRule securityRuleWithoutGroupIds(String id, String tenant, + Class etherType, Class direction, + Class protocol, int portMin, int portMax) { + SecurityRuleAttributes.Protocol proto = new SecurityRuleAttributes.Protocol(protocol); SecurityRuleBuilder secRule = new SecurityRuleBuilder(); secRule.setUuid(new Uuid(id)); diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperAssert.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperAssert.java index 865837cfd..356027ca7 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperAssert.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperAssert.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.google.common.base.Optional; + 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; @@ -61,6 +62,12 @@ public class NeutronMapperAssert { assertTrue(opt.isPresent()); } + public static void assertNetworkDomainExists(DataBroker dataBroker, Uuid tenantUuid, Subnet subnet, + Neutron neutron, IpAddress ipAddress) { + Optional opt = getNetworkDomainOptional(dataBroker, tenantUuid, neutron, ipAddress, subnet); + assertTrue(opt.isPresent()); + } + public static void assertNetworkDomainNotExists(DataBroker dataBroker, Port port, Subnet subnet, Neutron neutron, IpAddress ipAddress) { Optional opt = @@ -68,12 +75,6 @@ public class NeutronMapperAssert { assertFalse(opt.isPresent()); } - public static void assertNetworkDomainExists(DataBroker dataBroker, Uuid tenantUuid, Subnet subnet, - Neutron neutron, IpAddress ipAddress) { - Optional opt = getNetworkDomainOptional(dataBroker, tenantUuid, neutron, ipAddress, subnet); - assertTrue(opt.isPresent()); - } - public static void assertNetworkDomainNotExists(DataBroker dataBroker, Uuid tenantUuid, Subnet subnet, Neutron neutron, IpAddress ipAddress) { Optional opt = getNetworkDomainOptional(dataBroker, tenantUuid, neutron, ipAddress, subnet); diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperDataBrokerTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperDataBrokerTest.java index 14c2da927..a08a1ec74 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperDataBrokerTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperDataBrokerTest.java @@ -11,6 +11,8 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableList; + import java.util.Collection; import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; @@ -23,8 +25,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gb import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron; -import com.google.common.collect.ImmutableList; - /** * Loads only modules of GBP and it's dependencies for data broker. *
@@ -38,17 +38,18 @@ public class NeutronMapperDataBrokerTest extends CustomDataBrokerTest { Mappings.class); } + @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names, + // this will be removed when deprecated classes will be cleared. protected EndpointRegistrator getEpRegistrator() { EndpointRegistrator epRegistrator = mock(EndpointRegistrator.class); when(epRegistrator.registerEndpoint(any(RegisterEndpointInput.class))).thenReturn(true); when(epRegistrator.registerEndpoint( - any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput.class))) - .thenReturn(true); + any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput.class))) + .thenReturn(true); when(epRegistrator.unregisterEndpoint(any(UnregisterEndpointInput.class))).thenReturn(true); when(epRegistrator.unregisterEndpoint( - any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput.class))) - .thenReturn(true); + any(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput.class))) + .thenReturn(true); return epRegistrator; } - } diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/PolicyAssert.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/PolicyAssert.java index 98dcc7fc1..09ac059cc 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/PolicyAssert.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/PolicyAssert.java @@ -13,6 +13,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; + import java.util.Collection; import java.util.List; import java.util.Set; @@ -42,9 +45,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; - public final class PolicyAssert { private PolicyAssert() { @@ -65,7 +65,9 @@ public final class PolicyAssert { // asserts for contract - public static void assertContractExists(DataBroker dataBroker, String tenantId, String contractId) throws Exception { + public static void assertContractExists(DataBroker dataBroker, String tenantId, String contractId) + throws Exception { + Optional contract = ConfigDataStoreReader.readContract(dataBroker, tenantId, contractId); assertTrue(contract.isPresent()); } @@ -267,7 +269,8 @@ public final class PolicyAssert { assertEquals(SecRuleNameDecoder.getSubjectName(secRule), subjectRef); } - public static void assertClauseExists(DataBroker dataBroker, String tenantId, String contractId, String clauseName) { + public static void assertClauseExists(DataBroker dataBroker, String tenantId, String contractId, + String clauseName) { Optional clause = ConfigDataStoreReader.readClause(dataBroker, tenantId, contractId, clauseName); assertTrue(clause.isPresent()); } @@ -297,14 +300,13 @@ public final class PolicyAssert { assertEquals(order, rule.getOrder().intValue()); } - private static T assertOneItem(Collection c) { - assertNotNull(c); - assertTrue(c.size() == 1); - return c.iterator().next(); + private static T assertOneItem(Collection collection) { + assertNotNull(collection); + assertTrue(collection.size() == 1); + return collection.iterator().next(); } // asserts for selector - public static void assertConsumerNamedSelectorExists(DataBroker dataBroker, String tenantId, String egId, String selectorName) { Optional potentialCns = ConfigDataStoreReader.readConsumerNamedSelector(dataBroker, -- 2.36.6