blob: 7dad6b8a182ca673d8af264e8e2685f4ac36c3f9 [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'Connorb876bf12014-10-02 14:59:37 -070017
toma1d16b62014-10-02 23:45:11 -070018import com.google.common.base.MoreObjects;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080019import com.google.common.collect.ImmutableList;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.Link;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080026
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080027import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080028import java.util.List;
Brian O'Connorb876bf12014-10-02 14:59:37 -070029
Sho SHIMIZU2e660802014-11-21 14:55:32 -080030import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070031import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070032
33/**
34 * Abstraction of point-to-point connectivity.
35 */
36public class PointToPointIntent extends ConnectivityIntent {
37
tom85258ee2014-10-07 00:10:02 -070038 private final ConnectPoint ingressPoint;
39 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
42 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -080043 * ports and constraints.
44 *
45 * @param appId application identifier
46 * @param key key of the intent
47 * @param selector traffic selector
48 * @param treatment treatment
49 * @param ingressPoint ingress port
50 * @param egressPoint egress port
51 * @param constraints optional list of constraints
52 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
53 */
54 public PointToPointIntent(ApplicationId appId,
55 Key key,
56 TrafficSelector selector,
57 TrafficTreatment treatment,
58 ConnectPoint ingressPoint,
59 ConnectPoint egressPoint,
60 List<Constraint> constraints) {
61 super(appId, key, Collections.emptyList(), selector, treatment, constraints);
62
63 checkNotNull(ingressPoint);
64 checkNotNull(egressPoint);
65 checkArgument(!ingressPoint.equals(egressPoint),
66 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
67
68 this.ingressPoint = ingressPoint;
69 this.egressPoint = egressPoint;
70 }
71
72 /**
73 * Creates a new point-to-point intent with the supplied ingress/egress
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080074 * ports and with built-in link type constraint to avoid optical links.
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070076 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070077 * @param selector traffic selector
78 * @param treatment treatment
79 * @param ingressPoint ingress port
80 * @param egressPoint egress port
81 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
Brian O'Connorb876bf12014-10-02 14:59:37 -070082 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070083 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070084 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070085 ConnectPoint ingressPoint,
86 ConnectPoint egressPoint) {
Ray Milkey5b3717e2015-02-05 11:44:08 -080087 this(appId, null, selector, treatment, ingressPoint, egressPoint,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080088 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
89 }
90
91 /**
92 * Creates a new point-to-point intent with the supplied ingress/egress
93 * ports and constraints.
94 *
95 * @param appId application identifier
96 * @param selector traffic selector
97 * @param treatment treatment
98 * @param ingressPoint ingress port
99 * @param egressPoint egress port
100 * @param constraints optional list of constraints
101 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
102 */
103 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
104 TrafficTreatment treatment,
105 ConnectPoint ingressPoint,
106 ConnectPoint egressPoint,
107 List<Constraint> constraints) {
Ray Milkey5b3717e2015-02-05 11:44:08 -0800108 super(appId, null, Collections.emptyList(), selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800109
110 checkNotNull(ingressPoint);
111 checkNotNull(egressPoint);
112 checkArgument(!ingressPoint.equals(egressPoint),
113 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
114
115 this.ingressPoint = ingressPoint;
116 this.egressPoint = egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700117 }
118
119 /**
120 * Constructor for serializer.
121 */
122 protected PointToPointIntent() {
123 super();
tom85258ee2014-10-07 00:10:02 -0700124 this.ingressPoint = null;
125 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700126 }
127
128 /**
129 * Returns the port on which the ingress traffic should be connected to
130 * the egress.
131 *
132 * @return ingress port
133 */
tom85258ee2014-10-07 00:10:02 -0700134 public ConnectPoint ingressPoint() {
135 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700136 }
137
138 /**
139 * Returns the port on which the traffic should egress.
140 *
141 * @return egress port
142 */
tom85258ee2014-10-07 00:10:02 -0700143 public ConnectPoint egressPoint() {
144 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700145 }
146
147 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700148 public String toString() {
149 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700150 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800151 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700152 .add("appId", appId())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800153 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700154 .add("selector", selector())
155 .add("treatment", treatment())
156 .add("ingress", ingressPoint)
157 .add("egress", egressPoint)
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800158 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700159 .toString();
160 }
161
162}