Search in sources :

Example 1 with OpenFlowSwitchListener

use of org.onosproject.openflow.controller.OpenFlowSwitchListener in project onos by opennetworkinglab.

the class OpenFlowControllerImpl method processPacket.

@Override
public void processPacket(Dpid dpid, OFMessage msg) {
    OpenFlowSwitch sw = this.getSwitch(dpid);
    if (log.isTraceEnabled()) {
        log.trace("Processing message from switch {} via openflow: {}", dpid, msg);
    }
    // Check if someone is waiting for this message
    ConcurrentMap<Long, CompletableFuture<OFMessage>> xids = responses.get(dpid);
    if (xids != null) {
        CompletableFuture<OFMessage> future = xids.remove(msg.getXid());
        if (future != null) {
            future.complete(msg);
        }
    }
    switch(msg.getType()) {
        case PORT_STATUS:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.portChanged(dpid, (OFPortStatus) msg);
            }
            break;
        case FEATURES_REPLY:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.switchChanged(dpid);
            }
            break;
        case PACKET_IN:
            if (sw == null) {
                log.error("Ignoring PACKET_IN, switch {} is not found", dpid);
                break;
            }
            OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext.packetContextFromPacketIn(sw, (OFPacketIn) msg);
            for (PacketListener p : ofPacketListener.values()) {
                p.handlePacket(pktCtx);
            }
            break;
        // ie. Back to back error could cause us to starve.
        case FLOW_REMOVED:
            executorMsgs.execute(new OFMessageHandler(dpid, msg));
            break;
        case ERROR:
            log.debug("Received error message from {}: {}", dpid, msg);
            errorMsgs.putIfAbsent(msg.getXid(), true);
            executorErrorMsgs.execute(new OFMessageHandler(dpid, msg));
            break;
        case STATS_REPLY:
            processStatsReply(dpid, (OFStatsReply) msg);
            break;
        case BARRIER_REPLY:
            if (errorMsgs.containsKey(msg.getXid())) {
                // To make oferror msg handling and corresponding barrier reply serialized,
                // executorErrorMsgs is used for both transaction
                errorMsgs.remove(msg.getXid());
                executorErrorMsgs.execute(new OFMessageHandler(dpid, msg));
            } else {
                executorBarrier.execute(new OFMessageHandler(dpid, msg));
            }
            break;
        case EXPERIMENTER:
            if (sw == null) {
                log.error("Switch {} is not found", dpid);
                break;
            }
            long experimenter = ((OFExperimenter) msg).getExperimenter();
            if (experimenter == 0x748771) {
                // LINC-OE port stats
                OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg;
                OFPortStatus.Builder portStatus = sw.factory().buildPortStatus();
                OFPortDesc.Builder portDesc = sw.factory().buildPortDesc();
                portDesc.setPortNo(circuitPortStatus.getPortNo()).setHwAddr(circuitPortStatus.getHwAddr()).setName(circuitPortStatus.getName()).setConfig(circuitPortStatus.getConfig()).setState(circuitPortStatus.getState());
                portStatus.setReason(circuitPortStatus.getReason()).setDesc(portDesc.build());
                for (OpenFlowSwitchListener l : ofSwitchListener) {
                    l.portChanged(dpid, portStatus.build());
                }
            } else {
                log.warn("Handling experimenter type {} not yet implemented", ((OFExperimenter) msg).getExperimenter(), msg);
            }
            break;
        default:
            log.warn("Handling message type {} not yet implemented {}", msg.getType(), msg);
    }
}
Also used : OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) OFCircuitPortStatus(org.projectfloodlight.openflow.protocol.OFCircuitPortStatus) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) PacketListener(org.onosproject.openflow.controller.PacketListener) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) OpenFlowPacketContext(org.onosproject.openflow.controller.OpenFlowPacketContext) DefaultOpenFlowPacketContext(org.onosproject.openflow.controller.DefaultOpenFlowPacketContext) CompletableFuture(java.util.concurrent.CompletableFuture) OFExperimenter(org.projectfloodlight.openflow.protocol.OFExperimenter) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 2 with OpenFlowSwitchListener

use of org.onosproject.openflow.controller.OpenFlowSwitchListener in project onos by opennetworkinglab.

the class OpenFlowControllerImpl method processStatsReply.

private void processStatsReply(Dpid dpid, OFStatsReply reply) {
    switch(reply.getStatsType()) {
        case QUEUE:
            Collection<OFQueueStatsEntry> queueStatsEntries = publishQueueStats(dpid, (OFQueueStatsReply) reply);
            if (queueStatsEntries != null) {
                OFQueueStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildQueueStatsReply();
                rep.setEntries(ImmutableList.copyOf(queueStatsEntries));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case PORT_DESC:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.switchChanged(dpid);
            }
            break;
        case FLOW:
            Collection<OFFlowStatsEntry> flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply);
            if (flowStats != null) {
                OFFlowStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildFlowStatsReply();
                rep.setEntries(ImmutableList.copyOf(flowStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case FLOW_LIGHTWEIGHT:
            Collection<OFFlowLightweightStatsEntry> flowLightweightStats = publishFlowStatsLightweight(dpid, (OFFlowLightweightStatsReply) reply);
            if (flowLightweightStats != null) {
                OFFlowLightweightStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildFlowLightweightStatsReply();
                rep.setEntries(ImmutableList.copyOf(flowLightweightStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case TABLE:
            Collection<OFTableStatsEntry> tableStats = publishTableStats(dpid, (OFTableStatsReply) reply);
            if (tableStats != null) {
                OFTableStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildTableStatsReply();
                rep.setEntries(ImmutableList.copyOf(tableStats));
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case GROUP:
            Collection<OFGroupStatsEntry> groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply);
            if (groupStats != null) {
                OFGroupStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildGroupStatsReply();
                rep.setEntries(ImmutableList.copyOf(groupStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case GROUP_DESC:
            Collection<OFGroupDescStatsEntry> groupDescStats = publishGroupDescStats(dpid, (OFGroupDescStatsReply) reply);
            if (groupDescStats != null) {
                OFGroupDescStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildGroupDescStatsReply();
                rep.setEntries(ImmutableList.copyOf(groupDescStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case PORT:
            executorMsgs.execute(new OFMessageHandler(dpid, reply));
            break;
        case METER:
            executorMsgs.execute(new OFMessageHandler(dpid, reply));
            break;
        case EXPERIMENTER:
            if (reply instanceof OFCalientFlowStatsReply) {
                OpenFlowSwitch sw = this.getSwitch(dpid);
                // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API
                if (sw == null) {
                    log.error("Switch {} is not found", dpid);
                    break;
                }
                OFFlowStatsReply.Builder fsr = sw.factory().buildFlowStatsReply();
                List<OFFlowStatsEntry> entries = new ArrayList<>();
                for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) reply).getEntries()) {
                    // Single instruction, i.e., output to port
                    OFActionOutput action = sw.factory().actions().buildOutput().setPort(entry.getOutPort()).build();
                    OFInstruction instruction = sw.factory().instructions().applyActions(Collections.singletonList(action));
                    OFFlowStatsEntry fs = sw.factory().buildFlowStatsEntry().setMatch(entry.getMatch()).setTableId(entry.getTableId()).setDurationSec(entry.getDurationSec()).setDurationNsec(entry.getDurationNsec()).setPriority(entry.getPriority()).setIdleTimeout(entry.getIdleTimeout()).setHardTimeout(entry.getHardTimeout()).setFlags(entry.getFlags()).setCookie(entry.getCookie()).setInstructions(Collections.singletonList(instruction)).build();
                    entries.add(fs);
                }
                fsr.setEntries(entries);
                flowStats = publishFlowStats(dpid, fsr.build());
                if (flowStats != null) {
                    OFFlowStatsReply.Builder rep = sw.factory().buildFlowStatsReply();
                    rep.setEntries(ImmutableList.copyOf(flowStats));
                    executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
                }
            } else {
                executorMsgs.execute(new OFMessageHandler(dpid, reply));
            }
            break;
        default:
            log.warn("Discarding unknown stats reply type {}", reply.getStatsType());
            break;
    }
}
Also used : OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) OFQueueStatsEntry(org.projectfloodlight.openflow.protocol.OFQueueStatsEntry) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) OFFlowLightweightStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry) ArrayList(java.util.ArrayList) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFFlowLightweightStatsReply(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply) OFCalientFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFCalientFlowStatsReply(org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) OFGroupStatsReply(org.projectfloodlight.openflow.protocol.OFGroupStatsReply) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) OFQueueStatsReply(org.projectfloodlight.openflow.protocol.OFQueueStatsReply)

Aggregations

OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)2 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DefaultOpenFlowPacketContext (org.onosproject.openflow.controller.DefaultOpenFlowPacketContext)1 OpenFlowPacketContext (org.onosproject.openflow.controller.OpenFlowPacketContext)1 PacketListener (org.onosproject.openflow.controller.PacketListener)1 OFCalientFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry)1 OFCalientFlowStatsReply (org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply)1 OFCircuitPortStatus (org.projectfloodlight.openflow.protocol.OFCircuitPortStatus)1 OFExperimenter (org.projectfloodlight.openflow.protocol.OFExperimenter)1 OFFlowLightweightStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry)1 OFFlowLightweightStatsReply (org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply)1 OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)1 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)1 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)1 OFGroupDescStatsReply (org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply)1 OFGroupStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupStatsEntry)1 OFGroupStatsReply (org.projectfloodlight.openflow.protocol.OFGroupStatsReply)1 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)1