| """ |
| Wrapper functions for FuncIntent |
| This functions include Onosclidriver and Mininetclidriver driver functions |
| """ |
| def __init__( self ): |
| self.default = '' |
| |
| def addHostIntent( main, item ): |
| """ |
| Add host intents |
| """ |
| import time |
| stepResult = main.TRUE |
| global itemName |
| itemName = item[ 'name' ] |
| h1Name = item[ 'host1' ][ 'name' ] |
| h2Name = item[ 'host2' ][ 'name' ] |
| h1Mac = item[ 'host1' ][ 'MAC' ] |
| h2Mac = item[ 'host2' ][ 'MAC' ] |
| h1Id = item[ 'host1' ][ 'id'] |
| h2Id = item[ 'host2' ][ 'id'] |
| sw1 = item[ 'link' ][ 'switch1' ] |
| sw2 = item[ 'link' ][ 'switch2' ] |
| expectLink = item[ 'link' ][ 'expect' ] |
| intentsId = [] |
| pingResult = main.TRUE |
| intentResult = main.TRUE |
| flowResult = main.TRUE |
| topoResult = main.TRUE |
| linkDownResult = main.TRUE |
| linkUpResult = main.TRUE |
| |
| # Discover hosts using arping |
| main.log.info( itemName + ": Discover host using arping" ) |
| main.Mininet1.arping( host=h1Name ) |
| main.Mininet1.arping( host=h2Name ) |
| host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| |
| # Adding host intents |
| main.log.info( itemName + ": Adding host intents" ) |
| intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| hostIdTwo=h2Id ) |
| intentsId.append( intent1 ) |
| time.sleep( 5 ) |
| intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
| hostIdTwo=h1Id ) |
| intentsId.append( intent2 ) |
| |
| # Check intents state |
| time.sleep( 50 ) |
| intentResult = checkIntentState( main, intentsId ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Ping hosts |
| pingHost( main, h1Name, h2Name ) |
| # Ping hosts again... |
| pingResult = pingHost( main, h1Name, h2Name ) |
| time.sleep( 5 ) |
| |
| # link down |
| link( main, sw1, sw2, "down" ) |
| intentResult = intentResult and checkIntentState( main, intentsId ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Check OnosTopology |
| topoResult = checkTopology( main, expectLink ) |
| |
| # Ping hosts |
| pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| |
| intentResult = checkIntentState( main, intentsId ) |
| |
| # link up |
| link( main, sw1, sw2, "up" ) |
| time.sleep( 5 ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Check OnosTopology |
| topoResult = checkTopology( main, expectLink ) |
| |
| # Ping hosts |
| pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| |
| # Remove intents |
| for intent in intentsId: |
| main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| |
| print main.CLIs[ 0 ].intents() |
| stepResult = pingResult and linkDownResult and linkUpResult \ |
| and intentResult |
| |
| return stepResult |
| |
| def addPointIntent( main, item ): |
| """ |
| Add Point intents |
| """ |
| import time |
| stepResult = main.TRUE |
| global itemName |
| itemName = item[ 'name' ] |
| ingress = item[ 'ingress' ] |
| egress = item[ 'egress' ] |
| option = item[ 'option' ] |
| sw1 = item[ 'link' ][ 'switch1' ] |
| sw2 = item[ 'link' ][ 'switch2' ] |
| expectLink = item[ 'link' ][ 'expect' ] |
| intentsId = [] |
| |
| print 'OPTIONS ', option |
| return main.TRUE |
| pingResult = main.TRUE |
| intentResult = main.TRUE |
| flowResult = main.TRUE |
| topoResult = main.TRUE |
| linkDownResult = main.TRUE |
| linkUpResult = main.TRUE |
| |
| # Discover hosts using arping |
| main.log.info( itemName + ": Discover host using arping" ) |
| main.Mininet1.arping( host=h1Name ) |
| main.Mininet1.arping( host=h2Name ) |
| host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| |
| # Adding host intents |
| main.log.info( itemName + ": Adding host intents" ) |
| intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| hostIdTwo=h2Id ) |
| intentsId.append( intent1 ) |
| time.sleep( 5 ) |
| intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
| hostIdTwo=h1Id ) |
| intentsId.append( intent2 ) |
| |
| # Check intents state |
| time.sleep( 50 ) |
| intentResult = checkIntentState( main, intentsId ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Ping hosts |
| pingHost( main, h1Name, h2Name ) |
| # Ping hosts again... |
| pingResult = pingHost( main, h1Name, h2Name ) |
| time.sleep( 5 ) |
| |
| # link down |
| link( main, sw1, sw2, "down" ) |
| intentResult = intentResult and checkIntentState( main, intentsId ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Check OnosTopology |
| topoResult = checkTopology( main, expectLink ) |
| |
| # Ping hosts |
| pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| |
| intentResult = checkIntentState( main, intentsId ) |
| |
| # link up |
| link( main, sw1, sw2, "up" ) |
| time.sleep( 5 ) |
| |
| # Verify flows |
| checkFlowsState( main ) |
| |
| # Check OnosTopology |
| topoResult = checkTopology( main, expectLink ) |
| |
| # Ping hosts |
| pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| |
| # Remove intents |
| for intent in intentsId: |
| main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| |
| print main.CLIs[ 0 ].intents() |
| stepResult = pingResult and linkDownResult and linkUpResult \ |
| and intentResult |
| |
| return stepResult |
| |
| def link( main, sw1, sw2, option): |
| |
| # link down |
| main.log.info( itemName + ": Bring link " + option + "between " + |
| sw1 + " and " + sw2 ) |
| main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| |
| def pingHost( main, h1Name, h2Name ): |
| |
| # Ping hosts |
| main.log.info( itemName + ": Ping " + h1Name + " and " + |
| h2Name ) |
| pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| if not pingResult1: |
| main.log.info( itemName + ": " + h1Name + " cannot ping " |
| + h2Name ) |
| pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| if not pingResult2: |
| main.log.info( itemName + ": " + h2Name + " cannot ping " |
| + h1Name ) |
| pingResult = pingResult1 and pingResult2 |
| if pingResult: |
| main.log.info( itemName + ": Successfully pinged " + |
| "both hosts" ) |
| else: |
| main.log.info( itemName + ": Failed to ping " + |
| "both hosts" ) |
| return pingResult |
| |
| def checkItem( item ): |
| """ |
| Checks the dictionary |
| """ |
| |
| def checkTopology( main, expectedLink ): |
| statusResult = main.TRUE |
| # Check onos topology |
| main.log.info( itemName + ": Checking ONOS topology " ) |
| |
| for i in range( main.numCtrls ): |
| topologyResult = main.CLIs[ i ].topology() |
| statusResult = main.ONOSbench.checkStatus( topologyResult, |
| main.numSwitch, |
| expectedLink )\ |
| and statusResult |
| if not statusResult: |
| main.log.info( itemName + ": Topology mismatch" ) |
| else: |
| main.log.info( itemName + ": Topology match" ) |
| return statusResult |
| |
| def checkIntentState( main, intentsId ): |
| |
| main.log.info( itemName + ": Check host intents state" ) |
| for i in range( main.numCtrls ): |
| intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| if not intentResult: |
| main.log.info( itemName + ": Check host intents state again") |
| for i in range( main.numCtrls ): |
| intentResult = main.CLIs[ i ].checkIntentState( |
| intentsId=intentsId ) |
| return intentResult |
| |
| def checkFlowsState( main ): |
| |
| main.log.info( itemName + ": Check flows state" ) |
| checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| return checkFlowsResult |
| |
| def printMsg( main, h1Name, h2Name ): |
| main.log.info("PINGING HOST INSIDE printMSG") |
| pingHost( main, itemName, h1Name, h2Name ) |
| print 'lala' |
| |