SAMPstatTemplate2 with driver modifications

Change-Id: I324b060d9d30e5cf26131a4a83bfbe101c5f6ec2
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/Dependency/newFuncTopo.py b/TestON/tests/SAMP/SAMPstartTemplate2/Dependency/newFuncTopo.py
new file mode 100755
index 0000000..7fe68c1
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/Dependency/newFuncTopo.py
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+
+"""
+Custom topology for Mininet
+"""
+from mininet.topo import Topo
+from mininet.net import Mininet
+from mininet.node import Host, RemoteController
+from mininet.node import Node
+from mininet.node import CPULimitedHost
+from mininet.link import TCLink
+from mininet.cli import CLI
+from mininet.log import setLogLevel
+from mininet.util import dumpNodeConnections
+from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
+
+class VLANHost( Host ):
+    def config( self, vlan=100, **params ):
+        r = super( Host, self ).config( **params )
+        intf = self.defaultIntf()
+        self.cmd( 'ifconfig %s inet 0' % intf )
+        self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
+        self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
+        newName = '%s.%d' % ( intf, vlan )
+        intf.name = newName
+        self.nameToIntf[ newName ] = intf
+        return r
+
+class IPv6Host( Host ):
+    def config( self, v6Addr='1000:1/64', **params ):
+        r = super( Host, self ).config( **params )
+        intf = self.defaultIntf()
+        self.cmd( 'ifconfig %s inet 0' % intf )
+        self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
+        return r
+
+class dualStackHost( Host ):
+    def config( self, v6Addr='2000:1/64', **params ):
+        r = super( Host, self ).config( **params )
+        intf = self.defaultIntf()
+        self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
+        return r
+
+class MyTopo( Topo ):
+
+    def __init__( self ):
+        # Initialize topology
+        Topo.__init__( self )
+
+        # Switch S5 Hosts
+        host1=self.addHost( 'h1', ip='10.1.0.2/24' )
+        host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
+        host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
+        #VLAN hosts
+        host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
+        host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
+        #VPN-1 and VPN-2 Hosts
+        host6=self.addHost( 'h6', ip='11.1.0.2/24' )
+        host7=self.addHost( 'h7', ip='12.1.0.2/24' )
+        #Multicast Sender
+        host8=self.addHost( 'h8', ip='10.1.0.4/24' )
+
+        # Switch S6 Hosts
+        host9=self.addHost( 'h9', ip='10.1.0.5/24' )
+        host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
+        host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
+        #VLAN hosts
+        host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
+        host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
+        #VPN-1 and VPN-2 Hosts
+        host14=self.addHost( 'h14', ip='11.1.0.3/24' )
+        host15=self.addHost( 'h15', ip='12.1.0.3/24' )
+        #Multicast Receiver
+        host16=self.addHost( 'h16', ip='10.1.0.7/24' )
+
+        # Switch S7 Hosts
+        host17=self.addHost( 'h17', ip='10.1.0.8/24' )
+        host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
+        host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
+        #VLAN hosts
+        host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
+        host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
+        #VPN-1 and VPN-2 Hosts
+        host22=self.addHost( 'h22', ip='11.1.0.4/24' )
+        host23=self.addHost( 'h23', ip='12.1.0.4/24' )
+        #Multicast Receiver
+        host24=self.addHost( 'h24', ip='10.1.0.10/24' )
+
+        s1 = self.addSwitch( 's1' )
+        s2 = self.addSwitch( 's2' )
+        s3 = self.addSwitch( 's3' )
+        s4 = self.addSwitch( 's4' )
+        s5 = self.addSwitch( 's5' )
+        s6 = self.addSwitch( 's6' )
+        s7 = self.addSwitch( 's7' )
+
+        self.addLink(s5,host1)
+        self.addLink(s5,host2)
+        self.addLink(s5,host3)
+        self.addLink(s5,host4)
+        self.addLink(s5,host5)
+        self.addLink(s5,host6)
+        self.addLink(s5,host7)
+        self.addLink(s5,host8)
+
+        self.addLink(s6,host9)
+        self.addLink(s6,host10)
+        self.addLink(s6,host11)
+        self.addLink(s6,host12)
+        self.addLink(s6,host13)
+        self.addLink(s6,host14)
+        self.addLink(s6,host15)
+        self.addLink(s6,host16)
+
+        self.addLink(s7,host17)
+        self.addLink(s7,host18)
+        self.addLink(s7,host19)
+        self.addLink(s7,host20)
+        self.addLink(s7,host21)
+        self.addLink(s7,host22)
+        self.addLink(s7,host23)
+        self.addLink(s7,host24)
+
+        self.addLink(s1,s2)
+        self.addLink(s1,s3)
+        self.addLink(s1,s4)
+        self.addLink(s1,s5)
+
+        self.addLink(s2,s3)
+        self.addLink(s2,s5)
+        self.addLink(s2,s6)
+
+        self.addLink(s3,s4)
+        self.addLink(s3,s6)
+
+        self.addLink(s4,s7)
+        topos = { 'mytopo': ( lambda: MyTopo() ) }
+
+# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
+
+def setupNetwork():
+    "Create network"
+    topo = MyTopo()
+    network = Mininet(topo=topo, autoSetMacs=True, controller=None)
+    network.start()
+    CLI( network )
+    network.stop()
+
+if __name__ == '__main__':
+    setLogLevel('info')
+    #setLogLevel('debug')
+    setupNetwork()
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/README b/TestON/tests/SAMP/SAMPstartTemplate2/README
new file mode 100644
index 0000000..7df40db
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/README
@@ -0,0 +1,2 @@
+Summary:
+        Sample test case how onos test should start up.
\ No newline at end of file
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.params b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.params
new file mode 100755
index 0000000..8fde55a
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.params
@@ -0,0 +1,64 @@
+<PARAMS>
+    <!--
+        CASE0: pull onos code - this case should be skipped on Jenkins-driven prod test
+    -->
+    <!--
+        CASE1: setup and clean test env
+    -->
+    <!--
+        CASE2: get onos warnings, errors from log
+    -->
+    <!--
+        CASE10: start a 3-node ONOS Cluster
+    -->
+    <!--
+        CASE11: Start Mininet and assign controllers
+    -->
+    <!--
+        CASE12: Sample case of using onos cli
+    -->
+    <!--
+        CASE22: Sample case of using onos rest
+    -->
+
+    <testcases>0,1,10,11,12,22,2</testcases>
+
+    <CASE0>
+        <gitPull>False</gitPull> # False or True
+        <gitBranch>master</gitBranch>
+    </CASE0>
+
+    <CASE1>
+        <NodeList>OC1,OC2,OC3</NodeList>
+        <SleepTimers>
+            <onosStartup>60</onosStartup>
+            <onosCfg>5</onosCfg>
+            <mnStartup>15</mnStartup>
+            <mnCfg>10</mnCfg>
+        </SleepTimers>
+    </CASE1>
+
+    <CASE10>
+        <numNodes>3</numNodes>
+        <Apps>
+            org.onosproject.openflow,org.onosproject.fwd
+        </Apps>
+        <ONOS_Configuration>
+        <org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator>
+            <useFlowObjectives>true</useFlowObjectives>
+        </org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator>
+        </ONOS_Configuration>
+    </CASE10>
+
+    <CASE11>
+        <path>~/OnosSystemTest/TestON/tests/SAMP/SAMPstartTemplate2/Dependency/</path>
+        <topo>newFuncTopo.py</topo>
+    </CASE11>
+
+    <CASE12>
+    </CASE12>
+
+    <CASE22>
+    </CASE22>
+
+</PARAMS>
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.py b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.py
new file mode 100644
index 0000000..ce057f4
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.py
@@ -0,0 +1,228 @@
+
+# This is a sample template that starts up ONOS cluster, this template
+# can be use as a base script for ONOS System Testing.
+
+class SAMPstartTemplate2:
+
+    def __init__( self ):
+        self.default = ''
+
+
+    def CASE0(self, main):
+        '''
+            Pull specific ONOS branch, then Build ONOS ono ONOS Bench.
+            This step is usually skipped. Because in a Jenkins driven automated
+            test env. We want Jenkins jobs to pull&build for flexibility to handle
+            different versions of ONOS.
+        '''
+        gitPull = main.params['CASE0']['gitPull']
+        gitBranch = main.params['CASE0']['gitBranch']
+
+        main.case("Pull onos branch and build onos on Teststation.")
+
+        if gitPull == 'True':
+            main.step( "Git Checkout ONOS branch: " + gitBranch)
+            stepResult = main.ONOSbench.gitCheckout( branch = gitBranch )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=stepResult,
+                                     onpass="Successfully checkout onos branch.",
+                                     onfail="Failed to checkout onos branch. Exiting test..." )
+            if not stepResult: main.exit()
+
+            main.step( "Git Pull on ONOS branch:" + gitBranch)
+            stepResult = main.ONOSbench.gitPull( )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=stepResult,
+                                     onpass="Successfully pull onos. ",
+                                     onfail="Failed to pull onos. Exiting test ..." )
+            if not stepResult: main.exit()
+
+            main.step( "Building ONOS branch: " + gitBranch )
+            stepResult = main.ONOSbench.cleanInstall( skipTest = True )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=stepResult,
+                                     onpass="Successfully build onos.",
+                                     onfail="Failed to build onos. Exiting test..." )
+            if not stepResult: main.exit()
+
+        else:
+            main.log.warn( "Skipped pulling onos and Skipped building ONOS" )
+
+
+    def CASE1( self, main ):
+        '''
+            Set up global test variables;
+            Uninstall all running cells in test env defined in .topo file
+
+        '''
+
+        main.case( "Constructing global test variables and clean cluster env." )
+
+        main.step( "Constructing test variables" )
+        main.branch = main.ONOSbench.getBranchName()
+        main.log.info( "Running onos branch: " + main.branch )
+        main.commitNum = main.ONOSbench.getVersion().split(' ')[1]
+        main.log.info( "Running onos commit Number: " + main.commitNum)
+        main.nodeList = main.params['CASE1']['NodeList'].split(",")
+        main.onosStartupSleep = float( main.params['CASE1']['SleepTimers']['onosStartup'] )
+        main.onosCfgSleep = float( main.params['CASE1']['SleepTimers']['onosCfg'] )
+        main.mnStartupSleep = float( main.params['CASE1']['SleepTimers']['mnStartup'] )
+        main.mnCfgSleep = float( main.params['CASE1']['SleepTimers']['mnCfg'] )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=main.TRUE,
+                                 onpass="Successfully construct " +
+                                        "test variables ",
+                                 onfail="Failed to construct test variables" )
+
+
+
+        main.step( "Uninstall all onos nodes in the env.")
+        stepResult = main.TRUE
+        for node in main.nodeList:
+            nodeResult = main.ONOSbench.onosUninstall( nodeIp = "$" + node )
+            stepResult = stepResult & nodeResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully uninstall onos on all nodes in env.",
+                                 onfail="Failed to uninstall onos on all nodes in env!" )
+        if not stepResult:
+            main.log.error( "Failure to clean test env. Exiting test..." )
+            main.exit()
+
+    def CASE2( self, main ):
+        '''
+            Report errors/warnings/exceptions
+        '''
+        main.log.info("Error report: \n" )
+        main.ONOSbench.logReport( main.ONOScli1.ip_address,
+                                  [ "INFO",
+                                    "FOLLOWER",
+                                    "WARN",
+                                    "flow",
+                                    "ERROR",
+                                    "Except" ],
+                                  "s" )
+
+    def CASE10( self, main ):
+        """
+        Start ONOS cluster (3 nodes in this example) in three steps:
+        1) start a basic cluster with drivers app via ONOSDriver;
+        2) activate apps via ONOSCliDriver;
+        3) configure onos via ONOSCliDriver;
+        """
+
+        import time
+
+        numNodes = int( main.params['CASE10']['numNodes'] )
+        main.case( "Start up " + str( numNodes ) + "-node onos cluster.")
+
+        main.step( "Start ONOS cluster with basic (drivers) app.")
+        onosClusterIPs = []
+        for n in range( 1, numNodes + 1 ):
+            handle = "main.ONOScli" + str( n )
+            onosClusterIPs.append( eval( handle ).ip_address )
+
+        stepResult = main.ONOSbench.startBasicONOS(nodeList = onosClusterIPs, opSleep = 200 )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully started basic ONOS cluster ",
+                                 onfail="Failed to start basic ONOS Cluster " )
+
+        main.step( "Establishing Handles on ONOS CLIs.")
+        cliResult = main.TRUE
+        for n in range( 1, numNodes + 1 ):
+            handle = "main.ONOScli" + str( n )
+            cliResult = cliResult & ( eval( handle ).startCellCli() )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=cliResult,
+                                 onpass="Successfully started onos cli's ",
+                                 onfail="Failed to start onos cli's " )
+
+        main.step( "Activate onos apps.")
+        apps = main.params['CASE10'].get( 'Apps' )
+        if apps:
+            main.log.info( "Apps to activate: " + apps )
+            activateResult = main.TRUE
+            for a in apps.split(","):
+                activateResult = activateResult & main.ONOScli1.activateApp(a)
+            # TODO: check this worked
+            time.sleep( main.onosCfgSleep )  # wait for apps to activate
+        else:
+            main.log.warn( "No configurations were specified to be changed after startup" )
+        utilities.assert_equals( expect=main.TRUE,
+                                     actual=activateResult,
+                                     onpass="Successfully set config",
+                                     onfail="Failed to set config" )
+
+        main.step( "Set ONOS configurations" )
+        config = main.params['CASE10'].get( 'ONOS_Configuration' )
+        if config:
+            main.log.debug( config )
+            checkResult = main.TRUE
+            for component in config:
+                for setting in config[component]:
+                    value = config[component][setting]
+                    check = main.ONOScli1.setCfg( component, setting, value )
+                    main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
+                    checkResult = check and checkResult
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=checkResult,
+                                     onpass="Successfully set config",
+                                     onfail="Failed to set config" )
+        else:
+            main.log.warn( "No configurations were specified to be changed after startup" )
+
+    def CASE11( self, main ):
+        """
+            Start mininet and assign controllers
+        """
+        import time
+
+        dependencyPath = main.params['CASE11']['path']
+        topology = main.params['CASE11']['topo']
+        main.log.report( "Start Mininet topology" )
+        main.log.case( "Start Mininet topology" )
+
+        main.step( "Starting Mininet Topology" )
+        topoResult = main.Mininet1.startNet( topoFile=dependencyPath + topology )
+        stepResult = topoResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully loaded topology",
+                                 onfail="Failed to load topology" )
+        # Exit if topology did not load properly
+        if not topoResult:
+            main.cleanup()
+            main.exit()
+
+        main.step( "Assign switches to controllers.")
+        assignResult = main.TRUE
+        onosNodes = [ main.ONOScli1.ip_address, main.ONOScli2.ip_address, main.ONOScli3.ip_address ]
+        for i in range(1, 8):
+            assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
+                                                         ip=onosNodes,
+                                                         port='6653' )
+        time.sleep(main.mnCfgSleep)
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully assign switches to controllers",
+                                 onfail="Failed to assign switches to controllers" )
+
+
+    def CASE12( self, main ):
+        """
+            Tests using through ONOS CLI handles
+        """
+
+        main.log.case( "Test some onos commands through CLI. ")
+        main.log.debug( main.ONOScli1.sendline("summary") )
+        main.log.debug( main.ONOScli3.sendline("devices") )
+
+    def CASE22( self, main ):
+        """
+            Tests using ONOS REST API handles
+        """
+
+        main.case( " Sample tests using ONOS REST API handles. ")
+        main.log.debug( main.ONOSrest1.send("/devices") )
+        main.log.debug( main.ONOSrest2.apps() )
\ No newline at end of file
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.topo b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.topo
new file mode 100755
index 0000000..9f23369
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/SAMPstartTemplate2.topo
@@ -0,0 +1,94 @@
+<TOPOLOGY>
+    <COMPONENT>
+    <!--
+        This is a list of all components and their handles in the test setup.
+        Even with some handles not used in test cases, we want to define
+        all onos cells here, for cases to set up onos cluster.
+    -->
+        <ONOSbench>
+            <host>localhost</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosDriver</type>
+            <connect_order>1</connect_order>
+            <COMPONENTS>
+                <home></home> #defines where onos home is
+            </COMPONENTS>
+        </ONOSbench>
+
+        <ONOScli1>
+            <host>OC1</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosCliDriver</type>
+            <connect_order>2</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOScli1>
+
+        <ONOScli2>
+            <host>OC2</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosCliDriver</type>
+            <connect_order>3</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOScli2>
+
+         <ONOScli3>
+            <host>OC3</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosCliDriver</type>
+            <connect_order>4</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOScli3>
+
+        <Mininet1>
+            <host>localhost</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>MininetCliDriver</type>
+            <connect_order>5</connect_order>
+            <COMPONENTS>
+                <home>~/mininet/custom/</home>
+            </COMPONENTS>
+        </Mininet1>
+
+        <ONOSrest1>
+            <host>OC1</host>
+            <port>8181</port>
+            <user>onos</user>
+            <password>rocks</password>
+            <type>OnosRestDriver</type>
+            <connect_order>6</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOSrest1>
+
+        <ONOSrest2>
+            <host>OC2</host>
+            <port>8181</port>
+            <user>onos</user>
+            <password>rocks</password>
+            <type>OnosRestDriver</type>
+            <connect_order>7</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOSrest2>
+
+         <ONOSrest3>
+            <host>OC3</host>
+            <port>8181</port>
+            <user>onos</user>
+            <password>rocks</password>
+            <type>OnosRestDriver</type>
+            <connect_order>8</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOSrest3>
+
+    </COMPONENT>
+</TOPOLOGY>
diff --git a/TestON/tests/SAMP/SAMPstartTemplate2/__init__.py b/TestON/tests/SAMP/SAMPstartTemplate2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/tests/SAMP/SAMPstartTemplate2/__init__.py