Well, I found LLDP generation code in "*ryu.topology.switches*" and it is
working now. I had a lot of problems in TLVs definitions. Also, I used
Python3.6 default encoding "UTF-8" which should be "ASCII".

this is the current send_lldp:

>    def send_lldp(self, datapath: Datapath):
>        ports = self.dpset.get_ports(datapath.id)
>        for port in ports:
>            pkt = packet.Packet()
>            pkt.add_protocol(ethernet.ethernet(
>                ethertype=ethernet.ether.ETH_TYPE_LLDP,
>                dst="01:80:C2:00:00:02",
>                src=port.hw_addr
>            ))
>            tlv_chassis_id = lldp.ChassisID(
>                subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
>                chassis_id=(LLDPPacket.CHASSIS_ID_FMT %
>                            dpid_to_str(datapath.id)).encode('ascii'))

>            tlv_port_id =
lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
>                                      port_id=struct.pack(
>                                          LLDPPacket.PORT_ID_STR,
>                                          port.port_no))

>            tlv_ttl = lldp.TTL(ttl=15)
>            tlv_end = lldp.End()

>            tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
>            lldp_pkt = lldp.lldp(tlvs)
>            pkt.add_protocol(lldp_pkt)
>            self._send_packet(datapath, port.port_no, pkt)


On Tue, Feb 19, 2019 at 1:27 PM Maged Motawea <magedmota...@gmail.com>
wrote:

> Dear sir,
>
> I'm using ryu to generate LLDP packets and send them out of all switch
> ports using this code:
>
> >    def send_lldp(self, datapath):
> >        ports = self.dpset.get_ports(datapath.id)
> >        for port in ports:
> >            pkt = packet.Packet()
> >            pkt.add_protocol(ethernet.ethernet(
> >                ethertype=ethernet.ether.ETH_TYPE_LLDP,
> >                dst="01:80:C2:00:00:02",
> >                src=port.hw_addr
> >            ))
> >            pkt.add_protocol(lldp.lldp(
> >                [
> >                    
> > lldp.ChassisID(chassis_id=dpid_to_str(datapath.id).encode(),
> subtype=lldp.ChassisID.SUB_CHASSIS_COMPONENT),
> >                    lldp.PortID(port_id=port.name,
> subtype=lldp.PortID.SUB_INTERFACE_NAME),
> >                ]
> >            ))
> >            try:
> >                self._send_packet(datapath, port.port_no, pkt)
> >            except Exception as e:
> >                print(str(e))
>
>
> I've added a rule to forward packets to the controller in case of LLDP
> match:
> >  parser.OFPMatch(
> >            eth_type=ethernet.ether.ETH_TYPE_LLDP
> >        )
>
>
> but when the packets are received by the controller as PacketIn messages
> I'm unable to get LLDP headers. this is the code I'm using for PacketIn:
>
> >   @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> >    def _packet_in_handler(self, ev):
> >        msg = ev.msg
> >        datapath = msg.datapath
> >        port = msg.match['in_port']
> >        pkt = packet.Packet(msg.data)
> >        self.logger.info("packet-in %s" % (pkt,))
> >        pkt_ethernet = pkt.get_protocol(ethernet.ethernet)
> >        if not pkt_ethernet:
> >            return
> >        pkt_lldp = pkt.get_protocol(lldp.lldp)
> >        if pkt_lldp:
> >            self._handle_lldp(datapath, port, pkt_ethernet, pkt_lldp)
>
> pkt_lldp is None and the value of pkt.protocols is:
> >
> [ethernet(dst='01:80:c2:00:00:02',ethertype=35020,src='d2:7d:8f:dd:c8:bd'),
> b'\x02\x11\x010000ba8f9ab84c4c\x04\x07\x05p1-sw2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00']
>
>
> Best Regards,
> Maged
>
>
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to