Creating subfolders for test suites

allow teston to look in subfolders
create subfolders for current test suites
move tests into sub folders
create HA suite dependencies folder and moved all common files there
minor driver and test updates
standardize on the name dependencies for the directory
change from admin to sdn users

Conflicts:
	TestON/tests/FUNC/FUNCipv6Intent/FUNCipv6Intent.topo

Change-Id: I849e45ab67da8b285c36c5fdf43b34323876e741
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/2x2.json b/TestON/tests/USECASE/USECASE_SegmentRouting/2x2.json
new file mode 100644
index 0000000..31b2cc8
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/2x2.json
@@ -0,0 +1,104 @@
+{
+    "ports" : {
+    "of:0000000000000001/3" : {
+        "interfaces" : [
+        {
+            "ips" : [ "10.0.1.254/24" ]
+        }
+        ]
+    },
+    "of:0000000000000001/4" : {
+        "interfaces" : [
+        {
+            "ips" : [ "10.0.1.254/24" ]
+        }
+        ]
+    },
+    "of:0000000000000002/3" : {
+        "interfaces" : [
+        {
+            "ips" : [ "10.0.2.254/24" ]
+        }
+        ]
+    },
+    "of:0000000000000002/4" : {
+        "interfaces" : [
+        {
+            "ips" : [ "10.0.2.254/24" ]
+        }
+        ]
+    }
+    },
+    "devices" : {
+        "of:0000000000000001" : {
+            "basic":{ "driver" : "ofdpa-cpqd" },
+            "segmentrouting" : {
+                "name" : "Leaf-R1",
+                "nodeSid" : 1,
+                "routerIp" : "192.168.0.1",
+                "routerMac" : "00:00:00:00:00:01",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+        },
+        "of:0000000000000002" : {
+            "basic":{ "driver" : "ofdpa-cpqd" },
+            "segmentrouting" : {
+                "name" : "Leaf-R2",
+                "nodeSid" : 2,
+                "routerIp" : "192.168.0.2",
+                "routerMac" : "00:00:00:00:00:02",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+        },
+        "of:0000000000000101" : {
+            "basic":{ "driver" : "ofdpa-cpqd" },
+            "segmentrouting" : {
+                "name" : "Spine-R1",
+                "nodeSid" : 101,
+                "routerIp" : "192.168.0.101",
+                "routerMac" : "00:00:00:00:01:01",
+                "isEdgeRouter" : false,
+                "adjacencySids" : []
+            }
+        },
+        "of:0000000000000102" : {
+            "basic":{ "driver" : "ofdpa-cpqd" },
+            "segmentrouting" : {
+                "name" : "Spine-R2",
+                "nodeSid" : 102,
+                "routerIp" : "192.168.0.102",
+                "routerMac" : "00:00:00:00:01:02",
+                "isEdgeRouter" : false,
+                "adjacencySids" : []
+            }
+        }
+    },
+    "hosts" : {
+        "00:00:00:00:00:01/-1" : {
+            "basic": {
+                "ips": ["10.0.1.1"],
+                "location": "of:0000000000000001/3"
+            }
+        },
+        "00:00:00:00:00:02/-1" : {
+            "basic": {
+                "ips": ["10.0.1.2"],
+                "location": "of:0000000000000001/4"
+            }
+        },
+        "00:00:00:00:00:03/-1" : {
+            "basic": {
+                "ips": ["10.0.2.1"],
+                "location": "of:0000000000000002/3"
+            }
+        },
+        "00:00:00:00:00:04/-1" : {
+            "basic": {
+                "ips": ["10.0.2.2"],
+                "location": "of:0000000000000002/4"
+            }
+        }
+    }
+}
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/README.md b/TestON/tests/USECASE/USECASE_SegmentRouting/README.md
new file mode 100644
index 0000000..da75079
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/README.md
@@ -0,0 +1,18 @@
+This test is designed to verify basic connectivity the SegmentRouting application.
+
+It consists of 
+
+1) Installing and Starting ONOS
+2) Starting Mininet and testing connectivity
+
+Requirements
+
+ - A single ONOS instance is required for the test, the application is currently not stable in a cluster.
+ - An updated version of the CPQD switch has to be running to make sure it supports group chaining.
+
+Step 1:
+In this step we copy the proper config file to ONOS, next we package ONOS and install it in the target machine.
+
+Step 2:
+
+In this step we start a 2x2 leaf-spine topology, connect to ONOS, and next we send several pings between hosts to test connectivity.
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params
new file mode 100755
index 0000000..0ceb4f2
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params
@@ -0,0 +1,36 @@
+<PARAMS>
+
+    <testcases>1,2,11,9, 2,11,9</testcases>
+
+    <SCALE>
+        <size>1</size>
+        <max>1</max>
+    </SCALE>
+
+    <DEPENDENCY>
+        <path>/tests/USECASE_SegmentRouting/dependencies/</path>
+        <wrapper1>startUp</wrapper1>
+        <topology>cord_fabric.py</topology>
+    </DEPENDENCY>
+
+    <ENV>
+        <cellName>productionCell</cellName>
+        <cellApps>drivers,segmentrouting</cellApps>
+        <diffApps>openflow-base,netcfghostprovider,netcfglinksprovider;openflow</diffApps>
+        <cellUser>sdn</cellUser>
+    </ENV>
+
+    <GIT>
+        <pull>False</pull>
+        <branch>master</branch>
+    </GIT>
+
+    <CTRL>
+        <port>6653</port>
+    </CTRL>
+
+    <SLEEP>
+        <startup>10</startup>
+    </SLEEP>
+
+</PARAMS>
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py
new file mode 100644
index 0000000..31678fe
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py
@@ -0,0 +1,248 @@
+
+# This test is to determine if the Segment Routing application is working properly
+
+class USECASE_SegmentRouting:
+
+    def __init__( self ):
+        self.default = ''
+
+    def CASE1( self, main ):
+        import time
+        import os
+        import imp
+        import re
+
+        """
+        - Construct tests variables
+        - GIT ( optional )
+            - Checkout ONOS master branch
+            - Pull latest ONOS code
+        - Building ONOS ( optional )
+            - Install ONOS package
+            - Build ONOS package
+        """
+
+        main.case( "Constructing test variables and building ONOS" )
+        main.step( "Constructing test variables" )
+        stepResult = main.FALSE
+
+        # Test variables
+        main.cellName = main.params[ 'ENV' ][ 'cellName' ]
+        main.apps = main.params[ 'ENV' ][ 'cellApps' ]
+        main.diff = ( main.params[ 'ENV' ][ 'diffApps' ] ).split(";")
+        gitBranch = main.params[ 'GIT' ][ 'branch' ]
+        main.dependencyPath = os.path.dirname( main.testFile ) + "/dependencies/"
+        main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
+        #main.json = ["4x4"]
+        main.json = ["2x2", "2x2"]
+        main.args = [" ", " "]
+        #main.args = [" --spine 4 --leaf 4 "]
+        main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
+        main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
+        main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
+        wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
+        main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
+        gitPull = main.params[ 'GIT' ][ 'pull' ]
+        main.cellData = {} # for creating cell file
+        main.CLIs = []
+        main.ONOSip = []
+
+        main.ONOSip = main.ONOSbench.getOnosIps()
+
+        # Assigning ONOS cli handles to a list
+        for i in range( 1,  main.maxNodes + 1 ):
+            main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
+
+        # -- INIT SECTION, ONLY RUNS ONCE -- #
+        main.startUp = imp.load_source( wrapperFile1,
+                                        main.dependencyPath +
+                                        wrapperFile1 +
+                                        ".py" )
+
+        copyResult1 = main.ONOSbench.scp( main.Mininet1,
+                                          main.dependencyPath +
+                                          main.topology,
+                                          main.Mininet1.home,
+                                          direction="to" )
+        if main.CLIs:
+            stepResult = main.TRUE
+        else:
+            main.log.error( "Did not properly created list of ONOS CLI handle" )
+            stepResult = main.FALSE
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully construct " +
+                                        "test variables ",
+                                 onfail="Failed to construct test variables" )
+
+        if gitPull == 'True':
+            main.step( "Building ONOS in " + gitBranch + " branch" )
+            onosBuildResult = main.startUp.onosBuild( main, gitBranch )
+            stepResult = onosBuildResult
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=stepResult,
+                                     onpass="Successfully compiled " +
+                                            "latest ONOS",
+                                     onfail="Failed to compile " +
+                                            "latest ONOS" )
+        else:
+            main.log.warn( "Did not pull new code so skipping mvn " +
+                           "clean install" )
+         
+    def CASE2( self, main ):
+        """
+        - Set up cell
+            - Create cell file
+            - Set cell file
+            - Verify cell file
+        - Kill ONOS process
+        - Uninstall ONOS cluster
+        - Verify ONOS start up
+        - Install ONOS cluster
+        - Connect to cli
+        """
+
+        # main.scale[ 0 ] determines the current number of ONOS controller
+        main.numCtrls = int( main.scale[ 0 ] )
+
+        main.case( "Package and start ONOS")
+
+        #kill off all onos processes
+        main.log.info( "Safety check, killing all ONOS processes" +
+                       " before initiating environment setup" )
+
+        for i in range( main.maxNodes ):
+            main.ONOSbench.onosDie( main.ONOSip[ i ] )
+
+        print "NODE COUNT = ", main.numCtrls
+
+        tempOnosIp = []
+        for i in range( main.numCtrls ):
+            tempOnosIp.append( main.ONOSip[i] )
+        apps=main.apps
+        if main.diff:
+            apps = main.apps+","+main.diff.pop(0)
+        else: main.log.error( "App list is empty" )
+        onosUser = main.params[ 'ENV' ][ 'cellUser' ]
+        main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
+                                       "temp",
+                                       main.Mininet1.ip_address,
+                                       apps,
+                                       tempOnosIp )
+
+        main.step( "Apply cell to environment" )
+        cellResult = main.ONOSbench.setCell( "temp" )
+        verifyResult = main.ONOSbench.verifyCell()
+        stepResult = cellResult and verifyResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully applied cell to " + \
+                                        "environment",
+                                 onfail="Failed to apply cell to environment " )
+
+        main.step( "Creating ONOS package" )
+        main.ONOSbench.handle.sendline( "cp ~/OnosSystemTest/TestON/tests/USECASE_SegmentRouting/"+main.json.pop(0)+".json ~/onos/tools/package/config/network-cfg.json")
+        packageResult = main.ONOSbench.onosPackage()
+        stepResult = packageResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully created ONOS package",
+                                 onfail="Failed to create ONOS package" )
+
+        time.sleep( main.startUpSleep )
+
+        main.step( "Installing ONOS package" )
+        onosInstallResult = main.TRUE
+        for i in range( main.numCtrls ):
+            onosInstallResult = onosInstallResult and \
+                    main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
+        stepResult = onosInstallResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully installed ONOS package",
+                                 onfail="Failed to install ONOS package" )
+
+        main.step( "Starting ONOS service" )
+        stopResult = main.TRUE
+        startResult = main.TRUE
+        onosIsUp = main.TRUE
+
+        for i in range( main.numCtrls ):
+            onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
+        if onosIsUp == main.TRUE:
+            main.log.report( "ONOS instance is up and ready" )
+        else:
+            main.log.report( "ONOS instance may not be up, stop and " +
+                             "start ONOS again " )
+            for i in range( main.numCtrls ):
+                stopResult = stopResult and \
+                        main.ONOSbench.onosStop( main.ONOSip[ i ] )
+            for i in range( main.numCtrls ):
+                startResult = startResult and \
+                        main.ONOSbench.onosStart( main.ONOSip[ i ] )
+        stepResult = onosIsUp and stopResult and startResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="ONOS service is ready",
+                                 onfail="ONOS service did not start properly" )
+        time.sleep( 2*main.startUpSleep )
+
+    def CASE9( self, main ):
+        '''
+            Report errors/warnings/exceptions
+        '''
+        main.log.case( "Logging test" )
+        #main.ONOSbench.logReport( main.ONOSip[ 0 ],
+        #                          [ "INFO" ],
+        #                          "a" )
+        #main.log.info("Error report: \n" )
+        main.ONOSbench.logReport( main.ONOSip[ 0 ],
+                                  [ "INFO",
+                                    "FOLLOWER",
+                                    "WARN",
+                                    "flow",
+                                    "ERROR",
+                                    "Except" ],
+                                  "s" )
+
+    def CASE11( self, main ):
+        """
+            Start mininet
+        """
+        main.log.case( "Start Leaf-Spine 2x2 Mininet Topology" )
+        main.log.report( "Start Mininet topology" )
+
+        main.step( "Starting Mininet Topology" )
+        args,topo=" "," "
+        #if main.topology:
+        #    topo = main.topology.pop(0)
+        #else: main.log.error( "Topo list is empty" )
+        if main.args:
+            args = "--onos 1 " + main.args.pop(0)
+        else: main.log.error( "Argument list is empty" )
+
+        topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
+        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("Waiting for switch initialization and configuration")
+        time.sleep( 3*main.startUpSleep)
+        pa = main.Mininet1.pingall()
+        utilities.assert_equals( expect=main.TRUE, actual=pa,
+                                 onpass="Full connectivity successfully tested",
+                                 onfail="Full connectivity failed" )
+        # cleanup mininet
+        main.ONOSbench.onosStop( main.ONOSip[0] )
+        main.Mininet1.stopNet()
+
+
+
+
+
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.topo b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.topo
new file mode 100755
index 0000000..a5266a0
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.topo
@@ -0,0 +1,37 @@
+<TOPOLOGY>
+    <COMPONENT>
+
+        <ONOSbench>
+            <host>localhost</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosDriver</type>
+            <connect_order>1</connect_order>
+            <COMPONENTS>
+                <nodes>1</nodes>
+            </COMPONENTS>
+        </ONOSbench>
+
+        <ONOScli1>
+            <host>localhost</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>OnosCliDriver</type>
+            <connect_order>2</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOScli1>
+
+        <Mininet1>
+            <host>OCN</host>
+            <user>sdn</user>
+            <password>rocks</password>
+            <type>MininetCliDriver</type>
+            <connect_order>3</connect_order>
+            <COMPONENTS>
+                <home>~/mininet/custom/</home>
+            </COMPONENTS>
+        </Mininet1>
+
+    </COMPONENT>
+</TOPOLOGY>
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/__init__.py b/TestON/tests/USECASE/USECASE_SegmentRouting/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/__init__.py
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/cord_fabric.py b/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/cord_fabric.py
new file mode 100755
index 0000000..a2a8a8e
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/cord_fabric.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+import os
+from optparse import OptionParser
+
+from mininet.net import Mininet
+from mininet.topo import Topo
+from mininet.node import RemoteController, UserSwitch, Host
+from mininet.link import TCLink
+from mininet.log import setLogLevel
+from mininet.cli import CLI
+
+# Parse command line options and dump results
+def parseOptions():
+    """Parse command line options"""
+    parser = OptionParser()
+    parser.add_option('--spine', dest='spine', type='int', default=2,
+                      help='number of spine switches, default=2')
+    parser.add_option('--leaf', dest='leaf', type='int', default=2,
+                      help='number of leaf switches, default=2')
+    parser.add_option('--fanout', dest='fanout', type='int', default=2,
+                      help='number of hosts per leaf switch, default=2')
+    parser.add_option('--onos', dest='onos', type='int', default=0,
+                      help='number of ONOS Instances, default=0, 0 means localhost, 1 will use OC1 and so on')
+
+    (options, args) = parser.parse_args()
+    return options, args
+
+opts, args = parseOptions()
+
+class LeafAndSpine(Topo):
+    def __init__(self, spine=2, leaf=2, fanout=2, **opts):
+        "Create Leaf and Spine Topo."
+
+        Topo.__init__(self, **opts)
+
+        # Add spine switches
+        spines = {}
+        for s in range(spine):
+            spines[s] = self.addSwitch('spine10%s' % (s + 1), dpid="00000000010%s" % (s + 1))
+        # Set link speeds to 100Mb/s
+        linkopts = dict(bw=100)
+
+        # Add Leaf switches
+        for ls in range(leaf):
+            leafSwitch = self.addSwitch('leaf%s' % (ls + 1), dpid="00000000000%s" % (1+ls))
+            # Connect leaf to all spines
+            for s in range(spine):
+                switch = spines[s]
+                self.addLink(leafSwitch, switch, **linkopts)
+            # Add hosts under a leaf, fanout hosts per leaf switch
+            for f in range(fanout):
+                host = self.addHost('h%s' % (ls * fanout + f + 1),
+                                         cls=IpHost,
+                                         ip='10.0.%s.%s/24' % ((ls + 1), (f + 1)),
+                                         gateway='10.0.%s.254' % (ls + 1))
+                self.addLink(host, leafSwitch, **linkopts)
+
+class IpHost(Host):
+    def __init__(self, name, gateway, *args, **kwargs):
+        super(IpHost, self).__init__(name, *args, **kwargs)
+        self.gateway = gateway
+
+    def config(self, **kwargs):
+        Host.config(self, **kwargs)
+        mtu = "ifconfig "+self.name+"-eth0 mtu 1490"
+        self.cmd(mtu)
+        self.cmd('ip route add default via %s' % self.gateway)
+
+def config(opts):
+    spine = opts.spine
+    leaf = opts.leaf
+    fanout = opts.fanout 
+    controllers= [ os.environ['OC%s' % i] for i in range(1,opts.onos+1) ] if (opts.onos) else ['127.0.0.1']
+    topo = LeafAndSpine(spine=spine, leaf=leaf, fanout=fanout)
+    net = Mininet(topo=topo, link=TCLink, build=False,
+                  switch=UserSwitch,
+                  controller = None,
+                  autoSetMacs = True)
+    i = 0
+    for ip in controllers:
+        net.addController( "c%s" % (i), controller=RemoteController, ip=ip)
+        i += 1;
+    net.build()
+    net.start()
+    CLI(net)
+    net.stop()
+
+if __name__ == '__main__':
+    setLogLevel('info')
+    config(opts)
+    os.system('sudo mn -c')
+
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/startUp.py b/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/startUp.py
new file mode 100644
index 0000000..bf2a2b6
--- /dev/null
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/dependencies/startUp.py
@@ -0,0 +1,38 @@
+"""
+    This wrapper function is use for starting up onos instance
+"""
+
+import time
+import os
+import json
+
+def onosBuild( main, gitBranch ):
+    """
+        This includes pulling ONOS and building it using maven install
+    """
+
+    buildResult = main.FALSE
+
+    # Git checkout a branch of ONOS
+    checkOutResult = main.ONOSbench.gitCheckout( gitBranch )
+    # Does the git pull on the branch that was checked out
+    if not checkOutResult:
+        main.log.warn( "Failed to checked out " + gitBranch +
+                                           " branch")
+    else:
+        main.log.info( "Successfully checked out " + gitBranch +
+                                           " branch")
+    gitPullResult = main.ONOSbench.gitPull()
+    if gitPullResult == main.ERROR:
+        main.log.error( "Error pulling git branch" )
+    else:
+        main.log.info( "Successfully pulled " + gitBranch + " branch" )
+
+    # Maven clean install
+    buildResult = main.ONOSbench.cleanInstall()
+
+    return buildResult
+
+
+
+