Inherit Intent Key on compilation
- Added Intent#key() method description
- Inherit key field from parent Intent during Intent
compilation process
- Added assertion to existing unit tests
Change-Id: Iff85c5ec448b3f378957b7a20af865ad96cc3216
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index 427d56d..dad8e3b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -122,6 +122,7 @@
.matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
return PathIntent.builder()
.appId(intent.appId())
+ .key(intent.key())
.selector(selector)
.treatment(intent.treatment())
.path(path)
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
index d93764b..969372d 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
@@ -123,7 +123,7 @@
labels)
);
}
- return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+ return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources()));
}
@Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
index 0a15097..6a0081f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
@@ -119,7 +119,7 @@
});
}
return Collections.singletonList(
- new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
+ new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources()));
}
@Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index 9c4f535..9c84853 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -94,7 +94,10 @@
Map<LinkKey, MplsLabel> labels = assignMplsLabel(intent);
List<FlowRule> rules = generateRules(intent, labels);
- return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+ return Collections.singletonList(new FlowRuleIntent(appId,
+ intent.key(),
+ rules,
+ intent.resources()));
}
@Activate
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index f9b236f..cac5d68 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -119,6 +119,7 @@
Intent result = LinkCollectionIntent.builder()
.appId(intent.appId())
+ .key(intent.key())
.treatment(intent.treatment())
.selector(intent.selector())
.links(Sets.newHashSet(links.values()))
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
index f719a00..a2c26dd 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -83,7 +83,12 @@
List<DeviceId> devices = new LinkedList<>();
compile(this, intent, rules, devices);
- return ImmutableList.of(new FlowRuleIntent(appId, null, rules, intent.resources(), intent.type()));
+
+ return ImmutableList.of(new FlowRuleIntent(appId,
+ intent.key(),
+ rules,
+ intent.resources(),
+ intent.type()));
}
@Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
index 3f0fc19..521d6fc 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
@@ -89,7 +89,11 @@
List<DeviceId> devices = new LinkedList<>();
compile(this, intent, objectives, devices);
- return ImmutableList.of(new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
+ return ImmutableList.of(new FlowObjectiveIntent(appId,
+ intent.key(),
+ devices,
+ objectives,
+ intent.resources()));
}
@Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index 02b8865..a6fac6f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -256,6 +256,7 @@
createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(),
+ intent.key(),
createFailoverFlowRules(intent),
asList(ingressPoint.deviceId()),
PathIntent.ProtectionType.FAILOVER);
@@ -312,6 +313,7 @@
PathIntent.ProtectionType type) {
return PathIntent.builder()
.appId(intent.appId())
+ .key(intent.key())
.selector(intent.selector())
.treatment(intent.treatment())
.path(path)
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
index 4dc5045..d6333ff 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
@@ -39,10 +39,12 @@
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.easymock.EasyMock.*;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.NetTestTools.connectPoint;
@@ -80,6 +82,7 @@
private HostId hostTwoId = HostId.hostId(HOST_TWO);
private HostService mockHostService;
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
@@ -188,5 +191,9 @@
egressPoints = ImmutableSet.of(new FilteredConnectPoint(connectPoint(HOP_1, PORT_1)));
assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
+
+ assertThat("key is inherited",
+ result.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
index 4c45bb4..3970f8d 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -54,6 +54,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onlab.packet.EthType.EtherType.IPV4;
@@ -116,6 +117,11 @@
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
+
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(links.size()));
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
index 60da118..ce5f3b7 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -146,6 +146,7 @@
assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -178,6 +179,7 @@
assertThat(linkIntent.links(), linksHasPath("inner1", "inner2"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -213,6 +215,7 @@
}
assertThat(linkIntent.links(), linksHasPath("n1", egress));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -243,6 +246,7 @@
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
assertThat(linkIntent.links(), linksHasPath("i2", "i3"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -280,6 +284,7 @@
assertThat(linkIntent.links(), linksHasPath("of2", "of3"));
assertThat(linkIntent.links(), linksHasPath("of3", "of4"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
@@ -323,6 +328,7 @@
assertThat(linkIntent.links(), linksHasPath("of3", "of4"));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
index e9f5170..f7579d8 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
@@ -60,6 +60,7 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
@@ -783,6 +784,10 @@
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream()
@@ -987,8 +992,8 @@
.collect(Collectors.toSet());
assertThat(vlanRules, hasSize(1));
L2ModificationInstruction.ModVlanIdInstruction vlanRule = vlanRules.iterator().next();
- assertThat(vlanRule.vlanId().toShort(), greaterThan((short) VlanId.NO_VID));
- assertThat(vlanRule.vlanId().toShort(), lessThan((short) VlanId.MAX_VLAN));
+ assertThat(vlanRule.vlanId().toShort(), greaterThan(VlanId.NO_VID));
+ assertThat(vlanRule.vlanId().toShort(), lessThan(VlanId.MAX_VLAN));
vlanToEncap = vlanRule.vlanId();
} else if (!isIngress && !isEgress) {
@@ -998,8 +1003,8 @@
.collect(Collectors.toSet());
assertThat(vlanRules, hasSize(1));
L2ModificationInstruction.ModVlanIdInstruction vlanRule = vlanRules.iterator().next();
- assertThat(vlanRule.vlanId().toShort(), greaterThan((short) VlanId.NO_VID));
- assertThat(vlanRule.vlanId().toShort(), lessThan((short) VlanId.MAX_VLAN));
+ assertThat(vlanRule.vlanId().toShort(), greaterThan(VlanId.NO_VID));
+ assertThat(vlanRule.vlanId().toShort(), lessThan(VlanId.MAX_VLAN));
vlanToEncap = vlanRule.vlanId();
} else {
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
index d61e01d..65251dd 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -39,10 +39,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.fail;
@@ -159,6 +161,7 @@
assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
+ assertThat("key is inherited", forwardResultIntent.key(), is(intent.key()));
}
/**
@@ -193,6 +196,7 @@
assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
+ assertThat("key is inherited", reverseResultIntent.key(), is(intent.key()));
}
/**
@@ -215,6 +219,10 @@
List<Intent> compiled = sut.compile(intent, null);
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
assertThat(compiled, hasSize(1));
assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class)));
LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0);
@@ -245,6 +253,11 @@
assertThat(compiledIntents, Matchers.notNullValue());
assertThat(compiledIntents, hasSize(1));
+
+ assertThat("key is inherited",
+ compiledIntents.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
index cb13c68..eec242c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
@@ -37,7 +37,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -150,6 +149,7 @@
assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -182,6 +182,7 @@
assertThat(linkIntent.links(), linksHasPath("inner2", "egress1"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress2"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -215,6 +216,7 @@
}
assertThat(linkIntent.links(), linksHasPath(ingress, "n1"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -245,6 +247,7 @@
assertThat(linkIntent.links(), linksHasPath("i1", "i2"));
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -291,6 +294,7 @@
assertThat("Link collection egress points do not match base intent",
linkIntent.filteredEgressPoints().equals(intent.filteredEgressPoints()));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
@@ -342,6 +346,7 @@
linkIntent.filteredEgressPoints().equals(intent.filteredEgressPoints()));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
}