Committed by
Gerrit Code Review
ONOS-3224 HostToHostIntent should have implicit non-OPTICAL constraint
Change-Id: Ibd6214e9b12199f56f0761cfdaa1eb45a600eb1c
Showing
2 changed files
with
71 additions
and
1 deletions
| ... | @@ -17,11 +17,15 @@ package org.onosproject.net.intent; | ... | @@ -17,11 +17,15 @@ package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
| 19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
| 20 | +import com.google.common.collect.ImmutableList; | ||
| 20 | import com.google.common.collect.ImmutableSet; | 21 | import com.google.common.collect.ImmutableSet; |
| 22 | + | ||
| 21 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.HostId; | 24 | import org.onosproject.net.HostId; |
| 25 | +import org.onosproject.net.Link; | ||
| 23 | import org.onosproject.net.flow.TrafficSelector; | 26 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; | 27 | import org.onosproject.net.flow.TrafficTreatment; |
| 28 | +import org.onosproject.net.intent.constraint.LinkTypeConstraint; | ||
| 25 | 29 | ||
| 26 | import java.util.List; | 30 | import java.util.List; |
| 27 | 31 | ||
| ... | @@ -33,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -33,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 33 | @Beta | 37 | @Beta |
| 34 | public final class HostToHostIntent extends ConnectivityIntent { | 38 | public final class HostToHostIntent extends ConnectivityIntent { |
| 35 | 39 | ||
| 40 | + static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL); | ||
| 41 | + | ||
| 36 | private final HostId one; | 42 | private final HostId one; |
| 37 | private final HostId two; | 43 | private final HostId two; |
| 38 | 44 | ||
| ... | @@ -115,6 +121,15 @@ public final class HostToHostIntent extends ConnectivityIntent { | ... | @@ -115,6 +121,15 @@ public final class HostToHostIntent extends ConnectivityIntent { |
| 115 | */ | 121 | */ |
| 116 | public HostToHostIntent build() { | 122 | public HostToHostIntent build() { |
| 117 | 123 | ||
| 124 | + List<Constraint> theConstraints = constraints; | ||
| 125 | + // If not-OPTICAL constraint hasn't been specified, add them | ||
| 126 | + if (!constraints.contains(NOT_OPTICAL)) { | ||
| 127 | + theConstraints = ImmutableList.<Constraint>builder() | ||
| 128 | + .add(NOT_OPTICAL) | ||
| 129 | + .addAll(constraints) | ||
| 130 | + .build(); | ||
| 131 | + } | ||
| 132 | + | ||
| 118 | return new HostToHostIntent( | 133 | return new HostToHostIntent( |
| 119 | appId, | 134 | appId, |
| 120 | key, | 135 | key, |
| ... | @@ -122,7 +137,7 @@ public final class HostToHostIntent extends ConnectivityIntent { | ... | @@ -122,7 +137,7 @@ public final class HostToHostIntent extends ConnectivityIntent { |
| 122 | two, | 137 | two, |
| 123 | selector, | 138 | selector, |
| 124 | treatment, | 139 | treatment, |
| 125 | - constraints, | 140 | + theConstraints, |
| 126 | priority | 141 | priority |
| 127 | ); | 142 | ); |
| 128 | } | 143 | } | ... | ... |
| ... | @@ -16,15 +16,20 @@ | ... | @@ -16,15 +16,20 @@ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | +import org.onlab.util.Bandwidth; | ||
| 19 | import org.onosproject.TestApplicationId; | 20 | import org.onosproject.TestApplicationId; |
| 20 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.HostId; | 22 | import org.onosproject.net.HostId; |
| 22 | import org.onosproject.net.flow.TrafficSelector; | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | +import org.onosproject.net.intent.constraint.BandwidthConstraint; | ||
| 25 | +import org.onosproject.net.resource.link.BandwidthResource; | ||
| 23 | 26 | ||
| 27 | +import com.google.common.collect.ImmutableList; | ||
| 24 | import com.google.common.testing.EqualsTester; | 28 | import com.google.common.testing.EqualsTester; |
| 25 | 29 | ||
| 26 | import static org.hamcrest.MatcherAssert.assertThat; | 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.equalTo; | 31 | import static org.hamcrest.Matchers.equalTo; |
| 32 | +import static org.hamcrest.Matchers.hasItem; | ||
| 28 | import static org.hamcrest.Matchers.is; | 33 | import static org.hamcrest.Matchers.is; |
| 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 34 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 30 | import static org.onosproject.net.NetTestTools.hid; | 35 | import static org.onosproject.net.NetTestTools.hid; |
| ... | @@ -102,6 +107,56 @@ public class HostToHostIntentTest extends IntentTest { | ... | @@ -102,6 +107,56 @@ public class HostToHostIntentTest extends IntentTest { |
| 102 | .testEquals(); | 107 | .testEquals(); |
| 103 | } | 108 | } |
| 104 | 109 | ||
| 110 | + @Test | ||
| 111 | + public void testImplicitConstraintsAreAdded() { | ||
| 112 | + final BandwidthConstraint other = new BandwidthConstraint( | ||
| 113 | + new BandwidthResource(Bandwidth.gbps(1))); | ||
| 114 | + final HostToHostIntent intent = HostToHostIntent.builder() | ||
| 115 | + .appId(APPID) | ||
| 116 | + .one(id1) | ||
| 117 | + .two(id2) | ||
| 118 | + .selector(selector) | ||
| 119 | + .treatment(treatment) | ||
| 120 | + .constraints(ImmutableList.of(other)) | ||
| 121 | + .build(); | ||
| 122 | + | ||
| 123 | + assertThat(intent.constraints(), hasItem(HostToHostIntent.NOT_OPTICAL)); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Test | ||
| 127 | + public void testImplicitConstraints() { | ||
| 128 | + final HostToHostIntent implicit = HostToHostIntent.builder() | ||
| 129 | + .appId(APPID) | ||
| 130 | + .one(id1) | ||
| 131 | + .two(id2) | ||
| 132 | + .selector(selector) | ||
| 133 | + .treatment(treatment) | ||
| 134 | + .build(); | ||
| 135 | + final HostToHostIntent empty = HostToHostIntent.builder() | ||
| 136 | + .appId(APPID) | ||
| 137 | + .one(id1) | ||
| 138 | + .two(id2) | ||
| 139 | + .selector(selector) | ||
| 140 | + .treatment(treatment) | ||
| 141 | + .constraints(ImmutableList.of()) | ||
| 142 | + .build(); | ||
| 143 | + final HostToHostIntent exact = HostToHostIntent.builder() | ||
| 144 | + .appId(APPID) | ||
| 145 | + .one(id1) | ||
| 146 | + .two(id2) | ||
| 147 | + .selector(selector) | ||
| 148 | + .treatment(treatment) | ||
| 149 | + .constraints(ImmutableList.of(HostToHostIntent.NOT_OPTICAL)) | ||
| 150 | + .build(); | ||
| 151 | + | ||
| 152 | + new EqualsTester() | ||
| 153 | + .addEqualityGroup(implicit.constraints(), | ||
| 154 | + empty.constraints(), | ||
| 155 | + exact.constraints()) | ||
| 156 | + .testEquals(); | ||
| 157 | + | ||
| 158 | + } | ||
| 159 | + | ||
| 105 | @Override | 160 | @Override |
| 106 | protected Intent createOne() { | 161 | protected Intent createOne() { |
| 107 | return HostToHostIntent.builder() | 162 | return HostToHostIntent.builder() | ... | ... |
-
Please register or login to post a comment