Beispiel #1
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.Cluster.numCtrls):
                     main.log.warn("%s - invalid argument: %s" %
                                   (self.typeString, index))
                     result = EventStates().ABORT
                 else:
                     self.ONOSIndex = index
                     result = self.startONOSEvent()
         return result
Beispiel #2
0
 def startHostIntentEvent(self):
     try:
         assert self.hostA is not None and self.hostB is not 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 is 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
Beispiel #3
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
Beispiel #4
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
 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 is 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 is None or self.linkB is 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 is not None and self.linkB is not None:
                     break
             if self.linkA is None or self.linkB is 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()
Beispiel #6
0
 def startCheckEvent( self, args=None ):
     import json
     checkResult = EventStates().PASS
     if main.enableIPv6:
         coreFlowNum = int( main.params[ 'EVENT' ][ 'FlowCheck' ][ 'coreFlowNum6' ] )
     else:
         coreFlowNum = int( main.params[ 'EVENT' ][ 'FlowCheck' ][ 'coreFlowNum' ] )
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 # Check core flow number
                 for device in main.devices:
                     if device.isRemoved():
                         continue
                     coreFlowNumOnos = controller.CLI.flowAddedCount( device.dpid, core=True )
                     if coreFlowNumOnos is None:
                         main.log.warn( "Flow Check - error when trying to get flow number of %s on ONOS%s" % ( device.dpid, controller.index ) )
                         checkResult = EventStates().FAIL
                     else:
                         coreFlowNumOnos = int( coreFlowNumOnos )
                         if coreFlowNumOnos != coreFlowNum:
                             main.log.warn( "Flow Check - core flow number of %s on ONOS%s is %s" % ( device.dpid, controller.index, coreFlowNumOnos ) )
                             checkResult = EventStates().FAIL
                 # Get flows for comparison
                 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
Beispiel #7
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
             else:
                 if args[0] == args[1]:
                     main.log.warn("%s - invalid argument: %s" %
                                   (self.typeString, index))
                     return EventStates().ABORT
                 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()
Beispiel #8
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
     elif args[0] != 'true' and args[0] != 'false':
         main.log.warn("%s - Invalid arguments: %s" %
                       (self.typeString, args))
         return EventStates().ABORT
     else:
         self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
         self.propName = 'useFlowObjectives'
         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
     main.flowObj = True if self.value == 'true' else False
     return EventStates().PASS
Beispiel #9
0
 def startTestEvent(self, args=None):
     result = EventStates().PASS
     main.eventScheduler.setRunningState(True)
     return result
Beispiel #10
0
 def startPointIntentEvent(self):
     return EventStates().PASS
Beispiel #11
0
 def startCheckEvent(self):
     return EventStates().PASS
Beispiel #12
0
 def startTestEvent(self):
     return EventStates().PASS
Beispiel #13
0
 def startCheckEvent(self, args=None):
     import json
     checkResult = EventStates().PASS
     upLinkNum = 0
     upDeviceNum = 0
     upHostNum = 0
     with main.variableLock:
         for link in main.links:
             if not link.isDown() and not link.isRemoved():
                 upLinkNum += 1
         for device in main.devices:
             if not device.isDown() and not device.isRemoved():
                 upDeviceNum += 1
         for host in main.hosts:
             if not host.isDown() and not host.isRemoved():
                 upHostNum += 1
     clusterNum = 1
     with main.mininetLock:
         graphDictMininet = main.Mininet1.getGraphDict(useId=True)
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 topoState = controller.CLI.checkStatus(
                     upDeviceNum, upLinkNum)
                 # if not topoState:
                 #    main.log.warn( "Topo Check - link or device number discoverd by ONOS%s is incorrect" % ( controller.index ) )
                 #    checkResult = EventStates().FAIL
                 # Compare ONOS and Mininet topologies
                 graphDictONOS = controller.CLI.getGraphDict()
                 compareResult = main.graph.compareGraphs(
                     graphDictONOS, graphDictMininet)
                 if not compareResult:
                     checkResult = EventStates().FAIL
                     main.log.warn(
                         "Topo Check - ONOS and Mininet topologies do not match"
                     )
                 try:
                     # Check links
                     links = controller.CLI.links()
                     links = json.loads(links)
                     if not len(links) == upLinkNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - link number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, upLinkNum, len(links)))
                     # Check devices
                     devices = controller.CLI.devices()
                     devices = json.loads(devices)
                     availableDeviceNum = 0
                     for device in devices:
                         if device['available']:
                             availableDeviceNum += 1
                     if not availableDeviceNum == upDeviceNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - device number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, upDeviceNum,
                                availableDeviceNum))
                     # Check hosts
                     hosts = controller.CLI.hosts()
                     hosts = json.loads(hosts)
                     if not len(hosts) == upHostNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - host number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, upHostNum, len(hosts)))
                     # Check clusters
                     clusters = controller.CLI.clusters()
                     clusters = json.loads(clusters)
                     if not len(clusters) == clusterNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - cluster number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             %
                             (controller.index, clusterNum, len(clusters)))
                 except (TypeError, ValueError):
                     main.log.exception(
                         "Flow Check - Object not as expected")
                     return EventStates().FAIL
     return checkResult
Beispiel #14
0
 def startCheckEvent(self, args=None):
     import json
     checkResult = EventStates().PASS
     topics = []
     # TODO: Other topics?
     for i in range(14):
         topics.append("work-partition-" + str(i))
     dpidToAvailability = {}
     dpidToMaster = {}
     for device in main.devices:
         if device.isDown() or device.isRemoved():
             dpidToAvailability[device.dpid] = False
         else:
             dpidToAvailability[device.dpid] = True
         dpidToMaster[device.dpid] = 'unknown'
     # Check mastership, leaders and node states on each controller node
     for controller in main.controllers:
         if controller.isUp():
             # Check mastership
             try:
                 with controller.CLILock:
                     roles = controller.CLI.roles()
                 roles = json.loads(roles)
                 for device in roles:
                     dpid = device['id']
                     if dpidToMaster[dpid] == 'unknown':
                         dpidToMaster[dpid] = device['master']
                     elif dpidToMaster[dpid] != device['master']:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "ONOS Check - Mastership of %s on ONOS%s is inconsistent with that on ONOS1"
                             % (dpid, controller.index))
                     if dpidToAvailability[dpid] and device[
                             'master'] == "none":
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "ONOS Check - Device %s has no master on ONOS%s"
                             % (dpid, controller.index))
                 # Check leaders
                 with controller.CLILock:
                     leaders = controller.CLI.leaders()
                 leaders = json.loads(leaders)
                 ONOSTopics = [j['topic'] for j in leaders]
                 for topic in topics:
                     if topic not in ONOSTopics:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "ONOS Check - Topic %s not in leaders on ONOS%s"
                             % (topic, controller.index))
                 # Check node state
                 with controller.CLILock:
                     nodes = controller.CLI.nodes()
                 nodes = json.loads(nodes)
                 ipToState = {}
                 for node in nodes:
                     ipToState[node['ip']] = node['state']
                 for c in main.controllers:
                     if c.isUp() and ipToState[c.ip] == 'READY':
                         pass
                     elif not c.isUp() and ipToState[c.ip] == 'INACTIVE':
                         pass
                     else:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "ONOS Check - ONOS%s shows wrong node state: ONOS%s is %s but state is %s"
                             % (controller.index, c.index, c.status,
                                ipToState[c.ip]))
                 # TODO: check partitions?
             except (TypeError, ValueError):
                 main.log.exception("ONOS Check - Object not as expected")
                 return EventStates().FAIL
     return checkResult
Beispiel #15
0
 def startDeviceEvent(self):
     assert self.device != None
     with main.variableLock:
         if self.device.isUp():
             main.log.warn("Device Up - device already up")
             return EventStates().ABORT
     # Re-add the device
     with main.mininetLock:
         result = main.Mininet1.addSwitch(self.device.name,
                                          dpid=self.device.dpid[3:])
     if not result:
         main.log.warn("%s - failed to re-add device" % (self.typeString))
         return EventStates().FAIL
     with main.variableLock:
         self.device.bringUp()
     # Re-add links
     # We add host-device links first since we did the same in mininet topology file
     # TODO: a more rubust way is to add links according to the port info of the device
     for host in self.device.hosts:
         # Add host-device link
         with main.mininetLock:
             result = main.Mininet1.addLink(self.device.name, host.name)
         if not result:
             main.log.warn("%s - failed to re-connect host %s to device" %
                           (self.typeString, host.name))
             return EventStates().FAIL
     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
         with main.mininetLock:
             result = main.Mininet1.addLink(self.device.name, neighbor.name)
         if not result:
             main.log.warn("%s - failed to re-add link to %s" %
                           (self.typeString, neighbor.name))
             return EventStates().FAIL
         with main.variableLock:
             link.bringUp()
             link.backwardLink.bringUp()
             for intent in main.intents:
                 if intent.isFailed():
                     if intent.deviceA == self.device and intent.deviceB.isUp() or\
                     intent.deviceB == self.device and intent.deviceA.isUp():
                         intent.setInstalled()
     # Re-assign mastership for the device
     with main.mininetLock:
         main.Mininet1.assignSwController(sw=self.device.name,
                                          ip=main.onosIPs)
     # Re-discover hosts
     for host in self.device.hosts:
         correspondent = None
         for h in main.hosts:
             if h.isUp() and h != host:
                 correspondent = h
                 break
         if correspondent == None:
             with main.mininetLock:
                 main.Mininet1.pingall()
                 if main.enableIPv6:
                     main.Mininet1.pingall(protocol="IPv6")
         else:
             ipv4Addr = None
             ipv6Addr = None
             for ipAddress in correspondent.ipAddresses:
                 if ipAddress.startswith(
                         str(main.params['TEST']
                             ['ipv6Prefix'])) and ipv6Addr == None:
                     ipv6Addr = ipAddress
                 elif ipAddress.startswith(
                         str(main.params['TEST']
                             ['ipv4Prefix'])) and ipv4Addr == None:
                     ipv4Addr = ipAddress
             assert ipv4Addr != None
             host.handle.pingHostSetAlternative([ipv4Addr], 1)
             if main.enableIPv6:
                 assert ipv6Addr != None
                 host.handle.pingHostSetAlternative([ipv6Addr], 1, True)
         with main.variableLock:
             host.bringUp()
     return EventStates().PASS
Beispiel #16
0
 def startCheckEvent(self, args=None):
     import json
     checkResult = EventStates().PASS
     upLinkNum = 0
     upDeviceNum = 0
     upHostList = []
     with main.variableLock:
         for link in main.links:
             if not link.isDown() and not link.isRemoved():
                 upLinkNum += 1
         for device in main.devices:
             if not device.isDown() and not device.isRemoved():
                 upDeviceNum += 1
         for host in main.hosts:
             if not host.isDown() and not host.isRemoved():
                 upHostList.append(host)
     clusterNum = 1
     # Verify host IPs
     if hasattr(main, "expectedHosts"):
         for host in upHostList:
             ipResult = main.Network.verifyHostIp(
                 hostList=[host.name],
                 prefix=main.expectedHosts['network'][host.name],
                 update=False)
             if not ipResult:
                 checkResult = EventStates().FAIL
                 main.log.warn(
                     "Topo Check - Failed to verify IP address on host %s" %
                     (host.name))
     '''
     with main.networkLock:
         graphDictMininet = main.Network.getGraphDict( useId=True,
                                                       excludeNodes=main.excludeNodes )
     '''
     for controller in main.controllers:
         if controller.isUp():
             with controller.CLILock:
                 '''
                 topoState = controller.CLI.checkStatus( upDeviceNum, upLinkNum )
                 if not topoState:
                     main.log.warn( "Topo Check - link or device number discoverd by ONOS%s is incorrect" % ( controller.index ) )
                     checkResult = EventStates().FAIL
                 # Compare ONOS and Mininet topologies
                 graphDictONOS = controller.CLI.getGraphDict()
                 compareResult = main.graph.compareGraphs( graphDictONOS, graphDictMininet )
                 if not compareResult:
                     checkResult = EventStates().FAIL
                     main.log.warn( "Topo Check - ONOS and Mininet topologies do not match" )
                 '''
                 try:
                     # Check links
                     links = controller.CLI.links()
                     links = json.loads(links)
                     if not len(links) == upLinkNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - link number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, upLinkNum, len(links)))
                     # Check devices
                     devices = controller.CLI.devices()
                     devices = json.loads(devices)
                     availableDeviceNum = 0
                     for device in devices:
                         if device['available']:
                             availableDeviceNum += 1
                     if not availableDeviceNum == upDeviceNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - device number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, upDeviceNum,
                                availableDeviceNum))
                     # Check hosts
                     hosts = controller.CLI.hosts()
                     hosts = json.loads(hosts)
                     if hasattr(main, "expectedHosts"):
                         hosts = [
                             host for host in hosts if host['id'] in
                             main.expectedHosts['onos'].keys()
                         ]
                     if not len(hosts) == len(upHostList):
                         # checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - host number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             % (controller.index, len(upHostList),
                                len(hosts)))
                     # Check Host IPs
                     if hasattr(main, "expectedHosts"):
                         for host in upHostList:
                             ipResult = controller.CLI.verifyHostIp(
                                 hostList=[host.id],
                                 prefix=main.expectedHosts['onos'][host.id])
                             if not ipResult:
                                 checkResult = EventStates().FAIL
                                 main.log.warn(
                                     "Topo Check - ONOS%s failed to verify IP address on host %s"
                                     % (controller.index, host.id))
                     # Check clusters
                     clusters = controller.CLI.clusters()
                     clusters = json.loads(clusters)
                     if not len(clusters) == clusterNum:
                         checkResult = EventStates().FAIL
                         main.log.warn(
                             "Topo Check - cluster number discoverd by ONOS%s is incorrect: %s expected and %s actual"
                             %
                             (controller.index, clusterNum, len(clusters)))
                 except (TypeError, ValueError):
                     main.log.exception(
                         "Flow Check - Object not as expected")
                     return EventStates().FAIL
     return checkResult
Beispiel #17
0
 def startLinkEvent(self):
     return EventStates().PASS
Beispiel #18
0
 def startDeviceEvent(self):
     return EventStates().PASS
Beispiel #19
0
 def startPortEvent(self):
     return EventStates().PASS
Beispiel #20
0
 def startEvent(self, args):
     with self.eventLock:
         # main.log.info( "%s - starting event" % ( self.typeString ) )
         if self.typeIndex == EventType(
         ).APP_INTENT_POINT_ADD or self.typeIndex == EventType(
         ).APP_INTENT_POINT_DEL:
             if len(args) < 3:
                 main.log.warn("%s - Not enough arguments: %s" %
                               (self.typeString, args))
                 return EventStates().ABORT
             elif len(args) > 4:
                 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_POINT_ADD:
                         hostPairRandom = self.getRandomHostPair(
                             connected=False)
                         if hostPairRandom is None:
                             main.log.warn(
                                 "All host pairs are connected, aborting event"
                             )
                             return EventStates().ABORT
                         self.deviceA = hostPairRandom[0].device
                         self.deviceB = hostPairRandom[1].device
                     elif self.typeIndex == EventType(
                     ).APP_INTENT_POINT_DEL:
                         intent = self.getRandomIntentByType('INTENT_POINT')
                         if intent is None:
                             main.log.warn(
                                 "No point intent for deletion, aborting event"
                             )
                             return EventStates().ABORT
                         self.deviceA = intent.deviceA
                         self.deviceB = intent.deviceB
                 elif args[0] == args[1]:
                     main.log.warn("%s - invalid argument: %s" %
                                   (self.typeString, args[0], args[1]))
                     return EventStates().ABORT
                 else:
                     for device in main.devices:
                         if device.name == args[0]:
                             self.deviceA = device
                         elif device.name == args[1]:
                             self.deviceB = device
                         if self.deviceA is not None and self.deviceB is not None:
                             break
                     if self.deviceA is None:
                         main.log.warn("Device %s does not exist: " %
                                       (args[0]))
                         return EventStates().ABORT
                     if self.deviceB is None:
                         main.log.warn("Device %s does not exist: " %
                                       (args[1]))
                         return EventStates().ABORT
                 index = int(args[2])
                 if index < 1 or index > int(main.Cluster.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
                 if len(args) == 4 and args[3] == 'bidirectional':
                     # Install point intents for both directions
                     resultA = self.startPointIntentEvent()
                     [self.deviceA,
                      self.deviceB] = [self.deviceB, self.deviceA]
                     resultB = self.startPointIntentEvent()
                     if resultA == EventStates(
                     ).PASS and resultB == EventStates().PASS:
                         return EventStates().PASS
                     else:
                         return EventStates().FAIL
                 else:
                     return self.startPointIntentEvent()
             except Exception:
                 main.log.warn("Caught exception, aborting event")
                 return EventStates().ABORT
Beispiel #21
0
 def startEvent(self, args):
     """
     args are the device name and port number, e.g. [ 's1', '5' ]
     """
     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_PORT_DOWN:
                 with main.networkLock:
                     linkRandom = main.Network.getLinkRandom(
                         excludeNodes=main.excludeNodes,
                         skipLinks=main.skipLinks)
                 if linkRandom is None:
                     main.log.warn("No link available, aborting event")
                     return EventStates().ABORT
                 for link in main.links:
                     if link.deviceA.name == linkRandom[
                             0] and link.deviceB.name == linkRandom[1]:
                         self.device = link.deviceA
                         self.port = int(link.portA)
                 if not self.device:
                     main.log.warn(
                         "Failed to get a radnom device port, aborting event"
                     )
                     return EventStates().ABORT
             elif self.typeIndex == EventType().NETWORK_PORT_UP:
                 import random
                 with main.variableLock:
                     downPorts = {}
                     for link in main.links:
                         if link.isDown():
                             if int(link.portA) in link.deviceA.downPorts:
                                 downPorts[link.deviceA] = link.portA
                     if len(downPorts) == 0:
                         main.log.warn(
                             "None of the links are in 'down' state, aborting event"
                         )
                         return EventStates().ABORT
                     deviceList = random.sample(downPorts, 1)
                     self.device = deviceList[0]
                     self.port = int(downPorts[self.device])
         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
         if self.port is None:
             try:
                 self.port = int(args[1])
             except Exception:
                 main.log.warn("Device port is not a number: {}".format(
                     args[1]))
                 return EventStates().ABORT
         if self.link is None:
             for link in main.links:
                 if link.deviceA.name == self.device.name and int(
                         link.portA) == self.port:
                     self.link = link
             if self.link is None:
                 main.log.warn(
                     "There's no link on device {} port {}".format(
                         self.device.name, self.port))
                 return EventStates().ABORT
         main.log.debug("%s - %s:%s" %
                        (self.typeString, self.device, self.port))
         return self.startPortEvent()
Beispiel #22
0
 def startHostIntentEvent(self):
     return EventStates().PASS
Beispiel #23
0
 def startTestEvent(self, args=None):
     result = EventStates().PASS
     main.stop()
     return result
Beispiel #24
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 is 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 is 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 is not None and self.hostB is not None:
                             break
                     if self.hostA is None:
                         main.log.warn("Host %s does not exist: " %
                                       (args[0]))
                         return EventStates().ABORT
                     if self.hostB is 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.Cluster.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
Beispiel #25
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)
        import re
        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 re.match(str(main.params['TEST']['ipv6Regex']),
                                ipAddress):
                        dstIPv6List[host.index].append(ipAddress)
                    elif re.match(str(main.params['TEST']['ipv4Regex']),
                                  ipAddress):
                        dstIPv4List[host.index].append(ipAddress)
            if dstIPv4List[host.index]:
                main.log.debug("Check ping from host {} to {}".format(
                    host.name, dstIPv4List[host.index]))
            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:
            if dstIPv6List[host.index]:
                main.log.debug("Check ping from host {} to {}".format(
                    host.name, dstIPv6List[host.index]))
            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