blob: c4c53c79f69a2af290790d53a0efcd48da66abc9 [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
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080043 * ports and with built-in link type constraint to avoid optical links.
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070046 * @param selector traffic selector
47 * @param treatment treatment
48 * @param ingressPoint ingress port
49 * @param egressPoint egress port
50 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
Brian O'Connorb876bf12014-10-02 14:59:37 -070051 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070052 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070053 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070054 ConnectPoint ingressPoint,
55 ConnectPoint egressPoint) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080056 this(appId, selector, treatment, ingressPoint, egressPoint,
57 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
58 }
59
60 /**
61 * Creates a new point-to-point intent with the supplied ingress/egress
62 * ports and constraints.
63 *
64 * @param appId application identifier
65 * @param selector traffic selector
66 * @param treatment treatment
67 * @param ingressPoint ingress port
68 * @param egressPoint egress port
69 * @param constraints optional list of constraints
70 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
71 */
72 public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
73 TrafficTreatment treatment,
74 ConnectPoint ingressPoint,
75 ConnectPoint egressPoint,
76 List<Constraint> constraints) {
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080077 super(appId, Collections.emptyList(), selector, treatment, constraints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080078
79 checkNotNull(ingressPoint);
80 checkNotNull(egressPoint);
81 checkArgument(!ingressPoint.equals(egressPoint),
82 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
83
84 this.ingressPoint = ingressPoint;
85 this.egressPoint = egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070086 }
87
88 /**
89 * Constructor for serializer.
90 */
91 protected PointToPointIntent() {
92 super();
tom85258ee2014-10-07 00:10:02 -070093 this.ingressPoint = null;
94 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070095 }
96
97 /**
98 * Returns the port on which the ingress traffic should be connected to
99 * the egress.
100 *
101 * @return ingress port
102 */
tom85258ee2014-10-07 00:10:02 -0700103 public ConnectPoint ingressPoint() {
104 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700105 }
106
107 /**
108 * Returns the port on which the traffic should egress.
109 *
110 * @return egress port
111 */
tom85258ee2014-10-07 00:10:02 -0700112 public ConnectPoint egressPoint() {
113 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700114 }
115
116 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700117 public String toString() {
118 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700119 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700120 .add("appId", appId())
121 .add("selector", selector())
122 .add("treatment", treatment())
123 .add("ingress", ingressPoint)
124 .add("egress", egressPoint)
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800125 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700126 .toString();
127 }
128
129}