- Community Home
- >
- Networking
- >
- Software Defined Networking
- >
- Re: Get Packet Destination IP
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 11:45 AM - edited 08-13-2014 07:19 AM
08-12-2014 11:45 AM - edited 08-13-2014 07:19 AM
Get Packet Destination IP
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 04:20 PM
08-12-2014 04:20 PM
Re: Get Packet Destination IP
Try this:
Packet packet = Codec.decodeEthernet(context.getPacketIn().getData()); Ip ip = (Ip) packet.get(ProtocolId.IP); IpAddress dst = ip.dstAddr();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2014 07:13 AM
08-13-2014 07:13 AM
Re: Get Packet Destination IP
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2014 10:15 AM
08-13-2014 10:15 AM
Re: Get Packet Destination IP
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2014 03:44 PM
08-14-2014 03:44 PM
Re: Get Packet Destination IP
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)) { }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2014 01:08 AM
08-28-2014 01:08 AM
Re: Get Packet Destination IP
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