blob: 376a122a4156719884c80eb9890dbe02a2d06949 [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
toma1d16b62014-10-02 23:45:11 -070024import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070025
26/**
tomf5c9d922014-10-03 15:22:03 -070027 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070028 */
Ray Milkeye6684082014-10-16 16:59:47 -070029public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070030
tomf5c9d922014-10-03 15:22:03 -070031 private final HostId one;
32 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070033
34 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070035 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070036 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070037 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070038 * @param one first host
39 * @param two second host
toma1d16b62014-10-02 23:45:11 -070040 * @param selector action
41 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070042 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070043 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070045 TrafficSelector selector,
46 TrafficTreatment treatment) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070047 super(id(HostToHostIntent.class, min(one, two), max(one, two),
48 selector, treatment),
Thomas Vachuskac96058a2014-10-20 23:00:16 -070049 appId, null, selector, treatment);
tomf5c9d922014-10-03 15:22:03 -070050 this.one = checkNotNull(one);
51 this.two = checkNotNull(two);
Brian O'Connor66630c82014-10-02 21:08:19 -070052 }
53
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070054 private static HostId min(HostId one, HostId two) {
55 return one.hashCode() < two.hashCode() ? one : two;
56 }
57
58 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070059 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070060 }
61
Brian O'Connor66630c82014-10-02 21:08:19 -070062 /**
tomf5c9d922014-10-03 15:22:03 -070063 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070064 *
tomf5c9d922014-10-03 15:22:03 -070065 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070066 */
tomf5c9d922014-10-03 15:22:03 -070067 public HostId one() {
68 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070069 }
70
71 /**
tomf5c9d922014-10-03 15:22:03 -070072 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070073 *
tomf5c9d922014-10-03 15:22:03 -070074 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070075 */
tomf5c9d922014-10-03 15:22:03 -070076 public HostId two() {
77 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -070078 }
79
80 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -070081 public String toString() {
82 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070083 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070084 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -070085 .add("selector", selector())
86 .add("treatment", treatment())
tomf5c9d922014-10-03 15:22:03 -070087 .add("one", one)
88 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -070089 .toString();
90 }
91
92}