ONOS-6039 Removed unused openstackinterface app

Change-Id: I783483b2b5c9dbc9a3937c78d97e80f2824f1a80
This commit is contained in:
Hyunsun Moon 2017-03-20 11:35:00 +09:00 committed by Ray Milkey
parent e0a98f5020
commit bd1cd448a1
33 changed files with 0 additions and 3890 deletions

View File

@ -1,12 +0,0 @@
BUNDLES = [
'//apps/openstackinterface/api:onos-apps-openstackinterface-api',
'//apps/openstackinterface/app:onos-apps-openstackinterface-app',
]
onos_app (
title = 'OpenStack Interface App',
category = 'Utility',
url = 'http://onosproject.org',
description = 'Openstack Interface Application.',
included_bundles = BUNDLES,
)

View File

@ -1,9 +0,0 @@
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//lib:jersey-client',
'//lib:javax.ws.rs-api',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
)

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-openstackinterface</artifactId>
<version>1.10.0-SNAPSHOT</version>
</parent>
<artifactId>onos-app-openstackinterface-api</artifactId>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,145 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.onlab.packet.Ip4Address;
import java.util.Map;
import java.util.Objects;
/**
* A configurable external gateway modes extension model in openstack router.
*/
public final class OpenstackExternalGateway {
private final String networkId;
private final boolean enablePnat;
private final Map<String, Ip4Address> externalFixedIps;
private OpenstackExternalGateway(String networkId, boolean enablePnat,
Map<String, Ip4Address> externalFixedIps) {
this.networkId = networkId;
this.enablePnat = enablePnat;
this.externalFixedIps = externalFixedIps;
}
/**
* Returns network ID.
*
* @return Network ID
*/
public String networkId() {
return networkId;
}
/**
* Returns the PNAT status for external gateway.
*
* @return PNAT status
*/
public boolean isEnablePnat() {
return enablePnat;
}
/**
* Returns external fixed IP informations.
*
* @return External fixed IP informations
*/
public Map<String, Ip4Address> externalFixedIps() {
return ImmutableMap.copyOf(externalFixedIps);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackExternalGateway) {
OpenstackExternalGateway that = (OpenstackExternalGateway) o;
return this.networkId.equals(that.networkId) &&
this.enablePnat == that.enablePnat &&
this.externalFixedIps.equals(that.externalFixedIps);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(networkId, enablePnat, externalFixedIps);
}
/**
* An Openstack External Gateway Builder class.
*/
public static final class Builder {
private String networkId;
private boolean enablePnat;
private Map<String, Ip4Address> externalFixedIps;
public Builder() {
externalFixedIps = Maps.newHashMap();
}
/**
* Sets network ID.
*
* @param networkId Network ID
* @return Builder object
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return this;
}
/**
* Sets whether PNAT status is enabled or not.
*
* @param enablePnat true if PNAT status is enabled, false otherwise
* @return Builder object
*/
public Builder enablePnat(boolean enablePnat) {
this.enablePnat = enablePnat;
return this;
}
/**
* Sets external fixed IP address information.
*
* @param externalFixedIps External fixed IP information
* @return Builder object
*/
public Builder externalFixedIps(Map<String, Ip4Address> externalFixedIps) {
this.externalFixedIps.putAll(externalFixedIps);
return this;
}
/**
* Builds an OpenstackExternalGateway object.
*
* @return OpenstackExternalGateway object
*/
public OpenstackExternalGateway build() {
return new OpenstackExternalGateway(networkId, enablePnat, ImmutableMap.copyOf(externalFixedIps));
}
}
}

View File

@ -1,287 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import org.onlab.packet.Ip4Address;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An Openstack Neutron Floating IP Model.
*/
public final class OpenstackFloatingIP {
public enum FloatingIpStatus {
UP,
DOWN,
ACTIVE,
}
private final String tenantId;
private final String networkId;
private final Ip4Address fixedIpAddress;
private String portId;
private String routerId;
private final String id;
private final Ip4Address floatingIpAddress;
private final FloatingIpStatus status;
private OpenstackFloatingIP(FloatingIpStatus status, String id, String tenantId,
String networkId, Ip4Address fixedIpAddress, String portId,
String routerId, Ip4Address floatingIpAddress) {
this.status = status;
this.id = id;
this.tenantId = tenantId;
this.networkId = networkId;
this.fixedIpAddress = fixedIpAddress;
this.portId = portId;
this.routerId = routerId;
this.floatingIpAddress = floatingIpAddress;
}
/**
* Returns floating IP status.
*
* @return floating IP status
*/
public FloatingIpStatus status() {
return status;
}
/**
* Returns floating IP`s ID.
*
* @return floating IP`s ID
*/
public String id() {
return id;
}
/**
* Returns tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
/**
* Returns network ID.
*
* @return network ID
*/
public String networkId() {
return networkId;
}
/**
* Returns fixed IP Address.
*
* @return fixed IP Address
*/
public Ip4Address fixedIpAddress() {
return fixedIpAddress;
}
/**
* Returns port ID.
*
* @return port ID
*/
public String portId() {
return portId;
}
/**
* Updates port ID.
*
* @param portId Updated port ID
*/
public void updatePortId(String portId) {
this.portId = portId;
}
/**
* Returns router ID.
*
* @return router ID
*/
public String routerId() {
return routerId;
}
/**
* Updates router ID.
*
* @param routerId Updated router ID
*/
public void updateRouterId(String routerId) {
this.routerId = routerId;
}
/**
* Returns floating IP address.
*
* @return Floating IP address
*/
public Ip4Address floatingIpAddress() {
return floatingIpAddress;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackFloatingIP) {
OpenstackFloatingIP that = (OpenstackFloatingIP) o;
return this.status.equals(that.status) &&
this.id.equals(that.id) &&
this.tenantId.equals(that.tenantId) &&
this.networkId.equals(that.networkId) &&
this.fixedIpAddress.equals(that.fixedIpAddress) &&
this.floatingIpAddress.equals(that.floatingIpAddress) &&
this.portId.equals(that.portId) &&
this.routerId.equals(that.routerId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(status, id, tenantId, networkId, floatingIpAddress, fixedIpAddress, portId, routerId);
}
/**
* An Openstack Floating IP Builder class.
*/
public static final class Builder {
private String tenantId;
private String networkId;
private Ip4Address fixedIpAddress;
private String portId;
private String routerId;
private String id;
private Ip4Address floatingIpAddress;
private FloatingIpStatus status;
/**
* Sets tenant ID.
*
* @param tenantId tenant ID
* @return Builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets floating IP status.
*
* @param status Floating IP status
* @return Builder object
*/
public Builder status(FloatingIpStatus status) {
this.status = status;
return this;
}
/**
* Sets Floating IP`s ID.
*
* @param id Floating IP`s ID
* @return Builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets network ID.
*
* @param networkId Network ID
* @return Builder object
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return this;
}
/**
* Sets fixed IP address.
*
* @param fixedIpAddress Fixed IP address
* @return Builder object
*/
public Builder fixedIpAddress(Ip4Address fixedIpAddress) {
this.fixedIpAddress = fixedIpAddress;
return this;
}
/**
* Sets port ID.
*
* @param portId port ID
* @return Builder object
*/
public Builder portId(String portId) {
this.portId = portId;
return this;
}
/**
* Sets router ID.
*
* @param routerId router ID
* @return Builder object
*/
public Builder routerId(String routerId) {
this.routerId = routerId;
return this;
}
/**
* Sets floating IP address.
*
* @param floatingIpAddress Floating IP address
* @return Builder object
*/
public Builder floatingIpAddress(Ip4Address floatingIpAddress) {
this.floatingIpAddress = floatingIpAddress;
return this;
}
/**
* Builds an OpenstackFloatingIP object.
*
* @return OpenstackFloatingIP object
*/
public OpenstackFloatingIP build() {
return new OpenstackFloatingIP(checkNotNull(status), checkNotNull(id), checkNotNull(tenantId),
checkNotNull(networkId), fixedIpAddress, portId,
routerId, checkNotNull(floatingIpAddress));
}
}
}

View File

@ -1,116 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.basics.BasicElementConfig;
/**
* Handles configuration for OpenstackInterface app.
*/
public class OpenstackInterfaceConfig extends Config<ApplicationId> {
public static final String NEUTRON_SERVER = "neutronServer";
public static final String KEYSTONE_SERVER = "keystoneServer";
public static final String USER_NAME = "userName";
public static final String PASSWORD = "password";
public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
/**
* 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, "");
}
/**
* Returns the MacAddress for physical router.
*
* @return physical router mac
*/
public String physicalRouterMac() {
return get(PHYSICAL_ROUTER_MAC, "");
}
/**
* 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);
}
}

View File

@ -1,131 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import org.onlab.packet.Ip4Address;
import org.onosproject.net.Port;
import java.util.Collection;
import java.util.Optional;
/**
* Handles port management REST API from Openstack for VMs.
*/
public interface OpenstackInterfaceService {
/**
* 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 list.
*
* @return port information list
*/
Collection<OpenstackPort> ports();
/**
* 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, or null if not present
*/
OpenstackNetwork network(String networkId);
/**
* Returns the information of all openstack networks.
*
* @return collection of network information
*/
Collection<OpenstackNetwork> networks();
/**
* Returns subnet information for the subnet ID give.
*
* @param subnetId subnet id
* @return subnet information, or null if not present
*/
OpenstackSubnet subnet(String subnetId);
/**
* Returns collection of openstack subnet information.
*
* @return collection of openststack subnet information
*/
Collection<OpenstackSubnet> subnets();
/**
* Returns the router information list.
*
* @return router information list
*/
Collection<OpenstackRouter> routers();
/**
* Returns the router information for the router ID given.
*
* @param routerId router id
* @return router information
*/
OpenstackRouter router(String routerId);
/**
* Returns Security Group information of the security groupd id given.
*
* @param id security group id
* @return security group information
*/
OpenstackSecurityGroup securityGroup(String id);
/**
* Returns collection of OpenStack floating IP information.
*
* @return collection of OpenStack floating IP information
*/
Collection<OpenstackFloatingIP> floatingIps();
/**
* Updates a floating IP and its association with an internal port.
*
* @param id floating ip id
* @param portId port id
* @param fixedIpAddress fixed ip address of the port
* @return true if the update succeed
*/
boolean updateFloatingIp(String id, String portId, Optional<Ip4Address> fixedIpAddress);
}

View File

@ -1,138 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import java.util.Collection;
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;
private Collection<OpenstackSubnet> subnets;
public enum NetworkType {
/**
* Currently only VXLAN moded is supported.
*/
VXLAN
}
/**
* 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, Collection<OpenstackSubnet> subnets) {
this.name = checkNotNull(name);
this.tenantId = checkNotNull(tenantId);
this.segmentId = checkNotNull(sid);
this.id = checkNotNull(id);
this.networkType = type;
this.subnets = subnets;
}
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;
}
public Collection<OpenstackSubnet> subnets() {
return this.subnets;
}
@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;
private Collection<OpenstackSubnet> subnets;
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 Builder subnets(Collection<OpenstackSubnet> subnets) {
this.subnets = subnets;
return this;
}
public OpenstackNetwork build() {
return new OpenstackNetwork(name, tenantId, id, sid, networkType, subnets);
}
}
}

View File

@ -1,361 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import java.util.Collection;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* It represents the Openstack Port information.
*/
public final class OpenstackPort {
public enum PortStatus {
UP,
DOWN,
ACTIVE,
NA,
}
private PortStatus status;
private String name;
private ImmutableMap<IpAddress, MacAddress> allowedAddressPairs;
private boolean adminStateUp;
private String networkId;
private String tenantId;
private String deviceOwner;
private MacAddress macAddress;
// <subnet id, ip address>
private ImmutableMap<String, Ip4Address> fixedIps;
private String id;
private Collection<String> securityGroups;
private String deviceId;
private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs,
boolean adminStateUp, String networkId, String tenantId,
String deviceOwner, MacAddress macAddress, Map<String, Ip4Address> fixedIps,
String id, Collection<String> securityGroups, String deviceId) {
this.status = status;
this.name = name;
this.allowedAddressPairs = checkNotNull(ImmutableMap.copyOf(allowedAddressPairs));
this.adminStateUp = adminStateUp;
this.networkId = checkNotNull(networkId);
this.tenantId = checkNotNull(tenantId);
this.deviceOwner = deviceOwner;
this.macAddress = checkNotNull(macAddress);
this.fixedIps = checkNotNull(ImmutableMap.copyOf(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 allowed address pairs.
*
* @return map of ip address and mac address, or empty map
*/
public Map<IpAddress, MacAddress> allowedAddressPairs() {
return allowedAddressPairs;
}
/**
* 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 Map<String, Ip4Address> fixedIps() {
return fixedIps;
}
/**
* Returns port ID.
*
* @return port ID
*/
public String id() {
return id;
}
/**
* Returns security group information.
*
* @return security group info
*/
public Collection<String> securityGroups() {
return securityGroups;
}
/**
* Returns device ID.
*
* @return device ID
*/
public String deviceId() {
return deviceId;
}
/**
* OpenstackPort Builder class.
*/
public static final class Builder {
private PortStatus status;
private String name;
private Map<IpAddress, MacAddress> 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 Map<String, Ip4Address> fixedIps;
private String id;
private Collection<String> securityGroups;
private String deviceId;
Builder() {
fixedIps = Maps.newHashMap();
allowedAddressPairs = Maps.newHashMap();
}
/**
* 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 allowed address pairs.
*
* @param addrPairs map of ip address and mac address
* @return Builder object
*/
public Builder allowedAddressPairs(Map<IpAddress, MacAddress> addrPairs) {
this.allowedAddressPairs.putAll(addrPairs);
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(Map<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 securityGroupList security group list of the port
* @return Builder object
*/
public Builder securityGroup(Collection<String> securityGroupList) {
this.securityGroups = securityGroupList;
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, allowedAddressPairs, adminStateUp,
networkId, tenantId, deviceOwner, macAddress, fixedIps,
id, securityGroups, deviceId);
}
}
}

View File

@ -1,219 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An Openstack Neutron Router Model.
*/
public final class OpenstackRouter {
public enum RouterStatus {
UP,
DOWN,
ACTIVE,
}
private final String tenantId;
private final String id;
private final String name;
private RouterStatus status;
private boolean adminStateUp;
private OpenstackExternalGateway gatewayExternalInfo;
private OpenstackRouter(String id, String tenantId, String name, RouterStatus status,
boolean adminStateUp, OpenstackExternalGateway gatewayExternalInfo) {
this.id = id;
this.tenantId = tenantId;
this.name = name;
this.status = status;
this.adminStateUp = adminStateUp;
this.gatewayExternalInfo = gatewayExternalInfo;
}
/**
* Returns tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
/**
* Returns router ID.
*
* @return router ID
*/
public String id() {
return id;
}
/**
* Returns router name.
*
* @return router name
*/
public String name() {
return name;
}
/**
* Returns router status.
*
* @return router stauts
*/
public RouterStatus status() {
return status;
}
/**
* Returns whether admin state up or not.
*
* @return true if admin state up, false otherwise
*/
public boolean adminStateUp() {
return adminStateUp;
}
/**
* Returns external gateway information.
*
* @return external gateway information
*/
public OpenstackExternalGateway gatewayExternalInfo() {
return gatewayExternalInfo;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackRouter) {
OpenstackRouter that = (OpenstackRouter) o;
return this.adminStateUp == that.adminStateUp &&
this.gatewayExternalInfo.equals(that.gatewayExternalInfo) &&
this.id.equals(that.id) &&
this.name.equals(that.name) &&
this.status.equals(that.status) &&
this.tenantId.equals(that.tenantId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(adminStateUp, gatewayExternalInfo, id, name, status, tenantId);
}
/**
* An Openstack Router Builder class.
*/
public static final class Builder {
private String tenantId;
private String id;
private String name;
private RouterStatus status;
private Boolean adminStateUp;
private OpenstackExternalGateway gatewayExternalInfo;
/**
* Sets router ID.
*
* @param id router ID
* @return Builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets router name.
*
* @param name router name
* @return Builder object
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Sets router status.
*
* @param status router status
* @return Builder object
*/
public Builder status(RouterStatus status) {
this.status = status;
return this;
}
/**
* Sets tenant ID.
*
* @param tenantId Tenant ID
* @return Builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets whether admin state up or not.
*
* @param adminStateUp true if admin state is up, false otherwise
* @return Builder object
*/
public Builder adminStateUp(boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return this;
}
/**
* Sets external gateway information.
*
* @param gatewayExternalInfo external gateway information
* @return Builder object
*/
public Builder gatewayExternalInfo(OpenstackExternalGateway gatewayExternalInfo) {
this.gatewayExternalInfo = gatewayExternalInfo;
return this;
}
/**
* Builds an OpenstackRouter object.
*
* @return OpenstasckRouter object
*/
public OpenstackRouter build() {
return new OpenstackRouter(checkNotNull(id), checkNotNull(tenantId), name, checkNotNull(status),
checkNotNull(adminStateUp), gatewayExternalInfo);
}
}
}

View File

@ -1,170 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An OpenStack Neutron router interface model.
*/
public final class OpenstackRouterInterface {
private final String id;
private final String tenantId;
private final String subnetId;
private final String portId;
private OpenstackRouterInterface(String id, String tenantId,
String subnetId, String portId) {
this.id = checkNotNull(id);
this.tenantId = checkNotNull(tenantId);
this.subnetId = checkNotNull(subnetId);
this.portId = checkNotNull(portId);
}
/**
* Returns router interface ID.
*
* @return router interface id
*/
public String id() {
return id;
}
/**
* Returns tenant ID.
*
* @return tenant id
*/
public String tenantId() {
return tenantId;
}
/**
* Returns subnet ID.
*
* @return subnet id
*/
public String subnetId() {
return subnetId;
}
/**
* Returns port ID.
*
* @return port id
*/
public String portId() {
return portId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackRouterInterface) {
OpenstackRouterInterface that = (OpenstackRouterInterface) o;
return this.id.equals(that.id) &&
this.portId.equals(that.portId) &&
this.subnetId.equals(that.subnetId) &&
this.tenantId.equals(that.tenantId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(id, portId, subnetId, tenantId);
}
/**
* Returns OpenStack router interface builder.
*
* @return openstack router interface builder
*/
public static Builder builder() {
return new Builder();
}
/**
* An OpenStack Router interface builder class.
*/
public static final class Builder {
private String id;
private String tenantId;
private String subnetId;
private String portId;
/**
* Sets router interface ID.
*
* @param id router interface id
* @return builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets tenant ID.
*
* @param tenantId tenant ID
* @return builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Sets subnet ID.
*
* @param subnetId subnet ID
* @return builder object
*/
public Builder subnetId(String subnetId) {
this.subnetId = subnetId;
return this;
}
/**
* Sets port ID.
*
* @param portId port ID
* @return builder object
*/
public Builder portId(String portId) {
this.portId = portId;
return this;
}
/**
* Builds an OpenStack router interface object.
*
* @return openstack router interface object
*/
public OpenstackRouterInterface build() {
return new OpenstackRouterInterface(checkNotNull(id), checkNotNull(tenantId),
checkNotNull(subnetId), checkNotNull(portId));
}
}
}

View File

@ -1,207 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
/**
* Represents Openstack Security Group information.
*/
public final class OpenstackSecurityGroup {
private String description;
private String id;
private String name;
private Collection<OpenstackSecurityGroupRule> rules;
private String tenantId;
private OpenstackSecurityGroup(String description, String id, String name,
Collection<OpenstackSecurityGroupRule> rules,
String tenantId) {
this.description = description;
this.id = id;
this.name = name;
this.tenantId = tenantId;
this.rules = rules;
}
/**
* Returns the description of the security group.
*
* @return description
*/
public String description() {
return this.description;
}
/**
* Returns ID of the security group.
*
* @return ID
*/
public String id() {
return this.id;
}
/**
* Returns the name of the security group.
*
* @return name
*/
public String name() {
return this.name;
}
/**
* Returns the list of the security group rules.
*
* @return Collection of OpenstackSecurityGroupRule objects
*/
public Collection<OpenstackSecurityGroupRule> rules() {
return Collections.unmodifiableCollection(rules);
}
/**
* Returns the Tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return this.tenantId;
}
@Override
public String toString() {
StringBuilder sbuilder = new StringBuilder("Security Group :")
.append(description + ",")
.append(id + ",")
.append(name + ",");
rules.forEach(rule -> sbuilder.append(rule.toString()));
sbuilder.append(tenantId);
return sbuilder.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackSecurityGroup) {
OpenstackSecurityGroup that = (OpenstackSecurityGroup) o;
return this.description.equals(that.description) &&
this.tenantId.equals(that.tenantId) &&
this.id.equals(that.id) &&
this.name.equals(that.name) &&
this.rules.containsAll(that.rules);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(description, tenantId, id, name, rules);
}
/**
* Returns the SecurityGroupRule builder object.
*
* @return builder object
*/
public static Builder builder() {
return new Builder();
}
/**
* Represents the builder of the SecurityGroupRule.
*
*/
public static final class Builder {
private String description;
private String id;
private String name;
private Collection<OpenstackSecurityGroupRule> rules;
private String tenantId;
/**
* Sets the description of the security group.
*
* @param description description
* @return builder object
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* Sets the ID of the security group.
*
* @param id ID
* @return builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets the name of the security group.
*
* @param name name
* @return builder object
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Sets Security Group rules.
*
* @param rules security group rules
* @return builder object
*/
public Builder rules(Collection<OpenstackSecurityGroupRule> rules) {
this.rules = rules;
return this;
}
/**
* Sets the tenant ID of the security group.
*
* @param tenantId tenant ID
* @return builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Creates the OpenstackSecurityGroup object.
*
* @return OpenstackSecurityGroup object
*/
public OpenstackSecurityGroup build() {
return new OpenstackSecurityGroup(description, id, name, rules, tenantId);
}
}
}

View File

@ -1,360 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import org.onlab.packet.IpPrefix;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents Openstack Security Group Rules.
*/
public final class OpenstackSecurityGroupRule {
private final Direction direction;
private final String ethertype;
private final String id;
private final int portRangeMax;
private final int portRangeMin;
private final String protocol;
private final String remoteGroupId;
private final IpPrefix remoteIpPrefix;
private final String secuityGroupId;
private final String tenantId;
/**
* Direction of the Security Group.
*
*/
public enum Direction {
INGRESS,
EGRESS
}
private OpenstackSecurityGroupRule(Direction direction,
String ethertype,
String id,
int portRangeMax,
int portRangeMin,
String protocol,
String remoteGroupId,
IpPrefix remoteIpPrefix,
String securityGroupId,
String tenantId) {
this.direction = direction;
this.ethertype = ethertype;
this.id = checkNotNull(id);
this.portRangeMax = portRangeMax;
this.portRangeMin = portRangeMin;
this.protocol = protocol;
this.remoteGroupId = remoteGroupId;
this.remoteIpPrefix = remoteIpPrefix;
this.secuityGroupId = securityGroupId;
this.tenantId = tenantId;
}
/**
* Returns the builder object for the OpenstackSecurityGroupRule.
*
* @return OpenstackSecurityGroupRule builder object
*/
public static OpenstackSecurityGroupRule.Builder builder() {
return new Builder();
}
/**
* Returns the direction.
*
* @return direction
*/
public Direction direction() {
return direction;
}
/**
* Returns the Ethernet type.
*
* @return Ethernet type
*/
public String ethertype() {
return ethertype;
}
/**
* Returns the Security Group ID.
*
* @return Security Group ID
*/
public String id() {
return id;
}
/**
* Returns the max of the port range.
*
* @return max of the port range
*/
public int portRangeMax() {
return portRangeMax;
}
/**
* Returns the min of the port range.
*
* @return min of the port range
*/
public int portRangeMin() {
return portRangeMin;
}
/**
* Returns the IP protocol.
*
* @return IP protocol
*/
public String protocol() {
return protocol;
}
/**
* Returns the remote group ID.
*
* @return remote group ID
*/
public String remoteGroupId() {
return remoteGroupId;
}
/**
* Returns the remote IP address.
*
* @return remote IP address
*/
public IpPrefix remoteIpPrefix() {
return this.remoteIpPrefix;
}
/**
* Returns the Security Group ID.
*
* @return security group ID
*/
public String secuityGroupId() {
return secuityGroupId;
}
/**
* Returns the tenant ID.
*
* @return tenant ID
*/
public String tenantId() {
return tenantId;
}
@Override
public String toString() {
return new StringBuilder(" [")
.append(direction + ",")
.append(ethertype + ",")
.append(id + ",")
.append(portRangeMax + ",")
.append(portRangeMin + ",")
.append(protocol + ",'")
.append(remoteGroupId + ",")
.append(remoteIpPrefix + ",")
.append(secuityGroupId + ",")
.append(tenantId + "] ")
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof OpenstackSecurityGroupRule) {
OpenstackSecurityGroupRule that = (OpenstackSecurityGroupRule) o;
return this.direction.equals(that.direction) &&
this.ethertype.equals(that.ethertype) &&
this.id.equals(that.id) &&
this.portRangeMax == that.portRangeMax &&
this.portRangeMin == that.portRangeMin &&
this.protocol.equals(that.protocol) &&
this.remoteGroupId.equals(that.remoteGroupId) &&
this.secuityGroupId.equals(that.secuityGroupId) &&
this.remoteIpPrefix.equals(that.remoteIpPrefix) &&
this.tenantId.equals(that.tenantId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(direction, ethertype, id, portRangeMax, portRangeMin, protocol,
remoteGroupId, remoteIpPrefix, secuityGroupId, tenantId);
}
/**
* Represents a security group rule builder object.
*/
public static final class Builder {
private String direction;
private String etherType;
private String id;
private String portRangeMax;
private String portRangeMin;
private String protocol;
private String remoteGroupId;
private String remoteIpPrefix;
private String secuityGroupId;
private String tenantId;
/**
* Sets the direction of the security group rule.
*
* @param direction direction (ingress or egress)
* @return builder object
*/
public Builder direction(String direction) {
this.direction = direction;
return this;
}
/**
* Sets the Ethernet Type.
*
* @param etherType Ethernet Type
* @return builder object
*/
public Builder etherType(String etherType) {
this.etherType = etherType;
return this;
}
/**
* Sets the Security Group Rule ID.
*
* @param id security group rule ID
* @return builder object
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Sets the port range max value.
*
* @param portRangeMax port range max value
* @return builder object
*/
public Builder portRangeMax(String portRangeMax) {
this.portRangeMax = portRangeMax;
return this;
}
/**
* Sets the port range min value.
*
* @param portRangeMin port range min value
* @return builder object
*/
public Builder portRangeMin(String portRangeMin) {
this.portRangeMin = portRangeMin;
return this;
}
/**
* Sets the protocol.
*
* @param protocol protocol
* @return builder object
*/
public Builder protocol(String protocol) {
this.protocol = protocol;
return this;
}
/**
* Sets the remote security group ID.
*
* @param remoteGroupId remote security group ID
* @return builder
*/
public Builder remoteGroupId(String remoteGroupId) {
this.remoteGroupId = remoteGroupId;
return this;
}
/**
* Sets the remote IP address as prefix.
*
* @param remoteIpPrefix remote IP address
* @return builder object
*/
public Builder remoteIpPrefix(String remoteIpPrefix) {
this.remoteIpPrefix = remoteIpPrefix;
return this;
}
/**
* Sets the Security Group ID.
*
* @param securityGroupId security group ID
* @return builder object
*/
public Builder securityGroupId(String securityGroupId) {
this.secuityGroupId = securityGroupId;
return this;
}
/**
* Sets the tenant ID.
*
* @param tenantId tenant ID
* @return builder object
*/
public Builder tenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
/**
* Creates a OpenstackSecurityGroupRule instance.
*
* @return OpenstackSecurityGroupRule object
*/
public OpenstackSecurityGroupRule build() {
int portRangeMinInt = (portRangeMin == null || portRangeMin.equals("null")) ?
-1 : Integer.parseInt(portRangeMin);
int portRangeMaxInt = (portRangeMax == null || portRangeMax.equals("null")) ?
-1 : Integer.parseInt(portRangeMax);
IpPrefix ipPrefix = (remoteIpPrefix == null || remoteIpPrefix.equals("null")) ?
null : IpPrefix.valueOf(remoteIpPrefix);
return new OpenstackSecurityGroupRule(Direction.valueOf(direction.toUpperCase()), etherType, id,
portRangeMaxInt, portRangeMinInt, protocol, remoteGroupId, ipPrefix, secuityGroupId, tenantId);
}
}
}

View File

@ -1,176 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface;
import org.onlab.packet.Ip4Address;
import java.util.Collection;
import java.util.Collections;
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 Collection<String> securityGroups;
private OpenstackSubnet(String name, boolean enableHhcp, String networkId,
String tenantId, List<Ip4Address> dnsNameservers, String gatewayIp,
String cidr, String id, Collection<String> securityGroups) {
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);
this.securityGroups = securityGroups;
}
/**
* 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;
}
public Collection<String> securityGroups() {
return Collections.unmodifiableCollection(this.securityGroups);
}
/**
* 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;
private Collection<String> securityGroups;
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 Builder securityGroups(Collection<String> securityGroups) {
this.securityGroups = securityGroups;
return this;
}
public OpenstackSubnet build() {
return new OpenstackSubnet(name, enableDhcp, networkId, tenantId,
dnsNameservers, gatewayIp, cidr, id, securityGroups);
}
}
}

View File

@ -1,20 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Application that handles OpenStack Neutron REST calls.
*/
package org.onosproject.openstackinterface;

View File

@ -1,11 +0,0 @@
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//lib:jersey-client',
'//lib:javax.ws.rs-api',
'//apps/openstackinterface/api:onos-apps-openstackinterface-api',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
)

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<app name="org.onosproject.openstackinterface" origin="ON.Lab" version="${project.version}"
category="Utility" url="http://onosproject.org" title="OpenStack Interface App"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-app-openstackinterface-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-openstackinterface-app/${project.version}</artifact>
</app>

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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-openstackinterface-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-openstackinterface-app/${project.version}</bundle>
</feature>
</features>

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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-app-openstackinterface</artifactId>
<version>1.10.0-SNAPSHOT</version>
</parent>
<artifactId>onos-app-openstackinterface-app</artifactId>
<packaging>bundle</packaging>
<description>Openstack Interface Application</description>
<properties>
<onos.app.readme>Openstack Interface Application.</onos.app.readme>
</properties>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-openstackinterface-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>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-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>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>

View File

@ -1,582 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
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.glassfish.jersey.client.ClientProperties;
import org.onlab.packet.Ip4Address;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
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.openstackinterface.OpenstackFloatingIP;
import org.onosproject.openstackinterface.OpenstackInterfaceService;
import org.onosproject.openstackinterface.OpenstackNetwork;
import org.onosproject.openstackinterface.OpenstackInterfaceConfig;
import org.onosproject.openstackinterface.OpenstackPort;
import org.onosproject.openstackinterface.OpenstackRouter;
import org.onosproject.openstackinterface.OpenstackSecurityGroup;
import org.onosproject.openstackinterface.OpenstackSubnet;
import org.onosproject.openstackinterface.web.OpenstackFloatingIpCodec;
import org.onosproject.openstackinterface.web.OpenstackNetworkCodec;
import org.onosproject.openstackinterface.web.OpenstackPortCodec;
import org.onosproject.openstackinterface.web.OpenstackRouterCodec;
import org.onosproject.openstackinterface.web.OpenstackSecurityGroupCodec;
import org.onosproject.openstackinterface.web.OpenstackSubnetCodec;
import org.slf4j.Logger;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.net.MediaType.JSON_UTF_8;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Handles REST Calls to Openstack Neutron.
*
*/
@Service
@Component(immediate = true)
public class OpenstackInterfaceManager implements OpenstackInterfaceService {
private static final String URI_NETWORKS = "networks";
private static final String URI_PORTS = "ports";
private static final String URI_SUBNETS = "subnets";
private static final String URI_SECURITY_GROUPS = "security-groups";
private static final String URI_FLOATINGIPS = "floatingips";
private static final String URI_TOKENS = "tokens";
private static final String FLOATINGIP = "floatingip";
private static final String PORT_ID = "port_id";
private static final String FIXED_IP_ADDRESS = "fixed_ip_address";
private static final String PATH_ROUTERS = "routers";
private static final String PATH_NETWORKS = "networks";
private static final String PATH_PORTS = "ports";
private static final String PATH_SUBNETS = "subnets";
private static final String PATH_FLOATINGIPS = "floatingips";
private static final String PATH_ACCESS = "access";
private static final String PATH_TOKEN = "token";
private static final String PATH_ID = "id";
private static final String PATH_EXPIRES = "expires";
private static final String HEADER_AUTH_TOKEN = "X-Auth-Token";
private static final String TOKEN_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final int DEFAULT_TIMEOUT_MS = 2000;
private final Logger log = getLogger(getClass());
private final Client client = ClientBuilder.newClient();
private String neutronUrl;
private String keystoneUrl;
private String tokenId;
private String tokenExpires;
private String userName;
private String pass;
private ApplicationId appId;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigRegistry cfgService;
private InternalConfigListener internalConfigListener = new InternalConfigListener();
private ExecutorService networkEventExcutorService =
Executors.newSingleThreadExecutor(groupedThreads("onos/openstackinterface", "config-event", log));
private final Set<ConfigFactory> factories = ImmutableSet.of(
new ConfigFactory<ApplicationId, OpenstackInterfaceConfig>(APP_SUBJECT_FACTORY,
OpenstackInterfaceConfig.class,
"openstackinterface") {
@Override
public OpenstackInterfaceConfig createConfig() {
return new OpenstackInterfaceConfig();
}
}
);
@Activate
protected void activate() {
appId = coreService
.registerApplication("org.onosproject.openstackinterface");
factories.forEach(cfgService::registerConfigFactory);
cfgService.addListener(internalConfigListener);
client.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_TIMEOUT_MS);
client.property(ClientProperties.READ_TIMEOUT, DEFAULT_TIMEOUT_MS);
configureNetwork();
log.info("started");
}
@Deactivate
protected void deactivate() {
cfgService.removeListener(internalConfigListener);
factories.forEach(cfgService::unregisterConfigFactory);
log.info("stopped");
}
/**
* Returns network information stored in Neutron.
*
* @return List of OpenstackNetwork
*/
public Collection<OpenstackNetwork> getNetworks() {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_NETWORKS);
if (builder == null) {
log.warn("Failed to get networks");
return Collections.EMPTY_LIST;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
log.debug("networks response:" + response);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode networkList = (ArrayNode) node.path(PATH_NETWORKS);
OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec();
networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null)));
} catch (IOException e) {
log.warn("getNetworks()", e);
}
openstackNetworks.removeAll(Collections.singleton(null));
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() {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_PORTS);
if (builder == null) {
log.warn("Failed to get ports");
return Collections.EMPTY_LIST;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_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(PATH_PORTS);
OpenstackPortCodec portCodec = new OpenstackPortCodec();
portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null)));
} catch (IOException e) {
log.warn("getPorts()", e);
}
log.debug("port response:" + response);
openstackPorts.forEach(n -> log.debug("port ID: {}", n.id()));
return openstackPorts;
}
public Collection<OpenstackRouter> getRouters() {
Invocation.Builder builder = getClientBuilder(neutronUrl, PATH_ROUTERS);
if (builder == null) {
log.warn("Failed to get routers");
return Collections.EMPTY_LIST;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackRouter> openstackRouters = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode routerList = (ArrayNode) node.path(PATH_ROUTERS);
OpenstackRouterCodec openstackRouterCodec = new OpenstackRouterCodec();
routerList.forEach(r -> openstackRouters
.add(openstackRouterCodec.decode((ObjectNode) r, null)));
} catch (IOException e) {
log.warn("getRouters()", e);
}
log.debug("router response:" + response);
openstackRouters.forEach(r -> log.debug("router ID: {}", r.id()));
return openstackRouters;
}
/**
* Returns Subnet information in Neutron.
*
* @return List of OpenstackSubnet
*/
public Collection<OpenstackSubnet> getSubnets() {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_SUBNETS);
if (builder == null) {
log.warn("Failed to get subnets");
return Collections.EMPTY_LIST;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_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(PATH_SUBNETS);
OpenstackSubnetCodec subnetCodec = new OpenstackSubnetCodec();
subnetList.forEach(s -> subnets.add(subnetCodec.decode((ObjectNode) s, null)));
} catch (IOException e) {
log.warn("getSubnets()", e);
}
log.debug("subnets response:" + response);
subnets.forEach(s -> log.debug("subnet ID: {}", s.id()));
return subnets;
}
/**
* Extracts OpenstackSecurityGroup information for the ID.
*
* @param id Security Group ID
* @return OpenstackSecurityGroup object or null if fails
*/
@Override
public OpenstackSecurityGroup securityGroup(String id) {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_SECURITY_GROUPS + "/" + id);
if (builder == null) {
log.warn("Failed to get security group {}", id);
return null;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
OpenstackSecurityGroup securityGroup = null;
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
OpenstackSecurityGroupCodec sgCodec = new OpenstackSecurityGroupCodec();
securityGroup = sgCodec.decode(node, null);
} catch (IOException e) {
log.warn("securityGroup()", e);
}
return securityGroup;
}
private Invocation.Builder getClientBuilder(String baseUrl, String path) {
if (Strings.isNullOrEmpty(baseUrl)) {
log.warn("Keystone or Neutron URL is not set");
return null;
}
WebTarget wt = client.target(baseUrl + path);
return wt.request(JSON_UTF_8.toString());
}
private String getToken() {
if (!isTokenValid()) {
String request = "{\"auth\": {\"tenantName\": \"admin\", " +
"\"passwordCredentials\": {\"username\": \"" +
userName + "\",\"password\": \"" + pass + "\"}}}";
Invocation.Builder builder = getClientBuilder(keystoneUrl, URI_TOKENS);
if (builder == null) {
log.warn("Failed to get token");
return null;
}
String response = builder.accept(MediaType.APPLICATION_JSON).post(Entity.json(request), String.class);
ObjectMapper mapper = new ObjectMapper();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
tokenId = node.path(PATH_ACCESS).path(PATH_TOKEN).path(PATH_ID).asText();
tokenExpires = node.path(PATH_ACCESS).path(PATH_TOKEN).path(PATH_EXPIRES).asText();
} catch (IOException e) {
log.warn("getToken()", e);
}
log.debug("token response:" + response);
}
return tokenId;
}
private boolean isTokenValid() {
if (tokenExpires == null || tokenId == null || tokenExpires.isEmpty()) {
return false;
}
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(TOKEN_DATE_FORMAT);
Date exireDate = dateFormat.parse(tokenExpires);
Calendar today = Calendar.getInstance();
if (exireDate.after(today.getTime())) {
return true;
}
} catch (ParseException e) {
log.error("Token parse exception error : {}", e.getMessage());
return false;
}
log.debug("token is Invalid");
return false;
}
@Override
public Collection<OpenstackPort> ports(String networkId) {
return getPorts().stream()
.filter(port -> port.networkId().equals(networkId))
.collect(Collectors.toList());
}
@Override
public Collection<OpenstackPort> ports() {
return getPorts();
}
@Override
public OpenstackPort port(Port port) {
String uuid = port.annotations().value(PORT_NAME).substring(3);
return getPorts().stream()
.filter(p -> p.id().startsWith(uuid))
.findAny().orElse(null);
}
@Override
public OpenstackPort port(String portId) {
return getPorts().stream()
.filter(p -> p.id().equals(portId))
.findAny().orElse(null);
}
@Override
public OpenstackNetwork network(String networkId) {
Collection<OpenstackSubnet> subnets = getSubnets().stream()
.filter(s -> s.networkId().equals(networkId))
.collect(Collectors.toList());
OpenstackNetwork openstackNetwork = getNetworks().stream()
.filter(n -> n.id().equals(networkId))
.findAny().orElse(null);
if (openstackNetwork == null) {
return null;
}
return OpenstackNetwork.builder()
.id(openstackNetwork.id())
.name(openstackNetwork.name())
.networkType(openstackNetwork.networkType())
.segmentId(openstackNetwork.segmentId())
.tenantId(openstackNetwork.tenantId())
.subnets(subnets)
.build();
}
@Override
public Collection<OpenstackNetwork> networks() {
return getNetworks();
}
@Override
public OpenstackSubnet subnet(String subnetId) {
return getSubnets().stream()
.filter(subnet -> subnet.id().equals(subnetId))
.findAny().orElse(null);
}
@Override
public Collection<OpenstackSubnet> subnets() {
return getSubnets();
}
@Override
public Collection<OpenstackRouter> routers() {
return getRouters();
}
@Override
public OpenstackRouter router(String routerId) {
return getRouters().stream()
.filter(router -> router.id().equals(routerId))
.findAny().orElse(null);
}
@Override
public Collection<OpenstackFloatingIP> floatingIps() {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_FLOATINGIPS);
if (builder == null) {
log.warn("Failed to get floating IPs");
return Collections.EMPTY_LIST;
}
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
log.debug("floatingIps response:" + response);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackFloatingIP> openstackFloatingIPs = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode floatingIpList = (ArrayNode) node.path(PATH_FLOATINGIPS);
OpenstackFloatingIpCodec fipCodec = new OpenstackFloatingIpCodec();
floatingIpList.forEach(f -> openstackFloatingIPs.add(fipCodec.decode((ObjectNode) f, null)));
} catch (IOException e) {
log.warn("floatingIps()", e);
}
openstackFloatingIPs.removeAll(Collections.singleton(null));
return openstackFloatingIPs;
}
@Override
public boolean updateFloatingIp(String id, String portId, Optional<Ip4Address> fixedIpAddress) {
Invocation.Builder builder = getClientBuilder(neutronUrl, URI_FLOATINGIPS + "/" + id);
if (builder == null || (portId != null && !fixedIpAddress.isPresent())) {
log.warn("Failed to update floating IP");
return false;
}
ObjectNode objectNode = createFloatingIpObject(portId, fixedIpAddress);
InputStream inputStream = new ByteArrayInputStream(objectNode.toString().getBytes());
try {
Response response = builder.header(HEADER_AUTH_TOKEN, getToken())
.put(Entity.entity(IOUtils.toString(inputStream, StandardCharsets.UTF_8),
MediaType.APPLICATION_JSON));
log.debug("updateFloatingIp called: {}, status: {}", response.readEntity(String.class),
String.valueOf(response.getStatus()));
return checkReply(response);
} catch (IOException e) {
log.error("Cannot do PUT {} request");
return false;
}
}
private ObjectNode createFloatingIpObject(String portId, Optional<Ip4Address> fixedIpAddress) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode objectNode = mapper.createObjectNode();
objectNode.putObject(FLOATINGIP)
.put(PORT_ID, portId);
if (portId != null) {
objectNode.put(FIXED_IP_ADDRESS, fixedIpAddress.get().toString());
}
return objectNode;
}
private boolean checkReply(Response response) {
if (response != null) {
return checkStatusCode(response.getStatus());
}
log.warn("Null floating IP response from openstack");
return false;
}
private boolean checkStatusCode(int statusCode) {
if (statusCode == Response.Status.OK.getStatusCode()) {
return true;
}
return false;
}
private void configureNetwork() {
OpenstackInterfaceConfig cfg =
cfgService.getConfig(appId, OpenstackInterfaceConfig.class);
if (cfg == null) {
log.error("There is no openstack server information in config.");
return;
}
neutronUrl = checkNotNull(cfg.neutronServer());
keystoneUrl = checkNotNull(cfg.keystoneServer());
userName = checkNotNull(cfg.userName());
pass = checkNotNull(cfg.password());
}
private class InternalConfigListener implements NetworkConfigListener {
@Override
public void event(NetworkConfigEvent event) {
if (((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) &&
event.configClass().equals(OpenstackInterfaceConfig.class)) {
log.info("Network configuration changed");
networkEventExcutorService.execute(() -> configureNetwork());
}
}
}
}

View File

@ -1,20 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementation classes for OpenStack interface that handles Neutron REST calls.
*/
package org.onosproject.openstackinterface.impl;

View File

@ -1,111 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.web;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.Ip4Address;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.openstackinterface.OpenstackFloatingIP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of the OpenstackFloatingIP Codec.
*/
public class OpenstackFloatingIpCodec extends JsonCodec<OpenstackFloatingIP> {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String FLOATINGIP = "floatingip";
private static final String FLOATING_NETWORK_ID = "floating_network_id";
private static final String ROUTER_ID = "router_id";
private static final String FIXED_IP_ADDRESS = "fixed_ip_address";
private static final String FLOATING_IP_ADDRESS = "floating_ip_address";
private static final String TENANT_ID = "tenant_id";
private static final String STATUS = "status";
private static final String PORT_ID = "port_id";
private static final String ID = "id";
/**
* Decodes the OpenstackFloatingIP.
*
* @param json JSON to decode
* @param context decoding context
* @return OpenstackFloatingIP
*/
@Override
public OpenstackFloatingIP decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode floatingIpInfo = json.get(FLOATINGIP);
if (floatingIpInfo == null) {
floatingIpInfo = json;
}
String networkId = floatingIpInfo.path(FLOATING_NETWORK_ID).asText();
String routerId = floatingIpInfo.path(ROUTER_ID).asText();
String fixedIpAddressStr = floatingIpInfo.path(FIXED_IP_ADDRESS).asText();
String floatingIpAddressStr = floatingIpInfo.path(FLOATING_IP_ADDRESS).asText();
String tenantId = floatingIpInfo.path(TENANT_ID).asText();
String statusStr = floatingIpInfo.path(STATUS).asText();
String portId = floatingIpInfo.path(PORT_ID).asText();
String id = floatingIpInfo.path(ID).asText();
checkNotNull(networkId);
checkNotNull(floatingIpAddressStr);
checkNotNull(tenantId);
checkNotNull(statusStr);
checkNotNull(id);
if (routerId != null && routerId.equals("null")) {
routerId = null;
}
Ip4Address fixedIpAddress = null;
if (fixedIpAddressStr != null && !fixedIpAddressStr.equals("null")) {
fixedIpAddress = Ip4Address.valueOf(fixedIpAddressStr);
}
Ip4Address floatingIpAddress = Ip4Address.valueOf(floatingIpAddressStr);
OpenstackFloatingIP.FloatingIpStatus status =
OpenstackFloatingIP.FloatingIpStatus.valueOf(statusStr);
if (portId != null && portId.equals("null")) {
portId = null;
}
OpenstackFloatingIP.Builder osFloatingIpBuilder =
new OpenstackFloatingIP.Builder();
return osFloatingIpBuilder.networkId(networkId)
.routerId(routerId)
.fixedIpAddress(fixedIpAddress)
.floatingIpAddress(floatingIpAddress)
.tenantId(tenantId)
.status(status)
.portId(portId)
.id(id)
.build();
}
}

View File

@ -1,76 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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.openstackinterface.OpenstackNetwork;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Implementation of the OpenstackNetwork Codec.
*
*/
public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
private final Logger log = LoggerFactory.getLogger(getClass());
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()) {
log.debug("Network {} has no network type, ignore it.", name);
return null;
}
String networkType = networkInfo.path(NETWORK_TYPE).asText();
try {
onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkType.toUpperCase()));
} catch (IllegalArgumentException e) {
log.debug("Network {} has unsupported network type {}, ignore it.",
name, networkType);
return null;
}
onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
return onb.build();
}
}

View File

@ -1,130 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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 com.google.common.collect.Maps;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.openstackinterface.OpenstackPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Encodes and decodes the OpenstackPort.
*/
public class OpenstackPortCodec extends JsonCodec<OpenstackPort> {
private final Logger log = LoggerFactory.getLogger(getClass());
// 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";
private static final String NA = "N/A";
@Override
public OpenstackPort decode(ObjectNode json, CodecContext context) {
checkNotNull(json);
Map<String, Ip4Address> fixedIpMap = Maps.newHashMap();
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 (!fixedIpInfo.path(IP_ADDRESS).isMissingNode() && ipAddressStr != null) {
Ip4Address ipAddress = Ip4Address.valueOf(ipAddressStr);
fixedIpMap.put(subnetId, ipAddress);
}
}
String id = portInfo.path(ID).asText();
ArrayNode securityGroupList = (ArrayNode) portInfo.path(SECURITY_GROUPS);
Collection<String> securityGroupIdList = Lists.newArrayList();
securityGroupList.forEach(securityGroup -> securityGroupIdList.add(securityGroup.asText()));
String deviceId = portInfo.path(DEVICE_ID).asText();
Map<IpAddress, MacAddress> addressPairs = Maps.newHashMap();
for (JsonNode addrPair : (ArrayNode) portInfo.path(ADDRESS_PAIR)) {
try {
addressPairs.put(IpAddress.valueOf(addrPair.path(IP_ADDRESS).asText()),
MacAddress.valueOf(addrPair.path(MAC_ADDRESS).asText()));
} catch (IllegalArgumentException e) {
log.debug("Invalid address pair {}", addrPair.toString());
}
}
OpenstackPort.Builder openstackPortBuilder = OpenstackPort.builder();
OpenstackPort.PortStatus portStatus =
status.equals(NA) ? OpenstackPort.PortStatus.NA :
OpenstackPort.PortStatus.valueOf(status);
openstackPortBuilder.portStatus(portStatus)
.name(name)
.adminState(adminStateUp)
.netwrokId(networkId)
.tenantId(tenantId)
.deviceOwner(deviceOwner)
.macAddress(MacAddress.valueOf(macStr))
.fixedIps(fixedIpMap)
.id(id)
.deviceId(deviceId)
.securityGroup(securityGroupIdList);
if (!addressPairs.isEmpty()) {
openstackPortBuilder.allowedAddressPairs(addressPairs);
}
OpenstackPort openstackPort = openstackPortBuilder.build();
return openstackPort;
}
}

View File

@ -1,106 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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.Maps;
import org.onlab.packet.Ip4Address;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.openstackinterface.OpenstackExternalGateway;
import org.onosproject.openstackinterface.OpenstackRouter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
/**
* Implementation of the OpenstackRouter Codec.
*/
public class OpenstackRouterCodec extends JsonCodec<OpenstackRouter> {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String ROUTER = "router";
private static final String TENANT_ID = "tenant_id";
private static final String NETWORK_ID = "network_id";
private static final String ID = "id";
private static final String NAME = "name";
private static final String STATUS = "status";
private static final String ADMIN_STATE_UP = "admin_state_up";
private static final String EXTERNAL_GW_INFO = "external_gateway_info";
private static final String EXTERNAL_FIXED_IPS = "external_fixed_ips";
private static final String SUBNET_ID = "subnet_id";
private static final String IP_ADDRESS = "ip_address";
/**
* Decodes the OpenstackRouter.
*
* @param json JSON to decode
* @param context decoding context
* @return OpenstackRouter
*/
@Override
public OpenstackRouter decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode routerInfo = json.get(ROUTER);
if (routerInfo == null) {
routerInfo = json;
}
String tenantId = checkNotNull(routerInfo.path(TENANT_ID).asText());
String id = checkNotNull(routerInfo.path(ID).asText());
String name = checkNotNull(routerInfo.path(NAME).asText());
String adminStateUp = checkNotNull(routerInfo.path(ADMIN_STATE_UP).asText());
OpenstackExternalGateway.Builder osExtBuiler = new OpenstackExternalGateway.Builder();
if (!routerInfo.path(EXTERNAL_GW_INFO).isMissingNode()) {
String externalGatewayNetId = checkNotNull(routerInfo.path(EXTERNAL_GW_INFO).path(NETWORK_ID).asText());
Map<String, Ip4Address> fixedIpMap = Maps.newHashMap();
if (!routerInfo.path(EXTERNAL_GW_INFO).path(EXTERNAL_FIXED_IPS).isMissingNode()) {
ArrayNode fixedIpList = (ArrayNode) routerInfo.path(EXTERNAL_GW_INFO).path(EXTERNAL_FIXED_IPS);
for (JsonNode fixedIpInfo : fixedIpList) {
String subnetId = checkNotNull(fixedIpInfo.path(SUBNET_ID).asText());
String ipAddressStr = checkNotNull(fixedIpInfo.path(IP_ADDRESS).asText());
if (!fixedIpInfo.path(IP_ADDRESS).isMissingNode() && ipAddressStr != null) {
fixedIpMap.put(subnetId, Ip4Address.valueOf(ipAddressStr));
}
}
}
osExtBuiler.networkId(externalGatewayNetId)
.enablePnat(true)
.externalFixedIps(fixedIpMap);
}
OpenstackRouter.Builder osBuilder = new OpenstackRouter.Builder()
.tenantId(tenantId)
.id(id)
.name(name)
.status(OpenstackRouter.RouterStatus.ACTIVE)
.adminStateUp(Boolean.valueOf(adminStateUp))
.gatewayExternalInfo(osExtBuiler.build());
return osBuilder.build();
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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.openstackinterface.OpenstackRouterInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of the OpenstackRouterInterface Codec.
*/
public class OpenstackRouterInterfaceCodec extends JsonCodec<OpenstackRouterInterface> {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String ID = "id";
private static final String TENANT_ID = "tenant_id";
private static final String SUBNET_ID = "subnet_id";
private static final String PORT_ID = "port_id";
/**
* Decodes the OpenstackRouterInterface.
*
* @param json JSON to decode
* @param context decoding context
* @return OpenstackRouterInterface
*/
@Override
public OpenstackRouterInterface decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode routerIfInfo = json;
String id = checkNotNull(routerIfInfo.path(ID).asText());
String tenantId = checkNotNull(routerIfInfo.path(TENANT_ID).asText());
String subnetId = checkNotNull(routerIfInfo.path(SUBNET_ID).asText());
String portId = checkNotNull(routerIfInfo.path(PORT_ID).asText());
OpenstackRouterInterface.Builder osBuilder = new OpenstackRouterInterface.Builder()
.id(id)
.tenantId(tenantId)
.subnetId(subnetId)
.portId(portId);
return osBuilder.build();
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.openstackinterface.OpenstackSecurityGroup;
import org.onosproject.openstackinterface.OpenstackSecurityGroupRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
/**
* Encodes and decodes the Openstack Security Group.
*/
public class OpenstackSecurityGroupCodec extends JsonCodec<OpenstackSecurityGroup> {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String SECURITY_GROUP = "security_group";
private static final String DESCRIPTION = "description";
private static final String ID = "id";
private static final String NAME = "name";
private static final String SECURITY_GROUP_RULES = "security_group_rules";
private static final String DIRECTION = "direction";
private static final String EHTERTYPE = "ethertype";
private static final String PORT_RANGE_MAX = "port_range_max";
private static final String PORT_RANGE_MIN = "port_range_min";
private static final String PROTOCOL = "protocol";
private static final String REMOTE_GROUP_ID = "remote_group_id";
private static final String REMOTE_IP_PREFIX = "remote_ip_prefix";
private static final String SECURITY_GROUP_ID = "security_group_id";
private static final String TENANT_ID = "tenant_id";
@Override
public OpenstackSecurityGroup decode(ObjectNode json, CodecContext context) {
JsonNode securityGroupNode = json.get(SECURITY_GROUP);
if (securityGroupNode == null) {
log.warn("SecurityGroup Json data is null");
return null;
}
String description = securityGroupNode.path(DESCRIPTION).asText();
String id = securityGroupNode.path(ID).asText();
String name = securityGroupNode.path(NAME).asText();
ArrayNode ruleInfoList = (ArrayNode) securityGroupNode.path(SECURITY_GROUP_RULES);
Collection<OpenstackSecurityGroupRule> rules = Lists.newArrayList();
for (JsonNode ruleInfo: ruleInfoList) {
OpenstackSecurityGroupRule openstackSecurityGroupRule =
new OpenstackSecurityGroupRule.Builder()
.direction(ruleInfo.path(DIRECTION).asText())
.etherType(ruleInfo.path(EHTERTYPE).asText())
.id(ruleInfo.path(ID).asText())
.portRangeMax(ruleInfo.path(PORT_RANGE_MAX).asText())
.portRangeMin(ruleInfo.path(PORT_RANGE_MIN).asText())
.protocol(ruleInfo.path(PROTOCOL).asText())
.remoteGroupId(ruleInfo.path(REMOTE_GROUP_ID).asText())
.remoteIpPrefix(ruleInfo.path(REMOTE_IP_PREFIX).asText())
.securityGroupId(ruleInfo.path(SECURITY_GROUP_ID).asText())
.tenantId(ruleInfo.path(TENANT_ID).asText())
.build();
rules.add(openstackSecurityGroupRule);
}
String tenantId = securityGroupNode.path(TENANT_ID).asText();
OpenstackSecurityGroup openstackSecurityGroup = OpenstackSecurityGroup.builder()
.description(description)
.id(id)
.name(name)
.rules(rules)
.tenantId(tenantId)
.build();
return openstackSecurityGroup;
}
}

View File

@ -1,85 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.openstackinterface.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.openstackinterface.OpenstackSubnet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Encodes and decodes the OpenstackSubnet.
*/
public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
private final Logger log = LoggerFactory.getLogger(getClass());
// 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) {
checkNotNull(json);
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;
}
}

View File

@ -1,20 +0,0 @@
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* OpenStack networking implementation.
*/
package org.onosproject.openstackinterface.web;

View File

@ -1,12 +0,0 @@
{
"apps" : {
"org.onosproject.openstackinterface" : {
"openstackinterface" : {
"neutron_server" : "http://10.40.101.209:9696/v2.0/",
"keystone_server" : "http://10.40.101.209:5000/v2.0/",
"user_name" : "admin",
"password" : "nova"
}
}
}
}

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-apps</artifactId>
<version>1.10.0-SNAPSHOT</version>
</parent>
<artifactId>onos-app-openstackinterface</artifactId>
<packaging>pom</packaging>
<modules>
<module>api</module>
<module>app</module>
</modules>
</project>

View File

@ -69,7 +69,6 @@
<module>vpls</module>
<module>openstacknode</module>
<module>openstacknetworking</module>
<module>openstackinterface</module>
<module>influxdbmetrics</module>
<module>gangliametrics</module>
<module>graphitemetrics</module>

View File

@ -143,7 +143,6 @@ ONOS_APPS = [
'//apps/metrics:onos-apps-metrics-oar',
'//apps/mfwd:onos-apps-mfwd-oar',
'//apps/mlb:onos-apps-mlb-oar',
'//apps/openstackinterface:onos-apps-openstackinterface-oar',
'//apps/openstacknetworking:onos-apps-openstacknetworking-oar',
'//apps/mobility:onos-apps-mobility-oar',
'//apps/optical:onos-apps-optical-oar',