Ayaka Koshibe | cc260d2 | 2015-08-04 17:13:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-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.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; |
| 25 | import org.onosproject.incubator.net.config.Config; |
| 26 | import org.onosproject.incubator.net.config.ConfigApplyDelegate; |
| 27 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; |
| 28 | import org.onosproject.net.AnnotationKeys; |
| 29 | import org.onosproject.net.ConnectPoint; |
| 30 | import org.onosproject.net.DefaultAnnotations; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Link; |
| 33 | import org.onosproject.net.LinkKey; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.SparseAnnotations; |
| 36 | import org.onosproject.net.link.DefaultLinkDescription; |
| 37 | import org.onosproject.net.link.LinkDescription; |
| 38 | |
| 39 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 40 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 41 | |
| 42 | public class BasicLinkOperatorTest { |
| 43 | |
| 44 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 45 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 46 | private static final PortNumber P1 = portNumber(1); |
| 47 | |
| 48 | private static final ConnectPoint SRC = new ConnectPoint(DID1, P1); |
| 49 | private static final ConnectPoint DST = new ConnectPoint(DID2, P1); |
| 50 | private static final LinkKey LK = LinkKey.linkKey(SRC, DST); |
| 51 | private static final Duration NTIME = Duration.ofNanos(200); |
| 52 | |
| 53 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
| 54 | .set(AnnotationKeys.DURABLE, "true").build(); |
| 55 | private static final LinkDescription LD = new DefaultLinkDescription(SRC, DST, Link.Type.DIRECT, SA); |
| 56 | private final ConfigApplyDelegate delegate = new ConfigApplyDelegate() { |
| 57 | @Override |
| 58 | public void onApply(Config config) { |
| 59 | } |
| 60 | }; |
| 61 | private final ObjectMapper mapper = new ObjectMapper(); |
| 62 | |
| 63 | private static final BasicLinkConfig BLC = new BasicLinkConfig(); |
| 64 | |
| 65 | @Before |
| 66 | public void setUp() { |
| 67 | BLC.init(LK, "optest", JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 68 | BLC.latency(NTIME); |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public void testDescOps() { |
| 73 | LinkDescription desc = BasicLinkOperator.combine(BLC, LD); |
| 74 | assertEquals(NTIME.toString(), desc.annotations().value(AnnotationKeys.LATENCY)); |
| 75 | assertEquals("true", desc.annotations().value(AnnotationKeys.DURABLE)); |
| 76 | } |
| 77 | } |