<commit_before><commit_msg>App for updating the links between switches and servers at the switch map from the controller<commit_after>import logging

from kyco.core.napps import KycoCoreNApp
from kyco.utils import listen_to
from pyof.foundation.network_types import Ethernet

log = logging.getLogger('KycoNApp')


class Main(KycoCoreNApp):
    """
    This app intends to update the links between machines and switches. It
    considers that if an interface is connected to another interface then this
    is a link. If not, it must be a connection to a server
    """

    def setup(self):
        """Creates an empty dict to store the switches references and the
        information about the hosts"""

        self.name = 'kytos/of.topology'
        self.stop_signal = False

    def execute(self):
        """ Do nothing, only wait for packet-in messages"""
        pass

    @listen_to('kytos/of.core.messages.in.ofpt_packet_in')
    def update_links(self, event):
        """
        Main operation of the app., the one responsible for update the
        interface endpoints.
        """
        ethernet = Ethernet()
        ethernet.unpack(event.message.data.value)
        if ethernet.type != 0x88cc:

            port_no = event.message.in_port
            hw_address = event.message.source
            switch = event.source.switch
            interface = switch.get_interface_by_port_no(port_no)
            if not interface.is_link_between_switches():
                interface.update_endpoint(hw_address)

    def shutdown(self):
        self.stop_signal = True
{'fraction_non_alphanumeric': 0.07496823379923762, 'fraction_numerical': 0.0019059720457433292, 'mean_word_length': 2.6799065420560746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5799146', 'n_tokens_mistral': 448, 'n_tokens_neox': 421, 'n_words': 140}