コード例 #1
0
 def testHostnames4(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     hosts = host.Hosts()
     self.assertEqual(3, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         cid = h.X_CATAWAMPUS_ORG_ClientIdentification
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('192.168.1.1', h.IPAddress)
             self.assertEqual('dnssd_hostname4_1.local', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME4_1', cid.NetbiosName)
             self.assertEqual('ABCDEF', cid.Anonid)
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:02':
             self.assertEqual('192.168.1.2', h.IPAddress)
             self.assertEqual('dnssd_hostname4_2.local', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME4_2', cid.NetbiosName)
             self.assertEqual('dnssd_hostname4_2', h.HostName)
             self.assertEqual('GHIJKL', cid.Anonid)
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('192.168.1.3', h.IPAddress)
             self.assertEqual('', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME4_3', cid.NetbiosName)
             self.assertEqual('NETBIOS_HOSTNAME4_3', h.HostName)
             # testdata/host/anonid fails for this MAC
             self.assertEqual('XXXXXX', cid.Anonid)
             found |= 4
     self.assertEqual(7, found)
コード例 #2
0
 def testHostnames6(self):
     host.IP6NEIGH[0] = 'testdata/host/ip6neigh'
     hosts = host.Hosts()
     self.assertEqual(3, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         cid = h.X_CATAWAMPUS_ORG_ClientIdentification
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('fe80::fa8f:caff:fe00:1', h.IPAddress)
             self.assertEqual('dnssd_hostname6_1.local', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME6_1', cid.NetbiosName)
             self.assertEqual('ABCDEF', cid.Anonid)
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:02':
             self.assertEqual('fe80::fa8f:caff:fe00:2', h.IPAddress)
             self.assertEqual('dnssd_hostname6_2.local', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME6_2', cid.NetbiosName)
             self.assertEqual('dnssd_hostname6_2', h.HostName)
             self.assertEqual('GHIJKL', cid.Anonid)
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('fe80::fa8f:caff:fe00:3', h.IPAddress)
             self.assertEqual('', cid.DnsSdName)
             self.assertEqual('NETBIOS_HOSTNAME6_3', cid.NetbiosName)
             self.assertEqual('NETBIOS_HOSTNAME6_3', h.HostName)
             # testdata/host/anonid fails for this MAC
             self.assertEqual('XXXXXX', cid.Anonid)
             found |= 4
     self.assertEqual(7, found)
コード例 #3
0
 def testGetHostsFromIp6Neigh(self):
     host.IP6NEIGH[0] = 'testdata/host/ip6neigh'
     iflookup = {
         'foo0': 'Device.Foo.Interface.1',
         'foo1': 'Device.Foo.Interface.2'
     }
     hosts = host.Hosts(iflookup)
     self.assertEqual(3, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('Device.Foo.Interface.1', h.Layer1Interface)
             self.assertEqual('fe80::fa8f:caff:fe00:1', h.IPAddress)
             self.assertTrue(h.Active)
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:02':
             self.assertEqual('Device.Foo.Interface.1', h.Layer1Interface)
             self.assertEqual('fe80::fa8f:caff:fe00:2', h.IPAddress)
             self.assertFalse(h.Active)
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('Device.Foo.Interface.2', h.Layer1Interface)
             self.assertEqual('fe80::fa8f:caff:fe00:3', h.IPAddress)
             self.assertTrue(h.Active)
             found |= 4
     self.assertEqual(7, found)
コード例 #4
0
 def testHostsFromBridge(self):
     iflookup = {'eth0': 'Ethernet', 'eth1.0': 'MoCA'}
     h = host.Hosts(iflookup, bridgename='br0')
     self.assertEqual(10, len(h.HostList))
     tr.handle.ValidateExports(h)
     # brforward file taken from a real system in the lab
     expected = {
         'e8:39:35:b8:66:c8': 'Ethernet',
         '68:05:ca:16:2a:90': 'Ethernet',
         '28:c0:da:3a:b4:15': 'Ethernet',
         'f8:8f:ca:00:c4:47': 'MoCA',
         'f8:8f:ca:00:da:6c': 'Ethernet',
         'f8:8f:ca:09:4e:25': 'MoCA',
         'f8:8f:ca:00:c2:df': 'Ethernet',
         'f8:8f:ca:00:c2:47': 'Ethernet',
         '00:00:de:ad:be:ef': 'Ethernet',
         'ac:4b:c8:7e:32:04': 'Ethernet',
     }
     for entry in h.HostList.values():
         self.assertTrue(entry.PhysAddress in expected)
         self.assertEqual(expected[entry.PhysAddress],
                          entry.Layer1Interface)
         self.assertTrue(entry.Active)
         del expected[entry.PhysAddress]
         tr.handle.ValidateExports(entry)
     self.assertEqual(0, len(expected))
コード例 #5
0
 def testEmptyDhcpTaxonomyFile(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     host.DHCP_TAXONOMY_FILE = 'testdata/host/dhcp-taxonomy-empty'
     hosts = host.Hosts()
     self.assertEqual(3, len(hosts.HostList))
     for h in hosts.HostList.values():
         fp = h.X_CATAWAMPUS_ORG_ClientIdentification.DhcpTaxonomy
         self.assertEqual('', fp)
コード例 #6
0
 def __init__(self, dmroot):
     super(Device, self).__init__()
     self.DHCPv4 = dnsmasq.DHCPv4(dmroot=dmroot)
     self.Ethernet = Ethernet()
     self.Hosts = host.Hosts(dmroot=dmroot, bridgename='br0')
     self.MoCA = MoCA()
     self.Export(['DHCPv4', 'Ethernet', 'Hosts', 'MoCA'])
     pool = self.DHCPv4.Server.Pool()
     pool.MinAddress = '192.168.1.1'
     pool.MaxAddress = '192.168.1.255'
     self.DHCPv4.Server.PoolList['1'] = pool
コード例 #7
0
 def testBadAnonidCommand(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     host.ANONID[0] = '/no/such/command'
     hosts = host.Hosts()
     found = False
     for h in hosts.HostList.values():
         cid = h.X_CATAWAMPUS_ORG_ClientIdentification
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('XXXXXX', cid.Anonid)
             found = True
     self.assertTrue(found)
コード例 #8
0
 def testHostnameCorruptedFile(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     host.NETBIOS_HOSTNAMES = 'testdata/host/netbios_hostnames_corrupt'
     hosts = host.Hosts()
     self.assertEqual(3, len(hosts.HostList))
     found = False
     for h in hosts.HostList.values():
         if h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('NETBIOS_HOSTNAME4_3', h.HostName)
             found = True
     self.assertTrue(found)
コード例 #9
0
 def testHostnameInvalidUnicode(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     host.DNSSD_HOSTNAMES = 'testdata/host/dnssd_hostnames_invalid_unicode'
     hosts = host.Hosts()
     self.assertEqual(3, len(hosts.HostList))
     found = False
     for h in hosts.HostList.values():
         cid = h.X_CATAWAMPUS_ORG_ClientIdentification
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual(u'dnssd_hostname_invalidUTF8_\ufffd.local',
                              cid.DnsSdName)
             found = True
     self.assertTrue(found)
コード例 #10
0
 def testTr181(self):
     dmroot = self._GetFakeCPE(tr98=False, tr181=True)
     hosts = host.Hosts(dmroot=dmroot)
     self.assertEqual(6, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         l1interface = 'Device.MoCA.Interface.1'
         if h.PhysAddress == '00:11:22:33:44:11':
             self.assertTrue(h.Active)
             self.assertFalse(found & 0x1)
             found |= 0x1
             # Fields from MoCA AssocidatedDevice table
             self.assertEqual(l1interface, h.Layer1Interface)
             a = l1interface + '.AssociatedDevice.1'
             self.assertEqual(a, h.AssociatedDevice)
             # Fields from fake_dhcp_server.py
             self.assertEqual('192.168.133.7', h.IPAddress)
             self.assertEqual('client_id1', h.ClientID)
             self.assertEqual(2, h.IPv4AddressNumberOfEntries)
             self.assertEqual('192.168.133.7',
                              h.IPv4AddressList['1'].IPAddress)
             self.assertEqual('192.168.1.1',
                              h.IPv4AddressList['2'].IPAddress)
         elif h.PhysAddress == '00:11:22:33:44:22':
             self.assertTrue(h.Active)
             self.assertFalse(found & 0x2)
             found |= 0x2
             self.assertEqual(l1interface, h.Layer1Interface)
             a = l1interface + '.AssociatedDevice.2'
             self.assertEqual(a, h.AssociatedDevice)
         elif h.PhysAddress == '00:11:22:33:44:33':
             self.assertFalse(h.Active)
             self.assertFalse(found & 0x4)
             found |= 0x4
             # populated by fake_dhcp_server.py
             self.assertEqual('192.168.133.8', h.IPAddress)
             self.assertEqual('hostname_2', h.HostName)
             self.assertEqual(1, h.IPv4AddressNumberOfEntries)
             self.assertEqual('192.168.133.8',
                              h.IPv4AddressList['1'].IPAddress)
         elif h.PhysAddress == 'f8:8f:ca:00:00:04':
             found |= 0x8
         elif h.PhysAddress == 'f8:8f:ca:00:00:05':
             found |= 0x10
         elif h.PhysAddress == 'f8:8f:ca:00:00:06':
             found |= 0x20
     self.assertEqual(0x3f, found)
コード例 #11
0
 def testTr98(self):
     dmroot = self._GetFakeCPE(tr98=True, tr181=False)
     hosts = host.Hosts(dmroot=dmroot)
     self.assertEqual(2, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         self.assertTrue(h.Active)
         l1interface = 'InternetGatewayDevice.LANDevice.1.WLANConfiguration.1'
         self.assertEqual(l1interface, h.Layer1Interface)
         if h.PhysAddress == '00:01:02:03:04:05':
             self.assertFalse(found & 0x1)
             found |= 0x1
             a = l1interface + '.AssociatedDevice.1'
             self.assertEqual(a, h.AssociatedDevice)
         elif h.PhysAddress == '00:01:02:03:04:06':
             self.assertFalse(found & 0x2)
             found |= 0x2
             a = l1interface + '.AssociatedDevice.2'
             self.assertEqual(a, h.AssociatedDevice)
     self.assertEqual(0x3, found)
コード例 #12
0
 def testDhcpTaxonomy(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     iflookup = {
         'foo0': 'Device.Foo.Interface.1',
         'foo1': 'Device.Foo.Interface.2'
     }
     hosts = host.Hosts(iflookup)
     self.assertEqual(3, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         fp = h.X_CATAWAMPUS_ORG_ClientIdentification.DhcpTaxonomy
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('1,2,3', fp)
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:02':
             self.assertEqual('4,5,6', fp)
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('', fp)
             found |= 4
     self.assertEqual(7, found)
コード例 #13
0
 def testWifiTaxonomy(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp2'
     dmroot = self._GetFakeCPE(tr98=False, tr181=True)
     hosts = host.Hosts(dmroot=dmroot)
     found = 0
     for h in hosts.HostList.values():
         # Note that there are several more hosts in the list, supplied
         # by the fake_dhcp_server.py, but not relevant to this test case.
         ci = h.X_CATAWAMPUS_ORG_ClientIdentification
         if h.PhysAddress == 'f8:8f:ca:00:00:04':
             expected = 'wifi|probe:1,2,3,4|assoc:5,6,7,8'
             self.assertEqual(ci.WifiTaxonomy.strip(), expected)
             self.assertEqual(ci.WifiDeviceModel.strip(), 'genus species')
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:05':
             expected = 'wifi|probe:1,2,3,4|assoc:5,6,7,8'
             self.assertEqual(ci.WifiTaxonomy.strip(), expected)
             self.assertEqual(ci.WifiDeviceModel.strip(), 'genus species')
             # fake_dhcp_server.py says this is MyPhone, which is fine.
             self.assertEqual(h.HostName, 'MyPhone')
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:06':
             found |= 4
     self.assertEqual(7, found)
コード例 #14
0
 def testGetHostsFromArp(self):
     host.PROC_NET_ARP = 'testdata/host/proc_net_arp'
     iflookup = {
         'foo0': 'Device.Foo.Interface.1',
         'foo1': 'Device.Foo.Interface.2'
     }
     hosts = host.Hosts(iflookup)
     self.assertEqual(3, len(hosts.HostList))
     found = 0
     for h in hosts.HostList.values():
         self.assertTrue(h.Active)
         if h.PhysAddress == 'f8:8f:ca:00:00:01':
             self.assertEqual('Device.Foo.Interface.1', h.Layer1Interface)
             self.assertEqual('192.168.1.1', h.IPAddress)
             found |= 1
         elif h.PhysAddress == 'f8:8f:ca:00:00:02':
             self.assertEqual('Device.Foo.Interface.2', h.Layer1Interface)
             self.assertEqual('192.168.1.2', h.IPAddress)
             found |= 2
         elif h.PhysAddress == 'f8:8f:ca:00:00:03':
             self.assertEqual('Device.Foo.Interface.1', h.Layer1Interface)
             self.assertEqual('192.168.1.3', h.IPAddress)
             found |= 4
     self.assertEqual(7, found)
コード例 #15
0
 def testValidateExports(self):
     hosts = host.Hosts()
     tr.handle.ValidateExports(hosts)
     h = host.Host()
     tr.handle.ValidateExports(h)
コード例 #16
0
 def testMissingFdbFile(self):
     iflookup = {'eth0': 'Ethernet', 'eth1.0': 'MoCA'}
     h = host.Hosts(iflookup, bridgename='nonexistent0')
     self.assertEqual(0, len(h.HostList))