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 | */ |
| 16 | package org.onosproject.incubator.net.config.basics; |
| 17 | |
| 18 | import org.onosproject.net.Link; |
| 19 | import org.onosproject.net.LinkKey; |
| 20 | |
| 21 | import java.time.Duration; |
| 22 | |
| 23 | /** |
| 24 | * Basic configuration for network infrastructure link. |
| 25 | */ |
| 26 | public class BasicLinkConfig extends AllowedEntityConfig<LinkKey> { |
| 27 | |
| 28 | public static final String TYPE = "type"; |
| 29 | public static final String LATENCY = "latency"; |
| 30 | public static final String BANDWIDTH = "bandwidth"; |
| 31 | |
| 32 | /** |
| 33 | * Returns the link type. |
| 34 | * |
| 35 | * @return link type override |
| 36 | */ |
| 37 | public Link.Type type() { |
| 38 | return get(TYPE, Link.Type.DIRECT, Link.Type.class); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Sets the link type. |
| 43 | * |
| 44 | * @param type link type override |
| 45 | * @return self |
| 46 | */ |
| 47 | public BasicLinkConfig type(Link.Type type) { |
| 48 | return (BasicLinkConfig) setOrClear(TYPE, type); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns link latency in terms of nanos. |
| 53 | * |
| 54 | * @return link latency; -1 if not set |
| 55 | */ |
| 56 | public Duration latency() { |
| 57 | return Duration.ofNanos(get(LATENCY, -1)); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Sets the link latency. |
| 62 | * |
| 63 | * @param latency new latency; null to clear |
| 64 | * @return self |
| 65 | */ |
| 66 | public BasicElementConfig latency(Duration latency) { |
| 67 | Long nanos = latency == null ? null : latency.toNanos(); |
| 68 | return (BasicElementConfig) setOrClear(LATENCY, nanos); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns link bandwidth in terms of Mbps. |
| 73 | * |
| 74 | * @return link bandwidth; -1 if not set |
| 75 | */ |
| 76 | public long bandwidth() { |
| 77 | return get(BANDWIDTH, -1); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Sets the link bandwidth. |
| 82 | * |
| 83 | * @param bandwidth new bandwidth; null to clear |
| 84 | * @return self |
| 85 | */ |
| 86 | public BasicElementConfig bandwidth(Long bandwidth) { |
| 87 | return (BasicElementConfig) setOrClear(BANDWIDTH, bandwidth); |
| 88 | } |
| 89 | |
| 90 | } |