blob: c65d19cf7a5846714f9e5337d67bf1c643d5ae14 [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) {
Brian O'Connor520c0522014-11-23 23:50:47 -080071 super(appId, null, selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080072
73 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -070074 this.one = checkNotNull(one);
75 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080076
Brian O'Connor66630c82014-10-02 21:08:19 -070077 }
78
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070079 private static HostId min(HostId one, HostId two) {
80 return one.hashCode() < two.hashCode() ? one : two;
81 }
82
83 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -070084 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070085 }
86
Brian O'Connor66630c82014-10-02 21:08:19 -070087 /**
tomf5c9d922014-10-03 15:22:03 -070088 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070089 *
tomf5c9d922014-10-03 15:22:03 -070090 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070091 */
tomf5c9d922014-10-03 15:22:03 -070092 public HostId one() {
93 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070094 }
95
96 /**
tomf5c9d922014-10-03 15:22:03 -070097 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070098 *
tomf5c9d922014-10-03 15:22:03 -070099 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700100 */
tomf5c9d922014-10-03 15:22:03 -0700101 public HostId two() {
102 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700103 }
104
105 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700106 public String toString() {
107 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700108 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700109 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -0700110 .add("selector", selector())
111 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800112 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700113 .add("one", one)
114 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700115 .toString();
116 }
117
118}