Yixiao Chen
Committed by Gerrit Code Review

[ONOS-4880][ONOS-5021]IETF TE Topology Provider

The provider introduces IETF TE Topology YANG models and interacts with RESTCONF
client and YMS to provide IETF TE Topology to TE Topology Core subsystem.

This issue implements the interaction with RESTCONF client to obtain network topology
in JSON from south bound.

Change-Id: If203a98db69a516c8b09cb9247724e49a95abe4f
<?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">
<parent>
<artifactId>onos-providers</artifactId>
<groupId>org.onosproject</groupId>
<version>1.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>onos-ietfte-providers</artifactId>
<packaging>pom</packaging>
<modules>
<module>topology</module>
</modules>
</project>
<?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.teprovider.topology" origin="HUAWEI" version="${project.version}"
category="Provider" title="RESTCONF TE Topology Provider"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}</artifact>
</app>
<?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}">
<repository>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}/xml/features</repository>
<feature name="${project.artifactId}" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<feature>onos-app-tenbi-yangmodel</feature>
<bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-restsb-ctl/${project.version}</bundle>
<bundle>mvn:org.glassfish.jersey.core/jersey-client/2.22.2</bundle>
<bundle>mvn:commons-io/commons-io/2.4</bundle>
<bundle>mvn:org.apache.httpcomponents/httpclient-osgi/4.5.1</bundle>
<bundle>mvn:org.apache.httpcomponents/httpcore-osgi/4.4.4</bundle>
<bundle>mvn:${project.groupId}/onos-app-tetopology/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-yms-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-tenbi-utils/${project.version}</bundle>
</feature>
</features>
<?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">
<parent>
<artifactId>onos-ietfte-providers</artifactId>
<groupId>org.onosproject</groupId>
<version>1.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>onos-ietfte-provider-topology</artifactId>
<packaging>bundle</packaging>
<description>IETF TE topology southbound provider</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-restconf-client-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-restconf-client-ctl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-tetopology</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-tenbi-yangmodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-tenbi-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-yms-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-restconf-server-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.te.topology;
import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils;
import org.onosproject.yms.ych.YangCompositeEncoding;
import org.onosproject.yms.ych.YangDataTreeCodec;
import org.onosproject.yms.ydt.YdtBuilder;
import org.onosproject.yms.ydt.YmsOperationType;
import org.onosproject.yms.ymsm.YmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* JSON/YDT Codec implementation.
*/
public class JsonYdtCodec implements YangDataTreeCodec {
private static final String RESTCONF_ROOT = "restconf/data";
protected final YmsService ymsService;
private final Logger log = LoggerFactory.getLogger(getClass());
public JsonYdtCodec(YmsService service) {
ymsService = service;
}
@Override
public String encodeYdtToProtocolFormat(YdtBuilder builder,
YmsOperationType opType) {
String json = ParserUtils.convertYdtToJson(builder.getRootNode().getName(),
builder.getRootNode(),
ymsService.getYdtWalker())
.textValue();
return json;
}
@Override
public YangCompositeEncoding encodeYdtToCompositeProtocolFormat(YdtBuilder builder,
YmsOperationType opType) {
// Mainly for POST/PUT operation.
// YdtBuilder/YdtContext has YdtContextType NONE for URI,
// YdtContextType CREATE/MERGE/REPLACE for Resource data.
// TODO: Implement this method in Release Ibis for TE Tunnel.
return null;
}
@Override
public YdtBuilder decodeProtocolDataToYdt(String protocolData,
Object schemaRegistryForYdt,
YmsOperationType opType) {
// Get a new builder
YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
null,
opType,
schemaRegistryForYdt);
ParserUtils.convertJsonToYdt(getObjectNode(protocolData), builder);
return builder;
}
@Override
public YdtBuilder decodeCompositeProtocolDataToYdt(YangCompositeEncoding protocolData,
Object schemaRegistryForYdt,
YmsOperationType opType) {
// opType should be QUERY_REPLY
// Get a new builder
YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
null,
opType,
schemaRegistryForYdt);
// Convert the URI to ydtBuilder
// YdtContextOperationType should be NONE for URI in QUERY_RESPONSE.
ParserUtils.convertUriToYdt(protocolData.getResourceIdentifier(), builder, NONE);
// Set default operation type for the payload node, is this for resource data?
// NULL/EMPTY for Resource data
builder.setDefaultEditOperationType(null);
// Convert the payload json body to ydt
ParserUtils.convertJsonToYdt(getObjectNode(protocolData.getResourceInformation()), builder);
return builder;
}
// Returns an ObjectNode from s JSON string.
private ObjectNode getObjectNode(String json) {
InputStream stream = IOUtils.toInputStream(json);
ObjectNode rootNode;
ObjectMapper mapper = new ObjectMapper();
try {
rootNode = (ObjectNode) mapper.readTree(stream);
} catch (IOException e) {
log.error("Can't read stream as a JSON ObjectNode: {}", e);
return null;
}
return rootNode;
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.te.topology;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.config.basics.ConfigException;
import org.onosproject.net.config.Config;
import org.onosproject.protocol.rest.DefaultRestSBDevice;
import org.onosproject.protocol.rest.RestSBDevice;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
/**
* Configuration for Restconf Server.
*/
public class RestconfServerConfig extends Config<ApplicationId> {
private static final String CONFIG_VALUE_ERROR = "Error parsing config value";
private static final String IP = "ip";
private static final int DEFAULT_HTTP_PORT = 80;
private static final String PORT = "port";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
private static final String PROTOCOL = "protocol";
private static final String URL = "url";
/**
* Returns the device addresses from JSON.
*
* @return A set of RESTCONF Server devices
* @throws ConfigException if there is a configuration error
*/
public Set<RestSBDevice> getDevicesAddresses() throws ConfigException {
Set<RestSBDevice> devicesAddresses = Sets.newHashSet();
try {
for (JsonNode node : array) {
String ip = node.path(IP).asText();
IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT);
String username = node.path(USERNAME).asText();
String password = node.path(PASSWORD).asText();
String protocol = node.path(PROTOCOL).asText();
String url = node.path(URL).asText();
devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username,
password, protocol,
url, false));
}
} catch (IllegalArgumentException e) {
throw new ConfigException(CONFIG_VALUE_ERROR, e);
}
return devicesAddresses;
}
}
package org.onosproject.provider.te.topology;
import org.onosproject.yms.ych.YangCompositeEncoding;
import org.onosproject.yms.ych.YangResourceIdentifierType;
/**
* Represents implementation of YangCompositeEncoding interfaces.
*/
public class YangCompositeEncodingImpl implements YangCompositeEncoding {
/**
* Resource identifier for composite encoding.
*/
private final String resourceIdentifier;
/**
* Resource information for composite encoding.
*/
private final String resourceInformation;
/**
* Resource identifier type.
*/
public final YangResourceIdentifierType resourceIdentifierType;
/**
* Creates an instance of YangCompositeEncodingImpl.
*
* @param resourceIdentifierType is URI
* @param resourceIdentifier is the URI string
* @param resourceInformation is the JSON body string
*/
public YangCompositeEncodingImpl(YangResourceIdentifierType resourceIdentifierType,
String resourceIdentifier,
String resourceInformation) {
this.resourceIdentifierType = resourceIdentifierType;
this.resourceIdentifier = resourceIdentifier;
this.resourceInformation = resourceInformation;
}
@Override
public String getResourceIdentifier() {
return resourceIdentifier;
}
@Override
public YangResourceIdentifierType getResourceIdentifierType() {
return resourceIdentifierType;
}
@Override
public String getResourceInformation() {
return resourceInformation;
}
}
/**
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* IETF TE Topology provider implementation using RESTCONF protocol.
*/
package org.onosproject.provider.te.topology;
......@@ -50,6 +50,7 @@
<module>lisp</module>
<module>ospf</module>
<module>link</module>
<module>ietfte</module>
</modules>
<dependencies>
......