2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.segmentrouting.config;
18 import java.util.ArrayList;
19 import java.util.List;
22 import org.onosproject.net.DeviceId;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.databind.JsonNode;
30 * Public class corresponding to JSON described data model. Defines the network
31 * configuration at startup.
33 public class NetworkConfig {
34 protected static final Logger log = LoggerFactory.getLogger(NetworkConfig.class);
36 @SuppressWarnings("unused")
37 private String comment;
39 private Boolean restrictSwitches;
40 private Boolean restrictLinks;
41 private List<SwitchConfig> switches;
42 private List<LinkConfig> links;
45 * Default constructor.
47 public NetworkConfig() {
48 switches = new ArrayList<>();
49 links = new ArrayList<>();
52 @JsonProperty("comment")
53 public void setComment(String c) {
54 log.trace("NetworkConfig: comment={}", c);
58 @JsonProperty("restrictSwitches")
59 public void setRestrictSwitches(boolean rs) {
60 log.trace("NetworkConfig: restrictSwitches={}", rs);
61 restrictSwitches = rs;
65 * Returns default restrict configuration for switches.
69 public Boolean getRestrictSwitches() {
70 return restrictSwitches;
73 @JsonProperty("restrictLinks")
74 public void setRestrictLinks(boolean rl) {
75 log.trace("NetworkConfig: restrictLinks={}", rl);
80 * Returns default restrict configuration for links.
84 public Boolean getRestrictLinks() {
89 * Returns configuration for switches.
91 * @return list of switch configuration
93 public List<SwitchConfig> getSwitchConfig() {
97 @JsonProperty("switchConfig")
98 public void setSwitchConfig(List<SwitchConfig> switches2) {
99 log.trace("NetworkConfig: switchConfig={}", switches2);
100 this.switches = switches2;
104 * Java class corresponding to JSON described switch
105 * configuration data model.
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;
119 * Returns the configured "name" of a switch.
123 public String getName() {
127 @JsonProperty("name")
128 public void setName(String name) {
129 log.trace("SwitchConfig: name={}", name);
134 * Returns the data plane identifier of a switch.
136 * @return ONOS device identifier
138 public DeviceId getDpid() {
142 public void setDpid(DeviceId dpid) {
144 this.nodeDpid = dpid.toString();
148 * Returns the data plane identifier of a switch.
152 public String getNodeDpid() {
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);
165 * Returns the type of a switch.
169 public String getType() {
173 @JsonProperty("type")
174 public void setType(String type) {
175 log.trace("SwitchConfig: type={}", type);
180 * Returns the latitude of a switch.
184 public double getLatitude() {
188 @JsonProperty("latitude")
189 public void setLatitude(double latitude) {
190 log.trace("SwitchConfig: latitude={}", latitude);
191 this.latitude = latitude;
195 * Returns the longitude of a switch.
199 public double getLongitude() {
203 @JsonProperty("longitude")
204 public void setLongitude(double longitude) {
205 log.trace("SwitchConfig: longitude={}", longitude);
206 this.longitude = longitude;
210 * Returns the allowed flag for a switch.
214 public boolean isAllowed() {
218 @JsonProperty("allowed")
219 public void setAllowed(boolean allowed) {
220 this.allowed = allowed;
224 * Returns the additional configured parameters of a switch.
226 * @return key value map
228 public Map<String, JsonNode> getParams() {
232 @JsonProperty("params")
233 public void setParams(Map<String, JsonNode> params) {
234 this.params = params;
238 * Reserved for future use.
240 * @return key value map
242 public Map<String, String> getPublishAttributes() {
243 return publishAttributes;
246 @JsonProperty("publishAttributes")
247 public void setPublishAttributes(Map<String, String> publishAttributes) {
248 this.publishAttributes = publishAttributes;
253 @JsonProperty("linkConfig")
254 public void setLinkConfig(List<LinkConfig> links2) {
259 * Reserved for future use.
261 * @return list of configured link configuration
263 public List<LinkConfig> getLinkConfig() {
268 * Reserved for future use.
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;
280 public String getType() {
284 public void setType(String type) {
288 public Boolean isAllowed() {
292 public void setAllowed(Boolean allowed) {
293 this.allowed = allowed;
296 public String getNodeDpid1() {
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);
306 public String getNodeDpid2() {
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);
316 public DeviceId getDpid1() {
320 public void setDpid1(DeviceId dpid1) {
322 this.nodeDpid1 = dpid1.toString();
325 public DeviceId getDpid2() {
329 public void setDpid2(DeviceId dpid2) {
331 this.nodeDpid2 = dpid2.toString();
334 public Map<String, JsonNode> getParams() {
338 public void setParams(Map<String, JsonNode> params) {
339 this.params = params;
342 public Map<String, String> getPublishAttributes() {
343 return publishAttributes;
346 public void setPublishAttributes(Map<String, String> publishAttributes) {
347 this.publishAttributes = publishAttributes;