示例#1
0
def asumilation():
    Logger().do().info(
        str(paras.RETRY_OPEN) + ' ' + str(paras.NODE_NUMBER) + ' ' +
        str(paras.REQ_EXP_VALUE))
    t1 = threading.Thread(target=start_server, name='ServerThread')
    t1.start()
    time.sleep(1)
    t2 = threading.Thread(target=start_node_manaager, name='NodeManagerThread')
    t2.start()
    time.sleep(paras.SIMULATOR_TIME + 10)
    Logger().do().info('req :' + str(Node.count_all_req) + ' taken: ' +
                       str(Node.count_all_taken))
    Node.count_all_taken = 0
    Node.count_all_req = 0
示例#2
0
 def simulate_time_out(self):
     #停止所有计时器
     self.isRunning = False
     self.timer_req.cancel()
     self.timer_req_timeout.cancel()
     if self.client_socket is not None:
         self.client_socket.send('exit')
         self.client_socket.close()
         self.client_socket = None
     # 回写数据
     # Logger().do().info('data')
     Logger().do().info(
         str(self.name) + ' ' + str(self.count_req_number) + ' ' +
         str(self.count_taken_number))
     Logger().do().info(
         str(self.count_req_period_list) + ' ' + str(self.name))
     Node.count_all_req += self.count_req_number
     Node.count_all_taken += self.count_taken_number
示例#3
0
    def fun_taken_time_timeout(self):

        if cmp(self.state, "state_taken") == 0:
            self.action_ptt_up()
            if self.client_socket is not None and self.isRunning == True:

                Logger().do().info('send ' + str(self.name) + " " +
                                   str(signal.FLOOR_RELEASE))
                self.client_socket.send(str(signal.FLOOR_RELEASE))
示例#4
0
 def action_ptt_down(self):
     # 如果是系统是空闲状态,就进入按下ptt流程
     if self.isRunning is False:
         return
     if cmp(self.state, "state_idle") == 0:
         Logger().do().info('send ' + str(self.name) + " " +
                            str(signal.FLOOR_REQUEST))
         if self.client_socket is not None:
             self.client_socket.send(str(signal.FLOOR_REQUEST))
             self.function_ptt_down()
示例#5
0
    def get_retreat_time(self):

        win = math.pow(2, self.count_retreat) > data.cw[0.02][
            paras.NODE_NUMBER] and math.pow(
                2, self.count_retreat) or data.cw[0.02][paras.NODE_NUMBER]
        if paras.BACKOFF_METHOD == 0:
            win = math.pow(2, self.count_retreat)
        tmp = paras.NETWORK_DELAY * random.uniform(0, win)
        Logger().do().info('retreat ' + str(self.name) + ' ' +
                           str(self.count_retreat) + ' ' + str(tmp))
        return tmp
示例#6
0
def recv_signal():
    start_time = time.time()
    server_socket = socket.socket(socket.AF_INET,
                                  socket.SOCK_STREAM)  # 定义socket类型,网络通信,TCP
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    addr = (final.HOST, final.SERVER_PORT)
    server_socket.bind(addr)
    server_socket.listen(100)
    # 仅在仿真的前半程允许连接
    Logger().do().info('start server thread')

    try:
        for i in range(paras.NODE_NUMBER):

            sock, addr = server_socket.accept()
            socket_list[sock] = 1
            # 创建新线程来处理TCP连接:
            t = threading.Thread(target=tcplink,
                                 args=(sock, ),
                                 name='server_thread_' + str(i))
            t.start()
    except:
        server_socket = None
示例#7
0
import Md5Utils
import FlowHandler
import datetime
import rabbitMQ_produce as rabbitmq
import VoiceApi as voice_api
import RedisHandler as redis
from freeswitch import *
from LogUtils import Logger
import WebAPI as xunfei_asr
from pydub import AudioSegment

reload(voice_api)
reload(xunfei_asr)
reload(redis)

logger = Logger()

def hangup_hook(session, what):
    number = session.getVariable(b"caller_id_number")
    consoleLog("info", "hangup hook for %s!! \n\n" % number)
    return

def input_callback(session, what, obj):
    if (what == "dtmf"):
        consoleLog("info", what + " " + obj.digit + "\n")
    else:
        consoleLog("info", what + " " + obj.serialize() + "\n")
    return "pause"

class IVRBase(object):
    def __init__(self,session, args):
示例#8
0
def main():
    Logger().do().info('start node manager')
    for i in range(paras.NODE_NUMBER):
        t = threading.Thread(target=startNodethread, name='LoopThread' + str(i), args=(i,))
        t.start()
示例#9
0
    def parse_signal(self, data):
        # Logger().do().info('recv '+data)
        if (data) == signal.FLOOR_REQUEST:
            # 收到别人的请求
            if cmp(self.state, "state_idle") == 0:

                self.function_recv_req()
            elif cmp(self.state, "state_pending_req") == 0:
                #发送deny
                if self.client_socket is not None:
                    self.client_socket.send(str(signal.FLOOR_DENY))
                else:
                    pass

            elif cmp(self.state, "state_taken") == 0:
                # 发送deny
                if self.client_socket is not None:
                    self.client_socket.send(str(signal.FLOOR_DENY))
            elif cmp(self.state, "state_granted") == 0:
                if self.client_socket is not None:

                    self.client_socket.send(str(signal.FLOOR_DENY))
            elif cmp(self.state, "state_pend_req") == 0:
                pass
        if (data) == signal.FLOOR_TAKEN:

            # 收到taken,别人占有发言权
            if cmp(self.state, "state_idle") == 0:
                self.function_recv_taken()
            elif cmp(self.state, "state_pending_req") == 0:
                self.function_request_timeout()
            elif cmp(self.state, "state_taken") == 0:
                # todo error
                pass
            elif cmp(self.state, "state_granted") == 0:
                # todo error
                pass
            elif cmp(self.state, "state_pend_req") == 0:
                self.function_recv_taken()

        if (data) == signal.FLOOR_DENY:
            if cmp(self.state, "state_idle") == 0:
                pass
            elif cmp(self.state, "state_pending_req") == 0:
                if paras.RETRY_OPEN is True:
                    self.count_retreat += 1

                # 发送release
                Logger().do().info('sendddd floor release')
                self.client_socket.send(signal.FLOOR_RELEASE)
                self.function_recv_deny()

            elif cmp(self.state, "state_taken") == 0:
                pass
            elif cmp(self.state, "state_granted") == 0:
                pass
            elif cmp(self.state, "state_pend_req") == 0:
                self.function_recv_deny()
        if (data) == signal.FLOOR_RELEASE:
            if cmp(self.state, "state_idle") == 0:
                pass
            elif cmp(self.state, "state_pending_req") == 0:
                # 执行退避算法
                pass
            elif cmp(self.state, "state_granted") == 0:
                self.function_recv_release()
            elif cmp(self.state, "state_pend_req") == 0:
                #回到idle
                self.function_recv_release()
示例#10
0
    def fun_pending_req_timeout(self):

        if cmp(self.state, "state_pending_req") == 0:
            self.function_request_timeout()
            Logger().do().info('send ' + str(self.name) + " " +
                               str(signal.FLOOR_TAKEN))