blob: fd63797272c2628f0332d547c978dc392a72945d [file] [log] [blame]
tom568581d2014-09-08 20:13:36 -07001package org.onlab.onos.net;
2
3import com.google.common.testing.EqualsTester;
4import org.junit.Test;
5import org.onlab.onos.net.provider.ProviderId;
6
7import static org.junit.Assert.assertEquals;
tom297dfc02014-10-08 10:42:56 -07008import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink;
tom568581d2014-09-08 20:13:36 -07009import static org.onlab.onos.net.DefaultLinkTest.cp;
10import static org.onlab.onos.net.DeviceId.deviceId;
11import static org.onlab.onos.net.HostId.hostId;
12import static org.onlab.onos.net.PortNumber.portNumber;
13
14/**
15 * Test of the default edge link model entity.
16 */
17public class DefaultEdgeLinkTest {
18
tom7e02cda2014-09-18 12:05:46 -070019 private static final ProviderId PID = new ProviderId("of", "foo");
tom568581d2014-09-08 20:13:36 -070020 private static final DeviceId DID1 = deviceId("of:foo");
21 private static final HostId HID1 = hostId("nic:foobar");
22 private static final HostId HID2 = hostId("nic:barfoo");
23 private static final PortNumber P0 = portNumber(0);
24 private static final PortNumber P1 = portNumber(1);
25
26 @Test
27 public void testEquality() {
28 EdgeLink l1 = new DefaultEdgeLink(PID, cp(HID1, P0),
29 new HostLocation(DID1, P1, 123L), true);
30 EdgeLink l2 = new DefaultEdgeLink(PID, cp(HID1, P0),
31 new HostLocation(DID1, P1, 123L), true);
32
33 EdgeLink l3 = new DefaultEdgeLink(PID, cp(HID2, P0),
34 new HostLocation(DID1, P1, 123L), false);
35 EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0),
36 new HostLocation(DID1, P1, 123L), false);
37
38 EdgeLink l5 = new DefaultEdgeLink(PID, cp(HID1, P0),
39 new HostLocation(DID1, P1, 123L), false);
40
41 new EqualsTester().addEqualityGroup(l1, l2)
42 .addEqualityGroup(l3, l4)
43 .addEqualityGroup(l5)
44 .testEquals();
45 }
46
47 @Test
48 public void basics() {
49 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
50 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false);
tomcbefa232014-09-16 14:17:20 -070051 assertEquals("incorrect src", cp(HID1, P0), link.dst());
52 assertEquals("incorrect dst", hostLocation, link.src());
tom568581d2014-09-08 20:13:36 -070053 assertEquals("incorrect type", Link.Type.EDGE, link.type());
54 assertEquals("incorrect hostId", HID1, link.hostId());
55 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
56 assertEquals("incorrect time", 123L, link.hostLocation().time());
57 }
58
tom297dfc02014-10-08 10:42:56 -070059 @Test
60 public void phantomIngress() {
61 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
62 EdgeLink link = createEdgeLink(hostLocation, true);
63 assertEquals("incorrect dst", hostLocation, link.dst());
64 assertEquals("incorrect type", Link.Type.EDGE, link.type());
65 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
66 assertEquals("incorrect time", 123L, link.hostLocation().time());
67 }
68
69 @Test
70 public void phantomEgress() {
71 ConnectPoint hostLocation = new ConnectPoint(DID1, P1);
72 EdgeLink link = createEdgeLink(hostLocation, false);
73 assertEquals("incorrect src", hostLocation, link.src());
74 assertEquals("incorrect type", Link.Type.EDGE, link.type());
75 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
76 assertEquals("incorrect time", 0L, link.hostLocation().time());
77 }
78
tom568581d2014-09-08 20:13:36 -070079}