Configure the right jvm heap size to support more than 3 cluster instances of ONOS in cord-tester.

Change-Id: I1484c3f9d8012b33f31320d0ded480f71697966a
diff --git a/src/test/setup/cord-test.py b/src/test/setup/cord-test.py
index b182ea1..6cb542c 100755
--- a/src/test/setup/cord-test.py
+++ b/src/test/setup/cord-test.py
@@ -430,7 +430,7 @@
         data_volume = '{}-data'.format(Onos.NAME) if args.shared_volume else None
         onos = Onos(image = Onos.IMAGE,
                     tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
-                    data_volume = data_volume, async = async_mode)
+                    data_volume = data_volume, async = async_mode, max_instances = args.onos_instances)
         if onos.running:
             onos_ip = onos.ipaddr
             onos_ips.append(onos_ip)
@@ -446,7 +446,8 @@
             data_volume = '{}-data'.format(name) if args.shared_volume else None
             quagga_config = Onos.get_quagga_config(i)
             onos = Onos(name = name, image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
-                        data_volume = data_volume, async = async_mode, quagga_config = quagga_config)
+                        data_volume = data_volume, async = async_mode,
+                        quagga_config = quagga_config, max_instances = args.onos_instances)
             onos_instances.append(onos)
             if onos.running:
                 onos_ips.append(onos.ipaddr)
@@ -680,7 +681,7 @@
     if onos_ip is None:
         data_volume = '{}-data'.format(Onos.NAME) if args.shared_volume else None
         onos = Onos(image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
-                    data_volume = data_volume, async = async_mode)
+                    data_volume = data_volume, async = async_mode, max_instances = args.onos_instances)
         if onos.running:
             onos_ip = onos.ipaddr
             onos_ips.append(onos_ip)
@@ -696,7 +697,8 @@
             data_volume = '{}-data'.format(name) if args.shared_volume else None
             quagga_config = Onos.get_quagga_config(i)
             onos = Onos(name = name, image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
-                        data_volume = data_volume, async = async_mode, quagga_config = quagga_config)
+                        data_volume = data_volume, async = async_mode,
+                        quagga_config = quagga_config, max_instances = args.onos_instances)
             onos_instances.append(onos)
             if onos.running:
                 onos_ips.append(onos.ipaddr)
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index 3b62f68..d98bbe0 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -403,7 +403,7 @@
 
     def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
                  boot_delay = 20, restart = False, network_cfg = None,
-                 cluster = False, data_volume = None, async = False, quagga_config = None):
+                 cluster = False, data_volume = None, async = False, quagga_config = None, max_instances=1):
         if restart is True:
             ##Find the right image to restart
             running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
@@ -417,11 +417,18 @@
         if quagga_config is not None:
             self.quagga_config = quagga_config
         super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
+        self.max_instances = max_instances
         self.boot_delay = boot_delay
         self.data_map = None
         if cluster is True:
             self.ports = []
-            self.env['JAVA_OPTS'] = self.JAVA_OPTS_CLUSTER
+            if self.max_instances <= 3:
+                java_opts = self.JAVA_OPTS_CLUSTER
+            else:
+                instance_memory = (get_mem(instances=self.max_instances),) * 2
+                java_opts = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*instance_memory)
+
+            self.env['JAVA_OPTS'] = java_opts
             if data_volume is not None:
                 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
                 self.host_guest_map = self.host_guest_map + self.data_map