Kyuhwi Choi
Committed by Gerrit Code Review

[ONOS-3804] [ONOS-3805] Initial L3 flowrules setup for Compute/Gateway nodes and…

… PNAT Handler for OpenstackRouting

 - Performs app refactoring (openstackrouting and openstackswitching)
 - Implements L3 REST call corresponding openstackRouter and openstackRouterInterface.
 - Implements initail L3 rules population to compute/gateway node.
 - Implements PNAT rules population corresponding packet-in event.
 - Fixs comments and javadocs.
 - Rebases on master.

Change-Id: I5ad68810f50dc977737d30c43150c892b978b7cb
Showing 19 changed files with 153 additions and 1133 deletions
......@@ -15,6 +15,7 @@
*/
package org.onosproject.openstacknetworking;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.onlab.packet.Ip4Address;
import java.util.Map;
......@@ -60,7 +61,7 @@ public final class OpenstackExternalGateway {
* @return External fixed IP informations
*/
public Map<String, Ip4Address> externalFixedIps() {
return externalFixedIps;
return ImmutableMap.copyOf(externalFixedIps);
}
@Override
......@@ -137,7 +138,7 @@ public final class OpenstackExternalGateway {
* @return OpenstackExternalGateway object
*/
public OpenstackExternalGateway build() {
return new OpenstackExternalGateway(networkId, enablePnat, externalFixedIps);
return new OpenstackExternalGateway(networkId, enablePnat, ImmutableMap.copyOf(externalFixedIps));
}
}
......
......@@ -19,12 +19,14 @@ import org.onlab.packet.Ip4Address;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An Openstack Neutron Floating IP Model.
*/
public final class OpenstackFloatingIP {
public enum FloatingIPStatus {
public enum FloatingIpStatus {
UP,
DOWN,
ACTIVE,
......@@ -33,13 +35,13 @@ public final class OpenstackFloatingIP {
private final String tenantId;
private final String networkId;
private final Ip4Address fixedIpAddress;
private final String portId;
private final String routerId;
private String portId;
private String routerId;
private final String id;
private final Ip4Address floatingIpAddress;
private final FloatingIPStatus status;
private final FloatingIpStatus status;
private OpenstackFloatingIP(FloatingIPStatus status, String id, String tenantId,
private OpenstackFloatingIP(FloatingIpStatus status, String id, String tenantId,
String networkId, Ip4Address fixedIpAddress, String portId,
String routerId, Ip4Address floatingIpAddress) {
this.status = status;
......@@ -57,7 +59,7 @@ public final class OpenstackFloatingIP {
*
* @return floating IP status
*/
public FloatingIPStatus status() {
public FloatingIpStatus status() {
return status;
}
......@@ -107,6 +109,15 @@ public final class OpenstackFloatingIP {
}
/**
* Updates port ID.
*
* @param portId Updated port ID
*/
public void updatePortId(String portId) {
this.portId = portId;
}
/**
* Returns router ID.
*
* @return router ID
......@@ -116,6 +127,15 @@ public final class OpenstackFloatingIP {
}
/**
* Updates router ID.
*
* @param routerId Updated router ID
*/
public void updateRouterId(String routerId) {
this.routerId = routerId;
}
/**
* Returns floating IP address.
*
* @return Floating IP address
......@@ -162,7 +182,7 @@ public final class OpenstackFloatingIP {
private String routerId;
private String id;
private Ip4Address floatingIpAddress;
private FloatingIPStatus status;
private FloatingIpStatus status;
/**
* Sets tenant ID.
......@@ -181,7 +201,7 @@ public final class OpenstackFloatingIP {
* @param status Floating IP status
* @return Builder object
*/
public Builder status(FloatingIPStatus status) {
public Builder status(FloatingIpStatus status) {
this.status = status;
return this;
}
......@@ -258,8 +278,9 @@ public final class OpenstackFloatingIP {
* @return OpenstackFloatingIP object
*/
public OpenstackFloatingIP build() {
return new OpenstackFloatingIP(status, id, tenantId, networkId,
fixedIpAddress, portId, routerId, floatingIpAddress);
return new OpenstackFloatingIP(checkNotNull(status), checkNotNull(id), checkNotNull(tenantId),
checkNotNull(networkId), fixedIpAddress, portId,
routerId, checkNotNull(floatingIpAddress));
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.openstacknetworking;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An Openstack Neutron Router Model.
......@@ -31,9 +32,9 @@ public final class OpenstackRouter {
private final String tenantId;
private final String id;
private final String name;
private final RouterStatus status;
private final boolean adminStateUp;
private final OpenstackExternalGateway gatewayExternalInfo;
private RouterStatus status;
private boolean adminStateUp;
private OpenstackExternalGateway gatewayExternalInfo;
private OpenstackRouter(String id, String tenantId, String name, RouterStatus status,
boolean adminStateUp, OpenstackExternalGateway gatewayExternalInfo) {
......@@ -209,8 +210,8 @@ public final class OpenstackRouter {
* @return OpenstasckRouter object
*/
public OpenstackRouter build() {
return new OpenstackRouter(id, tenantId, name, status,
adminStateUp, gatewayExternalInfo);
return new OpenstackRouter(checkNotNull(id), checkNotNull(tenantId), name, checkNotNull(status),
checkNotNull(adminStateUp), gatewayExternalInfo);
}
}
......
......@@ -148,14 +148,14 @@ public final class OpenstackRouterInterface {
return this;
}
/**
* Builds an Openstack Router Interface object.
*
* @return OpenstackRouterInterface object
*/
public OpenstackRouterInterface build() {
return new OpenstackRouterInterface(id, tenantId, subnetId, portId);
return new OpenstackRouterInterface(checkNotNull(id), checkNotNull(tenantId),
checkNotNull(subnetId), checkNotNull(portId));
}
}
......
......@@ -17,24 +17,29 @@ package org.onosproject.openstacknetworking.routing;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TCP;
import org.onlab.packet.UDP;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.Port;
import org.onosproject.net.flow.DefaultTrafficTreatment;
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.PacketService;
import org.onosproject.openstacknetworking.OpenstackNetwork;
import org.onosproject.openstacknetworking.OpenstackNetworkingService;
import org.onosproject.openstacknetworking.OpenstackPort;
import org.onosproject.openstacknetworking.OpenstackRouter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.osgi.DefaultServiceDirectory.getService;
/**
......@@ -50,13 +55,20 @@ public class OpenstackPnatHandler implements Runnable {
private final OpenstackRoutingRulePopulator rulePopulator;
private final int portNum;
private final OpenstackPort openstackPort;
private final Port port;
private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface";
// TODO: This will be replaced to get the information from openstacknetworkingservice.
private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f");
private static final MacAddress EXTERNAL_INTERFACE_MAC = MacAddress.valueOf("00:00:00:00:00:11");
OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context,
int portNum, OpenstackPort openstackPort) {
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);
}
@Override
......@@ -70,14 +82,41 @@ public class OpenstackPnatHandler implements Runnable {
return;
}
packetOut(inboundPacket, portNum);
OpenstackRouter router = getOpenstackRouter(openstackPort);
rulePopulator.populatePnatFlowRules(inboundPacket, openstackPort, portNum,
getExternalInterfaceMacAddress(), getExternalRouterMacAddress());
getExternalIp(router), getExternalInterfaceMacAddress(), getExternalRouterMacAddress());
packetOut((Ethernet) ethernet.clone(), inboundPacket.receivedFrom().deviceId(), portNum, router);
}
private void packetOut(InboundPacket inboundPacket, int portNum) {
Ethernet ethernet = checkNotNull(inboundPacket.parsed());
private OpenstackRouter getOpenstackRouter(OpenstackPort openstackPort) {
OpenstackNetworkingService networkingService = getService(OpenstackNetworkingService.class);
OpenstackNetwork network = networkingService.network(openstackPort.networkId());
OpenstackPort port = networkingService.ports()
.stream()
.filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE))
.filter(p -> checkSameSubnet(p, openstackPort))
.findAny()
.orElse(null);
return checkNotNull(networkingService.router(port.deviceId()));
}
private boolean checkSameSubnet(OpenstackPort p, OpenstackPort openstackPort) {
String key1 = checkNotNull(p.fixedIps().keySet().stream().findFirst().orElse(null)).toString();
String key2 = checkNotNull(openstackPort.fixedIps().keySet().stream().findFirst().orElse(null)).toString();
return key1.equals(key2) ? true : false;
}
private Ip4Address getExternalIp(OpenstackRouter router) {
return router.gatewayExternalInfo().externalFixedIps().values().stream().findAny().orElse(null);
}
private void packetOut(Ethernet ethernet, DeviceId deviceId, int portNum, OpenstackRouter router) {
PacketService packetService = getService(PacketService.class);
IPv4 iPacket = (IPv4) ethernet.getPayload();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
......@@ -98,31 +137,27 @@ public class OpenstackPnatHandler implements Runnable {
iPacket.setPayload(udpPacket);
break;
default:
break;
log.error("Temporally, this method can process UDP and TCP protocol.");
return;
}
iPacket.setSourceAddress(getExternalIp(router).toString());
iPacket.resetChecksum();
iPacket.setPayload(ethernet);
iPacket.setParent(ethernet);
ethernet.setSourceMACAddress(getExternalInterfaceMacAddress())
.setDestinationMACAddress(getExternalRouterMacAddress());
ethernet.resetChecksum();
treatment.setOutput(getExternalPort(inboundPacket.receivedFrom().deviceId()));
treatment.setOutput(port.number());
packetService.emit(new DefaultOutboundPacket(inboundPacket.receivedFrom().deviceId(),
treatment.build(), ByteBuffer.wrap(ethernet.serialize())));
packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(),
ByteBuffer.wrap(ethernet.serialize())));
}
private PortNumber getExternalPort(DeviceId deviceId) {
// TODO
return null;
}
private MacAddress getExternalInterfaceMacAddress() {
// TODO
return null;
return EXTERNAL_INTERFACE_MAC;
}
private MacAddress getExternalRouterMacAddress() {
// TODO
return null;
return GATEWAYMAC;
}
}
\ No newline at end of file
......
......@@ -29,6 +29,8 @@ import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flowobjective.FlowObjectiveService;
......@@ -55,14 +57,14 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.groupedThreads;
@Service
@Component(immediate = true)
@Service
/**
* Populates flow rules about L3 functionality for VMs in Openstack.
*/
public class OpenstackRoutingManager implements OpenstackRoutingService {
private final Logger log = LoggerFactory
.getLogger(getClass());
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
......@@ -86,6 +88,12 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
private Map<String, OpenstackRouterInterface> routerInterfaceMap = Maps.newHashMap();
private Map<Integer, String> portNumMap = initPortNumMap();
private static final String APP_ID = "org.onosproject.openstackrouting";
private static final String PORT_NAME = "portName";
private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface";
// TODO: This will be replaced to get the information from openstackswitchingservice.
private static final String EXTERNAL_INTERFACE_NAME = "veth0";
private Map<Integer, String> initPortNumMap() {
Map<Integer, String> map = Maps.newHashMap();
for (int i = 1024; i < 65535; i++) {
......@@ -104,7 +112,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
protected void activate() {
appId = coreService.registerApplication(APP_ID);
packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1));
reloadInitL3Rules();
log.info("onos-openstackrouting started");
}
......@@ -150,7 +158,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
routerInterfaceMap.putIfAbsent(routerInterface.portId(), routerInterface);
List<OpenstackRouterInterface> routerInterfaces = Lists.newArrayList();
routerInterfaces.add(routerInterface);
checkExternalConnection(getOpenstackRouter(routerInterface.tenantId()), routerInterfaces);
checkExternalConnection(getOpenstackRouter(routerInterface.portId()), routerInterfaces);
}
@Override
......@@ -160,6 +168,27 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
rulePopulator.removeExternalRules(routerInterface);
routerInterfaceMap.remove(routerInterface.portId());
}
private void reloadInitL3Rules() {
openstackService.ports()
.stream()
.filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE))
.forEach(p -> {
OpenstackRouterInterface routerInterface = portToRouterInterface(p);
updateRouterInterface(routerInterface);
});
}
private OpenstackRouterInterface portToRouterInterface(OpenstackPort p) {
OpenstackRouterInterface.Builder osBuilder = new OpenstackRouterInterface.Builder()
.id(checkNotNull(p.id()))
.tenantId(checkNotNull(openstackService.network(p.networkId()).tenantId()))
.subnetId(checkNotNull(p.fixedIps().keySet().stream().findFirst().orElse(null)).toString())
.portId(checkNotNull(p.deviceId()));
return osBuilder.build();
}
private class InternalPacketProcessor implements PacketProcessor {
@Override
......@@ -183,10 +212,15 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
break;
default:
int portNum = getPortNum(ethernet.getSourceMAC(), iPacket.getDestinationAddress());
Port port = getExternalPort(pkt.receivedFrom().deviceId(), EXTERNAL_INTERFACE_NAME);
if (port == null) {
log.warn("There`s no external interface");
break;
}
OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(),
Ip4Address.valueOf(iPacket.getSourceAddress()));
l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context,
portNum, openstackPort));
portNum, openstackPort, port));
break;
}
......@@ -201,24 +235,30 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
}
}
private Port getExternalPort(DeviceId deviceId, String interfaceName) {
return deviceService.getPorts(deviceId)
.stream()
.filter(p -> p.annotations().value(PORT_NAME).equals(interfaceName))
.findAny()
.orElse(null);
}
private void checkExternalConnection(OpenstackRouter router,
Collection<OpenstackRouterInterface> routerInterfaces) {
checkNotNull(router, "Router can not be null");
checkNotNull(routerInterfaces, "RouterInterfaces can not be null");
checkNotNull(routerInterfaces, "routerInterfaces can not be null");
Ip4Address externalIp = router.gatewayExternalInfo().externalFixedIps()
.values().stream().findFirst().orElse(null);
if ((externalIp == null) || (!router.gatewayExternalInfo().isEnablePnat())) {
log.debug("Failed to set pnat configuration");
log.debug("Not satisfied to set pnat configuration");
return;
}
routerInterfaces.forEach(routerInterface -> {
initiateL3Rule(router, routerInterface);
});
routerInterfaces.forEach(routerInterface -> initiateL3Rule(router, routerInterface));
}
private void initiateL3Rule(OpenstackRouter router, OpenstackRouterInterface routerInterface) {
long vni = Long.parseLong(openstackService.network(openstackService
.port(routerInterface.portId()).networkId()).segmentId());
.port(routerInterface.id()).networkId()).segmentId());
OpenstackRoutingRulePopulator rulePopulator = new OpenstackRoutingRulePopulator(appId,
openstackService, flowObjectiveService, deviceService, driverService);
rulePopulator.populateExternalRules(vni, router, routerInterface);
......@@ -229,15 +269,15 @@ public class OpenstackRoutingManager implements OpenstackRoutingService {
.collect(Collectors.toList());
}
private OpenstackRouter getOpenstackRouter(String tenantId) {
private OpenstackRouter getOpenstackRouter(String id) {
return openstackService.routers().stream().filter(r ->
r.tenantId().equals(tenantId)).findFirst().orElse(null);
r.id().equals(id)).findAny().orElse(null);
}
private OpenstackPort getOpenstackPort(MacAddress sourceMac, Ip4Address ip4Address) {
OpenstackPort openstackPort = openstackService.ports("").stream()
OpenstackPort openstackPort = openstackService.ports().stream()
.filter(p -> p.macAddress().equals(sourceMac)).findFirst().orElse(null);
return openstackPort.fixedIps().values().stream().findFirst().orElse(null)
return checkNotNull(openstackPort.fixedIps().values().stream().findFirst().orElse(null))
.equals(ip4Address) ? openstackPort : null;
}
......
/*
* Copyright 2016 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.openstackrouting;
import com.google.common.collect.ImmutableMap;
import org.onlab.packet.Ip4Address;
import java.util.HashMap;
import java.util.Map;
/**
* A configurable external gateway modes extension model in openstack router.
*/
public final class OpenstackExternalGateway {
private String networkId;
private boolean enablePnat;
private Map<String, Ip4Address> externalFixedIps;
private OpenstackExternalGateway(String networkId, boolean enablePnat,
Map<String, Ip4Address> externalFixedIps) {
this.networkId = networkId;
this.enablePnat = enablePnat;
this.externalFixedIps = externalFixedIps;
}
public static OpenstackExternalGateway.Builder builder() {
return new Builder();
}
/**
* Returns network ID.
*
* @return Network ID
*/
public String networkId() {
return networkId;
}
/**
* Returns the PNAT status for external gateway.
*
* @return PNAT status
*/
public boolean isEnablePnat() {
return enablePnat;
}
public Map<String, Ip4Address> externalFixedIps() {
return ImmutableMap.copyOf(externalFixedIps);
}
/**
* An Openstack External Gateway Builder class.
*/
public static final class Builder {
private String networkId;
private boolean enablePnat;
private Map<String, Ip4Address> externalFixedIps;
Builder() {
externalFixedIps = new HashMap<>();
}
/**
* Sets network ID.
*
* @param networkId Network ID
* @return Builder object
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return this;
}
/**
* Sets whether PNAT status is enabled or not.
*
* @param enablePnat true if PNAT status is enabled, false otherwise
* @return Builder object
*/
public Builder enablePnat(boolean enablePnat) {
this.enablePnat = enablePnat;
return this;
}
/**
* Sets external fixed IP address information.
*
* @param externalFixedIps External fixed IP information
* @return Builder object
*/
public Builder externalFixedIps(Map<String, Ip4Address> externalFixedIps) {
this.externalFixedIps.putAll(externalFixedIps);
return this;
}
/**
* Builds an OpenstackExternalGateway object.
*
* @return OpenstackExternalGateway object
*/
public OpenstackExternalGateway build() {
return new OpenstackExternalGateway(networkId, enablePnat, externalFixedIps);
}
}
}
/*
* Copyright 2016 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.openstackrouting;
import org.onlab.packet.Ip4Address;
/**
* An Openstack Neutron Floating IP Model.
*/
public final class OpenstackFloatingIP {
public enum FloatingIPStatus {
UP,
DOWN,
ACTIVE,
}
private String tenantId;
private String networkId;
private Ip4Address fixedIpAddress;
private String portId;
private String routerId;
private String id;
private Ip4Address floatingIpAddress;
private FloatingIPStatus status;
private OpenstackFloatingIP(FloatingIPStatus status, String id, String tenantId,
String networkId, Ip4Address fixedIpAddress, String portId,
String routerId, Ip4Address floatingIpAddress) {
this.status = status;
this.id = id;
this.tenantId = tenantId;
this.networkId = networkId;
this.fixedIpAddress = fixedIpAddress;
this.portId = portId;
this.routerId = routerId;
this.floatingIpAddress = floatingIpAddress;
}
/**
* Returns floating ip status.
*
* @return floating ip status
*/
public FloatingIPStatus status() {
return status;
}
/**
* Returns floating ip`s ID.
*
* @return floating ip`s ID
*/
public String id() {
return id;
}
/**
* Returns tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
/**
* Returns network ID.
*
* @return network ID
*/
public String networkId() {
return networkId;
}
/**
* Returns fixed IP Address.
*
* @return fixed IP Address
*/
public Ip4Address fixedIpAddress() {
return fixedIpAddress;
}
/**
* Returns port ID.
*
* @return port ID
*/
public String portId() {
return portId;
}
/**
* Returns router ID.
*
* @return router ID
*/
public String routerId() {
return routerId;
}
/**
* Returns floating IP address.
*
* @return Floating IP address
*/
public Ip4Address floatingIpAddress() {
return floatingIpAddress;
}
/**
* An Openstack Floating IP Builder class.
*/
public static final class Builder {
private String tenantId;
private String networkId;
private Ip4Address fixedIpAddress;
private String portId;
private String routerId;
private String id;
private Ip4Address floatingIpAddress;
private FloatingIPStatus status;
/**
* Sets tenant ID.
*
* @param tenantId tenant ID
* @return Builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets floating IP status.
*
* @param status Floating IP status
* @return Builder object
*/
public Builder status(FloatingIPStatus status) {
this.status = status;
return this;
}
/**
* Sets Floating IP`s ID.
*
* @param id Floating IP`s ID
* @return Builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets network ID.
*
* @param networkId Network ID
* @return Builder object
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return this;
}
/**
* Sets fixed IP address.
*
* @param fixedIpAddress Fixed IP address
* @return Builder object
*/
public Builder fixedIpAddress(Ip4Address fixedIpAddress) {
this.fixedIpAddress = fixedIpAddress;
return this;
}
/**
* Sets port ID.
*
* @param portId port ID
* @return Builder object
*/
public Builder portId(String portId) {
this.portId = portId;
return this;
}
/**
* Sets router ID.
*
* @param routerId router ID
* @return Builder object
*/
public Builder routerId(String routerId) {
this.routerId = routerId;
return this;
}
/**
* Sets floating IP address.
*
* @param floatingIpAddress Floating IP address
* @return Builder object
*/
public Builder floatingIpAddress(Ip4Address floatingIpAddress) {
this.floatingIpAddress = floatingIpAddress;
return this;
}
/**
* Builds an OpenstackFloatingIP object.
*
* @return OpenstackFloatingIP object
*/
public OpenstackFloatingIP build() {
return new OpenstackFloatingIP(status, id, tenantId, networkId,
fixedIpAddress, portId, routerId, floatingIpAddress);
}
}
}
/*
* Copyright 2016 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.openstackrouting;
import org.onosproject.event.AbstractEvent;
/**
* Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes.
*/
public class OpenstackFloatingIPHandler implements Runnable {
volatile AbstractEvent event;
OpenstackFloatingIPHandler(AbstractEvent event) {
this.event = event;
}
@Override
public void run() {
}
}
/*
* Copyright 2016 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.openstackrouting;
import org.onosproject.net.packet.PacketContext;
/**
* Handle ICMP packet processing for Managing Flow Rules In Openstack Nodes.
*/
public class OpenstackIcmpHandler implements Runnable {
volatile PacketContext context;
OpenstackIcmpHandler(PacketContext context) {
this.context = context;
}
@Override
public void run() {
}
}
\ No newline at end of file
/*
* Copyright 2016 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.openstackrouting;
import org.onosproject.net.packet.PacketContext;
/**
* Handle NAT packet processing for Managing Flow Rules In Openstack Nodes.
*/
public class OpenstackPnatHandler implements Runnable {
volatile PacketContext context;
OpenstackPnatHandler(PacketContext context) {
this.context = context;
}
@Override
public void run() {
}
}
\ No newline at end of file
/*
* Copyright 2016 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.openstackrouting;
/**
* An Openstack Neutron Router Model.
*/
public final class OpenstackRouter {
public enum RouterStatus {
UP,
DOWN,
ACTIVE,
}
private String tenantId;
private String id;
private String name;
private RouterStatus status;
private boolean adminStateUp;
private OpenstackExternalGateway gatewayExternalInfo;
private OpenstackRouter(String id, String tenantId, String name, RouterStatus status,
boolean adminStateUp, OpenstackExternalGateway gatewayExternalInfo) {
this.id = id;
this.tenantId = tenantId;
this.name = name;
this.status = status;
this.adminStateUp = adminStateUp;
this.gatewayExternalInfo = gatewayExternalInfo;
}
public static OpenstackRouter.Builder builder() {
return new Builder();
}
/**
* Returns tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
/**
* Returns router ID.
*
* @return router ID
*/
public String id() {
return id;
}
/**
* Returns router name.
*
* @return router name
*/
public String name() {
return name;
}
/**
* Returns router status.
*
* @return router stauts
*/
public RouterStatus status() {
return status;
}
/**
* Returns whether admin state up or not.
*
* @return true if admin state up, false otherwise
*/
public boolean adminStateUp() {
return adminStateUp;
}
/**
* Returns external gateway information.
*
* @return external gateway information
*/
public OpenstackExternalGateway gatewayExternalInfo() {
return gatewayExternalInfo;
}
/**
* An Openstack Router Builder class.
*/
public static final class Builder {
private String tenantId;
private String id;
private String name;
private RouterStatus status;
private Boolean adminStateUp;
private OpenstackExternalGateway gatewayExternalInfo;
/**
* Sets router ID.
*
* @param id router ID
* @return Builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets router name.
*
* @param name router name
* @return Builder object
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Sets router status.
*
* @param status router status
* @return Builder object
*/
public Builder status(RouterStatus status) {
this.status = status;
return this;
}
/**
* Sets tenant ID.
*
* @param tenantId Tenant ID
* @return Builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets whether admin state up or not.
*
* @param adminStateUp true if admin state is up, false otherwise
* @return Builder object
*/
public Builder adminStateUp(boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return this;
}
/**
* Sets external gateway information.
*
* @param gatewayExternalInfo external gateway information
* @return Builder object
*/
public Builder gatewayExternalInfo(OpenstackExternalGateway gatewayExternalInfo) {
this.gatewayExternalInfo = gatewayExternalInfo;
return this;
}
/**
* Builds an OpenstackRouter object.
*
* @return OpenstasckRouter object
*/
public OpenstackRouter build() {
return new OpenstackRouter(id, tenantId, name, status,
adminStateUp, gatewayExternalInfo);
}
}
}
/*
* Copyright 2016 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.openstackrouting;
/**
* An Openstack Neutron Router Interface Model.
*/
public final class OpenstackRouterInterface {
private String id;
private String tenantId;
private String subnetId;
private String portId;
private OpenstackRouterInterface(String id, String tenantId,
String subnetId, String portId) {
this.id = id;
this.tenantId = tenantId;
this.subnetId = subnetId;
this.portId = portId;
}
/**
* Returns Router Interface ID.
*
* @return router interface ID
*/
public String id() {
return id;
}
/**
* Returns tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
/**
* Returns subnet ID.
*
* @return subnet ID
*/
public String subnetId() {
return subnetId;
}
/**
* Returns port ID.
*
* @return port ID
*/
public String portId() {
return portId;
}
/**
* An Openstack Router Interface Builder class.
*/
public static final class Builder {
private String id;
private String tenantId;
private String subnetId;
private String portId;
/**
* Sets Router Interface ID.
*
* @param id router interface ID
* @return Builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets tenant ID.
*
* @param tenantId tenant ID
* @return Builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets subnet ID.
*
* @param subnetId subnet ID
* @return Builder object
*/
public Builder subnetId(String subnetId) {
this.subnetId = subnetId;
return this;
}
/**
* Sets port ID.
*
* @param portId port ID
* @return Builder object
*/
public Builder portId(String portId) {
this.portId = portId;
return this;
}
/**
* Builds an Openstack Router Interface object.
*
* @return OpenstackRouterInterface object
*/
public OpenstackRouterInterface build() {
return new OpenstackRouterInterface(id, tenantId, subnetId, portId);
}
}
}
/*
* Copyright 2016 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.openstackrouting;
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.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static org.onlab.util.Tools.groupedThreads;
@Service
@Component(immediate = true)
/**
* Populates flow rules about L3 functionality for VMs in Openstack.
*/
public class OpenstackRoutingManager implements OpenstackRoutingService {
private static Logger log = LoggerFactory
.getLogger(OpenstackRoutingManager.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService;
private ApplicationId appId;
private OpenstackIcmpHandler icmpHandler;
private OpenstackPnatHandler natHandler;
private OpenstackFloatingIPHandler floatingIPHandler;
private OpenstackRoutingRulePopulator openstackRoutingRulePopulator;
private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor();
private ExecutorService l3EventExcutorService =
Executors.newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "L3-event"));
private ExecutorService icmpEventExcutorService =
Executors.newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "icmp-event"));
@Activate
protected void activate() {
appId = coreService.registerApplication("org.onosproject.openstackrouting");
packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1));
log.info("onos-openstackrouting started");
}
@Deactivate
protected void deactivate() {
packetService.removeProcessor(internalPacketProcessor);
log.info("onos-openstackrouting stopped");
}
@Override
public void createFloatingIP(OpenstackFloatingIP openstackFloatingIP) {
}
@Override
public void updateFloatingIP(OpenstackFloatingIP openstackFloatingIP) {
}
@Override
public void deleteFloatingIP(String id) {
}
@Override
public void createRouter(OpenstackRouter openstackRouter) {
}
@Override
public void updateRouter(OpenstackRouter openstackRouter) {
}
@Override
public void deleteRouter(String id) {
}
@Override
public void createRouterInterface(OpenstackRouterInterface openstackRouterInterface) {
}
@Override
public void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface) {
}
@Override
public void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface) {
}
private class InternalPacketProcessor implements PacketProcessor {
@Override
public void process(PacketContext context) {
if (context.isHandled()) {
return;
}
InboundPacket pkt = context.inPacket();
Ethernet ethernet = pkt.parsed();
if (ethernet != null && ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
IPv4 iPacket = (IPv4) ethernet.getPayload();
switch (iPacket.getProtocol()) {
case IPv4.PROTOCOL_ICMP:
icmpEventExcutorService.execute(new OpenstackIcmpHandler(context));
break;
default:
l3EventExcutorService.execute(new OpenstackPnatHandler(context));
break;
}
}
}
}
}
/*
* Copyright 2016 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.openstackrouting;
/**
* Populates Routing Flow Rules.
*/
public class OpenstackRoutingRulePopulator {
}
/*
* Copyright 2016 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.openstackrouting;
/**
* The Interface of Openstack Routing.
*/
public interface OpenstackRoutingService {
/**
* Stores the Floating IP information created by Openstack.
*
* @param openstackFloatingIP Floating IP information
*/
void createFloatingIP(OpenstackFloatingIP openstackFloatingIP);
/**
* Updates flow rules corresponding to the Floating IP information updated by Openstack.
*
* @param openstackFloatingIP Floating IP information
*/
void updateFloatingIP(OpenstackFloatingIP openstackFloatingIP);
/**
* Removes flow rules corresponding to Floating IP information deleted by Openstack.
*
* @param id Deleted Floating IP`s ID
*/
void deleteFloatingIP(String id);
/**
* Stores the router information created by Openstack.
*
* @param openstackRouter Floating IP information
*/
void createRouter(OpenstackRouter openstackRouter);
/**
* Updates flow rules corresponding to the router information updated by Openstack.
*
* @param openstackRouter Router information
*/
void updateRouter(OpenstackRouter openstackRouter);
/**
* Removes flow rules corresponding to the router information deleted by Openstack.
*
* @param id Deleted router`s ID
*/
void deleteRouter(String id);
/**
* Stores the router information created by Openstack.
*
* @param openstackRouterInterface Floating IP information
*/
void createRouterInterface(OpenstackRouterInterface openstackRouterInterface);
/**
* Updates flow rules corresponding to the router information updated by Openstack.
*
* @param openstackRouterInterface Router information
*/
void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface);
/**
* Removes flow rules corresponding to the router information removed by Openstack.
*
* @param openstackRouterInterface Router information
*/
void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface);
}
/*
* Copyright 2016 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.
*/
/**
* Application for OpenstackRouting.
*/
package org.onosproject.openstackrouting;
\ No newline at end of file
......@@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-openstackrouting</artifactId>
<artifactId>onos-app-openstackrouting-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
......