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