hi,
our names are Guillermo Spiller and Martin Irazoqui, we are working in 
Uruguay with the OLPC proyect. In a few days we are going to start a 
pilot in a school wishing to spread the internet all over the town. In 
order to accomplish this we needed to make the mpp configuration 
automatically (making each portal "intelligent" so it will be awared of 
the network changes).As for now the ip is given by a DHCP server, we 
configured some XO as dhcp servers (in differents ranges) so the ips 
won't collide. We also stopped the dhcp in every "normal" computer. We 
think that this script might help and it would be nice to receive some 
comments about it. We did a script (attached) so every minute the XO 
will check its status (am I a portal or not?), if it's a portal it will 
reconfirm its connectivity with the AP and if it's still good will 
sleep for an extra minute. If it's not, it will stop of being a portal. 
In case of not being a portal, and having a gateway in eth0, after 
checking the connectivity with this gateway will start the mpp 
services. If you want to see this with more details you can always read 
the script, we tried to comment it as well as possible.
This script saves the status of the computer in the file 
/var/log/portal and explain his behaviour.
It would be better if this "thinking" would be done in the network 
manager, so when a kid clicks in the circle you know that you have to 
stop the mpp, and if he clicks in the triangle you might be a portal. 
We tried to do this but we didn?t find the code of this buttons.

We also would like  to know if there is a table where the computers 
write the possible dhcp servers, or portals because when we try to 
connect an XO as a client for the first time we have to click in the 
circle several times, but if we want to re-connect it?s very easy..
#! /usr/bin/python
#
import os, sys, time
archivo = file('/var/log/portal','w') # File where every message is gonig to be 
saved
archivo.write('')
archivo.close()
archivo = file('/var/log/portal','a')
def autoportal():
        
        portal=0
        contador = 5
        i = 1
        archivo.write(str(time.localtime())+'Starting...'+"\n")
        archivo.flush()
        while (i == 1): 
                if (contador >= 10):   # scanning every ten minutes
                        os.popen("iwlist eth0 scan")
                        archivo.write(str(time.localtime())+'Scanning 
interfaces, refreshing UI \n')
                        archivo.flush()
                        contador = 0

                contador = contador + 1
                archivo.write(str(time.localtime())+"Am I a Portal? \n")
                archivo.flush()
                if (portal == 0): 
                        archivo.write(str(time.localtime())+"No, I´m not \n")
                        archivo.flush()
                        info=os.popen("route | grep eth0 | grep default")
                        temp=info.readline().split()
                        if (len(temp) != 0): #Im not a MPP but I have a gw in 
eth0
                                ip=temp[1]
                                check=os.popen("ping -c 5 "+str(ip)) # Checking 
if gw answers...
                                os.popen("sleep 5")                             
                                check.readline()
                                temp = check.readline().split()
                                if (len(temp) != 0):            
                                        temp=temp[0]
                                        if (temp != "From"): # gw answered. 
                                                # We should check if the AP has 
Internet
                                                TengoIpMesh() 
                                                info = os.popen("ifconfig msh0")
                                                info.readline()
                                                temp = 
info.readline().split()[1]
                                                if (temp != "addr:"): # I´m in 
the mesh?
                                                        os.popen("service mpp 
start") # yes
                                                        
archivo.write(str(time.localtime())+"Starting MPP \n")
                                                        archivo.flush()
                                                        portal = 1
                                                else: # no
                                                        
archivo.write(str(time.localtime())+"DHCP didn´t give me an IP \n")
                                                        archivo.flush()
                                        else:
                                                os.popen("service mpp stop")
                                                
archivo.write(str(time.localtime())+"stopping MPP, I can´t reach the AP. \n")
                                                archivo.flush()
                                else:
                                        os.popen("service mpp stop")
                                        
archivo.write(str(time.localtime())+"Stoppiing MPP, AP didn´t respond. \n")
                                        archivo.flush()

                                

                        else:   # I don´t have a default gw in eth0
                                archivo.write(str(time.localtime())+"Am I a 
client? \n")
                                archivo.flush()
                                info=os.popen("route | grep msh0 | grep 
default")
                                temp=info.readline().split()
                                if (len(temp) != 0):
                                        
archivo.write(str(time.localtime())+"Yes, yupi! \n")
                                        archivo.flush()
                                else:
                                        
archivo.write(str(time.localtime())+"I´m not a portal or client, pff \n")
                                        archivo.flush()


                                

                else: # I´m already a portal, checking my connection
                        TengoIpMesh() # Just checking
                        contador = contador + 1
                        info=os.popen("route | grep eth0 | grep default") # 
Looking for my default route
                        temp=info.readline().split() 
                        if (len(temp) != 0): 
                                ip=temp[1] # IP of my default route
                                check=os.popen("ping -c 5 "+str(ip)) # 
...pinging...
                                os.popen("sleep 5")
                                check.readline()
                                temp=check.readline().split()
                                if (len(temp) != 0): 
                                        temp=temp[0] 
                                        if (temp == "From"): # I lost my 
connection
                                                os.popen("service mpp stop") # 
:(
                                                portal = 0
                                                
archivo.write(str(time.localtime())+"Stopping MPP, I can´t reach my AP \n")
                                                archivo.flush()
                                        else:
                                                os.popen("service mpp start")
                                                
archivo.write(str(time.localtime())+"I'm a MPP \n")
                                                archivo.flush()
                                                os.popen("sleep 60") # Waiting 
an extra minute
                                                contador = contador + 1
                                else:
                                        os.popen("service mpp stop") 
                                        portal = 0
                                        
archivo.write(str(time.localtime())+"Sopping MPP, AP didn´t responde \n")
                                        archivo.flush()
                        else:
                                # Just for checking, special case. We shouldn´t 
be here
                                archivo.write(str(time.localtime())+"Stopping 
MPP, special case \n")
                                archivo.flush()
                                os.popen("service mpp stop") #  :(
                                portal = 0 
                        
                os.popen("sleep 60") # waitting for a minute

def TengoIpMesh(): #configurating Mesh
        info = os.popen("ifconfig msh0") 
        info.readline()
        temp = info.readline().split()[1]
        if (temp == "addr:"): # Is not already configurated
                os.popen("dhclient msh0") # getting an IP
                os.popen("killall dhclient")
                os.popen("iwlist eth0 scan") # scanning, circle sometimes kills 
eth0
                archivo.write(str(time.localtime())+"Refreshing graphic 
interface \n")
                archivo.flush()
                contador = 0

autoportal()

# Yoruguas
_______________________________________________
Devel mailing list
[email protected]
http://mailman.laptop.org/mailman/listinfo/devel

Reply via email to