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