def create_discovery_packet(self, dpid, port_num, port_addr): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl=self._ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet po = of.ofp_packet_out(action=of.ofp_action_output(port=port_num)) po.data = eth.pack() return po.pack()
def create_discovery_packet (self, dpid, port_num, port_addr): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl = self._ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet po = of.ofp_packet_out(action = of.ofp_action_output(port=port_num)) po.data = eth.pack() return po.pack()
def send_discovery_packet(event): """ Sends the discovery packet used to identity the links present between the switches""" for p in event.ofp.ports: chass_id = event.dpid src = str(p.hw_addr) portno = p.port_no chassis_id = pktt.chassis_id(subtype=pktt.chassis_id.SUB_LOCAL, id = str(chass_id)) port_id = pktt.port_id(subtype = pktt.port_id.SUB_PORT, id = str(portno)) ttl = pktt.ttl(ttl = lldp_ttl) discovery_packet = pktt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(pktt.end_tlv()) eth = pktt.ethernet(type = pktt.ethernet.LLDP_TYPE) eth.src = src eth.dst = pktt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet pkt = of.ofp_packet_out(action = of.ofp_action_output(port = portno)) pkt.data = eth.pack() event.connection.send(pkt.pack())
def _create_broadcast_discovery_packet (dpid, port_num, port_addr, ttl): chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl = ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.ETHER_BROADCAST eth.payload = discovery_packet return eth
def _create_discovery_packet(dpid, port_num, port_addr, ttl): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = ('dpid:' + hex(int(dpid))[2:]).encode() # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl=ttl) sysdesc = pkt.system_description() sysdesc.payload = ('dpid:' + hex(int(dpid))[2:]).encode() discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet return eth
def _create_lldp_packet(self,dpid,port_num,port_addr): chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl=self.ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet msg = of.ofp_packet_out(action=of.ofp_action_output(port=port_num)) msg.data = eth.pack() return msg.pack()
def _discover_neighbors(self): # Send an LLDP packet to discover switch links. LLDP lets us include the switch and port identity on this side, # so when we receive the packet on the other side we know about both ends of the link. ports = filter(lambda x: x.port_no <= of.OFPP_MAX, self.connection.ports.itervalues()) for port in ports: lldp_pkt = lldp() lldp_pkt.add_tlv(chassis_id(subtype = chassis_id.SUB_MAC, id = port.hw_addr.toRaw())) lldp_pkt.add_tlv(port_id(subtype = port_id.SUB_PORT, id = str(port.port_no))) lldp_pkt.add_tlv(ttl(ttl = SpanningTreeSwitch.LLDP_TTL)) lldp_pkt.add_tlv(system_description(payload = bytes(self.dpid))) lldp_pkt.add_tlv(end_tlv()) ether_wrapper = ethernet(type = ethernet.LLDP_TYPE, src = port.hw_addr, dst = SpecialMacs.LLDP_BROADCAST, payload = lldp_pkt) self._send_packet(ether_wrapper, port.port_no) Timer(SpanningTreeSwitch.LLDP_LISTEN_DELAY, self._activate)
def _discover_neighbors(self): LldpSwitch.logger.debug('Discovering neighbors on switch {}.'.format(self.dpid)) # Send an LLDP packet to discover switch links. LLDP lets us include the switch # and port identity on this side, so when we receive the packet on the other # side we know about both ends of the link. for port in self._get_discoverable_ports(): LldpSwitch.logger.debug('Discovering neighbors on switch {} port {}.'.format(self.dpid, port.port_no)) lldp_pkt = pkt.lldp() lldp_pkt.add_tlv(pkt.chassis_id(subtype = pkt.chassis_id.SUB_MAC, id = port.hw_addr.toRaw())) lldp_pkt.add_tlv(pkt.port_id(subtype = pkt.port_id.SUB_PORT, id = str(port.port_no))) lldp_pkt.add_tlv(pkt.ttl(ttl = LLDP_TTL)) lldp_pkt.add_tlv(pkt.system_description(payload = bytes(self.dpid))) lldp_pkt.add_tlv(pkt.end_tlv()) ether_wrapper = pkt.ethernet(type = pkt.ethernet.LLDP_TYPE, src = port.hw_addr, dst = SpecialMacs.LLDP_BROADCAST, payload = lldp_pkt) self._send_packet(ether_wrapper, port.port_no) Timer(DISCOVERY_TIMEOUT_PERIOD, self._activate_host_ports)
def create_discovery_packet (self, dpid): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(255)) ttl = pkt.ttl(ttl = 120) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = "0x000000" eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet #---------------Made changes----------------------- actionSet = [] selectedDpid = dpid #print'Sending PacketOut to SWitch', selectedDpid #:need to for all ports in one swtich for p in _portInfo: #packetOut floods exclueding the ingress (secure port to Controller) if p.port_num!=65534 and p.dpid == selectedDpid: actionSet.append(of.ofp_action_dl_addr.set_src(p.port_addr)) actionSet.append(of.ofp_action_output(port=p.port_num)) #print'actionSet-------->',actionSet po = of.ofp_packet_out(action = actionSet) po.data = eth.pack() return po.pack()
def _create_lldp_packet(self, dpid, port_num, port_addr): """ Creating LLDP packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_CHASSIS, id=str(dpid)) port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl=1) lldp_packet = pkt.lldp() lldp_packet.tlvs.append(chassis_id) lldp_packet.tlvs.append(port_id) lldp_packet.tlvs.append(ttl) lldp_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.LLDP_MULTICAST eth.payload = lldp_packet po = of.ofp_packet_out(action=of.ofp_action_output(port=port_num)) po.data = eth.pack() return po.pack()