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)
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 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)
def generate_trace_pkt(entries, color, r_id, my_domain): """ Receives the REST/PUT to generate a PacketOut data needs to be serialized. Args: entries: color: result from Coloring Napp for a specific DPID r_id: my_domain: Returns: in_port: pkt: """ trace = {} switch = {} eth = {} ip = {} tp = {} # TODO Validate for dl_vlan. If empty, return error. # Default values dpid, in_port = 0, 65532 if color['color_field'] == 'dl_src': dl_src = color['color_value'] else: dl_src = '0e:55:05:0e:55:05' dl_dst = "ca:fe:ca:fe:ca:fe" dl_vlan, dl_type, dl_vlan_pcp = 100, 2048, 0 nw_src, nw_dst, nw_tos = '127.0.0.1', '127.0.0.1', 0 tp_src, tp_dst = 1, 1 try: trace = entries['trace'] switch = trace['switch'] eth = trace['eth'] except: pass try: ip = trace['ip'] except: pass try: tp = trace['tp'] except: pass if len(switch) > 0: dpid, in_port = prepare_switch(switch, dpid, in_port) if len(eth) > 0: dl_src, dl_dst, dl_vlan, dl_type, dl_vlan_pcp = prepare_ethernet(eth, dl_src, dl_dst, dl_vlan, dl_type, dl_vlan_pcp) # if len(ip) > 0: nw_src, nw_dst, nw_tos = prepare_ip(ip, nw_src, nw_dst, nw_tos) # if len(tp) > 0: tp_src, tp_dst = prepare_tp(tp, tp_src, tp_dst) kethernet = Ethernet() kethernet.ether_type = constants.VLAN kethernet.source = dl_src kethernet.destination = dl_dst kvlan = VLAN(vid=int(dl_vlan), pcp=dl_vlan_pcp, ether_type=int(dl_type)) msg = TraceMsg(r_id, my_domain) if int(dl_type) == constants.IPv4: kip = IPv4() kip.destination = nw_dst kip.source = nw_src # ip.protocol = 6 kip.data = dill.dumps(msg) kvlan.data = kip.pack() else: kvlan.data = dill.dumps(msg) kethernet.data = kvlan.pack() pkt = kethernet.pack() return in_port, pkt