Thomas Vachuska | 8fd2505 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | */ |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 16 | package org.onosproject.segmentrouting.config; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 27 | import com.fasterxml.jackson.databind.JsonNode; |
| 28 | |
| 29 | /** |
| 30 | * Public class corresponding to JSON described data model. Defines the network |
| 31 | * configuration at startup. |
| 32 | */ |
| 33 | public class NetworkConfig { |
| 34 | protected static final Logger log = LoggerFactory.getLogger(NetworkConfig.class); |
| 35 | |
| 36 | @SuppressWarnings("unused") |
| 37 | private String comment; |
| 38 | |
| 39 | private Boolean restrictSwitches; |
| 40 | private Boolean restrictLinks; |
| 41 | private List<SwitchConfig> switches; |
| 42 | private List<LinkConfig> links; |
| 43 | |
| 44 | /** |
| 45 | * Default constructor. |
| 46 | */ |
| 47 | public NetworkConfig() { |
| 48 | switches = new ArrayList<SwitchConfig>(); |
| 49 | links = new ArrayList<LinkConfig>(); |
| 50 | } |
| 51 | |
| 52 | @JsonProperty("comment") |
| 53 | public void setComment(String c) { |
| 54 | log.trace("NetworkConfig: comment={}", c); |
| 55 | comment = c; |
| 56 | } |
| 57 | |
| 58 | @JsonProperty("restrictSwitches") |
| 59 | public void setRestrictSwitches(boolean rs) { |
| 60 | log.trace("NetworkConfig: restrictSwitches={}", rs); |
| 61 | restrictSwitches = rs; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns default restrict configuration for switches. |
| 66 | * |
| 67 | * @return boolean |
| 68 | */ |
| 69 | public Boolean getRestrictSwitches() { |
| 70 | return restrictSwitches; |
| 71 | } |
| 72 | |
| 73 | @JsonProperty("restrictLinks") |
| 74 | public void setRestrictLinks(boolean rl) { |
| 75 | log.trace("NetworkConfig: restrictLinks={}", rl); |
| 76 | restrictLinks = rl; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns default restrict configuration for links. |
| 81 | * |
| 82 | * @return boolean |
| 83 | */ |
| 84 | public Boolean getRestrictLinks() { |
| 85 | return restrictLinks; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns configuration for switches. |
| 90 | * |
| 91 | * @return list of switch configuration |
| 92 | */ |
| 93 | public List<SwitchConfig> getSwitchConfig() { |
| 94 | return switches; |
| 95 | } |
| 96 | |
| 97 | @JsonProperty("switchConfig") |
| 98 | public void setSwitchConfig(List<SwitchConfig> switches2) { |
| 99 | log.trace("NetworkConfig: switchConfig={}", switches2); |
| 100 | this.switches = switches2; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Java class corresponding to JSON described switch |
| 105 | * configuration data model. |
| 106 | */ |
| 107 | public static class SwitchConfig { |
| 108 | protected String nodeDpid; |
| 109 | protected String name; |
| 110 | protected String type; |
| 111 | protected boolean allowed; |
| 112 | protected double latitude; |
| 113 | protected double longitude; |
| 114 | protected Map<String, JsonNode> params; |
| 115 | protected Map<String, String> publishAttributes; |
| 116 | protected DeviceId dpid; |
| 117 | |
| 118 | /** |
| 119 | * Returns the configured "name" of a switch. |
| 120 | * |
| 121 | * @return string |
| 122 | */ |
| 123 | public String getName() { |
| 124 | return name; |
| 125 | } |
| 126 | |
| 127 | @JsonProperty("name") |
| 128 | public void setName(String name) { |
| 129 | log.trace("SwitchConfig: name={}", name); |
| 130 | this.name = name; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Returns the data plane identifier of a switch. |
| 135 | * |
| 136 | * @return ONOS device identifier |
| 137 | */ |
| 138 | public DeviceId getDpid() { |
| 139 | return dpid; |
| 140 | } |
| 141 | |
| 142 | public void setDpid(DeviceId dpid) { |
| 143 | this.dpid = dpid; |
| 144 | this.nodeDpid = dpid.toString(); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Returns the data plane identifier of a switch. |
| 149 | * |
| 150 | * @return string |
| 151 | */ |
| 152 | public String getNodeDpid() { |
| 153 | return nodeDpid; |
| 154 | } |
| 155 | |
| 156 | // mapper sets both DeviceId and string fields for dpid |
| 157 | @JsonProperty("nodeDpid") |
| 158 | public void setNodeDpid(String nodeDpid) { |
| 159 | log.trace("SwitchConfig: nodeDpid={}", nodeDpid); |
| 160 | this.nodeDpid = nodeDpid; |
| 161 | this.dpid = DeviceId.deviceId(nodeDpid); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns the type of a switch. |
| 166 | * |
| 167 | * @return string |
| 168 | */ |
| 169 | public String getType() { |
| 170 | return type; |
| 171 | } |
| 172 | |
| 173 | @JsonProperty("type") |
| 174 | public void setType(String type) { |
| 175 | log.trace("SwitchConfig: type={}", type); |
| 176 | this.type = type; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns the latitude of a switch. |
| 181 | * |
| 182 | * @return double |
| 183 | */ |
| 184 | public double getLatitude() { |
| 185 | return latitude; |
| 186 | } |
| 187 | |
| 188 | @JsonProperty("latitude") |
| 189 | public void setLatitude(double latitude) { |
| 190 | log.trace("SwitchConfig: latitude={}", latitude); |
| 191 | this.latitude = latitude; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns the longitude of a switch. |
| 196 | * |
| 197 | * @return double |
| 198 | */ |
| 199 | public double getLongitude() { |
| 200 | return longitude; |
| 201 | } |
| 202 | |
| 203 | @JsonProperty("longitude") |
| 204 | public void setLongitude(double longitude) { |
| 205 | log.trace("SwitchConfig: longitude={}", longitude); |
| 206 | this.longitude = longitude; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Returns the allowed flag for a switch. |
| 211 | * |
| 212 | * @return boolean |
| 213 | */ |
| 214 | public boolean isAllowed() { |
| 215 | return allowed; |
| 216 | } |
| 217 | |
| 218 | @JsonProperty("allowed") |
| 219 | public void setAllowed(boolean allowed) { |
| 220 | this.allowed = allowed; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Returns the additional configured parameters of a switch. |
| 225 | * |
| 226 | * @return key value map |
| 227 | */ |
| 228 | public Map<String, JsonNode> getParams() { |
| 229 | return params; |
| 230 | } |
| 231 | |
| 232 | @JsonProperty("params") |
| 233 | public void setParams(Map<String, JsonNode> params) { |
| 234 | this.params = params; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Reserved for future use. |
| 239 | * |
| 240 | * @return key value map |
| 241 | */ |
| 242 | public Map<String, String> getPublishAttributes() { |
| 243 | return publishAttributes; |
| 244 | } |
| 245 | |
| 246 | @JsonProperty("publishAttributes") |
| 247 | public void setPublishAttributes(Map<String, String> publishAttributes) { |
| 248 | this.publishAttributes = publishAttributes; |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | |
| 253 | @JsonProperty("linkConfig") |
| 254 | public void setLinkConfig(List<LinkConfig> links2) { |
| 255 | this.links = links2; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Reserved for future use. |
| 260 | * |
| 261 | * @return list of configured link configuration |
| 262 | */ |
| 263 | public List<LinkConfig> getLinkConfig() { |
| 264 | return links; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Reserved for future use. |
| 269 | */ |
| 270 | public static class LinkConfig { |
| 271 | protected String type; |
| 272 | protected Boolean allowed; |
| 273 | protected DeviceId dpid1; |
| 274 | protected DeviceId dpid2; |
| 275 | protected String nodeDpid1; |
| 276 | protected String nodeDpid2; |
| 277 | protected Map<String, JsonNode> params; |
| 278 | protected Map<String, String> publishAttributes; |
| 279 | |
| 280 | public String getType() { |
| 281 | return type; |
| 282 | } |
| 283 | |
| 284 | public void setType(String type) { |
| 285 | this.type = type; |
| 286 | } |
| 287 | |
| 288 | public Boolean isAllowed() { |
| 289 | return allowed; |
| 290 | } |
| 291 | |
| 292 | public void setAllowed(Boolean allowed) { |
| 293 | this.allowed = allowed; |
| 294 | } |
| 295 | |
| 296 | public String getNodeDpid1() { |
| 297 | return nodeDpid1; |
| 298 | } |
| 299 | |
| 300 | // mapper sets both long and string fields for dpid |
| 301 | public void setNodeDpid1(String nodeDpid1) { |
| 302 | this.nodeDpid1 = nodeDpid1; |
| 303 | this.dpid1 = DeviceId.deviceId(nodeDpid1); |
| 304 | } |
| 305 | |
| 306 | public String getNodeDpid2() { |
| 307 | return nodeDpid2; |
| 308 | } |
| 309 | |
| 310 | // mapper sets both long and string fields for dpid |
| 311 | public void setNodeDpid2(String nodeDpid2) { |
| 312 | this.nodeDpid2 = nodeDpid2; |
| 313 | this.dpid2 = DeviceId.deviceId(nodeDpid2); |
| 314 | } |
| 315 | |
| 316 | public DeviceId getDpid1() { |
| 317 | return dpid1; |
| 318 | } |
| 319 | |
| 320 | public void setDpid1(DeviceId dpid1) { |
| 321 | this.dpid1 = dpid1; |
| 322 | this.nodeDpid1 = dpid1.toString(); |
| 323 | } |
| 324 | |
| 325 | public DeviceId getDpid2() { |
| 326 | return dpid2; |
| 327 | } |
| 328 | |
| 329 | public void setDpid2(DeviceId dpid2) { |
| 330 | this.dpid2 = dpid2; |
| 331 | this.nodeDpid2 = dpid2.toString(); |
| 332 | } |
| 333 | |
| 334 | public Map<String, JsonNode> getParams() { |
| 335 | return params; |
| 336 | } |
| 337 | |
| 338 | public void setParams(Map<String, JsonNode> params) { |
| 339 | this.params = params; |
| 340 | } |
| 341 | |
| 342 | public Map<String, String> getPublishAttributes() { |
| 343 | return publishAttributes; |
| 344 | } |
| 345 | |
| 346 | public void setPublishAttributes(Map<String, String> publishAttributes) { |
| 347 | this.publishAttributes = publishAttributes; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |