예제 #1
0
파일: hosts.py 프로젝트: jonstout/Overlord
    def learn(self, event):
        """
        Intercept and inspect ARP messages.
        """
        pkt = event.parse()
        if pkt.type != 2054: return
        arp = pkt.next

        host_a = core.db.find_host({"mac": str(arp.hwsrc)})
        h = {
            "_parent": str(event.dpid),
            "port_no": str(event.port),
            "ip": str(arp.protosrc),
            "mac": str(arp.hwsrc),
            "group_no": "-1",
            "active": True
        }
        # Is the DB out of sync
        if host_a is None:
            print("Host %s is new. Recording and adding to null group" %
                  str(arp.hwsrc))
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            return
        # Is Local out of sync
        if not str(arp.hwsrc) in self.hosts:
            print("Host %s is new to local db. Syncing with remote db." %
                  str(arp.hwsrc))
            h["group_no"] = host_a["group_no"]
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            e = Event()
            e.host = host_a
            self.handle_event("host-update", e)
        # Is Local out of sync
        h["group_no"] = host_a["group_no"]
        if host_a["ip"] != h["ip"] or host_a["port_no"] != h["port_no"] \
                or host_a["_parent"] != h["_parent"] or host_a["active"] != h["active"]:
            print("Saving host %s changes to db and installing new flows." %
                  str(arp.hwsrc))
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            e = Event()
            e.host = host_a
            self.handle_event("host-update", e)

        if host_a["group_no"] is "-1":
            print("Not broadcasting ARP from Host %s" % str(arp.hwsrc))
            return
        else:
            host_b = core.db.find_host({"ip": str(arp.protodst)})
            if host_b is None or host_b["group_no"] is -1: return
            self.send_arp(host_a, host_b)
예제 #2
0
    def learn(self, event):
        """
        Intercept and inspect ARP messages.
        """
        pkt = event.parse()
        if pkt.type != 2054: return
        arp = pkt.next

        host_a = core.db.find_host({"mac": str(arp.hwsrc)})
        h = {"_parent": str(event.dpid),
             "port_no": str(event.port),
             "ip": str(arp.protosrc),
             "mac": str(arp.hwsrc),
             "group_no": "-1", "active": True}
        # Is the DB out of sync
        if host_a is None:
            print("Host %s is new. Recording and adding to null group" % str(arp.hwsrc))
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            return
        # Is Local out of sync
        if not str(arp.hwsrc) in self.hosts:
            print("Host %s is new to local db. Syncing with remote db." % str(arp.hwsrc))
            h["group_no"] = host_a["group_no"]
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            e = Event()
            e.host = host_a
            self.handle_event("host-update", e)
        # Is Local out of sync
        h["group_no"] = host_a["group_no"]
        if host_a["ip"] != h["ip"] or host_a["port_no"] != h["port_no"] \
                or host_a["_parent"] != h["_parent"] or host_a["active"] != h["active"]:
            print("Saving host %s changes to db and installing new flows." % str(arp.hwsrc))
            self.hosts[str(arp.hwsrc)] = h
            core.db.update_host(h)
            e = Event()
            e.host = host_a
            self.handle_event("host-update", e)
        
        if host_a["group_no"] is "-1":
            print("Not broadcasting ARP from Host %s" % str(arp.hwsrc))
            return
        else:
            host_b = core.db.find_host({"ip": str(arp.protodst)})
            if host_b is None or host_b["group_no"] is -1: return
            self.send_arp(host_a, host_b)