Hyunsun Moon
Committed by Gerrit Code Review

Refactored OpenstackRouting to support multiple gateway nodes

Change-Id: I6870ca9a4fd6f6b1cf2d2be72f52ef87827e1d2c
Showing 23 changed files with 334 additions and 247 deletions
......@@ -20,7 +20,7 @@ import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An Openstack Neutron Router Interface Model.
* An OpenStack Neutron router interface model.
*/
public final class OpenstackRouterInterface {
private final String id;
......@@ -37,9 +37,9 @@ public final class OpenstackRouterInterface {
}
/**
* Returns Router Interface ID.
* Returns router interface ID.
*
* @return router interface ID
* @return router interface id
*/
public String id() {
return id;
......@@ -48,7 +48,7 @@ public final class OpenstackRouterInterface {
/**
* Returns tenant ID.
*
* @return tenant ID
* @return tenant id
*/
public String tenantId() {
return tenantId;
......@@ -57,7 +57,7 @@ public final class OpenstackRouterInterface {
/**
* Returns subnet ID.
*
* @return subnet ID
* @return subnet id
*/
public String subnetId() {
return subnetId;
......@@ -66,7 +66,7 @@ public final class OpenstackRouterInterface {
/**
* Returns port ID.
*
* @return port ID
* @return port id
*/
public String portId() {
return portId;
......@@ -96,7 +96,16 @@ public final class OpenstackRouterInterface {
}
/**
* An Openstack Router Interface Builder class.
* Returns OpenStack router interface builder.
*
* @return openstack router interface builder
*/
public static Builder builder() {
return new Builder();
}
/**
* An OpenStack Router interface builder class.
*/
public static final class Builder {
private String id;
......@@ -105,10 +114,10 @@ public final class OpenstackRouterInterface {
private String portId;
/**
* Sets Router Interface ID.
* Sets router interface ID.
*
* @param id router interface ID
* @return Builder object
* @param id router interface id
* @return builder object
*/
public Builder id(String id) {
this.id = id;
......@@ -119,7 +128,7 @@ public final class OpenstackRouterInterface {
* Sets tenant ID.
*
* @param tenantId tenant ID
* @return Builder object
* @return builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
......@@ -130,7 +139,7 @@ public final class OpenstackRouterInterface {
* Sets subnet ID.
*
* @param subnetId subnet ID
* @return Builder object
* @return builder object
*/
public Builder subnetId(String subnetId) {
this.subnetId = subnetId;
......@@ -141,7 +150,7 @@ public final class OpenstackRouterInterface {
* Sets port ID.
*
* @param portId port ID
* @return Builder object
* @return builder object
*/
public Builder portId(String portId) {
this.portId = portId;
......@@ -149,14 +158,13 @@ public final class OpenstackRouterInterface {
}
/**
* Builds an Openstack Router Interface object.
* Builds an OpenStack router interface object.
*
* @return OpenstackRouterInterface object
* @return openstack router interface object
*/
public OpenstackRouterInterface build() {
return new OpenstackRouterInterface(checkNotNull(id), checkNotNull(tenantId),
checkNotNull(subnetId), checkNotNull(portId));
}
}
}
......
......@@ -13,20 +13,18 @@
* 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.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.Ip4Address;
import org.onlab.util.Tools;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.mastership.MastershipService;
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;
......@@ -53,7 +51,6 @@ public abstract class AbstractVmHandler {
protected MastershipService mastershipService;
protected HostService hostService;
protected ApplicationId appId;
protected HostListener hostListener = new InternalHostListener();
protected void activate() {
......@@ -61,8 +58,6 @@ public abstract class AbstractVmHandler {
coreService = services.get(CoreService.class);
mastershipService = services.get(MastershipService.class);
hostService = services.get(HostService.class);
appId = coreService.registerApplication(Constants.APP_ID);
hostService.addListener(hostListener);
log.info("Started");
......@@ -75,9 +70,19 @@ public abstract class AbstractVmHandler {
log.info("Stopped");
}
abstract void hostDetected(Host host);
abstract void hostRemoved(Host host);
/**
* Performs any action when a host is detected.
*
* @param host detected host
*/
protected abstract void hostDetected(Host host);
/**
* Performs any action when a host is removed.
*
* @param host removed host
*/
protected abstract void hostRemoved(Host host);
protected boolean isValidHost(Host host) {
return !host.ipAddresses().isEmpty() &&
......
......@@ -28,23 +28,27 @@ public final class Constants {
private Constants() {
}
public static final String APP_ID = "org.onosproject.openstackswitching";
public static final String SWITCHING_APP_ID = "org.onosproject.openstackswitching";
public static final String ROUTING_APP_ID = "org.onosproject.openstackrouting";
public static final String PORTNAME_PREFIX_VM = "tap";
public static final String PORTNAME_PREFIX_ROUTER = "qr-";
public static final String PORTNAME_PREFIX_TUNNEL = "vxlan";
public static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface";
public static final String DEVICE_OWNER_ROUTER_GATEWAY = "network:router_gateway";
public static final String DEVICE_OWNER_FLOATING_IP = "network:floatingip";
public static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f");
public static final String PORT_NAME_PREFIX_VM = "tap";
public static final String PORT_NAME_PREFIX_TUNNEL = "vxlan";
// 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 String DEFAULT_GATEWAY_MAC_STR = "fe:00:00:00:00:02";
public static final MacAddress DEFAULT_GATEWAY_MAC = MacAddress.valueOf(DEFAULT_GATEWAY_MAC_STR);
// TODO make this configurable
public static final MacAddress DEFAULT_EXTERNAL_ROUTER_MAC = MacAddress.valueOf("fe:00:00:00:00: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");
public static final int DHCP_INFINITE_LEASE = -1;
public static final String NETWORK_ID = "networkId";
public static final String SUBNET_ID = "subnetId";
public static final String PORT_ID = "portId";
public static final String VXLAN_ID = "vxlanId";
public static final String TENANT_ID = "tenantId";
......@@ -55,4 +59,8 @@ public final class Constants {
public static final int TUNNELTAG_RULE_PRIORITY = 30000;
public static final int ACL_RULE_PRIORITY = 30000;
public static final int ROUTING_RULE_PRIORITY = 25000;
public static final int FLOATING_RULE_PRIORITY = 42000;
public static final int PNAT_RULE_PRIORITY = 26000;
public static final int PNAT_TIMEOUT = 120;
}
\ 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.onosproject.openstackinterface.OpenstackFloatingIP;
/**
* Handles floating IP update requests from OpenStack.
*/
public interface OpenstackFloatingIpService {
enum Action {
ASSOCIATE,
DISSASSOCIATE
}
/**
* Handles floating IP create request from OpenStack.
*
* @param floatingIp floating IP information
*/
void createFloatingIp(OpenstackFloatingIP floatingIp);
/**
* Handles floating IP update request from OpenStack.
*
* @param floatingIp floating IP information
*/
void updateFloatingIp(OpenstackFloatingIP floatingIp);
/**
* Handles floating IP remove request from OpenStack.
*
* @param floatingIpId floating ip identifier
*/
void deleteFloatingIp(String floatingIpId);
}
......@@ -15,76 +15,49 @@
*/
package org.onosproject.openstacknetworking;
import org.onosproject.openstackinterface.OpenstackFloatingIP;
import org.onosproject.openstackinterface.OpenstackRouter;
import org.onosproject.openstackinterface.OpenstackRouterInterface;
/**
* Supports L3 management REST API for openstack.
* Handles router update requests from OpenStack.
*/
public interface OpenstackRoutingService {
/**
* Stores the floating IP information created by openstack.
* Handles the router create request from OpenStack.
*
* @param openstackFloatingIp Floating IP information
* @param osRouter router information
*/
void createFloatingIP(OpenstackFloatingIP openstackFloatingIp);
void createRouter(OpenstackRouter osRouter);
/**
* Updates flow rules corresponding to the floating IP information updated by openstack.
* Handles the router update request from OpenStack.
* Update router is called when the name, administrative state, or the external
* gateway setting is updated. The external gateway update is the only case
* that openstack routing service cares.
*
* @param openstackFloatingIp Floating IP information
* @param osRouter router information
*/
void updateFloatingIP(OpenstackFloatingIP openstackFloatingIp);
void updateRouter(OpenstackRouter osRouter);
/**
* Removes flow rules corresponding to floating IP information removed by openstack.
* Handles the router remove request from OpenStack.
*
* @param id Deleted Floating IP`s ID
* @param osRouterId identifier of the router
*/
void deleteFloatingIP(String id);
void removeRouter(String osRouterId);
/**
* Stores the router information created by openstack.
* Handles router interface add request from OpenStack.
*
* @param openstackRouter Router information
* @param osInterface router interface information
*/
void createRouter(OpenstackRouter openstackRouter);
void addRouterInterface(OpenstackRouterInterface osInterface);
/**
* Updates flow rules corresponding to the router information updated by openstack.
* Handles router interface remove request from OpenStack.
*
* @param openstackRouter Router information
* @param osInterface router interface information
*/
void updateRouter(OpenstackRouter openstackRouter);
/**
* Removes flow rules corresponding to the router information removed by openstack.
*
* @param id Deleted router`s ID
*/
void deleteRouter(String id);
/**
* Updates flow rules corresponding to the router information updated by openstack.
*
* @param openstackRouterInterface Router interface information
*/
void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface);
/**
* Removes flow rules corresponding to the router information removed by openstack.
*
* @param openstackRouterInterface Router interface information
*/
void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface);
/**
* Returns network id for routerInterface.
*
* @param portId routerInterface`s port id
* @return network id
*/
String networkIdForRouterInterface(String portId);
void removeRouterInterface(OpenstackRouterInterface osInterface);
}
......
/*
* 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.onosproject.core.ApplicationId;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.instructions.ExtensionPropertyException;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.slf4j.Logger;
import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides common methods to help populating flow rules for SONA applications.
*/
public final class RulePopulatorUtil {
protected static final Logger log = getLogger(RulePopulatorUtil.class);
private static final String TUNNEL_DST = "tunnelDst";
private RulePopulatorUtil() {
}
/**
* Returns tunnel destination extension treatment object.
*
* @param deviceService driver service
* @param deviceId device id to apply this treatment
* @param remoteIp tunnel destination ip address
* @return extension treatment
*/
public static ExtensionTreatment buildExtension(DeviceService deviceService,
DeviceId deviceId,
Ip4Address remoteIp) {
Device device = deviceService.getDevice(deviceId);
if (device != null && !device.is(ExtensionTreatmentResolver.class)) {
log.error("The extension treatment is not supported");
return null;
}
ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
try {
treatment.setPropertyValue(TUNNEL_DST, remoteIp);
return treatment;
} catch (ExtensionPropertyException e) {
log.warn("Failed to get tunnelDst extension treatment for {}", deviceId);
return null;
}
}
/**
* Removes flow rules with the supplied information.
*
* @param flowObjectiveService flow objective service
* @param appId application id
* @param deviceId device id to remove this flow rule
* @param selector traffic selector
* @param flag flag
* @param priority priority
*/
public static void removeRule(FlowObjectiveService flowObjectiveService,
ApplicationId appId,
DeviceId deviceId,
TrafficSelector selector,
ForwardingObjective.Flag flag,
int priority) {
ForwardingObjective fo = DefaultForwardingObjective.builder()
.withSelector(selector)
.withTreatment(DefaultTrafficTreatment.builder().build())
.withFlag(flag)
.withPriority(priority)
.fromApp(appId)
.remove();
flowObjectiveService.forward(deviceId, fo);
}
}
/*
* 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.routing;
import org.onosproject.net.Host;
import org.onosproject.openstackinterface.OpenstackFloatingIP;
/**
* 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 final Host host;
private final Action action;
OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator,
OpenstackFloatingIP openstackFloatingIP, Action action, Host host) {
this.floatingIP = openstackFloatingIP;
this.rulePopulator = rulePopulator;
this.action = action;
this.host = host;
}
@Override
public void run() {
if (action == Action.ASSOCIATE) {
rulePopulator.populateFloatingIpRules(floatingIP);
} else {
rulePopulator.removeFloatingIpRules(floatingIP, host);
}
}
}
......@@ -15,99 +15,74 @@
*/
package org.onosproject.openstacknetworking.routing;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.ARP;
import org.onlab.packet.EthType;
import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.scalablegateway.api.ScalableGatewayService;
import org.onosproject.openstacknetworking.Constants;
import org.onosproject.openstacknode.OpenstackNodeService;
import org.slf4j.Logger;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.openstacknetworking.Constants.DEVICE_OWNER_FLOATING_IP;
import static org.onosproject.openstacknetworking.Constants.DEVICE_OWNER_ROUTER_GATEWAY;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Handle ARP packet sent from Openstack Gateway nodes.
* Handle ARP, ICMP and NAT packets from gateway nodes.
*/
@Component(immediate = true)
public class OpenstackRoutingArpHandler {
protected final Logger log = getLogger(getClass());
private final PacketService packetService;
private final OpenstackInterfaceService openstackService;
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 openstackService openstackInterface service
* @param gatewayService gateway service
* @param nodeService openstackNodeService
*/
OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService,
OpenstackNodeService nodeService, ScalableGatewayService gatewayService) {
this.packetService = packetService;
this.openstackService = checkNotNull(openstackService);
this.nodeService = nodeService;
this.gatewayService = gatewayService;
}
private final Logger log = getLogger(getClass());
/**
* Requests ARP packet to GatewayNode.
*
* @param appId application id
*/
public void requestPacket(ApplicationId appId) {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
TrafficSelector arpSelector = DefaultTrafficSelector.builder()
.matchEthType(EthType.EtherType.ARP.ethType().toShort())
.build();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenstackInterfaceService openstackService;
getExternalInfo().forEach(deviceId ->
packetService.requestPackets(arpSelector,
PacketPriority.CONTROL,
appId,
Optional.of(deviceId))
);
}
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ScalableGatewayService gatewayService;
/**
* Handles ARP packet.
*
* @param context packet context
* @param ethernet ethernet
*/
public void processArpPacketFromRouter(PacketContext context, Ethernet ethernet) {
checkNotNull(context, "context can not be null");
checkNotNull(ethernet, "ethernet can not be null");
private final ExecutorService executorService =
newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "packet-event", log));
private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
ARP arp = (ARP) ethernet.getPayload();
@Activate
protected void activate() {
packetService.addProcessor(packetProcessor, PacketProcessor.director(1));
log.info("Started");
}
log.debug("arpEvent called from {} to {}",
@Deactivate
protected void deactivate() {
packetService.removeProcessor(packetProcessor);
log.info("Stopped");
}
private void processArpPacket(PacketContext context, Ethernet ethernet) {
ARP arp = (ARP) ethernet.getPayload();
log.trace("arpEvent called from {} to {}",
Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(),
Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString());
......@@ -116,13 +91,11 @@ public class OpenstackRoutingArpHandler {
}
IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) {
return;
return;
}
// FIXME: Set the correct gateway
MacAddress targetMac = Constants.GW_EXT_INT_MAC;
MacAddress targetMac = Constants.DEFAULT_EXTERNAL_ROUTER_MAC;
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(),
targetMac, ethernet);
......@@ -136,22 +109,35 @@ public class OpenstackRoutingArpHandler {
ByteBuffer.wrap(ethReply.serialize())));
}
private class InternalPacketProcessor implements PacketProcessor {
@Override
public void process(PacketContext context) {
if (context.isHandled()) {
return;
} else if (!gatewayService.getGatewayDeviceIds().contains(
context.inPacket().receivedFrom().deviceId())) {
// return if the packet is not from gateway nodes
return;
}
InboundPacket pkt = context.inPacket();
Ethernet ethernet = pkt.parsed();
if (ethernet != null &&
ethernet.getEtherType() == Ethernet.TYPE_ARP) {
executorService.execute(() -> processArpPacket(context, ethernet));
}
}
}
// TODO make a cache for the MAC, not a good idea to REST call every time it gets ARP request
private MacAddress getTargetMacForTargetIp(Ip4Address targetIp) {
OpenstackPort port = openstackService.ports().stream()
.filter(p -> p.deviceOwner().equals(NETWORK_ROUTER_GATEWAY) ||
p.deviceOwner().equals(NETWORK_FLOATING_IP))
.filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_GATEWAY) ||
p.deviceOwner().equals(DEVICE_OWNER_FLOATING_IP))
.filter(p -> p.fixedIps().containsValue(targetIp.getIp4Address()))
.findAny().orElse(null);
if (port == null) {
return MacAddress.NONE;
}
return port.macAddress();
}
private List<DeviceId> getExternalInfo() {
List<DeviceId> externalInfoList = Lists.newArrayList();
gatewayService.getGatewayDeviceIds().forEach(externalInfoList::add);
return externalInfoList;
return port == null ? MacAddress.NONE : port.macAddress();
}
}
......
......@@ -15,6 +15,8 @@
*/
/**
* Application for OpenstackRouting.
* Implements OpenStack L3 service plugin, which routes packets between subnets,
* forwards packets from internal networks to external ones, and accesses instances
* from external networks through floating IPs.
*/
package org.onosproject.openstacknetworking.routing;
\ No newline at end of file
package org.onosproject.openstacknetworking.routing;
......
......@@ -30,6 +30,7 @@ import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onlab.util.Tools;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.flow.DefaultTrafficSelector;
......@@ -43,6 +44,7 @@ import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstackinterface.OpenstackSecurityGroup;
import org.onosproject.openstackinterface.OpenstackSecurityGroupRule;
import org.onosproject.openstacknetworking.OpenstackSecurityGroupService;
import org.onosproject.openstacknetworking.AbstractVmHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -60,7 +62,7 @@ import static org.onosproject.openstacknetworking.Constants.*;
*/
@Component(immediate = true)
@Service
public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler
public class OpenstackSecurityGroupManager extends AbstractVmHandler
implements OpenstackSecurityGroupService {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -77,10 +79,12 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler
private static final String ETHTYPE_IPV4 = "IPV4";
private final Map<Host, Set<SecurityGroupRule>> securityGroupRuleMap = Maps.newConcurrentMap();
private ApplicationId appId;
@Activate
protected void activate() {
super.activate();
appId = coreService.registerApplication(SWITCHING_APP_ID);
}
@Deactivate
......@@ -96,7 +100,7 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler
Optional<Host> host = getVmByPortId(osPort.id());
if (!host.isPresent()) {
log.warn("No host found with {}", osPort);
log.debug("No host found with {}", osPort.id());
return;
}
eventExecutor.execute(() -> updateSecurityGroupRules(host.get(), true));
......
......@@ -40,6 +40,7 @@ import org.onosproject.net.packet.PacketService;
import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackNetwork;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstacknetworking.AbstractVmHandler;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -54,12 +55,11 @@ import static org.onosproject.openstacknetworking.Constants.*;
* Handles ARP packet from VMs.
*/
@Component(immediate = true)
public final class OpenstackArpHandler extends AbstractVmHandler {
public final class OpenstackSwitchingArpHandler extends AbstractVmHandler {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String GATEWAY_MAC = "gatewayMac";
private static final String DEFAULT_GATEWAY_MAC = "1f:1f:1f:1f:1f:1f";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
......@@ -67,9 +67,9 @@ public final class OpenstackArpHandler extends AbstractVmHandler {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenstackInterfaceService openstackService;
@Property(name = GATEWAY_MAC, value = DEFAULT_GATEWAY_MAC,
@Property(name = GATEWAY_MAC, value = DEFAULT_GATEWAY_MAC_STR,
label = "Fake MAC address for virtual network subnet gateway")
private String gatewayMac = DEFAULT_GATEWAY_MAC;
private String gatewayMac = DEFAULT_GATEWAY_MAC_STR;
private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
private final Set<Ip4Address> gateways = Sets.newConcurrentHashSet();
......
......@@ -126,7 +126,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource {
OpenstackRoutingService routingService
= getService(OpenstackRoutingService.class);
routingService.updateRouterInterface(openstackRouterInterface);
routingService.addRouterInterface(openstackRouterInterface);
log.debug("REST API AddRouterInterface is called from router {} portId: {}, subnetId: {}, tenantId: {}",
openstackRouterInterface.id(), openstackRouterInterface.portId(),
......@@ -147,7 +147,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource {
checkNotNull(id);
OpenstackRoutingService routingService
= getService(OpenstackRoutingService.class);
routingService.deleteRouter(id);
routingService.removeRouter(id);
log.debug("REST API DELETE routers is called {}", id);
return Response.noContent().build();
......
......@@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.openstackinterface.OpenstackFloatingIP;
import org.onosproject.openstackinterface.web.OpenstackFloatingIpCodec;
import org.onosproject.openstacknetworking.OpenstackRoutingService;
import org.onosproject.openstacknetworking.OpenstackFloatingIpService;
import org.onosproject.rest.AbstractWebResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -45,8 +45,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class OpenstackFloatingIpWebResource extends AbstractWebResource {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final OpenstackFloatingIpCodec FLOATING_IP_CODEC
= new OpenstackFloatingIpCodec();
private static final OpenstackFloatingIpCodec FLOATING_IP_CODEC = new OpenstackFloatingIpCodec();
/**
* Create FloatingIP.
......@@ -64,20 +63,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource {
ObjectMapper mapper = new ObjectMapper();
ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input);
OpenstackFloatingIP osFloatingIp =
FLOATING_IP_CODEC.decode(floatingIpNode, this);
OpenstackRoutingService routingService =
getService(OpenstackRoutingService.class);
routingService.createFloatingIP(osFloatingIp);
OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this);
OpenstackFloatingIpService floatingIpService =
getService(OpenstackFloatingIpService.class);
floatingIpService.createFloatingIp(osFloatingIp);
log.debug("REST API CREATE floatingip called");
return Response.status(Response.Status.OK).build();
} catch (Exception e) {
log.error("createFloatingIp failed with {}", e.toString());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
.build();
}
......@@ -102,20 +96,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource {
ObjectMapper mapper = new ObjectMapper();
ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input);
OpenstackFloatingIP osFloatingIp =
FLOATING_IP_CODEC.decode(floatingIpNode, this);
OpenstackRoutingService routingService =
getService(OpenstackRoutingService.class);
routingService.updateFloatingIP(osFloatingIp);
OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this);
OpenstackFloatingIpService floatingIpService =
getService(OpenstackFloatingIpService.class);
floatingIpService.updateFloatingIp(osFloatingIp);
log.debug("REST API UPDATE floatingip called {}", id);
return Response.status(Response.Status.OK).build();
} catch (Exception e) {
log.error("updateFloatingIp failed with {}", e.toString());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
.build();
}
......@@ -133,12 +122,11 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource {
public Response deleteFloatingIp(@PathParam("id") String id) {
checkNotNull(id);
OpenstackRoutingService routingService =
getService(OpenstackRoutingService.class);
routingService.deleteFloatingIP(id);
OpenstackFloatingIpService floatingIpService =
getService(OpenstackFloatingIpService.class);
floatingIpService.deleteFloatingIp(id);
log.debug("REST API DELETE floatingip is called {}", id);
return Response.noContent().build();
}
......
......@@ -79,7 +79,6 @@ public class OpenstackPortWebResource extends AbstractWebResource {
sgService.updateSecurityGroup(osPort);
return Response.status(Response.Status.OK).build();
} catch (IOException e) {
log.error("UpdatePort post process failed due to {}", e.getMessage());
......
......@@ -28,6 +28,7 @@ import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.openstacknode.Constants.PATCH_INTG_BRIDGE;
import static org.onosproject.openstacknode.OpenstackNodeEvent.NodeState.INIT;
/**
......@@ -182,6 +183,20 @@ public final class OpenstackNode {
return DeviceId.deviceId("ovsdb:" + managementIp.toString());
}
/**
* Returns the name of the port connected to the external network.
* It returns valid value only if the node is gateway node.
*
* @return external port name
*/
public Optional<String> externalPortName() {
if (type == NodeType.GATEWAY) {
return Optional.of(PATCH_INTG_BRIDGE);
} else {
return Optional.empty();
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
......