Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 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 | */ |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
| 17 | |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.LinkKey; |
| 23 | import org.onosproject.net.NetTestTools; |
| 24 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 25 | |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 26 | import java.time.Duration; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 27 | |
| 28 | import static java.lang.Boolean.FALSE; |
David Glantz | 0843f5d | 2020-03-05 21:23:10 -0600 | [diff] [blame] | 29 | import static java.lang.Boolean.TRUE; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | import static org.hamcrest.Matchers.is; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for the BasicLinkConfig class. |
| 35 | */ |
| 36 | |
| 37 | public class BasicLinkConfigTest { |
| 38 | private static final long BANDWIDTH = 11; |
| 39 | private static final double METRIC = 3.0; |
Aaron Dunlap | 239ea5c | 2020-02-26 12:10:31 -0600 | [diff] [blame] | 40 | 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 Glantz | de82ada | 2020-03-19 14:43:32 -0500 | [diff] [blame] | 45 | private static final long TIER = 4; |
| 46 | private static final double METERED_USAGE = 85.0; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 47 | 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 Dunlap | 239ea5c | 2020-02-26 12:10:31 -0600 | [diff] [blame] | 65 | .jitter(JITTER) |
| 66 | .delay(DELAY) |
| 67 | .loss(LOSS) |
| 68 | .availability(AVAILABILITY) |
| 69 | .flapping(FLAPPING) |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 70 | .isDurable(FALSE) |
| 71 | .metric(METRIC) |
| 72 | .type(Link.Type.DIRECT) |
| 73 | .latency(LATENCY) |
David Glantz | 0843f5d | 2020-03-05 21:23:10 -0600 | [diff] [blame] | 74 | .isBidirectional(FALSE) |
David Glantz | de82ada | 2020-03-19 14:43:32 -0500 | [diff] [blame] | 75 | .isMetered(TRUE) |
| 76 | .tier(TIER) |
| 77 | .meteredUsage(METERED_USAGE); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 78 | |
| 79 | assertThat(config.bandwidth(), is(BANDWIDTH)); |
Aaron Dunlap | 239ea5c | 2020-02-26 12:10:31 -0600 | [diff] [blame] | 80 | 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 Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 85 | 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 Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 89 | assertThat(config.isBidirectional(), is(FALSE)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 90 | assertThat(config.isValid(), is(true)); |
David Glantz | 0843f5d | 2020-03-05 21:23:10 -0600 | [diff] [blame] | 91 | assertThat(config.isMetered(), is(TRUE)); |
David Glantz | de82ada | 2020-03-19 14:43:32 -0500 | [diff] [blame] | 92 | assertThat(config.tier(), is(TIER)); |
| 93 | assertThat(config.meteredUsage(), is(METERED_USAGE)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 94 | } |
| 95 | } |