Search in sources :

Example 1 with INDIRECT

use of org.onosproject.net.Link.Type.INDIRECT in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileSingleHopIndirectEgressVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-indirect-link scenario. No ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopIndirectEgressVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(singleHopIndirectIntentEgressVlan, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(1));
    FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p2.deviceId())).findFirst().get();
    verifyIdAndPriority(rule, d2p2.deviceId());
    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port()).build()));
    assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p3.port()).build()));
    Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
    assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
    sut.deactivate();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 2 with INDIRECT

use of org.onosproject.net.Link.Type.INDIRECT in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileSingleHopIndirectVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-indirect-link scenario. Ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopIndirectVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(singleHopIndirectIntentVlan, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(1));
    FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p2.deviceId())).findFirst().get();
    verifyIdAndPriority(rule, d2p2.deviceId());
    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port()).matchVlanId(ingressVlan).build()));
    assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p3.port()).build()));
    Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
    assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
    sut.deactivate();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 3 with INDIRECT

use of org.onosproject.net.Link.Type.INDIRECT in project onos by opennetworkinglab.

the class ECLinkStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
    final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
    final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
    final CountDownLatch addLatch = new CountDownLatch(1);
    LinkStoreDelegate checkAdd = event -> {
        assertEquals(LINK_ADDED, event.type());
        assertLink(linkId1, INDIRECT, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    LinkStoreDelegate checkUpdate = event -> {
        assertEquals(LINK_UPDATED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    LinkStoreDelegate checkRemove = event -> {
        assertEquals(LINK_REMOVED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        removeLatch.countDown();
    };
    linkStore.setDelegate(checkAdd);
    putLink(linkId1, INDIRECT);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkAdd);
    linkStore.setDelegate(checkUpdate);
    putLink(linkId1, DIRECT);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkUpdate);
    linkStore.setDelegate(checkRemove);
    linkStore.removeLink(d1P1, d2P2);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : LINK_ADDED(org.onosproject.net.link.LinkEvent.Type.LINK_ADDED) DeviceClockServiceAdapter(org.onosproject.net.device.DeviceClockServiceAdapter) PortNumber(org.onosproject.net.PortNumber) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ConnectPoint(org.onosproject.net.ConnectPoint) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) After(org.junit.After) Map(java.util.Map) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) LinkKey(org.onosproject.net.LinkKey) NodeId(org.onosproject.cluster.NodeId) LinkDescription(org.onosproject.net.link.LinkDescription) AfterClass(org.junit.AfterClass) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) Set(java.util.Set) CountDownLatch(java.util.concurrent.CountDownLatch) DeviceClockService(org.onosproject.net.device.DeviceClockService) SparseAnnotations(org.onosproject.net.SparseAnnotations) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) DeviceId(org.onosproject.net.DeviceId) DIRECT(org.onosproject.net.Link.Type.DIRECT) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) LinkEvent(org.onosproject.net.link.LinkEvent) HashMap(java.util.HashMap) ControllerNode(org.onosproject.cluster.ControllerNode) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Timestamp(org.onosproject.store.Timestamp) ACTIVE(org.onosproject.cluster.ControllerNode.State.ACTIVE) ExecutorService(java.util.concurrent.ExecutorService) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) StaticClusterService(org.onosproject.store.cluster.StaticClusterService) ClusterMessageHandler(org.onosproject.store.cluster.messaging.ClusterMessageHandler) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) EasyMock(org.easymock.EasyMock) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Ignore(org.junit.Ignore) EDGE(org.onosproject.net.Link.Type.EDGE) LinkStore(org.onosproject.net.link.LinkStore) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) Assert(org.junit.Assert) Type(org.onosproject.net.Link.Type) LinkKey(org.onosproject.net.LinkKey) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectPoint(org.onosproject.net.ConnectPoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Set (java.util.Set)3 EasyMock (org.easymock.EasyMock)3 Before (org.junit.Before)3 Test (org.junit.Test)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DeviceId (org.onosproject.net.DeviceId)3 Link (org.onosproject.net.Link)3 DIRECT (org.onosproject.net.Link.Type.DIRECT)3 INDIRECT (org.onosproject.net.Link.Type.INDIRECT)3 ProviderId (org.onosproject.net.provider.ProviderId)3 ImmutableList (com.google.common.collect.ImmutableList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers (org.hamcrest.Matchers)2 OrderingComparison.greaterThan (org.hamcrest.number.OrderingComparison.greaterThan)2 Assert.assertTrue (org.junit.Assert.assertTrue)2