blob: 3e1121ec4cca70f81ff1fa1951382c203bc0ec32 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
tom80c0e5e2014-09-08 18:08:58 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.net.provider.ProviderId;
tom80c0e5e2014-09-08 18:08:58 -070019
20import static com.google.common.base.Preconditions.checkArgument;
tom297dfc02014-10-08 10:42:56 -070021import static com.google.common.base.Preconditions.checkNotNull;
tom80c0e5e2014-09-08 18:08:58 -070022
23/**
24 * Default edge link model implementation.
25 */
26public class DefaultEdgeLink extends DefaultLink implements EdgeLink {
27
28 private final HostId hostId;
29 private final HostLocation hostLocation;
30
31 /**
32 * Creates an edge link using the supplied information.
33 *
34 * @param providerId provider identity
35 * @param hostPoint host-side connection point
36 * @param hostLocation location where host attaches to the network
toma1d16b62014-10-02 23:45:11 -070037 * @param isIngress true to indicate host-to-network direction; false
tom80c0e5e2014-09-08 18:08:58 -070038 * for network-to-host direction
toma1d16b62014-10-02 23:45:11 -070039 * @param annotations optional key/value annotations
tom80c0e5e2014-09-08 18:08:58 -070040 */
41 public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint,
tomf5d85d42014-10-02 05:27:56 -070042 HostLocation hostLocation, boolean isIngress,
43 Annotations... annotations) {
tomcbefa232014-09-16 14:17:20 -070044 super(providerId, isIngress ? hostPoint : hostLocation,
Brian Stanke612cebf2016-05-02 10:21:33 -040045 isIngress ? hostLocation : hostPoint, Type.EDGE, State.ACTIVE, annotations);
tom80c0e5e2014-09-08 18:08:58 -070046 checkArgument(hostPoint.elementId() instanceof HostId,
47 "Host point does not refer to a host ID");
48 this.hostId = (HostId) hostPoint.elementId();
49 this.hostLocation = hostLocation;
50 }
51
52 @Override
53 public HostId hostId() {
54 return hostId;
55 }
56
57 @Override
tom568581d2014-09-08 20:13:36 -070058 public HostLocation hostLocation() {
tom80c0e5e2014-09-08 18:08:58 -070059 return hostLocation;
60 }
toma1d16b62014-10-02 23:45:11 -070061
62 /**
63 * Creates a phantom edge link, to an unspecified end-station. This link
64 * does not represent any actually discovered link stored in the system.
65 *
66 * @param edgePort network edge port
67 * @param isIngress true to indicate host-to-network direction; false
68 * for network-to-host direction
69 * @return new phantom edge link
70 */
tom297dfc02014-10-08 10:42:56 -070071 public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort,
toma1d16b62014-10-02 23:45:11 -070072 boolean isIngress) {
tom297dfc02014-10-08 10:42:56 -070073 checkNotNull(edgePort, "Edge port cannot be null");
74 HostLocation location = (edgePort instanceof HostLocation) ?
75 (HostLocation) edgePort : new HostLocation(edgePort, 0);
toma1d16b62014-10-02 23:45:11 -070076 return new DefaultEdgeLink(ProviderId.NONE,
77 new ConnectPoint(HostId.NONE, PortNumber.P0),
tom297dfc02014-10-08 10:42:56 -070078 location, isIngress);
toma1d16b62014-10-02 23:45:11 -070079 }
tom297dfc02014-10-08 10:42:56 -070080
Thomas Vachuska25455e72015-06-04 11:31:26 -070081 /**
82 * Creates a an edge link, to the specified end-station.
83 *
Thomas Vachuska95898842017-08-01 13:31:24 -070084 * The edge link inherits the target host annotations.
85 *
Thomas Vachuska25455e72015-06-04 11:31:26 -070086 * @param host host
87 * @param isIngress true to indicate host-to-network direction; false
88 * for network-to-host direction
89 * @return new phantom edge link
90 */
91 public static DefaultEdgeLink createEdgeLink(Host host, boolean isIngress) {
92 checkNotNull(host, "Host cannot be null");
93 return new DefaultEdgeLink(ProviderId.NONE,
94 new ConnectPoint(host.id(), PortNumber.P0),
Thomas Vachuska95898842017-08-01 13:31:24 -070095 host.location(), isIngress, host.annotations());
Thomas Vachuska25455e72015-06-04 11:31:26 -070096 }
97
tom80c0e5e2014-09-08 18:08:58 -070098}