diff options
author | Ashlee Young <ashlee@onosfw.com> | 2015-09-22 12:49:09 -0700 |
---|---|---|
committer | Ashlee Young <ashlee@onosfw.com> | 2015-09-22 12:49:09 -0700 |
commit | 81391595dca425ae58e2294898f09f11d9a32dbc (patch) | |
tree | f5d65c39a732150b2b29daa8de98a35d1236d3fb /framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java | |
parent | 0aa37e73dcb3a55b8d889b0c32ff74055551b1f3 (diff) |
bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4
Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f
Diffstat (limited to 'framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java')
-rw-r--r-- | framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java new file mode 100644 index 00000000..c2c37aba --- /dev/null +++ b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java @@ -0,0 +1,101 @@ +/* + * Copyright 2014-2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.cordvtn; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.collect.Sets; +import org.onlab.packet.IpAddress; +import org.onlab.packet.TpPort; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.config.Config; + +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Configuration object for CORD VTN service. + */ +public class CordVtnConfig extends Config<ApplicationId> { + + public static final String OVSDB_NODES = "ovsdbNodes"; + public static final String HOSTNAME = "hostname"; + public static final String IP = "ip"; + public static final String PORT = "port"; + + /** + * Returns the set of ovsdb nodes read from network config. + * + * @return set of OvsdbNodeConfig or null + */ + public Set<OvsdbNodeConfig> ovsdbNodes() { + Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet(); + + JsonNode nodes = object.get(OVSDB_NODES); + if (nodes == null) { + return null; + } + nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig( + jsonNode.path(HOSTNAME).asText(), + IpAddress.valueOf(jsonNode.path(IP).asText()), + TpPort.tpPort(jsonNode.path(PORT).asInt())))); + + return ovsdbNodes; + } + + /** + * Configuration for an OVSDB node. + */ + public static class OvsdbNodeConfig { + + private final String hostname; + private final IpAddress ip; + private final TpPort port; + + public OvsdbNodeConfig(String hostname, IpAddress ip, TpPort port) { + this.hostname = checkNotNull(hostname); + this.ip = checkNotNull(ip); + this.port = checkNotNull(port); + } + + /** + * Returns hostname of the node. + * + * @return hostname + */ + public String hostname() { + return this.hostname; + } + + /** + * Returns ip address to access ovsdb-server of the node. + * + * @return ip address + */ + public IpAddress ip() { + return this.ip; + } + + /** + * Returns port number to access ovsdb-server of the node. + * + * @return port number + */ + public TpPort port() { + return this.port; + } + } +} |