Exemple #1
0
 def testHandleSouthInco2(self):
    '''
    test handle arp request, not query gw, should be ignored
    '''
    req = dpkt.arp.ARP()
    req.op = dpkt.arp.ARP_OP_REQUEST
    req.sha = mac_aton("00:00:00:00:00:01")
    req.spa = socket.inet_aton("192.0.1.11")
    req.tha = mac_aton("ff:ff:ff:ff:ff:ff")  #don't care
    req.tpa = socket.inet_aton("192.0.0.2")  #where is 192.0.0.2 
    self.arp_stack.handle_south_inco(req)
    rsp = self.eth_stack.eth_pkg
    self.assertEqual(rsp, None)
    nmac = self.arp_stack.get_mac_addr(socket.inet_aton("192.0.1.11"))
    self.assertEqual(nmac, mac_aton("00:00:00:00:00:01"))
    return 
Exemple #2
0
 def testHandleSouthInco1(self):
    '''
    test handle arp request
    '''
    req = dpkt.arp.ARP()
    req.op = dpkt.arp.ARP_OP_REQUEST
    req.sha = mac_aton("00:00:00:00:00:01")
    req.spa = socket.inet_aton("192.0.1.11")
    req.tha = mac_aton("ff:ff:ff:ff:ff:ff")  #don't care
    req.tpa = socket.inet_aton("192.0.0.1")  #where is 192.0.0.1 
    self.arp_stack.handle_south_inco(req)
    rsp = self.eth_stack.eth_pkg
    self.assertEqual(rsp.op, dpkt.arp.ARP_OP_REPLY)
    self.assertEqual(rsp.sha, mac_aton(self._GW_MAC))
    self.assertEqual(rsp.spa, socket.inet_aton(self._GW_IP))
    self.assertEqual(rsp.tha, mac_aton("00:00:00:00:00:01"))
    self.assertEqual(rsp.tpa, socket.inet_aton("192.0.1.11"))
    nmac = self.arp_stack.get_mac_addr(socket.inet_aton("192.0.1.11"))
    self.assertEqual(nmac, mac_aton("00:00:00:00:00:01"))
    return 
Exemple #3
0
import logging
logging.basicConfig(level=logging.DEBUG)

class MockIpStack:
   def __init__(self):
      self.ip_pkg = None
   def handle_south_inco(self, ip_pkg):
      self.ip_pkg = ip_pkg

class MockArpStack:
   def __init__(self):
      self.arp_pkg = None
   def handle_south_inco(self, arp_pkg):
      self.arp_pkg = arp_pkg

MAC=mac_aton("50:00:00:00:00:01")

class EthTest(unittest.TestCase):
   def setUp(self):
      self.eth_stack = EthStack(MAC)
      self.ip_stack = MockIpStack()
      self.arp_stack = MockArpStack()
      self.eth_stack.set_ip_stack(self.ip_stack)
      self.eth_stack.set_arp_stack(self.arp_stack)
      return

   def tearDown(self):
      return


   def testHandleSouthInco1(self):
Exemple #4
0
 def testGetSetArpCache(self):
    self.arp_stack._add_arp_entry(socket.inet_aton("127.0.0.1"),
                                  mac_aton("50:00:00:00:00:01"))
    nmac = self.arp_stack.get_mac_addr(socket.inet_aton("127.0.0.1"))
    self.assertEqual(nmac, mac_aton("50:00:00:00:00:01"))
Exemple #5
0
 def testMacAton(self):
    amac = "50:00:00:00:00:01"
    nmac = utils.mac_aton(amac)
    self.assertEqual(nmac, str(bytearray([0x50, 0x00, 0x00, 0x00, 0x00, 0x01])))