Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

[Route Manager] Fix L3 e2e issues for Neutron Router #599

Merged
merged 18 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Copyright(c) 2020 Futurewei Cloud
</parent>

<properties>
<java.version>8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -143,8 +143,8 @@ Copyright(c) 2020 Futurewei Cloud
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ public RouterUpdateInfo updateL3Neighbors(String projectId, RouterUpdateInfo rou
Map<String, NeighborInfo> neighborInfos = new HashMap<>();
Map<String, List<NeighborEntry>> neighborTable = updateNeighborTable(routerUpdateInfo, neighborInfos);

for (String privateIp: neighborTable.keySet()) {
LOG.info("NeighborTable- key: {}, size: {}", privateIp, neighborTable.get(privateIp).size());
}
if (neighborTable.size() > 0) {
NetworkConfiguration networkConfiguration = new NetworkConfiguration();
networkConfiguration.setRsType(Common.ResourceType.NEIGHBOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String

RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.addAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid);

if (subnetId == null) {
subnetId = routerInterfaceResponse.getSubnetId();
}

// TODO: return all connected subnet-ids to Port Manager. The algorithm as follow:
//1. get ports array from the router.
Router router = this.routerDatabaseService.getByRouterId(routerid);
Expand Down Expand Up @@ -319,6 +323,10 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri

RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid);

if (subnetId == null) {
subnetId = routerInterfaceResponse.getSubnetId();
}

// TODO: return all connected subnet-ids to Port Manager. The algorithm as follow:
//1. get ports array from the router.
Router router = this.routerDatabaseService.getByRouterId(routerid);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
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.route.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code= HttpStatus.CONFLICT, reason="the router cannot attached interfaces from different VPC/Network")
public class RouterHasMultipleVPCs extends Exception {
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute(NeutronRo
BeanUtils.copyProperties(neutronRouter, routerExtraAttribute);
routerExtraAttribute.setId(attachedRouterExtraAttributeId);
RouteTable routeTable = neutronRouter.getRouteTable();
if (routeTable == null) {
if (routeTable == null || routeTable.getRouteEntities() == null) {
routeTable = new RouteTable();
List<RouteEntry> routeEntities = new ArrayList<>();
String routeTableId = UUID.randomUUID().toString();
Expand All @@ -120,7 +120,9 @@ public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute(NeutronRo
}

@Override
public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId {
public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId)
throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable,
DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs {
Comment on lines +124 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice before -- This method throws 9 different exceptions.. @cj-chung

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xieus We can rewrite the error handling part when we refactor the RM's code.

if (portId != null && subnetId != null) {
throw new SpecifyBothSubnetIDAndPortID();
}
Expand Down Expand Up @@ -177,6 +179,24 @@ else if (portId == null && subnetId != null) {
}
subnet.setAttachedRouterId(routerId);

/*
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.
We use VPC from the first attached gateway as router's owner
If any attaching gateway after the first one has different VPC, we will issue a warning message.
*/
List<String> gwPorts = router.getGatewayPorts();
if (gwPorts == null || gwPorts.size() == 0) {
router.setOwner(subnet.getVpcId());
} else {
cj-chung marked this conversation as resolved.
Show resolved Hide resolved
for (String port : gwPorts) {
SubnetsWebJson subnet_o = this.routerToSubnetService.getSubnetsByPortId(router.getProjectId(), port);
if (!subnet_o.getSubnets().get(0).getVpcId().equals(subnet.getVpcId())) {
cj-chung marked this conversation as resolved.
Show resolved Hide resolved
throw new RouterHasMultipleVPCs();
}
}
}

// update device_id and device_owner in PM
PortEntity portEntity = new PortEntity();
portEntity.setDeviceId(routerId);
Expand Down Expand Up @@ -280,13 +300,16 @@ public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid
}

List<RouteEntry> routeEntities = routeTable.getRouteEntities();
for (RouteEntry routeEntry : routeEntities) {
String nextHop = routeEntry.getNexthop();
if (gatewayIp.equals(nextHop)) {
throw new RouterInterfaceAreUsedByRoutes();
if (routeEntities != null) {
cj-chung marked this conversation as resolved.
Show resolved Hide resolved
for (RouteEntry routeEntry : routeEntities) {
String nextHop = routeEntry.getNexthop();
if (gatewayIp.equals(nextHop)) {
throw new RouterInterfaceAreUsedByRoutes();
}
}
}

// else part:
// the router doesn't come with a default routetable which is the OpenStack's scenario, just ignore it.
}

// remove interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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;
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 RoutesToNeutronWebResponse addRoutesToNeutronRouter (String routerid, NewRoutesWebRequest requestRouter) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, DatabasePersistenceException, DestinationOrNexthopCanNotBeNull;
public RoutesToNeutronWebResponse removeRoutesFromNeutronRouter(String routerid, NewRoutesWebRequest requestRouter) throws RouterOrSubnetAndPortNotExistOrNotVisible, ResourceNotFoundException, ResourcePersistenceException, DestinationOrNexthopCanNotBeNull, DatabasePersistenceException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ free of charge, to any person obtaining a copy of this software and associated d
package com.futurewei.alcor.route.utils;

import com.futurewei.alcor.common.enumClass.NetworkStatusEnum;
import com.futurewei.alcor.common.enumClass.NetworkTypeEnum;
import com.futurewei.alcor.common.enumClass.RouteTableType;
import com.futurewei.alcor.common.utils.DateUtil;
import com.futurewei.alcor.web.entity.route.*;
import com.futurewei.alcor.web.entity.route.NeutronRouterWebJson;
import com.futurewei.alcor.web.entity.route.NeutronRouterWebRequestObject;
import com.futurewei.alcor.web.entity.route.RouteTable;
import com.futurewei.alcor.web.entity.route.RouteTableWebJson;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RouteManagerUtil {

Expand Down Expand Up @@ -59,7 +61,7 @@ public static boolean checkNeutronRouterWebResourceIsValid(NeutronRouterWebJson

// status
String status = neutronRouter.getStatus();
if (!(status == null || NetworkStatusEnum.ACTIVE.getNetworkStatus().equals(status)
if (!(status == null
|| NetworkStatusEnum.ACTIVE.getNetworkStatus().equals(status)
|| NetworkStatusEnum.DOWN.getNetworkStatus().equals(status)
|| NetworkStatusEnum.BUILD.getNetworkStatus().equals(status)
Expand Down Expand Up @@ -103,7 +105,7 @@ public static NeutronRouterWebRequestObject configureNeutronRouterParameters (Ne

// status
String status = response.getStatus();
if (status == null) {
if (!NetworkStatusEnum.ACTIVE.getNetworkStatus().equals(status)) {
response.setStatus(NetworkStatusEnum.ACTIVE.getNetworkStatus());
}

Expand Down