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 | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 19 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 20 | import org.onlab.onos.net.HostId; |
| 21 | import org.onlab.onos.net.flow.TrafficSelector; |
| 22 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 23 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 27 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 28 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 29 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 30 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 31 | private final HostId one; |
| 32 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 35 | * 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] | 36 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 37 | * @param appId application identifier |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 38 | * @param one first host |
| 39 | * @param two second host |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 40 | * @param selector action |
| 41 | * @param treatment ingress port |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 42 | * @throws NullPointerException if {@code one} or {@code two} is null. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 43 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 44 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 45 | TrafficSelector selector, |
| 46 | TrafficTreatment treatment) { |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 47 | super(id(HostToHostIntent.class, min(one, two), max(one, two), |
| 48 | selector, treatment), |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 49 | appId, null, selector, treatment); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 50 | this.one = checkNotNull(one); |
| 51 | this.two = checkNotNull(two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 54 | private static HostId min(HostId one, HostId two) { |
| 55 | return one.hashCode() < two.hashCode() ? one : two; |
| 56 | } |
| 57 | |
| 58 | private static HostId max(HostId one, HostId two) { |
Thomas Vachuska | 46c07ad | 2014-10-21 16:01:01 -0700 | [diff] [blame] | 59 | return one.hashCode() >= two.hashCode() ? one : two; |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 62 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 63 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 64 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 65 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 66 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 67 | public HostId one() { |
| 68 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 72 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 73 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 74 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 75 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 76 | public HostId two() { |
| 77 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 83 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 84 | .add("appId", appId()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 85 | .add("selector", selector()) |
| 86 | .add("treatment", treatment()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 87 | .add("one", one) |
| 88 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 89 | .toString(); |
| 90 | } |
| 91 | |
| 92 | } |