private ChildEndpoint createChildEndpoint(AddressEndpointRegBuilder builder) { return new ChildEndpointBuilder().setAddress(builder.getAddress()) .setAddressType(builder.getAddressType()) .setContextId(builder.getContextId()) .setContextType(builder.getContextType()) .build(); }
private boolean registerExternalGateway(TenantId tenantId, IpPrefix ipPrefix, ContextId routerl3ContextId, NetworkDomainId networkDomainId) { AddressEndpointRegBuilder addrEpBuilder = new AddressEndpointRegBuilder(); addrEpBuilder.setAddressType(IpPrefixType.class); addrEpBuilder.setAddress(MappingUtils.ipPrefixToStringIpAddress(ipPrefix)); addrEpBuilder.setContextId(routerl3ContextId); addrEpBuilder.setContextType(MappingUtils.L3_CONTEXT); addrEpBuilder.setTenant(tenantId); addrEpBuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(networkDomainId).build()).build()); addrEpBuilder.setEndpointGroup(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID)); addrEpBuilder.setTimestamp(System.currentTimeMillis()); return epRegistrator.registerEndpoint(addrEpBuilder.build()); }
private ListenableFuture<RpcResult<Void>> chainL3EPServiceIfEpAbsent(final RegisterEndpointInput epInput) { AddressEndpointReg addressEndpoint = epInput.getAddressEndpointReg().get(0); CheckedFuture<Optional<AddressEndpoint>, ReadFailedException> existingEndpointFuture = findExistingEndPoint(addressEndpoint.getContextId(), addressEndpoint.getAddress()); return Futures.transform(existingEndpointFuture, new AsyncFunction<Optional<AddressEndpoint>, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(final Optional<AddressEndpoint> input) throws Exception { final ListenableFuture<RpcResult<Void>> nextResult; if (input == null || !input.isPresent() || !isSameEpg(epInput, input.get())) { // invoke service return JdkFutureAdapters.listenInPoolThread(l3EndpointService.registerEndpoint(epInput)); } else { final String existingL3EpMsg = String.format("address-endpoint for given key already exists: %s | %s", addressEndpoint.getContextId(), addressEndpoint.getAddress() ); nextResult = Futures.immediateFailedFuture(new IllegalStateException(existingL3EpMsg)); } return nextResult; } }); }
private void registerBaseEndpointAndStoreMapping(List<AddressEndpointReg> addrEpRegs, Port port, WriteTransaction wTx) { RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder().setAddressEndpointReg(addrEpRegs) .build(); boolean isRegisteredBaseEndpoint = epRegistrator.registerEndpoint(regBaseEpInput); if (!isRegisteredBaseEndpoint) { LOG.error("Failed to register an address endpoint: {}", addrEpRegs); return; } for (AddressEndpointReg addrEpReg : addrEpRegs) { if (MappingUtils.L2_BRDIGE_DOMAIN.equals(addrEpReg.getContextType())) { UniqueId portId = new UniqueId(port.getUuid().getValue()); LOG.trace("Adding Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid()); AddressEndpointKey addrEpKey = new AddressEndpointKey(addrEpReg.getAddress(), addrEpReg.getAddressType(), addrEpReg.getContextId(), addrEpReg.getContextType()); addBaseEndpointMappings(addrEpKey, portId, wTx); } } }
private void setParentChildRelationshipForEndpoints(AddressEndpointRegBuilder parentEp, AddressEndpointRegBuilder childEp) { childEp.setParentEndpointChoice(new ParentEndpointCaseBuilder().setParentEndpoint( ImmutableList.<ParentEndpoint>of(createParentEndpoint(parentEp))).build()); parentEp.setChildEndpoint(ImmutableList.<ChildEndpoint>of(createChildEndpoint(childEp))); }
ImmutableList.of(l2BaseEp.build(), l3BaseEp.build()), port, rwTx); registerEndpointAndStoreMapping(epInBuilder.build(), port, rwTx); ImmutableList.of(l2BaseEp.build(), l3BaseEp.build()), port, rwTx); registerEndpointAndStoreMapping(epInBuilder.build(), port, rwTx); DataStoreHelper.submitToDs(rwTx); baseEpRegs.add(l2BaseEp.build()); if (l3BaseEp != null) { baseEpRegs.add(l3BaseEp.build());
private boolean isSameEpg(RegisterEndpointInput epInput, AddressEndpoint input) { if (epInput == null || epInput.getAddressEndpointReg() == null || epInput.getAddressEndpointReg().isEmpty()) { return true; } final AddressEndpointReg epInputAddressEndpoint = epInput.getAddressEndpointReg().get(0); if (epInputAddressEndpoint.getEndpointGroup() == null || epInputAddressEndpoint.getEndpointGroup().isEmpty()) { return true; } if (input == null || input.getEndpointGroup() == null || input.getEndpointGroup().isEmpty()) { return true; } final EndpointGroupId addressEndpointGroupId = epInputAddressEndpoint.getEndpointGroup().get(0); final EndpointGroupId existingEndpointGroupId = input.getEndpointGroup().get(0); return addressEndpointGroupId.equals(existingEndpointGroupId); }
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; }
private ParentEndpoint createParentEndpoint(AddressEndpointRegBuilder builder) { return new ParentEndpointBuilder().setAddress(builder.getAddress()) .setAddressType(builder.getAddressType()) .setContextId(builder.getContextId()) .setContextType(builder.getContextType()) .build(); }
@Override public ListenableFuture<RpcResult<Void>> apply(final Optional<AddressEndpoint> input) throws Exception { final ListenableFuture<RpcResult<Void>> nextResult; if (input == null || !input.isPresent() || !isSameEpg(epInput, input.get())) { // invoke service return JdkFutureAdapters.listenInPoolThread(l3EndpointService.registerEndpoint(epInput)); } else { final String existingL3EpMsg = String.format("address-endpoint for given key already exists: %s | %s", addressEndpoint.getContextId(), addressEndpoint.getAddress() ); nextResult = Futures.immediateFailedFuture(new IllegalStateException(existingL3EpMsg)); } return nextResult; } });
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; }
networkContainment, endpointGroupIds, neutron); setParentChildRelationshipForEndpoints(l3BaseEp, l2BaseEp); AddressEndpointUnreg addrEpUnreg = new AddressEndpointUnregBuilder().setAddress(l3BaseEp.getAddress()) .setAddressType(l3BaseEp.getAddressType()) .setContextId(new ContextId(portInSameSubnet.getNetworkId().getValue())) .setContextType(l3BaseEp.getContextType()) .build(); epRegistrator.unregisterEndpoint(addrEpUnreg); epRegistrator.registerEndpoint(l3BaseEp.build()); modifyL3ContextForEndpoints(portInSameSubnet, ipWithSubnet, l3BaseEp.getContextId());
@Override public ListenableFuture<RpcResult<Void>> processTemplatesAndSxpMasterDB( final EndpointPolicyTemplateBySgt epPolicyTemplate, final EndpointForwardingTemplateBySubnet epForwardingTemplate, final MasterDatabaseBinding masterDBBinding) { LOG.debug("processing ep-templates + sxpMasterDB entry: {} - {}", masterDBBinding.getSecurityGroupTag(), masterDBBinding.getIpPrefix()); // apply sxpMasterDB to policy template final Ipv4Prefix address = new Ipv4Prefix(epForwardingTemplate.getIpPrefix().getIpv4Prefix().getValue()); final NetworkContainment networkContainment = new NetworkContainmentBuilder() .setContainment(new NetworkDomainContainmentBuilder() .setNetworkDomainType(epForwardingTemplate.getNetworkContainment().getNetworkDomainType()) .setNetworkDomainId(epForwardingTemplate.getNetworkContainment().getNetworkDomainId()) .build()) .build(); final RegisterEndpointInput epInput = new RegisterEndpointInputBuilder().setAddressEndpointReg( Collections.singletonList(new AddressEndpointRegBuilder().setAddressType(IpPrefixType.class) .setAddress(address.getValue()) .setContextType(L3Context.class) .setContextId(epForwardingTemplate.getL3Context()) .setNetworkContainment(networkContainment) .setCondition(epPolicyTemplate.getConditions()) .setTenant(epPolicyTemplate.getTenant()) .setEndpointGroup(epPolicyTemplate.getEndpointGroups()) .build())) .build(); epForwardingTemplate.getL3Context(); return chainL3EPServiceIfEpAbsent(epInput); }