Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [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 | */ |
| 16 | package org.onosproject.net.link.impl; |
| 17 | |
| 18 | import static org.onosproject.net.DeviceId.deviceId; |
| 19 | import static org.onosproject.net.PortNumber.portNumber; |
| 20 | import static org.junit.Assert.assertEquals; |
| 21 | |
| 22 | import java.time.Duration; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 25 | import org.onosproject.net.config.ConfigApplyDelegate; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 26 | import org.onosproject.net.config.basics.BasicLinkConfig; |
Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 27 | import org.onosproject.net.AnnotationKeys; |
| 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.DefaultAnnotations; |
| 30 | import org.onosproject.net.DeviceId; |
| 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.LinkKey; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.SparseAnnotations; |
| 35 | import org.onosproject.net.link.DefaultLinkDescription; |
| 36 | import org.onosproject.net.link.LinkDescription; |
| 37 | |
| 38 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 39 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 40 | |
| 41 | public class BasicLinkOperatorTest { |
| 42 | |
| 43 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 44 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 45 | private static final PortNumber P1 = portNumber(1); |
| 46 | |
| 47 | private static final ConnectPoint SRC = new ConnectPoint(DID1, P1); |
| 48 | private static final ConnectPoint DST = new ConnectPoint(DID2, P1); |
| 49 | private static final LinkKey LK = LinkKey.linkKey(SRC, DST); |
| 50 | private static final Duration NTIME = Duration.ofNanos(200); |
| 51 | |
| 52 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
| 53 | .set(AnnotationKeys.DURABLE, "true").build(); |
| 54 | private static final LinkDescription LD = new DefaultLinkDescription(SRC, DST, Link.Type.DIRECT, SA); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 55 | private final ConfigApplyDelegate delegate = config -> { }; |
Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 56 | private final ObjectMapper mapper = new ObjectMapper(); |
| 57 | |
| 58 | private static final BasicLinkConfig BLC = new BasicLinkConfig(); |
| 59 | |
| 60 | @Before |
| 61 | public void setUp() { |
| 62 | BLC.init(LK, "optest", JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 63 | BLC.latency(NTIME); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void testDescOps() { |
| 68 | LinkDescription desc = BasicLinkOperator.combine(BLC, LD); |
| 69 | assertEquals(NTIME.toString(), desc.annotations().value(AnnotationKeys.LATENCY)); |
| 70 | assertEquals("true", desc.annotations().value(AnnotationKeys.DURABLE)); |
| 71 | } |
| 72 | } |