blob: d7f85358021069845f2526e06524ea8bea4b1e72 [file] [log] [blame]
Michele Santuari4b6019e2014-12-19 11:31:45 +01001package org.onosproject.net.intent;
2
3import static com.google.common.base.Preconditions.checkArgument;
4import static com.google.common.base.Preconditions.checkNotNull;
5
6import java.util.Collections;
7import java.util.List;
8import java.util.Optional;
9
10import org.onlab.packet.MplsLabel;
11import org.onosproject.core.ApplicationId;
12import org.onosproject.net.ConnectPoint;
13import org.onosproject.net.Link;
14import org.onosproject.net.flow.TrafficSelector;
15import org.onosproject.net.flow.TrafficTreatment;
16import org.onosproject.net.intent.constraint.LinkTypeConstraint;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableList;
20
21
22/**
23 * Abstraction of MPLS label-switched connectivity.
24 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080025public final class MplsIntent extends ConnectivityIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010026
27 private final ConnectPoint ingressPoint;
28 private final Optional<MplsLabel> ingressLabel;
29 private final ConnectPoint egressPoint;
30 private final Optional<MplsLabel> egressLabel;
31
32 /**
33 * Creates a new MPLS intent with the supplied ingress/egress
34 * ports and labels and with built-in link type constraint to avoid optical links.
35 *
36 * @param appId application identifier
37 * @param selector traffic selector
38 * @param treatment treatment
39 * @param ingressPoint ingress port
40 * @param ingressLabel ingress MPLS label
41 * @param egressPoint egress port
42 * @param egressLabel egress MPLS label
43 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
44 */
45 public MplsIntent(ApplicationId appId, TrafficSelector selector,
46 TrafficTreatment treatment,
47 ConnectPoint ingressPoint,
48 Optional<MplsLabel> ingressLabel,
49 ConnectPoint egressPoint,
50 Optional<MplsLabel> egressLabel) {
51 this(appId, selector, treatment, ingressPoint, ingressLabel, egressPoint, egressLabel,
52 ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
53 }
54
55 /**
56 * Creates a new point-to-point intent with the supplied ingress/egress
57 * ports, labels and constraints.
58 *
59 * @param appId application identifier
60 * @param selector traffic selector
61 * @param treatment treatment
62 * @param ingressPoint ingress port
63 * @param ingressLabel ingress MPLS label
64 * @param egressPoint egress port
65 * @param egressLabel egress MPLS label
66 * @param constraints optional list of constraints
67 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
68 */
69 public MplsIntent(ApplicationId appId, TrafficSelector selector,
70 TrafficTreatment treatment,
71 ConnectPoint ingressPoint,
72 Optional<MplsLabel> ingressLabel,
73 ConnectPoint egressPoint,
74 Optional<MplsLabel> egressLabel,
75 List<Constraint> constraints) {
76
Ray Milkeyc24cde32015-03-10 18:20:18 -070077 super(appId, Collections.emptyList(), selector, treatment, constraints,
78 DEFAULT_INTENT_PRIORITY);
Michele Santuari4b6019e2014-12-19 11:31:45 +010079
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 checkNotNull(ingressLabel);
85 checkNotNull(egressLabel);
86 this.ingressPoint = ingressPoint;
87 this.ingressLabel = ingressLabel;
88 this.egressPoint = egressPoint;
89 this.egressLabel = egressLabel;
90
91 }
92
93 /**
94 * Constructor for serializer.
95 */
96 protected MplsIntent() {
97 super();
98 this.ingressPoint = null;
99 this.ingressLabel = null;
100 this.egressPoint = null;
101 this.egressLabel = null;
102
103 }
104
105 /**
106 * Returns the port on which the ingress traffic should be connected to
107 * the egress.
108 *
109 * @return ingress switch port
110 */
111 public ConnectPoint ingressPoint() {
112 return ingressPoint;
113 }
114
115 /**
116 * Returns the port on which the traffic should egress.
117 *
118 * @return egress switch port
119 */
120 public ConnectPoint egressPoint() {
121 return egressPoint;
122 }
123
124
125 /**
126 * Returns the MPLS label which the ingress traffic should tagged.
127 *
128 * @return ingress MPLS label
129 */
130 public Optional<MplsLabel> ingressLabel() {
131 return ingressLabel;
132 }
133
134 /**
135 * Returns the MPLS label which the egress traffic should tagged.
136 *
137 * @return egress MPLS label
138 */
139 public Optional<MplsLabel> egressLabel() {
140 return egressLabel;
141 }
142
143 @Override
144 public String toString() {
145 return MoreObjects.toStringHelper(getClass())
146 .add("id", id())
147 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700148 .add("priority", priority())
Michele Santuari4b6019e2014-12-19 11:31:45 +0100149 .add("selector", selector())
150 .add("treatment", treatment())
151 .add("ingressPoint", ingressPoint)
152 .add("ingressLabel", ingressLabel)
153 .add("egressPoint", egressPoint)
154 .add("egressLabel", egressLabel)
155 .add("constraints", constraints())
156 .toString();
157 }
158
159
160
161}