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, |
| 53 | DefaultTrafficSelector.builder().build(), |
| 54 | DefaultTrafficTreatment.builder().build(), |
| 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) { |
Sho SHIMIZU | d7d1800 | 2015-01-21 14:37:14 -0800 | [diff] [blame] | 90 | super(appId, Collections.emptyList(), selector, treatment, constraints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 91 | |
| 92 | // TODO: consider whether the case one and two are same is allowed |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 93 | this.one = checkNotNull(one); |
| 94 | this.two = checkNotNull(two); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 95 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 98 | private static HostId min(HostId one, HostId two) { |
| 99 | return one.hashCode() < two.hashCode() ? one : two; |
| 100 | } |
| 101 | |
| 102 | private static HostId max(HostId one, HostId two) { |
Thomas Vachuska | 46c07ad | 2014-10-21 16:01:01 -0700 | [diff] [blame] | 103 | return one.hashCode() >= two.hashCode() ? one : two; |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 106 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 107 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 108 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 109 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 110 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 111 | public HostId one() { |
| 112 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 116 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 117 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 118 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 119 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 120 | public HostId two() { |
| 121 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 125 | public String toString() { |
| 126 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 127 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 128 | .add("appId", appId()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 129 | .add("resources", resources()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 130 | .add("selector", selector()) |
| 131 | .add("treatment", treatment()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 132 | .add("constraints", constraints()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 133 | .add("one", one) |
| 134 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 135 | .toString(); |
| 136 | } |
| 137 | |
| 138 | } |