blob: 6450052a6530e30284c925f7602d6626da429cd1 [file] [log] [blame]
Ayaka Koshibecc260d22015-08-04 17:13:38 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ayaka Koshibecc260d22015-08-04 17:13:38 -07003 *
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;
Ray Milkeya4122362015-08-18 15:19:08 -070025import org.onosproject.net.config.ConfigApplyDelegate;
Thomas Vachuska4998caa2015-08-26 13:28:38 -070026import org.onosproject.net.config.basics.BasicLinkConfig;
Ayaka Koshibecc260d22015-08-04 17:13:38 -070027import org.onosproject.net.AnnotationKeys;
28import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.DefaultAnnotations;
30import org.onosproject.net.DeviceId;
31import org.onosproject.net.Link;
32import org.onosproject.net.LinkKey;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.SparseAnnotations;
35import org.onosproject.net.link.DefaultLinkDescription;
36import org.onosproject.net.link.LinkDescription;
37
38import com.fasterxml.jackson.databind.ObjectMapper;
39import com.fasterxml.jackson.databind.node.JsonNodeFactory;
40
41public 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);
dingdamud3a0b212017-05-16 11:18:27 +020050 private static final long NTIME = 200;
Ayaka Koshibecc260d22015-08-04 17:13:38 -070051
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 SHIMIZU74626412015-09-11 11:46:27 -070055 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibecc260d22015-08-04 17:13:38 -070056 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);
dingdamud3a0b212017-05-16 11:18:27 +020063 BLC.latency(Duration.ofNanos(NTIME));
Ayaka Koshibecc260d22015-08-04 17:13:38 -070064 }
65
66 @Test
67 public void testDescOps() {
68 LinkDescription desc = BasicLinkOperator.combine(BLC, LD);
dingdamud3a0b212017-05-16 11:18:27 +020069 assertEquals(String.valueOf(NTIME), desc.annotations().value(AnnotationKeys.LATENCY));
Ayaka Koshibecc260d22015-08-04 17:13:38 -070070 assertEquals("true", desc.annotations().value(AnnotationKeys.DURABLE));
71 }
72}