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