blob: e78d78cf38e5e044c0d8d5d33148d370562c0998 [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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connor66630c82014-10-02 21:08:19 -070017
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.HostId;
22import org.onosproject.net.Link;
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080023import org.onosproject.net.flow.DefaultTrafficSelector;
24import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Brian O'Connor66630c82014-10-02 21:08:19 -070028
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080029import java.util.List;
30
toma1d16b62014-10-02 23:45:11 -070031import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070032
33/**
tomf5c9d922014-10-03 15:22:03 -070034 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070035 */
Ray Milkeye6684082014-10-16 16:59:47 -070036public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070037
tomf5c9d922014-10-03 15:22:03 -070038 private final HostId one;
39 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070040
41 /**
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080042 * Creates a new host-to-host intent with the supplied host pair and no
43 * other traffic selection or treatment criteria.
44 *
45 * @param appId application identifier
46 * @param one first host
47 * @param two second host
48 * @throws NullPointerException if {@code one} or {@code two} is null.
49 */
50 public HostToHostIntent(ApplicationId appId, HostId one, HostId two) {
51 this(appId, one, two,
52 DefaultTrafficSelector.builder().build(),
53 DefaultTrafficTreatment.builder().build(),
54 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
55 }
56
57 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070058 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070059 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070060 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070061 * @param one first host
62 * @param two second host
toma1d16b62014-10-02 23:45:11 -070063 * @param selector action
64 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070065 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070066 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070067 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070068 TrafficSelector selector,
69 TrafficTreatment treatment) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080070 this(appId, one, two, selector, treatment,
71 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080072 }
73
74 /**
75 * Creates a new host-to-host intent with the supplied host pair.
76 *
77 * @param appId application identifier
78 * @param one first host
79 * @param two second host
80 * @param selector action
81 * @param treatment ingress port
82 * @param constraints optional prioritized list of path selection constraints
83 * @throws NullPointerException if {@code one} or {@code two} is null.
84 */
85 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
86 TrafficSelector selector,
87 TrafficTreatment treatment,
88 List<Constraint> constraints) {
Brian O'Connor520c0522014-11-23 23:50:47 -080089 super(appId, null, selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080090
91 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -070092 this.one = checkNotNull(one);
93 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080094
Brian O'Connor66630c82014-10-02 21:08:19 -070095 }
96
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070097 private static HostId min(HostId one, HostId two) {
98 return one.hashCode() < two.hashCode() ? one : two;
99 }
100
101 private static HostId max(HostId one, HostId two) {
Thomas Vachuska46c07ad2014-10-21 16:01:01 -0700102 return one.hashCode() >= two.hashCode() ? one : two;
Thomas Vachuskad03a56e2014-10-21 00:51:07 -0700103 }
104
Brian O'Connor66630c82014-10-02 21:08:19 -0700105 /**
tomf5c9d922014-10-03 15:22:03 -0700106 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700107 *
tomf5c9d922014-10-03 15:22:03 -0700108 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700109 */
tomf5c9d922014-10-03 15:22:03 -0700110 public HostId one() {
111 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700112 }
113
114 /**
tomf5c9d922014-10-03 15:22:03 -0700115 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700116 *
tomf5c9d922014-10-03 15:22:03 -0700117 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700118 */
tomf5c9d922014-10-03 15:22:03 -0700119 public HostId two() {
120 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700121 }
122
123 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700124 public String toString() {
125 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700126 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700127 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -0700128 .add("selector", selector())
129 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800130 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700131 .add("one", one)
132 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700133 .toString();
134 }
135
136}