Esempio n. 1
0
    def __init__(self):
        Receiver.__init__(self)
        ResReceiver.logger.info("ResReceiver Init")

        try:

            myQueId = 0
            if ResReceiver.myQueue is None:
                #IPC_CREAT : create or return key if it is allocated.
                #IPC_CREX  : IPC_CREAT | IPC_EXCL
                #IPC_EXCL  : return -1 if there is already allocated.
                myQueId = int(ConfManager.getInstance().getConfigData(
                    ConfManager.MSGQUEUE_INFO, "RESTIF_S"))
                maxQSize = ConfManager.getInstance().getConfigData(
                    ConfManager.MSGQUEUE_INFO, "MAX_QUEUE_SIZE")

                #ResReceiver.myQueue = sysv_ipc.MessageQueue(myQueId, sysv_ipc.IPC_CREAT, mode=0777, max_message_size = int(maxQSize) )
                ResReceiver.myQueue = sysv_ipc.MessageQueue(
                    myQueId, sysv_ipc.IPC_CREAT)
                self.resReceiver = self
                self.resReceiver.start()

        except Exception as e:
            ResReceiver.logger.error(
                "msgQueue Connection Failed.. RESTIF_S QUEUE_ID[%d] SIZE[%s] %s"
                % (myQueId, maxQSize, e))

        return None
Esempio n. 2
0
    def post(self):

        # [WEB->RESTIF] RECEIVE PROCESS
        content = request.get_json(force=True)
        data = dict()

        for keys in content.keys():
            data[keys] = content[keys]

        # [WEB->RESTIF] RECEIVE LOGGING
        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("[WEB] -> RESTIF")
            self.logger.info("===============================================")
            self.logger.info("REQUEST URL : " + request.url)
            self.logger.info("BODY : " + str(content))
            self.logger.info("===============================================")

        # [RESTIF->APP] MAKE SEND STRUCT
        resMsg = 'temp'
        #resMsg = self.setResMessage(data)

        # [RESTIF->APP] SEND QUEUE MESSAGE(RELAY)
        self.clientId = PLTEManager.getInstance().getClientReqId()

        self.logger.info("Client ID : " + str(self.clientId))

        PLTEManager.getInstance().sendCommand(ApiDefine.NSD_ON_BOARDING, self,
                                              self.clientId, resMsg)

        # WAIT
        self.receiveReqId = -1
        while self.clientId != self.receiveReqId:
            try:
                time.sleep(1)
            except Exception as e:
                self.logger.error(e)

        # [RESTIF->WEB] SEND LOGGING
        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("RESTIF -> [WEB]")
            self.logger.info("===============================================")
            self.logger.info("TID : " + str(self.receiveReqId))
            self.logger.info("RESCODE : " + str(self.rspCode))
            #                self.logger.info("BODY : "  + str(self.body))
            self.logger.info("===============================================")

        # [RESTIF->WEB] SEND RESPONSE

        name = content['name']
        age = content['age']

        return jsonify(name=name, age=age)
Esempio n. 3
0
    def post(self):

        # [WEB->RESTIF] RECEIVE PROCESS
        content = request.get_json(force=True)
        #         data = dict()
        #
        #         for keys in content.keys():
        #             data[keys] = content[keys]

        data = json.dumps(content)

        # [WEB->RESTIF] RECEIVE LOGGING
        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("[WEB] -> RESTIF")
            self.logger.info("===============================================")
            self.logger.info("REQUEST URL : " + request.url)
            self.logger.info("BODY : " + data)
            self.logger.info("===============================================")

        # [RESTIF->APP] MAKE SEND STRUCT
        self.clientId = PLTEManager.getInstance().getClientReqId()
        #resMsg = 'temp'
        reqMsg = self.setReqMessage(data, self.clientId)

        # [RESTIF->APP] SEND QUEUE MESSAGE(RELAY)

        PLTEManager.getInstance().sendCommand(ApiDefine.NSD_ON_BOARDING, self,
                                              reqMsg)

        # WAIT
        self.receiveReqId = -1
        while self.clientId != self.receiveReqId:
            try:
                time.sleep(1)
            except Exception as e:
                self.logger.error(e)

        # [RESTIF->WEB] SEND LOGGING
        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("RESTIF -> [WEB]")
            self.logger.info("===============================================")
            self.logger.info("TID : " + str(self.receiveReqId))
            self.logger.info("RESCODE : " + str(self.rspCode))
            self.logger.info("BODY : " + self.resMsg.jsonBody)
            self.logger.info("===============================================")

        # [RESTIF->WEB] SEND RESPONSE

        return flask.Response(
            self.resMsg.jsonBody,
            # mimetype=content_type,
            status=self.rspCode)
Esempio n. 4
0
    def __init__(self):
        self.logger.debug('PLTEConnector Init')
        Connector.__init__(self, PLTEManager.getInstance())

        self.plteQueId = int(ConfManager.getInstance().getConfigData(
            ConfManager.MSGQUEUE_INFO, "PLTEIB"))
        try:
            maxQSize = ConfManager.getInstance().getConfigData(
                ConfManager.MSGQUEUE_INFO, "MAX_QUEUE_SIZE")
            self.plteQueue = sysv_ipc.MessageQueue(
                self.plteQueId, max_message_size=int(maxQSize))

        except Exception as e:
            self.logger.error(
                "msgQueue Connection Failed.. PLTE QUEUE_ID[%d] SIZE[%s]" %
                (self.plteQueId, maxQSize))
Esempio n. 5
0
    def readMessage(self):
        try:

            if ResReceiver.myQueue is None:
                self.logger.error("msgQueue[MYQUEUE] Get Failed...")
                return

            #GenQMsg = GeneralQResMsg()
            resMsg = HttpRes()

            (message,
             msgType) = ResReceiver.myQueue.receive(ctypes.sizeof(resMsg))
            mydata = ctypes.create_string_buffer(message)

            self.logger.info("MSG RECEIVE..")

            if msgType == MTYPE_SLEE_TO_NBRESTIF_RES:

                # Server Mode( Handling Response Message )
                ctypes.memmove(ctypes.pointer(resMsg), mydata,
                               ctypes.sizeof(resMsg))

                #resMsg = GenQMsg.body
                headerMsg = resMsg.http_hdr

                # Receive Message Logging
                if ConfManager.getInstance().getLogFlag():
                    self.logger.info(
                        "===============================================")
                    self.logger.info("SLEE -> NBRESTIF")
                    self.logger.info(
                        "===============================================")
                    self.logger.info("QmsgType: %d" % msgType)
                    self.logger.info("tot_len : %s" % resMsg.tot_len)
                    self.logger.info("tid : %d" % resMsg.tid)
                    self.logger.info("msgId : %d" % resMsg.msgId)
                    self.logger.info("ehttp_idx : %d" % resMsg.ehttpf_idx)
                    self.logger.info("srcQid : %d" % resMsg.srcQid)
                    self.logger.info("srcSysId : %c" % resMsg.srcSysId)
                    self.logger.info("nResult : %d" % resMsg.nResult)
                    self.logger.info("jsonBody: %s" % resMsg.jsonBody)
                    self.logger.info(
                        "===============================================")
                    self.logger.info("method: %d" % headerMsg.method)
                    self.logger.info("api_type: %d" % headerMsg.api_type)
                    self.logger.info("op_type: %d" % headerMsg.op_type)
                    self.logger.info("resource_type: %d" %
                                     headerMsg.resource_type)
                    self.logger.info("length: %d" % headerMsg.length)
                    self.logger.info("encoding: %c" % headerMsg.encoding)
                    self.logger.info(
                        "===============================================")

                #if msgType == PLTEMANAGER_TYPE:
                PLTEManager.getInstance().receiveHandling(
                    resMsg.nResult, resMsg.tid, resMsg)

        except Exception as e:
            self.logger.error("Msgrcv Failed..  %s" % e)
            time.sleep(1)
Esempio n. 6
0
 def RecvLogging(logger, data, reqAPI):
     if ConfManager.getInstance().getLogFlag():
         logger.info("===============================================")
         logger.info("[WEB] -> RESTIF")
         logger.info("===============================================")
         logger.info("REQUEST URL : " + reqAPI.url)
         logger.info("BODY : " + data)
         logger.info("===============================================")
Esempio n. 7
0
 def SendLogging(logger, resMsg):
     if ConfManager.getInstance().getLogFlag():
         logger.info("===============================================")
         logger.info("RESTIF -> [WEB]")
         logger.info("===============================================")
         logger.info("TID : " + str(resMsg.tid))
         logger.info("RESCODE : " + str(resMsg.nResult))
         logger.info("BODY : " + str(resMsg.jsonBody))
         logger.info("===============================================")
Esempio n. 8
0
    def sendMessage(self, apiName, httpReqMsg):

        self.logger.info("Send Message..!")

        #GenQMsg = GeneralQReqMsg()
        #GenQMsg.body = httpReqMsg

        pData = ctypes.cast(
            ctypes.byref(httpReqMsg),
            ctypes.POINTER(ctypes.c_char * ctypes.sizeof(httpReqMsg)))

        try:
            if self.plteQueue is not None:

                if httpReqMsg.http_hdr.resource_type == ResourceType.NSLCM_NOTIFICATION_ENDPOINT:
                    self.plteQueue.send(pData.contents.raw, True,
                                        MTYPE_SBRESTIF_TO_SLEE_REQ)
                else:
                    self.plteQueue.send(pData.contents.raw, True,
                                        MTYPE_NBRESTIF_TO_SLEE_REQ)

        except Exception as e:
            self.logger.error("sendMessage Error! %s" % e)
            return False

        info = httpReqMsg.info
        header = httpReqMsg.http_hdr

        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("NBRESTIF -> SLEE")
            self.logger.info("===============================================")
            self.logger.info("API_NAME : " + str(apiName))
            self.logger.info("mType : " + str(MTYPE_NBRESTIF_TO_SLEE_REQ))
            self.logger.info("totlen  : " + str(httpReqMsg.tot_len))
            self.logger.info("msgId   : " + str(httpReqMsg.msgId))
            self.logger.info("ehttp_idex   : " + str(httpReqMsg.ehttpf_idx))
            self.logger.info("tid   : " + str(httpReqMsg.tid))
            self.logger.info("srcQid  : " + str(httpReqMsg.srcQid))
            self.logger.info("srcSysId: " + str(httpReqMsg.srcSysId))
            self.logger.info("HEADER----------------------------------------")
            self.logger.info("header.method   : " + str(header.method))
            self.logger.info("header.api_type : " + str(header.api_type))
            self.logger.info("header.op_type  : " + str(header.op_type))
            self.logger.info("header.resource_type : " +
                             str(header.resource_type))
            self.logger.info("header.length : " + str(header.length))
            self.logger.info("header.encoding : " + str(header.encoding))
            self.logger.info("INFO ----------------------------------------")
            self.logger.info("info.ns_instance_id : " +
                             str(info.ns_instance_id))
            self.logger.info("info.nfvo_ip : " + str(info.nfvo_ip))
            self.logger.info("info.nfvo_port : " + str(info.nfvo_port))
            self.logger.info("===============================================")

        return True
Esempio n. 9
0
    def __init__(self):
        self.logger.debug('PLTEConnector Init')
        Connector.__init__(self, PLTEManager.getInstance())

        self.plteQueId = int(ConfManager.getInstance().getConfigData(
            ConfManager.MSGQUEUE_INFO, "PLTEIB"))
        self.myQueue = Connector.getMyQueue()
        try:
            self.plteQueue = sysv_ipc.MessageQueue(self.plteQueId)
        except Exception as e:
            self.logger.error(
                "msgQueue Connection Failed.. PLTE QUEUE_ID[%d]" %
                self.plteQueId)
Esempio n. 10
0
    def readMessage(self):
        try:
            resMsg = HttpRes()

            if self.myQueue is None:
                self.myQueue = Connector.getMyQueue()

                if self.myQueue is None:
                    self.logger.error("msgQueue[MYQUEUE] Get Failed...")
                    return

            (message, msgType) = self.myQueue.receive(ctypes.sizeof(resMsg))

            mydata = ctypes.create_string_buffer(message)
            ctypes.memmove(ctypes.pointer(resMsg), mydata,
                           ctypes.sizeof(resMsg))

            time.sleep(1)

            headerMsg = resMsg.http_hdr

            # Receive Message Logging
            if ConfManager.getInstance().getLogFlag():
                self.logger.info(
                    "===============================================")
                self.logger.info("PLTEIB -> RESTIF")
                self.logger.info(
                    "===============================================")
                self.logger.info("msgType: %d" % msgType)
                self.logger.info("tot_len : %s" % resMsg.tot_len)
                self.logger.info("msgId : %d" % resMsg.msgId)
                self.logger.info("ehttp_idx : %d" % resMsg.ehttpf_idx)
                self.logger.info("srcQid : %d" % resMsg.srcQid)
                self.logger.info("srcSysId : %c" % resMsg.srcSysId)
                self.logger.info("nResult : %d" % resMsg.nResult)
                self.logger.info("jsonBody: %s" % resMsg.jsonBody)
                self.logger.info(
                    "===============================================")
                self.logger.info("method: %d" % headerMsg.method)
                self.logger.info("api_type: %d" % headerMsg.api_type)
                self.logger.info("op_type: %d" % headerMsg.op_type)
                self.logger.info("length: %d" % headerMsg.length)
                self.logger.info("encoding: %c" % headerMsg.encoding)

            self.manager.receiveHandling(resMsg.nResult, resMsg.msgId,
                                         resMsg.jsonBody)

        except Exception as e:
            self.logger.error("Msgrcv Failed..  %s" % e)
            time.sleep(1)
Esempio n. 11
0
    def sendResMessage(self, apiName, resMsg):

        #GenQMsg = GeneralQResMsg()
        #GenQMsg.body = resMsg

        pData = ctypes.cast(
            ctypes.byref(resMsg),
            ctypes.POINTER(ctypes.c_char * ctypes.sizeof(resMsg)))
        try:
            if self.plteQueue is not None:

                # MSG TYPE Check!
                self.plteQueue.send(pData.contents.raw, True,
                                    MTYPE_SBRESTIF_TO_SLEE_RES)

        except Exception as e:
            self.logger.error("sendMessage Error! %s" % e)
            return False

        header = resMsg.http_hdr

        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("SBRESTIF -> SLEE")
            self.logger.info("===============================================")
            self.logger.info("API_NAME : " + str(apiName))
            self.logger.info("mType : " + str(MTYPE_SBRESTIF_TO_SLEE_RES))
            self.logger.info("totlen  : " + str(resMsg.tot_len))
            self.logger.info("msgId   : " + str(resMsg.msgId))
            self.logger.info("ehttp_idex   : " + str(resMsg.ehttpf_idx))
            self.logger.info("tid   : " + str(resMsg.tid))
            self.logger.info("srcQid  : " + str(resMsg.srcQid))
            self.logger.info("srcSysId: " + str(resMsg.srcSysId))
            self.logger.info("RESTCODE : " + str(resMsg.nResult))
            self.logger.info("BODY   : " + resMsg.jsonBody)
            self.logger.info("HEADER----------------------------------------")
            self.logger.info("header.method   : " + str(header.method))
            self.logger.info("header.api_type : " + str(header.api_type))
            self.logger.info("header.op_type  : " + str(header.op_type))
            self.logger.info("header.resource_type : " +
                             str(header.resource_type))
            self.logger.info("header.length : " + str(header.length))
            self.logger.info("header.encoding : " + str(header.encoding))
            self.logger.info("===============================================")

        return True
Esempio n. 12
0
    def sendMessage(self, apiName, reqId, receiveMsg):

        httpMsg = HttpReq()
        header = HttpHeader()

        header.method = 1
        header.api_type = 2
        header.op_type = 3
        header.length = 4
        header.encoding = '5'

        httpMsg.tot_len = 100
        httpMsg.msgId = reqId
        httpMsg.ehttpf_idx = 71
        httpMsg.srcQid = 300
        httpMsg.srcSysId = '1'
        httpMsg.http_hdr = header
        httpMsg.jsonBody = receiveMsg

        pData = ctypes.cast(
            ctypes.byref(httpMsg),
            ctypes.POINTER(ctypes.c_char * ctypes.sizeof(httpMsg)))

        try:
            if self.plteQueue is not None:
                self.plteQueue.send(pData.contents.raw, True,
                                    HttpReq.MTYPE_RESTIF_TO_APP_REQ)

        except Exception as e:
            self.logger.error("sendMessage Error! %s" % e)
            return False

        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("RESTIF -> PLTEIB")
            self.logger.info("===============================================")
            self.logger.info("API_NAME : " + str(apiName))
            self.logger.info("PID   : " + str(reqId))
            self.logger.info("BODY   : " + str(receiveMsg))
            self.logger.info("===============================================")

        return True
Esempio n. 13
0
    def getMyQueue():

        try:
            myQueId = 0
            if Connector.myQueue is None:
                #IPC_CREAT : create or return key if it is allocated.
                #IPC_CREX  : IPC_CREAT | IPC_EXCL
                #IPC_EXCL  : return -1 if there is already allocated.
                myQueId = int(ConfManager.getInstance().getConfigData(
                    ConfManager.MSGQUEUE_INFO, "RESTIF"))
                myQueue = sysv_ipc.MessageQueue(myQueId,
                                                sysv_ipc.IPC_CREAT,
                                                mode=0777)

            return myQueue
        except Exception as e:
            Connector.logger.error(
                "msgQueue Connection Failed.. RESTIF QUEUE_ID[%d] %s" %
                (myQueId, e))

        return None
Esempio n. 14
0
    def readMessage(self):
        try:
            
            if ReqReceiver.myQueue is None:
                self.logger.error("msgQueue[RESTIF_RECV] Get Failed...")
                return
            
            #GenQMsg = GeneralQReqMsg()
            reqMsg = HttpReq()
        
            (message, msgType) = ReqReceiver.myQueue.receive(ctypes.sizeof(reqMsg))
            mydata = ctypes.create_string_buffer( message )
            
            #reqMsg = GenQMsg.body
            self.logger.error("ReqReceiver Queue Read Message ..")

            if msgType == MTYPE_SLEE_TO_SBRESTIF_REQ:    
                # Client Mode ( Handling Request Message )
                
                ctypes.memmove(ctypes.pointer(reqMsg), mydata ,ctypes.sizeof(reqMsg))
                            
                # Receive Message Logging
                if ConfManager.getInstance().getLogFlag():
                    headerMsg = reqMsg.http_hdr      
                    info = reqMsg.info
                                  
                    self.logger.info("===============================================")
                    self.logger.info("SLEE -> SBRESTIF")
                    self.logger.info("===============================================")
                    self.logger.info("msgType: %d" %msgType )
                    self.logger.info("tot_len : %s" %reqMsg.tot_len )
                    self.logger.info("msgId : %d" %reqMsg.msgId )
                    self.logger.info("tid : %d" %reqMsg.tid )
                    self.logger.info("ehttp_idx : %d" %reqMsg.ehttpf_idx )
                    self.logger.info("srcQid : %d" %reqMsg.srcQid )
                    self.logger.info("srcSysId : %c" %reqMsg.srcSysId )
                    self.logger.info("jsonBody: %s" %reqMsg.jsonBody )
                    self.logger.info("HEADER-----------------------------------------")
                    self.logger.info("method: %d" %headerMsg.method )
                    self.logger.info("api_type: %d" %headerMsg.api_type )
                    self.logger.info("op_type: %d" %headerMsg.op_type )
                    self.logger.info("resource_type: %d" %headerMsg.resource_type )
                    self.logger.info("length: %d" %headerMsg.length )
                    self.logger.info("encoding: %c" %headerMsg.encoding )
                    self.logger.info("INFO  -----------------------------------------")
                    self.logger.info("NFVO_IP: %s" %info.nfvo_ip )
                    self.logger.info("NFVO_PORT: %d" %info.nfvo_port )                   
                    self.logger.info("===============================================")

                
                if headerMsg.resource_type == ResourceType.NSLCM_NS_INSTANCES:
                    clientReq = C_NsCreation(reqMsg)
                elif headerMsg.resource_type == ResourceType.NSLCM_INSTANTIATE_NS_TASK:
                    clientReq = C_NsIntantication(reqMsg)
                                        
                clientReq.start()


                return 
        
        except Exception as e :
            self.logger.error("Msgrcv Failed..  %s" %e)
            time.sleep(1)
Esempio n. 15
0
    def run(self):
                
                        
        info   = self.reqMsg.info        
        ip = info.nfvo_ip
        port = info.nfvo_port
                
        #url='http://localhost:5555/departments/abc/123'
        url="http://"+str(ip)+":"+str(port)+"/e2e/nslcm/v1/ns_instances"
        #head = {'Content-type':'application/json', 'Accept':'application/json'} 
        #head = {'Content-type':'application/json'} 
        head = {'Content-type':'application/x-www-form-urlencoded', 'Accept':'application/json'} 

        # 1. [RESTIF->EXT] INPUT REQUSET MESSAGE ( httpReq -> REST API )
    
        payload = self.reqMsg.jsonBody
        
        # 2. [RESTIF->EXT] CLIENT SEND LOGGING        
        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================");
            self.logger.info("RESTIF -> [EXT]")
            self.logger.info("===============================================");
            self.logger.info("URL : " + url)
            self.logger.info("HEADER : " + str(head))
            self.logger.info("TID : " + str(self.reqMsg.tid)) # TID
            self.logger.info("BODY : "  + str(payload))
            self.logger.info("===============================================");
            
            
        # 3. [RESTIF->EXT] SEND DATA
        try:
            # payld = json.dumps(payload)
            #restAPI = requests.post(url,headers=head,data=payld)
            restAPI = requests.post(url,headers=head,data=payload)
            
        # 4. [EXT->RESTIF] RECEIVE LOGGING        
            if ConfManager.getInstance().getLogFlag():
                self.logger.info("===============================================");
                self.logger.info("[EXT] -> RESTIF")
                self.logger.info("===============================================");
                self.logger.info("URL : " + str(restAPI.url))
                self.logger.info("TID : " + str(self.reqMsg.tid)) # TID
                self.logger.info("RESULT : " + str(restAPI.status_code))
                self.logger.info("HEADER : "  + str(restAPI.headers))                   # resData.headers['Content-Length']
                self.logger.info("BODY : "  + str(restAPI.text))
                self.logger.info("===============================================");
            
        except Exception as e:
            # Error Exception -> if External Server is not connected..
            self.logger.info(e)
            return 
            
            
        # 5. [RESTIF->APP] INPUT RESPONSE MESSAGE ( REST API -> httpRes )
        resMsg = HttpRes()

        try:    
            resMsg.msgId = self.reqMsg.msgId
            resMsg.tid = self.reqMsg.tid
            resMsg.ehttpf_idx = self.reqMsg.ehttpf_idx
            resMsg.srcQid = self.reqMsg.srcQid
            resMsg.srcSysId = self.reqMsg.srcSysId
            resMsg.nResult = restAPI.status_code
            resMsg.jsonBody = restAPI.text
            
            resMsg.http_hdr = copy.deepcopy(self.reqMsg.http_hdr)
            resMsg.http_hdr.length = len(resMsg.jsonBody)
            resMsg.tot_len = ctypes.sizeof(HttpRes) - HTTPF_MSG_BUFSIZE + resMsg.http_hdr.length
                    
        except Exception as e :
            resMsg.nResult = 400 
            resMsg.jsonBody = "{Internal Server Error}"
            self.logger.info(e)

            # 6. [RESTIF->APP] SEND AND LOGGING
        PLTEManager.getInstance().sendResCommand( ApiDefine.NS_ID_CREATE , resMsg )