Beispiel #1
0
    def Request(self, localAE, remoteAE, mp, pcdl, userspdu=None):
        """Requests an association with a remote AE and waits for association response."""
        self.LocalAE = localAE
        self.RemoteAE = remoteAE
        self.MaxPDULength = mp

        # build association service parameters object
        assrq = A_ASSOCIATE_ServiceParameters()
        assrq.ApplicationContextName = self.ApplicationContextName
        assrq.CallingAETitle = self.LocalAE['AET']
        assrq.CalledAETitle = self.RemoteAE['AET']
        MaxPDULengthPar = MaximumLengthParameters()
        MaxPDULengthPar.MaximumLengthReceived = mp
        if userspdu <> None:
            assrq.UserInformation = [MaxPDULengthPar] + userspdu
        else:
            assrq.UserInformation = [MaxPDULengthPar]
        assrq.CallingPresentationAddress = (self.LocalAE['Address'],
                                            self.LocalAE['Port'])
        assrq.CalledPresentationAddress = (self.RemoteAE['Address'],
                                           self.RemoteAE['Port'])
        assrq.PresentationContextDefinitionList = pcdl
        if DEBUG: print pcdl
        # send A-Associate request
        if DEBUG: print "Sending Association Request ...",
        self.DUL.Send(assrq)
        if DEBUG: print " done"

        # get answer
        if DEBUG: print "Waiting for Association Response ...",

        assrsp = self.DUL.Receive(True)
        if DEBUG: print " done"
        if not assrsp:
            return False
            raise AssociationRefused
        if DEBUG: print assrsp

        if assrsp.Result <> 'Accepted':
            return False
            raise AssociationRefused

        # Get maximum pdu length from answer
        #print assrsp
        try:
            self.MaxPDULength = assrsp.UserInformation[0].MaximumLengthReceived
        except:
            self.MaxPDULength = 16000
        print assrsp.UserInformation[0].MaximumLengthReceived
        # Get accepted presentation contexts
        self.AcceptedPresentationContexts = []
        for cc in assrsp.PresentationContextDefinitionResultList:
            if cc[1] == 0:
                uid = [x[1] for x in pcdl if x[0] == cc[0]][0]
                self.AcceptedPresentationContexts.append(
                    (cc[0], uid, UID(cc[2])))
        return True
Beispiel #2
0
    def Request(self, localAE, remoteAE, mp, pcdl, userspdu=None, timeout=30):
        """Requests an association with a remote AE and waits for association
        response."""
        self.LocalAE = localAE
        self.RemoteAE = remoteAE
        self.MaxPDULength = mp

        # build association service parameters object
        assrq = A_ASSOCIATE_ServiceParameters()
        assrq.ApplicationContextName = self.ApplicationContextName
        assrq.CallingAETitle = self.LocalAE['AET']
        assrq.CalledAETitle = self.RemoteAE['AET']
        MaxPDULengthPar = MaximumLengthParameters()
        MaxPDULengthPar.MaximumLengthReceived = mp
        if userspdu is not None:
            assrq.UserInformation = [MaxPDULengthPar] + userspdu
        else:
            assrq.UserInformation = [MaxPDULengthPar]
        assrq.CallingPresentationAddress = (
            self.LocalAE['Address'], self.LocalAE['Port'])
        assrq.CalledPresentationAddress = (
            self.RemoteAE['Address'], self.RemoteAE['Port'])
        assrq.PresentationContextDefinitionList = pcdl
        logger.debug(pcdl)
        # send A-Associate request
        logger.debug("Sending Association Request")
        self.DUL.Send(assrq)

        # get answer
        logger.debug("Waiting for Association Response")

        assrsp = self.DUL.Receive(True, timeout)
        if not assrsp:
            return False
        logger.debug(assrsp)

        try:
            if assrsp.Result != 'Accepted':
                return False
        except AttributeError:
            return False

        # Get maximum pdu length from answer
        try:
            self.MaxPDULength = assrsp.UserInformation[0].MaximumLengthReceived
        except:
            self.MaxPDULength = 16000

        # Get accepted presentation contexts
        self.AcceptedPresentationContexts = []
        for cc in assrsp.PresentationContextDefinitionResultList:
            if cc[1] == 0:
                uid = [x[1] for x in pcdl if x[0] == cc[0]][0]
                self.AcceptedPresentationContexts.append(
                    (cc[0], uid, UID(cc[2])))
        return True
Beispiel #3
0
    def Request(self, localAE, remoteAE, mp, pcdl, userspdu=None, timeout=30):
        """Requests an association with a remote AE and waits for association
        response."""
        self.LocalAE = localAE
        self.RemoteAE = remoteAE
        self.MaxPDULength = mp

        # build association service parameters object
        assrq = A_ASSOCIATE_ServiceParameters()
        assrq.ApplicationContextName = self.ApplicationContextName
        assrq.CallingAETitle = self.LocalAE['AET']
        assrq.CalledAETitle = self.RemoteAE['AET']
        MaxPDULengthPar = MaximumLengthParameters()
        MaxPDULengthPar.MaximumLengthReceived = mp
        if userspdu is not None:
            assrq.UserInformation = [MaxPDULengthPar] + userspdu
        else:
            assrq.UserInformation = [MaxPDULengthPar]
        assrq.CallingPresentationAddress = (
            self.LocalAE['Address'], self.LocalAE['Port'])
        assrq.CalledPresentationAddress = (
            self.RemoteAE['Address'], self.RemoteAE['Port'])
        assrq.PresentationContextDefinitionList = pcdl
        logger.debug(pcdl)
        # send A-Associate request
        logger.debug("Sending Association Request")
        self.DUL.Send(assrq)

        # get answer
        logger.debug("Waiting for Association Response")

        assrsp = self.DUL.Receive(True, timeout)
        if not assrsp:
            return False
        logger.debug(assrsp)

        try:
            if assrsp.Result != 'Accepted':
                return False
        except AttributeError:
            return False

        # Get maximum pdu length from answer
        try:
            self.MaxPDULength = assrsp.UserInformation[0].MaximumLengthReceived
        except:
            self.MaxPDULength = 16000

        # Get accepted presentation contexts
        self.AcceptedPresentationContexts = []
        for cc in assrsp.PresentationContextDefinitionResultList:
            if cc[1] == 0:
                uid = [x[1] for x in pcdl if x[0] == cc[0]][0]
                self.AcceptedPresentationContexts.append(
                    (cc[0], uid, UID(cc[2])))
        return True
Beispiel #4
0
    def Request(self, localAE, remoteAE, mp, pcdl, userspdu = None):
        """Requests an association with a remote AE and waits for association response."""
        self.LocalAE = localAE
        self.RemoteAE = remoteAE
        self.MaxPDULength = mp

        # build association service parameters object
        assrq = A_ASSOCIATE_ServiceParameters()
        assrq.ApplicationContextName = self.ApplicationContextName
        assrq.CallingAETitle = self.LocalAE['AET']
        assrq.CalledAETitle = self.RemoteAE['AET']
        MaxPDULengthPar = MaximumLengthParameters()
        MaxPDULengthPar.MaximumLengthReceived = mp
        if userspdu <> None:
            assrq.UserInformation = [MaxPDULengthPar]+userspdu
        else:
            assrq.UserInformation = [MaxPDULengthPar]
        assrq.CallingPresentationAddress = (self.LocalAE['Address'],self.LocalAE['Port'])
        assrq.CalledPresentationAddress = (self.RemoteAE['Address'],self.RemoteAE['Port'])
        assrq.PresentationContextDefinitionList = pcdl
        if DEBUG: print pcdl
        # send A-Associate request 
        if DEBUG: print "Sending Association Request ...",
        self.DUL.Send(assrq)
        if DEBUG: print " done"     

        # get answer
        if DEBUG: print "Waiting for Association Response ...",
        
        assrsp = self.DUL.Receive(True)
        if DEBUG: print " done"
        if not assrsp:
            return False
            raise AssociationRefused
        if DEBUG: print assrsp
                 
        if assrsp.Result <> 'Accepted':
            return False
            raise AssociationRefused

        # Get maximum pdu length from answer
        #print assrsp
        try:
            self.MaxPDULength = assrsp.UserInformation[0].MaximumLengthReceived
        except:
            self.MaxPDULength = 16000
        print assrsp.UserInformation[0].MaximumLengthReceived
        # Get accepted presentation contexts
        self.AcceptedPresentationContexts = []
        for cc in assrsp.PresentationContextDefinitionResultList:
            if cc[1] == 0:
                uid = [ x[1] for x in pcdl if x[0] == cc[0] ][0]
                self.AcceptedPresentationContexts.append((cc[0],uid,UID(cc[2])))
        return True