示例#1
0
文件: bridge.py 项目: yapkke/yapc
 def _handle_json(self, jsonmsg):
     """Handle JSON message
     """
     ##Add change to list
     old_ip = pu.ip_string2val(jsonmsg.json_msg["ip_prev"][0])
     new_ip = pu.ip_string2val(jsonmsg.json_msg["ip_new"][0])
     self.ip_change[new_ip] = (old_ip, time.time())
示例#2
0
文件: nat.py 项目: yapkke/yapc
 def __route_check(self, o):
     """Check route
     
     @param o route check object (dictionary)
     """
     gw = self.get_if_route(mif=o["mif"])
     if gw == None:
         o["tried"] += 1
         if o["tried"] < MAX_RETRY:
             rc = yapc.priv_callback(self, o)
             self.server.post_event(rc, 1)
     else:
         no = self.switch.if_name2dpid_port_mac(o["if"])[1]
         mc.set(nat.get_gw_key(no), gw)
         output.info("Gateway of " + o["if"] + " is " + gw, self.__class__.__name__)
         # Check for route
         self.check_default_route()
         # Register ip range
         ipv4addr = self.ifmgr.ipv4_addr_n_mask(o["mif"])
         if ipv4addr == None:
             return
         ipr = (
             pu.ip_string2val(ipv4addr["addr"]),
             pu.ip_string2val(ipv4addr["netmask"]),
             pu.hex_str2array(self.ifmgr.ethernet_addr(o["mif"])),
         )
         mc.set(nat.get_ip_range_key(no), ipr)
         output.info(
             o["if"] + "(" + str(no) + ") has IP address %x and netmask %x" % (ipr[0], ipr[1]),
             self.__class__.__name__,
         )
         # Call for ARP
         rc = yapc.priv_callback(self, {"type": "arp", "tried": 0, "ip": gw, "if": o["mif"]})
         self.server.post_event(rc, 0)
示例#3
0
文件: bridge.py 项目: yapkke/yapc
 def _handle_json(self, jsonmsg):
     """Handle JSON message
     """
     ##Add change to list
     sip = pu.ip_string2val(jsonmsg.json_msg["server_ip"][0])
     mip = pu.ip_string2val(jsonmsg.json_msg["mobile_ip"][0])
     self.m2m[mip] = (sip, time.time())
     self.m2m[sip] = (mip, time.time())
示例#4
0
文件: nat.py 项目: yapkke/yapc
    def setup(self, interfaces, inner_addr=LOCAL_IP, gw=LOCAL_GW, gw_mac=None):
        """Add interfaces
        
        @param interfaces list of interfaces
        @param inner_addr IP to give COIN's client side interface
        @param gw gateway to use for COIN's interface
        @param gw_mac gateway mac address
        """
        # Set up interfaces
        self.loif = self.add_loif("local")
        self.add_interfaces(interfaces)

        # Get IP addresses on the interfaces
        self.ifmgr.set_ipv4_addr(self.loif.client_intf, inner_addr)
        mc.set(
            nat.SW_INNER_PORT_ADDR,
            (pu.ip_string2val(inner_addr), pu.hex_str2array(self.ifmgr.ethernet_addr(self.loif.client_intf))),
        )
        for i in range(0, len(interfaces)):
            self.ifmgr.up(interfaces[i])

        # Setup route
        self.ifmgr.add_route("default", gw=gw, iface=self.loif.client_intf)
        if gw_mac == None:
            gw_mac = self.ifmgr.ethernet_addr(self.loif.switch_intf)
        self.ifmgr.set_ip_mac(gw, gw_mac)

        self.check_default_route()
示例#5
0
文件: nat.py 项目: yapkke/yapc
 def set_ifconfig(self, msg):
     """Does manual ifconfig
     """
     intf = msg["name"]
     ip = msg["ipaddr"]
     mask = msg["netmask"]
     gw = msg["gwaddr"]
     gwmac = msg["gwmac"]
     no = self.switch.if_name2dpid_port_mac(intf)[1]
     # Register gateway
     mc.set(nat.get_gw_key(no), gw)
     output.info("Gateway of " + intf + " is " + gw, self.__class__.__name__)
     # Register ip range
     ipr = (pu.ip_string2val(ip), pu.ip_string2val(mask), pu.hex_str2array(self.ifmgr.ethernet_addr(intf)))
     mc.set(nat.get_ip_range_key(no), ipr)
     output.info(
         intf + "(" + str(no) + ") has IP address %x and netmask %x" % (ipr[0], ipr[1]), self.__class__.__name__
     )
     # Regsiter mac address
     mc.set(nat.get_gw_mac_key(gw), gwmac)
     output.info("ARP of " + gw + " is " + str(gwmac), self.__class__.__name__)
示例#6
0
import dpkt
import yapc.interface as yapc
import yapc.log.output as output
import yapc.pyopenflow as pyof
import yapc.events.openflow as ofevents
import yapc.util.memcacheutil as mcutil
import yapc.util.parse as pu
import yapc.forwarding.flows as flows
import yapc.netstate.swhost as swhost
import openwifi.event as owevent
import openwifi.globals as owglobal

AUTH_DST_IP = pu.ip_string2val("171.67.74.237")
AUTH_DST_PORT1 = 80
AUTH_DST_PORT2 = 8080
HTTPS_PORT = 443

AUTH_TIMEOUT = 120
MAX_AUTH_TIMEOUT = 3600 #One hour

BYPASS_IP = []
#BYPASS_IP.append(pu.ip_string2val("140.211.166.152")) #OpenID

def host_auth_server(host):
    """Return server host is going to authenticate with
    """
    au = mcutil.get(host_auth.get_auth_key(host))
    if (au == None):
        return None
    else:
        return au
示例#7
0
import dpkt
import yapc.interface as yapc
import yapc.log.output as output
import yapc.pyopenflow as pyof
import yapc.events.openflow as ofevents
import yapc.util.memcacheutil as mcutil
import yapc.util.parse as pu
import yapc.forwarding.flows as flows
import yapc.netstate.swhost as swhost
import openwifi.event as owevent
import openwifi.globals as owglobal

AUTH_DST_IP = pu.ip_string2val("171.67.74.237")
AUTH_DST_PORT1 = 80
AUTH_DST_PORT2 = 8080
HTTPS_PORT = 443

AUTH_TIMEOUT = 120
MAX_AUTH_TIMEOUT = 3600  #One hour

BYPASS_IP = []
#BYPASS_IP.append(pu.ip_string2val("140.211.166.152")) #OpenID


def host_auth_server(host):
    """Return server host is going to authenticate with
    """
    au = mcutil.get(host_auth.get_auth_key(host))
    if (au == None):
        return None
    else: