blob: d47594a8ac3cc9d310774a146800dc46cee83361 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connor66630c82014-10-02 21:08:19 -070017
toma1d16b62014-10-02 23:45:11 -070018import com.google.common.base.MoreObjects;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080019import com.google.common.collect.ImmutableList;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.HostId;
22import org.onosproject.net.Link;
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080023import org.onosproject.net.flow.DefaultTrafficSelector;
24import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Brian O'Connor66630c82014-10-02 21:08:19 -070028
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080029import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080030import java.util.List;
31
toma1d16b62014-10-02 23:45:11 -070032import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070033
34/**
tomf5c9d922014-10-03 15:22:03 -070035 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070036 */
Ray Milkeye6684082014-10-16 16:59:47 -070037public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070038
tomf5c9d922014-10-03 15:22:03 -070039 private final HostId one;
40 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070041
42 /**
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080043 * 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'Connor6b528132015-03-10 16:39:52 -070053 DefaultTrafficSelector.emptySelector(),
54 DefaultTrafficTreatment.emptyTreatment(),
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080055 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
56 }
57
58 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070059 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070060 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070061 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070062 * @param one first host
63 * @param two second host
toma1d16b62014-10-02 23:45:11 -070064 * @param selector action
65 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070066 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070067 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070068 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070069 TrafficSelector selector,
70 TrafficTreatment treatment) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080071 this(appId, one, two, selector, treatment,
72 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080073 }
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 Milkey5b3717e2015-02-05 11:44:08 -080090 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 SHIMIZU2e660802014-11-21 14:55:32 -0800110
111 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700112 this.one = checkNotNull(one);
113 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800114
Brian O'Connor66630c82014-10-02 21:08:19 -0700115 }
116
Thomas Vachuskad03a56e2014-10-21 00:51:07 -0700117 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 Vachuska46c07ad2014-10-21 16:01:01 -0700122 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -0700123 }
124
Brian O'Connor66630c82014-10-02 21:08:19 -0700125 /**
tomf5c9d922014-10-03 15:22:03 -0700126 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700127 *
tomf5c9d922014-10-03 15:22:03 -0700128 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700129 */
tomf5c9d922014-10-03 15:22:03 -0700130 public HostId one() {
131 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700132 }
133
134 /**
tomf5c9d922014-10-03 15:22:03 -0700135 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700136 *
tomf5c9d922014-10-03 15:22:03 -0700137 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700138 */
tomf5c9d922014-10-03 15:22:03 -0700139 public HostId two() {
140 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700141 }
142
143 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700144 public String toString() {
145 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700146 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800147 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700148 .add("appId", appId())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800149 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700150 .add("selector", selector())
151 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800152 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700153 .add("one", one)
154 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700155 .toString();
156 }
157
158}