Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 1 | package org.onosproject.net.intent; |
| 2 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 3 | import java.util.List; |
| 4 | import java.util.Optional; |
| 5 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 6 | import com.google.common.annotations.Beta; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 7 | import org.onlab.packet.MplsLabel; |
| 8 | import org.onosproject.core.ApplicationId; |
| 9 | import org.onosproject.net.Path; |
| 10 | import org.onosproject.net.flow.TrafficSelector; |
| 11 | import org.onosproject.net.flow.TrafficTreatment; |
| 12 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 13 | import static com.google.common.base.Preconditions.checkNotNull; |
| 14 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * Abstraction of explicit MPLS label-switched path. |
| 18 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 19 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 20 | public final class MplsPathIntent extends PathIntent { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 21 | |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 22 | private final Optional<MplsLabel> ingressLabel; |
| 23 | private final Optional<MplsLabel> egressLabel; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 27 | * ports and using the specified explicit path. |
| 28 | * |
| 29 | * @param appId application identifier |
| 30 | * @param selector traffic selector |
| 31 | * @param treatment treatment |
| 32 | * @param path traversed links |
| 33 | * @param ingressLabel MPLS egress label |
| 34 | * @param egressLabel MPLS ingress label |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 35 | * @param constraints optional list of constraints |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 36 | * @param priority priority to use for flows generated by this intent |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 37 | * @throws NullPointerException {@code path} is null |
| 38 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 39 | private MplsPathIntent(ApplicationId appId, TrafficSelector selector, |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 40 | TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 41 | Optional<MplsLabel> egressLabel, List<Constraint> constraints, |
| 42 | int priority) { |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 43 | super(appId, selector, treatment, path, constraints, |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 44 | priority); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 45 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 46 | this.ingressLabel = checkNotNull(ingressLabel); |
| 47 | this.egressLabel = checkNotNull(egressLabel); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 51 | * Returns a new host to host intent builder. |
| 52 | * |
| 53 | * @return host to host intent builder |
| 54 | */ |
| 55 | public static Builder builder() { |
| 56 | return new Builder(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Builder of a host to host intent. |
| 61 | */ |
| 62 | public static final class Builder extends PathIntent.Builder { |
| 63 | private Optional<MplsLabel> ingressLabel = Optional.empty(); |
| 64 | private Optional<MplsLabel> egressLabel = Optional.empty(); |
| 65 | |
| 66 | private Builder() { |
| 67 | // Hide constructor |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Builder appId(ApplicationId appId) { |
| 72 | return (Builder) super.appId(appId); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public Builder key(Key key) { |
| 77 | return (Builder) super.key(key); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Builder selector(TrafficSelector selector) { |
| 82 | return (Builder) super.selector(selector); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Builder treatment(TrafficTreatment treatment) { |
| 87 | return (Builder) super.treatment(treatment); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Builder constraints(List<Constraint> constraints) { |
| 92 | return (Builder) super.constraints(constraints); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Builder priority(int priority) { |
| 97 | return (Builder) super.priority(priority); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public Builder path(Path path) { |
| 102 | return (Builder) super.path(path); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the ingress label of the intent that will be built. |
| 107 | * |
| 108 | * @param ingressLabel ingress label |
| 109 | * @return this builder |
| 110 | */ |
| 111 | public Builder ingressLabel(Optional<MplsLabel> ingressLabel) { |
| 112 | this.ingressLabel = ingressLabel; |
| 113 | return this; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the ingress label of the intent that will be built. |
| 118 | * |
| 119 | * @param egressLabel ingress label |
| 120 | * @return this builder |
| 121 | */ |
| 122 | public Builder egressLabel(Optional<MplsLabel> egressLabel) { |
| 123 | this.egressLabel = egressLabel; |
| 124 | return this; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /** |
| 129 | * Builds a host to host intent from the accumulated parameters. |
| 130 | * |
| 131 | * @return point to point intent |
| 132 | */ |
| 133 | public MplsPathIntent build() { |
| 134 | |
| 135 | return new MplsPathIntent( |
| 136 | appId, |
| 137 | selector, |
| 138 | treatment, |
| 139 | path, |
| 140 | ingressLabel, |
| 141 | egressLabel, |
| 142 | constraints, |
| 143 | priority |
| 144 | ); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | /** |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 150 | * Returns the MPLS label which the ingress traffic should tagged. |
| 151 | * |
| 152 | * @return ingress MPLS label |
| 153 | */ |
| 154 | public Optional<MplsLabel> ingressLabel() { |
| 155 | return ingressLabel; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the MPLS label which the egress traffic should tagged. |
| 160 | * |
| 161 | * @return egress MPLS label |
| 162 | */ |
| 163 | public Optional<MplsLabel> egressLabel() { |
| 164 | return egressLabel; |
| 165 | } |
| 166 | |
| 167 | } |