Search in sources :

Example 11 with Port

use of org.onosproject.net.Port in project trellis-control by opennetworkinglab.

the class RoutingRulePopulatorTest method testNoMoreEnabledPortCase4.

// Disable port 1 to 3
@Test
public void testNoMoreEnabledPortCase4() throws Exception {
    Port port1 = new DefaultPort(dev1, p1, false);
    Port port2 = new DefaultPort(dev1, p2, false);
    Port port3 = new DefaultPort(dev1, p3, false);
    Port port4 = new DefaultPort(dev1, p4, true);
    Port port5 = new DefaultPort(dev1, p5, true);
    List<Port> ports = Lists.newArrayList(port1, port2, port3, port4, port5);
    expect(deviceService.getPorts(anyObject(DeviceId.class))).andReturn(ports).anyTimes();
    replay(deviceService);
    assertTrue(rrp.noMoreEnabledPort(devId1, v10));
    assertTrue(rrp.noMoreEnabledPort(devId1, v20));
    assertFalse(rrp.noMoreEnabledPort(devId1, vInt));
}
Also used : DefaultPort(org.onosproject.net.DefaultPort) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 12 with Port

use of org.onosproject.net.Port in project TFG by mattinelorza.

the class InterpreterImpl method mapOutboundPacket.

/**
 * Returns a collection of PI packet operations populated with metadata
 * specific for this pipeconf and equivalent to the given ONOS
 * OutboundPacket instance.
 *
 * @param packet ONOS OutboundPacket
 * @return collection of PI packet operations
 * @throws PiInterpreterException if the packet treatments cannot be
 *                                executed by this pipeline
 */
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // Packet-out in main.p4 supports only setting the output port,
    // i.e. we only understand OUTPUT instructions.
    List<OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (OutputInstruction) i).collect(toList());
    if (treatment.allInstructions().size() != outInstructions.size()) {
        // There are other instructions that are not of type OUTPUT.
        throw new PiInterpreterException("Treatment not supported: " + treatment);
    }
    ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
    for (OutputInstruction outInst : outInstructions) {
        if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
            throw new PiInterpreterException(format("Packet-out on logical port '%s' not supported", outInst.port()));
        } else if (outInst.port().equals(FLOOD)) {
            // To emulate flooding, we create a packet-out operation for
            // each switch port.
            final DeviceService deviceService = handler().get(DeviceService.class);
            for (Port port : deviceService.getPorts(packet.sendThrough())) {
                builder.add(buildPacketOut(packet.data(), port.number().toLong()));
            }
        } else {
            // Create only one packet-out for the given OUTPUT instruction.
            builder.add(buildPacketOut(packet.data(), outInst.port().toLong()));
        }
    }
    return builder.build();
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) Map(java.util.Map) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiPacketMetadataId(org.onosproject.net.pi.model.PiPacketMetadataId) CPU_PORT_ID(org.onosproject.ngsdn.tutorial.AppConstants.CPU_PORT_ID) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 13 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class ServiceApplicationComponent method createOpticalIntent.

/**
 * Returns a new optical intent created from the method parameters.
 *
 * @param ingress ingress description (device/port)
 * @param egress egress description (device/port)
 * @param key intent key
 * @param appId application id. As per Intent class, it cannot be null
 *
 * @return created intent
 */
protected Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint egress, Key key, ApplicationId appId) {
    if (ingress == null || egress == null) {
        log.error("Invalid endpoint(s) for optical intent: ingress {}, egress {}", ingress, egress);
        return null;
    }
    DeviceService ds = opticalView(deviceService);
    Port srcPort = ds.getPort(ingress.deviceId(), ingress.port());
    Port dstPort = ds.getPort(egress.deviceId(), egress.port());
    if (srcPort == null || dstPort == null) {
        log.error("Invalid port(s) for optical intent: src {}, dst {}", srcPort, dstPort);
        return null;
    }
    OduSignalType signalType = ((OchPort) srcPort).signalType();
    return OpticalConnectivityIntent.builder().appId(appId).key(key).src(ingress).dst(egress).signalType(signalType).bidirectional(// TODO Revisit this.
    true).build();
}
Also used : OduSignalType(org.onosproject.net.OduSignalType) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) DeviceService(org.onosproject.net.device.DeviceService) OchPort(org.onosproject.net.optical.OchPort)

Example 14 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method processEthDstFilter.

/**
 * Allows routed packets with correct destination MAC to be directed
 * to unicast routing table, multicast routing table or MPLS forwarding table.
 *
 * @param portCriterion  port on device for which this filter is programmed
 * @param ethCriterion   dstMac of device for which is filter is programmed
 * @param vidCriterion   vlan assigned to port, or NONE for untagged
 * @param assignedVlan   assigned vlan-id for untagged packets
 * @param unicastMac     some switches require a unicast TMAC flow to be programmed before multicast
 *                       TMAC flow. This MAC address will be used for the unicast TMAC flow.
 *                       This is unused if the filtering objective is a unicast.
 * @param applicationId  for application programming this filter
 * @return stages of flow rules for port-vlan filters
 */
protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, EthCriterion ethCriterion, VlanIdCriterion vidCriterion, VlanId assignedVlan, MacAddress unicastMac, ApplicationId applicationId) {
    // Consider PortNumber.ANY as wildcard. Match ETH_DST only
    if (portCriterion != null && PortNumber.ANY.equals(portCriterion.port())) {
        return processEthDstOnlyFilter(ethCriterion, applicationId);
    }
    // Multicast MAC
    if (ethCriterion.mask() != null) {
        return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId);
    }
    // handling untagged packets via assigned VLAN
    if (vidCriterion != null && vidCriterion.vlanId() == VlanId.NONE) {
        vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan);
    }
    List<FlowRule> rules = new ArrayList<>();
    OfdpaMatchVlanVid ofdpaMatchVlanVid = null;
    if (vidCriterion != null && requireVlanExtensions()) {
        ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
    }
    // ofdpa cannot match on ALL portnumber, so we need to use separate
    // rules for each port.
    List<PortNumber> portnums = new ArrayList<>();
    if (portCriterion != null) {
        if (PortNumber.ALL.equals(portCriterion.port())) {
            for (Port port : deviceService.getPorts(deviceId)) {
                if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
                    portnums.add(port.number());
                }
            }
        } else {
            portnums.add(portCriterion.port());
        }
        for (PortNumber pnum : portnums) {
            rules.add(buildTmacRuleForIpv4(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
            rules.add(buildTmacRuleForMpls(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
            rules.add(buildTmacRuleForIpv6(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
        }
    } else {
        rules.add(buildTmacRuleForIpv4(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
        rules.add(buildTmacRuleForMpls(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
        rules.add(buildTmacRuleForIpv6(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
    }
    return ImmutableList.of(rules);
}
Also used : Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid)

Example 15 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method processEgress.

/**
 * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
 * egress tables.
 * @param fwd  the forwarding objective of type 'egress'
 * @return     a collection of flow rules to be sent to the switch. An empty
 *             collection may be returned if there is a problem in processing
 *             the flow rule
 */
@Override
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
    log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
    List<FlowRule> rules = new ArrayList<>();
    // Build selector
    TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
    if (vlanIdCriterion == null) {
        log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst();
    if (!outInstr.isPresent()) {
        log.error("Egress forwarding objective:{} must include output port", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port();
    sb.matchVlanId(vlanIdCriterion.vlanId());
    OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
    sb.extension(actsetOutput, deviceId);
    // Build a flow rule for Egress VLAN Flow table
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    tb.transition(UNICAST_ROUTING_TABLE_1);
    if (fwd.treatment() != null) {
        for (Instruction instr : fwd.treatment().allInstructions()) {
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
                tb.immediate().add(instr);
            }
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
                EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
                tb.immediate().pushVlan(ethType);
            }
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
    rules.add(ruleBuilder.build());
    return rules;
}
Also used : MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) NONE(org.onlab.packet.MacAddress.NONE) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ImmutableSet(com.google.common.collect.ImmutableSet) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) Optional(java.util.Optional) Queue(java.util.Queue) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) BROADCAST(org.onlab.packet.MacAddress.BROADCAST) Host(org.onosproject.net.Host) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) HostService(org.onosproject.net.host.HostService) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TimeUnit(java.util.concurrent.TimeUnit) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) PacketPriority(org.onosproject.net.packet.PacketPriority) Collections(java.util.Collections) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ArrayList(java.util.ArrayList) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28