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