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