blob: 3bf5e4ed54112d31363d5df93c61a93e450cc9e0 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Brian O'Connor66630c82014-10-02 21:08:19 -070019package org.onlab.onos.net.intent;
20
toma1d16b62014-10-02 23:45:11 -070021import com.google.common.base.MoreObjects;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070022import org.onlab.onos.core.ApplicationId;
Brian O'Connor66630c82014-10-02 21:08:19 -070023import org.onlab.onos.net.HostId;
24import org.onlab.onos.net.flow.TrafficSelector;
25import org.onlab.onos.net.flow.TrafficTreatment;
26
toma1d16b62014-10-02 23:45:11 -070027import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070028
29/**
tomf5c9d922014-10-03 15:22:03 -070030 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070031 */
Ray Milkeye6684082014-10-16 16:59:47 -070032public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070033
tomf5c9d922014-10-03 15:22:03 -070034 private final HostId one;
35 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070036
37 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070038 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070039 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070040 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070041 * @param one first host
42 * @param two second host
toma1d16b62014-10-02 23:45:11 -070043 * @param selector action
44 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070045 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070046 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070048 TrafficSelector selector,
49 TrafficTreatment treatment) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070050 super(id(HostToHostIntent.class, min(one, two), max(one, two),
51 selector, treatment),
Thomas Vachuskac96058a2014-10-20 23:00:16 -070052 appId, null, selector, treatment);
tomf5c9d922014-10-03 15:22:03 -070053 this.one = checkNotNull(one);
54 this.two = checkNotNull(two);
Brian O'Connor66630c82014-10-02 21:08:19 -070055 }
56
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070057 private static HostId min(HostId one, HostId two) {
58 return one.hashCode() < two.hashCode() ? one : two;
59 }
60
61 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070062 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070063 }
64
Brian O'Connor66630c82014-10-02 21:08:19 -070065 /**
tomf5c9d922014-10-03 15:22:03 -070066 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070067 *
tomf5c9d922014-10-03 15:22:03 -070068 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070069 */
tomf5c9d922014-10-03 15:22:03 -070070 public HostId one() {
71 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070072 }
73
74 /**
tomf5c9d922014-10-03 15:22:03 -070075 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070076 *
tomf5c9d922014-10-03 15:22:03 -070077 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070078 */
tomf5c9d922014-10-03 15:22:03 -070079 public HostId two() {
80 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -070081 }
82
83 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -070084 public String toString() {
85 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070086 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070087 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -070088 .add("selector", selector())
89 .add("treatment", treatment())
tomf5c9d922014-10-03 15:22:03 -070090 .add("one", one)
91 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -070092 .toString();
93 }
94
95}