blob: 827ce052ec686d3bba5012d1d85f3b3d7dd91126 [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
Hyunsun Moon8539b042015-11-07 22:08:43 -080035 public static final String CORDVTN_NODES = "nodes";
36 public static final String HOSTNAME = "hostname";
37 public static final String OVSDB_IP = "ovsdbIp";
38 public static final String OVSDB_PORT = "ovsdbPort";
Hyunsun Moon1f145552015-10-08 22:25:30 -070039 public static final String BRIDGE_ID = "bridgeId";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070040
41 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080042 * Returns the set of nodes read from network config.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070043 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080044 * @return set of CordVtnNodeConfig or null
Hyunsun Moond0e932a2015-09-15 22:39:16 -070045 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080046 public Set<CordVtnNodeConfig> cordVtnNodes() {
47 Set<CordVtnNodeConfig> nodes = Sets.newHashSet();
Hyunsun Moond0e932a2015-09-15 22:39:16 -070048
Hyunsun Moon8539b042015-11-07 22:08:43 -080049 JsonNode jsonNodes = object.get(CORDVTN_NODES);
50 if (jsonNodes == null) {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070051 return null;
52 }
Hyunsun Moon8539b042015-11-07 22:08:43 -080053 jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig(
54 jsonNode.path(HOSTNAME).asText(),
55 IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()),
56 TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()),
Hyunsun Moon1f145552015-10-08 22:25:30 -070057 DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()))));
Hyunsun Moond0e932a2015-09-15 22:39:16 -070058
Hyunsun Moon8539b042015-11-07 22:08:43 -080059 return nodes;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070060 }
61
62 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080063 * Configuration for CordVtn node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070064 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080065 public static class CordVtnNodeConfig {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070066
Hyunsun Moon8539b042015-11-07 22:08:43 -080067 private final String hostname;
68 private final IpAddress ovsdbIp;
69 private final TpPort ovsdbPort;
Hyunsun Moon1f145552015-10-08 22:25:30 -070070 private final DeviceId bridgeId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070071
Hyunsun Moon8539b042015-11-07 22:08:43 -080072 public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) {
73 this.hostname = checkNotNull(hostname);
74 this.ovsdbIp = checkNotNull(ovsdbIp);
75 this.ovsdbPort = checkNotNull(ovsdbPort);
Hyunsun Moon1f145552015-10-08 22:25:30 -070076 this.bridgeId = checkNotNull(bridgeId);
Hyunsun Moond0e932a2015-09-15 22:39:16 -070077 }
78
79 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080080 * Returns hostname of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070081 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080082 * @return hostname
Hyunsun Moond0e932a2015-09-15 22:39:16 -070083 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080084 public String hostname() {
85 return this.hostname;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070086 }
87
88 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080089 * Returns OVSDB ip address of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070090 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080091 * @return OVSDB server IP address
Hyunsun Moond0e932a2015-09-15 22:39:16 -070092 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080093 public IpAddress ovsdbIp() {
94 return this.ovsdbIp;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070095 }
96
97 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080098 * Returns OVSDB port number of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070099 *
100 * @return port number
101 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800102 public TpPort ovsdbPort() {
103 return this.ovsdbPort;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700104 }
Hyunsun Moon1f145552015-10-08 22:25:30 -0700105
Hyunsun Moon8539b042015-11-07 22:08:43 -0800106 /**
107 * Returns integration bridge id of the node.
108 *
109 * @return device id
110 */
Hyunsun Moon1f145552015-10-08 22:25:30 -0700111 public DeviceId bridgeId() {
112 return this.bridgeId;
113 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700114 }
115}