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
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-providers</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.8.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 + <modelVersion>4.0.0</modelVersion>
28 +
29 + <artifactId>onos-ietfte-providers</artifactId>
30 + <packaging>pom</packaging>
31 + <modules>
32 + <module>topology</module>
33 + </modules>
34 +</project>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.teprovider.topology" origin="HUAWEI" version="${project.version}"
18 + category="Provider" title="RESTCONF TE Topology Provider"
19 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
20 + features="${project.artifactId}">
21 + <description>${project.description}</description>
22 + <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}</artifact>
24 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <repository>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}/xml/features</repository>
19 + <feature name="${project.artifactId}" version="${project.version}"
20 + description="${project.description}">
21 + <feature>onos-api</feature>
22 + <feature>onos-app-tenbi-yangmodel</feature>
23 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
24 + <bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
25 + <bundle>mvn:${project.groupId}/onos-restsb-ctl/${project.version}</bundle>
26 + <bundle>mvn:org.glassfish.jersey.core/jersey-client/2.22.2</bundle>
27 + <bundle>mvn:commons-io/commons-io/2.4</bundle>
28 + <bundle>mvn:org.apache.httpcomponents/httpclient-osgi/4.5.1</bundle>
29 + <bundle>mvn:org.apache.httpcomponents/httpcore-osgi/4.4.4</bundle>
30 + <bundle>mvn:${project.groupId}/onos-app-tetopology/${project.version}</bundle>
31 + <bundle>mvn:${project.groupId}/onos-app-yms-api/${project.version}</bundle>
32 + <bundle>mvn:${project.groupId}/onos-app-tenbi-utils/${project.version}</bundle>
33 + </feature>
34 +</features>
35 +
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-ietfte-providers</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.8.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 + <modelVersion>4.0.0</modelVersion>
28 +
29 + <artifactId>onos-ietfte-provider-topology</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>IETF TE topology southbound provider</description>
33 +
34 + <dependencies>
35 + <dependency>
36 + <groupId>org.onosproject</groupId>
37 + <artifactId>onos-restconf-client-api</artifactId>
38 + <version>${project.version}</version>
39 + </dependency>
40 + <dependency>
41 + <groupId>org.onosproject</groupId>
42 + <artifactId>onos-restconf-client-ctl</artifactId>
43 + <version>${project.version}</version>
44 + </dependency>
45 + <dependency>
46 + <groupId>org.onosproject</groupId>
47 + <artifactId>onos-app-tetopology</artifactId>
48 + <version>${project.version}</version>
49 + </dependency>
50 + <dependency>
51 + <groupId>org.onosproject</groupId>
52 + <artifactId>onos-app-tenbi-yangmodel</artifactId>
53 + <version>${project.version}</version>
54 + </dependency>
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
57 + <artifactId>onos-app-tenbi-utils</artifactId>
58 + <version>${project.version}</version>
59 + </dependency>
60 + <dependency>
61 + <groupId>org.onosproject</groupId>
62 + <artifactId>onos-app-yms-api</artifactId>
63 + <version>${project.version}</version>
64 + </dependency>
65 + <dependency>
66 + <groupId>org.onosproject</groupId>
67 + <artifactId>onos-restconf-server-utils</artifactId>
68 + <version>${project.version}</version>
69 + </dependency>
70 + </dependencies>
71 +
72 +</project>
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.te.topology;
17 +
18 +import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
19 +
20 +import java.io.IOException;
21 +import java.io.InputStream;
22 +
23 +import org.apache.commons.io.IOUtils;
24 +import org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils;
25 +import org.onosproject.yms.ych.YangCompositeEncoding;
26 +import org.onosproject.yms.ych.YangDataTreeCodec;
27 +import org.onosproject.yms.ydt.YdtBuilder;
28 +import org.onosproject.yms.ydt.YmsOperationType;
29 +import org.onosproject.yms.ymsm.YmsService;
30 +import org.slf4j.Logger;
31 +import org.slf4j.LoggerFactory;
32 +
33 +import com.fasterxml.jackson.databind.ObjectMapper;
34 +import com.fasterxml.jackson.databind.node.ObjectNode;
35 +
36 +
37 +/**
38 + * JSON/YDT Codec implementation.
39 + */
40 +public class JsonYdtCodec implements YangDataTreeCodec {
41 + private static final String RESTCONF_ROOT = "restconf/data";
42 +
43 + protected final YmsService ymsService;
44 +
45 + private final Logger log = LoggerFactory.getLogger(getClass());
46 +
47 + public JsonYdtCodec(YmsService service) {
48 + ymsService = service;
49 + }
50 +
51 + @Override
52 + public String encodeYdtToProtocolFormat(YdtBuilder builder,
53 + YmsOperationType opType) {
54 + String json = ParserUtils.convertYdtToJson(builder.getRootNode().getName(),
55 + builder.getRootNode(),
56 + ymsService.getYdtWalker())
57 + .textValue();
58 + return json;
59 + }
60 +
61 + @Override
62 + public YangCompositeEncoding encodeYdtToCompositeProtocolFormat(YdtBuilder builder,
63 + YmsOperationType opType) {
64 + // Mainly for POST/PUT operation.
65 + // YdtBuilder/YdtContext has YdtContextType NONE for URI,
66 + // YdtContextType CREATE/MERGE/REPLACE for Resource data.
67 +
68 + // TODO: Implement this method in Release Ibis for TE Tunnel.
69 +
70 + return null;
71 + }
72 +
73 + @Override
74 + public YdtBuilder decodeProtocolDataToYdt(String protocolData,
75 + Object schemaRegistryForYdt,
76 + YmsOperationType opType) {
77 + // Get a new builder
78 + YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
79 + null,
80 + opType,
81 + schemaRegistryForYdt);
82 + ParserUtils.convertJsonToYdt(getObjectNode(protocolData), builder);
83 + return builder;
84 + }
85 +
86 + @Override
87 + public YdtBuilder decodeCompositeProtocolDataToYdt(YangCompositeEncoding protocolData,
88 + Object schemaRegistryForYdt,
89 + YmsOperationType opType) {
90 + // opType should be QUERY_REPLY
91 + // Get a new builder
92 + YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
93 + null,
94 + opType,
95 + schemaRegistryForYdt);
96 + // Convert the URI to ydtBuilder
97 +
98 + // YdtContextOperationType should be NONE for URI in QUERY_RESPONSE.
99 + ParserUtils.convertUriToYdt(protocolData.getResourceIdentifier(), builder, NONE);
100 + // Set default operation type for the payload node, is this for resource data?
101 + // NULL/EMPTY for Resource data
102 + builder.setDefaultEditOperationType(null);
103 +
104 + // Convert the payload json body to ydt
105 + ParserUtils.convertJsonToYdt(getObjectNode(protocolData.getResourceInformation()), builder);
106 + return builder;
107 + }
108 +
109 + // Returns an ObjectNode from s JSON string.
110 + private ObjectNode getObjectNode(String json) {
111 + InputStream stream = IOUtils.toInputStream(json);
112 +
113 + ObjectNode rootNode;
114 + ObjectMapper mapper = new ObjectMapper();
115 + try {
116 + rootNode = (ObjectNode) mapper.readTree(stream);
117 + } catch (IOException e) {
118 + log.error("Can't read stream as a JSON ObjectNode: {}", e);
119 + return null;
120 + }
121 + return rootNode;
122 + }
123 +
124 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.te.topology;
17 +
18 +import java.util.Set;
19 +
20 +import org.onlab.packet.IpAddress;
21 +import org.onosproject.core.ApplicationId;
22 +import org.onosproject.incubator.net.config.basics.ConfigException;
23 +import org.onosproject.net.config.Config;
24 +import org.onosproject.protocol.rest.DefaultRestSBDevice;
25 +import org.onosproject.protocol.rest.RestSBDevice;
26 +
27 +import com.fasterxml.jackson.databind.JsonNode;
28 +import com.google.common.collect.Sets;
29 +
30 +/**
31 + * Configuration for Restconf Server.
32 + */
33 +public class RestconfServerConfig extends Config<ApplicationId> {
34 + private static final String CONFIG_VALUE_ERROR = "Error parsing config value";
35 + private static final String IP = "ip";
36 + private static final int DEFAULT_HTTP_PORT = 80;
37 + private static final String PORT = "port";
38 + private static final String USERNAME = "username";
39 + private static final String PASSWORD = "password";
40 + private static final String PROTOCOL = "protocol";
41 + private static final String URL = "url";
42 +
43 + /**
44 + * Returns the device addresses from JSON.
45 + *
46 + * @return A set of RESTCONF Server devices
47 + * @throws ConfigException if there is a configuration error
48 + */
49 + public Set<RestSBDevice> getDevicesAddresses() throws ConfigException {
50 + Set<RestSBDevice> devicesAddresses = Sets.newHashSet();
51 +
52 + try {
53 + for (JsonNode node : array) {
54 + String ip = node.path(IP).asText();
55 + IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
56 + int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT);
57 + String username = node.path(USERNAME).asText();
58 + String password = node.path(PASSWORD).asText();
59 + String protocol = node.path(PROTOCOL).asText();
60 + String url = node.path(URL).asText();
61 + devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username,
62 + password, protocol,
63 + url, false));
64 +
65 + }
66 + } catch (IllegalArgumentException e) {
67 + throw new ConfigException(CONFIG_VALUE_ERROR, e);
68 + }
69 +
70 + return devicesAddresses;
71 + }
72 +
73 +}
1 +package org.onosproject.provider.te.topology;
2 +
3 +import org.onosproject.yms.ych.YangCompositeEncoding;
4 +import org.onosproject.yms.ych.YangResourceIdentifierType;
5 +
6 +/**
7 + * Represents implementation of YangCompositeEncoding interfaces.
8 + */
9 +public class YangCompositeEncodingImpl implements YangCompositeEncoding {
10 +
11 + /**
12 + * Resource identifier for composite encoding.
13 + */
14 + private final String resourceIdentifier;
15 +
16 + /**
17 + * Resource information for composite encoding.
18 + */
19 + private final String resourceInformation;
20 +
21 + /**
22 + * Resource identifier type.
23 + */
24 + public final YangResourceIdentifierType resourceIdentifierType;
25 +
26 + /**
27 + * Creates an instance of YangCompositeEncodingImpl.
28 + *
29 + * @param resourceIdentifierType is URI
30 + * @param resourceIdentifier is the URI string
31 + * @param resourceInformation is the JSON body string
32 + */
33 + public YangCompositeEncodingImpl(YangResourceIdentifierType resourceIdentifierType,
34 + String resourceIdentifier,
35 + String resourceInformation) {
36 + this.resourceIdentifierType = resourceIdentifierType;
37 + this.resourceIdentifier = resourceIdentifier;
38 + this.resourceInformation = resourceInformation;
39 + }
40 +
41 + @Override
42 + public String getResourceIdentifier() {
43 + return resourceIdentifier;
44 + }
45 +
46 + @Override
47 + public YangResourceIdentifierType getResourceIdentifierType() {
48 + return resourceIdentifierType;
49 + }
50 +
51 + @Override
52 + public String getResourceInformation() {
53 + return resourceInformation;
54 + }
55 +}
56 +
1 +/**
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +/**
17 + * IETF TE Topology provider implementation using RESTCONF protocol.
18 + */
19 +package org.onosproject.provider.te.topology;
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
50 <module>lisp</module> 50 <module>lisp</module>
51 <module>ospf</module> 51 <module>ospf</module>
52 <module>link</module> 52 <module>link</module>
53 + <module>ietfte</module>
53 </modules> 54 </modules>
54 55
55 <dependencies> 56 <dependencies>
......