blob: 57842dc9a871d7786617f47318da15030fcdea97 [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 Moonb219fc42016-01-14 03:42:47 -080040 public static final String PHYSICAL_PORT_NAME = "phyPortName";
41 public static final String LOCAL_IP = "localIp";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070042
43 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080044 * Returns the set of nodes read from network config.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070045 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080046 * @return set of CordVtnNodeConfig or null
Hyunsun Moond0e932a2015-09-15 22:39:16 -070047 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080048 public Set<CordVtnNodeConfig> cordVtnNodes() {
49 Set<CordVtnNodeConfig> nodes = Sets.newHashSet();
Hyunsun Moond0e932a2015-09-15 22:39:16 -070050
Hyunsun Moon8539b042015-11-07 22:08:43 -080051 JsonNode jsonNodes = object.get(CORDVTN_NODES);
52 if (jsonNodes == null) {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070053 return null;
54 }
Hyunsun Moon8539b042015-11-07 22:08:43 -080055 jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig(
56 jsonNode.path(HOSTNAME).asText(),
57 IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()),
58 TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()),
Hyunsun Moonb219fc42016-01-14 03:42:47 -080059 DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
60 jsonNode.path(PHYSICAL_PORT_NAME).asText(),
61 IpAddress.valueOf(jsonNode.path(LOCAL_IP).asText()))));
Hyunsun Moond0e932a2015-09-15 22:39:16 -070062
Hyunsun Moon8539b042015-11-07 22:08:43 -080063 return nodes;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070064 }
65
66 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080067 * Configuration for CordVtn node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070068 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080069 public static class CordVtnNodeConfig {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070070
Hyunsun Moon8539b042015-11-07 22:08:43 -080071 private final String hostname;
72 private final IpAddress ovsdbIp;
73 private final TpPort ovsdbPort;
Hyunsun Moon1f145552015-10-08 22:25:30 -070074 private final DeviceId bridgeId;
Hyunsun Moonb219fc42016-01-14 03:42:47 -080075 private final String phyPortName;
76 private final IpAddress localIp;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070077
Hyunsun Moonb219fc42016-01-14 03:42:47 -080078 public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort,
79 DeviceId bridgeId, String phyPortName, IpAddress localIp) {
Hyunsun Moon8539b042015-11-07 22:08:43 -080080 this.hostname = checkNotNull(hostname);
81 this.ovsdbIp = checkNotNull(ovsdbIp);
82 this.ovsdbPort = checkNotNull(ovsdbPort);
Hyunsun Moon1f145552015-10-08 22:25:30 -070083 this.bridgeId = checkNotNull(bridgeId);
Hyunsun Moonb219fc42016-01-14 03:42:47 -080084 this.phyPortName = checkNotNull(phyPortName);
85 this.localIp = checkNotNull(localIp);
Hyunsun Moond0e932a2015-09-15 22:39:16 -070086 }
87
88 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080089 * Returns hostname of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070090 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080091 * @return hostname
Hyunsun Moond0e932a2015-09-15 22:39:16 -070092 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080093 public String hostname() {
94 return this.hostname;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070095 }
96
97 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080098 * Returns OVSDB ip address of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070099 *
Hyunsun Moon8539b042015-11-07 22:08:43 -0800100 * @return OVSDB server IP address
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700101 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800102 public IpAddress ovsdbIp() {
103 return this.ovsdbIp;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700104 }
105
106 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800107 * Returns OVSDB port number of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700108 *
109 * @return port number
110 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800111 public TpPort ovsdbPort() {
112 return this.ovsdbPort;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700113 }
Hyunsun Moon1f145552015-10-08 22:25:30 -0700114
Hyunsun Moon8539b042015-11-07 22:08:43 -0800115 /**
116 * Returns integration bridge id of the node.
117 *
118 * @return device id
119 */
Hyunsun Moon1f145552015-10-08 22:25:30 -0700120 public DeviceId bridgeId() {
121 return this.bridgeId;
122 }
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800123
124 /**
125 * Returns physical port name.
126 *
127 * @return physical port name
128 */
129 public String phyPortName() {
130 return this.phyPortName;
131 }
132
133 /**
134 * Returns local IP address.
135 *
136 * @return ip address
137 */
138 public IpAddress localIp() {
139 return this.localIp;
140 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700141 }
142}