Ask Your Question
0

How make the Parse IP/TCP packet from PacketHandler

asked 2014-07-17 11:41:31 -0700

anonymous user

Anonymous

Hi Everyone,

The example of the learning-switch application (in openflowplugin/sample/learning-switch) uses the PacketHandler Class. How and which I use the API for parse IP / TCP from a PacketReceive data?

Thank you very much.

Best Regards.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-08-05 11:33:21 -0700

updated 2014-08-05 11:34:07 -0700

You can use the org.opendaylight.controller.sal.packet package to parse the IP/TCP and other packets.

For a example :

public PacketResult receiveDataPacket(RawPacket inPkt) {
    Packet formattedPak = this.dataPacketService.decodeDataPacket(inPkt);

    if (nextPak instanceof IPv4) {
        IPv4 ipPak = (IPv4)nextPak;
        System.out.println("IP");
        log.trace("Handled IP packet");
        int sipAddr = ipPak.getSourceAddress();
        InetAddress sip = NetUtils.getInetAddress(sipAddr);
        int dipAddr = ipPak.getDestinationAddress();
        InetAddress dip = NetUtils.getInetAddress(dipAddr);
        System.out.println("SRC IP:");
        System.out.println(sip);
        System.out.println("DST IP:");
        System.out.println(dip);

        Object frame = ipPak.getPayload();
        if (frame instanceof ICMP) {
            System.out.println("ICMP from instance");
        }
edit flag offensive delete publish link more
Login/Signup to Answer

Stats

Asked: 2014-07-17 11:41:31 -0700

Seen: 478 times

Last updated: Aug 05 '14