Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 2 | import random |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 3 | import socket |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 4 | import unittest |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 5 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 6 | from framework import VppTestCase, VppTestRunner |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 7 | from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 8 | |
| 9 | from scapy.packet import Raw |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 10 | from scapy.layers.l2 import Ether, Dot1Q |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 11 | from scapy.layers.inet import IP, UDP |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 12 | from util import ppp |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 13 | |
| 14 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 15 | class TestIPv4(VppTestCase): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 16 | """ IPv4 Test Case """ |
| 17 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 18 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 19 | """ |
| 20 | Perform test setup before test case. |
| 21 | |
| 22 | **Config:** |
| 23 | - create 3 pg interfaces |
| 24 | - untagged pg0 interface |
| 25 | - Dot1Q subinterface on pg1 |
| 26 | - Dot1AD subinterface on pg2 |
| 27 | - setup interfaces: |
| 28 | - put it into UP state |
| 29 | - set IPv4 addresses |
| 30 | - resolve neighbor address using ARP |
| 31 | - configure 200 fib entries |
| 32 | |
| 33 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 34 | :ivar dict flows: IPv4 packet flows in test. |
| 35 | :ivar list pg_if_packet_sizes: packet sizes in test. |
| 36 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 37 | super(TestIPv4, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 38 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 39 | # create 3 pg interfaces |
| 40 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 41 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 42 | # create 2 subinterfaces for pg1 and pg2 |
| 43 | self.sub_interfaces = [ |
| 44 | VppDot1QSubint(self, self.pg1, 100), |
| 45 | VppDot1ADSubint(self, self.pg2, 200, 300, 400)] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 46 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 47 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 48 | self.flows = dict() |
| 49 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 50 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 51 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 52 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 53 | # packet sizes |
| 54 | self.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 55 | self.sub_if_packet_sizes = [64, 512, 1518 + 4, 9018 + 4] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 56 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 57 | self.interfaces = list(self.pg_interfaces) |
| 58 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 59 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 60 | # setup all interfaces |
| 61 | for i in self.interfaces: |
| 62 | i.admin_up() |
| 63 | i.config_ip4() |
| 64 | i.resolve_arp() |
| 65 | |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 66 | # config 2M FIB entries |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 67 | self.config_fib_entries(200) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 68 | |
| 69 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 70 | """Run standard test teardown and log ``show ip arp``.""" |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 71 | super(TestIPv4, self).tearDown() |
| 72 | if not self.vpp_dead: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 73 | self.logger.info(self.vapi.cli("show ip arp")) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 74 | # info(self.vapi.cli("show ip fib")) # many entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 75 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 76 | def config_fib_entries(self, count): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 77 | """For each interface add to the FIB table *count* routes to |
| 78 | "10.0.0.1/32" destination with interface's local address as next-hop |
| 79 | address. |
| 80 | |
| 81 | :param int count: Number of FIB entries. |
| 82 | |
| 83 | - *TODO:* check if the next-hop address shouldn't be remote address |
| 84 | instead of local address. |
| 85 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 86 | n_int = len(self.interfaces) |
| 87 | percent = 0 |
| 88 | counter = 0.0 |
| 89 | dest_addr = socket.inet_pton(socket.AF_INET, "10.0.0.1") |
| 90 | dest_addr_len = 32 |
| 91 | for i in self.interfaces: |
| 92 | next_hop_address = i.local_ip4n |
| 93 | for j in range(count / n_int): |
| 94 | self.vapi.ip_add_del_route( |
| 95 | dest_addr, dest_addr_len, next_hop_address) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 96 | counter += 1 |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 97 | if counter / count * 100 > percent: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 98 | self.logger.info("Configure %d FIB entries .. %d%% done" % |
| 99 | (count, percent)) |
| 100 | percent += 1 |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 101 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 102 | def create_stream(self, src_if, packet_sizes): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 103 | """Create input packet stream for defined interface. |
| 104 | |
| 105 | :param VppInterface src_if: Interface to create packet stream for. |
| 106 | :param list packet_sizes: Required packet sizes. |
| 107 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 108 | pkts = [] |
| 109 | for i in range(0, 257): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 110 | dst_if = self.flows[src_if][i % 2] |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 111 | info = self.create_packet_info(src_if, dst_if) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 112 | payload = self.info_to_payload(info) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 113 | p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / |
| 114 | IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) / |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 115 | UDP(sport=1234, dport=1234) / |
| 116 | Raw(payload)) |
| 117 | info.data = p.copy() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 118 | if isinstance(src_if, VppSubInterface): |
| 119 | p = src_if.add_dot1_layer(p) |
| 120 | size = packet_sizes[(i // 2) % len(packet_sizes)] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 121 | self.extend_packet(p, size) |
| 122 | pkts.append(p) |
| 123 | return pkts |
| 124 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 125 | def verify_capture(self, dst_if, capture): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 126 | """Verify captured input packet stream for defined interface. |
| 127 | |
| 128 | :param VppInterface dst_if: Interface to verify captured packet stream |
| 129 | for. |
| 130 | :param list capture: Captured packet stream. |
| 131 | """ |
| 132 | self.logger.info("Verifying capture on interface %s" % dst_if.name) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 133 | last_info = dict() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 134 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 135 | last_info[i.sw_if_index] = None |
| 136 | is_sub_if = False |
| 137 | dst_sw_if_index = dst_if.sw_if_index |
| 138 | if hasattr(dst_if, 'parent'): |
| 139 | is_sub_if = True |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 140 | for packet in capture: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 141 | if is_sub_if: |
| 142 | # Check VLAN tags and Ethernet header |
| 143 | packet = dst_if.remove_dot1_layer(packet) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 144 | self.assertTrue(Dot1Q not in packet) |
| 145 | try: |
| 146 | ip = packet[IP] |
| 147 | udp = packet[UDP] |
| 148 | payload_info = self.payload_to_info(str(packet[Raw])) |
| 149 | packet_index = payload_info.index |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 150 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 151 | self.logger.debug("Got packet on port %s: src=%u (id=%u)" % |
| 152 | (dst_if.name, payload_info.src, packet_index)) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 153 | next_info = self.get_next_packet_info_for_interface2( |
| 154 | payload_info.src, dst_sw_if_index, |
| 155 | last_info[payload_info.src]) |
| 156 | last_info[payload_info.src] = next_info |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 157 | self.assertTrue(next_info is not None) |
| 158 | self.assertEqual(packet_index, next_info.index) |
| 159 | saved_packet = next_info.data |
| 160 | # Check standard fields |
| 161 | self.assertEqual(ip.src, saved_packet[IP].src) |
| 162 | self.assertEqual(ip.dst, saved_packet[IP].dst) |
| 163 | self.assertEqual(udp.sport, saved_packet[UDP].sport) |
| 164 | self.assertEqual(udp.dport, saved_packet[UDP].dport) |
| 165 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 166 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 167 | raise |
| 168 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 169 | remaining_packet = self.get_next_packet_info_for_interface2( |
| 170 | i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index]) |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 171 | self.assertTrue(remaining_packet is None, |
| 172 | "Interface %s: Packet expected from interface %s " |
| 173 | "didn't arrive" % (dst_if.name, i.name)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 174 | |
| 175 | def test_fib(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 176 | """ IPv4 FIB test |
| 177 | |
| 178 | Test scenario: |
| 179 | |
| 180 | - Create IPv4 stream for pg0 interface |
| 181 | - Create IPv4 tagged streams for pg1's and pg2's subinterface. |
| 182 | - Send and verify received packets on each interface. |
| 183 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 184 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 185 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes) |
| 186 | self.pg0.add_stream(pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 187 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 188 | for i in self.sub_interfaces: |
| 189 | pkts = self.create_stream(i, self.sub_if_packet_sizes) |
| 190 | i.parent.add_stream(pkts) |
| 191 | |
| 192 | self.pg_enable_capture(self.pg_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 193 | self.pg_start() |
| 194 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 195 | pkts = self.pg0.get_capture() |
| 196 | self.verify_capture(self.pg0, pkts) |
| 197 | |
| 198 | for i in self.sub_interfaces: |
| 199 | pkts = i.parent.get_capture() |
| 200 | self.verify_capture(i, pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 201 | |
| 202 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 203 | class TestIPv4FibCrud(VppTestCase): |
| 204 | """ FIB - add/update/delete - ip4 routes |
| 205 | |
| 206 | Test scenario: |
| 207 | - add 1k, |
| 208 | - del 100, |
| 209 | - add new 1k, |
| 210 | - del 1.5k |
| 211 | |
| 212 | ..note:: Python API is to slow to add many routes, needs C code replacement. |
| 213 | """ |
| 214 | |
| 215 | def config_fib_many_to_one(self, start_dest_addr, next_hop_addr, count): |
| 216 | """ |
| 217 | |
| 218 | :param start_dest_addr: |
| 219 | :param next_hop_addr: |
| 220 | :param count: |
| 221 | :return list: added ips with 32 prefix |
| 222 | """ |
| 223 | added_ips = [] |
| 224 | dest_addr = int( |
| 225 | socket.inet_pton(socket.AF_INET, start_dest_addr).encode('hex'), 16) |
| 226 | dest_addr_len = 32 |
| 227 | n_next_hop_addr = socket.inet_pton(socket.AF_INET, next_hop_addr) |
| 228 | for _ in range(count): |
| 229 | n_dest_addr = '{:08x}'.format(dest_addr).decode('hex') |
| 230 | self.vapi.ip_add_del_route(n_dest_addr, dest_addr_len, |
| 231 | n_next_hop_addr) |
| 232 | added_ips.append(socket.inet_ntoa(n_dest_addr)) |
| 233 | dest_addr += 1 |
| 234 | return added_ips |
| 235 | |
| 236 | def unconfig_fib_many_to_one(self, start_dest_addr, next_hop_addr, count): |
| 237 | |
| 238 | removed_ips = [] |
| 239 | dest_addr = int( |
| 240 | socket.inet_pton(socket.AF_INET, start_dest_addr).encode('hex'), 16) |
| 241 | dest_addr_len = 32 |
| 242 | n_next_hop_addr = socket.inet_pton(socket.AF_INET, next_hop_addr) |
| 243 | for _ in range(count): |
| 244 | n_dest_addr = '{:08x}'.format(dest_addr).decode('hex') |
| 245 | self.vapi.ip_add_del_route(n_dest_addr, dest_addr_len, |
| 246 | n_next_hop_addr, is_add=0) |
| 247 | removed_ips.append(socket.inet_ntoa(n_dest_addr)) |
| 248 | dest_addr += 1 |
| 249 | return removed_ips |
| 250 | |
| 251 | def create_stream(self, src_if, dst_if, dst_ips, count): |
| 252 | pkts = [] |
| 253 | |
| 254 | for _ in range(count): |
| 255 | dst_addr = random.choice(dst_ips) |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 256 | info = self.create_packet_info(src_if, dst_if) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 257 | payload = self.info_to_payload(info) |
| 258 | p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / |
| 259 | IP(src=src_if.remote_ip4, dst=dst_addr) / |
| 260 | UDP(sport=1234, dport=1234) / |
| 261 | Raw(payload)) |
| 262 | info.data = p.copy() |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 263 | self.extend_packet(p, random.choice(self.pg_if_packet_sizes)) |
| 264 | pkts.append(p) |
| 265 | |
| 266 | return pkts |
| 267 | |
| 268 | def _find_ip_match(self, find_in, pkt): |
| 269 | for p in find_in: |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 270 | if self.payload_to_info(str(p[Raw])) == \ |
| 271 | self.payload_to_info(str(pkt[Raw])): |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 272 | if p[IP].src != pkt[IP].src: |
| 273 | break |
| 274 | if p[IP].dst != pkt[IP].dst: |
| 275 | break |
| 276 | if p[UDP].sport != pkt[UDP].sport: |
| 277 | break |
| 278 | if p[UDP].dport != pkt[UDP].dport: |
| 279 | break |
| 280 | return p |
| 281 | return None |
| 282 | |
| 283 | @staticmethod |
| 284 | def _match_route_detail(route_detail, ip, address_length=32, table_id=0): |
| 285 | if route_detail.address == socket.inet_pton(socket.AF_INET, ip): |
| 286 | if route_detail.table_id != table_id: |
| 287 | return False |
| 288 | elif route_detail.address_length != address_length: |
| 289 | return False |
| 290 | else: |
| 291 | return True |
| 292 | else: |
| 293 | return False |
| 294 | |
| 295 | def verify_capture(self, dst_interface, received_pkts, expected_pkts): |
| 296 | self.assertEqual(len(received_pkts), len(expected_pkts)) |
| 297 | to_verify = list(expected_pkts) |
| 298 | for p in received_pkts: |
| 299 | self.assertEqual(p.src, dst_interface.local_mac) |
| 300 | self.assertEqual(p.dst, dst_interface.remote_mac) |
| 301 | x = self._find_ip_match(to_verify, p) |
| 302 | to_verify.remove(x) |
| 303 | self.assertListEqual(to_verify, []) |
| 304 | |
| 305 | def verify_route_dump(self, fib_dump, ips): |
| 306 | |
| 307 | def _ip_in_route_dump(ip, fib_dump): |
| 308 | return next((route for route in fib_dump |
| 309 | if self._match_route_detail(route, ip)), |
| 310 | False) |
| 311 | |
| 312 | for ip in ips: |
| 313 | self.assertTrue(_ip_in_route_dump(ip, fib_dump), |
| 314 | 'IP {} is not in fib dump.'.format(ip)) |
| 315 | |
| 316 | def verify_not_in_route_dump(self, fib_dump, ips): |
| 317 | |
| 318 | def _ip_in_route_dump(ip, fib_dump): |
| 319 | return next((route for route in fib_dump |
| 320 | if self._match_route_detail(route, ip)), |
| 321 | False) |
| 322 | |
| 323 | for ip in ips: |
| 324 | self.assertFalse(_ip_in_route_dump(ip, fib_dump), |
| 325 | 'IP {} is in fib dump.'.format(ip)) |
| 326 | |
| 327 | @classmethod |
| 328 | def setUpClass(cls): |
| 329 | """ |
| 330 | #. Create and initialize 3 pg interfaces. |
| 331 | #. initialize class attributes configured_routes and deleted_routes |
| 332 | to store information between tests. |
| 333 | """ |
| 334 | super(TestIPv4FibCrud, cls).setUpClass() |
| 335 | |
| 336 | try: |
| 337 | # create 3 pg interfaces |
| 338 | cls.create_pg_interfaces(range(3)) |
| 339 | |
| 340 | cls.interfaces = list(cls.pg_interfaces) |
| 341 | |
| 342 | # setup all interfaces |
| 343 | for i in cls.interfaces: |
| 344 | i.admin_up() |
| 345 | i.config_ip4() |
| 346 | i.resolve_arp() |
| 347 | |
| 348 | cls.configured_routes = [] |
| 349 | cls.deleted_routes = [] |
| 350 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 351 | |
| 352 | except Exception: |
| 353 | super(TestIPv4FibCrud, cls).tearDownClass() |
| 354 | raise |
| 355 | |
| 356 | def setUp(self): |
| 357 | super(TestIPv4FibCrud, self).setUp() |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 358 | self.reset_packet_infos() |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 359 | |
| 360 | def test_1_add_routes(self): |
| 361 | """ Add 1k routes |
| 362 | |
| 363 | - add 100 routes check with traffic script. |
| 364 | """ |
| 365 | # config 1M FIB entries |
| 366 | self.configured_routes.extend(self.config_fib_many_to_one( |
| 367 | "10.0.0.0", self.pg0.remote_ip4, 100)) |
| 368 | |
| 369 | fib_dump = self.vapi.ip_fib_dump() |
| 370 | self.verify_route_dump(fib_dump, self.configured_routes) |
| 371 | |
| 372 | self.stream_1 = self.create_stream( |
| 373 | self.pg1, self.pg0, self.configured_routes, 100) |
| 374 | self.stream_2 = self.create_stream( |
| 375 | self.pg2, self.pg0, self.configured_routes, 100) |
| 376 | self.pg1.add_stream(self.stream_1) |
| 377 | self.pg2.add_stream(self.stream_2) |
| 378 | |
| 379 | self.pg_enable_capture(self.pg_interfaces) |
| 380 | self.pg_start() |
| 381 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 382 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 383 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 384 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 385 | def test_2_del_routes(self): |
| 386 | """ Delete 100 routes |
| 387 | |
| 388 | - delete 10 routes check with traffic script. |
| 389 | """ |
| 390 | self.deleted_routes.extend(self.unconfig_fib_many_to_one( |
| 391 | "10.0.0.10", self.pg0.remote_ip4, 10)) |
| 392 | for x in self.deleted_routes: |
| 393 | self.configured_routes.remove(x) |
| 394 | |
| 395 | fib_dump = self.vapi.ip_fib_dump() |
| 396 | self.verify_route_dump(fib_dump, self.configured_routes) |
| 397 | |
| 398 | self.stream_1 = self.create_stream( |
| 399 | self.pg1, self.pg0, self.configured_routes, 100) |
| 400 | self.stream_2 = self.create_stream( |
| 401 | self.pg2, self.pg0, self.configured_routes, 100) |
| 402 | self.stream_3 = self.create_stream( |
| 403 | self.pg1, self.pg0, self.deleted_routes, 100) |
| 404 | self.stream_4 = self.create_stream( |
| 405 | self.pg2, self.pg0, self.deleted_routes, 100) |
| 406 | self.pg1.add_stream(self.stream_1 + self.stream_3) |
| 407 | self.pg2.add_stream(self.stream_2 + self.stream_4) |
| 408 | self.pg_enable_capture(self.pg_interfaces) |
| 409 | self.pg_start() |
| 410 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 411 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 412 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 413 | |
| 414 | def test_3_add_new_routes(self): |
| 415 | """ Add 1k routes |
| 416 | |
| 417 | - re-add 5 routes check with traffic script. |
| 418 | - add 100 routes check with traffic script. |
| 419 | """ |
| 420 | tmp = self.config_fib_many_to_one( |
| 421 | "10.0.0.10", self.pg0.remote_ip4, 5) |
| 422 | self.configured_routes.extend(tmp) |
| 423 | for x in tmp: |
| 424 | self.deleted_routes.remove(x) |
| 425 | |
| 426 | self.configured_routes.extend(self.config_fib_many_to_one( |
| 427 | "10.0.1.0", self.pg0.remote_ip4, 100)) |
| 428 | |
| 429 | fib_dump = self.vapi.ip_fib_dump() |
| 430 | self.verify_route_dump(fib_dump, self.configured_routes) |
| 431 | |
| 432 | self.stream_1 = self.create_stream( |
| 433 | self.pg1, self.pg0, self.configured_routes, 300) |
| 434 | self.stream_2 = self.create_stream( |
| 435 | self.pg2, self.pg0, self.configured_routes, 300) |
| 436 | self.stream_3 = self.create_stream( |
| 437 | self.pg1, self.pg0, self.deleted_routes, 100) |
| 438 | self.stream_4 = self.create_stream( |
| 439 | self.pg2, self.pg0, self.deleted_routes, 100) |
| 440 | |
| 441 | self.pg1.add_stream(self.stream_1 + self.stream_3) |
| 442 | self.pg2.add_stream(self.stream_2 + self.stream_4) |
| 443 | self.pg_enable_capture(self.pg_interfaces) |
| 444 | self.pg_start() |
| 445 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 446 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 447 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 448 | |
| 449 | def test_4_del_routes(self): |
| 450 | """ Delete 1.5k routes |
| 451 | |
| 452 | - delete 5 routes check with traffic script. |
| 453 | - add 100 routes check with traffic script. |
| 454 | """ |
| 455 | self.deleted_routes.extend(self.unconfig_fib_many_to_one( |
| 456 | "10.0.0.0", self.pg0.remote_ip4, 15)) |
| 457 | self.deleted_routes.extend(self.unconfig_fib_many_to_one( |
| 458 | "10.0.0.20", self.pg0.remote_ip4, 85)) |
| 459 | self.deleted_routes.extend(self.unconfig_fib_many_to_one( |
| 460 | "10.0.1.0", self.pg0.remote_ip4, 100)) |
| 461 | fib_dump = self.vapi.ip_fib_dump() |
| 462 | self.verify_not_in_route_dump(fib_dump, self.deleted_routes) |
| 463 | |
| 464 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 465 | if __name__ == '__main__': |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 466 | unittest.main(testRunner=VppTestRunner) |