Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cordvtn; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.TpPort; |
| 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 30 | * Configuration object for CordVtn service. |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 31 | */ |
| 32 | public class CordVtnConfig extends Config<ApplicationId> { |
| 33 | |
| 34 | public static final String OVSDB_NODES = "ovsdbNodes"; |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 35 | public static final String HOST = "host"; |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 36 | public static final String IP = "ip"; |
| 37 | public static final String PORT = "port"; |
| 38 | |
| 39 | /** |
| 40 | * Returns the set of ovsdb nodes read from network config. |
| 41 | * |
| 42 | * @return set of OvsdbNodeConfig or null |
| 43 | */ |
| 44 | public Set<OvsdbNodeConfig> ovsdbNodes() { |
| 45 | Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet(); |
| 46 | |
| 47 | JsonNode nodes = object.get(OVSDB_NODES); |
| 48 | if (nodes == null) { |
| 49 | return null; |
| 50 | } |
| 51 | nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig( |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 52 | jsonNode.path(HOST).asText(), |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 53 | IpAddress.valueOf(jsonNode.path(IP).asText()), |
| 54 | TpPort.tpPort(jsonNode.path(PORT).asInt())))); |
| 55 | |
| 56 | return ovsdbNodes; |
| 57 | } |
| 58 | |
| 59 | /** |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 60 | * Configuration for an ovsdb node. |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 61 | */ |
| 62 | public static class OvsdbNodeConfig { |
| 63 | |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 64 | private final String host; |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 65 | private final IpAddress ip; |
| 66 | private final TpPort port; |
| 67 | |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 68 | public OvsdbNodeConfig(String host, IpAddress ip, TpPort port) { |
| 69 | this.host = checkNotNull(host); |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 70 | this.ip = checkNotNull(ip); |
| 71 | this.port = checkNotNull(port); |
| 72 | } |
| 73 | |
| 74 | /** |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 75 | * Returns host information of the node. |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 76 | * |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 77 | * @return host |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 78 | */ |
Hyunsun Moon | 2b53032 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 79 | public String host() { |
| 80 | return this.host; |
Hyunsun Moon | d0e932a | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns ip address to access ovsdb-server of the node. |
| 85 | * |
| 86 | * @return ip address |
| 87 | */ |
| 88 | public IpAddress ip() { |
| 89 | return this.ip; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns port number to access ovsdb-server of the node. |
| 94 | * |
| 95 | * @return port number |
| 96 | */ |
| 97 | public TpPort port() { |
| 98 | return this.port; |
| 99 | } |
| 100 | } |
| 101 | } |