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; |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 21 | import org.onlab.packet.MacAddress; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 22 | import org.onlab.packet.TpPort; |
| 23 | import org.onosproject.core.ApplicationId; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 24 | import org.onosproject.net.DeviceId; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 25 | import org.onosproject.net.config.Config; |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 26 | import org.slf4j.Logger; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 27 | |
| 28 | import java.util.Set; |
| 29 | |
| 30 | import static com.google.common.base.Preconditions.checkNotNull; |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 31 | import static org.slf4j.LoggerFactory.getLogger; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 34 | * Configuration object for CordVtn service. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 35 | */ |
| 36 | public class CordVtnConfig extends Config<ApplicationId> { |
| 37 | |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 38 | protected final Logger log = getLogger(getClass()); |
| 39 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 40 | public static final String CORDVTN_NODES = "nodes"; |
| 41 | public static final String HOSTNAME = "hostname"; |
| 42 | public static final String OVSDB_IP = "ovsdbIp"; |
| 43 | public static final String OVSDB_PORT = "ovsdbPort"; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 44 | public static final String BRIDGE_ID = "bridgeId"; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 45 | public static final String PHYSICAL_PORT_NAME = "phyPortName"; |
| 46 | public static final String LOCAL_IP = "localIp"; |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 47 | public static final String GATEWAY_MAC = "gatewayMac"; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 50 | * Returns the set of nodes read from network config. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 51 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 52 | * @return set of CordVtnNodeConfig or null |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 53 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 54 | public Set<CordVtnNodeConfig> cordVtnNodes() { |
| 55 | Set<CordVtnNodeConfig> nodes = Sets.newHashSet(); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 56 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 57 | JsonNode jsonNodes = object.get(CORDVTN_NODES); |
| 58 | if (jsonNodes == null) { |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 59 | return null; |
| 60 | } |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 61 | jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( |
| 62 | jsonNode.path(HOSTNAME).asText(), |
| 63 | IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), |
| 64 | TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 65 | DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()), |
| 66 | jsonNode.path(PHYSICAL_PORT_NAME).asText(), |
| 67 | IpAddress.valueOf(jsonNode.path(LOCAL_IP).asText())))); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 68 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 69 | return nodes; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 73 | * Returns gateway MAC address. |
| 74 | * |
| 75 | * @return mac address, or null |
| 76 | */ |
| 77 | public MacAddress gatewayMac() { |
| 78 | JsonNode jsonNode = object.get(GATEWAY_MAC); |
| 79 | if (jsonNode == null) { |
| 80 | return null; |
| 81 | } |
| 82 | |
| 83 | try { |
| 84 | return MacAddress.valueOf(jsonNode.asText()); |
| 85 | } catch (IllegalArgumentException e) { |
| 86 | log.error("Wrong MAC address format {}", jsonNode.asText()); |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 92 | * Configuration for CordVtn node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 93 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 94 | public static class CordVtnNodeConfig { |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 95 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 96 | private final String hostname; |
| 97 | private final IpAddress ovsdbIp; |
| 98 | private final TpPort ovsdbPort; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 99 | private final DeviceId bridgeId; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 100 | private final String phyPortName; |
| 101 | private final IpAddress localIp; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 102 | |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 103 | public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, |
| 104 | DeviceId bridgeId, String phyPortName, IpAddress localIp) { |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 105 | this.hostname = checkNotNull(hostname); |
| 106 | this.ovsdbIp = checkNotNull(ovsdbIp); |
| 107 | this.ovsdbPort = checkNotNull(ovsdbPort); |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 108 | this.bridgeId = checkNotNull(bridgeId); |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 109 | this.phyPortName = checkNotNull(phyPortName); |
| 110 | this.localIp = checkNotNull(localIp); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 114 | * Returns hostname of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 115 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 116 | * @return hostname |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 117 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 118 | public String hostname() { |
| 119 | return this.hostname; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 123 | * Returns OVSDB ip address of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 124 | * |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 125 | * @return OVSDB server IP address |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 126 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 127 | public IpAddress ovsdbIp() { |
| 128 | return this.ovsdbIp; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 132 | * Returns OVSDB port number of the node. |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 133 | * |
| 134 | * @return port number |
| 135 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 136 | public TpPort ovsdbPort() { |
| 137 | return this.ovsdbPort; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 138 | } |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 139 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Returns integration bridge id of the node. |
| 142 | * |
| 143 | * @return device id |
| 144 | */ |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 145 | public DeviceId bridgeId() { |
| 146 | return this.bridgeId; |
| 147 | } |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Returns physical port name. |
| 151 | * |
| 152 | * @return physical port name |
| 153 | */ |
| 154 | public String phyPortName() { |
| 155 | return this.phyPortName; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns local IP address. |
| 160 | * |
| 161 | * @return ip address |
| 162 | */ |
| 163 | public IpAddress localIp() { |
| 164 | return this.localIp; |
| 165 | } |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 166 | } |
| 167 | } |