blob: 355f49e1bda4eacf927f326bf587b8b4afea0b3c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
tom568581d2014-09-08 20:13:36 -070016package org.onlab.onos.net;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.onos.net.provider.ProviderId;
21
22import static org.junit.Assert.assertEquals;
tom297dfc02014-10-08 10:42:56 -070023import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink;
tom568581d2014-09-08 20:13:36 -070024import static org.onlab.onos.net.DefaultLinkTest.cp;
25import static org.onlab.onos.net.DeviceId.deviceId;
26import static org.onlab.onos.net.HostId.hostId;
27import static org.onlab.onos.net.PortNumber.portNumber;
28
29/**
30 * Test of the default edge link model entity.
31 */
32public class DefaultEdgeLinkTest {
33
tom7e02cda2014-09-18 12:05:46 -070034 private static final ProviderId PID = new ProviderId("of", "foo");
tom568581d2014-09-08 20:13:36 -070035 private static final DeviceId DID1 = deviceId("of:foo");
tom545708e2014-10-09 17:10:02 -070036 private static final HostId HID1 = hostId("00:00:00:00:00:01/-1");
37 private static final HostId HID2 = hostId("00:00:00:00:00:01/-1");
tom568581d2014-09-08 20:13:36 -070038 private static final PortNumber P0 = portNumber(0);
39 private static final PortNumber P1 = portNumber(1);
40
41 @Test
42 public void testEquality() {
43 EdgeLink l1 = new DefaultEdgeLink(PID, cp(HID1, P0),
44 new HostLocation(DID1, P1, 123L), true);
45 EdgeLink l2 = new DefaultEdgeLink(PID, cp(HID1, P0),
46 new HostLocation(DID1, P1, 123L), true);
47
48 EdgeLink l3 = new DefaultEdgeLink(PID, cp(HID2, P0),
49 new HostLocation(DID1, P1, 123L), false);
50 EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0),
51 new HostLocation(DID1, P1, 123L), false);
52
tom568581d2014-09-08 20:13:36 -070053 new EqualsTester().addEqualityGroup(l1, l2)
54 .addEqualityGroup(l3, l4)
tom568581d2014-09-08 20:13:36 -070055 .testEquals();
56 }
57
58 @Test
59 public void basics() {
60 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
61 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false);
tomcbefa232014-09-16 14:17:20 -070062 assertEquals("incorrect src", cp(HID1, P0), link.dst());
63 assertEquals("incorrect dst", hostLocation, link.src());
tom568581d2014-09-08 20:13:36 -070064 assertEquals("incorrect type", Link.Type.EDGE, link.type());
65 assertEquals("incorrect hostId", HID1, link.hostId());
66 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
67 assertEquals("incorrect time", 123L, link.hostLocation().time());
68 }
69
tom297dfc02014-10-08 10:42:56 -070070 @Test
71 public void phantomIngress() {
72 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
73 EdgeLink link = createEdgeLink(hostLocation, true);
74 assertEquals("incorrect dst", hostLocation, link.dst());
75 assertEquals("incorrect type", Link.Type.EDGE, link.type());
76 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
77 assertEquals("incorrect time", 123L, link.hostLocation().time());
78 }
79
80 @Test
81 public void phantomEgress() {
82 ConnectPoint hostLocation = new ConnectPoint(DID1, P1);
83 EdgeLink link = createEdgeLink(hostLocation, false);
84 assertEquals("incorrect src", hostLocation, link.src());
85 assertEquals("incorrect type", Link.Type.EDGE, link.type());
86 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
87 assertEquals("incorrect time", 0L, link.hostLocation().time());
88 }
89
tom568581d2014-09-08 20:13:36 -070090}