blob: 7fe1ee3b85c06ba56df72985cc9f6fc7b9901ce9 [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
Pier59266bc2018-03-15 12:10:24 -070018import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.provider.ProviderId;
tom80c0e5e2014-09-08 18:08:58 -070020
Pier59266bc2018-03-15 12:10:24 -070021import java.util.Set;
22
tom80c0e5e2014-09-08 18:08:58 -070023import static com.google.common.base.Preconditions.checkArgument;
tom297dfc02014-10-08 10:42:56 -070024import static com.google.common.base.Preconditions.checkNotNull;
tom80c0e5e2014-09-08 18:08:58 -070025
26/**
27 * Default edge link model implementation.
28 */
29public class DefaultEdgeLink extends DefaultLink implements EdgeLink {
30
31 private final HostId hostId;
32 private final HostLocation hostLocation;
33
34 /**
35 * Creates an edge link using the supplied information.
36 *
37 * @param providerId provider identity
38 * @param hostPoint host-side connection point
39 * @param hostLocation location where host attaches to the network
toma1d16b62014-10-02 23:45:11 -070040 * @param isIngress true to indicate host-to-network direction; false
tom80c0e5e2014-09-08 18:08:58 -070041 * for network-to-host direction
toma1d16b62014-10-02 23:45:11 -070042 * @param annotations optional key/value annotations
tom80c0e5e2014-09-08 18:08:58 -070043 */
44 public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint,
tomf5d85d42014-10-02 05:27:56 -070045 HostLocation hostLocation, boolean isIngress,
46 Annotations... annotations) {
tomcbefa232014-09-16 14:17:20 -070047 super(providerId, isIngress ? hostPoint : hostLocation,
Brian Stanke612cebf2016-05-02 10:21:33 -040048 isIngress ? hostLocation : hostPoint, Type.EDGE, State.ACTIVE, annotations);
tom80c0e5e2014-09-08 18:08:58 -070049 checkArgument(hostPoint.elementId() instanceof HostId,
50 "Host point does not refer to a host ID");
51 this.hostId = (HostId) hostPoint.elementId();
52 this.hostLocation = hostLocation;
53 }
54
55 @Override
56 public HostId hostId() {
57 return hostId;
58 }
59
60 @Override
tom568581d2014-09-08 20:13:36 -070061 public HostLocation hostLocation() {
tom80c0e5e2014-09-08 18:08:58 -070062 return hostLocation;
63 }
toma1d16b62014-10-02 23:45:11 -070064
65 /**
66 * Creates a phantom edge link, to an unspecified end-station. This link
67 * does not represent any actually discovered link stored in the system.
68 *
69 * @param edgePort network edge port
70 * @param isIngress true to indicate host-to-network direction; false
71 * for network-to-host direction
72 * @return new phantom edge link
73 */
tom297dfc02014-10-08 10:42:56 -070074 public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort,
toma1d16b62014-10-02 23:45:11 -070075 boolean isIngress) {
tom297dfc02014-10-08 10:42:56 -070076 checkNotNull(edgePort, "Edge port cannot be null");
77 HostLocation location = (edgePort instanceof HostLocation) ?
78 (HostLocation) edgePort : new HostLocation(edgePort, 0);
toma1d16b62014-10-02 23:45:11 -070079 return new DefaultEdgeLink(ProviderId.NONE,
80 new ConnectPoint(HostId.NONE, PortNumber.P0),
tom297dfc02014-10-08 10:42:56 -070081 location, isIngress);
toma1d16b62014-10-02 23:45:11 -070082 }
tom297dfc02014-10-08 10:42:56 -070083
Thomas Vachuska25455e72015-06-04 11:31:26 -070084 /**
85 * Creates a an edge link, to the specified end-station.
86 *
Thomas Vachuska95898842017-08-01 13:31:24 -070087 * The edge link inherits the target host annotations.
88 *
Thomas Vachuska25455e72015-06-04 11:31:26 -070089 * @param host host
90 * @param isIngress true to indicate host-to-network direction; false
91 * for network-to-host direction
92 * @return new phantom edge link
93 */
94 public static DefaultEdgeLink createEdgeLink(Host host, boolean isIngress) {
95 checkNotNull(host, "Host cannot be null");
96 return new DefaultEdgeLink(ProviderId.NONE,
97 new ConnectPoint(host.id(), PortNumber.P0),
Thomas Vachuska95898842017-08-01 13:31:24 -070098 host.location(), isIngress, host.annotations());
Thomas Vachuska25455e72015-06-04 11:31:26 -070099 }
100
Pier59266bc2018-03-15 12:10:24 -0700101 /**
102 * Creates edge links, to the specified end-station.
103 *
104 * The edge link inherits the target host annotations.
105 *
106 * @param host host
107 * @param isIngress true to indicate host-to-network direction; false
108 * for network-to-host direction
109 * @return new phantom edge link
110 */
111 public static Set<DefaultEdgeLink> createEdgeLinks(Host host, boolean isIngress) {
112 checkNotNull(host, "Host cannot be null");
113 ImmutableSet.Builder<DefaultEdgeLink> edgeLinksBuilder = ImmutableSet.builder();
114 host.locations().forEach(
115 location -> edgeLinksBuilder.add(new DefaultEdgeLink(ProviderId.NONE,
116 new ConnectPoint(host.id(), PortNumber.P0),
117 location, isIngress, host.annotations()))
118 );
119 return edgeLinksBuilder.build();
120 }
121
tom80c0e5e2014-09-08 18:08:58 -0700122}