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/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index 0ce0b3c..9b131ae 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -244,6 +244,10 @@
// Create optical connectivity intent
connectivityIntent = OpticalConnectivityIntent.builder()
.appId(appId)
+ // TODO New top-level Intent created and submitted
+ // during compilation.
+ // We'll need to track inter-Intent dependency,
+ // but `key` field cannot be used for the purpose.
.src(srcCP)
.dst(dstCP)
.signalType(ochPorts.getLeft().signalType())
@@ -324,7 +328,7 @@
rules.add(connectPorts(higherIntent.getDst(), lowerIntent.getDst(), higherIntent.priority(), slots));
}
- return new FlowRuleIntent(appId, rules, higherIntent.resources());
+ return new FlowRuleIntent(appId, higherIntent.key(), rules, higherIntent.resources());
}
/**
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index f48b844..de25fda 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -189,6 +189,7 @@
return OpticalPathIntent.builder()
.appId(parentIntent.appId())
+ .key(parentIntent.key())
.src(parentIntent.getSrc())
.dst(parentIntent.getDst())
// calling paths.iterator().next() is safe because of non-empty set
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
index 2da9a40..1d60875 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
@@ -175,7 +175,7 @@
rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
}
- return Collections.singletonList(new FlowRuleIntent(appId,
+ return Collections.singletonList(new FlowRuleIntent(appId, intent.key(),
rules, ImmutableSet.copyOf(path.links())));
}
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
index dc99574..26196b7 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
@@ -79,7 +79,10 @@
rules.addAll(createReverseRules(intent));
}
- return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+ return Collections.singletonList(new FlowRuleIntent(appId,
+ intent.key(),
+ rules,
+ intent.resources()));
}
/**
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
index 353925e..1c0eceb 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
@@ -87,6 +87,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
@@ -94,6 +95,7 @@
import static org.easymock.EasyMock.expectLastCall;
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.junit.Assert.assertEquals;
@@ -432,6 +434,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()
@@ -505,6 +511,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()
@@ -573,6 +583,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();
FlowRule rule1 = rules.stream()
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
index 810e897..f3d3e43 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
@@ -78,11 +78,13 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.easymock.EasyMock.createMock;
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.junit.Assert.assertEquals;
@@ -309,6 +311,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();
// 1st Device
@@ -395,6 +401,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();
// 1st Device
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
index 1fe306d..0c2d25e 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
@@ -38,12 +38,15 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import static org.easymock.EasyMock.createMock;
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.junit.Assert.assertEquals;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.NetTestTools.PID;
@@ -108,6 +111,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();
rules.stream()
.filter(x -> x.deviceId().equals(d1p1.deviceId()))