@Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final EpPolicyTemplateValueKey that = (EpPolicyTemplateValueKey) o; if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false; if (epgId != null ? !epgId.equals(that.epgId) : that.epgId != null) return false; return conditionName != null ? conditionName.equals(that.conditionName) : that.conditionName == null; }
@VisibleForTesting boolean handledPolicy(ResolvedPolicy policy) { if (!policy.getConsumerTenantId().equals(policy.getProviderTenantId())) { // FAAS always assumes consumer and provider EPGs belong to the same tenant LOG.warn( "Ignore Resolved Policy between Consumer EPG {} and Provider EPG {} becuase they belong to different Tenants", policy.getConsumerTenantId().getValue(), policy.getProviderTenantId().getValue()); return false; } return isTenantRegistered(policy.getConsumerTenantId()); }
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); }
/** * Creates an ordinal for the OfOverlay pipeline comparison, based on @TenantId and a * uniqueID (UUID) associated with any other attribute. * * @param tenantId the tenant id * @param id a unique id * @return the ordinal */ public static int getContextOrdinal(final TenantId tenantId, final UniqueId id) { if (tenantId == null || id == null) return 0; return getContextOrdinalFromString(tenantId.getValue() + "|" + id.getValue()); }
@Override public int hashCode() { return tenantId != null ? tenantId.hashCode() : 0; } }
public static int getContextOrdinal(Endpoint ep, NetworkDomainId networkContainment) { Set<String> epgs = new TreeSet<>(); // Get EPGs and add to ordered Set if (ep.getEndpointGroup() != null) { epgs.add(ep.getEndpointGroup().getValue()); } if (ep.getEndpointGroups() != null) { for (EndpointGroupId epgId : ep.getEndpointGroups()) { epgs.add(epgId.getValue()); } } StringBuilder key = new StringBuilder(ep.getTenant().getValue()); for (String epg : epgs) { key.append('|'); key.append(epg); } key.append("|").append(networkContainment); return getContextOrdinalFromString(key.toString()); }
@Override public boolean apply(EndpointL3Prefix input) { return (input.getTenant().equals(tenantId)); }
@VisibleForTesting void executeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) { // Remove for (InstanceIdentifier<?> iid : change.getRemovedPaths()) { DataObject old = change.getOriginalData().get(iid); if (old == null) { continue; } if (old instanceof Tenant) { Tenant tenant = (Tenant) old; if (tenant.getId().equals(gbpTenantId)) { LOG.info("Removed gbp Tenant {} -- faas Tenant {}", gbpTenantId.getValue(), faasTenantId.getValue()); this.policyManager.removeTenantLogicalNetwork(gbpTenantId, faasTenantId); } } } } }
public static int getContextOrdinal(Endpoint ep) { Set<String> epgs = new TreeSet<>(); // Get EPGs and add to ordered Set if (ep.getEndpointGroup() != null) { epgs.add(ep.getEndpointGroup().getValue()); } if (ep.getEndpointGroups() != null) { for (EndpointGroupId epgId : ep.getEndpointGroups()) { epgs.add(epgId.getValue()); } } StringBuilder key = new StringBuilder(ep.getTenant().getValue()); for (String epg : epgs) { key.append('|'); key.append(epg); } return getContextOrdinalFromString(key.toString()); }
@Override public void onDeleted(SecurityGroup deletedSecGroup, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("deleted securityGroup - {}", deletedSecGroup); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); TenantId tenantId = new TenantId(deletedSecGroup.getTenantId().getValue()); EndpointGroupId epgId = new EndpointGroupId(deletedSecGroup.getUuid().getValue()); Optional<EndpointGroup> potentialEpg = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, epgId), rwTx); if (!potentialEpg.isPresent()) { LOG.warn("Illegal state - Endpoint group {} does not exist.", epgId.getValue()); rwTx.cancel(); return; } DataStoreHelper.submitToDs(rwTx); }
/** * Reads endpointL3 from data store * @param l3c id of {@link L3Context} * @param ipAddress IP address of the endpoint * @param tenantId ID of {@link Tenant} can be optionally specified * @return {@link EndpointL3} if exists, otherwise null. */ public EndpointL3 getL3Endpoint(L3ContextId l3c, IpAddress ipAddress, @Nullable TenantId tenantId) { if (l3c == null || ipAddress == null) { LOG.warn("[ContextId: {}, IpAddress: {}] Cannot read endpoint from DS unless both keys are specified!", l3c, ipAddress); return null; } ReadOnlyTransaction rTx = dataProvider.newReadOnlyTransaction(); Optional<EndpointL3> endpointL3 = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, IidFactory.l3EndpointIid(l3c, ipAddress), rTx); rTx.close(); if (!endpointL3.isPresent()) { LOG.warn("EndpointL3 [{},{}] not found in data store.", l3c, ipAddress); return null; } if(tenantId != null && !endpointL3.get().getTenant().equals(tenantId)) { LOG.warn("EndpointL3 [{},{}] not found in data store for tenant: {}", l3c, ipAddress, tenantId); return null; } return endpointL3.get(); }
public static String createFlowCacheName(InstanceIdentifier<Classifier> classifierIid, FlowCacheCons.Value value) { PolicyRuleGroupKey policyRuleGroup = classifierIid.firstKeyOf(PolicyRuleGroup.class); ResolvedRuleKey resolvedRule = classifierIid.firstKeyOf(ResolvedRule.class); ClassifierKey classifier = classifierIid.firstKeyOf(Classifier.class); StringBuilder sb = new StringBuilder(); sb.append(createStringFromCompositeKey(policyRuleGroup.getTenantId().getValue(), policyRuleGroup.getContractId().getValue(), policyRuleGroup.getSubjectName().getValue())) .append(DELIMETER) .append(resolvedRule.getName().getValue()) .append(DELIMETER) .append(classifier.getName().getValue()) .append(DELIMETER) .append(value.get()); return sb.toString(); }
@Deprecated 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().setL2Context( new L2BridgeDomainId(port.getNetworkId().getValue())) .setMacAddress(new MacAddress(port.getMacAddress().getValue())) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); }
private boolean isEqualService(ResolvedPolicy newPolicy, ResolvedPolicy oldPolicy) { return oldPolicy != null && newPolicy.getConsumerEpgId().equals(oldPolicy.getConsumerEpgId()) && newPolicy.getProviderEpgId().equals(oldPolicy.getProviderEpgId()) && newPolicy.getConsumerTenantId().equals(oldPolicy.getConsumerTenantId()) && newPolicy.getProviderTenantId().equals(oldPolicy.getProviderTenantId()); }
public Uuid getFaasTenantId(TenantId tenantId) { Uuid val = mappedTenants.get(tenantId); if (val != null) { return val; } Uuid faasTenantId; if (isUUid(tenantId.getValue())) { faasTenantId = new Uuid(tenantId.getValue()); } else { faasTenantId = new Uuid(UUID.randomUUID().toString()); } mappedTenants.putIfAbsent(tenantId, faasTenantId); val = mappedTenants.get(tenantId); MappedTenantBuilder builder = new MappedTenantBuilder(); builder.setFaasTenantId(val); builder.setGbpTenantId(tenantId); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); MappedTenant result = builder.build(); wTx.put(LogicalDatastoreType.OPERATIONAL, FaasIidFactory.mappedTenantIid(tenantId), result); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Cached in Datastore Mapped Tenant {}", result); } else { LOG.error("Couldn't Cache in Datastore Mapped Tenant {}", result); } return val; }
@Override public void onDeleted(Network network, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("deleted network - {}", network); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); TenantId tenantId = new TenantId(network.getTenantId().getValue()); ContextId id = new ContextId(network.getUuid().getValue()); Optional<ForwardingContext> potentialL2Fd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2FloodDomainIid(tenantId, id), rwTx); if (!potentialL2Fd.isPresent()) { LOG.warn("Illegal state - l2-flood-domain {} does not exist.", id.getValue()); return; } Optional<ForwardingContext> potentialL2Bd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, id), rwTx); if (!potentialL2Bd.isPresent()) { LOG.warn("Illegal state - l2-bridge-domain {} does not exist.", id.getValue()); return; } Optional<ForwardingContext> potentialL3Ctx = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l3ContextIid(tenantId, id), rwTx); if (!potentialL3Ctx.isPresent()) { LOG.warn("Illegal state - l3-context {} does not exist.", id.getValue()); return; } removeTenantNetworkDomains(network, tenantId, rwTx); DataStoreHelper.submitToDs(rwTx); }
private void mapAllTenantResolvedPolicies(TenantId gbpTenantId, EndpointGroupId epgId) { Optional<ResolvedPolicies> resolvedPoliciesOptional = DataStoreHelper.readFromDs( LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(ResolvedPolicies.class).build(), dataProvider.newReadOnlyTransaction()); if (!resolvedPoliciesOptional.isPresent() || resolvedPoliciesOptional.get().getResolvedPolicy() == null) { return; } List<ResolvedPolicy> resolvedPolicies = resolvedPoliciesOptional.get().getResolvedPolicy(); for (ResolvedPolicy policy : resolvedPolicies) { if (policy.getConsumerTenantId().equals(gbpTenantId)) { if (epgId == null || epgId.equals(policy.getConsumerEpgId()) || epgId.equals(policy.getProviderEpgId())) { // if any epg or a specific epg policy updateLogicalNetwork(policy); } } } }
@VisibleForTesting void registerFollowedEndpointgroup(TenantId gbpTenantId, EndpointGroupId epgId) { if (epgId == null) { return; } FollowedEndpointGroupBuilder fEpgBuilder = new FollowedEndpointGroupBuilder(); fEpgBuilder.setId(epgId); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.followedEndpointgroupIid(rendererName, gbpTenantId, epgId), fEpgBuilder.build()); if (DataStoreHelper.submitToDs(wTx)) { LOG.trace("EPG {} in Tenant {} is followed by renderer {}", epgId.getValue(), gbpTenantId.getValue(), rendererName.getValue()); } else { LOG.info("Couldn't register EPG {} in Tenant {} that is followed by renderer {}", epgId.getValue(), gbpTenantId.getValue(), rendererName.getValue()); } }
@Override public void onDeleted( org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet neutronSubnet, Neutron oldNeutron, Neutron newNeutron) { LOG.trace("deleted subnet - {}", neutronSubnet); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); NetworkDomainId subnetId = new NetworkDomainId(neutronSubnet.getUuid().getValue()); TenantId tenantId = new TenantId(neutronSubnet.getTenantId().getValue()); Optional<NetworkDomain> 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(); return; } removeTenantSubnet(tenantId, new SubnetId(subnetId), rwTx); // TODO remove default gateway EP in case when subnet is in provider physical network DataStoreHelper.submitToDs(rwTx); }
LogicalNetworks logicalNetworks = op3.get(); for (LogicalNetwork ln : logicalNetworks.getLogicalNetwork()) { if (ln.getConsumerTenantId().equals(gbpTenantId) || ln.getProviderTenantId().equals(gbpTenantId)) { removeLogicalNetwork(ln.getConsumerEpgId(), ln.getConsumerTenantId(), ln.getContractId(), ln.getProviderEpgId(), ln.getProviderTenantId());