def is_entry_valid(entries):
        """ Make sure the switch selected by the user exists and
        that it has a color using the Coloring Napp.
        In fact, this method has to validate all params provided.

        Args:
            entries: dictionary with user request
        Returns:
            True: all set
            False: switch requested doesn't exist
        """
        # Check if provided dpid relates to an existing switch
        dpid = entries['trace']['switch']['dpid']
        init_switch = Switches().get_switch(dpid)
        if isinstance(init_switch, bool):
            return False, {'error': 'DPID %s not found' % dpid}

        # Check if the existing switch was colored
        color = Colors().get_switch_color(init_switch.dpid)
        if len(color) is 0:
            return False, {'error': 'switch color not defined'}

        # Check if dl_vlan was provided
        try:
            vlan = entries['trace']['eth']['dl_vlan']
        except:
            return False, {'error': 'dl_vlan is mandatory'}

        return True, 0
Exemple #2
0
    def tracepath(self):
        """
            Do the trace path
            The logic is very simple:
            1 - Generate the probe packet using entries provided
            2 - Results a result and the packet_in (used to generate new probe)
                Possible results: 'timeout' meaning the end of trace
                                  or the trace step {'dpid', 'port'}
                Some networks do vlan rewriting, so it is important to get the
                packetIn msg with the header
            3 - If result is a trace step, send PacketOut to the switch that
                originated the PacketIn. Repeat till reaching timeout
        """
        log.warning("Starting Trace Path ID: %s" % self.id)

        entries = copy.deepcopy(self.init_entries)
        color = Colors().get_switch_color(self.init_switch.dpid)
        switch = self.init_switch
        # Add initial trace step
        self.rest.add_trace_step(self.trace_result, trace_type='starting',
                                 dpid=switch.dpid,
                                 port=entries.in_port)

        # A loop waiting for 'trace_ended'.
        # It changes to True when reaches timeout
        self.tracepath_loop(entries, color, switch)

        # Add final result to trace_results_queue
        t_result = {"request_id": self.id,
                    "result": self.trace_result,
                    "start_time": str(self.rest.start_time),
                    "total_time": self.rest.get_time(),
                    "request": self.init_entries.init_entries}

        self.trace_mgr.add_result(self.id, t_result)
Exemple #3
0
    def is_entry_valid(entries):
        """ This method validates all params provided, including
        if the switch/dpid requested exists.

        Args:
            entries: dictionary with user request
        Returns:
            TraceEntries class
            Error msg
        """
        try:
            trace_entries = TraceEntries()
            trace_entries.load_entries(entries)
        except ValueError as msg:
            return str(msg)

        init_switch = Switches().get_switch(trace_entries.dpid)
        if isinstance(init_switch, bool):
            return "Unknown Switch"
        color = Colors().get_switch_color(init_switch.dpid)
        if len(color) is 0:
            return "Switch not Colored"

        # TODO: get Coloring API to confirm color_field

        return trace_entries
Exemple #4
0
    def tracepath(self):
        """
            Do the trace path
            The logic is very simple:
            1 - Generate the probe packet using entries provided
            2 - Results a result and the packet_in (used to generate new probe)
                Possible results: 'timeout' meaning the end of trace
                                  or the trace step {'dpid', 'port'}
                Some networks do vlan rewriting, so it is important to get the
                packetIn msg with the header
            3 - If result is a trace step, send PacketOut to the switch that
                originated the PacketIn. Repeat till reaching timeout
        """
        log.warning("Starting Trace Path for ID %s" % self.id)

        entries = copy.deepcopy(self.init_entries)
        color = Colors().get_switch_color(self.init_switch.dpid)
        switch = self.init_switch
        # Add initial trace step
        self.rest.add_trace_step(self.trace_result,
                                 trace_type='starting',
                                 dpid=switch.dpid,
                                 port=entries['trace']['switch']['in_port'])

        # A loop waiting for 'trace_ended'. It changes to True when reaches timeout
        while not self.trace_ended:
            in_port, probe_pkt = generate_trace_pkt(entries, color, self.id,
                                                    self.mydomain)
            result, packet_in = self.send_trace_probe(switch, in_port,
                                                      probe_pkt)
            if result == 'timeout':
                self.rest.add_trace_step(self.trace_result, trace_type='last')
                log.warning("Intra-Domain Trace Completed!")
                self.trace_ended = True
            else:
                self.rest.add_trace_step(self.trace_result,
                                         trace_type='trace',
                                         dpid=result['dpid'],
                                         port=result['port'])
                if self.check_loop():
                    self.rest.add_trace_step(self.trace_result,
                                             trace_type='last',
                                             reason='loop')
                    self.trace_ended = True
                    break
                # If we got here, that means we need to keep going.
                entries, color, switch = prepare_next_packet(
                    entries, result, packet_in)

        # Add final result to trace_results_queue
        t_result = {
            "request_id": self.id,
            "result": self.trace_result,
            "start_time": str(self.rest.start_time),
            "total_time": self.rest.get_time(),
            "request": self.init_entries
        }

        self.trace_mgr.add_result(self.id, t_result)
Exemple #5
0
def _get_node_color_from_dpid(dpid):
    """ Get node color from Coloring Napp

    Args:
        dpid: switch DPID
    Returns:
        switch and color
        0 for not Found
    """
    for switch in Switches().get_switches():
        if dpid == switch.dpid:
            return switch, Colors().get_switch_color(switch.dpid)
    return 0
Exemple #6
0
def get_node_color_from_dpid(dpid):
    for switch in Switches().get_switches():
        if dpid == switch.dpid:
            return switch, Colors().get_switch_color(switch.dpid)
    return 0