Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.provider.ProviderId; |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 19 | |
| 20 | import static com.google.common.base.Preconditions.checkArgument; |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 21 | import static com.google.common.base.Preconditions.checkNotNull; |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Default edge link model implementation. |
| 25 | */ |
| 26 | public 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 |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 37 | * @param isIngress true to indicate host-to-network direction; false |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 38 | * for network-to-host direction |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 39 | * @param annotations optional key/value annotations |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 40 | */ |
| 41 | public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 42 | HostLocation hostLocation, boolean isIngress, |
| 43 | Annotations... annotations) { |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 44 | super(providerId, isIngress ? hostPoint : hostLocation, |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 45 | isIngress ? hostLocation : hostPoint, Type.EDGE, State.ACTIVE, annotations); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 46 | 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 |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 58 | public HostLocation hostLocation() { |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 59 | return hostLocation; |
| 60 | } |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 61 | |
| 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 | */ |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 71 | public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 72 | boolean isIngress) { |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 73 | checkNotNull(edgePort, "Edge port cannot be null"); |
| 74 | HostLocation location = (edgePort instanceof HostLocation) ? |
| 75 | (HostLocation) edgePort : new HostLocation(edgePort, 0); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 76 | return new DefaultEdgeLink(ProviderId.NONE, |
| 77 | new ConnectPoint(HostId.NONE, PortNumber.P0), |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 78 | location, isIngress); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 79 | } |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 80 | |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Creates a an edge link, to the specified end-station. |
| 83 | * |
Thomas Vachuska | 9589884 | 2017-08-01 13:31:24 -0700 | [diff] [blame] | 84 | * The edge link inherits the target host annotations. |
| 85 | * |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 86 | * @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 Vachuska | 9589884 | 2017-08-01 13:31:24 -0700 | [diff] [blame] | 95 | host.location(), isIngress, host.annotations()); |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 96 | } |
| 97 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 98 | } |