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 | /** |
| 30 | * Configuration object for CORD VTN service. |
| 31 | */ |
| 32 | public class CordVtnConfig extends Config<ApplicationId> { |
| 33 | |
| 34 | public static final String OVSDB_NODES = "ovsdbNodes"; |
| 35 | public static final String HOSTNAME = "hostname"; |
| 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( |
| 52 | jsonNode.path(HOSTNAME).asText(), |
| 53 | IpAddress.valueOf(jsonNode.path(IP).asText()), |
| 54 | TpPort.tpPort(jsonNode.path(PORT).asInt())))); |
| 55 | |
| 56 | return ovsdbNodes; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Configuration for an OVSDB node. |
| 61 | */ |
| 62 | public static class OvsdbNodeConfig { |
| 63 | |
| 64 | private final String hostname; |
| 65 | private final IpAddress ip; |
| 66 | private final TpPort port; |
| 67 | |
| 68 | public OvsdbNodeConfig(String hostname, IpAddress ip, TpPort port) { |
| 69 | this.hostname = checkNotNull(hostname); |
| 70 | this.ip = checkNotNull(ip); |
| 71 | this.port = checkNotNull(port); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns hostname of the node. |
| 76 | * |
| 77 | * @return hostname |
| 78 | */ |
| 79 | public String hostname() { |
| 80 | return this.hostname; |
| 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 | } |