Example #1
0
 def startEvent(self, args):
     """
     args are the names of the device, e.g. 's1'
     """
     with self.eventLock:
         main.log.info("%s - starting event" % (self.typeString))
         if len(args) < 1:
             main.log.warn("%s - Not enough arguments: %s" %
                           (self.typeString, args))
             return EventStates().ABORT
         elif len(args) > 1:
             main.log.warn("%s - Too many arguments: %s" %
                           (self.typeString, args))
             return EventStates().ABORT
         if args[0] == 'random':
             import random
             if self.typeIndex == EventType().NETWORK_DEVICE_DOWN:
                 with main.variableLock:
                     graphHelper = GraphHelper()
                     availableDevices = graphHelper.getNonCutVertices()
                     if len(availableDevices) == 0:
                         main.log.warn(
                             "All devices are cut vertices, aborting event")
                         return EventStates().ABORT
                     deviceList = random.sample(availableDevices, 1)
                     self.device = deviceList[0]
             elif self.typeIndex == EventType().NETWORK_DEVICE_UP:
                 with main.variableLock:
                     removedDevices = []
                     for device in main.devices:
                         if device.isRemoved():
                             removedDevices.append(device)
                     if len(removedDevices) == 0:
                         main.log.warn(
                             "None of the devices are removed, aborting event"
                         )
                         return EventStates().ABORT
                     deviceList = random.sample(removedDevices, 1)
                     self.device = deviceList[0]
         else:
             for device in main.devices:
                 if device.name == args[0]:
                     self.device = device
             if self.device == None:
                 main.log.warn("Device %s does not exist: " % (args[0]))
                 return EventStates().ABORT
         main.log.debug("%s - %s" % (self.typeString, self.device))
         return self.startDeviceEvent()
Example #2
0
    def randomDeviceGroupToggle(self,
                                scheduleMethod,
                                args=None,
                                blocking=True):
        """
        The function randomly adds a group of device down-up events into the scheduler
        After each device down or up, all checks are inserted into the scheduler
        param:
            args[0] is the number of devices that are to be brought down
            args[1] is the average interval between device down events
            args[2] is the average interval between device group down and group up events
            blocking means blocking other events from being scheduled between device events
        """
        import random
        import time

        if len(args) < 3:
            main.log.warn(
                "Event Generator - Not enough arguments for randomDeviceGroupToggle: %s"
                % (args))
        elif len(args) > 3:
            main.log.warn(
                "Event Generator - Too many arguments for randomDeviceGroupToggle: %s"
                % (args))
        else:
            deviceGroupSize = int(args[0])
            downDownAvgInterval = int(args[1])
            downUpAvgInterval = int(args[2])
        downDevices = []
        for i in range(0, deviceGroupSize):
            with main.variableLock:
                graphHelper = GraphHelper()
                availableDevices = graphHelper.getNonCutVertices()
                if len(availableDevices) == 0:
                    main.log.warn(
                        "All devices are cut vertices, aborting event")
                    continue
                device = random.sample(availableDevices, 1)
            if i == 0:
                self.eventGeneratorLock.acquire()
            main.eventScheduler.scheduleEvent(EventType().NETWORK_DEVICE_DOWN,
                                              scheduleMethod, [device[0].name])
            with main.variableLock:
                device[0].setPendingDown()
            downDevices.append(device[0])
            sleepTime = int(main.params['EVENT']['randomLinkGroupToggle']
                            ['sleepBeforeCheck'])
            main.eventScheduler.scheduleEvent(EventType().TEST_SLEEP,
                                              EventScheduleMethod().RUN_BLOCK,
                                              [sleepTime])
            self.insertAllChecks(EventScheduleMethod().RUN_NON_BLOCK)
            if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
                # Insert a NULL BLOCK event
                main.eventScheduler.scheduleEvent(
                    EventType().NULL,
                    EventScheduleMethod().RUN_BLOCK)
            downDownInterval = abs(random.gauss(downDownAvgInterval, 1))
            if not blocking:
                self.eventGeneratorLock.release()
                time.sleep(downDownInterval)
                self.eventGeneratorLock.acquire()
            else:
                time.sleep(downDownInterval)

        downUpInterval = abs(random.gauss(downUpAvgInterval, 1))
        if not blocking:
            self.eventGeneratorLock.release()
            time.sleep(downUpInterval)
            self.eventGeneratorLock.acquire()
        else:
            time.sleep(downUpInterval)

        for device in downDevices:
            main.eventScheduler.scheduleEvent(EventType().NETWORK_DEVICE_UP,
                                              scheduleMethod, [device.name])
            main.eventScheduler.scheduleEvent(EventType().TEST_SLEEP,
                                              EventScheduleMethod().RUN_BLOCK,
                                              [sleepTime])
            self.insertAllChecks(EventScheduleMethod().RUN_NON_BLOCK)
            if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
                main.eventScheduler.scheduleEvent(
                    EventType().NULL,
                    EventScheduleMethod().RUN_BLOCK)
            upUpInterval = abs(random.gauss(downDownAvgInterval, 1))
            if not blocking:
                self.eventGeneratorLock.release()
                time.sleep(upUpInterval)
                self.eventGeneratorLock.acquire()
            else:
                time.sleep(upUpInterval)
        self.eventGeneratorLock.release()
Example #3
0
    def randomDeviceToggle(self, scheduleMethod, args=[5], blocking=True):
        """
        The function randomly removes a device and then adds it back
        After each individual device event, all checks are inserted into the scheduler
        param:
            args[0] is the average interval between device down and device up events
            blocking means blocking other events from being scheduled between device down and device up
        """
        import random
        import time

        if len(args) < 1:
            main.log.warn(
                "Event Generator - Not enough arguments for randomDeviceToggle: %s"
                % (args))
        elif len(args) > 1:
            main.log.warn(
                "Event Generator - Too many arguments for randomDeviceToggle: %s"
                % (args))
        else:
            downUpAvgInterval = int(args[0])
        with main.variableLock:
            graphHelper = GraphHelper()
            availableDevices = graphHelper.getNonCutVertices()
            if len(availableDevices) == 0:
                main.log.warn("All devices are Cut vertices, aborting event")
                return
            device = random.sample(availableDevices, 1)

        self.eventGeneratorLock.acquire()
        main.eventScheduler.scheduleEvent(EventType().NETWORK_DEVICE_DOWN,
                                          scheduleMethod, [device[0].name])
        with main.variableLock:
            device[0].setPendingDown()
        sleepTime = int(
            main.params['EVENT']['randomLinkToggle']['sleepBeforeCheck'])
        main.eventScheduler.scheduleEvent(EventType().TEST_SLEEP,
                                          EventScheduleMethod().RUN_BLOCK,
                                          [sleepTime])
        self.insertAllChecks(EventScheduleMethod().RUN_NON_BLOCK)
        if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
            # Insert a NULL BLOCK event
            main.eventScheduler.scheduleEvent(EventType().NULL,
                                              EventScheduleMethod().RUN_BLOCK)
        downUpInterval = abs(random.gauss(downUpAvgInterval, 1))
        if not blocking:
            self.eventGeneratorLock.release()
            time.sleep(downUpInterval)
            self.eventGeneratorLock.acquire()
        else:
            time.sleep(downUpInterval)
        main.eventScheduler.scheduleEvent(EventType().NETWORK_DEVICE_UP,
                                          scheduleMethod, [device[0].name])
        main.eventScheduler.scheduleEvent(EventType().TEST_SLEEP,
                                          EventScheduleMethod().RUN_BLOCK,
                                          [sleepTime])
        self.insertAllChecks(EventScheduleMethod().RUN_NON_BLOCK)
        if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
            main.eventScheduler.scheduleEvent(EventType().NULL,
                                              EventScheduleMethod().RUN_BLOCK)
        self.eventGeneratorLock.release()
Example #4
0
 def startEvent(self, args):
     """
     args are the names of the two link ends, e.g. ['s1', 's2']
     """
     with self.eventLock:
         main.log.info("%s - starting event" % (self.typeString))
         if len(args) < 2:
             main.log.warn("%s - Not enough arguments: %s" %
                           (self.typeString, args))
             return EventStates().ABORT
         elif len(args) > 2:
             main.log.warn("%s - Too many arguments: %s" %
                           (self.typeString, args))
             return EventStates().ABORT
         if args[0] == 'random' or args[1] == 'random':
             import random
             if self.typeIndex == EventType().NETWORK_LINK_DOWN:
                 with main.variableLock:
                     graphHelper = GraphHelper()
                     availableLinks = graphHelper.getNonCutEdges()
                     if len(availableLinks) == 0:
                         main.log.warn(
                             "All links are cut edges, aborting event")
                         return EventStates().ABORT
                     linkList = random.sample(availableLinks, 1)
                     self.linkA = linkList[0]
                     self.linkB = linkList[0].backwardLink
             elif self.typeIndex == EventType().NETWORK_LINK_UP:
                 with main.variableLock:
                     downLinks = []
                     for link in main.links:
                         if link.isDown():
                             downLinks.append(link)
                     if len(downLinks) == 0:
                         main.log.warn(
                             "None of the links are in 'down' state, aborting event"
                         )
                         return EventStates().ABORT
                     linkList = random.sample(downLinks, 1)
                     self.linkA = linkList[0]
                     self.linkB = linkList[0].backwardLink
         elif args[0] == args[1]:
             main.log.warn("%s - invalid arguments: %s" %
                           (self.typeString, args))
             return EventStates().ABORT
         else:
             for link in main.links:
                 if link.deviceA.name == args[
                         0] and link.deviceB.name == args[1]:
                     self.linkA = link
                 elif link.deviceA.name == args[
                         1] and link.deviceB.name == args[0]:
                     self.linkB = link
                 if self.linkA != None and self.linkB != None:
                     break
             if self.linkA == None or self.linkB == None:
                 main.log.warn(
                     "Bidirectional link %s - %s does not exist: " %
                     (args[0], args[1]))
                 return EventStates().ABORT
         main.log.debug("%s - %s" % (self.typeString, self.linkA))
         return self.startLinkEvent()