blob: e962110c47bd9cda3e95faf5d3ef2fdd7c450287 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
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 */
Thomas Vachuska4998caa2015-08-26 13:28:38 -070016package org.onosproject.net.config.basics;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070017
18import org.onosproject.net.Link;
19import org.onosproject.net.LinkKey;
Ayaka Koshibe2c59acf2015-09-08 15:37:47 -070020import com.fasterxml.jackson.databind.JsonNode;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070021
22import java.time.Duration;
23
24/**
25 * Basic configuration for network infrastructure link.
26 */
27public class BasicLinkConfig extends AllowedEntityConfig<LinkKey> {
28
29 public static final String TYPE = "type";
30 public static final String LATENCY = "latency";
31 public static final String BANDWIDTH = "bandwidth";
Ayaka Koshibe2c59acf2015-09-08 15:37:47 -070032 public static final String IS_DURABLE = "durable";
Thomas Vachuska96d55b12015-05-11 08:52:03 -070033
34 /**
35 * Returns the link type.
36 *
37 * @return link type override
38 */
39 public Link.Type type() {
40 return get(TYPE, Link.Type.DIRECT, Link.Type.class);
41 }
42
43 /**
44 * Sets the link type.
45 *
46 * @param type link type override
47 * @return self
48 */
49 public BasicLinkConfig type(Link.Type type) {
50 return (BasicLinkConfig) setOrClear(TYPE, type);
51 }
52
53 /**
54 * Returns link latency in terms of nanos.
55 *
56 * @return link latency; -1 if not set
57 */
58 public Duration latency() {
59 return Duration.ofNanos(get(LATENCY, -1));
60 }
61
62 /**
63 * Sets the link latency.
64 *
65 * @param latency new latency; null to clear
66 * @return self
67 */
Ayaka Koshibecc260d22015-08-04 17:13:38 -070068 public BasicLinkConfig latency(Duration latency) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070069 Long nanos = latency == null ? null : latency.toNanos();
Ayaka Koshibecc260d22015-08-04 17:13:38 -070070 return (BasicLinkConfig) setOrClear(LATENCY, nanos);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070071 }
72
73 /**
74 * Returns link bandwidth in terms of Mbps.
75 *
76 * @return link bandwidth; -1 if not set
77 */
78 public long bandwidth() {
79 return get(BANDWIDTH, -1);
80 }
81
82 /**
83 * Sets the link bandwidth.
84 *
85 * @param bandwidth new bandwidth; null to clear
86 * @return self
87 */
Ayaka Koshibecc260d22015-08-04 17:13:38 -070088 public BasicLinkConfig bandwidth(Long bandwidth) {
89 return (BasicLinkConfig) setOrClear(BANDWIDTH, bandwidth);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070090 }
91
Ayaka Koshibe2c59acf2015-09-08 15:37:47 -070092 /**
93 * Returns if link is durable in the network model or not.
94 *
95 * @return true for durable, false otherwise
96 */
97 public Boolean isDurable() {
98 JsonNode res = object.path(IS_DURABLE);
99 if (res.isMissingNode()) {
100 return null;
101 }
102 return res.asBoolean();
103 }
104
105 /**
106 * Sets durability for this link.
107 *
108 * @param isDurable true for durable, false otherwise
109 * @return this BasicLinkConfig
110 */
111 public BasicLinkConfig isDurable(Boolean isDurable) {
112 return (BasicLinkConfig) setOrClear(IS_DURABLE, isDurable);
113 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700114}