def handle_packet_in(self, event): """Handle PacketIn Event. Install flows allowing communication between switch ports. Args: event (KytosPacketIn): Received Event """ log.debug("PacketIn Received") packet_in = event.content['message'] ethernet = Ethernet() ethernet.unpack(packet_in.data.value) # Ignore LLDP packets or packets not generated by table-miss flows if (ethernet.destination in settings.lldp_macs or packet_in.reason != PacketInReason.OFPR_NO_MATCH): return # Learn the port where the sender is connected in_port = packet_in.in_port.value switch = event.source.switch switch.update_mac_table(ethernet.source, in_port) ports = switch.where_is_mac(ethernet.destination) # Add a flow to the switch if the destination is known if ports: flow_mod = FlowMod() flow_mod.command = FlowModCommand.OFPFC_ADD flow_mod.match = Match() flow_mod.match.dl_src = ethernet.source.value flow_mod.match.dl_dst = ethernet.destination.value flow_mod.match.dl_type = ethernet.ether_type flow_mod.actions.append(ActionOutput(port=ports[0])) event_out = KytosEvent(name=('kytos/of_l2ls.messages.out.' 'ofpt_flow_mod'), content={ 'destination': event.source, 'message': flow_mod }) self.controller.buffers.msg_out.put(event_out) # Send the packet to correct destination or flood it packet_out = PacketOut() packet_out.buffer_id = packet_in.buffer_id packet_out.in_port = packet_in.in_port packet_out.data = packet_in.data port = ports[0] if ports else Port.OFPP_FLOOD packet_out.actions.append(ActionOutput(port=port)) event_out = KytosEvent(name=('kytos/of_l2ls.messages.out.' 'ofpt_packet_out'), content={ 'destination': event.source, 'message': packet_out }) self.controller.buffers.msg_out.put(event_out)
def send_packet_out(controller, switch, port, data): """ Just prepare the PacketOut to be used by the Tracer. Args: controller: Kytos controller switch: OpenFlow datapath port: in_port data: Ethernet frame Return: output_action = ActionOutput """ output_action = ActionOutput() output_action.port = settings.OFPP_TABLE packet_out = PacketOut() packet_out.actions.append(output_action) packet_out.in_port = port packet_out.data = bytes(data) event_out = KytosEvent() event_out.name = 'kytos/of_lldp.messages.out.ofpt_packet_out' event_out.content = { 'destination': switch.connection, 'message': packet_out } log.debug('PacketOut %s sent' % event_out.content) controller.buffers.msg_out.put(event_out)
def send_packet_out(controller, switch, port, data): """ Just prepare the PacketOut to be used by the Tracer. Args: controller: Kytos controller switch: OpenFlow datapath port: in_port data: Ethernet frame Return: output_action = ActionOutput """ output_action = ActionOutput() output_action.port = settings.OFPP_TABLE packet_out = PacketOut() packet_out.actions.append(output_action) packet_out.in_port = port packet_out.data = bytes(data) event_out = KytosEvent() event_out.name = 'kytos/of_lldp.messages.out.ofpt_packet_out' event_out.content = {'destination': switch.connection, 'message': packet_out} log.debug('PacketOut %s sent' % event_out.content) controller.buffers.msg_out.put(event_out)
def _actions_from_list(action_list): """Return actions found in the action list.""" actions = [] for action in action_list: if action['action_type'] == 'set_vlan': new_action = ActionVlanVid(vlan_id=action['vlan_id']) elif action['action_type'] == 'output': if action['port'] == 'controller': new_action = ActionOutput(port=Port.OFPP_CONTROLLER) else: new_action = ActionOutput(port=action['port']) else: continue actions.append(new_action) return actions
def as_of_action(self): """Build a Action Output from this action. Returns: |action_output|: A instance of ActionOutput. """ return ActionOutput(port=self.output_port)
def send_packet_out(controller, switch, port, data): """ Just prepare and send a PacketOut used by the Tracer. """ output_action = ActionOutput() output_action.port = settings.OFPP_TABLE packet_out = PacketOut() packet_out.actions.append(output_action) packet_out.in_port = port packet_out.data = bytes(data) event_out = KytosEvent() event_out.name = 'kytos/of_lldp.messages.out.ofpt_packet_out' event_out.content = { 'destination': switch.connection, 'message': packet_out } log.debug('PacketOut %s sent' % event_out.content) controller.buffers.msg_out.put(event_out)
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)
def _get_actions(): """Return a List of actions registered by flow object.""" action = ActionOutput(port=65533, max_length=65535) return [action]
def _get_actions(): """Function used to return a list of actions used by packetout instance.""" action = ActionOutput(port=1, max_length=0) return [action]