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); }
@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); }
@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); }
@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); }
@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 AddressEndpointRegBuilder createBasicL3AddrEpInputBuilder(Port port, NetworkDomainId networkContainment, @Nullable List<EndpointGroupId> endpointGroupsToAdd, Neutron neutron) { Optional<FixedIps> firstFixedIps = PortUtils.resolveFirstFixedIps(port); if (!firstFixedIps.isPresent()) { throw new IllegalStateException("Failed to resolve FixedIps for port " + port.getKey() + ". Cannot register L3 Address endpoint."); } ContextId resolveL3ContextForPort = resolveL3ContextForPort(port, port.getFixedIps().get(0), neutron); AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder().setAddressType(MacAddressType.class) .setAddress(MappingUtils.ipAddressToStringIpPrefix(firstFixedIps.get().getIpAddress())) .setAddressType(IpPrefixType.class) .setContextType(MappingUtils.L3_CONTEXT) .setContextId(resolveL3ContextForPort) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); List<EndpointGroupId> epgs = concatEndpointGroups(port.getSecurityGroups(), endpointGroupsToAdd); addrEpbuilder.setEndpointGroup(epgs); if (networkContainment != null) { addrEpbuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(networkContainment) .setNetworkDomainType(MappingUtils.SUBNET) .build()).build()); } return addrEpbuilder; }
@Override public void onCreated(Router router, Neutron neutron) { LOG.trace("created router - {}", router); ContextId routerl3ContextId = new ContextId(router.getUuid().getValue()); TenantId tenantId = new TenantId(router.getTenantId().getValue()); InstanceIdentifier<ForwardingContext> routerL3CtxIid = L2L3IidFactory.l3ContextIid(tenantId, routerl3ContextId); ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder(); Name routerName = null; if (!Strings.isNullOrEmpty(router.getName())) { try { routerName = new Name(router.getName()); fwdCtxBuilder.setName(routerName); } catch (Exception e) { LOG.info("Name '{}' of Neutron Subnet '{}' is ignored.", router.getName(), router.getUuid().getValue()); LOG.debug("Name exception", e); } } 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); }
public boolean addNeutronSecurityGroup(SecurityGroup secGroup, ReadWriteTransaction rwTx) { TenantId tId = 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); } EndpointGroupBuilder epgBuilder = new EndpointGroupBuilder().setId(epgId); if (!Strings.isNullOrEmpty(secGroup.getName())) { try { epgBuilder.setName(new Name(secGroup.getName())); } catch (Exception 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), epgBuilder.build(), true); return true; }
LOG.trace("created subnet - {}", neutronSubnet); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); TenantId tenantId = new TenantId(neutronSubnet.getTenantId().getValue());
TenantId tenantId = new TenantId(newRouter.getTenantId().getValue()); ContextId routerL3CtxId = new ContextId(newRouter.getUuid().getValue());
private AddressEndpointRegBuilder createBasicMacAddrEpInputBuilder(Port port, NetworkDomainId networkContainment, @Nullable List<EndpointGroupId> endpointGroupsToAdd) { AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder().setAddressType(MacAddressType.class) .setAddress(port.getMacAddress().getValue()) .setAddressType(MacAddressType.class) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN) .setContextId(new ContextId(port.getNetworkId().getValue())) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); List<EndpointGroupId> epgs = concatEndpointGroups(port.getSecurityGroups(), endpointGroupsToAdd); addrEpbuilder.setEndpointGroup(epgs); if (networkContainment != null) { addrEpbuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(networkContainment) .setNetworkDomainType(MappingUtils.SUBNET) .build()).build()); } return addrEpbuilder; }
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());
TenantId tenantId = new TenantId(port.getTenantId().getValue()); Optional<Subnet> potentialRouterPortSubnet = SubnetUtils.findSubnet(portIpWithSubnet.getSubnetId(), neutron.getSubnets()); if (!potentialRouterPortSubnet.isPresent()) {
TenantId tenantId = new TenantId(port.getTenantId().getValue()); Optional<Subnet> potentialRouterPortSubnet = SubnetUtils.findSubnet(portIpWithSubnet.getSubnetId(), oldNeutron.getSubnets());
public boolean deleteNeutronSecurityRule(SecurityRule secRule, Neutron neutron, ReadWriteTransaction rwTx) { TenantId tenantId = new TenantId(secRule.getTenantId().getValue()); Uuid providerSecGroupId = secRule.getSecurityGroupId(); EndpointGroupId providerEpgId = new EndpointGroupId(providerSecGroupId.getValue()); SelectorName providerSelector = getSelectorNameWithConsumer(secRule, neutron); deleteProviderNamedSelectorFromEpg(providerSelector, new EpgKeyDto(providerEpgId, tenantId), rwTx); if (secRule.getRemoteGroupId() != null) { Uuid consumerSecGroupId = secRule.getRemoteGroupId(); 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); } } ContractId contractId = SecRuleEntityDecoder.getContractId(secRule); rwTx.delete(LogicalDatastoreType.CONFIGURATION, IidFactory.contractIid(tenantId, contractId)); ClassifierInstance classifierInstance = SecRuleEntityDecoder.getClassifierInstance(secRule); deleteClassifierInstanceIfNotUsed(tenantId, classifierInstance, rwTx); return true; }
public boolean addNeutronSecurityRuleWithAction(SecurityRule secRule, Neutron neutron, ActionChoice action, ReadWriteTransaction rwTx) { TenantId tenantId = new TenantId(secRule.getTenantId().getValue()); Uuid providerSecGroupId = secRule.getSecurityGroupId(); EndpointGroupId providerEpgId = new EndpointGroupId(providerSecGroupId.getValue()); Description contractDescription = createContractDescription(secRule, neutron); SingleRuleContract singleRuleContract = createSingleRuleContract(secRule, contractDescription, action); Contract contract = singleRuleContract.getContract(); 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); if (secRule.getRemoteGroupId() != null) { Uuid consumerSecGroupId = secRule.getRemoteGroupId(); designContractsBetweenProviderAndConsumer(tenantId, providerSecGroupId, consumerSecGroupId, neutron, rwTx); 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); } } ClassifierInstance classifierInstance = singleRuleContract.getSingleClassifierRule().getClassifierInstance(); createClassifierInstanceIfNotExists(tenantId, classifierInstance, rwTx); createAllowActionInstanceIfNotExists(tenantId, rwTx); return true; }