- i += 1
- start_nr = macs_per_if * i + start
- end_nr = count + start if i == (n_int - 1) \
- else macs_per_if * (i + 1) + start
- hosts = self.hosts_by_pg_idx[pg_if.sw_if_index]
- for j in range(start_nr, end_nr):
- host = Host(
- "00:00:00:ff:%02x:%02x" % (pg_if.sw_if_index, j),
- "172.17.1%02x.%u" % (pg_if.sw_if_index, j))
- hosts.append(host)
-
- def config_l2_fib_entries(self, count, start=0):
+ swif = pg_if.sw_if_index
+
+ def mac(j): return "00:00:%02x:ff:%02x:%02x" % (subnet, swif, j)
+
+ def ip(j): return "172.%02u.1%02x.%u" % (subnet, swif, j)
+
+ def h(j): return Host(mac(j), ip(j))
+ hosts[swif] = [h(j) for j in range(n_hosts_per_if)]
+ return hosts
+
+ def split_hosts(self, hosts, n):
+ splits = dict()
+ for pg_if in self.pg_interfaces:
+ swif = pg_if.sw_if_index
+ splits[swif] = hosts[swif][:n]
+ hosts[swif] = hosts[swif][n:]
+ return splits
+
+ def learn_hosts(self, bd_id, hosts):
+ """
+ Create and send per interface L2 MAC broadcast packet stream to
+ let the bridge domain learn these MAC addresses.
+
+ :param int bd_id: BD to teach
+ :param dict hosts: dict of hosts per interface
+ """
+ self.vapi.bridge_flags(bd_id=bd_id, is_set=1, flags=1)
+ ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
+ for pg_if in ifs:
+ swif = pg_if.sw_if_index
+ packets = [Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac)
+ for host in hosts[swif]]
+ pg_if.add_stream(packets)
+ self.logger.info("Sending broadcast eth frames for MAC learning")
+ self.pg_start()
+
+ def config_l2_fib_entries(self, bd_id, hosts):