Extension of the LinkCollectionCompiler to support Domains

Introduced the DomainConstraint which marks intents that allow domains.
Added the handling of domains to the base compiler and its implementations.
Fixed existing test by adding the domain service and added new ones for domains.

Change-Id: I6594e92e41c2434a9b667415e6fb90a6c571df79
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
index f6e5dc8..32dc47f 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
@@ -25,6 +25,8 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
 import org.onosproject.net.ResourceGroup;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
@@ -52,14 +54,23 @@
 
     final ApplicationId appId = new TestApplicationId("test");
 
+    final DomainId domain = DomainId.domainId("d1");
+
+    final DeviceId d2Id = DeviceId.deviceId("of:s2");
     final ConnectPoint d2p0 = connectPoint("s2", 0);
     final ConnectPoint d2p1 = connectPoint("s2", 1);
     final ConnectPoint d2p10 = connectPoint("s2", 10);
 
+    final DeviceId d3Id = DeviceId.deviceId("of:s3");
     final ConnectPoint d3p0 = connectPoint("s3", 0);
     final ConnectPoint d3p1 = connectPoint("s3", 1);
     final ConnectPoint d3p10 = connectPoint("s3", 10);
 
+    final DeviceId d4Id = DeviceId.deviceId("of:s4");
+    final ConnectPoint d4p0 = connectPoint("s4", 0);
+    final ConnectPoint d4p1 = connectPoint("s4", 1);
+    final ConnectPoint d4p10 = connectPoint("s4", 10);
+
     final DeviceId of1Id = DeviceId.deviceId("of:of1");
     final DeviceId of2Id = DeviceId.deviceId("of:of2");
     final DeviceId of3Id = DeviceId.deviceId("of:of3");
@@ -76,6 +87,7 @@
     final ConnectPoint of4p1 = connectPoint("of4", 1);
     final ConnectPoint of4p2 = connectPoint("of4", 2);
 
+    final DeviceId d1Id = DeviceId.deviceId("of:s1");
     final ConnectPoint d1p0 = connectPoint("s1", 0);
     final ConnectPoint d1p1 = connectPoint("s1", 1);
     final ConnectPoint d1p10 = connectPoint("s1", 10);
@@ -103,6 +115,12 @@
             link(d2p1, d3p1)
     );
 
+    final Set<Link> domainP2Plinks = ImmutableSet.of(
+            link(d1p0, d2p0),
+            link(d2p1, d4p1),
+            link(d4p0, d3p0)
+    );
+
     final Set<Link> linksForSp2MpCoLoc = ImmutableSet.of(
             link(d1p0, d2p0),
             link(d2p1, d3p0)
@@ -134,6 +152,7 @@
     final List<Constraint> constraintsForMPLS = mplsConstraint();
 
     CoreService coreService;
+    DomainService domainService;
     IntentExtensionService intentExtensionService;
     IntentConfigurableRegistrator registrator;
     IdGenerator idGenerator = new MockIdGenerator();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
index 028f8bf..55c1d9b 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
@@ -25,7 +25,9 @@
 import org.onlab.packet.VlanId;
 import org.onosproject.cfg.ComponentConfigAdapter;
 import org.onosproject.core.CoreService;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.FilteredConnectPoint;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
@@ -43,13 +45,19 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyObject;
+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.hasSize;
 import static org.hamcrest.core.Is.is;
 import static org.onlab.packet.EthType.EtherType.IPV4;
 import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.flow.criteria.Criterion.Type.*;
+import static org.onosproject.net.domain.DomainId.LOCAL;
+import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
+import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
+import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
 import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
 
 /**
@@ -65,6 +73,10 @@
         expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
         sut.coreService = coreService;
 
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
+        sut.domainService = domainService;
+
         Intent.unbindIdGenerator(idGenerator);
         Intent.bindIdGenerator(idGenerator);
 
@@ -83,7 +95,7 @@
         LinkCollectionCompiler.optimizeInstructions = false;
         LinkCollectionCompiler.copyTtl = false;
 
-        replay(coreService, intentExtensionService);
+        replay(coreService, domainService, intentExtensionService);
     }
 
     @After
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java
new file mode 100644
index 0000000..1b726f7
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java
@@ -0,0 +1,337 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.intent.impl.compiler;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.cfg.ComponentConfigAdapter;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.FilteredConnectPoint;
+import org.onosproject.net.domain.DomainPointToPointIntent;
+import org.onosproject.net.domain.DomainService;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.intent.Constraint;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.intent.constraint.DomainConstraint;
+import org.onosproject.net.resource.MockResourceService;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+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.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.link;
+import static org.onosproject.net.domain.DomainId.LOCAL;
+
+/**
+ * Those tests verify the compilation process with domains included in the path.
+ */
+public class LinkCollectionIntentCompilerDomainP2PTest extends AbstractLinkCollectionTest {
+
+    private static List<Constraint> domainConstraint =
+            ImmutableList.of(DomainConstraint.domain());
+
+    @Before
+    public void setUp() {
+        sut = new LinkCollectionIntentCompiler();
+        coreService = createMock(CoreService.class);
+        expect(coreService.registerApplication("org.onosproject.net.intent"))
+                .andReturn(appId);
+        sut.coreService = coreService;
+
+        // defining the domain assignments
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(d1Id)).andReturn(LOCAL).anyTimes();
+        expect(domainService.getDomain(d2Id)).andReturn(domain).anyTimes();
+        expect(domainService.getDomain(d4Id)).andReturn(domain).anyTimes();
+        expect(domainService.getDomain(d3Id)).andReturn(LOCAL).anyTimes();
+        sut.domainService = domainService;
+
+        Intent.unbindIdGenerator(idGenerator);
+        Intent.bindIdGenerator(idGenerator);
+
+        intentExtensionService = createMock(IntentExtensionService.class);
+        intentExtensionService
+                .registerCompiler(LinkCollectionIntent.class, sut);
+        intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
+
+        registrator = new IntentConfigurableRegistrator();
+        registrator.extensionService = intentExtensionService;
+        registrator.cfgService = new ComponentConfigAdapter();
+        registrator.activate();
+
+        sut.registrator = registrator;
+        sut.resourceService = new MockResourceService();
+
+        LinkCollectionCompiler.optimizeInstructions = false;
+        LinkCollectionCompiler.copyTtl = false;
+
+        replay(coreService, domainService, intentExtensionService);
+    }
+
+    @After
+    public void tearDown() {
+        Intent.unbindIdGenerator(idGenerator);
+    }
+
+    /**
+     * We test the proper compilation of one domain device.
+     */
+    @Test
+    public void testCompilationSingleDeviceDomainP2P() {
+
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .applyTreatmentOnEgress(true)
+                .links(p2pLinks)
+                .filteredIngressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d1p10)
+                ))
+                .filteredEgressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d3p10)
+                ))
+                .constraints(domainConstraint)
+                .build();
+
+        sut.activate();
+
+        List<Intent> compiled = sut.compile(intent, Collections.emptyList());
+        assertThat(compiled, hasSize(2));
+
+        DomainPointToPointIntent domainIntent =
+                ((DomainPointToPointIntent) compiled.get(0));
+        ConnectPoint ingress =
+                domainIntent.filteredIngressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(ingress, equalTo(d2p0));
+        ConnectPoint egress =
+                domainIntent.filteredEgressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(egress, equalTo(d2p1));
+        assertThat(domainIntent.links(), hasSize(0));
+
+        Collection<FlowRule> rules =
+                ((FlowRuleIntent) compiled.get(1)).flowRules();
+        assertThat(rules, hasSize(2));
+
+        sut.deactivate();
+
+    }
+
+    /**
+     * We test the proper compilation of a domain with two devices.
+     */
+    @Test
+    public void testCompilationMultiHopDomainP2P() {
+
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .applyTreatmentOnEgress(true)
+                .links(domainP2Plinks)
+                .filteredIngressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d1p10)
+                ))
+                .filteredEgressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d3p10)
+                ))
+                .constraints(domainConstraint)
+                .build();
+
+        sut.activate();
+
+        List<Intent> compiled = sut.compile(intent, Collections.emptyList());
+        assertThat(compiled, hasSize(2));
+
+        DomainPointToPointIntent domainIntent =
+                ((DomainPointToPointIntent) compiled.get(0));
+        ConnectPoint ingress =
+                domainIntent.filteredIngressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(ingress, equalTo(d2p0));
+        ConnectPoint egress =
+                domainIntent.filteredEgressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(egress, equalTo(d4p0));
+        assertThat(domainIntent.links(), hasSize(1));
+
+        Collection<FlowRule> rules =
+                ((FlowRuleIntent) compiled.get(1)).flowRules();
+        assertThat(rules, hasSize(2));
+
+        sut.deactivate();
+
+    }
+
+
+    /**
+     * We test the proper compilation of a domain starting with a domain device.
+     */
+    @Test
+    public void testCompilationDomainStartP2P() {
+
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .applyTreatmentOnEgress(true)
+                .links(ImmutableSet.of(
+                        link(d2p0, d1p0)
+                ))
+                .filteredIngressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d2p10)
+                ))
+                .filteredEgressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d1p10)
+                ))
+                .constraints(domainConstraint)
+                .build();
+
+        sut.activate();
+
+        List<Intent> compiled = sut.compile(intent, Collections.emptyList());
+        assertThat(compiled, hasSize(2));
+
+        DomainPointToPointIntent domainIntent =
+                ((DomainPointToPointIntent) compiled.get(0));
+        ConnectPoint ingress =
+                domainIntent.filteredIngressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(ingress, equalTo(d2p10));
+        ConnectPoint egress =
+                domainIntent.filteredEgressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(egress, equalTo(d2p0));
+        assertThat(domainIntent.links(), hasSize(0));
+
+        Collection<FlowRule> rules =
+                ((FlowRuleIntent) compiled.get(1)).flowRules();
+        assertThat(rules, hasSize(1));
+
+        sut.deactivate();
+
+    }
+
+    /**
+     * We test the proper compilation of a domain ending with a domain device.
+     */
+    @Test
+    public void testCompilationDomainEndP2P() {
+
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .applyTreatmentOnEgress(true)
+                .links(ImmutableSet.of(
+                        link(d1p0, d2p0)
+                ))
+                .filteredIngressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d1p10)
+                ))
+                .filteredEgressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d2p10)
+                ))
+                .constraints(domainConstraint)
+                .build();
+
+        sut.activate();
+
+        List<Intent> compiled = sut.compile(intent, Collections.emptyList());
+        assertThat(compiled, hasSize(2));
+
+        DomainPointToPointIntent domainIntent =
+                ((DomainPointToPointIntent) compiled.get(0));
+        ConnectPoint ingress =
+                domainIntent.filteredIngressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(ingress, equalTo(d2p0));
+        ConnectPoint egress =
+                domainIntent.filteredEgressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(egress, equalTo(d2p10));
+        assertThat(domainIntent.links(), hasSize(0));
+
+        Collection<FlowRule> rules =
+                ((FlowRuleIntent) compiled.get(1)).flowRules();
+        assertThat(rules, hasSize(1));
+
+        sut.deactivate();
+
+    }
+
+    /**
+     * We test the proper compilation of a path fully inside of a domain.
+     */
+    @Test
+    public void testCompilationDomainFullP2P() {
+
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .applyTreatmentOnEgress(true)
+                .links(ImmutableSet.of(
+                        link(d2p0, d4p0)
+                ))
+                .filteredIngressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d2p10)
+                ))
+                .filteredEgressPoints(ImmutableSet.of(
+                        new FilteredConnectPoint(d4p10)
+                ))
+                .constraints(domainConstraint)
+                .build();
+
+        sut.activate();
+
+        List<Intent> compiled = sut.compile(intent, Collections.emptyList());
+        assertThat(compiled, hasSize(1));
+
+        DomainPointToPointIntent domainIntent =
+                ((DomainPointToPointIntent) compiled.get(0));
+        ConnectPoint ingress =
+                domainIntent.filteredIngressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(ingress, equalTo(d2p10));
+        ConnectPoint egress =
+                domainIntent.filteredEgressPoints().iterator().next()
+                        .connectPoint();
+        assertThat(egress, equalTo(d4p10));
+        assertThat(domainIntent.links(), hasSize(1));
+
+        sut.deactivate();
+
+    }
+
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
index 44754a6..2b93ce9 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
@@ -26,7 +26,9 @@
 import org.onlab.packet.VlanId;
 import org.onosproject.cfg.ComponentConfigAdapter;
 import org.onosproject.core.CoreService;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.FilteredConnectPoint;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
@@ -43,6 +45,7 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -50,9 +53,10 @@
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.core.Is.is;
 import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.domain.DomainId.LOCAL;
 import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
 import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
-import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*;
+import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
 
 /**
  * This set of tests are meant to test the proper compilation
@@ -68,6 +72,10 @@
                 .andReturn(appId);
         sut.coreService = coreService;
 
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
+        sut.domainService = domainService;
+
         Intent.unbindIdGenerator(idGenerator);
         Intent.bindIdGenerator(idGenerator);
 
@@ -86,7 +94,7 @@
         LinkCollectionCompiler.optimizeInstructions = false;
         LinkCollectionCompiler.copyTtl = false;
 
-        replay(coreService, intentExtensionService);
+        replay(coreService, domainService, intentExtensionService);
     }
 
     @After
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 f70c69b..d5aea2c 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
@@ -26,9 +26,11 @@
 import org.onosproject.core.CoreService;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.FilteredConnectPoint;
 import org.onosproject.net.Link;
 import org.onosproject.net.PortNumber;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
@@ -49,6 +51,7 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -60,11 +63,13 @@
 import static org.hamcrest.Matchers.is;
 import static org.onlab.packet.EthType.EtherType.IPV4;
 import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.*;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.domain.DomainId.LOCAL;
 import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
 import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
 import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
-import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*;
+import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
 
 /**
  * This set of tests are meant to test the LinkCollectionIntent
@@ -80,6 +85,10 @@
                 .andReturn(appId);
         sut.coreService = coreService;
 
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
+        sut.domainService = domainService;
+
         Intent.unbindIdGenerator(idGenerator);
         Intent.bindIdGenerator(idGenerator);
 
@@ -107,7 +116,7 @@
         LinkCollectionCompiler.optimizeInstructions = false;
         LinkCollectionCompiler.copyTtl = false;
 
-        replay(coreService, intentExtensionService);
+        replay(coreService, domainService, intentExtensionService);
 
     }
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
index 613c3cb..2c77956 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
@@ -25,9 +25,11 @@
 import org.onosproject.cfg.ComponentConfigAdapter;
 import org.onosproject.core.CoreService;
 import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.FilteredConnectPoint;
 import org.onosproject.net.Link;
 import org.onosproject.net.PortNumber;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficSelector;
@@ -50,7 +52,10 @@
 import java.util.List;
 import java.util.Set;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -59,6 +64,7 @@
 import static org.hamcrest.Matchers.nullValue;
 import static org.onosproject.net.Link.Type.DIRECT;
 import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.domain.DomainId.LOCAL;
 
 public class LinkCollectionIntentObjectiveCompilerTest extends AbstractLinkCollectionTest {
 
@@ -82,6 +88,11 @@
         compiler.coreService = coreService;
         compiler.flowObjectiveService = flowObjectiveService;
 
+
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
+        compiler.domainService = domainService;
+
         Intent.bindIdGenerator(idGenerator);
 
         intentExtensionService = createMock(IntentExtensionService.class);
@@ -99,7 +110,7 @@
         LinkCollectionCompiler.optimizeInstructions = false;
         LinkCollectionCompiler.copyTtl = false;
 
-        replay(coreService, intentExtensionService);
+        replay(coreService, domainService, intentExtensionService);
 
     }
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
index 8038619..93b83fa 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
@@ -25,7 +25,9 @@
 import org.onlab.packet.VlanId;
 import org.onosproject.cfg.ComponentConfigAdapter;
 import org.onosproject.core.CoreService;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.FilteredConnectPoint;
+import org.onosproject.net.domain.DomainService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
@@ -42,13 +44,18 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyObject;
+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.hasSize;
 import static org.hamcrest.core.Is.is;
 import static org.onlab.packet.EthType.EtherType.IPV4;
-import static org.onosproject.net.NetTestTools.*;
-import static org.onosproject.net.flow.criteria.Criterion.Type.*;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.domain.DomainId.LOCAL;
+import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
+import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
 import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
 
 /**
@@ -65,6 +72,10 @@
                 .andReturn(appId);
         sut.coreService = coreService;
 
+        domainService = createMock(DomainService.class);
+        expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
+        sut.domainService = domainService;
+
         Intent.unbindIdGenerator(idGenerator);
         Intent.bindIdGenerator(idGenerator);
 
@@ -86,7 +97,7 @@
         LinkCollectionCompiler.optimizeInstructions = true;
         LinkCollectionCompiler.copyTtl = true;
 
-        replay(coreService, intentExtensionService);
+        replay(coreService, domainService, intentExtensionService);
     }
 
     @After