blob: 46a582a7cb3cb96a5d07e55cc8dcb04a8265e8d3 [file] [log] [blame]
tom80c0e5e2014-09-08 18:08:58 -07001package org.onlab.onos.net;
2
3import org.onlab.onos.net.provider.ProviderId;
4
5import static com.google.common.base.Preconditions.checkArgument;
tom297dfc02014-10-08 10:42:56 -07006import static com.google.common.base.Preconditions.checkNotNull;
tom80c0e5e2014-09-08 18:08:58 -07007
8/**
9 * Default edge link model implementation.
10 */
11public class DefaultEdgeLink extends DefaultLink implements EdgeLink {
12
13 private final HostId hostId;
14 private final HostLocation hostLocation;
15
16 /**
17 * Creates an edge link using the supplied information.
18 *
19 * @param providerId provider identity
20 * @param hostPoint host-side connection point
21 * @param hostLocation location where host attaches to the network
toma1d16b62014-10-02 23:45:11 -070022 * @param isIngress true to indicate host-to-network direction; false
tom80c0e5e2014-09-08 18:08:58 -070023 * for network-to-host direction
toma1d16b62014-10-02 23:45:11 -070024 * @param annotations optional key/value annotations
tom80c0e5e2014-09-08 18:08:58 -070025 */
26 public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint,
tomf5d85d42014-10-02 05:27:56 -070027 HostLocation hostLocation, boolean isIngress,
28 Annotations... annotations) {
tomcbefa232014-09-16 14:17:20 -070029 super(providerId, isIngress ? hostPoint : hostLocation,
tomf5d85d42014-10-02 05:27:56 -070030 isIngress ? hostLocation : hostPoint, Type.EDGE, annotations);
tom80c0e5e2014-09-08 18:08:58 -070031 checkArgument(hostPoint.elementId() instanceof HostId,
32 "Host point does not refer to a host ID");
33 this.hostId = (HostId) hostPoint.elementId();
34 this.hostLocation = hostLocation;
35 }
36
37 @Override
38 public HostId hostId() {
39 return hostId;
40 }
41
42 @Override
tom568581d2014-09-08 20:13:36 -070043 public HostLocation hostLocation() {
tom80c0e5e2014-09-08 18:08:58 -070044 return hostLocation;
45 }
toma1d16b62014-10-02 23:45:11 -070046
47 /**
48 * Creates a phantom edge link, to an unspecified end-station. This link
49 * does not represent any actually discovered link stored in the system.
50 *
51 * @param edgePort network edge port
52 * @param isIngress true to indicate host-to-network direction; false
53 * for network-to-host direction
54 * @return new phantom edge link
55 */
tom297dfc02014-10-08 10:42:56 -070056 public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort,
toma1d16b62014-10-02 23:45:11 -070057 boolean isIngress) {
tom297dfc02014-10-08 10:42:56 -070058 checkNotNull(edgePort, "Edge port cannot be null");
59 HostLocation location = (edgePort instanceof HostLocation) ?
60 (HostLocation) edgePort : new HostLocation(edgePort, 0);
toma1d16b62014-10-02 23:45:11 -070061 return new DefaultEdgeLink(ProviderId.NONE,
62 new ConnectPoint(HostId.NONE, PortNumber.P0),
tom297dfc02014-10-08 10:42:56 -070063 location, isIngress);
toma1d16b62014-10-02 23:45:11 -070064 }
tom297dfc02014-10-08 10:42:56 -070065
tom80c0e5e2014-09-08 18:08:58 -070066}