blob: fdaf752a882f1faaf3f042041a8b9397d085d549 [file] [log] [blame]
Hyunsun Moond0e932a2015-09-15 22:39:16 -07001/*
2 * Copyright 2014-2015 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 */
16package org.onosproject.cordvtn;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.google.common.collect.Sets;
20import org.onlab.packet.IpAddress;
21import org.onlab.packet.TpPort;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.net.config.Config;
24
25import java.util.Set;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
Hyunsun Moon2b530322015-09-23 13:24:35 -070030 * Configuration object for CordVtn service.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070031 */
32public class CordVtnConfig extends Config<ApplicationId> {
33
34 public static final String OVSDB_NODES = "ovsdbNodes";
Hyunsun Moon2b530322015-09-23 13:24:35 -070035 public static final String HOST = "host";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070036 public static final String IP = "ip";
37 public static final String PORT = "port";
38
39 /**
40 * Returns the set of ovsdb nodes read from network config.
41 *
42 * @return set of OvsdbNodeConfig or null
43 */
44 public Set<OvsdbNodeConfig> ovsdbNodes() {
45 Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet();
46
47 JsonNode nodes = object.get(OVSDB_NODES);
48 if (nodes == null) {
49 return null;
50 }
51 nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig(
Hyunsun Moon2b530322015-09-23 13:24:35 -070052 jsonNode.path(HOST).asText(),
Hyunsun Moond0e932a2015-09-15 22:39:16 -070053 IpAddress.valueOf(jsonNode.path(IP).asText()),
54 TpPort.tpPort(jsonNode.path(PORT).asInt()))));
55
56 return ovsdbNodes;
57 }
58
59 /**
Hyunsun Moon2b530322015-09-23 13:24:35 -070060 * Configuration for an ovsdb node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070061 */
62 public static class OvsdbNodeConfig {
63
Hyunsun Moon2b530322015-09-23 13:24:35 -070064 private final String host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070065 private final IpAddress ip;
66 private final TpPort port;
67
Hyunsun Moon2b530322015-09-23 13:24:35 -070068 public OvsdbNodeConfig(String host, IpAddress ip, TpPort port) {
69 this.host = checkNotNull(host);
Hyunsun Moond0e932a2015-09-15 22:39:16 -070070 this.ip = checkNotNull(ip);
71 this.port = checkNotNull(port);
72 }
73
74 /**
Hyunsun Moon2b530322015-09-23 13:24:35 -070075 * Returns host information of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070076 *
Hyunsun Moon2b530322015-09-23 13:24:35 -070077 * @return host
Hyunsun Moond0e932a2015-09-15 22:39:16 -070078 */
Hyunsun Moon2b530322015-09-23 13:24:35 -070079 public String host() {
80 return this.host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070081 }
82
83 /**
84 * Returns ip address to access ovsdb-server of the node.
85 *
86 * @return ip address
87 */
88 public IpAddress ip() {
89 return this.ip;
90 }
91
92 /**
93 * Returns port number to access ovsdb-server of the node.
94 *
95 * @return port number
96 */
97 public TpPort port() {
98 return this.port;
99 }
100 }
101}