sangho
Committed by Gerrit Code Review

OpenstackRouting refactoring

- Replace OpenstackPortInfo with HostService
- Replace OpenstackRoutingConfig with OpenstackNodeService
  (Remove OpenstackRoutingConfig)
- Rebased with 10330 (existing_vm)
- Added initialization process using OpenstackNodeListener

Change-Id: If2ce8eb86d242a7180c9154e1a0f1668b266bf1c
Showing 17 changed files with 58 additions and 320 deletions
......@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstacknetworking.switching;
package org.onosproject.openstacknetworking;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
/**
* Provides constants used in OpenStack node services.
* Provides constants used in OpenStackSwitching.
*/
public final class Constants {
......@@ -33,9 +34,11 @@ public final class Constants {
public static final String PORTNAME_PREFIX_ROUTER = "qr-";
public static final String PORTNAME_PREFIX_TUNNEL = "vxlan";
// TODO remove this
public static final String ROUTER_INTERFACE = "network:router_interface";
public static final String DEVICE_OWNER_GATEWAY = "network:router_gateway";
public static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f");
// TODO: Please change these valuses following the way vrouter is implemented
public static final MacAddress GW_EXT_INT_MAC = MacAddress.valueOf("56:e6:30:a6:8c:e5");
public static final MacAddress PHY_ROUTER_MAC = MacAddress.valueOf("00:00:00:00:01:01");
public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8");
public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0");
......@@ -51,4 +54,5 @@ public final class Constants {
public static final int SWITCHING_RULE_PRIORITY = 30000;
public static final int TUNNELTAG_RULE_PRIORITY = 30000;
public static final int ACL_RULE_PRIORITY = 30000;
}
\ No newline at end of file
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstacknetworking;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.net.DeviceId;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Contains OpenstackPort Information.
*/
// TODO remove this
public final class OpenstackPortInfo {
private final Ip4Address hostIp;
private final MacAddress hostMac;
private final DeviceId deviceId;
private final long vni;
private final Ip4Address gatewayIP;
private final String networkId;
/**
* Returns OpenstackPortInfo reference.
*
* @param hostIp host IP address
* @param hostMac host MAC address
* @param deviceId device ID
* @param vni tunnel ID
* @param gatewayIP gateway IP address
* @param networkId network identifier
*/
public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni,
Ip4Address gatewayIP, String networkId) {
this.hostIp = hostIp;
this.hostMac = hostMac;
this.deviceId = deviceId;
this.vni = vni;
this.gatewayIP = gatewayIP;
this.networkId = networkId;
}
/**
* Returns IP address of the port.
*
* @return IP address
*/
public Ip4Address ip() {
return hostIp;
}
/**
* Returns MAC address of the port.
*
* @return MAC address
*/
public MacAddress mac() {
return hostMac;
}
/**
* Returns device ID.
*
* @return device ID
*/
public DeviceId deviceId() {
return deviceId;
}
/**
* Returns tunnel ID.
*
* @return tunnel ID
*/
public long vni() {
return vni;
}
/**
* Returns gateway IP address.
*
* @return gateway IP address
*/
public Ip4Address gatewayIP() {
return gatewayIP;
}
/**
* Returns network ID.
*
* @return network ID
*/
public String networkId() {
return networkId;
}
/**
* Returns the builder of the OpenstackPortInfo.
*
* @return OpenstackPortInfo builder reference
*/
public static OpenstackPortInfo.Builder builder() {
return new Builder();
}
/**
* Represents the OpenstackPortInfo Builder.
*
*/
public static final class Builder {
private Ip4Address hostIp;
private MacAddress hostMac;
private DeviceId deviceId;
private long vni;
private Ip4Address gatewayIP;
private String networkId;
/**
* Sets the IP address of the port.
*
* @param gatewayIP gateway IP
* @return Builder reference
*/
public Builder setGatewayIP(Ip4Address gatewayIP) {
this.gatewayIP = checkNotNull(gatewayIP, "gatewayIP cannot be null");
return this;
}
/**
* Sets the network ID.
*
* @param networkId network id
* @return Builder reference
*/
public Builder setNetworkId(String networkId) {
this.networkId = checkNotNull(networkId, "networkId cannot be null");
return this;
}
/**
* Sets the host IP address of the port.
*
* @param hostIp host IP address
* @return Builder reference
*/
public Builder setHostIp(Ip4Address hostIp) {
this.hostIp = checkNotNull(hostIp, "hostIp cannot be null");
return this;
}
/**
* Sets the host MAC address of the port.
*
* @param hostMac host MAC address
* @return Builder reference
*/
public Builder setHostMac(MacAddress hostMac) {
this.hostMac = checkNotNull(hostMac, "hostMac cannot be bull");
return this;
}
/**
* Sets the device ID.
*
* @param deviceId device ID
* @return Builder reference
*/
public Builder setDeviceId(DeviceId deviceId) {
this.deviceId = checkNotNull(deviceId, "deviceId cannot be null");
return this;
}
/**
* Sets the tunnel ID.
*
* @param vni tunnel ID
* @return Builder reference
*/
public Builder setVni(long vni) {
this.vni = checkNotNull(vni, "vni cannot be null");
return this;
}
/**
* Builds the OpenstackPortInfo reference.
*
* @return OpenstackPortInfo reference
*/
public OpenstackPortInfo build() {
return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId);
}
}
}
......@@ -85,8 +85,8 @@ public interface OpenstackRoutingService {
*
* @param portId Deleted vm
* @param portInfo stored information about deleted vm
*/
void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo);
*/
/**
* Returns network id for routerInterface.
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstacknetworking;
import java.util.Map;
/**
* Handles port management REST API from Openstack for VMs.
*/
// TODO remove this
public interface OpenstackSwitchingService {
/**
* Retruns OpenstackPortInfo map.
*
* @return OpenstackPortInfo map
*/
// TODO remove this
Map<String, OpenstackPortInfo> openstackPortInfo();
}
......@@ -68,6 +68,11 @@
<artifactId>onos-scalablegateway</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-openstacknode</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......
......@@ -15,34 +15,39 @@
*/
package org.onosproject.openstacknetworking.routing;
import org.onosproject.net.Host;
import org.onosproject.openstackinterface.OpenstackFloatingIP;
import org.onosproject.openstacknetworking.OpenstackPortInfo;
/**
* Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes.
*/
public class OpenstackFloatingIPHandler implements Runnable {
public enum Action {
ASSOCIATE,
DISSASSOCIATE
}
private final OpenstackFloatingIP floatingIP;
private final OpenstackRoutingRulePopulator rulePopulator;
private boolean associate;
private final OpenstackPortInfo portInfo;
private final Host host;
private final Action action;
OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator,
OpenstackFloatingIP openstackFloatingIP, boolean associate, OpenstackPortInfo portInfo) {
OpenstackFloatingIP openstackFloatingIP, Action action, Host host) {
this.floatingIP = openstackFloatingIP;
this.rulePopulator = rulePopulator;
this.associate = associate;
this.portInfo = portInfo;
this.action = action;
this.host = host;
}
@Override
public void run() {
if (associate) {
if (action == Action.ASSOCIATE) {
rulePopulator.populateFloatingIpRules(floatingIP);
} else {
rulePopulator.removeFloatingIpRules(floatingIP, portInfo);
rulePopulator.removeFloatingIpRules(floatingIP, host);
}
}
}
......
......@@ -32,7 +32,6 @@ import org.onosproject.net.packet.PacketService;
import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstackinterface.OpenstackRouter;
import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
import org.onosproject.scalablegateway.api.GatewayNode;
import org.onosproject.scalablegateway.api.ScalableGatewayService;
import org.slf4j.Logger;
......@@ -52,25 +51,21 @@ public class OpenstackPnatHandler implements Runnable {
volatile PacketContext context;
private final Logger log = LoggerFactory.getLogger(getClass());
protected PacketService packetService;
private final OpenstackRoutingRulePopulator rulePopulator;
private final int portNum;
private final OpenstackPort openstackPort;
private final Port port;
private OpenstackNetworkingConfig config;
private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface";
private static final String EXTERNAL_PORT_NULL = "There is no external port in this deviceId []";
OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context,
int portNum, OpenstackPort openstackPort, Port port, OpenstackNetworkingConfig config) {
int portNum, OpenstackPort openstackPort, Port port) {
this.rulePopulator = checkNotNull(rulePopulator);
this.context = checkNotNull(context);
this.portNum = checkNotNull(portNum);
this.openstackPort = checkNotNull(openstackPort);
this.port = checkNotNull(port);
this.config = checkNotNull(config);
}
@Override
......@@ -149,6 +144,7 @@ public class OpenstackPnatHandler implements Runnable {
iPacket.resetChecksum();
iPacket.setParent(ethernet);
ethernet.setPayload(iPacket);
ScalableGatewayService gatewayService = getService(ScalableGatewayService.class);
GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId);
if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) {
......@@ -159,7 +155,6 @@ public class OpenstackPnatHandler implements Runnable {
ethernet.resetChecksum();
packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(),
ByteBuffer.wrap(ethernet.serialize())));
}
......
......@@ -34,8 +34,9 @@ import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketService;
import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
import org.onosproject.scalablegateway.api.ScalableGatewayService;
import org.onosproject.openstacknetworking.Constants;
import org.onosproject.openstacknode.OpenstackNodeService;
import org.slf4j.Logger;
import java.nio.ByteBuffer;
......@@ -53,23 +54,24 @@ public class OpenstackRoutingArpHandler {
private final PacketService packetService;
private final OpenstackInterfaceService openstackService;
private final OpenstackNetworkingConfig config;
private final ScalableGatewayService gatewayService;
private final OpenstackNodeService nodeService;
private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway";
private static final String NETWORK_FLOATING_IP = "network:floatingip";
/**
* Default constructor.
* @param packetService packet service
*
* @param packetService packet service
* @param openstackService openstackInterface service
* @param config openstackRoutingConfig
* @param gatewayService
* @param gatewayService gateway service
* @param nodeService openstackNodeService
*/
OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService,
OpenstackNetworkingConfig config, ScalableGatewayService gatewayService) {
OpenstackNodeService nodeService, ScalableGatewayService gatewayService) {
this.packetService = packetService;
this.openstackService = checkNotNull(openstackService);
this.config = checkNotNull(config);
this.nodeService = nodeService;
this.gatewayService = gatewayService;
}
......@@ -118,7 +120,8 @@ public class OpenstackRoutingArpHandler {
if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) {
return;
}
MacAddress targetMac = MacAddress.valueOf(config.gatewayExternalInterfaceMac());
// FIXME: Set the correct gateway
MacAddress targetMac = Constants.GW_EXT_INT_MAC;
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(),
targetMac, ethernet);
......
......@@ -26,6 +26,7 @@ import org.onosproject.net.Host;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostListener;
import org.onosproject.net.host.HostService;
import org.onosproject.openstacknetworking.Constants;
import org.slf4j.Logger;
import java.util.Objects;
......@@ -36,7 +37,7 @@ import java.util.stream.Collectors;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.openstacknetworking.switching.Constants.*;
import static org.onosproject.openstacknetworking.Constants.*;
import static org.slf4j.LoggerFactory.getLogger;
/**
......
......@@ -48,7 +48,7 @@ import java.util.Dictionary;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.openstacknetworking.switching.Constants.*;
import static org.onosproject.openstacknetworking.Constants.*;
/**
* Handles ARP packet from VMs.
......
......@@ -50,7 +50,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static org.onosproject.openstacknetworking.switching.Constants.*;
import static org.onosproject.openstacknetworking.Constants.*;
/**
* Populates flows rules for Security Groups of VMs.
......
......@@ -16,7 +16,6 @@
package org.onosproject.openstacknetworking.switching;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......@@ -27,7 +26,6 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.VlanId;
import org.onlab.util.Tools;
import org.onosproject.core.CoreService;
import org.onosproject.dhcp.DhcpService;
import org.onosproject.dhcp.IpAssignment;
......@@ -54,8 +52,6 @@ import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackNetwork;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstackinterface.OpenstackSubnet;
import org.onosproject.openstacknetworking.OpenstackPortInfo;
import org.onosproject.openstacknetworking.OpenstackSwitchingService;
import org.onosproject.openstacknode.OpenstackNode;
import org.onosproject.openstacknode.OpenstackNodeEvent;
import org.onosproject.openstacknode.OpenstackNodeListener;
......@@ -64,7 +60,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -74,7 +69,7 @@ import static org.onosproject.dhcp.IpAssignment.AssignmentStatus.Option_RangeNot
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.openstacknetworking.switching.Constants.*;
import static org.onosproject.openstacknetworking.Constants.*;
@Service
@Component(immediate = true)
......@@ -82,7 +77,7 @@ import static org.onosproject.openstacknetworking.switching.Constants.*;
* Populates forwarding rules for VMs created by Openstack.
*/
public final class OpenstackSwitchingManager extends AbstractProvider
implements OpenstackSwitchingService, HostProvider {
implements HostProvider {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -153,41 +148,6 @@ public final class OpenstackSwitchingManager extends AbstractProvider
// no probe is required
}
@Override
// TODO remove this and openstackPortInfo
public Map<String, OpenstackPortInfo> openstackPortInfo() {
Map<String, OpenstackPortInfo> portInfoMap = Maps.newHashMap();
Tools.stream(hostService.getHosts()).filter(this::isValidHost).forEach(host -> {
Port port = deviceService.getPort(
host.location().deviceId(),
host.location().port());
OpenstackPortInfo portInfo = OpenstackPortInfo.builder()
.setDeviceId(host.location().deviceId())
.setHostMac(host.mac())
.setNetworkId(host.annotations().value(NETWORK_ID))
.setGatewayIP(Ip4Address.valueOf(host.annotations().value(GATEWAY_IP)))
.setVni(Long.valueOf(host.annotations().value(VXLAN_ID)))
.setHostIp(host.ipAddresses().stream().findFirst().get().getIp4Address())
.build();
portInfoMap.put(port.annotations().value(PORT_NAME), portInfo);
});
return portInfoMap;
}
// TODO remove this and openstackPortInfo
private boolean isValidHost(Host host) {
return !host.ipAddresses().isEmpty() &&
host.annotations().value(VXLAN_ID) != null &&
host.annotations().value(NETWORK_ID) != null &&
host.annotations().value(TENANT_ID) != null &&
host.annotations().value(GATEWAY_IP) != null &&
host.annotations().value(PORT_ID) != null;
}
private void processPortAdded(Port port) {
// TODO check the node state is COMPLETE
OpenstackPort osPort = openstackService.port(port);
......
......@@ -47,7 +47,7 @@ import java.util.Objects;
import java.util.Optional;
import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST;
import static org.onosproject.openstacknetworking.switching.Constants.*;
import static org.onosproject.openstacknetworking.Constants.*;
/**
* Populates switching flow rules.
......
......@@ -50,6 +50,7 @@ import org.onosproject.scalablegateway.api.GatewayNodeConfig;
import org.onosproject.scalablegateway.api.ScalableGatewayService;
import java.util.List;
import java.util.Optional;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
......@@ -128,7 +129,6 @@ public class ScalableGatewayManager implements ScalableGatewayService {
deviceService.addListener(internalDeviceListener);
selectGroupHandler = new SelectGroupHandler(groupService, deviceService, driverService, appId);
readConfiguration();
gatewayNodeMap = storageService.<DeviceId, GatewayNode>consistentMapBuilder()
.withSerializer(Serializer.using(GATEWAYNODE_SERIALIZER.build()))
......@@ -165,13 +165,17 @@ public class ScalableGatewayManager implements ScalableGatewayService {
}
private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) {
Port port = deviceService.getPorts(gatewayDeviceId)
Optional<Port> port = deviceService.getPorts(gatewayDeviceId)
.stream()
.filter(p -> p.annotations().value(PORT_NAME).equals(name))
.iterator()
.next();
return checkNotNull(port, PORT_CAN_NOT_BE_NULL).number();
.findFirst();
if (!port.isPresent()) {
log.error("Cannot find port {} in gateway device {}", name, gatewayDeviceId);
return null;
}
return port.get().number();
}
@Override
......