Example #1
0
    def send_subscription(self,
                          addr,
                          proc_id,
                          objid,
                          confirmed=None,
                          lifetime=None):
        if _debug: logger.debug("send_subscription")

        # build a request
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=proc_id,
            monitoredObjectIdentifier=objid,
        )
        request.pduDestination = Address(addr)

        # optional parameters
        if confirmed is not None:
            request.issueConfirmedNotifications = confirmed
        if lifetime is not None:
            request.lifetime = lifetime

        self._request = request

        # make an IOCB
        iocb = IOCB(request)
        if _debug: logger.debug("    - iocb: %r", iocb)

        # callback when it is acknowledged
        #iocb.add_callback(self.subscription_acknowledged)

        # give it to the application
        self.request_io(iocb)
Example #2
0
    def send_subscription(self, context):
        if _debug: SubscribeCOVApplication._debug("send_subscription %r", context)

        # build a request
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=context.subscriberProcessIdentifier,
            monitoredObjectIdentifier=context.monitoredObjectIdentifier,
            )
        request.pduDestination = context.address

        # optional parameters
        if context.issueConfirmedNotifications is not None:
            request.issueConfirmedNotifications = context.issueConfirmedNotifications
        if context.lifetime is not None:
            request.lifetime = context.lifetime

        # make an IOCB
        iocb = IOCB(request)
        if _debug: SubscribeCOVApplication._debug("    - iocb: %r", iocb)

        # callback when it is acknowledged
        iocb.add_callback(self.subscription_acknowledged)

        # give it to the application
        this_application.request_io(iocb)
Example #3
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug: SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r", issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug: SubscribeCOVConsoleCmd._debug("    - lifetime: %r", lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
                )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug: SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # give it to the application
            this_application.request(request)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
Example #4
0
File: cov.py Project: snuids/BAC0
    def _build_cov_request(self, context):
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=context.subscriberProcessIdentifier,
            monitoredObjectIdentifier=context.monitoredObjectIdentifier,
        )
        request.pduDestination = context.address

        # optional parameters
        if context.issueConfirmedNotifications is not None:
            request.issueConfirmedNotifications = context.issueConfirmedNotifications
        if context.lifetime is not None:
            request.lifetime = context.lifetime

        return request
Example #5
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
            )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - response: %r",
                                                  iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - error: %r",
                                                  iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
Example #6
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_id [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug:
            SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_id = args[:3]
            obj_id = ObjectIdentifier(obj_id).value

            proc_id = int(proc_id)

            if len(args) >= 4:
                issue_confirmed = args[3]
                if issue_confirmed == "-":
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == "true"
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 5:
                lifetime = args[4]
                if lifetime == "-":
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(subscriberProcessIdentifier=proc_id,
                                          monitoredObjectIdentifier=obj_id)
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug:
                SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            deferred(this_application.request_io, iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - response: %r",
                                                  iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - error: %r",
                                                  iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
Example #7
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
            )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # give it to the application
            this_application.request(request)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
Example #8
0
    def run(self):
        while True:
            self.inicio = time.time()
            for ids in Dispositivos:
                for obj in Dispositivos[ids]:
                    addr = Dispositivos[ids]["IPort"]
                    if not obj == "IPort":
                        for args in Dispositivos[ids][obj]:
                            RETRY = 0
                            DONE = False
                            if self.ProcessID > 3000: self.ProcessID = 0
                            while RETRY < SubRetrys and DONE == False:
                                try:
                                    #proc_id = Dispositivos[ids][obj][args]["ProcID"]
                                    proc_id = self.ProcessID
                                    lifetime = (int(TimeToRefreshSubs) + 30)
                                    obj_type, obj_inst = obj.split("_")
                                    issue_confirmed = True
                                    if obj_type.isdigit():
                                        obj_type = int(obj_type)
                                    elif not get_object_class(obj_type):
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                " Error trying to subscribe unknown object type.\n"
                                            )
                                    obj_inst = int(obj_inst)
                                    request = SubscribeCOVRequest(
                                        subscriberProcessIdentifier=proc_id,
                                        monitoredObjectIdentifier=(obj_type,
                                                                   obj_inst),
                                    )
                                    request.pduDestination = Address(addr)
                                    if issue_confirmed is not None:
                                        request.issueConfirmedNotifications = issue_confirmed
                                    if lifetime is not None:
                                        request.lifetime = lifetime
                                    iocb = IOCB(request)
                                    this_application.request_io(iocb)
                                    #print "Trying to subscribe to", ids, addr, obj_type, obj_inst
                                    iocb.wait(TimeToWaitForSub)
                                    state = iocb.ioState
                                    '''
									IDLE = 0        # has not been submitted
									PENDING = 1     # queued, waiting for processing
									ACTIVE = 2      # being processed
									COMPLETED = 3   # finished
									ABORTED = 4 	# finished in a bad way
									'''
                                    if state == 0:
                                        time.sleep(TimeBetweenSubs)
                                        #print "ZZzzzzZZZzzzzZZZzzzzZZZ"
                                    elif state == 1:
                                        #print "Esta na queue, vai limpar e tentar de novo..."
                                        this_application.queue_by_address.clear(
                                        )
                                        time.sleep(TimeBetweenSubs)
                                    elif state == 2:
                                        #print "Esta em processamento..."
                                        self.ProcessID += 1
                                        DONE = True
                                    elif state == 3:
                                        #print "YEIII"
                                        self.ProcessID += 1
                                        DONE = True
                                    elif state == 4:
                                        time.sleep(TimeBetweenSubs)
                                        #print "ABORTTTTTTTT, ja deu merdinha"
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                "ABORTTTTTTTT")
                                    else:
                                        time.sleep(TimeBetweenSubs)
                                        #print "WATTTT YYYY!!!! NUNCA VISTO"
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                "WATTTT YYYY!!!! NUNCA VISTO")
                                except Exception as e:
                                    with open("ErrorLog.txt", "a") as myfile:
                                        myfile.write(
                                            str(
                                                time.strftime(
                                                    "%d-%m-%Y %H:%M:%S")) +
                                            " Error while trying to subscribe, proc_id:"
                                            + str(proc_id) + " Addr:" +
                                            str(addr) + "\n")
                                        myfile.write("Error -> " + str(e) +
                                                     "\n")
                                RETRY += 1
            self.fim = time.time()
            #print "Levou:", self.fim - self.inicio
            #print "Refresh Default:", TimeToRefreshSubs
            #print "Refresh Fixed:" , TimeToRefreshSubs - TimeBetweenSubs - round(self.fim - self.inicio, 1)
            #print Dispositivos
            time.sleep(
                abs(TimeToRefreshSubs - TimeBetweenSubs -
                    round(self.fim - self.inicio, 1)))
Example #9
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]
        """
        args = args.split()
        if _debug: COVConsoleCmd._debug("do_subscribe %r", args)
        global test_application

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            client_addr = Address(addr)
            if _debug: COVConsoleCmd._debug("    - client_addr: %r", client_addr)

            proc_id = int(proc_id)
            if _debug: COVConsoleCmd._debug("    - proc_id: %r", proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)
            obj_id = (obj_type, obj_inst)
            if _debug: COVConsoleCmd._debug("    - obj_id: %r", obj_id)

            obj = test_application.get_object_id(obj_id)
            if not obj:
                print("object not found")
                return

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug: COVConsoleCmd._debug("    - issue_confirmed: %r", issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug: COVConsoleCmd._debug("    - lifetime: %r", lifetime)
            else:
                lifetime = None

            # can a match be found?
            cov = obj._cov_subscriptions.find(client_addr, proc_id, obj_id)
            if _debug: COVConsoleCmd._debug("    - cov: %r", cov)

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=obj_id,
                )

            # spoof that it came from the client
            request.pduSource = client_addr

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug: COVConsoleCmd._debug("    - request: %r", request)

            # give it to the application
            test_application.do_SubscribeCOVRequest(request)

        except Exception as err:
            COVConsoleCmd._exception("exception: %r", err)
Example #10
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug: SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r", issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug: SubscribeCOVConsoleCmd._debug("    - lifetime: %r", lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
                )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug: SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug: SubscribeCOVConsoleCmd._debug("    - response: %r", iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug: SubscribeCOVConsoleCmd._debug("    - error: %r", iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)