blob: 24a3bca8c1e398e280c07c5d485c95eb71c81c8a [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
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080024import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080025import java.util.List;
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) {
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080050 this(appId, one, two, selector, treatment, Collections.emptyList());
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080051 }
52
53 /**
54 * Creates a new host-to-host intent with the supplied host pair.
55 *
56 * @param appId application identifier
57 * @param one first host
58 * @param two second host
59 * @param selector action
60 * @param treatment ingress port
61 * @param constraints optional prioritized list of path selection constraints
62 * @throws NullPointerException if {@code one} or {@code two} is null.
63 */
64 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
65 TrafficSelector selector,
66 TrafficTreatment treatment,
67 List<Constraint> constraints) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070068 super(id(HostToHostIntent.class, min(one, two), max(one, two),
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080069 selector, treatment, constraints),
70 appId, null, selector, treatment, constraints);
tomf5c9d922014-10-03 15:22:03 -070071 this.one = checkNotNull(one);
72 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080073
Brian O'Connor66630c82014-10-02 21:08:19 -070074 }
75
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070076 private static HostId min(HostId one, HostId two) {
77 return one.hashCode() < two.hashCode() ? one : two;
78 }
79
80 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070081 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070082 }
83
Brian O'Connor66630c82014-10-02 21:08:19 -070084 /**
tomf5c9d922014-10-03 15:22:03 -070085 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070086 *
tomf5c9d922014-10-03 15:22:03 -070087 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070088 */
tomf5c9d922014-10-03 15:22:03 -070089 public HostId one() {
90 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070091 }
92
93 /**
tomf5c9d922014-10-03 15:22:03 -070094 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070095 *
tomf5c9d922014-10-03 15:22:03 -070096 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070097 */
tomf5c9d922014-10-03 15:22:03 -070098 public HostId two() {
99 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700100 }
101
102 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700103 public String toString() {
104 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700105 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700106 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -0700107 .add("selector", selector())
108 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800109 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700110 .add("one", one)
111 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700112 .toString();
113 }
114
115}