diff options
Diffstat (limited to 'framework/src/onos/apps/openstackswitching')
25 files changed, 0 insertions, 2759 deletions
diff --git a/framework/src/onos/apps/openstackswitching/api/pom.xml b/framework/src/onos/apps/openstackswitching/api/pom.xml deleted file mode 100644 index 7bb09465..00000000 --- a/framework/src/onos/apps/openstackswitching/api/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?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-rc1</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> diff --git a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java b/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java deleted file mode 100644 index 1b28d0c4..00000000 --- a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -import static com.google.common.base.Preconditions.checkNotNull; - - -/** - * Represents the network information given by Neutron. - */ -public final class OpenstackNetwork { - - private String name; - private String tenantId; - private String segmentId; - private String id; - private NetworkType networkType; - - public enum NetworkType { - /** - * Currently only VXLAN moded is supported. - */ - VXLAN, - VLAN, - STT, - LOCAL - } - - /** - * Returns the builder object of the OpenstackNetwork class. - * - * @return OpenstackNetwork builder object - */ - public static OpenstackNetwork.Builder builder() { - return new Builder(); - } - - private OpenstackNetwork(String name, String tenantId, String id, String sid, - NetworkType type) { - this.name = checkNotNull(name); - this.tenantId = checkNotNull(tenantId); - this.segmentId = checkNotNull(sid); - this.id = checkNotNull(id); - this.networkType = type; - } - - public String name() { - return this.name; - } - - public String tenantId() { - return this.tenantId; - } - - public String id() { - return this.id; - } - - public String segmentId() { - return this.segmentId; - } - - public NetworkType networkType() { - return this.networkType; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public static final class Builder { - private String name; - private String tenantId; - private String id; - private String sid; - private NetworkType networkType; - - public Builder name(String name) { - this.name = name; - - return this; - } - - public Builder tenantId(String tenantId) { - this.tenantId = tenantId; - - return this; - } - - public Builder id(String id) { - this.id = id; - - return this; - } - - public Builder segmentId(String sid) { - this.sid = sid; - - return this; - } - - public Builder networkType(NetworkType type) { - this.networkType = type; - - return this; - } - - public OpenstackNetwork build() { - return new OpenstackNetwork(name, tenantId, id, sid, networkType); - } - - } -} diff --git a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackPort.java b/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackPort.java deleted file mode 100644 index 1613b597..00000000 --- a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackPort.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -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; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * It represents the Openstack Port information. - */ -public final class OpenstackPort { - - public enum PortStatus { - UP, - DOWN, - ACTIVE - } - - private PortStatus status; - private String name; - // FIX_ME - private String allowedAddressPairs; - private boolean adminStateUp; - private String networkId; - private String tenantId; - private String deviceOwner; - private MacAddress macAddress; - // <subnet id, ip address> - private HashMap<String, Ip4Address> fixedIps; - private String id; - private List<String> securityGroups; - private String deviceId; - - private OpenstackPort(PortStatus status, String name, boolean adminStateUp, - String networkId, String tenantId, String deviceOwner, - MacAddress macAddress, HashMap fixedIps, String id, - List<String> securityGroups, String deviceId) { - - this.status = status; - this.name = name; - this.adminStateUp = adminStateUp; - this.networkId = checkNotNull(networkId); - this.tenantId = checkNotNull(tenantId); - this.deviceOwner = deviceOwner; - this.macAddress = checkNotNull(macAddress); - this.fixedIps = checkNotNull(fixedIps); - this.id = checkNotNull(id); - this.securityGroups = securityGroups; - this.deviceId = deviceId; - } - - - - /** - * Returns OpenstackPort builder object. - * - * @return OpenstackPort builder - */ - public static OpenstackPort.Builder builder() { - return new Builder(); - } - - /** - * Returns port status. - * - * @return port status - */ - public PortStatus status() { - return status; - } - - /** - * Returns port name. - * - * @return port name - */ - public String name() { - return name; - } - - /** - * Returns whether admin state up or not. - * - * @return true if admin state up, false otherwise - */ - public boolean isAdminStateUp() { - return adminStateUp; - } - - /** - * Returns network ID. - * - * @return network ID - */ - public String networkId() { - return networkId; - } - - /** - * Returns device owner. - * - * @return device owner - */ - public String deviceOwner() { - return deviceOwner; - } - - /** - * Returns mac address. - * - * @return mac address - */ - public MacAddress macAddress() { - return macAddress; - } - - /** - * Returns the fixed IP information. - * - * @return fixed IP info - */ - public HashMap fixedIps() { - return fixedIps; - } - - /** - * Returns port ID. - * - * @return port ID - */ - public String id() { - return id; - } - - /** - * Returns security group information. - * - * @return security group info - */ - public List<String> securityGroups() { - return securityGroups; - } - - /** - * Returns device ID. - * - * @return device ID - */ - public String deviceId() { - return deviceId; - } - - // TODO : Implement the following functions when necessary - //@Override - //public void equals(Object that) { - // - //} - // - //@Override - //public int hashCode() { - // - //} - - @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. - */ - public static final class Builder { - - private PortStatus status; - private String name; - // FIX_ME - private String allowedAddressPairs; - private boolean adminStateUp; - private String networkId; - private String tenantId; - private String deviceOwner; - private MacAddress macAddress; - // list of hash map <subnet id, ip address> - private HashMap<String, Ip4Address> fixedIps; - private String id; - private List<String> securityGroups; - private String deviceId; - - Builder() { - fixedIps = new HashMap<>(); - securityGroups = Lists.newArrayList(); - } - - /** - * Sets port status. - * - * @param status port status - * @return Builder object - */ - public Builder portStatus(PortStatus status) { - this.status = status; - - return this; - } - - /** - * Sets port name. - * - * @param name port name - * @return Builder object - */ - public Builder name(String name) { - this.name = name; - - return this; - } - - /** - * Sets whether admin state up or not. - * - * @param isAdminStateUp true if admin state is up, false otherwise - * @return Builder object - */ - public Builder adminState(boolean isAdminStateUp) { - this.adminStateUp = isAdminStateUp; - - return this; - } - - /** - * Sets network ID. - * - * @param networkId network ID - * @return Builder object - */ - public Builder netwrokId(String networkId) { - this.networkId = networkId; - - return this; - } - - /** - * Sets tenant ID. - * - * @param tenantId tenant ID - * @return Builder object - */ - public Builder tenantId(String tenantId) { - this.tenantId = tenantId; - - return this; - } - - /** - * Sets device owner. - * - * @param owner device owner - * @return Builder object - */ - public Builder deviceOwner(String owner) { - this.deviceOwner = owner; - - return this; - } - - /** - * Sets MAC address of the port. - * - * @param mac MAC address - * @return Builder object - */ - public Builder macAddress(MacAddress mac) { - this.macAddress = mac; - - return this; - } - - /** - * Sets Fixed IP address information. - * - * @param fixedIpList Fixed IP info - * @return Builder object - */ - public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) { - fixedIps.putAll(fixedIpList); - - return this; - } - - /** - * Sets ID of the port. - * - * @param id ID of the port - * @return Builder object - */ - public Builder id(String id) { - this.id = id; - - return this; - } - - /** - * Sets security group of the port. - * - * @param securityGroup security group of the port - * @return Builder object - */ - public Builder securityGroup(String securityGroup) { - securityGroups.add(securityGroup); - - return this; - } - - /** - * Sets device ID of the port. - * - * @param deviceId device ID - * @return Builder object - */ - public Builder deviceId(String deviceId) { - this.deviceId = deviceId; - - return this; - } - - /** - * Builds an OpenstackPort object. - * - * @return OpenstackPort objecet - */ - public OpenstackPort build() { - return new OpenstackPort(status, name, adminStateUp, networkId, networkId, - deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId); - } - } -} - diff --git a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java b/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java deleted file mode 100644 index bc536e88..00000000 --- a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -import org.onlab.packet.Ip4Address; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Represents the subnet information given by Neutron. - * - */ -public final class OpenstackSubnet { - private String name; - private boolean enableHhcp; - private String networkId; - private String tenantId; - private List<Ip4Address> dnsNameservers; - private String gatewayIp; - private String cidr; - private String id; - - private OpenstackSubnet(String name, boolean enableHhcp, String networkId, - String tenantId, List<Ip4Address> dnsNameservers, String gatewayIp, - String cidr, String id) { - this.name = name; - this.enableHhcp = enableHhcp; - this.networkId = checkNotNull(networkId); - this.tenantId = checkNotNull(tenantId); - this.dnsNameservers = dnsNameservers; - this.gatewayIp = gatewayIp; - this.cidr = checkNotNull(cidr); - this.id = checkNotNull(id); - } - - /** - * Returns OpenstackSubnet builder object. - * - * @return OpenstackSubnet builder - */ - public static OpenstackSubnet.Builder builder() { - return new Builder(); - } - - public String name() { - return name; - } - - public boolean enableHhcp() { - return enableHhcp; - } - - public String networkId() { - return networkId; - } - - public String tenantId() { - return tenantId; - } - - public List<Ip4Address> dnsNameservers() { - return dnsNameservers; - } - - public String gatewayIp() { - return gatewayIp; - } - - public String cidr() { - return cidr; - } - - public String id() { - return id; - } - - /** - * OpenstackSubnet Builder class. - * - */ - public static final class Builder { - private String name; - private boolean enableDhcp; - private String networkId; - private String tenantId; - private List<Ip4Address> dnsNameservers; - private String gatewayIp; - private String cidr; - private String id; - - Builder() {} - - public Builder setName(String name) { - this.name = name; - - return this; - } - - public Builder setEnableDhcp(boolean enableDhcp) { - this.enableDhcp = enableDhcp; - - return this; - } - - public Builder setNetworkId(String networkId) { - this.networkId = networkId; - - return this; - } - - public Builder setTenantId(String tenantId) { - this.tenantId = tenantId; - - return this; - } - - public Builder setDnsNameservers(List<Ip4Address> dnsNameservers) { - this.dnsNameservers = dnsNameservers; - - return this; - } - - public Builder setGatewayIp(String gatewayIp) { - this.gatewayIp = gatewayIp; - - return this; - } - - public Builder setCidr(String cidr) { - this.cidr = cidr; - - return this; - } - - public Builder setId(String id) { - this.id = id; - - return this; - } - - public OpenstackSubnet build() { - return new OpenstackSubnet(name, enableDhcp, networkId, tenantId, - dnsNameservers, gatewayIp, cidr, id); - } - } -} diff --git a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java b/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java deleted file mode 100644 index 59b8db0c..00000000 --- a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -import org.onosproject.net.Port; - -import java.util.Collection; - -/** - * Handles port management REST API from Openstack for VMs. - */ -public interface OpenstackSwitchingService { - - /** - * Store the port information created by Openstack. - * - * @param openstackPort port information - */ - void createPorts(OpenstackPort openstackPort); - - /** - * Removes flow rules corresponding to the port removed by Openstack. - * - */ - void deletePorts(); - - /** - * Updates flow rules corresponding to the port information updated by Openstack. - * - */ - void updatePorts(); - - /** - * Stores the network information created by openstack. - * - * @param openstackNetwork network information - */ - void createNetwork(OpenstackNetwork openstackNetwork); - - /** - * 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 given. - * - * @param port port reference - * @return port information - */ - OpenstackPort port(Port port); - - /** - * 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); - -} diff --git a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/package-info.java b/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/package-info.java deleted file mode 100644 index cd50f912..00000000 --- a/framework/src/onos/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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; diff --git a/framework/src/onos/apps/openstackswitching/app/app.xml b/framework/src/onos/apps/openstackswitching/app/app.xml deleted file mode 100644 index e982b90d..00000000 --- a/framework/src/onos/apps/openstackswitching/app/app.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?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> diff --git a/framework/src/onos/apps/openstackswitching/app/features.xml b/framework/src/onos/apps/openstackswitching/app/features.xml deleted file mode 100644 index a13c2aaf..00000000 --- a/framework/src/onos/apps/openstackswitching/app/features.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?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}"> - <feature name="${project.artifactId}" 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> - <bundle>mvn:com.sun.jersey/jersey-client/1.19</bundle> - <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle> - </feature> -</features> diff --git a/framework/src/onos/apps/openstackswitching/app/pom.xml b/framework/src/onos/apps/openstackswitching/app/pom.xml deleted file mode 100644 index edd43e02..00000000 --- a/framework/src/onos/apps/openstackswitching/app/pom.xml +++ /dev/null @@ -1,136 +0,0 @@ -<?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-rc1</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-app-openstackswitching</artifactId> - <packaging>bundle</packaging> - - <description>SONA Openstack Switching applications</description> - <properties> - <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> - <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <version>1.19</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.api.client, - 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> diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java deleted file mode 100644 index 944d12a1..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java +++ /dev/null @@ -1,108 +0,0 @@ -/* -* 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. -*/ -package org.onosproject.openstackswitching; - -import org.onlab.packet.ARP; -import org.onlab.packet.Ethernet; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.MacAddress; -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.OutboundPacket; -import org.onosproject.net.packet.PacketService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Handles ARP packet from VMs. - */ -public class OpenstackArpHandler { - - private static Logger log = LoggerFactory - .getLogger(OpenstackArpHandler.class); - private PacketService packetService; - private OpenstackRestHandler restHandler; - - /** - * Returns OpenstackArpHandler reference. - * - * @param restHandler rest API handler reference - * @param packetService PacketService reference - */ - public OpenstackArpHandler(OpenstackRestHandler restHandler, PacketService packetService) { - this.restHandler = checkNotNull(restHandler); - this.packetService = packetService; - } - - /** - * Processes ARP packets. - * - * @param pkt ARP request packet - */ - public void processPacketIn(InboundPacket pkt) { - Ethernet ethernet = pkt.parsed(); - ARP arp = (ARP) ethernet.getPayload(); - - if (arp.getOpCode() == ARP.OP_REQUEST) { - byte[] srcMacAddress = arp.getSenderHardwareAddress(); - byte[] srcIPAddress = arp.getSenderProtocolAddress(); - byte[] dstIPAddress = arp.getTargetProtocolAddress(); - - //Searches the Dst MAC Address based on openstackPortMap - MacAddress macAddress = null; - - OpenstackPort openstackPort = restHandler.getPorts().stream(). - filter(e -> e.fixedIps().containsValue(Ip4Address.valueOf( - dstIPAddress))).findAny().orElse(null); - - if (openstackPort != null) { - macAddress = openstackPort.macAddress(); - log.debug("Found MACAddress: {}", macAddress.toString()); - } else { - return; - } - - //Creates a response packet - ARP arpReply = new ARP(); - arpReply.setOpCode(ARP.OP_REPLY) - .setHardwareAddressLength(arp.getHardwareAddressLength()) - .setHardwareType(arp.getHardwareType()) - .setProtocolAddressLength(arp.getProtocolAddressLength()) - .setProtocolType(arp.getProtocolType()) - .setSenderHardwareAddress(macAddress.toBytes()) - .setSenderProtocolAddress(dstIPAddress) - .setTargetHardwareAddress(srcMacAddress) - .setTargetProtocolAddress(srcIPAddress); - - //Sends a response packet - ethernet.setDestinationMACAddress(srcMacAddress) - .setSourceMACAddress(macAddress) - .setEtherType(Ethernet.TYPE_ARP) - .setPayload(arpReply); - - TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); - builder.setOutput(pkt.receivedFrom().port()); - OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), - builder.build(), ByteBuffer.wrap(ethernet.serialize())); - packetService.emit(packet); - } - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java deleted file mode 100644 index 9065bc52..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.Lists; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import org.onosproject.openstackswitching.web.OpenstackNetworkCodec; -import org.onosproject.openstackswitching.web.OpenstackPortCodec; -import org.onosproject.openstackswitching.web.OpenstackSubnetCodec; -import org.slf4j.Logger; -import javax.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.Collection; -import java.util.List; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.net.MediaType.JSON_UTF_8; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Handles REST Calls to Openstack Neutron. - * - */ -public class OpenstackRestHandler { - - private final Logger log = getLogger(getClass()); - private String neutronUrl; - private String keystoneUrl; - private String tokenId; - private String userName; - private String pass; - - /** - * Creates OpenstackRestHandler instance. - * - * @param cfg OpenstackSwitchingConfig reference - */ - public OpenstackRestHandler(OpenstackSwitchingConfig cfg) { - this.neutronUrl = checkNotNull(cfg.neutronServer()); - this.keystoneUrl = checkNotNull(cfg.keystoneServer()); - this.userName = checkNotNull(cfg.userName()); - this.pass = checkNotNull(cfg.password()); - } - - /** - * Returns network information stored in Neutron. - * - * @return List of OpenstackNetwork - */ - public Collection<OpenstackNetwork> getNetworks() { - - WebResource.Builder builder = getClientBuilder(neutronUrl + "networks"); - String response = builder.accept(MediaType.APPLICATION_JSON_TYPE). - header("X-Auth-Token", getToken()).get(String.class); - - ObjectMapper mapper = new ObjectMapper(); - List<OpenstackNetwork> openstackNetworks = Lists.newArrayList(); - try { - ObjectNode node = (ObjectNode) mapper.readTree(response); - ArrayNode networkList = (ArrayNode) node.path("networks"); - OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec(); - networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null))); - } catch (IOException e) { - e.printStackTrace(); - } - - log.debug("networks response:" + response); - openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id())); - - return openstackNetworks; - } - - /** - * Returns port information stored in Neutron. - * - * @return List of OpenstackPort - */ - public Collection<OpenstackPort> getPorts() { - - WebResource.Builder builder = getClientBuilder(neutronUrl + "ports"); - String response = builder.accept(MediaType.APPLICATION_JSON_TYPE). - header("X-Auth-Token", getToken()).get(String.class); - - ObjectMapper mapper = new ObjectMapper(); - List<OpenstackPort> openstackPorts = Lists.newArrayList(); - try { - ObjectNode node = (ObjectNode) mapper.readTree(response); - ArrayNode portList = (ArrayNode) node.path("ports"); - OpenstackPortCodec portCodec = new OpenstackPortCodec(); - portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null))); - } catch (IOException e) { - e.printStackTrace(); - } - - log.debug("port response:" + response); - openstackPorts.forEach(n -> log.debug("port ID: {}", n.id())); - - return openstackPorts; - } - - /** - * Returns Subnet information in Neutron. - * - * @return List of OpenstackSubnet - */ - public Collection<OpenstackSubnet> getSubnets() { - - WebResource.Builder builder = getClientBuilder(neutronUrl + "subnets"); - String response = builder.accept(MediaType.APPLICATION_JSON_TYPE). - header("X-Auth-Token", getToken()).get(String.class); - - ObjectMapper mapper = new ObjectMapper(); - List<OpenstackSubnet> subnets = Lists.newArrayList(); - try { - ObjectNode node = (ObjectNode) mapper.readTree(response); - ArrayNode subnetList = (ArrayNode) node.path("subnets"); - OpenstackSubnetCodec subnetCodec = new OpenstackSubnetCodec(); - subnetList.forEach(s -> subnets.add(subnetCodec.decode((ObjectNode) s, null))); - } catch (IOException e) { - e.printStackTrace(); - } - - log.debug("subnets response:" + response); - subnets.forEach(s -> log.debug("subnet ID: {}", s.id())); - - return subnets; - } - - private WebResource.Builder getClientBuilder(String uri) { - Client client = Client.create(); - WebResource resource = client.resource(uri); - return resource.accept(JSON_UTF_8.toString()) - .type(JSON_UTF_8.toString()); - } - - private String getToken() { - if (isTokenInvalid()) { - String request = "{\"auth\": {\"tenantName\": \"admin\", " + - "\"passwordCredentials\": {\"username\": \"" + - userName + "\",\"password\": \"" + pass + "\"}}}"; - WebResource.Builder builder = getClientBuilder(keystoneUrl + "tokens"); - String response = builder.accept(MediaType.APPLICATION_JSON).post(String.class, request); - - ObjectMapper mapper = new ObjectMapper(); - try { - ObjectNode node = (ObjectNode) mapper.readTree(response); - tokenId = node.path("access").path("token").path("id").asText(); - } catch (IOException e) { - e.printStackTrace(); - } - log.debug("token response:" + response); - } - - return tokenId; - } - - private boolean isTokenInvalid() { - //TODO: validation check for the existing token - return true; - } - -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingConfig.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingConfig.java deleted file mode 100644 index ba39ff66..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingConfig.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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"; - public static final String NEUTRON_SERVER = "neutron_server"; - public static final String KEYSTONE_SERVER = "keystone_server"; - public static final String USER_NAME = "user_name"; - public static final String PASSWORD = "password"; - - /** - * 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); - } - - /** - * Returns the Neutron server IP address. - * - * @return Neutron server IP - */ - public String neutronServer() { - return get(NEUTRON_SERVER, ""); - } - - /** - * Returns the Keystone server IP address. - * - * @return Keystone server IP - */ - public String keystoneServer() { - return get(KEYSTONE_SERVER, ""); - } - - /** - * Returns the username for openstack. - * - * @return username for openstack - */ - public String userName() { - return get(USER_NAME, ""); - } - - /** - * Returns the password for openstack. - * - * @return password for openstack - */ - public String password() { - return get(PASSWORD, ""); - } - - /** - * 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); - } - - /** - * Sets the neutron server IP address. - * - * @param url neutron server IP address - * @return itself - */ - public BasicElementConfig neutronServer(String url) { - return (BasicElementConfig) setOrClear(NEUTRON_SERVER, url); - } - - /** - * Sets the keystone server IP address. - * - * @param url keystone server IP address - * @return itself - */ - public BasicElementConfig keystoneServer(String url) { - return (BasicElementConfig) setOrClear(KEYSTONE_SERVER, url); - } - - /** - * Sets the username for openstack. - * - * @param username user name for openstack - * @return itself - */ - public BasicElementConfig userName(String username) { - return (BasicElementConfig) setOrClear(USER_NAME, username); - } - - /** - * Sets the password for openstack. - * - * @param password password for openstack - * @return itself - */ - public BasicElementConfig password(String password) { - return (BasicElementConfig) setOrClear(PASSWORD, password); - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java deleted file mode 100644 index d881d81c..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching; - -import com.google.common.collect.ImmutableSet; -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.apache.felix.scr.annotations.Service; -import org.onlab.packet.Ethernet; -import org.onlab.packet.Ip4Address; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.dhcp.DhcpService; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Port; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flowobjective.FlowObjectiveService; -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.List; -import java.util.Collection; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.stream.Collectors; - -import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; - -@SuppressWarnings("ALL") -@Service -@Component(immediate = true) -/** - * Populates forwarding rules for VMs created by Openstack. - */ -public class OpenstackSwitchingManager implements OpenstackSwitchingService { - - private static Logger log = LoggerFactory - .getLogger(OpenstackSwitchingManager.class); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected PacketService packetService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DhcpService dhcpService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry cfgService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DriverService driverService; - - private ApplicationId appId; - private boolean doNotPushFlows; - private Ip4Address neutronServer; - private Ip4Address keystoneServer; - private String userName; - private String password; - private OpenstackArpHandler arpHandler; - private OpenstackRestHandler restHandler; - - private ExecutorService deviceEventExcutorService = Executors.newFixedThreadPool(10); - - private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor(); - private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); - private InternalConfigListener internalConfigListener = new InternalConfigListener(); - private final Set<ConfigFactory> factories = ImmutableSet.of( - new ConfigFactory<ApplicationId, OpenstackSwitchingConfig>(APP_SUBJECT_FACTORY, - OpenstackSwitchingConfig.class, - "openstackswitching") { - @Override - public OpenstackSwitchingConfig createConfig() { - return new OpenstackSwitchingConfig(); - } - } - ); - - @Activate - protected void activate() { - appId = coreService - .registerApplication("org.onosproject.openstackswitching"); - - factories.forEach(cfgService::registerConfigFactory); - packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); - deviceService.addListener(internalDeviceListener); - cfgService.addListener(internalConfigListener); - - internalConfigListener.configureNetwork(); - - log.info("Started"); - } - - @Deactivate - protected void deactivate() { - packetService.removeProcessor(internalPacketProcessor); - deviceService.removeListener(internalDeviceListener); - cfgService.removeListener(internalConfigListener); - - deviceEventExcutorService.shutdown(); - - log.info("Stopped"); - } - - @Override - public void createPorts(OpenstackPort openstackPort) { - registerDhcpInfo(openstackPort); - } - - @Override - public void deletePorts() { - - } - - @Override - public void updatePorts() { - - } - - @Override - public void createNetwork(OpenstackNetwork openstackNetwork) { - } - - @Override - public void createSubnet(OpenstackSubnet openstackSubnet) { - } - - @Override - public Collection<OpenstackPort> ports(String networkId) { - Collection<OpenstackPort> ports = restHandler.getPorts(); - List<OpenstackPort> portList = ports.stream() - .filter(p -> p.networkId().equals(networkId)) - .collect(Collectors.toList()); - - return portList; - } - - @Override - public OpenstackPort port(Port port) { - Collection<OpenstackPort> ports = restHandler.getPorts(); - String uuid = port.annotations().value("portName").substring(3); - return ports.stream() - .filter(p -> p.id().startsWith(uuid)) - .findFirst().orElse(null); - } - - @Override - public OpenstackPort port(String portId) { - Collection<OpenstackPort> ports = restHandler.getPorts(); - return ports.stream() - .filter(p -> p.id().equals(portId)) - .findFirst().orElse(null); - } - - @Override - public OpenstackNetwork network(String networkId) { - Collection<OpenstackNetwork> networks = restHandler.getNetworks(); - return networks.stream() - .filter(n -> n.id().equals(networkId)) - .findFirst().orElse(null); - } - - private void processDeviceAdded(Device device) { - log.debug("device {} is added", device.id()); - } - - private void processPortAdded(Device device, Port port) { - if (!port.annotations().value("portName").equals("vxlan")) { - OpenstackSwitchingRulePopulator rulePopulator = - new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, - deviceService, restHandler, driverService); - rulePopulator.populateSwitchingRules(device, port); - } - } - - private void processPortRemoved(Device device, Port port) { - // TODO: Remove flow rules for the VM removed - log.debug("port {} is removed", port.toString()); - } - - private void registerDhcpInfo(OpenstackPort openstackPort) { - Ip4Address ip4Address; - Ip4Address subnetMask; - Ip4Address dhcpServer; - Ip4Address gatewayIPAddress; - Ip4Address domainServer; - OpenstackSubnet openstackSubnet; - - ip4Address = (Ip4Address) openstackPort.fixedIps().values().toArray()[0]; - - openstackSubnet = restHandler.getSubnets().stream() - .filter(n -> n.networkId().equals(openstackPort.networkId())) - .findFirst().get(); - - subnetMask = Ip4Address.valueOf(buildSubnetMask(openstackSubnet.cidr())); - gatewayIPAddress = Ip4Address.valueOf(openstackSubnet.gatewayIp()); - dhcpServer = gatewayIPAddress; - // TODO: supports multiple DNS servers - if (openstackSubnet.dnsNameservers().isEmpty()) { - domainServer = Ip4Address.valueOf("8.8.8.8"); - } else { - domainServer = openstackSubnet.dnsNameservers().get(0); - } - List<Ip4Address> options = Lists.newArrayList(); - options.add(subnetMask); - options.add(dhcpServer); - options.add(gatewayIPAddress); - options.add(domainServer); - - dhcpService.setStaticMapping(openstackPort.macAddress(), ip4Address, true, options); - } - - private byte[] buildSubnetMask(String cidr) { - int prefix; - String[] parts = cidr.split("/"); - prefix = Integer.parseInt(parts[1]); - int mask = 0xffffffff << (32 - prefix); - byte[] bytes = new byte[]{(byte) (mask >>> 24), - (byte) (mask >> 16 & 0xff), (byte) (mask >> 8 & 0xff), (byte) (mask & 0xff)}; - - return bytes; - } - - - - 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.getEtherType() == Ethernet.TYPE_ARP) { - arpHandler.processPacketIn(pkt); - } - } - } - - private class InternalDeviceListener implements DeviceListener { - - @Override - public void event(DeviceEvent deviceEvent) { - deviceEventExcutorService.execute(new InternalEventHandler(deviceEvent)); - } - } - - private class InternalEventHandler implements Runnable { - - volatile DeviceEvent deviceEvent; - - InternalEventHandler(DeviceEvent deviceEvent) { - this.deviceEvent = deviceEvent; - } - - @Override - public void run() { - - if (doNotPushFlows) { - return; - } - - switch (deviceEvent.type()) { - case DEVICE_ADDED: - processDeviceAdded((Device) deviceEvent.subject()); - break; - case DEVICE_UPDATED: - Port port = (Port) deviceEvent.subject(); - if (port.isEnabled()) { - processPortAdded((Device) deviceEvent.subject(), deviceEvent.port()); - } - break; - case DEVICE_AVAILABILITY_CHANGED: - Device device = (Device) deviceEvent.subject(); - if (deviceService.isAvailable(device.id())) { - processDeviceAdded(device); - } - break; - case PORT_ADDED: - processPortAdded((Device) deviceEvent.subject(), deviceEvent.port()); - break; - case PORT_UPDATED: - processPortAdded((Device) deviceEvent.subject(), deviceEvent.port()); - break; - case PORT_REMOVED: - processPortRemoved((Device) deviceEvent.subject(), deviceEvent.port()); - break; - default: - break; - } - } - } - - private class InternalConfigListener implements NetworkConfigListener { - - public void configureNetwork() { - OpenstackSwitchingConfig cfg = - cfgService.getConfig(appId, OpenstackSwitchingConfig.class); - if (cfg == null) { - log.error("There is no openstack server information in config."); - return; - } - doNotPushFlows = cfg.doNotPushFlows(); - restHandler = new OpenstackRestHandler(cfg); - arpHandler = new OpenstackArpHandler(restHandler, packetService); - } - - @Override - public void event(NetworkConfigEvent event) { - if (((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || - event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) && - event.configClass().equals(OpenstackSwitchingConfig.class)) { - configureNetwork(); - } - } - - } - - private final class PortInfo { - DeviceId deviceId; - String portName; - Ip4Address fixedIp; - Ip4Address hostIp; - - private PortInfo(DeviceId deviceId, String portName, Ip4Address fixedIp, - Ip4Address hostIp) { - this.deviceId = deviceId; - this.portName = portName; - this.fixedIp = fixedIp; - this.hostIp = hostIp; - } - } - -}
\ No newline at end of file diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java deleted file mode 100644 index 38c03638..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java +++ /dev/null @@ -1,307 +0,0 @@ -/* -* 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. -*/ - -package org.onosproject.openstackswitching; - -import org.onlab.packet.Ethernet; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.MacAddress; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.ExtensionTreatmentResolver; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.DefaultDriverHandler; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -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.flow.instructions.ExtensionTreatment; -import org.onosproject.net.flow.instructions.ExtensionPropertyException; -import org.onosproject.net.flow.instructions.ExtensionTreatmentType; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; - -/** - * Populates switching flow rules. - */ -public class OpenstackSwitchingRulePopulator { - - private static Logger log = LoggerFactory - .getLogger(OpenstackSwitchingRulePopulator.class); - private static final int SWITCHING_RULE_PRIORITY = 50000; - - private FlowObjectiveService flowObjectiveService; - private DriverService driverService; - private DeviceService deviceService; - private OpenstackRestHandler restHandler; - private ApplicationId appId; - - private Collection<OpenstackNetwork> openstackNetworkList; - private Collection<OpenstackPort> openstackPortList; - - /** - * Creates OpenstackSwitchingRulPopulator. - * - * @param appId application id - * @param flowObjectiveService FlowObjectiveService reference - * @param deviceService DeviceService reference - * @param driverService DriverService reference - */ - public OpenstackSwitchingRulePopulator(ApplicationId appId, - FlowObjectiveService flowObjectiveService, - DeviceService deviceService, - OpenstackRestHandler restHandler, - DriverService driverService) { - this.flowObjectiveService = flowObjectiveService; - this.deviceService = deviceService; - this.driverService = driverService; - this.restHandler = restHandler; - this.appId = appId; - - openstackNetworkList = restHandler.getNetworks(); - openstackPortList = restHandler.getPorts(); - } - - /** - * Populates flow rules for the VM created. - * - * @param device device to populate rules to - * @param port port for the VM created - */ - public void populateSwitchingRules(Device device, Port port) { - populateFlowRulesForTrafficToSameCnode(device, port); - populateFlowRulesForTrafficToDifferentCnode(device, port); - } - - /** - * Populates the flow rules for traffic to VMs in the same Cnode as the sender. - * - * @param device device to put the rules - * @param port port info of the VM - */ - private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) { - Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); - if (vmIp != null) { - setFlowRuleForVMsInSameCnode(vmIp, device.id(), port); - } - } - - /** - * Populates the flow rules for traffic to VMs in different Cnode using - * Nicira extention. - * - * @param device device to put rules - * @param port port information of the VM - */ - private void populateFlowRulesForTrafficToDifferentCnode(Device device, Port port) { - String portName = port.annotations().value("portName"); - String channelId = device.annotations().value("channelId"); - Ip4Address hostIpAddress = Ip4Address.valueOf(channelId.split(":")[0]); - Ip4Address fixedIp = getFixedIpAddressForPort(portName); - MacAddress vmMac = getVmMacAddressForPort(portName); - String vni = getVniForPort(portName); - deviceService.getAvailableDevices().forEach(d -> { - if (!d.equals(device)) { - deviceService.getPorts(d.id()).forEach(p -> { - String pName = p.annotations().value("portName"); - if (!p.equals(port) && vni.equals(getVniForPort(pName))) { - String cidx = d.annotations().value("channelId"); - Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]); - MacAddress vmMacx = getVmMacAddressForPort(pName); - Ip4Address fixedIpx = getFixedIpAddressForPort(pName); - - setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx, vmMacx); - setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp, vmMac); - } - }); - } - }); - } - - /** - * Returns the VNI of the VM of the port. - * - * @param portName VM port - * @return VNI - */ - private String getVniForPort(String portName) { - String uuid = portName.substring(3); - OpenstackPort port = openstackPortList.stream() - .filter(p -> p.id().startsWith(uuid)) - .findAny().orElse(null); - if (port == null) { - log.warn("No port information for port {}", portName); - return null; - } - - OpenstackNetwork network = openstackNetworkList.stream() - .filter(n -> n.id().equals(port.networkId())) - .findAny().orElse(null); - if (network == null) { - log.warn("No VNI information for network {}", port.networkId()); - return null; - } - - return network.segmentId(); - } - - /** - * Returns the Fixed IP address of the VM. - * - * @param portName VM port info - * @return IP address of the VM - */ - private Ip4Address getFixedIpAddressForPort(String portName) { - - String uuid = portName.substring(3); - OpenstackPort port = openstackPortList.stream() - .filter(p -> p.id().startsWith(uuid)) - .findFirst().orElse(null); - - if (port == null) { - log.error("There is no port information for port name {}", portName); - return null; - } - - if (port.fixedIps().isEmpty()) { - log.error("There is no fixed IP info in the port information"); - return null; - } - - return (Ip4Address) port.fixedIps().values().toArray()[0]; - } - - /** - * Returns the MAC address of the VM of the port. - * - * @param portName VM port - * @return MAC address of the VM - */ - private MacAddress getVmMacAddressForPort(String portName) { - - String uuid = portName.substring(3); - OpenstackPort port = openstackPortList.stream() - .filter(p -> p.id().startsWith(uuid)) - .findFirst().orElse(null); - - if (port == null) { - log.error("There is port information for port name {}", portName); - return null; - } - - return port.macAddress(); - } - - /** - * Sets the flow rules for traffic between VMs in the same Cnode. - * - * @param ip4Address VM IP address - * @param id device ID to put rules - * @param port VM port - */ - private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id, - Port port) { - TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); - TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); - - sBuilder.matchEthType(Ethernet.TYPE_IPV4) - .matchIPDst(ip4Address.toIpPrefix()); - tBuilder.setOutput(port.number()); - - ForwardingObjective fo = DefaultForwardingObjective.builder() - .withSelector(sBuilder.build()) - .withTreatment(tBuilder.build()) - .withPriority(SWITCHING_RULE_PRIORITY) - .withFlag(ForwardingObjective.Flag.VERSATILE) - .fromApp(appId) - .add(); - - flowObjectiveService.forward(id, fo); - } - - /** - * Sets the flow rules between traffic from VMs in different Cnode. - * - * @param vni VNI - * @param id device ID - * @param hostIp host IP of the VM - * @param vmIp fixed IP of the VM - * @param vmMac MAC address of the VM - */ - private void setVxLanFlowRule(String vni, DeviceId id, Ip4Address hostIp, - Ip4Address vmIp, MacAddress vmMac) { - TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); - TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); - - sBuilder.matchEthType(Ethernet.TYPE_IPV4) - .matchIPDst(vmIp.toIpPrefix()); - tBuilder.setTunnelId(Long.parseLong(vni)) - .extension(buildNiciraExtenstion(id, hostIp), id) - .setOutput(getTunnelPort(id)); - - ForwardingObjective fo = DefaultForwardingObjective.builder() - .withSelector(sBuilder.build()) - .withTreatment(tBuilder.build()) - .withPriority(SWITCHING_RULE_PRIORITY) - .withFlag(ForwardingObjective.Flag.VERSATILE) - .fromApp(appId) - .add(); - - flowObjectiveService.forward(id, fo); - } - - private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) { - Driver driver = driverService.getDriver(id); - DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id)); - ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class); - - ExtensionTreatment extensionInstruction = - resolver.getExtensionInstruction( - ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type()); - - try { - extensionInstruction.setPropertyValue("tunnelDst", hostIp); - } catch (ExtensionPropertyException e) { - log.error("Error setting Nicira extension setting {}", e); - } - - return extensionInstruction; - } - - private PortNumber getTunnelPort(DeviceId id) { - Port port = deviceService.getPorts(id).stream() - .filter(p -> p.annotations().value("portName").equals("vxlan")) - .findAny().orElse(null); - - if (port == null) { - log.error("No TunnelPort was created."); - return null; - } - return port.number(); - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/package-info.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/package-info.java deleted file mode 100644 index cd50f912..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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; diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java deleted file mode 100644 index 0a0b5dce..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching.web; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.openstackswitching.OpenstackNetwork; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Implementation of the OpenstackNetwork Codec. - * - */ -public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> { - - protected static final Logger log = LoggerFactory - .getLogger(OpenstackNetworkCodec.class); - - private static final String NETWORK = "network"; - private static final String NAME = "name"; - private static final String TENANT_ID = "tenant_id"; - private static final String SEGMENTATION_ID = "provider:segmentation_id"; - private static final String NETWORK_TYPE = "provider:network_type"; - private static final String ID = "id"; - - @Override - public OpenstackNetwork decode(ObjectNode json, CodecContext context) { - - JsonNode networkInfo = json.get(NETWORK); - if (networkInfo == null) { - networkInfo = json; - } - - String name = networkInfo.path(NAME).asText(); - String tenantId = networkInfo.path(TENANT_ID).asText(); - String id = networkInfo.path(ID).asText(); - - OpenstackNetwork.Builder onb = OpenstackNetwork.builder(); - onb.name(name) - .tenantId(tenantId) - .id(id); - - if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) { - onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkInfo.path(NETWORK_TYPE). - asText().toUpperCase())); - onb.name(networkInfo.path(NETWORK_TYPE).asText()); - onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText()); - } - - return onb.build(); - } - -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkWebResource.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkWebResource.java deleted file mode 100644 index bf04cc4d..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkWebResource.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching.web; - -import org.onosproject.rest.AbstractWebResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.InputStream; - -/** - * Handles REST API call of Neutron ML2 plugin. - */ -@Path("networks") -public class OpenstackNetworkWebResource extends AbstractWebResource { - - protected static final Logger log = LoggerFactory - .getLogger(OpenstackNetworkWebResource.class); - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createNetwork(InputStream input) { - log.debug("REST API networks is called {}", input.toString()); - return Response.status(Response.Status.OK).build(); - } - - @PUT - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response updateNetwork(InputStream input) { - log.debug("REST API networks is called {}", input.toString()); - return Response.status(Response.Status.OK).build(); - } - - @DELETE - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response deleteNetwork(InputStream input) { - log.debug("REST API networks is called {}", input.toString()); - return Response.status(Response.Status.OK).build(); - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortCodec.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortCodec.java deleted file mode 100644 index 63e6d2ea..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortCodec.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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. - */ -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 org.onlab.packet.Ip4Address; -import org.onlab.packet.MacAddress; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.openstackswitching.OpenstackPort; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; - -/** - * Encodes and decodes the OpenstackPort. - */ -public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { - - private static Logger log = LoggerFactory - .getLogger(OpenstackPortCodec.class); - - // JSON field names - private static final String PORT = "port"; - private static final String STATUS = "status"; - private static final String NAME = "name"; - private static final String ADDRESS_PAIR = "allowed_address_pairs"; - private static final String ADMIN_STATUS = "admin_status"; - private static final String NETWORK_ID = "network_id"; - private static final String TENANT_ID = "tenant_id"; - private static final String DEVICE_OWNER = "device_owner"; - private static final String MAC_ADDRESS = "mac_address"; - private static final String FIXED_IPS = "fixed_ips"; - private static final String SUBNET_ID = "subnet_id"; - private static final String IP_ADDRESS = "ip_address"; - private static final String ID = "id"; - private static final String SECURITY_GROUPS = "security_groups"; - private static final String DEVICE_ID = "device_id"; - - @Override - public OpenstackPort decode(ObjectNode json, CodecContext context) { - - HashMap<String, Ip4Address> fixedIpMap = new HashMap<>(); - JsonNode portInfo = json.get(PORT); - if (portInfo == null) { - portInfo = json; - } - - String status = portInfo.path(STATUS).asText(); - String name = portInfo.path(NAME).asText(); - boolean adminStateUp = portInfo.path(ADMIN_STATUS).asBoolean(); - String networkId = portInfo.path(NETWORK_ID).asText(); - String tenantId = portInfo.path(TENANT_ID).asText(); - String deviceOwner = portInfo.path(DEVICE_OWNER).asText(); - String macStr = portInfo.path(MAC_ADDRESS).asText(); - ArrayNode fixedIpList = (ArrayNode) portInfo.path(FIXED_IPS); - for (JsonNode fixedIpInfo: fixedIpList) { - String subnetId = fixedIpInfo.path(SUBNET_ID).asText(); - String ipAddressStr = fixedIpInfo.path(IP_ADDRESS).asText(); - if (ipAddressStr != null) { - Ip4Address ipAddress = Ip4Address.valueOf(ipAddressStr); - fixedIpMap.put(subnetId, ipAddress); - } - } - String id = portInfo.path(ID).asText(); - String securityGroups = portInfo.path(SECURITY_GROUPS).asText(); - String deviceId = portInfo.path(DEVICE_ID).asText(); - - OpenstackPort.Builder openstackPortBuilder = OpenstackPort.builder(); - openstackPortBuilder.portStatus(OpenstackPort.PortStatus.valueOf(status)) - .name(name) - .adminState(adminStateUp) - .netwrokId(networkId) - .tenantId(tenantId) - .deviceOwner(deviceOwner) - .macAddress(MacAddress.valueOf(macStr)) - .fixedIps(fixedIpMap) - .id(id) - .deviceId(deviceId); - - // FIX ME - if (!securityGroups.isEmpty()) { - openstackPortBuilder.securityGroup(securityGroups); - } - - OpenstackPort openstackPort = openstackPortBuilder.build(); - - return openstackPort; - } - -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortWebResource.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortWebResource.java deleted file mode 100644 index faffa732..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackPortWebResource.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching.web; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onosproject.openstackswitching.OpenstackPort; -import org.onosproject.openstackswitching.OpenstackSwitchingService; -import org.onosproject.rest.AbstractWebResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.InputStream; - -/** - * Handles Rest API call from Neutron ML2 plugin. - */ -@Path("ports") -public class OpenstackPortWebResource extends AbstractWebResource { - - protected static final Logger log = LoggerFactory - .getLogger(OpenstackPortWebResource.class); - - private static final OpenstackPortCodec PORT_CODEC = new OpenstackPortCodec(); - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createPorts(InputStream input) { - try { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode portNode = (ObjectNode) mapper.readTree(input); - - OpenstackPort openstackPort = PORT_CODEC.decode(portNode, this); - OpenstackSwitchingService switchingService = - getService(OpenstackSwitchingService.class); - switchingService.createPorts(openstackPort); - - log.debug("REST API ports is called with {}", portNode.toString()); - return Response.status(Response.Status.OK).build(); - - } catch (Exception e) { - log.error("Creates Port failed because of exception {}", - e.toString()); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) - .build(); - } - } - - @DELETE - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response deletesPorts(InputStream input) { - log.debug("REST API ports is called with {}", input.toString()); - return Response.status(Response.Status.OK).build(); - } - - @PUT - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response updatePorts(InputStream input) { - log.info("REST API ports is called with {}", input.toString()); - return Response.status(Response.Status.OK).build(); - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java deleted file mode 100644 index 2a7af82a..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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. - */ -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; - -/** - * Encodes and decodes the OpenstackSubnet. - */ -public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> { - private static Logger log = LoggerFactory - .getLogger(OpenstackSubnetCodec.class); - - // JSON Field names - private static final String SUBNET = "subnet"; - private static final String NAME = "name"; - private static final String ENABLE_DHCP = "enable_dhcp"; - private static final String NETWORK_ID = "network_id"; - private static final String TENANT_ID = "tenant_id"; - private static final String DNS_NAMESERVERS = "dns_nameservers"; - private static final String GATEWAY_IP = "gateway_ip"; - private static final String CIDR = "cidr"; - private static final String ID = "id"; - - @Override - public OpenstackSubnet decode(ObjectNode json, CodecContext context) { - JsonNode subnetInfo = json.get(SUBNET); - if (subnetInfo == null) { - subnetInfo = json; - } - - String name = subnetInfo.path(NAME).asText(); - boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean(); - String networkId = subnetInfo.path(NETWORK_ID).asText(); - String tenantId = subnetInfo.path(TENANT_ID).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(); - - OpenstackSubnet openstackSubnet = OpenstackSubnet.builder() - .setName(name) - .setEnableDhcp(enableDhcp) - .setNetworkId(networkId) - .setTenantId(tenantId) - .setDnsNameservers(dnsList) - .setGatewayIp(gatewayIp) - .setCidr(cidr) - .setId(id) - .build(); - return openstackSubnet; - } -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java deleted file mode 100644 index 43205eac..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ -package org.onosproject.openstackswitching.web; - -/** - * Handles Rest API call from Neutron ML2 plugin. - */ -import org.onosproject.rest.AbstractWebResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.InputStream; - -@Path("subnets") -public class OpenstackSubnetWebResource extends AbstractWebResource { - protected static final Logger log = LoggerFactory - .getLogger(OpenstackSubnetWebResource.class); - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createSubnet(InputStream input) { - return Response.status(Response.Status.OK).build(); - } - - - @PUT - @Path("{subnetUUID}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public Response updateSubnet(@PathParam("id") String id, - final InputStream input) { - return Response.status(Response.Status.OK).build(); - - } - - @DELETE - @Path("{subnetUUID}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public Response deleteSubnet(@PathParam("id") String id, - final InputStream input) { - return Response.status(Response.Status.OK).build(); - } - - -} diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/package-info.java b/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/package-info.java deleted file mode 100644 index 91e19c62..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 switching REST API. - */ -package org.onosproject.openstackswitching.web; diff --git a/framework/src/onos/apps/openstackswitching/app/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/openstackswitching/app/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 4f50ef72..00000000 --- a/framework/src/onos/apps/openstackswitching/app/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?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. - --> -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" - id="ONOS" version="2.5"> - <display-name>Openstack Switching REST API v1.0</display-name> - - <servlet> - <servlet-name>JAX-RS Service</servlet-name> - <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> - <init-param> - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> - </init-param> - <init-param> - <param-name>com.sun.jersey.config.property.classnames</param-name> - <param-value> - org.onosproject.openstackswitching.web.OpenstackPortWebResource, - org.onosproject.openstackswitching.web.OpenstackNetworkWebResource, - org.onosproject.openstackswitching.web.OpenstackSubnetWebResource - </param-value> - </init-param> - <load-on-startup>1</load-on-startup> - </servlet> - - <servlet-mapping> - <servlet-name>JAX-RS Service</servlet-name> - <url-pattern>/*</url-pattern> - </servlet-mapping> -</web-app> diff --git a/framework/src/onos/apps/openstackswitching/network-cfg.json b/framework/src/onos/apps/openstackswitching/network-cfg.json deleted file mode 100644 index 62c3a515..00000000 --- a/framework/src/onos/apps/openstackswitching/network-cfg.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "apps" : { - "org.onosproject.openstackswitching" : { - "openstackswitching" : { - "do_not_push_flows" : "false", - "neutron_server" : "http://127.0.0.1:9696/v2.0/", - "keystone_server" : "http://127.0.0.1:5000/v2.0/", - "user_name" : "admin", - "password" : "nova" - } - }, - "org.onosproject.dhcp" : { - "dhcp" : { - "ip": "10.0.0.1", - "mac": "1a:2b:3c:4e:5e:6f", - "subnet": "255.0.0.0", - "broadcast": "10.255.255.255", - "router": "10.0.0.1", - "domain": "10.0.0.1", - "ttl": "63", - "lease": "300", - "renew": "150", - "rebind": "200", - "delay": "3", - "timeout": "150", - "startip": "10.0.0.110", - "endip": "10.0.0.130" - } - }, - "org.onosproject.cordvtn" : { - "cordvtn" : { - "ovsdbNodes" : [ - { - "host" : "compute-01", - "ip" : "128.199.162.106", - "port" : "6640", - "bridgeId" : "of:0000000000000001" - }, - { - "host" : "compute-02", - "ip" : "103.253.145.133", - "port" : "6640", - "bridgeId" : "of:0000000000000002" - }, - { - "host" : "network", - "ip" : "128.199.125.11", - "port" : "6640", - "bridgeId" : "of:0000000000000003" - } - ] - } - } - } -} diff --git a/framework/src/onos/apps/openstackswitching/pom.xml b/framework/src/onos/apps/openstackswitching/pom.xml deleted file mode 100644 index cfeaa5b3..00000000 --- a/framework/src/onos/apps/openstackswitching/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?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-apps</artifactId> - <version>1.4.0-rc1</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-openstackswitching</artifactId> - <packaging>pom</packaging> - - <description>SONA Openstack Switching application</description> - - <modules> - <module>api</module> - <module>app</module> - </modules> - - <dependencies> - </dependencies> - - -</project> |