mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 18:32:28 +02:00
Added metered annotation to link
Change-Id: Ief7410d442e8e1c556cc97c0578aa5d717a7b127
This commit is contained in:
parent
2786122009
commit
0843f5d375
@ -241,6 +241,12 @@ public final class AnnotationKeys {
|
||||
*/
|
||||
public static final String FLAPPING = "flapping";
|
||||
|
||||
/**
|
||||
* Annotation key for identifying a metered link.
|
||||
* The value of this key is expected to be a boolean for metered as true/false.
|
||||
*/
|
||||
public static final String METERED = "metered";
|
||||
|
||||
/**
|
||||
* Returns the value annotated object for the specified annotation key.
|
||||
* The annotated value is expected to be String that can be parsed as double.
|
||||
|
@ -48,6 +48,7 @@ public final class BasicLinkConfig extends AllowedEntityConfig<LinkKey> {
|
||||
public static final String FLAPPING = "flapping";
|
||||
public static final String IS_DURABLE = "durable";
|
||||
public static final String IS_BIDIRECTIONAL = "bidirectional";
|
||||
public static final String IS_METERED = "metered";
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
@ -55,12 +56,13 @@ public final class BasicLinkConfig extends AllowedEntityConfig<LinkKey> {
|
||||
type();
|
||||
|
||||
return hasOnlyFields(ALLOWED, TYPE, METRIC, LATENCY, BANDWIDTH, JITTER, DELAY, LOSS, AVAILABILITY, FLAPPING,
|
||||
IS_DURABLE, IS_BIDIRECTIONAL) &&
|
||||
IS_DURABLE, IS_BIDIRECTIONAL, IS_METERED) &&
|
||||
isBoolean(ALLOWED, OPTIONAL) && isNumber(METRIC, OPTIONAL) &&
|
||||
isNumber(LATENCY, OPTIONAL) && isNumber(BANDWIDTH, OPTIONAL) && isDecimal(JITTER, OPTIONAL) &&
|
||||
isDecimal(DELAY, OPTIONAL) && isDecimal(LOSS, OPTIONAL) && isDecimal(AVAILABILITY, OPTIONAL) &&
|
||||
isDecimal(FLAPPING, OPTIONAL) &&
|
||||
isBoolean(IS_BIDIRECTIONAL, OPTIONAL);
|
||||
isBoolean(IS_BIDIRECTIONAL, OPTIONAL) &&
|
||||
isBoolean(IS_METERED, OPTIONAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,6 +308,29 @@ public final class BasicLinkConfig extends AllowedEntityConfig<LinkKey> {
|
||||
return (BasicLinkConfig) setOrClear(FLAPPING, flapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if link is metered in the network model or not.
|
||||
*
|
||||
* @return true for metered, false otherwise
|
||||
*/
|
||||
public Boolean isMetered() {
|
||||
JsonNode res = object.path(IS_METERED);
|
||||
if (res.isMissingNode()) {
|
||||
return true;
|
||||
}
|
||||
return res.asBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets durability for this link.
|
||||
*
|
||||
* @param isMetered true for metered, false otherwise
|
||||
* @return this BasicLinkConfig
|
||||
*/
|
||||
public BasicLinkConfig isMetered(Boolean isMetered) {
|
||||
return (BasicLinkConfig) setOrClear(IS_METERED, isMetered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link BasicLinkConfig} instance.
|
||||
* <p>
|
||||
|
@ -26,6 +26,7 @@ import org.onosproject.net.config.ConfigApplyDelegate;
|
||||
import java.time.Duration;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ -68,7 +69,8 @@ public class BasicLinkConfigTest {
|
||||
.metric(METRIC)
|
||||
.type(Link.Type.DIRECT)
|
||||
.latency(LATENCY)
|
||||
.isBidirectional(FALSE);
|
||||
.isBidirectional(FALSE)
|
||||
.isMetered(TRUE);
|
||||
|
||||
assertThat(config.bandwidth(), is(BANDWIDTH));
|
||||
assertThat(config.jitter(), is(JITTER));
|
||||
@ -82,5 +84,6 @@ public class BasicLinkConfigTest {
|
||||
assertThat(config.latency(), is(LATENCY));
|
||||
assertThat(config.isBidirectional(), is(FALSE));
|
||||
assertThat(config.isValid(), is(true));
|
||||
assertThat(config.isMetered(), is(TRUE));
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,9 @@ public final class BasicLinkOperator implements ConfigOperator {
|
||||
if (cfg.flapping() != DEF_FLAPPING) {
|
||||
b.set(AnnotationKeys.FLAPPING, String.valueOf(cfg.flapping()));
|
||||
}
|
||||
if (cfg.isMetered() != null) {
|
||||
b.set(AnnotationKeys.METERED, String.valueOf(cfg.isMetered()));
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user