SD-WAN

 View Only
  • 1.  Get Packet Destination IP

    Posted Aug 12, 2014 02:46 PM

    Hi,

     

    I have an application that registers itself as a packet listener on the controller (by implementing SequencedPacketListener). When the SPL event() method is triggered, I want to get the destination IP address and destination port of the packet passed in (from the MessageContext object). How can I get this information?

     

    EDIT:

    I did find the PathDiagnosticService interface which has a .getPath() method. Looks like what I want. Can I use this the same way the ControllerService interface is used?  By this I mean can I simply say "protected volatile PathDiagnosticService pds;" then later invoke it's methods like "pds.findPacketModel(...)" or will that return a NullPointerException because pds wasn't instantiated?


    #SequencedPacketListener
    #PathDiagnosticService
    #SDN
    #nullpointerexception


  • 2.  RE: Get Packet Destination IP

    Posted Aug 12, 2014 07:20 PM

    Try this:

     

    Packet packet = Codec.decodeEthernet(context.getPacketIn().getData());
    Ip ip = (Ip) packet.get(ProtocolId.IP);
    IpAddress dst = ip.dstAddr();

     



  • 3.  RE: Get Packet Destination IP

    Posted Aug 13, 2014 10:13 AM

    Haven't tested it yet, but I'll post if it doesn't work.

     

    One question about the code you supplied, why use Codec specifically to decode the packet? Wouldn't context.decodedPacket() work?



  • 4.  RE: Get Packet Destination IP

    Posted Aug 13, 2014 01:15 PM

    The code you've supplied causes a NullPointerException on the line:

    IpAddress dst = ip.dstAddr();

     

    Full code used in that method was:

    @Override
        public boolean event(MessageContext messageContext) {
            Packet packet = messageContext.decodedPacket();
            Ip ip = (Ip) packet.get(ProtocolId.IP);
            IpAddress dst = ip.dstAddr();
            return false;
        }

     

     



  • 5.  RE: Get Packet Destination IP

    Posted Aug 14, 2014 06:45 PM

    If the packet only goes up to layer 2, then it will not have any IP information which might be the cause of the NullPointerException. Try puttin a check like this and see if it works:

     

    if (packet.has(ProtocolId.IP) || packet.has(ProtocolId.IPV6)) {
    
    }

     



  • 6.  RE: Get Packet Destination IP

    Posted Aug 28, 2014 04:08 AM

    Hello ssrirama,

     

    Did you try as suggested in earlier post?

     

    Please let us know if your problem is solved or you are still facing the issue.

     

    Thanks,

    HP SDN Team