Class AbstractOpenFlowSwitch

  • All Implemented Interfaces:
    org.onosproject.net.driver.Behaviour, org.onosproject.net.driver.HandlerBehaviour, OpenFlowSwitchDriver, OpenFlowSwitch

    public abstract class AbstractOpenFlowSwitch
    extends org.onosproject.net.driver.AbstractHandlerBehaviour
    implements OpenFlowSwitchDriver
    An abstract representation of an OpenFlow switch. Can be extended by others to serve as a base for their vendor specific representation of a switch.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean activateEqualSwitch()
      Activate this EQUAL switch-controller relationship in the OF agent.
      boolean activateMasterSwitch()
      Activate this MASTER switch-controller relationship in the OF agent.
      java.lang.String channelId()
      Identifies the channel used to communicate with the switch.
      boolean connectSwitch()
      Announce to the OpenFlow agent that this switch has connected.
      java.lang.String datapathDescription()
      fetch the datapath description.
      org.onosproject.net.Device.Type deviceType()
      Returns the switch device type.
      void disconnectSwitch()
      Disconnects the switch by closing the TCP connection.
      org.projectfloodlight.openflow.protocol.OFFactory factory()
      Provides the factory for this OF version.
      org.projectfloodlight.openflow.protocol.OFFeaturesReply features()
      Fetches the features of this switch.
      Dpid getDpid()
      Gets the datapathId of the switch.
      long getId()
      Gets the datapathId of the switch.
      org.projectfloodlight.openflow.protocol.OFMeterFeatures getMeterFeatures()
      Fetches the meter features of this switch.
      int getNextTransactionId()
      Gets the next transaction id to use.
      java.util.List<org.projectfloodlight.openflow.protocol.OFPortDesc> getPorts()
      Fetches the ports of this switch.
      RoleState getRole()
      Fetch the role for this switch.
      java.lang.String getStringId()
      Gets a string version of the ID for this switch.
      void handleMessage​(org.projectfloodlight.openflow.protocol.OFMessage m)
      Handle the message coming from the dataplane.
      void handleNiciraRole​(org.projectfloodlight.openflow.protocol.OFMessage m)
      If this driver know of Nicira style role messages, these should be handled here.
      void handleRole​(org.projectfloodlight.openflow.protocol.OFMessage m)
      Handle OF 1.x (where x > 0) role messages.
      boolean handleRoleError​(org.projectfloodlight.openflow.protocol.OFErrorMsg error)
      Handle the situation where the role request triggers an error.
      java.lang.String hardwareDescription()
      fetch the hardware description.
      void init​(Dpid dpid, org.projectfloodlight.openflow.protocol.OFDescStatsReply desc, org.projectfloodlight.openflow.protocol.OFVersion ofv)
      Initialises the behaviour.
      boolean isConnected()
      Checks if the switch is still connected.
      abstract boolean isDriverHandshakeComplete()
      Checks whether the driver specific handshake is complete.
      java.lang.String manufacturerDescription()
      fetch the manufacturer description.
      protected java.util.Map<org.projectfloodlight.openflow.types.OFPort,​org.projectfloodlight.openflow.protocol.OFPortDesc> portDescs()  
      abstract void processDriverHandshakeMessage​(org.projectfloodlight.openflow.protocol.OFMessage m)
      Process a message during the driver specific handshake.
      void reassertRole()
      Reasserts this controllers role to the switch.
      void removeConnectedSwitch()
      Remove this switch from the openflow agent.
      protected void replacePortDescsWith​(java.util.Collection<org.projectfloodlight.openflow.protocol.OFPortDesc> allPorts)  
      void returnRoleReply​(RoleState requested, RoleState response)
      Notifies the controller that the device has responded to a set-role request.
      void sendHandshakeMessage​(org.projectfloodlight.openflow.protocol.OFMessage message)
      Allows the handshaker behaviour to send messages during the handshake phase only.
      void sendMsg​(java.util.List<org.projectfloodlight.openflow.protocol.OFMessage> msgs)
      Writes the OFMessage list to the driver.
      void sendMsg​(org.projectfloodlight.openflow.protocol.OFMessage msg)
      Writes the message to the driver.
      void sendRoleRequest​(org.projectfloodlight.openflow.protocol.OFMessage msg)
      Sends only role request messages.
      java.lang.String serialNumber()
      fetch the serial number.
      void setAgent​(OpenFlowAgent ag)
      Sets the OpenFlow agent to be used.
      void setChannel​(OpenFlowSession channel)
      Sets the associated OpenFlow session for this switch.
      void setConnected​(boolean connected)
      Sets whether the switch is connected.
      void setFeaturesReply​(org.projectfloodlight.openflow.protocol.OFFeaturesReply featuresReply)
      Sets the features reply for this switch.
      void setMeterFeaturesReply​(org.projectfloodlight.openflow.protocol.OFMeterFeaturesStatsReply meterFeaturesReply)
      Sets the meter features reply for this switch.
      void setOFVersion​(org.projectfloodlight.openflow.protocol.OFVersion ofV)
      Sets the OF version for this switch.
      void setPortDescReplies​(java.util.List<org.projectfloodlight.openflow.protocol.OFPortDescStatsReply> portDescReplies)
      Sets the ports on this switch.
      void setPortDescReply​(org.projectfloodlight.openflow.protocol.OFPortDescStatsReply portDescReply)
      Sets the ports on this switch.
      void setRole​(RoleState role)
      Sets the role for this switch.
      void setRoleHandler​(RoleHandler roleHandler)
      Sets the Role handler object.
      void setSwitchDescription​(org.projectfloodlight.openflow.protocol.OFDescStatsReply d)
      Sets the switch description.
      void setTableFull​(boolean full)
      Sets this switch has having a full flowtable.
      java.lang.String softwareDescription()
      fetch the software description.
      abstract void startDriverHandshake()
      Starts the driver specific handshake process.
      abstract java.lang.Boolean supportNxRole()
      Does this switch support Nicira Role messages.
      java.lang.String toString()  
      void transitionToEqualSwitch()
      Transition this switch-controller relationship to an EQUAL state.
      void transitionToMasterSwitch()
      Transition this switch-controller relationship to an Master state.
      • Methods inherited from class org.onosproject.net.driver.AbstractHandlerBehaviour

        handler, setHandler
      • Methods inherited from class org.onosproject.net.driver.AbstractBehaviour

        data, setData
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.onosproject.net.driver.Behaviour

        data, setData
      • Methods inherited from interface org.onosproject.net.driver.HandlerBehaviour

        handler, setHandler
    • Field Detail

      • log

        protected final org.slf4j.Logger log
      • channelId

        protected java.lang.String channelId
      • startDriverHandshakeCalled

        protected boolean startDriverHandshakeCalled
    • Constructor Detail

      • AbstractOpenFlowSwitch

        public AbstractOpenFlowSwitch()
    • Method Detail

      • init

        public void init​(Dpid dpid,
                         org.projectfloodlight.openflow.protocol.OFDescStatsReply desc,
                         org.projectfloodlight.openflow.protocol.OFVersion ofv)
        Description copied from interface: OpenFlowSwitchDriver
        Initialises the behaviour.
        Specified by:
        init in interface OpenFlowSwitchDriver
        Parameters:
        dpid - a dpid
        desc - a switch description
        ofv - OpenFlow version
      • disconnectSwitch

        public final void disconnectSwitch()
        Description copied from interface: OpenFlowSwitch
        Disconnects the switch by closing the TCP connection. Results in a call to the channel handler's channelDisconnected method for cleanup
        Specified by:
        disconnectSwitch in interface OpenFlowSwitch
      • sendMsg

        public void sendMsg​(org.projectfloodlight.openflow.protocol.OFMessage msg)
        Description copied from interface: OpenFlowSwitch
        Writes the message to the driver.

        Note: Messages may be silently dropped/lost due to IOExceptions or role. If this is a concern, then a caller should use barriers.

        Specified by:
        sendMsg in interface OpenFlowSwitch
        Parameters:
        msg - the message to write
      • sendMsg

        public final void sendMsg​(java.util.List<org.projectfloodlight.openflow.protocol.OFMessage> msgs)
        Description copied from interface: OpenFlowSwitch
        Writes the OFMessage list to the driver.

        Note: Messages may be silently dropped/lost due to IOExceptions or role. If this is a concern, then a caller should use barriers.

        Specified by:
        sendMsg in interface OpenFlowSwitch
        Parameters:
        msgs - the messages to be written
      • sendRoleRequest

        public final void sendRoleRequest​(org.projectfloodlight.openflow.protocol.OFMessage msg)
        Description copied from interface: OpenFlowSwitchDriver
        Sends only role request messages.
        Specified by:
        sendRoleRequest in interface OpenFlowSwitchDriver
        Parameters:
        msg - a role request message.
      • sendHandshakeMessage

        public final void sendHandshakeMessage​(org.projectfloodlight.openflow.protocol.OFMessage message)
        Description copied from interface: OpenFlowSwitchDriver
        Allows the handshaker behaviour to send messages during the handshake phase only.
        Specified by:
        sendHandshakeMessage in interface OpenFlowSwitchDriver
        Parameters:
        message - an OpenFlow message
      • isConnected

        public final boolean isConnected()
        Description copied from interface: OpenFlowSwitch
        Checks if the switch is still connected.
        Specified by:
        isConnected in interface OpenFlowSwitch
        Returns:
        whether the switch is still connected
      • setConnected

        public final void setConnected​(boolean connected)
        Description copied from interface: OpenFlowSwitchDriver
        Sets whether the switch is connected.
        Specified by:
        setConnected in interface OpenFlowSwitchDriver
        Parameters:
        connected - whether the switch is connected
      • channelId

        public java.lang.String channelId()
        Description copied from interface: OpenFlowSwitch
        Identifies the channel used to communicate with the switch.
        Specified by:
        channelId in interface OpenFlowSwitch
        Returns:
        string representation of the connection to the device
      • getId

        public final long getId()
        Description copied from interface: OpenFlowSwitch
        Gets the datapathId of the switch.
        Specified by:
        getId in interface OpenFlowSwitch
        Returns:
        the switch dpid in long format
      • getDpid

        public Dpid getDpid()
        Description copied from interface: OpenFlowSwitch
        Gets the datapathId of the switch.
        Specified by:
        getDpid in interface OpenFlowSwitch
        Returns:
        the switch dpid
      • getStringId

        public final java.lang.String getStringId()
        Description copied from interface: OpenFlowSwitch
        Gets a string version of the ID for this switch.
        Specified by:
        getStringId in interface OpenFlowSwitch
        Returns:
        string version of the ID
      • setOFVersion

        public final void setOFVersion​(org.projectfloodlight.openflow.protocol.OFVersion ofV)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the OF version for this switch.
        Specified by:
        setOFVersion in interface OpenFlowSwitchDriver
        Parameters:
        ofV - the version to set.
      • setTableFull

        public void setTableFull​(boolean full)
        Description copied from interface: OpenFlowSwitchDriver
        Sets this switch has having a full flowtable.
        Specified by:
        setTableFull in interface OpenFlowSwitchDriver
        Parameters:
        full - true if full, false otherswise.
      • setFeaturesReply

        public void setFeaturesReply​(org.projectfloodlight.openflow.protocol.OFFeaturesReply featuresReply)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the features reply for this switch.
        Specified by:
        setFeaturesReply in interface OpenFlowSwitchDriver
        Parameters:
        featuresReply - the features to set.
      • setMeterFeaturesReply

        public void setMeterFeaturesReply​(org.projectfloodlight.openflow.protocol.OFMeterFeaturesStatsReply meterFeaturesReply)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the meter features reply for this switch.
        Specified by:
        setMeterFeaturesReply in interface OpenFlowSwitchDriver
        Parameters:
        meterFeaturesReply - the meter features to set.
      • supportNxRole

        public abstract java.lang.Boolean supportNxRole()
        Description copied from interface: OpenFlowSwitchDriver
        Does this switch support Nicira Role messages.

        Only relevant if this Device is OpenFlow 1.0.

        Specified by:
        supportNxRole in interface OpenFlowSwitchDriver
        Returns:
        true if supports, false otherwise.
      • handleMessage

        public final void handleMessage​(org.projectfloodlight.openflow.protocol.OFMessage m)
        Handle the message coming from the dataplane.
        Specified by:
        handleMessage in interface OpenFlowSwitch
        Parameters:
        m - the actual message
      • connectSwitch

        public final boolean connectSwitch()
        Description copied from interface: OpenFlowSwitchDriver
        Announce to the OpenFlow agent that this switch has connected.
        Specified by:
        connectSwitch in interface OpenFlowSwitchDriver
        Returns:
        true if successful, false if duplicate switch.
      • activateMasterSwitch

        public final boolean activateMasterSwitch()
        Description copied from interface: OpenFlowSwitchDriver
        Activate this MASTER switch-controller relationship in the OF agent.
        Specified by:
        activateMasterSwitch in interface OpenFlowSwitchDriver
        Returns:
        true is successful, false is switch has not connected or is unknown to the system.
      • activateEqualSwitch

        public final boolean activateEqualSwitch()
        Description copied from interface: OpenFlowSwitchDriver
        Activate this EQUAL switch-controller relationship in the OF agent.
        Specified by:
        activateEqualSwitch in interface OpenFlowSwitchDriver
        Returns:
        true is successful, false is switch has not connected or is unknown to the system.
      • factory

        public org.projectfloodlight.openflow.protocol.OFFactory factory()
        Description copied from interface: OpenFlowSwitch
        Provides the factory for this OF version.
        Specified by:
        factory in interface OpenFlowSwitch
        Returns:
        OF version specific factory.
      • setPortDescReply

        public void setPortDescReply​(org.projectfloodlight.openflow.protocol.OFPortDescStatsReply portDescReply)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the ports on this switch.
        Specified by:
        setPortDescReply in interface OpenFlowSwitchDriver
        Parameters:
        portDescReply - the port set and descriptions
      • replacePortDescsWith

        protected void replacePortDescsWith​(java.util.Collection<org.projectfloodlight.openflow.protocol.OFPortDesc> allPorts)
      • portDescs

        protected java.util.Map<org.projectfloodlight.openflow.types.OFPort,​org.projectfloodlight.openflow.protocol.OFPortDesc> portDescs()
      • setPortDescReplies

        public void setPortDescReplies​(java.util.List<org.projectfloodlight.openflow.protocol.OFPortDescStatsReply> portDescReplies)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the ports on this switch.
        Specified by:
        setPortDescReplies in interface OpenFlowSwitchDriver
        Parameters:
        portDescReplies - list of port set and descriptions
      • returnRoleReply

        public void returnRoleReply​(RoleState requested,
                                    RoleState response)
        Description copied from interface: OpenFlowSwitch
        Notifies the controller that the device has responded to a set-role request.
        Specified by:
        returnRoleReply in interface OpenFlowSwitch
        Parameters:
        requested - the role requested by the controller
        response - the role set at the device
      • processDriverHandshakeMessage

        public abstract void processDriverHandshakeMessage​(org.projectfloodlight.openflow.protocol.OFMessage m)
        Description copied from interface: OpenFlowSwitchDriver
        Process a message during the driver specific handshake.
        Specified by:
        processDriverHandshakeMessage in interface OpenFlowSwitchDriver
        Parameters:
        m - the message to process.
      • setRole

        public void setRole​(RoleState role)
        Description copied from interface: OpenFlowSwitch
        Sets the role for this switch.
        Specified by:
        setRole in interface OpenFlowSwitch
        Parameters:
        role - the role to set.
      • reassertRole

        public void reassertRole()
        Description copied from interface: OpenFlowSwitchDriver
        Reasserts this controllers role to the switch. Useful in cases where the switch no longer agrees that this controller has the role it claims.
        Specified by:
        reassertRole in interface OpenFlowSwitchDriver
      • handleRoleError

        public boolean handleRoleError​(org.projectfloodlight.openflow.protocol.OFErrorMsg error)
        Description copied from interface: OpenFlowSwitchDriver
        Handle the situation where the role request triggers an error.
        Specified by:
        handleRoleError in interface OpenFlowSwitchDriver
        Parameters:
        error - the error to handle.
        Returns:
        true if handled, false if not.
      • setSwitchDescription

        public void setSwitchDescription​(org.projectfloodlight.openflow.protocol.OFDescStatsReply d)
        Description copied from interface: OpenFlowSwitchDriver
        Sets the switch description.
        Specified by:
        setSwitchDescription in interface OpenFlowSwitchDriver
        Parameters:
        d - the descriptions
      • getPorts

        public java.util.List<org.projectfloodlight.openflow.protocol.OFPortDesc> getPorts()
        Description copied from interface: OpenFlowSwitch
        Fetches the ports of this switch.
        Specified by:
        getPorts in interface OpenFlowSwitch
        Returns:
        unmodifiable list of the ports.
      • getMeterFeatures

        public org.projectfloodlight.openflow.protocol.OFMeterFeatures getMeterFeatures()
        Description copied from interface: OpenFlowSwitch
        Fetches the meter features of this switch.
        Specified by:
        getMeterFeatures in interface OpenFlowSwitch
        Returns:
        unmodifiable meter features
      • features

        public org.projectfloodlight.openflow.protocol.OFFeaturesReply features()
        Description copied from interface: OpenFlowSwitch
        Fetches the features of this switch.
        Specified by:
        features in interface OpenFlowSwitch
        Returns:
        unmodifiable features
      • manufacturerDescription

        public java.lang.String manufacturerDescription()
        Description copied from interface: OpenFlowSwitch
        fetch the manufacturer description.
        Specified by:
        manufacturerDescription in interface OpenFlowSwitch
        Returns:
        the description
      • datapathDescription

        public java.lang.String datapathDescription()
        Description copied from interface: OpenFlowSwitch
        fetch the datapath description.
        Specified by:
        datapathDescription in interface OpenFlowSwitch
        Returns:
        the description
      • hardwareDescription

        public java.lang.String hardwareDescription()
        Description copied from interface: OpenFlowSwitch
        fetch the hardware description.
        Specified by:
        hardwareDescription in interface OpenFlowSwitch
        Returns:
        the description
      • softwareDescription

        public java.lang.String softwareDescription()
        Description copied from interface: OpenFlowSwitch
        fetch the software description.
        Specified by:
        softwareDescription in interface OpenFlowSwitch
        Returns:
        the description
      • serialNumber

        public java.lang.String serialNumber()
        Description copied from interface: OpenFlowSwitch
        fetch the serial number.
        Specified by:
        serialNumber in interface OpenFlowSwitch
        Returns:
        the serial
      • deviceType

        public org.onosproject.net.Device.Type deviceType()
        Description copied from interface: OpenFlowSwitch
        Returns the switch device type.
        Specified by:
        deviceType in interface OpenFlowSwitch
        Returns:
        device type
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object