blob: 167d7bfbad4f3240f7b7929b2541df3a2fe73e81 [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;
Hyunsun Moon746956f2016-01-24 21:47:06 -080021import org.onlab.packet.MacAddress;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070022import org.onlab.packet.TpPort;
23import org.onosproject.core.ApplicationId;
Hyunsun Moon1f145552015-10-08 22:25:30 -070024import org.onosproject.net.DeviceId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070025import org.onosproject.net.config.Config;
Hyunsun Moon746956f2016-01-24 21:47:06 -080026import org.slf4j.Logger;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070027
28import java.util.Set;
29
30import static com.google.common.base.Preconditions.checkNotNull;
Hyunsun Moon746956f2016-01-24 21:47:06 -080031import static org.slf4j.LoggerFactory.getLogger;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070032
33/**
Hyunsun Moon2b530322015-09-23 13:24:35 -070034 * Configuration object for CordVtn service.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070035 */
36public class CordVtnConfig extends Config<ApplicationId> {
37
Hyunsun Moon746956f2016-01-24 21:47:06 -080038 protected final Logger log = getLogger(getClass());
39
Hyunsun Moon8539b042015-11-07 22:08:43 -080040 public static final String CORDVTN_NODES = "nodes";
41 public static final String HOSTNAME = "hostname";
42 public static final String OVSDB_IP = "ovsdbIp";
43 public static final String OVSDB_PORT = "ovsdbPort";
Hyunsun Moon1f145552015-10-08 22:25:30 -070044 public static final String BRIDGE_ID = "bridgeId";
Hyunsun Moonb219fc42016-01-14 03:42:47 -080045 public static final String PHYSICAL_PORT_NAME = "phyPortName";
46 public static final String LOCAL_IP = "localIp";
Hyunsun Moon746956f2016-01-24 21:47:06 -080047 public static final String GATEWAY_MAC = "gatewayMac";
Hyunsun Moond0e932a2015-09-15 22:39:16 -070048
49 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080050 * Returns the set of nodes read from network config.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070051 *
Hyunsun Moon8539b042015-11-07 22:08:43 -080052 * @return set of CordVtnNodeConfig or null
Hyunsun Moond0e932a2015-09-15 22:39:16 -070053 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080054 public Set<CordVtnNodeConfig> cordVtnNodes() {
55 Set<CordVtnNodeConfig> nodes = Sets.newHashSet();
Hyunsun Moond0e932a2015-09-15 22:39:16 -070056
Hyunsun Moon8539b042015-11-07 22:08:43 -080057 JsonNode jsonNodes = object.get(CORDVTN_NODES);
58 if (jsonNodes == null) {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070059 return null;
60 }
Hyunsun Moon8539b042015-11-07 22:08:43 -080061 jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig(
62 jsonNode.path(HOSTNAME).asText(),
63 IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()),
64 TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()),
Hyunsun Moonb219fc42016-01-14 03:42:47 -080065 DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
66 jsonNode.path(PHYSICAL_PORT_NAME).asText(),
67 IpAddress.valueOf(jsonNode.path(LOCAL_IP).asText()))));
Hyunsun Moond0e932a2015-09-15 22:39:16 -070068
Hyunsun Moon8539b042015-11-07 22:08:43 -080069 return nodes;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070070 }
71
72 /**
Hyunsun Moon746956f2016-01-24 21:47:06 -080073 * Returns gateway MAC address.
74 *
75 * @return mac address, or null
76 */
77 public MacAddress gatewayMac() {
78 JsonNode jsonNode = object.get(GATEWAY_MAC);
79 if (jsonNode == null) {
80 return null;
81 }
82
83 try {
84 return MacAddress.valueOf(jsonNode.asText());
85 } catch (IllegalArgumentException e) {
86 log.error("Wrong MAC address format {}", jsonNode.asText());
87 return null;
88 }
89 }
90
91 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -080092 * Configuration for CordVtn node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070093 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080094 public static class CordVtnNodeConfig {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070095
Hyunsun Moon8539b042015-11-07 22:08:43 -080096 private final String hostname;
97 private final IpAddress ovsdbIp;
98 private final TpPort ovsdbPort;
Hyunsun Moon1f145552015-10-08 22:25:30 -070099 private final DeviceId bridgeId;
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800100 private final String phyPortName;
101 private final IpAddress localIp;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700102
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800103 public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort,
104 DeviceId bridgeId, String phyPortName, IpAddress localIp) {
Hyunsun Moon8539b042015-11-07 22:08:43 -0800105 this.hostname = checkNotNull(hostname);
106 this.ovsdbIp = checkNotNull(ovsdbIp);
107 this.ovsdbPort = checkNotNull(ovsdbPort);
Hyunsun Moon1f145552015-10-08 22:25:30 -0700108 this.bridgeId = checkNotNull(bridgeId);
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800109 this.phyPortName = checkNotNull(phyPortName);
110 this.localIp = checkNotNull(localIp);
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700111 }
112
113 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800114 * Returns hostname of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700115 *
Hyunsun Moon8539b042015-11-07 22:08:43 -0800116 * @return hostname
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700117 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800118 public String hostname() {
119 return this.hostname;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700120 }
121
122 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800123 * Returns OVSDB ip address of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700124 *
Hyunsun Moon8539b042015-11-07 22:08:43 -0800125 * @return OVSDB server IP address
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700126 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800127 public IpAddress ovsdbIp() {
128 return this.ovsdbIp;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700129 }
130
131 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800132 * Returns OVSDB port number of the node.
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700133 *
134 * @return port number
135 */
Hyunsun Moon8539b042015-11-07 22:08:43 -0800136 public TpPort ovsdbPort() {
137 return this.ovsdbPort;
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700138 }
Hyunsun Moon1f145552015-10-08 22:25:30 -0700139
Hyunsun Moon8539b042015-11-07 22:08:43 -0800140 /**
141 * Returns integration bridge id of the node.
142 *
143 * @return device id
144 */
Hyunsun Moon1f145552015-10-08 22:25:30 -0700145 public DeviceId bridgeId() {
146 return this.bridgeId;
147 }
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800148
149 /**
150 * Returns physical port name.
151 *
152 * @return physical port name
153 */
154 public String phyPortName() {
155 return this.phyPortName;
156 }
157
158 /**
159 * Returns local IP address.
160 *
161 * @return ip address
162 */
163 public IpAddress localIp() {
164 return this.localIp;
165 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700166 }
167}