blob: b9baf10586d0990aaf8921da07fde1fd50aae59e [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 Vachuskadea45ff2014-11-12 18:35:46 -080019import com.google.common.collect.ImmutableList;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.ApplicationId;
Brian O'Connor66630c82014-10-02 21:08:19 -070021import org.onlab.onos.net.HostId;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080022import org.onlab.onos.net.Link;
Brian O'Connor66630c82014-10-02 21:08:19 -070023import org.onlab.onos.net.flow.TrafficSelector;
24import org.onlab.onos.net.flow.TrafficTreatment;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080025import org.onlab.onos.net.intent.constraint.LinkTypeConstraint;
Brian O'Connor66630c82014-10-02 21:08:19 -070026
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080027import java.util.List;
28
toma1d16b62014-10-02 23:45:11 -070029import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070030
31/**
tomf5c9d922014-10-03 15:22:03 -070032 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070033 */
Ray Milkeye6684082014-10-16 16:59:47 -070034public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070035
tomf5c9d922014-10-03 15:22:03 -070036 private final HostId one;
37 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070038
39 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070040 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070041 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070042 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070043 * @param one first host
44 * @param two second host
toma1d16b62014-10-02 23:45:11 -070045 * @param selector action
46 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070047 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070048 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070049 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070050 TrafficSelector selector,
51 TrafficTreatment treatment) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080052 this(appId, one, two, selector, treatment,
53 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080054 }
55
56 /**
57 * Creates a new host-to-host intent with the supplied host pair.
58 *
59 * @param appId application identifier
60 * @param one first host
61 * @param two second host
62 * @param selector action
63 * @param treatment ingress port
64 * @param constraints optional prioritized list of path selection constraints
65 * @throws NullPointerException if {@code one} or {@code two} is null.
66 */
67 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
68 TrafficSelector selector,
69 TrafficTreatment treatment,
70 List<Constraint> constraints) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070071 super(id(HostToHostIntent.class, min(one, two), max(one, two),
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080072 selector, treatment, constraints),
73 appId, null, selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080074
75 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -070076 this.one = checkNotNull(one);
77 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080078
Brian O'Connor66630c82014-10-02 21:08:19 -070079 }
80
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070081 private static HostId min(HostId one, HostId two) {
82 return one.hashCode() < two.hashCode() ? one : two;
83 }
84
85 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070086 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070087 }
88
Brian O'Connor66630c82014-10-02 21:08:19 -070089 /**
tomf5c9d922014-10-03 15:22:03 -070090 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070091 *
tomf5c9d922014-10-03 15:22:03 -070092 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070093 */
tomf5c9d922014-10-03 15:22:03 -070094 public HostId one() {
95 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070096 }
97
98 /**
tomf5c9d922014-10-03 15:22:03 -070099 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700100 *
tomf5c9d922014-10-03 15:22:03 -0700101 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700102 */
tomf5c9d922014-10-03 15:22:03 -0700103 public HostId two() {
104 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700105 }
106
107 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700108 public String toString() {
109 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700110 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700111 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -0700112 .add("selector", selector())
113 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800114 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700115 .add("one", one)
116 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700117 .toString();
118 }
119
120}