Exemplo n.º 1
0
    def execute(self):
        """Send LLDP Packets every 'POLLING_TIME' seconds to all switches."""
        switches = list(self.controller.switches.values())
        for switch in switches:
            try:
                of_version = switch.connection.protocol.version
            except AttributeError:
                of_version = None

            if not (switch.is_connected() and of_version in [0x01, 0x04]):
                continue

            for interface in switch.interfaces.values():

                # Avoid ports with speed == 0
                if interface.port_number == 65534:
                    continue

                lldp = LLDP()
                lldp.chassis_id.sub_value = DPID(switch.dpid)
                port_type = UBInt16 if of_version == 0x01 else UBInt32
                lldp.port_id.sub_value = port_type(interface.port_number)

                ethernet = Ethernet()
                ethernet.ether_type = EtherType.LLDP
                ethernet.source = interface.address
                ethernet.destination = constants.LLDP_MULTICAST_MAC
                ethernet.data = lldp.pack()

                packet_out = self.build_lldp_packet_out(
                    of_version, interface.port_number, ethernet.pack())

                if packet_out is not None:
                    name = 'kytos/of_lldp.messages.out.ofpt_packet_out'
                    content = {
                        'destination': switch.connection,
                        'message': packet_out
                    }
                    event_out = KytosEvent(name=name, content=content)
                    self.controller.buffers.msg_out.put(event_out)

                    log.debug("Sending a LLDP PacketOut to the switch %s",
                              switch.dpid)
Exemplo n.º 2
0
    def execute(self):
        """Implement a loop to check switches liveness."""
        switches = list(self.controller.switches.values())
        for switch in switches:
            if not (switch.is_connected() and
                    switch.connection.protocol.version == 0x01):
                continue
            # Gerar lldp para cada uma das portas do switch
            # Gerar o hash de cada um dos pacotes e armazenar

            for port in switch.features.ports:
                output_action = ActionOutput()
                output_action.port = port.port_no

                # Avoid ports with speed == 0
                if port.port_no.value == 65534:
                    continue

                ethernet = Ethernet()
                ethernet.ether_type = constants.LLDP_ETHERTYPE
                ethernet.source = port.hw_addr
                ethernet.destination = constants.LLDP_MULTICAST_MAC

                lldp = LLDP()
                lldp.chassis_id.sub_value = DPID(switch.dpid)
                lldp.port_id.sub_value = port.port_no

                ethernet.data = lldp.pack()

                packet_out = PacketOut()
                packet_out.actions.append(output_action)
                packet_out.data = ethernet.pack()

                event_out = KytosEvent()
                event_out.name = 'kytos/of_lldp.messages.out.ofpt_packet_out'
                event_out.content = {'destination': switch.connection,
                                     'message': packet_out}
                self.controller.buffers.msg_out.put(event_out)

                log.debug("Sending a LLDP PacketOut to the switch %s",
                          switch.dpid)
Exemplo n.º 3
0
    def execute(self):
        """Send LLDP Packets every 'POLLING_TIME' seconds to all switches."""
        switches = list(self.controller.switches.values())
        for switch in switches:
            try:
                of_version = switch.connection.protocol.version
            except AttributeError:
                of_version = None

            if not switch.is_connected():
                continue

            if of_version == 0x01:
                port_type = UBInt16
                local_port = Port10.OFPP_LOCAL
            elif of_version == 0x04:
                port_type = UBInt32
                local_port = Port13.OFPP_LOCAL
            else:
                # skip the current switch with unsupported OF version
                continue

            interfaces = list(switch.interfaces.values())
            for interface in interfaces:

                # Avoid the interface that connects to the controller.
                if interface.port_number == local_port:
                    continue

                lldp = LLDP()
                lldp.chassis_id.sub_value = DPID(switch.dpid)
                lldp.port_id.sub_value = port_type(interface.port_number)

                ethernet = Ethernet()
                ethernet.ether_type = EtherType.LLDP
                ethernet.source = interface.address
                ethernet.destination = constants.LLDP_MULTICAST_MAC
                ethernet.data = lldp.pack()
                # self.vlan_id == None will result in a packet with no VLAN.
                ethernet.vlans.append(VLAN(vid=self.vlan_id))

                packet_out = self._build_lldp_packet_out(
                    of_version, interface.port_number, ethernet.pack())

                if packet_out is not None:
                    event_out = KytosEvent(
                        name='kytos/of_lldp.messages.out.ofpt_packet_out',
                        content={
                            'destination': switch.connection,
                            'message': packet_out
                        })
                    self.controller.buffers.msg_out.put(event_out)

                    log.debug("Sending a LLDP PacketOut to the switch %s",
                              switch.dpid)

                    msg = '\n'
                    msg += 'Switch: %s (%s)\n'
                    msg += '  Interfaces: %s\n'
                    msg += '  -- LLDP PacketOut --\n'
                    msg += '  Ethernet: eth_type (%s) | src (%s) | dst (%s)\n'
                    msg += '    LLDP: Switch (%s) | port (%s)'

                    log.debug(msg, switch.connection.address, switch.dpid,
                              switch.interfaces, ethernet.ether_type,
                              ethernet.source, ethernet.destination,
                              switch.dpid, interface.port_number)