blob: ca01b3127167921502c1d3f1c7e4190fbb2e7c10 [file] [log] [blame]
Ayaka Koshibecc260d22015-08-04 17:13:38 -07001/*
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 */
16package org.onosproject.net.link.impl;
17
18import static org.onosproject.net.DeviceId.deviceId;
19import static org.onosproject.net.PortNumber.portNumber;
20import static org.junit.Assert.assertEquals;
21
22import java.time.Duration;
23import org.junit.Before;
24import org.junit.Test;
25import org.onosproject.incubator.net.config.Config;
26import org.onosproject.incubator.net.config.ConfigApplyDelegate;
27import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
28import org.onosproject.net.AnnotationKeys;
29import org.onosproject.net.ConnectPoint;
30import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.Link;
33import org.onosproject.net.LinkKey;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.SparseAnnotations;
36import org.onosproject.net.link.DefaultLinkDescription;
37import org.onosproject.net.link.LinkDescription;
38
39import com.fasterxml.jackson.databind.ObjectMapper;
40import com.fasterxml.jackson.databind.node.JsonNodeFactory;
41
42public 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}