コード例 #1
0
from construct import Struct, Union, Enum, SLInt32

announcement_type = Enum(
    SLInt32("type"),
    LAUNCH=0,
    EXIT=1,
)

announcement = Struct(
    "announcement",
    announcement_type,
    Union(
        "args",
        SLInt32("rank"),
    ),
)

ANNOUNCEMENT_PACKET_LEN = announcement.sizeof()
コード例 #2
0
@since: July 2015
@status: in development

@requires: construct 2.5.2
"""
from construct import SLInt8, SLInt32, ULInt64, CString
from construct import Embed, Struct, Container
from construct import If

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION, tri_boolean
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

field_mac_ap = Struct(
    'mac_ap',
    SLInt32('mac_ap_size'),
    If(lambda ctx: ctx["mac_ap_size"] > 0, CString("mac_ap")),
)
""" handles the ap's mac address used in msg_association
"""

field_mac_sta = Struct(
    'mac_sta',
    SLInt32('mac_sta_size'),
    If(lambda ctx: ctx["mac_sta_size"] > 0, CString("mac_sta")),
)
""" handles the station's mac address used in msg_association
"""
msg_association = Struct(
    'msg_association',
    Embed(msg_default),  # default fields
コード例 #3
0
from construct import ULInt32, SLInt32, ULInt64
from construct import Embed, Struct, Container, Array

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_station, field_mac_addr, field_ssid, field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

# ###############################################################
#
# MSG_TYPE.MSG_WLAN_INFO
#
# ###############################################################
wlan_entry = Struct(
    'wlan_entry',
    SLInt32('ifindex'),
    Embed(field_intf_name),
    ULInt32('wlan_indx'),
    ULInt32('phy_indx'),
    ULInt64('dev'),
    Embed(field_mac_addr),
    Embed(field_ssid),
    ULInt32('channel_type'),
    ULInt32('chan_width'),
    ULInt32('freq'),
    ULInt32('freq1'),
    ULInt32('freq2'),
    SLInt32('iftype'),
)
""" information about a wifi interface"""
コード例 #4
0
from construct import SLInt32
from construct import Embed
from construct import Struct
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_ap_dtiminterval = Struct('msg_ap_dtiminterval',
                             Embed(msg_default),  # default fields
                             Embed(field_intf_name),
                             SLInt32('dtim_interval'),
                             # Probe()
                             )


def get_ap_dtiminterval(server, id=0, intf_name=None):
    """ get the DTIM interval set in the interface intf_name
        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str

        @return msg: received message
        @return value:
    """
    if intf_name is None:
コード例 #5
0
"""
from datetime import datetime
from construct import SLInt32, LFloat32, CString, SLInt8
from construct import Embed, Struct, Container
from construct import If
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION, BUFFER_SIZE
from pox.ethanol.ssl_message.msg_common import connect_ssl_socket
from pox.ethanol.ssl_message.msg_common import is_error_msg, tri_boolean, len_of_string

msg_ping = Struct(
    'msg_ping',
    Embed(msg_default),  # default fields
    SLInt32('data_size'),
    If(lambda ctx: ctx["data_size"] > 0, CString("data")),
    # Probe(),
)
""" ping message data structure
"""

msg_pong = Struct(
    'msg_pong',
    Embed(msg_default),  # default fields
    LFloat32('rtt'),  # float com 32 bits, LFloat32 (C little endian 32 bits)
    SLInt8('verify_data'),  # class boolean
    # Probe(),
)
""" pong message data structure
"""
コード例 #6
0
from pox.ethanol.ssl_message.msg_log import log

from pox.ethanol.ethanol.ap import add_ap
from pox.ethanol.ethanol.station import add_station

from pox.ethanol.events import Events

events_hello = Events()
"""to handle a receiving hello message, just add your function to events_hello
   your function must use 'def my_funct(**kwargs)' signature for compatibility
   @change: we send to parameters: msg, fromaddr
"""

msg_hello = Struct('msg_hello',
                   Embed(msg_default),  # default fields
                   SLInt32('device_type'),  # 0 = controller, 1 = ap, 2 = station
                   SLInt32('tcp_port'),
                   LFloat32('rtt')  # float com 32 bits
                   )


def send_msg_hello(server, m_id=0):
    """
      @param server: tuple (ip, port_num)
      @param m_id: message id

      @return: msg - received message
    """
    ssl_sock, sckt = connect_ssl_socket(server)

    # print "send_msg_hello id:", m_id
コード例 #7
0
    LFloat64('tx_carrier_errors'),
    LFloat64('tx_compressed'),
    LFloat64('tx_dropped'),
    LFloat64('tx_errors'),
    LFloat64('tx_fifo_errors'),
    LFloat64('tx_heartbeat_errors'),
    LFloat64('tx_packets'),
    LFloat64('tx_window_errors'),
    # Probe()
)

msg_mean_statistics = Struct(
    'msg_mean_statistics',
    Embed(msg_default),  # default fields
    Embed(field_station),
    SLInt32('num'),
    Array(lambda ctx: ctx.num, CString('intf')),
    Array(lambda ctx: ctx.num, mean_net_statistics),
    # Probe()
)


def send_msg_mean_sta_statistics(server, id=0, sta_ip=None, sta_port=0):
    """
      @param server: tuple (ip, port_num)
      @param id: message id
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int
コード例 #8
0
            ),  # long in c is coded as a unsigned 64-bit integer little endian
    SLInt64(
        'receive_time'
    ),  # long long in c is coded as a unsigned 64-bit integer little endian
    SLInt64('transmit_time'),
    SLInt64('active_time'),
    SLInt64('busy_time'),
    SLInt64('channel_type'),
    SLInt64('extension_channel_busy_time'),
)

msg_channelinfo = Struct(
    'msg_channelinfo',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    SLInt32('channel'),
    SLInt32('num_freqs'),
    # Probe(),
    Array(lambda ctx: ctx.num_freqs, channel_info),
)


def get_channelinfo(server,
                    id=0,
                    intf_name=None,
                    channel=0,
                    only_channel_in_use=False):
    """ get the channels the interface inff_name supports, this function applies to access points

      @param server: tuple (ip, port_num)
      @param id: message id
コード例 #9
0
@requires: construct 2.5.2
"""
from construct import SLInt8, SLInt32, ULInt64, LFloat32
from construct import Embed, Struct, Container

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION, tri_boolean
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string
from pox.ethanol.ssl_message.msg_core import field_mac_addr

msg_metric = Struct(
    'msg_metric',
    Embed(msg_default),  # default fields
    SLInt8('enable'),  # boolean enable or disable
    SLInt32('period'),
    ULInt64(
        'metric'
    ),  # bit array, bit=0 is not considered, bit=1 apply 'enable' action
)
""" all metric message types are the same
"""


def set_metric(server, id=0, metric=0, enable=True, period=100):
    """ only for tests. the controller don't use this!!!
    """
    if metric == 0:
        return None
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_METRIC,
コード例 #10
0
@requires: construct 2.5.2
"""

from construct import SLInt32, CString
from construct import Embed, If
from construct import Struct
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

field_current_ap = Struct('current_ap',
                          SLInt32('current_ap_size'),
                          If(lambda ctx: ctx["current_ap_size"] > 0, CString("current_ap")),
                          )

msg_changed_ap = Struct('msg_changed_ap',
                        Embed(msg_default),  # default fields
                        Embed(field_intf_name),
                        Embed(field_current_ap),
                        SLInt32('status'),
                        # Probe()
                        )


def changed_ap(server, id=0, status=0, current_ap=None, intf_name=None):
    """ verify is the interface is broadcasting the SSID
      @param server: tuple (ip, port_num)
コード例 #11
0
from pox.ethanol.ssl_message.msg_core import field_intf_name, field_station
from pox.ethanol.ssl_message.msg_core import field_mac_addr
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

from pox.ethanol.events import Events

events_snr_threshold_reached = Events()
"""to handle a receiving snr_threshold_reached message, just add your function to events_snr_threshold_reached
   your function must use 'def my_funct(**kwargs)' signature for compatibility
   @change: we send to parameters: msg, fromaddr, sta_mac, intf_name, mac_ap
"""

field_mac_ap = Struct(
    'mac_ap',
    SLInt32('mac_ap_size'),
    If(lambda ctx: ctx["mac_ap_size"] > 0, CString("mac_ap")),
)
""" handles a mac address field for the new ap (a C char * field)
"""

msg_snr_threshold_reached = Struct(
    'msg_snr_threshold_reached',
    Embed(msg_default),  # default fields
    Embed(field_station),
    Embed(field_mac_addr),  # sta_mac
    Embed(field_intf_name),  # intf_name
    Embed(field_mac_ap),  # mac_ap
    SLInt64('snr'),
    # Probe()
)
コード例 #12
0
@status: in development

@requires: construct 2.5.2
"""

from construct import SLInt32, CString
from construct import Embed, Struct, Container, If

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

field_parameter = Struct(
    'param_name',
    SLInt32('param_name_size'),
    If(lambda ctx: ctx["param_name_size"] > 0, CString("param_name")),
)
""" name of the parameter
"""

field_parameter_value = Struct(
    'param_name_value',
    SLInt32('param_name_value_size'),
    If(lambda ctx: ctx["param_name_value_size"] > 0,
       CString("param_value_name")),
)
""" value of the parameter
"""

msg_hostapd_conf = Struct(
コード例 #13
0
from construct import Array
from construct import Struct
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_mac_addr, field_ssid, field_intf_name, field_station
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, tri_boolean, len_of_string

ap_in_range = Struct(
    'ap_in_range',
    Embed(field_intf_name),
    Embed(field_mac_addr),
    Embed(field_ssid),
    SLInt32('status'),
    SLInt64('frequency'),
    SLInt32('channel'),
    LFloat32('signal'),  # float in C is coded as little endian 32 bit number
    SLInt32('powerconstraint'),
    SLInt32('tx_power'),
    SLInt32('link_margin'),
    SLInt32('age'),
    SLInt8('is_dBm'),  # this is a boolean coded as a 8 bit integer
)

msg_ap_in_range = Struct(
    'msg_ap_in_range',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    Embed(field_station),
コード例 #14
0
@requires: construct 2.5.2
"""

from construct import SLInt32, SLInt64, CString
from construct import Embed, If
from construct import Struct
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default, field_intf_name, field_station
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string, return_from_dict

field_time_stamp = Struct(
    'time_stamp',
    SLInt32('time_stamp_size'),
    If(lambda ctx: ctx["time_stamp_size"] > 0, CString("time_stamp")),
)

msg_statistics = Struct(
    'msg_statistics',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    Embed(field_station),
    SLInt64('rx_packets'),
    SLInt64('rx_bytes'),
    SLInt64('rx_dropped'),
    SLInt64('rx_errors'),
    SLInt64('tx_packets'),
    SLInt64('tx_bytes'),
    SLInt64('tx_dropped'),
コード例 #15
0
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_station, field_ssid, field_intf_name, field_mac_addr
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_sta_link_info = Struct(
    'msg_sta_link_info',
    Embed(msg_default),
    Embed(field_intf_name),
    Embed(field_station),
    Embed(field_mac_addr),
    Embed(field_ssid),
    SLInt32('frequency'),
)


def get_sta_link_info(server, id=0, sta_ip=None, sta_port=0, intf_name=None):
    """
      returns three values: mac_addr, ssid, frequency
      None equals an error has occured (or no interface found)

      @todo: Nao eh necessario retornar intf_name

      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: names of the wireless interface
      @type intf_name: list of str
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
コード例 #16
0
@requires: construct 2.5.2
"""
from construct import SLInt32
from construct import Embed, Struct, Container

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_preamble = Struct(
    'msg_preamble',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    SLInt32('preamble'),
)


def get_preamble(server, id=0, intf_name=None):
    """ gets if the configured preamble is long or short
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str

      @return: msg - received message
    """
    # 1) create message
    if intf_name is None:
        return
コード例 #17
0
from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

from pox.ethanol.events import Events

events_bye = Events()
"""to handle a receiving bye messages, just add your function to events_bye
   your function must use 'def my_funct(**kwargs)' signature for compatibility
   @change: we send to parameters: msg, fromaddr
"""

msg_bye = Struct(
    'msg_bye',
    Embed(msg_default),  # default fields
    SLInt32('tcp_port'),
)


def send_msg_bye(server, id=0, tcp_port=None):
    """ disconnects the ethanol device from the controller
      @param server: tuple (ip, port_num)
      @param id: message id
      @param tcp_port: socket port number of the device
      @type tcp_port: int
    """
    if (tcp_port is None):
        return None  # error

    # print "send_msg_bye id:", id
    # 1) create message
コード例 #18
0
    """
    return SymmetricMapping(
        Field(name, 4),
        # FormatField(name, "<", "l")
        {
            True: int32_to_bytes(truth_value),
            False: int32_to_bytes(false_value)
        },
        default=default,
    )


msg_default = Struct(
    'msg_default',
    # Probe(), # utilizado para debug
    SLInt32('m_type'),
    SLInt32('m_id'),
    SLInt32('p_version_length'),
    If(lambda ctx: ctx["p_version_length"] > 0, CString("p_version")),
    # Probe(),
    SLInt32('m_size'),
)
"""
  default message structure
  to be embedded in the first part of every message
"""

field_intf_name = Struct(
    'intf_name',
    SLInt32('intf_name_size'),
    If(lambda ctx: ctx["intf_name_size"] > 0, CString("intf_name")),
コード例 #19
0
from construct import SLInt32, CString
from construct import Embed
from construct import Struct
from construct import Container, If
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_mac_addr
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_core import field_station
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

field_mac_new_ap = Struct('mac_new_ap',
                          SLInt32('mac_new_ap_size'),
                          If(lambda ctx: ctx["mac_new_ap_size"] > 0,
                             CString("mac_new_ap")
                             ),
                          )
""" handles a mac address field for the new ap (a C char * field)
"""

msg_station_trigger_transition = Struct('msg_station_trigger_transition',
                                        Embed(msg_default),  # default fields
                                        Embed(field_station),
                                        Embed(field_mac_addr),  # mac_sta
                                        Embed(field_intf_name),  # intf_name
                                        Embed(field_mac_new_ap),  # mac_new_ap
                                        # Probe()
                                        )
コード例 #20
0
from construct import SLInt32
from construct import Embed, Struct, Container

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_station
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_mtu_qlen = Struct(
    'msg_mtu_qlen',
    Embed(msg_default),  # default fields
    Embed(field_station),
    Embed(field_intf_name),
    SLInt32('value'),
)
""" message structure """


def set_msg_mtu_qlen(server,
                     m_type,
                     m_id=0,
                     sta_ip=None,
                     sta_port=0,
                     intf_name=None,
                     value=None):
    """ sets the MTU or Queue Len values
    @param server: tuple (ip, port_num)
    @param id: message id
    @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
コード例 #21
0
ファイル: sngparser.py プロジェクト: tj-murphy/rs-utils

BEAT = Struct('ebeats', LFloat32('time'), ULInt16('measure'), ULInt16('beat'),
              ULInt32('phraseIteration'), ULInt32('mask'))

PHRASE = Struct('phrases', SLInt8('solo'), SLInt8('disparity'),
                SLInt8('ignore'), Padding(1), ULInt32('maxDifficulty'),
                ULInt32('phraseIterationLinks'),
                String('name', 32, padchar='\x00'))

CHORD_TEMPLATE = Struct('chordTemplates', ULInt32('mask'), SLInt8('fret0'),
                        SLInt8('fret1'), SLInt8('fret2'), SLInt8('fret3'),
                        SLInt8('fret4'), SLInt8('fret5'), SLInt8('finger0'),
                        SLInt8('finger1'), SLInt8('finger2'),
                        SLInt8('finger3'), SLInt8('finger4'),
                        SLInt8('finger5'), Array(6, SLInt32('notes')),
                        String('chordName', 32, padchar='\x00'))

BEND_VALUE = Struct(
    'bendValues',
    LFloat32('time'),
    LFloat32('step'),
    Padding(3),
    # Seens values: 0 1 3 31 32 36..49 51..54 56
    SLInt8('UNK'))

BEND_VALUES_32 = Struct('bendValues32', Array(32, BEND_VALUE),
                        ULInt32('usedCount'))

CHORD_NOTE = Struct(
    'chordNotes',
コード例 #22
0
        m_id=id,
        p_version_length=len(VERSION),
        p_version=VERSION,
        m_size=0,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_tos_cleanall.build,
                         msg_tos_cleanall.parse,
                         only_send=True)


msg_tos = Struct(
    'msg_tos',
    Embed(msg_default),  # default fields
    SLInt32('rule_id'),
    Embed(field_intf_name),
    SLInt32('proto_size'),
    If(lambda ctx: ctx["proto_size"] > 0, CString("proto")),
    SLInt32('sip_size'),
    If(lambda ctx: ctx["sip_size"] > 0, CString("sip")),
    SLInt32('sport_size'),
    If(lambda ctx: ctx["sport_size"] > 0, CString("sport")),
    SLInt32('dip_size'),
    If(lambda ctx: ctx["dip_size"] > 0, CString("dip")),
    SLInt32('dport_size'),
    If(lambda ctx: ctx["dport_size"] > 0, CString("dport")),
    SLInt32('wmm_class'),
    # Probe(),
)
""" message to add or replace mange rules """
コード例 #23
0
@requires: construct 2.5.2
"""

from construct import SLInt32
from construct import Embed, Struct, Container

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_beacon_interval = Struct(
    'msg_beacon_interval',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    SLInt32('beacon_interval'),
)

ERROR = -1


def get_beacon_interval(server, id=0, intf_name=None):
    """
    get beacon interval in miliseconds for the interface intf_name
    @param server: tuple (ip, port_num)
    @param id: message id
    @param intf_name: name of the wireless interface
    @type intf_name: str

    @return: -1 if an error occurs
    """
コード例 #24
0
    def __iter__(self):
        table_definition = self.tables.get_definition(
            self.current_table_number)
        for page_ref in self.pages.list():
            if self.pages[page_ref].hierarchy_level == 0:
                for record in TpsRecordsList(self,
                                             self.pages[page_ref],
                                             encoding=self.encoding,
                                             check=self.check):
                    if record.type == 'DATA' and record.data.table_number == self.current_table_number:
                        check_value('table_record_size', len(record.data.data),
                                    table_definition.record_size)
                        # TODO convert name to string
                        fields = {"b':RecNo'": record.data.record_number}
                        for field in table_definition.record_table_definition_field:
                            field_data = record.data.data[field.
                                                          offset:field.offset +
                                                          field.size]
                            value = ''
                            if field.type == 'BYTE':
                                value = ULInt8('byte').parse(field_data)
                            elif field.type == 'SHORT':
                                value = SLInt16('short').parse(field_data)
                            elif field.type == 'USHORT':
                                value = ULInt16('ushort').parse(field_data)
                            elif field.type == 'DATE':
                                value = self.to_date(field_data)
                            elif field.type == 'TIME':
                                value = self.to_time(field_data)
                            elif field.type == 'LONG':
                                #TODO
                                if field.name.decode(encoding='cp437').split(
                                        ':')[1].lower() in self.date_fieldname:
                                    if SLInt32('long').parse(field_data) == 0:
                                        value = None
                                    else:
                                        value = date.fromordinal(
                                            657433 +
                                            SLInt32('long').parse(field_data))
                                elif field.name.decode(encoding='cp437').split(
                                        ':')[1].lower() in self.time_fieldname:
                                    s, ms = divmod(
                                        SLInt32('long').parse(field_data), 100)
                                    value = str('{}.{:03d}'.format(
                                        time.strftime('%Y-%m-%d %H:%M:%S',
                                                      time.gmtime(s)), ms))
                                else:
                                    value = SLInt32('long').parse(field_data)
                            elif field.type == 'ULONG':
                                value = ULInt32('ulong').parse(field_data)
                            elif field.type == 'FLOAT':
                                value = LFloat32('float').parse(field_data)
                            elif field.type == 'DOUBLE':
                                value = LFloat64('double').parse(field_data)
                            elif field.type == 'DECIMAL':
                                # TODO BCD
                                if field_data[0] & 0xF0 == 0xF0:
                                    sign = -1
                                    field_data = bytearray(field_data)
                                    field_data[0] &= 0x0F
                                else:
                                    sign = 1
                                value = sign * int(hexlify(
                                    field_data)) / 10**field.decimal_count
                            elif field.type == 'STRING':
                                value = text_type(
                                    field_data,
                                    encoding=self.encoding).strip()
                            elif field.type == 'CSTRING':
                                value = text_type(
                                    field_data,
                                    encoding=self.encoding).strip()
                            elif field.type == 'PSTRING':
                                value = text_type(
                                    field_data[1:field_data[0] + 1],
                                    encoding=self.encoding).strip()
                            else:
                                # GROUP=0x16
                                # raise ValueError
                                #TODO
                                pass

                            fields[text_type(field.name)] = value
                        # print(fields)
                        yield fields
コード例 #25
0
ssid_info = Struct(
    'ssid_info',
    Embed(field_intf_name),
    Embed(field_ssid),
    ULInt32('channel'),
    ULInt32('frequency'),
)
""" information about the configured SSID: wiphy, ESSID, channel, frequency, mode
"""

msg_ap_ssid = Struct(
    'msg_ap_ssid',
    Embed(msg_default),  # default fields
    Embed(field_station),
    SLInt32('num_ssids'),
    Array(lambda ctx: ctx.num_ssids, ssid_info),
)
""" message structure """


def get_ap_ssids(server, id=0, sta_ip=None, sta_port=0, intf_names=[]):
    """ returns the channel and frequency of the ssid for each intf_names
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_names: names of the wireless interface
      @type intf_names: list of str
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int
コード例 #26
0
"""

from construct import SLInt32
from construct import Struct, Embed
from construct import Container

from pox.ethanol.ssl_message.msg_common import MSG_TYPE, MSG_ERROR_TYPE
from pox.ethanol.ssl_message.msg_common import VERSION
from pox.ethanol.ssl_message.msg_common import len_of_string
from pox.ethanol.ssl_message.msg_core import msg_default, decode_default_fields

msg_error = Struct(
    'msg_error',
    Embed(msg_default),  # default fields
    SLInt32(
        'error_type'
    )  # int (32 bits) - little endian --> define the type of error, default UNKNOWN
)


def return_error_msg_struct(m_id, error_type=MSG_ERROR_TYPE.ERROR_UNKNOWN):
    """
      return error message as an array of bytes
      @param id: message id

      @return: msg - received message
    """
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_ERR_TYPE,
        m_id=m_id,
        p_version_length=len_of_string(VERSION),
コード例 #27
0
@requires: construct 2.5.2
"""

from construct import SLInt32, SLInt64, CString, LFloat32
from construct import Embed, If
from construct import Struct, Array
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_station, field_intf_name, field_mac_addr
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

field_time_stamp = Struct('time_stamp',
                          SLInt32('time_stamp_size'),
                          If(lambda ctx: ctx["time_stamp_size"] > 0, CString("time_stamp")),
                          )

stats_field = Struct('stats',
                     Embed(field_mac_addr),
                     Embed(field_intf_name),
                     SLInt32('inactive_time'),  # long
                     SLInt64('rx_bytes'),
                     SLInt64('tx_bytes'),
                     SLInt64('rx_packets'),
                     SLInt64('rx_duration'),
                     SLInt64('tx_packets'),
                     SLInt64('tx_retries'),
                     SLInt64('tx_failed'),
                     SLInt64('beacon_loss'),
コード例 #28
0
from construct import Array
from construct import Struct
from construct import Container
# from construct.debug import Probe

from pox.ethanol.ssl_message.msg_core import msg_default
from pox.ethanol.ssl_message.msg_core import field_intf_name, field_station
from pox.ethanol.ssl_message.msg_common import MSG_TYPE, VERSION
from pox.ethanol.ssl_message.msg_common import send_and_receive_msg, len_of_string

msg_acs = Struct(
    'msg_ap_in_range',
    Embed(msg_default),  # default fields
    Embed(field_intf_name),
    Embed(field_station),
    SLInt32('num_tests'),
    SLInt32('num_chan'),
    Array(lambda ctx: ctx.num_chan, SLInt32('freq')),  # int
    Array(lambda ctx: ctx.num_chan,
          SLInt64('factor')),  # long double == LFloat64 ??
    # Probe(),
)

ACS_SCALE_FACTOR = 1000000000000000000.0


def get_acs(server,
            id=0,
            intf_name=None,
            sta_ip=None,
            sta_port=0,