Пример #1
0
 def startPointIntentEvent(self):
     try:
         assert self.deviceA is not None and self.deviceB is not None
         targetIntent = None
         for intent in main.intents:
             if not intent.type == 'INTENT_POINT':
                 continue
             if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
                 targetIntent = intent
                 break
         if targetIntent is None:
             main.log.warn(self.typeString + " - intent does not exist")
             return EventStates().FAIL
         main.log.info("Event recorded: {} {} {} {} {}".format(
             self.typeIndex, self.typeString, self.deviceA.name,
             self.deviceB.name, self.CLIIndex))
         controller = main.controllers[self.CLIIndex - 1]
         with controller.CLILock:
             result = controller.CLI.removeIntent(targetIntent.id,
                                                  purge=True)
         if result is None or result == main.FALSE:
             main.log.warn(self.typeString +
                           " - delete point intent failed")
             return EventStates().FAIL
         with main.variableLock:
             targetIntent.setWithdrawn()
             main.intents.remove(targetIntent)
         return EventStates().PASS
     except Exception:
         main.log.warn("Caught exception, aborting event")
         return EventStates().ABORT
Пример #2
0
 def startHostIntentEvent(self):
     assert self.hostA != None and self.hostB != None
     # Check whether there already exists some intent for the host pair
     # For now we should avoid installing overlapping intents
     for intent in main.intents:
         if not intent.type == 'INTENT_HOST':
             continue
         if intent.hostA == self.hostA and intent.hostB == self.hostB or\
         intent.hostB == self.hostA and intent.hostA == self.hostB:
             main.log.warn(
                 self.typeString +
                 " - find an exiting intent for the host pair, abort installation"
             )
             return EventStates().ABORT
     controller = main.controllers[self.CLIIndex - 1]
     with controller.CLILock:
         id = controller.CLI.addHostIntent(self.hostA.id, self.hostB.id)
     if id == None:
         main.log.warn(self.typeString + " - add host intent failed")
         return EventStates().FAIL
     with main.variableLock:
         newHostIntent = HostIntent(id, self.hostA, self.hostB)
         main.intents.append(newHostIntent)
         # Update host connectivity status
         # TODO: should we check whether hostA and hostB are already correspondents?
         self.hostB.correspondents.append(self.hostA)
         self.hostA.correspondents.append(self.hostB)
     return EventStates().PASS
Пример #3
0
 def startLinkEvent(self):
     assert self.linkA != None and self.linkB != None
     with main.variableLock:
         if self.linkA.isUp() or self.linkB.isUp():
             main.log.warn("Link Up - link already up")
             return EventStates().ABORT
         if self.linkA.isRemoved() or self.linkB.isRemoved():
             main.log.warn("Link Up - link has been removed")
             return EventStates().ABORT
     main.log.info("Event recorded: {} {} {} {}".format(
         self.typeIndex, self.typeString, self.linkA.deviceA.name,
         self.linkA.deviceB.name))
     with main.mininetLock:
         '''
         result = main.Mininet1.link( END1=self.linkA.deviceA.name,
                                      END2=self.linkA.deviceB.name,
                                      OPTION="up")
         '''
         result = main.Mininet1.addLink(self.linkA.deviceA.name,
                                        self.linkA.deviceB.name)
     if not result:
         main.log.warn("%s - failed to bring up link" % (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.linkA.bringUp()
         self.linkB.bringUp()
     return EventStates().PASS
Пример #4
0
 def startHostIntentEvent( self ):
     try:
         assert self.hostA != None and self.hostB != None
         # Check whether there already exists some intent for the host pair
         # For now we should avoid installing overlapping intents
         for intent in main.intents:
             if not intent.type == 'INTENT_HOST':
                 continue
             if intent.hostA == self.hostA and intent.hostB == self.hostB or\
             intent.hostB == self.hostA and intent.hostA == self.hostB:
                 main.log.warn( self.typeString + " - find an exiting intent for the host pair, abort installation" )
                 return EventStates().ABORT
         main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.hostA.name, self.hostB.name, self.CLIIndex ) )
         controller = main.controllers[ self.CLIIndex - 1 ]
         with controller.CLILock:
             id = controller.CLI.addHostIntent( self.hostA.id, self.hostB.id )
         if id == None:
             main.log.warn( self.typeString + " - add host intent failed" )
             return EventStates().FAIL
         with main.variableLock:
             newHostIntent = HostIntent( id, self.hostA, self.hostB )
             if self.hostA.isDown() or self.hostA.isRemoved() or self.hostB.isDown() or self.hostB.isRemoved():
                 newHostIntent.setFailed()
             else:
                 newHostIntent.setInstalled()
             main.intents.append( newHostIntent )
         return EventStates().PASS
     except Exception:
         main.log.warn( "Caught exception, aborting event" )
         return EventStates().ABORT
Пример #5
0
 def startPointIntentEvent(self):
     assert self.deviceA != None and self.deviceB != None
     controller = main.controllers[self.CLIIndex - 1]
     # TODO: the following check only work when we use default port number for point intents
     # Check whether there already exists some intent for the device pair
     # For now we should avoid installing overlapping intents
     for intent in main.intents:
         if not intent.type == 'INTENT_POINT':
             continue
         if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
             main.log.warn(
                 self.typeString +
                 " - find an exiting intent for the device pair, abort installation"
             )
             return EventStates().ABORT
     controller = main.controllers[self.CLIIndex - 1]
     with controller.CLILock:
         # TODO: handle the case that multiple hosts attach to one device
         id = controller.CLI.addPointIntent(self.deviceA.dpid,
                                            self.deviceB.dpid, 1, 1, '',
                                            self.deviceA.hosts[0].mac,
                                            self.deviceB.hosts[0].mac)
     if id == None:
         main.log.warn(self.typeString + " - add point intent failed")
         return EventStates().FAIL
     with main.variableLock:
         newPointIntent = PointIntent(id, self.deviceA, self.deviceB)
         main.intents.append(newPointIntent)
         # Update host connectivity status
         for hostA in self.deviceA.hosts:
             for hostB in self.deviceB.hosts:
                 hostA.correspondents.append(hostB)
     return EventStates().PASS
Пример #6
0
 def startLinkEvent(self):
     # TODO: do we need to handle a unidirectional link?
     assert self.linkA != None and self.linkB != None
     with main.variableLock:
         if self.linkA.isDown() or self.linkB.isDown():
             main.log.warn("Link Down - link already down")
             return EventStates().ABORT
         elif self.linkA.isRemoved() or self.linkB.isRemoved():
             main.log.warn("Link Down - link has been removed")
             return EventStates().ABORT
     main.log.info("Event recorded: {} {} {} {}".format(
         self.typeIndex, self.typeString, self.linkA.deviceA.name,
         self.linkA.deviceB.name))
     with main.mininetLock:
         '''
         result = main.Mininet1.link( END1=self.linkA.deviceA.name,
                                      END2=self.linkA.deviceB.name,
                                      OPTION="down")
         '''
         result = main.Mininet1.delLink(self.linkA.deviceA.name,
                                        self.linkA.deviceB.name)
     if not result:
         main.log.warn("%s - failed to bring down link" % (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.linkA.bringDown()
         self.linkB.bringDown()
     return EventStates().PASS
Пример #7
0
 def startDeviceEvent(self):
     assert self.device != None
     with main.variableLock:
         if self.device.isRemoved():
             main.log.warn("Device Down - device has been removed")
             return EventStates().ABORT
     main.log.info("Event recorded: {} {} {}".format(
         self.typeIndex, self.typeString, self.device.name))
     with main.mininetLock:
         result = main.Mininet1.delSwitch(self.device.name)
     if not result:
         main.log.warn("%s - failed to bring down device" %
                       (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.device.setRemoved()
         for link in self.device.outgoingLinks:
             link.setRemoved()
             link.backwardLink.setRemoved()
         for host in self.device.hosts:
             host.setRemoved()
         for intent in main.intents:
             if intent.deviceA == self.device or intent.deviceB == self.device:
                 intent.setFailed()
     return EventStates().PASS
Пример #8
0
 def startPointIntentEvent(self):
     assert self.deviceA != None and self.deviceB != None
     targetIntent = None
     for intent in main.intents:
         if not intent.type == 'INTENT_POINT':
             continue
         if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
             targetIntent = intent
             break
     if targetIntent == None:
         main.log.warn(self.typeString + " - intent does not exist")
         return EventStates().FAIL
     controller = main.controllers[self.CLIIndex - 1]
     with controller.CLILock:
         result = controller.CLI.removeIntent(targetIntent.id, purge=True)
     if result == None or result == main.FALSE:
         main.log.warn(self.typeString + " - delete host intent failed")
         return EventStates().FAIL
     with main.variableLock:
         main.intents.remove(targetIntent)
         # Update host connectivity status
         for hostA in self.deviceA.hosts:
             for hostB in self.deviceB.hosts:
                 hostA.correspondents.remove(hostB)
     return EventStates().PASS
Пример #9
0
    def startEvent(self, eventTuple):
        """
        Start a network/ONOS/application event
        """
        import time

        with self.runningEventsCondition:
            self.runningEvents.append(eventTuple)
        #self.printEvents()
        rerunNum = 0
        result = eventTuple.startEvent()
        while result == EventStates(
        ).FAIL and rerunNum < eventTuple.maxRerunNum:
            time.sleep(eventTuple.rerunInterval)
            rerunNum += 1
            main.log.debug(eventTuple.typeString + ": retry number " +
                           str(rerunNum))
            result = eventTuple.startEvent()
        if result == EventStates().FAIL:
            main.log.error(eventTuple.typeString + " failed")
            main.caseResult = main.FALSE
            if main.params['TEST']['pauseTest'] == 'on':
                #self.isRunning = False
                #main.log.error( "Event Scheduler - Test paused. To resume test, run \'resume-test\' command in CLI debugging mode" )
                main.stop()
        with self.runningEventsCondition:
            self.runningEvents.remove(eventTuple)
            if len(self.runningEvents) == 0:
                self.runningEventsCondition.notify()
                with self.pendingEventsCondition:
                    if len(self.pendingEvents) == 0:
                        with self.idleCondition:
                            self.idleCondition.notify()
Пример #10
0
 def startPortEvent(self):
     assert self.device is not None and self.port is not None and self.link is not None
     if self.link.isUp():
         main.log.warn("port up - link already up")
         return EventStates().ABORT
     elif self.link.isRemoved():
         main.log.warn("port up - link has been removed")
         return EventStates().ABORT
     main.log.info("Event recorded: {} {} {} {}".format(
         self.typeIndex, self.typeString, self.device.name, self.port))
     with main.networkLock:
         result = main.Cluster.active(0).CLI.portstate(
             dpid=self.device.dpid, port=self.port, state="enable")
     if not result:
         main.log.warn("%s - failed to bring up port " % (self.typeString))
         return EventStates().FAIL
     # FIXME: remove this temporary hack for CORD-3240
     if self.link.deviceB.name == 's225':
         main.NetworkBench.switches['s225'].setPortSpeed(
             index=self.link.portB)
     with main.variableLock:
         self.device.downPorts.remove(self.port)
         self.link.bringUp()
         self.link.backwardLink.bringUp()
     return EventStates().PASS
Пример #11
0
 def startCfgEvent(self, args):
     if len(args) < 3:
         main.log.warn("%s - Not enough arguments: %s" %
                       (self.typeString, args))
         return EventStates().ABORT
     elif len(args) > 3:
         main.log.warn("%s - Too many arguments: %s" %
                       (self.typeString, args))
         return EventStates().ABORT
     else:
         self.component = str(args[0])
         self.propName = str(args[1])
         self.value = str(args[2])
     assert self.component != '' and self.propName != '' and self.value != ''
     index = -1
     for controller in main.controllers:
         if controller.isUp():
             index = controller.index
     if index == -1:
         main.log.warn("%s - No available controllers" % s(self.typeString))
         return EventStates().ABORT
     main.log.info("Event recorded: {} {} {} {} {}".format(
         self.typeIndex, self.typeString, self.component, self.propName,
         self.value))
     controller = main.controllers[index - 1]
     with controller.CLILock:
         result = controller.CLI.setCfg(component=self.component,
                                        propName=self.propName,
                                        value=self.value)
     if not result:
         main.log.warn("%s - failed to set configuration" %
                       (self.typeString))
         return EventStates().FAIL
     return EventStates().PASS
Пример #12
0
 def startCfgEvent( self, args ):
     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
     else:
         self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
         self.propName = 'defaultFlowObjectiveCompiler'
         self.value = str( args[ 0 ] )
     index = -1
     for controller in main.controllers:
         if controller.isUp():
             index = controller.index
     if index == -1:
         main.log.warn( "%s - No available controllers" % s( self.typeString ) )
         return EventStates().ABORT
     main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
     controller = main.controllers[ index - 1 ]
     with controller.CLILock:
         result = controller.CLI.setCfg( component=self.component,
                                         propName=self.propName,
                                         value=self.value )
     if not result:
         main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
         return EventStates().FAIL
     return EventStates().PASS
Пример #13
0
 def startONOSEvent(self):
     assert self.ONOSIndex != -1
     with main.variableLock:
         if main.controllers[self.ONOSIndex - 1].isUp():
             main.log.warn("ONOS Up - ONOS already up")
             return EventStates().ABORT
     main.log.info("Event recorded: {} {} {}".format(
         self.typeIndex, self.typeString, self.ONOSIndex))
     with main.ONOSbenchLock:
         startResult = main.ONOSbench.onosStart(
             main.controllers[self.ONOSIndex - 1].ip)
     if not startResult:
         main.log.warn("%s - failed to bring up ONOS" % (self.typeString))
         return EventStates().FAIL
     else:
         ONOSState = main.ONOSbench.isup(main.controllers[self.ONOSIndex -
                                                          1].ip)
         if not ONOSState:
             main.log.warn("%s - ONOS is not up" % (self.typeString))
             return EventStates().FAIL
         else:
             cliResult = main.controllers[self.ONOSIndex - 1].startCLI()
             if not cliResult:
                 main.log.warn("%s - failed to start ONOS cli" %
                               (self.typeString))
                 return EventStates().FAIL
             else:
                 with main.variableLock:
                     main.controllers[self.ONOSIndex - 1].bringUp()
     return EventStates().PASS
Пример #14
0
    def startCheckEvent(self, args=None):
        checkResult = EventStates().PASS
        main.log.info("Starting checking Raft Log size")
        if not main.Cluster.checkPartitionSize():
            checkResult = EventStates().FAIL
            main.log.warn("Raft Log Size Check - Raft log grew too big")

        return checkResult
Пример #15
0
    def startCheckEvent(self, args=None):
        checkResult = EventStates().PASS
        pool = []
        wait = int(main.params['EVENT']['TrafficCheck']['pingWait'])
        timeout = int(main.params['EVENT']['TrafficCheck']['pingTimeout'])
        dstIPv4List = {}
        dstIPv6List = {}
        upHosts = []
        for host in main.hosts:
            if host.isUp():
                upHosts.append(host)
        for host in upHosts:
            dstIPv4List[host.index] = []
            dstIPv6List[host.index] = []
            for correspondent in host.correspondents:
                if correspondent not in upHosts:
                    continue
                for ipAddress in correspondent.ipAddresses:
                    if ipAddress.startswith(
                            str(main.params['TEST']['ipv6Prefix'])):
                        dstIPv6List[host.index].append(ipAddress)
                    elif ipAddress.startswith(
                            str(main.params['TEST']['ipv4Prefix'])):
                        dstIPv4List[host.index].append(ipAddress)
            thread = main.Thread(target=host.handle.pingHostSetAlternative,
                                 threadID=main.threadID,
                                 name="pingHostSetAlternative",
                                 args=[dstIPv4List[host.index], 1])
            pool.append(thread)
            thread.start()
            with main.variableLock:
                main.threadID += 1
        for thread in pool:
            thread.join(10)
            if not thread.result:
                checkResult = EventStates().FAIL
                main.log.warn("Traffic Check - ping failed")

        if not main.enableIPv6:
            return checkResult
        # Check ipv6 ping
        for host in upHosts:
            thread = main.Thread(target=host.handle.pingHostSetAlternative,
                                 threadID=main.threadID,
                                 name="pingHostSetAlternative",
                                 args=[dstIPv6List[host.index], 1, True])
            pool.append(thread)
            thread.start()
            with main.variableLock:
                main.threadID += 1
        for thread in pool:
            thread.join(10)
            if not thread.result:
                checkResult = EventStates().FAIL
                main.log.warn("Traffic Check - ping6 failed")
        return checkResult
Пример #16
0
 def startDeviceEvent(self):
     assert self.device is not None
     with main.variableLock:
         if self.device.isUp():
             main.log.warn("Device Up - device already up")
             return EventStates().ABORT
     # Re-add the device
     main.log.info("Event recorded: {} {} {}".format(
         self.typeIndex, self.typeString, self.device.name))
     if hasattr(main, 'Mininet1'):
         with main.networkLock:
             # result = main.Network.addSwitch( self.device.name, dpid=self.device.dpid[ 3: ] )
             result = main.Network.switch(SW=self.device.name,
                                          OPTION='start')
         if not result:
             main.log.warn("%s - failed to re-add device" %
                           (self.typeString))
             return EventStates().FAIL
     # Re-assign mastership for the device
     with main.networkLock:
         result = main.Network.assignSwController(sw=self.device.name,
                                                  ip=main.Cluster.getIps())
         if not result:
             main.log.warn("%s - failed to assign device to controller" %
                           (self.typeString))
             return EventStates().FAIL
     with main.variableLock:
         self.device.bringUp()
     for link in self.device.outgoingLinks:
         neighbor = link.deviceB
         # Skip bringing up any link that connecting this device to a removed neighbor
         if neighbor.isRemoved():
             continue
         # FIXME: remove this temporary hack for CORD-3240
         if neighbor.name == 's225':
             time.sleep(5)
             main.NetworkBench.switches['s225'].setPortSpeed(
                 index=link.portB)
         # Bring down again any link that was brought down before the device was down
         if int(link.portB) in link.deviceB.downPorts:
             with main.variableLock:
                 link.bringDown()
                 link.backwardLink.bringDown()
         else:
             with main.variableLock:
                 link.bringUp()
                 link.backwardLink.bringUp()
     # Re-discover hosts
     if self.device.hosts:
         main.Network.discoverHosts(
             hostList=[host.name for host in self.device.hosts])
     for host in self.device.hosts:
         with main.variableLock:
             host.bringUp()
     self.device.downPorts = []
     return EventStates().PASS
Пример #17
0
 def startEvent( self, args ):
     with self.eventLock:
         #main.log.info( "%s - starting event" % ( self.typeString ) )
         if self.typeIndex == EventType().APP_INTENT_HOST_ADD or self.typeIndex == EventType().APP_INTENT_HOST_DEL:
             if len( args ) < 3:
                 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
                 return EventStates().ABORT
             elif len( args ) > 3:
                 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
                 return EventStates().ABORT
             try:
                 if args[ 0 ] == 'random' or args[ 1 ] == 'random':
                     if self.typeIndex == EventType().APP_INTENT_HOST_ADD:
                         hostPairRandom = self.getRandomHostPair( connected=False )
                         if hostPairRandom == None:
                             main.log.warn( "All host pairs are connected, aborting event" )
                             return EventStates().ABORT
                         self.hostA = hostPairRandom[ 0 ]
                         self.hostB = hostPairRandom[ 1 ]
                     elif self.typeIndex == EventType().APP_INTENT_HOST_DEL:
                         intent = self.getRandomIntentByType( 'INTENT_HOST' )
                         if intent == None:
                             main.log.warn( "No host intent for deletion, aborting event" )
                             return EventStates().ABORT
                         self.hostA = intent.hostA
                         self.hostB = intent.hostB
                 elif args[ 0 ] == args[ 1 ]:
                     main.log.warn( "%s - invalid argument: %s, %s" % ( self.typeString, args[ 0 ], args[ 1 ] ) )
                     return EventStates().ABORT
                 else:
                     for host in main.hosts:
                         if host.name == args[ 0 ]:
                             self.hostA = host
                         elif host.name == args[ 1 ]:
                             self.hostB = host
                         if self.hostA != None and self.hostB != None:
                             break
                     if self.hostA == None:
                         main.log.warn( "Host %s does not exist: " % ( args[ 0 ] ) )
                         return EventStates().ABORT
                     if self.hostB == None:
                         main.log.warn( "Host %s does not exist: " % ( args[ 1 ] ) )
                         return EventStates().ABORT
                 index = int( args[ 2 ] )
                 if index < 1 or index > int( main.numCtrls ):
                     main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
                     return EventStates().ABORT
                 if not main.controllers[ index - 1 ].isUp():
                     main.log.warn( self.typeString + " - invalid argument: onos %s is down" % ( controller.index ) )
                     return EventStates().ABORT
                 self.CLIIndex = index
                 return self.startHostIntentEvent()
             except Exception:
                 main.log.warn( "Caught exception, aborting event" )
                 return EventStates().ABORT
Пример #18
0
 def startTestEvent( self, args ):
     import time
     result = EventStates().PASS
     if len( args ) < 1:
         main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
         result = EventStates().ABORT
     elif len( args ) > 1:
         main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
         result = EventStates().ABORT
     sleepTime = int( args[ 0 ] )
     time.sleep( sleepTime )
     return result
Пример #19
0
 def startONOSEvent( self ):
     assert self.ONOSIndex != -1
     with main.variableLock:
         if not main.controllers[ self.ONOSIndex - 1 ].isUp():
             main.log.warn( "ONOS Down - ONOS already down" )
             return EventStates().ABORT
     with main.ONOSbenchLock:
         result = main.ONOSbench.onosStop( main.controllers[ self.ONOSIndex - 1 ].ip )
     if not result:
         main.log.warn( "%s - failed to bring down ONOS" % ( self.typeString ) )
         return EventStates().FAIL
     with main.variableLock:
         main.controllers[ self.ONOSIndex - 1 ].bringDown()
     return EventStates().PASS
Пример #20
0
 def startCheckEvent(self, args=None):
     checkResult = EventStates().PASS
     intentDict = {}
     for intent in main.intents:
         intentDict[intent.id] = intent.expectedState
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 intentState = controller.CLI.compareIntent(intentDict)
             if not intentState:
                 main.log.warn(
                     "Intent Check - not all intent ids and states match that on ONOS%s"
                     % (controller.index))
                 checkResult = EventStates().FAIL
     return checkResult
Пример #21
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()
Пример #22
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.networkLock:
                     switchRandom = main.Network.getSwitchRandom(
                         excludeNodes=main.excludeNodes,
                         skipSwitches=main.skipSwitches)
                 if switchRandom is None:
                     main.log.warn("No switch available, aborting event")
                     return EventStates().ABORT
                 args[0] = switchRandom
             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]
         if self.device is None:
             for device in main.devices:
                 if device.name == args[0]:
                     self.device = device
             if self.device is 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()
Пример #23
0
 def startEvent( self, args=None ):
     with self.eventLock:
         main.log.info( "%s - starting event" % ( self.typeString ) )
         index = -1
         for controller in main.controllers:
             if controller.isUp():
                 index = controller.index
         if index == -1:
             main.log.warn( "%s - No available controllers" %s ( self.typeString ) )
             return EventStates().ABORT
         controller = main.controllers[ index - 1 ]
         with controller.CLILock:
             result = controller.CLI.balanceMasters()
         if not result:
             main.log.warn( "%s - failed to balance masters" % ( self.typeString ) )
             return EventStates().FAIL
         return EventStates().PASS
Пример #24
0
 def startPointIntentEvent(self):
     try:
         assert self.deviceA is not None and self.deviceB is not None
         controller = main.controllers[self.CLIIndex - 1]
         # TODO: support multiple hosts under one device
         # Check whether there already exists some intent for the device pair
         # For now we should avoid installing overlapping intents
         for intent in main.intents:
             if not intent.type == 'INTENT_POINT':
                 continue
             if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
                 main.log.warn(
                     self.typeString +
                     " - find an exiting intent for the device pair, abort installation"
                 )
                 return EventStates().ABORT
         main.log.info("Event recorded: {} {} {} {} {}".format(
             self.typeIndex, self.typeString, self.deviceA.name,
             self.deviceB.name, self.CLIIndex))
         controller = main.controllers[self.CLIIndex - 1]
         with controller.CLILock:
             srcMAC = ""
             dstMAC = ""
             if len(self.deviceA.hosts) > 0:
                 srcMAC = self.deviceA.hosts[0].mac
             if len(self.deviceB.hosts) > 0:
                 dstMAC = self.deviceB.hosts[0].mac
             id = controller.CLI.addPointIntent(self.deviceA.dpid,
                                                self.deviceB.dpid, 1, 1, '',
                                                srcMAC, dstMAC)
         if id is None:
             main.log.warn(self.typeString + " - add point intent failed")
             return EventStates().FAIL
         with main.variableLock:
             newPointIntent = PointIntent(id, self.deviceA, self.deviceB)
             if self.deviceA.isDown() or self.deviceB.isDown(
             ) or self.deviceA.isRemoved() or self.deviceB.isRemoved():
                 newPointIntent.setFailed()
             else:
                 newPointIntent.setInstalled()
             main.intents.append(newPointIntent)
         return EventStates().PASS
     except Exception:
         main.log.warn("Caught exception, aborting event")
         return EventStates().ABORT
Пример #25
0
 def startEvent( self, args ):
     with self.eventLock:
         main.log.info( "%s - starting event" % ( self.typeString ) )
         result = EventStates().PASS
         if self.typeIndex == EventType().ONOS_ONOS_DOWN or self.typeIndex == EventType().ONOS_ONOS_UP:
             if len( args ) < 1:
                 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
                 result = EventStates().ABORT
             elif len( args ) > 1:
                 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
                 result = EventStates().ABORT
             else:
                 index = int( args[ 0 ] )
                 if index < 1 or index > int( main.numCtrls ):
                     main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
                     result = EventStates().ABORT
                 else:
                     self.ONOSIndex = index
                     result = self.startONOSEvent()
         return result
Пример #26
0
 def startCheckEvent(self, args=None):
     import json
     checkResult = EventStates().PASS
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 flows = controller.CLI.flows()
                 try:
                     flows = json.loads(flows)
                 except (TypeError, ValueError):
                     main.log.exception(
                         "Flow Check - Object not as expected: {!r}".format(
                             flows))
                     return EventStates().FAIL
                 # Compare flow IDs in ONOS and Mininet
                 flowIDList = []
                 for item in flows:
                     for flow in item["flows"]:
                         flowIDList.append(hex(int(flow['id'])))
                 main.log.info(
                     "Flow Check - current flow number on ONOS%s: %s" %
                     (controller.index, len(flowIDList)))
                 switchList = []
                 for device in main.devices:
                     switchList.append(device.name)
                 with main.mininetLock:
                     flowCompareResult = main.Mininet1.checkFlowId(
                         switchList, flowIDList, debug=False)
                 if not flowCompareResult:
                     main.log.warn(
                         "Flow Check - flows on ONOS%s do not match that in Mininet"
                         % (controller.index))
                     checkResult = EventStates().FAIL
                 # Check flow state
                 flowState = controller.CLI.checkFlowsState(isPENDING=False)
                 if not flowState:
                     main.log.warn(
                         "Flow Check - not all flows are in ADDED state on ONOS%s"
                         % (controller.index))
                     checkResult = EventStates().FAIL
     return checkResult
Пример #27
0
 def startPortEvent(self):
     assert self.device is not None and self.port is not None and self.link is not None
     if self.link.isDown():
         main.log.warn("port Down - link already down")
         return EventStates().ABORT
     elif self.link.isRemoved():
         main.log.warn("port Down - link has been removed")
         return EventStates().ABORT
     main.log.info("Event recorded: {} {} {} {}".format(
         self.typeIndex, self.typeString, self.device.name, self.port))
     with main.networkLock:
         result = main.Cluster.active(0).CLI.portstate(
             dpid=self.device.dpid, port=self.port, state="disable")
     if not result:
         main.log.warn("%s - failed to bring down port" % (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.device.downPorts.append(self.port)
         self.link.bringDown()
         self.link.backwardLink.bringDown()
     return EventStates().PASS
Пример #28
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':
             if self.typeIndex == EventType().NETWORK_LINK_DOWN:
                 with main.mininetLock:
                     linkRandom = main.Mininet1.getLinkRandom()
                 if linkRandom == None:
                     main.log.warn("No link available, aborting event")
                     return EventStates().ABORT
                 args[0] = linkRandom[0]
                 args[1] = linkRandom[1]
             elif self.typeIndex == EventType().NETWORK_LINK_UP:
                 import random
                 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
         if self.linkA == None or self.linkB == None:
             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()
Пример #29
0
 def startCheckEvent( self, args=None ):
     checkResult = EventStates().PASS
     intentDict = {}
     for intent in main.intents:
         intentDict[ intent.id ] = intent.expectedState
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 intentState = controller.CLI.compareIntent( intentDict )
             if not intentState:
                 main.log.warn( "Intent Check - not all intent ids and states match that on ONOS%s" % ( controller.index ) )
                 # FIXME: ONOS leaves intents as WITHDRAWN state occasionally and we don't consider that as a FAIL for now
                 # checkResult = EventStates().FAIL
     return checkResult
Пример #30
0
 def startDeviceEvent(self):
     assert self.device is not None
     with main.variableLock:
         if self.device.isRemoved():
             main.log.warn("Device Down - device has been removed")
             return EventStates().ABORT
     main.log.info("Event recorded: {} {} {}".format(
         self.typeIndex, self.typeString, self.device.name))
     result = main.TRUE
     with main.networkLock:
         # Disable ports toward dual-homed hosts
         for host, port in self.device.hosts.items():
             if host.isDualHomed:
                 main.log.info(
                     "Disable port {}/{} which connects to a dual-homed host before bringing down this device"
                     .format(self.device.dpid, port))
                 result = result and main.Cluster.active(0).CLI.portstate(
                     dpid=self.device.dpid, port=port, state="disable")
         # result = main.Network.delSwitch( self.device.name )
         result = result and main.Network.switch(SW=self.device.name,
                                                 OPTION="stop")
     if not result:
         main.log.warn("%s - failed to bring down device" %
                       (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.device.setRemoved()
         for link in self.device.outgoingLinks:
             link.setRemoved()
             link.backwardLink.setRemoved()
         for host in self.device.hosts:
             host.setRemoved()
         for intent in main.intents:
             if intent.deviceA == self.device or intent.deviceB == self.device:
                 intent.setFailed()
     return EventStates().PASS