Adding unit tests for simple link manager.
Converted ConnectPoint and HostLocation to classes.
diff --git a/net/api/src/main/java/org/onlab/onos/net/ConnectPoint.java b/net/api/src/main/java/org/onlab/onos/net/ConnectPoint.java
index 72ea3f4..f870698 100644
--- a/net/api/src/main/java/org/onlab/onos/net/ConnectPoint.java
+++ b/net/api/src/main/java/org/onlab/onos/net/ConnectPoint.java
@@ -1,23 +1,86 @@
package org.onlab.onos.net;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
/**
* Abstraction of a network connection point expressed as a pair of the
- * device identifier and the device port number.
+ * network element identifier and port number.
*/
-public interface ConnectPoint {
+public class ConnectPoint {
+
+ private final ElementId elementId;
+ private final PortNumber portNumber;
/**
- * Returns the connection device identifier.
+ * Creates a new connection point.
*
- * @return device id
+ * @param elementId network element identifier
+ * @param portNumber port number
*/
- DeviceId deviceId();
+ public ConnectPoint(ElementId elementId, PortNumber portNumber) {
+ this.elementId = elementId;
+ this.portNumber = portNumber;
+ }
+
+ /**
+ * Returns the network element identifier.
+ *
+ * @return element identifier
+ */
+ public ElementId elementId() {
+ return elementId;
+ }
+
+ /**
+ * Returns the identifier of the infrastructure device if the connection
+ * point belongs to a network element which is indeed an infrastructure
+ * device.
+ *
+ * @return network element identifier as a device identifier
+ * @throws java.lang.IllegalStateException if connection point is not
+ * associated with a device
+ */
+ @SuppressWarnings("unchecked")
+ public DeviceId deviceId() {
+ if (elementId instanceof DeviceId) {
+ return (DeviceId) elementId;
+ }
+ throw new IllegalStateException("Connection point not associated " +
+ "with an infrastructure device");
+ }
/**
* Returns the connection port number.
*
* @return port number
*/
- PortNumber port();
+ public PortNumber port() {
+ return portNumber;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(elementId, portNumber);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ConnectPoint) {
+ final ConnectPoint other = (ConnectPoint) obj;
+ return Objects.equals(this.elementId, other.elementId) &&
+ Objects.equals(this.portNumber, other.portNumber);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("elementId", elementId)
+ .add("portNumber", portNumber)
+ .toString();
+ }
}
diff --git a/net/api/src/main/java/org/onlab/onos/net/HostLocation.java b/net/api/src/main/java/org/onlab/onos/net/HostLocation.java
index 022a6f9..22673a6 100644
--- a/net/api/src/main/java/org/onlab/onos/net/HostLocation.java
+++ b/net/api/src/main/java/org/onlab/onos/net/HostLocation.java
@@ -1,10 +1,19 @@
package org.onlab.onos.net;
+import java.util.Objects;
+
/**
* Representation of a network edge location where an end-station host is
* connected.
*/
-public interface HostLocation extends ConnectPoint {
+public class HostLocation extends ConnectPoint {
+
+ private final long time;
+
+ public HostLocation(DeviceId deviceId, PortNumber portNumber, long time) {
+ super(deviceId, portNumber);
+ this.time = time;
+ }
/**
* Returns the timestamp when the location was established, given in
@@ -12,6 +21,22 @@
*
* @return timestamp in milliseconds since start of epoch
*/
- long time();
+ public long time() {
+ return time;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * super.hashCode() + Objects.hash(time);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof HostLocation) {
+ final HostLocation other = (HostLocation) obj;
+ return super.equals(obj) && Objects.equals(this.time, other.time);
+ }
+ return false;
+ }
}
diff --git a/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java b/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
index 710cb08..d8465ef 100644
--- a/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
+++ b/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
@@ -4,23 +4,15 @@
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.event.Event;
+import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
import org.onlab.onos.net.MastershipRole;
-import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
-import org.onlab.onos.net.device.DefaultDeviceDescription;
-import org.onlab.onos.net.device.DefaultPortDescription;
-import org.onlab.onos.net.device.DeviceAdminService;
-import org.onlab.onos.net.device.DeviceDescription;
-import org.onlab.onos.net.device.DeviceEvent;
-import org.onlab.onos.net.device.DeviceListener;
-import org.onlab.onos.net.device.DeviceProvider;
-import org.onlab.onos.net.device.DeviceProviderRegistry;
-import org.onlab.onos.net.device.DeviceProviderService;
-import org.onlab.onos.net.device.DeviceService;
-import org.onlab.onos.net.device.PortDescription;
+import org.onlab.onos.net.link.DefaultLinkDescription;
import org.onlab.onos.net.link.LinkAdminService;
+import org.onlab.onos.net.link.LinkDescription;
import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.link.LinkListener;
import org.onlab.onos.net.link.LinkProvider;
@@ -31,13 +23,10 @@
import org.onlab.onos.net.provider.ProviderId;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.*;
-import static org.onlab.onos.net.Device.Type.SWITCH;
import static org.onlab.onos.net.DeviceId.deviceId;
-import static org.onlab.onos.net.device.DeviceEvent.Type.*;
/**
* Test codifying the link service & link provider service contracts.
@@ -47,11 +36,6 @@
private static final ProviderId PID = new ProviderId("foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
- private static final String MFR = "whitebox";
- private static final String HW = "1.1.x";
- private static final String SW1 = "3.8.1";
- private static final String SW2 = "3.9.5";
- private static final String SN = "43311-12345";
private static final PortNumber P1 = PortNumber.portNumber(1);
private static final PortNumber P2 = PortNumber.portNumber(2);
@@ -94,6 +78,14 @@
}
+ @Test
+ public void createLink() {
+ LinkDescription ld = new DefaultLinkDescription(new ConnectPoint(DID1, P1),
+ new ConnectPoint(DID2, P2),
+ Link.Type.DIRECT);
+ providerService.linkDetected(ld);
+ }
+
protected void validateEvents(Enum... types) {
int i = 0;
assertEquals("wrong events received", types.length, listener.events.size());