ONOS-1066: Move IntentCompilers to the dedicated package

Change-Id: I3e588cab0559093d389c9d44d2c7df536cabe953
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
new file mode 100644
index 0000000..b154d22
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2014 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 org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.TestApplicationId;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.intent.AbstractIntentTest;
+import org.onosproject.net.intent.HostToHostIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.PathIntent;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+
+import java.util.List;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.NetTestTools.hid;
+import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
+
+/**
+ * Unit tests for the HostToHost intent compiler.
+ */
+public class HostToHostIntentCompilerTest extends AbstractIntentTest {
+    private static final String HOST_ONE_MAC = "00:00:00:00:00:01";
+    private static final String HOST_TWO_MAC = "00:00:00:00:00:02";
+    private static final String HOST_ONE_VLAN = "-1";
+    private static final String HOST_TWO_VLAN = "-1";
+    private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN;
+    private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN;
+
+    private static final ApplicationId APPID = new TestApplicationId("foo");
+
+    private TrafficSelector selector = new IntentTestsMocks.MockSelector();
+    private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
+
+    private HostId hostOneId = HostId.hostId(HOST_ONE);
+    private HostId hostTwoId = HostId.hostId(HOST_TWO);
+    private HostService mockHostService;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        Host hostOne = createMock(Host.class);
+        expect(hostOne.mac()).andReturn(new MacAddress(HOST_ONE_MAC.getBytes())).anyTimes();
+        expect(hostOne.vlan()).andReturn(VlanId.vlanId()).anyTimes();
+        replay(hostOne);
+
+        Host hostTwo = createMock(Host.class);
+        expect(hostTwo.mac()).andReturn(new MacAddress(HOST_TWO_MAC.getBytes())).anyTimes();
+        expect(hostTwo.vlan()).andReturn(VlanId.vlanId()).anyTimes();
+        replay(hostTwo);
+
+        mockHostService = createMock(HostService.class);
+        expect(mockHostService.getHost(eq(hostOneId))).andReturn(hostOne).anyTimes();
+        expect(mockHostService.getHost(eq(hostTwoId))).andReturn(hostTwo).anyTimes();
+        replay(mockHostService);
+    }
+
+    /**
+     * Creates a HostToHost intent based on two host Ids.
+     *
+     * @param oneIdString string for host one id
+     * @param twoIdString string for host two id
+     * @return HostToHostIntent for the two hosts
+     */
+    private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
+        return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString),
+                                    selector, treatment);
+    }
+
+    /**
+     * Creates a compiler for HostToHost intents.
+     *
+     * @param hops string array describing the path hops to use when compiling
+     * @return HostToHost intent compiler
+     */
+    private HostToHostIntentCompiler makeCompiler(String[] hops) {
+        HostToHostIntentCompiler compiler =
+                new HostToHostIntentCompiler();
+        compiler.pathService = new IntentTestsMocks.MockPathService(hops);
+        compiler.hostService = mockHostService;
+        return compiler;
+    }
+
+
+    /**
+     * Tests a pair of hosts with 8 hops between them.
+     */
+    @Test
+    public void testSingleLongPathCompilation() {
+
+        HostToHostIntent intent = makeIntent(HOST_ONE,
+                                             HOST_TWO);
+        assertThat(intent, is(notNullValue()));
+
+        String[] hops = {HOST_ONE, "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", HOST_TWO};
+        HostToHostIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(2));
+        Intent forwardResultIntent = result.get(0);
+        assertThat(forwardResultIntent instanceof PathIntent, is(true));
+        Intent reverseResultIntent = result.get(1);
+        assertThat(reverseResultIntent instanceof PathIntent, is(true));
+
+        if (forwardResultIntent instanceof PathIntent) {
+            PathIntent forwardPathIntent = (PathIntent) forwardResultIntent;
+            assertThat(forwardPathIntent.path().links(), hasSize(9));
+            assertThat(forwardPathIntent.path().links(), linksHasPath(HOST_ONE, "h1"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h1", "h2"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h2", "h3"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h3", "h4"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h4", "h5"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h5", "h6"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h6", "h7"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h7", "h8"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("h8", HOST_TWO));
+        }
+
+        if (reverseResultIntent instanceof PathIntent) {
+            PathIntent reversePathIntent = (PathIntent) reverseResultIntent;
+            assertThat(reversePathIntent.path().links(), hasSize(9));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h1", HOST_ONE));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h2", "h1"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h3", "h2"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h4", "h3"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h5", "h4"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h6", "h5"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h7", "h6"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("h8", "h7"));
+            assertThat(reversePathIntent.path().links(), linksHasPath(HOST_TWO, "h8"));
+        }
+    }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
new file mode 100644
index 0000000..40bacb9
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
@@ -0,0 +1,175 @@
+package org.onosproject.net.intent.impl.compiler;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+import org.onlab.packet.MplsLabel;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.AbstractIntentTest;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.MplsIntent;
+import org.onosproject.net.intent.MplsPathIntent;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
+
+/**
+ * Unit tests for the HostToHost intent compiler.
+ */
+public class MplsIntentCompilerTest extends AbstractIntentTest {
+
+    private static final ApplicationId APPID = new TestApplicationId("foo");
+
+    private TrafficSelector selector = new IntentTestsMocks.MockSelector();
+    private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
+
+    /**
+     * Creates a PointToPoint intent based on ingress and egress device Ids.
+     *
+     * @param ingressIdString string for id of ingress device
+     * @param egressIdString  string for id of egress device
+     * @return PointToPointIntent for the two devices
+     */
+    private MplsIntent makeIntent(String ingressIdString,  Optional<MplsLabel> ingressLabel,
+                                          String egressIdString, Optional<MplsLabel> egressLabel) {
+
+        return new MplsIntent(APPID, selector, treatment,
+                                      connectPoint(ingressIdString, 1),
+                                      ingressLabel,
+                                      connectPoint(egressIdString, 1),
+                                      egressLabel);
+    }
+    /**
+     * Creates a compiler for HostToHost intents.
+     *
+     * @param hops string array describing the path hops to use when compiling
+     * @return HostToHost intent compiler
+     */
+    private MplsIntentCompiler makeCompiler(String[] hops) {
+        MplsIntentCompiler compiler =
+                new MplsIntentCompiler();
+        compiler.pathService = new IntentTestsMocks.MockPathService(hops);
+        return compiler;
+    }
+
+
+    /**
+     * Tests a pair of devices in an 8 hop path, forward direction.
+     */
+    @Test
+    public void testForwardPathCompilation() {
+        Optional<MplsLabel> ingressLabel = Optional.ofNullable(MplsLabel.mplsLabel(10));
+        Optional<MplsLabel> egressLabel = Optional.ofNullable(MplsLabel.mplsLabel(20));
+
+        MplsIntent intent = makeIntent("d1", ingressLabel, "d8", egressLabel);
+        assertThat(intent, is(notNullValue()));
+
+        String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"};
+        MplsIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent forwardResultIntent = result.get(0);
+        assertThat(forwardResultIntent instanceof MplsPathIntent, is(true));
+
+        if (forwardResultIntent instanceof MplsIntent) {
+            MplsPathIntent forwardPathIntent = (MplsPathIntent) forwardResultIntent;
+            // 7 links for the hops, plus one default lnk on ingress and egress
+            assertThat(forwardPathIntent.path().links(), hasSize(hops.length + 1));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d1", "d2"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d2", "d3"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d3", "d4"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d4", "d5"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d5", "d6"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d6", "d7"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d7", "d8"));
+            assertEquals(forwardPathIntent.egressLabel(), egressLabel);
+            assertEquals(forwardPathIntent.ingressLabel(), ingressLabel);
+        }
+    }
+
+    /**
+     * Tests a pair of devices in an 8 hop path, forward direction.
+     */
+    @Test
+    public void testReversePathCompilation() {
+        Optional<MplsLabel> ingressLabel = Optional.ofNullable(MplsLabel.mplsLabel(10));
+        Optional<MplsLabel> egressLabel = Optional.ofNullable(MplsLabel.mplsLabel(20));
+
+        MplsIntent intent = makeIntent("d8", ingressLabel, "d1", egressLabel);
+        assertThat(intent, is(notNullValue()));
+
+        String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"};
+        MplsIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent reverseResultIntent = result.get(0);
+        assertThat(reverseResultIntent instanceof MplsPathIntent, is(true));
+
+        if (reverseResultIntent instanceof MplsIntent) {
+            MplsPathIntent reversePathIntent = (MplsPathIntent) reverseResultIntent;
+            assertThat(reversePathIntent.path().links(), hasSize(hops.length + 1));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d2", "d1"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d3", "d2"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d4", "d3"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d5", "d4"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d6", "d5"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d7", "d6"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d8", "d7"));
+            assertEquals(reversePathIntent.egressLabel(), egressLabel);
+            assertEquals(reversePathIntent.ingressLabel(), ingressLabel);
+        }
+    }
+
+    /**
+     * Tests compilation of the intent which designates two different ports on the same switch.
+     */
+    @Test
+    public void testSameSwitchDifferentPortsIntentCompilation() {
+        ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
+        ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2));
+        MplsIntent intent = new MplsIntent(APP_ID, selector, treatment, src, Optional.empty(), dst, Optional.empty());
+
+        String[] hops = {"1"};
+        MplsIntentCompiler sut = makeCompiler(hops);
+
+        List<Intent> compiled = sut.compile(intent, null, null);
+
+        assertThat(compiled, hasSize(1));
+        assertThat(compiled.get(0), is(instanceOf(MplsPathIntent.class)));
+        Path path = ((MplsPathIntent) compiled.get(0)).path();
+
+        assertThat(path.links(), hasSize(2));
+        Link firstLink = path.links().get(0);
+        assertThat(firstLink, is(createEdgeLink(src, true)));
+        Link secondLink = path.links().get(1);
+        assertThat(secondLink, is(createEdgeLink(dst, false)));
+    }
+}
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
new file mode 100644
index 0000000..bbc7ad1
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2014 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 org.hamcrest.Matchers;
+import org.junit.Test;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.TestApplicationId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.AbstractIntentTest;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.intent.MultiPointToSinglePointIntent;
+import org.onosproject.net.topology.LinkWeight;
+import org.onosproject.net.topology.PathService;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.NetTestTools.createPath;
+import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
+
+/**
+ * Unit tests for the MultiPointToSinglePoint intent compiler.
+ */
+public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTest {
+
+    private static final ApplicationId APPID = new TestApplicationId("foo");
+
+    private TrafficSelector selector = new IntentTestsMocks.MockSelector();
+    private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
+
+    /**
+     * Mock path service for creating paths within the test.
+     */
+    private static class MockPathService implements PathService {
+
+        final String[] pathHops;
+
+        /**
+         * Constructor that provides a set of hops to mock.
+         *
+         * @param pathHops path hops to mock
+         */
+        MockPathService(String[] pathHops) {
+            this.pathHops = pathHops;
+        }
+
+        @Override
+        public Set<Path> getPaths(ElementId src, ElementId dst) {
+            Set<Path> result = new HashSet<>();
+
+            String[] allHops = new String[pathHops.length + 1];
+            allHops[0] = src.toString();
+            System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
+
+            result.add(createPath(allHops));
+            return result;
+        }
+
+        @Override
+        public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
+            return null;
+        }
+    }
+
+    /**
+     * Creates a MultiPointToSinglePoint intent for a group of ingress points
+     * and an egress point.
+     *
+     * @param ingressIds array of ingress device ids
+     * @param egressId   device id of the egress point
+     * @return MultiPointToSinglePoint intent
+     */
+    private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) {
+        Set<ConnectPoint> ingressPoints = new HashSet<>();
+        ConnectPoint egressPoint = connectPoint(egressId, 1);
+
+        for (String ingressId : ingressIds) {
+            ingressPoints.add(connectPoint(ingressId, 1));
+        }
+
+        return new MultiPointToSinglePointIntent(APPID, selector, treatment,
+                                                 ingressPoints, egressPoint);
+    }
+
+    /**
+     * Creates a compiler for MultiPointToSinglePoint intents.
+     *
+     * @param hops hops to use while computing paths for this intent
+     * @return MultiPointToSinglePoint intent
+     */
+    private MultiPointToSinglePointIntentCompiler makeCompiler(String[] hops) {
+        MultiPointToSinglePointIntentCompiler compiler =
+                new MultiPointToSinglePointIntentCompiler();
+        compiler.pathService = new MockPathService(hops);
+        return compiler;
+    }
+
+    /**
+     * Tests a single ingress point with 8 hops to its egress point.
+     */
+    @Test
+    public void testSingleLongPathCompilation() {
+
+        String[] ingress = {"ingress"};
+        String egress = "egress";
+
+        MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
+        assertThat(intent, is(notNullValue()));
+
+        String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8",
+                egress};
+        MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent resultIntent = result.get(0);
+        assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
+
+        if (resultIntent instanceof LinkCollectionIntent) {
+            LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
+            assertThat(linkIntent.links(), hasSize(9));
+            assertThat(linkIntent.links(), linksHasPath("ingress", "h1"));
+            assertThat(linkIntent.links(), linksHasPath("h1", "h2"));
+            assertThat(linkIntent.links(), linksHasPath("h2", "h3"));
+            assertThat(linkIntent.links(), linksHasPath("h4", "h5"));
+            assertThat(linkIntent.links(), linksHasPath("h5", "h6"));
+            assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
+            assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
+        }
+    }
+
+    /**
+     * Tests a simple topology where two ingress points share some path segments
+     * and some path segments are not shared.
+     */
+    @Test
+    public void testTwoIngressCompilation() {
+        String[] ingress = {"ingress1", "ingress2"};
+        String egress = "egress";
+
+        MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
+        assertThat(intent, is(notNullValue()));
+
+        final String[] hops = {"inner1", "inner2", egress};
+        MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent resultIntent = result.get(0);
+        assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
+
+        if (resultIntent instanceof LinkCollectionIntent) {
+            LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
+            assertThat(linkIntent.links(), hasSize(4));
+            assertThat(linkIntent.links(), linksHasPath("ingress1", "inner1"));
+            assertThat(linkIntent.links(), linksHasPath("ingress2", "inner1"));
+            assertThat(linkIntent.links(), linksHasPath("inner1", "inner2"));
+            assertThat(linkIntent.links(), linksHasPath("inner2", "egress"));
+        }
+    }
+
+    /**
+     * Tests a large number of ingress points that share a common path to the
+     * egress point.
+     */
+    @Test
+    public void testMultiIngressCompilation() {
+        String[] ingress = {"i1", "i2", "i3", "i4", "i5",
+                "i6", "i7", "i8", "i9", "i10"};
+        String egress = "e";
+
+        MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
+        assertThat(intent, is(notNullValue()));
+
+        final String[] hops = {"n1", egress};
+        MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
+        assertThat(compiler, is(notNullValue()));
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent resultIntent = result.get(0);
+        assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
+
+        if (resultIntent instanceof LinkCollectionIntent) {
+            LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
+            assertThat(linkIntent.links(), hasSize(ingress.length + 1));
+            for (String ingressToCheck : ingress) {
+                assertThat(linkIntent.links(),
+                           linksHasPath(ingressToCheck,
+                                        "n1"));
+            }
+            assertThat(linkIntent.links(), linksHasPath("n1", egress));
+        }
+    }
+}
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
new file mode 100644
index 0000000..b651beb
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -0,0 +1,301 @@
+/*
+ * Copyright 2014 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 org.hamcrest.Matchers;
+import org.junit.Test;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.AbstractIntentTest;
+import org.onosproject.net.intent.Constraint;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.PathIntent;
+import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.intent.constraint.BandwidthConstraint;
+import org.onosproject.net.intent.constraint.LambdaConstraint;
+import org.onosproject.net.intent.impl.PathNotFoundException;
+import org.onosproject.net.resource.Bandwidth;
+import org.onosproject.net.resource.Lambda;
+import org.onosproject.net.resource.LinkResourceService;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.fail;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
+
+/**
+ * Unit tests for the HostToHost intent compiler.
+ */
+public class PointToPointIntentCompilerTest extends AbstractIntentTest {
+
+    private static final ApplicationId APPID = new TestApplicationId("foo");
+
+    private TrafficSelector selector = new IntentTestsMocks.MockSelector();
+    private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
+
+    /**
+     * Creates a PointToPoint intent based on ingress and egress device Ids.
+     *
+     * @param ingressIdString string for id of ingress device
+     * @param egressIdString  string for id of egress device
+     * @return PointToPointIntent for the two devices
+     */
+    private PointToPointIntent makeIntent(String ingressIdString,
+                                          String egressIdString) {
+        return new PointToPointIntent(APPID, selector, treatment,
+                                      connectPoint(ingressIdString, 1),
+                                      connectPoint(egressIdString, 1));
+    }
+
+    /**
+     * Creates a PointToPoint intent based on ingress and egress deviceIds and constraints.
+     *
+     * @param ingressIdString string for id of ingress device
+     * @param egressIdString  string for id of egress device
+     * @param constraints     constraints
+     * @return PointToPointIntent for the two device with constraints
+     */
+    private PointToPointIntent makeIntent(String ingressIdString,
+                                          String egressIdString, List<Constraint> constraints) {
+        return new PointToPointIntent(APPID, selector, treatment,
+                connectPoint(ingressIdString, 1),
+                connectPoint(egressIdString, 1),
+                constraints);
+    }
+
+    /**
+     * Creates a compiler for HostToHost intents.
+     *
+     * @param hops string array describing the path hops to use when compiling
+     * @return HostToHost intent compiler
+     */
+    private PointToPointIntentCompiler makeCompiler(String[] hops) {
+        PointToPointIntentCompiler compiler = new PointToPointIntentCompiler();
+        compiler.pathService = new IntentTestsMocks.MockPathService(hops);
+        return compiler;
+    }
+
+    /**
+     * Creates a point to point intent compiler for a three switch linear
+     * topology.
+     *
+     * @param resourceService service to use for resource allocation requests
+     * @return point to point compiler
+     */
+    private PointToPointIntentCompiler makeCompiler(String[] hops, LinkResourceService resourceService) {
+        final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler();
+        compiler.resourceService = resourceService;
+        compiler.pathService = new IntentTestsMocks.MockPathService(hops);
+        return compiler;
+    }
+
+    /**
+     * Tests a pair of devices in an 8 hop path, forward direction.
+     */
+    @Test
+    public void testForwardPathCompilation() {
+
+        PointToPointIntent intent = makeIntent("d1", "d8");
+
+        String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"};
+        PointToPointIntentCompiler compiler = makeCompiler(hops);
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent forwardResultIntent = result.get(0);
+        assertThat(forwardResultIntent instanceof PathIntent, is(true));
+
+        if (forwardResultIntent instanceof PathIntent) {
+            PathIntent forwardPathIntent = (PathIntent) forwardResultIntent;
+            // 7 links for the hops, plus one default lnk on ingress and egress
+            assertThat(forwardPathIntent.path().links(), hasSize(hops.length + 1));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d1", "d2"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d2", "d3"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d3", "d4"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d4", "d5"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d5", "d6"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d6", "d7"));
+            assertThat(forwardPathIntent.path().links(), linksHasPath("d7", "d8"));
+        }
+    }
+
+    /**
+     * Tests a pair of devices in an 8 hop path, forward direction.
+     */
+    @Test
+    public void testReversePathCompilation() {
+
+        PointToPointIntent intent = makeIntent("d8", "d1");
+
+        String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"};
+        PointToPointIntentCompiler compiler = makeCompiler(hops);
+
+        List<Intent> result = compiler.compile(intent, null, null);
+        assertThat(result, is(Matchers.notNullValue()));
+        assertThat(result, hasSize(1));
+        Intent reverseResultIntent = result.get(0);
+        assertThat(reverseResultIntent instanceof PathIntent, is(true));
+
+        if (reverseResultIntent instanceof PathIntent) {
+            PathIntent reversePathIntent = (PathIntent) reverseResultIntent;
+            assertThat(reversePathIntent.path().links(), hasSize(hops.length + 1));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d2", "d1"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d3", "d2"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d4", "d3"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d5", "d4"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d6", "d5"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d7", "d6"));
+            assertThat(reversePathIntent.path().links(), linksHasPath("d8", "d7"));
+        }
+    }
+
+    /**
+     * Tests compilation of the intent which designates two different ports on the same switch.
+     */
+    @Test
+    public void testSameSwitchDifferentPortsIntentCompilation() {
+        ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
+        ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2));
+        PointToPointIntent intent = new PointToPointIntent(APP_ID, selector, treatment, src, dst);
+
+        String[] hops = {"1"};
+        PointToPointIntentCompiler sut = makeCompiler(hops);
+
+        List<Intent> compiled = sut.compile(intent, null, null);
+
+        assertThat(compiled, hasSize(1));
+        assertThat(compiled.get(0), is(instanceOf(PathIntent.class)));
+        Path path = ((PathIntent) compiled.get(0)).path();
+
+        assertThat(path.links(), hasSize(2));
+        Link firstLink = path.links().get(0);
+        assertThat(firstLink, is(createEdgeLink(src, true)));
+        Link secondLink = path.links().get(1);
+        assertThat(secondLink, is(createEdgeLink(dst, false)));
+    }
+
+    /**
+     * Tests that requests with sufficient available bandwidth succeed.
+     */
+    @Test
+    public void testBandwidthConstrainedIntentSuccess() {
+
+        final LinkResourceService resourceService =
+                IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
+        final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(Bandwidth.bps(100.0)));
+
+        final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
+
+        String[] hops = {"s1", "s2", "s3"};
+        final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
+
+        final List<Intent> compiledIntents = compiler.compile(intent, null, null);
+
+        assertThat(compiledIntents, Matchers.notNullValue());
+        assertThat(compiledIntents, hasSize(1));
+    }
+
+    /**
+     * Tests that requests with insufficient available bandwidth fail.
+     */
+    @Test
+    public void testBandwidthConstrainedIntentFailure() {
+
+        final LinkResourceService resourceService =
+                IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
+        final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(Bandwidth.bps(100.0)));
+
+        try {
+            final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
+
+            String[] hops = {"s1", "s2", "s3"};
+            final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
+
+            compiler.compile(intent, null, null);
+
+            fail("Point to Point compilation with insufficient bandwidth does "
+                    + "not throw exception.");
+        } catch (PathNotFoundException noPath) {
+            assertThat(noPath.getMessage(), containsString("No path"));
+        }
+    }
+
+    /**
+     * Tests that requests for available lambdas are successful.
+     */
+    @Test
+    public void testLambdaConstrainedIntentSuccess() {
+
+        final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(Lambda.valueOf(1)));
+        final LinkResourceService resourceService =
+                IntentTestsMocks.MockResourceService.makeLambdaResourceService(1);
+
+        final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
+
+        String[] hops = {"s1", "s2", "s3"};
+        final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
+
+        final List<Intent> compiledIntents =
+                compiler.compile(intent, null, null);
+
+        assertThat(compiledIntents, Matchers.notNullValue());
+        assertThat(compiledIntents, hasSize(1));
+    }
+
+    /**
+     * Tests that requests for lambdas when there are no available lambdas
+     * fail.
+     */
+    @Test
+    public void testLambdaConstrainedIntentFailure() {
+
+        final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(Lambda.valueOf(1)));
+        final LinkResourceService resourceService =
+                IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
+        try {
+            final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
+
+            String[] hops = {"s1", "s2", "s3"};
+            final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
+
+            compiler.compile(intent, null, null);
+
+            fail("Point to Point compilation with no available lambda does "
+                    + "not throw exception.");
+        } catch (PathNotFoundException noPath) {
+            assertThat(noPath.getMessage(), containsString("No path"));
+        }
+    }
+
+}