Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -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 | */ |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.net.Link; |
| 19 | import org.onosproject.net.LinkKey; |
Ayaka Koshibe | 2c59acf | 2015-09-08 15:37:47 -0700 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.JsonNode; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | |
| 22 | import java.time.Duration; |
| 23 | |
| 24 | /** |
| 25 | * Basic configuration for network infrastructure link. |
| 26 | */ |
| 27 | public 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 Koshibe | 2c59acf | 2015-09-08 15:37:47 -0700 | [diff] [blame] | 32 | public static final String IS_DURABLE = "durable"; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 33 | |
| 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 Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 68 | public BasicLinkConfig latency(Duration latency) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 69 | Long nanos = latency == null ? null : latency.toNanos(); |
Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 70 | return (BasicLinkConfig) setOrClear(LATENCY, nanos); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 71 | } |
| 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 Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 88 | public BasicLinkConfig bandwidth(Long bandwidth) { |
| 89 | return (BasicLinkConfig) setOrClear(BANDWIDTH, bandwidth); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Ayaka Koshibe | 2c59acf | 2015-09-08 15:37:47 -0700 | [diff] [blame] | 92 | /** |
| 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 Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 114 | } |