blob: 0c13e3f655940881043d6dde2e69e0d3954d87e4 [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
77 super(appId, Collections.emptyList(), selector, treatment, constraints);
78
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 checkNotNull(ingressLabel);
84 checkNotNull(egressLabel);
85 this.ingressPoint = ingressPoint;
86 this.ingressLabel = ingressLabel;
87 this.egressPoint = egressPoint;
88 this.egressLabel = egressLabel;
89
90 }
91
92 /**
93 * Constructor for serializer.
94 */
95 protected MplsIntent() {
96 super();
97 this.ingressPoint = null;
98 this.ingressLabel = null;
99 this.egressPoint = null;
100 this.egressLabel = null;
101
102 }
103
104 /**
105 * Returns the port on which the ingress traffic should be connected to
106 * the egress.
107 *
108 * @return ingress switch port
109 */
110 public ConnectPoint ingressPoint() {
111 return ingressPoint;
112 }
113
114 /**
115 * Returns the port on which the traffic should egress.
116 *
117 * @return egress switch port
118 */
119 public ConnectPoint egressPoint() {
120 return egressPoint;
121 }
122
123
124 /**
125 * Returns the MPLS label which the ingress traffic should tagged.
126 *
127 * @return ingress MPLS label
128 */
129 public Optional<MplsLabel> ingressLabel() {
130 return ingressLabel;
131 }
132
133 /**
134 * Returns the MPLS label which the egress traffic should tagged.
135 *
136 * @return egress MPLS label
137 */
138 public Optional<MplsLabel> egressLabel() {
139 return egressLabel;
140 }
141
142 @Override
143 public String toString() {
144 return MoreObjects.toStringHelper(getClass())
145 .add("id", id())
146 .add("appId", appId())
147 .add("selector", selector())
148 .add("treatment", treatment())
149 .add("ingressPoint", ingressPoint)
150 .add("ingressLabel", ingressLabel)
151 .add("egressPoint", egressPoint)
152 .add("egressLabel", egressLabel)
153 .add("constraints", constraints())
154 .toString();
155 }
156
157
158
159}