Opendaylight BORON packet handling ( Hydrogen's IListenDataPacket class)

和自甴很熟 提交于 2019-12-25 08:49:23

问题


What API to use to handle packets that arrive at the ODL Controller? In the Hydrogen version, I could implement the IListenDataPacket class, and it did the job.

I searched the documentation for quite a while, but I cant figure it out.


回答1:


Since Beryllium IListenDataPacket is replaced with PacketProcessingListener as part of moving towards MDSAL from ADSAL

Create listener by extending PacketProcsessingListener. and register this listener. If you need to send packets from controller to OVS, you can use PacketProcessingService.

public class PacketHandler implements PacketProcessingListener {

    private final static Logger LOG = LoggerFactory.getLogger(PacketHandler.class);
    private final DataBroker dataBroker;
    private final PacketProcessingService packetProcessor;

    public PacketHandler(DataBroker dataBroker, PacketProcessingService packetProcessor) {
        super();
        this.dataBroker = dataBroker;
        this.packetProcessor = packetProcessor;
    }

    @Override
    public void onPacketReceived(PacketReceived notification) {

        LOG.trace("PacketReceived invoked...");
        short tableId = notification.getTableId().getValue();
        byte[] data = notification.getPayload();
        // BigInteger metadata =
        // notification.getMatch().getMetadata().getMetadata();
        Ethernet res = new Ethernet();

        try {
            res.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
        } catch (Exception e) {
            LOG.warn("Failed to decode Packet ", e);
            return;
        }
        try {
            Packet pkt = res.getPayload();
            if (pkt instanceof IPv4) {
                IPv4 ipv4 = (IPv4) pkt;
                // Handle IPv4 packet
            }
            return;

        } catch (Exception ex) {
            // Failed to handle packet
            LOG.error("Failed to handle subnetroute packets ", ex);
        }
        return;

    }
}


来源:https://stackoverflow.com/questions/41622720/opendaylight-boron-packet-handling-hydrogens-ilistendatapacket-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!