Search in sources :

Example 51 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class DefaultCheckLoop method updatePktInportPerHop.

private PortCriterion updatePktInportPerHop(TsLoopPacket oldPkt, ConnectPoint dstPoint) {
    PortCriterion inPort = oldPkt.getInport();
    PortCriterion oldInPort = null != inPort ? (PortCriterion) matchInPort(inPort.port()) : null;
    // TODO - check - if it really copies this object
    oldPkt.setHeader(matchInPort(dstPoint.port()));
    return oldInPort;
}
Also used : PortCriterion(org.onosproject.net.flow.criteria.PortCriterion)

Example 52 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class StatsFlowRuleManager method getUnderlayFlowInfos.

@Override
public Set<FlowInfo> getUnderlayFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    for (Device device : getUnderlayDevices()) {
        if (!isEdgeSwitch(device.id())) {
            continue;
        }
        for (FlowEntry entry : flowRuleService.getFlowEntries(device.id())) {
            FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
            TrafficSelector selector = entry.selector();
            Criterion inPort = selector.getCriterion(Criterion.Type.IN_PORT);
            Criterion dstIpCriterion = selector.getCriterion(Criterion.Type.IPV4_DST);
            if (inPort != null && dstIpCriterion != null) {
                IpAddress srcIp = getIpAddress(device, (PortCriterion) inPort);
                IpAddress dstIp = ((IPCriterion) dstIpCriterion).ip().address();
                if (srcIp == null) {
                    continue;
                }
                fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(IpPrefix.valueOf(srcIp, ARBITRARY_LENGTH)).withDstIp(IpPrefix.valueOf(dstIp, ARBITRARY_LENGTH)).withSrcMac(getMacAddress(srcIp)).withDstMac(getMacAddress(dstIp)).withInputInterfaceId(getInterfaceId(srcIp)).withOutputInterfaceId(getInterfaceId(dstIp)).withDeviceId(entry.deviceId());
                StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
                sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
                fBuilder.withStatsInfo(sBuilder.build());
                FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
                flowInfos.add(flowInfo);
            }
        }
    }
    return flowInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 53 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class ChannelData method fromFlow.

/**
 * Returns a ChannelData representation from a flow rule. The rule must contain
 * a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
 * Instruction.Type.OUTPUT instruction.
 *
 * @param rule the flow rule representing the connection
 * @return ChannelData representation of the connection
 */
public static ChannelData fromFlow(FlowRule rule) {
    checkNotNull(rule);
    Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
    checkNotNull(in);
    PortNumber inPort = ((PortCriterion) in).port();
    Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
    OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();
    PortNumber outPort = null;
    List<Instruction> instructions = rule.treatment().allInstructions();
    for (Instruction ins : instructions) {
        if (ins.type() == Instruction.Type.OUTPUT) {
            outPort = ((Instructions.OutputInstruction) ins).port();
        }
    }
    checkNotNull(outPort);
    return new ChannelData(inPort, outPort, ochSignal);
}
Also used : PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) OchSignal(org.onosproject.net.OchSignal) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 54 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class RoadmCrossConnectCommand method dropRule.

/**
 * This function drops XC installed on the device, which is matching parsed criteria.
 * Takes as an input "global" parameters (passed by user through the console).
 * @return - returns number of the rules that were dropped.
 */
protected FlowId dropRule() {
    // Preparing parameters
    DeviceId device = DeviceId.deviceId(deviceId);
    PortNumber inPort = PortNumber.portNumber(srcPort);
    PortNumber outPort = PortNumber.portNumber(dstPort);
    // Creating some variables
    OchSignal ochSignal = null;
    PortNumber inputPortNumber = null;
    PortNumber outputPortNumber = null;
    // Main idea: Go over all flow rules (read out from the storage) of current device and
    // filter them based on input and output port with respect to OchSignal
    FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
    Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
    FlowId flowId = null;
    OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
    for (FlowEntry flowRule : flowRules) {
        // Taken from FlowRuleParser
        for (Criterion c : flowRule.selector().criteria()) {
            if (c instanceof OchSignalCriterion) {
                ochSignal = ((OchSignalCriterion) c).lambda();
            }
            if (c instanceof PortCriterion) {
                // obtain input port
                inputPortNumber = ((PortCriterion) c).port();
            }
        }
        for (Instruction i : flowRule.treatment().immediate()) {
            if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
                ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
            }
            if (i instanceof Instructions.OutputInstruction) {
                // obtain output port
                outputPortNumber = ((Instructions.OutputInstruction) i).port();
            }
        }
        // If we found match, then let's delete this rule
        if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
            flowId = flowRule.id();
            RoadmService manager = AbstractShellCommand.get(RoadmService.class);
            manager.removeConnection(device, flowId);
            print("Dropping existing XC from the device %s", deviceId);
            return flowId;
        }
    }
    return null;
}
Also used : DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) FlowId(org.onosproject.net.flow.FlowId) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) RoadmService(org.onosproject.roadm.RoadmService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 55 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class FlowAnalyzer method analyzeInstruction.

private boolean analyzeInstruction(Instruction i, FlowEntry flow) {
    boolean pointsToLiveEntry = false;
    Instructions.OutputInstruction output = (Instructions.OutputInstruction) i;
    PortNumber port = output.port();
    PortNumber outPort = null;
    DeviceId egress = null;
    boolean hasHost = false;
    ConnectPoint portPt = new ConnectPoint(flow.deviceId(), port);
    for (Link l : linkService.getEgressLinks(portPt)) {
        if (l.dst().elementId() instanceof DeviceId) {
            egress = l.dst().deviceId();
            outPort = l.dst().port();
        } else if (l.dst().elementId() instanceof HostId) {
            // the port leads to a host: therefore it is not a dead link
            pointsToLiveEntry = true;
            hasHost = true;
        }
    }
    if (!topologyService.isInfrastructure(topologyService.currentTopology(), portPt) && egress == null) {
        pointsToLiveEntry = true;
        hasHost = true;
    }
    if (hasHost) {
        return pointsToLiveEntry;
    }
    if (egress == null) {
        // the port that the flow instructions tells you to send the packet
        // to doesn't exist or is a controller port
        label.put(flow, "NA");
        return pointsToLiveEntry;
    }
    Iterable<FlowEntry> dstFlowTable = flowRuleService.getFlowEntries(egress);
    Set<Criterion> flowCriteria = flow.selector().criteria();
    // filter the criteria in order to remove port dependency
    Set<Criterion> filteredCriteria = new HashSet<>();
    for (Criterion criterion : flowCriteria) {
        if (!(criterion instanceof PortCriterion)) {
            filteredCriteria.add(criterion);
        }
    }
    // ensure that the in port is equal to the port that it is coming in from
    filteredCriteria.add(Criteria.matchInPort(outPort));
    for (FlowEntry entry : dstFlowTable) {
        if (ignoredFlows.contains(entry)) {
            continue;
        }
        if (filteredCriteria.containsAll(entry.selector().criteria())) {
            dfs(entry);
            if (!"Black Hole".equals(label.get(entry))) {
                // this entry is "live" i.e not a black hole
                pointsToLiveEntry = true;
            }
        }
    }
    return pointsToLiveEntry;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Link(org.onosproject.net.Link) HashSet(java.util.HashSet)

Aggregations

PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)55 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)34 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)32 FlowRule (org.onosproject.net.flow.FlowRule)32 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 TrafficSelector (org.onosproject.net.flow.TrafficSelector)25 List (java.util.List)24 Criterion (org.onosproject.net.flow.criteria.Criterion)24 Test (org.junit.Test)22 Intent (org.onosproject.net.intent.Intent)21 CoreService (org.onosproject.core.CoreService)20 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)20 PortNumber (org.onosproject.net.PortNumber)20 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)20 DeviceId (org.onosproject.net.DeviceId)18 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)18 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)18 Collection (java.util.Collection)16 Collectors (java.util.stream.Collectors)16