mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 02:11:38 +02:00
Removed unused xosclient application
Change-Id: I630e8dbf9068d1b6e1d9ac72484f1aa58d39937e
This commit is contained in:
parent
2d54a36508
commit
cadc37c17e
@ -73,7 +73,6 @@
|
||||
<module>influxdbmetrics</module>
|
||||
<module>gangliametrics</module>
|
||||
<module>graphitemetrics</module>
|
||||
<module>xosclient</module>
|
||||
<module>scalablegateway</module>
|
||||
<module>bmv2-demo</module>
|
||||
<module>yms</module>
|
||||
|
@ -1,19 +0,0 @@
|
||||
COMPILE_DEPS = [
|
||||
'//lib:CORE_DEPS',
|
||||
'//lib:javax.ws.rs-api',
|
||||
'//lib:openstack4j-core',
|
||||
'//lib:openstack4j-http-connector',
|
||||
'//lib:openstack4j-httpclient',
|
||||
'//lib:jersey-client',
|
||||
]
|
||||
|
||||
osgi_jar_with_tests (
|
||||
deps = COMPILE_DEPS,
|
||||
)
|
||||
|
||||
onos_app (
|
||||
title = 'XOS Client App',
|
||||
category = 'Utility',
|
||||
url = 'http://onosproject.org',
|
||||
description = 'XOS client service',
|
||||
)
|
@ -1,95 +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>
|
||||
<artifactId>onos-apps</artifactId>
|
||||
<groupId>org.onosproject</groupId>
|
||||
<version>1.10.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>onos-app-xos-client</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<description>XOS client service</description>
|
||||
|
||||
<properties>
|
||||
<onos.app.name>org.onosproject.xosclient</onos.app.name>
|
||||
<onos.app.title>XOS Client App</onos.app.title>
|
||||
<onos.app.category>Utility</onos.app.category>
|
||||
<onos.app.url>http://onosproject.org</onos.app.url>
|
||||
<onos.app.readme>XOS Client Application.</onos.app.readme>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.compendium</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.onosproject</groupId>
|
||||
<artifactId>onlab-misc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pacesys</groupId>
|
||||
<artifactId>openstack4j-core</artifactId>
|
||||
<version>2.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pacesys.openstack4j.connectors</groupId>
|
||||
<artifactId>openstack4j-http-connector</artifactId>
|
||||
<version>2.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pacesys.openstack4j.connectors</groupId>
|
||||
<artifactId>openstack4j-httpclient</artifactId>
|
||||
<version>2.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>
|
||||
!org.apache.http.*,
|
||||
!com.fasterxml.jackson.dataformat.*,
|
||||
!javax.annotation,*
|
||||
</Import-Package>
|
||||
<Embed-Dependency>
|
||||
openstack4j-core,
|
||||
openstack4j-http-connector,
|
||||
openstack4j-httpclient
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,115 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Object holding OpenStack API access information.
|
||||
*/
|
||||
// TODO remove this when XOS provides this information
|
||||
public class OpenStackAccess {
|
||||
|
||||
private final String endpoint;
|
||||
private final String tenant;
|
||||
private final String user;
|
||||
private final String password;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param endpoint Keystone endpoint
|
||||
* @param tenant tenant name
|
||||
* @param user user name
|
||||
* @param password password
|
||||
*/
|
||||
public OpenStackAccess(String endpoint, String tenant, String user, String password) {
|
||||
this.endpoint = endpoint;
|
||||
this.tenant = tenant;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns OpenStack API endpoint.
|
||||
*
|
||||
* @return endpoint
|
||||
*/
|
||||
public String endpoint() {
|
||||
return this.endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns OpenStack tenant name.
|
||||
*
|
||||
* @return tenant name
|
||||
*/
|
||||
public String tenant() {
|
||||
return this.tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns OpenStack user.
|
||||
*
|
||||
* @return user name
|
||||
*/
|
||||
public String user() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns OpenStack password for the user.
|
||||
*
|
||||
* @return password
|
||||
*/
|
||||
public String password() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(endpoint, tenant, user, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if ((obj instanceof OpenStackAccess)) {
|
||||
OpenStackAccess that = (OpenStackAccess) obj;
|
||||
if (Objects.equals(endpoint, that.endpoint) &&
|
||||
Objects.equals(tenant, that.tenant) &&
|
||||
Objects.equals(user, that.user) &&
|
||||
Objects.equals(password, that.password)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(getClass())
|
||||
.add("endpoint", endpoint)
|
||||
.add("tenant", tenant)
|
||||
.add("user", user)
|
||||
.add("password", password)
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -1,295 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onlab.packet.MacAddress;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Representation of port in a CORD VTN controlled network, it can be for VM
|
||||
* or container.
|
||||
*/
|
||||
public final class VtnPort {
|
||||
|
||||
private final VtnPortId id;
|
||||
private final String name;
|
||||
private final VtnServiceId serviceId;
|
||||
private final MacAddress mac;
|
||||
private final IpAddress ip;
|
||||
// TODO remove this when XOS provides vSG information
|
||||
private final Map<IpAddress, MacAddress> addressPairs;
|
||||
|
||||
private VtnPort(VtnPortId id,
|
||||
String name,
|
||||
VtnServiceId serviceId,
|
||||
MacAddress mac,
|
||||
IpAddress ip,
|
||||
Map<IpAddress, MacAddress> addressPairs) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.serviceId = serviceId;
|
||||
this.mac = mac;
|
||||
this.ip = ip;
|
||||
this.addressPairs = addressPairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns vtn port ID.
|
||||
*
|
||||
* @return vtn port id
|
||||
*/
|
||||
public VtnPortId id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns vtn port name.
|
||||
*
|
||||
* @return vtn port name
|
||||
*/
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the service this port is in.
|
||||
*
|
||||
* @return vtn service id
|
||||
*/
|
||||
public VtnServiceId serviceId() {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns MAC address of this port.
|
||||
*
|
||||
* @return mac address
|
||||
*/
|
||||
public MacAddress mac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IP address of this port.
|
||||
*
|
||||
* @return ip address
|
||||
*/
|
||||
public IpAddress ip() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns address pairs of the nested containers inside.
|
||||
*
|
||||
* @return map of ip and address
|
||||
*/
|
||||
public Map<IpAddress, MacAddress> addressPairs() {
|
||||
return addressPairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof VtnPort)) {
|
||||
return false;
|
||||
}
|
||||
final VtnPort other = (VtnPort) obj;
|
||||
return Objects.equals(this.id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("id", id)
|
||||
.add("name", name)
|
||||
.add("serviceId", serviceId)
|
||||
.add("mac", mac)
|
||||
.add("ip", ip)
|
||||
.add("addressPairs", addressPairs)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new vtn port builder instance.
|
||||
*
|
||||
* @return new vtn port builder
|
||||
*/
|
||||
public static final Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder of VTN port entities.
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
private VtnPortId id;
|
||||
private String name;
|
||||
private VtnServiceId serviceId;
|
||||
private MacAddress mac;
|
||||
private IpAddress ip;
|
||||
// TODO remove this when XOS provides vSG information
|
||||
private Map<IpAddress, MacAddress> addressPairs;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an immutable VTN port.
|
||||
*
|
||||
* @return vtn port instance
|
||||
*/
|
||||
public VtnPort build() {
|
||||
checkNotNull(id, "VTN port ID cannot be null");
|
||||
checkNotNull(serviceId, "VTN port service ID cannot be null");
|
||||
checkNotNull(mac, "VTN port MAC address cannot be null");
|
||||
checkNotNull(ip, "VTN port IP address cannot be null");
|
||||
addressPairs = addressPairs == null ? ImmutableMap.of() : addressPairs;
|
||||
|
||||
return new VtnPort(id,
|
||||
name,
|
||||
serviceId,
|
||||
mac,
|
||||
ip,
|
||||
addressPairs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied port ID.
|
||||
*
|
||||
* @param id port identifier
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder id(VtnPortId id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied port name.
|
||||
* Port name can be null.
|
||||
*
|
||||
* @param name port name
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied service ID.
|
||||
*
|
||||
* @param serviceId vtn port service id
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder serviceId(VtnServiceId serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied MAC address.
|
||||
*
|
||||
* @param mac mac address
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder mac(MacAddress mac) {
|
||||
if (mac == null) {
|
||||
final String msg = "VTN port MAC address cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.mac = mac;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied MAC address.
|
||||
*
|
||||
* @param mac mac address as a string
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder mac(String mac) {
|
||||
try {
|
||||
return mac(MacAddress.valueOf(mac));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
final String msg = "Malformed MAC address string " + mac +
|
||||
" for VTN port MAC address";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied IP address.
|
||||
*
|
||||
* @param ip ip address
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder ip(IpAddress ip) {
|
||||
if (ip == null) {
|
||||
final String msg = "VTN port IP address cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied IP address.
|
||||
*
|
||||
* @param ip ip address as a string
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder ip(String ip) {
|
||||
try {
|
||||
return ip(IpAddress.valueOf(ip));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
final String msg = "Malformed IP address string " + ip +
|
||||
" for VTN port IP address";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN port builder with the supplied address pairs.
|
||||
*
|
||||
* @param addressPairs address pairs
|
||||
* @return vtn port builder
|
||||
*/
|
||||
public Builder addressPairs(Map<IpAddress, MacAddress> addressPairs) {
|
||||
if (addressPairs == null) {
|
||||
final String msg = "VTN address pairs cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.addressPairs = addressPairs;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,67 +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.xosclient.api;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service for interacting with XOS VTN ports.
|
||||
*/
|
||||
public interface VtnPortApi {
|
||||
|
||||
/**
|
||||
* Returns all ports.
|
||||
*
|
||||
* @return set of ports
|
||||
*/
|
||||
Set<VtnPort> vtnPorts();
|
||||
|
||||
/**
|
||||
* Returns all ports with a given service.
|
||||
*
|
||||
* @param serviceId service id
|
||||
* @return set of ports
|
||||
*/
|
||||
Set<VtnPort> vtnPorts(VtnServiceId serviceId);
|
||||
|
||||
/**
|
||||
* Returns port information with port id.
|
||||
*
|
||||
* @param portId port id
|
||||
* @return vtn port; null if it fails to get port information
|
||||
*/
|
||||
VtnPort vtnPort(VtnPortId portId);
|
||||
|
||||
/**
|
||||
* Returns port information from OpenStack with port id.
|
||||
*
|
||||
* @param portId port id
|
||||
* @param osAccess OpenStack address for OS access
|
||||
* @return vtn port; null if it fails to get port information
|
||||
*/
|
||||
// TODO remove this when XOS provides port information
|
||||
VtnPort vtnPort(VtnPortId portId, OpenStackAccess osAccess);
|
||||
|
||||
/**
|
||||
* Returns port information from OpenStack with port name.
|
||||
*
|
||||
* @param portName port name
|
||||
* @param osAccess OpenStack address for OS access
|
||||
* @return vtn port; null if it fails to get port information
|
||||
*/
|
||||
// TODO remove this when XOS provides port information
|
||||
VtnPort vtnPort(String portName, OpenStackAccess osAccess);
|
||||
}
|
@ -1,42 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.onlab.util.Identifier;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Representation of VTN port ID.
|
||||
*/
|
||||
public final class VtnPortId extends Identifier<String> {
|
||||
|
||||
private VtnPortId(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns vtn port identifier with value.
|
||||
*
|
||||
* @param id id
|
||||
* @return instance port id
|
||||
*/
|
||||
public static VtnPortId of(String id) {
|
||||
checkArgument(!Strings.isNullOrEmpty(id), "VTN port ID cannot be null");
|
||||
return new VtnPortId(id);
|
||||
}
|
||||
}
|
@ -1,406 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onlab.packet.IpPrefix;
|
||||
import org.onosproject.xosclient.api.VtnServiceApi.NetworkType;
|
||||
import org.onosproject.xosclient.api.VtnServiceApi.ServiceType;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Representation of CORD VTN controlled network service.
|
||||
*/
|
||||
public final class VtnService {
|
||||
|
||||
private final VtnServiceId id;
|
||||
private final String name;
|
||||
private final ServiceType serviceType;
|
||||
private final NetworkType networkType;
|
||||
private final long vni;
|
||||
private final IpPrefix subnet;
|
||||
private final IpAddress serviceIp;
|
||||
private final Set<VtnServiceId> providerServices;
|
||||
private final Set<VtnServiceId> tenantServices;
|
||||
|
||||
private VtnService(VtnServiceId id,
|
||||
String name,
|
||||
ServiceType serviceType,
|
||||
NetworkType networkType,
|
||||
long vni,
|
||||
IpPrefix subnet,
|
||||
IpAddress serviceIp,
|
||||
Set<VtnServiceId> providerServices,
|
||||
Set<VtnServiceId> tenantServices) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.serviceType = serviceType;
|
||||
this.networkType = networkType;
|
||||
this.vni = vni;
|
||||
this.subnet = subnet;
|
||||
this.serviceIp = serviceIp;
|
||||
this.providerServices = providerServices;
|
||||
this.tenantServices = tenantServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service ID.
|
||||
*
|
||||
* @return service id
|
||||
*/
|
||||
public VtnServiceId id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service name.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service type.
|
||||
*
|
||||
* @return service type
|
||||
*/
|
||||
public ServiceType serviceType() {
|
||||
return serviceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns segmentation ID of this service.
|
||||
*
|
||||
* @return segmentation id
|
||||
*/
|
||||
public long vni() {
|
||||
return vni;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns network type.
|
||||
*
|
||||
* @return network type
|
||||
*/
|
||||
public NetworkType networkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service IP range.
|
||||
*
|
||||
* @return subnet cidr
|
||||
*/
|
||||
public IpPrefix subnet() {
|
||||
return subnet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service IP address.
|
||||
*
|
||||
* @return ip address
|
||||
*/
|
||||
public IpAddress serviceIp() {
|
||||
return serviceIp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns provider service IDs.
|
||||
*
|
||||
* @return list of provider service id
|
||||
*/
|
||||
public Set<VtnServiceId> providerServices() {
|
||||
return providerServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns tenant service IDs.
|
||||
*
|
||||
* @return list of tenant service id
|
||||
*/
|
||||
public Set<VtnServiceId> tenantServices() {
|
||||
return tenantServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof VtnService)) {
|
||||
return false;
|
||||
}
|
||||
final VtnService other = (VtnService) obj;
|
||||
return Objects.equals(this.id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("id", id)
|
||||
.add("name", name)
|
||||
.add("serviceType", serviceType)
|
||||
.add("networkType", networkType)
|
||||
.add("vni", vni)
|
||||
.add("subnet", subnet)
|
||||
.add("serviceIp", serviceIp)
|
||||
.add("providerServices", providerServices)
|
||||
.add("tenantServices", tenantServices)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new builder instance.
|
||||
*
|
||||
* @return new builder
|
||||
*/
|
||||
public static final Builder build() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder of VTN service entities.
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
private VtnServiceId id;
|
||||
private String name;
|
||||
private ServiceType serviceType;
|
||||
private NetworkType networkType;
|
||||
private long vni = -1;
|
||||
private IpPrefix subnet;
|
||||
private IpAddress serviceIp;
|
||||
private Set<VtnServiceId> providerServices;
|
||||
private Set<VtnServiceId> tenantServices;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an immutable VTN service.
|
||||
*
|
||||
* @return vtn service instance
|
||||
*/
|
||||
public VtnService build() {
|
||||
checkNotNull(id, "VTN service ID cannot be null");
|
||||
checkArgument(!Strings.isNullOrEmpty(name), "VTN service name cannot be null");
|
||||
checkNotNull(serviceType, "VTN service type cannot be null");
|
||||
checkNotNull(networkType, "VTN network type cannot be null");
|
||||
checkArgument(vni > 0, "VTN network VNI is not set");
|
||||
checkNotNull(subnet, "VTN subnet cannot be null");
|
||||
checkNotNull(serviceIp, "VTN service IP cannot be null");
|
||||
|
||||
providerServices = providerServices == null ? ImmutableSet.of() : providerServices;
|
||||
tenantServices = tenantServices == null ? ImmutableSet.of() : tenantServices;
|
||||
|
||||
return new VtnService(id,
|
||||
name,
|
||||
serviceType,
|
||||
networkType,
|
||||
vni,
|
||||
subnet,
|
||||
serviceIp,
|
||||
providerServices,
|
||||
tenantServices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied service ID.
|
||||
*
|
||||
* @param id service identifier
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder id(VtnServiceId id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied service name.
|
||||
*
|
||||
* @param name service name
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
final String msg = "VTN service name cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied service type.
|
||||
*
|
||||
* @param serviceType service type
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder serviceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied network type.
|
||||
*
|
||||
* @param networkType network type
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder networkType(NetworkType networkType) {
|
||||
this.networkType = networkType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied VNI.
|
||||
*
|
||||
* @param vni vni of the service network
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder vni(long vni) {
|
||||
if (vni < 0 || vni > 16777215) {
|
||||
final String msg = "VNI " + vni + " is out of range";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.vni = vni;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied VNI.
|
||||
*
|
||||
* @param vni vni of the service network as a string
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder vni(String vni) {
|
||||
try {
|
||||
return vni(Long.parseLong(vni));
|
||||
} catch (NumberFormatException | NullPointerException e) {
|
||||
final String msg = "Malformed number string " + vni +
|
||||
" for VTN network VNI";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied subnet.
|
||||
*
|
||||
* @param subnet subnet of the service network
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder subnet(IpPrefix subnet) {
|
||||
if (subnet == null) {
|
||||
final String msg = "VTN service subnet is null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.subnet = subnet;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied subnet.
|
||||
*
|
||||
* @param subnet subnet of the service network as a string
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder subnet(String subnet) {
|
||||
try {
|
||||
return subnet(IpPrefix.valueOf(subnet));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
final String msg = "Malformed IP prefix string " + subnet +
|
||||
" for VTN service subnet";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied service IP address.
|
||||
*
|
||||
* @param serviceIp service ip address
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder serviceIp(IpAddress serviceIp) {
|
||||
if (serviceIp == null) {
|
||||
final String msg = "VTN service IP cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.serviceIp = serviceIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied service IP address.
|
||||
*
|
||||
* @param serviceIp service ip address as a string
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder serviceIp(String serviceIp) {
|
||||
try {
|
||||
return serviceIp(IpAddress.valueOf(serviceIp));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
final String msg = "Malformed IP address string " + serviceIp +
|
||||
" for VTN service IP address";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied provider services.
|
||||
*
|
||||
* @param pServices provider services
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder providerServices(Set<VtnServiceId> pServices) {
|
||||
if (pServices == null) {
|
||||
final String msg = "Provider services cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.providerServices = pServices;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns VTN service builder with the supplied tenant services.
|
||||
*
|
||||
* @param tServices tenant services
|
||||
* @return vtn service builder
|
||||
*/
|
||||
public Builder tenantServices(Set<VtnServiceId> tServices) {
|
||||
if (tServices == null) {
|
||||
final String msg = "Tenant services cannot be null";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.tenantServices = tServices;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,80 +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.xosclient.api;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service for interacting with XOS VTN service and service dependency.
|
||||
*/
|
||||
public interface VtnServiceApi {
|
||||
|
||||
// TODO move network type to VtnNetwork later
|
||||
enum NetworkType {
|
||||
PRIVATE,
|
||||
PUBLIC,
|
||||
MANAGEMENT_HOSTS,
|
||||
MANAGEMENT_LOCAL
|
||||
}
|
||||
|
||||
enum ServiceType {
|
||||
VSG,
|
||||
ACCESS_AGENT,
|
||||
MANAGEMENT,
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all services list.
|
||||
*
|
||||
* @return service list
|
||||
*/
|
||||
Set<VtnServiceId> services();
|
||||
|
||||
/**
|
||||
* Returns VTN service.
|
||||
*
|
||||
* @param serviceId service id
|
||||
* @return vtn service
|
||||
*/
|
||||
VtnService service(VtnServiceId serviceId);
|
||||
|
||||
/**
|
||||
* Returns dependent tenant services of a given provider service.
|
||||
*
|
||||
* @param pServiceId vtn service id
|
||||
* @return set of service ids
|
||||
*/
|
||||
Set<VtnServiceId> tenantServices(VtnServiceId pServiceId);
|
||||
|
||||
/**
|
||||
* Returns dependent provider services of a given tenant service.
|
||||
*
|
||||
* @param tServiceId vtn service id
|
||||
* @return set of service ids
|
||||
*/
|
||||
Set<VtnServiceId> providerServices(VtnServiceId tServiceId);
|
||||
|
||||
/**
|
||||
* Returns VTN service from OpenStack.
|
||||
*
|
||||
* @param serviceId service id
|
||||
* @param osAccess openstack access
|
||||
* @return vtn service
|
||||
*/
|
||||
// TODO remove this when XOS provides service information
|
||||
VtnService service(VtnServiceId serviceId, OpenStackAccess osAccess);
|
||||
}
|
@ -1,46 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.onlab.util.Identifier;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Representation of VTN service identifier.
|
||||
*/
|
||||
public final class VtnServiceId extends Identifier<String> {
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param id service identifier
|
||||
*/
|
||||
private VtnServiceId(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the VtnServiceId with value.
|
||||
*
|
||||
* @param id service id
|
||||
* @return CordServiceId
|
||||
*/
|
||||
public static VtnServiceId of(String id) {
|
||||
checkArgument(!Strings.isNullOrEmpty(id), "VTN service ID cannot be null");
|
||||
return new VtnServiceId(id);
|
||||
}
|
||||
}
|
@ -1,104 +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.xosclient.api;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Objects holding XOS API access information.
|
||||
*/
|
||||
public class XosAccess {
|
||||
|
||||
private final String endpoint;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param endpoint XOS service endpoint
|
||||
* @param adminUser admin user name
|
||||
* @param adminPassword admin password
|
||||
*/
|
||||
public XosAccess(String endpoint, String adminUser, String adminPassword) {
|
||||
this.endpoint = checkNotNull(endpoint);
|
||||
this.username = checkNotNull(adminUser);
|
||||
this.password = checkNotNull(adminPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XOS service endpoint.
|
||||
*
|
||||
* @return endpoint
|
||||
*/
|
||||
public String endpoint() {
|
||||
return this.endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns admin user name.
|
||||
*
|
||||
* @return user name
|
||||
*/
|
||||
public String username() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns admin password.
|
||||
*
|
||||
* @return password
|
||||
*/
|
||||
public String password() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(endpoint, username, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((obj instanceof XosAccess)) {
|
||||
XosAccess that = (XosAccess) obj;
|
||||
if (Objects.equals(endpoint, that.endpoint) &&
|
||||
Objects.equals(username, that.username) &&
|
||||
Objects.equals(password, that.password)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(getClass())
|
||||
.add("endpoint", endpoint)
|
||||
.add("username", username)
|
||||
.add("password", password)
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -1,69 +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.xosclient.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.onosproject.core.ApplicationId;
|
||||
import org.onosproject.net.config.Config;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
/**
|
||||
* XOS API access information.
|
||||
*/
|
||||
public class XosAccessConfig extends Config<ApplicationId> {
|
||||
|
||||
protected final Logger log = getLogger(getClass());
|
||||
|
||||
private static final String XOS_SERVICE_ENDPOINT = "serviceEndpoint";
|
||||
private static final String XOS_ADMIN_USER = "adminUser";
|
||||
private static final String XOS_ADMIN_PASSWORD = "adminPassword";
|
||||
|
||||
/**
|
||||
* Returns XOS access information.
|
||||
*
|
||||
* @return XOS access, or null
|
||||
*/
|
||||
public XosAccess xosAccess() {
|
||||
try {
|
||||
return new XosAccess(getConfig(object, XOS_SERVICE_ENDPOINT),
|
||||
getConfig(object, XOS_ADMIN_USER),
|
||||
getConfig(object, XOS_ADMIN_PASSWORD));
|
||||
} catch (NullPointerException e) {
|
||||
log.error("Failed to get XOS access");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of a given path. If the path is missing, show log and return
|
||||
* null.
|
||||
*
|
||||
* @param path path
|
||||
* @return value or null
|
||||
*/
|
||||
private String getConfig(JsonNode jsonNode, String path) {
|
||||
jsonNode = jsonNode.path(path);
|
||||
|
||||
if (jsonNode.isMissingNode()) {
|
||||
log.error("{} is not configured", path);
|
||||
return null;
|
||||
} else {
|
||||
return jsonNode.asText();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +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.xosclient.api;
|
||||
|
||||
/**
|
||||
* Provides interactions with XOS.
|
||||
*/
|
||||
public interface XosClientService {
|
||||
|
||||
/**
|
||||
* Returns XOS API access information of the client.
|
||||
*
|
||||
* @return xos access
|
||||
*/
|
||||
XosAccess access();
|
||||
|
||||
/**
|
||||
* Returns XOS client with access.
|
||||
*
|
||||
* @param xosAccess xos access information
|
||||
* @return xos client; null if access fails authentication
|
||||
*/
|
||||
XosClientService getClient(XosAccess xosAccess);
|
||||
|
||||
/**
|
||||
* Returns CORD VTN service and service dependency API.
|
||||
*
|
||||
* @return cord vtn service api
|
||||
*/
|
||||
VtnServiceApi vtnService();
|
||||
|
||||
/**
|
||||
* Returns CORD VTN port API.
|
||||
*
|
||||
* @return cord vtn port api
|
||||
*/
|
||||
VtnPortApi vtnPort();
|
||||
|
||||
/*
|
||||
* adds more XOS service APIs below.
|
||||
*/
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* XOS client application API.
|
||||
*/
|
||||
package org.onosproject.xosclient.api;
|
@ -1,149 +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.xosclient.impl;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onlab.packet.MacAddress;
|
||||
import org.onosproject.xosclient.api.OpenStackAccess;
|
||||
import org.onosproject.xosclient.api.VtnPort;
|
||||
import org.onosproject.xosclient.api.VtnPortApi;
|
||||
import org.onosproject.xosclient.api.VtnPortId;
|
||||
import org.onosproject.xosclient.api.VtnServiceId;
|
||||
import org.onosproject.xosclient.api.XosAccess;
|
||||
import org.openstack4j.api.OSClient;
|
||||
import org.openstack4j.api.exceptions.AuthenticationException;
|
||||
import org.openstack4j.model.network.IP;
|
||||
import org.openstack4j.model.network.Port;
|
||||
import org.openstack4j.openstack.OSFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Provides CORD VTN port APIs.
|
||||
*/
|
||||
public final class DefaultVtnPortApi extends XosApi implements VtnPortApi {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param baseUrl base url
|
||||
* @param access xos access
|
||||
*/
|
||||
public DefaultVtnPortApi(String baseUrl, XosAccess access) {
|
||||
super(baseUrl, access);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<VtnPort> vtnPorts() {
|
||||
// TODO implement this when XOS provides this information
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<VtnPort> vtnPorts(VtnServiceId serviceId) {
|
||||
// TODO implement this when XOS provides this information
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VtnPort vtnPort(VtnPortId portId) {
|
||||
// TODO implement this when XOS provides this information
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO remove this when XOS provides this information
|
||||
public VtnPort vtnPort(String portName, OpenStackAccess osAccess) {
|
||||
checkNotNull(osAccess);
|
||||
|
||||
OSClient osClient = getOpenStackClient(osAccess);
|
||||
Port osPort = osClient.networking().port().list()
|
||||
.stream()
|
||||
.filter(p -> p.getId().contains(portName.substring(3)))
|
||||
.findFirst().orElse(null);
|
||||
if (osPort == null) {
|
||||
log.warn("Failed to get OpenStack port for {}", portName);
|
||||
return null;
|
||||
}
|
||||
return getVtnPort(osPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO remove this when XOS provides this information
|
||||
public VtnPort vtnPort(VtnPortId portId, OpenStackAccess osAccess) {
|
||||
checkNotNull(osAccess);
|
||||
|
||||
OSClient osClient = getOpenStackClient(osAccess);
|
||||
Port osPort = osClient.networking().port().get(portId.id());
|
||||
if (osPort == null) {
|
||||
log.warn("Failed to get OpenStack port {}", portId);
|
||||
return null;
|
||||
}
|
||||
return getVtnPort(osPort);
|
||||
}
|
||||
|
||||
// TODO remove this when XOS provides this information
|
||||
private VtnPort getVtnPort(Port osPort) {
|
||||
checkNotNull(osPort);
|
||||
|
||||
// assumes all vtn port has single IP address
|
||||
IP ipAddr = osPort.getFixedIps().stream().findFirst().orElse(null);
|
||||
if (ipAddr == null) {
|
||||
log.warn("Failed to get IP address for {}", osPort);
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<IpAddress, MacAddress> addressPairs = Maps.newHashMap();
|
||||
osPort.getAllowedAddressPairs().forEach(
|
||||
pair -> addressPairs.put(IpAddress.valueOf(pair.getIpAddress()),
|
||||
MacAddress.valueOf(pair.getMacAddress())));
|
||||
|
||||
return VtnPort.builder()
|
||||
.id(VtnPortId.of(osPort.getId()))
|
||||
.name(osPort.getName())
|
||||
.serviceId(VtnServiceId.of(osPort.getNetworkId()))
|
||||
.mac(osPort.getMacAddress())
|
||||
.ip(ipAddr.getIpAddress())
|
||||
.addressPairs(addressPairs)
|
||||
.build();
|
||||
}
|
||||
|
||||
// TODO remove this when XOS provides this information
|
||||
private OSClient getOpenStackClient(OpenStackAccess osAccess) {
|
||||
checkNotNull(osAccess);
|
||||
|
||||
// creating a client every time must be inefficient, but this method
|
||||
// will be removed once XOS provides equivalent APIs
|
||||
try {
|
||||
return OSFactory.builder()
|
||||
.endpoint(osAccess.endpoint())
|
||||
.credentials(osAccess.user(), osAccess.password())
|
||||
.tenantName(osAccess.tenant())
|
||||
.authenticate();
|
||||
} catch (AuthenticationException e) {
|
||||
log.warn("Failed to authenticate OpenStack API with {}", osAccess);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,209 +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.xosclient.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.onosproject.xosclient.api.OpenStackAccess;
|
||||
import org.onosproject.xosclient.api.VtnServiceApi;
|
||||
import org.onosproject.xosclient.api.XosAccess;
|
||||
import org.onosproject.xosclient.api.VtnService;
|
||||
import org.onosproject.xosclient.api.VtnServiceId;
|
||||
|
||||
import org.openstack4j.api.OSClient;
|
||||
import org.openstack4j.api.exceptions.AuthenticationException;
|
||||
import org.openstack4j.model.network.Network;
|
||||
import org.openstack4j.model.network.Subnet;
|
||||
import org.openstack4j.openstack.OSFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.onosproject.xosclient.api.VtnServiceApi.NetworkType.*;
|
||||
import static org.onosproject.xosclient.api.VtnServiceApi.ServiceType.*;
|
||||
|
||||
/**
|
||||
* Provides CORD VTN service and service dependency APIs.
|
||||
*/
|
||||
public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param baseUrl base url
|
||||
* @param access xos access
|
||||
*/
|
||||
public DefaultVtnServiceApi(String baseUrl, XosAccess access) {
|
||||
super(baseUrl, access);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<VtnServiceId> services() {
|
||||
String response = restGet(EMPTY_STRING);
|
||||
log.trace("Get services {}", response);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Set<VtnServiceId> services = Sets.newHashSet();
|
||||
|
||||
try {
|
||||
JsonNode nodes = mapper.readTree(response);
|
||||
nodes.fieldNames().forEachRemaining(id -> services.add(VtnServiceId.of(id)));
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to get service list");
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VtnService service(VtnServiceId serviceId) {
|
||||
// TODO implement this when XOS provides this API
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<VtnServiceId> providerServices(VtnServiceId tServiceId) {
|
||||
checkNotNull(tServiceId);
|
||||
|
||||
String response = restGet(tServiceId.id());
|
||||
log.trace("Get provider services {}", response);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Set<VtnServiceId> pServices = Sets.newHashSet();
|
||||
|
||||
try {
|
||||
JsonNode nodes = mapper.readTree(response);
|
||||
nodes.forEach(node -> pServices.add(VtnServiceId.of(node.asText())));
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to get service dependency");
|
||||
}
|
||||
return pServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<VtnServiceId> tenantServices(VtnServiceId tServiceId) {
|
||||
checkNotNull(tServiceId);
|
||||
|
||||
String response = restGet(EMPTY_STRING);
|
||||
log.trace("Get tenant services {}", response);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Set<VtnServiceId> tServices = Sets.newHashSet();
|
||||
|
||||
try {
|
||||
JsonNode nodes = mapper.readTree(response);
|
||||
nodes.fields().forEachRemaining(entry -> entry.getValue().forEach(
|
||||
pService -> {
|
||||
if (pService.asText().equals(tServiceId.id())) {
|
||||
tServices.add(VtnServiceId.of(entry.getKey()));
|
||||
}
|
||||
}));
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to get service list");
|
||||
}
|
||||
return tServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO remove this when XOS provides this information
|
||||
public VtnService service(VtnServiceId serviceId, OpenStackAccess osAccess) {
|
||||
checkNotNull(osAccess);
|
||||
|
||||
OSClient osClient = getOpenStackClient(osAccess);
|
||||
Network osNet = osClient.networking().network().get(serviceId.id());
|
||||
if (osNet == null) {
|
||||
log.warn("Failed to get OpenStack network {}", serviceId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// assumes all cord service networks has single subnet
|
||||
Subnet osSubnet = osNet.getNeutronSubnets().stream()
|
||||
.findFirst().orElse(null);
|
||||
if (osSubnet == null) {
|
||||
log.warn("Failed to get OpenStack subnet of network {}", serviceId);
|
||||
return null;
|
||||
}
|
||||
|
||||
return VtnService.build()
|
||||
.id(serviceId)
|
||||
.name(osNet.getName())
|
||||
.serviceType(serviceType(osNet.getName()))
|
||||
.networkType(networkType(osNet.getName()))
|
||||
.vni(osNet.getProviderSegID())
|
||||
.subnet(osSubnet.getCidr())
|
||||
.serviceIp(osSubnet.getGateway())
|
||||
.providerServices(providerServices(serviceId))
|
||||
.tenantServices(tenantServices(serviceId))
|
||||
.build();
|
||||
}
|
||||
|
||||
// TODO remove this when XOS provides this information
|
||||
private OSClient getOpenStackClient(OpenStackAccess osAccess) {
|
||||
checkNotNull(osAccess);
|
||||
|
||||
// creating a client every time must be inefficient, but this method
|
||||
// will be removed once XOS provides equivalent APIs
|
||||
try {
|
||||
return OSFactory.builder()
|
||||
.endpoint(osAccess.endpoint())
|
||||
.credentials(osAccess.user(), osAccess.password())
|
||||
.tenantName(osAccess.tenant())
|
||||
.authenticate();
|
||||
} catch (AuthenticationException e) {
|
||||
log.warn("Failed to authenticate OpenStack API with {}", osAccess);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove this when XOS provides this information
|
||||
private NetworkType networkType(String netName) {
|
||||
checkArgument(!Strings.isNullOrEmpty(netName), "VTN network name cannot be null");
|
||||
|
||||
String name = netName.toUpperCase();
|
||||
if (name.contains(PUBLIC.name())) {
|
||||
return PUBLIC;
|
||||
} else if (name.contains(MANAGEMENT_HOSTS.name())) {
|
||||
return MANAGEMENT_HOSTS;
|
||||
} else if (name.contains("MANAGEMENT")) {
|
||||
return MANAGEMENT_LOCAL;
|
||||
} else {
|
||||
return PRIVATE;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove this when XOS provides this information
|
||||
private ServiceType serviceType(String netName) {
|
||||
checkArgument(!Strings.isNullOrEmpty(netName), "VTN network name cannot be null");
|
||||
|
||||
String name = netName.toUpperCase();
|
||||
if (name.contains(VSG.name())) {
|
||||
return VSG;
|
||||
} else if (name.contains(ACCESS_AGENT.name())) {
|
||||
return ACCESS_AGENT;
|
||||
} else if (name.contains(ServiceType.MANAGEMENT.name())) {
|
||||
return ServiceType.MANAGEMENT;
|
||||
} else {
|
||||
return DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +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.xosclient.impl;
|
||||
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.onosproject.xosclient.api.XosAccess;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Invocation;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static com.google.common.net.MediaType.JSON_UTF_8;
|
||||
import static java.net.HttpURLConnection.HTTP_OK;
|
||||
|
||||
/**
|
||||
* XOS common REST API implementation.
|
||||
*/
|
||||
public class XosApi {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected static final String EMPTY_STRING = "";
|
||||
protected static final String EMPTY_JSON_STRING = "{}";
|
||||
|
||||
protected final String baseUrl;
|
||||
protected final XosAccess access;
|
||||
protected final Client client;
|
||||
|
||||
private static final int DEFAULT_TIMEOUT_MS = 2000;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param baseUrl base url of this api
|
||||
* @param xosAccess xos access
|
||||
*/
|
||||
public XosApi(String baseUrl, XosAccess xosAccess) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.access = xosAccess;
|
||||
this.client = ClientBuilder.newClient();
|
||||
|
||||
client.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_TIMEOUT_MS);
|
||||
client.property(ClientProperties.READ_TIMEOUT, DEFAULT_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access of this api.
|
||||
*
|
||||
* @return xos access
|
||||
*/
|
||||
public XosAccess access() {
|
||||
return this.access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base url of this api.
|
||||
*
|
||||
* @return base url
|
||||
*/
|
||||
public String baseUrl() {
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns response of the REST get operation with a given additional path.
|
||||
*
|
||||
* @param path path or null
|
||||
* @return response json string
|
||||
*/
|
||||
public String restGet(String path) {
|
||||
WebTarget wt = client.target(access.endpoint() + baseUrl).path(path);
|
||||
Invocation.Builder builder = wt.request(JSON_UTF_8.toString());
|
||||
try {
|
||||
Response response = builder.get();
|
||||
if (response.getStatus() != HTTP_OK) {
|
||||
log.warn("Failed to get resource {}", access.endpoint() + baseUrl + path);
|
||||
return EMPTY_JSON_STRING;
|
||||
}
|
||||
} catch (javax.ws.rs.ProcessingException e) {
|
||||
return EMPTY_JSON_STRING;
|
||||
}
|
||||
return builder.get(String.class);
|
||||
}
|
||||
}
|
@ -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.xosclient.impl;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
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.Modified;
|
||||
import org.apache.felix.scr.annotations.Property;
|
||||
import org.apache.felix.scr.annotations.Reference;
|
||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||
import org.apache.felix.scr.annotations.Service;
|
||||
import org.onlab.util.Tools;
|
||||
import org.onosproject.cfg.ComponentConfigService;
|
||||
import org.onosproject.core.ApplicationId;
|
||||
import org.onosproject.core.CoreService;
|
||||
import org.onosproject.net.config.ConfigFactory;
|
||||
import org.onosproject.net.config.NetworkConfigEvent;
|
||||
import org.onosproject.net.config.NetworkConfigListener;
|
||||
import org.onosproject.net.config.NetworkConfigRegistry;
|
||||
import org.onosproject.net.config.basics.SubjectFactories;
|
||||
import org.onosproject.xosclient.api.VtnPortApi;
|
||||
import org.onosproject.xosclient.api.VtnServiceApi;
|
||||
import org.onosproject.xosclient.api.XosAccess;
|
||||
import org.onosproject.xosclient.api.XosAccessConfig;
|
||||
import org.onosproject.xosclient.api.XosClientService;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Provides interactions with XOS.
|
||||
*/
|
||||
@Component(immediate = true)
|
||||
@Service
|
||||
public class XosClient implements XosClientService {
|
||||
|
||||
protected final Logger log = getLogger(getClass());
|
||||
|
||||
private static final String VTN_SERVICE_URL = "vtnServiceBaseUrl";
|
||||
private static final String DEFAULT_VTN_SERVICE_URL = "/api/service/vtn/services/";
|
||||
|
||||
private static final String VTN_PORT_URL = "vtnPortBaseUrl";
|
||||
private static final String DEFAULT_VTN_PORT_URL = "/api/service/vtn/ports/";
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
protected CoreService coreService;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
protected ComponentConfigService componentConfigService;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
protected NetworkConfigRegistry configRegistry;
|
||||
|
||||
@Property(name = VTN_SERVICE_URL, value = DEFAULT_VTN_SERVICE_URL,
|
||||
label = "XOS VTN service API base url")
|
||||
private String vtnServiceUrl = DEFAULT_VTN_SERVICE_URL;
|
||||
|
||||
@Property(name = VTN_PORT_URL, value = DEFAULT_VTN_PORT_URL,
|
||||
label = "XOS VTN port API base url")
|
||||
private String vtnPortUrl = DEFAULT_VTN_PORT_URL;
|
||||
|
||||
private final ConfigFactory configFactory =
|
||||
new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, XosAccessConfig.class, "xosclient") {
|
||||
@Override
|
||||
public XosAccessConfig createConfig() {
|
||||
return new XosAccessConfig();
|
||||
}
|
||||
};
|
||||
|
||||
private final NetworkConfigListener configListener = new InternalConfigListener();
|
||||
|
||||
private ApplicationId appId;
|
||||
private XosAccess access = null;
|
||||
|
||||
private VtnServiceApi vtnServiceApi = null;
|
||||
private VtnPortApi vtnPortApi = null;
|
||||
|
||||
/*
|
||||
* adds more XOS service APIs below.
|
||||
*/
|
||||
|
||||
@Activate
|
||||
protected void activate(ComponentContext context) {
|
||||
appId = coreService.registerApplication("org.onosproject.xosclient");
|
||||
|
||||
componentConfigService.registerProperties(getClass());
|
||||
modified(context);
|
||||
|
||||
configRegistry.registerConfigFactory(configFactory);
|
||||
configRegistry.addListener(configListener);
|
||||
|
||||
log.info("Started");
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
protected void deactivate() {
|
||||
configRegistry.unregisterConfigFactory(configFactory);
|
||||
configRegistry.removeListener(configListener);
|
||||
|
||||
log.info("Stopped");
|
||||
}
|
||||
|
||||
@Modified
|
||||
protected void modified(ComponentContext context) {
|
||||
Dictionary<?, ?> properties = context.getProperties();
|
||||
String updatedUrl;
|
||||
|
||||
updatedUrl = Tools.get(properties, VTN_SERVICE_URL);
|
||||
if (!Strings.isNullOrEmpty(updatedUrl) && !updatedUrl.equals(vtnServiceUrl)) {
|
||||
vtnServiceUrl = updatedUrl;
|
||||
vtnServiceApi = new DefaultVtnServiceApi(vtnServiceUrl, access);
|
||||
}
|
||||
|
||||
updatedUrl = Tools.get(properties, VTN_PORT_URL);
|
||||
if (!Strings.isNullOrEmpty(updatedUrl) && !updatedUrl.equals(vtnPortUrl)) {
|
||||
vtnPortUrl = updatedUrl;
|
||||
vtnPortApi = new DefaultVtnPortApi(vtnPortUrl, access);
|
||||
}
|
||||
|
||||
log.info("Modified");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XosAccess access() {
|
||||
return access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized XosClient getClient(XosAccess access) {
|
||||
checkNotNull(access);
|
||||
|
||||
if (!Objects.equals(this.access, access)) {
|
||||
// TODO do authentication before return
|
||||
this.access = access;
|
||||
|
||||
vtnServiceApi = new DefaultVtnServiceApi(vtnServiceUrl, access);
|
||||
vtnPortApi = new DefaultVtnPortApi(vtnPortUrl, access);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VtnServiceApi vtnService() {
|
||||
checkNotNull(vtnServiceApi, "VtnServiceApi is null");
|
||||
return vtnServiceApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VtnPortApi vtnPort() {
|
||||
checkNotNull(vtnPortApi, "VtnPortApi is null");
|
||||
return vtnPortApi;
|
||||
}
|
||||
|
||||
/*
|
||||
* adds more XOS service APIs below.
|
||||
*/
|
||||
|
||||
private void readConfiguration() {
|
||||
XosAccessConfig config = configRegistry.getConfig(appId, XosAccessConfig.class);
|
||||
if (config == null) {
|
||||
log.debug("No configuration found");
|
||||
return;
|
||||
}
|
||||
getClient(config.xosAccess());
|
||||
}
|
||||
|
||||
private class InternalConfigListener implements NetworkConfigListener {
|
||||
|
||||
@Override
|
||||
public void event(NetworkConfigEvent event) {
|
||||
if (!event.configClass().equals(XosAccessConfig.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.type()) {
|
||||
case CONFIG_ADDED:
|
||||
case CONFIG_UPDATED:
|
||||
log.info("Network configuration changed");
|
||||
readConfiguration();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* XOS client application.
|
||||
*/
|
||||
package org.onosproject.xosclient.impl;
|
@ -173,7 +173,6 @@ ONOS_APPS = [
|
||||
'//apps/faultmanagement:onos-apps-faultmanagement-oar',
|
||||
'//apps/openstacknode:onos-apps-openstacknode-oar',
|
||||
'//apps/cpman/app:onos-apps-cpman-app-oar',
|
||||
'//apps/xosclient:onos-apps-xosclient-oar',
|
||||
'//apps/scalablegateway:onos-apps-scalablegateway-oar',
|
||||
'//apps/castor:onos-apps-castor-oar',
|
||||
'//apps/yms:onos-apps-yms-oar',
|
||||
|
Loading…
x
Reference in New Issue
Block a user