Search in sources :

Example 1 with OFPortStatus

use of org.projectfloodlight.openflow.protocol.OFPortStatus in project onos by opennetworkinglab.

the class DefaultOFSwitch method sendPortStatus.

private void sendPortStatus(Port port, OFPortReason ofPortReason) {
    Set<Channel> channels = controllerChannels();
    if (channels.isEmpty()) {
        log.trace("No channels present.  Port status will not be sent.");
        return;
    }
    OFPortDesc ofPortDesc = portDesc(port);
    OFPortStatus ofPortStatus = FACTORY.buildPortStatus().setDesc(ofPortDesc).setReason(ofPortReason).build();
    log.trace("Sending port status {}", ofPortStatus);
    channels.forEach(channel -> {
        channel.writeAndFlush(Collections.singletonList(ofPortStatus));
    });
}
Also used : OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) Channel(io.netty.channel.Channel) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus)

Example 2 with OFPortStatus

use of org.projectfloodlight.openflow.protocol.OFPortStatus 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 3 with OFPortStatus

use of org.projectfloodlight.openflow.protocol.OFPortStatus in project onos by opennetworkinglab.

the class OpenFlowDeviceProviderTest method portChanged.

@Test
public void portChanged() {
    OFPortStatus stat = SW1.factory().buildPortStatus().setReason(OFPortReason.ADD).setDesc(PD3).build();
    controller.listener.portChanged(DPID1, stat);
    assertNotNull("never went throught the provider service", registry.descr);
    assertEquals("port status unhandled", 3, registry.ports.get(DID1).size());
}
Also used : OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) Test(org.junit.Test)

Aggregations

OFPortStatus (org.projectfloodlight.openflow.protocol.OFPortStatus)3 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)2 Channel (io.netty.channel.Channel)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.Test)1 DefaultOpenFlowPacketContext (org.onosproject.openflow.controller.DefaultOpenFlowPacketContext)1 OpenFlowPacketContext (org.onosproject.openflow.controller.OpenFlowPacketContext)1 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)1 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)1 PacketListener (org.onosproject.openflow.controller.PacketListener)1 OFCircuitPortStatus (org.projectfloodlight.openflow.protocol.OFCircuitPortStatus)1 OFExperimenter (org.projectfloodlight.openflow.protocol.OFExperimenter)1 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)1