blob: 21cb0edf1f87016199dbbdc109752b5d891fff79 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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 */
tom80c0e5e2014-09-08 18:08:58 -070016package org.onlab.onos.net;
17
18import org.onlab.onos.net.provider.ProviderId;
19
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,
tomf5d85d42014-10-02 05:27:56 -070045 isIngress ? hostLocation : hostPoint, Type.EDGE, 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
tom80c0e5e2014-09-08 18:08:58 -070081}