blob: b3891f11db2019a10c10a097b16fdde361a0f6e7 [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;
8import static org.onlab.onos.net.DefaultLinkTest.cp;
9import static org.onlab.onos.net.DeviceId.deviceId;
10import static org.onlab.onos.net.HostId.hostId;
11import static org.onlab.onos.net.PortNumber.portNumber;
12
13/**
14 * Test of the default edge link model entity.
15 */
16public class DefaultEdgeLinkTest {
17
tom7e02cda2014-09-18 12:05:46 -070018 private static final ProviderId PID = new ProviderId("of", "foo");
tom568581d2014-09-08 20:13:36 -070019 private static final DeviceId DID1 = deviceId("of:foo");
20 private static final HostId HID1 = hostId("nic:foobar");
21 private static final HostId HID2 = hostId("nic:barfoo");
22 private static final PortNumber P0 = portNumber(0);
23 private static final PortNumber P1 = portNumber(1);
24
25 @Test
26 public void testEquality() {
27 EdgeLink l1 = new DefaultEdgeLink(PID, cp(HID1, P0),
28 new HostLocation(DID1, P1, 123L), true);
29 EdgeLink l2 = new DefaultEdgeLink(PID, cp(HID1, P0),
30 new HostLocation(DID1, P1, 123L), true);
31
32 EdgeLink l3 = new DefaultEdgeLink(PID, cp(HID2, P0),
33 new HostLocation(DID1, P1, 123L), false);
34 EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0),
35 new HostLocation(DID1, P1, 123L), false);
36
37 EdgeLink l5 = new DefaultEdgeLink(PID, cp(HID1, P0),
38 new HostLocation(DID1, P1, 123L), false);
39
40 new EqualsTester().addEqualityGroup(l1, l2)
41 .addEqualityGroup(l3, l4)
42 .addEqualityGroup(l5)
43 .testEquals();
44 }
45
46 @Test
47 public void basics() {
48 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
49 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false);
tomcbefa232014-09-16 14:17:20 -070050 assertEquals("incorrect src", cp(HID1, P0), link.dst());
51 assertEquals("incorrect dst", hostLocation, link.src());
tom568581d2014-09-08 20:13:36 -070052 assertEquals("incorrect type", Link.Type.EDGE, link.type());
53 assertEquals("incorrect hostId", HID1, link.hostId());
54 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
55 assertEquals("incorrect time", 123L, link.hostLocation().time());
56 }
57
58}