blob: 315552b52d82f843869d1075ba297a24c802559a [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
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 */
Ray Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net.config.basics;
17
Marc De Leenheerec551d32017-03-10 15:48:18 -080018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Ray Milkeydbf59f02016-08-19 12:54:16 -070020import org.junit.Test;
21import org.onosproject.net.Link;
22import org.onosproject.net.LinkKey;
23import org.onosproject.net.NetTestTools;
24import org.onosproject.net.config.ConfigApplyDelegate;
25
Marc De Leenheerec551d32017-03-10 15:48:18 -080026import java.time.Duration;
Ray Milkeydbf59f02016-08-19 12:54:16 -070027
28import static java.lang.Boolean.FALSE;
David Glantz0843f5d2020-03-05 21:23:10 -060029import static java.lang.Boolean.TRUE;
Ray Milkeydbf59f02016-08-19 12:54:16 -070030import static org.hamcrest.MatcherAssert.assertThat;
31import static org.hamcrest.Matchers.is;
32
33/**
34 * Unit tests for the BasicLinkConfig class.
35 */
36
37public class BasicLinkConfigTest {
38 private static final long BANDWIDTH = 11;
39 private static final double METRIC = 3.0;
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060040 private static final double JITTER = 3.0;
41 private static final double DELAY = 3.0;
42 private static final double LOSS = 3.0;
43 private static final double AVAILABILITY = 3.0;
44 private static final double FLAPPING = 3.0;
David Glantzde82ada2020-03-19 14:43:32 -050045 private static final long TIER = 4;
46 private static final double METERED_USAGE = 85.0;
Ray Milkeydbf59f02016-08-19 12:54:16 -070047 private static final Duration LATENCY = Duration.ofNanos(5555);
48
49 /**
50 * Tests construction, setters and getters of a BasicLinkConfig object.
51 */
52 @Test
53 public void testConstruction() {
54 BasicLinkConfig config = new BasicLinkConfig();
55 ConfigApplyDelegate delegate = configApply -> { };
56 ObjectMapper mapper = new ObjectMapper();
57 LinkKey linkKey = LinkKey.linkKey(
58 NetTestTools.connectPoint("device1", 1),
59 NetTestTools.connectPoint("device2", 2));
60
61 config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
62
63
64 config.bandwidth(BANDWIDTH)
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060065 .jitter(JITTER)
66 .delay(DELAY)
67 .loss(LOSS)
68 .availability(AVAILABILITY)
69 .flapping(FLAPPING)
Marc De Leenheerec551d32017-03-10 15:48:18 -080070 .isDurable(FALSE)
71 .metric(METRIC)
72 .type(Link.Type.DIRECT)
73 .latency(LATENCY)
David Glantz0843f5d2020-03-05 21:23:10 -060074 .isBidirectional(FALSE)
David Glantzde82ada2020-03-19 14:43:32 -050075 .isMetered(TRUE)
76 .tier(TIER)
77 .meteredUsage(METERED_USAGE);
Ray Milkeydbf59f02016-08-19 12:54:16 -070078
79 assertThat(config.bandwidth(), is(BANDWIDTH));
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060080 assertThat(config.jitter(), is(JITTER));
81 assertThat(config.delay(), is(DELAY));
82 assertThat(config.loss(), is(LOSS));
83 assertThat(config.availability(), is(AVAILABILITY));
84 assertThat(config.flapping(), is(FLAPPING));
Ray Milkeydbf59f02016-08-19 12:54:16 -070085 assertThat(config.isDurable(), is(FALSE));
86 assertThat(config.metric(), is(METRIC));
87 assertThat(config.type(), is(Link.Type.DIRECT));
88 assertThat(config.latency(), is(LATENCY));
Marc De Leenheerec551d32017-03-10 15:48:18 -080089 assertThat(config.isBidirectional(), is(FALSE));
Ray Milkeydbf59f02016-08-19 12:54:16 -070090 assertThat(config.isValid(), is(true));
David Glantz0843f5d2020-03-05 21:23:10 -060091 assertThat(config.isMetered(), is(TRUE));
David Glantzde82ada2020-03-19 14:43:32 -050092 assertThat(config.tier(), is(TIER));
93 assertThat(config.meteredUsage(), is(METERED_USAGE));
Ray Milkeydbf59f02016-08-19 12:54:16 -070094 }
95}