blob: 28af4c77d1efd7f10a3ca3db12e175c89fab84fa [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'Connorb876bf12014-10-02 14:59:37 -070016package org.onlab.onos.net.intent;
17
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;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070021import org.onlab.onos.net.ConnectPoint;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080022import org.onlab.onos.net.Link;
Brian O'Connorb876bf12014-10-02 14:59:37 -070023import org.onlab.onos.net.flow.TrafficSelector;
24import org.onlab.onos.net.flow.TrafficTreatment;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080025import org.onlab.onos.net.intent.constraint.LinkTypeConstraint;
26
27import java.util.List;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
Sho SHIMIZU2e660802014-11-21 14:55:32 -080029import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070030import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32/**
33 * Abstraction of point-to-point connectivity.
34 */
35public class PointToPointIntent extends ConnectivityIntent {
36
tom85258ee2014-10-07 00:10:02 -070037 private final ConnectPoint ingressPoint;
38 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
40 /**
41 * Creates a new point-to-point intent with the supplied ingress/egress
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080042 * ports and with built-in link type constraint to avoid optical links.
Brian O'Connorb876bf12014-10-02 14:59:37 -070043 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070045 * @param selector traffic selector
46 * @param treatment treatment
47 * @param ingressPoint ingress port
48 * @param egressPoint egress port
49 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070052 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070053 ConnectPoint ingressPoint,
54 ConnectPoint egressPoint) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080055 this(appId, selector, treatment, ingressPoint, egressPoint,
56 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
57 }
58
59 /**
60 * Creates a new point-to-point intent with the supplied ingress/egress
61 * ports and constraints.
62 *
63 * @param appId application identifier
64 * @param selector traffic selector
65 * @param treatment treatment
66 * @param ingressPoint ingress port
67 * @param egressPoint egress port
68 * @param constraints optional list of constraints
69 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
70 */
71 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
72 TrafficTreatment treatment,
73 ConnectPoint ingressPoint,
74 ConnectPoint egressPoint,
75 List<Constraint> constraints) {
Brian O'Connor520c0522014-11-23 23:50:47 -080076 super(appId, null, selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080077
78 checkNotNull(ingressPoint);
79 checkNotNull(egressPoint);
80 checkArgument(!ingressPoint.equals(egressPoint),
81 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
82
83 this.ingressPoint = ingressPoint;
84 this.egressPoint = egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070085 }
86
87 /**
88 * Constructor for serializer.
89 */
90 protected PointToPointIntent() {
91 super();
tom85258ee2014-10-07 00:10:02 -070092 this.ingressPoint = null;
93 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070094 }
95
96 /**
97 * Returns the port on which the ingress traffic should be connected to
98 * the egress.
99 *
100 * @return ingress port
101 */
tom85258ee2014-10-07 00:10:02 -0700102 public ConnectPoint ingressPoint() {
103 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700104 }
105
106 /**
107 * Returns the port on which the traffic should egress.
108 *
109 * @return egress port
110 */
tom85258ee2014-10-07 00:10:02 -0700111 public ConnectPoint egressPoint() {
112 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700113 }
114
115 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700116 public String toString() {
117 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700118 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700119 .add("appId", appId())
120 .add("selector", selector())
121 .add("treatment", treatment())
122 .add("ingress", ingressPoint)
123 .add("egress", egressPoint)
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800124 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700125 .toString();
126 }
127
128}