Opendaylight BORON packet handling ( Hydrogen'

2019-09-16 12:46发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-16 13:36

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;

    }
}
查看更多
登录 后发表回答