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 | |
Pier | 59266bc | 2018-03-15 12:10:24 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.provider.ProviderId; |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 20 | |
Pier | 59266bc | 2018-03-15 12:10:24 -0700 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkArgument; |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Default edge link model implementation. |
| 28 | */ |
| 29 | public 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 |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 40 | * @param isIngress true to indicate host-to-network direction; false |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 41 | * for network-to-host direction |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 42 | * @param annotations optional key/value annotations |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 43 | */ |
| 44 | public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 45 | HostLocation hostLocation, boolean isIngress, |
| 46 | Annotations... annotations) { |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 47 | super(providerId, isIngress ? hostPoint : hostLocation, |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 48 | isIngress ? hostLocation : hostPoint, Type.EDGE, State.ACTIVE, annotations); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 49 | 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 |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 61 | public HostLocation hostLocation() { |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 62 | return hostLocation; |
| 63 | } |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 64 | |
| 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 | */ |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 74 | public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 75 | boolean isIngress) { |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 76 | checkNotNull(edgePort, "Edge port cannot be null"); |
| 77 | HostLocation location = (edgePort instanceof HostLocation) ? |
| 78 | (HostLocation) edgePort : new HostLocation(edgePort, 0); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 79 | return new DefaultEdgeLink(ProviderId.NONE, |
| 80 | new ConnectPoint(HostId.NONE, PortNumber.P0), |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 81 | location, isIngress); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 82 | } |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 83 | |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Creates a an edge link, to the specified end-station. |
| 86 | * |
Thomas Vachuska | 9589884 | 2017-08-01 13:31:24 -0700 | [diff] [blame] | 87 | * The edge link inherits the target host annotations. |
| 88 | * |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 89 | * @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 Vachuska | 9589884 | 2017-08-01 13:31:24 -0700 | [diff] [blame] | 98 | host.location(), isIngress, host.annotations()); |
Thomas Vachuska | 25455e7 | 2015-06-04 11:31:26 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Pier | 59266bc | 2018-03-15 12:10:24 -0700 | [diff] [blame] | 101 | /** |
| 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 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 122 | } |