blob: 550452ce3bc2dbb6d5511cd63f3b69b68bf1aae5 [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;
Hyunsun Moon1f145552015-10-08 22:25:30 -070023import org.onosproject.net.DeviceId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070024import org.onosproject.net.config.Config;
25
26import java.util.Set;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
Hyunsun Moon2b530322015-09-23 13:24:35 -070031 * Configuration object for CordVtn service.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070032 */
33public class CordVtnConfig extends Config<ApplicationId> {
34
35 public static final String OVSDB_NODES = "ovsdbNodes";
Hyunsun Moon2b530322015-09-23 13:24:35 -070036 public static final String HOST = "host";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070037 public static final String IP = "ip";
38 public static final String PORT = "port";
Hyunsun Moon1f145552015-10-08 22:25:30 -070039 public static final String BRIDGE_ID = "bridgeId";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070040
41 /**
42 * Returns the set of ovsdb nodes read from network config.
43 *
44 * @return set of OvsdbNodeConfig or null
45 */
46 public Set<OvsdbNodeConfig> ovsdbNodes() {
47 Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet();
48
49 JsonNode nodes = object.get(OVSDB_NODES);
50 if (nodes == null) {
51 return null;
52 }
53 nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig(
Hyunsun Moon2b530322015-09-23 13:24:35 -070054 jsonNode.path(HOST).asText(),
Hyunsun Moond0e932a2015-09-15 22:39:16 -070055 IpAddress.valueOf(jsonNode.path(IP).asText()),
Hyunsun Moon1f145552015-10-08 22:25:30 -070056 TpPort.tpPort(jsonNode.path(PORT).asInt()),
57 DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()))));
Hyunsun Moond0e932a2015-09-15 22:39:16 -070058
59 return ovsdbNodes;
60 }
61
62 /**
Hyunsun Moon2b530322015-09-23 13:24:35 -070063 * Configuration for an ovsdb node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070064 */
65 public static class OvsdbNodeConfig {
66
Hyunsun Moon2b530322015-09-23 13:24:35 -070067 private final String host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070068 private final IpAddress ip;
69 private final TpPort port;
Hyunsun Moon1f145552015-10-08 22:25:30 -070070 private final DeviceId bridgeId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070071
Hyunsun Moon1f145552015-10-08 22:25:30 -070072 public OvsdbNodeConfig(String host, IpAddress ip, TpPort port, DeviceId bridgeId) {
Hyunsun Moon2b530322015-09-23 13:24:35 -070073 this.host = checkNotNull(host);
Hyunsun Moond0e932a2015-09-15 22:39:16 -070074 this.ip = checkNotNull(ip);
75 this.port = checkNotNull(port);
Hyunsun Moon1f145552015-10-08 22:25:30 -070076 this.bridgeId = checkNotNull(bridgeId);
Hyunsun Moond0e932a2015-09-15 22:39:16 -070077 }
78
79 /**
Hyunsun Moon2b530322015-09-23 13:24:35 -070080 * Returns host information of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070081 *
Hyunsun Moon2b530322015-09-23 13:24:35 -070082 * @return host
Hyunsun Moond0e932a2015-09-15 22:39:16 -070083 */
Hyunsun Moon2b530322015-09-23 13:24:35 -070084 public String host() {
85 return this.host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070086 }
87
88 /**
89 * Returns ip address to access ovsdb-server of the node.
90 *
91 * @return ip address
92 */
93 public IpAddress ip() {
94 return this.ip;
95 }
96
97 /**
98 * Returns port number to access ovsdb-server of the node.
99 *
100 * @return port number
101 */
102 public TpPort port() {
103 return this.port;
104 }
Hyunsun Moon1f145552015-10-08 22:25:30 -0700105
106 public DeviceId bridgeId() {
107 return this.bridgeId;
108 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700109 }
110}