blob: 9fb95704d7ad621e3edf9c876a22b20f487af51f [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");
tom545708e2014-10-09 17:10:02 -070021 private static final HostId HID1 = hostId("00:00:00:00:00:01/-1");
22 private static final HostId HID2 = hostId("00:00:00:00:00:01/-1");
tom568581d2014-09-08 20:13:36 -070023 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
tom568581d2014-09-08 20:13:36 -070038 new EqualsTester().addEqualityGroup(l1, l2)
39 .addEqualityGroup(l3, l4)
tom568581d2014-09-08 20:13:36 -070040 .testEquals();
41 }
42
43 @Test
44 public void basics() {
45 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
46 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false);
tomcbefa232014-09-16 14:17:20 -070047 assertEquals("incorrect src", cp(HID1, P0), link.dst());
48 assertEquals("incorrect dst", hostLocation, link.src());
tom568581d2014-09-08 20:13:36 -070049 assertEquals("incorrect type", Link.Type.EDGE, link.type());
50 assertEquals("incorrect hostId", HID1, link.hostId());
51 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
52 assertEquals("incorrect time", 123L, link.hostLocation().time());
53 }
54
tom297dfc02014-10-08 10:42:56 -070055 @Test
56 public void phantomIngress() {
57 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
58 EdgeLink link = createEdgeLink(hostLocation, true);
59 assertEquals("incorrect dst", hostLocation, link.dst());
60 assertEquals("incorrect type", Link.Type.EDGE, link.type());
61 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
62 assertEquals("incorrect time", 123L, link.hostLocation().time());
63 }
64
65 @Test
66 public void phantomEgress() {
67 ConnectPoint hostLocation = new ConnectPoint(DID1, P1);
68 EdgeLink link = createEdgeLink(hostLocation, false);
69 assertEquals("incorrect src", hostLocation, link.src());
70 assertEquals("incorrect type", Link.Type.EDGE, link.type());
71 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
72 assertEquals("incorrect time", 0L, link.hostLocation().time());
73 }
74
tom568581d2014-09-08 20:13:36 -070075}