sanghoshin
Committed by Gerrit Code Review

SONA: Openstackswitching

 - Refactored the app to expose APIs to CordVtn App
 - Added clone method in OpenstackPort and OpenstackNetwork
 - Added NetworkConfig to select the working mode of the app
 - Added a few more APIs for getting network topology information
 - Integrated with the modified DhcpService app
Change-Id: I9e266aff10a00d80074d031276864fff195d2b3f
Showing 23 changed files with 377 additions and 110 deletions
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-openstackswitching</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-openstackswitching-api</artifactId>
<packaging>bundle</packaging>
<description>SONA Openstack Switching application API</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
</dependencies>
</project>
......@@ -77,6 +77,11 @@ public final class OpenstackNetwork {
return this.networkType;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public static final class Builder {
private String name;
private String tenantId;
......
......@@ -19,6 +19,7 @@ import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -179,6 +180,16 @@ public final class OpenstackPort {
//
//}
@Override
public Object clone() {
OpenstackPort op = new OpenstackPort(this.status, this.name, this.adminStateUp,
this.networkId, this.tenantId, this.deviceOwner, this.macAddress,
(HashMap) this.fixedIps.clone(), this.id,
Collections.unmodifiableList(this.securityGroups), this.deviceId);
return op;
}
/**
* OpenstackPort Builder class.
*/
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.openstackswitching;
import org.onlab.packet.Ip4Address;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
......@@ -26,13 +30,13 @@ public final class OpenstackSubnet {
private boolean enableHhcp;
private String networkId;
private String tenantId;
private String dnsNameservers;
private List<Ip4Address> dnsNameservers;
private String gatewayIp;
private String cidr;
private String id;
private OpenstackSubnet(String name, boolean enableHhcp, String networkId,
String tenantId, String dnsNameservers, String gatewayIp,
String tenantId, List<Ip4Address> dnsNameservers, String gatewayIp,
String cidr, String id) {
this.name = name;
this.enableHhcp = enableHhcp;
......@@ -69,7 +73,7 @@ public final class OpenstackSubnet {
return tenantId;
}
public String dnsNameservers() {
public List<Ip4Address> dnsNameservers() {
return dnsNameservers;
}
......@@ -85,8 +89,6 @@ public final class OpenstackSubnet {
return id;
}
// TODO : Implement the following functions when necessary
/**
* OpenstackSubnet Builder class.
*
......@@ -96,7 +98,7 @@ public final class OpenstackSubnet {
private boolean enableDhcp;
private String networkId;
private String tenantId;
private String dnsNameservers;
private List<Ip4Address> dnsNameservers;
private String gatewayIp;
private String cidr;
private String id;
......@@ -127,7 +129,7 @@ public final class OpenstackSubnet {
return this;
}
public Builder setDnsNameservers(String dnsNameservers) {
public Builder setDnsNameservers(List<Ip4Address> dnsNameservers) {
this.dnsNameservers = dnsNameservers;
return this;
......
......@@ -15,8 +15,10 @@
*/
package org.onosproject.openstackswitching;
import java.util.Collection;
/**
* It handles port management REST API from Openstack for VMs.
* Handles port management REST API from Openstack for VMs.
*/
public interface OpenstackSwitchingService {
......@@ -40,16 +42,41 @@ public interface OpenstackSwitchingService {
void updatePorts();
/**
* Store the network information created by openstack.
* Stores the network information created by openstack.
*
* @param openstackNetwork network information
*/
void createNetwork(OpenstackNetwork openstackNetwork);
/**
* Store the subnet information created by openstack.
* Stores the subnet information created by openstack.
*
* @param openstackSubnet subnet information
*/
void createSubnet(OpenstackSubnet openstackSubnet);
/**
* Returns port information list for the network ID given.
*
* @param networkId Network ID of the ports
* @return port information list
*/
Collection<OpenstackPort> ports(String networkId);
/**
* Returns port information for the port ID given.
*
* @param portId Port ID
* @return port information
*/
OpenstackPort port(String portId);
/**
* Returns network information list for the network ID given.
*
* @param networkId Network ID
* @return network information list
*/
OpenstackNetwork network(String networkId);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 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.
-->
<app name="org.onosproject.openstackswitching" origin="ON.Lab" version="${project.version}"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-dhcp-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-dhcp/${project.version}</artifact>
</app>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright 2015 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.
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
<repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
<feature name="onos-app-openstackswitching" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<bundle>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-dhcp-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-dhcp/${project.version}</bundle>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-openstackswitching</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-openstackswitching</artifactId>
<packaging>bundle</packaging>
<description>SONA Openstack Switching applications</description>
<properties>
<onos.version>1.4.0-SNAPSHOT</onos.version>
<onos.app.name>org.onosproject.openstackswitching</onos.app.name>
<web.context>/onos/openstackswitching</web.context>
<api.version>1.0.0</api.version>
<api.title>ONOS OpenStack Switching REST API</api.title>
<api.description>
APIs for receiving Neutron information.
</api.description>
<api.package>org.onosproject.openstackswitching.web</api.package>
<onos.app.origin>SKT, Inc.</onos.app.origin>
</properties>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-openstackswitching-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
</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>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-dhcp-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<_wab>src/main/webapp/</_wab>
<Bundle-SymbolicName>
${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Import-Package>
org.slf4j,
org.osgi.framework,
javax.ws.rs,
javax.ws.rs.core,
com.sun.jersey.api.core,
com.sun.jersey.spi.container.servlet,
com.sun.jersey.server.impl.container.servlet,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.node,
com.fasterxml.jackson.core,
org.apache.karaf.shell.commands,
com.google.common.*,
org.onlab.packet.*,
org.onosproject.*
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -31,7 +31,7 @@ import java.nio.ByteBuffer;
import java.util.Map;
/**
* It handles ARP packet from VMs.
* Handles ARP packet from VMs.
*/
public class OpenstackArpHandler {
......
/*
* Copyright 2014 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.openstackswitching;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.basics.BasicElementConfig;
/**
* Handles configuration for OpenstackSwitching app.
*/
public class OpenstackSwitchingConfig extends Config<ApplicationId> {
public static final String DONOTPUSH = "do_not_push_flows";
/**
* Returns the flag whether the app pushes flows or not.
*
* @return the flag or false if not set
*/
public boolean doNotPushFlows() {
String flag = get(DONOTPUSH, "false");
return Boolean.valueOf(flag);
}
/**
* Sets the flag whether the app pushes flows or not.
*
* @param flag the flag whether the app pushes flows or not
* @return self
*/
public BasicElementConfig doNotPushFlows(boolean flag) {
return (BasicElementConfig) setOrClear(DONOTPUSH, flag);
}
}
......@@ -37,8 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* It populates switching flow rules.
*
* Populates switching flow rules.
*/
public class OpenstackSwitchingRulePopulator {
......
/*
* Copyright 2015 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.
*/
/**
* OpenStack switch interface.
*/
package org.onosproject.openstackswitching;
......@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap;
/**
* It encodes and decodes the OpenstackPort.
* Encodes and decodes the OpenstackPort.
*/
public class OpenstackPortCodec extends JsonCodec<OpenstackPort> {
......
......@@ -53,7 +53,7 @@ public class OpenstackPortWebResource extends AbstractWebResource {
OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
switchingService.createPorts(openstackPort);
log.info("REST API ports is called with {}", portNode.toString());
log.debug("REST API ports is called with {}", portNode.toString());
return Response.status(Response.Status.OK).build();
} catch (Exception e) {
log.error("Creates VirtualPort failed because of exception {}",
......
......@@ -18,17 +18,21 @@ package org.onosproject.openstackswitching.web;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.openstackswitching.OpenstackSubnet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* It encodes and decodes the OpenstackSubnet.
* Encodes and decodes the OpenstackSubnet.
*/
public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
private static Logger log = LoggerFactory
.getLogger(OpenstackSubnetCodec.class);
......@@ -52,7 +56,11 @@ public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean();
String networkId = subnetInfo.path(NETWORK_ID).asText();
String tenantId = subnetInfo.path(TENANT_ID).asText();
String dnsNameservsers = subnetInfo.path(DNS_NAMESERVERS).asText();
ArrayNode dnsNameservsers = (ArrayNode) subnetInfo.path(DNS_NAMESERVERS);
List<Ip4Address> dnsList = Lists.newArrayList();
if (dnsNameservsers != null && !dnsNameservsers.isMissingNode()) {
dnsNameservsers.forEach(dns -> dnsList.add(Ip4Address.valueOf(dns.asText())));
}
String gatewayIp = subnetInfo.path(GATEWAY_IP).asText();
String cidr = subnetInfo.path(CIDR).asText();
String id = subnetInfo.path(ID).asText();
......@@ -62,7 +70,7 @@ public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
.setEnableDhcp(enableDhcp)
.setNetworkId(networkId)
.setTenantId(tenantId)
.setDnsNameservers(dnsNameservsers)
.setDnsNameservers(dnsList)
.setGatewayIp(gatewayIp)
.setCidr(cidr)
.setId(id)
......
......@@ -51,7 +51,7 @@ public class OpenstackSubnetWebResource extends AbstractWebResource {
OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
switchingService.createSubnet(openstackSubnet);
log.info("REST API subnets is called with {}", subnetNode.toString());
log.debug("REST API subnets is called with {}", subnetNode.toString());
return Response.status(Response.Status.OK).build();
} catch (Exception e) {
log.error("Creates VirtualSubnet failed because of exception {}",
......
......@@ -26,101 +26,18 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-openstackswitching</artifactId>
<packaging>bundle</packaging>
<artifactId>onos-openstackswitching</artifactId>
<packaging>pom</packaging>
<description>SONA Openstack Switching applications</description>
<properties>
<onos.version>1.4.0-SNAPSHOT</onos.version>
<onos.app.name>org.onosproject.openstackswitching</onos.app.name>
<web.context>/onos/openstackswitching</web.context>
<api.version>1.0.0</api.version>
<api.title>ONOS OpenStack Switching REST API</api.title>
<api.description>
APIs for receiving Neutron information.
</api.description>
<api.package>org.onosproject.openstackswitching.web</api.package>
<onos.app.origin>SKT, Inc.</onos.app.origin>
</properties>
<description>SONA Openstack Switching application</description>
<modules>
<module>api</module>
<module>app</module>
</modules>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
</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>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-dhcp-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<_wab>src/main/webapp/</_wab>
<Bundle-SymbolicName>
${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Import-Package>
org.slf4j,
org.osgi.framework,
javax.ws.rs,
javax.ws.rs.core,
com.sun.jersey.api.core,
com.sun.jersey.spi.container.servlet,
com.sun.jersey.server.impl.container.servlet,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.node,
com.fasterxml.jackson.core,
org.apache.karaf.shell.commands,
com.google.common.*,
org.onlab.packet.*,
org.onosproject.*
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
......