blob: 8f332e9d447968fb1625cffc300848136dc481fb [file] [log] [blame]
tom64b7aac2014-08-26 00:18:21 -07001package org.onlab.onos.net;
2
tombb58c202014-09-07 22:51:50 -07003import java.util.Objects;
4
alshabibdf652ad2014-09-09 11:53:19 -07005import com.google.common.base.MoreObjects;
tombb58c202014-09-07 22:51:50 -07006
tom64b7aac2014-08-26 00:18:21 -07007/**
8 * Abstraction of a network connection point expressed as a pair of the
tombb58c202014-09-07 22:51:50 -07009 * network element identifier and port number.
tom64b7aac2014-08-26 00:18:21 -070010 */
tombb58c202014-09-07 22:51:50 -070011public class ConnectPoint {
12
13 private final ElementId elementId;
14 private final PortNumber portNumber;
tom64b7aac2014-08-26 00:18:21 -070015
16 /**
tombb58c202014-09-07 22:51:50 -070017 * Creates a new connection point.
tom64b7aac2014-08-26 00:18:21 -070018 *
tombb58c202014-09-07 22:51:50 -070019 * @param elementId network element identifier
20 * @param portNumber port number
tom64b7aac2014-08-26 00:18:21 -070021 */
tombb58c202014-09-07 22:51:50 -070022 public ConnectPoint(ElementId elementId, PortNumber portNumber) {
23 this.elementId = elementId;
24 this.portNumber = portNumber;
25 }
26
27 /**
28 * Returns the network element identifier.
29 *
30 * @return element identifier
31 */
32 public ElementId elementId() {
33 return elementId;
34 }
35
36 /**
37 * Returns the identifier of the infrastructure device if the connection
38 * point belongs to a network element which is indeed an infrastructure
39 * device.
40 *
41 * @return network element identifier as a device identifier
42 * @throws java.lang.IllegalStateException if connection point is not
43 * associated with a device
44 */
tombb58c202014-09-07 22:51:50 -070045 public DeviceId deviceId() {
46 if (elementId instanceof DeviceId) {
47 return (DeviceId) elementId;
48 }
49 throw new IllegalStateException("Connection point not associated " +
alshabibdf652ad2014-09-09 11:53:19 -070050 "with an infrastructure device");
tombb58c202014-09-07 22:51:50 -070051 }
tom64b7aac2014-08-26 00:18:21 -070052
53 /**
54 * Returns the connection port number.
55 *
56 * @return port number
57 */
tombb58c202014-09-07 22:51:50 -070058 public PortNumber port() {
59 return portNumber;
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(elementId, portNumber);
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (obj instanceof ConnectPoint) {
70 final ConnectPoint other = (ConnectPoint) obj;
71 return Objects.equals(this.elementId, other.elementId) &&
72 Objects.equals(this.portNumber, other.portNumber);
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
alshabibdf652ad2014-09-09 11:53:19 -070079 return MoreObjects.toStringHelper(this)
tombb58c202014-09-07 22:51:50 -070080 .add("elementId", elementId)
81 .add("portNumber", portNumber)
82 .toString();
83 }
tom64b7aac2014-08-26 00:18:21 -070084
85}