HIGUCHI Yuta
Committed by Gerrit Code Review

ONOS-3224 HostToHostIntent should have implicit non-OPTICAL constraint

Change-Id: Ibd6214e9b12199f56f0761cfdaa1eb45a600eb1c
......@@ -17,11 +17,15 @@ package org.onosproject.net.intent;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.HostId;
import org.onosproject.net.Link;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import java.util.List;
......@@ -33,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
@Beta
public final class HostToHostIntent extends ConnectivityIntent {
static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL);
private final HostId one;
private final HostId two;
......@@ -115,6 +121,15 @@ public final class HostToHostIntent extends ConnectivityIntent {
*/
public HostToHostIntent build() {
List<Constraint> theConstraints = constraints;
// If not-OPTICAL constraint hasn't been specified, add them
if (!constraints.contains(NOT_OPTICAL)) {
theConstraints = ImmutableList.<Constraint>builder()
.add(NOT_OPTICAL)
.addAll(constraints)
.build();
}
return new HostToHostIntent(
appId,
key,
......@@ -122,7 +137,7 @@ public final class HostToHostIntent extends ConnectivityIntent {
two,
selector,
treatment,
constraints,
theConstraints,
priority
);
}
......
......@@ -16,15 +16,20 @@
package org.onosproject.net.intent;
import org.junit.Test;
import org.onlab.util.Bandwidth;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.HostId;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.resource.link.BandwidthResource;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import static org.onosproject.net.NetTestTools.hid;
......@@ -102,6 +107,56 @@ public class HostToHostIntentTest extends IntentTest {
.testEquals();
}
@Test
public void testImplicitConstraintsAreAdded() {
final BandwidthConstraint other = new BandwidthConstraint(
new BandwidthResource(Bandwidth.gbps(1)));
final HostToHostIntent intent = HostToHostIntent.builder()
.appId(APPID)
.one(id1)
.two(id2)
.selector(selector)
.treatment(treatment)
.constraints(ImmutableList.of(other))
.build();
assertThat(intent.constraints(), hasItem(HostToHostIntent.NOT_OPTICAL));
}
@Test
public void testImplicitConstraints() {
final HostToHostIntent implicit = HostToHostIntent.builder()
.appId(APPID)
.one(id1)
.two(id2)
.selector(selector)
.treatment(treatment)
.build();
final HostToHostIntent empty = HostToHostIntent.builder()
.appId(APPID)
.one(id1)
.two(id2)
.selector(selector)
.treatment(treatment)
.constraints(ImmutableList.of())
.build();
final HostToHostIntent exact = HostToHostIntent.builder()
.appId(APPID)
.one(id1)
.two(id2)
.selector(selector)
.treatment(treatment)
.constraints(ImmutableList.of(HostToHostIntent.NOT_OPTICAL))
.build();
new EqualsTester()
.addEqualityGroup(implicit.constraints(),
empty.constraints(),
exact.constraints())
.testEquals();
}
@Override
protected Intent createOne() {
return HostToHostIntent.builder()
......