Configure quagga container with multiple interfaces to host peers for adding routes with different gateways.
Add vrouter test cases with multiple peers and test traffic to verify flows.
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index b2ce27c..ccc59b0 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -38,14 +38,7 @@
         self.image_name = image + ':' + tag
         self.id = None
         self.command = command
-        if quagga_config is not None:
-            self.bridge = quagga_config['bridge']
-            self.ipaddress = quagga_config['ip']
-            self.mask = quagga_config['mask']
-        else:
-            self.bridge = None
-            self.ipaddress = None
-            self.mask = None
+        self.quagga_config = quagga_config
 
     @classmethod
     def build_image(cls, dockerfile, tag, force=True, nocache=False):
@@ -118,36 +111,39 @@
                                          volumes = volumes, 
                                          host_config = host_config, stdin_open=stdin_open, tty = tty)
         self.dckr.start(container=self.name)
-        if self.bridge:
+        if self.quagga_config:
             self.connect_to_br()
         self.id = ctn['Id']
         return ctn
 
     def connect_to_br(self):
+        index = 0
         with docker_netns(self.name) as pid:
-            ip = IPRoute()
-            br = ip.link_lookup(ifname=self.bridge)
-            if len(br) == 0:
-                ip.link_create(ifname=self.bridge, kind='bridge')
-                br = ip.link_lookup(ifname=self.bridge)
-            br = br[0]
-            ip.link('set', index=br, state='up')
-
-            ifs = ip.link_lookup(ifname=self.name)
-            if len(ifs) > 0:
-               ip.link_remove(ifs[0])
-
-            ip.link_create(ifname=self.name, kind='veth', peer=pid)
-            host = ip.link_lookup(ifname=self.name)[0]
-            ip.link('set', index=host, master=br)
-            ip.link('set', index=host, state='up')
-            guest = ip.link_lookup(ifname=pid)[0]
-            ip.link('set', index=guest, net_ns_fd=pid)
-            with Namespace(pid, 'net'):
+            for quagga_config in self.quagga_config:
                 ip = IPRoute()
-                ip.link('set', index=guest, ifname='eth1')
-                ip.addr('add', index=guest, address=self.ipaddress, mask=self.mask)
-                ip.link('set', index=guest, state='up')
+                br = ip.link_lookup(ifname=quagga_config['bridge'])
+                if len(br) == 0:
+                    ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
+                    br = ip.link_lookup(ifname=quagga_config['bridge'])
+                br = br[0]
+                ip.link('set', index=br, state='up')
+                ifname = '{0}-{1}'.format(self.name, index)
+                ifs = ip.link_lookup(ifname=ifname)
+                if len(ifs) > 0:
+                   ip.link_remove(ifs[0])
+                peer_ifname = '{0}-{1}'.format(pid, index)
+                ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
+                host = ip.link_lookup(ifname=ifname)[0]
+                ip.link('set', index=host, master=br)
+                ip.link('set', index=host, state='up')
+                guest = ip.link_lookup(ifname=peer_ifname)[0]
+                ip.link('set', index=guest, net_ns_fd=pid)
+                with Namespace(pid, 'net'):
+                    ip = IPRoute()
+                    ip.link('set', index=guest, ifname='eth{}'.format(index+1))
+                    ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
+                    ip.link('set', index=guest, state='up')
+                index += 1
 
     def execute(self, cmd, tty = True, stream = False, shell = False):
         res = 0
@@ -168,7 +164,7 @@
 
 class Onos(Container):
 
-    quagga_config = { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }
+    quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, )
     env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,aaa,igmp,vrouter' }
     ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
     host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/onos-config')
@@ -234,7 +230,9 @@
                        host_config = host_config, tty = True)
 
 class Quagga(Container):
-    quagga_config = { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }
+    quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }, 
+                      { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
+                      )
     ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
     host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
     guest_quagga_config = '/root/config'
diff --git a/src/test/vrouter/vrouterTest.py b/src/test/vrouter/vrouterTest.py
index 8fd5adb..e4778fe 100644
--- a/src/test/vrouter/vrouterTest.py
+++ b/src/test/vrouter/vrouterTest.py
@@ -43,11 +43,11 @@
     test_path = os.path.dirname(os.path.realpath(__file__))
     quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
     onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
-    GATEWAY = '172.17.0.50'
+    GATEWAY = '192.168.10.50'
     INGRESS_PORT = 1
     EGRESS_PORT = 2
     MAX_PORTS = 100
-    peer_list = ['172.17.0.50', '172.17.0.51']
+    peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ]
     network_list = []
 
     @classmethod
@@ -97,7 +97,7 @@
     @classmethod
     def vrouter_host_load(cls):
         index = 1
-        for host in cls.peer_list:
+        for host,_ in cls.peer_list:
             iface = cls.port_map[index]
             index += 1
             config_cmds = ( 'ifconfig {0} {1}'.format(iface, host),
@@ -109,7 +109,7 @@
     @classmethod
     def vrouter_host_unload(cls):
         index = 1
-        for host in cls.peer_list:
+        for host,_ in cls.peer_list:
             iface = cls.port_map[index]
             index += 1
             config_cmds = ('ifconfig {} 0'.format(iface), )
@@ -181,13 +181,13 @@
     @classmethod
     def generate_vrouter_conf(cls, networks = 4, peers = 1):
         num = 0
-        start_peer = ( 172 << 24) | ( 17 << 16)  |  (0 << 8) | 100
-        end_peer =   ( 172 << 24 ) | (17 << 16)  |  (0 << 8) | 150
+        start_peer = ( 192 << 24) | ( 168 << 16)  |  (10 << 8) | 0
+        end_peer =   ( 200 << 24 ) | (168 << 16)  |  (10 << 8) | 0
         local_network = end_peer + 1
         ports_dict = { 'ports' : {} }
         interface_list = []
         peer_list = []
-        for n in xrange(start_peer, end_peer):
+        for n in xrange(start_peer, end_peer, 256):
             port_map = ports_dict['ports']
             port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
             device_port_key = '{0}/{1}'.format(cls.device_id, port)
@@ -196,12 +196,14 @@
             except:
                 port_map[device_port_key] = { 'interfaces' : [] }
                 interfaces = port_map[device_port_key]['interfaces']
-            ip = local_network + num
+            ip = n + 2
+            peer_ip = n + 1
             ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
-            peer = '%d.%d.%d.%d' % ( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ), n & 0xff )
-            peer_list.append(peer)
+            peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
+            mac = RandMAC()._fix()
+            peer_list.append((peer, mac))
             if num < cls.MAX_PORTS - 1:
-                interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : '00:00:00:00:00:01' }
+                interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
                 interfaces.append(interface_dict)
                 interface_list.append(interface_dict['name'])
             else:
@@ -233,14 +235,13 @@
         net_list = []
         peer_list = cls.peer_list
         network_list = []
-        for n in xrange(start_network, end_network):
-            if n & 255 == 0:
-                net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
-                network_list.append(net)
-                gateway = peer_list[num % len(peer_list)]
-                net_route = 'ip route {0}/24 {1}'.format(net, gateway)
-                net_list.append(net_route)
-                num += 1
+        for n in xrange(start_network, end_network, 256):
+            net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
+            network_list.append(net)
+            gateway = peer_list[num % len(peer_list)][0]
+            net_route = 'ip route {0}/24 {1}'.format(net, gateway)
+            net_list.append(net_route)
+            num += 1
             if num == networks:
                 break
         cls.network_list = network_list
@@ -301,7 +302,7 @@
             for i in xrange(num_ips):
                 octets[-1] = str(int(octets[-1]) + 1)
                 dst_ip = '.'.join(octets)
-                dst_mac = '00:00:00:00:00:01'
+                dst_mac = self.peer_list[ num % peers ] [1] #'00:00:00:00:00:01'
                 port = (num % peers)
                 ingress = port + 1
                 #Since peers are on the same network
@@ -329,42 +330,62 @@
 
     def test_vrouter_1(self):
         '''Test vrouter with 5 routes'''
-        res = self.__vrouter_network_verify(5)
+        res = self.__vrouter_network_verify(5, peers = 1)
         assert_equal(res, True)
 
     def test_vrouter_2(self):
-        '''Test vrouter with 50 routes'''
-        res = self.__vrouter_network_verify(50)
+        '''Test vrouter with 5 routes with 2 peers'''
+        res = self.__vrouter_network_verify(5, peers = 2)
         assert_equal(res, True)
 
     def test_vrouter_3(self):
-        '''Test vrouter with 100 routes'''
-        res = self.__vrouter_network_verify(100)
+        '''Test vrouter with 6 routes with 3 peers'''
+        res = self.__vrouter_network_verify(6, peers = 3)
         assert_equal(res, True)
 
     def test_vrouter_4(self):
-        '''Test vrouter with 300 routes'''
-        res = self.__vrouter_network_verify(300)
+        '''Test vrouter with 50 routes'''
+        res = self.__vrouter_network_verify(50, peers = 1)
         assert_equal(res, True)
 
     def test_vrouter_5(self):
+        '''Test vrouter with 50 routes and 5 peers'''
+        res = self.__vrouter_network_verify(50, peers = 5)
+        assert_equal(res, True)
+
+    def test_vrouter_6(self):
+        '''Test vrouter with 100 routes'''
+        res = self.__vrouter_network_verify(100, peers = 1)
+        assert_equal(res, True)
+
+    def test_vrouter_7(self):
+        '''Test vrouter with 100 routes and 10 peers'''
+        res = self.__vrouter_network_verify(100, peers = 10)
+        assert_equal(res, True)
+
+    def test_vrouter_8(self):
+        '''Test vrouter with 300 routes'''
+        res = self.__vrouter_network_verify(300, peers = 1)
+        assert_equal(res, True)
+
+    def test_vrouter_9(self):
         '''Test vrouter with 1000 routes'''
-        res = self.__vrouter_network_verify(1000)
+        res = self.__vrouter_network_verify(1000, peers = 1)
         assert_equal(res, True)
     
-    def test_vrouter_6(self):
+    def test_vrouter_10(self):
         '''Test vrouter with 10000 routes'''
-        res = self.__vrouter_network_verify(10000)
+        res = self.__vrouter_network_verify(10000, peers = 1)
         assert_equal(res, True)
     
     @nottest
-    def test_vrouter_7(self):
+    def test_vrouter_11(self):
         '''Test vrouter with 100000 routes'''
-        res = self.__vrouter_network_verify(100000)
+        res = self.__vrouter_network_verify(100000, peers = 1)
         assert_equal(res, True)
 
     @nottest
-    def test_vrouter_8(self):
+    def test_vrouter_12(self):
         '''Test vrouter with 1000000 routes'''
-        res = self.__vrouter_network_verify(1000000)
+        res = self.__vrouter_network_verify(1000000, peers = 1)
         assert_equal(res, True)