@Override
    public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {

        SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
        SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
        Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();

        Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);

        computePorts(intent, inputPorts, outputPorts);

        if (encapConstraint.isPresent()) {
            labels = labelAllocator.assignLabelToPorts(intent.links(),
                                                       intent.key(),
                                                       encapConstraint.get().encapType(),
                                                       encapConstraint.get().suggestedIdentifier());
        }

        ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
        if (this.isDomainProcessingEnabled(intent)) {
            intentList.addAll(this.getDomainIntents(intent, domainService));
        }

        List<Objective> objectives = new ArrayList<>();
        List<DeviceId> devices = new ArrayList<>();
        for (DeviceId deviceId : outputPorts.keySet()) {
            // add only objectives that are not inside of a domain
            if (LOCAL.equals(domainService.getDomain(deviceId))) {
                List<Objective> deviceObjectives =
                        createRules(intent,
                                    deviceId,
                                    inputPorts.get(deviceId),
                                    outputPorts.get(deviceId),
                                    labels);
                deviceObjectives.forEach(objective -> {
                    objectives.add(objective);
                    devices.add(deviceId);
                });
            }
        }
        // if any objectives have been created
        if (!objectives.isEmpty()) {
            intentList.add(new FlowObjectiveIntent(appId, intent.key(), devices,
                                                   objectives,
                                                   intent.resources(),
                                                   intent.resourceGroup()));
        }
        return intentList.build();
    }
@Test
    public void testCompile() {
        LinkCollectionIntent intent = LinkCollectionIntent.builder()
                .appId(appId)
                .selector(selector)
                .treatment(treatment)
                .links(links)
                .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p1)))
                .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p1)))
                .build();

        List<Intent> result = compiler.compile(intent, Collections.emptyList());
        assertThat(result, hasSize(1));
        assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));

        FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
        List<Objective> objectives = foIntent.objectives();
        assertThat(objectives, hasSize(6));

        /*
         * First set of objective
         */
        forwardingObjective = (ForwardingObjective) objectives.get(0);
        nextObjective = (NextObjective) objectives.get(1);

        // expect selector and treatment
        TrafficSelector expectSelector = DefaultTrafficSelector.builder()
                .matchInPort(PortNumber.portNumber(1))
                .build();
        TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder()
                .setOutput(PortNumber.portNumber(1))
                .build();

        // test case for first next objective
        checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);

        // test case for first forwarding objective
        checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);

        /*
         * Second set of objective
         */
        forwardingObjective = (ForwardingObjective) objectives.get(2);
        nextObjective = (NextObjective) objectives.get(3);


        expectSelector = DefaultTrafficSelector.builder()
                .matchInPort(PortNumber.portNumber(0))
                .build();

        // test case for second next objective
        checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);

        // test case for second forwarding objective
        checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);

        /*
         * 3rd set of objective
         */
        forwardingObjective = (ForwardingObjective) objectives.get(4);
        nextObjective = (NextObjective) objectives.get(5);
        expectSelector = DefaultTrafficSelector.builder()
                .matchInPort(PortNumber.portNumber(1))
                .build();

        // test case for 3rd next objective
        checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);

        // test case for 3rd forwarding objective
        checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    }