Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 20 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 21 | import org.onlab.onos.net.HostId; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 22 | import org.onlab.onos.net.Link; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.flow.TrafficSelector; |
| 24 | import org.onlab.onos.net.flow.TrafficTreatment; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 25 | import org.onlab.onos.net.intent.constraint.LinkTypeConstraint; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 32 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 33 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 34 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 35 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 36 | private final HostId one; |
| 37 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 40 | * Creates a new host-to-host intent with the supplied host pair. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 41 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 42 | * @param appId application identifier |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 43 | * @param one first host |
| 44 | * @param two second host |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 45 | * @param selector action |
| 46 | * @param treatment ingress port |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 47 | * @throws NullPointerException if {@code one} or {@code two} is null. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 48 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 49 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 50 | TrafficSelector selector, |
| 51 | TrafficTreatment treatment) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 52 | this(appId, one, two, selector, treatment, |
| 53 | ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL))); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Creates a new host-to-host intent with the supplied host pair. |
| 58 | * |
| 59 | * @param appId application identifier |
| 60 | * @param one first host |
| 61 | * @param two second host |
| 62 | * @param selector action |
| 63 | * @param treatment ingress port |
| 64 | * @param constraints optional prioritized list of path selection constraints |
| 65 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 66 | */ |
| 67 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
| 68 | TrafficSelector selector, |
| 69 | TrafficTreatment treatment, |
| 70 | List<Constraint> constraints) { |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 71 | super(id(HostToHostIntent.class, min(one, two), max(one, two), |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 72 | selector, treatment, constraints), |
| 73 | appId, null, selector, treatment, constraints); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 74 | this.one = checkNotNull(one); |
| 75 | this.two = checkNotNull(two); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 76 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 79 | private static HostId min(HostId one, HostId two) { |
| 80 | return one.hashCode() < two.hashCode() ? one : two; |
| 81 | } |
| 82 | |
| 83 | private static HostId max(HostId one, HostId two) { |
Thomas Vachuska | 46c07ad | 2014-10-21 16:01:01 -0700 | [diff] [blame] | 84 | return one.hashCode() >= two.hashCode() ? one : two; |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 87 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 88 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 89 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 90 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 91 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 92 | public HostId one() { |
| 93 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 97 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 98 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 99 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 100 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 101 | public HostId two() { |
| 102 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 106 | public String toString() { |
| 107 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 108 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 109 | .add("appId", appId()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 110 | .add("selector", selector()) |
| 111 | .add("treatment", treatment()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 112 | .add("constraints", constraints()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 113 | .add("one", one) |
| 114 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 115 | .toString(); |
| 116 | } |
| 117 | |
| 118 | } |