1 package org.onosproject.segmentrouting.config;
 
   3 import java.util.ArrayList;
 
   7 import org.onosproject.net.DeviceId;
 
   8 import org.slf4j.Logger;
 
   9 import org.slf4j.LoggerFactory;
 
  11 import com.fasterxml.jackson.annotation.JsonProperty;
 
  12 import com.fasterxml.jackson.databind.JsonNode;
 
  15  * Public class corresponding to JSON described data model. Defines the network
 
  16  * configuration at startup.
 
  18 public class NetworkConfig {
 
  19     protected static final Logger log = LoggerFactory.getLogger(NetworkConfig.class);
 
  21     @SuppressWarnings("unused")
 
  22     private String comment;
 
  24     private Boolean restrictSwitches;
 
  25     private Boolean restrictLinks;
 
  26     private List<SwitchConfig> switches;
 
  27     private List<LinkConfig> links;
 
  30      * Default constructor.
 
  32     public NetworkConfig() {
 
  33         switches = new ArrayList<SwitchConfig>();
 
  34         links = new ArrayList<LinkConfig>();
 
  37     @JsonProperty("comment")
 
  38     public void setComment(String c) {
 
  39         log.trace("NetworkConfig: comment={}", c);
 
  43     @JsonProperty("restrictSwitches")
 
  44     public void setRestrictSwitches(boolean rs) {
 
  45         log.trace("NetworkConfig: restrictSwitches={}", rs);
 
  46         restrictSwitches = rs;
 
  50      * Returns default restrict configuration for switches.
 
  54     public Boolean getRestrictSwitches() {
 
  55         return restrictSwitches;
 
  58     @JsonProperty("restrictLinks")
 
  59     public void setRestrictLinks(boolean rl) {
 
  60         log.trace("NetworkConfig: restrictLinks={}", rl);
 
  65      * Returns default restrict configuration for links.
 
  69     public Boolean getRestrictLinks() {
 
  74      * Returns configuration for switches.
 
  76      * @return list of switch configuration
 
  78     public List<SwitchConfig> getSwitchConfig() {
 
  82     @JsonProperty("switchConfig")
 
  83     public void setSwitchConfig(List<SwitchConfig> switches2) {
 
  84         log.trace("NetworkConfig: switchConfig={}", switches2);
 
  85         this.switches = switches2;
 
  89      * Java class corresponding to JSON described switch
 
  90      * configuration data model.
 
  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;
 
 104          * Returns the configured "name" of a switch.
 
 108         public String getName() {
 
 112         @JsonProperty("name")
 
 113         public void setName(String name) {
 
 114             log.trace("SwitchConfig: name={}", name);
 
 119          * Returns the data plane identifier of a switch.
 
 121          * @return ONOS device identifier
 
 123         public DeviceId getDpid() {
 
 127         public void setDpid(DeviceId dpid) {
 
 129             this.nodeDpid = dpid.toString();
 
 133          * Returns the data plane identifier of a switch.
 
 137         public String getNodeDpid() {
 
 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);
 
 150          * Returns the type of a switch.
 
 154         public String getType() {
 
 158         @JsonProperty("type")
 
 159         public void setType(String type) {
 
 160             log.trace("SwitchConfig: type={}", type);
 
 165          * Returns the latitude of a switch.
 
 169         public double getLatitude() {
 
 173         @JsonProperty("latitude")
 
 174         public void setLatitude(double latitude) {
 
 175             log.trace("SwitchConfig: latitude={}", latitude);
 
 176             this.latitude = latitude;
 
 180          * Returns the longitude of a switch.
 
 184         public double getLongitude() {
 
 188         @JsonProperty("longitude")
 
 189         public void setLongitude(double longitude) {
 
 190             log.trace("SwitchConfig: longitude={}", longitude);
 
 191             this.longitude = longitude;
 
 195          * Returns the allowed flag for a switch.
 
 199         public boolean isAllowed() {
 
 203         @JsonProperty("allowed")
 
 204         public void setAllowed(boolean allowed) {
 
 205             this.allowed = allowed;
 
 209          * Returns the additional configured parameters of a switch.
 
 211          * @return key value map
 
 213         public Map<String, JsonNode> getParams() {
 
 217         @JsonProperty("params")
 
 218         public void setParams(Map<String, JsonNode> params) {
 
 219             this.params = params;
 
 223          * Reserved for future use.
 
 225          * @return key value map
 
 227         public Map<String, String> getPublishAttributes() {
 
 228             return publishAttributes;
 
 231         @JsonProperty("publishAttributes")
 
 232         public void setPublishAttributes(Map<String, String> publishAttributes) {
 
 233             this.publishAttributes = publishAttributes;
 
 238     @JsonProperty("linkConfig")
 
 239     public void setLinkConfig(List<LinkConfig> links2) {
 
 244      * Reserved for future use.
 
 246      * @return list of configured link configuration
 
 248     public List<LinkConfig> getLinkConfig() {
 
 253      * Reserved for future use.
 
 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;
 
 265         public String getType() {
 
 269         public void setType(String type) {
 
 273         public Boolean isAllowed() {
 
 277         public void setAllowed(Boolean allowed) {
 
 278             this.allowed = allowed;
 
 281         public String getNodeDpid1() {
 
 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);
 
 291         public String getNodeDpid2() {
 
 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);
 
 301         public DeviceId getDpid1() {
 
 305         public void setDpid1(DeviceId dpid1) {
 
 307             this.nodeDpid1 = dpid1.toString();
 
 310         public DeviceId getDpid2() {
 
 314         public void setDpid2(DeviceId dpid2) {
 
 316             this.nodeDpid2 = dpid2.toString();
 
 319         public Map<String, JsonNode> getParams() {
 
 323         public void setParams(Map<String, JsonNode> params) {
 
 324             this.params = params;
 
 327         public Map<String, String> getPublishAttributes() {
 
 328             return publishAttributes;
 
 331         public void setPublishAttributes(Map<String, String> publishAttributes) {
 
 332             this.publishAttributes = publishAttributes;