blob: b07a3a61e0586b6dad09221b2ead4f59839595dc [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) {
76 super(id(PointToPointIntent.class, selector, treatment,
77 ingressPoint, egressPoint, constraints),
78 appId, null, selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080079
80 checkNotNull(ingressPoint);
81 checkNotNull(egressPoint);
82 checkArgument(!ingressPoint.equals(egressPoint),
83 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
84
85 this.ingressPoint = ingressPoint;
86 this.egressPoint = egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070087 }
88
89 /**
90 * Constructor for serializer.
91 */
92 protected PointToPointIntent() {
93 super();
tom85258ee2014-10-07 00:10:02 -070094 this.ingressPoint = null;
95 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070096 }
97
98 /**
99 * Returns the port on which the ingress traffic should be connected to
100 * the egress.
101 *
102 * @return ingress port
103 */
tom85258ee2014-10-07 00:10:02 -0700104 public ConnectPoint ingressPoint() {
105 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700106 }
107
108 /**
109 * Returns the port on which the traffic should egress.
110 *
111 * @return egress port
112 */
tom85258ee2014-10-07 00:10:02 -0700113 public ConnectPoint egressPoint() {
114 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700115 }
116
117 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700118 public String toString() {
119 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700120 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700121 .add("appId", appId())
122 .add("selector", selector())
123 .add("treatment", treatment())
124 .add("ingress", ingressPoint)
125 .add("egress", egressPoint)
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800126 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700127 .toString();
128 }
129
130}