Changeset 5712

Show
Ignore:
Timestamp:
07/06/10 00:13:02 (3 years ago)
Author:
kosma
Message:

test_models.py: a uniform method of choosing local IP that works on Linux/BSD/Windows

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • umpa/branches/link-layer-integration/tests/a_unit/test_extensions/test_models.py

    r5711 r5712  
    3636    # Windows doesn't have a loopback interface and wants us to send 
    3737    # from a valid local address 
    38     revhosts_ip = '127.0.0.1' 
     38    local_ip = '127.0.0.1' 
    3939else: 
    4040    # other OSes have a loopback interface (which we don't want to use here) 
    4141    # and allow us to use any IP we like 
    42     revhosts_ip = '1.2.3.4' 
     42    local_ip = '1.2.3.4' 
    4343 
    4444class SniffThread(threading.Thread): 
     
    5454                                            filter=self._filter) 
    5555        try: 
    56             assert pkt[0].ip.src == "1.2.3.4" 
     56            assert pkt[0].ip.src == local_ip 
    5757            assert pkt[0].ip.dst == "8.8.8.8" 
    5858            assert pkt[0].tcp.srcport == 80 
    5959            assert pkt[0].tcp.dstport == 0 
    60             assert pkt[1].ip.src == "1.2.3.4" 
     60            assert pkt[1].ip.src == local_ip 
    6161            assert pkt[1].ip.dst == "8.8.8.8" 
    6262            assert pkt[1].tcp.srcport == 0 
     
    7070                                            filter=self._filter) 
    7171        try: 
    72             assert pkt[0].ip.src == "127.0.0.1" 
     72            assert pkt[0].ip.src == local_ip 
    7373            assert pkt[0].ip.dst == "8.8.8.8" 
    7474            assert pkt[0].udp.srcport == 80 
    7575            assert pkt[0].udp.dstport == 0 
    76             assert pkt[1].ip.src == "127.0.0.1" 
     76            assert pkt[1].ip.src == local_ip 
    7777            assert pkt[1].ip.dst == "8.8.8.8" 
    7878            assert pkt[1].udp.srcport == 0 
     
    8686        try: 
    8787            assert pkt[0].ip.src == "8.8.8.8" 
    88             assert pkt[0].ip.dst == revhosts_ip 
    89             assert pkt[1].ip.src == revhosts_ip 
     88            assert pkt[0].ip.dst == local_ip 
     89            assert pkt[1].ip.src == local_ip 
    9090            assert pkt[1].ip.dst == "8.8.8.8" 
    9191        except Exception, e: 
     
    9696        pkt = umit.umpa.sniffing.sniff(2, device=self._device, filter=self._filter) 
    9797        try: 
    98             assert pkt[0].ip.src == "127.0.0.1" 
     98            assert pkt[0].ip.src == local_ip 
    9999            assert pkt[0].ip.dst == "8.8.8.8" 
    100             assert pkt[1].ip.src == "127.0.0.1" 
     100            assert pkt[1].ip.src == local_ip 
    101101            assert pkt[1].ip.dst == "8.8.4.4" 
    102102        except Exception, e: 
     
    130130        queue = Queue.Queue() 
    131131 
    132         th = SendPacket(umit.umpa.Packet(IP(src='1.2.3.4', dst='8.8.8.8'), 
     132        th = SendPacket(umit.umpa.Packet(IP(src=local_ip, dst='8.8.8.8'), 
    133133                                         TCP(srcport=80, dstport=0))) 
    134134        th.start() 
     
    154154        queue = Queue.Queue() 
    155155 
    156         th = SendPacket(umit.umpa.Packet(IP(src='127.0.0.1', dst='8.8.8.8'), 
     156        th = SendPacket(umit.umpa.Packet(IP(src=local_ip, dst='8.8.8.8'), 
    157157                                         UDP(srcport=80, dstport=0))) 
    158158        th.start() 
     
    175175        queue = Queue.Queue() 
    176176 
    177         th = SendPacket(umit.umpa.Packet(IP(src="8.8.8.8", dst=revhosts_ip), 
     177        th = SendPacket(umit.umpa.Packet(IP(src="8.8.8.8", dst=local_ip), 
    178178                                         UDP(srcport=80, dstport=0))) 
    179179        th.start() 
     
    196196        queue = Queue.Queue() 
    197197 
    198         th = SendPacket(umit.umpa.Packet(IP(src="127.0.0.1",  
     198        th = SendPacket(umit.umpa.Packet(IP(src=local_ip,  
    199199                        dst="8.8.8.8"), UDP(srcport=888))) 
    200200        th.start() 
    201201         
    202202        th2 = ForwardThread( 
    203                 "host 127.0.0.1 and port 888 and udp", 
     203                "host %s and port 888 and udp" % local_ip, 
    204204                self.device, queue) 
    205205        th2.start() 
    206206        models.react(1, 
    207             filter="host 127.0.0.1 and port 888 and udp", 
     207            filter="host %s and port 888 and udp" % local_ip, 
    208208            device=self.device, forward="8.8.4.4") 
    209209        th.join() 
     
    221221 
    222222            th = SendPacket(umit.umpa.Packet( 
    223                 IP(src="127.0.0.1", dst="8.8.8.8", ttl=ttl), 
     223                IP(src=local_ip, dst="8.8.8.8", ttl=ttl), 
    224224                UDP(srcport=888))) 
    225225            th.start() 
    226226             
    227227            th2 = TTLThread( 
    228                     "host 127.0.0.1 and port 888 and udp", 
     228                    "host 8.8.8.8 and port 888 and udp", 
    229229                    self.device, queue, begin=ttl, decrement=decrement) 
    230230            th2.start() 
    231231            models.react(1, 
    232                 filter="host 127.0.0.1 and port 888 and udp", 
     232                filter="host 8.8.8.8 and port 888 and udp", 
    233233                device=self.device, 
    234234                ttl=decrement)