コード例 #1
0
    def _say_hello(self, connection, xid=None):
        """Method used to send a hello messages.

        Should be called once a new connection is established.
        To be able to deal with OF1.3 negotiation, hello should also
        carry a version_bitmap.
        """
        hello = GenericHello(versions=settings.OPENFLOW_VERSIONS, xid=xid)
        self.emit_message_out(connection, hello)
コード例 #2
0
 def test_pack_generic_hello(self):
     """Test packing a generic hello message."""
     data = b'\x04\x00\x00\x10\x00\x00\x00\x3e'
     data += b'\x00\x01\x00\x08\x00\x00\x00\x10'
     generic_hello = GenericHello(packet=data, versions=b'\x04')
     self.assertEqual(generic_hello.pack(), data)
コード例 #3
0
    def handle_raw_in(self, event):
        """Handle a RawEvent and generate a kytos/core.messages.in.* event.

        Args:
            event (KytosEvent): RawEvent with openflow message to be unpacked
        """

        # If the switch is already known to the controller, update the
        # 'lastseen' attribute
        switch = event.source.switch
        if switch:
            switch.update_lastseen()

        connection = event.source

        data = connection.remaining_data + event.content['new_data']
        packets, connection.remaining_data = of_slicer(data)
        if not packets:
            return

        unprocessed_packets = []

        for packet in packets:
            if not connection.is_alive():
                return
            log.debug('Connection %s: New Raw Openflow packet - %s',
                      connection.id, packet.hex())

            if connection.is_new():
                try:
                    message = GenericHello(packet=packet)
                    self._negotiate(connection, message)
                except (UnpackException, NegotiationException) as e:
                    if type(e) == UnpackException:
                        log.debug('Connection %s: Invalid hello message',
                                  connection.id)
                    else:
                        log.debug('Connection %s: Negotiation Failed',
                                  connection.id)
                    connection.protocol.state = 'hello_failed'
                    connection.close()
                    connection.state = ConnectionState.FAILED
                    return
                connection.set_setup_state()
                continue

            try:
                message = connection.protocol.unpack(packet)
            except (UnpackException, AttributeError) as e:
                log.debug(e)
                if type(e) == AttributeError:
                    debug_msg = 'connection closed before version negotiation'
                    log.debug('Connection %s: %s' , connection.id, debug_msg)
                connection.close()
                return

            log.debug('Connection %s: IN OFP, version: %s, type: %s, xid: %s',
                      connection.id,
                      message.header.version,
                      message.header.message_type,
                      message.header.xid)

            if connection.is_during_setup():
                if not (str(message.header.message_type) ==
                        'Type.OFPT_FEATURES_REPLY' and
                        connection.protocol.state == 'waiting_features_reply'):
                    unprocessed_packets.append(packet)
                    continue

            self.emit_message_in(connection, message)

        connection.remaining_data = b''.join(unprocessed_packets) + \
                                    connection.remaining_data
コード例 #4
0
ファイル: test_utils.py プロジェクト: kytos/of_core
 def test_pack(self, mock_ofptype):
     """Test pack."""
     mock_ofptype.return_value = True
     generic = GenericHello(packet=self.data, versions=b'\x04')
     response = generic.pack()
     self.assertEqual(self.data, response)