blob: 3fad93ddf95108f0d2f6c1dc8f3ec951907ad299 [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'Connor66630c82014-10-02 21:08:19 -070016package org.onlab.onos.net.intent;
17
toma1d16b62014-10-02 23:45:11 -070018import com.google.common.base.MoreObjects;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070019import org.onlab.onos.core.ApplicationId;
Brian O'Connor66630c82014-10-02 21:08:19 -070020import org.onlab.onos.net.HostId;
21import org.onlab.onos.net.flow.TrafficSelector;
22import org.onlab.onos.net.flow.TrafficTreatment;
23
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080024import java.util.List;
25
toma1d16b62014-10-02 23:45:11 -070026import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070027
28/**
tomf5c9d922014-10-03 15:22:03 -070029 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070030 */
Ray Milkeye6684082014-10-16 16:59:47 -070031public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070032
tomf5c9d922014-10-03 15:22:03 -070033 private final HostId one;
34 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070035
36 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070037 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070038 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070039 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070040 * @param one first host
41 * @param two second host
toma1d16b62014-10-02 23:45:11 -070042 * @param selector action
43 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070044 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070045 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070046 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070047 TrafficSelector selector,
48 TrafficTreatment treatment) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080049 this(appId, one, two, selector, treatment, null);
50 }
51
52 /**
53 * Creates a new host-to-host intent with the supplied host pair.
54 *
55 * @param appId application identifier
56 * @param one first host
57 * @param two second host
58 * @param selector action
59 * @param treatment ingress port
60 * @param constraints optional prioritized list of path selection constraints
61 * @throws NullPointerException if {@code one} or {@code two} is null.
62 */
63 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
64 TrafficSelector selector,
65 TrafficTreatment treatment,
66 List<Constraint> constraints) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070067 super(id(HostToHostIntent.class, min(one, two), max(one, two),
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080068 selector, treatment, constraints),
69 appId, null, selector, treatment, constraints);
tomf5c9d922014-10-03 15:22:03 -070070 this.one = checkNotNull(one);
71 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080072
Brian O'Connor66630c82014-10-02 21:08:19 -070073 }
74
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070075 private static HostId min(HostId one, HostId two) {
76 return one.hashCode() < two.hashCode() ? one : two;
77 }
78
79 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070080 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070081 }
82
Brian O'Connor66630c82014-10-02 21:08:19 -070083 /**
tomf5c9d922014-10-03 15:22:03 -070084 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070085 *
tomf5c9d922014-10-03 15:22:03 -070086 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070087 */
tomf5c9d922014-10-03 15:22:03 -070088 public HostId one() {
89 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070090 }
91
92 /**
tomf5c9d922014-10-03 15:22:03 -070093 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070094 *
tomf5c9d922014-10-03 15:22:03 -070095 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070096 */
tomf5c9d922014-10-03 15:22:03 -070097 public HostId two() {
98 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -070099 }
100
101 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700102 public String toString() {
103 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700104 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700105 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -0700106 .add("selector", selector())
107 .add("treatment", treatment())
tomf5c9d922014-10-03 15:22:03 -0700108 .add("one", one)
109 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700110 .toString();
111 }
112
113}