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 | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.HostId; |
| 22 | import org.onosproject.net.Link; |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 23 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 24 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 27 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 28 | |
Sho SHIMIZU | d7d1800 | 2015-01-21 14:37:14 -0800 | [diff] [blame] | 29 | import java.util.Collections; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 32 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 35 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 36 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 37 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 38 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 39 | private final HostId one; |
| 40 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 43 | * Creates a new host-to-host intent with the supplied host pair and no |
| 44 | * other traffic selection or treatment criteria. |
| 45 | * |
| 46 | * @param appId application identifier |
| 47 | * @param one first host |
| 48 | * @param two second host |
| 49 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 50 | */ |
| 51 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two) { |
| 52 | this(appId, one, two, |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame^] | 53 | DefaultTrafficSelector.emptySelector(), |
| 54 | DefaultTrafficTreatment.emptyTreatment(), |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 55 | ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL))); |
| 56 | } |
| 57 | |
| 58 | /** |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 59 | * 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] | 60 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 61 | * @param appId application identifier |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 62 | * @param one first host |
| 63 | * @param two second host |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 64 | * @param selector action |
| 65 | * @param treatment ingress port |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 66 | * @throws NullPointerException if {@code one} or {@code two} is null. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 67 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 68 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 69 | TrafficSelector selector, |
| 70 | TrafficTreatment treatment) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 71 | this(appId, one, two, selector, treatment, |
| 72 | ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL))); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Creates a new host-to-host intent with the supplied host pair. |
| 77 | * |
| 78 | * @param appId application identifier |
| 79 | * @param one first host |
| 80 | * @param two second host |
| 81 | * @param selector action |
| 82 | * @param treatment ingress port |
| 83 | * @param constraints optional prioritized list of path selection constraints |
| 84 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 85 | */ |
| 86 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
| 87 | TrafficSelector selector, |
| 88 | TrafficTreatment treatment, |
| 89 | List<Constraint> constraints) { |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 90 | this(appId, null, one, two, selector, treatment, constraints); |
| 91 | } |
| 92 | /** |
| 93 | * Creates a new host-to-host intent with the supplied host pair. |
| 94 | * |
| 95 | * @param appId application identifier |
| 96 | * @param key intent key |
| 97 | * @param one first host |
| 98 | * @param two second host |
| 99 | * @param selector action |
| 100 | * @param treatment ingress port |
| 101 | * @param constraints optional prioritized list of path selection constraints |
| 102 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 103 | */ |
| 104 | public HostToHostIntent(ApplicationId appId, Key key, |
| 105 | HostId one, HostId two, |
| 106 | TrafficSelector selector, |
| 107 | TrafficTreatment treatment, |
| 108 | List<Constraint> constraints) { |
| 109 | super(appId, key, Collections.emptyList(), selector, treatment, constraints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 110 | |
| 111 | // TODO: consider whether the case one and two are same is allowed |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 112 | this.one = checkNotNull(one); |
| 113 | this.two = checkNotNull(two); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 114 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 117 | private static HostId min(HostId one, HostId two) { |
| 118 | return one.hashCode() < two.hashCode() ? one : two; |
| 119 | } |
| 120 | |
| 121 | private static HostId max(HostId one, HostId two) { |
Thomas Vachuska | 46c07ad | 2014-10-21 16:01:01 -0700 | [diff] [blame] | 122 | return one.hashCode() >= two.hashCode() ? one : two; |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 125 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 126 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 127 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 128 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 129 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 130 | public HostId one() { |
| 131 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 135 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 136 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 137 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 138 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 139 | public HostId two() { |
| 140 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 144 | public String toString() { |
| 145 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 146 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 147 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 148 | .add("appId", appId()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 149 | .add("resources", resources()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 150 | .add("selector", selector()) |
| 151 | .add("treatment", treatment()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 152 | .add("constraints", constraints()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 153 | .add("one", one) |
| 154 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 155 | .toString(); |
| 156 | } |
| 157 | |
| 158 | } |