summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler')
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java167
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java163
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java107
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java203
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java145
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java270
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java135
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java172
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java319
9 files changed, 0 insertions, 1681 deletions
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
deleted file mode 100644
index 5588904d..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2014-2015 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 HostToHostIntent.builder()
- .appId(APPID)
- .one(hid(oneIdString))
- .two(hid(twoIdString))
- .selector(selector)
- .treatment(treatment)
- .build();
- }
-
- /**
- * 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/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
deleted file mode 100644
index c5fa3719..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright 2015 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.ImmutableSet;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-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.MockIdGenerator;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-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.Matchers.is;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-
-public class LinkCollectionIntentCompilerTest {
-
- private final ApplicationId appId = new TestApplicationId("test");
-
- private final ConnectPoint d1p1 = connectPoint("s1", 0);
- private final ConnectPoint d2p0 = connectPoint("s2", 0);
- private final ConnectPoint d2p1 = connectPoint("s2", 1);
- private final ConnectPoint d3p1 = connectPoint("s3", 1);
- private final ConnectPoint d3p0 = connectPoint("s3", 10);
- private final ConnectPoint d1p0 = connectPoint("s1", 10);
-
- private final Set<Link> links = ImmutableSet.of(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- new DefaultLink(PID, d1p1, d3p1, DIRECT));
-
- private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- private CoreService coreService;
- private IntentExtensionService intentExtensionService;
- private IdGenerator idGenerator = new MockIdGenerator();
-
- private LinkCollectionIntent intent;
-
- private LinkCollectionIntentCompiler sut;
-
- @Before
- public void setUp() {
- sut = new LinkCollectionIntentCompiler();
- coreService = createMock(CoreService.class);
- expect(coreService.registerApplication("org.onosproject.net.intent"))
- .andReturn(appId);
- sut.coreService = coreService;
-
- Intent.bindIdGenerator(idGenerator);
-
- intent = LinkCollectionIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .links(links)
- .ingressPoints(ImmutableSet.of(d1p1))
- .egressPoints(ImmutableSet.of(d3p1))
- .build();
- intentExtensionService = createMock(IntentExtensionService.class);
- intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
- intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
- sut.intentManager = intentExtensionService;
-
- replay(coreService, intentExtensionService);
- }
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- @Test
- public void testCompile() {
- sut.activate();
-
- List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
- assertThat(compiled, hasSize(1));
-
- Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
- assertThat(rules, hasSize(links.size()));
-
- // if not found, get() raises an exception
- FlowRule rule1 = rules.stream()
- .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule1.selector(), is(
- DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build()
- ));
- assertThat(rule1.treatment(), is(
- DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build()
- ));
- assertThat(rule1.priority(), is(intent.priority()));
-
- FlowRule rule2 = rules.stream()
- .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule2.selector(), is(
- DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build()
- ));
- assertThat(rule2.treatment(), is(
- DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()
- ));
- assertThat(rule2.priority(), is(intent.priority()));
-
- FlowRule rule3 = rules.stream()
- .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule3.selector(), is(
- DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build()
- ));
- assertThat(rule3.treatment(), is(
- DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()
- ));
- assertThat(rule3.priority(), is(intent.priority()));
-
- sut.deactivate();
- }
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
deleted file mode 100644
index f5d3d0f3..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2015 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 org.onlab.packet.MplsLabel;
-import org.onosproject.net.newresource.ResourceAllocation;
-import org.onosproject.net.newresource.ResourceConsumer;
-import org.onosproject.net.newresource.ResourceListener;
-import org.onosproject.net.newresource.ResourcePath;
-import org.onosproject.net.newresource.ResourceService;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-class MockResourceService implements ResourceService {
-
- private final Map<ResourcePath, ResourceConsumer> assignment = new HashMap<>();
-
- @Override
- public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources) {
- assignment.putAll(
- resources.stream().collect(Collectors.toMap(x -> x, x -> consumer))
- );
-
- return resources.stream()
- .map(x -> new ResourceAllocation(x, consumer))
- .collect(Collectors.toList());
- }
-
- @Override
- public boolean release(List<ResourceAllocation> allocations) {
- allocations.forEach(x -> assignment.remove(x.resource()));
-
- return true;
- }
-
- @Override
- public boolean release(ResourceConsumer consumer) {
- List<ResourcePath> resources = assignment.entrySet().stream()
- .filter(x -> x.getValue().equals(consumer))
- .map(Map.Entry::getKey)
- .collect(Collectors.toList());
- List<ResourceAllocation> allocations = resources.stream()
- .map(x -> new ResourceAllocation(x, consumer))
- .collect(Collectors.toList());
-
- return release(allocations);
- }
-
- @Override
- public Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
- return Optional.ofNullable(assignment.get(resource))
- .map(x -> new ResourceAllocation(resource, x));
- }
-
- @Override
- public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
- return assignment.entrySet().stream()
- .filter(x -> x.getKey().parent().isPresent())
- .filter(x -> x.getKey().parent().get().equals(parent))
- .map(x -> new ResourceAllocation(x.getKey(), x.getValue()))
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
- return assignment.entrySet().stream()
- .filter(x -> x.getValue().equals(consumer))
- .map(x -> new ResourceAllocation(x.getKey(), x.getValue()))
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection<ResourcePath> getAvailableResources(ResourcePath parent) {
- ResourcePath resource = parent.child(MplsLabel.mplsLabel(10));
- return ImmutableList.of(resource);
- }
-
- @Override
- public boolean isAvailable(ResourcePath resource) {
- return true;
- }
-
- @Override
- public void addListener(ResourceListener listener) {}
-
- @Override
- public void removeListener(ResourceListener listener) {}
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
deleted file mode 100644
index 03a38a5a..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright 2015 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 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 MplsIntent.builder()
- .appId(APPID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(connectPoint(ingressIdString, 1))
- .ingressLabel(ingressLabel)
- .egressPoint(connectPoint(egressIdString, 1))
- .egressLabel(egressLabel).build();
- }
- /**
- * 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.of(MplsLabel.mplsLabel(10));
- Optional<MplsLabel> egressLabel = Optional.of(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 statement suppresses static analysis warnings about unchecked cast
- if (forwardResultIntent instanceof MplsPathIntent) {
- 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.of(MplsLabel.mplsLabel(10));
- Optional<MplsLabel> egressLabel = Optional.of(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 statement suppresses static analysis warnings about unchecked cast
- if (reverseResultIntent instanceof MplsPathIntent) {
- 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 = MplsIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(src)
- .ingressLabel(Optional.empty())
- .egressPoint(dst)
- .egressLabel(Optional.empty())
- .build();
-
- 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/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
deleted file mode 100644
index 6cceee12..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright 2015 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 java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.MplsLabel;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.FlowRuleIntent;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.MplsPathIntent;
-
-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.Matchers.is;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-
-public class MplsPathIntentCompilerTest {
-
- private final ApplicationId appId = new TestApplicationId("test");
-
- private final ConnectPoint d1pi = connectPoint("s1", 100);
- private final ConnectPoint d1p1 = connectPoint("s1", 0);
- private final ConnectPoint d2p0 = connectPoint("s2", 0);
- private final ConnectPoint d2p1 = connectPoint("s2", 1);
- private final ConnectPoint d3p1 = connectPoint("s3", 1);
- private final ConnectPoint d3pe = connectPoint("s3", 100);
-
- private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- private final Optional<MplsLabel> ingressLabel =
- Optional.of(MplsLabel.mplsLabel(10));
- private final Optional<MplsLabel> egressLabel =
- Optional.of(MplsLabel.mplsLabel(20));
-
- private final List<Link> links = Arrays.asList(
- createEdgeLink(d1pi, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3pe, false)
- );
-
- private IdGenerator idGenerator = new MockIdGenerator();
-
- private final int hops = links.size() - 1;
- private MplsPathIntent intent;
- private MplsPathIntentCompiler sut;
-
- @Before
- public void setUp() {
- sut = new MplsPathIntentCompiler();
- CoreService coreService = createMock(CoreService.class);
- expect(coreService.registerApplication("org.onosproject.net.intent"))
- .andReturn(appId);
- sut.coreService = coreService;
- sut.resourceService = new MockResourceService();
-
- Intent.bindIdGenerator(idGenerator);
-
- intent = MplsPathIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .path(new DefaultPath(PID, links, hops))
- .ingressLabel(ingressLabel)
- .egressLabel(egressLabel)
- .priority(55)
- .build();
-
- IntentExtensionService intentExtensionService = createMock(IntentExtensionService.class);
- intentExtensionService.registerCompiler(MplsPathIntent.class, sut);
- intentExtensionService.unregisterCompiler(MplsPathIntent.class);
- sut.intentExtensionService = intentExtensionService;
-
- replay(coreService, intentExtensionService);
- }
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- @Test
- public void testCompile() {
- sut.activate();
-
- List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
- assertThat(compiled, hasSize(1));
-
- Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
- assertThat(rules, hasSize(3));
-
- FlowRule rule = rules.stream()
- .filter(x -> x.deviceId().equals(d2p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule.deviceId(), is(d2p0.deviceId()));
-
- sut.deactivate();
-
- }
-
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
deleted file mode 100644
index 03d664d3..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright 2014-2015 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.DeviceId;
-import org.onosproject.net.ElementId;
-import org.onosproject.net.Path;
-import org.onosproject.net.device.DeviceServiceAdapter;
-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.PathServiceAdapter;
-
-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;
-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 extends PathServiceAdapter {
-
- 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();
- if (pathHops.length != 0) {
- System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
- }
- result.add(createPath(allHops));
-
- return result;
- }
- }
-
- /**
- * Mocks the device service so that a device appears available in the test.
- */
- private static class MockDeviceService extends DeviceServiceAdapter {
- @Override
- public boolean isAvailable(DeviceId deviceId) {
- return true;
- }
- }
-
- /**
- * 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, 2);
-
- for (String ingressId : ingressIds) {
- ingressPoints.add(connectPoint(ingressId, 1));
- }
-
- return MultiPointToSinglePointIntent.builder()
- .appId(APPID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoints(ingressPoints)
- .egressPoint(egressPoint)
- .build();
- }
-
- /**
- * 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);
- compiler.deviceService = new MockDeviceService();
- 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));
- }
- }
-
- /**
- * Tests ingress and egress on the same device.
- */
- @Test
- public void testSameDeviceCompilation() {
- String[] ingress = {"i1", "i2"};
- String egress = "i1";
-
- MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
- assertThat(intent, is(notNullValue()));
-
- final String[] hops = {"i1", "i2"};
- 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.class));
-
- if (resultIntent instanceof LinkCollectionIntent) {
- LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
- assertThat(linkIntent.links(), hasSize(ingress.length));
-
- assertThat(linkIntent.links(), linksHasPath("i2", "i1"));
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
deleted file mode 100644
index 38a116dd..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 2015 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.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.OchSignalType;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.intent.FlowRuleIntent;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.OpticalPathIntent;
-
-import java.util.Arrays;
-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.hasSize;
-import static org.junit.Assert.assertEquals;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-import static org.onosproject.net.NetTestTools.createLambda;
-
-public class OpticalPathIntentCompilerTest {
-
- private CoreService coreService;
- private IntentExtensionService intentExtensionService;
- private final IdGenerator idGenerator = new MockIdGenerator();
- private OpticalPathIntentCompiler sut;
-
- private final ApplicationId appId = new TestApplicationId("test");
- private final ConnectPoint d1p1 = connectPoint("s1", 0);
- private final ConnectPoint d2p0 = connectPoint("s2", 0);
- private final ConnectPoint d2p1 = connectPoint("s2", 1);
- private final ConnectPoint d3p1 = connectPoint("s3", 1);
-
- private final List<Link> links = Arrays.asList(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT)
- );
- private final int hops = links.size() + 1;
- private OpticalPathIntent intent;
-
- @Before
- public void setUp() {
- sut = new OpticalPathIntentCompiler();
- coreService = createMock(CoreService.class);
- expect(coreService.registerApplication("org.onosproject.net.intent"))
- .andReturn(appId);
- sut.coreService = coreService;
-
- Intent.bindIdGenerator(idGenerator);
-
- intent = OpticalPathIntent.builder()
- .appId(appId)
- .src(d1p1)
- .dst(d3p1)
- .path(new DefaultPath(PID, links, hops))
- .lambda(createLambda())
- .signalType(OchSignalType.FIXED_GRID)
- .build();
- intentExtensionService = createMock(IntentExtensionService.class);
- intentExtensionService.registerCompiler(OpticalPathIntent.class, sut);
- intentExtensionService.unregisterCompiler(OpticalPathIntent.class);
- sut.intentManager = intentExtensionService;
-
- replay(coreService, intentExtensionService);
- }
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- @Test
- public void testCompiler() {
- sut.activate();
-
- List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
- assertThat(compiled, hasSize(1));
-
- Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
- rules.stream()
- .filter(x -> x.deviceId().equals(d1p1.deviceId()))
- .findFirst()
- .get();
-
- rules.stream()
- .filter(x -> x.deviceId().equals(d2p1.deviceId()))
- .findFirst()
- .get();
-
- rules.stream()
- .filter(x -> x.deviceId().equals(d3p1.deviceId()))
- .findFirst()
- .get();
-
- rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
- intent.priority(), rule.priority()));
-
- sut.deactivate();
- }
-
- //TODO test bidirectional optical paths and verify rules
-
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
deleted file mode 100644
index f07bf42c..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright 2015 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 java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.FlowRuleIntent;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.provider.ProviderId;
-
-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.Matchers.is;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-
-/**
- * Unit tests for PathIntentCompiler.
- */
-public class PathIntentCompilerTest {
-
- private CoreService coreService;
- private IntentExtensionService intentExtensionService;
- private IdGenerator idGenerator = new MockIdGenerator();
- private PathIntentCompiler sut;
-
- private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- private final ApplicationId appId = new TestApplicationId("test");
- private final ProviderId pid = new ProviderId("of", "test");
- private final ConnectPoint d1p1 = connectPoint("s1", 0);
- private final ConnectPoint d2p0 = connectPoint("s2", 0);
- private final ConnectPoint d2p1 = connectPoint("s2", 1);
- private final ConnectPoint d3p1 = connectPoint("s3", 1);
- private final ConnectPoint d3p0 = connectPoint("s3", 10);
- private final ConnectPoint d1p0 = connectPoint("s1", 10);
- private static final int PRIORITY = 555;
-
- private final List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- private final int hops = links.size() - 1;
- private PathIntent intent;
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void setUp() {
- sut = new PathIntentCompiler();
- coreService = createMock(CoreService.class);
- expect(coreService.registerApplication("org.onosproject.net.intent"))
- .andReturn(appId);
- sut.coreService = coreService;
-
- Intent.bindIdGenerator(idGenerator);
-
- intent = PathIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .priority(PRIORITY)
- .path(new DefaultPath(pid, links, hops))
- .build();
- intentExtensionService = createMock(IntentExtensionService.class);
- intentExtensionService.registerCompiler(PathIntent.class, sut);
- intentExtensionService.unregisterCompiler(PathIntent.class);
- sut.intentManager = intentExtensionService;
-
- replay(coreService, intentExtensionService);
- }
-
- /**
- * Tears down objects used in all the test cases.
- */
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- /**
- * Tests the compilation behavior of the path intent compiler.
- */
- @Test
- public void testCompile() {
- sut.activate();
-
- List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
- assertThat(compiled, hasSize(1));
-
- Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
-
- FlowRule rule1 = rules.stream()
- .filter(x -> x.deviceId().equals(d1p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule1.deviceId(), is(d1p0.deviceId()));
- assertThat(rule1.selector(),
- is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
- assertThat(rule1.treatment(),
- is(DefaultTrafficTreatment.builder().setOutput(d1p1.port()).build()));
- assertThat(rule1.priority(), is(intent.priority()));
-
- FlowRule rule2 = rules.stream()
- .filter(x -> x.deviceId().equals(d2p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule2.deviceId(), is(d2p0.deviceId()));
- assertThat(rule2.selector(),
- is(DefaultTrafficSelector.builder(selector).matchInPort(d2p0.port()).build()));
- assertThat(rule2.treatment(),
- is(DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()));
- assertThat(rule2.priority(), is(intent.priority()));
-
- FlowRule rule3 = rules.stream()
- .filter(x -> x.deviceId().equals(d3p0.deviceId()))
- .findFirst()
- .get();
- assertThat(rule3.deviceId(), is(d3p1.deviceId()));
- assertThat(rule3.selector(),
- is(DefaultTrafficSelector.builder(selector).matchInPort(d3p1.port()).build()));
- assertThat(rule3.treatment(),
- is(DefaultTrafficTreatment.builder(treatment).setOutput(d3p0.port()).build()));
- assertThat(rule3.priority(), is(intent.priority()));
-
- sut.deactivate();
- }
-}
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
deleted file mode 100644
index 5d7b5c8d..00000000
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright 2014-2015 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.onlab.util.Bandwidth;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.IndexedLambda;
-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.link.LinkResourceService;
-
-import java.util.Collections;
-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 PointToPointIntent.builder()
- .appId(APPID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(connectPoint(ingressIdString, 1))
- .egressPoint(connectPoint(egressIdString, 1))
- .build();
- }
-
- /**
- * 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 PointToPointIntent.builder()
- .appId(APPID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(connectPoint(ingressIdString, 1))
- .egressPoint(connectPoint(egressIdString, 1))
- .constraints(constraints)
- .build();
- }
-
- /**
- * 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 = PointToPointIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(src)
- .egressPoint(dst)
- .build();
-
- 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 =
- Collections.singletonList(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 =
- Collections.singletonList(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 =
- Collections.singletonList(new LambdaConstraint(new IndexedLambda(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 =
- Collections.singletonList(new LambdaConstraint(new IndexedLambda(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"));
- }
- }
-
-}