Example #1
0
    def handle_stats_reply(self, event):
        """Handle stats replies for v0x01 switches.

        Args:
            event (:class:`~kytos.core.events.KytosEvent):
                Event with ofpt_stats_reply in message.
        """
        switch = event.source.switch
        msg = event.content['message']
        if msg.body_type == StatsType.OFPST_FLOW:
            switch.flows = [
                Flow01.from_of_flow_stats(f, switch) for f in msg.body
            ]
            event_raw = KytosEvent(name='kytos/of_core.flow_stats.received',
                                   content={'switch': switch})
            self.controller.buffers.app.put(event_raw)
        elif msg.body_type == StatsType.OFPST_PORT:
            port_stats = [of_port_stats for of_port_stats in msg.body]
            port_stats_event = KytosEvent(name=f"kytos/of_core.port_stats",
                                          content={
                                              'switch': switch,
                                              'port_stats': port_stats
                                          })
            self.controller.buffers.app.put(port_stats_event)
        elif msg.body_type == StatsType.OFPST_DESC:
            switch.update_description(msg.body)
Example #2
0
    def _generate_install_flow_req_body(self, endpoint_a: Endpoint, endpoint_b: Endpoint):
        """Generate a Flow object to be uses as a body to the install flow request."""
        if endpoint_a is None:
            raise ValueError("Endpoint A is missing.")
        if endpoint_b is None:
            raise ValueError("Endpoint Z is missing.")

        # Build a basic flow from settings template
        flow_dict = settings.flow_dict_v10  # Future expansion to OF1.3

        # Change flow values to match endpoint A to output to endpoint B
        flow = Flow.from_dict(flow_dict, self.controller.get_switch_by_dpid(endpoint_a._dpid))

        flow.match.in_port = int(endpoint_a._port)
        flow.actions[0].value = int(endpoint_b._port)
        flow.actions[0].port = int(endpoint_b._port)

        # Setting endpoint A vlan
        if endpoint_a._tag is not None and endpoint_a._tag._type == 'ctag':
            flow.match.dl_vlan = int(endpoint_a._tag._value)

        # Setting endpoint B vlan
        if endpoint_b._tag is not None and endpoint_a._tag != endpoint_b._tag and endpoint_b._tag._type == 'ctag':
            action = ActionSetVlan(int(endpoint_b._tag._value))
            flow.actions.append(action)

        return flow
Example #3
0
 def test_of_flow_mod(self):
     """Test convertion from Flow to OFFlow."""
     flow_mod_01 = Flow01.from_dict(self.EXPECTED, self.SWITCH)
     flow_mod_04 = Flow04.from_dict(self.EXPECTED, self.SWITCH)
     of_flow_mod_01 = flow_mod_01.as_of_add_flow_mod()
     of_flow_mod_04 = flow_mod_04.as_of_delete_flow_mod()
     self.assertIsInstance(of_flow_mod_01, OFFlow01)
     self.assertIsInstance(of_flow_mod_04, OFFlow04)
Example #4
0
    def handle_stats_reply(event):
        """This method handles stats replies for v0x01 switches.

        Args:
            event (:class:`~kytos.core.events.KytosEvent):
                Event with ofpt_stats_reply in message.
        """
        switch = event.source.switch
        msg = event.content['message']
        if msg.body_type == StatsType.OFPST_FLOW:
            switch.flows = [Flow01.from_of_flow_stats(f, switch)
                            for f in msg.body]
        elif msg.body_type == StatsType.OFPST_DESC:
            switch.update_description(msg.body)