Create input packet stream for defined interface using hosts list. :param object src_if: Interface to create packet stream for. :param list packet_sizes: List of required packet sizes. :return: Stream of packets.
(self, src_if, packet_sizes)
| 204 | self.pg_in_xc.remove(rx_if) |
| 205 | |
| 206 | def create_stream(self, src_if, packet_sizes): |
| 207 | """ |
| 208 | Create input packet stream for defined interface using hosts list. |
| 209 | |
| 210 | :param object src_if: Interface to create packet stream for. |
| 211 | :param list packet_sizes: List of required packet sizes. |
| 212 | :return: Stream of packets. |
| 213 | """ |
| 214 | pkts = [] |
| 215 | src_hosts = self.hosts_by_pg_idx[src_if.sw_if_index] |
| 216 | for dst_if in self.flows[src_if]: |
| 217 | dst_hosts = self.hosts_by_pg_idx[dst_if.sw_if_index] |
| 218 | n_int = len(dst_hosts) |
| 219 | for i in range(0, n_int): |
| 220 | dst_host = dst_hosts[i] |
| 221 | src_host = random.choice(src_hosts) |
| 222 | pkt_info = self.create_packet_info(src_if, dst_if) |
| 223 | payload = self.info_to_payload(pkt_info) |
| 224 | p = ( |
| 225 | Ether(dst=dst_host.mac, src=src_host.mac) |
| 226 | / IP(src=src_host.ip4, dst=dst_host.ip4) |
| 227 | / UDP(sport=1234, dport=1234) |
| 228 | / Raw(payload) |
| 229 | ) |
| 230 | pkt_info.data = p.copy() |
| 231 | size = random.choice(packet_sizes) |
| 232 | self.extend_packet(p, size) |
| 233 | pkts.append(p) |
| 234 | self.logger.debug( |
| 235 | "Input stream created for port %s. Length: %u pkt(s)" |
| 236 | % (src_if.name, len(pkts)) |
| 237 | ) |
| 238 | return pkts |
| 239 | |
| 240 | def verify_capture(self, pg_if, capture): |
| 241 | """ |
no test coverage detected