コード例 #1
0
    def handle_topology_answer(self, pkt=None):
        """
        Handle topology packet
        :param pkt: contains the topology packet
        :return:
        """

        # if the controller is not yet connected to all local controllers
        # don't handle topology packets
        if not Configuration.get('system_done'):
            return

        ip = pkt.ip.encode('utf-8')
        mac = pkt.mac.encode('utf-8')
        name = pkt.name.encode('utf-8')
        port = pkt.port
        switch = pkt.switch.encode('utf-8')

        if name.startswith('h'):  # it's a host
            TopologyManager.add_device(name=name,
                                       device=Host(name=name, ip=ip, mac=mac))
            TopologyManager.get_device(name=name).add_device_to_port(
                device=switch, port=1)

        Log.event("topology packet with identifier", name, "from switch",
                  switch, "on port", port, "with ip", ip)

        if TopologyManager.get_device(name=switch).add_device_to_port(
                device=name, port=int(port)):
            Event.trigger("topology_change",
                          src_device=switch,
                          dst_device=name,
                          port=int(port))
コード例 #2
0
    def handle_packet_in(pkt):
        switch = pkt.switch.encode('utf-8')
        mc_addr = pkt.mc_address.encode('utf-8')
        src_ip = pkt.src_ip.encode('utf-8')

        if pkt.type == 0x16:
            GroupManager.add_to_group(switch, src_ip, mc_addr)
        elif pkt.type == 0x17:
            GroupManager.remove_from_group(switch, src_ip, mc_addr)

        Event.trigger("group_update")

        Log.event("Got igmp packet with type", hex(pkt.type), "and src",
                  src_ip, "for group", mc_addr, "from", switch)