diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java index 7aa17161e..f989149bd 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java @@ -43,11 +43,15 @@ public class LocalCacheImpl implements LocalCache { @Autowired private SubnetPortsCache subnetPortsCache; + @Autowired + private PortHostInfoCache portHostInfoCache; + @Autowired private NodeInfoCache nodeInfoCache; @Override public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception { + List portEntities = networkConfig.getPortEntities(); if (portEntities == null) { return; @@ -70,6 +74,7 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception portHostInfo.setPortId(portEntity.getId()); portHostInfo.setHostIp(portEntity.getBindingHostIP()); portHostInfo.setHostId(portEntity.getBindingHostId()); + portHostInfo.setSubnetId(subnetId); InternalSubnetPorts subnetPorts = subnetPortsMap.get(subnetId); if (subnetPorts == null) { @@ -85,7 +90,6 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception subnetPorts.setVpcId(subnetEntity.getVpcId()); subnetPorts.setTunnelId(subnetEntity.getTunnelId()); subnetPorts.setDhcpEnable(subnetEntity.getDhcpEnable()); - subnetPorts.setPorts(new ArrayList<>()); List routers = networkConfig.getInternalRouterInfos(); if (routers != null && routers.size() > 0) { @@ -106,14 +110,13 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception subnetPortsMap.put(subnetId, subnetPorts); } - - subnetPorts.getPorts().add(portHostInfo); } } for (Map.Entry entry: subnetPortsMap.entrySet()) { subnetPortsCache.updateSubnetPorts(entry.getValue()); } + } private InternalSubnetEntity getSubnetEntity(NetworkConfiguration networkConfig, String subnetId) throws Exception { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java new file mode 100644 index 000000000..7c10f54d0 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java @@ -0,0 +1,87 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package com.futurewei.alcor.dataplane.cache; + +import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.db.CacheFactory; +import com.futurewei.alcor.common.db.ICache; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; +import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Repository +@ComponentScan(value="com.futurewei.alcor.common.db") +public class PortHostInfoCache { + + private ICache portHostInfoCache; + private CacheFactory cacheFactory; + + @Autowired + public PortHostInfoCache(CacheFactory cacheFactory) { + this.cacheFactory = cacheFactory; + portHostInfoCache = cacheFactory.getCache(PortHostInfo.class); + } + + public Map getPortHostInfo(NetworkConfiguration networkConfig) { + Map portHostInfoMap = networkConfig + .getPortEntities() + .stream() + .filter(portEntity -> portEntity.getFixedIps().size() > 0) + .flatMap(portEntity -> portEntity.getFixedIps() + .stream() + .filter(fixedIp -> fixedIp != null) + .map(fixedIp -> new PortHostInfo(portEntity.getId() + , fixedIp.getIpAddress() + , portEntity.getMacAddress() + , portEntity.getBindingHostId() + , portEntity.getBindingHostIP() + , fixedIp.getSubnetId()))) + .collect(Collectors.toMap(portHostInfo -> portHostInfo.getSubnetId() + cacheFactory.KEY_DELIMITER + portHostInfo.getPortIp(), Function.identity())); + return portHostInfoMap; + } + + public void updatePortHostInfo(Map portHostInfoMap) throws CacheException { + portHostInfoCache.putAll(portHostInfoMap); + } + + public synchronized Collection getPortHostInfos(String subnetId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = subnetId; + queryParams.put("subnetId", values); + // Use sql index + return portHostInfoCache.getAll(queryParams).values(); + } + + public synchronized PortHostInfo getPortHostInfoByIp(String subnetId, String ip) throws CacheException { + return portHostInfoCache.get(subnetId + cacheFactory.KEY_DELIMITER + ip); + } + + public synchronized void deletePortHostInfo(String subnetId, String portIp) throws CacheException { + portHostInfoCache.remove(subnetId + cacheFactory.KEY_DELIMITER + portIp); + } + +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java index 78fea3d7a..1d96e5ece 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java @@ -20,89 +20,62 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.ICache; import com.futurewei.alcor.common.db.repo.ICacheRepository; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @Slf4j @Repository @ComponentScan(value="com.futurewei.alcor.common.db") -public class RouterSubnetsCache implements ICacheRepository { +public class RouterSubnetsCache { // The cache is a map(routerId, subnetIds) - private final ICache routerSubnetsCache; + private final ICache routerSubnetsCache; + private CacheFactory cacheFactory; @Autowired public RouterSubnetsCache(CacheFactory cacheFactory) { - this.routerSubnetsCache = cacheFactory.getCache(InternalSubnets.class); + this.cacheFactory = cacheFactory; + this.routerSubnetsCache = cacheFactory.getCache(InternalSubnetRouterMap.class); } @DurationStatistics - public InternalSubnets getRouterSubnets(String routerId) throws CacheException { - return routerSubnetsCache.get(routerId); - } + public Collection getRouterSubnets(String routerId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = routerId; + queryParams.put("routerId", values); + return routerSubnetsCache.getAll(queryParams).values(); - @DurationStatistics - public Map getAllSubnets() throws CacheException { - return routerSubnetsCache.getAll(); - } - - @DurationStatistics - public Map getAllSubnets(Map queryParams) throws CacheException { - return routerSubnetsCache.getAll(queryParams); } @DurationStatistics - public synchronized void addVpcSubnets(InternalSubnets subnets) throws CacheException { - routerSubnetsCache.put(subnets.getRouterId(), subnets); + public Collection updateVpcSubnets(NetworkConfiguration networkConfig) throws CacheException { + Map internalSubnetsMap = networkConfig + .getInternalRouterInfos() + .stream() + .filter(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables().size() > 0) + .flatMap(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables() + .stream() + .map(routingTable -> new InternalSubnetRouterMap(routerInfo.getRouterConfiguration().getId() + , routingTable.getSubnetId()))) + .collect(Collectors.toMap(routerInfo -> routerInfo.getRouterId() + cacheFactory.KEY_DELIMITER + routerInfo.getSubnetId(), Function.identity())); + routerSubnetsCache.putAll(internalSubnetsMap); + return internalSubnetsMap.values(); } @DurationStatistics - public void updateVpcSubnets(InternalSubnets subnets) throws CacheException { - routerSubnetsCache.put(subnets.getRouterId(), subnets); - } - - @DurationStatistics - public void deleteVpcGatewayInfo(String routerId) throws CacheException { - routerSubnetsCache.remove(routerId); - } - - @Override - public InternalSubnets findItem(String id) throws CacheException { - return routerSubnetsCache.get(id); + public void deleteVpcGatewayInfo(String routerId, String subnetId) throws CacheException { + routerSubnetsCache.remove(routerId + cacheFactory.KEY_DELIMITER + subnetId); } - @Override - public Map findAllItems() throws CacheException { - return routerSubnetsCache.getAll(); - } - @Override - public Map findAllItems(Map queryParams) throws CacheException { - return routerSubnetsCache.getAll(queryParams); - } - - @Override - public void addItem(InternalSubnets subnets) throws CacheException { - log.debug("Add Subnets {} to Router {}", subnets.toString(), subnets.getRouterId()); - routerSubnetsCache.put(subnets.getRouterId(), subnets); - } - - @Override - public void addItems(List items) throws CacheException { - Map subnetsMap = items.stream().collect(Collectors.toMap(InternalSubnets::getRouterId, Function.identity())); - routerSubnetsCache.putAll(subnetsMap); - } - - @Override - public void deleteItem(String id) throws CacheException { - log.debug("Delete Router {}", id); - routerSubnetsCache.remove(id); - } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 52f24fd1d..33d5bc970 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -18,22 +18,34 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.common.db.CacheFactory; import com.futurewei.alcor.common.db.ICache; +import com.futurewei.alcor.common.db.Transaction; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; +import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.schema.Subnet; +import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; -import java.util.Map; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; @Repository @ComponentScan(value="com.futurewei.alcor.common.db") public class SubnetPortsCache { // The cache is a map(subnetId, subnetPorts) private ICache subnetPortsCache; + private CacheFactory cacheFactory; @Autowired public SubnetPortsCache(CacheFactory cacheFactory) { + this.cacheFactory = cacheFactory; subnetPortsCache = cacheFactory.getCache(InternalSubnetPorts.class); } @@ -42,6 +54,16 @@ public InternalSubnetPorts getSubnetPorts(String subnetId) throws CacheException return subnetPortsCache.get(subnetId); } + @DurationStatistics + public Map getSubnetPortsByRouterId(String routerId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = routerId; + queryParams.put("routerId", values); + // Use sql index + return subnetPortsCache.getAll(queryParams); + } + @DurationStatistics public Map getAllSubnetPorts() throws CacheException { return subnetPortsCache.getAll(); @@ -57,6 +79,74 @@ public synchronized void addSubnetPorts(InternalSubnetPorts internalSubnetPorts) subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); } + @DurationStatistics + public Map getInternalSubnetRouterMap(NetworkConfiguration networkConfig) { + if (networkConfig.getInternalRouterInfos() != null) { + Map internalSubnetsRouterMap = networkConfig + .getInternalRouterInfos() + .stream() + .filter(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables().size() > 0) + .flatMap(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables() + .stream() + .map(routingTable -> new InternalSubnetRouterMap(routerInfo.getRouterConfiguration().getId() + , routingTable.getSubnetId()))) + .distinct() + .collect(Collectors.toMap(routerInfo -> routerInfo.getSubnetId(), routerInfo -> routerInfo.getRouterId())); + return internalSubnetsRouterMap; + } + return new HashMap<>(); + } + + @DurationStatistics + public Map attacheRouter(Map subnetIdRouterIdMap) throws CacheException { + Map internalSubnetEntityMap = new TreeMap<>(); + for (Map.Entry subnetIdRouterId : subnetIdRouterIdMap.entrySet()) { + InternalSubnetPorts internalSubnetPorts = null; + try { + if (subnetPortsCache.containsKey(subnetIdRouterId.getKey())) { + internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); + internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); + internalSubnetEntityMap.put(subnetIdRouterId.getKey(), internalSubnetPorts); + } + } catch (CacheException e) { + e.printStackTrace(); + } + } + + subnetPortsCache.putAll(internalSubnetEntityMap); + return internalSubnetEntityMap; + } + + + @DurationStatistics + public Map getSubnetPorts(NetworkConfiguration networkConfig) throws CacheException { + Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); + Map internalSubnetPortsMap = new TreeMap<>(); + for (InternalSubnetEntity subnetEntity : networkConfig.getSubnets()) { + internalSubnetPortsMap.put(subnetEntity.getId(), getInternalSubnetPorts(subnetEntity, internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null))); + } + return internalSubnetPortsMap; + } + + private InternalSubnetPorts getInternalSubnetPorts(InternalSubnetEntity subnetEntity, String routerId) { + InternalSubnetPorts internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() + ,subnetEntity.getGatewayPortDetail().getGatewayPortId() + ,subnetEntity.getGatewayIp() + ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() + ,subnetEntity.getName() + ,subnetEntity.getCidr() + ,subnetEntity.getVpcId() + ,subnetEntity.getTunnelId() + ,subnetEntity.getDhcpEnable() + ,routerId); + return internalSubnetPorts; + } + + @DurationStatistics + public void updateSubnetPorts(Map internalSubnetPortsMap) throws Exception { + subnetPortsCache.putAll(internalSubnetPortsMap); + } + @DurationStatistics public void updateSubnetPorts(InternalSubnetPorts internalSubnetPorts) throws Exception { subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); @@ -67,4 +157,8 @@ public void deleteSubnetPorts(String subnetId) throws Exception { subnetPortsCache.remove(subnetId); } + public Transaction getTransaction() { + return subnetPortsCache.getTransaction(); + } + } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java new file mode 100644 index 000000000..375bf1459 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java @@ -0,0 +1,58 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package com.futurewei.alcor.dataplane.entity; + +import com.futurewei.alcor.web.entity.route.RouteEntry; + +public class InternalSubnetRouterMap { + private String routerId; + private String subnetId; + + public InternalSubnetRouterMap() { }; + + public InternalSubnetRouterMap(String routerId, String subnetId) { + this.routerId = routerId; + this.subnetId = subnetId; + } + + public void setRouterId(String routerId) { this.routerId = routerId; } + + public void setSubnetIds(String subnetId) { + this.subnetId = subnetId; + } + + public String getRouterId() { return this.routerId; } + + public String getSubnetId() { + return this.subnetId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + //if (!super.equals(o)) return false; + InternalSubnetRouterMap internalSubnetRouterMap = (InternalSubnetRouterMap) o; + return routerId.equals(internalSubnetRouterMap.routerId) && subnetId.equals(internalSubnetRouterMap.subnetId); + } + + @Override + public int hashCode() + { + return 31 * subnetId.hashCode() + routerId.hashCode(); + } +} \ No newline at end of file diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java index 6a786455a..a55e0d673 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java @@ -20,10 +20,12 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class MulticastGoalStateV2 { - private List hostIps; + private Set hostIps; private List vpcIds; private List topics; private List subTopics; @@ -32,26 +34,26 @@ public class MulticastGoalStateV2 { private GoalStateV2.Builder goalStateBuilder; public MulticastGoalStateV2() { - hostIps = new ArrayList<>(); + hostIps = new HashSet<>(); goalStateBuilder = GoalStateV2.newBuilder(); } - public MulticastGoalStateV2(List hostIps, GoalStateV2 goalState) { + public MulticastGoalStateV2(Set hostIps, GoalStateV2 goalState) { this.hostIps = hostIps; this.goalState = goalState; } - public MulticastGoalStateV2(List hostIps, List vpcIds, GoalStateV2 goalState) { + public MulticastGoalStateV2(Set hostIps, List vpcIds, GoalStateV2 goalState) { this.hostIps = hostIps; this.vpcIds = vpcIds; this.goalState = goalState; } - public List getHostIps() { + public Set getHostIps() { return hostIps; } - public void setHostIps(List hostIps) { + public void setHostIps(Set hostIps) { this.hostIps = hostIps; } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java index dd19d7aa3..34a8adb38 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java @@ -37,6 +37,11 @@ public UnicastGoalStateV2(String hostIp, GoalStateV2 goalState) { this.goalState = goalState; } + public UnicastGoalStateV2(String hostIp, GoalStateV2.Builder goalStateBuilder) { + this.hostIp = hostIp; + this.goalStateBuilder = goalStateBuilder; + } + public UnicastGoalStateV2(String hostIp, String vpcId, GoalStateV2 goalState) { this.hostIp = hostIp; this.vpcId = vpcId; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index b875652b8..0271d0500 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -16,10 +16,9 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.dataplane.service.impl; import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.db.Transaction; import com.futurewei.alcor.common.tracer.Tracer; -import com.futurewei.alcor.dataplane.cache.LocalCache; -import com.futurewei.alcor.dataplane.cache.SubnetPortsCache; -import com.futurewei.alcor.dataplane.cache.VpcGatewayInfoCache; +import com.futurewei.alcor.dataplane.cache.*; import com.futurewei.alcor.dataplane.client.DataPlaneClient; import com.futurewei.alcor.dataplane.client.ZetaGatewayClient; import com.futurewei.alcor.dataplane.config.Config; @@ -103,6 +102,12 @@ public class DpmServiceImplV2 implements DpmService { @Autowired private RouterService routerService; + @Autowired + private RouterSubnetsCache routerSubnetsCache; + + @Autowired + private PortHostInfoCache portHostInfoCache; + @Autowired private DpmServiceImplV2(Config globalConfig) { this.goalStateMessageVersion = globalConfig.goalStateMessageVersion; @@ -119,13 +124,26 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon portService.buildPortState(networkConfig, portEntities, unicastGoalState); } + Map internalSubnetPorts = subnetPortsCache.getSubnetPorts(networkConfig); + Map portHostInfoMap = portHostInfoCache.getPortHostInfo(networkConfig); + synchronized (this) { + try(Transaction tx = subnetPortsCache.getTransaction().start()) { + subnetPortsCache.updateSubnetPorts(internalSubnetPorts); + portHostInfoCache.updatePortHostInfo(portHostInfoMap); + tx.commit(); + } + } + vpcService.buildVpcStates(networkConfig, unicastGoalState); - subnetService.buildSubnetStates(networkConfig, unicastGoalState, multicastGoalState); - neighborService.buildNeighborStates(networkConfig, hostIp, unicastGoalState, multicastGoalState); + subnetService.buildSubnetStates(networkConfig, unicastGoalState); securityGroupService.buildSecurityGroupStates(networkConfig, unicastGoalState); dhcpService.buildDhcpStates(networkConfig, unicastGoalState); - routerService.buildRouterStates(networkConfig, unicastGoalState, multicastGoalState); - patchGoalstateForNeighbor(networkConfig, unicastGoalState); + routerService.buildRouterStates(networkConfig, unicastGoalState); + + neighborService.buildNeighborStatesL2(unicastGoalState, multicastGoalState, networkConfig.getOpType()); + if (networkConfig.getInternalRouterInfos() != null) { + neighborService.buildNeighborStatesL3(networkConfig, unicastGoalState, multicastGoalState); + } unicastGoalState.setGoalState(unicastGoalState.getGoalStateBuilder().build()); unicastGoalState.setGoalStateBuilder(null); @@ -135,86 +153,6 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon return unicastGoalState; } - private void patchGoalstateForNeighbor(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws CacheException { - Map neighborStatesMap = unicastGoalState.getGoalStateBuilder().getNeighborStatesMap(); - for (Map.Entry neighborStateEntry : neighborStatesMap.entrySet()) { - List fixedIps = neighborStateEntry.getValue().getConfiguration().getFixedIpsList(); - for (Neighbor.NeighborConfiguration.FixedIp fixedIp : fixedIps) { - if (fixedIp != null && fixedIp.getNeighborType().equals(Neighbor.NeighborType.L3)) { - String subnetId = fixedIp.getSubnetId(); - InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); - if (subnetEntity != null) { - if (unicastGoalState.getGoalStateBuilder().getSubnetStatesMap().entrySet().stream() - .filter(e -> e.getValue().getConfiguration().getId().equals(subnetEntity.getSubnetId())) - .findFirst().orElse(null) == null) { - Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); - subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - subnetConfigBuilder.setId(subnetEntity.getSubnetId()); - subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); - subnetConfigBuilder.setName(subnetEntity.getName()); - subnetConfigBuilder.setCidr(subnetEntity.getCidr()); - subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); - - Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); - gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); - gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); - subnetConfigBuilder.setGateway(gatewayBuilder.build()); - - if (subnetEntity.getDhcpEnable() != null) { - subnetConfigBuilder.setDhcpEnable(subnetEntity.getDhcpEnable()); - } - - // TODO: need to set DNS based on latest contract - - Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); - subnetStateBuilder.setOperationType(Common.OperationType.INFO); - subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putSubnetStates(subnetEntity.getSubnetId(), subnetStateBuilder.build()); - - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetEntity.getSubnetId()); - - List subnetRoutingTablesList = new ArrayList<>(); - subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - - Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState.getGoalStateBuilder(); - List routerStatesBuilders = new ArrayList<>(goalStateBuilder.getRouterStatesMap().values()); - - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTablesList.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - } - - String routerId = subnetEntity.getRouterId(); - // If subnet has attached to a router (test scenario #4), we just use the routerId in the subnet. - // Otherwise, we need to get router_state in the networkConfig for test scenario #5. - if (routerId == null) { - List internalRouterInfos = networkConfig.getInternalRouterInfos(); - for (InternalRouterInfo internalRouterInfo : internalRouterInfos) { - routerId = internalRouterInfo.getRouterConfiguration().getId(); - if (routerId != null) break; - } - } - - // Add subnet to router_state - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - routerConfigBuilder.setHostDvrMacAddress(HOST_DVR_MAC); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTablesList); - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); - } - } - } - } - } - } - private List doCreatePortConfiguration(NetworkConfiguration networkConfig, Map> hostPortEntities, DataPlaneClient dataPlaneClient) throws Exception { @@ -309,126 +247,6 @@ private List processPortConfiguration(NetworkConfiguration networkConfig return statusList; } - private Subnet.SubnetState.Builder constructSubnetState(InternalSubnetPorts subnetEntity) { - Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); - - if (subnetEntity != null) { - Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); - subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - subnetConfigBuilder.setId(subnetEntity.getSubnetId()); - subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); - subnetConfigBuilder.setName(subnetEntity.getName()); - subnetConfigBuilder.setCidr(subnetEntity.getCidr()); - subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); - - Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); - gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); - gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); - subnetConfigBuilder.setGateway(gatewayBuilder.build()); - - if (subnetEntity.getDhcpEnable() != null) { - subnetConfigBuilder.setDhcpEnable(subnetEntity.getDhcpEnable()); - } - - // TODO: need to set DNS based on latest contract - subnetStateBuilder.setOperationType(Common.OperationType.INFO); - subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - } - - return subnetStateBuilder; - } - - private void patchGoalstateForRouterSubnet(NetworkConfiguration networkConfig, Map> hostsSubnets, MulticastGoalStateV2 multicastGoalState) throws CacheException { - for (Map.Entry> entry: hostsSubnets.entrySet()) { - for (String subnetId : entry.getValue()) { - InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); - if (subnetEntity != null) { - if (multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().values().stream() - .filter(e -> e.getConfiguration().getId().equals(subnetEntity.getSubnetId())) - .findFirst().orElse(null) == null) { - Subnet.SubnetState.Builder subnetStateBuilder = constructSubnetState(subnetEntity); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetStateBuilder.getConfiguration().getId(), subnetStateBuilder.build()); - - // Add subnet to router_state - Goalstate.GoalStateV2.Builder goalStateBuilder = multicastGoalState.getGoalStateBuilder(); - Router.RouterState.Builder routerStateBuilder = constructRouterState(networkConfig, subnetEntity, goalStateBuilder); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerStateBuilder.getConfiguration().getId(), routerStateBuilder.build()); - } - } - } - } - } - - private Router.RouterState.Builder constructRouterState(NetworkConfiguration networkConfig, InternalSubnetPorts subnetEntity, Goalstate.GoalStateV2.Builder goalStateBuilder) { - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - if (subnetEntity != null) { - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetEntity.getSubnetId()); - - List subnetRoutingTablesList = new ArrayList<>(); - subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); - - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTablesList.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - } - - String routerId = subnetEntity.getRouterId(); - // If subnet has attached to a router (test scenario #4), we just use the routerId in the subnet. - // Otherwise, we need to get router_state in the networkConfig for test scenario #5. - if (routerId == null) { - List internalRouterInfos = networkConfig.getInternalRouterInfos(); - for (InternalRouterInfo internalRouterInfo : internalRouterInfos) { - routerId = internalRouterInfo.getRouterConfiguration().getId(); - if (routerId != null) break; - } - } - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - routerConfigBuilder.setHostDvrMacAddress(HOST_DVR_MAC); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTablesList); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - } - return routerStateBuilder; - } - - @Tracer - private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, Goalstate.GoalStateV2.Builder newGoalState) { - List subnetRoutingTables = new ArrayList<>(); - for (Router.RouterConfiguration.SubnetRoutingTable subnetRoutingTable : newGoalState.getRouterStatesMap().entrySet().iterator().next().getValue().getConfiguration().getSubnetRoutingTablesList()) { - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetRoutingTable.getSubnetId()); - subnetRoutingTables.add(subnetRoutingTableBuilder.build()); - } - - List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTables.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - String routerId = routerState.getConfiguration().getId(); - String hostDvrMac = routerState.getConfiguration().getHostDvrMacAddress(); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - - //TODO: where does the hostDvrMacAddress come from ? - routerConfigBuilder.setHostDvrMacAddress(hostDvrMac); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTables); - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - goalStateBuilder.putRouterStates(routerStateBuilder.getConfiguration().getId(), routerStateBuilder.build()); - } - } - /** * This method get neighbor information from NetworkConfiguration, then build one * UnicastGoalState for each host and fill in the neighbor information it needs, @@ -438,126 +256,26 @@ private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, * @throws Exception Process exceptions and send exceptions */ private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { - Map neighborInfos = networkConfig.getNeighborInfos(); - Map> neighborTable = networkConfig.getNeighborTable(); - List unicastGoalStates = new ArrayList<>(); + Map subnetIdRouterIdMap = subnetPortsCache.getInternalSubnetRouterMap(networkConfig); + subnetPortsCache.attacheRouter(subnetIdRouterIdMap); + Map unicastGoalStates = new HashMap<>(); MulticastGoalStateV2 multicastGoalState = new MulticastGoalStateV2(); - Map> hostsSubnets = new HashMap<>(); - - if (neighborTable == null || neighborInfos == null) { - throw new NeighborInfoNotFound(); - //return new ArrayList<>(); - } - - Map> hostNeighbors = new HashMap<>(); - for (Map.Entry> entry: neighborTable.entrySet()) { - String portIp = entry.getKey(); - NeighborInfo localInfo = neighborInfos.get(portIp); - if (localInfo == null) { - throw new NeighborInfoNotFound(); - } - - String hostIp = localInfo.getHostIp(); - if (!hostNeighbors.containsKey(hostIp)) { - hostNeighbors.put(hostIp, new ArrayList<>()); - hostsSubnets.put(hostIp, new ArrayList<>()); - } - hostsSubnets.get(hostIp).add(localInfo.getSubnetId()); - - List neighborEntries = entry.getValue(); - for (NeighborEntry neighborEntry: neighborEntries) { - String neighborIp = neighborEntry.getNeighborIp(); - NeighborInfo neighborInfo = neighborInfos.get(neighborIp); - if (neighborInfo == null) { - throw new NeighborInfoNotFound(); - } - if (!Objects.equals(neighborEntry.getNeighborType().name(), "L2")) { - hostNeighbors.get(hostIp).add(neighborInfo); - multicastGoalState.getHostIps().add(neighborInfo.getHostIp()); - } - } - - if (multicastGoalState.getHostIps().size() <= 0) { - // return new ArrayList<>(); - continue; - } - //Add neighborInfo to multicastGoalState - Neighbor.NeighborState neighborState = neighborService.buildNeighborState( - NeighborEntry.NeighborType.L3, localInfo, networkConfig.getOpType()); - multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - UnicastGoalStateV2 unicastGoalStateTemp = new UnicastGoalStateV2(); - unicastGoalStateTemp.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - patchGoalstateForNeighbor(networkConfig, unicastGoalStateTemp); - if (unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap() != null && - unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap().size() > 0 ) { - multicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - } - if (unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap() != null && - unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap().size() > 0) { - multicastGoalState.getGoalStateBuilder().putAllRouterStates(unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap()); - } - } - - boolean patchRouterSubnetStates = false; - for (Map.Entry> entry: hostNeighbors.entrySet()) { - String hostIp = entry.getKey(); - List hostNeighborInfos = entry.getValue(); - - if (hostNeighborInfos.size() <= 0) { - multicastGoalState.getHostIps().add(hostIp); - patchRouterSubnetStates = true; - } - - /** - * At present, there are only L3 neighbors in the neighbor table, - * and the processing of L2 neighbors should be considered in the future. - */ - for (NeighborInfo neighborInfo: hostNeighborInfos) { - Neighbor.NeighborState neighborState = neighborService.buildNeighborState( - NeighborEntry.NeighborType.L3, - neighborInfo, - networkConfig.getOpType()); - - UnicastGoalStateV2 unicastGoalState = new UnicastGoalStateV2(); - //unicastGoalState.setHostIp(neighborInfo.getHostIp()); - unicastGoalState.setHostIp(hostIp); - unicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - - // use unicastGoalStateTemp object to get patchGoalStates for neighborState update - // unicasGoalStateTemp will include subnet_states and a consolidated router_state based on the current neighborState - UnicastGoalStateV2 unicastGoalStateTemp = new UnicastGoalStateV2(); - unicastGoalStateTemp.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - patchGoalstateForNeighbor(networkConfig, unicastGoalStateTemp); - - unicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - unicastGoalState.getGoalStateBuilder().putAllRouterStates(unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap()); - unicastGoalState.getGoalStateBuilder().putAllSubnetStates(multicastGoalState.getGoalStateBuilder().getSubnetStatesMap()); - rebuildRouterState(unicastGoalState.getGoalStateBuilder(), multicastGoalState.getGoalStateBuilder()); - multicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - rebuildRouterState(multicastGoalState.getGoalStateBuilder(), unicastGoalStateTemp.getGoalStateBuilder()); - unicastGoalStates.add(unicastGoalState); - } - } - - /** - * The flag patchRouterSubnetStates is to fix issue #686 (issue from test scenario 4.5) - */ - if (patchRouterSubnetStates) { - patchGoalstateForRouterSubnet(networkConfig, hostsSubnets, multicastGoalState); + if (networkConfig.getInternalRouterInfos() != null) { + neighborService.buildNeighborStatesL3(networkConfig, unicastGoalStates, multicastGoalState); } multicastGoalState.setGoalState(multicastGoalState.getGoalStateBuilder().build()); multicastGoalState.setGoalStateBuilder(null); - unicastGoalStates.stream().forEach(u -> { + unicastGoalStates.values().stream().forEach(u -> { u.setGoalState(u.getGoalStateBuilder().build()); u.setGoalStateBuilder(null); }); if (USE_PULSAR_CLIENT) { - return pulsarDataPlaneClient.sendGoalStates(unicastGoalStates, multicastGoalState); + return pulsarDataPlaneClient.sendGoalStates(new ArrayList<>(unicastGoalStates.values()), multicastGoalState); } - return grpcDataPlaneClient.sendGoalStates(unicastGoalStates, multicastGoalState); + return grpcDataPlaneClient.sendGoalStates(new ArrayList<>(unicastGoalStates.values()), multicastGoalState); } private List processSecurityGroupConfiguration(NetworkConfiguration networkConfig) throws Exception { @@ -594,8 +312,8 @@ private List processRouterConfiguration(NetworkConfiguration networkConf for (InternalSubnetRoutingTable subnetRoutingTable : subnetRoutingTables) { String subnetId = subnetRoutingTable.getSubnetId(); - InternalSubnetPorts subnetPorts = localCache.getSubnetPorts(subnetId); - if (subnetPorts == null) { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(subnetId); + if (portHostInfos == null) { //throw new SubnetPortsNotFound(); //return new ArrayList<>(); continue; @@ -604,7 +322,7 @@ private List processRouterConfiguration(NetworkConfiguration networkConf subnetRoutingTable.getRoutingRules().forEach(routingRule -> {ips.add(routingRule.getNextHopIp());}); List neighbors = neighborService.getAllNeighbors(ips) ; - for (PortHostInfo portHostInfo : subnetPorts.getPorts()) { + for (PortHostInfo portHostInfo : portHostInfos) { String hostIp = portHostInfo.getHostIp(); UnicastGoalStateV2 unicastGoalState = unicastGoalStateMap.get(hostIp); if (unicastGoalState == null) { @@ -627,7 +345,7 @@ private List processRouterConfiguration(NetworkConfiguration networkConf } } - routerService.buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState, multicastGoalState); + routerService.buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState); subnetService.buildSubnetState(subnetId, unicastGoalState, multicastGoalState); } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index ca8bbbea6..216ff31b3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -15,12 +15,11 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.dataplane.service.impl; +import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.dataplane.cache.NeighborCache; +import com.futurewei.alcor.dataplane.cache.PortHostInfoCache; import com.futurewei.alcor.dataplane.cache.SubnetPortsCache; -import com.futurewei.alcor.dataplane.entity.MulticastGoalState; -import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; -import com.futurewei.alcor.dataplane.entity.UnicastGoalState; -import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.dataplane.entity.*; import com.futurewei.alcor.dataplane.exception.NeighborInfoNotFound; import com.futurewei.alcor.dataplane.exception.PortFixedIpNotFound; import com.futurewei.alcor.schema.*; @@ -30,18 +29,33 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.port.PortEntity; import com.futurewei.alcor.web.entity.port.PortHostInfo; +import com.futurewei.alcor.web.entity.route.InternalRouterInfo; +import com.futurewei.alcor.web.entity.route.InternalSubnetRoutingTable; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; +import java.util.stream.Collectors; @Service public class NeighborService extends ResourceService { + @Autowired + private PortHostInfoCache portHostInfoCache; + + @Autowired + private SubnetPortsCache subnetPortsCache; + @Autowired private NeighborCache neighborCache; + @Autowired + private SubnetService subnetService; + + @Autowired + private RouterService routerService; + public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type, NeighborInfo neighborInfo, Common.OperationType operationType) throws Exception { Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); @@ -69,6 +83,33 @@ public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type return neighborStateBuilder.build(); } + public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type, PortHostInfo portHostInfo, Common.OperationType operationType, String vpcId) throws Exception { + Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); + neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); + neighborConfigBuilder.setId(UUID.randomUUID().toString()); // TODO: We are going to need this per latest ACA change + neighborConfigBuilder.setVpcId(vpcId); + //neighborConfigBuilder.setName(); + neighborConfigBuilder.setMacAddress(portHostInfo.getPortMac()); + neighborConfigBuilder.setHostIpAddress(portHostInfo.getHostIp()); + Neighbor.NeighborType neighborType = Neighbor.NeighborType.valueOf(type.getType()); + + //TODO:setNeighborHostDvrMac + //neighborConfigBuilder.setNeighborHostDvrMac(); + Neighbor.NeighborConfiguration.FixedIp.Builder fixedIpBuilder = Neighbor.NeighborConfiguration.FixedIp.newBuilder(); + fixedIpBuilder.setSubnetId(portHostInfo.getSubnetId()); + fixedIpBuilder.setIpAddress(portHostInfo.getPortIp()); + fixedIpBuilder.setNeighborType(neighborType); + neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); + //TODO:setAllowAddressPairs + //neighborConfigBuilder.setAllowAddressPairs(); + + Neighbor.NeighborState.Builder neighborStateBuilder = Neighbor.NeighborState.newBuilder(); + neighborStateBuilder.setOperationType(operationType); + neighborStateBuilder.setConfiguration(neighborConfigBuilder.build()); + neighborCache.setNeighborState(neighborStateBuilder.build()); + return neighborStateBuilder.build(); + } + private List buildNeighborInfosByPortEntities(NetworkConfiguration networkConfig) { List neighborInfos = new ArrayList<>(); @@ -283,4 +324,173 @@ public List getAllNeighbors (Set ips) throws Exc } return neighbors; } + + public void buildNeighborStatesL2(UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2, Common.OperationType operationType) { + Collection portStates = unicastGoalStateV2.getGoalStateBuilder().getPortStatesMap().values(); + Map neighborStateMap = new TreeMap<>(); + + Set ips = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getIpAddress())) + .collect(Collectors.toSet()); + + multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); + + portStates.parallelStream().forEach(portState -> { + List subnetIds = portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId()).collect(Collectors.toList()); + + for (String subnetId : subnetIds) { + try { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(subnetId); + + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L2, portHostInfo, operationType, portState.getConfiguration().getVpcId()); + if (ips.contains(portHostInfo.getPortIp())) { + multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + } else { + multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + }); + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + if (multicastGoalStateV2.getHostIps().size() == 0){ + multicastGoalStateV2.getGoalStateBuilder().clear(); + } + } + + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2) { + Collection portStates = unicastGoalStateV2.getGoalStateBuilder().getPortStatesMap().values(); + Map neighborStateMap = new TreeMap<>(); + Map subnetStateMap = new TreeMap<>(); + Set ips = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getIpAddress())) + .collect(Collectors.toSet()); + + Set subnetIds = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId())) + .collect(Collectors.toSet()); + + multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); + + Set routerIds = subnetPortsCache.getInternalSubnetRouterMap(networkConfiguration).values().stream().collect(Collectors.toSet()); + String vpcid = unicastGoalStateV2.getGoalStateBuilder().getVpcStatesMap().values().stream().map(vpcState -> vpcState.getConfiguration().getId()).findFirst().orElse(null); + routerIds.parallelStream().forEach(routerId -> { + try { + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); + for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { + try { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); + if (subnetIds.contains(internalSubnetPort.getSubnetId()) && ips.contains(portHostInfo.getPortIp())) { + multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + } else { + multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + if (!unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap().containsKey(internalSubnetPort.getSubnetId())){ + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + String subnetId = portHostInfo.getSubnetId(); + subnetRoutingTableBuilder.setSubnetId(subnetId); + Router.RouterConfiguration.Builder routerConfigurationBuilder = unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); + routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + } catch (CacheException e) { + e.printStackTrace(); + } + }); + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); + } + + + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map unicastGoalStates, MulticastGoalStateV2 multicastGoalState) throws Exception { + String routerId = networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getId(); + Map neighborStateMap = new TreeMap<>(); + Map subnetStateMap = new TreeMap<>(); + Router.RouterConfiguration.Builder unicastRouterConfigurationBuilder = Router.RouterConfiguration.newBuilder(); + if (networkConfiguration.getSubnets().size() == 0) { + return; + } + String subnetId = networkConfiguration.getSubnets().stream().map(subnetEntity -> subnetEntity.getId()).findFirst().orElse(""); + if (subnetPortsCache.getSubnetPorts(subnetId) == null) { + return; + } + String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); + portHostInfoCache.getPortHostInfos(subnetId) + .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); + Subnet.SubnetState subnetState = subnetService.buildSubnetState(subnetId).build(); + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); + for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { + try { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); + if (subnetId.equals(internalSubnetPort.getSubnetId())) { + multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + if (!multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().containsKey(subnetId)) { + InternalSubnetRoutingTable subnetRoutingTables = + networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); + Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); + multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetState); + } + } else { + multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + if (!subnetStateMap.containsKey(subnetId)) { + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); + unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + + subnetStateMap.put(subnetId, subnetState); + for (UnicastGoalStateV2 unicastGoalStateV2 : unicastGoalStates.values()) { + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); + Router.RouterConfiguration.Builder routerConfigurationBuilder = multicastGoalState.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); + routerConfigurationBuilder.addAllSubnetRoutingTables(unicastRouterConfigurationBuilder.getSubnetRoutingTablesList()); + Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder.build()); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); + } + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java index 4703eae46..533a1966c 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java @@ -151,7 +151,7 @@ public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalSta } } - public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) { + public Router.RouterState.Builder buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2... unicastGoalState) { Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); String subnetId = subnetRoutingTable.getSubnetId(); subnetRoutingTableBuilder.setSubnetId(subnetId); @@ -184,10 +184,14 @@ public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutin } } - List subnetRoutingTablesList = new ArrayList<>(); + Set subnetRoutingTablesList = new HashSet<>(); subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState.getGoalStateBuilder(); + if (unicastGoalState.length == 0) { + unicastGoalState = new UnicastGoalStateV2[1]; + unicastGoalState[0] = new UnicastGoalStateV2("", Goalstate.GoalStateV2.newBuilder()); + } + Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState[0].getGoalStateBuilder(); List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { @@ -212,11 +216,12 @@ public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutin Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); routerStateBuilder.setConfiguration(routerConfigBuilder.build()); Router.RouterState routerState = routerStateBuilder.build(); - unicastGoalState.getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); + unicastGoalState[0].getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); + return routerStateBuilder; } - public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { + + public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws Exception { List portStates = new ArrayList(unicastGoalState.getGoalStateBuilder().getPortStatesMap().values()); if (portStates == null || portStates.size() == 0) { return; @@ -247,7 +252,7 @@ public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalSta for (InternalSubnetRoutingTable subnetRoutingTable : subnetRoutingTables) { if (subnetId.equals(subnetRoutingTable.getSubnetId())) { - buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState, multicastGoalState); + buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState); break; } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java index a3daa2f67..0ca943b03 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java @@ -120,6 +120,36 @@ public void buildSubnetState (String subnetId, UnicastGoalState unicastGoalState } } + public Subnet.SubnetState.Builder buildSubnetState (String subnetId) throws Exception + { + InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); + Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); + subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); + subnetConfigBuilder.setId(subnetId); + subnetConfigBuilder.setNetworkType(Common.NetworkType.VXLAN); + subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); + subnetConfigBuilder.setName(subnetEntity.getName()); + subnetConfigBuilder.setCidr(subnetEntity.getCidr()); + if (subnetEntity.getTunnelId() != null) { + subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); + } + Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); + gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); + gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); + subnetConfigBuilder.setGateway(gatewayBuilder.build()); + + if (subnetEntity.getDhcpEnable() != null) { + subnetConfigBuilder.setDhcpEnable(true); + } + + // TODO: need to set DNS based on latest contract + + Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); + subnetStateBuilder.setOperationType(Common.OperationType.INFO); + subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); + return subnetStateBuilder; + } + public void buildSubnetState (String subnetId, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); @@ -227,11 +257,16 @@ private void buildSubnetState(String id, Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); subnetStateBuilder.setOperationType(Common.OperationType.INFO); subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); - multicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + if (unicastGoalState != null) { + unicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + } + if (multicastGoalState != null) { + multicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + } + } - public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { + public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws Exception { Map portStateMap = unicastGoalState.getGoalStateBuilder().getPortStatesMap(); List portStates = new ArrayList(portStateMap.values()); if (portStates == null || portStates.size() == 0) { @@ -282,7 +317,6 @@ public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalSta subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); Subnet.SubnetState subnetState = subnetStateBuilder.build(); unicastGoalState.getGoalStateBuilder().putSubnetStates(subnetState.getConfiguration().getId(), subnetState); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetState.getConfiguration().getId(), subnetState); } } } diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index 1f90e6b5d..60add060e 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -307,8 +307,10 @@ public void onCompleted() { try { long before_get_goalState = System.currentTimeMillis(); Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); + long after_get_goalState = System.currentTimeMillis(); logger.log(Level.INFO, "Sending GS with size " + goalState.getSerializedSize() + " to Host " + hostIp + " as follows | " + goalState.toString()); + requestObserver.onNext(goalState); long after_onNext = System.currentTimeMillis(); logger.log(Level.FINE, "[doSendGoalState] Get goalstatev2 from HostGoalState in milliseconds: " + (after_get_goalState - before_get_goalState)); @@ -320,7 +322,7 @@ public void onCompleted() { // hardcoded) this send goalstate action is probably caused by on-demand workflow, need to record when it // sends this goalState so what we can look into this and the ACA log to see how much time was spent. String neighbor_id = hostGoalState.getGoalState().getNeighborStatesMap().keySet().iterator().next(); - logger.log(Level.INFO, "Sending neighbor ID: " + neighbor_id + " at: " + sent_gs_time); + logger.log(Level.FINE, "Sending neighbor ID: " + neighbor_id + " at: " + sent_gs_time); } } catch (RuntimeException e) { // Cancel RPC diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java index 97a856a2c..9c156f1a5 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java @@ -209,7 +209,7 @@ public void onNext(Goalstate.GoalStateV2 value) { Scope cscope = tracer.scopeManager().activate(span); - logger.log(Level.INFO, "pushGoalStatesStream : receiving GS V2 message " + value.toString()); + logger.log(Level.FINE, "pushGoalStatesStream : receiving GS V2 message " + value.toString()); long start = System.currentTimeMillis(); Span storeGsSpan = tracer.buildSpan(serverStoreGsSpanName).asChildOf(span.context()).start(); Scope storageCscope = tracer.scopeManager().activate(storeGsSpan); diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java index 21b69198d..d35273d56 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java @@ -40,7 +40,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; @AfterProcessor({FixedIpsProcessor.class, MacProcessor.class, - NeighborProcessor.class, NodeProcessor.class, PortProcessor.class, + NodeProcessor.class, PortProcessor.class, RouterProcessor.class, SecurityGroupProcessor.class, VpcProcessor.class}) public class DataPlaneProcessor extends AbstractProcessor { private static final Logger LOG = LoggerFactory.getLogger(DataPlaneProcessor.class); diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java index 0f23b6e78..d66e273a2 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java @@ -23,8 +23,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; import java.util.stream.Collectors; -@AfterProcessor(PortProcessor.class) -public class NeighborProcessor extends AbstractProcessor { +public class NeighborProcessor { private void fetchPortNeighborCallback(IRestRequest request) { Map neighborInfoMap = ((FetchPortNeighborRequest) request).getNeighborInfos(); if (neighborInfoMap == null || neighborInfoMap.size() == 0) { @@ -54,18 +53,16 @@ private void getNeighbors(PortContext context, List portEntities) { fetchPortNeighborRequest, this::fetchPortNeighborCallback); } - @Override + void createProcess(PortContext context) { getNeighbors(context, context.getPortEntities()); } - @Override void updateProcess(PortContext context) { PortEntity portEntity = context.getNewPortEntity(); getNeighbors(context, Collections.singletonList(portEntity)); } - @Override void deleteProcess(PortContext context) { getNeighbors(context, context.getPortEntities()); } diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java index de1e1069e..8bdf0bd1d 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java @@ -263,19 +263,11 @@ public PortNeighbors getPortNeighbors(Object arg) throws CacheException { @DurationStatistics public synchronized void createPortBulk(List portEntities, Map> neighbors) throws Exception { - portEntities.forEach(item -> { - try { - neighborRepository.addProject(item.getProjectId(), item.getVpcId()); - } catch (CacheException e) { - e.printStackTrace(); - } - }); try (Transaction tx = portCache.getTransaction().start()) { Map portEntityMap = portEntities .stream() .collect(Collectors.toMap(PortEntity::getId, Function.identity())); portCache.putAll(portEntityMap); - neighborRepository.createNeighbors(portEntities.get(0).getProjectId(), neighbors); subnetPortsRepository.addSubnetPortIds(portEntities); tx.commit(); } @@ -285,7 +277,6 @@ public synchronized void createPortBulk(List portEntities, Map neighborInfos) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.put(newPortEntity.getId(), newPortEntity); - neighborRepository.updateNeighbors(oldPortEntity, neighborInfos); subnetPortsRepository.updateSubnetPortIds(oldPortEntity, newPortEntity); tx.commit(); } @@ -295,7 +286,6 @@ public synchronized void updatePort(PortEntity oldPortEntity, PortEntity newPort public synchronized void deletePort(PortEntity portEntity) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.remove(portEntity.getId()); - neighborRepository.deleteNeighbors(portEntity); subnetPortsRepository.deleteSubnetPortIds(portEntity); tx.commit(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java index c07047b66..8bf3d930b 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java @@ -29,8 +29,11 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.route.utils.RouteManagerUtil; import com.futurewei.alcor.route.utils.RestPreconditionsUtil; import com.futurewei.alcor.schema.Common; +import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.route.*; import com.futurewei.alcor.common.logging.*; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -289,8 +292,9 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String String portId = resource.getPortId(); String subnetId = resource.getSubnetId(); + SubnetEntity subnetEntity = new SubnetEntity(); - RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.addAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid); + RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.addAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid, subnetEntity); if (subnetId == null) { subnetId = routerInterfaceResponse.getSubnetId(); @@ -322,8 +326,17 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String InternalSubnetRoutingTable internalSubnetRoutingTable = updateRoutingRuleResponse.getInternalSubnetRoutingTable(); List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); - InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList); - this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "add", gatewayPorts, internalRouterInfo); + InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.CREATE); + NetworkConfiguration networkConfiguration = new NetworkConfiguration(); + List internalRouterInfos = new ArrayList<>(); + internalRouterInfos.add(internalRouterInfo); + networkConfiguration.setInternalRouterInfos(internalRouterInfos); + List internalSubnetEntities = new ArrayList<>(); + InternalSubnetEntity internalSubnetEntity = new InternalSubnetEntity(subnetEntity, null); + internalSubnetEntities.add(internalSubnetEntity); + networkConfiguration.setSubnets(internalSubnetEntities); + networkConfiguration.setRsType(Common.ResourceType.NEIGHBOR); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, networkConfiguration); } return routerInterfaceResponse; @@ -342,8 +355,9 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri String portId = resource.getPortId(); String subnetId = resource.getSubnetId(); + SubnetEntity subnetEntity = new SubnetEntity(); - RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid); + RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid, subnetEntity); if (subnetId == null) { subnetId = routerInterfaceResponse.getSubnetId(); @@ -373,8 +387,18 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); - InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList); - this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "delete", gatewayPorts, internalRouterInfo); + InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.DELETE); + NetworkConfiguration networkConfiguration = new NetworkConfiguration(); + List internalRouterInfos = new ArrayList<>(); + internalRouterInfos.add(internalRouterInfo); + networkConfiguration.setInternalRouterInfos(internalRouterInfos); + List internalSubnetEntities = new ArrayList<>(); + InternalSubnetEntity internalSubnetEntity = new InternalSubnetEntity(subnetEntity, null); + internalSubnetEntities.add(internalSubnetEntity); + networkConfiguration.setSubnets(internalSubnetEntities); + networkConfiguration.setSubnets(new ArrayList<>()); + networkConfiguration.setRsType(Common.ResourceType.NEIGHBOR); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, networkConfiguration); } return routerInterfaceResponse; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java index 5da6ce48e..295bc81ec 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java @@ -122,7 +122,7 @@ public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute(NeutronRo } @Override - public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId) + public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs { if (portId != null && subnetId != null) { @@ -166,6 +166,7 @@ else if (portId == null && subnetId != null) { } else { return new RouterInterfaceResponse(); } + Router router = this.routerDatabaseService.getByRouterId(routerId); if (router == null) { throw new RouterUnavailable(routerId); @@ -180,7 +181,7 @@ else if (portId == null && subnetId != null) { throw new PortIsAlreadyInUse(); } subnet.setAttachedRouterId(routerId); - + BeanUtils.copyProperties(subnet, subnetEntity); /* In order to make Neutron router compatible with VPC scenario. We only allow subnet's gateways from the same VPC can be attached to router. @@ -239,7 +240,7 @@ else if (portId == null && subnetId != null) { } @Override - public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException { + public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException { SubnetEntity subnet = null; String projectId = null; String subnetid = null; @@ -292,7 +293,7 @@ public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid } else { return new RouterInterfaceResponse(); } - + BeanUtils.copyProperties(subnet, subnetEntity); // check if the router or the subnet and port do not exist or are not visible Router router = this.routerDatabaseService.getByRouterId(routerId); if (router == null) { @@ -660,7 +661,7 @@ public UpdateRoutingRuleResponse updateRoutingRule (String owner, NewRoutesWebRe } @Override - public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalSubnetRoutingTableList) { + public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalSubnetRoutingTableList, OperationType... operationType) { String requestId = UUID.randomUUID().toString(); InternalRouterInfo internalRouterInfo = new InternalRouterInfo(); @@ -675,8 +676,12 @@ public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalRouterInfos = new ArrayList<>(); internalRouterInfos.add(internalRouterInfo); networkConfiguration.setInternalRouterInfos(internalRouterInfos); - networkConfiguration.setRsType(Common.ResourceType.ROUTER); + + if (networkConfigurations.length == 0) { + networkConfiguration.setRsType(Common.ResourceType.ROUTER); + } else { + networkConfiguration = networkConfigurations[0]; + internalRouterInfo = networkConfiguration.getInternalRouterInfos().get(0); + } + switch (internalRouterInfo.getOperationType()) { case CREATE: diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java index 18ce95042..4475f3395 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java @@ -16,12 +16,14 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.route.service; import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.enumClass.OperationType; import com.futurewei.alcor.common.exception.DatabasePersistenceException; import com.futurewei.alcor.common.exception.QueryParamTypeNotSupportException; import com.futurewei.alcor.common.exception.ResourceNotFoundException; import com.futurewei.alcor.common.exception.ResourcePersistenceException; import com.futurewei.alcor.route.exception.*; import com.futurewei.alcor.web.entity.route.*; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import java.util.List; @@ -29,13 +31,13 @@ public interface NeutronRouterService { public NeutronRouterWebRequestObject getNeutronRouter (String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable; public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute (NeutronRouterWebRequestObject neutronRouter) throws NeutronRouterIsNull, DatabasePersistenceException; - public RouterInterfaceResponse addAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs; - public RouterInterfaceResponse removeAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException; + public RouterInterfaceResponse addAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs; + public RouterInterfaceResponse removeAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException; public RoutesToNeutronWebResponse addRoutesToNeutronRouter (String routerid, NewRoutesWebRequest requestRouter) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, DatabasePersistenceException, DestinationOrNexthopCanNotBeNull, DestinationSame; public RoutesToNeutronWebResponse removeRoutesFromNeutronRouter(String routerid, NewRoutesWebRequest requestRouter) throws RouterOrSubnetAndPortNotExistOrNotVisible, ResourceNotFoundException, ResourcePersistenceException, DestinationOrNexthopCanNotBeNull, DatabasePersistenceException; public ConnectedSubnetsWebResponse getConnectedSubnets (String projectId, String vpcId, String subnetId) throws ResourceNotFoundException, ResourcePersistenceException, SubnetNotBindUniquePortId; public UpdateRoutingRuleResponse updateRoutingRule (String owner, NewRoutesWebRequest newRouteEntry, boolean isNeutronOrVPCLevelRoutingRule, boolean isAddOperation) throws DestinationOrNexthopCanNotBeNull, CacheException, CanNotFindRouteTableByOwner, QueryParamTypeNotSupportException, RouteTableNotUnique, DestinationInvalid, DatabasePersistenceException; - public InternalRouterInfo constructInternalRouterInfo (String routerid, List internalSubnetRoutingTableList); + public InternalRouterInfo constructInternalRouterInfo (String routerid, List internalSubnetRoutingTableList, OperationType... operationType); public List constructInternalSubnetRoutingTables (Router router) throws Exception; public List getRouteTablesBySubnetIds (List subnetIds, String projectid) throws Exception; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java index 0668ea21b..1ecc356fa 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java @@ -15,10 +15,13 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.route.service; +import com.futurewei.alcor.schema.Common; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.route.InternalRouterInfo; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; public interface RouterToDPMService { - public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo) throws Exception; + public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo, NetworkConfiguration... networkConfigurations) throws Exception; } diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java index b8582dec2..e770cc0fd 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java @@ -15,23 +15,28 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.web.entity.port; +import org.apache.ignite.cache.query.annotations.QuerySqlField; + public class PortHostInfo { private String portId; private String portIp; private String portMac; private String hostId; private String hostIp; + @QuerySqlField(index = true) + private String subnetId; public PortHostInfo() { } - public PortHostInfo(String portId, String portIp, String portMac, String hostId, String hostIp) { + public PortHostInfo(String portId, String portIp, String portMac, String hostId, String hostIp, String subnetId) { this.portId = portId; this.portIp = portIp; this.portMac = portMac; this.hostId = hostId; this.hostIp = hostIp; + this.subnetId = subnetId; } public String getPortId() { @@ -73,4 +78,12 @@ public String getHostIp() { public void setHostIp(String hostIp) { this.hostIp = hostIp; } + + public String getSubnetId() { + return subnetId; + } + + public void setSubnetId(String subnetId) { + this.subnetId = subnetId; + } } diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java index 9f72b846a..4cb5bb374 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java @@ -16,6 +16,7 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.web.entity.subnet; import com.futurewei.alcor.web.entity.port.PortHostInfo; +import org.apache.ignite.cache.query.annotations.QuerySqlField; import java.util.List; @@ -30,12 +31,28 @@ public class InternalSubnetPorts { private Long tunnelId; private Boolean dhcpEnable; private List ports; + @QuerySqlField(index = true) private String routerId; public InternalSubnetPorts() { } + public InternalSubnetPorts(String subnetId, String gatewayPortId, String gatewayPortIp, String gatewayPortMac, + String name, String cidr, String vpcId, Long tunnelId, Boolean dhcpEnable, String routerId) { + this.subnetId = subnetId; + this.gatewayPortId = gatewayPortId; + this.gatewayPortIp = gatewayPortIp; + this.gatewayPortMac = gatewayPortMac; + this.name = name; + this.cidr = cidr; + this.vpcId = vpcId; + this.tunnelId = tunnelId; + this.dhcpEnable = dhcpEnable; + this.routerId = routerId; + this.ports = ports; + } + public InternalSubnetPorts(String subnetId, String gatewayPortId, String gatewayPortIp, String gatewayPortMac, String name, String cidr, String vpcId, Long tunnelId, Boolean dhcpEnable, String routerId, List ports) { @@ -49,7 +66,6 @@ public InternalSubnetPorts(String subnetId, String gatewayPortId, String gateway this.tunnelId = tunnelId; this.dhcpEnable = dhcpEnable; this.routerId = routerId; - this.ports = ports; } public String getSubnetId() {