Search in sources :

Example 21 with VlanId

use of org.onlab.packet.VlanId in project onos by opennetworkinglab.

the class TestProtectionEndpointIntentCommand method output.

private FilteredConnectPoint output(DeviceId did, String portNumberStr, String vlanStr) {
    ConnectPoint cp = new ConnectPoint(did, PortNumber.fromString(portNumberStr));
    if (deviceService.getPort(cp) == null) {
        print("Unknown port: %s", cp);
    }
    if (vlanStr == null) {
        return new FilteredConnectPoint(cp);
    } else {
        VlanId vlan = VlanId.vlanId(vlanStr);
        TrafficSelector sel = DefaultTrafficSelector.builder().matchVlanId(vlan).build();
        return new FilteredConnectPoint(cp, sel);
    }
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) VlanId(org.onlab.packet.VlanId) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 22 with VlanId

use of org.onlab.packet.VlanId in project onos by opennetworkinglab.

the class PortQueryVlansCommand method printVlans.

private void printVlans(Port port) {
    DeviceService deviceService = get(DeviceService.class);
    DriverService driverService = get(DriverService.class);
    DeviceId deviceId = (DeviceId) port.element().id();
    Device device = deviceService.getDevice(deviceId);
    if (!device.is(VlanQuery.class)) {
        // The relevant behavior is not supported by the device.
        print(NO_SUPPORT);
        return;
    }
    DriverHandler h = driverService.createHandler(deviceId);
    VlanQuery vlanQuery = h.behaviour(VlanQuery.class);
    try {
        Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number());
        if (vlanIds.isEmpty()) {
            print(VLAN_NOT_AVAILABLE);
        } else {
            print(AVAIL_VLANS, getRanges(vlanIds).toString());
        }
    } catch (Exception e) {
        print(FAILURE + e.getMessage());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) DriverHandler(org.onosproject.net.driver.DriverHandler) VlanQuery(org.onosproject.net.behaviour.VlanQuery) VlanId(org.onlab.packet.VlanId) DriverService(org.onosproject.net.driver.DriverService)

Example 23 with VlanId

use of org.onlab.packet.VlanId in project onos by opennetworkinglab.

the class LabelAllocatorTest method testPortKey.

/**
 * To test the port key based API.
 */
@Test
public void testPortKey() {
    // Verify the first fit behavior
    this.allocator.setLabelSelection(firstFit);
    assertThat(this.allocator.getLabelSelection(), instanceOf(FirstFitSelection.class));
    // We test the behavior for VLAN
    Map<ConnectPoint, Identifier<?>> allocation = this.allocator.assignLabelToPorts(ImmutableSet.copyOf(links.subList(1, 2)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    Identifier<?> id = allocation.get(new ConnectPoint(d1p1.elementId(), d1p1.port()));
    // value has to be a VlanId
    assertThat(id, instanceOf(VlanId.class));
    // value should not be a forbidden value
    VlanId prevVlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < prevVlanId.toShort() && prevVlanId.toShort() < VlanId.MAX_VLAN);
    // value has to be 1
    assertEquals(1, prevVlanId.toShort());
    // verify same applies for d2p1
    id = allocation.get(new ConnectPoint(d3p1.elementId(), d3p1.port()));
    assertThat(id, instanceOf(VlanId.class));
    // value should not be a forbidden value
    VlanId vlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < vlanId.toShort() && vlanId.toShort() < VlanId.MAX_VLAN);
    // value has to be 1
    assertEquals(prevVlanId, vlanId);
}
Also used : Identifier(org.onlab.util.Identifier) FirstFitSelection(org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 24 with VlanId

use of org.onlab.packet.VlanId in project onos by opennetworkinglab.

the class LinkCollectionOptimizationTest method testOptimizationVlanEncapDifferentSelectors.

/**
 * We test the proper compilation of sp2mp with the VLAN
 * encapsulation and filtered selectors of different type.
 */
@Test
public void testOptimizationVlanEncapDifferentSelectors() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForVlan).links(linksForSp2Mp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d1p11, vlan200Selector), new FilteredConnectPoint(d1p12), new FilteredConnectPoint(d2p10, mpls200Selector))).build();
    sut.activate();
    /*
         * We use the FIRST_FIT to simplify tests.
         */
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder(vlan69Selector).matchInPort(d3p10.port()).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d3p0.port()).build()));
    Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS2, hasSize(1));
    FlowRule ruleS2 = rulesS2.iterator().next();
    assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p1.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).popVlan().pushMpls().copyTtlOut().setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d2p10.port()).build()));
    Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS1, hasSize(1));
    FlowRule ruleS1 = rulesS1.iterator().next();
    assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p11.port()).popVlan().setOutput(d1p12.port()).pushMpls().copyTtlOut().setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p10.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRule(org.onosproject.net.flow.FlowRule) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 25 with VlanId

use of org.onlab.packet.VlanId in project onos by opennetworkinglab.

the class LinkCollectionOptimizationTest method testVlanOrder.

/**
 * We test the proper optimization of sp2mp with VLAN
 * ingress point and different egress points: 1) it is
 * a simple ingress point; 2) it is a vlan ingress point;
 * 3) It is a simple ingress point. 1) and 2) share the same
 * egress switch. The outcomes of the test are the re-ordering
 * of the actions and the proper optimization of the chain.
 */
@Test
public void testVlanOrder() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(linksForSp2Mp).applyTreatmentOnEgress(true).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10), new FilteredConnectPoint(d1p11, vlan200Selector), new FilteredConnectPoint(d2p10))).build();
    sut.activate();
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d3p10.port()).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d3p0.port()).build()));
    Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS2, hasSize(1));
    FlowRule ruleS2 = rulesS2.iterator().next();
    assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d2p1.port()).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d2p0.port()).popVlan().setOutput(d2p10.port()).build()));
    Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS1, hasSize(1));
    FlowRule ruleS1 = rulesS1.iterator().next();
    assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p0.port()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p11.port()).popVlan().setOutput(d1p10.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRule(org.onosproject.net.flow.FlowRule) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Aggregations

VlanId (org.onlab.packet.VlanId)201 DeviceId (org.onosproject.net.DeviceId)85 MacAddress (org.onlab.packet.MacAddress)81 List (java.util.List)76 ConnectPoint (org.onosproject.net.ConnectPoint)76 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)68 Collectors (java.util.stream.Collectors)65 Test (org.junit.Test)59 Ethernet (org.onlab.packet.Ethernet)58 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 Set (java.util.Set)55 Collection (java.util.Collection)54 Collections (java.util.Collections)53 TrafficSelector (org.onosproject.net.flow.TrafficSelector)53 CoreService (org.onosproject.core.CoreService)51 IpAddress (org.onlab.packet.IpAddress)50 ImmutableSet (com.google.common.collect.ImmutableSet)44 FlowRule (org.onosproject.net.flow.FlowRule)43 MplsLabel (org.onlab.packet.MplsLabel)42