Daniel Park
Committed by Gerrit Code Review

[ONOS-3688] Implement application for Openstack Node bootstrap

- Using OVSDB connnection, it makes bridge and vxlan tunnel for Openstack Nodes.
- Reading nodes information from network config supported

Change-Id: I1c0483b146ace19cd77ac91141182ee9200a9432
{
"apps" : {
"org.onosproject.openstacknode" : {
"openstacknode" : {
"nodes" : [
{
"hostname" : "compute-01",
"ovsdbIp" : "192.168.56.112",
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000001",
"openstackNodeType" : "COMPUTENODE"
},
{
"hostname" : "compute-02",
"ovsdbIp" : "192.168.56.106",
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000002",
"openstackNodeType" : "COMPUTENODE"
},
{
"hostname" : "network",
"ovsdbIp" : "192.168.56.108",
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000003",
"openstackNodeType" : "GATEWAYNODE",
"gatewayExternalInterfaceName" : "eth1",
"gatewayExternalInterfaceMac" : "00:00:00:00:00:10"
}
]
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-apps</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-openstacknode</artifactId>
<packaging>bundle</packaging>
<description>SONA Openstack Node Bootstrap Application</description>
<properties>
<onos.app.name>org.onosproject.openstacknode</onos.app.name>
<onos.app.category>default</onos.app.category>
<onos.app.url>http://onosproject.org</onos.app.url>
<onos.app.readme>SONA Openstack Node Bootstrap Application</onos.app.readme>
<onos.app.requires>
org.onosproject.ovsdb
</onos.app.requires>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
</project>
/*
* 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.openstacknode;
/**
* Entity capable of handling a subject connected and disconnected situation.
*/
public interface ConnectionHandler<T> {
/**
* Processes the connected subject.
*
* @param subject subject
*/
void connected(T subject);
/**
* Processes the disconnected subject.
*
* @param subject subject.
*/
void disconnected(T subject);
}
/*
* 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.openstacknode;
import com.google.common.base.MoreObjects;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onosproject.net.DeviceId;
import java.util.Comparator;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of a compute/gateway node for OpenstackSwitching/Routing service.
*/
public final class OpenstackNode {
private final String hostName;
private final IpAddress ovsdbIp;
private final TpPort ovsdbPort;
private final DeviceId bridgeId;
private final OpenstackNodeService.OpenstackNodeType openstackNodeType;
private final String gatewayExternalInterfaceName;
private final MacAddress gatewayExternalInterfaceMac;
private static final String OVSDB = "ovsdb:";
public static final Comparator<OpenstackNode> OPENSTACK_NODE_COMPARATOR =
(node1, node2) -> node1.hostName().compareTo(node2.hostName());
/**
* Creates a new node.
*
* @param hostName hostName
* @param ovsdbIp OVSDB server IP address
* @param ovsdbPort OVSDB server port number
* @param bridgeId integration bridge identifier
* @param openstackNodeType openstack node type
* @param gatewayExternalInterfaceName gatewayExternalInterfaceName
* @param gatewayExternalInterfaceMac gatewayExternalInterfaceMac
*/
public OpenstackNode(String hostName, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId,
OpenstackNodeService.OpenstackNodeType openstackNodeType,
String gatewayExternalInterfaceName,
MacAddress gatewayExternalInterfaceMac) {
this.hostName = checkNotNull(hostName, "hostName cannot be null");
this.ovsdbIp = checkNotNull(ovsdbIp, "ovsdbIp cannot be null");
this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null");
this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null");
this.openstackNodeType = checkNotNull(openstackNodeType, "openstackNodeType cannot be null");
this.gatewayExternalInterfaceName = gatewayExternalInterfaceName;
this.gatewayExternalInterfaceMac = gatewayExternalInterfaceMac;
if (openstackNodeType == OpenstackNodeService.OpenstackNodeType.GATEWAYNODE) {
checkNotNull(gatewayExternalInterfaceName, "gatewayExternalInterfaceName cannot be null");
checkNotNull(gatewayExternalInterfaceMac, "gatewayExternalInterfaceMac cannot be null");
}
}
/**
* Returns the OVSDB server IP address.
*
* @return ip address
*/
public IpAddress ovsdbIp() {
return this.ovsdbIp;
}
/**
* Returns the OVSDB server port number.
*
* @return port number
*/
public TpPort ovsdbPort() {
return this.ovsdbPort;
}
/**
* Returns the hostName.
*
* @return hostName
*/
public String hostName() {
return this.hostName;
}
/**
* Returns the identifier of the integration bridge.
*
* @return device id
*/
public DeviceId intBrId() {
return this.bridgeId;
}
/**
* Returns the identifier of the OVSDB device.
*
* @return device id
*/
public DeviceId ovsdbId() {
return DeviceId.deviceId(OVSDB.concat(this.ovsdbIp.toString()));
}
/**
* Returns the openstack node type.
*
* @return openstack node type
*/
public OpenstackNodeService.OpenstackNodeType openstackNodeType() {
return this.openstackNodeType;
}
/**
* Returns the gatewayExternalInterfaceName.
*
* @return gatewayExternalInterfaceName
*/
public String gatewayExternalInterfaceName() {
return this.gatewayExternalInterfaceName;
}
/**
* Returns the gatewayExternalInterfaceMac.
*
* @return gatewayExternalInterfaceMac
*/
public MacAddress gatewayExternalInterfaceMac() {
return this.gatewayExternalInterfaceMac;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OpenstackNode) {
OpenstackNode that = (OpenstackNode) obj;
if (Objects.equals(hostName, that.hostName) &&
Objects.equals(ovsdbIp, that.ovsdbIp) &&
Objects.equals(ovsdbPort, that.ovsdbPort) &&
Objects.equals(bridgeId, that.bridgeId) &&
Objects.equals(openstackNodeType, that.openstackNodeType)) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(hostName, ovsdbIp, ovsdbPort, bridgeId, openstackNodeType);
}
@Override
public String toString() {
if (openstackNodeType == OpenstackNodeService.OpenstackNodeType.COMPUTENODE) {
return MoreObjects.toStringHelper(getClass())
.add("host", hostName)
.add("ip", ovsdbIp)
.add("port", ovsdbPort)
.add("bridgeId", bridgeId)
.add("openstacknodetype", openstackNodeType)
.toString();
} else {
return MoreObjects.toStringHelper(getClass())
.add("host", hostName)
.add("ip", ovsdbIp)
.add("port", ovsdbPort)
.add("bridgeId", bridgeId)
.add("openstacknodetype", openstackNodeType)
.add("gatewayExternalInterfaceName", gatewayExternalInterfaceName)
.add("gatewayExternalInterfaceMac", gatewayExternalInterfaceMac)
.toString();
}
}
}
/*
* 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.openstacknode;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.slf4j.Logger;
import java.util.Set;
import org.onosproject.net.config.Config;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Configuration object for OpensatckNode service.
*/
public class OpenstackNodeConfig extends Config<ApplicationId> {
protected final Logger log = getLogger(getClass());
public static final String NODES = "nodes";
public static final String HOST_NAME = "hostname";
public static final String OVSDB_IP = "ovsdbIp";
public static final String OVSDB_PORT = "ovsdbPort";
public static final String BRIDGE_ID = "bridgeId";
public static final String NODE_TYPE = "openstackNodeType";
public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName";
public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac";
/**
* Returns the set of nodes read from network config.
*
* @return set of OpensatckNodeConfig or null
*/
public Set<OpenstackNode> openstackNodes() {
Set<OpenstackNode> nodes = Sets.newHashSet();
JsonNode jsonNodes = object.get(NODES);
if (jsonNodes == null) {
return null;
}
jsonNodes.forEach(jsonNode -> {
try {
if (OpenstackNodeService.OpenstackNodeType.valueOf(jsonNode.path(NODE_TYPE).asText()) ==
OpenstackNodeService.OpenstackNodeType.COMPUTENODE) {
nodes.add(new OpenstackNode(
jsonNode.path(HOST_NAME).asText(),
Ip4Address.valueOf(jsonNode.path(OVSDB_IP).asText()),
TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()),
DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
OpenstackNodeService.OpenstackNodeType.valueOf(jsonNode.path(NODE_TYPE).asText()),
null, MacAddress.NONE));
} else {
nodes.add(new OpenstackNode(
jsonNode.path(HOST_NAME).asText(),
Ip4Address.valueOf(jsonNode.path(OVSDB_IP).asText()),
TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()),
DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
OpenstackNodeService.OpenstackNodeType.valueOf(jsonNode.path(NODE_TYPE).asText()),
jsonNode.path(GATEWAY_EXTERNAL_INTERFACE_NAME).asText(),
MacAddress.valueOf(jsonNode.path(GATEWAY_EXTERNAL_INTERFACE_MAC).asText())));
}
} catch (IllegalArgumentException | NullPointerException e) {
log.error("Failed to read {}", e.toString());
}
});
return nodes;
}
}
/*
* 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.openstacknode;
import java.util.List;
/**
* Handles the bootstrap request for compute/gateway node.
*/
public interface OpenstackNodeService {
public enum OpenstackNodeType {
/**
* Compute or Gateway Node.
*/
COMPUTENODE,
GATEWAYNODE
}
/**
* Adds a new node to the service.
*
* @param node openstack node
*/
void addNode(OpenstackNode node);
/**
* Deletes a node from the service.
*
* @param node openstack node
*/
void deleteNode(OpenstackNode node);
/**
* Returns nodes known to the service for designated openstacktype.
*
* @param openstackNodeType openstack node type
* @return list of nodes
*/
List<OpenstackNode> getNodes(OpenstackNodeType openstackNodeType);
/**
* Returns the NodeState for a given node.
*
* @param node openstack node
* @return true if the NodeState for a given node is COMPLETE, false otherwise
*/
boolean isComplete(OpenstackNode node);
}
/*
* 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 bootstrapping Compute/Gateway Node in OpenStack.
*/
package org.onosproject.openstacknode;
\ No newline at end of file
......@@ -68,6 +68,7 @@
<module>openstackrouting</module>
<module>cordmcast</module>
<module>vpls</module>
<module>openstacknode</module>
</modules>
<properties>
......