Hyunsun Moon | e9d7599 | 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 | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
Hyunsun Moon | e9d7599 | 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 | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 31 | * Configuration object for CordVtn service. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 32 | */ |
| 33 | public class CordVtnConfig extends Config<ApplicationId> { |
| 34 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 35 | public static final String CORDVTN_NODES = "nodes"; |
| 36 | public static final String HOSTNAME = "hostname"; |
| 37 | public static final String OVSDB_IP = "ovsdbIp"; |
| 38 | public static final String OVSDB_PORT = "ovsdbPort"; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 39 | public static final String BRIDGE_ID = "bridgeId"; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 42 | * Returns the set of nodes read from network config. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 43 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 44 | * @return set of CordVtnNodeConfig or null |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 45 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 46 | public Set<CordVtnNodeConfig> cordVtnNodes() { |
| 47 | Set<CordVtnNodeConfig> nodes = Sets.newHashSet(); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 48 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 49 | JsonNode jsonNodes = object.get(CORDVTN_NODES); |
| 50 | if (jsonNodes == null) { |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 51 | return null; |
| 52 | } |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 53 | jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( |
| 54 | jsonNode.path(HOSTNAME).asText(), |
| 55 | IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), |
| 56 | TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 57 | DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())))); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 58 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 59 | return nodes; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 63 | * Configuration for CordVtn node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 64 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 65 | public static class CordVtnNodeConfig { |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 66 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 67 | private final String hostname; |
| 68 | private final IpAddress ovsdbIp; |
| 69 | private final TpPort ovsdbPort; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 70 | private final DeviceId bridgeId; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 71 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 72 | public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) { |
| 73 | this.hostname = checkNotNull(hostname); |
| 74 | this.ovsdbIp = checkNotNull(ovsdbIp); |
| 75 | this.ovsdbPort = checkNotNull(ovsdbPort); |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 76 | this.bridgeId = checkNotNull(bridgeId); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 80 | * Returns hostname of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 81 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 82 | * @return hostname |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 83 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 84 | public String hostname() { |
| 85 | return this.hostname; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 89 | * Returns OVSDB ip address of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 90 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 91 | * @return OVSDB server IP address |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 92 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 93 | public IpAddress ovsdbIp() { |
| 94 | return this.ovsdbIp; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 98 | * Returns OVSDB port number of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 99 | * |
| 100 | * @return port number |
| 101 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 102 | public TpPort ovsdbPort() { |
| 103 | return this.ovsdbPort; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 104 | } |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 105 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Returns integration bridge id of the node. |
| 108 | * |
| 109 | * @return device id |
| 110 | */ |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 111 | public DeviceId bridgeId() { |
| 112 | return this.bridgeId; |
| 113 | } |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 114 | } |
| 115 | } |